[cfe-commits] r84976 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/AST/CanonicalType.h lib/AST/ASTContext.cpp lib/CodeGen/CodeGenTypes.cpp lib/Sema/SemaTemplateDeduction.cpp

John McCall rjmccall at apple.com
Fri Oct 23 16:03:22 PDT 2009


Author: rjmccall
Date: Fri Oct 23 18:03:21 2009
New Revision: 84976

URL: http://llvm.org/viewvc/llvm-project?rev=84976&view=rev
Log:
Store the builtin types as CanQualTypes.  Expand a bit on the CanQual API,
but also remove some methods that cause ambiguities, and generally
make CanQual<blah> more analogous to QualType.


Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/include/clang/AST/CanonicalType.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Oct 23 18:03:21 2009
@@ -301,22 +301,22 @@
   const char *getCommentForDecl(const Decl *D);
 
   // Builtin Types.
-  QualType VoidTy;
-  QualType BoolTy;
-  QualType CharTy;
-  QualType WCharTy;  // [C++ 3.9.1p5], integer type in C99.
-  QualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
-  QualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
-  QualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
-  QualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
-  QualType UnsignedLongLongTy, UnsignedInt128Ty;
-  QualType FloatTy, DoubleTy, LongDoubleTy;
-  QualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
-  QualType VoidPtrTy, NullPtrTy;
-  QualType OverloadTy;
-  QualType DependentTy;
-  QualType UndeducedAutoTy;
-  QualType ObjCBuiltinIdTy, ObjCBuiltinClassTy;
+  CanQualType VoidTy;
+  CanQualType BoolTy;
+  CanQualType CharTy;
+  CanQualType WCharTy;  // [C++ 3.9.1p5], integer type in C99.
+  CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
+  CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
+  CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
+  CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
+  CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
+  CanQualType FloatTy, DoubleTy, LongDoubleTy;
+  CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
+  CanQualType VoidPtrTy, NullPtrTy;
+  CanQualType OverloadTy;
+  CanQualType DependentTy;
+  CanQualType UndeducedAutoTy;
+  CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy;
 
   ASTContext(const LangOptions& LOpts, SourceManager &SM, TargetInfo &t,
              IdentifierTable &idents, SelectorTable &sels,
@@ -387,10 +387,16 @@
   /// getComplexType - Return the uniqued reference to the type for a complex
   /// number with the specified element type.
   QualType getComplexType(QualType T);
+  CanQualType getComplexType(CanQualType T) {
+    return CanQualType::CreateUnsafe(getComplexType((QualType) T));
+  }
 
   /// getPointerType - Return the uniqued reference to the type for a pointer to
   /// the specified type.
   QualType getPointerType(QualType T);
+  CanQualType getPointerType(CanQualType T) {
+    return CanQualType::CreateUnsafe(getPointerType((QualType) T));
+  }
 
   /// getBlockPointerType - Return the uniqued reference to the type for a block
   /// of the specified type.
@@ -739,7 +745,7 @@
   QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error);
 
 private:
-  QualType getFromTargetType(unsigned Type) const;
+  CanQualType getFromTargetType(unsigned Type) const;
 
   //===--------------------------------------------------------------------===//
   //                         Type Predicates.
@@ -1096,7 +1102,7 @@
   void operator=(const ASTContext&); // DO NOT IMPLEMENT
 
   void InitBuiltinTypes();
-  void InitBuiltinType(QualType &R, BuiltinType::Kind K);
+  void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
 
   // Return the ObjC type encoding for a given type.
   void getObjCEncodingForTypeImpl(QualType t, std::string &S,

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

==============================================================================
--- cfe/trunk/include/clang/AST/CanonicalType.h (original)
+++ cfe/trunk/include/clang/AST/CanonicalType.h Fri Oct 23 18:03:21 2009
@@ -64,15 +64,6 @@
   CanQual(const CanQual<U>& Other,
           typename llvm::enable_if<llvm::is_base_of<T, U>, int>::type = 0);
 
-  /// \brief Implicit conversion to the underlying pointer.
-  ///
-  /// Also provides the ability to use canonical types in a boolean context,
-  /// e.g.,
-  /// @code
-  ///   if (CanQual<PointerType> Ptr = T->getAs<PointerType>()) { ... }
-  /// @endcode
-  operator const T*() const { return getTypePtr(); }
-
   /// \brief Retrieve the underlying type pointer, which refers to a
   /// canonical type.
   T *getTypePtr() const { return cast_or_null<T>(Stored.getTypePtr()); }
@@ -80,6 +71,10 @@
   /// \brief Implicit conversion to a qualified type.
   operator QualType() const { return Stored; }
 
+  bool isNull() const {
+    return Stored.isNull();
+  }
+
   /// \brief Retrieve a canonical type pointer with a different static type,
   /// upcasting or downcasting as needed.
   ///
@@ -125,8 +120,10 @@
   /// \brief Retrieve the unqualified form of this type.
   CanQual<T> getUnqualifiedType() const;
 
-  CanQual<T> getQualifiedType(unsigned TQs) const {
-    return CanQual<T>::CreateUnsafe(QualType(getTypePtr(), TQs));
+  /// \brief Retrieves a version of this type with const applied.
+  /// Note that this does not always yield a canonical type.
+  QualType withConst() const {
+    return Stored.withConst();
   }
 
   /// \brief Determines whether this canonical type is more qualified than

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

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Oct 23 18:03:21 2009
@@ -138,9 +138,9 @@
 }
 
 
-void ASTContext::InitBuiltinType(QualType &R, BuiltinType::Kind K) {
+void ASTContext::InitBuiltinType(CanQualType &R, BuiltinType::Kind K) {
   BuiltinType *Ty = new (*this, TypeAlignment) BuiltinType(K);
-  R = QualType(Ty, 0);
+  R = CanQualType::CreateUnsafe(QualType(Ty, 0));
   Types.push_back(Ty);
 }
 
@@ -3600,9 +3600,9 @@
 /// getFromTargetType - Given one of the integer types provided by
 /// TargetInfo, produce the corresponding type. The unsigned @p Type
 /// is actually a value of type @c TargetInfo::IntType.
-QualType ASTContext::getFromTargetType(unsigned Type) const {
+CanQualType ASTContext::getFromTargetType(unsigned Type) const {
   switch (Type) {
-  case TargetInfo::NoInt: return QualType();
+  case TargetInfo::NoInt: return CanQualType();
   case TargetInfo::SignedShort: return ShortTy;
   case TargetInfo::UnsignedShort: return UnsignedShortTy;
   case TargetInfo::SignedInt: return IntTy;
@@ -3614,7 +3614,7 @@
   }
 
   assert(false && "Unhandled TargetInfo::IntType value");
-  return QualType();
+  return CanQualType();
 }
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=84976&r1=84975&r2=84976&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Fri Oct 23 18:03:21 2009
@@ -180,7 +180,7 @@
 }
 
 const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
-  const clang::Type &Ty = *Context.getCanonicalType(T);
+  const clang::Type &Ty = *Context.getCanonicalType(T).getTypePtr();
 
   switch (Ty.getTypeClass()) {
 #define TYPE(Class, Base)

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Fri Oct 23 18:03:21 2009
@@ -1643,15 +1643,15 @@
   //   performed on the types used for partial ordering: 
   //     - If P is a reference type, P is replaced by the type referred to. 
   CanQual<ReferenceType> ParamRef = Param->getAs<ReferenceType>();
-  if (ParamRef)
+  if (!ParamRef.isNull())
     Param = ParamRef->getPointeeType();
   
   //     - If A is a reference type, A is replaced by the type referred to.
   CanQual<ReferenceType> ArgRef = Arg->getAs<ReferenceType>();
-  if (ArgRef)
+  if (!ArgRef.isNull())
     Arg = ArgRef->getPointeeType();
   
-  if (QualifierComparisons && ParamRef && ArgRef) {
+  if (QualifierComparisons && !ParamRef.isNull() && !ArgRef.isNull()) {
     // C++0x [temp.deduct.partial]p6:
     //   If both P and A were reference types (before being replaced with the 
     //   type referred to above), determine which of the two types (if any) is 





More information about the cfe-commits mailing list