jdk.nashorn.internal.ir.TernaryNode Java Examples

The following examples show how to use jdk.nashorn.internal.ir.TernaryNode. 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 6 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    enterDefault(ternaryNode);

    type("ConditionalExpression");
    comma();

    property("test");
    ternaryNode.getTest().accept(this);
    comma();

    property("consequent");
    ternaryNode.getTrueExpression().accept(this);
    comma();

    property("alternate");
    ternaryNode.getFalseExpression().accept(this);

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

    type("ConditionalExpression");
    comma();

    property("test");
    ternaryNode.getTest().accept(this);
    comma();

    property("consequent");
    ternaryNode.getTrueExpression().accept(this);
    comma();

    property("alternate");
    ternaryNode.getFalseExpression().accept(this);

    return leave();
}
 
Example #3
Source File: JSONWriter.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    enterDefault(ternaryNode);

    type("ConditionalExpression");
    comma();

    property("test");
    ternaryNode.getTest().accept(this);
    comma();

    property("consequent");
    ternaryNode.getTrueExpression().accept(this);
    comma();

    property("alternate");
    ternaryNode.getFalseExpression().accept(this);

    return leave();
}
 
Example #4
Source File: JSONWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    enterDefault(ternaryNode);

    type("ConditionalExpression");
    comma();

    property("test");
    ternaryNode.getTest().accept(this);
    comma();

    property("consequent");
    ternaryNode.getTrueExpression().accept(this);
    comma();

    property("alternate");
    ternaryNode.getFalseExpression().accept(this);

    return leave();
}
 
Example #5
Source File: JSONWriter.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    enterDefault(ternaryNode);

    type("ConditionalExpression");
    comma();

    property("test");
    ternaryNode.getTest().accept(this);
    comma();

    property("consequent");
    ternaryNode.getTrueExpression().accept(this);
    comma();

    property("alternate");
    ternaryNode.getFalseExpression().accept(this);

    return leave();
}
 
Example #6
Source File: BranchOptimizer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void branchOptimizer(final Expression node, final Label label, final boolean state) {
    if (!(node instanceof TernaryNode)) {

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

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

    codegen.load(node, Type.BOOLEAN);
    if (state) {
        method.ifne(label);
    } else {
        method.ifeq(label);
    }
}
 
Example #7
Source File: JSONWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    enterDefault(ternaryNode);

    type("ConditionalExpression");
    comma();

    property("test");
    ternaryNode.getTest().accept(this);
    comma();

    property("consequent");
    ternaryNode.getTrueExpression().accept(this);
    comma();

    property("alternate");
    ternaryNode.getFalseExpression().accept(this);

    return leave();
}
 
Example #8
Source File: BranchOptimizer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void branchOptimizer(final Expression node, final Label label, final boolean state) {
    if (!(node instanceof TernaryNode)) {

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

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

    codegen.load(node, Type.BOOLEAN);
    if (state) {
        method.ifne(label);
    } else {
        method.ifeq(label);
    }
}
 
Example #9
Source File: JSONWriter.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    enterDefault(ternaryNode);

    type("ConditionalExpression");
    comma();

    property("test");
    ternaryNode.getTest().accept(this);
    comma();

    property("consequent");
    ternaryNode.getTrueExpression().accept(this);
    comma();

    property("alternate");
    ternaryNode.getFalseExpression().accept(this);

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

    type("ConditionalExpression");
    comma();

    property("test");
    ternaryNode.getTest().accept(this);
    comma();

    property("consequent");
    ternaryNode.getTrueExpression().accept(this);
    comma();

    property("alternate");
    ternaryNode.getFalseExpression().accept(this);

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

    type("ConditionalExpression");
    comma();

    property("test");
    ternaryNode.getTest().accept(this);
    comma();

    property("consequent");
    ternaryNode.getTrueExpression().accept(this);
    comma();

    property("alternate");
    ternaryNode.getFalseExpression().accept(this);

    return leave();
}
 
Example #12
Source File: BranchOptimizer.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
private void branchOptimizer(final Expression node, final Label label, final boolean state) {
    if (!(node instanceof TernaryNode)) {

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

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

    load(node);
    method.convert(Type.BOOLEAN);
    if (state) {
        method.ifne(label);
    } else {
        method.ifeq(label);
    }
}
 
Example #13
Source File: JSONWriter.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    enterDefault(ternaryNode);

    type("ConditionalExpression");
    comma();

    property("test");
    ternaryNode.getTest().accept(this);
    comma();

    property("consequent");
    ternaryNode.getTrueExpression().accept(this);
    comma();

    property("alternate");
    ternaryNode.getFalseExpression().accept(this);

    return leave();
}
 
Example #14
Source File: LocalVariableTypesCalculator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    final Expression test = ternaryNode.getTest();
    final Expression trueExpr = ternaryNode.getTrueExpression();
    final Expression falseExpr = ternaryNode.getFalseExpression();

    visitExpression(test);

    final Map<Symbol, LvarType> testExitLvarTypes = localVariableTypes;
    final LvarType trueType;
    if(!isAlwaysFalse(test)) {
        trueType = visitExpression(trueExpr);
    } else {
        trueType = null;
    }
    final Map<Symbol, LvarType> trueExitLvarTypes = localVariableTypes;
    localVariableTypes = testExitLvarTypes;
    final LvarType falseType;
    if(!isAlwaysTrue(test)) {
        falseType = visitExpression(falseExpr);
    } else {
        falseType = null;
    }
    final Map<Symbol, LvarType> falseExitLvarTypes = localVariableTypes;
    localVariableTypes = getUnionTypes(trueExitLvarTypes, falseExitLvarTypes);
    setConversion((JoinPredecessor)trueExpr, trueExitLvarTypes, localVariableTypes);
    setConversion((JoinPredecessor)falseExpr, falseExitLvarTypes, localVariableTypes);

    typeStack.push(trueType != null ? falseType != null ? widestLvarType(trueType, falseType) : trueType : assertNotNull(falseType));
    return false;
}
 
Example #15
Source File: FoldConstants.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveTernaryNode(final TernaryNode ternaryNode) {
    final Node test = ternaryNode.getTest();
    if (test instanceof LiteralNode.PrimitiveLiteralNode) {
        return (((LiteralNode.PrimitiveLiteralNode<?>)test).isTrue() ? ternaryNode.getTrueExpression() : ternaryNode.getFalseExpression()).getExpression();
    }
    return ternaryNode;
}
 
Example #16
Source File: Attr.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveTernaryNode(final TernaryNode ternaryNode) {
    final Expression trueExpr  = ternaryNode.getTrueExpression();
    final Expression falseExpr = ternaryNode.getFalseExpression();

    ensureTypeNotUnknown(trueExpr);
    ensureTypeNotUnknown(falseExpr);

    final Type type = widestReturnType(trueExpr.getType(), falseExpr.getType());
    return end(ensureSymbol(type, ternaryNode));
}
 
Example #17
Source File: Attr.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveTernaryNode(final TernaryNode ternaryNode) {
    final Expression trueExpr  = ternaryNode.getTrueExpression();
    final Expression falseExpr = ternaryNode.getFalseExpression();

    ensureTypeNotUnknown(trueExpr);
    ensureTypeNotUnknown(falseExpr);

    final Type type = Type.widest(trueExpr.getType(), falseExpr.getType());
    return end(ensureSymbol(type, ternaryNode));
}
 
Example #18
Source File: FoldConstants.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveTernaryNode(final TernaryNode ternaryNode) {
    final Node test = ternaryNode.getTest();
    if (test instanceof LiteralNode.PrimitiveLiteralNode) {
        return (((LiteralNode.PrimitiveLiteralNode<?>)test).isTrue() ? ternaryNode.getTrueExpression() : ternaryNode.getFalseExpression()).getExpression();
    }
    return ternaryNode;
}
 
Example #19
Source File: LocalVariableTypesCalculator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    final Expression test = ternaryNode.getTest();
    final Expression trueExpr = ternaryNode.getTrueExpression();
    final Expression falseExpr = ternaryNode.getFalseExpression();

    visitExpression(test);

    final Map<Symbol, LvarType> testExitLvarTypes = localVariableTypes;
    final LvarType trueType;
    if(!isAlwaysFalse(test)) {
        trueType = visitExpression(trueExpr);
    } else {
        trueType = null;
    }
    final Map<Symbol, LvarType> trueExitLvarTypes = localVariableTypes;
    localVariableTypes = testExitLvarTypes;
    final LvarType falseType;
    if(!isAlwaysTrue(test)) {
        falseType = visitExpression(falseExpr);
    } else {
        falseType = null;
    }
    final Map<Symbol, LvarType> falseExitLvarTypes = localVariableTypes;
    localVariableTypes = getUnionTypes(trueExitLvarTypes, falseExitLvarTypes);
    setConversion((JoinPredecessor)trueExpr, trueExitLvarTypes, localVariableTypes);
    setConversion((JoinPredecessor)falseExpr, falseExitLvarTypes, localVariableTypes);

    typeStack.push(trueType != null ? falseType != null ? widestLvarType(trueType, falseType) : trueType : assertNotNull(falseType));
    return false;
}
 
Example #20
Source File: CodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    final Expression test      = ternaryNode.getTest();
    final Expression trueExpr  = ternaryNode.getTrueExpression();
    final Expression falseExpr = ternaryNode.getFalseExpression();

    final Symbol symbol     = ternaryNode.getSymbol();
    final Label  falseLabel = new Label("ternary_false");
    final Label  exitLabel  = new Label("ternary_exit");

    Type widest = Type.widest(ternaryNode.getType(), Type.widest(trueExpr.getType(), falseExpr.getType()));
    if (trueExpr.getType().isArray() || falseExpr.getType().isArray()) { //loadArray creates a Java array type on the stack, calls global allocate, which creates a native array type
        widest = Type.OBJECT;
    }

    load(test, Type.BOOLEAN);
    // we still keep the conversion here as the AccessSpecializer can have separated the types, e.g. var y = x ? x=55 : 17
    // will left as (Object)x=55 : (Object)17 by Lower. Then the first term can be {I}x=55 of type int, which breaks the
    // symmetry for the temporary slot for this TernaryNode. This is evidence that we assign types and explicit conversions
    // too early, or Apply the AccessSpecializer too late. We are mostly probably looking for a separate type pass to
    // do this property. Then we never need any conversions in CodeGenerator
    method.ifeq(falseLabel);
    load(trueExpr, widest);
    method._goto(exitLabel);
    method.label(falseLabel);
    load(falseExpr, widest);
    method.label(exitLabel);
    method.store(symbol);

    return false;
}
 
Example #21
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    final Expression test = ternaryNode.getTest();
    final Expression trueExpr = ternaryNode.getTrueExpression();
    final Expression falseExpr = ternaryNode.getFalseExpression();

    visitExpression(test);

    final Map<Symbol, LvarType> testExitLvarTypes = localVariableTypes;
    final LvarType trueType;
    if(!isAlwaysFalse(test)) {
        trueType = visitExpression(trueExpr);
    } else {
        trueType = null;
    }
    final Map<Symbol, LvarType> trueExitLvarTypes = localVariableTypes;
    localVariableTypes = testExitLvarTypes;
    final LvarType falseType;
    if(!isAlwaysTrue(test)) {
        falseType = visitExpression(falseExpr);
    } else {
        falseType = null;
    }
    final Map<Symbol, LvarType> falseExitLvarTypes = localVariableTypes;
    localVariableTypes = getUnionTypes(trueExitLvarTypes, falseExitLvarTypes);
    setConversion((JoinPredecessor)trueExpr, trueExitLvarTypes, localVariableTypes);
    setConversion((JoinPredecessor)falseExpr, falseExitLvarTypes, localVariableTypes);

    typeStack.push(trueType != null ? falseType != null ? widestLvarType(trueType, falseType) : trueType : assertNotNull(falseType));
    return false;
}
 
Example #22
Source File: IRTranslator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    curExpr = new ConditionalExpressionTreeImpl(ternaryNode,
            translateExpr(ternaryNode.getTest()),
            translateExpr(ternaryNode.getTrueExpression()),
            translateExpr(ternaryNode.getFalseExpression()));
    return false;
}
 
Example #23
Source File: ConditionalExpressionTreeImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
ConditionalExpressionTreeImpl(final TernaryNode node,
        final ExpressionTree condExpr, final ExpressionTree trueExpr,
        final ExpressionTree falseExpr) {
    super(node);
    this.condExpr = condExpr;
    this.trueExpr = trueExpr;
    this.falseExpr = falseExpr;

}
 
Example #24
Source File: CodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    final Expression test      = ternaryNode.getTest();
    final Expression trueExpr  = ternaryNode.getTrueExpression();
    final Expression falseExpr = ternaryNode.getFalseExpression();

    final Symbol symbol     = ternaryNode.getSymbol();
    final Label  falseLabel = new Label("ternary_false");
    final Label  exitLabel  = new Label("ternary_exit");

    Type widest = Type.widest(ternaryNode.getType(), Type.widest(trueExpr.getType(), falseExpr.getType()));
    if (trueExpr.getType().isArray() || falseExpr.getType().isArray()) { //loadArray creates a Java array type on the stack, calls global allocate, which creates a native array type
        widest = Type.OBJECT;
    }

    load(test, Type.BOOLEAN);
    // we still keep the conversion here as the AccessSpecializer can have separated the types, e.g. var y = x ? x=55 : 17
    // will left as (Object)x=55 : (Object)17 by Lower. Then the first term can be {I}x=55 of type int, which breaks the
    // symmetry for the temporary slot for this TernaryNode. This is evidence that we assign types and explicit conversions
    // too early, or Apply the AccessSpecializer too late. We are mostly probably looking for a separate type pass to
    // do this property. Then we never need any conversions in CodeGenerator
    method.ifeq(falseLabel);
    load(trueExpr, widest);
    method._goto(exitLabel);
    method.label(falseLabel);
    load(falseExpr, widest);
    method.label(exitLabel);
    method.store(symbol);

    return false;
}
 
Example #25
Source File: FoldConstants.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveTernaryNode(final TernaryNode ternaryNode) {
    final Node test = ternaryNode.getTest();
    if (test instanceof LiteralNode.PrimitiveLiteralNode) {
        return (((LiteralNode.PrimitiveLiteralNode<?>)test).isTrue() ? ternaryNode.getTrueExpression() : ternaryNode.getFalseExpression()).getExpression();
    }
    return ternaryNode;
}
 
Example #26
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    final Expression test = ternaryNode.getTest();
    final Expression trueExpr = ternaryNode.getTrueExpression();
    final Expression falseExpr = ternaryNode.getFalseExpression();

    visitExpression(test);

    final Map<Symbol, LvarType> testExitLvarTypes = localVariableTypes;
    final LvarType trueType;
    if(!isAlwaysFalse(test)) {
        trueType = visitExpression(trueExpr);
    } else {
        trueType = null;
    }
    final Map<Symbol, LvarType> trueExitLvarTypes = localVariableTypes;
    localVariableTypes = testExitLvarTypes;
    final LvarType falseType;
    if(!isAlwaysTrue(test)) {
        falseType = visitExpression(falseExpr);
    } else {
        falseType = null;
    }
    final Map<Symbol, LvarType> falseExitLvarTypes = localVariableTypes;
    localVariableTypes = getUnionTypes(trueExitLvarTypes, falseExitLvarTypes);
    setConversion((JoinPredecessor)trueExpr, trueExitLvarTypes, localVariableTypes);
    setConversion((JoinPredecessor)falseExpr, falseExitLvarTypes, localVariableTypes);

    typeStack.push(trueType != null ? falseType != null ? widestLvarType(trueType, falseType) : trueType : assertNotNull(falseType));
    return false;
}
 
Example #27
Source File: FoldConstants.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveTernaryNode(final TernaryNode ternaryNode) {
    final Node test = ternaryNode.getTest();
    if (test instanceof LiteralNode.PrimitiveLiteralNode) {
        return ((LiteralNode.PrimitiveLiteralNode<?>)test).isTrue() ? ternaryNode.getTrueExpression() : ternaryNode.getFalseExpression();
    }
    return ternaryNode;
}
 
Example #28
Source File: Attr.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveTernaryNode(final TernaryNode ternaryNode) {
    final Expression trueExpr  = ternaryNode.getTrueExpression();
    final Expression falseExpr = ternaryNode.getFalseExpression();

    ensureTypeNotUnknown(trueExpr);
    ensureTypeNotUnknown(falseExpr);

    final Type type = widestReturnType(trueExpr.getType(), falseExpr.getType());
    return end(ensureSymbol(type, ternaryNode));
}
 
Example #29
Source File: FoldConstants.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveTernaryNode(final TernaryNode ternaryNode) {
    final Node test = ternaryNode.getTest();
    if (test instanceof LiteralNode.PrimitiveLiteralNode) {
        return (((LiteralNode.PrimitiveLiteralNode<?>)test).isTrue() ? ternaryNode.getTrueExpression() : ternaryNode.getFalseExpression()).getExpression();
    }
    return ternaryNode;
}
 
Example #30
Source File: LocalVariableTypesCalculator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
    final Expression test = ternaryNode.getTest();
    final Expression trueExpr = ternaryNode.getTrueExpression();
    final Expression falseExpr = ternaryNode.getFalseExpression();

    visitExpression(test);

    final Map<Symbol, LvarType> testExitLvarTypes = localVariableTypes;
    final LvarType trueType;
    if(!isAlwaysFalse(test)) {
        trueType = visitExpression(trueExpr);
    } else {
        trueType = null;
    }
    final Map<Symbol, LvarType> trueExitLvarTypes = localVariableTypes;
    localVariableTypes = testExitLvarTypes;
    final LvarType falseType;
    if(!isAlwaysTrue(test)) {
        falseType = visitExpression(falseExpr);
    } else {
        falseType = null;
    }
    final Map<Symbol, LvarType> falseExitLvarTypes = localVariableTypes;
    localVariableTypes = getUnionTypes(trueExitLvarTypes, falseExitLvarTypes);
    setConversion((JoinPredecessor)trueExpr, trueExitLvarTypes, localVariableTypes);
    setConversion((JoinPredecessor)falseExpr, falseExitLvarTypes, localVariableTypes);

    typeStack.push(trueType != null ? falseType != null ? widestLvarType(trueType, falseType) : trueType : assertNotNull(falseType));
    return false;
}