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

Steve Naroff snaroff at apple.com
Sun Aug 26 18:27:54 PDT 2007


Author: snaroff
Date: Sun Aug 26 20:27:54 2007
New Revision: 41474

URL: http://llvm.org/viewvc/llvm-project?rev=41474&view=rev
Log:

Replaced ASTContext::maxComplexType() with ASTContext::getFloatingTypeOfSizeWithinDomain().

Changed Sema::UsualArithmeticConversions to correctly implement complex/float conversions, 
using maxFloatingType() with getFloatingTypeOfSizeWithinDomain().


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

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

==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Sun Aug 26 20:27:54 2007
@@ -685,28 +685,28 @@
   }
 }
 
-// maxComplexType - the following code handles 3 different combinations:
-// complex/complex, complex/float, float/complex. 
-// When both operands are complex, the shorter operand is converted to the 
-// type of the longer, and that is the type of the result. This corresponds 
-// to what is done when combining two real floating-point operands. 
-// The fun begins when size promotion occur across type domains. g
-// getFloatingRank & convertFloatingRankToComplexType handle this without 
-// enumerating all permutations. 
-// It also allows us to add new types without breakage.
-// From H&S 6.3.4: When one operand is complex and the other is a real
-// floating-point type, the less precise type is converted, within it's 
-// 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".
-
-QualType ASTContext::maxComplexType(QualType lt, QualType rt) const {
-  switch (std::max(getFloatingRank(lt), getFloatingRank(rt))) {
-  default: assert(0 && "convertRankToComplex(): illegal value for rank");
-  case FloatRank:      return FloatComplexTy;
-  case DoubleRank:     return DoubleComplexTy;
-  case LongDoubleRank: return LongDoubleComplexTy;
+/// getFloatingTypeOfSizeWithinDomain - Returns the either a real floating 
+/// point type or a complex type (based on typeDomain) of typeSize. 
+/// typeSize is expected to be a floating point type (real or complex).
+QualType ASTContext::getFloatingTypeOfSizeWithinDomain(
+  QualType typeSize, QualType typeDomain) const {
+  if (typeDomain->isComplexType()) {
+    switch (getFloatingRank(typeSize)) {
+    default: assert(0 && "convertRankToComplex(): illegal value for rank");
+    case FloatRank:      return FloatComplexTy;
+    case DoubleRank:     return DoubleComplexTy;
+    case LongDoubleRank: return LongDoubleComplexTy;
+    }
+  }
+  if (typeDomain->isRealFloatingType()) {
+    switch (getFloatingRank(typeSize)) {
+    default: assert(0 && "convertRankToComplex(): illegal value for rank");
+    case FloatRank:      return FloatTy;
+    case DoubleRank:     return DoubleTy;
+    case LongDoubleRank: return LongDoubleTy;
+    }
   }
+  assert(0 && "getFloatingTypeOfSizeWithinDomain(): illegal domain");
 }
 
 // maxFloatingType - handles the simple case, both operands are floats.

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

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Sun Aug 26 20:27:54 2007
@@ -811,13 +811,26 @@
       if (!isCompAssign) promoteExprToType(lhsExpr, rhs);
       return rhs;
     }
-    // Two complex types. Convert the smaller operand to the bigger result.
-    if (Context.maxComplexType(lhs, rhs) == lhs) { // convert the rhs
-      if (!isCompAssign) promoteExprToType(rhsExpr, lhs);
-      return lhs;
-    }
-    if (!isCompAssign) promoteExprToType(lhsExpr, rhs); // convert the lhs
-    return rhs;
+    // This handles complex/complex, complex/float, or float/complex.
+    // When both operands are complex, the shorter operand is converted to the 
+    // type of the longer, and that is the type of the result. This corresponds 
+    // to what is done when combining two real floating-point operands. 
+    // The fun begins when size promotion occur across type domains. 
+    // From H&S 6.3.4: When one operand is complex and the other is a real
+    // floating-point type, the less precise type is converted, within it's 
+    // 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".
+    if (Context.maxFloatingType(lhs, rhs) == lhs) {
+      // The left side is bigger, convert rhs within it's domain. 
+      QualType tMax = Context.getFloatingTypeOfSizeWithinDomain(lhs, rhs);
+      if (!isCompAssign) promoteExprToType(rhsExpr, tMax);
+      return tMax;
+    }
+    // The right side is bigger, convert lhs within it's domain. 
+    QualType tMax = Context.getFloatingTypeOfSizeWithinDomain(rhs, lhs);
+    if (!isCompAssign) promoteExprToType(lhsExpr, tMax);
+    return tMax;
   }
   // Now handle "real" floating types (i.e. float, double, long double).
   if (lhs->isRealFloatingType() || rhs->isRealFloatingType()) {

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

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sun Aug 26 20:27:54 2007
@@ -160,14 +160,15 @@
   /// different type combos: unsigned/unsigned, signed/signed, signed/unsigned.
   static QualType maxIntegerType(QualType lhs, QualType rhs);
   
-  /// maxFloatingType - Returns the highest ranked float type. Both input 
-  /// types are required to be floats.
+  /// maxFloatingType - Returns the highest ranked float type. Handles 3
+  /// different combos: float/float, float/complex, complex/complex.
   static QualType maxFloatingType(QualType lt, QualType rt);
 
-  /// maxComplexType - Returns the highest ranked complex type. Handles 3
-  /// different type combos: complex/complex, complex/float, float/complex. 
-  QualType maxComplexType(QualType lt, QualType rt) const;
-  
+  /// getFloatingTypeOfSizeWithinDomain - Returns the either a real floating 
+  /// point type or a complex type (based on typeDomain) of typeSize. 
+  /// typeSize is expected to be a floating point type (real or complex).
+  QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize, 
+                                             QualType typeDomain) const;
 private:
   ASTContext(const ASTContext&); // DO NOT IMPLEMENT
   void operator=(const ASTContext&); // DO NOT IMPLEMENT





More information about the cfe-commits mailing list