当前位置: 首页>>代码示例>>C#>>正文


C# AST.TranslateToIL方法代码示例

本文整理汇总了C#中Microsoft.JScript.AST.TranslateToIL方法的典型用法代码示例。如果您正苦于以下问题:C# AST.TranslateToIL方法的具体用法?C# AST.TranslateToIL怎么用?C# AST.TranslateToIL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.JScript.AST的用法示例。


在下文中一共展示了AST.TranslateToIL方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TranslateToILSet

      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);
      }
开发者ID:ArildF,项目名称:masters,代码行数:50,代码来源:lookup.cs

示例2: TranslateToILSet

 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);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:28,代码来源:ThisLiteral.cs

示例3: TranslateToILSet

 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);
 }     
开发者ID:ArildF,项目名称:masters,代码行数:15,代码来源:thisliteral.cs

示例4: TranslateToStringWithSpecialCaseForNull

 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);
 }
开发者ID:ArildF,项目名称:masters,代码行数:12,代码来源:plus.cs

示例5: TranslateToILSet

 internal virtual void TranslateToILSet(ILGenerator il, AST rhvalue)
 {
     if (rhvalue != null)
     {
         rhvalue.TranslateToIL(il, Typeob.Object);
     }
     il.Emit(OpCodes.Call, CompilerGlobals.setIndexedPropertyValueStaticMethod);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:AST.cs

示例6: PlaceArgumentsOnStack

 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);
     }
   }
 }
开发者ID:ArildF,项目名称:masters,代码行数:51,代码来源:binding.cs

示例7: TranslateToSpeculativeEarlyBoundSet

 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;
 }
开发者ID:ArildF,项目名称:masters,代码行数:81,代码来源:binding.cs

示例8: TranslateToILSet

 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);
 }
开发者ID:ArildF,项目名称:masters,代码行数:92,代码来源:binding.cs

示例9: TranslateToStringWithSpecialCaseForNull

 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);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:23,代码来源:Plus.cs


注:本文中的Microsoft.JScript.AST.TranslateToIL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。