Browse Source

Fixed decompilation of nested lambdas.

pull/118/head
Daniel Grunwald 14 years ago
parent
commit
d805e07ffe
  1. 8
      ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs
  2. 2
      ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs
  3. 5
      ICSharpCode.Decompiler/Tests/DelegateConstruction.cs

8
ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs

@ -177,7 +177,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -177,7 +177,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
static bool IsPotentialClosure(DecompilerContext context, TypeDefinition potentialDisplayClass)
{
if (potentialDisplayClass == null || !potentialDisplayClass.IsCompilerGenerated())
if (potentialDisplayClass == null || !potentialDisplayClass.IsCompilerGeneratedOrIsInCompilerGeneratedClass())
return false;
// check that methodContainingType is within containingType
while (potentialDisplayClass != context.CurrentType) {
@ -293,7 +293,13 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -293,7 +293,13 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
if (!ok)
continue;
Dictionary<FieldReference, AstNode> dict = new Dictionary<FieldReference, AstNode>();
// Delete the variable declaration statement:
VariableDeclarationStatement displayClassVarDecl = PatternStatementTransform.FindVariableDeclaration(stmt, variable.Name);
if (displayClassVarDecl != null)
displayClassVarDecl.Remove();
// Delete the assignment statement:
AstNode cur = stmt.NextSibling;
stmt.Remove();

2
ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs

@ -201,7 +201,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -201,7 +201,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
return null;
}
VariableDeclarationStatement FindVariableDeclaration(AstNode node, string identifier)
internal static VariableDeclarationStatement FindVariableDeclaration(AstNode node, string identifier)
{
while (node != null) {
while (node.PrevSibling != null) {

5
ICSharpCode.Decompiler/Tests/DelegateConstruction.cs

@ -157,4 +157,9 @@ public static class DelegateConstruction @@ -157,4 +157,9 @@ public static class DelegateConstruction
}
};
}
public static Func<int, Func<int, int>> CurriedAddition(int a)
{
return b => c => a + b + c;
}
}

Loading…
Cancel
Save