SetWrongNumberOfArgumentsError() public method

public SetWrongNumberOfArgumentsError ( int actual, int expected ) : void
actual int
expected int
return void
        public static IList <DynamicMetaObject /*!*/> NormalizeArguments(MetaObjectBuilder /*!*/ metaBuilder, CallArguments /*!*/ args, int minCount, int maxCount)
        {
            int   lastSplattedArg;
            IList list;
            ParameterExpression listVariable;

            // 2 hidden arguments: block and self
            var actualArgs = CreateActualArguments(new List <DynamicMetaObject>(), metaBuilder, args, 2, maxCount, maxCount,
                                                   out lastSplattedArg, out list, out listVariable);

            int actualCount = actualArgs.Count + actualArgs.CollapsedCount;

            if (actualCount < minCount)
            {
                metaBuilder.SetWrongNumberOfArgumentsError(actualCount, minCount);
                return(null);
            }
            else if (actualCount > maxCount)
            {
                metaBuilder.SetWrongNumberOfArgumentsError(actualCount, maxCount);
                return(null);
            }

            // any collapsed args are out of limits:
            return(actualArgs.Arguments);
        }
Exemplo n.º 2
0
 internal override void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name) {
     var actualArgs = RubyMethodGroupInfo.NormalizeArguments(metaBuilder, args, SelfCallConvention.NoSelf, false, false);
     if (actualArgs.Length == 0) {
         metaBuilder.Result = Methods.GetInstanceVariable.OpCall(
             args.ScopeExpression,
             AstFactory.Box(args.TargetExpression),
             AstUtils.Constant(InstanceVariableName)
         );
     } else {
         metaBuilder.SetWrongNumberOfArgumentsError(actualArgs.Length, 0);
     }
 }
Exemplo n.º 3
0
        public void AddCallArguments(MetaObjectBuilder /*!*/ metaBuilder, CallArguments /*!*/ args)
        {
            // simple args:
            for (int i = 0; i < args.SimpleArgumentCount; i++)
            {
                Add(args.GetSimpleArgumentExpression(i));
            }

            // splat arg:
            if (args.Signature.HasSplattedArgument)
            {
                AddSplatted(metaBuilder, args);
            }

            // rhs arg:
            if (args.Signature.HasRhsArgument)
            {
                Add(args.GetRhsArgumentExpression());
            }

            if (HasTooFewArguments)
            {
                metaBuilder.SetWrongNumberOfArgumentsError(_explicitArgCount, _mandatoryParamCount);
                return;
            }

            if (HasTooManyArguments)
            {
                metaBuilder.SetWrongNumberOfArgumentsError(_explicitArgCount, _mandatoryParamCount);
                return;
            }

            // add optional placeholders:
            FillMissingArguments();

            if (_hasUnsplatParameter)
            {
                AddUnsplat();
            }
        }
Exemplo n.º 4
0
        public void AddCallArguments(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
            // simple args:
            for (int i = 0; i < args.SimpleArgumentCount; i++) {
                Add(args.GetSimpleArgumentExpression(i));
            }

            // splat arg:
            if (args.Signature.HasSplattedArgument) {
                AddSplatted(metaBuilder, args);
            }

            // rhs arg:
            if (args.Signature.HasRhsArgument) {
                Add(args.GetRhsArgumentExpression());
            }

            if (HasTooFewArguments) {
                metaBuilder.SetWrongNumberOfArgumentsError(_explicitArgCount, _mandatoryParamCount);
                return;
            }

            if (HasTooManyArguments) {
                metaBuilder.SetWrongNumberOfArgumentsError(_explicitArgCount, _mandatoryParamCount);
                return;
            }

            // add optional placeholders:
            FillMissingArguments();

            if (_hasUnsplatParameter) {
                AddUnsplat();
            }
        }
Exemplo n.º 5
0
        public static IList<DynamicMetaObject/*!*/> NormalizeArguments(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, int minCount, int maxCount) {
            int lastSplattedArg;
            IList list;
            ParameterExpression listVariable;

            // 2 hidden arguments: block and self
            var actualArgs = CreateActualArguments(new List<DynamicMetaObject>(), metaBuilder, args, 2, maxCount, maxCount,
                out lastSplattedArg, out list, out listVariable);

            int actualCount = actualArgs.Count + actualArgs.CollapsedCount;

            if (actualCount < minCount) {
                metaBuilder.SetWrongNumberOfArgumentsError(actualCount, minCount);
                return null;
            } else if (actualCount > maxCount) {
                metaBuilder.SetWrongNumberOfArgumentsError(actualCount, maxCount);
                return null;
            }

            // any collapsed args are out of limits:
            return actualArgs.Arguments;
        }
Exemplo n.º 6
0
        public void AddCallArguments(MetaObjectBuilder /*!*/ metaBuilder, CallArguments /*!*/ args)
        {
            _callArguments = args;

            // calculate actual argument count:
            _actualArgumentCount = args.SimpleArgumentCount;
            if (args.Signature.HasSplattedArgument)
            {
                var splattedArg = args.GetSplattedMetaArgument();
                metaBuilder.AddSplattedArgumentTest((IList)splattedArg.Value, splattedArg.Expression, out _listLength, out _listVariable);
                _actualArgumentCount += _listLength;
            }
            if (args.Signature.HasRhsArgument)
            {
                _actualArgumentCount++;
            }

            // check:
            if (HasTooFewArguments)
            {
                metaBuilder.SetWrongNumberOfArgumentsError(_actualArgumentCount, _mandatoryParamCount);
                return;
            }

            if (HasTooManyArguments)
            {
                metaBuilder.SetWrongNumberOfArgumentsError(_actualArgumentCount, _mandatoryParamCount);
                return;
            }

            bool isSplatted;

            // leading mandatory:
            for (int i = 0; i < _leadingMandatoryParamCount; i++)
            {
                _arguments[LeadingMandatoryIndex + i] = GetArgument(i, out isSplatted);
            }

            // trailing mandatory:
            for (int i = 0; i < TrailingMandatoryCount; i++)
            {
                _arguments[TrailingMandatoryIndex + i] = GetArgument(_actualArgumentCount - TrailingMandatoryCount + i, out isSplatted);
            }

            int start = _leadingMandatoryParamCount;
            int end   = _actualArgumentCount - TrailingMandatoryCount;

            // optional:
            for (int i = 0; i < _optionalParamCount; i++)
            {
                _arguments[OptionalParameterIndex + i] = (start < end) ? GetArgument(start++, out isSplatted) : Ast.Field(null, Fields.DefaultArgument);
            }

            // unsplat:
            if (_hasUnsplatParameter)
            {
                Expression array;
                if (args.Signature.HasSplattedArgument)
                {
                    // simple:
                    var argsToUnsplat = new List <Expression>();
                    while (start < end)
                    {
                        var arg = GetArgument(start, out isSplatted);
                        if (isSplatted)
                        {
                            break;
                        }
                        argsToUnsplat.Add(AstUtils.Box(arg));
                        start++;
                    }
                    array = Methods.MakeArrayOpCall(argsToUnsplat);

                    int rangeStart  = start - args.SimpleArgumentCount;
                    int rangeLength = Math.Min(end - start, _listLength - rangeStart);

                    // splatted:
                    if (rangeLength > 0)
                    {
                        array  = Methods.AddSubRange.OpCall(array, _listVariable, Ast.Constant(rangeStart), Ast.Constant(rangeLength));
                        start += rangeLength;
                    }

                    // rhs:
                    while (start < end)
                    {
                        array = Methods.AddItem.OpCall(array, AstUtils.Box(GetArgument(start, out isSplatted)));
                        start++;
                    }
                }
                else
                {
                    var argsToUnsplat = new List <Expression>(end - start);
                    while (start < end)
                    {
                        argsToUnsplat.Add(AstUtils.Box(GetArgument(start++, out isSplatted)));
                    }
                    array = Methods.MakeArrayOpCall(argsToUnsplat);
                }

                _arguments[UnsplatParameterIndex] = array;
            }

            _callArguments = null;
            _listVariable  = null;
            Debug.Assert(CollectionUtils.TrueForAll(_arguments, (e) => e != null));
        }
Exemplo n.º 7
0
        public void AddCallArguments(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
            _callArguments = args;

            // calculate actual argument count:
            _actualArgumentCount = args.SimpleArgumentCount;
            if (args.Signature.HasSplattedArgument) {
                var splattedArg = args.GetSplattedMetaArgument();
                metaBuilder.AddSplattedArgumentTest((IList)splattedArg.Value, splattedArg.Expression, out _listLength, out _listVariable);
                _actualArgumentCount += _listLength;
            }
            if (args.Signature.HasRhsArgument) {
                _actualArgumentCount++;
            }

            // check:
            if (HasTooFewArguments) {
                metaBuilder.SetWrongNumberOfArgumentsError(_actualArgumentCount, _mandatoryParamCount);
                return;
            }

            if (HasTooManyArguments) {
                metaBuilder.SetWrongNumberOfArgumentsError(_actualArgumentCount, _mandatoryParamCount);
                return;
            }

            bool isSplatted;

            // leading mandatory:
            for (int i = 0; i < _leadingMandatoryParamCount; i++) {
                _arguments[LeadingMandatoryIndex + i] = GetArgument(i, out isSplatted);
            }

            // trailing mandatory:
            for (int i = 0; i < TrailingMandatoryCount; i++) {
                _arguments[TrailingMandatoryIndex + i] = GetArgument(_actualArgumentCount - TrailingMandatoryCount + i, out isSplatted);
            }

            int start = _leadingMandatoryParamCount;
            int end = _actualArgumentCount - TrailingMandatoryCount;

            // optional:
            for (int i = 0; i < _optionalParamCount; i++) {
                _arguments[OptionalParameterIndex + i] = (start < end) ? GetArgument(start++, out isSplatted) : Ast.Field(null, Fields.DefaultArgument);
            }

            // unsplat:
            if (_hasUnsplatParameter) {
                Expression array;
                if (args.Signature.HasSplattedArgument) {
                    // simple:
                    var argsToUnsplat = new List<Expression>();
                    while (start < end) {
                        var arg = GetArgument(start, out isSplatted);
                        if (isSplatted) {
                            break;
                        }
                        argsToUnsplat.Add(AstUtils.Box(arg));
                        start++;
                    }
                    array = Methods.MakeArrayOpCall(argsToUnsplat);
                    
                    int rangeStart = start - args.SimpleArgumentCount;
                    int rangeLength = Math.Min(end - start, _listLength - rangeStart);

                    // splatted:
                    if (rangeLength > 0) {
                        array = Methods.AddSubRange.OpCall(array, _listVariable, Ast.Constant(rangeStart), Ast.Constant(rangeLength));
                        start += rangeLength;
                    }

                    // rhs:
                    while (start < end) {
                        array = Methods.AddItem.OpCall(array, AstUtils.Box(GetArgument(start, out isSplatted)));
                        start++;
                    }
                } else {
                    var argsToUnsplat = new List<Expression>(end - start);
                    while (start < end) {
                        argsToUnsplat.Add(AstUtils.Box(GetArgument(start++, out isSplatted)));
                    }
                    array = Methods.MakeArrayOpCall(argsToUnsplat);
                }

                _arguments[UnsplatParameterIndex] = array;
            }

            _callArguments = null;
            _listVariable = null;
            Debug.Assert(CollectionUtils.TrueForAll(_arguments, (e) => e != null));
        }