]> granicus.if.org Git - clang/commitdiff
Store the builtin types as CanQualTypes. Expand a bit on the CanQual API,
authorJohn McCall <rjmccall@apple.com>
Fri, 23 Oct 2009 23:03:21 +0000 (23:03 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 23 Oct 2009 23:03:21 +0000 (23:03 +0000)
but also remove some methods that cause ambiguities, and generally
make CanQual<blah> more analogous to QualType.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84976 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ASTContext.h
include/clang/AST/CanonicalType.h
lib/AST/ASTContext.cpp
lib/CodeGen/CodeGenTypes.cpp
lib/Sema/SemaTemplateDeduction.cpp

index 66e69995c698e12cfcab1cd9bd747ca54f0ab349..3acddab4b2c0f946f8b00694dd4d05fe3f65acb2 100644 (file)
@@ -301,22 +301,22 @@ public:
   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 @@ public:
   /// 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 @@ public:
   QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error);
 
 private:
-  QualType getFromTargetType(unsigned Type) const;
+  CanQualType getFromTargetType(unsigned Type) const;
 
   //===--------------------------------------------------------------------===//
   //                         Type Predicates.
@@ -1096,7 +1102,7 @@ private:
   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,
index 8b84bc26799769485891d44130fcf86513c926c0..a7750517090e6c70ed3a050d3dd042e391836c1b 100644 (file)
@@ -64,15 +64,6 @@ public:
   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 @@ public:
   /// \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 @@ public:
   /// \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
index 3ece8c95a27a70f2427f6f358456d5d5a38bdf5b..5d6d0ba3a15cb68632dcf98ca49a0e67d495a5e5 100644 (file)
@@ -138,9 +138,9 @@ void ASTContext::PrintStats() const {
 }
 
 
-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 @@ TemplateName ASTContext::getDependentTemplateName(NestedNameSpecifier *NNS,
 /// 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 @@ QualType ASTContext::getFromTargetType(unsigned Type) const {
   }
 
   assert(false && "Unhandled TargetInfo::IntType value");
-  return QualType();
+  return CanQualType();
 }
 
 //===----------------------------------------------------------------------===//
index dedf824ef9fd46d608bad5d6398afa3f7fe9b038..d43d13e26bbb2d57ae25d69821eb197726f62686 100644 (file)
@@ -180,7 +180,7 @@ static const llvm::Type* getTypeForFormat(llvm::LLVMContext &VMContext,
 }
 
 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)
index 2a44f83598e8ba41ec2e447e7bbbdda4ada7a04e..32ae0a8dd01e1d3da7855ef42a2374c744753fab 100644 (file)
@@ -1643,15 +1643,15 @@ DeduceTemplateArgumentsDuringPartialOrdering(ASTContext &Context,
   //   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