예제 #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);
        }
예제 #2
0
        public Expression NewObject(Source src, DataType type, params Expression[] args)
        {
            bool found = false;
            var  fc    = new FunctionCompiler(_compiler, _il);

            type.PopulateMembers();

            foreach (var m in type.Constructors)
            {
                if (m.IsPublic)
                {
                    if (fc.IsArgumentListCompatible(m.Parameters, args))
                    {
                        return(new NewObject(src, m, args));
                    }

                    found = true;
                }
            }

            if (found)
            {
                foreach (var m in type.Constructors)
                {
                    if (m.IsPublic)
                    {
                        var processedArgs = fc.TryApplyDefaultValuesOnArgumentList(src, m.Parameters, args);

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

            Log.Error(src, ErrorCode.E0000, "Constructor not found: '" + type + "..ctor'");
            return(Expression.Invalid);
        }