ArgBuilder provides an argument value used by the MethodBinder. One ArgBuilder exists for each physical parameter defined on a method. Contrast this with ParameterWrapper which represents the logical argument passed to the method.
Example #1
0
        public KeywordArgBuilder(ArgBuilder builder, int kwArgCount, int kwArgIndex) 
            : base(builder.ParameterInfo) {

            Debug.Assert(BuilderExpectsSingleParameter(builder));
            _builder = builder;

            Debug.Assert(kwArgIndex < kwArgCount);
            _kwArgCount = kwArgCount;
            _kwArgIndex = kwArgIndex;
        }
Example #2
0
 /// <summary>
 /// The underlying builder should expect a single parameter as KeywordArgBuilder is responsible
 /// for calculating the correct parameter to use
 /// </summary>
 /// <param name="builder"></param>
 internal static bool BuilderExpectsSingleParameter(ArgBuilder builder)
 {
     return (((SimpleArgBuilder)builder).Index == 0);
 }
Example #3
0
        private MethodCandidate MakeParamsExtended(string[] names, int[] nameIndices, List <ParameterWrapper> parameters)
        {
            Debug.Assert(Overload.IsVariadic);

            List <ArgBuilder> newArgBuilders = new List <ArgBuilder>(ArgBuilders.Count);

            // current argument that we consume, initially skip this if we have it.
            int        curArg            = Overload.IsStatic ? 0 : 1;
            int        kwIndex           = -1;
            ArgBuilder paramsDictBuilder = null;

            foreach (ArgBuilder ab in ArgBuilders)
            {
                // TODO: define a virtual method on ArgBuilder implementing this functionality:

                if (ab is SimpleArgBuilder sab)
                {
                    // we consume one or more incoming argument(s)
                    if (sab.IsParamsArray)
                    {
                        // consume all the extra arguments
                        int paramsUsed = parameters.Count -
                                         GetConsumedArguments() -
                                         names.Length +
                                         (Overload.IsStatic ? 1 : 0);

                        newArgBuilders.Add(new ParamsArgBuilder(
                                               sab.ParameterInfo,
                                               sab.Type.GetElementType(),
                                               curArg,
                                               paramsUsed
                                               ));

                        curArg += paramsUsed;
                    }
                    else if (sab.IsParamsDict)
                    {
                        // consume all the kw arguments
                        kwIndex           = newArgBuilders.Count;
                        paramsDictBuilder = sab;
                    }
                    else
                    {
                        // consume the argument, adjust its position:
                        newArgBuilders.Add(sab.MakeCopy(curArg++));
                    }
                }
                else if (ab is KeywordArgBuilder)
                {
                    newArgBuilders.Add(ab);
                    curArg++;
                }
                else
                {
                    // CodeContext, null, default, etc...  we don't consume an
                    // actual incoming argument.
                    newArgBuilders.Add(ab);
                }
            }

            if (kwIndex != -1)
            {
                newArgBuilders.Insert(kwIndex, new ParamsDictArgBuilder(paramsDictBuilder.ParameterInfo, curArg, names, nameIndices));
            }

            return(new MethodCandidate(Resolver, Overload, parameters, null, ReturnBuilder, _instanceBuilder, newArgBuilders, null));
        }
Example #4
0
 /// <summary>
 /// The underlying builder should expect a single parameter as KeywordArgBuilder is responsible
 /// for calculating the correct parameter to use
 /// </summary>
 /// <param name="builder"></param>
 internal static bool BuilderExpectsSingleParameter(ArgBuilder builder)
 {
     return(((SimpleArgBuilder)builder).Index == 0);
 }
Example #5
0
        internal MethodTarget(MethodBinder binder, MethodBase method, int parameterCount, ArgBuilder instanceBuilder, IList <ArgBuilder> argBuilders, ReturnBuilder returnBuilder)
        {
            this._binder          = binder;
            this._method          = method;
            this._parameterCount  = parameterCount;
            this._instanceBuilder = instanceBuilder;
            this._argBuilders     = argBuilders;
            this._returnBuilder   = returnBuilder;

            //argBuilders.TrimExcess();
        }
Example #6
0
        internal MethodTarget MakeParamsExtended(int argCount, SymbolId[] names, int[] nameIndexes)
        {
            Debug.Assert(BinderHelpers.IsParamsMethod(Method));

            List <ArgBuilder> newArgBuilders = new List <ArgBuilder>(_argBuilders.Count);

            // current argument that we consume, initially skip this if we have it.
            int        curArg            = CompilerHelpers.IsStatic(_method) ? 0 : 1;
            int        kwIndex           = -1;
            ArgBuilder paramsDictBuilder = null;

            foreach (ArgBuilder ab in _argBuilders)
            {
                SimpleArgBuilder sab = ab as SimpleArgBuilder;
                if (sab != null)
                {
                    // we consume one or more incoming argument(s)
                    if (sab.IsParamsArray)
                    {
                        // consume all the extra arguments
                        int paramsUsed = argCount -
                                         GetConsumedArguments() -
                                         names.Length +
                                         (CompilerHelpers.IsStatic(_method) ? 1 : 0);

                        newArgBuilders.Add(new ParamsArgBuilder(
                                               sab.ParameterInfo,
                                               sab.Type.GetElementType(),
                                               curArg,
                                               paramsUsed
                                               ));

                        curArg += paramsUsed;
                    }
                    else if (sab.IsParamsDict)
                    {
                        // consume all the kw arguments
                        kwIndex           = newArgBuilders.Count;
                        paramsDictBuilder = sab;
                    }
                    else
                    {
                        // consume the argument, adjust its position:
                        newArgBuilders.Add(sab.MakeCopy(curArg++));
                    }
                }
                else
                {
                    // CodeContext, null, default, etc...  we don't consume an
                    // actual incoming argument.
                    newArgBuilders.Add(ab);
                }
            }

            if (kwIndex != -1)
            {
                newArgBuilders.Insert(kwIndex, new ParamsDictArgBuilder(paramsDictBuilder.ParameterInfo, curArg, names, nameIndexes));
            }

            return(new MethodTarget(_binder, Method, argCount, _instanceBuilder, newArgBuilders, _returnBuilder));
        }