Browse Source

Fixed bug in DeclareVariableInSmallestScope

pull/100/head
Daniel Grunwald 15 years ago
parent
commit
3c1400d605
  1. 5
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  2. 8
      ICSharpCode.Decompiler/Ast/DeclareVariableInSmallestScope.cs

5
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -22,6 +22,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -22,6 +22,7 @@ namespace ICSharpCode.Decompiler.Ast
TypeSystem typeSystem;
DecompilerContext context;
HashSet<ILVariable> localVariablesToDefine = new HashSet<ILVariable>(); // local variables that are missing a definition
HashSet<ILVariable> implicitlyDefinedVariables = new HashSet<ILVariable>(); // local variables that are implicitly defined (e.g. catch handler)
public static BlockStatement CreateMethodBody(MethodDefinition methodDef, DecompilerContext context)
{
@ -69,7 +70,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -69,7 +70,7 @@ namespace ICSharpCode.Decompiler.Ast
context.CancellationToken.ThrowIfCancellationRequested();
Ast.BlockStatement astBlock = TransformBlock(ilMethod);
CommentStatement.ReplaceAll(astBlock); // convert CommentStatements to Comments
foreach (ILVariable v in localVariablesToDefine) {
foreach (ILVariable v in localVariablesToDefine.Except(implicitlyDefinedVariables)) {
DeclareVariableInSmallestScope.DeclareVariable(astBlock, AstBuilder.ConvertType(v.Type), v.Name);
}
@ -138,6 +139,8 @@ namespace ICSharpCode.Decompiler.Ast @@ -138,6 +139,8 @@ namespace ICSharpCode.Decompiler.Ast
var tryCatchStmt = new Ast.TryCatchStatement();
tryCatchStmt.TryBlock = TransformBlock(tryCatchNode.TryBlock);
foreach (var catchClause in tryCatchNode.CatchBlocks) {
if (catchClause.ExceptionVariable != null)
implicitlyDefinedVariables.Add(catchClause.ExceptionVariable);
tryCatchStmt.CatchClauses.Add(
new Ast.CatchClause {
Type = AstBuilder.ConvertType(catchClause.ExceptionType),

8
ICSharpCode.Decompiler/Ast/DeclareVariableInSmallestScope.cs

@ -47,13 +47,13 @@ namespace ICSharpCode.Decompiler.Ast @@ -47,13 +47,13 @@ namespace ICSharpCode.Decompiler.Ast
static AstNode FindInsertPos(AstNode node, string name, bool allowPassIntoLoops)
{
IdentifierExpression ident = node as IdentifierExpression;
if (ident != null && ident.Identifier == name && ident.TypeArguments.Count == 0)
return node;
AstNode pos = null;
AstNode withinPos = null;
while (node != null) {
IdentifierExpression ident = node as IdentifierExpression;
if (ident != null && ident.Identifier == name && ident.TypeArguments.Count == 0)
return node;
AstNode withinCurrent = FindInsertPos(node.FirstChild, name, allowPassIntoLoops);
if (withinCurrent != null) {
if (pos == null) {

Loading…
Cancel
Save