Emit() static private method

static private Emit ( AST ast, ILGenerator il, Type source_type, Type target_type ) : void
ast AST
il ILGenerator
source_type System.Type
target_type System.Type
return void
Exemplo n.º 1
0
        internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets)
        {
            MethodInfo meth = this.method;

            if (meth != null)
            {
                Type t = meth.ReflectedType;
                if (!meth.IsStatic)
                {
                    this.method = null;
                    this.TranslateToIL(il, t);
                    this.method = meth;
                }
                ParameterInfo[] pars = meth.GetParameters();
                Binding.PlaceArgumentsOnStack(il, pars, argList, 0, 0, Binding.ReflectionMissingCW);
                if (meth.IsVirtual && !meth.IsFinal && !t.IsSealed)
                {
                    il.Emit(OpCodes.Callvirt, meth);
                }
                else
                {
                    il.Emit(OpCodes.Call, meth);
                }
                Convert.Emit(this, il, meth.ReturnType, rtype);
            }
            else
            {
                base.TranslateToILCall(il, rtype, argList, construct, brackets);
            }
        }
Exemplo n.º 2
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            if (rtype == Typeob.Void)
            {
                return;
            }
            IReflect ir = this.InferType(null);

            if (ir is GlobalScope)
            {
                this.EmitILToLoadEngine(il);
                if (rtype == Typeob.LenientGlobalObject)
                {
                    il.Emit(OpCodes.Call, CompilerGlobals.getLenientGlobalObjectMethod);
                }
                else
                {
                    il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
                    il.Emit(OpCodes.Castclass, CompilerGlobals.iActivationObjectClass);
                    il.Emit(OpCodes.Callvirt, CompilerGlobals.getDefaultThisObjectMethod);
                }
                return;
            }
            il.Emit(OpCodes.Ldarg_0);
            Convert.Emit(this, il, Convert.ToType(this.InferType(null)), rtype);
        }
Exemplo n.º 3
0
        internal virtual void TranslateToConditionalBranch(ILGenerator il, bool branchIfTrue, Label label, bool shortForm)
        {
            //This method is overridden in all interesting cases.
            IReflect ir = this.InferType(null);

            if (ir != Typeob.Object && ir is Type)
            {
                String     op   = branchIfTrue ? "op_True" : "op_False";
                MethodInfo meth = ir.GetMethod(op, BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { (Type)ir }, null);
                if (meth != null)
                {
                    this.TranslateToIL(il, (Type)ir);
                    il.Emit(OpCodes.Call, meth);
                    il.Emit(OpCodes.Brtrue, label);
                    return;
                }
            }
            Type t = Convert.ToType(ir);

            this.TranslateToIL(il, t);
            Convert.Emit(this, il, t, Typeob.Boolean, true);
            if (branchIfTrue)
            {
                il.Emit(shortForm ? OpCodes.Brtrue_S : OpCodes.Brtrue, label);
            }
            else
            {
                il.Emit(shortForm ? OpCodes.Brfalse_S : OpCodes.Brfalse, label);
            }
        }
Exemplo n.º 4
0
        internal override void TranslateToILDelete(ILGenerator il, Type rtype)
        {
            IReflect ir     = this.func.InferType(null);
            Type     obType = Convert.ToType(ir);

            this.func.TranslateToIL(il, obType);
            this.args.TranslateToIL(il, Typeob.ArrayOfObject);
            if (this.func is Binding)
            {
                MethodInfo deleteOp;
                if (ir is ClassScope)
                {
                    deleteOp = ((ClassScope)ir).owner.deleteOpMethod;
                }
                else
                {
                    deleteOp = ir.GetMethod("op_Delete", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static,
                                            null, new Type[] { obType, Typeob.ArrayOfObject }, null);
                }
                if (deleteOp != null && (deleteOp.Attributes & MethodAttributes.SpecialName) != 0 && deleteOp.ReturnType == Typeob.Boolean)
                {
                    il.Emit(OpCodes.Call, deleteOp);
                    Convert.Emit(this, il, Typeob.Boolean, rtype);
                    return;
                }
            }
            ConstantWrapper.TranslateToILInt(il, this.args.count - 1);
            il.Emit(OpCodes.Ldelem_Ref);
            Convert.Emit(this, il, Typeob.Object, Typeob.String);
            il.Emit(OpCodes.Call, CompilerGlobals.deleteMemberMethod);
            Convert.Emit(this, il, Typeob.Boolean, rtype);
        }
Exemplo n.º 5
0
 internal override void TranslateToIL(ILGenerator il, Type rtype)
 {
     this.operand1.TranslateToIL(il, Typeob.Object);
     this.operand2.TranslateToIL(il, Typeob.Object);
     il.Emit(OpCodes.Call, CompilerGlobals.jScriptInMethod);
     Convert.Emit(this, il, Typeob.Boolean, rtype);
 }
Exemplo n.º 6
0
 internal override void TranslateToIL(ILGenerator il, Type rtype)
 {
     //This assumes that rtype == Void.class.
     this.context.EmitLineInfo(il);
     if (this.operand != null)
     {
         this.operand.TranslateToIL(il, this.enclosingFunctionScope.returnVar.FieldType);
     }
     else if (this.enclosingFunctionScope.returnVar != null)
     {
         il.Emit(OpCodes.Ldsfld, CompilerGlobals.undefinedField);
         Convert.Emit(this, il, Typeob.Object, this.enclosingFunctionScope.returnVar.FieldType);
     }
     if (this.enclosingFunctionScope.returnVar != null)
     {
         il.Emit(OpCodes.Stloc, (LocalBuilder)this.enclosingFunctionScope.returnVar.GetMetaData());
     }
     if (this.leavesFinally)
     {
         il.Emit(OpCodes.Newobj, CompilerGlobals.returnOutOfFinallyConstructor);
         il.Emit(OpCodes.Throw);
     }
     else if (compilerGlobals.InsideProtectedRegion)
     {
         il.Emit(OpCodes.Leave, this.enclosingFunctionScope.owner.returnLabel);
     }
     else
     {
         il.Emit(OpCodes.Br, this.enclosingFunctionScope.owner.returnLabel);
     }
 }
Exemplo n.º 7
0
 internal virtual void TranslateToILDelete(ILGenerator il, Type rtype)
 {
     if (rtype != Typeob.Void)
     {
         il.Emit(OpCodes.Ldc_I4_1); //This is according to spec, but not backwards compatible with JS5. The latter throws an exception.
         Convert.Emit(this, il, Typeob.Boolean, rtype);
     }
 }
Exemplo n.º 8
0
 internal override void TranslateToIL(ILGenerator il, Type rtype)
 {
     if (this.metaData == null)
     {
         TranslateToILForNoOverloadCase(il, rtype);
         return;
     }
     if (this.metaData is MethodInfo)
     {
         Object          result = null;
         MethodInfo      oper   = (MethodInfo)this.metaData;
         Type            type   = Convert.ToType(this.operand1.InferType(null));
         ParameterInfo[] pars   = oper.GetParameters();
         this.operand1.TranslateToILPreSetPlusGet(il);
         Convert.Emit(this, il, type, pars[0].ParameterType);
         this.operand2.TranslateToIL(il, pars[1].ParameterType);
         il.Emit(OpCodes.Call, oper);
         if (rtype != Typeob.Void)
         {
             result = il.DeclareLocal(rtype);
             il.Emit(OpCodes.Dup);
             Convert.Emit(this, il, type, rtype);
             il.Emit(OpCodes.Stloc, (LocalBuilder)result);
         }
         Convert.Emit(this, il, oper.ReturnType, type);
         this.operand1.TranslateToILSet(il);
         if (rtype != Typeob.Void)
         {
             il.Emit(OpCodes.Ldloc, (LocalBuilder)result);
         }
     }
     else
     {
         //Getting here is just too bad. We do not know until the code runs whether or not to call an overloaded operator method.
         //Compile operands to objects and devolve the decision making to run time thunks
         Type         type   = Convert.ToType(this.operand1.InferType(null));
         LocalBuilder result = il.DeclareLocal(Typeob.Object);
         this.operand1.TranslateToILPreSetPlusGet(il);
         Convert.Emit(this, il, type, Typeob.Object);
         il.Emit(OpCodes.Stloc, result);
         il.Emit(OpCodes.Ldloc, (LocalBuilder)this.metaData);
         il.Emit(OpCodes.Ldloc, result);
         this.operand2.TranslateToIL(il, Typeob.Object);
         il.Emit(OpCodes.Call, CompilerGlobals.evaluatePlusMethod);
         if (rtype != Typeob.Void)
         {
             il.Emit(OpCodes.Dup);
             il.Emit(OpCodes.Stloc, result);
         }
         Convert.Emit(this, il, Typeob.Object, type);
         this.operand1.TranslateToILSet(il);
         if (rtype != Typeob.Void)
         {
             il.Emit(OpCodes.Ldloc, result);
             Convert.Emit(this, il, Typeob.Object, rtype);
         }
     }
 }
Exemplo n.º 9
0
        private void TranslateToILForNoOverloadCase(ILGenerator il, Type rtype)
        {
            Type lhtype       = Convert.ToType(this.operand1.InferType(null));
            Type operand2type = Convert.ToType(this.operand2.InferType(null));
            Type bbrType      = BitwiseBinary.ResultType(lhtype, operand2type, this.operatorTok);

            this.operand1.TranslateToILPreSetPlusGet(il);
            Convert.Emit(this, il, lhtype, bbrType, true);
            this.operand2.TranslateToIL(il, operand2type);
            Convert.Emit(this, il, operand2type, BitwiseBinary.Operand2Type(this.operatorTok, bbrType), true);
            switch (this.operatorTok)
            {
            case JSToken.BitwiseAnd:
                il.Emit(OpCodes.And);
                break;

            case JSToken.BitwiseOr:
                il.Emit(OpCodes.Or);
                break;

            case JSToken.BitwiseXor:
                il.Emit(OpCodes.Xor);
                break;

            case JSToken.LeftShift:
                BitwiseBinary.TranslateToBitCountMask(il, bbrType, this.operand2);
                il.Emit(OpCodes.Shl);
                break;

            case JSToken.RightShift:
                BitwiseBinary.TranslateToBitCountMask(il, bbrType, this.operand2);
                il.Emit(OpCodes.Shr);
                break;

            case JSToken.UnsignedRightShift:
                BitwiseBinary.TranslateToBitCountMask(il, bbrType, this.operand2);
                il.Emit(OpCodes.Shr_Un);
                break;

            default:
                throw new JScriptException(JSError.InternalError, this.context);
            }
            if (rtype != Typeob.Void)
            {
                LocalBuilder result = il.DeclareLocal(bbrType);
                il.Emit(OpCodes.Dup);
                il.Emit(OpCodes.Stloc, result);
                Convert.Emit(this, il, bbrType, lhtype);
                this.operand1.TranslateToILSet(il);
                il.Emit(OpCodes.Ldloc, result);
                Convert.Emit(this, il, bbrType, rtype);
            }
            else
            {
                Convert.Emit(this, il, bbrType, lhtype);
                this.operand1.TranslateToILSet(il);
            }
        }
Exemplo n.º 10
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            Type t1 = Convert.ToType(this.operand1.InferType(null));
            Type t2 = Convert.ToType(this.operand2.InferType(null));

            if (t1 != t2)
            {
                t1 = Typeob.Object;
            }
            MethodInfo opTrue = t1.GetMethod("op_True", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { t1 }, null);

            if (opTrue == null || (opTrue.Attributes & MethodAttributes.SpecialName) == 0 || opTrue.ReturnType != Typeob.Boolean)
            {
                opTrue = null;
            }
            MethodInfo bitwiseOr = null;

            if (opTrue != null)
            {
                bitwiseOr = t1.GetMethod("op_BitwiseOr", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { t1, t1 }, null);
            }
            if (bitwiseOr == null || (bitwiseOr.Attributes & MethodAttributes.SpecialName) == 0)
            {
                opTrue = null;
            }
            Label exit = il.DefineLabel();

            this.operand1.TranslateToIL(il, t1);
            il.Emit(OpCodes.Dup);
            if (opTrue != null)
            {
                if (t1.IsValueType)
                {
                    Convert.EmitLdloca(il, t1);
                }
                il.Emit(OpCodes.Call, opTrue);
                il.Emit(OpCodes.Brtrue, exit);
                this.operand2.TranslateToIL(il, t1);
                il.Emit(OpCodes.Call, bitwiseOr);
                il.MarkLabel(exit);
                Convert.Emit(this, il, bitwiseOr.ReturnType, rtype);
            }
            else
            {
                Convert.Emit(this, il, t1, Typeob.Boolean, true);
                il.Emit(OpCodes.Brtrue, exit);
                il.Emit(OpCodes.Pop);
                this.operand2.TranslateToIL(il, t1);
                il.MarkLabel(exit);
                Convert.Emit(this, il, t1, rtype);
            }
        }
Exemplo n.º 11
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            Label true_label = il.DefineLabel();
            Label done_label = il.DefineLabel();

            this.TranslateToConditionalBranch(il, true, true_label, true);
            il.Emit(OpCodes.Ldc_I4_0);
            il.Emit(OpCodes.Br_S, done_label);
            il.MarkLabel(true_label);
            il.Emit(OpCodes.Ldc_I4_1);
            il.MarkLabel(done_label);
            Convert.Emit(this, il, Typeob.Boolean, rtype);
        }
Exemplo n.º 12
0
 internal override void TranslateToIL(ILGenerator il, Type rtype)
 {
     this.operand.TranslateToIL(il, Typeob.Object); //force evaluation
     if (rtype != Typeob.Void)
     {
         il.Emit(OpCodes.Ldsfld, CompilerGlobals.undefinedField);
         Convert.Emit(this, il, Typeob.Object, rtype);
     }
     else
     {
         il.Emit(OpCodes.Pop);
     }
 }
Exemplo n.º 13
0
 internal override void TranslateToIL(ILGenerator il, Type rtype)
 {
     if (this.operand is Binding)
     {
         //Make sure that no exception is thrown if the operand is an undefined identifier
         ((Binding)this.operand).TranslateToIL(il, Typeob.Object, true);
     }
     else
     {
         this.operand.TranslateToIL(il, Typeob.Object);
     }
     il.Emit(OpCodes.Call, CompilerGlobals.jScriptTypeofMethod);
     Convert.Emit(this, il, Typeob.String, rtype);
 }
Exemplo n.º 14
0
 internal override void TranslateToIL(ILGenerator il, Type rtype)
 {
     if (this.enclosingFunctionScope != null && this.enclosingFunctionScope.owner != null)
     {
         this.enclosingFunctionScope.owner.TranslateToILToSaveLocals(il);
     }
     this.operand.TranslateToIL(il, Typeob.Object);
     this.EmitILToLoadEngine(il);
     il.Emit(OpCodes.Call, CompilerGlobals.jScriptEvaluateMethod);
     Convert.Emit(this, il, Typeob.Object, rtype);
     if (this.enclosingFunctionScope != null && this.enclosingFunctionScope.owner != null)
     {
         this.enclosingFunctionScope.owner.TranslateToILToRestoreLocals(il);
     }
 }
Exemplo n.º 15
0
 internal override void TranslateToIL(ILGenerator il, Type rtype)
 {
     foreach (CustomAttributeBuilder ca in this.list.GetCustomAttributeBuilders(false))
     {
         this.compilerGlobals.assemblyBuilder.SetCustomAttribute(ca);
     }
     if (rtype != Typeob.Void)
     {
         il.Emit(OpCodes.Ldnull);
         if (rtype.IsValueType)
         {
             Convert.Emit(this, il, Typeob.Object, rtype);
         }
     }
 }
Exemplo n.º 16
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            int n = this.keys.Length;

            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.getOriginalObjectConstructorMethod);
            il.Emit(OpCodes.Call, CompilerGlobals.constructObjectMethod);
            for (int i = 0; i < n; i++)
            {
                il.Emit(OpCodes.Dup);
                this.keys[i].TranslateToIL(il, Typeob.String);
                this.values[i].TranslateToIL(il, Typeob.Object);
                il.Emit(OpCodes.Call, CompilerGlobals.setMemberValue2Method);
            }
            Convert.Emit(this, il, Typeob.Object, rtype);
        }
Exemplo n.º 17
0
        internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets)
        {
            if (this.isFullyResolved)
            {
                base.TranslateToILCall(il, rtype, argList, construct, brackets);
                return;
            }
            //Need to do a dynamic lookup to see if there is a dynamically introduced (by eval or with) hiding definition.
            Label lateBoundCall = il.DefineLabel();
            Label done          = il.DefineLabel();

            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
            il.Emit(OpCodes.Castclass, Typeob.IActivationObject);
            il.Emit(OpCodes.Ldstr, this.name);
            ConstantWrapper.TranslateToILInt(il, this.lexLevel);
            il.Emit(OpCodes.Callvirt, CompilerGlobals.getMemberValueMethod);
            il.Emit(OpCodes.Dup);
            il.Emit(OpCodes.Call, CompilerGlobals.isMissingMethod);
            il.Emit(OpCodes.Brfalse, lateBoundCall); //dynamic lookup succeeded, do not call early bound method
            il.Emit(OpCodes.Pop);                    //The dynamic lookup returned Missing.Value, discard it and go on to use the value from the early bound location.
            base.TranslateToILCall(il, Typeob.Object, argList, construct, brackets);
            il.Emit(OpCodes.Br, done);               //Skip over the latebound call sequence
            il.MarkLabel(lateBoundCall);
            this.TranslateToILDefaultThisObject(il);
            argList.TranslateToIL(il, Typeob.ArrayOfObject);
            if (construct)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            if (brackets)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.callValue2Method);
            il.MarkLabel(done);
            Convert.Emit(this, il, Typeob.Object, rtype);
        }
Exemplo n.º 18
0
        protected override void TranslateToILWithDupOfThisOb(ILGenerator il)
        {
            IReflect ir       = this.rootObject.InferType(null);
            Type     tempType = Convert.ToType(ir);

            this.rootObject.TranslateToIL(il, tempType);
            if (ir == Typeob.Object || ir == Typeob.String || ir is TypedArray || (ir == tempType && Typeob.Array.IsAssignableFrom(tempType)))
            {
                tempType = Typeob.Object;
                this.EmitILToLoadEngine(il);
                il.Emit(OpCodes.Call, CompilerGlobals.toObjectMethod);
            }
            il.Emit(OpCodes.Dup);
            this.temp = il.DeclareLocal(tempType);
            il.Emit(OpCodes.Stloc, temp);
            Convert.Emit(this, il, tempType, Typeob.Object);
            this.TranslateToIL(il, Typeob.Object);
        }
Exemplo n.º 19
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            //This assumes that rtype == Void.class
            Label loop_start = il.DefineLabel();
            Label loop_end   = il.DefineLabel();
            Label body       = il.DefineLabel();

            compilerGlobals.BreakLabelStack.Push(loop_end);
            compilerGlobals.ContinueLabelStack.Push(loop_start);
            if (this.initializer != null)
            {
                this.initializer.TranslateToIL(il, Typeob.Void);
            }
            this.inExpressionContext.EmitLineInfo(il);
            this.collection.TranslateToIL(il, Typeob.Object);
            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.toForInObjectMethod);
            il.Emit(OpCodes.Call, CompilerGlobals.jScriptGetEnumeratorMethod);
            LocalBuilder enumerator = il.DeclareLocal(Typeob.IEnumerator);

            il.Emit(OpCodes.Stloc, enumerator);
            il.Emit(OpCodes.Br, loop_start);
            il.MarkLabel(body);
            this.body.TranslateToIL(il, Typeob.Void);
            il.MarkLabel(loop_start);
            this.context.EmitLineInfo(il);
            il.Emit(OpCodes.Ldloc, enumerator);
            il.Emit(OpCodes.Callvirt, CompilerGlobals.moveNextMethod);
            il.Emit(OpCodes.Brfalse, loop_end);
            il.Emit(OpCodes.Ldloc, enumerator);
            il.Emit(OpCodes.Callvirt, CompilerGlobals.getCurrentMethod);
            Type         vt  = Convert.ToType(this.var.InferType(null));
            LocalBuilder val = il.DeclareLocal(vt);

            Convert.Emit(this, il, Typeob.Object, vt);
            il.Emit(OpCodes.Stloc, val);
            this.var.TranslateToILPreSet(il);
            il.Emit(OpCodes.Ldloc, val);
            this.var.TranslateToILSet(il);
            il.Emit(OpCodes.Br, body);
            il.MarkLabel(loop_end);
            compilerGlobals.BreakLabelStack.Pop();
            compilerGlobals.ContinueLabelStack.Pop();
        }
Exemplo n.º 20
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            if (this.context.document.debugOn)
            {
                il.Emit(OpCodes.Nop);
            }
            ASTList astList = this.operand;
            int     n       = astList.count;

            for (int i = 0; i < n; i++)
            {
                AST      ast = astList[i];
                IReflect ir  = ast.InferType(null);
                if (ir == Typeob.String)
                {
                    ast.TranslateToIL(il, Typeob.String);
                }
                else
                {
                    ast.TranslateToIL(il, Typeob.Object);
                    ConstantWrapper.TranslateToILInt(il, 1);
                    il.Emit(OpCodes.Call, CompilerGlobals.toStringMethod);
                }
                if (i == n - 1)
                {
                    il.Emit(OpCodes.Call, CompilerGlobals.writeLineMethod);
                }
                else
                {
                    il.Emit(OpCodes.Call, CompilerGlobals.writeMethod);
                }
            }
            if (n == 0)
            {
                il.Emit(OpCodes.Ldstr, "");
                il.Emit(OpCodes.Call, CompilerGlobals.writeLineMethod);
            }
            if (rtype != Typeob.Void)
            {
                il.Emit(OpCodes.Ldsfld, CompilerGlobals.undefinedField);
                Convert.Emit(this, il, Typeob.Object, rtype);
            }
        }
Exemplo n.º 21
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            Type lhtype = Convert.ToType(this.lhside.InferType(null));

            this.lhside.TranslateToILPreSet(il);
            if (rtype != Typeob.Void)
            {
                Type rhtype = Convert.ToType(this.rhside.InferType(null));
                this.rhside.TranslateToIL(il, rhtype);
                LocalBuilder result = il.DeclareLocal(rhtype);
                il.Emit(OpCodes.Dup);
                il.Emit(OpCodes.Stloc, result);
                Convert.Emit(this, il, rhtype, lhtype);
                this.lhside.TranslateToILSet(il);
                il.Emit(OpCodes.Ldloc, result);
                Convert.Emit(this, il, rhtype, rtype);
            }
            else
            {
                this.lhside.TranslateToILSet(il, rhside);
            }
        }
Exemplo n.º 22
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            if (this.enclosingFunctionScope != null && this.enclosingFunctionScope.owner != null)
            {
                this.enclosingFunctionScope.owner.TranslateToILToSaveLocals(il);
            }
            this.operand.TranslateToIL(il, Typeob.Object);
            MethodInfo      evaluateMethod = null;
            ConstantWrapper cw             = this.unsafeOption as ConstantWrapper;

            if (cw != null)
            {
                string s = cw.value as string;
                if (s != null && s == "unsafe")
                {
                    evaluateMethod = CompilerGlobals.jScriptEvaluateMethod1;
                }
            }
            if (evaluateMethod == null)
            {
                evaluateMethod = CompilerGlobals.jScriptEvaluateMethod2;
                if (this.unsafeOption == null)
                {
                    il.Emit(OpCodes.Ldnull);
                }
                else
                {
                    this.unsafeOption.TranslateToIL(il, Typeob.Object);
                }
            }
            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, evaluateMethod);
            Convert.Emit(this, il, Typeob.Object, rtype);
            if (this.enclosingFunctionScope != null && this.enclosingFunctionScope.owner != null)
            {
                this.enclosingFunctionScope.owner.TranslateToILToRestoreLocals(il);
            }
        }
Exemplo n.º 23
0
        internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets)
        {
            if (this.defaultMember != null && construct && brackets)
            {
                base.TranslateToILCall(il, rtype, argList, construct, brackets);
                return;
            }
            JSGlobalField gf = this.member as JSGlobalField;

            if (gf != null && gf.IsLiteral && argList.count == 1)
            {
                Type t = Convert.ToType((IReflect)gf.value);
                argList[0].TranslateToIL(il, t);
                Convert.Emit(this, il, t, rtype);
                return;
            }
            this.TranslateToILWithDupOfThisOb(il);
            argList.TranslateToIL(il, typeof(Object[]));
            if (construct)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            if (brackets)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.callValueMethod);
            Convert.Emit(this, il, Typeob.Object, rtype);
        }
Exemplo n.º 24
0
 protected override void TranslateToILObject(ILGenerator il, Type obType, bool noValue)
 {
     if (noValue && obType.IsValueType && obType != Typeob.Enum)
     {
         if (this.temp == null)
         {
             this.rootObject.TranslateToILReference(il, obType);
         }
         else
         {
             Type tempType = Convert.ToType(this.rootObject.InferType(null));
             if (tempType == obType)
             {
                 il.Emit(OpCodes.Ldloca, this.temp);
             }
             else
             {
                 il.Emit(OpCodes.Ldloc, this.temp);
                 Convert.Emit(this, il, tempType, obType);
                 Convert.EmitLdloca(il, obType);
             }
         }
     }
     else
     {
         if (this.temp == null || this.rootObject is ThisLiteral)
         {
             this.rootObject.TranslateToIL(il, obType);
         }
         else
         {
             il.Emit(OpCodes.Ldloc, this.temp);
             Type tempType = Convert.ToType(this.rootObject.InferType(null));
             Convert.Emit(this, il, tempType, obType);
         }
     }
 }
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            if (rtype == Typeob.Array)
            {
                this.TranslateToILArray(il, Typeob.Object);
                return;
            }
            if (rtype.IsArray && rtype.GetArrayRank() == 1)
            {
                this.TranslateToILArray(il, rtype.GetElementType());
                return;
            }
            int        n = this.elements.count;
            MethodInfo constructorMethod = null;

            if (this.Engine.Globals.globalObject is LenientGlobalObject)
            {
                this.EmitILToLoadEngine(il);
                il.Emit(OpCodes.Call, CompilerGlobals.getOriginalArrayConstructorMethod);
                constructorMethod = CompilerGlobals.constructArrayMethod;
            }
            else
            {
                constructorMethod = CompilerGlobals.fastConstructArrayLiteralMethod;
            }
            ConstantWrapper.TranslateToILInt(il, n);
            il.Emit(OpCodes.Newarr, Typeob.Object);
            for (int i = 0; i < n; i++)
            {
                il.Emit(OpCodes.Dup);
                ConstantWrapper.TranslateToILInt(il, i);
                this.elements[i].TranslateToIL(il, Typeob.Object);
                il.Emit(OpCodes.Stelem_Ref);
            }
            il.Emit(OpCodes.Call, constructorMethod);
            Convert.Emit(this, il, Typeob.ArrayObject, rtype);
        }
Exemplo n.º 26
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            this.operand1.TranslateToIL(il, Typeob.Object);
            Object val = null;

            if (this.operand2 is ConstantWrapper && (val = this.operand2.Evaluate()) is Type && !((Type)val).IsValueType)
            {
                il.Emit(OpCodes.Isinst, (Type)val);
                il.Emit(OpCodes.Ldnull);
                il.Emit(OpCodes.Cgt_Un);
            }
            else if (val is ClassScope)
            {
                il.Emit(OpCodes.Isinst, ((ClassScope)val).GetTypeBuilderOrEnumBuilder());
                il.Emit(OpCodes.Ldnull);
                il.Emit(OpCodes.Cgt_Un);
            }
            else
            {
                this.operand2.TranslateToIL(il, Typeob.Object);
                il.Emit(OpCodes.Call, CompilerGlobals.jScriptInstanceofMethod);
            }
            Convert.Emit(this, il, Typeob.Boolean, rtype);
        }
Exemplo n.º 27
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            if (this.isFullyResolved)
            {
                base.TranslateToIL(il, rtype);
                return;
            }
            //Need to do a dynamic lookup to see if there is a dynamically introduced (by eval or with) hiding definition.
            Label done = il.DefineLabel();

            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
            il.Emit(OpCodes.Castclass, Typeob.IActivationObject);
            il.Emit(OpCodes.Ldstr, this.name);
            ConstantWrapper.TranslateToILInt(il, this.lexLevel);
            il.Emit(OpCodes.Callvirt, CompilerGlobals.getMemberValueMethod);
            il.Emit(OpCodes.Dup);
            il.Emit(OpCodes.Call, CompilerGlobals.isMissingMethod);
            il.Emit(OpCodes.Brfalse, done); //dynamic lookup succeeded, do not use the value from the early bound location.
            il.Emit(OpCodes.Pop);           //The dynamic lookup returned Missing.Value, discard it and go on to use the value from the early bound location.
            base.TranslateToIL(il, Typeob.Object);
            il.MarkLabel(done);
            Convert.Emit(this, il, Typeob.Object, rtype);
        }
Exemplo n.º 28
0
 internal override void TranslateToIL(ILGenerator il, Type rtype)
 {
     //This is executed every time the function expression is executed and constructs a new closure for every execution.
     if (rtype == Typeob.Void)
     {
         return;
     }
     il.Emit(OpCodes.Ldloc, this.func_local);
     il.Emit(OpCodes.Newobj, CompilerGlobals.closureConstructor);
     Convert.Emit(this, il, Typeob.Closure, rtype);
     if (this.field != null)
     {
         il.Emit(OpCodes.Dup);
         Object tok = this.field.GetMetaData();
         if (tok is LocalBuilder)
         {
             il.Emit(OpCodes.Stloc, (LocalBuilder)tok);
         }
         else
         {
             il.Emit(OpCodes.Stsfld, (FieldInfo)tok);
         }
     }
 }
Exemplo n.º 29
0
        private void TranslateToILForNoOverloadCase(ILGenerator il, Type rtype)
        {
            Type lhtype = Convert.ToType(this.operand1.InferType(null));
            Type rhtype = Convert.ToType(this.operand2.InferType(null));
            Type rt     = Typeob.Object;

            if (lhtype == Typeob.String || rhtype == Typeob.String)
            {
                rt = Typeob.String;
            }
            else if (rtype == Typeob.Void || rtype == lhtype || Convert.IsPrimitiveNumericType(lhtype) &&
                     (Convert.IsPromotableTo(rhtype, lhtype) || ((this.operand2 is ConstantWrapper) && ((ConstantWrapper)this.operand2).IsAssignableTo(lhtype))))
            {
                rt = lhtype;
            }
            if (rt == Typeob.SByte || rt == Typeob.Int16)
            {
                rt = Typeob.Int32;
            }
            else if (rt == Typeob.Byte || rt == Typeob.UInt16)
            {
                rt = Typeob.UInt32;
            }

            // If we have "unsigned += signed" or "signed += unsigned" then generating the
            // correct code gets quite complicated.  Just go late-bound for this edge case.
            if (this.operand2 is ConstantWrapper)
            {
                if (!((ConstantWrapper)this.operand2).IsAssignableTo(rt))
                {
                    // eg: "var u : byte = 123; u += -100;" should go late bound because
                    // of signed/unsigned mismatch but "u += 1" should not.
                    rt = Typeob.Object;
                }
            }
            else
            {
                if ((Convert.IsPrimitiveSignedNumericType(rhtype) && Convert.IsPrimitiveUnsignedIntegerType(lhtype)) ||
                    (Convert.IsPrimitiveUnsignedIntegerType(rhtype) && Convert.IsPrimitiveSignedIntegerType(lhtype)))
                {
                    rt = Typeob.Object;
                }
            }

            this.operand1.TranslateToILPreSetPlusGet(il);
            Convert.Emit(this, il, lhtype, rt);
            this.operand2.TranslateToIL(il, rt);
            if (rt == Typeob.Object || rt == Typeob.String)
            {
                il.Emit(OpCodes.Call, CompilerGlobals.plusDoOpMethod);
                rt = Typeob.Object;
            }
            else if (rt == Typeob.Double || rt == Typeob.Single)
            {
                il.Emit(OpCodes.Add);
            }
            else if (rt == Typeob.Int32 || rt == Typeob.Int64 || rt == Typeob.Int16 || rt == Typeob.SByte)
            {
                il.Emit(OpCodes.Add_Ovf);
            }
            else
            {
                il.Emit(OpCodes.Add_Ovf_Un);
            }
            if (rtype != Typeob.Void)
            {
                LocalBuilder result = il.DeclareLocal(rt);
                il.Emit(OpCodes.Dup);
                il.Emit(OpCodes.Stloc, result);
                Convert.Emit(this, il, rt, lhtype);
                this.operand1.TranslateToILSet(il);
                il.Emit(OpCodes.Ldloc, result);
                Convert.Emit(this, il, rt, rtype);
            }
            else
            {
                Convert.Emit(this, il, rt, lhtype);
                this.operand1.TranslateToILSet(il);
            }
        }
Exemplo n.º 30
0
        internal void TranslateToILSet(ILGenerator il, bool doBoth, AST rhvalue)
        {
            if (this.isFullyResolved)
            {
                base.TranslateToILSet(il, rhvalue);
                return;
            }
            if (rhvalue != null)
            {
                rhvalue.TranslateToIL(il, Typeob.Object);
            }
            if (this.fieldLoc == null)
            {
                //There is a callable value plus parameters on the stack
                il.Emit(OpCodes.Call, CompilerGlobals.setIndexedPropertyValueStaticMethod);
                return;
            }
            LocalBuilder temp = il.DeclareLocal(Typeob.Object);

            if (doBoth)
            {
                //save copy of rh value
                il.Emit(OpCodes.Dup);
                il.Emit(OpCodes.Stloc, temp);
                //store it in early bound location
                this.isFullyResolved = true;
                Convert.Emit(this, il, Typeob.Object, Convert.ToType(this.InferType(null)));
                base.TranslateToILSet(il, null);
            }
            //See if there is a late bound field
            Label earlyBound = il.DefineLabel();

            il.Emit(OpCodes.Ldloc, this.fieldLoc);
            il.Emit(OpCodes.Ldnull);
            il.Emit(OpCodes.Beq_S, earlyBound); //No late bound field

            //store it in the late bound field
            Label done = il.DefineLabel();

            if (!doBoth)
            {
                il.Emit(OpCodes.Stloc, temp);
                if (this.thereIsAnObjectOnTheStack)
                {
                    il.Emit(OpCodes.Pop);
                }
            }
            il.Emit(OpCodes.Ldloc, this.fieldLoc);
            il.Emit(OpCodes.Ldnull);
            il.Emit(OpCodes.Ldloc, temp);
            il.Emit(OpCodes.Callvirt, CompilerGlobals.setFieldValueMethod);
            il.Emit(OpCodes.Br_S, done);

            //Alternative store it in the early bound location
            il.MarkLabel(earlyBound);
            if (!doBoth)
            {
                this.isFullyResolved = true;
                Convert.Emit(this, il, Typeob.Object, Convert.ToType(this.InferType(null)));
                base.TranslateToILSet(il, null);
            }
            il.MarkLabel(done);
        }