[cfe-commits] r49296 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/Sema/SemaExpr.cpp

Chris Lattner sabre at nondot.org
Sun Apr 6 16:38:49 PDT 2008


Author: lattner
Date: Sun Apr  6 18:38:49 2008
New Revision: 49296

URL: http://llvm.org/viewvc/llvm-project?rev=49296&view=rev
Log:
minor simplifications/cleanups to type comparisons.

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=49296&r1=49295&r2=49296&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sun Apr  6 18:38:49 2008
@@ -303,14 +303,15 @@
   /// 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). 

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=49296&r1=49295&r2=49296&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun Apr  6 18:38:49 2008
@@ -1010,13 +1010,12 @@
 
 /// 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 @@
   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 @@
   }
 }
 
-// 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;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=49296&r1=49295&r2=49296&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Apr  6 18:38:49 2008
@@ -1008,7 +1008,7 @@
     // 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 @@
     }
     // 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 @@
     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 @@
     }
   }
   // 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;
   }





More information about the cfe-commits mailing list