Java Code Examples for jdk.nashorn.internal.codegen.types.Type#isInteger()

The following examples show how to use jdk.nashorn.internal.codegen.types.Type#isInteger() . 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: LiteralNode.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayType getArrayType(final Type elementType) {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example 2
Source File: LiteralNode.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayType getArrayType(final Type elementType) {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isLong()) {
        return Type.LONG_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example 3
Source File: LiteralNode.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayType getArrayType(final Type elementType) {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example 4
Source File: LiteralNode.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayType getArrayType(final Type elementType) {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example 5
Source File: LiteralNode.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayType getArrayType(final Type elementType) {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example 6
Source File: LiteralNode.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayType getArrayType(final Type elementType) {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example 7
Source File: LiteralNode.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayType getArrayType(final Type elementType) {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example 8
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);
}
 
Example 9
Source File: FoldConstants.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected LiteralNode<?> eval() {
    final Node rhsNode = parent.getExpression();

    if (!(rhsNode instanceof LiteralNode)) {
        return null;
    }

    if (rhsNode instanceof ArrayLiteralNode) {
        return null;
    }

    final LiteralNode<?> rhs = (LiteralNode<?>)rhsNode;
    final Type rhsType = rhs.getType();
    final boolean rhsInteger = rhsType.isInteger() || rhsType.isBoolean();

    LiteralNode<?> literalNode;

    switch (parent.tokenType()) {
    case ADD:
        if (rhsInteger) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getInt32());
        } else if (rhsType.isLong()) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getLong());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getNumber());
        }
        break;
    case SUB:
        if (rhsInteger && rhs.getInt32() != 0) { // @see test/script/basic/minuszero.js
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getInt32());
        } else if (rhsType.isLong() && rhs.getLong() != 0L) {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getLong());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getNumber());
        }
        break;
    case NOT:
        literalNode = LiteralNode.newInstance(token, finish, !rhs.getBoolean());
        break;
    case BIT_NOT:
        literalNode = LiteralNode.newInstance(token, finish, ~rhs.getInt32());
        break;
    default:
        return null;
    }

    return literalNode;
}
 
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 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 12
Source File: FoldConstants.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected LiteralNode<?> eval() {
    final Node rhsNode = parent.getExpression();

    if (!(rhsNode instanceof LiteralNode)) {
        return null;
    }

    if (rhsNode instanceof ArrayLiteralNode) {
        return null;
    }

    final LiteralNode<?> rhs = (LiteralNode<?>)rhsNode;
    final Type rhsType = rhs.getType();
    final boolean rhsInteger = rhsType.isInteger() || rhsType.isBoolean();

    LiteralNode<?> literalNode;

    switch (parent.tokenType()) {
    case ADD:
        if (rhsInteger) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getInt32());
        } else if (rhsType.isLong()) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getLong());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getNumber());
        }
        break;
    case SUB:
        if (rhsInteger && rhs.getInt32() != 0) { // @see test/script/basic/minuszero.js
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getInt32());
        } else if (rhsType.isLong() && rhs.getLong() != 0L) {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getLong());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getNumber());
        }
        break;
    case NOT:
        literalNode = LiteralNode.newInstance(token, finish, !rhs.getBoolean());
        break;
    case BIT_NOT:
        literalNode = LiteralNode.newInstance(token, finish, ~rhs.getInt32());
        break;
    default:
        return null;
    }

    return literalNode;
}
 
Example 13
Source File: FoldConstants.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected LiteralNode<?> eval() {
    final Node rhsNode = parent.getExpression();

    if (!(rhsNode instanceof LiteralNode)) {
        return null;
    }

    if (rhsNode instanceof ArrayLiteralNode) {
        return null;
    }

    final LiteralNode<?> rhs = (LiteralNode<?>)rhsNode;
    final Type rhsType = rhs.getType();
    final boolean rhsInteger = rhsType.isInteger() || rhsType.isBoolean();

    LiteralNode<?> literalNode;

    switch (parent.tokenType()) {
    case ADD:
        if (rhsInteger) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getInt32());
        } else if (rhsType.isLong()) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getLong());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getNumber());
        }
        break;
    case SUB:
        if (rhsInteger && rhs.getInt32() != 0) { // @see test/script/basic/minuszero.js
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getInt32());
        } else if (rhsType.isLong() && rhs.getLong() != 0L) {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getLong());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getNumber());
        }
        break;
    case NOT:
        literalNode = LiteralNode.newInstance(token, finish, !rhs.getBoolean());
        break;
    case BIT_NOT:
        literalNode = LiteralNode.newInstance(token, finish, ~rhs.getInt32());
        break;
    default:
        return null;
    }

    return literalNode;
}
 
Example 14
Source File: FoldConstants.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected LiteralNode<?> eval() {
    final Node rhsNode = parent.getExpression();

    if (!(rhsNode instanceof LiteralNode)) {
        return null;
    }

    if (rhsNode instanceof ArrayLiteralNode) {
        return null;
    }

    final LiteralNode<?> rhs = (LiteralNode<?>)rhsNode;
    final Type rhsType = rhs.getType();
    final boolean rhsInteger = rhsType.isInteger() || rhsType.isBoolean();

    LiteralNode<?> literalNode;

    switch (parent.tokenType()) {
    case ADD:
        if (rhsInteger) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getInt32());
        } else if (rhsType.isLong()) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getLong());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getNumber());
        }
        break;
    case SUB:
        if (rhsInteger && rhs.getInt32() != 0) { // @see test/script/basic/minuszero.js
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getInt32());
        } else if (rhsType.isLong() && rhs.getLong() != 0L) {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getLong());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getNumber());
        }
        break;
    case NOT:
        literalNode = LiteralNode.newInstance(token, finish, !rhs.getBoolean());
        break;
    case BIT_NOT:
        literalNode = LiteralNode.newInstance(token, finish, ~rhs.getInt32());
        break;
    default:
        return null;
    }

    return literalNode;
}
 
Example 15
Source File: FoldConstants.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected LiteralNode<?> eval() {
    final Node rhsNode = parent.getExpression();

    if (!(rhsNode instanceof LiteralNode)) {
        return null;
    }

    if (rhsNode instanceof ArrayLiteralNode) {
        return null;
    }

    final LiteralNode<?> rhs = (LiteralNode<?>)rhsNode;
    final Type rhsType = rhs.getType();
    final boolean rhsInteger = rhsType.isInteger() || rhsType.isBoolean();

    LiteralNode<?> literalNode;

    switch (parent.tokenType()) {
    case ADD:
        if (rhsInteger) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getInt32());
        } else if (rhsType.isLong()) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getLong());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getNumber());
        }
        break;
    case SUB:
        if (rhsInteger && rhs.getInt32() != 0) { // @see test/script/basic/minuszero.js
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getInt32());
        } else if (rhsType.isLong() && rhs.getLong() != 0L) {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getLong());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getNumber());
        }
        break;
    case NOT:
        literalNode = LiteralNode.newInstance(token, finish, !rhs.getBoolean());
        break;
    case BIT_NOT:
        literalNode = LiteralNode.newInstance(token, finish, ~rhs.getInt32());
        break;
    default:
        return null;
    }

    return literalNode;
}
 
Example 16
Source File: FoldConstants.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected LiteralNode<?> eval() {
    final Node rhsNode = parent.getExpression();

    if (!(rhsNode instanceof LiteralNode)) {
        return null;
    }

    if (rhsNode instanceof ArrayLiteralNode) {
        return null;
    }

    final LiteralNode<?> rhs = (LiteralNode<?>)rhsNode;
    final Type rhsType = rhs.getType();
    final boolean rhsInteger = rhsType.isInteger() || rhsType.isBoolean();

    LiteralNode<?> literalNode;

    switch (parent.tokenType()) {
    case ADD:
        if (rhsInteger) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getInt32());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getNumber());
        }
        break;
    case SUB:
        if (rhsInteger && rhs.getInt32() != 0) { // @see test/script/basic/minuszero.js
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getInt32());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getNumber());
        }
        break;
    case NOT:
        literalNode = LiteralNode.newInstance(token, finish, !rhs.getBoolean());
        break;
    case BIT_NOT:
        literalNode = LiteralNode.newInstance(token, finish, ~rhs.getInt32());
        break;
    default:
        return null;
    }

    return literalNode;
}
 
Example 17
Source File: FoldConstants.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected LiteralNode<?> eval() {
    final Node rhsNode = parent.getExpression();

    if (!(rhsNode instanceof LiteralNode)) {
        return null;
    }

    if (rhsNode instanceof ArrayLiteralNode) {
        return null;
    }

    final LiteralNode<?> rhs = (LiteralNode<?>)rhsNode;
    final Type rhsType = rhs.getType();
    final boolean rhsInteger = rhsType.isInteger() || rhsType.isBoolean();

    LiteralNode<?> literalNode;

    switch (parent.tokenType()) {
    case ADD:
        if (rhsInteger) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getInt32());
        } else if (rhsType.isLong()) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getLong());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getNumber());
        }
        break;
    case SUB:
        if (rhsInteger && rhs.getInt32() != 0) { // @see test/script/basic/minuszero.js
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getInt32());
        } else if (rhsType.isLong() && rhs.getLong() != 0L) {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getLong());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getNumber());
        }
        break;
    case NOT:
        literalNode = LiteralNode.newInstance(token, finish, !rhs.getBoolean());
        break;
    case BIT_NOT:
        literalNode = LiteralNode.newInstance(token, finish, ~rhs.getInt32());
        break;
    default:
        return null;
    }

    return literalNode;
}