Java Code Examples for jdk.nashorn.internal.ir.LiteralNode#isNumeric()

The following examples show how to use jdk.nashorn.internal.ir.LiteralNode#isNumeric() . 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: 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 2
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;
}
 
Example 3
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 4
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 5
Source File: LiteralTreeImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Kind literalKind(final LiteralNode<?> node) {
    if (node.isBoolean()) {
        return Kind.BOOLEAN_LITERAL;
    } else if (node.isNumeric()) {
        return Kind.NUMBER_LITERAL;
    } else if (node.isString()) {
        return Kind.STRING_LITERAL;
    } else if (node.isNull()) {
        return Kind.NULL_LITERAL;
    } else {
        throw new AssertionError("should not reach here: " + node.getValue());
    }
}
 
Example 6
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 7
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 8
Source File: Lower.java    From jdk8u_nashorn 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 9
Source File: Attr.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveSwitchNode(final SwitchNode switchNode) {
    Type type = Type.UNKNOWN;

    final List<CaseNode> newCases = new ArrayList<>();
    for (final CaseNode caseNode : switchNode.getCases()) {
        final Node test = caseNode.getTest();

        CaseNode newCaseNode = caseNode;
        if (test != null) {
            if (test instanceof LiteralNode) {
                //go down to integers if we can
                final LiteralNode<?> lit = (LiteralNode<?>)test;
                if (lit.isNumeric() && !(lit.getValue() instanceof Integer)) {
                    if (JSType.isRepresentableAsInt(lit.getNumber())) {
                        newCaseNode = caseNode.setTest((Expression)LiteralNode.newInstance(lit, lit.getInt32()).accept(this));
                    }
                }
            } else {
                // the "all integer" case that CodeGenerator optimizes for currently assumes literals only
                type = Type.OBJECT;
            }

            final Type newCaseType = newCaseNode.getTest().getType();
            if (newCaseType.isBoolean()) {
                type = Type.OBJECT; //booleans and integers aren't assignment compatible
            } else {
                type = Type.widest(type, newCaseType);
            }
        }

        newCases.add(newCaseNode);
    }

    //only optimize for all integers
    if (!type.isInteger()) {
        type = Type.OBJECT;
    }

    switchNode.setTag(newInternal(lc.getCurrentFunction().uniqueName(SWITCH_TAG_PREFIX.symbolName()), type));

    end(switchNode);

    return switchNode.setCases(lc, newCases);
}
 
Example 10
Source File: Attr.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveSwitchNode(final SwitchNode switchNode) {
    Type type = Type.UNKNOWN;

    final List<CaseNode> newCases = new ArrayList<>();
    for (final CaseNode caseNode : switchNode.getCases()) {
        final Node test = caseNode.getTest();

        CaseNode newCaseNode = caseNode;
        if (test != null) {
            if (test instanceof LiteralNode) {
                //go down to integers if we can
                final LiteralNode<?> lit = (LiteralNode<?>)test;
                if (lit.isNumeric() && !(lit.getValue() instanceof Integer)) {
                    if (JSType.isRepresentableAsInt(lit.getNumber())) {
                        newCaseNode = caseNode.setTest((Expression)LiteralNode.newInstance(lit, lit.getInt32()).accept(this));
                    }
                }
            } else {
                // the "all integer" case that CodeGenerator optimizes for currently assumes literals only
                type = Type.OBJECT;
            }

            final Type newCaseType = newCaseNode.getTest().getType();
            if (newCaseType.isBoolean()) {
                type = Type.OBJECT; //booleans and integers aren't assignment compatible
            } else {
                type = Type.widest(type, newCaseType);
            }
        }

        newCases.add(newCaseNode);
    }

    //only optimize for all integers
    if (!type.isInteger()) {
        type = Type.OBJECT;
    }

    switchNode.setTag(newInternal(lc.getCurrentFunction().uniqueName(SWITCH_TAG_PREFIX.symbolName()), type));

    end(switchNode);

    return switchNode.setCases(lc, newCases);
}
 
Example 11
Source File: Attr.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Node leaveSwitchNode(final SwitchNode switchNode) {
    Type type = Type.UNKNOWN;

    final List<CaseNode> newCases = new ArrayList<>();
    for (final CaseNode caseNode : switchNode.getCases()) {
        final Node test = caseNode.getTest();

        CaseNode newCaseNode = caseNode;
        if (test != null) {
            if (test instanceof LiteralNode) {
                //go down to integers if we can
                final LiteralNode<?> lit = (LiteralNode<?>)test;
                if (lit.isNumeric() && !(lit.getValue() instanceof Integer)) {
                    if (JSType.isRepresentableAsInt(lit.getNumber())) {
                        newCaseNode = caseNode.setTest((Expression)LiteralNode.newInstance(lit, lit.getInt32()).accept(this));
                    }
                }
            } else {
                // the "all integer" case that CodeGenerator optimizes for currently assumes literals only
                type = Type.OBJECT;
            }

            final Type newCaseType = newCaseNode.getTest().getType();
            if (newCaseType.isBoolean()) {
                type = Type.OBJECT; //booleans and integers aren't assignment compatible
            } else {
                type = Type.widest(type, newCaseType);
            }
        }

        newCases.add(newCaseNode);
    }

    //only optimize for all integers
    if (!type.isInteger()) {
        type = Type.OBJECT;
    }

    switchNode.setTag(newInternal(lc.getCurrentFunction().uniqueName(SWITCH_TAG_PREFIX.symbolName()), type));

    end(switchNode);

    return switchNode.setCases(lc, newCases);
}