jdk.nashorn.internal.ir.CaseNode Java Examples

The following examples show how to use jdk.nashorn.internal.ir.CaseNode. 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 6 votes vote down vote up
@Override
public Node leaveSwitchNode(final SwitchNode switchNode) {
    final boolean allInteger = switchNode.getTag().getSymbolType().isInteger();

    if (allInteger) {
        return switchNode;
    }

    final Expression     expression  = switchNode.getExpression();
    final List<CaseNode> cases       = switchNode.getCases();
    final List<CaseNode> newCases    = new ArrayList<>();

    for (final CaseNode caseNode : cases) {
        final Expression test = caseNode.getTest();
        newCases.add(test != null ? caseNode.setTest(convert(test, Type.OBJECT)) : caseNode);
    }

    return switchNode.
        setExpression(lc, convert(expression, Type.OBJECT)).
        setCases(lc, newCases);
}
 
Example #2
Source File: JSONWriter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCaseNode(final CaseNode caseNode) {
    enterDefault(caseNode);

    type("SwitchCase");
    comma();

    final Node test = caseNode.getTest();
    property("test");
    if (test != null) {
        test.accept(this);
    } else {
        nullValue();
    }
    comma();

    array("consequent", caseNode.getBody().getStatements());

    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 enterCaseNode(final CaseNode caseNode) {
    enterDefault(caseNode);

    type("SwitchCase");
    comma();

    final Node test = caseNode.getTest();
    property("test");
    if (test != null) {
        test.accept(this);
    } else {
        nullValue();
    }
    comma();

    array("consequent", caseNode.getBody().getStatements());

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

    type("SwitchCase");
    comma();

    final Node test = caseNode.getTest();
    property("test");
    if (test != null) {
        test.accept(this);
    } else {
        nullValue();
    }
    comma();

    array("consequent", caseNode.getBody().getStatements());

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

    type("SwitchCase");
    comma();

    final Node test = caseNode.getTest();
    property("test");
    if (test != null) {
        test.accept(this);
    } else {
        nullValue();
    }
    comma();

    array("consequent", caseNode.getBody().getStatements());

    return leave();
}
 
Example #6
Source File: IRTranslator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterSwitchNode(final SwitchNode switchNode) {
    final List<CaseNode> caseNodes = switchNode.getCases();
    final List<CaseTreeImpl> caseTrees = new ArrayList<>(caseNodes.size());
    for (final CaseNode caseNode : caseNodes) {
        final Block body = caseNode.getBody();
        caseTrees.add(
                new CaseTreeImpl(caseNode,
                        translateExpr(caseNode.getTest()),
                        translateStats(body != null? body.getStatements() : null)));
    }

    curStat = new SwitchTreeImpl(switchNode,
            translateExpr(switchNode.getExpression()),
            caseTrees);
    return false;
}
 
Example #7
Source File: JSONWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCaseNode(final CaseNode caseNode) {
    enterDefault(caseNode);

    type("SwitchCase");
    comma();

    final Node test = caseNode.getTest();
    property("test");
    if (test != null) {
        test.accept(this);
    } else {
        nullValue();
    }
    comma();

    array("consequent", caseNode.getBody().getStatements());

    return leave();
}
 
Example #8
Source File: JSONWriter.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCaseNode(final CaseNode caseNode) {
    enterDefault(caseNode);

    type("SwitchCase");
    comma();

    final Node test = caseNode.getTest();
    property("test");
    if (test != null) {
        test.accept(this);
    } else {
        nullValue();
    }
    comma();

    array("consequent", caseNode.getBody().getStatements());

    return leave();
}
 
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 enterCaseNode(final CaseNode caseNode) {
    enterDefault(caseNode);

    type("SwitchCase");
    comma();

    final Node test = caseNode.getTest();
    property("test");
    if (test != null) {
        test.accept(this);
    } else {
        nullValue();
    }
    comma();

    array("consequent", caseNode.getBody().getStatements());

    return leave();
}
 
Example #10
Source File: PrintVisitor.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterSwitchNode(final SwitchNode switchNode) {
    switchNode.toString(sb);
    sb.append(" {");

    final List<CaseNode> cases = switchNode.getCases();

    for (final CaseNode caseNode : cases) {
        sb.append(EOLN);
        indent();
        caseNode.toString(sb);
        indent += TABWIDTH;
        caseNode.getBody().accept(this);
        indent -= TABWIDTH;
        sb.append(EOLN);
    }

    sb.append(EOLN);
    indent();
    sb.append("}");

    return false;
}
 
Example #11
Source File: JSONWriter.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCaseNode(final CaseNode caseNode) {
    enterDefault(caseNode);

    type("SwitchCase");
    comma();

    final Node test = caseNode.getTest();
    property("test");
    if (test != null) {
        test.accept(this);
    } else {
        nullValue();
    }
    comma();

    array("consequent", caseNode.getBody().getStatements());

    return leave();
}
 
Example #12
Source File: PrintVisitor.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterSwitchNode(final SwitchNode switchNode) {
    switchNode.toString(sb);
    sb.append(" {");

    final List<CaseNode> cases = switchNode.getCases();

    for (final CaseNode caseNode : cases) {
        sb.append(EOLN);
        indent();
        caseNode.toString(sb);
        indent += TABWIDTH;
        caseNode.getBody().accept(this);
        indent -= TABWIDTH;
        sb.append(EOLN);
    }

    sb.append(EOLN);
    indent();
    sb.append("}");

    return false;
}
 
Example #13
Source File: JSONWriter.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCaseNode(final CaseNode caseNode) {
    enterDefault(caseNode);

    type("SwitchCase");
    comma();

    final Node test = caseNode.getTest();
    property("test");
    if (test != null) {
        test.accept(this);
    } else {
        nullValue();
    }
    comma();

    array("consequent", caseNode.getBody().getStatements());

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

    type("SwitchCase");
    comma();

    final Node test = caseNode.getTest();
    property("test");
    if (test != null) {
        test.accept(this);
    } else {
        nullValue();
    }
    comma();

    array("consequent", caseNode.getBody().getStatements());

    return leave();
}
 
Example #15
Source File: PrintVisitor.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterSwitchNode(final SwitchNode switchNode) {
    switchNode.toString(sb);
    sb.append(" {");

    final List<CaseNode> cases = switchNode.getCases();

    for (final CaseNode caseNode : cases) {
        sb.append(EOLN);
        indent();
        caseNode.toString(sb);
        indent += TABWIDTH;
        caseNode.getBody().accept(this);
        indent -= TABWIDTH;
        sb.append(EOLN);
    }

    sb.append(EOLN);
    indent();
    sb.append("}");

    return false;
}
 
Example #16
Source File: Lower.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveCaseNode(final CaseNode caseNode) {
    // Try to represent the case test as an integer
    final Node test = caseNode.getTest();
    if (test instanceof LiteralNode) {
        final LiteralNode<?> lit = (LiteralNode<?>)test;
        if (lit.isNumeric() && !(lit.getValue() instanceof Integer)) {
            if (JSType.isRepresentableAsInt(lit.getNumber())) {
                return caseNode.setTest((Expression)LiteralNode.newInstance(lit, lit.getInt32()).accept(this));
            }
        }
    }
    return caseNode;
}
 
Example #17
Source File: FoldConstants.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isUniqueIntegerSwitchNode(final SwitchNode switchNode) {
    final Set<Integer> alreadySeen = new HashSet<>();
    for (final CaseNode caseNode : switchNode.getCases()) {
        final Expression test = caseNode.getTest();
        if (test != null && !isUniqueIntegerLiteral(test, alreadySeen)) {
            return false;
        }
    }
    return true;
}
 
Example #18
Source File: Lower.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveCaseNode(final CaseNode caseNode) {
    // Try to represent the case test as an integer
    final Node test = caseNode.getTest();
    if (test instanceof LiteralNode) {
        final LiteralNode<?> lit = (LiteralNode<?>)test;
        if (lit.isNumeric() && !(lit.getValue() instanceof Integer)) {
            if (JSType.isRepresentableAsInt(lit.getNumber())) {
                return caseNode.setTest((Expression)LiteralNode.newInstance(lit, lit.getInt32()).accept(this));
            }
        }
    }
    return caseNode;
}
 
Example #19
Source File: PrintVisitor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterSwitchNode(final SwitchNode switchNode) {
    switchNode.toString(sb, printTypes);
    sb.append(" {");

    final List<CaseNode> cases = switchNode.getCases();

    for (final CaseNode caseNode : cases) {
        sb.append(EOLN);
        indent();
        caseNode.toString(sb, printTypes);
        printLocalVariableConversion(caseNode);
        indent += TABWIDTH;
        caseNode.getBody().accept(this);
        indent -= TABWIDTH;
        sb.append(EOLN);
    }
    if(switchNode.getLocalVariableConversion() != null) {
        sb.append(EOLN);
        indent();
        sb.append("default: ");
        printLocalVariableConversion(switchNode);
        sb.append("{}");
    }
    sb.append(EOLN);
    indent();
    sb.append("}");

    return false;
}
 
Example #20
Source File: FoldConstants.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isUniqueIntegerSwitchNode(final SwitchNode switchNode) {
    final Set<Integer> alreadySeen = new HashSet<>();
    for (final CaseNode caseNode : switchNode.getCases()) {
        final Expression test = caseNode.getTest();
        if (test != null && !isUniqueIntegerLiteral(test, alreadySeen)) {
            return false;
        }
    }
    return true;
}
 
Example #21
Source File: CaseTreeImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public CaseTreeImpl(final CaseNode node,
    final ExpressionTree expression,
    final List<? extends StatementTree> statements) {
    super(node);
    this.expression = expression;
    this.statements = statements;
}
 
Example #22
Source File: PrintVisitor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterSwitchNode(final SwitchNode switchNode) {
    switchNode.toString(sb, printTypes);
    sb.append(" {");

    final List<CaseNode> cases = switchNode.getCases();

    for (final CaseNode caseNode : cases) {
        sb.append(EOLN);
        indent();
        caseNode.toString(sb, printTypes);
        printLocalVariableConversion(caseNode);
        indent += TABWIDTH;
        caseNode.getBody().accept(this);
        indent -= TABWIDTH;
        sb.append(EOLN);
    }
    if(switchNode.getLocalVariableConversion() != null) {
        sb.append(EOLN);
        indent();
        sb.append("default: ");
        printLocalVariableConversion(switchNode);
        sb.append("{}");
    }
    sb.append(EOLN);
    indent();
    sb.append("}");

    return false;
}
 
Example #23
Source File: PrintVisitor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterSwitchNode(final SwitchNode switchNode) {
    switchNode.toString(sb, printTypes);
    sb.append(" {");

    final List<CaseNode> cases = switchNode.getCases();

    for (final CaseNode caseNode : cases) {
        sb.append(EOLN);
        indent();
        caseNode.toString(sb, printTypes);
        printLocalVariableConversion(caseNode);
        indent += TABWIDTH;
        caseNode.getBody().accept(this);
        indent -= TABWIDTH;
        sb.append(EOLN);
    }
    if(switchNode.getLocalVariableConversion() != null) {
        sb.append(EOLN);
        indent();
        sb.append("default: ");
        printLocalVariableConversion(switchNode);
        sb.append("{}");
    }
    sb.append(EOLN);
    indent();
    sb.append("}");

    return false;
}
 
Example #24
Source File: Lower.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveCaseNode(final CaseNode caseNode) {
    // Try to represent the case test as an integer
    final Node test = caseNode.getTest();
    if (test instanceof LiteralNode) {
        final LiteralNode<?> lit = (LiteralNode<?>)test;
        if (lit.isNumeric() && !(lit.getValue() instanceof Integer)) {
            if (JSType.isRepresentableAsInt(lit.getNumber())) {
                return caseNode.setTest((Expression)LiteralNode.newInstance(lit, lit.getInt32()).accept(this));
            }
        }
    }
    return caseNode;
}
 
Example #25
Source File: FoldConstants.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isUniqueIntegerSwitchNode(final SwitchNode switchNode) {
    final Set<Integer> alreadySeen = new HashSet<>();
    for (final CaseNode caseNode : switchNode.getCases()) {
        final Expression test = caseNode.getTest();
        if (test != null && !isUniqueIntegerLiteral(test, alreadySeen)) {
            return false;
        }
    }
    return true;
}
 
Example #26
Source File: Lower.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveCaseNode(final CaseNode caseNode) {
    // Try to represent the case test as an integer
    final Node test = caseNode.getTest();
    if (test instanceof LiteralNode) {
        final LiteralNode<?> lit = (LiteralNode<?>)test;
        if (lit.isNumeric() && !(lit.getValue() instanceof Integer)) {
            if (JSType.isRepresentableAsInt(lit.getNumber())) {
                return caseNode.setTest((Expression)LiteralNode.newInstance(lit, lit.getInt32()).accept(this));
            }
        }
    }
    return caseNode;
}
 
Example #27
Source File: PrintVisitor.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterSwitchNode(final SwitchNode switchNode) {
    switchNode.toString(sb, printTypes);
    sb.append(" {");

    final List<CaseNode> cases = switchNode.getCases();

    for (final CaseNode caseNode : cases) {
        sb.append(EOLN);
        indent();
        caseNode.toString(sb, printTypes);
        printLocalVariableConversion(caseNode);
        indent += TABWIDTH;
        caseNode.getBody().accept(this);
        indent -= TABWIDTH;
        sb.append(EOLN);
    }
    if(switchNode.getLocalVariableConversion() != null) {
        sb.append(EOLN);
        indent();
        sb.append("default: ");
        printLocalVariableConversion(switchNode);
        sb.append("{}");
    }
    sb.append(EOLN);
    indent();
    sb.append("}");

    return false;
}
 
Example #28
Source File: FoldConstants.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isUniqueIntegerSwitchNode(final SwitchNode switchNode) {
    final Set<Integer> alreadySeen = new HashSet<>();
    for (final CaseNode caseNode : switchNode.getCases()) {
        final Expression test = caseNode.getTest();
        if (test != null && !isUniqueIntegerLiteral(test, alreadySeen)) {
            return false;
        }
    }
    return true;
}
 
Example #29
Source File: Lower.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveCaseNode(final CaseNode caseNode) {
    // Try to represent the case test as an integer
    final Node test = caseNode.getTest();
    if (test instanceof LiteralNode) {
        final LiteralNode<?> lit = (LiteralNode<?>)test;
        if (lit.isNumeric() && !(lit.getValue() instanceof Integer)) {
            if (JSType.isRepresentableAsInt(lit.getNumber())) {
                return caseNode.setTest((Expression)LiteralNode.newInstance(lit, lit.getInt32()).accept(this));
            }
        }
    }
    return caseNode;
}
 
Example #30
Source File: Lower.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveCaseNode(final CaseNode caseNode) {
    // Try to represent the case test as an integer
    final Node test = caseNode.getTest();
    if (test instanceof LiteralNode) {
        final LiteralNode<?> lit = (LiteralNode<?>)test;
        if (lit.isNumeric() && !(lit.getValue() instanceof Integer)) {
            if (JSType.isRepresentableAsInt(lit.getNumber())) {
                return caseNode.setTest((Expression)LiteralNode.newInstance(lit, lit.getInt32()).accept(this));
            }
        }
    }
    return caseNode;
}