minor simplifications/cleanups to type comparisons.

llvm-svn: 49296
This commit is contained in:
Chris Lattner 2008-04-06 23:38:49 +00:00
parent fc4379f916
commit b90739d556
3 changed files with 25 additions and 22 deletions

View File

@ -303,14 +303,15 @@ public:
/// See C99 6.7.5.3p7 and C99 6.3.2.1p3.
QualType getArrayDecayedType(QualType T);
/// maxIntegerType - Returns the highest ranked integer type. Handles 3
/// different type combos: unsigned/unsigned, signed/signed, signed/unsigned.
QualType maxIntegerType(QualType lhs, QualType rhs);
/// getMaxIntegerType - Returns the highest ranked integer type:
/// C99 6.3.1.8p1.
QualType getMaxIntegerType(QualType LHS, QualType RHS);
/// compareFloatingType - Handles 3 different combos:
/// float/float, float/complex, complex/complex.
/// If lt > rt, return 1. If lt == rt, return 0. If lt < rt, return -1.
int compareFloatingType(QualType lt, QualType rt);
/// getFloatingTypeOrder - Compare the rank of the two specified floating
/// point types, ignoring the domain of the type (i.e. 'double' ==
/// '_Complex double'). If LHS > RHS, return 1. If LHS == RHS, return 0. If
/// LHS < RHS, return -1.
int getFloatingTypeOrder(QualType LHS, QualType RHS);
/// getFloatingTypeOfSizeWithinDomain - Returns a real floating
/// point or a complex type (based on typeDomain/typeSize).

View File

@ -1010,13 +1010,12 @@ QualType ASTContext::getArrayDecayedType(QualType Ty) {
/// getFloatingRank - Return a relative rank for floating point types.
/// This routine will assert if passed a built-in type that isn't a float.
static int getFloatingRank(QualType T) {
T = T.getCanonicalType();
static FloatingRank getFloatingRank(QualType T) {
if (const ComplexType *CT = T->getAsComplexType())
return getFloatingRank(CT->getElementType());
switch (T->getAsBuiltinType()->getKind()) {
default: assert(0 && "getFloatingRank(): not a floating type");
default: assert(0 && "getFloatingRank(): not a floating type");
case BuiltinType::Float: return FloatRank;
case BuiltinType::Double: return DoubleRank;
case BuiltinType::LongDouble: return LongDoubleRank;
@ -1051,13 +1050,16 @@ QualType ASTContext::getFloatingTypeOfSizeWithinDomain(
return VoidTy;
}
/// compareFloatingType - Handles 3 different combos:
/// getFloatingTypeOrder - Handles 3 different combos:
/// float/float, float/complex, complex/complex.
/// If lt > rt, return 1. If lt == rt, return 0. If lt < rt, return -1.
int ASTContext::compareFloatingType(QualType lt, QualType rt) {
if (getFloatingRank(lt) == getFloatingRank(rt))
int ASTContext::getFloatingTypeOrder(QualType LHS, QualType RHS) {
FloatingRank LHSR = getFloatingRank(LHS);
FloatingRank RHSR = getFloatingRank(RHS);
if (LHSR == RHSR)
return 0;
if (getFloatingRank(lt) > getFloatingRank(rt))
if (LHSR > RHSR)
return 1;
return -1;
}
@ -1094,9 +1096,9 @@ static unsigned getIntegerRank(Type *T) {
}
}
// maxIntegerType - Returns the highest ranked integer type. Handles 3 case:
// getMaxIntegerType - Returns the highest ranked integer type. Handles 3 case:
// unsigned/unsigned, signed/signed, signed/unsigned. C99 6.3.1.8p1.
QualType ASTContext::maxIntegerType(QualType LHS, QualType RHS) {
QualType ASTContext::getMaxIntegerType(QualType LHS, QualType RHS) {
Type *LHSC = getCanonicalType(LHS).getTypePtr();
Type *RHSC = getCanonicalType(RHS).getTypePtr();
if (LHSC == RHSC) return LHS;

View File

@ -1008,7 +1008,7 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr,
// real or complex domain, to the precision of the other type. For example,
// when combining a "long double" with a "double _Complex", the
// "double _Complex" is promoted to "long double _Complex".
int result = Context.compareFloatingType(lhs, rhs);
int result = Context.getFloatingTypeOrder(lhs, rhs);
if (result > 0) { // The left side is bigger, convert rhs.
rhs = Context.getFloatingTypeOfSizeWithinDomain(lhs, rhs);
@ -1050,7 +1050,7 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr,
}
// We have two real floating types, float/complex combos were handled above.
// Convert the smaller operand to the bigger result.
int result = Context.compareFloatingType(lhs, rhs);
int result = Context.getFloatingTypeOrder(lhs, rhs);
if (result > 0) { // convert the rhs
if (!isCompAssign) ImpCastExprToType(rhsExpr, lhs);
@ -1068,8 +1068,8 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr,
const ComplexType *rhsComplexInt = rhs->getAsComplexIntegerType();
if (lhsComplexInt && rhsComplexInt) {
if (Context.maxIntegerType(lhsComplexInt->getElementType(),
rhsComplexInt->getElementType()) == lhs) {
if (Context.getMaxIntegerType(lhsComplexInt->getElementType(),
rhsComplexInt->getElementType()) == lhs) {
// convert the rhs
if (!isCompAssign) ImpCastExprToType(rhsExpr, lhs);
return lhs;
@ -1088,7 +1088,7 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr,
}
}
// Finally, we have two differing integer types.
if (Context.maxIntegerType(lhs, rhs) == lhs) { // convert the rhs
if (Context.getMaxIntegerType(lhs, rhs) == lhs) { // convert the rhs
if (!isCompAssign) ImpCastExprToType(rhsExpr, lhs);
return lhs;
}