Removes exception handlers in a special case when exception handler is

exactly at the start of a protected block
This commit is contained in:
konsoletyper 2014-02-26 21:45:58 +04:00
parent a4f477329d
commit 1f18148144
3 changed files with 11 additions and 5 deletions

View File

@ -221,19 +221,19 @@ public class Decompiler {
for (Instruction insn : generator.currentBlock.getInstructions()) { for (Instruction insn : generator.currentBlock.getInstructions()) {
insn.acceptVisitor(generator); insn.acceptVisitor(generator);
} }
block.body.addAll(generator.statements);
for (TryCatchBlock tryCatch : generator.currentBlock.getTryCatchBlocks()) { for (TryCatchBlock tryCatch : generator.currentBlock.getTryCatchBlocks()) {
TryCatchStatement tryCatchStmt = new TryCatchStatement(); TryCatchStatement tryCatchStmt = new TryCatchStatement();
tryCatchStmt.setExceptionType(tryCatch.getExceptionType()); tryCatchStmt.setExceptionType(tryCatch.getExceptionType());
tryCatchStmt.setExceptionVariable(tryCatch.getExceptionVariable().getIndex()); tryCatchStmt.setExceptionVariable(tryCatch.getExceptionVariable().getIndex());
tryCatchStmt.getProtectedBody().addAll(block.body); tryCatchStmt.getProtectedBody().addAll(generator.statements);
block.body.clear(); generator.statements.clear();
block.body.add(tryCatchStmt); generator.statements.add(tryCatchStmt);
Statement handlerStmt = generator.generateJumpStatement(tryCatch.getHandler()); Statement handlerStmt = generator.generateJumpStatement(tryCatch.getHandler());
if (handlerStmt != null) { if (handlerStmt != null) {
tryCatchStmt.getHandler().add(handlerStmt); tryCatchStmt.getHandler().add(handlerStmt);
} }
} }
block.body.addAll(generator.statements);
} }
} }
SequentialStatement result = new SequentialStatement(); SequentialStatement result = new SequentialStatement();

View File

@ -1280,7 +1280,7 @@ public class Renderer implements ExprVisitor, StatementVisitor {
.append("$e;").softNewLine(); .append("$e;").softNewLine();
} }
} }
for (Statement part : statement.getHandler()) { for (Statement part : catchClause.getHandler()) {
part.acceptVisitor(this); part.acceptVisitor(this);
} }
writer.outdent().append("}").ws().append("else "); writer.outdent().append("}").ws().append("else ");

View File

@ -178,6 +178,9 @@ public class ProgramParser {
Deque<Step> workStack = new ArrayDeque<>(); Deque<Step> workStack = new ArrayDeque<>();
for (Object obj : method.tryCatchBlocks) { for (Object obj : method.tryCatchBlocks) {
TryCatchBlockNode tryCatchNode = (TryCatchBlockNode)obj; TryCatchBlockNode tryCatchNode = (TryCatchBlockNode)obj;
if (tryCatchNode.start == tryCatchNode.handler) {
continue;
}
workStack.push(new Step(-2, labelIndexes.get(tryCatchNode.handler.getLabel()))); workStack.push(new Step(-2, labelIndexes.get(tryCatchNode.handler.getLabel())));
} }
workStack.push(new Step(-1, 0)); workStack.push(new Step(-1, 0));
@ -213,6 +216,9 @@ public class ProgramParser {
} }
for (Object obj : method.tryCatchBlocks) { for (Object obj : method.tryCatchBlocks) {
TryCatchBlockNode tryCatchNode = (TryCatchBlockNode)obj; TryCatchBlockNode tryCatchNode = (TryCatchBlockNode)obj;
if (tryCatchNode.start == tryCatchNode.handler) {
continue;
}
int start = labelIndexes.get(tryCatchNode.start.getLabel()); int start = labelIndexes.get(tryCatchNode.start.getLabel());
int end = labelIndexes.get(tryCatchNode.end.getLabel()); int end = labelIndexes.get(tryCatchNode.end.getLabel());
getBasicBlock(start); getBasicBlock(start);