Browse Source

Fixed decompilation of nested lambdas.

pull/118/head
Daniel Grunwald 15 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
static bool IsPotentialClosure(DecompilerContext context, TypeDefinition potentialDisplayClass) static bool IsPotentialClosure(DecompilerContext context, TypeDefinition potentialDisplayClass)
{ {
if (potentialDisplayClass == null || !potentialDisplayClass.IsCompilerGenerated()) if (potentialDisplayClass == null || !potentialDisplayClass.IsCompilerGeneratedOrIsInCompilerGeneratedClass())
return false; return false;
// check that methodContainingType is within containingType // check that methodContainingType is within containingType
while (potentialDisplayClass != context.CurrentType) { while (potentialDisplayClass != context.CurrentType) {
@ -293,7 +293,13 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
if (!ok) if (!ok)
continue; continue;
Dictionary<FieldReference, AstNode> dict = new Dictionary<FieldReference, AstNode>(); Dictionary<FieldReference, AstNode> dict = new Dictionary<FieldReference, AstNode>();
// Delete the variable declaration statement: // 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; AstNode cur = stmt.NextSibling;
stmt.Remove(); stmt.Remove();

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

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

5
ICSharpCode.Decompiler/Tests/DelegateConstruction.cs

@ -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