|
|
|
|
@ -31,11 +31,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms
@@ -31,11 +31,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms
|
|
|
|
|
{ |
|
|
|
|
ILTransformContext context; |
|
|
|
|
ITypeResolveContext decompilationContext; |
|
|
|
|
readonly Stack<MethodDefinitionHandle> activeMethods = new Stack<MethodDefinitionHandle>(); |
|
|
|
|
|
|
|
|
|
void IILTransform.Run(ILFunction function, ILTransformContext context) |
|
|
|
|
{ |
|
|
|
|
if (!context.Settings.AnonymousMethods) |
|
|
|
|
return; |
|
|
|
|
var prevContext = this.context; |
|
|
|
|
var prevDecompilationContext = this.decompilationContext; |
|
|
|
|
try { |
|
|
|
|
activeMethods.Push((MethodDefinitionHandle)function.Method.MetadataToken); |
|
|
|
|
this.context = context; |
|
|
|
|
this.decompilationContext = new SimpleTypeResolveContext(function.Method); |
|
|
|
|
var cancellationToken = context.CancellationToken; |
|
|
|
|
@ -58,6 +63,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms
@@ -58,6 +63,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms
|
|
|
|
|
context.StepEndGroup(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} finally { |
|
|
|
|
this.context = prevContext; |
|
|
|
|
this.decompilationContext = prevDecompilationContext; |
|
|
|
|
activeMethods.Pop(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal static bool IsDelegateConstruction(NewObj inst, bool allowTransformed = false) |
|
|
|
|
@ -131,6 +141,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms
@@ -131,6 +141,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms
|
|
|
|
|
if (LocalFunctionDecompiler.IsLocalFunctionMethod(targetMethod, context)) |
|
|
|
|
return null; |
|
|
|
|
target = value.Arguments[0]; |
|
|
|
|
var handle = (MethodDefinitionHandle)targetMethod.MetadataToken; |
|
|
|
|
if (activeMethods.Contains(handle)) { |
|
|
|
|
this.context.Function.Warnings.Add(" Found self-referencing delegate construction. Abort transformation to avoid stack overflow."); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
var methodDefinition = context.PEFile.Metadata.GetMethodDefinition((MethodDefinitionHandle)targetMethod.MetadataToken); |
|
|
|
|
if (!methodDefinition.HasBody()) |
|
|
|
|
return null; |
|
|
|
|
@ -157,7 +172,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
@@ -157,7 +172,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
|
|
|
|
|
function.AcceptVisitor(new ReplaceDelegateTargetVisitor(target, function.Variables.SingleOrDefault(v => v.Index == -1 && v.Kind == VariableKind.Parameter))); |
|
|
|
|
// handle nested lambdas
|
|
|
|
|
nestedContext.StepStartGroup("DelegateConstruction (nested lambdas)", function); |
|
|
|
|
((IILTransform)new DelegateConstruction()).Run(function, nestedContext); |
|
|
|
|
((IILTransform)this).Run(function, nestedContext); |
|
|
|
|
nestedContext.StepEndGroup(); |
|
|
|
|
function.AddILRange(target); |
|
|
|
|
function.AddILRange(value); |
|
|
|
|
|