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

Steve Naroff snaroff at apple.com
Wed Jul 11 09:44:11 PDT 2007


Author: snaroff
Date: Wed Jul 11 11:44:10 2007
New Revision: 39421

URL: http://llvm.org/viewvc/llvm-project?rev=39421&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
- Disabled -pedantic for now (until it ignores system headers).
- Removed convertSignedWithGreaterRankThanUnsigned() and convertFloatingRankToComplexType().
The logic is now inlined in maxIntegerType and maxComplexType().
- Removed getIntegerRank/getFloatingRank from the private interface. These
are now really private helpers:-)
- Declare maxIntegerType/maxFloatingType static. maxComplexType const.
- Added an enum for the floating ranks.
- Several fixed to getIntegerRank: add Bool, Char, and a clause for enums.

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

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

==============================================================================
--- cfe/cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/cfe/trunk/AST/ASTContext.cpp Wed Jul 11 11:44:10 2007
@@ -19,6 +19,10 @@
 using namespace llvm;
 using namespace clang;
 
+enum FloatingRank {
+  FloatRank, DoubleRank, LongDoubleRank
+};
+
 ASTContext::~ASTContext() {
   // Deallocate all the types.
   while (!Types.empty()) {
@@ -293,72 +297,55 @@
   return UnsignedLongTy; 
 }
 
-/// getIntegerRank - Helper function for UsualArithmeticConversions().
-int ASTContext::getIntegerRank(QualType t) {
+/// getIntegerRank - Return an integer conversion rank (C99 6.3.1.1p1). This
+/// routine will assert if passed a built-in type that isn't an integer or enum.
+static int getIntegerRank(QualType t) {
   if (const BuiltinType *BT = dyn_cast<BuiltinType>(t.getCanonicalType())) {
     switch (BT->getKind()) {
+    default:
+      assert(0 && "GetIntegerRank(): not a built-in integer");
+    case BuiltinType::Bool:
+      return 1;
+    case BuiltinType::Char:
     case BuiltinType::SChar:
     case BuiltinType::UChar:
-      return 1;
+      return 2;
     case BuiltinType::Short:
     case BuiltinType::UShort:
-      return 2;
+      return 3;
     case BuiltinType::Int:
     case BuiltinType::UInt:
-      return 3;
+      return 4;
     case BuiltinType::Long:
     case BuiltinType::ULong:
-      return 4;
+      return 5;
     case BuiltinType::LongLong:
     case BuiltinType::ULongLong:
-      return 5;
-    default:
-      assert(0 && "GetIntegerRank(): not an integer type");
+      return 6;
     }
   }
-  return 0;
-}
-
-/// getFloatingRank - Helper function for UsualArithmeticConversions().
-int ASTContext::getFloatingRank(QualType t) {
-  if (const BuiltinType *BT = dyn_cast<BuiltinType>(t.getCanonicalType())) {
-    switch (BT->getKind()) {
-    case BuiltinType::Float:
-    case BuiltinType::FloatComplex:
-      return 1;
-    case BuiltinType::Double:
-    case BuiltinType::DoubleComplex:
-      return 2;
-    case BuiltinType::LongDouble:
-    case BuiltinType::LongDoubleComplex:
-      return 3;
-    default:
-      assert(0 && "getFloatingPointRank(): not a floating type");
-    }
-  }
-  return 0;
-}
-
-QualType ASTContext::convertSignedWithGreaterRankThanUnsigned(
-  QualType signedType, QualType unsignedType) {
-  // FIXME: Need to check if the signed type can represent all values of the 
-  // unsigned type. If it can, then the result is the signed type. If it can't, 
-  // then the result is the unsigned version of the signed type.
-  return signedType; 
+  if (const TagType *TT = cast<TagType>(t.getCanonicalType()))
+    if (TT->getDecl()->getKind() == Decl::Enum)
+      return 4;
+  assert(0 && "GetIntegerRank(): not a built-in integer or enum constant");
 }
 
-
-/// ConvertFloatingRankToComplexType - Another helper for converting floats.
-QualType ASTContext::convertFloatingRankToComplexType(int rank) {
-  switch (rank) {
-  case 1:
-    return FloatComplexTy;
-  case 2:
-    return DoubleComplexTy;
-  case 3:
-    return LongDoubleComplexTy;
+/// 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) {
+  const BuiltinType *BT = cast<BuiltinType>(t.getCanonicalType());
+  switch (BT->getKind()) {
   default:
-    assert(0 && "convertRankToComplex(): illegal value for rank");
+    assert(0 && "getFloatingPointRank(): not a floating type");
+  case BuiltinType::Float:
+  case BuiltinType::FloatComplex:
+    return FloatRank;
+  case BuiltinType::Double:
+  case BuiltinType::DoubleComplex:
+    return DoubleRank;
+  case BuiltinType::LongDouble:
+  case BuiltinType::LongDoubleComplex:
+    return LongDoubleRank;
   }
 }
 
@@ -377,11 +364,17 @@
 // 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) {
-  int lhsRank = getFloatingRank(lt);
-  int rhsRank = getFloatingRank(rt);
-  
-  return convertFloatingRankToComplexType(std::max(lhsRank, rhsRank));
+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;
+  }
 }
 
 // maxFloatingType - handles the simple case, both operands are floats.
@@ -389,8 +382,9 @@
   return getFloatingRank(lt) > getFloatingRank(rt) ? lt : rt;
 }
 
+// maxIntegerType - 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) {
-  // Lastly, handle two integers (C99 6.3.1.8p1)
   bool t1Unsigned = lhs->isUnsignedIntegerType();
   bool t2Unsigned = rhs->isUnsignedIntegerType();
   
@@ -403,6 +397,12 @@
   
   if (getIntegerRank(unsignedType) >= getIntegerRank(signedType))
     return unsignedType;
-  else 
-    return convertSignedWithGreaterRankThanUnsigned(signedType, unsignedType); 
+  else {
+    // FIXME: Need to check if the signed type can represent all values of the 
+    // unsigned type. If it can, then the result is the signed type. 
+    // If it can't, then the result is the unsigned version of the signed type.  
+    // Should probably add a helper that returns a signed integer type from 
+    // an unsigned (and vice versa). C99 6.3.1.8.
+    return signedType; 
+  }
 }

Modified: cfe/cfe/trunk/AST/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaExpr.cpp?rev=39421&r1=39420&r2=39421&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/AST/SemaExpr.cpp Wed Jul 11 11:44:10 2007
@@ -604,6 +604,9 @@
 Action::ExprResult Sema::CheckAssignmentOperands( // C99 6.5.16
   Expr *lex, Expr *rex, SourceLocation loc, unsigned code) 
 {
+  QualType lhsType = lex->getType();
+  QualType rhsType = rex->getType();
+  
   // FIXME: add type checking and fix result type
   return new BinaryOperator(lex, rex, (BOP)code, Context.IntTy);
 }

Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=39421&r1=39420&r2=39421&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:44:10 2007
@@ -299,7 +299,7 @@
 WarningsAsErrors("Werror", cl::desc("Treat all warnings as errors"));
 
 static cl::opt<bool>
-WarnOnExtensions("pedantic", cl::init(true),
+WarnOnExtensions("pedantic", cl::init(false),
                  cl::desc("Issue a warning on uses of GCC extensions"));
 
 static cl::opt<bool>

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:44:10 2007
@@ -604,6 +604,9 @@
 Action::ExprResult Sema::CheckAssignmentOperands( // C99 6.5.16
   Expr *lex, Expr *rex, SourceLocation loc, unsigned code) 
 {
+  QualType lhsType = lex->getType();
+  QualType rhsType = rex->getType();
+  
   // FIXME: add type checking and fix result type
   return new BinaryOperator(lex, rex, (BOP)code, Context.IntTy);
 }

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

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/cfe/trunk/include/clang/AST/ASTContext.h Wed Jul 11 11:44:10 2007
@@ -85,15 +85,15 @@
 
   // maxIntegerType - Returns the highest ranked integer type. Handles 3
   // different type combos: unsigned/unsigned, signed/signed, signed/unsigned.
-  QualType maxIntegerType(QualType lhs, QualType rhs);
+  static QualType maxIntegerType(QualType lhs, QualType rhs);
   
   // maxFloatingType - Returns the highest ranked float type. Both input 
   // types are required to be floats.
-  QualType maxFloatingType(QualType lt, QualType rt);
+  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);
+  QualType maxComplexType(QualType lt, QualType rt) const;
   
 private:
   ASTContext(const ASTContext&); // DO NOT IMPLEMENT
@@ -101,20 +101,6 @@
   
   void InitBuiltinTypes();
   void InitBuiltinType(QualType &R, BuiltinType::Kind K);
-
-  /// getIntegerRank - Return an integer conversion rank (C99 6.3.1.1p1).
-  /// This routine will assert if passed a built-in type that isn't an integer.
-  int getIntegerRank(QualType t);
-  
-  /// getFloatingRank - Return a relative rank for floating point types.
-  /// This routine will assert if passed a built-in type that isn't a float.
-  int getFloatingRank(QualType t);
-  
-  /// FIXME: comment
-  QualType convertSignedWithGreaterRankThanUnsigned(QualType signedT, 
-                                                    QualType unsignedT);
-  /// FIXME: comment                                                    
-  QualType convertFloatingRankToComplexType(int rank);
 };
   
 }  // end namespace clang





More information about the cfe-commits mailing list