jdk.nashorn.internal.ir.LoopNode Java Examples

The following examples show how to use jdk.nashorn.internal.ir.LoopNode. 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: Lower.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends LoopNode> T checkEscape(final T loopNode) {
    final boolean escapes = controlFlowEscapes(lc, loopNode.getBody());
    if (escapes) {
        return (T)loopNode.
            setBody(lc, loopNode.getBody().setIsTerminal(lc, false)).
            setControlFlowEscapes(lc, escapes);
    }
    return loopNode;
}
 
Example #2
Source File: CodeGenerator.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterContinueNode(final ContinueNode continueNode) {
    lineNumber(continueNode);

    final LoopNode continueTo = lc.getContinueTo(continueNode.getLabel());
    for (int i = 0; i < lc.getScopeNestingLevelTo(continueTo); i++) {
        closeWith();
    }
    method.splitAwareGoto(lc, continueTo.getContinueLabel());

    return false;
}
 
Example #3
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check for a loop counter. This is currently quite conservative, in that it only handles
 * x <= counter and x < counter.
 *
 * @param node loop node to check
 * @return
 */
private static Symbol findLoopCounter(final LoopNode node) {
    final Expression test = node.getTest();

    if (test != null && test.isComparison()) {
        final BinaryNode binaryNode = (BinaryNode)test;
        final Expression lhs = binaryNode.lhs();
        final Expression rhs = binaryNode.rhs();

        //detect ident cmp int_literal
        if (lhs instanceof IdentNode && rhs instanceof LiteralNode && ((LiteralNode<?>)rhs).getType().isInteger()) {
            final Symbol    symbol = lhs.getSymbol();
            final int       margin = ((LiteralNode<?>)rhs).getInt32();
            final TokenType op     = test.tokenType();

            switch (op) {
            case LT:
            case LE:
                symbol.setRange(RANGE.join(symbol.getRange(), Range.createRange(op == TokenType.LT ? margin - 1 : margin)));
                return symbol;
            case GT:
            case GE:
                //setRange(lhs, Range.createRange(op == TokenType.GT ? margin + 1 : margin));
                //return symbol;
            default:
                break;
            }
        }
    }

    return null;
}
 
Example #4
Source File: Lower.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private LoopNode checkEscape(final LoopNode loopNode) {
    final boolean escapes = controlFlowEscapes(lc, loopNode.getBody());
    if (escapes) {
        return loopNode.
            setBody(lc, loopNode.getBody().setIsTerminal(lc, false)).
            setControlFlowEscapes(lc, escapes);
    }
    return loopNode;
}
 
Example #5
Source File: Lower.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends LoopNode> T checkEscape(final T loopNode) {
    final boolean escapes = controlFlowEscapes(lc, loopNode.getBody());
    if (escapes) {
        return (T)loopNode.
            setBody(lc, loopNode.getBody().setIsTerminal(lc, false)).
            setControlFlowEscapes(lc, escapes);
    }
    return loopNode;
}
 
Example #6
Source File: CodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterContinueNode(final ContinueNode continueNode) {
    lineNumber(continueNode);

    final LoopNode continueTo = lc.getContinueTo(continueNode.getLabel());
    for (int i = 0; i < lc.getScopeNestingLevelTo(continueTo); i++) {
        closeWith();
    }
    method.splitAwareGoto(lc, continueTo.getContinueLabel());

    return false;
}
 
Example #7
Source File: RangeAnalyzer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check for a loop counter. This is currently quite conservative, in that it only handles
 * x <= counter and x < counter.
 *
 * @param node loop node to check
 * @return
 */
private static Symbol findLoopCounter(final LoopNode node) {
    final Expression test = node.getTest();

    if (test != null && test.isComparison()) {
        final BinaryNode binaryNode = (BinaryNode)test;
        final Expression lhs = binaryNode.lhs();
        final Expression rhs = binaryNode.rhs();

        //detect ident cmp int_literal
        if (lhs instanceof IdentNode && rhs instanceof LiteralNode && ((LiteralNode<?>)rhs).getType().isInteger()) {
            final Symbol    symbol = lhs.getSymbol();
            final int       margin = ((LiteralNode<?>)rhs).getInt32();
            final TokenType op     = test.tokenType();

            switch (op) {
            case LT:
            case LE:
                symbol.setRange(RANGE.join(symbol.getRange(), Range.createRange(op == TokenType.LT ? margin - 1 : margin)));
                return symbol;
            case GT:
            case GE:
                //setRange(lhs, Range.createRange(op == TokenType.GT ? margin + 1 : margin));
                //return symbol;
            default:
                break;
            }
        }
    }

    return null;
}
 
Example #8
Source File: Lower.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private LoopNode checkEscape(final LoopNode loopNode) {
    final boolean escapes = controlFlowEscapes(lc, loopNode.getBody());
    if (escapes) {
        return loopNode.
            setBody(lc, loopNode.getBody().setIsTerminal(lc, false)).
            setControlFlowEscapes(lc, escapes);
    }
    return loopNode;
}
 
Example #9
Source File: CodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterContinueNode(final ContinueNode continueNode) {
    lineNumber(continueNode);

    final LoopNode continueTo = lc.getContinueTo(continueNode.getLabel());
    for (int i = 0; i < lc.getScopeNestingLevelTo(continueTo); i++) {
        closeWith();
    }
    method.splitAwareGoto(lc, continueTo.getContinueLabel());

    return false;
}
 
Example #10
Source File: RangeAnalyzer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check for a loop counter. This is currently quite conservative, in that it only handles
 * x <= counter and x < counter.
 *
 * @param node loop node to check
 * @return
 */
private static Symbol findLoopCounter(final LoopNode node) {
    final Expression test = node.getTest();

    if (test != null && test.isComparison()) {
        final BinaryNode binaryNode = (BinaryNode)test;
        final Expression lhs = binaryNode.lhs();
        final Expression rhs = binaryNode.rhs();

        //detect ident cmp int_literal
        if (lhs instanceof IdentNode && rhs instanceof LiteralNode && ((LiteralNode<?>)rhs).getType().isInteger()) {
            final Symbol    symbol = lhs.getSymbol();
            final int       margin = ((LiteralNode<?>)rhs).getInt32();
            final TokenType op     = test.tokenType();

            switch (op) {
            case LT:
            case LE:
                symbol.setRange(RANGE.join(symbol.getRange(), Range.createRange(op == TokenType.LT ? margin - 1 : margin)));
                return symbol;
            case GT:
            case GE:
                //setRange(lhs, Range.createRange(op == TokenType.GT ? margin + 1 : margin));
                //return symbol;
            default:
                break;
            }
        }
    }

    return null;
}
 
Example #11
Source File: Lower.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private LoopNode checkEscape(final LoopNode loopNode) {
    final boolean escapes = controlFlowEscapes(lc, loopNode.getBody());
    if (escapes) {
        return loopNode.
            setBody(lc, loopNode.getBody().setIsTerminal(lc, false)).
            setControlFlowEscapes(lc, escapes);
    }
    return loopNode;
}
 
Example #12
Source File: Lower.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends LoopNode> T checkEscape(final T loopNode) {
    final boolean escapes = controlFlowEscapes(lc, loopNode.getBody());
    if (escapes) {
        return (T)loopNode.
            setBody(lc, loopNode.getBody().setIsTerminal(lc, false)).
            setControlFlowEscapes(lc, escapes);
    }
    return loopNode;
}
 
Example #13
Source File: Lower.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends LoopNode> T checkEscape(final T loopNode) {
    final boolean escapes = controlFlowEscapes(lc, loopNode.getBody());
    if (escapes) {
        return (T)loopNode.
            setBody(lc, loopNode.getBody().setIsTerminal(lc, false)).
            setControlFlowEscapes(lc, escapes);
    }
    return loopNode;
}
 
Example #14
Source File: Lower.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends LoopNode> T checkEscape(final T loopNode) {
    final boolean escapes = controlFlowEscapes(lc, loopNode.getBody());
    if (escapes) {
        return (T)loopNode.
            setBody(lc, loopNode.getBody().setIsTerminal(lc, false)).
            setControlFlowEscapes(lc, escapes);
    }
    return loopNode;
}
 
Example #15
Source File: Lower.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends LoopNode> T checkEscape(final T loopNode) {
    final boolean escapes = controlFlowEscapes(lc, loopNode.getBody());
    if (escapes) {
        return (T)loopNode.
            setBody(lc, loopNode.getBody().setIsTerminal(lc, false)).
            setControlFlowEscapes(lc, escapes);
    }
    return loopNode;
}
 
Example #16
Source File: Lower.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends LoopNode> T checkEscape(final T loopNode) {
    final boolean escapes = controlFlowEscapes(lc, loopNode.getBody());
    if (escapes) {
        return (T)loopNode.
            setBody(lc, loopNode.getBody().setIsTerminal(lc, false)).
            setControlFlowEscapes(lc, escapes);
    }
    return loopNode;
}
 
Example #17
Source File: Parser.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ContinueStatement :
 *      continue Identifier? ; // [no LineTerminator here]
 *
 * See 12.7
 *
 * Parse CONTINUE statement.
 */
private void continueStatement() {
    // Capture CONTINUE token.
    final int  continueLine  = line;
    final long continueToken = token;
    // CONTINUE tested in caller.
    nextOrEOL();

    LabelNode labelNode = null;

    // SEMICOLON or label.
    switch (type) {
    case RBRACE:
    case SEMICOLON:
    case EOL:
    case EOF:
        break;

    default:
        final IdentNode ident = getIdent();
        labelNode = lc.findLabel(ident.getName());

        if (labelNode == null) {
            throw error(AbstractParser.message("undefined.label", ident.getName()), ident.getToken());
        }

        break;
    }

    final String labelName = labelNode == null ? null : labelNode.getLabelName();
    final LoopNode targetNode = lc.getContinueTo(labelName);

    if (targetNode == null) {
        throw error(AbstractParser.message("illegal.continue.stmt"), continueToken);
    }

    endOfLine();

    // Construct and add CONTINUE node.
    appendStatement(new ContinueNode(continueLine, continueToken, finish, labelName));
}
 
Example #18
Source File: Parser.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ContinueStatement :
 *      continue Identifier? ; // [no LineTerminator here]
 *
 * See 12.7
 *
 * Parse CONTINUE statement.
 */
private void continueStatement() {
    // Capture CONTINUE token.
    final int  continueLine  = line;
    final long continueToken = token;
    // CONTINUE tested in caller.
    nextOrEOL();

    LabelNode labelNode = null;

    // SEMICOLON or label.
    switch (type) {
    case RBRACE:
    case SEMICOLON:
    case EOL:
    case EOF:
        break;

    default:
        final IdentNode ident = getIdent();
        labelNode = lc.findLabel(ident.getName());

        if (labelNode == null) {
            throw error(AbstractParser.message("undefined.label", ident.getName()), ident.getToken());
        }

        break;
    }

    final String labelName = labelNode == null ? null : labelNode.getLabelName();
    final LoopNode targetNode = lc.getContinueTo(labelName);

    if (targetNode == null) {
        throw error(AbstractParser.message("illegal.continue.stmt"), continueToken);
    }

    endOfLine();

    // Construct and add CONTINUE node.
    appendStatement(new ContinueNode(continueLine, continueToken, finish, labelName));
}
 
Example #19
Source File: RangeAnalyzer.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
private boolean isLoopCounter(final LoopNode loopNode, final Symbol symbol) {
    //this only works if loop nodes aren't replaced by other ones during this transform, but they are not
    return loopCounters.get(loopNode) == symbol;
}
 
Example #20
Source File: OptimisticTypesCalculator.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private void tagNeverOptimisticLoopTest(final LoopNode loopNode) {
    final JoinPredecessorExpression test = loopNode.getTest();
    if(test != null) {
        tagNeverOptimistic(test.getExpression());
    }
}
 
Example #21
Source File: LocalVariableTypesCalculator.java    From TencentKona-8 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 #22
Source File: Parser.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ContinueStatement :
 *      continue Identifier? ; // [no LineTerminator here]
 *
 * See 12.7
 *
 * Parse CONTINUE statement.
 */
private void continueStatement() {
    // Capture CONTINUE token.
    final int  continueLine  = line;
    final long continueToken = token;
    // CONTINUE tested in caller.
    nextOrEOL();

    LabelNode labelNode = null;

    // SEMICOLON or label.
    switch (type) {
    case RBRACE:
    case SEMICOLON:
    case EOL:
    case EOF:
        break;

    default:
        final IdentNode ident = getIdent();
        labelNode = lc.findLabel(ident.getName());

        if (labelNode == null) {
            throw error(AbstractParser.message("undefined.label", ident.getName()), ident.getToken());
        }

        break;
    }

    final IdentNode label = labelNode == null ? null : labelNode.getLabel();
    final LoopNode targetNode = lc.getContinueTo(label);

    if (targetNode == null) {
        throw error(AbstractParser.message("illegal.continue.stmt"), continueToken);
    }

    endOfLine();

    // Construct and add CONTINUE node.
    appendStatement(new ContinueNode(continueLine, continueToken, finish, label == null ? null : new IdentNode(label)));
}
 
Example #23
Source File: LocalVariableTypesCalculator.java    From jdk8u_nashorn 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 #24
Source File: OptimisticTypesCalculator.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
private void tagNeverOptimisticLoopTest(final LoopNode loopNode) {
    final JoinPredecessorExpression test = loopNode.getTest();
    if(test != null) {
        tagNeverOptimistic(test.getExpression());
    }
}
 
Example #25
Source File: Parser.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ContinueStatement :
 *      continue Identifier? ; // [no LineTerminator here]
 *
 * See 12.7
 *
 * Parse CONTINUE statement.
 */
private void continueStatement() {
    // Capture CONTINUE token.
    final int  continueLine  = line;
    final long continueToken = token;
    // CONTINUE tested in caller.
    nextOrEOL();

    LabelNode labelNode = null;

    // SEMICOLON or label.
    switch (type) {
    case RBRACE:
    case SEMICOLON:
    case EOL:
    case EOF:
        break;

    default:
        final IdentNode ident = getIdent();
        labelNode = lc.findLabel(ident.getName());

        if (labelNode == null) {
            throw error(AbstractParser.message("undefined.label", ident.getName()), ident.getToken());
        }

        break;
    }

    final String labelName = labelNode == null ? null : labelNode.getLabelName();
    final LoopNode targetNode = lc.getContinueTo(labelName);

    if (targetNode == null) {
        throw error(AbstractParser.message("illegal.continue.stmt"), continueToken);
    }

    endOfLine();

    // Construct and add CONTINUE node.
    appendStatement(new ContinueNode(continueLine, continueToken, finish, labelName));
}
 
Example #26
Source File: Parser.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ContinueStatement :
 *      continue Identifier? ; // [no LineTerminator here]
 *
 * See 12.7
 *
 * Parse CONTINUE statement.
 */
private void continueStatement() {
    // Capture CONTINUE token.
    final int  continueLine  = line;
    final long continueToken = token;
    // CONTINUE tested in caller.
    nextOrEOL();

    LabelNode labelNode = null;

    // SEMICOLON or label.
    switch (type) {
    case RBRACE:
    case SEMICOLON:
    case EOL:
    case EOF:
        break;

    default:
        final IdentNode ident = getIdent();
        labelNode = lc.findLabel(ident.getName());

        if (labelNode == null) {
            throw error(AbstractParser.message("undefined.label", ident.getName()), ident.getToken());
        }

        break;
    }

    final String labelName = labelNode == null ? null : labelNode.getLabelName();
    final LoopNode targetNode = lc.getContinueTo(labelName);

    if (targetNode == null) {
        throw error(AbstractParser.message("illegal.continue.stmt"), continueToken);
    }

    endOfLine();

    // Construct and add CONTINUE node.
    appendStatement(new ContinueNode(continueLine, continueToken, finish, labelName));
}
 
Example #27
Source File: RangeAnalyzer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean isLoopCounter(final LoopNode loopNode, final Symbol symbol) {
    //this only works if loop nodes aren't replaced by other ones during this transform, but they are not
    return loopCounters.get(loopNode) == symbol;
}
 
Example #28
Source File: OptimisticTypesCalculator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void tagNeverOptimisticLoopTest(final LoopNode loopNode) {
    final JoinPredecessorExpression test = loopNode.getTest();
    if(test != null) {
        tagNeverOptimistic(test.getExpression());
    }
}
 
Example #29
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 #30
Source File: Parser.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ContinueStatement :
 *      continue Identifier? ; // [no LineTerminator here]
 *
 * See 12.7
 *
 * Parse CONTINUE statement.
 */
private void continueStatement() {
    // Capture CONTINUE token.
    final int  continueLine  = line;
    final long continueToken = token;
    // CONTINUE tested in caller.
    nextOrEOL();

    LabelNode labelNode = null;

    // SEMICOLON or label.
    switch (type) {
    case RBRACE:
    case SEMICOLON:
    case EOL:
    case EOF:
        break;

    default:
        final IdentNode ident = getIdent();
        labelNode = lc.findLabel(ident.getName());

        if (labelNode == null) {
            throw error(AbstractParser.message("undefined.label", ident.getName()), ident.getToken());
        }

        break;
    }

    final IdentNode label = labelNode == null ? null : labelNode.getLabel();
    final LoopNode targetNode = lc.getContinueTo(label);

    if (targetNode == null) {
        throw error(AbstractParser.message("illegal.continue.stmt"), continueToken);
    }

    endOfLine();

    // Construct and add CONTINUE node.
    appendStatement(new ContinueNode(continueLine, continueToken, finish, label == null ? null : new IdentNode(label)));
}