@Override public boolean enterTryNode(final TryNode tryNode) { tryNode.toString(sb, printTypes); printLocalVariableConversion(tryNode); tryNode.getBody().accept(this); final List<Block> catchBlocks = tryNode.getCatchBlocks(); for (final Block catchBlock : catchBlocks) { final CatchNode catchNode = (CatchNode)catchBlock.getStatements().get(0); catchNode.toString(sb, printTypes); catchNode.getBody().accept(this); } final Block finallyBody = tryNode.getFinallyBody(); if (finallyBody != null) { sb.append(" finally "); finallyBody.accept(this); } return false; }
private Block catchAllBlock(final TryNode tryNode) { final int lineNumber = tryNode.getLineNumber(); final long token = tryNode.getToken(); final int finish = tryNode.getFinish(); final IdentNode exception = new IdentNode(token, finish, lc.getCurrentFunction().uniqueName(CompilerConstants.EXCEPTION_PREFIX.symbolName())); final Block catchBody = new Block(token, finish, new ThrowNode(lineNumber, token, finish, new IdentNode(exception), true)); assert catchBody.isTerminal(); //ends with throw, so terminal final CatchNode catchAllNode = new CatchNode(lineNumber, token, finish, new IdentNode(exception), null, catchBody, true); final Block catchAllBlock = new Block(token, finish, catchAllNode); //catchallblock -> catchallnode (catchnode) -> exception -> throw return (Block)catchAllBlock.accept(this); //not accepted. has to be accepted by lower }
@Override public boolean enterTryNode(final TryNode tryNode) { final List<? extends CatchNode> catchNodes = tryNode.getCatches(); final List<CatchTreeImpl> catchTrees = new ArrayList<>(catchNodes.size()); for (final CatchNode catchNode : catchNodes) { catchTrees.add(new CatchTreeImpl(catchNode, translateExpr(catchNode.getException()), (BlockTree) translateBlock(catchNode.getBody()), translateExpr(catchNode.getExceptionCondition()))); } curStat = new TryTreeImpl(tryNode, (BlockTree) translateBlock(tryNode.getBody()), catchTrees, (BlockTree) translateBlock(tryNode.getFinallyBody())); return false; }
@Override public boolean enterTryNode(final TryNode tryNode) { tryNode.toString(sb, printTypes); printLocalVariableConversion(tryNode); tryNode.getBody().accept(this); final List<Block> catchBlocks = tryNode.getCatchBlocks(); for (final Block catchBlock : catchBlocks) { final CatchNode catchNode = (CatchNode)catchBlock.getStatements().get(0); catchNode.toString(sb, printTypes); catchNode.getBody().accept(this); } final Block finallyBody = tryNode.getFinallyBody(); if (finallyBody != null) { sb.append(" finally "); finallyBody.accept(this); } for (final Block inlinedFinally : tryNode.getInlinedFinallies()) { inlinedFinally.accept(this); } return false; }
@Override public boolean enterTryNode(final TryNode tryNode) { final List<? extends CatchNode> catchNodes = tryNode.getCatches(); final List<CatchTreeImpl> catchTrees = new ArrayList<>(catchNodes.size()); for (final CatchNode catchNode : catchNodes) { catchTrees.add(new CatchTreeImpl(catchNode, translateIdent(catchNode.getException()), (BlockTree) translateBlock(catchNode.getBody()), translateExpr(catchNode.getExceptionCondition()))); } curStat = new TryTreeImpl(tryNode, (BlockTree) translateBlock(tryNode.getBody()), catchTrees, (BlockTree) translateBlock(tryNode.getFinallyBody())); return false; }
@Override public boolean enterTryNode(final TryNode tryNode) { tryNode.toString(sb); tryNode.getBody().accept(this); final List<Block> catchBlocks = tryNode.getCatchBlocks(); for (final Block catchBlock : catchBlocks) { final CatchNode catchNode = (CatchNode)catchBlock.getStatements().get(0); catchNode.toString(sb); catchNode.getBody().accept(this); } final Block finallyBody = tryNode.getFinallyBody(); if (finallyBody != null) { sb.append(" finally "); finallyBody.accept(this); } return false; }
private Block catchAllBlock(final TryNode tryNode) { final int lineNumber = tryNode.getLineNumber(); final long token = tryNode.getToken(); final int finish = tryNode.getFinish(); final IdentNode exception = new IdentNode(token, finish, lc.getCurrentFunction().uniqueName("catch_all")); final Block catchBody = new Block(token, finish, new ThrowNode(lineNumber, token, finish, new IdentNode(exception), ThrowNode.IS_SYNTHETIC_RETHROW)); assert catchBody.isTerminal(); //ends with throw, so terminal final CatchNode catchAllNode = new CatchNode(lineNumber, token, finish, new IdentNode(exception), null, catchBody, CatchNode.IS_SYNTHETIC_RETHROW); final Block catchAllBlock = new Block(token, finish, catchAllNode); //catchallblock -> catchallnode (catchnode) -> exception -> throw return (Block)catchAllBlock.accept(this); //not accepted. has to be accepted by lower }
void beforeTry(final TryNode tryNode, final Label recovery) { LocalVariableConversion next = tryNode.getLocalVariableConversion(); while(next != null) { if(next.isLive()) { final Type to = emitLocalVariableConversion(next, false); recovery.getStack().onLocalStore(to, next.getSymbol().getSlot(to), true); } next = next.getNext(); } }
@Override public Node leaveTryNode(final TryNode tryNode) { tryNode.setException(exceptionSymbol()); if (tryNode.getFinallyBody() != null) { tryNode.setFinallyCatchAll(exceptionSymbol()); } end(tryNode); return tryNode; }
private TryNode ensureUnconditionalCatch(final TryNode tryNode) { final List<CatchNode> catches = tryNode.getCatches(); if(catches == null || catches.isEmpty() || catches.get(catches.size() - 1).getExceptionCondition() == null) { return tryNode; } // If the last catch block is conditional, add an unconditional rethrow block final List<Block> newCatchBlocks = new ArrayList<>(tryNode.getCatchBlocks()); newCatchBlocks.add(catchAllBlock(tryNode)); return tryNode.setCatchBlocks(newCatchBlocks); }
TryTreeImpl(final TryNode node, final BlockTree block, final List<? extends CatchTree> catches, final BlockTree finallyBlock) { super(node); this.block = block; this.catches = catches; this.finallyBlock = finallyBlock; }
@Override public Node leaveTryNode(final TryNode tryNode) { assert tryNode.getFinallyBody() == null; end(tryNode); return tryNode.setException(lc, exceptionSymbol()); }
private TryNode ensureUnconditionalCatch(final TryNode tryNode) { final List<CatchNode> catches = tryNode.getCatches(); if(catches == null || catches.isEmpty() || catches.get(catches.size() - 1).getExceptionCondition() == null) { return tryNode; } // If the last catch block is conditional, add an unconditional rethrow block final List<Block> newCatchBlocks = new ArrayList<>(tryNode.getCatchBlocks()); newCatchBlocks.add(catchAllBlock(tryNode)); return tryNode.setCatchBlocks(lc, newCatchBlocks); }
@Override public Node leaveTryNode(final TryNode tryNode) { tryNode.setException(exceptionSymbol()); assert tryNode.getFinallyBody() == null; end(tryNode); return tryNode; }