Ejemplo n.º 1
0
        public Expression CallMethod(Source src, DataType dt, Expression obj, string method, params Expression[] args)
        {
            var fc = new FunctionCompiler(_compiler, dt, obj);
            var mg = fc.CompileExpression(Parser.ParseExpression(Log, src, method));

            if (mg.IsInvalid)
            {
                return(mg);
            }

            if (mg is MethodGroup)
            {
                foreach (var m in (mg as MethodGroup).Candidates)
                {
                    if (fc.IsArgumentListCompatible(m.Parameters, args))
                    {
                        return(new CallMethod(src, obj, m, args));
                    }
                }

                foreach (var m in (mg as MethodGroup).Candidates)
                {
                    var processedArgs = fc.TryApplyDefaultValuesOnArgumentList(src, m.Parameters, args);

                    if (fc.IsArgumentListCompatibleUsingImplicitCasts(m.Parameters, processedArgs))
                    {
                        fc.ApplyImplicitCastsOnArgumentList(m.Parameters, processedArgs);
                        return(new CallMethod(src, obj, m, processedArgs));
                    }
                }
            }

            var pl    = "(";
            var first = true;

            foreach (var a in args)
            {
                if (!first)
                {
                    pl += ",";
                }
                pl   += a.ReturnType;
                first = false;
            }
            pl += ")";

            Log.Error(src, ErrorCode.E0000, "No matching method overload: '" + dt + "." + method + pl + "'");
            return(Expression.Invalid);
        }
Ejemplo n.º 2
0
        void CompileTerminalProperty(TerminalProperty t)
        {
            var dt = _ilf.GetType(t.TypeString);
            var mp = new MetaProperty(Source.Unknown, _terminals, dt, t.Name, MetaVisibility.Public);
            var fc = new FunctionCompiler(_compiler, mp);

            _terminals.Members.Add(mp);
            _terminalNames.Add(mp.Name);

            if (t.DefaultString != null)
            {
                var e = Parser.ParseExpression(Log, Source.Unknown, t.DefaultString, ParseContext.MetaProperty);
                var v = fc.CompileExpression(e);
                mp.SetDefinitions(new MetaDefinition(v, new string[0]));
            }
            else
            {
                mp.SetDefinitions();
            }
        }