clang API Documentation
00001 //===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the Type interface and subclasses. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_AST_TYPE_H 00015 #define LLVM_CLANG_AST_TYPE_H 00016 00017 #include "clang/AST/NestedNameSpecifier.h" 00018 #include "clang/AST/TemplateName.h" 00019 #include "clang/Basic/Diagnostic.h" 00020 #include "clang/Basic/ExceptionSpecificationType.h" 00021 #include "clang/Basic/LLVM.h" 00022 #include "clang/Basic/Linkage.h" 00023 #include "clang/Basic/PartialDiagnostic.h" 00024 #include "clang/Basic/Specifiers.h" 00025 #include "clang/Basic/Visibility.h" 00026 #include "llvm/ADT/APInt.h" 00027 #include "llvm/ADT/FoldingSet.h" 00028 #include "llvm/ADT/iterator_range.h" 00029 #include "llvm/ADT/Optional.h" 00030 #include "llvm/ADT/PointerIntPair.h" 00031 #include "llvm/ADT/PointerUnion.h" 00032 #include "llvm/ADT/Twine.h" 00033 #include "llvm/Support/ErrorHandling.h" 00034 00035 namespace clang { 00036 enum { 00037 TypeAlignmentInBits = 4, 00038 TypeAlignment = 1 << TypeAlignmentInBits 00039 }; 00040 class Type; 00041 class ExtQuals; 00042 class QualType; 00043 } 00044 00045 namespace llvm { 00046 template <typename T> 00047 class PointerLikeTypeTraits; 00048 template<> 00049 class PointerLikeTypeTraits< ::clang::Type*> { 00050 public: 00051 static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 00052 static inline ::clang::Type *getFromVoidPointer(void *P) { 00053 return static_cast< ::clang::Type*>(P); 00054 } 00055 enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 00056 }; 00057 template<> 00058 class PointerLikeTypeTraits< ::clang::ExtQuals*> { 00059 public: 00060 static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; } 00061 static inline ::clang::ExtQuals *getFromVoidPointer(void *P) { 00062 return static_cast< ::clang::ExtQuals*>(P); 00063 } 00064 enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 00065 }; 00066 00067 template <> 00068 struct isPodLike<clang::QualType> { static const bool value = true; }; 00069 } 00070 00071 namespace clang { 00072 class ASTContext; 00073 class TypedefNameDecl; 00074 class TemplateDecl; 00075 class TemplateTypeParmDecl; 00076 class NonTypeTemplateParmDecl; 00077 class TemplateTemplateParmDecl; 00078 class TagDecl; 00079 class RecordDecl; 00080 class CXXRecordDecl; 00081 class EnumDecl; 00082 class FieldDecl; 00083 class FunctionDecl; 00084 class ObjCInterfaceDecl; 00085 class ObjCProtocolDecl; 00086 class ObjCMethodDecl; 00087 class UnresolvedUsingTypenameDecl; 00088 class Expr; 00089 class Stmt; 00090 class SourceLocation; 00091 class StmtIteratorBase; 00092 class TemplateArgument; 00093 class TemplateArgumentLoc; 00094 class TemplateArgumentListInfo; 00095 class ElaboratedType; 00096 class ExtQuals; 00097 class ExtQualsTypeCommonBase; 00098 struct PrintingPolicy; 00099 00100 template <typename> class CanQual; 00101 typedef CanQual<Type> CanQualType; 00102 00103 // Provide forward declarations for all of the *Type classes 00104 #define TYPE(Class, Base) class Class##Type; 00105 #include "clang/AST/TypeNodes.def" 00106 00107 /// Qualifiers - The collection of all-type qualifiers we support. 00108 /// Clang supports five independent qualifiers: 00109 /// * C99: const, volatile, and restrict 00110 /// * Embedded C (TR18037): address spaces 00111 /// * Objective C: the GC attributes (none, weak, or strong) 00112 class Qualifiers { 00113 public: 00114 enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 00115 Const = 0x1, 00116 Restrict = 0x2, 00117 Volatile = 0x4, 00118 CVRMask = Const | Volatile | Restrict 00119 }; 00120 00121 enum GC { 00122 GCNone = 0, 00123 Weak, 00124 Strong 00125 }; 00126 00127 enum ObjCLifetime { 00128 /// There is no lifetime qualification on this type. 00129 OCL_None, 00130 00131 /// This object can be modified without requiring retains or 00132 /// releases. 00133 OCL_ExplicitNone, 00134 00135 /// Assigning into this object requires the old value to be 00136 /// released and the new value to be retained. The timing of the 00137 /// release of the old value is inexact: it may be moved to 00138 /// immediately after the last known point where the value is 00139 /// live. 00140 OCL_Strong, 00141 00142 /// Reading or writing from this object requires a barrier call. 00143 OCL_Weak, 00144 00145 /// Assigning into this object requires a lifetime extension. 00146 OCL_Autoreleasing 00147 }; 00148 00149 enum { 00150 /// The maximum supported address space number. 00151 /// 24 bits should be enough for anyone. 00152 MaxAddressSpace = 0xffffffu, 00153 00154 /// The width of the "fast" qualifier mask. 00155 FastWidth = 3, 00156 00157 /// The fast qualifier mask. 00158 FastMask = (1 << FastWidth) - 1 00159 }; 00160 00161 Qualifiers() : Mask(0) {} 00162 00163 /// \brief Returns the common set of qualifiers while removing them from 00164 /// the given sets. 00165 static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R) { 00166 // If both are only CVR-qualified, bit operations are sufficient. 00167 if (!(L.Mask & ~CVRMask) && !(R.Mask & ~CVRMask)) { 00168 Qualifiers Q; 00169 Q.Mask = L.Mask & R.Mask; 00170 L.Mask &= ~Q.Mask; 00171 R.Mask &= ~Q.Mask; 00172 return Q; 00173 } 00174 00175 Qualifiers Q; 00176 unsigned CommonCRV = L.getCVRQualifiers() & R.getCVRQualifiers(); 00177 Q.addCVRQualifiers(CommonCRV); 00178 L.removeCVRQualifiers(CommonCRV); 00179 R.removeCVRQualifiers(CommonCRV); 00180 00181 if (L.getObjCGCAttr() == R.getObjCGCAttr()) { 00182 Q.setObjCGCAttr(L.getObjCGCAttr()); 00183 L.removeObjCGCAttr(); 00184 R.removeObjCGCAttr(); 00185 } 00186 00187 if (L.getObjCLifetime() == R.getObjCLifetime()) { 00188 Q.setObjCLifetime(L.getObjCLifetime()); 00189 L.removeObjCLifetime(); 00190 R.removeObjCLifetime(); 00191 } 00192 00193 if (L.getAddressSpace() == R.getAddressSpace()) { 00194 Q.setAddressSpace(L.getAddressSpace()); 00195 L.removeAddressSpace(); 00196 R.removeAddressSpace(); 00197 } 00198 return Q; 00199 } 00200 00201 static Qualifiers fromFastMask(unsigned Mask) { 00202 Qualifiers Qs; 00203 Qs.addFastQualifiers(Mask); 00204 return Qs; 00205 } 00206 00207 static Qualifiers fromCVRMask(unsigned CVR) { 00208 Qualifiers Qs; 00209 Qs.addCVRQualifiers(CVR); 00210 return Qs; 00211 } 00212 00213 // Deserialize qualifiers from an opaque representation. 00214 static Qualifiers fromOpaqueValue(unsigned opaque) { 00215 Qualifiers Qs; 00216 Qs.Mask = opaque; 00217 return Qs; 00218 } 00219 00220 // Serialize these qualifiers into an opaque representation. 00221 unsigned getAsOpaqueValue() const { 00222 return Mask; 00223 } 00224 00225 bool hasConst() const { return Mask & Const; } 00226 void setConst(bool flag) { 00227 Mask = (Mask & ~Const) | (flag ? Const : 0); 00228 } 00229 void removeConst() { Mask &= ~Const; } 00230 void addConst() { Mask |= Const; } 00231 00232 bool hasVolatile() const { return Mask & Volatile; } 00233 void setVolatile(bool flag) { 00234 Mask = (Mask & ~Volatile) | (flag ? Volatile : 0); 00235 } 00236 void removeVolatile() { Mask &= ~Volatile; } 00237 void addVolatile() { Mask |= Volatile; } 00238 00239 bool hasRestrict() const { return Mask & Restrict; } 00240 void setRestrict(bool flag) { 00241 Mask = (Mask & ~Restrict) | (flag ? Restrict : 0); 00242 } 00243 void removeRestrict() { Mask &= ~Restrict; } 00244 void addRestrict() { Mask |= Restrict; } 00245 00246 bool hasCVRQualifiers() const { return getCVRQualifiers(); } 00247 unsigned getCVRQualifiers() const { return Mask & CVRMask; } 00248 void setCVRQualifiers(unsigned mask) { 00249 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 00250 Mask = (Mask & ~CVRMask) | mask; 00251 } 00252 void removeCVRQualifiers(unsigned mask) { 00253 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 00254 Mask &= ~mask; 00255 } 00256 void removeCVRQualifiers() { 00257 removeCVRQualifiers(CVRMask); 00258 } 00259 void addCVRQualifiers(unsigned mask) { 00260 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 00261 Mask |= mask; 00262 } 00263 00264 bool hasObjCGCAttr() const { return Mask & GCAttrMask; } 00265 GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); } 00266 void setObjCGCAttr(GC type) { 00267 Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift); 00268 } 00269 void removeObjCGCAttr() { setObjCGCAttr(GCNone); } 00270 void addObjCGCAttr(GC type) { 00271 assert(type); 00272 setObjCGCAttr(type); 00273 } 00274 Qualifiers withoutObjCGCAttr() const { 00275 Qualifiers qs = *this; 00276 qs.removeObjCGCAttr(); 00277 return qs; 00278 } 00279 Qualifiers withoutObjCLifetime() const { 00280 Qualifiers qs = *this; 00281 qs.removeObjCLifetime(); 00282 return qs; 00283 } 00284 00285 bool hasObjCLifetime() const { return Mask & LifetimeMask; } 00286 ObjCLifetime getObjCLifetime() const { 00287 return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift); 00288 } 00289 void setObjCLifetime(ObjCLifetime type) { 00290 Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift); 00291 } 00292 void removeObjCLifetime() { setObjCLifetime(OCL_None); } 00293 void addObjCLifetime(ObjCLifetime type) { 00294 assert(type); 00295 assert(!hasObjCLifetime()); 00296 Mask |= (type << LifetimeShift); 00297 } 00298 00299 /// True if the lifetime is neither None or ExplicitNone. 00300 bool hasNonTrivialObjCLifetime() const { 00301 ObjCLifetime lifetime = getObjCLifetime(); 00302 return (lifetime > OCL_ExplicitNone); 00303 } 00304 00305 /// True if the lifetime is either strong or weak. 00306 bool hasStrongOrWeakObjCLifetime() const { 00307 ObjCLifetime lifetime = getObjCLifetime(); 00308 return (lifetime == OCL_Strong || lifetime == OCL_Weak); 00309 } 00310 00311 bool hasAddressSpace() const { return Mask & AddressSpaceMask; } 00312 unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; } 00313 void setAddressSpace(unsigned space) { 00314 assert(space <= MaxAddressSpace); 00315 Mask = (Mask & ~AddressSpaceMask) 00316 | (((uint32_t) space) << AddressSpaceShift); 00317 } 00318 void removeAddressSpace() { setAddressSpace(0); } 00319 void addAddressSpace(unsigned space) { 00320 assert(space); 00321 setAddressSpace(space); 00322 } 00323 00324 // Fast qualifiers are those that can be allocated directly 00325 // on a QualType object. 00326 bool hasFastQualifiers() const { return getFastQualifiers(); } 00327 unsigned getFastQualifiers() const { return Mask & FastMask; } 00328 void setFastQualifiers(unsigned mask) { 00329 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 00330 Mask = (Mask & ~FastMask) | mask; 00331 } 00332 void removeFastQualifiers(unsigned mask) { 00333 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 00334 Mask &= ~mask; 00335 } 00336 void removeFastQualifiers() { 00337 removeFastQualifiers(FastMask); 00338 } 00339 void addFastQualifiers(unsigned mask) { 00340 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 00341 Mask |= mask; 00342 } 00343 00344 /// hasNonFastQualifiers - Return true if the set contains any 00345 /// qualifiers which require an ExtQuals node to be allocated. 00346 bool hasNonFastQualifiers() const { return Mask & ~FastMask; } 00347 Qualifiers getNonFastQualifiers() const { 00348 Qualifiers Quals = *this; 00349 Quals.setFastQualifiers(0); 00350 return Quals; 00351 } 00352 00353 /// hasQualifiers - Return true if the set contains any qualifiers. 00354 bool hasQualifiers() const { return Mask; } 00355 bool empty() const { return !Mask; } 00356 00357 /// \brief Add the qualifiers from the given set to this set. 00358 void addQualifiers(Qualifiers Q) { 00359 // If the other set doesn't have any non-boolean qualifiers, just 00360 // bit-or it in. 00361 if (!(Q.Mask & ~CVRMask)) 00362 Mask |= Q.Mask; 00363 else { 00364 Mask |= (Q.Mask & CVRMask); 00365 if (Q.hasAddressSpace()) 00366 addAddressSpace(Q.getAddressSpace()); 00367 if (Q.hasObjCGCAttr()) 00368 addObjCGCAttr(Q.getObjCGCAttr()); 00369 if (Q.hasObjCLifetime()) 00370 addObjCLifetime(Q.getObjCLifetime()); 00371 } 00372 } 00373 00374 /// \brief Remove the qualifiers from the given set from this set. 00375 void removeQualifiers(Qualifiers Q) { 00376 // If the other set doesn't have any non-boolean qualifiers, just 00377 // bit-and the inverse in. 00378 if (!(Q.Mask & ~CVRMask)) 00379 Mask &= ~Q.Mask; 00380 else { 00381 Mask &= ~(Q.Mask & CVRMask); 00382 if (getObjCGCAttr() == Q.getObjCGCAttr()) 00383 removeObjCGCAttr(); 00384 if (getObjCLifetime() == Q.getObjCLifetime()) 00385 removeObjCLifetime(); 00386 if (getAddressSpace() == Q.getAddressSpace()) 00387 removeAddressSpace(); 00388 } 00389 } 00390 00391 /// \brief Add the qualifiers from the given set to this set, given that 00392 /// they don't conflict. 00393 void addConsistentQualifiers(Qualifiers qs) { 00394 assert(getAddressSpace() == qs.getAddressSpace() || 00395 !hasAddressSpace() || !qs.hasAddressSpace()); 00396 assert(getObjCGCAttr() == qs.getObjCGCAttr() || 00397 !hasObjCGCAttr() || !qs.hasObjCGCAttr()); 00398 assert(getObjCLifetime() == qs.getObjCLifetime() || 00399 !hasObjCLifetime() || !qs.hasObjCLifetime()); 00400 Mask |= qs.Mask; 00401 } 00402 00403 /// \brief Determines if these qualifiers compatibly include another set. 00404 /// Generally this answers the question of whether an object with the other 00405 /// qualifiers can be safely used as an object with these qualifiers. 00406 bool compatiblyIncludes(Qualifiers other) const { 00407 return 00408 // Address spaces must match exactly. 00409 getAddressSpace() == other.getAddressSpace() && 00410 // ObjC GC qualifiers can match, be added, or be removed, but can't be 00411 // changed. 00412 (getObjCGCAttr() == other.getObjCGCAttr() || 00413 !hasObjCGCAttr() || !other.hasObjCGCAttr()) && 00414 // ObjC lifetime qualifiers must match exactly. 00415 getObjCLifetime() == other.getObjCLifetime() && 00416 // CVR qualifiers may subset. 00417 (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)); 00418 } 00419 00420 /// \brief Determines if these qualifiers compatibly include another set of 00421 /// qualifiers from the narrow perspective of Objective-C ARC lifetime. 00422 /// 00423 /// One set of Objective-C lifetime qualifiers compatibly includes the other 00424 /// if the lifetime qualifiers match, or if both are non-__weak and the 00425 /// including set also contains the 'const' qualifier. 00426 bool compatiblyIncludesObjCLifetime(Qualifiers other) const { 00427 if (getObjCLifetime() == other.getObjCLifetime()) 00428 return true; 00429 00430 if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak) 00431 return false; 00432 00433 return hasConst(); 00434 } 00435 00436 /// \brief Determine whether this set of qualifiers is a strict superset of 00437 /// another set of qualifiers, not considering qualifier compatibility. 00438 bool isStrictSupersetOf(Qualifiers Other) const; 00439 00440 bool operator==(Qualifiers Other) const { return Mask == Other.Mask; } 00441 bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; } 00442 00443 LLVM_EXPLICIT operator bool() const { return hasQualifiers(); } 00444 00445 Qualifiers &operator+=(Qualifiers R) { 00446 addQualifiers(R); 00447 return *this; 00448 } 00449 00450 // Union two qualifier sets. If an enumerated qualifier appears 00451 // in both sets, use the one from the right. 00452 friend Qualifiers operator+(Qualifiers L, Qualifiers R) { 00453 L += R; 00454 return L; 00455 } 00456 00457 Qualifiers &operator-=(Qualifiers R) { 00458 removeQualifiers(R); 00459 return *this; 00460 } 00461 00462 /// \brief Compute the difference between two qualifier sets. 00463 friend Qualifiers operator-(Qualifiers L, Qualifiers R) { 00464 L -= R; 00465 return L; 00466 } 00467 00468 std::string getAsString() const; 00469 std::string getAsString(const PrintingPolicy &Policy) const; 00470 00471 bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const; 00472 void print(raw_ostream &OS, const PrintingPolicy &Policy, 00473 bool appendSpaceIfNonEmpty = false) const; 00474 00475 void Profile(llvm::FoldingSetNodeID &ID) const { 00476 ID.AddInteger(Mask); 00477 } 00478 00479 private: 00480 00481 // bits: |0 1 2|3 .. 4|5 .. 7|8 ... 31| 00482 // |C R V|GCAttr|Lifetime|AddressSpace| 00483 uint32_t Mask; 00484 00485 static const uint32_t GCAttrMask = 0x18; 00486 static const uint32_t GCAttrShift = 3; 00487 static const uint32_t LifetimeMask = 0xE0; 00488 static const uint32_t LifetimeShift = 5; 00489 static const uint32_t AddressSpaceMask = ~(CVRMask|GCAttrMask|LifetimeMask); 00490 static const uint32_t AddressSpaceShift = 8; 00491 }; 00492 00493 /// A std::pair-like structure for storing a qualified type split 00494 /// into its local qualifiers and its locally-unqualified type. 00495 struct SplitQualType { 00496 /// The locally-unqualified type. 00497 const Type *Ty; 00498 00499 /// The local qualifiers. 00500 Qualifiers Quals; 00501 00502 SplitQualType() : Ty(nullptr), Quals() {} 00503 SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {} 00504 00505 SplitQualType getSingleStepDesugaredType() const; // end of this file 00506 00507 // Make std::tie work. 00508 std::pair<const Type *,Qualifiers> asPair() const { 00509 return std::pair<const Type *, Qualifiers>(Ty, Quals); 00510 } 00511 00512 friend bool operator==(SplitQualType a, SplitQualType b) { 00513 return a.Ty == b.Ty && a.Quals == b.Quals; 00514 } 00515 friend bool operator!=(SplitQualType a, SplitQualType b) { 00516 return a.Ty != b.Ty || a.Quals != b.Quals; 00517 } 00518 }; 00519 00520 /// QualType - For efficiency, we don't store CV-qualified types as nodes on 00521 /// their own: instead each reference to a type stores the qualifiers. This 00522 /// greatly reduces the number of nodes we need to allocate for types (for 00523 /// example we only need one for 'int', 'const int', 'volatile int', 00524 /// 'const volatile int', etc). 00525 /// 00526 /// As an added efficiency bonus, instead of making this a pair, we 00527 /// just store the two bits we care about in the low bits of the 00528 /// pointer. To handle the packing/unpacking, we make QualType be a 00529 /// simple wrapper class that acts like a smart pointer. A third bit 00530 /// indicates whether there are extended qualifiers present, in which 00531 /// case the pointer points to a special structure. 00532 class QualType { 00533 // Thankfully, these are efficiently composable. 00534 llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>, 00535 Qualifiers::FastWidth> Value; 00536 00537 const ExtQuals *getExtQualsUnsafe() const { 00538 return Value.getPointer().get<const ExtQuals*>(); 00539 } 00540 00541 const Type *getTypePtrUnsafe() const { 00542 return Value.getPointer().get<const Type*>(); 00543 } 00544 00545 const ExtQualsTypeCommonBase *getCommonPtr() const { 00546 assert(!isNull() && "Cannot retrieve a NULL type pointer"); 00547 uintptr_t CommonPtrVal 00548 = reinterpret_cast<uintptr_t>(Value.getOpaqueValue()); 00549 CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1); 00550 return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal); 00551 } 00552 00553 friend class QualifierCollector; 00554 public: 00555 QualType() {} 00556 00557 QualType(const Type *Ptr, unsigned Quals) 00558 : Value(Ptr, Quals) {} 00559 QualType(const ExtQuals *Ptr, unsigned Quals) 00560 : Value(Ptr, Quals) {} 00561 00562 unsigned getLocalFastQualifiers() const { return Value.getInt(); } 00563 void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); } 00564 00565 /// Retrieves a pointer to the underlying (unqualified) type. 00566 /// 00567 /// This function requires that the type not be NULL. If the type might be 00568 /// NULL, use the (slightly less efficient) \c getTypePtrOrNull(). 00569 const Type *getTypePtr() const; 00570 00571 const Type *getTypePtrOrNull() const; 00572 00573 /// Retrieves a pointer to the name of the base type. 00574 const IdentifierInfo *getBaseTypeIdentifier() const; 00575 00576 /// Divides a QualType into its unqualified type and a set of local 00577 /// qualifiers. 00578 SplitQualType split() const; 00579 00580 void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 00581 static QualType getFromOpaquePtr(const void *Ptr) { 00582 QualType T; 00583 T.Value.setFromOpaqueValue(const_cast<void*>(Ptr)); 00584 return T; 00585 } 00586 00587 const Type &operator*() const { 00588 return *getTypePtr(); 00589 } 00590 00591 const Type *operator->() const { 00592 return getTypePtr(); 00593 } 00594 00595 bool isCanonical() const; 00596 bool isCanonicalAsParam() const; 00597 00598 /// isNull - Return true if this QualType doesn't point to a type yet. 00599 bool isNull() const { 00600 return Value.getPointer().isNull(); 00601 } 00602 00603 /// \brief Determine whether this particular QualType instance has the 00604 /// "const" qualifier set, without looking through typedefs that may have 00605 /// added "const" at a different level. 00606 bool isLocalConstQualified() const { 00607 return (getLocalFastQualifiers() & Qualifiers::Const); 00608 } 00609 00610 /// \brief Determine whether this type is const-qualified. 00611 bool isConstQualified() const; 00612 00613 /// \brief Determine whether this particular QualType instance has the 00614 /// "restrict" qualifier set, without looking through typedefs that may have 00615 /// added "restrict" at a different level. 00616 bool isLocalRestrictQualified() const { 00617 return (getLocalFastQualifiers() & Qualifiers::Restrict); 00618 } 00619 00620 /// \brief Determine whether this type is restrict-qualified. 00621 bool isRestrictQualified() const; 00622 00623 /// \brief Determine whether this particular QualType instance has the 00624 /// "volatile" qualifier set, without looking through typedefs that may have 00625 /// added "volatile" at a different level. 00626 bool isLocalVolatileQualified() const { 00627 return (getLocalFastQualifiers() & Qualifiers::Volatile); 00628 } 00629 00630 /// \brief Determine whether this type is volatile-qualified. 00631 bool isVolatileQualified() const; 00632 00633 /// \brief Determine whether this particular QualType instance has any 00634 /// qualifiers, without looking through any typedefs that might add 00635 /// qualifiers at a different level. 00636 bool hasLocalQualifiers() const { 00637 return getLocalFastQualifiers() || hasLocalNonFastQualifiers(); 00638 } 00639 00640 /// \brief Determine whether this type has any qualifiers. 00641 bool hasQualifiers() const; 00642 00643 /// \brief Determine whether this particular QualType instance has any 00644 /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType 00645 /// instance. 00646 bool hasLocalNonFastQualifiers() const { 00647 return Value.getPointer().is<const ExtQuals*>(); 00648 } 00649 00650 /// \brief Retrieve the set of qualifiers local to this particular QualType 00651 /// instance, not including any qualifiers acquired through typedefs or 00652 /// other sugar. 00653 Qualifiers getLocalQualifiers() const; 00654 00655 /// \brief Retrieve the set of qualifiers applied to this type. 00656 Qualifiers getQualifiers() const; 00657 00658 /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 00659 /// local to this particular QualType instance, not including any qualifiers 00660 /// acquired through typedefs or other sugar. 00661 unsigned getLocalCVRQualifiers() const { 00662 return getLocalFastQualifiers(); 00663 } 00664 00665 /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 00666 /// applied to this type. 00667 unsigned getCVRQualifiers() const; 00668 00669 bool isConstant(ASTContext& Ctx) const { 00670 return QualType::isConstant(*this, Ctx); 00671 } 00672 00673 /// \brief Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10). 00674 bool isPODType(ASTContext &Context) const; 00675 00676 /// isCXX98PODType() - Return true if this is a POD type according to the 00677 /// rules of the C++98 standard, regardless of the current compilation's 00678 /// language. 00679 bool isCXX98PODType(ASTContext &Context) const; 00680 00681 /// isCXX11PODType() - Return true if this is a POD type according to the 00682 /// more relaxed rules of the C++11 standard, regardless of the current 00683 /// compilation's language. 00684 /// (C++0x [basic.types]p9) 00685 bool isCXX11PODType(ASTContext &Context) const; 00686 00687 /// isTrivialType - Return true if this is a trivial type 00688 /// (C++0x [basic.types]p9) 00689 bool isTrivialType(ASTContext &Context) const; 00690 00691 /// isTriviallyCopyableType - Return true if this is a trivially 00692 /// copyable type (C++0x [basic.types]p9) 00693 bool isTriviallyCopyableType(ASTContext &Context) const; 00694 00695 // Don't promise in the API that anything besides 'const' can be 00696 // easily added. 00697 00698 /// addConst - add the specified type qualifier to this QualType. 00699 void addConst() { 00700 addFastQualifiers(Qualifiers::Const); 00701 } 00702 QualType withConst() const { 00703 return withFastQualifiers(Qualifiers::Const); 00704 } 00705 00706 /// addVolatile - add the specified type qualifier to this QualType. 00707 void addVolatile() { 00708 addFastQualifiers(Qualifiers::Volatile); 00709 } 00710 QualType withVolatile() const { 00711 return withFastQualifiers(Qualifiers::Volatile); 00712 } 00713 00714 /// Add the restrict qualifier to this QualType. 00715 void addRestrict() { 00716 addFastQualifiers(Qualifiers::Restrict); 00717 } 00718 QualType withRestrict() const { 00719 return withFastQualifiers(Qualifiers::Restrict); 00720 } 00721 00722 QualType withCVRQualifiers(unsigned CVR) const { 00723 return withFastQualifiers(CVR); 00724 } 00725 00726 void addFastQualifiers(unsigned TQs) { 00727 assert(!(TQs & ~Qualifiers::FastMask) 00728 && "non-fast qualifier bits set in mask!"); 00729 Value.setInt(Value.getInt() | TQs); 00730 } 00731 00732 void removeLocalConst(); 00733 void removeLocalVolatile(); 00734 void removeLocalRestrict(); 00735 void removeLocalCVRQualifiers(unsigned Mask); 00736 00737 void removeLocalFastQualifiers() { Value.setInt(0); } 00738 void removeLocalFastQualifiers(unsigned Mask) { 00739 assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers"); 00740 Value.setInt(Value.getInt() & ~Mask); 00741 } 00742 00743 // Creates a type with the given qualifiers in addition to any 00744 // qualifiers already on this type. 00745 QualType withFastQualifiers(unsigned TQs) const { 00746 QualType T = *this; 00747 T.addFastQualifiers(TQs); 00748 return T; 00749 } 00750 00751 // Creates a type with exactly the given fast qualifiers, removing 00752 // any existing fast qualifiers. 00753 QualType withExactLocalFastQualifiers(unsigned TQs) const { 00754 return withoutLocalFastQualifiers().withFastQualifiers(TQs); 00755 } 00756 00757 // Removes fast qualifiers, but leaves any extended qualifiers in place. 00758 QualType withoutLocalFastQualifiers() const { 00759 QualType T = *this; 00760 T.removeLocalFastQualifiers(); 00761 return T; 00762 } 00763 00764 QualType getCanonicalType() const; 00765 00766 /// \brief Return this type with all of the instance-specific qualifiers 00767 /// removed, but without removing any qualifiers that may have been applied 00768 /// through typedefs. 00769 QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); } 00770 00771 /// \brief Retrieve the unqualified variant of the given type, 00772 /// removing as little sugar as possible. 00773 /// 00774 /// This routine looks through various kinds of sugar to find the 00775 /// least-desugared type that is unqualified. For example, given: 00776 /// 00777 /// \code 00778 /// typedef int Integer; 00779 /// typedef const Integer CInteger; 00780 /// typedef CInteger DifferenceType; 00781 /// \endcode 00782 /// 00783 /// Executing \c getUnqualifiedType() on the type \c DifferenceType will 00784 /// desugar until we hit the type \c Integer, which has no qualifiers on it. 00785 /// 00786 /// The resulting type might still be qualified if it's sugar for an array 00787 /// type. To strip qualifiers even from within a sugared array type, use 00788 /// ASTContext::getUnqualifiedArrayType. 00789 inline QualType getUnqualifiedType() const; 00790 00791 /// getSplitUnqualifiedType - Retrieve the unqualified variant of the 00792 /// given type, removing as little sugar as possible. 00793 /// 00794 /// Like getUnqualifiedType(), but also returns the set of 00795 /// qualifiers that were built up. 00796 /// 00797 /// The resulting type might still be qualified if it's sugar for an array 00798 /// type. To strip qualifiers even from within a sugared array type, use 00799 /// ASTContext::getUnqualifiedArrayType. 00800 inline SplitQualType getSplitUnqualifiedType() const; 00801 00802 /// \brief Determine whether this type is more qualified than the other 00803 /// given type, requiring exact equality for non-CVR qualifiers. 00804 bool isMoreQualifiedThan(QualType Other) const; 00805 00806 /// \brief Determine whether this type is at least as qualified as the other 00807 /// given type, requiring exact equality for non-CVR qualifiers. 00808 bool isAtLeastAsQualifiedAs(QualType Other) const; 00809 00810 QualType getNonReferenceType() const; 00811 00812 /// \brief Determine the type of a (typically non-lvalue) expression with the 00813 /// specified result type. 00814 /// 00815 /// This routine should be used for expressions for which the return type is 00816 /// explicitly specified (e.g., in a cast or call) and isn't necessarily 00817 /// an lvalue. It removes a top-level reference (since there are no 00818 /// expressions of reference type) and deletes top-level cvr-qualifiers 00819 /// from non-class types (in C++) or all types (in C). 00820 QualType getNonLValueExprType(const ASTContext &Context) const; 00821 00822 /// getDesugaredType - Return the specified type with any "sugar" removed from 00823 /// the type. This takes off typedefs, typeof's etc. If the outer level of 00824 /// the type is already concrete, it returns it unmodified. This is similar 00825 /// to getting the canonical type, but it doesn't remove *all* typedefs. For 00826 /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 00827 /// concrete. 00828 /// 00829 /// Qualifiers are left in place. 00830 QualType getDesugaredType(const ASTContext &Context) const { 00831 return getDesugaredType(*this, Context); 00832 } 00833 00834 SplitQualType getSplitDesugaredType() const { 00835 return getSplitDesugaredType(*this); 00836 } 00837 00838 /// \brief Return the specified type with one level of "sugar" removed from 00839 /// the type. 00840 /// 00841 /// This routine takes off the first typedef, typeof, etc. If the outer level 00842 /// of the type is already concrete, it returns it unmodified. 00843 QualType getSingleStepDesugaredType(const ASTContext &Context) const { 00844 return getSingleStepDesugaredTypeImpl(*this, Context); 00845 } 00846 00847 /// IgnoreParens - Returns the specified type after dropping any 00848 /// outer-level parentheses. 00849 QualType IgnoreParens() const { 00850 if (isa<ParenType>(*this)) 00851 return QualType::IgnoreParens(*this); 00852 return *this; 00853 } 00854 00855 /// operator==/!= - Indicate whether the specified types and qualifiers are 00856 /// identical. 00857 friend bool operator==(const QualType &LHS, const QualType &RHS) { 00858 return LHS.Value == RHS.Value; 00859 } 00860 friend bool operator!=(const QualType &LHS, const QualType &RHS) { 00861 return LHS.Value != RHS.Value; 00862 } 00863 std::string getAsString() const { 00864 return getAsString(split()); 00865 } 00866 static std::string getAsString(SplitQualType split) { 00867 return getAsString(split.Ty, split.Quals); 00868 } 00869 static std::string getAsString(const Type *ty, Qualifiers qs); 00870 00871 std::string getAsString(const PrintingPolicy &Policy) const; 00872 00873 void print(raw_ostream &OS, const PrintingPolicy &Policy, 00874 const Twine &PlaceHolder = Twine()) const { 00875 print(split(), OS, Policy, PlaceHolder); 00876 } 00877 static void print(SplitQualType split, raw_ostream &OS, 00878 const PrintingPolicy &policy, const Twine &PlaceHolder) { 00879 return print(split.Ty, split.Quals, OS, policy, PlaceHolder); 00880 } 00881 static void print(const Type *ty, Qualifiers qs, 00882 raw_ostream &OS, const PrintingPolicy &policy, 00883 const Twine &PlaceHolder); 00884 00885 void getAsStringInternal(std::string &Str, 00886 const PrintingPolicy &Policy) const { 00887 return getAsStringInternal(split(), Str, Policy); 00888 } 00889 static void getAsStringInternal(SplitQualType split, std::string &out, 00890 const PrintingPolicy &policy) { 00891 return getAsStringInternal(split.Ty, split.Quals, out, policy); 00892 } 00893 static void getAsStringInternal(const Type *ty, Qualifiers qs, 00894 std::string &out, 00895 const PrintingPolicy &policy); 00896 00897 class StreamedQualTypeHelper { 00898 const QualType &T; 00899 const PrintingPolicy &Policy; 00900 const Twine &PlaceHolder; 00901 public: 00902 StreamedQualTypeHelper(const QualType &T, const PrintingPolicy &Policy, 00903 const Twine &PlaceHolder) 00904 : T(T), Policy(Policy), PlaceHolder(PlaceHolder) { } 00905 00906 friend raw_ostream &operator<<(raw_ostream &OS, 00907 const StreamedQualTypeHelper &SQT) { 00908 SQT.T.print(OS, SQT.Policy, SQT.PlaceHolder); 00909 return OS; 00910 } 00911 }; 00912 00913 StreamedQualTypeHelper stream(const PrintingPolicy &Policy, 00914 const Twine &PlaceHolder = Twine()) const { 00915 return StreamedQualTypeHelper(*this, Policy, PlaceHolder); 00916 } 00917 00918 void dump(const char *s) const; 00919 void dump() const; 00920 00921 void Profile(llvm::FoldingSetNodeID &ID) const { 00922 ID.AddPointer(getAsOpaquePtr()); 00923 } 00924 00925 /// getAddressSpace - Return the address space of this type. 00926 inline unsigned getAddressSpace() const; 00927 00928 /// getObjCGCAttr - Returns gc attribute of this type. 00929 inline Qualifiers::GC getObjCGCAttr() const; 00930 00931 /// isObjCGCWeak true when Type is objc's weak. 00932 bool isObjCGCWeak() const { 00933 return getObjCGCAttr() == Qualifiers::Weak; 00934 } 00935 00936 /// isObjCGCStrong true when Type is objc's strong. 00937 bool isObjCGCStrong() const { 00938 return getObjCGCAttr() == Qualifiers::Strong; 00939 } 00940 00941 /// getObjCLifetime - Returns lifetime attribute of this type. 00942 Qualifiers::ObjCLifetime getObjCLifetime() const { 00943 return getQualifiers().getObjCLifetime(); 00944 } 00945 00946 bool hasNonTrivialObjCLifetime() const { 00947 return getQualifiers().hasNonTrivialObjCLifetime(); 00948 } 00949 00950 bool hasStrongOrWeakObjCLifetime() const { 00951 return getQualifiers().hasStrongOrWeakObjCLifetime(); 00952 } 00953 00954 enum DestructionKind { 00955 DK_none, 00956 DK_cxx_destructor, 00957 DK_objc_strong_lifetime, 00958 DK_objc_weak_lifetime 00959 }; 00960 00961 /// isDestructedType - nonzero if objects of this type require 00962 /// non-trivial work to clean up after. Non-zero because it's 00963 /// conceivable that qualifiers (objc_gc(weak)?) could make 00964 /// something require destruction. 00965 DestructionKind isDestructedType() const { 00966 return isDestructedTypeImpl(*this); 00967 } 00968 00969 /// \brief Determine whether expressions of the given type are forbidden 00970 /// from being lvalues in C. 00971 /// 00972 /// The expression types that are forbidden to be lvalues are: 00973 /// - 'void', but not qualified void 00974 /// - function types 00975 /// 00976 /// The exact rule here is C99 6.3.2.1: 00977 /// An lvalue is an expression with an object type or an incomplete 00978 /// type other than void. 00979 bool isCForbiddenLValueType() const; 00980 00981 private: 00982 // These methods are implemented in a separate translation unit; 00983 // "static"-ize them to avoid creating temporary QualTypes in the 00984 // caller. 00985 static bool isConstant(QualType T, ASTContext& Ctx); 00986 static QualType getDesugaredType(QualType T, const ASTContext &Context); 00987 static SplitQualType getSplitDesugaredType(QualType T); 00988 static SplitQualType getSplitUnqualifiedTypeImpl(QualType type); 00989 static QualType getSingleStepDesugaredTypeImpl(QualType type, 00990 const ASTContext &C); 00991 static QualType IgnoreParens(QualType T); 00992 static DestructionKind isDestructedTypeImpl(QualType type); 00993 }; 00994 00995 } // end clang. 00996 00997 namespace llvm { 00998 /// Implement simplify_type for QualType, so that we can dyn_cast from QualType 00999 /// to a specific Type class. 01000 template<> struct simplify_type< ::clang::QualType> { 01001 typedef const ::clang::Type *SimpleType; 01002 static SimpleType getSimplifiedValue(::clang::QualType Val) { 01003 return Val.getTypePtr(); 01004 } 01005 }; 01006 01007 // Teach SmallPtrSet that QualType is "basically a pointer". 01008 template<> 01009 class PointerLikeTypeTraits<clang::QualType> { 01010 public: 01011 static inline void *getAsVoidPointer(clang::QualType P) { 01012 return P.getAsOpaquePtr(); 01013 } 01014 static inline clang::QualType getFromVoidPointer(void *P) { 01015 return clang::QualType::getFromOpaquePtr(P); 01016 } 01017 // Various qualifiers go in low bits. 01018 enum { NumLowBitsAvailable = 0 }; 01019 }; 01020 01021 } // end namespace llvm 01022 01023 namespace clang { 01024 01025 /// \brief Base class that is common to both the \c ExtQuals and \c Type 01026 /// classes, which allows \c QualType to access the common fields between the 01027 /// two. 01028 /// 01029 class ExtQualsTypeCommonBase { 01030 ExtQualsTypeCommonBase(const Type *baseType, QualType canon) 01031 : BaseType(baseType), CanonicalType(canon) {} 01032 01033 /// \brief The "base" type of an extended qualifiers type (\c ExtQuals) or 01034 /// a self-referential pointer (for \c Type). 01035 /// 01036 /// This pointer allows an efficient mapping from a QualType to its 01037 /// underlying type pointer. 01038 const Type *const BaseType; 01039 01040 /// \brief The canonical type of this type. A QualType. 01041 QualType CanonicalType; 01042 01043 friend class QualType; 01044 friend class Type; 01045 friend class ExtQuals; 01046 }; 01047 01048 /// ExtQuals - We can encode up to four bits in the low bits of a 01049 /// type pointer, but there are many more type qualifiers that we want 01050 /// to be able to apply to an arbitrary type. Therefore we have this 01051 /// struct, intended to be heap-allocated and used by QualType to 01052 /// store qualifiers. 01053 /// 01054 /// The current design tags the 'const', 'restrict', and 'volatile' qualifiers 01055 /// in three low bits on the QualType pointer; a fourth bit records whether 01056 /// the pointer is an ExtQuals node. The extended qualifiers (address spaces, 01057 /// Objective-C GC attributes) are much more rare. 01058 class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { 01059 // NOTE: changing the fast qualifiers should be straightforward as 01060 // long as you don't make 'const' non-fast. 01061 // 1. Qualifiers: 01062 // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ). 01063 // Fast qualifiers must occupy the low-order bits. 01064 // b) Update Qualifiers::FastWidth and FastMask. 01065 // 2. QualType: 01066 // a) Update is{Volatile,Restrict}Qualified(), defined inline. 01067 // b) Update remove{Volatile,Restrict}, defined near the end of 01068 // this header. 01069 // 3. ASTContext: 01070 // a) Update get{Volatile,Restrict}Type. 01071 01072 /// Quals - the immutable set of qualifiers applied by this 01073 /// node; always contains extended qualifiers. 01074 Qualifiers Quals; 01075 01076 ExtQuals *this_() { return this; } 01077 01078 public: 01079 ExtQuals(const Type *baseType, QualType canon, Qualifiers quals) 01080 : ExtQualsTypeCommonBase(baseType, 01081 canon.isNull() ? QualType(this_(), 0) : canon), 01082 Quals(quals) 01083 { 01084 assert(Quals.hasNonFastQualifiers() 01085 && "ExtQuals created with no fast qualifiers"); 01086 assert(!Quals.hasFastQualifiers() 01087 && "ExtQuals created with fast qualifiers"); 01088 } 01089 01090 Qualifiers getQualifiers() const { return Quals; } 01091 01092 bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); } 01093 Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); } 01094 01095 bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); } 01096 Qualifiers::ObjCLifetime getObjCLifetime() const { 01097 return Quals.getObjCLifetime(); 01098 } 01099 01100 bool hasAddressSpace() const { return Quals.hasAddressSpace(); } 01101 unsigned getAddressSpace() const { return Quals.getAddressSpace(); } 01102 01103 const Type *getBaseType() const { return BaseType; } 01104 01105 public: 01106 void Profile(llvm::FoldingSetNodeID &ID) const { 01107 Profile(ID, getBaseType(), Quals); 01108 } 01109 static void Profile(llvm::FoldingSetNodeID &ID, 01110 const Type *BaseType, 01111 Qualifiers Quals) { 01112 assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!"); 01113 ID.AddPointer(BaseType); 01114 Quals.Profile(ID); 01115 } 01116 }; 01117 01118 /// \brief The kind of C++0x ref-qualifier associated with a function type, 01119 /// which determines whether a member function's "this" object can be an 01120 /// lvalue, rvalue, or neither. 01121 enum RefQualifierKind { 01122 /// \brief No ref-qualifier was provided. 01123 RQ_None = 0, 01124 /// \brief An lvalue ref-qualifier was provided (\c &). 01125 RQ_LValue, 01126 /// \brief An rvalue ref-qualifier was provided (\c &&). 01127 RQ_RValue 01128 }; 01129 01130 /// Type - This is the base class of the type hierarchy. A central concept 01131 /// with types is that each type always has a canonical type. A canonical type 01132 /// is the type with any typedef names stripped out of it or the types it 01133 /// references. For example, consider: 01134 /// 01135 /// typedef int foo; 01136 /// typedef foo* bar; 01137 /// 'int *' 'foo *' 'bar' 01138 /// 01139 /// There will be a Type object created for 'int'. Since int is canonical, its 01140 /// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 01141 /// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 01142 /// there is a PointerType that represents 'int*', which, like 'int', is 01143 /// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 01144 /// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 01145 /// is also 'int*'. 01146 /// 01147 /// Non-canonical types are useful for emitting diagnostics, without losing 01148 /// information about typedefs being used. Canonical types are useful for type 01149 /// comparisons (they allow by-pointer equality tests) and useful for reasoning 01150 /// about whether something has a particular form (e.g. is a function type), 01151 /// because they implicitly, recursively, strip all typedefs out of a type. 01152 /// 01153 /// Types, once created, are immutable. 01154 /// 01155 class Type : public ExtQualsTypeCommonBase { 01156 public: 01157 enum TypeClass { 01158 #define TYPE(Class, Base) Class, 01159 #define LAST_TYPE(Class) TypeLast = Class, 01160 #define ABSTRACT_TYPE(Class, Base) 01161 #include "clang/AST/TypeNodes.def" 01162 TagFirst = Record, TagLast = Enum 01163 }; 01164 01165 private: 01166 Type(const Type &) LLVM_DELETED_FUNCTION; 01167 void operator=(const Type &) LLVM_DELETED_FUNCTION; 01168 01169 /// Bitfields required by the Type class. 01170 class TypeBitfields { 01171 friend class Type; 01172 template <class T> friend class TypePropertyCache; 01173 01174 /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 01175 unsigned TC : 8; 01176 01177 /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 01178 unsigned Dependent : 1; 01179 01180 /// \brief Whether this type somehow involves a template parameter, even 01181 /// if the resolution of the type does not depend on a template parameter. 01182 unsigned InstantiationDependent : 1; 01183 01184 /// \brief Whether this type is a variably-modified type (C99 6.7.5). 01185 unsigned VariablyModified : 1; 01186 01187 /// \brief Whether this type contains an unexpanded parameter pack 01188 /// (for C++0x variadic templates). 01189 unsigned ContainsUnexpandedParameterPack : 1; 01190 01191 /// \brief True if the cache (i.e. the bitfields here starting with 01192 /// 'Cache') is valid. 01193 mutable unsigned CacheValid : 1; 01194 01195 /// \brief Linkage of this type. 01196 mutable unsigned CachedLinkage : 3; 01197 01198 /// \brief Whether this type involves and local or unnamed types. 01199 mutable unsigned CachedLocalOrUnnamed : 1; 01200 01201 /// \brief FromAST - Whether this type comes from an AST file. 01202 mutable unsigned FromAST : 1; 01203 01204 bool isCacheValid() const { 01205 return CacheValid; 01206 } 01207 Linkage getLinkage() const { 01208 assert(isCacheValid() && "getting linkage from invalid cache"); 01209 return static_cast<Linkage>(CachedLinkage); 01210 } 01211 bool hasLocalOrUnnamedType() const { 01212 assert(isCacheValid() && "getting linkage from invalid cache"); 01213 return CachedLocalOrUnnamed; 01214 } 01215 }; 01216 enum { NumTypeBits = 18 }; 01217 01218 protected: 01219 // These classes allow subclasses to somewhat cleanly pack bitfields 01220 // into Type. 01221 01222 class ArrayTypeBitfields { 01223 friend class ArrayType; 01224 01225 unsigned : NumTypeBits; 01226 01227 /// IndexTypeQuals - CVR qualifiers from declarations like 01228 /// 'int X[static restrict 4]'. For function parameters only. 01229 unsigned IndexTypeQuals : 3; 01230 01231 /// SizeModifier - storage class qualifiers from declarations like 01232 /// 'int X[static restrict 4]'. For function parameters only. 01233 /// Actually an ArrayType::ArraySizeModifier. 01234 unsigned SizeModifier : 3; 01235 }; 01236 01237 class BuiltinTypeBitfields { 01238 friend class BuiltinType; 01239 01240 unsigned : NumTypeBits; 01241 01242 /// The kind (BuiltinType::Kind) of builtin type this is. 01243 unsigned Kind : 8; 01244 }; 01245 01246 class FunctionTypeBitfields { 01247 friend class FunctionType; 01248 friend class FunctionProtoType; 01249 01250 unsigned : NumTypeBits; 01251 01252 /// Extra information which affects how the function is called, like 01253 /// regparm and the calling convention. 01254 unsigned ExtInfo : 9; 01255 01256 /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 01257 /// other bitfields. 01258 /// The qualifiers are part of FunctionProtoType because... 01259 /// 01260 /// C++ 8.3.5p4: The return type, the parameter type list and the 01261 /// cv-qualifier-seq, [...], are part of the function type. 01262 unsigned TypeQuals : 3; 01263 01264 /// \brief The ref-qualifier associated with a \c FunctionProtoType. 01265 /// 01266 /// This is a value of type \c RefQualifierKind. 01267 unsigned RefQualifier : 2; 01268 }; 01269 01270 class ObjCObjectTypeBitfields { 01271 friend class ObjCObjectType; 01272 01273 unsigned : NumTypeBits; 01274 01275 /// NumProtocols - The number of protocols stored directly on this 01276 /// object type. 01277 unsigned NumProtocols : 32 - NumTypeBits; 01278 }; 01279 01280 class ReferenceTypeBitfields { 01281 friend class ReferenceType; 01282 01283 unsigned : NumTypeBits; 01284 01285 /// True if the type was originally spelled with an lvalue sigil. 01286 /// This is never true of rvalue references but can also be false 01287 /// on lvalue references because of C++0x [dcl.typedef]p9, 01288 /// as follows: 01289 /// 01290 /// typedef int &ref; // lvalue, spelled lvalue 01291 /// typedef int &&rvref; // rvalue 01292 /// ref &a; // lvalue, inner ref, spelled lvalue 01293 /// ref &&a; // lvalue, inner ref 01294 /// rvref &a; // lvalue, inner ref, spelled lvalue 01295 /// rvref &&a; // rvalue, inner ref 01296 unsigned SpelledAsLValue : 1; 01297 01298 /// True if the inner type is a reference type. This only happens 01299 /// in non-canonical forms. 01300 unsigned InnerRef : 1; 01301 }; 01302 01303 class TypeWithKeywordBitfields { 01304 friend class TypeWithKeyword; 01305 01306 unsigned : NumTypeBits; 01307 01308 /// An ElaboratedTypeKeyword. 8 bits for efficient access. 01309 unsigned Keyword : 8; 01310 }; 01311 01312 class VectorTypeBitfields { 01313 friend class VectorType; 01314 01315 unsigned : NumTypeBits; 01316 01317 /// VecKind - The kind of vector, either a generic vector type or some 01318 /// target-specific vector type such as for AltiVec or Neon. 01319 unsigned VecKind : 3; 01320 01321 /// NumElements - The number of elements in the vector. 01322 unsigned NumElements : 29 - NumTypeBits; 01323 01324 enum { MaxNumElements = (1 << (29 - NumTypeBits)) - 1 }; 01325 }; 01326 01327 class AttributedTypeBitfields { 01328 friend class AttributedType; 01329 01330 unsigned : NumTypeBits; 01331 01332 /// AttrKind - an AttributedType::Kind 01333 unsigned AttrKind : 32 - NumTypeBits; 01334 }; 01335 01336 class AutoTypeBitfields { 01337 friend class AutoType; 01338 01339 unsigned : NumTypeBits; 01340 01341 /// Was this placeholder type spelled as 'decltype(auto)'? 01342 unsigned IsDecltypeAuto : 1; 01343 }; 01344 01345 union { 01346 TypeBitfields TypeBits; 01347 ArrayTypeBitfields ArrayTypeBits; 01348 AttributedTypeBitfields AttributedTypeBits; 01349 AutoTypeBitfields AutoTypeBits; 01350 BuiltinTypeBitfields BuiltinTypeBits; 01351 FunctionTypeBitfields FunctionTypeBits; 01352 ObjCObjectTypeBitfields ObjCObjectTypeBits; 01353 ReferenceTypeBitfields ReferenceTypeBits; 01354 TypeWithKeywordBitfields TypeWithKeywordBits; 01355 VectorTypeBitfields VectorTypeBits; 01356 }; 01357 01358 private: 01359 /// \brief Set whether this type comes from an AST file. 01360 void setFromAST(bool V = true) const { 01361 TypeBits.FromAST = V; 01362 } 01363 01364 template <class T> friend class TypePropertyCache; 01365 01366 protected: 01367 // silence VC++ warning C4355: 'this' : used in base member initializer list 01368 Type *this_() { return this; } 01369 Type(TypeClass tc, QualType canon, bool Dependent, 01370 bool InstantiationDependent, bool VariablyModified, 01371 bool ContainsUnexpandedParameterPack) 01372 : ExtQualsTypeCommonBase(this, 01373 canon.isNull() ? QualType(this_(), 0) : canon) { 01374 TypeBits.TC = tc; 01375 TypeBits.Dependent = Dependent; 01376 TypeBits.InstantiationDependent = Dependent || InstantiationDependent; 01377 TypeBits.VariablyModified = VariablyModified; 01378 TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 01379 TypeBits.CacheValid = false; 01380 TypeBits.CachedLocalOrUnnamed = false; 01381 TypeBits.CachedLinkage = NoLinkage; 01382 TypeBits.FromAST = false; 01383 } 01384 friend class ASTContext; 01385 01386 void setDependent(bool D = true) { 01387 TypeBits.Dependent = D; 01388 if (D) 01389 TypeBits.InstantiationDependent = true; 01390 } 01391 void setInstantiationDependent(bool D = true) { 01392 TypeBits.InstantiationDependent = D; } 01393 void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; 01394 } 01395 void setContainsUnexpandedParameterPack(bool PP = true) { 01396 TypeBits.ContainsUnexpandedParameterPack = PP; 01397 } 01398 01399 public: 01400 TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); } 01401 01402 /// \brief Whether this type comes from an AST file. 01403 bool isFromAST() const { return TypeBits.FromAST; } 01404 01405 /// \brief Whether this type is or contains an unexpanded parameter 01406 /// pack, used to support C++0x variadic templates. 01407 /// 01408 /// A type that contains a parameter pack shall be expanded by the 01409 /// ellipsis operator at some point. For example, the typedef in the 01410 /// following example contains an unexpanded parameter pack 'T': 01411 /// 01412 /// \code 01413 /// template<typename ...T> 01414 /// struct X { 01415 /// typedef T* pointer_types; // ill-formed; T is a parameter pack. 01416 /// }; 01417 /// \endcode 01418 /// 01419 /// Note that this routine does not specify which 01420 bool containsUnexpandedParameterPack() const { 01421 return TypeBits.ContainsUnexpandedParameterPack; 01422 } 01423 01424 /// Determines if this type would be canonical if it had no further 01425 /// qualification. 01426 bool isCanonicalUnqualified() const { 01427 return CanonicalType == QualType(this, 0); 01428 } 01429 01430 /// Pull a single level of sugar off of this locally-unqualified type. 01431 /// Users should generally prefer SplitQualType::getSingleStepDesugaredType() 01432 /// or QualType::getSingleStepDesugaredType(const ASTContext&). 01433 QualType getLocallyUnqualifiedSingleStepDesugaredType() const; 01434 01435 /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 01436 /// object types, function types, and incomplete types. 01437 01438 /// isIncompleteType - Return true if this is an incomplete type. 01439 /// A type that can describe objects, but which lacks information needed to 01440 /// determine its size (e.g. void, or a fwd declared struct). Clients of this 01441 /// routine will need to determine if the size is actually required. 01442 /// 01443 /// \brief Def If non-NULL, and the type refers to some kind of declaration 01444 /// that can be completed (such as a C struct, C++ class, or Objective-C 01445 /// class), will be set to the declaration. 01446 bool isIncompleteType(NamedDecl **Def = nullptr) const; 01447 01448 /// isIncompleteOrObjectType - Return true if this is an incomplete or object 01449 /// type, in other words, not a function type. 01450 bool isIncompleteOrObjectType() const { 01451 return !isFunctionType(); 01452 } 01453 01454 /// \brief Determine whether this type is an object type. 01455 bool isObjectType() const { 01456 // C++ [basic.types]p8: 01457 // An object type is a (possibly cv-qualified) type that is not a 01458 // function type, not a reference type, and not a void type. 01459 return !isReferenceType() && !isFunctionType() && !isVoidType(); 01460 } 01461 01462 /// isLiteralType - Return true if this is a literal type 01463 /// (C++11 [basic.types]p10) 01464 bool isLiteralType(const ASTContext &Ctx) const; 01465 01466 /// \brief Test if this type is a standard-layout type. 01467 /// (C++0x [basic.type]p9) 01468 bool isStandardLayoutType() const; 01469 01470 /// Helper methods to distinguish type categories. All type predicates 01471 /// operate on the canonical type, ignoring typedefs and qualifiers. 01472 01473 /// isBuiltinType - returns true if the type is a builtin type. 01474 bool isBuiltinType() const; 01475 01476 /// isSpecificBuiltinType - Test for a particular builtin type. 01477 bool isSpecificBuiltinType(unsigned K) const; 01478 01479 /// isPlaceholderType - Test for a type which does not represent an 01480 /// actual type-system type but is instead used as a placeholder for 01481 /// various convenient purposes within Clang. All such types are 01482 /// BuiltinTypes. 01483 bool isPlaceholderType() const; 01484 const BuiltinType *getAsPlaceholderType() const; 01485 01486 /// isSpecificPlaceholderType - Test for a specific placeholder type. 01487 bool isSpecificPlaceholderType(unsigned K) const; 01488 01489 /// isNonOverloadPlaceholderType - Test for a placeholder type 01490 /// other than Overload; see BuiltinType::isNonOverloadPlaceholderType. 01491 bool isNonOverloadPlaceholderType() const; 01492 01493 /// isIntegerType() does *not* include complex integers (a GCC extension). 01494 /// isComplexIntegerType() can be used to test for complex integers. 01495 bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 01496 bool isEnumeralType() const; 01497 bool isBooleanType() const; 01498 bool isCharType() const; 01499 bool isWideCharType() const; 01500 bool isChar16Type() const; 01501 bool isChar32Type() const; 01502 bool isAnyCharacterType() const; 01503 bool isIntegralType(ASTContext &Ctx) const; 01504 01505 /// \brief Determine whether this type is an integral or enumeration type. 01506 bool isIntegralOrEnumerationType() const; 01507 /// \brief Determine whether this type is an integral or unscoped enumeration 01508 /// type. 01509 bool isIntegralOrUnscopedEnumerationType() const; 01510 01511 /// Floating point categories. 01512 bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 01513 /// isComplexType() does *not* include complex integers (a GCC extension). 01514 /// isComplexIntegerType() can be used to test for complex integers. 01515 bool isComplexType() const; // C99 6.2.5p11 (complex) 01516 bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 01517 bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 01518 bool isHalfType() const; // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half) 01519 bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 01520 bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 01521 bool isVoidType() const; // C99 6.2.5p19 01522 bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 01523 bool isAggregateType() const; 01524 bool isFundamentalType() const; 01525 bool isCompoundType() const; 01526 01527 // Type Predicates: Check to see if this type is structurally the specified 01528 // type, ignoring typedefs and qualifiers. 01529 bool isFunctionType() const; 01530 bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } 01531 bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } 01532 bool isPointerType() const; 01533 bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 01534 bool isBlockPointerType() const; 01535 bool isVoidPointerType() const; 01536 bool isReferenceType() const; 01537 bool isLValueReferenceType() const; 01538 bool isRValueReferenceType() const; 01539 bool isFunctionPointerType() const; 01540 bool isMemberPointerType() const; 01541 bool isMemberFunctionPointerType() const; 01542 bool isMemberDataPointerType() const; 01543 bool isArrayType() const; 01544 bool isConstantArrayType() const; 01545 bool isIncompleteArrayType() const; 01546 bool isVariableArrayType() const; 01547 bool isDependentSizedArrayType() const; 01548 bool isRecordType() const; 01549 bool isClassType() const; 01550 bool isStructureType() const; 01551 bool isInterfaceType() const; 01552 bool isStructureOrClassType() const; 01553 bool isUnionType() const; 01554 bool isComplexIntegerType() const; // GCC _Complex integer type. 01555 bool isVectorType() const; // GCC vector type. 01556 bool isExtVectorType() const; // Extended vector type. 01557 bool isObjCObjectPointerType() const; // pointer to ObjC object 01558 bool isObjCRetainableType() const; // ObjC object or block pointer 01559 bool isObjCLifetimeType() const; // (array of)* retainable type 01560 bool isObjCIndirectLifetimeType() const; // (pointer to)* lifetime type 01561 bool isObjCNSObjectType() const; // __attribute__((NSObject)) 01562 // FIXME: change this to 'raw' interface type, so we can used 'interface' type 01563 // for the common case. 01564 bool isObjCObjectType() const; // NSString or typeof(*(id)0) 01565 bool isObjCQualifiedInterfaceType() const; // NSString<foo> 01566 bool isObjCQualifiedIdType() const; // id<foo> 01567 bool isObjCQualifiedClassType() const; // Class<foo> 01568 bool isObjCObjectOrInterfaceType() const; 01569 bool isObjCIdType() const; // id 01570 bool isObjCClassType() const; // Class 01571 bool isObjCSelType() const; // Class 01572 bool isObjCBuiltinType() const; // 'id' or 'Class' 01573 bool isObjCARCBridgableType() const; 01574 bool isCARCBridgableType() const; 01575 bool isTemplateTypeParmType() const; // C++ template type parameter 01576 bool isNullPtrType() const; // C++0x nullptr_t 01577 bool isAtomicType() const; // C11 _Atomic() 01578 01579 bool isImage1dT() const; // OpenCL image1d_t 01580 bool isImage1dArrayT() const; // OpenCL image1d_array_t 01581 bool isImage1dBufferT() const; // OpenCL image1d_buffer_t 01582 bool isImage2dT() const; // OpenCL image2d_t 01583 bool isImage2dArrayT() const; // OpenCL image2d_array_t 01584 bool isImage3dT() const; // OpenCL image3d_t 01585 01586 bool isImageType() const; // Any OpenCL image type 01587 01588 bool isSamplerT() const; // OpenCL sampler_t 01589 bool isEventT() const; // OpenCL event_t 01590 01591 bool isOpenCLSpecificType() const; // Any OpenCL specific type 01592 01593 /// Determines if this type, which must satisfy 01594 /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather 01595 /// than implicitly __strong. 01596 bool isObjCARCImplicitlyUnretainedType() const; 01597 01598 /// Return the implicit lifetime for this type, which must not be dependent. 01599 Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const; 01600 01601 enum ScalarTypeKind { 01602 STK_CPointer, 01603 STK_BlockPointer, 01604 STK_ObjCObjectPointer, 01605 STK_MemberPointer, 01606 STK_Bool, 01607 STK_Integral, 01608 STK_Floating, 01609 STK_IntegralComplex, 01610 STK_FloatingComplex 01611 }; 01612 /// getScalarTypeKind - Given that this is a scalar type, classify it. 01613 ScalarTypeKind getScalarTypeKind() const; 01614 01615 /// isDependentType - Whether this type is a dependent type, meaning 01616 /// that its definition somehow depends on a template parameter 01617 /// (C++ [temp.dep.type]). 01618 bool isDependentType() const { return TypeBits.Dependent; } 01619 01620 /// \brief Determine whether this type is an instantiation-dependent type, 01621 /// meaning that the type involves a template parameter (even if the 01622 /// definition does not actually depend on the type substituted for that 01623 /// template parameter). 01624 bool isInstantiationDependentType() const { 01625 return TypeBits.InstantiationDependent; 01626 } 01627 01628 /// \brief Determine whether this type is an undeduced type, meaning that 01629 /// it somehow involves a C++11 'auto' type which has not yet been deduced. 01630 bool isUndeducedType() const; 01631 01632 /// \brief Whether this type is a variably-modified type (C99 6.7.5). 01633 bool isVariablyModifiedType() const { return TypeBits.VariablyModified; } 01634 01635 /// \brief Whether this type involves a variable-length array type 01636 /// with a definite size. 01637 bool hasSizedVLAType() const; 01638 01639 /// \brief Whether this type is or contains a local or unnamed type. 01640 bool hasUnnamedOrLocalType() const; 01641 01642 bool isOverloadableType() const; 01643 01644 /// \brief Determine wither this type is a C++ elaborated-type-specifier. 01645 bool isElaboratedTypeSpecifier() const; 01646 01647 bool canDecayToPointerType() const; 01648 01649 /// hasPointerRepresentation - Whether this type is represented 01650 /// natively as a pointer; this includes pointers, references, block 01651 /// pointers, and Objective-C interface, qualified id, and qualified 01652 /// interface types, as well as nullptr_t. 01653 bool hasPointerRepresentation() const; 01654 01655 /// hasObjCPointerRepresentation - Whether this type can represent 01656 /// an objective pointer type for the purpose of GC'ability 01657 bool hasObjCPointerRepresentation() const; 01658 01659 /// \brief Determine whether this type has an integer representation 01660 /// of some sort, e.g., it is an integer type or a vector. 01661 bool hasIntegerRepresentation() const; 01662 01663 /// \brief Determine whether this type has an signed integer representation 01664 /// of some sort, e.g., it is an signed integer type or a vector. 01665 bool hasSignedIntegerRepresentation() const; 01666 01667 /// \brief Determine whether this type has an unsigned integer representation 01668 /// of some sort, e.g., it is an unsigned integer type or a vector. 01669 bool hasUnsignedIntegerRepresentation() const; 01670 01671 /// \brief Determine whether this type has a floating-point representation 01672 /// of some sort, e.g., it is a floating-point type or a vector thereof. 01673 bool hasFloatingRepresentation() const; 01674 01675 // Type Checking Functions: Check to see if this type is structurally the 01676 // specified type, ignoring typedefs and qualifiers, and return a pointer to 01677 // the best type we can. 01678 const RecordType *getAsStructureType() const; 01679 /// NOTE: getAs*ArrayType are methods on ASTContext. 01680 const RecordType *getAsUnionType() const; 01681 const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 01682 // The following is a convenience method that returns an ObjCObjectPointerType 01683 // for object declared using an interface. 01684 const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 01685 const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 01686 const ObjCObjectPointerType *getAsObjCQualifiedClassType() const; 01687 const ObjCObjectType *getAsObjCQualifiedInterfaceType() const; 01688 01689 /// \brief Retrieves the CXXRecordDecl that this type refers to, either 01690 /// because the type is a RecordType or because it is the injected-class-name 01691 /// type of a class template or class template partial specialization. 01692 CXXRecordDecl *getAsCXXRecordDecl() const; 01693 01694 /// If this is a pointer or reference to a RecordType, return the 01695 /// CXXRecordDecl that that type refers to. 01696 /// 01697 /// If this is not a pointer or reference, or the type being pointed to does 01698 /// not refer to a CXXRecordDecl, returns NULL. 01699 const CXXRecordDecl *getPointeeCXXRecordDecl() const; 01700 01701 /// \brief Get the AutoType whose type will be deduced for a variable with 01702 /// an initializer of this type. This looks through declarators like pointer 01703 /// types, but not through decltype or typedefs. 01704 AutoType *getContainedAutoType() const; 01705 01706 /// Member-template getAs<specific type>'. Look through sugar for 01707 /// an instance of <specific type>. This scheme will eventually 01708 /// replace the specific getAsXXXX methods above. 01709 /// 01710 /// There are some specializations of this member template listed 01711 /// immediately following this class. 01712 template <typename T> const T *getAs() const; 01713 01714 /// A variant of getAs<> for array types which silently discards 01715 /// qualifiers from the outermost type. 01716 const ArrayType *getAsArrayTypeUnsafe() const; 01717 01718 /// Member-template castAs<specific type>. Look through sugar for 01719 /// the underlying instance of <specific type>. 01720 /// 01721 /// This method has the same relationship to getAs<T> as cast<T> has 01722 /// to dyn_cast<T>; which is to say, the underlying type *must* 01723 /// have the intended type, and this method will never return null. 01724 template <typename T> const T *castAs() const; 01725 01726 /// A variant of castAs<> for array type which silently discards 01727 /// qualifiers from the outermost type. 01728 const ArrayType *castAsArrayTypeUnsafe() const; 01729 01730 /// getBaseElementTypeUnsafe - Get the base element type of this 01731 /// type, potentially discarding type qualifiers. This method 01732 /// should never be used when type qualifiers are meaningful. 01733 const Type *getBaseElementTypeUnsafe() const; 01734 01735 /// getArrayElementTypeNoTypeQual - If this is an array type, return the 01736 /// element type of the array, potentially with type qualifiers missing. 01737 /// This method should never be used when type qualifiers are meaningful. 01738 const Type *getArrayElementTypeNoTypeQual() const; 01739 01740 /// getPointeeType - If this is a pointer, ObjC object pointer, or block 01741 /// pointer, this returns the respective pointee. 01742 QualType getPointeeType() const; 01743 01744 /// getUnqualifiedDesugaredType() - Return the specified type with 01745 /// any "sugar" removed from the type, removing any typedefs, 01746 /// typeofs, etc., as well as any qualifiers. 01747 const Type *getUnqualifiedDesugaredType() const; 01748 01749 /// More type predicates useful for type checking/promotion 01750 bool isPromotableIntegerType() const; // C99 6.3.1.1p2 01751 01752 /// isSignedIntegerType - Return true if this is an integer type that is 01753 /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 01754 /// or an enum decl which has a signed representation. 01755 bool isSignedIntegerType() const; 01756 01757 /// isUnsignedIntegerType - Return true if this is an integer type that is 01758 /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], 01759 /// or an enum decl which has an unsigned representation. 01760 bool isUnsignedIntegerType() const; 01761 01762 /// Determines whether this is an integer type that is signed or an 01763 /// enumeration types whose underlying type is a signed integer type. 01764 bool isSignedIntegerOrEnumerationType() const; 01765 01766 /// Determines whether this is an integer type that is unsigned or an 01767 /// enumeration types whose underlying type is a unsigned integer type. 01768 bool isUnsignedIntegerOrEnumerationType() const; 01769 01770 /// isConstantSizeType - Return true if this is not a variable sized type, 01771 /// according to the rules of C99 6.7.5p3. It is not legal to call this on 01772 /// incomplete types. 01773 bool isConstantSizeType() const; 01774 01775 /// isSpecifierType - Returns true if this type can be represented by some 01776 /// set of type specifiers. 01777 bool isSpecifierType() const; 01778 01779 /// \brief Determine the linkage of this type. 01780 Linkage getLinkage() const; 01781 01782 /// \brief Determine the visibility of this type. 01783 Visibility getVisibility() const { 01784 return getLinkageAndVisibility().getVisibility(); 01785 } 01786 01787 /// \brief Return true if the visibility was explicitly set is the code. 01788 bool isVisibilityExplicit() const { 01789 return getLinkageAndVisibility().isVisibilityExplicit(); 01790 } 01791 01792 /// \brief Determine the linkage and visibility of this type. 01793 LinkageInfo getLinkageAndVisibility() const; 01794 01795 /// \brief True if the computed linkage is valid. Used for consistency 01796 /// checking. Should always return true. 01797 bool isLinkageValid() const; 01798 01799 const char *getTypeClassName() const; 01800 01801 QualType getCanonicalTypeInternal() const { 01802 return CanonicalType; 01803 } 01804 CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h 01805 void dump() const; 01806 01807 friend class ASTReader; 01808 friend class ASTWriter; 01809 }; 01810 01811 /// \brief This will check for a TypedefType by removing any existing sugar 01812 /// until it reaches a TypedefType or a non-sugared type. 01813 template <> const TypedefType *Type::getAs() const; 01814 01815 /// \brief This will check for a TemplateSpecializationType by removing any 01816 /// existing sugar until it reaches a TemplateSpecializationType or a 01817 /// non-sugared type. 01818 template <> const TemplateSpecializationType *Type::getAs() const; 01819 01820 /// \brief This will check for an AttributedType by removing any existing sugar 01821 /// until it reaches an AttributedType or a non-sugared type. 01822 template <> const AttributedType *Type::getAs() const; 01823 01824 // We can do canonical leaf types faster, because we don't have to 01825 // worry about preserving child type decoration. 01826 #define TYPE(Class, Base) 01827 #define LEAF_TYPE(Class) \ 01828 template <> inline const Class##Type *Type::getAs() const { \ 01829 return dyn_cast<Class##Type>(CanonicalType); \ 01830 } \ 01831 template <> inline const Class##Type *Type::castAs() const { \ 01832 return cast<Class##Type>(CanonicalType); \ 01833 } 01834 #include "clang/AST/TypeNodes.def" 01835 01836 01837 /// BuiltinType - This class is used for builtin types like 'int'. Builtin 01838 /// types are always canonical and have a literal name field. 01839 class BuiltinType : public Type { 01840 public: 01841 enum Kind { 01842 #define BUILTIN_TYPE(Id, SingletonId) Id, 01843 #define LAST_BUILTIN_TYPE(Id) LastKind = Id 01844 #include "clang/AST/BuiltinTypes.def" 01845 }; 01846 01847 public: 01848 BuiltinType(Kind K) 01849 : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent), 01850 /*InstantiationDependent=*/(K == Dependent), 01851 /*VariablyModified=*/false, 01852 /*Unexpanded paramter pack=*/false) { 01853 BuiltinTypeBits.Kind = K; 01854 } 01855 01856 Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); } 01857 StringRef getName(const PrintingPolicy &Policy) const; 01858 const char *getNameAsCString(const PrintingPolicy &Policy) const { 01859 // The StringRef is null-terminated. 01860 StringRef str = getName(Policy); 01861 assert(!str.empty() && str.data()[str.size()] == '\0'); 01862 return str.data(); 01863 } 01864 01865 bool isSugared() const { return false; } 01866 QualType desugar() const { return QualType(this, 0); } 01867 01868 bool isInteger() const { 01869 return getKind() >= Bool && getKind() <= Int128; 01870 } 01871 01872 bool isSignedInteger() const { 01873 return getKind() >= Char_S && getKind() <= Int128; 01874 } 01875 01876 bool isUnsignedInteger() const { 01877 return getKind() >= Bool && getKind() <= UInt128; 01878 } 01879 01880 bool isFloatingPoint() const { 01881 return getKind() >= Half && getKind() <= LongDouble; 01882 } 01883 01884 /// Determines whether the given kind corresponds to a placeholder type. 01885 static bool isPlaceholderTypeKind(Kind K) { 01886 return K >= Overload; 01887 } 01888 01889 /// Determines whether this type is a placeholder type, i.e. a type 01890 /// which cannot appear in arbitrary positions in a fully-formed 01891 /// expression. 01892 bool isPlaceholderType() const { 01893 return isPlaceholderTypeKind(getKind()); 01894 } 01895 01896 /// Determines whether this type is a placeholder type other than 01897 /// Overload. Most placeholder types require only syntactic 01898 /// information about their context in order to be resolved (e.g. 01899 /// whether it is a call expression), which means they can (and 01900 /// should) be resolved in an earlier "phase" of analysis. 01901 /// Overload expressions sometimes pick up further information 01902 /// from their context, like whether the context expects a 01903 /// specific function-pointer type, and so frequently need 01904 /// special treatment. 01905 bool isNonOverloadPlaceholderType() const { 01906 return getKind() > Overload; 01907 } 01908 01909 static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 01910 }; 01911 01912 /// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 01913 /// types (_Complex float etc) as well as the GCC integer complex extensions. 01914 /// 01915 class ComplexType : public Type, public llvm::FoldingSetNode { 01916 QualType ElementType; 01917 ComplexType(QualType Element, QualType CanonicalPtr) : 01918 Type(Complex, CanonicalPtr, Element->isDependentType(), 01919 Element->isInstantiationDependentType(), 01920 Element->isVariablyModifiedType(), 01921 Element->containsUnexpandedParameterPack()), 01922 ElementType(Element) { 01923 } 01924 friend class ASTContext; // ASTContext creates these. 01925 01926 public: 01927 QualType getElementType() const { return ElementType; } 01928 01929 bool isSugared() const { return false; } 01930 QualType desugar() const { return QualType(this, 0); } 01931 01932 void Profile(llvm::FoldingSetNodeID &ID) { 01933 Profile(ID, getElementType()); 01934 } 01935 static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 01936 ID.AddPointer(Element.getAsOpaquePtr()); 01937 } 01938 01939 static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 01940 }; 01941 01942 /// ParenType - Sugar for parentheses used when specifying types. 01943 /// 01944 class ParenType : public Type, public llvm::FoldingSetNode { 01945 QualType Inner; 01946 01947 ParenType(QualType InnerType, QualType CanonType) : 01948 Type(Paren, CanonType, InnerType->isDependentType(), 01949 InnerType->isInstantiationDependentType(), 01950 InnerType->isVariablyModifiedType(), 01951 InnerType->containsUnexpandedParameterPack()), 01952 Inner(InnerType) { 01953 } 01954 friend class ASTContext; // ASTContext creates these. 01955 01956 public: 01957 01958 QualType getInnerType() const { return Inner; } 01959 01960 bool isSugared() const { return true; } 01961 QualType desugar() const { return getInnerType(); } 01962 01963 void Profile(llvm::FoldingSetNodeID &ID) { 01964 Profile(ID, getInnerType()); 01965 } 01966 static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) { 01967 Inner.Profile(ID); 01968 } 01969 01970 static bool classof(const Type *T) { return T->getTypeClass() == Paren; } 01971 }; 01972 01973 /// PointerType - C99 6.7.5.1 - Pointer Declarators. 01974 /// 01975 class PointerType : public Type, public llvm::FoldingSetNode { 01976 QualType PointeeType; 01977 01978 PointerType(QualType Pointee, QualType CanonicalPtr) : 01979 Type(Pointer, CanonicalPtr, Pointee->isDependentType(), 01980 Pointee->isInstantiationDependentType(), 01981 Pointee->isVariablyModifiedType(), 01982 Pointee->containsUnexpandedParameterPack()), 01983 PointeeType(Pointee) { 01984 } 01985 friend class ASTContext; // ASTContext creates these. 01986 01987 public: 01988 01989 QualType getPointeeType() const { return PointeeType; } 01990 01991 bool isSugared() const { return false; } 01992 QualType desugar() const { return QualType(this, 0); } 01993 01994 void Profile(llvm::FoldingSetNodeID &ID) { 01995 Profile(ID, getPointeeType()); 01996 } 01997 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 01998 ID.AddPointer(Pointee.getAsOpaquePtr()); 01999 } 02000 02001 static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 02002 }; 02003 02004 /// \brief Represents a type which was implicitly adjusted by the semantic 02005 /// engine for arbitrary reasons. For example, array and function types can 02006 /// decay, and function types can have their calling conventions adjusted. 02007 class AdjustedType : public Type, public llvm::FoldingSetNode { 02008 QualType OriginalTy; 02009 QualType AdjustedTy; 02010 02011 protected: 02012 AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy, 02013 QualType CanonicalPtr) 02014 : Type(TC, CanonicalPtr, OriginalTy->isDependentType(), 02015 OriginalTy->isInstantiationDependentType(), 02016 OriginalTy->isVariablyModifiedType(), 02017 OriginalTy->containsUnexpandedParameterPack()), 02018 OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {} 02019 02020 friend class ASTContext; // ASTContext creates these. 02021 02022 public: 02023 QualType getOriginalType() const { return OriginalTy; } 02024 QualType getAdjustedType() const { return AdjustedTy; } 02025 02026 bool isSugared() const { return true; } 02027 QualType desugar() const { return AdjustedTy; } 02028 02029 void Profile(llvm::FoldingSetNodeID &ID) { 02030 Profile(ID, OriginalTy, AdjustedTy); 02031 } 02032 static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New) { 02033 ID.AddPointer(Orig.getAsOpaquePtr()); 02034 ID.AddPointer(New.getAsOpaquePtr()); 02035 } 02036 02037 static bool classof(const Type *T) { 02038 return T->getTypeClass() == Adjusted || T->getTypeClass() == Decayed; 02039 } 02040 }; 02041 02042 /// \brief Represents a pointer type decayed from an array or function type. 02043 class DecayedType : public AdjustedType { 02044 02045 DecayedType(QualType OriginalType, QualType DecayedPtr, QualType CanonicalPtr) 02046 : AdjustedType(Decayed, OriginalType, DecayedPtr, CanonicalPtr) { 02047 assert(isa<PointerType>(getAdjustedType())); 02048 } 02049 02050 friend class ASTContext; // ASTContext creates these. 02051 02052 public: 02053 QualType getDecayedType() const { return getAdjustedType(); } 02054 02055 QualType getPointeeType() const { 02056 return cast<PointerType>(getDecayedType())->getPointeeType(); 02057 } 02058 02059 static bool classof(const Type *T) { return T->getTypeClass() == Decayed; } 02060 }; 02061 02062 /// BlockPointerType - pointer to a block type. 02063 /// This type is to represent types syntactically represented as 02064 /// "void (^)(int)", etc. Pointee is required to always be a function type. 02065 /// 02066 class BlockPointerType : public Type, public llvm::FoldingSetNode { 02067 QualType PointeeType; // Block is some kind of pointer type 02068 BlockPointerType(QualType Pointee, QualType CanonicalCls) : 02069 Type(BlockPointer, CanonicalCls, Pointee->isDependentType(), 02070 Pointee->isInstantiationDependentType(), 02071 Pointee->isVariablyModifiedType(), 02072 Pointee->containsUnexpandedParameterPack()), 02073 PointeeType(Pointee) { 02074 } 02075 friend class ASTContext; // ASTContext creates these. 02076 02077 public: 02078 02079 // Get the pointee type. Pointee is required to always be a function type. 02080 QualType getPointeeType() const { return PointeeType; } 02081 02082 bool isSugared() const { return false; } 02083 QualType desugar() const { return QualType(this, 0); } 02084 02085 void Profile(llvm::FoldingSetNodeID &ID) { 02086 Profile(ID, getPointeeType()); 02087 } 02088 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 02089 ID.AddPointer(Pointee.getAsOpaquePtr()); 02090 } 02091 02092 static bool classof(const Type *T) { 02093 return T->getTypeClass() == BlockPointer; 02094 } 02095 }; 02096 02097 /// ReferenceType - Base for LValueReferenceType and RValueReferenceType 02098 /// 02099 class ReferenceType : public Type, public llvm::FoldingSetNode { 02100 QualType PointeeType; 02101 02102 protected: 02103 ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, 02104 bool SpelledAsLValue) : 02105 Type(tc, CanonicalRef, Referencee->isDependentType(), 02106 Referencee->isInstantiationDependentType(), 02107 Referencee->isVariablyModifiedType(), 02108 Referencee->containsUnexpandedParameterPack()), 02109 PointeeType(Referencee) 02110 { 02111 ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue; 02112 ReferenceTypeBits.InnerRef = Referencee->isReferenceType(); 02113 } 02114 02115 public: 02116 bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; } 02117 bool isInnerRef() const { return ReferenceTypeBits.InnerRef; } 02118 02119 QualType getPointeeTypeAsWritten() const { return PointeeType; } 02120 QualType getPointeeType() const { 02121 // FIXME: this might strip inner qualifiers; okay? 02122 const ReferenceType *T = this; 02123 while (T->isInnerRef()) 02124 T = T->PointeeType->castAs<ReferenceType>(); 02125 return T->PointeeType; 02126 } 02127 02128 void Profile(llvm::FoldingSetNodeID &ID) { 02129 Profile(ID, PointeeType, isSpelledAsLValue()); 02130 } 02131 static void Profile(llvm::FoldingSetNodeID &ID, 02132 QualType Referencee, 02133 bool SpelledAsLValue) { 02134 ID.AddPointer(Referencee.getAsOpaquePtr()); 02135 ID.AddBoolean(SpelledAsLValue); 02136 } 02137 02138 static bool classof(const Type *T) { 02139 return T->getTypeClass() == LValueReference || 02140 T->getTypeClass() == RValueReference; 02141 } 02142 }; 02143 02144 /// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 02145 /// 02146 class LValueReferenceType : public ReferenceType { 02147 LValueReferenceType(QualType Referencee, QualType CanonicalRef, 02148 bool SpelledAsLValue) : 02149 ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue) 02150 {} 02151 friend class ASTContext; // ASTContext creates these 02152 public: 02153 bool isSugared() const { return false; } 02154 QualType desugar() const { return QualType(this, 0); } 02155 02156 static bool classof(const Type *T) { 02157 return T->getTypeClass() == LValueReference; 02158 } 02159 }; 02160 02161 /// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 02162 /// 02163 class RValueReferenceType : public ReferenceType { 02164 RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 02165 ReferenceType(RValueReference, Referencee, CanonicalRef, false) { 02166 } 02167 friend class ASTContext; // ASTContext creates these 02168 public: 02169 bool isSugared() const { return false; } 02170 QualType desugar() const { return QualType(this, 0); } 02171 02172 static bool classof(const Type *T) { 02173 return T->getTypeClass() == RValueReference; 02174 } 02175 }; 02176 02177 /// MemberPointerType - C++ 8.3.3 - Pointers to members 02178 /// 02179 class MemberPointerType : public Type, public llvm::FoldingSetNode { 02180 QualType PointeeType; 02181 /// The class of which the pointee is a member. Must ultimately be a 02182 /// RecordType, but could be a typedef or a template parameter too. 02183 const Type *Class; 02184 02185 MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 02186 Type(MemberPointer, CanonicalPtr, 02187 Cls->isDependentType() || Pointee->isDependentType(), 02188 (Cls->isInstantiationDependentType() || 02189 Pointee->isInstantiationDependentType()), 02190 Pointee->isVariablyModifiedType(), 02191 (Cls->containsUnexpandedParameterPack() || 02192 Pointee->containsUnexpandedParameterPack())), 02193 PointeeType(Pointee), Class(Cls) { 02194 } 02195 friend class ASTContext; // ASTContext creates these. 02196 02197 public: 02198 QualType getPointeeType() const { return PointeeType; } 02199 02200 /// Returns true if the member type (i.e. the pointee type) is a 02201 /// function type rather than a data-member type. 02202 bool isMemberFunctionPointer() const { 02203 return PointeeType->isFunctionProtoType(); 02204 } 02205 02206 /// Returns true if the member type (i.e. the pointee type) is a 02207 /// data type rather than a function type. 02208 bool isMemberDataPointer() const { 02209 return !PointeeType->isFunctionProtoType(); 02210 } 02211 02212 const Type *getClass() const { return Class; } 02213 CXXRecordDecl *getMostRecentCXXRecordDecl() const; 02214 02215 bool isSugared() const { return false; } 02216 QualType desugar() const { return QualType(this, 0); } 02217 02218 void Profile(llvm::FoldingSetNodeID &ID) { 02219 Profile(ID, getPointeeType(), getClass()); 02220 } 02221 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 02222 const Type *Class) { 02223 ID.AddPointer(Pointee.getAsOpaquePtr()); 02224 ID.AddPointer(Class); 02225 } 02226 02227 static bool classof(const Type *T) { 02228 return T->getTypeClass() == MemberPointer; 02229 } 02230 }; 02231 02232 /// ArrayType - C99 6.7.5.2 - Array Declarators. 02233 /// 02234 class ArrayType : public Type, public llvm::FoldingSetNode { 02235 public: 02236 /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 02237 /// an array with a static size (e.g. int X[static 4]), or an array 02238 /// with a star size (e.g. int X[*]). 02239 /// 'static' is only allowed on function parameters. 02240 enum ArraySizeModifier { 02241 Normal, Static, Star 02242 }; 02243 private: 02244 /// ElementType - The element type of the array. 02245 QualType ElementType; 02246 02247 protected: 02248 // C++ [temp.dep.type]p1: 02249 // A type is dependent if it is... 02250 // - an array type constructed from any dependent type or whose 02251 // size is specified by a constant expression that is 02252 // value-dependent, 02253 ArrayType(TypeClass tc, QualType et, QualType can, 02254 ArraySizeModifier sm, unsigned tq, 02255 bool ContainsUnexpandedParameterPack) 02256 : Type(tc, can, et->isDependentType() || tc == DependentSizedArray, 02257 et->isInstantiationDependentType() || tc == DependentSizedArray, 02258 (tc == VariableArray || et->isVariablyModifiedType()), 02259 ContainsUnexpandedParameterPack), 02260 ElementType(et) { 02261 ArrayTypeBits.IndexTypeQuals = tq; 02262 ArrayTypeBits.SizeModifier = sm; 02263 } 02264 02265 friend class ASTContext; // ASTContext creates these. 02266 02267 public: 02268 QualType getElementType() const { return ElementType; } 02269 ArraySizeModifier getSizeModifier() const { 02270 return ArraySizeModifier(ArrayTypeBits.SizeModifier); 02271 } 02272 Qualifiers getIndexTypeQualifiers() const { 02273 return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers()); 02274 } 02275 unsigned getIndexTypeCVRQualifiers() const { 02276 return ArrayTypeBits.IndexTypeQuals; 02277 } 02278 02279 static bool classof(const Type *T) { 02280 return T->getTypeClass() == ConstantArray || 02281 T->getTypeClass() == VariableArray || 02282 T->getTypeClass() == IncompleteArray || 02283 T->getTypeClass() == DependentSizedArray; 02284 } 02285 }; 02286 02287 /// ConstantArrayType - This class represents the canonical version of 02288 /// C arrays with a specified constant size. For example, the canonical 02289 /// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 02290 /// type is 'int' and the size is 404. 02291 class ConstantArrayType : public ArrayType { 02292 llvm::APInt Size; // Allows us to unique the type. 02293 02294 ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 02295 ArraySizeModifier sm, unsigned tq) 02296 : ArrayType(ConstantArray, et, can, sm, tq, 02297 et->containsUnexpandedParameterPack()), 02298 Size(size) {} 02299 protected: 02300 ConstantArrayType(TypeClass tc, QualType et, QualType can, 02301 const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 02302 : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()), 02303 Size(size) {} 02304 friend class ASTContext; // ASTContext creates these. 02305 public: 02306 const llvm::APInt &getSize() const { return Size; } 02307 bool isSugared() const { return false; } 02308 QualType desugar() const { return QualType(this, 0); } 02309 02310 02311 /// \brief Determine the number of bits required to address a member of 02312 // an array with the given element type and number of elements. 02313 static unsigned getNumAddressingBits(ASTContext &Context, 02314 QualType ElementType, 02315 const llvm::APInt &NumElements); 02316 02317 /// \brief Determine the maximum number of active bits that an array's size 02318 /// can require, which limits the maximum size of the array. 02319 static unsigned getMaxSizeBits(ASTContext &Context); 02320 02321 void Profile(llvm::FoldingSetNodeID &ID) { 02322 Profile(ID, getElementType(), getSize(), 02323 getSizeModifier(), getIndexTypeCVRQualifiers()); 02324 } 02325 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 02326 const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 02327 unsigned TypeQuals) { 02328 ID.AddPointer(ET.getAsOpaquePtr()); 02329 ID.AddInteger(ArraySize.getZExtValue()); 02330 ID.AddInteger(SizeMod); 02331 ID.AddInteger(TypeQuals); 02332 } 02333 static bool classof(const Type *T) { 02334 return T->getTypeClass() == ConstantArray; 02335 } 02336 }; 02337 02338 /// IncompleteArrayType - This class represents C arrays with an unspecified 02339 /// size. For example 'int A[]' has an IncompleteArrayType where the element 02340 /// type is 'int' and the size is unspecified. 02341 class IncompleteArrayType : public ArrayType { 02342 02343 IncompleteArrayType(QualType et, QualType can, 02344 ArraySizeModifier sm, unsigned tq) 02345 : ArrayType(IncompleteArray, et, can, sm, tq, 02346 et->containsUnexpandedParameterPack()) {} 02347 friend class ASTContext; // ASTContext creates these. 02348 public: 02349 bool isSugared() const { return false; } 02350 QualType desugar() const { return QualType(this, 0); } 02351 02352 static bool classof(const Type *T) { 02353 return T->getTypeClass() == IncompleteArray; 02354 } 02355 02356 friend class StmtIteratorBase; 02357 02358 void Profile(llvm::FoldingSetNodeID &ID) { 02359 Profile(ID, getElementType(), getSizeModifier(), 02360 getIndexTypeCVRQualifiers()); 02361 } 02362 02363 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 02364 ArraySizeModifier SizeMod, unsigned TypeQuals) { 02365 ID.AddPointer(ET.getAsOpaquePtr()); 02366 ID.AddInteger(SizeMod); 02367 ID.AddInteger(TypeQuals); 02368 } 02369 }; 02370 02371 /// VariableArrayType - This class represents C arrays with a specified size 02372 /// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 02373 /// Since the size expression is an arbitrary expression, we store it as such. 02374 /// 02375 /// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 02376 /// should not be: two lexically equivalent variable array types could mean 02377 /// different things, for example, these variables do not have the same type 02378 /// dynamically: 02379 /// 02380 /// void foo(int x) { 02381 /// int Y[x]; 02382 /// ++x; 02383 /// int Z[x]; 02384 /// } 02385 /// 02386 class VariableArrayType : public ArrayType { 02387 /// SizeExpr - An assignment expression. VLA's are only permitted within 02388 /// a function block. 02389 Stmt *SizeExpr; 02390 /// Brackets - The left and right array brackets. 02391 SourceRange Brackets; 02392 02393 VariableArrayType(QualType et, QualType can, Expr *e, 02394 ArraySizeModifier sm, unsigned tq, 02395 SourceRange brackets) 02396 : ArrayType(VariableArray, et, can, sm, tq, 02397 et->containsUnexpandedParameterPack()), 02398 SizeExpr((Stmt*) e), Brackets(brackets) {} 02399 friend class ASTContext; // ASTContext creates these. 02400 02401 public: 02402 Expr *getSizeExpr() const { 02403 // We use C-style casts instead of cast<> here because we do not wish 02404 // to have a dependency of Type.h on Stmt.h/Expr.h. 02405 return (Expr*) SizeExpr; 02406 } 02407 SourceRange getBracketsRange() const { return Brackets; } 02408 SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 02409 SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 02410 02411 bool isSugared() const { return false; } 02412 QualType desugar() const { return QualType(this, 0); } 02413 02414 static bool classof(const Type *T) { 02415 return T->getTypeClass() == VariableArray; 02416 } 02417 02418 friend class StmtIteratorBase; 02419 02420 void Profile(llvm::FoldingSetNodeID &ID) { 02421 llvm_unreachable("Cannot unique VariableArrayTypes."); 02422 } 02423 }; 02424 02425 /// DependentSizedArrayType - This type represents an array type in 02426 /// C++ whose size is a value-dependent expression. For example: 02427 /// 02428 /// \code 02429 /// template<typename T, int Size> 02430 /// class array { 02431 /// T data[Size]; 02432 /// }; 02433 /// \endcode 02434 /// 02435 /// For these types, we won't actually know what the array bound is 02436 /// until template instantiation occurs, at which point this will 02437 /// become either a ConstantArrayType or a VariableArrayType. 02438 class DependentSizedArrayType : public ArrayType { 02439 const ASTContext &Context; 02440 02441 /// \brief An assignment expression that will instantiate to the 02442 /// size of the array. 02443 /// 02444 /// The expression itself might be NULL, in which case the array 02445 /// type will have its size deduced from an initializer. 02446 Stmt *SizeExpr; 02447 02448 /// Brackets - The left and right array brackets. 02449 SourceRange Brackets; 02450 02451 DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can, 02452 Expr *e, ArraySizeModifier sm, unsigned tq, 02453 SourceRange brackets); 02454 02455 friend class ASTContext; // ASTContext creates these. 02456 02457 public: 02458 Expr *getSizeExpr() const { 02459 // We use C-style casts instead of cast<> here because we do not wish 02460 // to have a dependency of Type.h on Stmt.h/Expr.h. 02461 return (Expr*) SizeExpr; 02462 } 02463 SourceRange getBracketsRange() const { return Brackets; } 02464 SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 02465 SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 02466 02467 bool isSugared() const { return false; } 02468 QualType desugar() const { return QualType(this, 0); } 02469 02470 static bool classof(const Type *T) { 02471 return T->getTypeClass() == DependentSizedArray; 02472 } 02473 02474 friend class StmtIteratorBase; 02475 02476 02477 void Profile(llvm::FoldingSetNodeID &ID) { 02478 Profile(ID, Context, getElementType(), 02479 getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); 02480 } 02481 02482 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 02483 QualType ET, ArraySizeModifier SizeMod, 02484 unsigned TypeQuals, Expr *E); 02485 }; 02486 02487 /// DependentSizedExtVectorType - This type represent an extended vector type 02488 /// where either the type or size is dependent. For example: 02489 /// @code 02490 /// template<typename T, int Size> 02491 /// class vector { 02492 /// typedef T __attribute__((ext_vector_type(Size))) type; 02493 /// } 02494 /// @endcode 02495 class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { 02496 const ASTContext &Context; 02497 Expr *SizeExpr; 02498 /// ElementType - The element type of the array. 02499 QualType ElementType; 02500 SourceLocation loc; 02501 02502 DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType, 02503 QualType can, Expr *SizeExpr, SourceLocation loc); 02504 02505 friend class ASTContext; 02506 02507 public: 02508 Expr *getSizeExpr() const { return SizeExpr; } 02509 QualType getElementType() const { return ElementType; } 02510 SourceLocation getAttributeLoc() const { return loc; } 02511 02512 bool isSugared() const { return false; } 02513 QualType desugar() const { return QualType(this, 0); } 02514 02515 static bool classof(const Type *T) { 02516 return T->getTypeClass() == DependentSizedExtVector; 02517 } 02518 02519 void Profile(llvm::FoldingSetNodeID &ID) { 02520 Profile(ID, Context, getElementType(), getSizeExpr()); 02521 } 02522 02523 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 02524 QualType ElementType, Expr *SizeExpr); 02525 }; 02526 02527 02528 /// VectorType - GCC generic vector type. This type is created using 02529 /// __attribute__((vector_size(n)), where "n" specifies the vector size in 02530 /// bytes; or from an Altivec __vector or vector declaration. 02531 /// Since the constructor takes the number of vector elements, the 02532 /// client is responsible for converting the size into the number of elements. 02533 class VectorType : public Type, public llvm::FoldingSetNode { 02534 public: 02535 enum VectorKind { 02536 GenericVector, // not a target-specific vector type 02537 AltiVecVector, // is AltiVec vector 02538 AltiVecPixel, // is AltiVec 'vector Pixel' 02539 AltiVecBool, // is AltiVec 'vector bool ...' 02540 NeonVector, // is ARM Neon vector 02541 NeonPolyVector // is ARM Neon polynomial vector 02542 }; 02543 protected: 02544 /// ElementType - The element type of the vector. 02545 QualType ElementType; 02546 02547 VectorType(QualType vecType, unsigned nElements, QualType canonType, 02548 VectorKind vecKind); 02549 02550 VectorType(TypeClass tc, QualType vecType, unsigned nElements, 02551 QualType canonType, VectorKind vecKind); 02552 02553 friend class ASTContext; // ASTContext creates these. 02554 02555 public: 02556 02557 QualType getElementType() const { return ElementType; } 02558 unsigned getNumElements() const { return VectorTypeBits.NumElements; } 02559 static bool isVectorSizeTooLarge(unsigned NumElements) { 02560 return NumElements > VectorTypeBitfields::MaxNumElements; 02561 } 02562 02563 bool isSugared() const { return false; } 02564 QualType desugar() const { return QualType(this, 0); } 02565 02566 VectorKind getVectorKind() const { 02567 return VectorKind(VectorTypeBits.VecKind); 02568 } 02569 02570 void Profile(llvm::FoldingSetNodeID &ID) { 02571 Profile(ID, getElementType(), getNumElements(), 02572 getTypeClass(), getVectorKind()); 02573 } 02574 static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 02575 unsigned NumElements, TypeClass TypeClass, 02576 VectorKind VecKind) { 02577 ID.AddPointer(ElementType.getAsOpaquePtr()); 02578 ID.AddInteger(NumElements); 02579 ID.AddInteger(TypeClass); 02580 ID.AddInteger(VecKind); 02581 } 02582 02583 static bool classof(const Type *T) { 02584 return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 02585 } 02586 }; 02587 02588 /// ExtVectorType - Extended vector type. This type is created using 02589 /// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 02590 /// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 02591 /// class enables syntactic extensions, like Vector Components for accessing 02592 /// points, colors, and textures (modeled after OpenGL Shading Language). 02593 class ExtVectorType : public VectorType { 02594 ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 02595 VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {} 02596 friend class ASTContext; // ASTContext creates these. 02597 public: 02598 static int getPointAccessorIdx(char c) { 02599 switch (c) { 02600 default: return -1; 02601 case 'x': return 0; 02602 case 'y': return 1; 02603 case 'z': return 2; 02604 case 'w': return 3; 02605 } 02606 } 02607 static int getNumericAccessorIdx(char c) { 02608 switch (c) { 02609 default: return -1; 02610 case '0': return 0; 02611 case '1': return 1; 02612 case '2': return 2; 02613 case '3': return 3; 02614 case '4': return 4; 02615 case '5': return 5; 02616 case '6': return 6; 02617 case '7': return 7; 02618 case '8': return 8; 02619 case '9': return 9; 02620 case 'A': 02621 case 'a': return 10; 02622 case 'B': 02623 case 'b': return 11; 02624 case 'C': 02625 case 'c': return 12; 02626 case 'D': 02627 case 'd': return 13; 02628 case 'E': 02629 case 'e': return 14; 02630 case 'F': 02631 case 'f': return 15; 02632 } 02633 } 02634 02635 static int getAccessorIdx(char c) { 02636 if (int idx = getPointAccessorIdx(c)+1) return idx-1; 02637 return getNumericAccessorIdx(c); 02638 } 02639 02640 bool isAccessorWithinNumElements(char c) const { 02641 if (int idx = getAccessorIdx(c)+1) 02642 return unsigned(idx-1) < getNumElements(); 02643 return false; 02644 } 02645 bool isSugared() const { return false; } 02646 QualType desugar() const { return QualType(this, 0); } 02647 02648 static bool classof(const Type *T) { 02649 return T->getTypeClass() == ExtVector; 02650 } 02651 }; 02652 02653 /// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 02654 /// class of FunctionNoProtoType and FunctionProtoType. 02655 /// 02656 class FunctionType : public Type { 02657 // The type returned by the function. 02658 QualType ResultType; 02659 02660 public: 02661 /// ExtInfo - A class which abstracts out some details necessary for 02662 /// making a call. 02663 /// 02664 /// It is not actually used directly for storing this information in 02665 /// a FunctionType, although FunctionType does currently use the 02666 /// same bit-pattern. 02667 /// 02668 // If you add a field (say Foo), other than the obvious places (both, 02669 // constructors, compile failures), what you need to update is 02670 // * Operator== 02671 // * getFoo 02672 // * withFoo 02673 // * functionType. Add Foo, getFoo. 02674 // * ASTContext::getFooType 02675 // * ASTContext::mergeFunctionTypes 02676 // * FunctionNoProtoType::Profile 02677 // * FunctionProtoType::Profile 02678 // * TypePrinter::PrintFunctionProto 02679 // * AST read and write 02680 // * Codegen 02681 class ExtInfo { 02682 // Feel free to rearrange or add bits, but if you go over 9, 02683 // you'll need to adjust both the Bits field below and 02684 // Type::FunctionTypeBitfields. 02685 02686 // | CC |noreturn|produces|regparm| 02687 // |0 .. 3| 4 | 5 | 6 .. 8| 02688 // 02689 // regparm is either 0 (no regparm attribute) or the regparm value+1. 02690 enum { CallConvMask = 0xF }; 02691 enum { NoReturnMask = 0x10 }; 02692 enum { ProducesResultMask = 0x20 }; 02693 enum { RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask), 02694 RegParmOffset = 6 }; // Assumed to be the last field 02695 02696 uint16_t Bits; 02697 02698 ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {} 02699 02700 friend class FunctionType; 02701 02702 public: 02703 // Constructor with no defaults. Use this when you know that you 02704 // have all the elements (when reading an AST file for example). 02705 ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc, 02706 bool producesResult) { 02707 assert((!hasRegParm || regParm < 7) && "Invalid regparm value"); 02708 Bits = ((unsigned) cc) | 02709 (noReturn ? NoReturnMask : 0) | 02710 (producesResult ? ProducesResultMask : 0) | 02711 (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0); 02712 } 02713 02714 // Constructor with all defaults. Use when for example creating a 02715 // function know to use defaults. 02716 ExtInfo() : Bits(CC_C) { } 02717 02718 // Constructor with just the calling convention, which is an important part 02719 // of the canonical type. 02720 ExtInfo(CallingConv CC) : Bits(CC) { } 02721 02722 bool getNoReturn() const { return Bits & NoReturnMask; } 02723 bool getProducesResult() const { return Bits & ProducesResultMask; } 02724 bool getHasRegParm() const { return (Bits >> RegParmOffset) != 0; } 02725 unsigned getRegParm() const { 02726 unsigned RegParm = Bits >> RegParmOffset; 02727 if (RegParm > 0) 02728 --RegParm; 02729 return RegParm; 02730 } 02731 CallingConv getCC() const { return CallingConv(Bits & CallConvMask); } 02732 02733 bool operator==(ExtInfo Other) const { 02734 return Bits == Other.Bits; 02735 } 02736 bool operator!=(ExtInfo Other) const { 02737 return Bits != Other.Bits; 02738 } 02739 02740 // Note that we don't have setters. That is by design, use 02741 // the following with methods instead of mutating these objects. 02742 02743 ExtInfo withNoReturn(bool noReturn) const { 02744 if (noReturn) 02745 return ExtInfo(Bits | NoReturnMask); 02746 else 02747 return ExtInfo(Bits & ~NoReturnMask); 02748 } 02749 02750 ExtInfo withProducesResult(bool producesResult) const { 02751 if (producesResult) 02752 return ExtInfo(Bits | ProducesResultMask); 02753 else 02754 return ExtInfo(Bits & ~ProducesResultMask); 02755 } 02756 02757 ExtInfo withRegParm(unsigned RegParm) const { 02758 assert(RegParm < 7 && "Invalid regparm value"); 02759 return ExtInfo((Bits & ~RegParmMask) | 02760 ((RegParm + 1) << RegParmOffset)); 02761 } 02762 02763 ExtInfo withCallingConv(CallingConv cc) const { 02764 return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc); 02765 } 02766 02767 void Profile(llvm::FoldingSetNodeID &ID) const { 02768 ID.AddInteger(Bits); 02769 } 02770 }; 02771 02772 protected: 02773 FunctionType(TypeClass tc, QualType res, 02774 QualType Canonical, bool Dependent, 02775 bool InstantiationDependent, 02776 bool VariablyModified, bool ContainsUnexpandedParameterPack, 02777 ExtInfo Info) 02778 : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified, 02779 ContainsUnexpandedParameterPack), 02780 ResultType(res) { 02781 FunctionTypeBits.ExtInfo = Info.Bits; 02782 } 02783 unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; } 02784 02785 public: 02786 QualType getReturnType() const { return ResultType; } 02787 02788 bool getHasRegParm() const { return getExtInfo().getHasRegParm(); } 02789 unsigned getRegParmType() const { return getExtInfo().getRegParm(); } 02790 /// \brief Determine whether this function type includes the GNU noreturn 02791 /// attribute. The C++11 [[noreturn]] attribute does not affect the function 02792 /// type. 02793 bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); } 02794 CallingConv getCallConv() const { return getExtInfo().getCC(); } 02795 ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); } 02796 bool isConst() const { return getTypeQuals() & Qualifiers::Const; } 02797 bool isVolatile() const { return getTypeQuals() & Qualifiers::Volatile; } 02798 bool isRestrict() const { return getTypeQuals() & Qualifiers::Restrict; } 02799 02800 /// \brief Determine the type of an expression that calls a function of 02801 /// this type. 02802 QualType getCallResultType(ASTContext &Context) const { 02803 return getReturnType().getNonLValueExprType(Context); 02804 } 02805 02806 static StringRef getNameForCallConv(CallingConv CC); 02807 02808 static bool classof(const Type *T) { 02809 return T->getTypeClass() == FunctionNoProto || 02810 T->getTypeClass() == FunctionProto; 02811 } 02812 }; 02813 02814 /// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 02815 /// no information available about its arguments. 02816 class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 02817 FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info) 02818 : FunctionType(FunctionNoProto, Result, Canonical, 02819 /*Dependent=*/false, /*InstantiationDependent=*/false, 02820 Result->isVariablyModifiedType(), 02821 /*ContainsUnexpandedParameterPack=*/false, Info) {} 02822 02823 friend class ASTContext; // ASTContext creates these. 02824 02825 public: 02826 // No additional state past what FunctionType provides. 02827 02828 bool isSugared() const { return false; } 02829 QualType desugar() const { return QualType(this, 0); } 02830 02831 void Profile(llvm::FoldingSetNodeID &ID) { 02832 Profile(ID, getReturnType(), getExtInfo()); 02833 } 02834 static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 02835 ExtInfo Info) { 02836 Info.Profile(ID); 02837 ID.AddPointer(ResultType.getAsOpaquePtr()); 02838 } 02839 02840 static bool classof(const Type *T) { 02841 return T->getTypeClass() == FunctionNoProto; 02842 } 02843 }; 02844 02845 /// FunctionProtoType - Represents a prototype with parameter type info, e.g. 02846 /// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 02847 /// parameters, not as having a single void parameter. Such a type can have an 02848 /// exception specification, but this specification is not part of the canonical 02849 /// type. 02850 class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 02851 public: 02852 struct ExceptionSpecInfo { 02853 ExceptionSpecInfo() 02854 : Type(EST_None), NoexceptExpr(nullptr), 02855 SourceDecl(nullptr), SourceTemplate(nullptr) {} 02856 02857 ExceptionSpecInfo(ExceptionSpecificationType EST) 02858 : Type(EST), NoexceptExpr(nullptr), SourceDecl(nullptr), 02859 SourceTemplate(nullptr) {} 02860 02861 /// The kind of exception specification this is. 02862 ExceptionSpecificationType Type; 02863 /// Explicitly-specified list of exception types. 02864 ArrayRef<QualType> Exceptions; 02865 /// Noexcept expression, if this is EST_ComputedNoexcept. 02866 Expr *NoexceptExpr; 02867 /// The function whose exception specification this is, for 02868 /// EST_Unevaluated and EST_Uninstantiated. 02869 FunctionDecl *SourceDecl; 02870 /// The function template whose exception specification this is instantiated 02871 /// from, for EST_Uninstantiated. 02872 FunctionDecl *SourceTemplate; 02873 }; 02874 02875 /// ExtProtoInfo - Extra information about a function prototype. 02876 struct ExtProtoInfo { 02877 ExtProtoInfo() 02878 : Variadic(false), HasTrailingReturn(false), TypeQuals(0), 02879 RefQualifier(RQ_None), ConsumedParameters(nullptr) {} 02880 02881 ExtProtoInfo(CallingConv CC) 02882 : ExtInfo(CC), Variadic(false), HasTrailingReturn(false), TypeQuals(0), 02883 RefQualifier(RQ_None), ConsumedParameters(nullptr) {} 02884 02885 ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &O) { 02886 ExtProtoInfo Result(*this); 02887 Result.ExceptionSpec = O; 02888 return Result; 02889 } 02890 02891 FunctionType::ExtInfo ExtInfo; 02892 bool Variadic : 1; 02893 bool HasTrailingReturn : 1; 02894 unsigned char TypeQuals; 02895 RefQualifierKind RefQualifier; 02896 ExceptionSpecInfo ExceptionSpec; 02897 const bool *ConsumedParameters; 02898 }; 02899 02900 private: 02901 /// \brief Determine whether there are any argument types that 02902 /// contain an unexpanded parameter pack. 02903 static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray, 02904 unsigned numArgs) { 02905 for (unsigned Idx = 0; Idx < numArgs; ++Idx) 02906 if (ArgArray[Idx]->containsUnexpandedParameterPack()) 02907 return true; 02908 02909 return false; 02910 } 02911 02912 FunctionProtoType(QualType result, ArrayRef<QualType> params, 02913 QualType canonical, const ExtProtoInfo &epi); 02914 02915 /// The number of parameters this function has, not counting '...'. 02916 unsigned NumParams : 15; 02917 02918 /// NumExceptions - The number of types in the exception spec, if any. 02919 unsigned NumExceptions : 9; 02920 02921 /// ExceptionSpecType - The type of exception specification this function has. 02922 unsigned ExceptionSpecType : 4; 02923 02924 /// HasAnyConsumedParams - Whether this function has any consumed parameters. 02925 unsigned HasAnyConsumedParams : 1; 02926 02927 /// Variadic - Whether the function is variadic. 02928 unsigned Variadic : 1; 02929 02930 /// HasTrailingReturn - Whether this function has a trailing return type. 02931 unsigned HasTrailingReturn : 1; 02932 02933 // ParamInfo - There is an variable size array after the class in memory that 02934 // holds the parameter types. 02935 02936 // Exceptions - There is another variable size array after ArgInfo that 02937 // holds the exception types. 02938 02939 // NoexceptExpr - Instead of Exceptions, there may be a single Expr* pointing 02940 // to the expression in the noexcept() specifier. 02941 02942 // ExceptionSpecDecl, ExceptionSpecTemplate - Instead of Exceptions, there may 02943 // be a pair of FunctionDecl* pointing to the function which should be used to 02944 // instantiate this function type's exception specification, and the function 02945 // from which it should be instantiated. 02946 02947 // ConsumedParameters - A variable size array, following Exceptions 02948 // and of length NumParams, holding flags indicating which parameters 02949 // are consumed. This only appears if HasAnyConsumedParams is true. 02950 02951 friend class ASTContext; // ASTContext creates these. 02952 02953 const bool *getConsumedParamsBuffer() const { 02954 assert(hasAnyConsumedParams()); 02955 02956 // Find the end of the exceptions. 02957 Expr *const *eh_end = reinterpret_cast<Expr *const *>(param_type_end()); 02958 if (getExceptionSpecType() != EST_ComputedNoexcept) 02959 eh_end += NumExceptions; 02960 else 02961 eh_end += 1; // NoexceptExpr 02962 02963 return reinterpret_cast<const bool*>(eh_end); 02964 } 02965 02966 public: 02967 unsigned getNumParams() const { return NumParams; } 02968 QualType getParamType(unsigned i) const { 02969 assert(i < NumParams && "invalid parameter index"); 02970 return param_type_begin()[i]; 02971 } 02972 ArrayRef<QualType> getParamTypes() const { 02973 return llvm::makeArrayRef(param_type_begin(), param_type_end()); 02974 } 02975 02976 ExtProtoInfo getExtProtoInfo() const { 02977 ExtProtoInfo EPI; 02978 EPI.ExtInfo = getExtInfo(); 02979 EPI.Variadic = isVariadic(); 02980 EPI.HasTrailingReturn = hasTrailingReturn(); 02981 EPI.ExceptionSpec.Type = getExceptionSpecType(); 02982 EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals()); 02983 EPI.RefQualifier = getRefQualifier(); 02984 if (EPI.ExceptionSpec.Type == EST_Dynamic) { 02985 EPI.ExceptionSpec.Exceptions = exceptions(); 02986 } else if (EPI.ExceptionSpec.Type == EST_ComputedNoexcept) { 02987 EPI.ExceptionSpec.NoexceptExpr = getNoexceptExpr(); 02988 } else if (EPI.ExceptionSpec.Type == EST_Uninstantiated) { 02989 EPI.ExceptionSpec.SourceDecl = getExceptionSpecDecl(); 02990 EPI.ExceptionSpec.SourceTemplate = getExceptionSpecTemplate(); 02991 } else if (EPI.ExceptionSpec.Type == EST_Unevaluated) { 02992 EPI.ExceptionSpec.SourceDecl = getExceptionSpecDecl(); 02993 } 02994 if (hasAnyConsumedParams()) 02995 EPI.ConsumedParameters = getConsumedParamsBuffer(); 02996 return EPI; 02997 } 02998 02999 /// \brief Get the kind of exception specification on this function. 03000 ExceptionSpecificationType getExceptionSpecType() const { 03001 return static_cast<ExceptionSpecificationType>(ExceptionSpecType); 03002 } 03003 /// \brief Return whether this function has any kind of exception spec. 03004 bool hasExceptionSpec() const { 03005 return getExceptionSpecType() != EST_None; 03006 } 03007 /// \brief Return whether this function has a dynamic (throw) exception spec. 03008 bool hasDynamicExceptionSpec() const { 03009 return isDynamicExceptionSpec(getExceptionSpecType()); 03010 } 03011 /// \brief Return whether this function has a noexcept exception spec. 03012 bool hasNoexceptExceptionSpec() const { 03013 return isNoexceptExceptionSpec(getExceptionSpecType()); 03014 } 03015 /// \brief Return whether this function has a dependent exception spec. 03016 bool hasDependentExceptionSpec() const; 03017 /// \brief Result type of getNoexceptSpec(). 03018 enum NoexceptResult { 03019 NR_NoNoexcept, ///< There is no noexcept specifier. 03020 NR_BadNoexcept, ///< The noexcept specifier has a bad expression. 03021 NR_Dependent, ///< The noexcept specifier is dependent. 03022 NR_Throw, ///< The noexcept specifier evaluates to false. 03023 NR_Nothrow ///< The noexcept specifier evaluates to true. 03024 }; 03025 /// \brief Get the meaning of the noexcept spec on this function, if any. 03026 NoexceptResult getNoexceptSpec(const ASTContext &Ctx) const; 03027 unsigned getNumExceptions() const { return NumExceptions; } 03028 QualType getExceptionType(unsigned i) const { 03029 assert(i < NumExceptions && "Invalid exception number!"); 03030 return exception_begin()[i]; 03031 } 03032 Expr *getNoexceptExpr() const { 03033 if (getExceptionSpecType() != EST_ComputedNoexcept) 03034 return nullptr; 03035 // NoexceptExpr sits where the arguments end. 03036 return *reinterpret_cast<Expr *const *>(param_type_end()); 03037 } 03038 /// \brief If this function type has an exception specification which hasn't 03039 /// been determined yet (either because it has not been evaluated or because 03040 /// it has not been instantiated), this is the function whose exception 03041 /// specification is represented by this type. 03042 FunctionDecl *getExceptionSpecDecl() const { 03043 if (getExceptionSpecType() != EST_Uninstantiated && 03044 getExceptionSpecType() != EST_Unevaluated) 03045 return nullptr; 03046 return reinterpret_cast<FunctionDecl *const *>(param_type_end())[0]; 03047 } 03048 /// \brief If this function type has an uninstantiated exception 03049 /// specification, this is the function whose exception specification 03050 /// should be instantiated to find the exception specification for 03051 /// this type. 03052 FunctionDecl *getExceptionSpecTemplate() const { 03053 if (getExceptionSpecType() != EST_Uninstantiated) 03054 return nullptr; 03055 return reinterpret_cast<FunctionDecl *const *>(param_type_end())[1]; 03056 } 03057 /// \brief Determine whether this function type has a non-throwing exception 03058 /// specification. If this depends on template arguments, returns 03059 /// \c ResultIfDependent. 03060 bool isNothrow(const ASTContext &Ctx, bool ResultIfDependent = false) const; 03061 03062 bool isVariadic() const { return Variadic; } 03063 03064 /// \brief Determines whether this function prototype contains a 03065 /// parameter pack at the end. 03066 /// 03067 /// A function template whose last parameter is a parameter pack can be 03068 /// called with an arbitrary number of arguments, much like a variadic 03069 /// function. 03070 bool isTemplateVariadic() const; 03071 03072 bool hasTrailingReturn() const { return HasTrailingReturn; } 03073 03074 unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 03075 03076 03077 /// \brief Retrieve the ref-qualifier associated with this function type. 03078 RefQualifierKind getRefQualifier() const { 03079 return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier); 03080 } 03081 03082 typedef const QualType *param_type_iterator; 03083 typedef llvm::iterator_range<param_type_iterator> param_type_range; 03084 03085 param_type_range param_types() const { 03086 return param_type_range(param_type_begin(), param_type_end()); 03087 } 03088 param_type_iterator param_type_begin() const { 03089 return reinterpret_cast<const QualType *>(this+1); 03090 } 03091 param_type_iterator param_type_end() const { 03092 return param_type_begin() + NumParams; 03093 } 03094 03095 typedef const QualType *exception_iterator; 03096 03097 ArrayRef<QualType> exceptions() const { 03098 return llvm::makeArrayRef(exception_begin(), exception_end()); 03099 } 03100 exception_iterator exception_begin() const { 03101 // exceptions begin where arguments end 03102 return param_type_end(); 03103 } 03104 exception_iterator exception_end() const { 03105 if (getExceptionSpecType() != EST_Dynamic) 03106 return exception_begin(); 03107 return exception_begin() + NumExceptions; 03108 } 03109 03110 bool hasAnyConsumedParams() const { return HasAnyConsumedParams; } 03111 bool isParamConsumed(unsigned I) const { 03112 assert(I < getNumParams() && "parameter index out of range"); 03113 if (hasAnyConsumedParams()) 03114 return getConsumedParamsBuffer()[I]; 03115 return false; 03116 } 03117 03118 bool isSugared() const { return false; } 03119 QualType desugar() const { return QualType(this, 0); } 03120 03121 void printExceptionSpecification(raw_ostream &OS, 03122 const PrintingPolicy &Policy) const; 03123 03124 static bool classof(const Type *T) { 03125 return T->getTypeClass() == FunctionProto; 03126 } 03127 03128 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx); 03129 static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 03130 param_type_iterator ArgTys, unsigned NumArgs, 03131 const ExtProtoInfo &EPI, const ASTContext &Context); 03132 }; 03133 03134 03135 /// \brief Represents the dependent type named by a dependently-scoped 03136 /// typename using declaration, e.g. 03137 /// using typename Base<T>::foo; 03138 /// Template instantiation turns these into the underlying type. 03139 class UnresolvedUsingType : public Type { 03140 UnresolvedUsingTypenameDecl *Decl; 03141 03142 UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) 03143 : Type(UnresolvedUsing, QualType(), true, true, false, 03144 /*ContainsUnexpandedParameterPack=*/false), 03145 Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {} 03146 friend class ASTContext; // ASTContext creates these. 03147 public: 03148 03149 UnresolvedUsingTypenameDecl *getDecl() const { return Decl; } 03150 03151 bool isSugared() const { return false; } 03152 QualType desugar() const { return QualType(this, 0); } 03153 03154 static bool classof(const Type *T) { 03155 return T->getTypeClass() == UnresolvedUsing; 03156 } 03157 03158 void Profile(llvm::FoldingSetNodeID &ID) { 03159 return Profile(ID, Decl); 03160 } 03161 static void Profile(llvm::FoldingSetNodeID &ID, 03162 UnresolvedUsingTypenameDecl *D) { 03163 ID.AddPointer(D); 03164 } 03165 }; 03166 03167 03168 class TypedefType : public Type { 03169 TypedefNameDecl *Decl; 03170 protected: 03171 TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can) 03172 : Type(tc, can, can->isDependentType(), 03173 can->isInstantiationDependentType(), 03174 can->isVariablyModifiedType(), 03175 /*ContainsUnexpandedParameterPack=*/false), 03176 Decl(const_cast<TypedefNameDecl*>(D)) { 03177 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 03178 } 03179 friend class ASTContext; // ASTContext creates these. 03180 public: 03181 03182 TypedefNameDecl *getDecl() const { return Decl; } 03183 03184 bool isSugared() const { return true; } 03185 QualType desugar() const; 03186 03187 static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 03188 }; 03189 03190 /// TypeOfExprType (GCC extension). 03191 class TypeOfExprType : public Type { 03192 Expr *TOExpr; 03193 03194 protected: 03195 TypeOfExprType(Expr *E, QualType can = QualType()); 03196 friend class ASTContext; // ASTContext creates these. 03197 public: 03198 Expr *getUnderlyingExpr() const { return TOExpr; } 03199 03200 /// \brief Remove a single level of sugar. 03201 QualType desugar() const; 03202 03203 /// \brief Returns whether this type directly provides sugar. 03204 bool isSugared() const; 03205 03206 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 03207 }; 03208 03209 /// \brief Internal representation of canonical, dependent 03210 /// typeof(expr) types. 03211 /// 03212 /// This class is used internally by the ASTContext to manage 03213 /// canonical, dependent types, only. Clients will only see instances 03214 /// of this class via TypeOfExprType nodes. 03215 class DependentTypeOfExprType 03216 : public TypeOfExprType, public llvm::FoldingSetNode { 03217 const ASTContext &Context; 03218 03219 public: 03220 DependentTypeOfExprType(const ASTContext &Context, Expr *E) 03221 : TypeOfExprType(E), Context(Context) { } 03222 03223 void Profile(llvm::FoldingSetNodeID &ID) { 03224 Profile(ID, Context, getUnderlyingExpr()); 03225 } 03226 03227 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 03228 Expr *E); 03229 }; 03230 03231 /// TypeOfType (GCC extension). 03232 class TypeOfType : public Type { 03233 QualType TOType; 03234 TypeOfType(QualType T, QualType can) 03235 : Type(TypeOf, can, T->isDependentType(), 03236 T->isInstantiationDependentType(), 03237 T->isVariablyModifiedType(), 03238 T->containsUnexpandedParameterPack()), 03239 TOType(T) { 03240 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 03241 } 03242 friend class ASTContext; // ASTContext creates these. 03243 public: 03244 QualType getUnderlyingType() const { return TOType; } 03245 03246 /// \brief Remove a single level of sugar. 03247 QualType desugar() const { return getUnderlyingType(); } 03248 03249 /// \brief Returns whether this type directly provides sugar. 03250 bool isSugared() const { return true; } 03251 03252 static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 03253 }; 03254 03255 /// DecltypeType (C++0x) 03256 class DecltypeType : public Type { 03257 Expr *E; 03258 QualType UnderlyingType; 03259 03260 protected: 03261 DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 03262 friend class ASTContext; // ASTContext creates these. 03263 public: 03264 Expr *getUnderlyingExpr() const { return E; } 03265 QualType getUnderlyingType() const { return UnderlyingType; } 03266 03267 /// \brief Remove a single level of sugar. 03268 QualType desugar() const; 03269 03270 /// \brief Returns whether this type directly provides sugar. 03271 bool isSugared() const; 03272 03273 static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 03274 }; 03275 03276 /// \brief Internal representation of canonical, dependent 03277 /// decltype(expr) types. 03278 /// 03279 /// This class is used internally by the ASTContext to manage 03280 /// canonical, dependent types, only. Clients will only see instances 03281 /// of this class via DecltypeType nodes. 03282 class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { 03283 const ASTContext &Context; 03284 03285 public: 03286 DependentDecltypeType(const ASTContext &Context, Expr *E); 03287 03288 void Profile(llvm::FoldingSetNodeID &ID) { 03289 Profile(ID, Context, getUnderlyingExpr()); 03290 } 03291 03292 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 03293 Expr *E); 03294 }; 03295 03296 /// \brief A unary type transform, which is a type constructed from another 03297 class UnaryTransformType : public Type { 03298 public: 03299 enum UTTKind { 03300 EnumUnderlyingType 03301 }; 03302 03303 private: 03304 /// The untransformed type. 03305 QualType BaseType; 03306 /// The transformed type if not dependent, otherwise the same as BaseType. 03307 QualType UnderlyingType; 03308 03309 UTTKind UKind; 03310 protected: 03311 UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind, 03312 QualType CanonicalTy); 03313 friend class ASTContext; 03314 public: 03315 bool isSugared() const { return !isDependentType(); } 03316 QualType desugar() const { return UnderlyingType; } 03317 03318 QualType getUnderlyingType() const { return UnderlyingType; } 03319 QualType getBaseType() const { return BaseType; } 03320 03321 UTTKind getUTTKind() const { return UKind; } 03322 03323 static bool classof(const Type *T) { 03324 return T->getTypeClass() == UnaryTransform; 03325 } 03326 }; 03327 03328 class TagType : public Type { 03329 /// Stores the TagDecl associated with this type. The decl may point to any 03330 /// TagDecl that declares the entity. 03331 TagDecl * decl; 03332 03333 friend class ASTReader; 03334 03335 protected: 03336 TagType(TypeClass TC, const TagDecl *D, QualType can); 03337 03338 public: 03339 TagDecl *getDecl() const; 03340 03341 /// @brief Determines whether this type is in the process of being 03342 /// defined. 03343 bool isBeingDefined() const; 03344 03345 static bool classof(const Type *T) { 03346 return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 03347 } 03348 }; 03349 03350 /// RecordType - This is a helper class that allows the use of isa/cast/dyncast 03351 /// to detect TagType objects of structs/unions/classes. 03352 class RecordType : public TagType { 03353 protected: 03354 explicit RecordType(const RecordDecl *D) 03355 : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { } 03356 explicit RecordType(TypeClass TC, RecordDecl *D) 03357 : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { } 03358 friend class ASTContext; // ASTContext creates these. 03359 public: 03360 03361 RecordDecl *getDecl() const { 03362 return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 03363 } 03364 03365 // FIXME: This predicate is a helper to QualType/Type. It needs to 03366 // recursively check all fields for const-ness. If any field is declared 03367 // const, it needs to return false. 03368 bool hasConstFields() const { return false; } 03369 03370 bool isSugared() const { return false; } 03371 QualType desugar() const { return QualType(this, 0); } 03372 03373 static bool classof(const Type *T) { return T->getTypeClass() == Record; } 03374 }; 03375 03376 /// EnumType - This is a helper class that allows the use of isa/cast/dyncast 03377 /// to detect TagType objects of enums. 03378 class EnumType : public TagType { 03379 explicit EnumType(const EnumDecl *D) 03380 : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { } 03381 friend class ASTContext; // ASTContext creates these. 03382 public: 03383 03384 EnumDecl *getDecl() const { 03385 return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 03386 } 03387 03388 bool isSugared() const { return false; } 03389 QualType desugar() const { return QualType(this, 0); } 03390 03391 static bool classof(const Type *T) { return T->getTypeClass() == Enum; } 03392 }; 03393 03394 /// AttributedType - An attributed type is a type to which a type 03395 /// attribute has been applied. The "modified type" is the 03396 /// fully-sugared type to which the attributed type was applied; 03397 /// generally it is not canonically equivalent to the attributed type. 03398 /// The "equivalent type" is the minimally-desugared type which the 03399 /// type is canonically equivalent to. 03400 /// 03401 /// For example, in the following attributed type: 03402 /// int32_t __attribute__((vector_size(16))) 03403 /// - the modified type is the TypedefType for int32_t 03404 /// - the equivalent type is VectorType(16, int32_t) 03405 /// - the canonical type is VectorType(16, int) 03406 class AttributedType : public Type, public llvm::FoldingSetNode { 03407 public: 03408 // It is really silly to have yet another attribute-kind enum, but 03409 // clang::attr::Kind doesn't currently cover the pure type attrs. 03410 enum Kind { 03411 // Expression operand. 03412 attr_address_space, 03413 attr_regparm, 03414 attr_vector_size, 03415 attr_neon_vector_type, 03416 attr_neon_polyvector_type, 03417 03418 FirstExprOperandKind = attr_address_space, 03419 LastExprOperandKind = attr_neon_polyvector_type, 03420 03421 // Enumerated operand (string or keyword). 03422 attr_objc_gc, 03423 attr_objc_ownership, 03424 attr_pcs, 03425 attr_pcs_vfp, 03426 03427 FirstEnumOperandKind = attr_objc_gc, 03428 LastEnumOperandKind = attr_pcs_vfp, 03429 03430 // No operand. 03431 attr_noreturn, 03432 attr_cdecl, 03433 attr_fastcall, 03434 attr_stdcall, 03435 attr_thiscall, 03436 attr_pascal, 03437 attr_vectorcall, 03438 attr_pnaclcall, 03439 attr_inteloclbicc, 03440 attr_ms_abi, 03441 attr_sysv_abi, 03442 attr_ptr32, 03443 attr_ptr64, 03444 attr_sptr, 03445 attr_uptr 03446 }; 03447 03448 private: 03449 QualType ModifiedType; 03450 QualType EquivalentType; 03451 03452 friend class ASTContext; // creates these 03453 03454 AttributedType(QualType canon, Kind attrKind, 03455 QualType modified, QualType equivalent) 03456 : Type(Attributed, canon, canon->isDependentType(), 03457 canon->isInstantiationDependentType(), 03458 canon->isVariablyModifiedType(), 03459 canon->containsUnexpandedParameterPack()), 03460 ModifiedType(modified), EquivalentType(equivalent) { 03461 AttributedTypeBits.AttrKind = attrKind; 03462 } 03463 03464 public: 03465 Kind getAttrKind() const { 03466 return static_cast<Kind>(AttributedTypeBits.AttrKind); 03467 } 03468 03469 QualType getModifiedType() const { return ModifiedType; } 03470 QualType getEquivalentType() const { return EquivalentType; } 03471 03472 bool isSugared() const { return true; } 03473 QualType desugar() const { return getEquivalentType(); } 03474 03475 bool isMSTypeSpec() const; 03476 03477 bool isCallingConv() const; 03478 03479 void Profile(llvm::FoldingSetNodeID &ID) { 03480 Profile(ID, getAttrKind(), ModifiedType, EquivalentType); 03481 } 03482 03483 static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind, 03484 QualType modified, QualType equivalent) { 03485 ID.AddInteger(attrKind); 03486 ID.AddPointer(modified.getAsOpaquePtr()); 03487 ID.AddPointer(equivalent.getAsOpaquePtr()); 03488 } 03489 03490 static bool classof(const Type *T) { 03491 return T->getTypeClass() == Attributed; 03492 } 03493 }; 03494 03495 class TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 03496 // Helper data collector for canonical types. 03497 struct CanonicalTTPTInfo { 03498 unsigned Depth : 15; 03499 unsigned ParameterPack : 1; 03500 unsigned Index : 16; 03501 }; 03502 03503 union { 03504 // Info for the canonical type. 03505 CanonicalTTPTInfo CanTTPTInfo; 03506 // Info for the non-canonical type. 03507 TemplateTypeParmDecl *TTPDecl; 03508 }; 03509 03510 /// Build a non-canonical type. 03511 TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon) 03512 : Type(TemplateTypeParm, Canon, /*Dependent=*/true, 03513 /*InstantiationDependent=*/true, 03514 /*VariablyModified=*/false, 03515 Canon->containsUnexpandedParameterPack()), 03516 TTPDecl(TTPDecl) { } 03517 03518 /// Build the canonical type. 03519 TemplateTypeParmType(unsigned D, unsigned I, bool PP) 03520 : Type(TemplateTypeParm, QualType(this, 0), 03521 /*Dependent=*/true, 03522 /*InstantiationDependent=*/true, 03523 /*VariablyModified=*/false, PP) { 03524 CanTTPTInfo.Depth = D; 03525 CanTTPTInfo.Index = I; 03526 CanTTPTInfo.ParameterPack = PP; 03527 } 03528 03529 friend class ASTContext; // ASTContext creates these 03530 03531 const CanonicalTTPTInfo& getCanTTPTInfo() const { 03532 QualType Can = getCanonicalTypeInternal(); 03533 return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo; 03534 } 03535 03536 public: 03537 unsigned getDepth() const { return getCanTTPTInfo().Depth; } 03538 unsigned getIndex() const { return getCanTTPTInfo().Index; } 03539 bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; } 03540 03541 TemplateTypeParmDecl *getDecl() const { 03542 return isCanonicalUnqualified() ? nullptr : TTPDecl; 03543 } 03544 03545 IdentifierInfo *getIdentifier() const; 03546 03547 bool isSugared() const { return false; } 03548 QualType desugar() const { return QualType(this, 0); } 03549 03550 void Profile(llvm::FoldingSetNodeID &ID) { 03551 Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl()); 03552 } 03553 03554 static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 03555 unsigned Index, bool ParameterPack, 03556 TemplateTypeParmDecl *TTPDecl) { 03557 ID.AddInteger(Depth); 03558 ID.AddInteger(Index); 03559 ID.AddBoolean(ParameterPack); 03560 ID.AddPointer(TTPDecl); 03561 } 03562 03563 static bool classof(const Type *T) { 03564 return T->getTypeClass() == TemplateTypeParm; 03565 } 03566 }; 03567 03568 /// \brief Represents the result of substituting a type for a template 03569 /// type parameter. 03570 /// 03571 /// Within an instantiated template, all template type parameters have 03572 /// been replaced with these. They are used solely to record that a 03573 /// type was originally written as a template type parameter; 03574 /// therefore they are never canonical. 03575 class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode { 03576 // The original type parameter. 03577 const TemplateTypeParmType *Replaced; 03578 03579 SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) 03580 : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(), 03581 Canon->isInstantiationDependentType(), 03582 Canon->isVariablyModifiedType(), 03583 Canon->containsUnexpandedParameterPack()), 03584 Replaced(Param) { } 03585 03586 friend class ASTContext; 03587 03588 public: 03589 /// Gets the template parameter that was substituted for. 03590 const TemplateTypeParmType *getReplacedParameter() const { 03591 return Replaced; 03592 } 03593 03594 /// Gets the type that was substituted for the template 03595 /// parameter. 03596 QualType getReplacementType() const { 03597 return getCanonicalTypeInternal(); 03598 } 03599 03600 bool isSugared() const { return true; } 03601 QualType desugar() const { return getReplacementType(); } 03602 03603 void Profile(llvm::FoldingSetNodeID &ID) { 03604 Profile(ID, getReplacedParameter(), getReplacementType()); 03605 } 03606 static void Profile(llvm::FoldingSetNodeID &ID, 03607 const TemplateTypeParmType *Replaced, 03608 QualType Replacement) { 03609 ID.AddPointer(Replaced); 03610 ID.AddPointer(Replacement.getAsOpaquePtr()); 03611 } 03612 03613 static bool classof(const Type *T) { 03614 return T->getTypeClass() == SubstTemplateTypeParm; 03615 } 03616 }; 03617 03618 /// \brief Represents the result of substituting a set of types for a template 03619 /// type parameter pack. 03620 /// 03621 /// When a pack expansion in the source code contains multiple parameter packs 03622 /// and those parameter packs correspond to different levels of template 03623 /// parameter lists, this type node is used to represent a template type 03624 /// parameter pack from an outer level, which has already had its argument pack 03625 /// substituted but that still lives within a pack expansion that itself 03626 /// could not be instantiated. When actually performing a substitution into 03627 /// that pack expansion (e.g., when all template parameters have corresponding 03628 /// arguments), this type will be replaced with the \c SubstTemplateTypeParmType 03629 /// at the current pack substitution index. 03630 class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode { 03631 /// \brief The original type parameter. 03632 const TemplateTypeParmType *Replaced; 03633 03634 /// \brief A pointer to the set of template arguments that this 03635 /// parameter pack is instantiated with. 03636 const TemplateArgument *Arguments; 03637 03638 /// \brief The number of template arguments in \c Arguments. 03639 unsigned NumArguments; 03640 03641 SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param, 03642 QualType Canon, 03643 const TemplateArgument &ArgPack); 03644 03645 friend class ASTContext; 03646 03647 public: 03648 IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); } 03649 03650 /// Gets the template parameter that was substituted for. 03651 const TemplateTypeParmType *getReplacedParameter() const { 03652 return Replaced; 03653 } 03654 03655 bool isSugared() const { return false; } 03656 QualType desugar() const { return QualType(this, 0); } 03657 03658 TemplateArgument getArgumentPack() const; 03659 03660 void Profile(llvm::FoldingSetNodeID &ID); 03661 static void Profile(llvm::FoldingSetNodeID &ID, 03662 const TemplateTypeParmType *Replaced, 03663 const TemplateArgument &ArgPack); 03664 03665 static bool classof(const Type *T) { 03666 return T->getTypeClass() == SubstTemplateTypeParmPack; 03667 } 03668 }; 03669 03670 /// \brief Represents a C++11 auto or C++1y decltype(auto) type. 03671 /// 03672 /// These types are usually a placeholder for a deduced type. However, before 03673 /// the initializer is attached, or if the initializer is type-dependent, there 03674 /// is no deduced type and an auto type is canonical. In the latter case, it is 03675 /// also a dependent type. 03676 class AutoType : public Type, public llvm::FoldingSetNode { 03677 AutoType(QualType DeducedType, bool IsDecltypeAuto, 03678 bool IsDependent) 03679 : Type(Auto, DeducedType.isNull() ? QualType(this, 0) : DeducedType, 03680 /*Dependent=*/IsDependent, /*InstantiationDependent=*/IsDependent, 03681 /*VariablyModified=*/false, 03682 /*ContainsParameterPack=*/DeducedType.isNull() 03683 ? false : DeducedType->containsUnexpandedParameterPack()) { 03684 assert((DeducedType.isNull() || !IsDependent) && 03685 "auto deduced to dependent type"); 03686 AutoTypeBits.IsDecltypeAuto = IsDecltypeAuto; 03687 } 03688 03689 friend class ASTContext; // ASTContext creates these 03690 03691 public: 03692 bool isDecltypeAuto() const { return AutoTypeBits.IsDecltypeAuto; } 03693 03694 bool isSugared() const { return !isCanonicalUnqualified(); } 03695 QualType desugar() const { return getCanonicalTypeInternal(); } 03696 03697 /// \brief Get the type deduced for this auto type, or null if it's either 03698 /// not been deduced or was deduced to a dependent type. 03699 QualType getDeducedType() const { 03700 return !isCanonicalUnqualified() ? getCanonicalTypeInternal() : QualType(); 03701 } 03702 bool isDeduced() const { 03703 return !isCanonicalUnqualified() || isDependentType(); 03704 } 03705 03706 void Profile(llvm::FoldingSetNodeID &ID) { 03707 Profile(ID, getDeducedType(), isDecltypeAuto(), 03708 isDependentType()); 03709 } 03710 03711 static void Profile(llvm::FoldingSetNodeID &ID, QualType Deduced, 03712 bool IsDecltypeAuto, bool IsDependent) { 03713 ID.AddPointer(Deduced.getAsOpaquePtr()); 03714 ID.AddBoolean(IsDecltypeAuto); 03715 ID.AddBoolean(IsDependent); 03716 } 03717 03718 static bool classof(const Type *T) { 03719 return T->getTypeClass() == Auto; 03720 } 03721 }; 03722 03723 /// \brief Represents a type template specialization; the template 03724 /// must be a class template, a type alias template, or a template 03725 /// template parameter. A template which cannot be resolved to one of 03726 /// these, e.g. because it is written with a dependent scope 03727 /// specifier, is instead represented as a 03728 /// @c DependentTemplateSpecializationType. 03729 /// 03730 /// A non-dependent template specialization type is always "sugar", 03731 /// typically for a @c RecordType. For example, a class template 03732 /// specialization type of @c vector<int> will refer to a tag type for 03733 /// the instantiation @c std::vector<int, std::allocator<int>> 03734 /// 03735 /// Template specializations are dependent if either the template or 03736 /// any of the template arguments are dependent, in which case the 03737 /// type may also be canonical. 03738 /// 03739 /// Instances of this type are allocated with a trailing array of 03740 /// TemplateArguments, followed by a QualType representing the 03741 /// non-canonical aliased type when the template is a type alias 03742 /// template. 03743 class TemplateSpecializationType 03744 : public Type, public llvm::FoldingSetNode { 03745 /// \brief The name of the template being specialized. This is 03746 /// either a TemplateName::Template (in which case it is a 03747 /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a 03748 /// TypeAliasTemplateDecl*), a 03749 /// TemplateName::SubstTemplateTemplateParmPack, or a 03750 /// TemplateName::SubstTemplateTemplateParm (in which case the 03751 /// replacement must, recursively, be one of these). 03752 TemplateName Template; 03753 03754 /// \brief - The number of template arguments named in this class 03755 /// template specialization. 03756 unsigned NumArgs : 31; 03757 03758 /// \brief Whether this template specialization type is a substituted 03759 /// type alias. 03760 bool TypeAlias : 1; 03761 03762 TemplateSpecializationType(TemplateName T, 03763 const TemplateArgument *Args, 03764 unsigned NumArgs, QualType Canon, 03765 QualType Aliased); 03766 03767 friend class ASTContext; // ASTContext creates these 03768 03769 public: 03770 /// \brief Determine whether any of the given template arguments are 03771 /// dependent. 03772 static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args, 03773 unsigned NumArgs, 03774 bool &InstantiationDependent); 03775 03776 static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &, 03777 bool &InstantiationDependent); 03778 03779 /// \brief Print a template argument list, including the '<' and '>' 03780 /// enclosing the template arguments. 03781 static void PrintTemplateArgumentList(raw_ostream &OS, 03782 const TemplateArgument *Args, 03783 unsigned NumArgs, 03784 const PrintingPolicy &Policy, 03785 bool SkipBrackets = false); 03786 03787 static void PrintTemplateArgumentList(raw_ostream &OS, 03788 const TemplateArgumentLoc *Args, 03789 unsigned NumArgs, 03790 const PrintingPolicy &Policy); 03791 03792 static void PrintTemplateArgumentList(raw_ostream &OS, 03793 const TemplateArgumentListInfo &, 03794 const PrintingPolicy &Policy); 03795 03796 /// True if this template specialization type matches a current 03797 /// instantiation in the context in which it is found. 03798 bool isCurrentInstantiation() const { 03799 return isa<InjectedClassNameType>(getCanonicalTypeInternal()); 03800 } 03801 03802 /// \brief Determine if this template specialization type is for a type alias 03803 /// template that has been substituted. 03804 /// 03805 /// Nearly every template specialization type whose template is an alias 03806 /// template will be substituted. However, this is not the case when 03807 /// the specialization contains a pack expansion but the template alias 03808 /// does not have a corresponding parameter pack, e.g., 03809 /// 03810 /// \code 03811 /// template<typename T, typename U, typename V> struct S; 03812 /// template<typename T, typename U> using A = S<T, int, U>; 03813 /// template<typename... Ts> struct X { 03814 /// typedef A<Ts...> type; // not a type alias 03815 /// }; 03816 /// \endcode 03817 bool isTypeAlias() const { return TypeAlias; } 03818 03819 /// Get the aliased type, if this is a specialization of a type alias 03820 /// template. 03821 QualType getAliasedType() const { 03822 assert(isTypeAlias() && "not a type alias template specialization"); 03823 return *reinterpret_cast<const QualType*>(end()); 03824 } 03825 03826 typedef const TemplateArgument * iterator; 03827 03828 iterator begin() const { return getArgs(); } 03829 iterator end() const; // defined inline in TemplateBase.h 03830 03831 /// \brief Retrieve the name of the template that we are specializing. 03832 TemplateName getTemplateName() const { return Template; } 03833 03834 /// \brief Retrieve the template arguments. 03835 const TemplateArgument *getArgs() const { 03836 return reinterpret_cast<const TemplateArgument *>(this + 1); 03837 } 03838 03839 /// \brief Retrieve the number of template arguments. 03840 unsigned getNumArgs() const { return NumArgs; } 03841 03842 /// \brief Retrieve a specific template argument as a type. 03843 /// \pre @c isArgType(Arg) 03844 const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 03845 03846 bool isSugared() const { 03847 return !isDependentType() || isCurrentInstantiation() || isTypeAlias(); 03848 } 03849 QualType desugar() const { return getCanonicalTypeInternal(); } 03850 03851 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) { 03852 Profile(ID, Template, getArgs(), NumArgs, Ctx); 03853 if (isTypeAlias()) 03854 getAliasedType().Profile(ID); 03855 } 03856 03857 static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 03858 const TemplateArgument *Args, 03859 unsigned NumArgs, 03860 const ASTContext &Context); 03861 03862 static bool classof(const Type *T) { 03863 return T->getTypeClass() == TemplateSpecialization; 03864 } 03865 }; 03866 03867 /// \brief The injected class name of a C++ class template or class 03868 /// template partial specialization. Used to record that a type was 03869 /// spelled with a bare identifier rather than as a template-id; the 03870 /// equivalent for non-templated classes is just RecordType. 03871 /// 03872 /// Injected class name types are always dependent. Template 03873 /// instantiation turns these into RecordTypes. 03874 /// 03875 /// Injected class name types are always canonical. This works 03876 /// because it is impossible to compare an injected class name type 03877 /// with the corresponding non-injected template type, for the same 03878 /// reason that it is impossible to directly compare template 03879 /// parameters from different dependent contexts: injected class name 03880 /// types can only occur within the scope of a particular templated 03881 /// declaration, and within that scope every template specialization 03882 /// will canonicalize to the injected class name (when appropriate 03883 /// according to the rules of the language). 03884 class InjectedClassNameType : public Type { 03885 CXXRecordDecl *Decl; 03886 03887 /// The template specialization which this type represents. 03888 /// For example, in 03889 /// template <class T> class A { ... }; 03890 /// this is A<T>, whereas in 03891 /// template <class X, class Y> class A<B<X,Y> > { ... }; 03892 /// this is A<B<X,Y> >. 03893 /// 03894 /// It is always unqualified, always a template specialization type, 03895 /// and always dependent. 03896 QualType InjectedType; 03897 03898 friend class ASTContext; // ASTContext creates these. 03899 friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not 03900 // currently suitable for AST reading, too much 03901 // interdependencies. 03902 InjectedClassNameType(CXXRecordDecl *D, QualType TST) 03903 : Type(InjectedClassName, QualType(), /*Dependent=*/true, 03904 /*InstantiationDependent=*/true, 03905 /*VariablyModified=*/false, 03906 /*ContainsUnexpandedParameterPack=*/false), 03907 Decl(D), InjectedType(TST) { 03908 assert(isa<TemplateSpecializationType>(TST)); 03909 assert(!TST.hasQualifiers()); 03910 assert(TST->isDependentType()); 03911 } 03912 03913 public: 03914 QualType getInjectedSpecializationType() const { return InjectedType; } 03915 const TemplateSpecializationType *getInjectedTST() const { 03916 return cast<TemplateSpecializationType>(InjectedType.getTypePtr()); 03917 } 03918 03919 CXXRecordDecl *getDecl() const; 03920 03921 bool isSugared() const { return false; } 03922 QualType desugar() const { return QualType(this, 0); } 03923 03924 static bool classof(const Type *T) { 03925 return T->getTypeClass() == InjectedClassName; 03926 } 03927 }; 03928 03929 /// \brief The kind of a tag type. 03930 enum TagTypeKind { 03931 /// \brief The "struct" keyword. 03932 TTK_Struct, 03933 /// \brief The "__interface" keyword. 03934 TTK_Interface, 03935 /// \brief The "union" keyword. 03936 TTK_Union, 03937 /// \brief The "class" keyword. 03938 TTK_Class, 03939 /// \brief The "enum" keyword. 03940 TTK_Enum 03941 }; 03942 03943 /// \brief The elaboration keyword that precedes a qualified type name or 03944 /// introduces an elaborated-type-specifier. 03945 enum ElaboratedTypeKeyword { 03946 /// \brief The "struct" keyword introduces the elaborated-type-specifier. 03947 ETK_Struct, 03948 /// \brief The "__interface" keyword introduces the elaborated-type-specifier. 03949 ETK_Interface, 03950 /// \brief The "union" keyword introduces the elaborated-type-specifier. 03951 ETK_Union, 03952 /// \brief The "class" keyword introduces the elaborated-type-specifier. 03953 ETK_Class, 03954 /// \brief The "enum" keyword introduces the elaborated-type-specifier. 03955 ETK_Enum, 03956 /// \brief The "typename" keyword precedes the qualified type name, e.g., 03957 /// \c typename T::type. 03958 ETK_Typename, 03959 /// \brief No keyword precedes the qualified type name. 03960 ETK_None 03961 }; 03962 03963 /// A helper class for Type nodes having an ElaboratedTypeKeyword. 03964 /// The keyword in stored in the free bits of the base class. 03965 /// Also provides a few static helpers for converting and printing 03966 /// elaborated type keyword and tag type kind enumerations. 03967 class TypeWithKeyword : public Type { 03968 protected: 03969 TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, 03970 QualType Canonical, bool Dependent, 03971 bool InstantiationDependent, bool VariablyModified, 03972 bool ContainsUnexpandedParameterPack) 03973 : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified, 03974 ContainsUnexpandedParameterPack) { 03975 TypeWithKeywordBits.Keyword = Keyword; 03976 } 03977 03978 public: 03979 ElaboratedTypeKeyword getKeyword() const { 03980 return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword); 03981 } 03982 03983 /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST) 03984 /// into an elaborated type keyword. 03985 static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec); 03986 03987 /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST) 03988 /// into a tag type kind. It is an error to provide a type specifier 03989 /// which *isn't* a tag kind here. 03990 static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec); 03991 03992 /// getKeywordForTagDeclKind - Converts a TagTypeKind into an 03993 /// elaborated type keyword. 03994 static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag); 03995 03996 /// getTagTypeKindForKeyword - Converts an elaborated type keyword into 03997 // a TagTypeKind. It is an error to provide an elaborated type keyword 03998 /// which *isn't* a tag kind here. 03999 static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword); 04000 04001 static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword); 04002 04003 static StringRef getKeywordName(ElaboratedTypeKeyword Keyword); 04004 04005 static StringRef getTagTypeKindName(TagTypeKind Kind) { 04006 return getKeywordName(getKeywordForTagTypeKind(Kind)); 04007 } 04008 04009 class CannotCastToThisType {}; 04010 static CannotCastToThisType classof(const Type *); 04011 }; 04012 04013 /// \brief Represents a type that was referred to using an elaborated type 04014 /// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type, 04015 /// or both. 04016 /// 04017 /// This type is used to keep track of a type name as written in the 04018 /// source code, including tag keywords and any nested-name-specifiers. 04019 /// The type itself is always "sugar", used to express what was written 04020 /// in the source code but containing no additional semantic information. 04021 class ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode { 04022 04023 /// \brief The nested name specifier containing the qualifier. 04024 NestedNameSpecifier *NNS; 04025 04026 /// \brief The type that this qualified name refers to. 04027 QualType NamedType; 04028 04029 ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 04030 QualType NamedType, QualType CanonType) 04031 : TypeWithKeyword(Keyword, Elaborated, CanonType, 04032 NamedType->isDependentType(), 04033 NamedType->isInstantiationDependentType(), 04034 NamedType->isVariablyModifiedType(), 04035 NamedType->containsUnexpandedParameterPack()), 04036 NNS(NNS), NamedType(NamedType) { 04037 assert(!(Keyword == ETK_None && NNS == nullptr) && 04038 "ElaboratedType cannot have elaborated type keyword " 04039 "and name qualifier both null."); 04040 } 04041 04042 friend class ASTContext; // ASTContext creates these 04043 04044 public: 04045 ~ElaboratedType(); 04046 04047 /// \brief Retrieve the qualification on this type. 04048 NestedNameSpecifier *getQualifier() const { return NNS; } 04049 04050 /// \brief Retrieve the type named by the qualified-id. 04051 QualType getNamedType() const { return NamedType; } 04052 04053 /// \brief Remove a single level of sugar. 04054 QualType desugar() const { return getNamedType(); } 04055 04056 /// \brief Returns whether this type directly provides sugar. 04057 bool isSugared() const { return true; } 04058 04059 void Profile(llvm::FoldingSetNodeID &ID) { 04060 Profile(ID, getKeyword(), NNS, NamedType); 04061 } 04062 04063 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 04064 NestedNameSpecifier *NNS, QualType NamedType) { 04065 ID.AddInteger(Keyword); 04066 ID.AddPointer(NNS); 04067 NamedType.Profile(ID); 04068 } 04069 04070 static bool classof(const Type *T) { 04071 return T->getTypeClass() == Elaborated; 04072 } 04073 }; 04074 04075 /// \brief Represents a qualified type name for which the type name is 04076 /// dependent. 04077 /// 04078 /// DependentNameType represents a class of dependent types that involve a 04079 /// possibly dependent nested-name-specifier (e.g., "T::") followed by a 04080 /// name of a type. The DependentNameType may start with a "typename" (for a 04081 /// typename-specifier), "class", "struct", "union", or "enum" (for a 04082 /// dependent elaborated-type-specifier), or nothing (in contexts where we 04083 /// know that we must be referring to a type, e.g., in a base class specifier). 04084 /// Typically the nested-name-specifier is dependent, but in MSVC compatibility 04085 /// mode, this type is used with non-dependent names to delay name lookup until 04086 /// instantiation. 04087 class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { 04088 04089 /// \brief The nested name specifier containing the qualifier. 04090 NestedNameSpecifier *NNS; 04091 04092 /// \brief The type that this typename specifier refers to. 04093 const IdentifierInfo *Name; 04094 04095 DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 04096 const IdentifierInfo *Name, QualType CanonType) 04097 : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true, 04098 /*InstantiationDependent=*/true, 04099 /*VariablyModified=*/false, 04100 NNS->containsUnexpandedParameterPack()), 04101 NNS(NNS), Name(Name) {} 04102 04103 friend class ASTContext; // ASTContext creates these 04104 04105 public: 04106 /// \brief Retrieve the qualification on this type. 04107 NestedNameSpecifier *getQualifier() const { return NNS; } 04108 04109 /// \brief Retrieve the type named by the typename specifier as an 04110 /// identifier. 04111 /// 04112 /// This routine will return a non-NULL identifier pointer when the 04113 /// form of the original typename was terminated by an identifier, 04114 /// e.g., "typename T::type". 04115 const IdentifierInfo *getIdentifier() const { 04116 return Name; 04117 } 04118 04119 bool isSugared() const { return false; } 04120 QualType desugar() const { return QualType(this, 0); } 04121 04122 void Profile(llvm::FoldingSetNodeID &ID) { 04123 Profile(ID, getKeyword(), NNS, Name); 04124 } 04125 04126 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 04127 NestedNameSpecifier *NNS, const IdentifierInfo *Name) { 04128 ID.AddInteger(Keyword); 04129 ID.AddPointer(NNS); 04130 ID.AddPointer(Name); 04131 } 04132 04133 static bool classof(const Type *T) { 04134 return T->getTypeClass() == DependentName; 04135 } 04136 }; 04137 04138 /// DependentTemplateSpecializationType - Represents a template 04139 /// specialization type whose template cannot be resolved, e.g. 04140 /// A<T>::template B<T> 04141 class DependentTemplateSpecializationType : 04142 public TypeWithKeyword, public llvm::FoldingSetNode { 04143 04144 /// \brief The nested name specifier containing the qualifier. 04145 NestedNameSpecifier *NNS; 04146 04147 /// \brief The identifier of the template. 04148 const IdentifierInfo *Name; 04149 04150 /// \brief - The number of template arguments named in this class 04151 /// template specialization. 04152 unsigned NumArgs; 04153 04154 const TemplateArgument *getArgBuffer() const { 04155 return reinterpret_cast<const TemplateArgument*>(this+1); 04156 } 04157 TemplateArgument *getArgBuffer() { 04158 return reinterpret_cast<TemplateArgument*>(this+1); 04159 } 04160 04161 DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 04162 NestedNameSpecifier *NNS, 04163 const IdentifierInfo *Name, 04164 unsigned NumArgs, 04165 const TemplateArgument *Args, 04166 QualType Canon); 04167 04168 friend class ASTContext; // ASTContext creates these 04169 04170 public: 04171 NestedNameSpecifier *getQualifier() const { return NNS; } 04172 const IdentifierInfo *getIdentifier() const { return Name; } 04173 04174 /// \brief Retrieve the template arguments. 04175 const TemplateArgument *getArgs() const { 04176 return getArgBuffer(); 04177 } 04178 04179 /// \brief Retrieve the number of template arguments. 04180 unsigned getNumArgs() const { return NumArgs; } 04181 04182 const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 04183 04184 typedef const TemplateArgument * iterator; 04185 iterator begin() const { return getArgs(); } 04186 iterator end() const; // inline in TemplateBase.h 04187 04188 bool isSugared() const { return false; } 04189 QualType desugar() const { return QualType(this, 0); } 04190 04191 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) { 04192 Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs()); 04193 } 04194 04195 static void Profile(llvm::FoldingSetNodeID &ID, 04196 const ASTContext &Context, 04197 ElaboratedTypeKeyword Keyword, 04198 NestedNameSpecifier *Qualifier, 04199 const IdentifierInfo *Name, 04200 unsigned NumArgs, 04201 const TemplateArgument *Args); 04202 04203 static bool classof(const Type *T) { 04204 return T->getTypeClass() == DependentTemplateSpecialization; 04205 } 04206 }; 04207 04208 /// \brief Represents a pack expansion of types. 04209 /// 04210 /// Pack expansions are part of C++0x variadic templates. A pack 04211 /// expansion contains a pattern, which itself contains one or more 04212 /// "unexpanded" parameter packs. When instantiated, a pack expansion 04213 /// produces a series of types, each instantiated from the pattern of 04214 /// the expansion, where the Ith instantiation of the pattern uses the 04215 /// Ith arguments bound to each of the unexpanded parameter packs. The 04216 /// pack expansion is considered to "expand" these unexpanded 04217 /// parameter packs. 04218 /// 04219 /// \code 04220 /// template<typename ...Types> struct tuple; 04221 /// 04222 /// template<typename ...Types> 04223 /// struct tuple_of_references { 04224 /// typedef tuple<Types&...> type; 04225 /// }; 04226 /// \endcode 04227 /// 04228 /// Here, the pack expansion \c Types&... is represented via a 04229 /// PackExpansionType whose pattern is Types&. 04230 class PackExpansionType : public Type, public llvm::FoldingSetNode { 04231 /// \brief The pattern of the pack expansion. 04232 QualType Pattern; 04233 04234 /// \brief The number of expansions that this pack expansion will 04235 /// generate when substituted (+1), or indicates that 04236 /// 04237 /// This field will only have a non-zero value when some of the parameter 04238 /// packs that occur within the pattern have been substituted but others have 04239 /// not. 04240 unsigned NumExpansions; 04241 04242 PackExpansionType(QualType Pattern, QualType Canon, 04243 Optional<unsigned> NumExpansions) 04244 : Type(PackExpansion, Canon, /*Dependent=*/Pattern->isDependentType(), 04245 /*InstantiationDependent=*/true, 04246 /*VariablyModified=*/Pattern->isVariablyModifiedType(), 04247 /*ContainsUnexpandedParameterPack=*/false), 04248 Pattern(Pattern), 04249 NumExpansions(NumExpansions? *NumExpansions + 1: 0) { } 04250 04251 friend class ASTContext; // ASTContext creates these 04252 04253 public: 04254 /// \brief Retrieve the pattern of this pack expansion, which is the 04255 /// type that will be repeatedly instantiated when instantiating the 04256 /// pack expansion itself. 04257 QualType getPattern() const { return Pattern; } 04258 04259 /// \brief Retrieve the number of expansions that this pack expansion will 04260 /// generate, if known. 04261 Optional<unsigned> getNumExpansions() const { 04262 if (NumExpansions) 04263 return NumExpansions - 1; 04264 04265 return None; 04266 } 04267 04268 bool isSugared() const { return !Pattern->isDependentType(); } 04269 QualType desugar() const { return isSugared() ? Pattern : QualType(this, 0); } 04270 04271 void Profile(llvm::FoldingSetNodeID &ID) { 04272 Profile(ID, getPattern(), getNumExpansions()); 04273 } 04274 04275 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern, 04276 Optional<unsigned> NumExpansions) { 04277 ID.AddPointer(Pattern.getAsOpaquePtr()); 04278 ID.AddBoolean(NumExpansions.hasValue()); 04279 if (NumExpansions) 04280 ID.AddInteger(*NumExpansions); 04281 } 04282 04283 static bool classof(const Type *T) { 04284 return T->getTypeClass() == PackExpansion; 04285 } 04286 }; 04287 04288 /// ObjCObjectType - Represents a class type in Objective C. 04289 /// Every Objective C type is a combination of a base type and a 04290 /// list of protocols. 04291 /// 04292 /// Given the following declarations: 04293 /// \code 04294 /// \@class C; 04295 /// \@protocol P; 04296 /// \endcode 04297 /// 04298 /// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType 04299 /// with base C and no protocols. 04300 /// 04301 /// 'C<P>' is an ObjCObjectType with base C and protocol list [P]. 04302 /// 04303 /// 'id' is a TypedefType which is sugar for an ObjCObjectPointerType whose 04304 /// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType 04305 /// and no protocols. 04306 /// 04307 /// 'id<P>' is an ObjCObjectPointerType whose pointee is an ObjCObjectType 04308 /// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually 04309 /// this should get its own sugar class to better represent the source. 04310 class ObjCObjectType : public Type { 04311 // ObjCObjectType.NumProtocols - the number of protocols stored 04312 // after the ObjCObjectPointerType node. 04313 // 04314 // These protocols are those written directly on the type. If 04315 // protocol qualifiers ever become additive, the iterators will need 04316 // to get kindof complicated. 04317 // 04318 // In the canonical object type, these are sorted alphabetically 04319 // and uniqued. 04320 04321 /// Either a BuiltinType or an InterfaceType or sugar for either. 04322 QualType BaseType; 04323 04324 ObjCProtocolDecl * const *getProtocolStorage() const { 04325 return const_cast<ObjCObjectType*>(this)->getProtocolStorage(); 04326 } 04327 04328 ObjCProtocolDecl **getProtocolStorage(); 04329 04330 protected: 04331 ObjCObjectType(QualType Canonical, QualType Base, 04332 ObjCProtocolDecl * const *Protocols, unsigned NumProtocols); 04333 04334 enum Nonce_ObjCInterface { Nonce_ObjCInterface }; 04335 ObjCObjectType(enum Nonce_ObjCInterface) 04336 : Type(ObjCInterface, QualType(), false, false, false, false), 04337 BaseType(QualType(this_(), 0)) { 04338 ObjCObjectTypeBits.NumProtocols = 0; 04339 } 04340 04341 public: 04342 /// getBaseType - Gets the base type of this object type. This is 04343 /// always (possibly sugar for) one of: 04344 /// - the 'id' builtin type (as opposed to the 'id' type visible to the 04345 /// user, which is a typedef for an ObjCObjectPointerType) 04346 /// - the 'Class' builtin type (same caveat) 04347 /// - an ObjCObjectType (currently always an ObjCInterfaceType) 04348 QualType getBaseType() const { return BaseType; } 04349 04350 bool isObjCId() const { 04351 return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId); 04352 } 04353 bool isObjCClass() const { 04354 return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass); 04355 } 04356 bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); } 04357 bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); } 04358 bool isObjCUnqualifiedIdOrClass() const { 04359 if (!qual_empty()) return false; 04360 if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>()) 04361 return T->getKind() == BuiltinType::ObjCId || 04362 T->getKind() == BuiltinType::ObjCClass; 04363 return false; 04364 } 04365 bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); } 04366 bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); } 04367 04368 /// Gets the interface declaration for this object type, if the base type 04369 /// really is an interface. 04370 ObjCInterfaceDecl *getInterface() const; 04371 04372 typedef ObjCProtocolDecl * const *qual_iterator; 04373 typedef llvm::iterator_range<qual_iterator> qual_range; 04374 04375 qual_range quals() const { return qual_range(qual_begin(), qual_end()); } 04376 qual_iterator qual_begin() const { return getProtocolStorage(); } 04377 qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); } 04378 04379 bool qual_empty() const { return getNumProtocols() == 0; } 04380 04381 /// getNumProtocols - Return the number of qualifying protocols in this 04382 /// interface type, or 0 if there are none. 04383 unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; } 04384 04385 /// \brief Fetch a protocol by index. 04386 ObjCProtocolDecl *getProtocol(unsigned I) const { 04387 assert(I < getNumProtocols() && "Out-of-range protocol access"); 04388 return qual_begin()[I]; 04389 } 04390 04391 bool isSugared() const { return false; } 04392 QualType desugar() const { return QualType(this, 0); } 04393 04394 static bool classof(const Type *T) { 04395 return T->getTypeClass() == ObjCObject || 04396 T->getTypeClass() == ObjCInterface; 04397 } 04398 }; 04399 04400 /// ObjCObjectTypeImpl - A class providing a concrete implementation 04401 /// of ObjCObjectType, so as to not increase the footprint of 04402 /// ObjCInterfaceType. Code outside of ASTContext and the core type 04403 /// system should not reference this type. 04404 class ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode { 04405 friend class ASTContext; 04406 04407 // If anyone adds fields here, ObjCObjectType::getProtocolStorage() 04408 // will need to be modified. 04409 04410 ObjCObjectTypeImpl(QualType Canonical, QualType Base, 04411 ObjCProtocolDecl * const *Protocols, 04412 unsigned NumProtocols) 04413 : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {} 04414 04415 public: 04416 void Profile(llvm::FoldingSetNodeID &ID); 04417 static void Profile(llvm::FoldingSetNodeID &ID, 04418 QualType Base, 04419 ObjCProtocolDecl *const *protocols, 04420 unsigned NumProtocols); 04421 }; 04422 04423 inline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() { 04424 return reinterpret_cast<ObjCProtocolDecl**>( 04425 static_cast<ObjCObjectTypeImpl*>(this) + 1); 04426 } 04427 04428 /// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 04429 /// object oriented design. They basically correspond to C++ classes. There 04430 /// are two kinds of interface types, normal interfaces like "NSString" and 04431 /// qualified interfaces, which are qualified with a protocol list like 04432 /// "NSString<NSCopyable, NSAmazing>". 04433 /// 04434 /// ObjCInterfaceType guarantees the following properties when considered 04435 /// as a subtype of its superclass, ObjCObjectType: 04436 /// - There are no protocol qualifiers. To reinforce this, code which 04437 /// tries to invoke the protocol methods via an ObjCInterfaceType will 04438 /// fail to compile. 04439 /// - It is its own base type. That is, if T is an ObjCInterfaceType*, 04440 /// T->getBaseType() == QualType(T, 0). 04441 class ObjCInterfaceType : public ObjCObjectType { 04442 mutable ObjCInterfaceDecl *Decl; 04443 04444 ObjCInterfaceType(const ObjCInterfaceDecl *D) 04445 : ObjCObjectType(Nonce_ObjCInterface), 04446 Decl(const_cast<ObjCInterfaceDecl*>(D)) {} 04447 friend class ASTContext; // ASTContext creates these. 04448 friend class ASTReader; 04449 friend class ObjCInterfaceDecl; 04450 04451 public: 04452 /// getDecl - Get the declaration of this interface. 04453 ObjCInterfaceDecl *getDecl() const { return Decl; } 04454 04455 bool isSugared() const { return false; } 04456 QualType desugar() const { return QualType(this, 0); } 04457 04458 static bool classof(const Type *T) { 04459 return T->getTypeClass() == ObjCInterface; 04460 } 04461 04462 // Nonsense to "hide" certain members of ObjCObjectType within this 04463 // class. People asking for protocols on an ObjCInterfaceType are 04464 // not going to get what they want: ObjCInterfaceTypes are 04465 // guaranteed to have no protocols. 04466 enum { 04467 qual_iterator, 04468 qual_begin, 04469 qual_end, 04470 getNumProtocols, 04471 getProtocol 04472 }; 04473 }; 04474 04475 inline ObjCInterfaceDecl *ObjCObjectType::getInterface() const { 04476 if (const ObjCInterfaceType *T = 04477 getBaseType()->getAs<ObjCInterfaceType>()) 04478 return T->getDecl(); 04479 return nullptr; 04480 } 04481 04482 /// ObjCObjectPointerType - Used to represent a pointer to an 04483 /// Objective C object. These are constructed from pointer 04484 /// declarators when the pointee type is an ObjCObjectType (or sugar 04485 /// for one). In addition, the 'id' and 'Class' types are typedefs 04486 /// for these, and the protocol-qualified types 'id<P>' and 'Class<P>' 04487 /// are translated into these. 04488 /// 04489 /// Pointers to pointers to Objective C objects are still PointerTypes; 04490 /// only the first level of pointer gets it own type implementation. 04491 class ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 04492 QualType PointeeType; 04493 04494 ObjCObjectPointerType(QualType Canonical, QualType Pointee) 04495 : Type(ObjCObjectPointer, Canonical, false, false, false, false), 04496 PointeeType(Pointee) {} 04497 friend class ASTContext; // ASTContext creates these. 04498 04499 public: 04500 /// getPointeeType - Gets the type pointed to by this ObjC pointer. 04501 /// The result will always be an ObjCObjectType or sugar thereof. 04502 QualType getPointeeType() const { return PointeeType; } 04503 04504 /// getObjCObjectType - Gets the type pointed to by this ObjC 04505 /// pointer. This method always returns non-null. 04506 /// 04507 /// This method is equivalent to getPointeeType() except that 04508 /// it discards any typedefs (or other sugar) between this 04509 /// type and the "outermost" object type. So for: 04510 /// \code 04511 /// \@class A; \@protocol P; \@protocol Q; 04512 /// typedef A<P> AP; 04513 /// typedef A A1; 04514 /// typedef A1<P> A1P; 04515 /// typedef A1P<Q> A1PQ; 04516 /// \endcode 04517 /// For 'A*', getObjectType() will return 'A'. 04518 /// For 'A<P>*', getObjectType() will return 'A<P>'. 04519 /// For 'AP*', getObjectType() will return 'A<P>'. 04520 /// For 'A1*', getObjectType() will return 'A'. 04521 /// For 'A1<P>*', getObjectType() will return 'A1<P>'. 04522 /// For 'A1P*', getObjectType() will return 'A1<P>'. 04523 /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because 04524 /// adding protocols to a protocol-qualified base discards the 04525 /// old qualifiers (for now). But if it didn't, getObjectType() 04526 /// would return 'A1P<Q>' (and we'd have to make iterating over 04527 /// qualifiers more complicated). 04528 const ObjCObjectType *getObjectType() const { 04529 return PointeeType->castAs<ObjCObjectType>(); 04530 } 04531 04532 /// getInterfaceType - If this pointer points to an Objective C 04533 /// \@interface type, gets the type for that interface. Any protocol 04534 /// qualifiers on the interface are ignored. 04535 /// 04536 /// \return null if the base type for this pointer is 'id' or 'Class' 04537 const ObjCInterfaceType *getInterfaceType() const { 04538 return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>(); 04539 } 04540 04541 /// getInterfaceDecl - If this pointer points to an Objective \@interface 04542 /// type, gets the declaration for that interface. 04543 /// 04544 /// \return null if the base type for this pointer is 'id' or 'Class' 04545 ObjCInterfaceDecl *getInterfaceDecl() const { 04546 return getObjectType()->getInterface(); 04547 } 04548 04549 /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if 04550 /// its object type is the primitive 'id' type with no protocols. 04551 bool isObjCIdType() const { 04552 return getObjectType()->isObjCUnqualifiedId(); 04553 } 04554 04555 /// isObjCClassType - True if this is equivalent to the 'Class' type, 04556 /// i.e. if its object tive is the primitive 'Class' type with no protocols. 04557 bool isObjCClassType() const { 04558 return getObjectType()->isObjCUnqualifiedClass(); 04559 } 04560 04561 /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some 04562 /// non-empty set of protocols. 04563 bool isObjCQualifiedIdType() const { 04564 return getObjectType()->isObjCQualifiedId(); 04565 } 04566 04567 /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for 04568 /// some non-empty set of protocols. 04569 bool isObjCQualifiedClassType() const { 04570 return getObjectType()->isObjCQualifiedClass(); 04571 } 04572 04573 /// An iterator over the qualifiers on the object type. Provided 04574 /// for convenience. This will always iterate over the full set of 04575 /// protocols on a type, not just those provided directly. 04576 typedef ObjCObjectType::qual_iterator qual_iterator; 04577 typedef llvm::iterator_range<qual_iterator> qual_range; 04578 04579 qual_range quals() const { return qual_range(qual_begin(), qual_end()); } 04580 qual_iterator qual_begin() const { 04581 return getObjectType()->qual_begin(); 04582 } 04583 qual_iterator qual_end() const { 04584 return getObjectType()->qual_end(); 04585 } 04586 bool qual_empty() const { return getObjectType()->qual_empty(); } 04587 04588 /// getNumProtocols - Return the number of qualifying protocols on 04589 /// the object type. 04590 unsigned getNumProtocols() const { 04591 return getObjectType()->getNumProtocols(); 04592 } 04593 04594 /// \brief Retrieve a qualifying protocol by index on the object 04595 /// type. 04596 ObjCProtocolDecl *getProtocol(unsigned I) const { 04597 return getObjectType()->getProtocol(I); 04598 } 04599 04600 bool isSugared() const { return false; } 04601 QualType desugar() const { return QualType(this, 0); } 04602 04603 void Profile(llvm::FoldingSetNodeID &ID) { 04604 Profile(ID, getPointeeType()); 04605 } 04606 static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { 04607 ID.AddPointer(T.getAsOpaquePtr()); 04608 } 04609 static bool classof(const Type *T) { 04610 return T->getTypeClass() == ObjCObjectPointer; 04611 } 04612 }; 04613 04614 class AtomicType : public Type, public llvm::FoldingSetNode { 04615 QualType ValueType; 04616 04617 AtomicType(QualType ValTy, QualType Canonical) 04618 : Type(Atomic, Canonical, ValTy->isDependentType(), 04619 ValTy->isInstantiationDependentType(), 04620 ValTy->isVariablyModifiedType(), 04621 ValTy->containsUnexpandedParameterPack()), 04622 ValueType(ValTy) {} 04623 friend class ASTContext; // ASTContext creates these. 04624 04625 public: 04626 /// getValueType - Gets the type contained by this atomic type, i.e. 04627 /// the type returned by performing an atomic load of this atomic type. 04628 QualType getValueType() const { return ValueType; } 04629 04630 bool isSugared() const { return false; } 04631 QualType desugar() const { return QualType(this, 0); } 04632 04633 void Profile(llvm::FoldingSetNodeID &ID) { 04634 Profile(ID, getValueType()); 04635 } 04636 static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { 04637 ID.AddPointer(T.getAsOpaquePtr()); 04638 } 04639 static bool classof(const Type *T) { 04640 return T->getTypeClass() == Atomic; 04641 } 04642 }; 04643 04644 /// A qualifier set is used to build a set of qualifiers. 04645 class QualifierCollector : public Qualifiers { 04646 public: 04647 QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {} 04648 04649 /// Collect any qualifiers on the given type and return an 04650 /// unqualified type. The qualifiers are assumed to be consistent 04651 /// with those already in the type. 04652 const Type *strip(QualType type) { 04653 addFastQualifiers(type.getLocalFastQualifiers()); 04654 if (!type.hasLocalNonFastQualifiers()) 04655 return type.getTypePtrUnsafe(); 04656 04657 const ExtQuals *extQuals = type.getExtQualsUnsafe(); 04658 addConsistentQualifiers(extQuals->getQualifiers()); 04659 return extQuals->getBaseType(); 04660 } 04661 04662 /// Apply the collected qualifiers to the given type. 04663 QualType apply(const ASTContext &Context, QualType QT) const; 04664 04665 /// Apply the collected qualifiers to the given type. 04666 QualType apply(const ASTContext &Context, const Type* T) const; 04667 }; 04668 04669 04670 // Inline function definitions. 04671 04672 inline SplitQualType SplitQualType::getSingleStepDesugaredType() const { 04673 SplitQualType desugar = 04674 Ty->getLocallyUnqualifiedSingleStepDesugaredType().split(); 04675 desugar.Quals.addConsistentQualifiers(Quals); 04676 return desugar; 04677 } 04678 04679 inline const Type *QualType::getTypePtr() const { 04680 return getCommonPtr()->BaseType; 04681 } 04682 04683 inline const Type *QualType::getTypePtrOrNull() const { 04684 return (isNull() ? nullptr : getCommonPtr()->BaseType); 04685 } 04686 04687 inline SplitQualType QualType::split() const { 04688 if (!hasLocalNonFastQualifiers()) 04689 return SplitQualType(getTypePtrUnsafe(), 04690 Qualifiers::fromFastMask(getLocalFastQualifiers())); 04691 04692 const ExtQuals *eq = getExtQualsUnsafe(); 04693 Qualifiers qs = eq->getQualifiers(); 04694 qs.addFastQualifiers(getLocalFastQualifiers()); 04695 return SplitQualType(eq->getBaseType(), qs); 04696 } 04697 04698 inline Qualifiers QualType::getLocalQualifiers() const { 04699 Qualifiers Quals; 04700 if (hasLocalNonFastQualifiers()) 04701 Quals = getExtQualsUnsafe()->getQualifiers(); 04702 Quals.addFastQualifiers(getLocalFastQualifiers()); 04703 return Quals; 04704 } 04705 04706 inline Qualifiers QualType::getQualifiers() const { 04707 Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers(); 04708 quals.addFastQualifiers(getLocalFastQualifiers()); 04709 return quals; 04710 } 04711 04712 inline unsigned QualType::getCVRQualifiers() const { 04713 unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers(); 04714 cvr |= getLocalCVRQualifiers(); 04715 return cvr; 04716 } 04717 04718 inline QualType QualType::getCanonicalType() const { 04719 QualType canon = getCommonPtr()->CanonicalType; 04720 return canon.withFastQualifiers(getLocalFastQualifiers()); 04721 } 04722 04723 inline bool QualType::isCanonical() const { 04724 return getTypePtr()->isCanonicalUnqualified(); 04725 } 04726 04727 inline bool QualType::isCanonicalAsParam() const { 04728 if (!isCanonical()) return false; 04729 if (hasLocalQualifiers()) return false; 04730 04731 const Type *T = getTypePtr(); 04732 if (T->isVariablyModifiedType() && T->hasSizedVLAType()) 04733 return false; 04734 04735 return !isa<FunctionType>(T) && !isa<ArrayType>(T); 04736 } 04737 04738 inline bool QualType::isConstQualified() const { 04739 return isLocalConstQualified() || 04740 getCommonPtr()->CanonicalType.isLocalConstQualified(); 04741 } 04742 04743 inline bool QualType::isRestrictQualified() const { 04744 return isLocalRestrictQualified() || 04745 getCommonPtr()->CanonicalType.isLocalRestrictQualified(); 04746 } 04747 04748 04749 inline bool QualType::isVolatileQualified() const { 04750 return isLocalVolatileQualified() || 04751 getCommonPtr()->CanonicalType.isLocalVolatileQualified(); 04752 } 04753 04754 inline bool QualType::hasQualifiers() const { 04755 return hasLocalQualifiers() || 04756 getCommonPtr()->CanonicalType.hasLocalQualifiers(); 04757 } 04758 04759 inline QualType QualType::getUnqualifiedType() const { 04760 if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) 04761 return QualType(getTypePtr(), 0); 04762 04763 return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0); 04764 } 04765 04766 inline SplitQualType QualType::getSplitUnqualifiedType() const { 04767 if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) 04768 return split(); 04769 04770 return getSplitUnqualifiedTypeImpl(*this); 04771 } 04772 04773 inline void QualType::removeLocalConst() { 04774 removeLocalFastQualifiers(Qualifiers::Const); 04775 } 04776 04777 inline void QualType::removeLocalRestrict() { 04778 removeLocalFastQualifiers(Qualifiers::Restrict); 04779 } 04780 04781 inline void QualType::removeLocalVolatile() { 04782 removeLocalFastQualifiers(Qualifiers::Volatile); 04783 } 04784 04785 inline void QualType::removeLocalCVRQualifiers(unsigned Mask) { 04786 assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits"); 04787 assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask); 04788 04789 // Fast path: we don't need to touch the slow qualifiers. 04790 removeLocalFastQualifiers(Mask); 04791 } 04792 04793 /// getAddressSpace - Return the address space of this type. 04794 inline unsigned QualType::getAddressSpace() const { 04795 return getQualifiers().getAddressSpace(); 04796 } 04797 04798 /// getObjCGCAttr - Return the gc attribute of this type. 04799 inline Qualifiers::GC QualType::getObjCGCAttr() const { 04800 return getQualifiers().getObjCGCAttr(); 04801 } 04802 04803 inline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { 04804 if (const PointerType *PT = t.getAs<PointerType>()) { 04805 if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>()) 04806 return FT->getExtInfo(); 04807 } else if (const FunctionType *FT = t.getAs<FunctionType>()) 04808 return FT->getExtInfo(); 04809 04810 return FunctionType::ExtInfo(); 04811 } 04812 04813 inline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { 04814 return getFunctionExtInfo(*t); 04815 } 04816 04817 /// isMoreQualifiedThan - Determine whether this type is more 04818 /// qualified than the Other type. For example, "const volatile int" 04819 /// is more qualified than "const int", "volatile int", and 04820 /// "int". However, it is not more qualified than "const volatile 04821 /// int". 04822 inline bool QualType::isMoreQualifiedThan(QualType other) const { 04823 Qualifiers myQuals = getQualifiers(); 04824 Qualifiers otherQuals = other.getQualifiers(); 04825 return (myQuals != otherQuals && myQuals.compatiblyIncludes(otherQuals)); 04826 } 04827 04828 /// isAtLeastAsQualifiedAs - Determine whether this type is at last 04829 /// as qualified as the Other type. For example, "const volatile 04830 /// int" is at least as qualified as "const int", "volatile int", 04831 /// "int", and "const volatile int". 04832 inline bool QualType::isAtLeastAsQualifiedAs(QualType other) const { 04833 return getQualifiers().compatiblyIncludes(other.getQualifiers()); 04834 } 04835 04836 /// getNonReferenceType - If Type is a reference type (e.g., const 04837 /// int&), returns the type that the reference refers to ("const 04838 /// int"). Otherwise, returns the type itself. This routine is used 04839 /// throughout Sema to implement C++ 5p6: 04840 /// 04841 /// If an expression initially has the type "reference to T" (8.3.2, 04842 /// 8.5.3), the type is adjusted to "T" prior to any further 04843 /// analysis, the expression designates the object or function 04844 /// denoted by the reference, and the expression is an lvalue. 04845 inline QualType QualType::getNonReferenceType() const { 04846 if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 04847 return RefType->getPointeeType(); 04848 else 04849 return *this; 04850 } 04851 04852 inline bool QualType::isCForbiddenLValueType() const { 04853 return ((getTypePtr()->isVoidType() && !hasQualifiers()) || 04854 getTypePtr()->isFunctionType()); 04855 } 04856 04857 /// \brief Tests whether the type is categorized as a fundamental type. 04858 /// 04859 /// \returns True for types specified in C++0x [basic.fundamental]. 04860 inline bool Type::isFundamentalType() const { 04861 return isVoidType() || 04862 // FIXME: It's really annoying that we don't have an 04863 // 'isArithmeticType()' which agrees with the standard definition. 04864 (isArithmeticType() && !isEnumeralType()); 04865 } 04866 04867 /// \brief Tests whether the type is categorized as a compound type. 04868 /// 04869 /// \returns True for types specified in C++0x [basic.compound]. 04870 inline bool Type::isCompoundType() const { 04871 // C++0x [basic.compound]p1: 04872 // Compound types can be constructed in the following ways: 04873 // -- arrays of objects of a given type [...]; 04874 return isArrayType() || 04875 // -- functions, which have parameters of given types [...]; 04876 isFunctionType() || 04877 // -- pointers to void or objects or functions [...]; 04878 isPointerType() || 04879 // -- references to objects or functions of a given type. [...] 04880 isReferenceType() || 04881 // -- classes containing a sequence of objects of various types, [...]; 04882 isRecordType() || 04883 // -- unions, which are classes capable of containing objects of different 04884 // types at different times; 04885 isUnionType() || 04886 // -- enumerations, which comprise a set of named constant values. [...]; 04887 isEnumeralType() || 04888 // -- pointers to non-static class members, [...]. 04889 isMemberPointerType(); 04890 } 04891 04892 inline bool Type::isFunctionType() const { 04893 return isa<FunctionType>(CanonicalType); 04894 } 04895 inline bool Type::isPointerType() const { 04896 return isa<PointerType>(CanonicalType); 04897 } 04898 inline bool Type::isAnyPointerType() const { 04899 return isPointerType() || isObjCObjectPointerType(); 04900 } 04901 inline bool Type::isBlockPointerType() const { 04902 return isa<BlockPointerType>(CanonicalType); 04903 } 04904 inline bool Type::isReferenceType() const { 04905 return isa<ReferenceType>(CanonicalType); 04906 } 04907 inline bool Type::isLValueReferenceType() const { 04908 return isa<LValueReferenceType>(CanonicalType); 04909 } 04910 inline bool Type::isRValueReferenceType() const { 04911 return isa<RValueReferenceType>(CanonicalType); 04912 } 04913 inline bool Type::isFunctionPointerType() const { 04914 if (const PointerType *T = getAs<PointerType>()) 04915 return T->getPointeeType()->isFunctionType(); 04916 else 04917 return false; 04918 } 04919 inline bool Type::isMemberPointerType() const { 04920 return isa<MemberPointerType>(CanonicalType); 04921 } 04922 inline bool Type::isMemberFunctionPointerType() const { 04923 if (const MemberPointerType* T = getAs<MemberPointerType>()) 04924 return T->isMemberFunctionPointer(); 04925 else 04926 return false; 04927 } 04928 inline bool Type::isMemberDataPointerType() const { 04929 if (const MemberPointerType* T = getAs<MemberPointerType>()) 04930 return T->isMemberDataPointer(); 04931 else 04932 return false; 04933 } 04934 inline bool Type::isArrayType() const { 04935 return isa<ArrayType>(CanonicalType); 04936 } 04937 inline bool Type::isConstantArrayType() const { 04938 return isa<ConstantArrayType>(CanonicalType); 04939 } 04940 inline bool Type::isIncompleteArrayType() const { 04941 return isa<IncompleteArrayType>(CanonicalType); 04942 } 04943 inline bool Type::isVariableArrayType() const { 04944 return isa<VariableArrayType>(CanonicalType); 04945 } 04946 inline bool Type::isDependentSizedArrayType() const { 04947 return isa<DependentSizedArrayType>(CanonicalType); 04948 } 04949 inline bool Type::isBuiltinType() const { 04950 return isa<BuiltinType>(CanonicalType); 04951 } 04952 inline bool Type::isRecordType() const { 04953 return isa<RecordType>(CanonicalType); 04954 } 04955 inline bool Type::isEnumeralType() const { 04956 return isa<EnumType>(CanonicalType); 04957 } 04958 inline bool Type::isAnyComplexType() const { 04959 return isa<ComplexType>(CanonicalType); 04960 } 04961 inline bool Type::isVectorType() const { 04962 return isa<VectorType>(CanonicalType); 04963 } 04964 inline bool Type::isExtVectorType() const { 04965 return isa<ExtVectorType>(CanonicalType); 04966 } 04967 inline bool Type::isObjCObjectPointerType() const { 04968 return isa<ObjCObjectPointerType>(CanonicalType); 04969 } 04970 inline bool Type::isObjCObjectType() const { 04971 return isa<ObjCObjectType>(CanonicalType); 04972 } 04973 inline bool Type::isObjCObjectOrInterfaceType() const { 04974 return isa<ObjCInterfaceType>(CanonicalType) || 04975 isa<ObjCObjectType>(CanonicalType); 04976 } 04977 inline bool Type::isAtomicType() const { 04978 return isa<AtomicType>(CanonicalType); 04979 } 04980 04981 inline bool Type::isObjCQualifiedIdType() const { 04982 if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 04983 return OPT->isObjCQualifiedIdType(); 04984 return false; 04985 } 04986 inline bool Type::isObjCQualifiedClassType() const { 04987 if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 04988 return OPT->isObjCQualifiedClassType(); 04989 return false; 04990 } 04991 inline bool Type::isObjCIdType() const { 04992 if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 04993 return OPT->isObjCIdType(); 04994 return false; 04995 } 04996 inline bool Type::isObjCClassType() const { 04997 if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 04998 return OPT->isObjCClassType(); 04999 return false; 05000 } 05001 inline bool Type::isObjCSelType() const { 05002 if (const PointerType *OPT = getAs<PointerType>()) 05003 return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); 05004 return false; 05005 } 05006 inline bool Type::isObjCBuiltinType() const { 05007 return isObjCIdType() || isObjCClassType() || isObjCSelType(); 05008 } 05009 05010 inline bool Type::isImage1dT() const { 05011 return isSpecificBuiltinType(BuiltinType::OCLImage1d); 05012 } 05013 05014 inline bool Type::isImage1dArrayT() const { 05015 return isSpecificBuiltinType(BuiltinType::OCLImage1dArray); 05016 } 05017 05018 inline bool Type::isImage1dBufferT() const { 05019 return isSpecificBuiltinType(BuiltinType::OCLImage1dBuffer); 05020 } 05021 05022 inline bool Type::isImage2dT() const { 05023 return isSpecificBuiltinType(BuiltinType::OCLImage2d); 05024 } 05025 05026 inline bool Type::isImage2dArrayT() const { 05027 return isSpecificBuiltinType(BuiltinType::OCLImage2dArray); 05028 } 05029 05030 inline bool Type::isImage3dT() const { 05031 return isSpecificBuiltinType(BuiltinType::OCLImage3d); 05032 } 05033 05034 inline bool Type::isSamplerT() const { 05035 return isSpecificBuiltinType(BuiltinType::OCLSampler); 05036 } 05037 05038 inline bool Type::isEventT() const { 05039 return isSpecificBuiltinType(BuiltinType::OCLEvent); 05040 } 05041 05042 inline bool Type::isImageType() const { 05043 return isImage3dT() || 05044 isImage2dT() || isImage2dArrayT() || 05045 isImage1dT() || isImage1dArrayT() || isImage1dBufferT(); 05046 } 05047 05048 inline bool Type::isOpenCLSpecificType() const { 05049 return isSamplerT() || isEventT() || isImageType(); 05050 } 05051 05052 inline bool Type::isTemplateTypeParmType() const { 05053 return isa<TemplateTypeParmType>(CanonicalType); 05054 } 05055 05056 inline bool Type::isSpecificBuiltinType(unsigned K) const { 05057 if (const BuiltinType *BT = getAs<BuiltinType>()) 05058 if (BT->getKind() == (BuiltinType::Kind) K) 05059 return true; 05060 return false; 05061 } 05062 05063 inline bool Type::isPlaceholderType() const { 05064 if (const BuiltinType *BT = dyn_cast<BuiltinType>(this)) 05065 return BT->isPlaceholderType(); 05066 return false; 05067 } 05068 05069 inline const BuiltinType *Type::getAsPlaceholderType() const { 05070 if (const BuiltinType *BT = dyn_cast<BuiltinType>(this)) 05071 if (BT->isPlaceholderType()) 05072 return BT; 05073 return nullptr; 05074 } 05075 05076 inline bool Type::isSpecificPlaceholderType(unsigned K) const { 05077 assert(BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K)); 05078 if (const BuiltinType *BT = dyn_cast<BuiltinType>(this)) 05079 return (BT->getKind() == (BuiltinType::Kind) K); 05080 return false; 05081 } 05082 05083 inline bool Type::isNonOverloadPlaceholderType() const { 05084 if (const BuiltinType *BT = dyn_cast<BuiltinType>(this)) 05085 return BT->isNonOverloadPlaceholderType(); 05086 return false; 05087 } 05088 05089 inline bool Type::isVoidType() const { 05090 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 05091 return BT->getKind() == BuiltinType::Void; 05092 return false; 05093 } 05094 05095 inline bool Type::isHalfType() const { 05096 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 05097 return BT->getKind() == BuiltinType::Half; 05098 // FIXME: Should we allow complex __fp16? Probably not. 05099 return false; 05100 } 05101 05102 inline bool Type::isNullPtrType() const { 05103 if (const BuiltinType *BT = getAs<BuiltinType>()) 05104 return BT->getKind() == BuiltinType::NullPtr; 05105 return false; 05106 } 05107 05108 extern bool IsEnumDeclComplete(EnumDecl *); 05109 extern bool IsEnumDeclScoped(EnumDecl *); 05110 05111 inline bool Type::isIntegerType() const { 05112 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 05113 return BT->getKind() >= BuiltinType::Bool && 05114 BT->getKind() <= BuiltinType::Int128; 05115 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 05116 // Incomplete enum types are not treated as integer types. 05117 // FIXME: In C++, enum types are never integer types. 05118 return IsEnumDeclComplete(ET->getDecl()) && 05119 !IsEnumDeclScoped(ET->getDecl()); 05120 } 05121 return false; 05122 } 05123 05124 inline bool Type::isScalarType() const { 05125 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 05126 return BT->getKind() > BuiltinType::Void && 05127 BT->getKind() <= BuiltinType::NullPtr; 05128 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 05129 // Enums are scalar types, but only if they are defined. Incomplete enums 05130 // are not treated as scalar types. 05131 return IsEnumDeclComplete(ET->getDecl()); 05132 return isa<PointerType>(CanonicalType) || 05133 isa<BlockPointerType>(CanonicalType) || 05134 isa<MemberPointerType>(CanonicalType) || 05135 isa<ComplexType>(CanonicalType) || 05136 isa<ObjCObjectPointerType>(CanonicalType); 05137 } 05138 05139 inline bool Type::isIntegralOrEnumerationType() const { 05140 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 05141 return BT->getKind() >= BuiltinType::Bool && 05142 BT->getKind() <= BuiltinType::Int128; 05143 05144 // Check for a complete enum type; incomplete enum types are not properly an 05145 // enumeration type in the sense required here. 05146 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 05147 return IsEnumDeclComplete(ET->getDecl()); 05148 05149 return false; 05150 } 05151 05152 inline bool Type::isBooleanType() const { 05153 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 05154 return BT->getKind() == BuiltinType::Bool; 05155 return false; 05156 } 05157 05158 inline bool Type::isUndeducedType() const { 05159 const AutoType *AT = getContainedAutoType(); 05160 return AT && !AT->isDeduced(); 05161 } 05162 05163 /// \brief Determines whether this is a type for which one can define 05164 /// an overloaded operator. 05165 inline bool Type::isOverloadableType() const { 05166 return isDependentType() || isRecordType() || isEnumeralType(); 05167 } 05168 05169 /// \brief Determines whether this type can decay to a pointer type. 05170 inline bool Type::canDecayToPointerType() const { 05171 return isFunctionType() || isArrayType(); 05172 } 05173 05174 inline bool Type::hasPointerRepresentation() const { 05175 return (isPointerType() || isReferenceType() || isBlockPointerType() || 05176 isObjCObjectPointerType() || isNullPtrType()); 05177 } 05178 05179 inline bool Type::hasObjCPointerRepresentation() const { 05180 return isObjCObjectPointerType(); 05181 } 05182 05183 inline const Type *Type::getBaseElementTypeUnsafe() const { 05184 const Type *type = this; 05185 while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe()) 05186 type = arrayType->getElementType().getTypePtr(); 05187 return type; 05188 } 05189 05190 /// Insertion operator for diagnostics. This allows sending QualType's into a 05191 /// diagnostic with <<. 05192 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 05193 QualType T) { 05194 DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 05195 DiagnosticsEngine::ak_qualtype); 05196 return DB; 05197 } 05198 05199 /// Insertion operator for partial diagnostics. This allows sending QualType's 05200 /// into a diagnostic with <<. 05201 inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, 05202 QualType T) { 05203 PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 05204 DiagnosticsEngine::ak_qualtype); 05205 return PD; 05206 } 05207 05208 // Helper class template that is used by Type::getAs to ensure that one does 05209 // not try to look through a qualified type to get to an array type. 05210 template <typename T, bool isArrayType = (std::is_same<T, ArrayType>::value || 05211 std::is_base_of<ArrayType, T>::value)> 05212 struct ArrayType_cannot_be_used_with_getAs {}; 05213 05214 template<typename T> 05215 struct ArrayType_cannot_be_used_with_getAs<T, true>; 05216 05217 // Member-template getAs<specific type>'. 05218 template <typename T> const T *Type::getAs() const { 05219 ArrayType_cannot_be_used_with_getAs<T> at; 05220 (void)at; 05221 05222 // If this is directly a T type, return it. 05223 if (const T *Ty = dyn_cast<T>(this)) 05224 return Ty; 05225 05226 // If the canonical form of this type isn't the right kind, reject it. 05227 if (!isa<T>(CanonicalType)) 05228 return nullptr; 05229 05230 // If this is a typedef for the type, strip the typedef off without 05231 // losing all typedef information. 05232 return cast<T>(getUnqualifiedDesugaredType()); 05233 } 05234 05235 inline const ArrayType *Type::getAsArrayTypeUnsafe() const { 05236 // If this is directly an array type, return it. 05237 if (const ArrayType *arr = dyn_cast<ArrayType>(this)) 05238 return arr; 05239 05240 // If the canonical form of this type isn't the right kind, reject it. 05241 if (!isa<ArrayType>(CanonicalType)) 05242 return nullptr; 05243 05244 // If this is a typedef for the type, strip the typedef off without 05245 // losing all typedef information. 05246 return cast<ArrayType>(getUnqualifiedDesugaredType()); 05247 } 05248 05249 template <typename T> const T *Type::castAs() const { 05250 ArrayType_cannot_be_used_with_getAs<T> at; 05251 (void) at; 05252 05253 if (const T *ty = dyn_cast<T>(this)) return ty; 05254 assert(isa<T>(CanonicalType)); 05255 return cast<T>(getUnqualifiedDesugaredType()); 05256 } 05257 05258 inline const ArrayType *Type::castAsArrayTypeUnsafe() const { 05259 assert(isa<ArrayType>(CanonicalType)); 05260 if (const ArrayType *arr = dyn_cast<ArrayType>(this)) return arr; 05261 return cast<ArrayType>(getUnqualifiedDesugaredType()); 05262 } 05263 05264 } // end namespace clang 05265 05266 #endif