Java Code Examples for jdk.nashorn.internal.ir.ReturnNode#getExpression()

The following examples show how to use jdk.nashorn.internal.ir.ReturnNode#getExpression() . 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 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 2
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 3
Source File: CodeGenerator.java    From nashorn 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 4
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 5
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 6
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 7
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 8
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 9
Source File: JSONWriter.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) {
    enterDefault(returnNode);

    type("ReturnStatement");
    comma();

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

    return leave();
}
 
Example 10
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 11
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 12
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 13
Source File: JSONWriter.java    From openjdk-jdk9 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 14
Source File: JSONWriter.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) {
    enterDefault(returnNode);

    type("ReturnStatement");
    comma();

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

    return leave();
}
 
Example 15
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 16
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 17
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 18
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 19
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 20
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;
}