jdk.nashorn.internal.ir.ThrowNode Java Examples

The following examples show how to use jdk.nashorn.internal.ir.ThrowNode. 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: JSONWriter.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    enterDefault(throwNode);

    type("ThrowStatement");
    comma();

    property("argument");
    throwNode.getExpression().accept(this);

    return leave();
}
 
Example #2
Source File: LocalVariableTypesCalculator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    if(!reachable) {
        return false;
    }

    visitExpressionOnEmptyStack(throwNode.getExpression());
    jumpToCatchBlock(throwNode);
    doesNotContinueSequentially();
    return false;
}
 
Example #3
Source File: Parser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ThrowStatement :
 *      throw Expression ; // [no LineTerminator here]
 *
 * See 12.13
 *
 * Parse throw statement.
 */
private void throwStatement() {
    // Capture THROW token.
    final int  throwLine  = line;
    final long throwToken = token;
    // THROW tested in caller.
    nextOrEOL();

    Expression expression = null;

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

    default:
        expression = expression();
        break;
    }

    if (expression == null) {
        throw error(AbstractParser.message("expected.operand", type.getNameOrType()));
    }

    endOfLine();

    appendStatement(new ThrowNode(throwLine, throwToken, finish, expression, false));
}
 
Example #4
Source File: Parser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ThrowStatement :
 *      throw Expression ; // [no LineTerminator here]
 *
 * See 12.13
 *
 * Parse throw statement.
 */
private void throwStatement() {
    // Capture THROW token.
    final int  throwLine  = line;
    final long throwToken = token;
    // THROW tested in caller.
    nextOrEOL();

    Expression expression = null;

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

    default:
        expression = expression();
        break;
    }

    if (expression == null) {
        throw error(AbstractParser.message("expected.operand", type.getNameOrType()));
    }

    endOfLine();

    appendStatement(new ThrowNode(throwLine, throwToken, finish, expression, false));
}
 
Example #5
Source File: JSONWriter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    enterDefault(throwNode);

    type("ThrowStatement");
    comma();

    property("argument");
    throwNode.getExpression().accept(this);

    return leave();
}
 
Example #6
Source File: LocalVariableTypesCalculator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    if(!reachable) {
        return false;
    }

    visitExpressionOnEmptyStack(throwNode.getExpression());
    jumpToCatchBlock(throwNode);
    doesNotContinueSequentially();
    return false;
}
 
Example #7
Source File: JSONWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    enterDefault(throwNode);

    type("ThrowStatement");
    comma();

    property("argument");
    throwNode.getExpression().accept(this);

    return leave();
}
 
Example #8
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    if(!reachable) {
        return false;
    }

    visitExpressionOnEmptyStack(throwNode.getExpression());
    jumpToCatchBlock(throwNode);
    doesNotContinueSequentially();
    return false;
}
 
Example #9
Source File: Parser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ThrowStatement :
 *      throw Expression ; // [no LineTerminator here]
 *
 * See 12.13
 *
 * Parse throw statement.
 */
private void throwStatement() {
    // Capture THROW token.
    final int  throwLine  = line;
    final long throwToken = token;
    // THROW tested in caller.
    nextOrEOL();

    Expression expression = null;

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

    default:
        expression = expression();
        break;
    }

    if (expression == null) {
        throw error(AbstractParser.message("expected.operand", type.getNameOrType()));
    }

    endOfLine();

    appendStatement(new ThrowNode(throwLine, throwToken, finish, expression, false));
}
 
Example #10
Source File: JSONWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    enterDefault(throwNode);

    type("ThrowStatement");
    comma();

    property("argument");
    throwNode.getExpression().accept(this);

    return leave();
}
 
Example #11
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    if(!reachable) {
        return false;
    }

    visitExpressionOnEmptyStack(throwNode.getExpression());
    jumpToCatchBlock(throwNode);
    doesNotContinueSequentially();
    return false;
}
 
Example #12
Source File: JSONWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    enterDefault(throwNode);

    type("ThrowStatement");
    comma();

    property("argument");
    throwNode.getExpression().accept(this);

    return leave();
}
 
Example #13
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    if(!reachable) {
        return false;
    }

    visitExpressionOnEmptyStack(throwNode.getExpression());
    jumpToCatchBlock(throwNode);
    doesNotContinueSequentially();
    return false;
}
 
Example #14
Source File: JSONWriter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    enterDefault(throwNode);

    type("ThrowStatement");
    comma();

    property("argument");
    throwNode.getExpression().accept(this);

    return leave();
}
 
Example #15
Source File: Parser.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ThrowStatement :
 *      throw Expression ; // [no LineTerminator here]
 *
 * See 12.13
 *
 * Parse throw statement.
 */
private void throwStatement() {
    // Capture THROW token.
    final int  throwLine  = line;
    final long throwToken = token;
    // THROW tested in caller.
    nextOrEOL();

    Expression expression = null;

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

    default:
        expression = expression();
        break;
    }

    if (expression == null) {
        throw error(AbstractParser.message("expected.operand", type.getNameOrType()));
    }

    endOfLine();

    appendStatement(new ThrowNode(throwLine, throwToken, finish, expression, 0));
}
 
Example #16
Source File: LocalVariableTypesCalculator.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    if(!reachable) {
        return false;
    }

    visitExpressionOnEmptyStack(throwNode.getExpression());
    jumpToCatchBlock(throwNode);
    doesNotContinueSequentially();
    return false;
}
 
Example #17
Source File: JSONWriter.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    enterDefault(throwNode);

    type("ThrowStatement");
    comma();

    property("argument");
    throwNode.getExpression().accept(this);

    return leave();
}
 
Example #18
Source File: Parser.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ThrowStatement :
 *      throw Expression ; // [no LineTerminator here]
 *
 * See 12.13
 *
 * Parse throw statement.
 */
private void throwStatement() {
    // Capture THROW token.
    final int  throwLine  = line;
    final long throwToken = token;
    // THROW tested in caller.
    nextOrEOL();

    Expression expression = null;

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

    default:
        expression = expression();
        break;
    }

    if (expression == null) {
        throw error(AbstractParser.message("expected.operand", type.getNameOrType()));
    }

    endOfLine();

    appendStatement(new ThrowNode(throwLine, throwToken, finish, expression, false));
}
 
Example #19
Source File: CodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    lineNumber(throwNode);

    if (throwNode.isSyntheticRethrow()) {
        //do not wrap whatever this is in an ecma exception, just rethrow it
        load(throwNode.getExpression());
        method.athrow();
        return false;
    }

    method._new(ECMAException.class).dup();

    final Source source     = lc.getCurrentFunction().getSource();

    final Expression expression = throwNode.getExpression();
    final int        position   = throwNode.position();
    final int        line       = throwNode.getLineNumber();
    final int        column     = source.getColumn(position);

    load(expression, Type.OBJECT);

    method.load(source.getName());
    method.load(line);
    method.load(column);
    method.invoke(ECMAException.THROW_INIT);

    method.athrow();

    return false;
}
 
Example #20
Source File: JSONWriter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    enterDefault(throwNode);

    type("ThrowStatement");
    comma();

    property("argument");
    throwNode.getExpression().accept(this);

    return leave();
}
 
Example #21
Source File: Parser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ThrowStatement :
 *      throw Expression ; // [no LineTerminator here]
 *
 * See 12.13
 *
 * Parse throw statement.
 */
private void throwStatement() {
    // Capture THROW token.
    final int  throwLine  = line;
    final long throwToken = token;
    // THROW tested in caller.
    nextOrEOL();

    Expression expression = null;

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

    default:
        expression = expression();
        break;
    }

    if (expression == null) {
        throw error(AbstractParser.message("expected.operand", type.getNameOrType()));
    }

    endOfLine();

    appendStatement(new ThrowNode(throwLine, throwToken, finish, expression, 0));
}
 
Example #22
Source File: CodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    lineNumber(throwNode);

    if (throwNode.isSyntheticRethrow()) {
        //do not wrap whatever this is in an ecma exception, just rethrow it
        load(throwNode.getExpression());
        method.athrow();
        return false;
    }

    method._new(ECMAException.class).dup();

    final Source source     = lc.getCurrentFunction().getSource();

    final Expression expression = throwNode.getExpression();
    final int        position   = throwNode.position();
    final int        line       = throwNode.getLineNumber();
    final int        column     = source.getColumn(position);

    load(expression, Type.OBJECT);

    method.load(source.getName());
    method.load(line);
    method.load(column);
    method.invoke(ECMAException.THROW_INIT);

    method.athrow();

    return false;
}
 
Example #23
Source File: JSONWriter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    enterDefault(throwNode);

    type("ThrowStatement");
    comma();

    property("argument");
    throwNode.getExpression().accept(this);

    return leave();
}
 
Example #24
Source File: Parser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ThrowStatement :
 *      throw Expression ; // [no LineTerminator here]
 *
 * See 12.13
 *
 * Parse throw statement.
 */
private void throwStatement() {
    // Capture THROW token.
    final int  throwLine  = line;
    final long throwToken = token;
    // THROW tested in caller.
    nextOrEOL();

    Expression expression = null;

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

    default:
        expression = expression();
        break;
    }

    if (expression == null) {
        throw error(AbstractParser.message("expected.operand", type.getNameOrType()));
    }

    endOfLine();

    appendStatement(new ThrowNode(throwLine, throwToken, finish, expression, 0));
}
 
Example #25
Source File: LocalVariableTypesCalculator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
    if(!reachable) {
        return false;
    }

    visitExpressionOnEmptyStack(throwNode.getExpression());
    jumpToCatchBlock(throwNode);
    doesNotContinueSequentially();
    return false;
}
 
Example #26
Source File: Parser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ThrowStatement :
 *      throw Expression ; // [no LineTerminator here]
 *
 * See 12.13
 *
 * Parse throw statement.
 */
private void throwStatement() {
    // Capture THROW token.
    final int  throwLine  = line;
    final long throwToken = token;
    // THROW tested in caller.
    nextOrEOL();

    Expression expression = null;

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

    default:
        expression = expression();
        break;
    }

    if (expression == null) {
        throw error(AbstractParser.message("expected.operand", type.getNameOrType()));
    }

    endOfLine();

    appendStatement(new ThrowNode(throwLine, throwToken, finish, expression, false));
}
 
Example #27
Source File: Lower.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Splice finally code into all endpoints of a trynode
 * @param tryNode the try node
 * @param rethrow the rethrowing throw nodes from the synthetic catch block
 * @param finallyBody the code in the original finally block
 * @return new try node after splicing finally code (same if nop)
 */
private TryNode spliceFinally(final TryNode tryNode, final ThrowNode rethrow, final Block finallyBody) {
    assert tryNode.getFinallyBody() == null;

    final Block finallyBlock = createFinallyBlock(finallyBody);
    final ArrayList<Block> inlinedFinallies = new ArrayList<>();
    final FunctionNode fn = lc.getCurrentFunction();
    final TryNode newTryNode = (TryNode)tryNode.accept(new SimpleNodeVisitor() {

        @Override
        public boolean enterFunctionNode(final FunctionNode functionNode) {
            // do not enter function nodes - finally code should not be inlined into them
            return false;
        }

        @Override
        public Node leaveThrowNode(final ThrowNode throwNode) {
            if (rethrow == throwNode) {
                return new BlockStatement(prependFinally(finallyBlock, throwNode));
            }
            return throwNode;
        }

        @Override
        public Node leaveBreakNode(final BreakNode breakNode) {
            return leaveJumpStatement(breakNode);
        }

        @Override
        public Node leaveContinueNode(final ContinueNode continueNode) {
            return leaveJumpStatement(continueNode);
        }

        private Node leaveJumpStatement(final JumpStatement jump) {
            // NOTE: leaveJumpToInlinedFinally deliberately does not delegate to this method, only break and
            // continue are edited. JTIF nodes should not be changed, rather the surroundings of
            // break/continue/return that were moved into the inlined finally block itself will be changed.

            // If this visitor's lc doesn't find the target of the jump, it means it's external to the try block.
            if (jump.getTarget(lc) == null) {
                return createJumpToInlinedFinally(fn, inlinedFinallies, prependFinally(finallyBlock, jump));
            }
            return jump;
        }

        @Override
        public Node leaveReturnNode(final ReturnNode returnNode) {
            final Expression expr = returnNode.getExpression();
            if (isTerminalFinally(finallyBlock)) {
                if (expr == null) {
                    // Terminal finally; no return expression.
                    return createJumpToInlinedFinally(fn, inlinedFinallies, ensureUniqueNamesIn(finallyBlock));
                }
                // Terminal finally; has a return expression.
                final List<Statement> newStatements = new ArrayList<>(2);
                final int retLineNumber = returnNode.getLineNumber();
                final long retToken = returnNode.getToken();
                // Expression is evaluated for side effects.
                newStatements.add(new ExpressionStatement(retLineNumber, retToken, returnNode.getFinish(), expr));
                newStatements.add(createJumpToInlinedFinally(fn, inlinedFinallies, ensureUniqueNamesIn(finallyBlock)));
                return new BlockStatement(retLineNumber, new Block(retToken, finallyBlock.getFinish(), newStatements));
            } else if (expr == null || expr instanceof PrimitiveLiteralNode<?> || (expr instanceof IdentNode && RETURN.symbolName().equals(((IdentNode)expr).getName()))) {
                // Nonterminal finally; no return expression, or returns a primitive literal, or returns :return.
                // Just move the return expression into the finally block.
                return createJumpToInlinedFinally(fn, inlinedFinallies, prependFinally(finallyBlock, returnNode));
            } else {
                // We need to evaluate the result of the return in case it is complex while still in the try block,
                // store it in :return, and return it afterwards.
                final List<Statement> newStatements = new ArrayList<>();
                final int retLineNumber = returnNode.getLineNumber();
                final long retToken = returnNode.getToken();
                final int retFinish = returnNode.getFinish();
                final Expression resultNode = new IdentNode(expr.getToken(), expr.getFinish(), RETURN.symbolName());
                // ":return = <expr>;"
                newStatements.add(new ExpressionStatement(retLineNumber, retToken, retFinish, new BinaryNode(Token.recast(returnNode.getToken(), TokenType.ASSIGN), resultNode, expr)));
                // inline finally and end it with "return :return;"
                newStatements.add(createJumpToInlinedFinally(fn, inlinedFinallies, prependFinally(finallyBlock, returnNode.setExpression(resultNode))));
                return new BlockStatement(retLineNumber, new Block(retToken, retFinish, newStatements));
            }
        }
    });
    addStatement(inlinedFinallies.isEmpty() ? newTryNode : newTryNode.setInlinedFinallies(lc, inlinedFinallies));
    // TODO: if finallyStatement is terminal, we could just have sites of inlined finallies jump here.
    addStatement(new BlockStatement(finallyBlock));

    return newTryNode;
}
 
Example #28
Source File: Lower.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveThrowNode(final ThrowNode throwNode) {
    return addStatement(throwNode); //ThrowNodes are always terminal, marked as such in constructor
}
 
Example #29
Source File: PrintVisitor.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode node) {
    node.toString(sb, printTypes);
    printLocalVariableConversion(node);
    return false;
}
 
Example #30
Source File: PrintVisitor.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterThrowNode(final ThrowNode node) {
    node.toString(sb, printTypes);
    printLocalVariableConversion(node);
    return false;
}