From a75cea3f6be0daa8054d36af81a6ffda1713f82d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 6 Apr 2008 23:38:49 +0000 Subject: [PATCH] minor simplifications/cleanups to type comparisons. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49296 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ASTContext.h | 17 +++++++++-------- lib/AST/ASTContext.cpp | 22 ++++++++++++---------- lib/Sema/SemaExpr.cpp | 10 +++++----- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index f3030d8f81..67f517b480 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -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); - - /// 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); + /// getMaxIntegerType - Returns the highest ranked integer type: + /// C99 6.3.1.8p1. + QualType getMaxIntegerType(QualType LHS, QualType RHS); + + /// 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). diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 9a6cd4db15..eb2f7ef52d 100644 --- a/lib/AST/ASTContext.cpp +++ b/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/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 1c6044a744..73e075f7d6 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/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; } -- 2.40.0