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


C# AstNode.GetExpressions方法代码示例

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


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

示例1: Convert

        /// <summary>
        /// Optimize expressions
        /// </summary>
        public static void Convert(AstNode ast, AssemblyCompiler compiler)
        {
            // Convert IntPtr.Zero
            foreach (var node in ast.GetExpressions(AstCode.Ldsfld))
            {
                var field = (XFieldReference)node.Operand;
                if (field.DeclaringType.IsIntPtr() && (field.Name == "Zero"))
                {
                    node.Code = AstCode.Ldnull;
                    node.Operand = null;
                    node.Arguments.Clear();
                    node.SetType(compiler.Module.TypeSystem.Object);
                }                
            }

            // Convert box(IntPtr)
            foreach (var node in ast.GetExpressions(AstCode.Box))
            {
                var type = (XTypeReference)node.Operand;
                if (type.IsIntPtr())
                {
                    node.CopyFrom(node.Arguments[0]);
                }
            }
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:28,代码来源:IntPtrConverter.cs

示例2: Convert

 /// <summary>
 /// Optimize expressions
 /// </summary>
 public static void Convert(AstNode ast, AssemblyCompiler compiler)
 {
     // Optimize enum2int(ldsfld(enum-const))
     foreach (var node in ast.GetExpressions())
     {
         switch (node.Code)
         {
             case AstCode.Enum_to_int:
             case AstCode.Enum_to_long:
                 {
                     var arg = node.Arguments[0];
                     XFieldReference fieldRef;
                     if (arg.Match(AstCode.Ldsfld, out fieldRef))
                     {
                         XFieldDefinition field;
                         object value;
                         if (fieldRef.TryResolve(out field) && field.IsStatic && field.DeclaringType.IsEnum && field.TryGetEnumValue(out value))
                         {
                             // Replace with ldc_ix
                             var wide = (node.Code == AstCode.Enum_to_long);
                             node.SetCode(wide ? AstCode.Ldc_I8 : AstCode.Ldc_I4);
                             node.Operand = wide ? (object)XConvert.ToLong(value) : XConvert.ToInt(value);
                             node.Arguments.Clear();
                         }
                     }
                 }
                 break;
         }
     }
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:33,代码来源:EnumOptimizer.cs

示例3: Convert

        /// <summary>
        /// Optimize expressions
        /// </summary>
        public static void Convert(AstNode ast)
        {
            foreach (var node in ast.GetExpressions(AstCode.Stloc))
            {
                // Select the nodes to work on
                var ldCode = AstCode.Ldloc;

                var stArg = node.Arguments[0];
                AstCode newCode;
                if ((stArg.Arguments.Count >= 1) && (operatorMap.TryGetValue(stArg.Code, out newCode)))
                {
                    // Found matching operator
                    var ldArg = stArg.Arguments[0];
                    if (ldArg.Code == ldCode)
                    {
                        // Found a matching 'load' opcode.
                        if (ldArg.Operand == node.Operand)
                        {
                            var type = stArg.GetResultType();
                            if (!type.IsEnum())
                            {
                                // Found matching "local" 
                                node.Code = newCode;
                                node.SetArguments(stArg.Arguments.Skip(1));
                                node.SetType(type);
                            }
                        }
                    }
                }
            }
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:34,代码来源:CompoundAssignmentConverter.cs

示例4: Convert

        /// <summary>
        /// Optimize expressions
        /// </summary>
        public static void Convert(AstNode ast)
        {
            foreach (var node in ast.GetExpressions())
            {
                switch (node.Code)
                {
                    case AstCode.ByRefOutArray:
                        node.Arguments.Clear();
                        return;
                    case AstCode.Conv_U2:
                        if (node.GetResultType().IsChar() && node.Arguments[0].Match(AstCode.Int_to_ushort))
                        {
                            // Remove useless conversion (int_to_ushort followed by conv_u2)
                            var value = node.Arguments[0].Arguments[0];

                            if (value.GetResultType().IsChar())
                            {
                                node.CopyFrom(value);
                            }
                            else
                            {
                                // keep the conv_u2 but drop the int_to_ushort.
                                // TODO:maybe there is a better way to do the conversion in one step.
                                // Convert.ToUInt16(char) looks now like this:

                                // .method public static ToUInt16(C)S
                                //    .registers 3
                                //    .param p0    # C

                                //    #v0=(Uninit);p0=(Char);
                                //    int-to-char v0, p0
                                //    #v0=(Char);

                                //    #v1=(Uninit);
                                //    const v1, 0xffff
                                //    #v1=(Char);

                                //    #v0=(Char);v1=(Char);
                                //    and-int/2addr v0, v1
                                //    #v0=(Integer);

                                //    #v0=(Integer);
                                //    return v0
                                //.end method

                                node.Arguments.Clear();
                                node.Arguments.Add(value);
                            }
                        }
                        break;
                }
            }
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:56,代码来源:CleanupConverter.cs

示例5: Convert

 /// <summary>
 /// Optimize expressions
 /// </summary>
 public static void Convert(AstNode ast)
 {
     foreach (var node in ast.GetExpressions())
     {
         if (node.Code == AstCode.Ldloc)
         {
             var variable = (AstVariable) node.Operand;
             var varType = variable.Type;
             var expType = node.ExpectedType;
             if ((expType != null) && (!varType.IsSame(expType)))
             {
                 if (varType.IsByte() && (expType.IsChar() || expType.IsUInt16()))
                 {
                     var ldloc = new AstExpression(node);
                     var code = expType.IsUInt16() ? AstCode.Int_to_ushort : AstCode.Conv_U2;
                     node.CopyFrom(new AstExpression(node.SourceLocation, code, null, ldloc).SetType(expType));
                 } 
             }
         }
         else if (node.Code.IsCall())
         {
             var methodRef = (XMethodReference) node.Operand;
             var returnType = methodRef.ReturnType;
             var expType = node.ExpectedType;
             if ((expType != null) && (!returnType.IsSame(expType)))
             {
                 if (returnType.IsByte() && (expType.IsChar() || expType.IsUInt16()))
                 {
                     var ldloc = new AstExpression(node);
                     var code = expType.IsUInt16() ? AstCode.Int_to_ushort : AstCode.Conv_U2;
                     node.CopyFrom(new AstExpression(node.SourceLocation, code, null, ldloc).SetType(expType));
                 }
                 else if (returnType.IsUInt16() && expType.IsChar())
                 {
                     var ldloc = new AstExpression(node);
                     node.CopyFrom(new AstExpression(node.SourceLocation, AstCode.Conv_U2, null, ldloc).SetType(expType));
                 }
                 else if (returnType.IsChar() && expType.IsUInt16())
                 {
                     var ldloc = new AstExpression(node);
                     node.CopyFrom(new AstExpression(node.SourceLocation, AstCode.Int_to_ushort, null, ldloc).SetType(expType));
                 }
             }
         }
     }
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:49,代码来源:LdLocWithConversionConverter.cs

示例6: Convert

 /// <summary>
 /// Optimize expressions
 /// </summary>
 public static void Convert(AstNode ast, AssemblyCompiler compiler)
 {
     foreach (var node in ast.GetExpressions())
     {
         AstExpression arg1;
         XMethodReference method;
         if (node.Match(AstCode.Call, out method, out arg1) && arg1.Match(AstCode.Ldtoken))
         {
             if ((method.Name == "GetTypeFromHandle") && method.DeclaringType.IsSystemType())
             {
                 node.Code = AstCode.TypeOf;
                 node.Operand = arg1.Operand;
                 node.Arguments.Clear();
                 node.SetType(compiler.Module.TypeSystem.Type);
             }
         }
     }
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:21,代码来源:TypeOfConverter.cs

示例7: Convert

 /// <summary>
 /// Optimize expressions
 /// </summary>
 public static void Convert(AstNode ast)
 {
     foreach (var node in ast.GetExpressions())
     {
         switch (node.Code)
         {
             case AstCode.ByRefOutArray:
                 node.Arguments.Clear();
                 return;
             case AstCode.Conv_U2:
                 if (node.GetResultType().IsChar() && node.Arguments[0].Match(AstCode.Int_to_ushort))
                 {
                     // Remove useless conversion (int_to_ushort followed by conv_u2)
                     var value = node.Arguments[0].Arguments[0];
                     node.CopyFrom(value);
                 }
                 break;
         }
     }
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:23,代码来源:CleanupConverter.cs

示例8: Convert

        /// <summary>
        /// Optimize expressions
        /// </summary>
        public static void Convert(AstNode ast)
        {
            // Optimize brtrue (cxx(int, int)) expressions
            foreach (var node in ast.GetExpressions(x => (x.Code == AstCode.Brtrue) || (x.Code == AstCode.Brfalse)))
            {
                var expr = node.Arguments[0];
                if (expr.Code.IsCompare() && (expr.Arguments.Count == 2))
                {
                    var arg1 = expr.Arguments[0];
                    var arg2 = expr.Arguments[1];

                    if (arg1.IsInt32() && arg2.IsInt32())
                    {
                        // Simplify
                        var code = (node.Code == AstCode.Brtrue) ? expr.Code : expr.Code.Reverse();
                        var newExpr = new AstExpression(expr.SourceLocation, code.ToBranch(), node.Operand, arg1, arg2);
                        node.CopyFrom(newExpr, true);
                    }
                }
            }
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:24,代码来源:BranchOptimizer.cs

示例9: Convert

 /// <summary>
 /// Optimize expressions
 /// </summary>
 public static void Convert(AstNode ast)
 {
     foreach (var node in ast.GetExpressions())
     {
         if ((node.Code == AstCode.Conv_U8) && (node.Arguments[0].Code == AstCode.Ldc_I4))
         {
             var value = node.Arguments[0].Operand;
             node.Code = AstCode.Ldc_I8;
             node.Arguments.Clear();
             node.Operand = XConvert.ToLong(value) & 0xFFFFFFFFL;
         }
         else if ((node.Code == AstCode.Ldc_I4) || (node.Code == AstCode.Ldc_R4))
         {
             var type = node.GetResultType();
             if (type.IsWide())
             {
                 node.Code = (node.Code == AstCode.Ldc_I4) ? AstCode.Ldc_I8 : AstCode.Ldc_R8;
             }
         }
     }
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:24,代码来源:LdcWideConverter.cs

示例10: Convert

 /// <summary>
 /// Optimize expressions
 /// </summary>
 public static void Convert(AstNode ast)
 {
     foreach (var node in ast.GetExpressions(AstCode.Newobj))
     {
         var method = (XMethodReference) node.Operand;
         if (method.Name == ".ctor")
         {
             XTypeDefinition declaringType;
             if (method.DeclaringType.TryResolve(out declaringType) && declaringType.IsDelegate())
             {
                 var ldftn = node.Arguments[1];
                 if ((ldftn.Code == AstCode.Ldftn) || (ldftn.Code == AstCode.Ldvirtftn))
                 {
                     var token = (XMethodReference) ldftn.Operand;
                     node.Code = AstCode.Delegate;
                     node.Operand = Tuple.Create(declaringType, token.GetElementMethod().Resolve());
                     node.Arguments.RemoveAt(1);
                 }
             }
         }
     }
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:25,代码来源:DelegateConverter.cs

示例11: Convert

 /// <summary>
 /// Optimize expressions
 /// </summary>
 public static void Convert(AstNode ast, MethodSource currentMethod, AssemblyCompiler compiler)
 {
     foreach (var node in ast.GetExpressions(x => (x.Code == AstCode.Call) || (x.Code == AstCode.Calli) || (x.Code == AstCode.Callvirt)))
     {
         var method = (XMethodReference)node.Operand;
         XMethodDefinition methodDef;
         if (method.TryResolve(out methodDef) && methodDef.IsConstructor && methodDef.DeclaringType.IsPrimitive && (node.Arguments.Count == 2))
         {
             // primitive.ctor(addressof_primitive, value) -> primitive.cast(value)
             var locVar = node.Arguments[0].Operand;
             node.Arguments.RemoveAt(0);
             node.SetCode(AstCode.Stloc).SetType(node.Arguments[0].GetResultType()).Operand = locVar;
         }
         else
         {
             for (var i = 0; i < node.Arguments.Count; i++)
             {
                 ProcessArgument(node, method, i, currentMethod, compiler.Module);
             }
         }
     }
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:25,代码来源:PrimitiveAddressOfConverter.cs

示例12: Convert

 /// <summary>
 /// Optimize expressions
 /// </summary>
 public static void Convert(AstNode ast)
 {
     foreach (var node in ast.GetExpressions())
     {
         switch (node.Code)
         {
             case AstCode.Stloc:
                 {
                     var variable = (AstVariable)node.Operand;
                     var varType = variable.Type;
                     var arg = node.Arguments[0];
                     ConvertIfNeeded(arg, varType);                            
                 }
                 break;
             case AstCode.Ret:
                 {
                     // TODO: whats the difference between this and RLBuilder.ConvertTypeBeforeStore?
                     if (node.Arguments.Count > 0)
                     {
                         var varType = node.Arguments[0].ExpectedType;
                         if (varType != null)
                         {
                             var arg = node.Arguments[0];
                             ConvertForRetIfNeeded(arg, varType);
                         }
                     }
                 }
                 break;
             case AstCode.Stelem_I2:
                 {
                     var arrayElementType = node.Arguments[0].GetResultType().ElementType;
                     var arg = node.Arguments[2];
                     ConvertIfNeeded(arg, arrayElementType);
                 }
                 break;
         }
     }
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:41,代码来源:ConvertBeforeStoreConversionConverter.cs

示例13: Convert

 /// <summary>
 /// Optimize expressions
 /// </summary>
 public static void Convert(AstNode ast)
 {
     foreach (var node in ast.GetExpressions())
     {
         switch (node.Code)
         {
             case AstCode.Stloc:
                 {
                     var variable = (AstVariable)node.Operand;
                     var varType = variable.Type;
                     var arg = node.Arguments[0];
                     ConvertIfNeeded(arg, varType);                            
                 }
                 break;
             case AstCode.Stelem_I2:
                 {
                     var arrayElementType = node.Arguments[0].GetResultType().ElementType;
                     var arg = node.Arguments[2];
                     ConvertIfNeeded(arg, arrayElementType);
                 }
                 break;
         }
     }
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:27,代码来源:ConvertBeforeStoreConversionConverter.cs

示例14: Convert

 /// <summary>
 /// Optimize expressions
 /// </summary>
 public static void Convert(AstNode ast)
 {
     foreach (var node in ast.GetExpressions(AstCode.Cgt_Un))
     {
         if ((node.Arguments.Count == 2) && (node.Arguments[1].Code == AstCode.Ldnull))
         {
             if (node.Arguments[0].Code == AstCode.Isinst)
             {
                 // Cgt_un(IsInst(x), ldnull) -> InstanceOf(x)
                 var argX = node.Arguments[0].Arguments[0];
                 node.Operand = node.Arguments[0].Operand;
                 node.Code = AstCode.InstanceOf;
                 node.Arguments.Clear();
                 node.Arguments.Add(argX);
             }
             else
             {
                 // Cgt_un(x, ldnull) -> CIsNotNull(x)
                 node.Arguments.RemoveAt(1);
                 node.Code = AstCode.CIsNotNull;
             }
         }
     }
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:27,代码来源:CompareUnorderedConverter.cs

示例15: Convert

        /// <summary>
        /// Optimize expressions
        /// </summary>
        public static void Convert(AstNode ast, AssemblyCompiler compiler)
        {
            foreach (var node in ast.GetExpressions())
            {
                switch (node.Code)
                {
                    // Optimize enum2int(ldsfld(enum-const))
                    //      and enum2int(int.to.enum(xxx))
                    case AstCode.Enum_to_int:
                    case AstCode.Enum_to_long:
                        {
                            var arg = node.Arguments[0];
                            XFieldReference fieldRef;
                            if (arg.Match(AstCode.Ldsfld, out fieldRef))
                            {
                                XFieldDefinition field;
                                object value;
                                if (fieldRef.TryResolve(out field) && field.IsStatic && field.DeclaringType.IsEnum && field.TryGetEnumValue(out value))
                                {
                                    // Replace with ldc_ix
                                    var wide = (node.Code == AstCode.Enum_to_long);
                                    node.SetCode(wide ? AstCode.Ldc_I8 : AstCode.Ldc_I4);
                                    node.Operand = wide ? (object)XConvert.ToLong(value) : XConvert.ToInt(value);
                                    node.Arguments.Clear();
                                }
                            }
                            else if (arg.Code == AstCode.Int_to_enum || arg.Code == AstCode.Long_to_enum)
                            {
                                var expectedType = node.ExpectedType;
                                node.CopyFrom(arg.Arguments[0]);
                                node.ExpectedType = expectedType;
                            }
                        }
                        break;
                    // optimize ceq/cne (int/long-to-enum(int), yyy)
                    case AstCode.Ceq:
                    case AstCode.Cne:
                    {
                        if (node.Arguments.Any(a=>IsToEnum(a.Code)))
                        {
                            // xx_to_enum is a quite costly operation when compared to enum-to-int,
                            // so convert this to an interger-only compare.
                            bool isLong = node.Arguments.Any(a => a.Code == AstCode.Long_to_enum);

                            foreach (var arg in node.Arguments)
                            {
                                if (IsToEnum(arg.Code))
                                {
                                    arg.CopyFrom(arg.Arguments[0]);
                                    arg.ExpectedType = isLong ? compiler.Module.TypeSystem.Long : compiler.Module.TypeSystem.Int;
                                }
                                else
                                {
                                    Debug.Assert(arg.GetResultType().IsEnum());
                                    var orig = new AstExpression(arg);
                                    var convert = new AstExpression(arg.SourceLocation,
                                        isLong ? AstCode.Enum_to_long : AstCode.Enum_to_int, null, orig);
                                    convert.ExpectedType = isLong ? compiler.Module.TypeSystem.Long : compiler.Module.TypeSystem.Int;
                                    arg.CopyFrom(convert);
                                }
                            }
                        }
                        break;
                    }
                }
            }
 
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:71,代码来源:EnumOptimizer.cs


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