Java Code Examples for jdk.nashorn.internal.ir.WhileNode#setBody()

The following examples show how to use jdk.nashorn.internal.ir.WhileNode#setBody() . 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: Parser.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ...IterationStatement :
 *           ...
 *           while ( Expression ) Statement
 *           ...
 *
 * See 12.6
 *
 * Parse while statement.
 */
private void whileStatement() {
    // Capture WHILE token.
    final int  whileLine  = line;
    final long whileToken = token;
    // WHILE tested in caller.
    next();

    // Construct WHILE node.
    WhileNode whileNode = new WhileNode(whileLine, whileToken, Token.descPosition(whileToken), false);
    lc.push(whileNode);

    try {
        expect(LPAREN);
        whileNode = whileNode.setTest(lc, expression());
        expect(RPAREN);
        whileNode = whileNode.setBody(lc, getStatement());
        appendStatement(whileNode);
    } finally {
        lc.pop(whileNode);
    }
}
 
Example 2
Source File: Parser.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ...IterationStatement :
 *           ...
 *           do Statement while( Expression ) ;
 *           ...
 *
 * See 12.6
 *
 * Parse DO WHILE statement.
 */
private void doStatement() {
    // Capture DO token.
    final int  doLine  = line;
    final long doToken = token;
    // DO tested in the caller.
    next();

    WhileNode doWhileNode = new WhileNode(doLine, doToken, Token.descPosition(doToken), true);
    lc.push(doWhileNode);

    try {
       // Get DO body.
        doWhileNode = doWhileNode.setBody(lc, getStatement());

        expect(WHILE);
        expect(LPAREN);
        doWhileNode = doWhileNode.setTest(lc, expression());
        expect(RPAREN);

        if (type == SEMICOLON) {
            endOfLine();
        }
        doWhileNode.setFinish(finish);
        appendStatement(doWhileNode);
    } finally {
        lc.pop(doWhileNode);
    }
}