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. 3
      ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs
  3. 3
      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);

3
ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

@ -52,7 +52,8 @@ namespace Decompiler.ControlFlow @@ -52,7 +52,8 @@ namespace Decompiler.ControlFlow
foreach(ILTryCatchBlock.CatchBlock catchBlock in tryCatchBlock.CatchBlocks) {
Optimize(ref catchBlock.Body);
}
Optimize(ref tryCatchBlock.FinallyBlock.Body);
if (tryCatchBlock.FinallyBlock != null)
Optimize(ref tryCatchBlock.FinallyBlock.Body);
}
ast.Insert(0, new ILExpression(OpCodes.Br, entryLabel));

3
ICSharpCode.Decompiler/ILAst/ILAstTypes.cs

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

Loading…
Cancel
Save