本文整理汇总了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;
}
示例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;
}