public static VarType getCommonMinType(VarType type1, VarType type2) { if (type1.type == CodeConstants.TYPE_BOOLEAN && type2.type == CodeConstants.TYPE_BOOLEAN) { // special case booleans return type1.isFalseBoolean() ? type2 : type1; } if (type1.isSuperset(type2)) { return type2; } else if (type2.isSuperset(type1)) { return type1; } else if (type1.typeFamily == type2.typeFamily) { switch (type1.typeFamily) { case CodeConstants.TYPE_FAMILY_INTEGER: if ((type1.type == CodeConstants.TYPE_CHAR && type2.type == CodeConstants.TYPE_SHORT) || (type1.type == CodeConstants.TYPE_SHORT && type2.type == CodeConstants.TYPE_CHAR)) { return VARTYPE_SHORTCHAR; } else { return VARTYPE_BYTECHAR; } case CodeConstants.TYPE_FAMILY_OBJECT: return VARTYPE_NULL; } } return null; }
public static VarType getCommonSupertype(VarType type1, VarType type2) { if (type1.type == CodeConstants.TYPE_BOOLEAN && type2.type == CodeConstants.TYPE_BOOLEAN) { // special case booleans return type1.isFalseBoolean() ? type1 : type2; } if (type1.isSuperset(type2)) { return type1; } else if (type2.isSuperset(type1)) { return type2; } else if (type1.typeFamily == type2.typeFamily) { switch (type1.typeFamily) { case CodeConstants.TYPE_FAMILY_INTEGER: if ((type1.type == CodeConstants.TYPE_SHORTCHAR && type2.type == CodeConstants.TYPE_BYTE) || (type1.type == CodeConstants.TYPE_BYTE && type2.type == CodeConstants.TYPE_SHORTCHAR)) { return VARTYPE_SHORT; } else { return VARTYPE_INT; } case CodeConstants.TYPE_FAMILY_OBJECT: return VARTYPE_OBJECT; } } return null; }
VarType supertype = VarType.getCommonSupertype(param1.getExprType(), param2.getExprType()); if (param1.type == Exprent.EXPRENT_CONST && param2.type == Exprent.EXPRENT_CONST && supertype.type != CodeConstants.TYPE_BOOLEAN && VarType.VARTYPE_INT.isSuperset(supertype)) { exprType = VarType.VARTYPE_INT;
(!leftType.isSuperset(rightType) && (rightType.equals(VarType.VARTYPE_OBJECT) || leftType.type != CodeConstants.TYPE_OBJECT)) || (castNull && rightType.type == CodeConstants.TYPE_NULL && !UNDEFINED_TYPE_STRING.equals(getTypeName(leftType))) || (castNarrowing && isIntConstant(exprent) && isNarrowedIntType(leftType));
!leftType.isSuperset(rightType) && (rightType.equals(VarType.VARTYPE_OBJECT) || leftType.type != CodeConstants.TYPE_OBJECT)) { if (right.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST)) {
public static VarType getCommonMinType(VarType type1, VarType type2) { if (type1.type == CodeConstants.TYPE_BOOLEAN && type2.type == CodeConstants.TYPE_BOOLEAN) { // special case booleans return type1.isFalseBoolean() ? type2 : type1; } if (type1.isSuperset(type2)) { return type2; } else if (type2.isSuperset(type1)) { return type1; } else if (type1.typeFamily == type2.typeFamily) { switch (type1.typeFamily) { case CodeConstants.TYPE_FAMILY_INTEGER: if ((type1.type == CodeConstants.TYPE_CHAR && type2.type == CodeConstants.TYPE_SHORT) || (type1.type == CodeConstants.TYPE_SHORT && type2.type == CodeConstants.TYPE_CHAR)) { return VARTYPE_SHORTCHAR; } else { return VARTYPE_BYTECHAR; } case CodeConstants.TYPE_FAMILY_OBJECT: return VARTYPE_NULL; } } return null; }
public static VarType getCommonSupertype(VarType type1, VarType type2) { if (type1.type == CodeConstants.TYPE_BOOLEAN && type2.type == CodeConstants.TYPE_BOOLEAN) { // special case booleans return type1.isFalseBoolean() ? type1 : type2; } if (type1.isSuperset(type2)) { return type1; } else if (type2.isSuperset(type1)) { return type2; } else if (type1.typeFamily == type2.typeFamily) { switch (type1.typeFamily) { case CodeConstants.TYPE_FAMILY_INTEGER: if ((type1.type == CodeConstants.TYPE_SHORTCHAR && type2.type == CodeConstants.TYPE_BYTE) || (type1.type == CodeConstants.TYPE_BYTE && type2.type == CodeConstants.TYPE_SHORTCHAR)) { return VARTYPE_SHORT; } else { return VARTYPE_INT; } case CodeConstants.TYPE_FAMILY_OBJECT: return VARTYPE_OBJECT; } } return null; }
supertype.type != CodeConstants.TYPE_BOOLEAN && VarType.VARTYPE_INT.isSuperset(supertype)) { exprType = VarType.VARTYPE_INT;
public static boolean getCastedExprent(Exprent exprent, VarType leftType, TextBuffer buffer, int indent, boolean castNull, boolean castAlways, boolean castNarrowing, BytecodeMappingTracer tracer) { VarType rightType = exprent.getExprType(); boolean cast = castAlways || (!leftType.isSuperset(rightType) && (rightType.equals(VarType.VARTYPE_OBJECT) || leftType.type != CodeConstants.TYPE_OBJECT)) || (castNull && rightType.type == CodeConstants.TYPE_NULL && !UNDEFINED_TYPE_STRING.equals(getTypeName(leftType))) || (castNarrowing && isIntConstant(exprent) && VarType.VARTYPE_INT.isStrictSuperset(leftType)); boolean quote = cast && exprent.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST); if (cast) buffer.append('(').append(getCastTypeName(leftType)).append(')'); if (quote) buffer.append('('); if (exprent.type == Exprent.EXPRENT_CONST) { ((ConstExprent) exprent).adjustConstType(leftType); } buffer.append(exprent.toJava(indent, tracer)); if (quote) buffer.append(')'); return cast; }
!leftType.isSuperset(rightType) && (rightType.equals(VarType.VARTYPE_OBJECT) || leftType.type != CodeConstants.TYPE_OBJECT)) { if (right.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST)) {