int getSplitStateIndex(final JumpStatement jump) { if (jump instanceof BreakNode && jump.getLabelName() == null) { // Unlabelled break is a special case hasBreak = true; return BREAK_STATE; } int i = 0; for(final JumpStatement exJump: jumpStatements) { if (jump.getClass() == exJump.getClass() && Objects.equals(jump.getLabelName(), exJump.getLabelName())) { return i + FIRST_JUMP_STATE; } ++i; } jumpStatements.add(jump); return i + FIRST_JUMP_STATE; }
private JumpStatement leaveJumpNode(final JumpStatement jump) { if (inSplitNode()) { final SplitState splitState = getCurrentSplitState(); final SplitNode splitNode = splitState.splitNode; if (lc.isExternalTarget(splitNode, jump.getTarget(lc))) { appendSplitReturn(splitState.getSplitStateIndex(jump), jump.getLineNumber()); return jump; } } appendStatement(jump); return jump; }
private boolean enterJumpStatement(final JumpStatement jump) { if(!reachable) { return false; } final BreakableNode target = jump.getTarget(lc); jumpToLabel(jump, jump.getTargetLabel(target), getBreakTargetTypes(target)); doesNotContinueSequentially(); return false; }
private boolean enterJumpStatement(final JumpStatement jump) { if(!method.isReachable()) { return false; } enterStatement(jump); method.beforeJoinPoint(jump); final BreakableNode target = jump.getTarget(lc); popScopesUntil(target); final Label targetLabel = jump.getTargetLabel(target); targetLabel.markAsBreakTarget(); method._goto(targetLabel); return false; }
private boolean enterJumpStatement(final JumpStatement jump) { if(!reachable) { return false; } assertTypeStackIsEmpty(); jumpToLabel(jump, jump.getTargetLabel(lc), getBreakTargetTypes(jump.getPopScopeLimit(lc))); doesNotContinueSequentially(); return false; }
private boolean enterJumpStatement(final JumpStatement jump) { if(!method.isReachable()) { return false; } enterStatement(jump); method.beforeJoinPoint(jump); popScopesUntil(jump.getPopScopeLimit(lc)); final Label targetLabel = jump.getTargetLabel(lc); targetLabel.markAsBreakTarget(); method._goto(targetLabel); return false; }
private Block enblockAndVisit(final JumpStatement jump) { artificialBlock = true; final Block block = (Block)new Block(NO_TOKEN, NO_FINISH, jump).accept(this); artificialBlock = false; return block; }
/** * Constructor. */ Lower(final Compiler compiler) { super(new BlockLexicalContext() { @Override public List<Statement> popStatements() { final List<Statement> newStatements = new ArrayList<>(); boolean terminated = false; final List<Statement> statements = super.popStatements(); for (final Statement statement : statements) { if (!terminated) { newStatements.add(statement); if (statement.isTerminal() || statement instanceof JumpStatement) { //TODO hasGoto? But some Loops are hasGoto too - why? terminated = true; } } else { FoldConstants.extractVarNodesFromDeadCode(statement, newStatements); } } return newStatements; } @Override protected Block afterSetStatements(final Block block) { final List<Statement> stmts = block.getStatements(); for(final ListIterator<Statement> li = stmts.listIterator(stmts.size()); li.hasPrevious();) { final Statement stmt = li.previous(); // popStatements() guarantees that the only thing after a terminal statement are uninitialized // VarNodes. We skip past those, and set the terminal state of the block to the value of the // terminal state of the first statement that is not an uninitialized VarNode. if(!(stmt instanceof VarNode && ((VarNode)stmt).getInit() == null)) { return block.setIsTerminal(this, stmt.isTerminal()); } } return block.setIsTerminal(this, false); } }); this.log = initLogger(compiler.getContext()); this.es6 = compiler.getScriptEnvironment()._es6; this.source = compiler.getSource(); }
/** * Constructor. */ Lower(final Compiler compiler) { super(new BlockLexicalContext() { @Override public List<Statement> popStatements() { final List<Statement> newStatements = new ArrayList<>(); boolean terminated = false; final List<Statement> statements = super.popStatements(); for (final Statement statement : statements) { if (!terminated) { newStatements.add(statement); if (statement.isTerminal() || statement instanceof JumpStatement) { //TODO hasGoto? But some Loops are hasGoto too - why? terminated = true; } } else { FoldConstants.extractVarNodesFromDeadCode(statement, newStatements); } } return newStatements; } @Override protected Block afterSetStatements(final Block block) { final List<Statement> stmts = block.getStatements(); for(final ListIterator<Statement> li = stmts.listIterator(stmts.size()); li.hasPrevious();) { final Statement stmt = li.previous(); // popStatements() guarantees that the only thing after a terminal statement are uninitialized // VarNodes. We skip past those, and set the terminal state of the block to the value of the // terminal state of the first statement that is not an uninitialized VarNode. if(!(stmt instanceof VarNode && ((VarNode)stmt).getInit() == null)) { return block.setIsTerminal(this, stmt.isTerminal()); } } return block.setIsTerminal(this, false); } }); this.log = initLogger(compiler.getContext()); this.es6 = compiler.getScriptEnvironment()._es6; }
/** * Constructor. */ Lower(final Compiler compiler) { super(new BlockLexicalContext() { @Override public List<Statement> popStatements() { final List<Statement> newStatements = new ArrayList<>(); boolean terminated = false; final List<Statement> statements = super.popStatements(); for (final Statement statement : statements) { if (!terminated) { newStatements.add(statement); if (statement.isTerminal() || statement instanceof JumpStatement) { //TODO hasGoto? But some Loops are hasGoto too - why? terminated = true; } } else { statement.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { @Override public boolean enterVarNode(final VarNode varNode) { newStatements.add(varNode.setInit(null)); return false; } }); } } return newStatements; } @Override protected Block afterSetStatements(final Block block) { final List<Statement> stmts = block.getStatements(); for(final ListIterator<Statement> li = stmts.listIterator(stmts.size()); li.hasPrevious();) { final Statement stmt = li.previous(); // popStatements() guarantees that the only thing after a terminal statement are uninitialized // VarNodes. We skip past those, and set the terminal state of the block to the value of the // terminal state of the first statement that is not an uninitialized VarNode. if(!(stmt instanceof VarNode && ((VarNode)stmt).getInit() == null)) { return block.setIsTerminal(this, stmt.isTerminal()); } } return block.setIsTerminal(this, false); } }); this.log = initLogger(compiler.getContext()); }
/** * Constructor. */ Lower(final Compiler compiler) { super(new BlockLexicalContext() { @Override public List<Statement> popStatements() { final List<Statement> newStatements = new ArrayList<>(); boolean terminated = false; final List<Statement> statements = super.popStatements(); for (final Statement statement : statements) { if (!terminated) { newStatements.add(statement); if (statement.isTerminal() || statement instanceof JumpStatement) { //TODO hasGoto? But some Loops are hasGoto too - why? terminated = true; } } else { FoldConstants.extractVarNodesFromDeadCode(statement, newStatements); } } return newStatements; } @Override protected Block afterSetStatements(final Block block) { final List<Statement> stmts = block.getStatements(); for(final ListIterator<Statement> li = stmts.listIterator(stmts.size()); li.hasPrevious();) { final Statement stmt = li.previous(); // popStatements() guarantees that the only thing after a terminal statement are uninitialized // VarNodes. We skip past those, and set the terminal state of the block to the value of the // terminal state of the first statement that is not an uninitialized VarNode. if(!(stmt instanceof VarNode && ((VarNode)stmt).getInit() == null)) { return block.setIsTerminal(this, stmt.isTerminal()); } } return block.setIsTerminal(this, false); } }); this.log = initLogger(compiler.getContext()); }