TranslateToIL() abstract private method

abstract private TranslateToIL ( ILGenerator il, Type rtype ) : void
il ILGenerator
rtype Type
return void
Beispiel #1
0
 internal void TranslateToILStaticInitializers(ILGenerator il)
 {
     for (int i = 0, n = this.list.Count; i < n; i++)
     {
         AST elem = (AST)(this.list[i]);
         if (elem is VariableDeclaration && ((VariableDeclaration)elem).field.IsStatic ||
             elem is Constant && ((Constant)elem).field.IsStatic)
         {
             elem.TranslateToILInitializer(il);
             elem.TranslateToIL(il, Typeob.Void);
         }
         else if (elem is StaticInitializer)
         {
             elem.TranslateToIL(il, Typeob.Void);
         }
         else if (elem is FunctionDeclaration && ((FunctionDeclaration)elem).func.isStatic)
         {
             elem.TranslateToILInitializer(il);
         }
         else if (elem is Class)
         {
             elem.TranslateToIL(il, Typeob.Void);
         }
         else if (elem is Block)
         {
             ((Block)elem).TranslateToILStaticInitializers(il);
         }
     }
 }
        internal void TranslateToILStaticInitializers(ILGenerator il)
        {
            int num   = 0;
            int count = this.list.Count;

            while (num < count)
            {
                AST ast = (AST)this.list[num];
                if (((ast is VariableDeclaration) && ((VariableDeclaration)ast).field.IsStatic) || ((ast is Constant) && ((Constant)ast).field.IsStatic))
                {
                    ast.TranslateToILInitializer(il);
                    ast.TranslateToIL(il, Typeob.Void);
                }
                else if (ast is StaticInitializer)
                {
                    ast.TranslateToIL(il, Typeob.Void);
                }
                else if ((ast is FunctionDeclaration) && ((FunctionDeclaration)ast).func.isStatic)
                {
                    ast.TranslateToILInitializer(il);
                }
                else if (ast is Class)
                {
                    ast.TranslateToIL(il, Typeob.Void);
                }
                else if (ast is Block)
                {
                    ((Block)ast).TranslateToILStaticInitializers(il);
                }
                num++;
            }
        }
        internal override void TranslateToILSet(ILGenerator il, AST rhvalue)
        {
            MethodInfo method = this.method;

            if (method != null)
            {
                if (rhvalue != null)
                {
                    rhvalue.TranslateToIL(il, method.GetParameters()[0].ParameterType);
                }
                Type reflectedType = method.ReflectedType;
                if ((method.IsVirtual && !method.IsFinal) && (!reflectedType.IsSealed || !reflectedType.IsValueType))
                {
                    il.Emit(OpCodes.Callvirt, method);
                }
                else
                {
                    il.Emit(OpCodes.Call, method);
                }
                if (method.ReturnType != Typeob.Void)
                {
                    il.Emit(OpCodes.Pop);
                }
            }
            else
            {
                base.TranslateToILSet(il, rhvalue);
            }
        }
Beispiel #4
0
        internal override void TranslateToILSet(ILGenerator il, AST rhvalue)
        {
            MethodInfo meth = this.method;

            if (meth != null)
            {
                if (rhvalue != null)
                {
                    rhvalue.TranslateToIL(il, meth.GetParameters()[0].ParameterType);
                }
                Type t = meth.ReflectedType;
                if (meth.IsVirtual && !meth.IsFinal && !t.IsSealed)
                {
                    il.Emit(OpCodes.Callvirt, meth);
                }
                else
                {
                    il.Emit(OpCodes.Call, meth);
                }
                if (meth.ReturnType != Typeob.Void) //Should never be the case if the property is well formed, but there is no gaurantee
                {
                    il.Emit(OpCodes.Pop);
                }
            }
            else
            {
                base.TranslateToILSet(il, rhvalue);
            }
        }
Beispiel #5
0
 internal virtual void TranslateToILSet(ILGenerator il, AST rhvalue)
 {
     if (rhvalue != null)
     {
         rhvalue.TranslateToIL(il, Typeob.Object);
     }
     il.Emit(OpCodes.Call, CompilerGlobals.setIndexedPropertyValueStaticMethod);
 }
 internal void TranslateToILSet(ILGenerator il, bool doBoth, AST rhvalue)
 {
     if (base.isFullyResolved)
     {
         base.TranslateToILSet(il, rhvalue);
     }
     else
     {
         if (rhvalue != null)
         {
             rhvalue.TranslateToIL(il, Typeob.Object);
         }
         if (this.fieldLoc == null)
         {
             il.Emit(OpCodes.Call, CompilerGlobals.setIndexedPropertyValueStaticMethod);
         }
         else
         {
             LocalBuilder local = il.DeclareLocal(Typeob.Object);
             if (doBoth)
             {
                 il.Emit(OpCodes.Dup);
                 il.Emit(OpCodes.Stloc, local);
                 base.isFullyResolved = true;
                 Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, Microsoft.JScript.Convert.ToType(this.InferType(null)));
                 base.TranslateToILSet(il, null);
             }
             Label label = il.DefineLabel();
             il.Emit(OpCodes.Ldloc, this.fieldLoc);
             il.Emit(OpCodes.Ldnull);
             il.Emit(OpCodes.Beq_S, label);
             Label label2 = il.DefineLabel();
             if (!doBoth)
             {
                 il.Emit(OpCodes.Stloc, local);
                 if (this.thereIsAnObjectOnTheStack)
                 {
                     il.Emit(OpCodes.Pop);
                 }
             }
             il.Emit(OpCodes.Ldloc, this.fieldLoc);
             il.Emit(OpCodes.Ldnull);
             il.Emit(OpCodes.Ldloc, local);
             il.Emit(OpCodes.Callvirt, CompilerGlobals.setFieldValueMethod);
             il.Emit(OpCodes.Br_S, label2);
             il.MarkLabel(label);
             if (!doBoth)
             {
                 base.isFullyResolved = true;
                 Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, Microsoft.JScript.Convert.ToType(this.InferType(null)));
                 base.TranslateToILSet(il, null);
             }
             il.MarkLabel(label2);
         }
     }
 }
Beispiel #7
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);
            }
        }
Beispiel #8
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            if (base.context.document.debugOn)
            {
                il.Emit(OpCodes.Nop);
            }
            ASTList operand = this.operand;
            int     count   = operand.count;

            for (int i = 0; i < count; i++)
            {
                AST ast = operand[i];
                if (ast.InferType(null) == 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 == (count - 1))
                {
                    il.Emit(OpCodes.Call, CompilerGlobals.writeLineMethod);
                }
                else
                {
                    il.Emit(OpCodes.Call, CompilerGlobals.writeMethod);
                }
            }
            if (count == 0)
            {
                il.Emit(OpCodes.Ldstr, "");
                il.Emit(OpCodes.Call, CompilerGlobals.writeLineMethod);
            }
            if (rtype != Typeob.Void)
            {
                il.Emit(OpCodes.Ldsfld, CompilerGlobals.undefinedField);
                Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, rtype);
            }
        }
Beispiel #9
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            //This assumes that rtype == Void.class
            Label lab = il.DefineLabel();

            compilerGlobals.BreakLabelStack.Push(lab);
            compilerGlobals.ContinueLabelStack.Push(lab);
            for (int i = 0, n = this.list.Count; i < n; i++)
            {
                AST elem = (AST)(this.list[i]);
                elem.TranslateToIL(il, Typeob.Void);
            }
            il.MarkLabel(lab);
            compilerGlobals.BreakLabelStack.Pop();
            compilerGlobals.ContinueLabelStack.Pop();
        }
        private static void TranslateToStringWithSpecialCaseForNull(ILGenerator il, AST operand)
        {
            ConstantWrapper cw = operand as ConstantWrapper;

            if (cw != null)
            {
                if (cw.value is DBNull)
                {
                    il.Emit(OpCodes.Ldstr, "null");
                }
                else if (cw.value == Empty.Value)
                {
                    il.Emit(OpCodes.Ldstr, "undefined");
                }
                else
                {
                    cw.TranslateToIL(il, Typeob.String);
                }
            }
            else
            {
                operand.TranslateToIL(il, Typeob.String);
            }
        }
Beispiel #11
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);
        }
Beispiel #12
0
 internal override void TranslateToILSet(ILGenerator il, AST rhvalue){
   if (this.isArrayElementAccess){
     IReflect defIR = this.defaultMemberReturnIR;
     Type defType = defIR is Type ? (Type)defIR : Convert.ToType(defIR);
     Debug.Assert(defType.IsArray);
     int n = defType.GetArrayRank();
     Type etype = defType.GetElementType();
     if (rhvalue != null)
       rhvalue.TranslateToIL(il, etype);
     if (n == 1){
       Binding.TranslateToStelem(il, etype);
     }else{
       Type[] indexTypes = new Type[n+1];
       for (int i = 0; i < n; i++) indexTypes[i] = Typeob.Int32;
       indexTypes[n] = etype;
       MethodInfo setter = defType.GetMethod("Set", indexTypes);
       il.Emit(OpCodes.Call, setter);
     }
     return;
   }
   if (this.isAssignmentToDefaultIndexedProperty){
     if (this.member is PropertyInfo && this.defaultMember != null){ //early bound to default indexed property
       PropertyInfo prop = (PropertyInfo)this.member;
       MethodInfo meth = JSProperty.GetSetMethod(prop, false);
       //Guard against trying to assign to properties on the Global object
       JSWrappedMethod wmeth = meth as JSWrappedMethod;
       if (wmeth == null || !(wmeth.GetWrappedObject() is GlobalObject)){
         if (meth is JSMethod)
           meth = ((JSMethod)meth).GetMethodInfo(compilerGlobals);
         else if (meth is JSMethodInfo)
           meth = ((JSMethodInfo)meth).method;
         if (rhvalue != null)
           rhvalue.TranslateToIL(il, prop.PropertyType);
         if (meth.IsVirtual && !meth.IsFinal && !meth.ReflectedType.IsSealed)
           il.Emit(OpCodes.Callvirt, meth);
         else
           il.Emit(OpCodes.Call, meth);
         return;
       }
     }
     base.TranslateToILSet(il, rhvalue);
     return;
   }
   if (this.member is FieldInfo){
     FieldInfo field = (FieldInfo)this.member;
     if (rhvalue != null)
       rhvalue.TranslateToIL(il, field.FieldType);
     if (field.IsLiteral || field.IsInitOnly){
       il.Emit(OpCodes.Pop);
       return;
     }
     Object tok = field is JSField ? ((JSField)field).GetMetaData() : field is JSFieldInfo ? ((JSFieldInfo)field).field : field;
     FieldInfo f = tok as FieldInfo;
     if (f != null)
       il.Emit(f.IsStatic ? OpCodes.Stsfld : OpCodes.Stfld, f);
     else if (tok is LocalBuilder)
       il.Emit(OpCodes.Stloc, (LocalBuilder)tok);
     else
       il.Emit(OpCodes.Starg, (short)tok);
     return;
   }
   if (this.member is PropertyInfo){
     PropertyInfo prop = (PropertyInfo)this.member;
     if (rhvalue != null)
       rhvalue.TranslateToIL(il, prop.PropertyType);
     MethodInfo meth = JSProperty.GetSetMethod(prop, true);
     if (meth == null){
       il.Emit(OpCodes.Pop);
       return;
     }
     if (meth is JSMethod)
       meth = ((JSMethod)meth).GetMethodInfo(compilerGlobals);
     else if (meth is JSMethodInfo)
       meth = ((JSMethodInfo)meth).method;
     if (meth.IsStatic && !(meth is JSClosureMethod))
       il.Emit(OpCodes.Call, meth);
     else{
       if (!this.isNonVirtual && meth.IsVirtual && !meth.IsFinal && !meth.ReflectedType.IsSealed)
         il.Emit(OpCodes.Callvirt, meth);
       else
         il.Emit(OpCodes.Call, meth);
     }
     return;
   }
   //do speculative early bound assignments
   Object done = this.TranslateToSpeculativeEarlyBoundSet(il, rhvalue);
   if (rhvalue != null)
     rhvalue.TranslateToIL(il, Typeob.Object);
   il.Emit(OpCodes.Call, CompilerGlobals.setValueMethod);
   if (done != null)
     il.MarkLabel((Label)done);
 }
 internal override void TranslateToILSet(ILGenerator il, AST rhvalue)
 {
     MethodInfo method = this.method;
     if (method != null)
     {
         if (rhvalue != null)
         {
             rhvalue.TranslateToIL(il, method.GetParameters()[0].ParameterType);
         }
         Type reflectedType = method.ReflectedType;
         if ((method.IsVirtual && !method.IsFinal) && (!reflectedType.IsSealed || !reflectedType.IsValueType))
         {
             il.Emit(OpCodes.Callvirt, method);
         }
         else
         {
             il.Emit(OpCodes.Call, method);
         }
         if (method.ReturnType != Typeob.Void)
         {
             il.Emit(OpCodes.Pop);
         }
     }
     else
     {
         base.TranslateToILSet(il, rhvalue);
     }
 }
Beispiel #14
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);
      }
Beispiel #15
0
 private static void TranslateToStringWithSpecialCaseForNull(ILGenerator il, AST operand){
   ConstantWrapper cw = operand as ConstantWrapper;
   if (cw != null){
     if (cw.value is DBNull)
       il.Emit(OpCodes.Ldstr, "null");
     else if (cw.value == Empty.Value)
       il.Emit(OpCodes.Ldstr, "undefined");
     else
       cw.TranslateToIL(il, Typeob.String);
   }else
     operand.TranslateToIL(il, Typeob.String);
 }
Beispiel #16
0
 private Object TranslateToSpeculativeEarlyBoundSet(ILGenerator il, AST rhvalue){
   this.giveErrors = false;
   Object done = null;
   bool needObject = true;
   LocalBuilder objectLocal = null;
   LocalBuilder valueLocal = null;
   Label next = il.DefineLabel();
   MemberInfoList members = this.GetAllKnownInstanceBindingsForThisName();
   for (int i = 0, n = members.count; i < n; i++){
     MemberInfo member = members[i];
     FieldInfo field = null;
     MethodInfo setter = null;
     PropertyInfo prop = null;
     if (member is FieldInfo){
       field = (FieldInfo)member;
       if (field.IsLiteral || field.IsInitOnly) continue;
     }else if (member is PropertyInfo){
       prop = (PropertyInfo)member;
       if (prop.GetIndexParameters().Length > 0 ||
           (setter = JSProperty.GetSetMethod(prop, true)) == null) continue;
     }else
       continue;
     this.member = member;
     if (!this.Accessible(true)) continue;
     if (needObject){
       needObject = false;
       if (rhvalue == null){
         valueLocal = il.DeclareLocal(Typeob.Object);
         il.Emit(OpCodes.Stloc, valueLocal);
       }
       il.Emit(OpCodes.Dup);
       il.Emit(OpCodes.Ldfld, CompilerGlobals.objectField);
       objectLocal = il.DeclareLocal(Typeob.Object);
       il.Emit(OpCodes.Stloc, objectLocal);
       done = il.DefineLabel();
     }
     Type t = member.DeclaringType;
     il.Emit(OpCodes.Ldloc, objectLocal);
     il.Emit(OpCodes.Isinst, t);
     LocalBuilder objectTemp = il.DeclareLocal(t);
     il.Emit(OpCodes.Dup);
     il.Emit(OpCodes.Stloc, objectTemp);
     il.Emit(OpCodes.Brfalse, next);
     il.Emit(OpCodes.Ldloc, objectTemp);
     if (rhvalue == null)
       il.Emit(OpCodes.Ldloc, valueLocal);
     if (field != null){
       if (rhvalue == null)
         Convert.Emit(this, il, Typeob.Object, field.FieldType);
       else
         rhvalue.TranslateToIL(il, field.FieldType);
       if (field is JSField)
         il.Emit(OpCodes.Stfld, (FieldInfo)((JSField)field).GetMetaData());
       else if (field is JSFieldInfo)
         il.Emit(OpCodes.Stfld, ((JSFieldInfo)field).field);
       else
         il.Emit(OpCodes.Stfld, field);
     }else{
       if (rhvalue == null)
         Convert.Emit(this, il, Typeob.Object, prop.PropertyType);
       else
         rhvalue.TranslateToIL(il, prop.PropertyType);
       if (setter is JSMethod)
         setter = ((JSMethod)setter).GetMethodInfo(this.compilerGlobals);
       else if (setter is JSMethodInfo)
         setter = ((JSMethodInfo)setter).method;
       if (setter.IsVirtual && !setter.IsFinal && !t.IsSealed)
         il.Emit(OpCodes.Callvirt, setter);
       else
         il.Emit(OpCodes.Call, setter);
     }
     il.Emit(OpCodes.Pop); //Get rid of the LateBound instance
     il.Emit(OpCodes.Br, (Label)done);
     il.MarkLabel(next);
     next = il.DefineLabel();
   }
   if (valueLocal != null)
     il.Emit(OpCodes.Ldloc, valueLocal);
   this.member = null;
   return done;
 }
Beispiel #17
0
 internal static void PlaceArgumentsOnStack(ILGenerator il, ParameterInfo[] pars, ASTList args, int offset, int rhoffset, AST missing){
   int k = args.count;
   int n = k+offset;
   int m = pars.Length-rhoffset;
   bool varargs = m > 0 && pars[m-1].IsDefined(Typeob.ParamArrayAttribute, false) && 
    !(k == m && Convert.IsArrayType(args[k-1].InferType(null)));
   Type varargElemType = varargs ? pars[--m].ParameterType.GetElementType() : null;
   if (n > m) n = m;
   for (int i = offset; i < n; i++){
     Type ptype = pars[i].ParameterType;
     AST arg = args[i-offset];
     if (arg is ConstantWrapper && ((ConstantWrapper)arg).value == System.Reflection.Missing.Value){
       Object defVal = pars[i].DefaultValue;
       ((ConstantWrapper)arg).value =  defVal != System.Convert.DBNull ? defVal : null;
     }
     if (ptype.IsByRef)
       arg.TranslateToILReference(il, ptype.GetElementType());
     else
       arg.TranslateToIL(il, ptype);
   }
   if (n < m){
     for (int i = n; i < m; i++){
       Type ptype = pars[i].ParameterType;
       if (pars[i].DefaultValue == System.Convert.DBNull) //No default value was specified
         if (ptype.IsByRef)
           missing.TranslateToILReference(il, ptype.GetElementType());
         else
           missing.TranslateToIL(il, ptype); 
       else
         if (ptype.IsByRef)
           (new ConstantWrapper(pars[i].DefaultValue, null)).TranslateToILReference(il, ptype.GetElementType());
         else
           (new ConstantWrapper(pars[i].DefaultValue, null)).TranslateToIL(il, ptype);
     }
   }
   if (varargs){
     n -= offset; //The number of arguments in argList that are already on the stack
     m = k>n ? k-n : 0; //The number of arguments in argList that are to be placed in the vararg array
     ConstantWrapper.TranslateToILInt(il, m);
     il.Emit(OpCodes.Newarr, varargElemType);
     bool doLdelema = varargElemType.IsValueType && !varargElemType.IsPrimitive;
     for (int i = 0; i < m; i++){
       il.Emit(OpCodes.Dup);
       ConstantWrapper.TranslateToILInt(il, i);
       if (doLdelema)
         il.Emit(OpCodes.Ldelema, varargElemType);
       args[i+n].TranslateToIL(il, varargElemType);
       Binding.TranslateToStelem(il, varargElemType);
     }
   }
 }
 private static void TranslateToStringWithSpecialCaseForNull(ILGenerator il, AST operand)
 {
     ConstantWrapper wrapper = operand as ConstantWrapper;
     if (wrapper != null)
     {
         if (wrapper.value is DBNull)
         {
             il.Emit(OpCodes.Ldstr, "null");
         }
         else if (wrapper.value == Microsoft.JScript.Empty.Value)
         {
             il.Emit(OpCodes.Ldstr, "undefined");
         }
         else
         {
             wrapper.TranslateToIL(il, Typeob.String);
         }
     }
     else
     {
         operand.TranslateToIL(il, Typeob.String);
     }
 }
 internal virtual void TranslateToILSet(ILGenerator il, AST rhvalue)
 {
     if (rhvalue != null)
     {
         rhvalue.TranslateToIL(il, Typeob.Object);
     }
     il.Emit(OpCodes.Call, CompilerGlobals.setIndexedPropertyValueStaticMethod);
 }
Beispiel #20
0
 internal override void TranslateToILSet(ILGenerator il, AST rhvalue){
   MethodInfo meth = this.method;
   if (meth != null){
     if (rhvalue != null)
       rhvalue.TranslateToIL(il, meth.GetParameters()[0].ParameterType);
     Type t = meth.ReflectedType;
     if (meth.IsVirtual && !meth.IsFinal && !t.IsSealed)
       il.Emit(OpCodes.Callvirt, meth);
     else
       il.Emit(OpCodes.Call, meth);
     if (meth.ReturnType != Typeob.Void) //Should never be the case if the property is well formed, but there is no gaurantee
       il.Emit(OpCodes.Pop);
   }else
     base.TranslateToILSet(il, rhvalue);
 }