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


C# ILExpression.GetSelfAndChildrenRecursiveILRanges方法代码示例

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


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

示例1: TransformExpression

		AstNode TransformExpression(ILExpression expr)
		{
			List<ILRange> ilRanges = ILRange.OrderAndJoin(expr.GetSelfAndChildrenRecursiveILRanges());

			AstNode node = TransformByteCode(expr);
			Expression astExpr = node as Expression;
			
			AstNode result;
			
			if (astExpr != null)
				result = Convert(astExpr, expr.InferredType, expr.ExpectedType);
			else
				result = node;
			
			if (result != null)
				result = result.WithAnnotation(new TypeInformation(expr.InferredType, expr.ExpectedType));
			
			if (result != null)
				return result.WithAnnotation(ilRanges);
			
			return result;
		}
开发者ID:nakijun,项目名称:dnSpy,代码行数:22,代码来源:AstMethodBodyBuilder.cs

示例2: MakeAssignmentExpression

		bool MakeAssignmentExpression(ILBlockBase block, List<ILNode> body, ILExpression expr, int pos)
		{
			// exprVar = ...
			// stloc(v, exprVar)
			// ->
			// exprVar = stloc(v, ...))
			ILVariable exprVar;
			ILExpression initializer;
			if (!(expr.Match(ILCode.Stloc, out exprVar, out initializer) && exprVar.GeneratedByDecompiler))
				return false;
			ILExpression nextExpr = body.ElementAtOrDefault(pos + 1) as ILExpression;
			if (nextExpr == null)
				return false;
			ILVariable v;
			ILExpression stLocArg;
			if (nextExpr.Match(ILCode.Stloc, out v, out stLocArg) && stLocArg.MatchLdloc(exprVar)) {
				ILExpression store2 = body.ElementAtOrDefault(pos + 2) as ILExpression;
				if (StoreCanBeConvertedToAssignment(store2, exprVar)) {
					// expr_44 = ...
					// stloc(v1, expr_44)
					// anystore(v2, expr_44)
					// ->
					// stloc(v1, anystore(v2, ...))
					ILInlining inlining = new ILInlining(method);
					if (inlining.numLdloc.GetOrDefault(exprVar) == 2 && inlining.numStloc.GetOrDefault(exprVar) == 1) {
						body.RemoveAt(pos + 2); // remove store2
						body.RemoveAt(pos); // remove expr = ...
						nextExpr.ILRanges.AddRange(nextExpr.Arguments[0].GetSelfAndChildrenRecursiveILRanges());
						nextExpr.Arguments[0] = store2;
						store2.ILRanges.AddRange(expr.GetSelfAndChildrenRecursiveILRanges());
						store2.ILRanges.AddRange(store2.Arguments[store2.Arguments.Count - 1].GetSelfAndChildrenRecursiveILRanges());
						store2.Arguments[store2.Arguments.Count - 1] = initializer;
						
						inlining.InlineIfPossible(block, body, ref pos);
						
						return true;
					}
				}
				
				body.RemoveAt(pos + 1); // remove stloc
				nextExpr.ILRanges.AddRange(nextExpr.Arguments[0].GetSelfAndChildrenRecursiveILRanges());
				nextExpr.Arguments[0] = initializer;
				nextExpr.ILRanges.AddRange(expr.Arguments[0].GetSelfAndChildrenRecursiveILRanges());
				expr.Arguments[0] = nextExpr;
				return true;
			} else if ((nextExpr.Code == ILCode.Stsfld || nextExpr.Code == ILCode.CallSetter || nextExpr.Code == ILCode.CallvirtSetter) && nextExpr.Arguments.Count == 1) {
				// exprVar = ...
				// stsfld(fld, exprVar)
				// ->
				// exprVar = stsfld(fld, ...))
				if (nextExpr.Arguments[0].MatchLdloc(exprVar)) {
					body.RemoveAt(pos + 1); // remove stsfld
					nextExpr.ILRanges.AddRange(nextExpr.Arguments[0].GetSelfAndChildrenRecursiveILRanges());
					nextExpr.Arguments[0] = initializer;
					expr.ILRanges.AddRange(expr.Arguments[0].GetSelfAndChildrenRecursiveILRanges());
					expr.Arguments[0] = nextExpr;
					return true;
				}
			}
			return false;
		}
开发者ID:lovebanyi,项目名称:dnSpy,代码行数:61,代码来源:PeepholeTransform.cs


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