// For clone
        internal FunctionGroup(FunctionGroup <T> other)
        {
            Debug.Assert(other != null);

            this.funcList = new List <
                FunctionInfo <T> >(other.funcList);
        }
Beispiel #2
0
        Exception WrongArgsCount(
            int pos, int len, int args, FunctionGroup <T> group)
        {
            var buf =
                new StringBuilder(Resource.sFunction)
                .Append(" \"")
                .Append(this.expr, pos, len)
                .Append("\" ")
                .AppendFormat(Resource.errWrongOverload, args);

            // NOTE: improve this?
            // NOTE: may be empty FunctionGroup! Show actual message
            // NOTE: FunctionGroup => IEnumerable<FunctionInfo>
            if (group != null)
            {
                buf
                .Append(' ')
                .AppendFormat(
                    Resource.errExistOverload,
                    group.MakeMethodsArgsList());
            }

            return(new SyntaxException(
                       buf.ToString(), this.expr, pos, len));
        }
        public GroupDebugView(FunctionGroup <T> list)
        {
            this.items = new FunctionInfo <T> [list.Count];
            int i = 0;

            foreach (var f in list)
            {
                this.items[i++] = f;
            }
        }
Beispiel #4
0
        Item SimpleMatch(Capture match, ref int i, int len)
        {
            if (match.Type == IdenType.Argument)
            {
                Debug.Assert(Context.Arguments.Count > match.Index);

                Output.PutArgument(match.Index);
                return(Item.Identifier);
            }

            if (match.Type == IdenType.Constant)
            {
                Debug.Assert(Context.Constants.Count > match.Index);

                Output.PutConstant(Context.Constants[match.Index]);
                return(Item.Identifier);
            }

            if (match.Type == IdenType.Function)
            {
                int funcPos = this.curPos;
                if (!SkipBrace(ref i))
                {
                    throw NoOpenBrace(funcPos, len);
                }

                FunctionGroup <T> group = GetGroup(match);

                Output.PutBeginCall();
                int argsCount = ParseNested(ref i, true);

                FunctionInfo <T> func = group.GetOverload(argsCount);
                if (func == null)
                {
                    // there is no valid overload to use:
                    throw WrongArgsCount(
                              funcPos, len, argsCount, group);
                }

                Output.PutCall(func, argsCount);
                return(Item.End);
            }

            throw new NotSupportedException();
        }