jdk.nashorn.internal.ir.SwitchNode Java Examples

The following examples show how to use jdk.nashorn.internal.ir.SwitchNode. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
Source File: Lower.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveSwitchNode(final SwitchNode switchNode) {
    if(!switchNode.isUniqueInteger()) {
        // Wrap it in a block so its internally created tag is restricted in scope
        addStatementEnclosedInBlock(switchNode);
    } else {
        addStatement(switchNode);
    }
    return switchNode;
}
 
Example #7
Source File: JSONWriter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterSwitchNode(final SwitchNode switchNode) {
    enterDefault(switchNode);

    type("SwitchStatement");
    comma();

    property("discriminant");
    switchNode.getExpression().accept(this);
    comma();

    array("cases", switchNode.getCases());

    return leave();
}
 
Example #8
Source File: AssignSymbols.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveSwitchNode(final SwitchNode switchNode) {
    // We only need a symbol for the tag if it's not an integer switch node
    if(!switchNode.isUniqueInteger()) {
        switchNode.setTag(newObjectInternal(SWITCH_TAG_PREFIX));
    }
    return switchNode;
}
 
Example #9
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 #10
Source File: Lower.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveSwitchNode(final SwitchNode switchNode) {
    if(!switchNode.isUniqueInteger()) {
        // Wrap it in a block so its internally created tag is restricted in scope
        addStatementEnclosedInBlock(switchNode);
    } else {
        addStatement(switchNode);
    }
    return switchNode;
}
 
Example #11
Source File: PrintVisitor.java    From TencentKona-8 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 #12
Source File: FoldConstants.java    From jdk8u60 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 #13
Source File: AssignSymbols.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveSwitchNode(final SwitchNode switchNode) {
    // We only need a symbol for the tag if it's not an integer switch node
    if(!switchNode.isUniqueInteger()) {
        return switchNode.setTag(lc, newObjectInternal(SWITCH_TAG_PREFIX));
    }
    return switchNode;
}
 
Example #14
Source File: FoldConstants.java    From openjdk-jdk8u 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 #15
Source File: PrintVisitor.java    From jdk8u_nashorn 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 #16
Source File: PrintVisitor.java    From openjdk-jdk8u-backup 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 #17
Source File: AssignSymbols.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveSwitchNode(final SwitchNode switchNode) {
    // We only need a symbol for the tag if it's not an integer switch node
    if(!switchNode.isUniqueInteger()) {
        return switchNode.setTag(lc, newObjectInternal(SWITCH_TAG_PREFIX));
    }
    return switchNode;
}
 
Example #18
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 #19
Source File: JSONWriter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterSwitchNode(final SwitchNode switchNode) {
    enterDefault(switchNode);

    type("SwitchStatement");
    comma();

    property("discriminant");
    switchNode.getExpression().accept(this);
    comma();

    array("cases", switchNode.getCases());

    return leave();
}
 
Example #20
Source File: JSONWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterSwitchNode(final SwitchNode switchNode) {
    enterDefault(switchNode);

    type("SwitchStatement");
    comma();

    property("discriminant");
    switchNode.getExpression().accept(this);
    comma();

    array("cases", switchNode.getCases());

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

    type("SwitchStatement");
    comma();

    property("discriminant");
    switchNode.getExpression().accept(this);
    comma();

    array("cases", switchNode.getCases());

    return leave();
}
 
Example #22
Source File: SwitchTreeImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
SwitchTreeImpl(final SwitchNode node,
        final ExpressionTree expr,
        final List<? extends CaseTree> cases) {
    super(node);
    this.expr = expr;
    this.cases = cases;
}
 
Example #23
Source File: JSONWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterSwitchNode(final SwitchNode switchNode) {
    enterDefault(switchNode);

    type("SwitchStatement");
    comma();

    property("discriminant");
    switchNode.getExpression().accept(this);
    comma();

    array("cases", switchNode.getCases());

    return leave();
}
 
Example #24
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 #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 leaveSwitchNode(final SwitchNode switchNode) {
    if(!switchNode.isUniqueInteger()) {
        // Wrap it in a block so its internally created tag is restricted in scope
        addStatementEnclosedInBlock(switchNode);
    } else {
        addStatement(switchNode);
    }
    return switchNode;
}
 
Example #27
Source File: JSONWriter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterSwitchNode(final SwitchNode switchNode) {
    enterDefault(switchNode);

    type("SwitchStatement");
    comma();

    property("discriminant");
    switchNode.getExpression().accept(this);
    comma();

    array("cases", switchNode.getCases());

    return leave();
}
 
Example #28
Source File: JSONWriter.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterSwitchNode(final SwitchNode switchNode) {
    enterDefault(switchNode);

    type("SwitchStatement");
    comma();

    property("discriminant");
    switchNode.getExpression().accept(this);
    comma();

    array("cases", switchNode.getCases());

    return leave();
}
 
Example #29
Source File: Lower.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveSwitchNode(final SwitchNode switchNode) {
    if(!switchNode.isUniqueInteger()) {
        // Wrap it in a block so its internally created tag is restricted in scope
        addStatementEnclosedInBlock(switchNode);
    } else {
        addStatement(switchNode);
    }
    return switchNode;
}
 
Example #30
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;
}