Browse Source

Fix exception when decompiling a try-catch block without finally block.

pull/10/head
Daniel Grunwald 15 years ago
parent
commit
9502746b05
  1. 8
      ICSharpCode.Decompiler/Ast/AstMetodBodyBuilder.cs
  2. 1
      ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs
  3. 1
      ICSharpCode.Decompiler/ILAst/ILAstTypes.cs

8
ICSharpCode.Decompiler/Ast/AstMetodBodyBuilder.cs

@ -157,9 +157,9 @@ namespace Decompiler @@ -157,9 +157,9 @@ namespace Decompiler
FalseStatement = TransformBlock(conditionalNode.TrueBlock)
};
} else if (node is ILTryCatchBlock) {
ILTryCatchBlock tryCachNode = ((ILTryCatchBlock)node);
ILTryCatchBlock tryCatchNode = ((ILTryCatchBlock)node);
List<Ast.CatchClause> catchClauses = new List<CatchClause>();
foreach (var catchClause in tryCachNode.CatchBlocks) {
foreach (var catchClause in tryCatchNode.CatchBlocks) {
catchClauses.Add(new Ast.CatchClause {
Type = AstBuilder.ConvertType(catchClause.ExceptionType),
VariableName = "exception",
@ -167,9 +167,9 @@ namespace Decompiler @@ -167,9 +167,9 @@ namespace Decompiler
});
}
yield return new Ast.TryCatchStatement {
TryBlock = TransformBlock(tryCachNode.TryBlock),
TryBlock = TransformBlock(tryCatchNode.TryBlock),
CatchClauses = catchClauses,
FinallyBlock = TransformBlock(tryCachNode.FinallyBlock)
FinallyBlock = tryCatchNode.FinallyBlock != null ? TransformBlock(tryCatchNode.FinallyBlock) : null
};
} else if (node is ILBlock) {
yield return TransformBlock((ILBlock)node);

1
ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

@ -52,6 +52,7 @@ namespace Decompiler.ControlFlow @@ -52,6 +52,7 @@ namespace Decompiler.ControlFlow
foreach(ILTryCatchBlock.CatchBlock catchBlock in tryCatchBlock.CatchBlocks) {
Optimize(ref catchBlock.Body);
}
if (tryCatchBlock.FinallyBlock != null)
Optimize(ref tryCatchBlock.FinallyBlock.Body);
}

1
ICSharpCode.Decompiler/ILAst/ILAstTypes.cs

@ -93,6 +93,7 @@ namespace Decompiler @@ -93,6 +93,7 @@ namespace Decompiler
foreach (var catchBlock in this.CatchBlocks) {
yield return catchBlock;
}
if (this.FinallyBlock != null)
yield return this.FinallyBlock;
}

Loading…
Cancel
Save