jdk.nashorn.internal.ir.Assignment Java Examples

The following examples show how to use jdk.nashorn.internal.ir.Assignment. 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: FinalizeTypes.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
<T extends Expression> SpecializedNode specialize(final Assignment<T> assignment) {
    final Node node = ((Node)assignment);
    final T lhs = assignment.getAssignmentDest();
    final Expression rhs = assignment.getAssignmentSource();

    if (!canHaveCallSiteType(lhs)) {
        return new SpecializedNode(node, null);
    }

    final Type to;
    if (node.isSelfModifying()) {
        to = node.getWidestOperationType();
    } else {
        to = rhs.getType();
    }

    if (!isSupportedCallSiteType(to)) {
        //meaningless to specialize to boolean or object
        return new SpecializedNode(node, null);
    }

    final Node newNode = assignment.setAssignmentDest(setTypeOverride(lhs, to));
    final Node typePropagatedNode;
    if(newNode instanceof Expression) {
        typePropagatedNode = propagateType((Expression)newNode, to);
    } else if(newNode instanceof VarNode) {
        // VarNode, being a statement, doesn't have its own symbol; it uses the symbol of its name instead.
        final VarNode varNode = (VarNode)newNode;
        typePropagatedNode = varNode.setName((IdentNode)propagateType(varNode.getName(), to));
    } else {
        throw new AssertionError();
    }
    return new SpecializedNode(typePropagatedNode, to);
}