From 1f1814814475eadfca8759adbb09e5e838375b7f Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Wed, 26 Feb 2014 21:45:58 +0400 Subject: [PATCH] Removes exception handlers in a special case when exception handler is exactly at the start of a protected block --- .../src/main/java/org/teavm/javascript/Decompiler.java | 8 ++++---- .../src/main/java/org/teavm/javascript/Renderer.java | 2 +- .../src/main/java/org/teavm/parsing/ProgramParser.java | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java b/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java index fcadfdf9b..7a9a23ffa 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java +++ b/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java @@ -221,19 +221,19 @@ public class Decompiler { for (Instruction insn : generator.currentBlock.getInstructions()) { insn.acceptVisitor(generator); } - block.body.addAll(generator.statements); for (TryCatchBlock tryCatch : generator.currentBlock.getTryCatchBlocks()) { TryCatchStatement tryCatchStmt = new TryCatchStatement(); tryCatchStmt.setExceptionType(tryCatch.getExceptionType()); tryCatchStmt.setExceptionVariable(tryCatch.getExceptionVariable().getIndex()); - tryCatchStmt.getProtectedBody().addAll(block.body); - block.body.clear(); - block.body.add(tryCatchStmt); + tryCatchStmt.getProtectedBody().addAll(generator.statements); + generator.statements.clear(); + generator.statements.add(tryCatchStmt); Statement handlerStmt = generator.generateJumpStatement(tryCatch.getHandler()); if (handlerStmt != null) { tryCatchStmt.getHandler().add(handlerStmt); } } + block.body.addAll(generator.statements); } } SequentialStatement result = new SequentialStatement(); diff --git a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java index ad7052c3c..aa897235a 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java +++ b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java @@ -1280,7 +1280,7 @@ public class Renderer implements ExprVisitor, StatementVisitor { .append("$e;").softNewLine(); } } - for (Statement part : statement.getHandler()) { + for (Statement part : catchClause.getHandler()) { part.acceptVisitor(this); } writer.outdent().append("}").ws().append("else "); diff --git a/teavm-core/src/main/java/org/teavm/parsing/ProgramParser.java b/teavm-core/src/main/java/org/teavm/parsing/ProgramParser.java index b697c0c14..111e97529 100644 --- a/teavm-core/src/main/java/org/teavm/parsing/ProgramParser.java +++ b/teavm-core/src/main/java/org/teavm/parsing/ProgramParser.java @@ -178,6 +178,9 @@ public class ProgramParser { Deque workStack = new ArrayDeque<>(); for (Object obj : method.tryCatchBlocks) { TryCatchBlockNode tryCatchNode = (TryCatchBlockNode)obj; + if (tryCatchNode.start == tryCatchNode.handler) { + continue; + } workStack.push(new Step(-2, labelIndexes.get(tryCatchNode.handler.getLabel()))); } workStack.push(new Step(-1, 0)); @@ -213,6 +216,9 @@ public class ProgramParser { } for (Object obj : method.tryCatchBlocks) { TryCatchBlockNode tryCatchNode = (TryCatchBlockNode)obj; + if (tryCatchNode.start == tryCatchNode.handler) { + continue; + } int start = labelIndexes.get(tryCatchNode.start.getLabel()); int end = labelIndexes.get(tryCatchNode.end.getLabel()); getBasicBlock(start);