Java Code Examples for jdk.nashorn.internal.ir.Block#accept()

The following examples show how to use jdk.nashorn.internal.ir.Block#accept() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrintVisitor.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: PrintVisitor.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: PrintVisitor.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 4
Source File: CodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterWhileNode(final WhileNode whileNode) {
    final Expression test          = whileNode.getTest();
    final Block      body          = whileNode.getBody();
    final Label      breakLabel    = whileNode.getBreakLabel();
    final Label      continueLabel = whileNode.getContinueLabel();
    final boolean    isDoWhile     = whileNode.isDoWhile();
    final Label      loopLabel     = new Label("loop");

    if (!isDoWhile) {
        method._goto(continueLabel);
    }

    method.label(loopLabel);
    body.accept(this);
    if (!whileNode.isTerminal()) {
        method.label(continueLabel);
        lineNumber(whileNode);
        new BranchOptimizer(this, method).execute(test, loopLabel, true);
        method.label(breakLabel);
    }

    return false;
}
 
Example 5
Source File: FoldConstants.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void extractVarNodes(final Block block, final List<Statement> statements) {
    final LexicalContext lc = new LexicalContext();
    block.accept(lc, new NodeVisitor<LexicalContext>(lc) {
        @Override
        public boolean enterVarNode(VarNode varNode) {
            statements.add(varNode.setInit(null));
            return false;
        }
    });
}
 
Example 6
Source File: CodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void enterFor(final ForNode forNode) {
    final Expression init   = forNode.getInit();
    final Expression test   = forNode.getTest();
    final Block      body   = forNode.getBody();
    final Expression modify = forNode.getModify();

    if (init != null) {
        init.accept(this);
    }

    final Label loopLabel = new Label("loop");
    final Label testLabel = new Label("test");

    method._goto(testLabel);
    method.label(loopLabel);
    body.accept(this);
    method.label(forNode.getContinueLabel());

    if (!body.isTerminal() && modify != null) {
        load(modify);
    }

    method.label(testLabel);
    if (test != null) {
        new BranchOptimizer(this, method).execute(test, loopLabel, true);
    } else {
        method._goto(loopLabel);
    }

    method.label(forNode.getBreakLabel());
}
 
Example 7
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void enterDoWhileLoop(final WhileNode loopNode) {
    assertTypeStackIsEmpty();
    final JoinPredecessorExpression test = loopNode.getTest();
    final Block body = loopNode.getBody();
    final Label continueLabel = loopNode.getContinueLabel();
    final Label breakLabel = loopNode.getBreakLabel();
    final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes;
    final Label repeatLabel = new Label("");
    for(;;) {
        jumpToLabel(loopNode, repeatLabel, beforeLoopTypes);
        final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes;
        body.accept(this);
        if(reachable) {
            jumpToLabel(body, continueLabel);
        }
        joinOnLabel(continueLabel);
        if(!reachable) {
            break;
        }
        visitExpressionOnEmptyStack(test);
        jumpToLabel(test, breakLabel);
        if(isAlwaysFalse(test)) {
            break;
        }
        jumpToLabel(test, repeatLabel);
        joinOnLabel(repeatLabel);
        if(localVariableTypes.equals(beforeRepeatTypes)) {
            break;
        }
        resetJoinPoint(continueLabel);
        resetJoinPoint(breakLabel);
        resetJoinPoint(repeatLabel);
    }

    if(isAlwaysTrue(test)) {
        doesNotContinueSequentially();
    }

    leaveBreakable(loopNode);
}
 
Example 8
Source File: AssignSymbols.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Define symbols for all variable declarations at the top of the function scope. This way we can get around
 * problems like
 *
 * while (true) {
 *   break;
 *   if (true) {
 *     var s;
 *   }
 * }
 *
 * to an arbitrary nesting depth.
 *
 * see NASHORN-73
 *
 * @param functionNode the FunctionNode we are entering
 * @param body the body of the FunctionNode we are entering
 */
private void acceptDeclarations(final FunctionNode functionNode, final Block body) {
    // This visitor will assign symbol to all declared variables.
    body.accept(new SimpleNodeVisitor() {
        @Override
        protected boolean enterDefault(final Node node) {
            // Don't bother visiting expressions; var is a statement, it can't be inside an expression.
            // This will also prevent visiting nested functions (as FunctionNode is an expression).
            return !(node instanceof Expression);
        }

        @Override
        public Node leaveVarNode(final VarNode varNode) {
            final IdentNode ident  = varNode.getName();
            final boolean blockScoped = varNode.isBlockScoped();
            if (blockScoped && lc.inUnprotectedSwitchContext()) {
                throwUnprotectedSwitchError(varNode);
            }
            final Block block = blockScoped ? lc.getCurrentBlock() : body;
            final Symbol symbol = defineSymbol(block, ident.getName(), ident, varNode.getSymbolFlags());
            if (varNode.isFunctionDeclaration()) {
                symbol.setIsFunctionDeclaration();
            }
            return varNode.setName(ident.setSymbol(symbol));
        }
    });
}
 
Example 9
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void enterDoWhileLoop(final WhileNode loopNode) {
    assertTypeStackIsEmpty();
    final JoinPredecessorExpression test = loopNode.getTest();
    final Block body = loopNode.getBody();
    final Label continueLabel = loopNode.getContinueLabel();
    final Label breakLabel = loopNode.getBreakLabel();
    final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes;
    final Label repeatLabel = new Label("");
    for(;;) {
        jumpToLabel(loopNode, repeatLabel, beforeLoopTypes);
        final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes;
        body.accept(this);
        if(reachable) {
            jumpToLabel(body, continueLabel);
        }
        joinOnLabel(continueLabel);
        if(!reachable) {
            break;
        }
        visitExpressionOnEmptyStack(test);
        jumpToLabel(test, breakLabel);
        if(isAlwaysFalse(test)) {
            break;
        }
        jumpToLabel(test, repeatLabel);
        joinOnLabel(repeatLabel);
        if(localVariableTypes.equals(beforeRepeatTypes)) {
            break;
        }
        resetJoinPoint(continueLabel);
        resetJoinPoint(breakLabel);
        resetJoinPoint(repeatLabel);
    }

    if(isAlwaysTrue(test)) {
        doesNotContinueSequentially();
    }

    leaveBreakable(loopNode);
}
 
Example 10
Source File: LocalVariableTypesCalculator.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private void enterDoWhileLoop(final WhileNode loopNode) {
    assertTypeStackIsEmpty();
    final JoinPredecessorExpression test = loopNode.getTest();
    final Block body = loopNode.getBody();
    final Label continueLabel = loopNode.getContinueLabel();
    final Label breakLabel = loopNode.getBreakLabel();
    final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes;
    final Label repeatLabel = new Label("");
    for(;;) {
        jumpToLabel(loopNode, repeatLabel, beforeLoopTypes);
        final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes;
        body.accept(this);
        if(reachable) {
            jumpToLabel(body, continueLabel);
        }
        joinOnLabel(continueLabel);
        if(!reachable) {
            break;
        }
        visitExpressionOnEmptyStack(test);
        jumpToLabel(test, breakLabel);
        if(isAlwaysFalse(test)) {
            break;
        }
        jumpToLabel(test, repeatLabel);
        joinOnLabel(repeatLabel);
        if(localVariableTypes.equals(beforeRepeatTypes)) {
            break;
        }
        resetJoinPoint(continueLabel);
        resetJoinPoint(breakLabel);
        resetJoinPoint(repeatLabel);
    }

    if(isAlwaysTrue(test)) {
        doesNotContinueSequentially();
    }

    leaveBreakable(loopNode);
}
 
Example 11
Source File: LocalVariableTypesCalculator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void enterDoWhileLoop(final WhileNode loopNode) {
    assertTypeStackIsEmpty();
    final JoinPredecessorExpression test = loopNode.getTest();
    final Block body = loopNode.getBody();
    final Label continueLabel = loopNode.getContinueLabel();
    final Label breakLabel = loopNode.getBreakLabel();
    final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes;
    final Label repeatLabel = new Label("");
    for(;;) {
        jumpToLabel(loopNode, repeatLabel, beforeLoopTypes);
        final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes;
        body.accept(this);
        if(reachable) {
            jumpToLabel(body, continueLabel);
        }
        joinOnLabel(continueLabel);
        if(!reachable) {
            break;
        }
        visitExpressionOnEmptyStack(test);
        jumpToLabel(test, breakLabel);
        if(isAlwaysFalse(test)) {
            break;
        }
        jumpToLabel(test, repeatLabel);
        joinOnLabel(repeatLabel);
        if(localVariableTypes.equals(beforeRepeatTypes)) {
            break;
        }
        resetJoinPoint(continueLabel);
        resetJoinPoint(breakLabel);
        resetJoinPoint(repeatLabel);
    }

    if(isAlwaysTrue(test)) {
        doesNotContinueSequentially();
    }

    leaveBreakable(loopNode);
}
 
Example 12
Source File: LocalVariableTypesCalculator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void enterDoWhileLoop(final WhileNode loopNode) {
    assertTypeStackIsEmpty();
    final JoinPredecessorExpression test = loopNode.getTest();
    final Block body = loopNode.getBody();
    final Label continueLabel = loopNode.getContinueLabel();
    final Label breakLabel = loopNode.getBreakLabel();
    final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes;
    final Label repeatLabel = new Label("");
    for(;;) {
        jumpToLabel(loopNode, repeatLabel, beforeLoopTypes);
        final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes;
        body.accept(this);
        if(reachable) {
            jumpToLabel(body, continueLabel);
        }
        joinOnLabel(continueLabel);
        if(!reachable) {
            break;
        }
        visitExpressionOnEmptyStack(test);
        jumpToLabel(test, breakLabel);
        if(isAlwaysFalse(test)) {
            break;
        }
        jumpToLabel(test, repeatLabel);
        joinOnLabel(repeatLabel);
        if(localVariableTypes.equals(beforeRepeatTypes)) {
            break;
        }
        resetJoinPoint(continueLabel);
        resetJoinPoint(breakLabel);
        resetJoinPoint(repeatLabel);
    }

    if(isAlwaysTrue(test)) {
        doesNotContinueSequentially();
    }

    leaveBreakable(loopNode);
}
 
Example 13
Source File: CodeGenerator.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private void enterFor(final ForNode forNode) {
    final Expression init   = forNode.getInit();
    final Expression test   = forNode.getTest();
    final Block      body   = forNode.getBody();
    final Expression modify = forNode.getModify();

    if (init != null) {
        init.accept(this);
    }

    final Label loopLabel = new Label("loop");
    final Label testLabel = new Label("test");

    method._goto(testLabel);
    method.label(loopLabel);
    body.accept(this);
    method.label(forNode.getContinueLabel());

    if (!body.isTerminal() && modify != null) {
        load(modify);
    }

    method.label(testLabel);
    if (test != null) {
        new BranchOptimizer(this, method).execute(test, loopLabel, true);
    } else {
        method._goto(loopLabel);
    }

    method.label(forNode.getBreakLabel());
}
 
Example 14
Source File: AssignSymbols.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Define symbols for all variable declarations at the top of the function scope. This way we can get around
 * problems like
 *
 * while (true) {
 *   break;
 *   if (true) {
 *     var s;
 *   }
 * }
 *
 * to an arbitrary nesting depth.
 *
 * see NASHORN-73
 *
 * @param functionNode the FunctionNode we are entering
 * @param body the body of the FunctionNode we are entering
 */
private void acceptDeclarations(final FunctionNode functionNode, final Block body) {
    // This visitor will assign symbol to all declared variables.
    body.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
        @Override
        protected boolean enterDefault(final Node node) {
            // Don't bother visiting expressions; var is a statement, it can't be inside an expression.
            // This will also prevent visiting nested functions (as FunctionNode is an expression).
            return !(node instanceof Expression);
        }

        @Override
        public Node leaveVarNode(final VarNode varNode) {
            final IdentNode ident  = varNode.getName();
            final boolean blockScoped = varNode.isBlockScoped();
            if (blockScoped && lc.inUnprotectedSwitchContext()) {
                throwUnprotectedSwitchError(varNode);
            }
            final Block block = blockScoped ? lc.getCurrentBlock() : body;
            final Symbol symbol = defineSymbol(block, ident.getName(), ident, varNode.getSymbolFlags());
            if (varNode.isFunctionDeclaration()) {
                symbol.setIsFunctionDeclaration();
            }
            return varNode.setName(ident.setSymbol(symbol));
        }
    });
}
 
Example 15
Source File: AssignSymbols.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Define symbols for all variable declarations at the top of the function scope. This way we can get around
 * problems like
 *
 * while (true) {
 *   break;
 *   if (true) {
 *     var s;
 *   }
 * }
 *
 * to an arbitrary nesting depth.
 *
 * see NASHORN-73
 *
 * @param functionNode the FunctionNode we are entering
 * @param body the body of the FunctionNode we are entering
 */
private void acceptDeclarations(final FunctionNode functionNode, final Block body) {
    // This visitor will assign symbol to all declared variables.
    body.accept(new SimpleNodeVisitor() {
        @Override
        protected boolean enterDefault(final Node node) {
            // Don't bother visiting expressions; var is a statement, it can't be inside an expression.
            // This will also prevent visiting nested functions (as FunctionNode is an expression).
            return !(node instanceof Expression);
        }

        @Override
        public Node leaveVarNode(final VarNode varNode) {
            final IdentNode ident  = varNode.getName();
            final boolean blockScoped = varNode.isBlockScoped();
            if (blockScoped && lc.inUnprotectedSwitchContext()) {
                throwUnprotectedSwitchError(varNode);
            }
            final Block block = blockScoped ? lc.getCurrentBlock() : body;
            final Symbol symbol = defineSymbol(block, ident.getName(), ident, varNode.getSymbolFlags());
            if (varNode.isFunctionDeclaration()) {
                symbol.setIsFunctionDeclaration();
            }
            return varNode.setName(ident.setSymbol(symbol));
        }
    });
}
 
Example 16
Source File: PrintVisitor.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterIfNode(final IfNode ifNode) {
    ifNode.toString(sb);
    ifNode.getPass().accept(this);

    final Block fail = ifNode.getFail();

    if (fail != null) {
        sb.append(" else ");
        fail.accept(this);
    }

    return false;
}
 
Example 17
Source File: LocalVariableTypesCalculator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void enterTestFirstLoop(final LoopNode loopNode, final JoinPredecessorExpression modify,
        final Expression iteratorValues, final boolean iteratorValuesAreObject) {
    final JoinPredecessorExpression test = loopNode.getTest();
    if(isAlwaysFalse(test)) {
        visitExpressionOnEmptyStack(test);
        return;
    }

    final Label continueLabel = loopNode.getContinueLabel();
    final Label breakLabel = loopNode.getBreakLabel();

    final Label repeatLabel = modify == null ? continueLabel : new Label("");
    final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes;
    for(;;) {
        jumpToLabel(loopNode, repeatLabel, beforeLoopTypes);
        final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes;
        if(test != null) {
            visitExpressionOnEmptyStack(test);
        }
        if(!isAlwaysTrue(test)) {
            jumpToLabel(test, breakLabel);
        }
        if(iteratorValues instanceof IdentNode) {
            final IdentNode ident = (IdentNode)iteratorValues;
            // Receives iterator values; the optimistic type of the iterator values is tracked on the
            // identifier, but we override optimism if it's known that the object being iterated over will
            // never have primitive property names.
            onAssignment(ident, iteratorValuesAreObject ? LvarType.OBJECT :
                toLvarType(compiler.getOptimisticType(ident)));
        }
        final Block body = loopNode.getBody();
        body.accept(this);
        if(reachable) {
            jumpToLabel(body, continueLabel);
        }
        joinOnLabel(continueLabel);
        if(!reachable) {
            break;
        }
        if(modify != null) {
            visitExpressionOnEmptyStack(modify);
            jumpToLabel(modify, repeatLabel);
            joinOnLabel(repeatLabel);
        }
        if(localVariableTypes.equals(beforeRepeatTypes)) {
            break;
        }
        // Reset the join points and repeat the analysis
        resetJoinPoint(continueLabel);
        resetJoinPoint(breakLabel);
        resetJoinPoint(repeatLabel);
    }

    if(isAlwaysTrue(test) && iteratorValues == null) {
        doesNotContinueSequentially();
    }

    leaveBreakable(loopNode);
}
 
Example 18
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void enterTestFirstLoop(final LoopNode loopNode, final JoinPredecessorExpression modify,
        final Expression iteratorValues, final boolean iteratorValuesAreObject) {
    final JoinPredecessorExpression test = loopNode.getTest();
    if(isAlwaysFalse(test)) {
        visitExpressionOnEmptyStack(test);
        return;
    }

    final Label continueLabel = loopNode.getContinueLabel();
    final Label breakLabel = loopNode.getBreakLabel();

    final Label repeatLabel = modify == null ? continueLabel : new Label("");
    final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes;
    for(;;) {
        jumpToLabel(loopNode, repeatLabel, beforeLoopTypes);
        final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes;
        if(test != null) {
            visitExpressionOnEmptyStack(test);
        }
        if(!isAlwaysTrue(test)) {
            jumpToLabel(test, breakLabel);
        }
        if(iteratorValues instanceof IdentNode) {
            final IdentNode ident = (IdentNode)iteratorValues;
            // Receives iterator values; the optimistic type of the iterator values is tracked on the
            // identifier, but we override optimism if it's known that the object being iterated over will
            // never have primitive property names.
            onAssignment(ident, iteratorValuesAreObject ? LvarType.OBJECT :
                toLvarType(compiler.getOptimisticType(ident)));
        }
        final Block body = loopNode.getBody();
        body.accept(this);
        if(reachable) {
            jumpToLabel(body, continueLabel);
        }
        joinOnLabel(continueLabel);
        if(!reachable) {
            break;
        }
        if(modify != null) {
            visitExpressionOnEmptyStack(modify);
            jumpToLabel(modify, repeatLabel);
            joinOnLabel(repeatLabel);
        }
        if(localVariableTypes.equals(beforeRepeatTypes)) {
            break;
        }
        // Reset the join points and repeat the analysis
        resetJoinPoint(continueLabel);
        resetJoinPoint(breakLabel);
        resetJoinPoint(repeatLabel);
    }

    if(isAlwaysTrue(test) && iteratorValues == null) {
        doesNotContinueSequentially();
    }

    leaveBreakable(loopNode);
}
 
Example 19
Source File: CodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterTryNode(final TryNode tryNode) {
    lineNumber(tryNode);

    final Block       body        = tryNode.getBody();
    final List<Block> catchBlocks = tryNode.getCatchBlocks();
    final Symbol      symbol      = tryNode.getException();
    final Label       entry       = new Label("try");
    final Label       recovery    = new Label("catch");
    final Label       exit        = tryNode.getExit();
    final Label       skip        = new Label("skip");

    method.label(entry);

    body.accept(this);

    if (!body.hasTerminalFlags()) {
        method._goto(skip);
    }

    method.label(exit);

    method._catch(recovery);
    method.store(symbol);

    for (int i = 0; i < catchBlocks.size(); i++) {
        final Block catchBlock = catchBlocks.get(i);

        //TODO this is very ugly - try not to call enter/leave methods directly
        //better to use the implicit lexical context scoping given by the visitor's
        //accept method.
        lc.push(catchBlock);
        enterBlock(catchBlock);

        final CatchNode  catchNode          = (CatchNode)catchBlocks.get(i).getStatements().get(0);
        final IdentNode  exception          = catchNode.getException();
        final Expression exceptionCondition = catchNode.getExceptionCondition();
        final Block      catchBody          = catchNode.getBody();

        new Store<IdentNode>(exception) {
            @Override
            protected void storeNonDiscard() {
                return;
            }

            @Override
            protected void evaluate() {
                if (catchNode.isSyntheticRethrow()) {
                    method.load(symbol);
                    return;
                }
                /*
                 * If caught object is an instance of ECMAException, then
                 * bind obj.thrown to the script catch var. Or else bind the
                 * caught object itself to the script catch var.
                 */
                final Label notEcmaException = new Label("no_ecma_exception");
                method.load(symbol).dup()._instanceof(ECMAException.class).ifeq(notEcmaException);
                method.checkcast(ECMAException.class); //TODO is this necessary?
                method.getField(ECMAException.THROWN);
                method.label(notEcmaException);
            }
        }.store();

        final Label next;

        if (exceptionCondition != null) {
            next = new Label("next");
            load(exceptionCondition, Type.BOOLEAN).ifeq(next);
        } else {
            next = null;
        }

        catchBody.accept(this);

        if (i + 1 != catchBlocks.size() && !catchBody.hasTerminalFlags()) {
            method._goto(skip);
        }

        if (next != null) {
            if (i + 1 == catchBlocks.size()) {
                // no next catch block - rethrow if condition failed
                method._goto(skip);
                method.label(next);
                method.load(symbol).athrow();
            } else {
                method.label(next);
            }
        }

        leaveBlock(catchBlock);
        lc.pop(catchBlock);
    }

    method.label(skip);
    method._try(entry, exit, recovery, Throwable.class);

    // Finally body is always inlined elsewhere so it doesn't need to be emitted

    return false;
}
 
Example 20
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private void enterTestFirstLoop(final LoopNode loopNode, final JoinPredecessorExpression modify,
        final Expression iteratorValues, final boolean iteratorValuesAreObject) {
    final JoinPredecessorExpression test = loopNode.getTest();
    if(isAlwaysFalse(test)) {
        visitExpressionOnEmptyStack(test);
        return;
    }

    final Label continueLabel = loopNode.getContinueLabel();
    final Label breakLabel = loopNode.getBreakLabel();

    final Label repeatLabel = modify == null ? continueLabel : new Label("");
    final Map<Symbol, LvarType> beforeLoopTypes = localVariableTypes;
    for(;;) {
        jumpToLabel(loopNode, repeatLabel, beforeLoopTypes);
        final Map<Symbol, LvarType> beforeRepeatTypes = localVariableTypes;
        if(test != null) {
            visitExpressionOnEmptyStack(test);
        }
        if(!isAlwaysTrue(test)) {
            jumpToLabel(test, breakLabel);
        }
        if(iteratorValues instanceof IdentNode) {
            final IdentNode ident = (IdentNode)iteratorValues;
            // Receives iterator values; the optimistic type of the iterator values is tracked on the
            // identifier, but we override optimism if it's known that the object being iterated over will
            // never have primitive property names.
            onAssignment(ident, iteratorValuesAreObject ? LvarType.OBJECT :
                toLvarType(compiler.getOptimisticType(ident)));
        }
        final Block body = loopNode.getBody();
        body.accept(this);
        if(reachable) {
            jumpToLabel(body, continueLabel);
        }
        joinOnLabel(continueLabel);
        if(!reachable) {
            break;
        }
        if(modify != null) {
            visitExpressionOnEmptyStack(modify);
            jumpToLabel(modify, repeatLabel);
            joinOnLabel(repeatLabel);
        }
        if(localVariableTypes.equals(beforeRepeatTypes)) {
            break;
        }
        // Reset the join points and repeat the analysis
        resetJoinPoint(continueLabel);
        resetJoinPoint(breakLabel);
        resetJoinPoint(repeatLabel);
    }

    if(isAlwaysTrue(test) && iteratorValues == null) {
        doesNotContinueSequentially();
    }

    leaveBreakable(loopNode);
}