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