Exemple #1
0
        /// <summary>
        /// Bind a macro parameter of multivector type to a set of target language variables or constant values
        /// using a generating function acting on each basis blade of the multivector
        /// </summary>
        /// <param name="valueAccess"></param>
        /// <param name="bindingFunction"></param>
        /// <param name="ignoreNullPatterns"></param>
        /// <returns></returns>
        public GMacMacroBinding BindMultivectorUsing(AstDatastoreValueAccess valueAccess, Func <AstFrame, int, GMacScalarBinding> bindingFunction, bool ignoreNullPatterns = true)
        {
            if (valueAccess.IsNullOrInvalid())
            {
                throw new ArgumentNullException(nameof(valueAccess));
            }

            if (valueAccess.AssociatedValueAccess.ExpressionType.IsFrameMultivector() == false)
            {
                throw new InvalidOperationException("Specified macro parameter is not of multivector type");
            }

            var frameInfo =
                new AstFrame(
                    ((GMacFrameMultivector)valueAccess.AssociatedValueAccess.ExpressionType).ParentFrame
                    );

            var primitiveValueAccessList =
                valueAccess.ExpandAll();

            foreach (var primitiveValueAccess in primitiveValueAccessList)
            {
                var id = primitiveValueAccess.GetBasisBladeId();

                var scalarPattern = bindingFunction(frameInfo, id);

                if (ignoreNullPatterns == false || scalarPattern != null)
                {
                    BindScalarToPattern(primitiveValueAccess, scalarPattern);
                }
            }

            return(this);
        }
Exemple #2
0
        /// <summary>
        /// Find all primitive parameters in this code block that are sub-components of the given
        /// macro parameter value access component
        /// </summary>
        /// <param name="paramValueAccess"></param>
        /// <returns></returns>
        public IEnumerable <IGMacCbParameterVariable> GetParameters(AstDatastoreValueAccess paramValueAccess)
        {
            var result = new List <IGMacCbParameterVariable>();

            if (paramValueAccess.IsNullOrInvalid())
            {
                return(result);
            }

            var name = paramValueAccess.ValueAccessName;

            //A single parameter is to be found
            if (paramValueAccess.IsPrimitive)
            {
                var item = ParameterVariables.FirstOrDefault(
                    p => p.ValueAccessName == name
                    );

                if (ReferenceEquals(item, null) == false)
                {
                    result.Add(item);
                }

                return(result);
            }

            //Partial multivectors require special treatment
            if (paramValueAccess.IsPartialMultivector)
            {
                var primitiveValueAccessList = paramValueAccess.ExpandAll();

                foreach (var primitiveValueAccess in primitiveValueAccessList)
                {
                    IGMacCbParameterVariable paramVar;

                    if (TryGetParameterVariable(primitiveValueAccess, out paramVar))
                    {
                        result.Add(paramVar);
                    }
                }

                return(result);
            }

            //All other cases can be searched by name
            name = name + ".";

            result.AddRange(
                ParameterVariables.Where(
                    p => p.ValueAccessName.IndexOf(name, StringComparison.Ordinal) == 0
                    )
                );

            return(result);
        }
Exemple #3
0
        /// <summary>
        /// Bind a macro parameter of any type to a set of variables
        /// </summary>
        /// <param name="valueAccess"></param>
        /// <returns></returns>
        public GMacMacroBinding BindToVariables(AstDatastoreValueAccess valueAccess)
        {
            if (valueAccess.IsNullOrInvalid())
            {
                throw new ArgumentNullException(nameof(valueAccess));
            }

            if (valueAccess.IsScalar)
            {
                BindScalarToPattern(valueAccess, GMacScalarBinding.CreateVariable(BaseMacro.Root));

                return(this);
            }

            var primitiveValueAccessList = valueAccess.ExpandAll();

            foreach (var primitiveValueAccess in primitiveValueAccessList)
            {
                BindScalarToPattern(primitiveValueAccess, GMacScalarBinding.CreateVariable(BaseMacro.Root));
            }

            return(this);
        }