Example #1
0
        protected override Expression DoResolve(ResolveContext ec)
        {
            // We have to set these
            this.type   = mg.BestCandidateReturnType;
            this.eclass = ExprClass.Value;

            expr = expr.Resolve(ec);
            if (expr == null)
            {
                return(null);
            }

            Expression argExp;

            bool dynamic_arg;

            if (arguments != null)
            {
                arguments.Resolve(ec, out dynamic_arg);
            }

            switch (mg.Name)
            {
            case "Emit":
                if (!CheckConstant(ec, arguments [0]))
                {
                    return(null);
                }
                this.opcode = _opCodes [(int)((Constant)arguments [0].Expr).GetValue()];
                break;

            case "Load":
                break;

            case "LoadAddr":
                argExp = arguments [0].Expr;
                if (argExp is BoxedCast)
                {
                    argExp = ((BoxedCast)argExp).Child;
                }
                var memloc = argExp as IMemoryLocation;
                if (memloc == null)
                {
                    ec.Report.Error(7803, expr.Location, "Argument must be a valid memory location");
                    return(null);
                }
                break;

            case "LoadInd":
                if (!CheckTypeExpr(ec, arguments[0]))
                {
                    return(null);
                }
                if (!CheckConstant(ec, arguments [1]))
                {
                    return(null);
                }
                break;

            case "Store":
                argExp = arguments [0].Expr;
                if (argExp is BoxedCast)
                {
                    argExp = ((BoxedCast)argExp).Child;
                }
                var t = argExp as IAssignMethod;
                if (t == null)
                {
                    ec.Report.Error(7804, expr.Location, "Argument must be a valid assignment target");
                    return(null);
                }
                if (!CheckConstant(ec, arguments [1]))
                {
                    return(null);
                }
                break;

            case "StoreInd":
                if (!CheckTypeExpr(ec, arguments[0]))
                {
                    return(null);
                }
                if (!CheckConstant(ec, arguments [1]))
                {
                    return(null);
                }
                break;

            default:
                ec.Report.Error(7802, "Invalid intrinsic method");
                return(null);
            }

            return(this);
        }