jdk.nashorn.internal.ir.UnaryNode Java Examples

The following examples show how to use jdk.nashorn.internal.ir.UnaryNode. 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: AssignSymbols.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private Node leaveTYPEOF(final UnaryNode unaryNode) {
    final Expression rhs = unaryNode.getExpression();

    final List<Expression> args = new ArrayList<>();
    if (rhs instanceof IdentNode && !isParamOrVar((IdentNode)rhs)) {
        args.add(compilerConstantIdentifier(SCOPE));
        args.add(LiteralNode.newInstance(rhs, ((IdentNode)rhs).getName())); //null
    } else {
        args.add(rhs);
        args.add(LiteralNode.newInstance(unaryNode)); //null, do not reuse token of identifier rhs, it can be e.g. 'this'
    }

    final Node runtimeNode = new RuntimeNode(unaryNode, Request.TYPEOF, args);

    end(unaryNode);

    return runtimeNode;
}
 
Example #2
Source File: AssignSymbols.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private Node leaveTYPEOF(final UnaryNode unaryNode) {
    final Expression rhs = unaryNode.getExpression();

    final List<Expression> args = new ArrayList<>();
    if (rhs instanceof IdentNode && !isParamOrVar((IdentNode)rhs)) {
        args.add(compilerConstantIdentifier(SCOPE));
        args.add((Expression)LiteralNode.newInstance(rhs, ((IdentNode)rhs).getName()).accept(this)); //null
    } else {
        args.add(rhs);
        args.add((Expression)LiteralNode.newInstance(unaryNode).accept(this)); //null, do not reuse token of identifier rhs, it can be e.g. 'this'
    }

    final Node runtimeNode = new RuntimeNode(unaryNode, Request.TYPEOF, args).accept(this);

    end(unaryNode);

    return runtimeNode;
}
 
Example #3
Source File: BranchOptimizer.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
private void branchOptimizer(final UnaryNode unaryNode, final Label label, final boolean state) {
    final Expression rhs = unaryNode.rhs();

    switch (unaryNode.tokenType()) {
    case NOT:
        branchOptimizer(rhs, label, !state);
        return;
    case CONVERT:
        if (unaryNode.getType().isBoolean()) {
            branchOptimizer(rhs, label, state);
            return;
        }
        break;
    default:
        break;
    }

    // convert to boolean
    load(unaryNode);
    method.convert(Type.BOOLEAN);
    if (state) {
        method.ifne(label);
    } else {
        method.ifeq(label);
    }
}
 
Example #4
Source File: AssignSymbols.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Node leaveTYPEOF(final UnaryNode unaryNode) {
    final Expression rhs = unaryNode.getExpression();

    final List<Expression> args = new ArrayList<>();
    if (rhs instanceof IdentNode && !isParamOrVar((IdentNode)rhs)) {
        args.add(compilerConstantIdentifier(SCOPE));
        args.add(LiteralNode.newInstance(rhs, ((IdentNode)rhs).getName())); //null
    } else {
        args.add(rhs);
        args.add(LiteralNode.newInstance(unaryNode)); //null, do not reuse token of identifier rhs, it can be e.g. 'this'
    }

    final Node runtimeNode = new RuntimeNode(unaryNode, Request.TYPEOF, args);

    end(unaryNode);

    return runtimeNode;
}
 
Example #5
Source File: AssignSymbols.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Node leaveTYPEOF(final UnaryNode unaryNode) {
    final Expression rhs = unaryNode.getExpression();

    final List<Expression> args = new ArrayList<>();
    if (rhs instanceof IdentNode && !isParamOrVar((IdentNode)rhs)) {
        args.add(compilerConstantIdentifier(SCOPE));
        args.add(LiteralNode.newInstance(rhs, ((IdentNode)rhs).getName())); //null
    } else {
        args.add(rhs);
        args.add(LiteralNode.newInstance(unaryNode)); //null, do not reuse token of identifier rhs, it can be e.g. 'this'
    }

    final Node runtimeNode = new RuntimeNode(unaryNode, Request.TYPEOF, args);

    end(unaryNode);

    return runtimeNode;
}
 
Example #6
Source File: OptimisticTypesCalculator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
    if(unaryNode.isTokenType(TokenType.NOT) || unaryNode.isTokenType(TokenType.NEW)) {
        // Operand of boolean negation is never optimistic (always coerced to boolean).
        // Operand of "new" is never optimistic (always coerced to Object).
        tagNeverOptimistic(unaryNode.getExpression());
    }
    return true;
}
 
Example #7
Source File: OptimisticTypesCalculator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
    if(unaryNode.isTokenType(TokenType.NOT) || unaryNode.isTokenType(TokenType.NEW)) {
        // Operand of boolean negation is never optimistic (always coerced to boolean).
        // Operand of "new" is never optimistic (always coerced to Object).
        tagNeverOptimistic(unaryNode.getExpression());
    }
    return true;
}
 
Example #8
Source File: RangeAnalyzer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveADD(final UnaryNode node) {
    Range range = node.rhs().getSymbol().getRange();
    if (!range.getType().isNumeric()) {
       range = Range.createTypeRange(Type.NUMBER);
    }
    setRange(node, range);
    return node;
}
 
Example #9
Source File: FoldConstants.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveUnaryNode(final UnaryNode unaryNode) {
    final LiteralNode<?> literalNode = new UnaryNodeConstantEvaluator(unaryNode).eval();
    if (literalNode != null) {
        log.info("Unary constant folded ", unaryNode, " to ", literalNode);
        return literalNode;
    }
    return unaryNode;
}
 
Example #10
Source File: NodeOperatorVisitor.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final boolean enterUnaryNode(final UnaryNode unaryNode) {
    switch (unaryNode.tokenType()) {
    case ADD:
        return enterADD(unaryNode);
    case BIT_NOT:
        return enterBIT_NOT(unaryNode);
    case DELETE:
        return enterDELETE(unaryNode);
    case DISCARD:
        return enterDISCARD(unaryNode);
    case NEW:
        return enterNEW(unaryNode);
    case NOT:
        return enterNOT(unaryNode);
    case SUB:
        return enterSUB(unaryNode);
    case TYPEOF:
        return enterTYPEOF(unaryNode);
    case VOID:
        return enterVOID(unaryNode);
    case DECPREFIX:
    case DECPOSTFIX:
    case INCPREFIX:
    case INCPOSTFIX:
        return enterDECINC(unaryNode);
    default:
        return super.enterUnaryNode(unaryNode);
    }
}
 
Example #11
Source File: FoldConstants.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveUnaryNode(final UnaryNode unaryNode) {
    final LiteralNode<?> literalNode = new UnaryNodeConstantEvaluator(unaryNode).eval();
    if (literalNode != null) {
        log.info("Unary constant folded ", unaryNode, " to ", literalNode);
        return literalNode;
    }
    return unaryNode;
}
 
Example #12
Source File: NodeOperatorVisitor.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final Node leaveUnaryNode(final UnaryNode unaryNode) {
    switch (unaryNode.tokenType()) {
    case ADD:
        return leaveADD(unaryNode);
    case BIT_NOT:
        return leaveBIT_NOT(unaryNode);
    case DELETE:
        return leaveDELETE(unaryNode);
    case NEW:
        return leaveNEW(unaryNode);
    case NOT:
        return leaveNOT(unaryNode);
    case SUB:
        return leaveSUB(unaryNode);
    case TYPEOF:
        return leaveTYPEOF(unaryNode);
    case VOID:
        return leaveVOID(unaryNode);
    case DECPREFIX:
    case DECPOSTFIX:
    case INCPREFIX:
    case INCPOSTFIX:
        return leaveDECINC(unaryNode);
    default:
        return super.leaveUnaryNode(unaryNode);
    }
}
 
Example #13
Source File: PrintVisitor.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
    unaryNode.toString(sb, new Runnable() {
        @Override
        public void run() {
            unaryNode.rhs().accept(PrintVisitor.this);
        }
    });
    return false;
}
 
Example #14
Source File: Parser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * NewExpression :
 *      MemberExpression
 *      new NewExpression
 *
 * See 11.2
 *
 * Parse new expression.
 * @return Expression node.
 */
private Expression newExpression() {
    final long newToken = token;
    // NEW is tested in caller.
    next();

    // Get function base.
    final int  callLine    = line;
    final Expression constructor = memberExpression();
    if (constructor == null) {
        return null;
    }
    // Get arguments.
    ArrayList<Expression> arguments;

    // Allow for missing arguments.
    if (type == LPAREN) {
        arguments = argumentList();
    } else {
        arguments = new ArrayList<>();
    }

    // Nashorn extension: This is to support the following interface implementation
    // syntax:
    //
    //     var r = new java.lang.Runnable() {
    //         run: function() { println("run"); }
    //     };
    //
    // The object literal following the "new Constructor()" expresssion
    // is passed as an additional (last) argument to the constructor.
    if (!env._no_syntax_extensions && type == LBRACE) {
        arguments.add(objectLiteral());
    }

    final CallNode callNode = new CallNode(callLine, constructor.getToken(), finish, constructor, optimizeList(arguments));

    return new UnaryNode(newToken, callNode);
}
 
Example #15
Source File: NodeOperatorVisitor.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final boolean enterUnaryNode(final UnaryNode unaryNode) {
    switch (unaryNode.tokenType()) {
    case ADD:
        return enterADD(unaryNode);
    case BIT_NOT:
        return enterBIT_NOT(unaryNode);
    case DELETE:
        return enterDELETE(unaryNode);
    case DISCARD:
        return enterDISCARD(unaryNode);
    case NEW:
        return enterNEW(unaryNode);
    case NOT:
        return enterNOT(unaryNode);
    case SUB:
        return enterSUB(unaryNode);
    case TYPEOF:
        return enterTYPEOF(unaryNode);
    case VOID:
        return enterVOID(unaryNode);
    case DECPREFIX:
    case DECPOSTFIX:
    case INCPREFIX:
    case INCPOSTFIX:
        return enterDECINC(unaryNode);
    default:
        return super.enterUnaryNode(unaryNode);
    }
}
 
Example #16
Source File: NodeOperatorVisitor.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final Node leaveUnaryNode(final UnaryNode unaryNode) {
    switch (unaryNode.tokenType()) {
    case ADD:
        return leaveADD(unaryNode);
    case BIT_NOT:
        return leaveBIT_NOT(unaryNode);
    case DELETE:
        return leaveDELETE(unaryNode);
    case NEW:
        return leaveNEW(unaryNode);
    case NOT:
        return leaveNOT(unaryNode);
    case SUB:
        return leaveSUB(unaryNode);
    case TYPEOF:
        return leaveTYPEOF(unaryNode);
    case VOID:
        return leaveVOID(unaryNode);
    case DECPREFIX:
    case DECPOSTFIX:
    case INCPREFIX:
    case INCPOSTFIX:
        return leaveDECINC(unaryNode);
    default:
        return super.leaveUnaryNode(unaryNode);
    }
}
 
Example #17
Source File: CodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterVOID(final UnaryNode unaryNode) {
    load(unaryNode.rhs()).pop();
    method.loadUndefined(Type.OBJECT);

    return false;
}
 
Example #18
Source File: CodeGenerator.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterCONVERT(final UnaryNode unaryNode) {
    final Expression rhs = unaryNode.rhs();
    final Type to  = unaryNode.getType();

    if (to.isObject() && rhs instanceof LiteralNode) {
        final LiteralNode<?> literalNode = (LiteralNode<?>)rhs;
        final Object value = literalNode.getValue();

        if (value instanceof Number) {
            assert !to.isArray() : "type hygiene - cannot convert number to array: (" + to.getTypeClass().getSimpleName() + ')' + value;
            if (value instanceof Integer) {
                method.load((Integer)value);
            } else if (value instanceof Long) {
                method.load((Long)value);
            } else if (value instanceof Double) {
                method.load((Double)value);
            } else {
                assert false;
            }
            method.convert(Type.OBJECT);
        } else if (value instanceof Boolean) {
            method.getField(staticField(Boolean.class, value.toString().toUpperCase(Locale.ENGLISH), Boolean.class));
        } else {
            load(rhs);
            method.convert(unaryNode.getType());
        }
    } else {
        load(rhs);
        method.convert(unaryNode.getType());
    }

    method.store(unaryNode.getSymbol());

    return false;
}
 
Example #19
Source File: NodeOperatorVisitor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final Node leaveUnaryNode(final UnaryNode unaryNode) {
    switch (unaryNode.tokenType()) {
    case ADD:
        return leaveADD(unaryNode);
    case BIT_NOT:
        return leaveBIT_NOT(unaryNode);
    case DELETE:
        return leaveDELETE(unaryNode);
    case NEW:
        return leaveNEW(unaryNode);
    case NOT:
        return leaveNOT(unaryNode);
    case SUB:
        return leaveSUB(unaryNode);
    case TYPEOF:
        return leaveTYPEOF(unaryNode);
    case VOID:
        return leaveVOID(unaryNode);
    case DECPREFIX:
    case DECPOSTFIX:
    case INCPREFIX:
    case INCPOSTFIX:
        return leaveDECINC(unaryNode);
    default:
        return super.leaveUnaryNode(unaryNode);
    }
}
 
Example #20
Source File: AssignSymbols.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveUnaryNode(final UnaryNode unaryNode) {
    switch (unaryNode.tokenType()) {
    case DELETE:
        return leaveDELETE(unaryNode);
    case TYPEOF:
        return leaveTYPEOF(unaryNode);
    default:
        return super.leaveUnaryNode(unaryNode);
    }
}
 
Example #21
Source File: Attr.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveDECINC(final UnaryNode unaryNode) {
    // @see assignOffset
    final Type type = arithType();
    newType(unaryNode.rhs().getSymbol(), type);
    return end(ensureSymbol(type, unaryNode));
}
 
Example #22
Source File: OptimisticTypesCalculator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
    if(unaryNode.isTokenType(TokenType.NOT) || unaryNode.isTokenType(TokenType.NEW)) {
        // Operand of boolean negation is never optimistic (always coerced to boolean).
        // Operand of "new" is never optimistic (always coerced to Object).
        tagNeverOptimistic(unaryNode.getExpression());
    }
    return true;
}
 
Example #23
Source File: BranchOptimizer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void branchOptimizer(final Expression node, final Label label, final boolean state) {
    if (node instanceof BinaryNode) {
        branchOptimizer((BinaryNode)node, label, state);
        return;
    }

    if (node instanceof UnaryNode) {
        branchOptimizer((UnaryNode)node, label, state);
        return;
    }

    loadTestAndJump(node, label, state);
}
 
Example #24
Source File: WeighNodes.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveVOID(final UnaryNode unaryNode) {
    return unaryNodeWeight(unaryNode);
}
 
Example #25
Source File: WeighNodes.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveBIT_NOT(final UnaryNode unaryNode) {
    return unaryNodeWeight(unaryNode);
}
 
Example #26
Source File: FoldConstants.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
UnaryNodeConstantEvaluator(final UnaryNode parent) {
    super(parent);
}
 
Example #27
Source File: WeighNodes.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveSUB(final UnaryNode unaryNode) {
    return unaryNodeWeight(unaryNode);
}
 
Example #28
Source File: WeighNodes.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveDECINC(final UnaryNode unaryNode) {
     return unaryNodeWeight(unaryNode);
}
 
Example #29
Source File: WeighNodes.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveADD(final UnaryNode unaryNode) {
    return unaryNodeWeight(unaryNode);
}
 
Example #30
Source File: WeighNodes.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private Node runtimeNodeWeight(final UnaryNode unaryNode) {
    weight += CALL_WEIGHT;
    return unaryNode;
}