jdk.nashorn.internal.ir.ReturnNode Java Examples

The following examples show how to use jdk.nashorn.internal.ir.ReturnNode. 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 nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveBlock(final Block block) {
    //now we have committed the entire statement list to the block, but we need to truncate
    //whatever is after the last terminal. block append won't append past it


    if (lc.isFunctionBody()) {
        final FunctionNode currentFunction = lc.getCurrentFunction();
        final boolean isProgram = currentFunction.isProgram();
        final Statement last = lc.getLastStatement();
        final ReturnNode returnNode = new ReturnNode(
            last == null ? currentFunction.getLineNumber() : last.getLineNumber(), //TODO?
            currentFunction.getToken(),
            currentFunction.getFinish(),
            isProgram ?
                compilerConstant(RETURN) :
                LiteralNode.newInstance(block, ScriptRuntime.UNDEFINED));

        returnNode.accept(this);
    }

    return block;
}
 
Example #2
Source File: JSONWriter.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    enterDefault(returnNode);

    type("ReturnStatement");
    comma();

    final Node arg = returnNode.getExpression();
    property("argument");
    if (arg != null) {
        arg.accept(this);
    } else {
        nullValue();
    }

    return leave();
}
 
Example #3
Source File: JSONWriter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    enterDefault(returnNode);

    type("ReturnStatement");
    comma();

    final Node arg = returnNode.getExpression();
    property("argument");
    if (arg != null) {
        arg.accept(this);
    } else {
        nullValue();
    }

    return leave();
}
 
Example #4
Source File: CodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    lineNumber(returnNode);

    method.registerReturn();

    final Type returnType = lc.getCurrentFunction().getReturnType();

    final Expression expression = returnNode.getExpression();
    if (expression != null) {
        load(expression);
    } else {
        method.loadUndefined(returnType);
    }

    method._return(returnType);

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

    final Expression returnExpr = returnNode.getExpression();
    final Type returnExprType;
    if(returnExpr != null) {
        returnExprType = visitExpressionOnEmptyStack(returnExpr).type;
    } else {
        assertTypeStackIsEmpty();
        returnExprType = Type.UNDEFINED;
    }
    returnType = Type.widestReturnType(returnType, returnExprType);
    doesNotContinueSequentially();
    return false;
}
 
Example #6
Source File: Lower.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveBlock(final Block block) {
    //now we have committed the entire statement list to the block, but we need to truncate
    //whatever is after the last terminal. block append won't append past it


    if (lc.isFunctionBody()) {
        final FunctionNode currentFunction = lc.getCurrentFunction();
        final boolean isProgram = currentFunction.isProgram();
        final Statement last = lc.getLastStatement();
        final ReturnNode returnNode = new ReturnNode(
            last == null ? currentFunction.getLineNumber() : last.getLineNumber(), //TODO?
            currentFunction.getToken(),
            currentFunction.getFinish(),
            isProgram ?
                compilerConstant(RETURN) :
                LiteralNode.newInstance(block, ScriptRuntime.UNDEFINED));

        returnNode.accept(this);
    }

    return block;
}
 
Example #7
Source File: JSONWriter.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    enterDefault(returnNode);

    type("ReturnStatement");
    comma();

    final Node arg = returnNode.getExpression();
    property("argument");
    if (arg != null) {
        arg.accept(this);
    } else {
        nullValue();
    }

    return leave();
}
 
Example #8
Source File: Attr.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveReturnNode(final ReturnNode returnNode) {
    final Expression expr = returnNode.getExpression();
    final Type returnType;

    if (expr != null) {
        //we can't do parameter specialization if we return something that hasn't been typed yet
        final Symbol symbol = expr.getSymbol();
        if (expr.getType().isUnknown() && symbol.isParam()) {
            symbol.setType(Type.OBJECT);
        }

        returnType = Type.widest(returnTypes.pop(), symbol.getSymbolType());
    } else {
        returnType = Type.OBJECT; //undefined
    }
    LOG.info("Returntype is now ", returnType);
    returnTypes.push(returnType);

    end(returnNode);

    return returnNode;
}
 
Example #9
Source File: Attr.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveReturnNode(final ReturnNode returnNode) {
    final Expression expr = returnNode.getExpression();
    final Type returnType;

    if (expr != null) {
        //we can't do parameter specialization if we return something that hasn't been typed yet
        final Symbol symbol = expr.getSymbol();
        if (expr.getType().isUnknown() && symbol.isParam()) {
            symbol.setType(Type.OBJECT);
        }

        returnType = widestReturnType(returnTypes.pop(), symbol.getSymbolType());
    } else {
        returnType = Type.OBJECT; //undefined
    }
    LOG.info("Returntype is now ", returnType);
    returnTypes.push(returnType);

    end(returnNode);

    return returnNode;
}
 
Example #10
Source File: Lower.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveBlock(final Block block) {
    //now we have committed the entire statement list to the block, but we need to truncate
    //whatever is after the last terminal. block append won't append past it


    if (lc.isFunctionBody()) {
        final FunctionNode currentFunction = lc.getCurrentFunction();
        final boolean isProgram = currentFunction.isProgram();
        final Statement last = lc.getLastStatement();
        final ReturnNode returnNode = new ReturnNode(
            last == null ? currentFunction.getLineNumber() : last.getLineNumber(), //TODO?
            currentFunction.getToken(),
            currentFunction.getFinish(),
            isProgram ?
                compilerConstant(RETURN) :
                LiteralNode.newInstance(block, ScriptRuntime.UNDEFINED));

        returnNode.accept(this);
    }

    return block;
}
 
Example #11
Source File: JSONWriter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    enterDefault(returnNode);

    type("ReturnStatement");
    comma();

    final Node arg = returnNode.getExpression();
    property("argument");
    if (arg != null) {
        arg.accept(this);
    } else {
        nullValue();
    }

    return leave();
}
 
Example #12
Source File: JSONWriter.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    enterDefault(returnNode);

    type("ReturnStatement");
    comma();

    final Node arg = returnNode.getExpression();
    property("argument");
    if (arg != null) {
        arg.accept(this);
    } else {
        nullValue();
    }

    return leave();
}
 
Example #13
Source File: LocalVariableTypesCalculator.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    if(!reachable) {
        return false;
    }

    final Expression returnExpr = returnNode.getExpression();
    final Type returnExprType;
    if(returnExpr != null) {
        returnExprType = visitExpressionOnEmptyStack(returnExpr).type;
    } else {
        assertTypeStackIsEmpty();
        returnExprType = Type.UNDEFINED;
    }
    returnType = Type.widestReturnType(returnType, returnExprType);
    doesNotContinueSequentially();
    return false;
}
 
Example #14
Source File: LocalVariableTypesCalculator.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    if(!reachable) {
        return false;
    }

    final Expression returnExpr = returnNode.getExpression();
    final Type returnExprType;
    if(returnExpr != null) {
        returnExprType = visitExpressionOnEmptyStack(returnExpr).type;
    } else {
        assertTypeStackIsEmpty();
        returnExprType = Type.UNDEFINED;
    }
    returnType = Type.widestReturnType(returnType, returnExprType);
    doesNotContinueSequentially();
    return false;
}
 
Example #15
Source File: LocalVariableTypesCalculator.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    if(!reachable) {
        return false;
    }

    final Expression returnExpr = returnNode.getExpression();
    final Type returnExprType;
    if(returnExpr != null) {
        returnExprType = visitExpressionOnEmptyStack(returnExpr).type;
    } else {
        assertTypeStackIsEmpty();
        returnExprType = Type.UNDEFINED;
    }
    returnType = Type.widestReturnType(returnType, returnExprType);
    doesNotContinueSequentially();
    return false;
}
 
Example #16
Source File: Attr.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveReturnNode(final ReturnNode returnNode) {
    final Expression expr = returnNode.getExpression();
    final Type returnType;

    if (expr != null) {
        //we can't do parameter specialization if we return something that hasn't been typed yet
        final Symbol symbol = expr.getSymbol();
        if (expr.getType().isUnknown() && symbol.isParam()) {
            symbol.setType(Type.OBJECT);
        }

        returnType = widestReturnType(returnTypes.pop(), symbol.getSymbolType());
    } else {
        returnType = Type.OBJECT; //undefined
    }
    LOG.info("Returntype is now ", returnType);
    returnTypes.push(returnType);

    end(returnNode);

    return returnNode;
}
 
Example #17
Source File: JSONWriter.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    enterDefault(returnNode);

    type("ReturnStatement");
    comma();

    final Node arg = returnNode.getExpression();
    property("argument");
    if (arg != null) {
        arg.accept(this);
    } else {
        nullValue();
    }

    return leave();
}
 
Example #18
Source File: JSONWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    enterDefault(returnNode);

    type("ReturnStatement");
    comma();

    final Node arg = returnNode.getExpression();
    property("argument");
    if (arg != null) {
        arg.accept(this);
    } else {
        nullValue();
    }

    return leave();
}
 
Example #19
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    if(!reachable) {
        return false;
    }

    final Expression returnExpr = returnNode.getExpression();
    final Type returnExprType;
    if(returnExpr != null) {
        returnExprType = visitExpressionOnEmptyStack(returnExpr).type;
    } else {
        assertTypeStackIsEmpty();
        returnExprType = Type.UNDEFINED;
    }
    returnType = Type.widestReturnType(returnType, returnExprType);
    doesNotContinueSequentially();
    return false;
}
 
Example #20
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    if(!reachable) {
        return false;
    }

    final Expression returnExpr = returnNode.getExpression();
    final Type returnExprType;
    if(returnExpr != null) {
        returnExprType = visitExpressionOnEmptyStack(returnExpr).type;
    } else {
        assertTypeStackIsEmpty();
        returnExprType = Type.UNDEFINED;
    }
    returnType = Type.widestReturnType(returnType, returnExprType);
    doesNotContinueSequentially();
    return false;
}
 
Example #21
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    if(!reachable) {
        return false;
    }

    final Expression returnExpr = returnNode.getExpression();
    final Type returnExprType;
    if(returnExpr != null) {
        returnExprType = visitExpressionOnEmptyStack(returnExpr).type;
    } else {
        assertTypeStackIsEmpty();
        returnExprType = Type.UNDEFINED;
    }
    returnType = Type.widestReturnType(returnType, returnExprType);
    doesNotContinueSequentially();
    return false;
}
 
Example #22
Source File: LocalVariableTypesCalculator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void createSyntheticReturn(final Block body) {
    final FunctionNode functionNode = lc.getCurrentFunction();
    final long token = functionNode.getToken();
    final int finish = functionNode.getFinish();
    final List<Statement> statements = body.getStatements();
    final int lineNumber = statements.isEmpty() ? functionNode.getLineNumber() : statements.get(statements.size() - 1).getLineNumber();
    final IdentNode returnExpr;
    if(functionNode.isProgram()) {
        returnExpr = new IdentNode(token, finish, RETURN.symbolName()).setSymbol(getCompilerConstantSymbol(functionNode, RETURN));
    } else {
        returnExpr = null;
    }
    syntheticReturn = new ReturnNode(lineNumber, token, finish, returnExpr);
    syntheticReturn.accept(this);
}
 
Example #23
Source File: Parser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ReturnStatement :
 *      return Expression? ; // [no LineTerminator here]
 *
 * See 12.9
 *
 * Parse RETURN statement.
 */
private void returnStatement() {
    // check for return outside function
    if (lc.getCurrentFunction().getKind() == FunctionNode.Kind.SCRIPT) {
        throw error(AbstractParser.message("invalid.return"));
    }

    // Capture RETURN token.
    final int  returnLine  = line;
    final long returnToken = token;
    // RETURN tested in caller.
    nextOrEOL();

    Expression expression = null;

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

    default:
        expression = expression();
        break;
    }

    endOfLine();

    // Construct and add RETURN node.
    appendStatement(new ReturnNode(returnLine, returnToken, finish, expression));
}
 
Example #24
Source File: Parser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ReturnStatement :
 *      return Expression? ; // [no LineTerminator here]
 *
 * See 12.9
 *
 * Parse RETURN statement.
 */
private void returnStatement() {
    // check for return outside function
    if (lc.getCurrentFunction().getKind() == FunctionNode.Kind.SCRIPT) {
        throw error(AbstractParser.message("invalid.return"));
    }

    // Capture RETURN token.
    final int  returnLine  = line;
    final long returnToken = token;
    // RETURN tested in caller.
    nextOrEOL();

    Expression expression = null;

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

    default:
        expression = expression();
        break;
    }

    endOfLine();

    // Construct and add RETURN node.
    appendStatement(new ReturnNode(returnLine, returnToken, finish, expression));
}
 
Example #25
Source File: Parser.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * YieldStatement :
 *      yield Expression? ; // [no LineTerminator here]
 *
 * JavaScript 1.8
 *
 * Parse YIELD statement.
 */
private void yieldStatement() {
    // Capture YIELD token.
    final int  yieldLine  = line;
    final long yieldToken = token;
    // YIELD tested in caller.
    nextOrEOL();

    Expression expression = null;

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

    default:
        expression = expression();
        break;
    }

    endOfLine();

    // Construct and add YIELD node.
    appendStatement(new ReturnNode(yieldLine, yieldToken, finish, expression));
}
 
Example #26
Source File: FinalizeTypes.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveReturnNode(final ReturnNode returnNode) {
    final Expression expr = returnNode.getExpression();
    if (expr != null) {
        return returnNode.setExpression(convert(expr, lc.getCurrentFunction().getReturnType()));
    }
    return returnNode;
}
 
Example #27
Source File: Parser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ReturnStatement :
 *      return Expression? ; // [no LineTerminator here]
 *
 * See 12.9
 *
 * Parse RETURN statement.
 */
private void returnStatement() {
    // check for return outside function
    if (lc.getCurrentFunction().getKind() == FunctionNode.Kind.SCRIPT) {
        throw error(AbstractParser.message("invalid.return"));
    }

    // Capture RETURN token.
    final int  returnLine  = line;
    final long returnToken = token;
    // RETURN tested in caller.
    nextOrEOL();

    Expression expression = null;

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

    default:
        expression = expression();
        break;
    }

    endOfLine();

    // Construct and add RETURN node.
    appendStatement(new ReturnNode(returnLine, returnToken, finish, expression));
}
 
Example #28
Source File: Parser.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * YieldStatement :
 *      yield Expression? ; // [no LineTerminator here]
 *
 * JavaScript 1.8
 *
 * Parse YIELD statement.
 */
private void yieldStatement() {
    // Capture YIELD token.
    final int  yieldLine  = line;
    final long yieldToken = token;
    // YIELD tested in caller.
    nextOrEOL();

    Expression expression = null;

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

    default:
        expression = expression();
        break;
    }

    endOfLine();

    // Construct and add YIELD node.
    appendStatement(new ReturnNode(yieldLine, yieldToken, finish, expression));
}
 
Example #29
Source File: SplitIntoFunctions.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveReturnNode(final ReturnNode returnNode) {
    if(inSplitNode()) {
        appendStatement(new SetSplitState(RETURN_STATE, returnNode.getLineNumber()));
        getCurrentSplitState().hasReturn = true;
    }
    appendStatement(returnNode);
    return returnNode;
}
 
Example #30
Source File: Parser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * YieldStatement :
 *      yield Expression? ; // [no LineTerminator here]
 *
 * JavaScript 1.8
 *
 * Parse YIELD statement.
 */
private void yieldStatement() {
    // Capture YIELD token.
    final int  yieldLine  = line;
    final long yieldToken = token;
    // YIELD tested in caller.
    nextOrEOL();

    Expression expression = null;

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

    default:
        expression = expression();
        break;
    }

    endOfLine();

    // Construct and add YIELD node.
    appendStatement(new ReturnNode(yieldLine, yieldToken, finish, expression));
}