Browse Source

Adjust CapturedVariables collection in ReplaceDelegateTargetVisitor and in TransformExpressionTrees

pull/2005/head
Siegfried Pammer 5 years ago
parent
commit
bcd7219535
  1. 2
      ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs
  2. 25
      ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs
  3. 4
      ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs

2
ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs

@ -77,7 +77,7 @@ namespace ICSharpCode.Decompiler.IL @@ -77,7 +77,7 @@ namespace ICSharpCode.Decompiler.IL
/// Gets the set of captured variables by this ILFunction.
/// </summary>
/// <remarks>This is populated by the <see cref="TransformDisplayClassUsage" /> step.</remarks>
public HashSet<ILVariable> CapturedVariables { get; } = new HashSet<ILVariable>(ILVariableEqualityComparer.Instance);
public HashSet<ILVariable> CapturedVariables { get; } = new HashSet<ILVariable>();
/// <summary>
/// List of warnings of ILReader.

25
ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs

@ -238,7 +238,30 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -238,7 +238,30 @@ namespace ICSharpCode.Decompiler.IL.Transforms
child.AcceptVisitor(this);
}
}
protected internal override void VisitILFunction(ILFunction function)
{
if (function == thisVariable?.Function) {
ILVariable v = null;
switch (target) {
case LdLoc l:
v = l.Variable;
break;
case LdObj lo:
ILInstruction inner = lo.Target;
while (inner is LdFlda ldf) {
inner = ldf.Target;
}
if (inner is LdLoc l2)
v = l2.Variable;
break;
}
if (v != null)
function.CapturedVariables.Add(v);
}
base.VisitILFunction(function);
}
protected internal override void VisitLdLoc(LdLoc inst)
{
if (inst.Variable == thisVariable) {

4
ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs

@ -1229,6 +1229,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -1229,6 +1229,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
}
if (ldloc.Variable.CaptureScope == null) {
ldloc.Variable.CaptureScope = BlockContainer.FindClosestContainer(context);
var f = ldloc.Variable.CaptureScope.Ancestors.OfType<ILFunction>().FirstOrDefault();
if (f != null) {
f.CapturedVariables.Add(ldloc.Variable);
}
}
return ldloc;
} else {

Loading…
Cancel
Save