diff options
| author | Chris Lattner <sabre@nondot.org> | 2008-04-06 23:38:49 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2008-04-06 23:38:49 +0000 |
| commit | b90739d556d6126d04ad563726d9d4ea68a4c0c1 (patch) | |
| tree | 62aafc8d4f8c152a06389729eea699413a1fb9cd /clang/lib | |
| parent | fc4379f916dbc7d31d0605f5f2d252ac4626f31b (diff) | |
| download | bcm5719-llvm-b90739d556d6126d04ad563726d9d4ea68a4c0c1.tar.gz bcm5719-llvm-b90739d556d6126d04ad563726d9d4ea68a4c0c1.zip | |
minor simplifications/cleanups to type comparisons.
llvm-svn: 49296
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 22 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 10 |
2 files changed, 17 insertions, 15 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 9a6cd4db15f..eb2f7ef52dd 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -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; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 1c6044a744a..73e075f7d6a 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -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; } |

