Example #1
0
        public MethodTarget MakeParamsExtended(int argCount, SymbolId[] names, int[] nameIndexes)
        {
            Debug.Assert(CompilerHelpers.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;

            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(
                                               curArg,
                                               paramsUsed,
                                               sab.Type.GetElementType()));

                        curArg += paramsUsed;
                    }
                    else if (sab.IsParamsDict)
                    {
                        // consume all the kw arguments
                        kwIndex = newArgBuilders.Count;
                    }
                    else
                    {
                        // consume the next argument
                        newArgBuilders.Add(new SimpleArgBuilder(curArg++, sab.Type));
                    }
                }
                else
                {
                    // CodeContext, null, default, etc...  we don't consume an
                    // actual incoming argument.
                    newArgBuilders.Add(ab);
                }
            }

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

            return(new MethodTarget(_binder, Method, argCount, _instanceBuilder, newArgBuilders, _returnBuilder));
        }
Example #2
0
        private int GetConsumedArguments()
        {
            int consuming = 0;

            foreach (ArgBuilder argb in _argBuilders)
            {
                SimpleArgBuilder sab = argb as SimpleArgBuilder;
                if (sab != null && !sab.IsParamsDict)
                {
                    consuming++;
                }
            }
            return(consuming);
        }