Browse Source

Fixed bug in creation of try-catch ILAst blocks

pull/10/head
David Srbecký 15 years ago
parent
commit
ed11a717a0
  1. 12
      ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs

12
ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs

@ -106,7 +106,7 @@ namespace Decompiler
List<ByteCode> body = StackAnalysis(methodDef); List<ByteCode> body = StackAnalysis(methodDef);
List<ILNode> ast = ConvertToAst(body, methodDef.Body.ExceptionHandlers); List<ILNode> ast = ConvertToAst(body, new HashSet<ExceptionHandler>(methodDef.Body.ExceptionHandlers));
return ast; return ast;
} }
@ -292,7 +292,7 @@ namespace Decompiler
return body; return body;
} }
List<ILNode> ConvertToAst(List<ByteCode> body, IEnumerable<ExceptionHandler> ehs) List<ILNode> ConvertToAst(List<ByteCode> body, HashSet<ExceptionHandler> ehs)
{ {
List<ILNode> ast = new List<ILNode>(); List<ILNode> ast = new List<ILNode>();
@ -313,7 +313,8 @@ namespace Decompiler
// Cut the try block // Cut the try block
{ {
List<ExceptionHandler> nestedEHs = ehs.Where(eh => (tryStart <= eh.TryStart.Offset && eh.TryEnd.Offset < tryEnd) || (tryStart < eh.TryStart.Offset && eh.TryEnd.Offset <= tryEnd)).ToList(); HashSet<ExceptionHandler> nestedEHs = new HashSet<ExceptionHandler>(ehs.Where(eh => (tryStart <= eh.TryStart.Offset && eh.TryEnd.Offset < tryEnd) || (tryStart < eh.TryStart.Offset && eh.TryEnd.Offset <= tryEnd)));
ehs.ExceptWith(nestedEHs);
int tryEndIdx; int tryEndIdx;
for (tryEndIdx = 0; tryEndIdx < body.Count && body[tryEndIdx].Offset != tryEnd; tryEndIdx++); for (tryEndIdx = 0; tryEndIdx < body.Count && body[tryEndIdx].Offset != tryEnd; tryEndIdx++);
tryCatchBlock.TryBlock = new ILBlock(ConvertToAst(body.CutRange(0, tryEndIdx), nestedEHs)); tryCatchBlock.TryBlock = new ILBlock(ConvertToAst(body.CutRange(0, tryEndIdx), nestedEHs));
@ -328,7 +329,8 @@ namespace Decompiler
// Note that the end(exclusiove) instruction may not necessarly be in our body // Note that the end(exclusiove) instruction may not necessarly be in our body
for (endInclusiveIndex = 0; body[endInclusiveIndex].Next.Offset != eh.HandlerEnd.Offset; endInclusiveIndex++); for (endInclusiveIndex = 0; body[endInclusiveIndex].Next.Offset != eh.HandlerEnd.Offset; endInclusiveIndex++);
int count = 1 + endInclusiveIndex - startIndex; int count = 1 + endInclusiveIndex - startIndex;
List<ExceptionHandler> nestedEHs = ehs.Where(e => (eh.HandlerStart.Offset <= e.TryStart.Offset && e.TryEnd.Offset < eh.HandlerEnd.Offset) || (eh.HandlerStart.Offset < e.TryStart.Offset && e.TryEnd.Offset <= eh.HandlerEnd.Offset)).ToList(); HashSet<ExceptionHandler> nestedEHs = new HashSet<ExceptionHandler>(ehs.Where(e => (eh.HandlerStart.Offset <= e.TryStart.Offset && e.TryEnd.Offset < eh.HandlerEnd.Offset) || (eh.HandlerStart.Offset < e.TryStart.Offset && e.TryEnd.Offset <= eh.HandlerEnd.Offset)));
ehs.ExceptWith(nestedEHs);
List<ILNode> handlerAst = ConvertToAst(body.CutRange(startIndex, count), nestedEHs); List<ILNode> handlerAst = ConvertToAst(body.CutRange(startIndex, count), nestedEHs);
if (eh.HandlerType == ExceptionHandlerType.Catch) { if (eh.HandlerType == ExceptionHandlerType.Catch) {
tryCatchBlock.CatchBlocks.Add(new ILTryCatchBlock.CatchBlock() { tryCatchBlock.CatchBlocks.Add(new ILTryCatchBlock.CatchBlock() {
@ -342,7 +344,7 @@ namespace Decompiler
} }
} }
ehs = ehs.Where(eh => eh.TryStart.Offset > tryEnd).ToList(); ehs.ExceptWith(handlers);
ast.Add(tryCatchBlock); ast.Add(tryCatchBlock);
} }

Loading…
Cancel
Save