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

The following examples show how to use jdk.nashorn.internal.codegen.types.Type#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: CodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterADD(final BinaryNode binaryNode) {
    final Expression lhs = binaryNode.lhs();
    final Expression rhs = binaryNode.rhs();

    final Type type = binaryNode.getType();
    if (type.isNumeric()) {
        enterNumericAdd(lhs, rhs, type, binaryNode.getSymbol());
    } else {
        loadBinaryOperands(binaryNode);
        method.add();
        method.store(binaryNode.getSymbol());
    }

    return false;
}
 
Example 2
Source File: CodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterADD(final BinaryNode binaryNode) {
    final Expression lhs = binaryNode.lhs();
    final Expression rhs = binaryNode.rhs();

    final Type type = binaryNode.getType();
    if (type.isNumeric()) {
        enterNumericAdd(lhs, rhs, type, binaryNode.getSymbol());
    } else {
        loadBinaryOperands(binaryNode);
        method.add();
        method.store(binaryNode.getSymbol());
    }

    return false;
}
 
Example 3
Source File: CodeGenerator.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterADD(final BinaryNode binaryNode) {
    final Expression lhs = binaryNode.lhs();
    final Expression rhs = binaryNode.rhs();

    final Type type = binaryNode.getType();
    if (type.isNumeric()) {
        enterNumericAdd(lhs, rhs, type, binaryNode.getSymbol());
    } else {
        load(lhs).convert(Type.OBJECT);
        load(rhs).convert(Type.OBJECT);
        method.add();
        method.store(binaryNode.getSymbol());
    }

    return false;
}
 
Example 4
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 5
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 6
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 7
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 8
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 9
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 10
Source File: Attr.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * When doing widening for return types of a function or a ternary operator, it is not valid to widen a boolean to
 * anything other than Object. Also, widening a numeric type to an object type must widen to Object proper and not
 * any more specific subclass (e.g. widest of int/long/double and String is Object).
 * @param t1 type 1
 * @param t2 type 2
 * @return wider of t1 and t2, except if one is boolean and the other is neither boolean nor unknown, or if one is
 * numeric and the other is neither numeric nor unknown in which case {@code Type.OBJECT} is returned.
 */
private static Type widestReturnType(final Type t1, final Type t2) {
    if (t1.isUnknown()) {
        return t2;
    } else if (t2.isUnknown()) {
        return t1;
    } else if (t1.isBoolean() != t2.isBoolean() || t1.isNumeric() != t2.isNumeric()) {
        return Type.OBJECT;
    }
    return Type.widest(t1, t2);
}
 
Example 11
Source File: Attr.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * When doing widening for return types of a function or a ternary operator, it is not valid to widen a boolean to
 * anything other than Object. Also, widening a numeric type to an object type must widen to Object proper and not
 * any more specific subclass (e.g. widest of int/long/double and String is Object).
 * @param t1 type 1
 * @param t2 type 2
 * @return wider of t1 and t2, except if one is boolean and the other is neither boolean nor unknown, or if one is
 * numeric and the other is neither numeric nor unknown in which case {@code Type.OBJECT} is returned.
 */
private static Type widestReturnType(final Type t1, final Type t2) {
    if (t1.isUnknown()) {
        return t2;
    } else if (t2.isUnknown()) {
        return t1;
    } else if (t1.isBoolean() != t2.isBoolean() || t1.isNumeric() != t2.isNumeric()) {
        return Type.OBJECT;
    }
    return Type.widest(t1, t2);
}
 
Example 12
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 13
Source File: FinalizeTypes.java    From nashorn with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Is the specialization type supported. Currently we treat booleans as objects
 * and have no special boolean type accessor, thus booleans are ignored.
 * TODO - support booleans? NASHORN-590
 *
 * @param castTo the type to check
 * @return true if call site type is supported
 */
private static boolean isSupportedCallSiteType(final Type castTo) {
    return castTo.isNumeric(); // don't specializable for boolean
}