1 //===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the Type interface and subclasses.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_TYPE_H
15 #define LLVM_CLANG_AST_TYPE_H
17 #include "clang/Basic/Diagnostic.h"
18 #include "clang/Basic/ExceptionSpecificationType.h"
19 #include "clang/Basic/IdentifierTable.h"
20 #include "clang/Basic/Linkage.h"
21 #include "clang/Basic/PartialDiagnostic.h"
22 #include "clang/Basic/Visibility.h"
23 #include "clang/AST/NestedNameSpecifier.h"
24 #include "clang/AST/TemplateName.h"
25 #include "llvm/Support/type_traits.h"
26 #include "llvm/Support/ErrorHandling.h"
27 #include "llvm/ADT/APSInt.h"
28 #include "llvm/ADT/FoldingSet.h"
29 #include "llvm/ADT/Optional.h"
30 #include "llvm/ADT/PointerIntPair.h"
31 #include "llvm/ADT/PointerUnion.h"
32 #include "clang/Basic/LLVM.h"
36 TypeAlignmentInBits = 4,
37 TypeAlignment = 1 << TypeAlignmentInBits
46 class PointerLikeTypeTraits;
48 class PointerLikeTypeTraits< ::clang::Type*> {
50 static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
51 static inline ::clang::Type *getFromVoidPointer(void *P) {
52 return static_cast< ::clang::Type*>(P);
54 enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
57 class PointerLikeTypeTraits< ::clang::ExtQuals*> {
59 static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
60 static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
61 return static_cast< ::clang::ExtQuals*>(P);
63 enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
67 struct isPodLike<clang::QualType> { static const bool value = true; };
72 class TypedefNameDecl;
74 class TemplateTypeParmDecl;
75 class NonTypeTemplateParmDecl;
76 class TemplateTemplateParmDecl;
83 class ObjCInterfaceDecl;
84 class ObjCProtocolDecl;
86 class UnresolvedUsingTypenameDecl;
90 class StmtIteratorBase;
91 class TemplateArgument;
92 class TemplateArgumentLoc;
93 class TemplateArgumentListInfo;
96 class ExtQualsTypeCommonBase;
97 struct PrintingPolicy;
99 template <typename> class CanQual;
100 typedef CanQual<Type> CanQualType;
102 // Provide forward declarations for all of the *Type classes
103 #define TYPE(Class, Base) class Class##Type;
104 #include "clang/AST/TypeNodes.def"
106 /// Qualifiers - The collection of all-type qualifiers we support.
107 /// Clang supports five independent qualifiers:
108 /// * C99: const, volatile, and restrict
109 /// * Embedded C (TR18037): address spaces
110 /// * Objective C: the GC attributes (none, weak, or strong)
113 enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
117 CVRMask = Const | Volatile | Restrict
127 /// There is no lifetime qualification on this type.
130 /// This object can be modified without requiring retains or
134 /// Assigning into this object requires the old value to be
135 /// released and the new value to be retained. The timing of the
136 /// release of the old value is inexact: it may be moved to
137 /// immediately after the last known point where the value is
141 /// Reading or writing from this object requires a barrier call.
144 /// Assigning into this object requires a lifetime extension.
149 /// The maximum supported address space number.
150 /// 24 bits should be enough for anyone.
151 MaxAddressSpace = 0xffffffu,
153 /// The width of the "fast" qualifier mask.
156 /// The fast qualifier mask.
157 FastMask = (1 << FastWidth) - 1
160 Qualifiers() : Mask(0) {}
162 static Qualifiers fromFastMask(unsigned Mask) {
164 Qs.addFastQualifiers(Mask);
168 static Qualifiers fromCVRMask(unsigned CVR) {
170 Qs.addCVRQualifiers(CVR);
174 // Deserialize qualifiers from an opaque representation.
175 static Qualifiers fromOpaqueValue(unsigned opaque) {
181 // Serialize these qualifiers into an opaque representation.
182 unsigned getAsOpaqueValue() const {
186 bool hasConst() const { return Mask & Const; }
187 void setConst(bool flag) {
188 Mask = (Mask & ~Const) | (flag ? Const : 0);
190 void removeConst() { Mask &= ~Const; }
191 void addConst() { Mask |= Const; }
193 bool hasVolatile() const { return Mask & Volatile; }
194 void setVolatile(bool flag) {
195 Mask = (Mask & ~Volatile) | (flag ? Volatile : 0);
197 void removeVolatile() { Mask &= ~Volatile; }
198 void addVolatile() { Mask |= Volatile; }
200 bool hasRestrict() const { return Mask & Restrict; }
201 void setRestrict(bool flag) {
202 Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
204 void removeRestrict() { Mask &= ~Restrict; }
205 void addRestrict() { Mask |= Restrict; }
207 bool hasCVRQualifiers() const { return getCVRQualifiers(); }
208 unsigned getCVRQualifiers() const { return Mask & CVRMask; }
209 void setCVRQualifiers(unsigned mask) {
210 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
211 Mask = (Mask & ~CVRMask) | mask;
213 void removeCVRQualifiers(unsigned mask) {
214 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
217 void removeCVRQualifiers() {
218 removeCVRQualifiers(CVRMask);
220 void addCVRQualifiers(unsigned mask) {
221 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
225 bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
226 GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
227 void setObjCGCAttr(GC type) {
228 Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
230 void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
231 void addObjCGCAttr(GC type) {
235 Qualifiers withoutObjCGCAttr() const {
236 Qualifiers qs = *this;
237 qs.removeObjCGCAttr();
240 Qualifiers withoutObjCLifetime() const {
241 Qualifiers qs = *this;
242 qs.removeObjCLifetime();
246 bool hasObjCLifetime() const { return Mask & LifetimeMask; }
247 ObjCLifetime getObjCLifetime() const {
248 return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
250 void setObjCLifetime(ObjCLifetime type) {
251 Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
253 void removeObjCLifetime() { setObjCLifetime(OCL_None); }
254 void addObjCLifetime(ObjCLifetime type) {
256 assert(!hasObjCLifetime());
257 Mask |= (type << LifetimeShift);
260 /// True if the lifetime is neither None or ExplicitNone.
261 bool hasNonTrivialObjCLifetime() const {
262 ObjCLifetime lifetime = getObjCLifetime();
263 return (lifetime > OCL_ExplicitNone);
266 /// True if the lifetime is either strong or weak.
267 bool hasStrongOrWeakObjCLifetime() const {
268 ObjCLifetime lifetime = getObjCLifetime();
269 return (lifetime == OCL_Strong || lifetime == OCL_Weak);
272 bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
273 unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }
274 void setAddressSpace(unsigned space) {
275 assert(space <= MaxAddressSpace);
276 Mask = (Mask & ~AddressSpaceMask)
277 | (((uint32_t) space) << AddressSpaceShift);
279 void removeAddressSpace() { setAddressSpace(0); }
280 void addAddressSpace(unsigned space) {
282 setAddressSpace(space);
285 // Fast qualifiers are those that can be allocated directly
286 // on a QualType object.
287 bool hasFastQualifiers() const { return getFastQualifiers(); }
288 unsigned getFastQualifiers() const { return Mask & FastMask; }
289 void setFastQualifiers(unsigned mask) {
290 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
291 Mask = (Mask & ~FastMask) | mask;
293 void removeFastQualifiers(unsigned mask) {
294 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
297 void removeFastQualifiers() {
298 removeFastQualifiers(FastMask);
300 void addFastQualifiers(unsigned mask) {
301 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
305 /// hasNonFastQualifiers - Return true if the set contains any
306 /// qualifiers which require an ExtQuals node to be allocated.
307 bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
308 Qualifiers getNonFastQualifiers() const {
309 Qualifiers Quals = *this;
310 Quals.setFastQualifiers(0);
314 /// hasQualifiers - Return true if the set contains any qualifiers.
315 bool hasQualifiers() const { return Mask; }
316 bool empty() const { return !Mask; }
318 /// \brief Add the qualifiers from the given set to this set.
319 void addQualifiers(Qualifiers Q) {
320 // If the other set doesn't have any non-boolean qualifiers, just
322 if (!(Q.Mask & ~CVRMask))
325 Mask |= (Q.Mask & CVRMask);
326 if (Q.hasAddressSpace())
327 addAddressSpace(Q.getAddressSpace());
328 if (Q.hasObjCGCAttr())
329 addObjCGCAttr(Q.getObjCGCAttr());
330 if (Q.hasObjCLifetime())
331 addObjCLifetime(Q.getObjCLifetime());
335 /// \brief Add the qualifiers from the given set to this set, given that
336 /// they don't conflict.
337 void addConsistentQualifiers(Qualifiers qs) {
338 assert(getAddressSpace() == qs.getAddressSpace() ||
339 !hasAddressSpace() || !qs.hasAddressSpace());
340 assert(getObjCGCAttr() == qs.getObjCGCAttr() ||
341 !hasObjCGCAttr() || !qs.hasObjCGCAttr());
342 assert(getObjCLifetime() == qs.getObjCLifetime() ||
343 !hasObjCLifetime() || !qs.hasObjCLifetime());
347 /// \brief Determines if these qualifiers compatibly include another set.
348 /// Generally this answers the question of whether an object with the other
349 /// qualifiers can be safely used as an object with these qualifiers.
350 bool compatiblyIncludes(Qualifiers other) const {
352 // Address spaces must match exactly.
353 getAddressSpace() == other.getAddressSpace() &&
354 // ObjC GC qualifiers can match, be added, or be removed, but can't be
356 (getObjCGCAttr() == other.getObjCGCAttr() ||
357 !hasObjCGCAttr() || !other.hasObjCGCAttr()) &&
358 // ObjC lifetime qualifiers must match exactly.
359 getObjCLifetime() == other.getObjCLifetime() &&
360 // CVR qualifiers may subset.
361 (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask));
364 /// \brief Determines if these qualifiers compatibly include another set of
365 /// qualifiers from the narrow perspective of Objective-C ARC lifetime.
367 /// One set of Objective-C lifetime qualifiers compatibly includes the other
368 /// if the lifetime qualifiers match, or if both are non-__weak and the
369 /// including set also contains the 'const' qualifier.
370 bool compatiblyIncludesObjCLifetime(Qualifiers other) const {
371 if (getObjCLifetime() == other.getObjCLifetime())
374 if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak)
380 bool isSupersetOf(Qualifiers Other) const;
382 /// \brief Determine whether this set of qualifiers is a strict superset of
383 /// another set of qualifiers, not considering qualifier compatibility.
384 bool isStrictSupersetOf(Qualifiers Other) const;
386 bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
387 bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
389 operator bool() const { return hasQualifiers(); }
391 Qualifiers &operator+=(Qualifiers R) {
396 // Union two qualifier sets. If an enumerated qualifier appears
397 // in both sets, use the one from the right.
398 friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
403 Qualifiers &operator-=(Qualifiers R) {
404 Mask = Mask & ~(R.Mask);
408 /// \brief Compute the difference between two qualifier sets.
409 friend Qualifiers operator-(Qualifiers L, Qualifiers R) {
414 std::string getAsString() const;
415 std::string getAsString(const PrintingPolicy &Policy) const {
417 getAsStringInternal(Buffer, Policy);
420 void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const;
422 void Profile(llvm::FoldingSetNodeID &ID) const {
428 // bits: |0 1 2|3 .. 4|5 .. 7|8 ... 31|
429 // |C R V|GCAttr|Lifetime|AddressSpace|
432 static const uint32_t GCAttrMask = 0x18;
433 static const uint32_t GCAttrShift = 3;
434 static const uint32_t LifetimeMask = 0xE0;
435 static const uint32_t LifetimeShift = 5;
436 static const uint32_t AddressSpaceMask = ~(CVRMask|GCAttrMask|LifetimeMask);
437 static const uint32_t AddressSpaceShift = 8;
440 /// CallingConv - Specifies the calling convention that a function uses.
443 CC_C, // __attribute__((cdecl))
444 CC_X86StdCall, // __attribute__((stdcall))
445 CC_X86FastCall, // __attribute__((fastcall))
446 CC_X86ThisCall, // __attribute__((thiscall))
447 CC_X86Pascal, // __attribute__((pascal))
448 CC_AAPCS, // __attribute__((pcs("aapcs")))
449 CC_AAPCS_VFP // __attribute__((pcs("aapcs-vfp")))
452 /// A std::pair-like structure for storing a qualified type split
453 /// into its local qualifiers and its locally-unqualified type.
454 struct SplitQualType {
455 /// The locally-unqualified type.
458 /// The local qualifiers.
461 SplitQualType() : Ty(0), Quals() {}
462 SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {}
464 SplitQualType getSingleStepDesugaredType() const; // end of this file
466 // Make llvm::tie work.
467 operator std::pair<const Type *,Qualifiers>() const {
468 return std::pair<const Type *,Qualifiers>(Ty, Quals);
471 friend bool operator==(SplitQualType a, SplitQualType b) {
472 return a.Ty == b.Ty && a.Quals == b.Quals;
474 friend bool operator!=(SplitQualType a, SplitQualType b) {
475 return a.Ty != b.Ty || a.Quals != b.Quals;
479 /// QualType - For efficiency, we don't store CV-qualified types as nodes on
480 /// their own: instead each reference to a type stores the qualifiers. This
481 /// greatly reduces the number of nodes we need to allocate for types (for
482 /// example we only need one for 'int', 'const int', 'volatile int',
483 /// 'const volatile int', etc).
485 /// As an added efficiency bonus, instead of making this a pair, we
486 /// just store the two bits we care about in the low bits of the
487 /// pointer. To handle the packing/unpacking, we make QualType be a
488 /// simple wrapper class that acts like a smart pointer. A third bit
489 /// indicates whether there are extended qualifiers present, in which
490 /// case the pointer points to a special structure.
492 // Thankfully, these are efficiently composable.
493 llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>,
494 Qualifiers::FastWidth> Value;
496 const ExtQuals *getExtQualsUnsafe() const {
497 return Value.getPointer().get<const ExtQuals*>();
500 const Type *getTypePtrUnsafe() const {
501 return Value.getPointer().get<const Type*>();
504 const ExtQualsTypeCommonBase *getCommonPtr() const {
505 assert(!isNull() && "Cannot retrieve a NULL type pointer");
506 uintptr_t CommonPtrVal
507 = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
508 CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
509 return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
512 friend class QualifierCollector;
516 QualType(const Type *Ptr, unsigned Quals)
517 : Value(Ptr, Quals) {}
518 QualType(const ExtQuals *Ptr, unsigned Quals)
519 : Value(Ptr, Quals) {}
521 unsigned getLocalFastQualifiers() const { return Value.getInt(); }
522 void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
524 /// Retrieves a pointer to the underlying (unqualified) type.
525 /// This should really return a const Type, but it's not worth
526 /// changing all the users right now.
528 /// This function requires that the type not be NULL. If the type might be
529 /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
530 const Type *getTypePtr() const;
532 const Type *getTypePtrOrNull() const;
534 /// Retrieves a pointer to the name of the base type.
535 const IdentifierInfo *getBaseTypeIdentifier() const;
537 /// Divides a QualType into its unqualified type and a set of local
539 SplitQualType split() const;
541 void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
542 static QualType getFromOpaquePtr(const void *Ptr) {
544 T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
548 const Type &operator*() const {
549 return *getTypePtr();
552 const Type *operator->() const {
556 bool isCanonical() const;
557 bool isCanonicalAsParam() const;
559 /// isNull - Return true if this QualType doesn't point to a type yet.
560 bool isNull() const {
561 return Value.getPointer().isNull();
564 /// \brief Determine whether this particular QualType instance has the
565 /// "const" qualifier set, without looking through typedefs that may have
566 /// added "const" at a different level.
567 bool isLocalConstQualified() const {
568 return (getLocalFastQualifiers() & Qualifiers::Const);
571 /// \brief Determine whether this type is const-qualified.
572 bool isConstQualified() const;
574 /// \brief Determine whether this particular QualType instance has the
575 /// "restrict" qualifier set, without looking through typedefs that may have
576 /// added "restrict" at a different level.
577 bool isLocalRestrictQualified() const {
578 return (getLocalFastQualifiers() & Qualifiers::Restrict);
581 /// \brief Determine whether this type is restrict-qualified.
582 bool isRestrictQualified() const;
584 /// \brief Determine whether this particular QualType instance has the
585 /// "volatile" qualifier set, without looking through typedefs that may have
586 /// added "volatile" at a different level.
587 bool isLocalVolatileQualified() const {
588 return (getLocalFastQualifiers() & Qualifiers::Volatile);
591 /// \brief Determine whether this type is volatile-qualified.
592 bool isVolatileQualified() const;
594 /// \brief Determine whether this particular QualType instance has any
595 /// qualifiers, without looking through any typedefs that might add
596 /// qualifiers at a different level.
597 bool hasLocalQualifiers() const {
598 return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
601 /// \brief Determine whether this type has any qualifiers.
602 bool hasQualifiers() const;
604 /// \brief Determine whether this particular QualType instance has any
605 /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
607 bool hasLocalNonFastQualifiers() const {
608 return Value.getPointer().is<const ExtQuals*>();
611 /// \brief Retrieve the set of qualifiers local to this particular QualType
612 /// instance, not including any qualifiers acquired through typedefs or
614 Qualifiers getLocalQualifiers() const;
616 /// \brief Retrieve the set of qualifiers applied to this type.
617 Qualifiers getQualifiers() const;
619 /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
620 /// local to this particular QualType instance, not including any qualifiers
621 /// acquired through typedefs or other sugar.
622 unsigned getLocalCVRQualifiers() const {
623 return getLocalFastQualifiers();
626 /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
627 /// applied to this type.
628 unsigned getCVRQualifiers() const;
630 bool isConstant(ASTContext& Ctx) const {
631 return QualType::isConstant(*this, Ctx);
634 /// \brief Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
635 bool isPODType(ASTContext &Context) const;
637 /// isCXX11PODType() - Return true if this is a POD type according to the
638 /// more relaxed rules of the C++11 standard, regardless of the current
639 /// compilation's language.
640 /// (C++0x [basic.types]p9)
641 bool isCXX11PODType(ASTContext &Context) const;
643 /// isTrivialType - Return true if this is a trivial type
644 /// (C++0x [basic.types]p9)
645 bool isTrivialType(ASTContext &Context) const;
647 /// isTriviallyCopyableType - Return true if this is a trivially
648 /// copyable type (C++0x [basic.types]p9)
649 bool isTriviallyCopyableType(ASTContext &Context) const;
651 // Don't promise in the API that anything besides 'const' can be
654 /// addConst - add the specified type qualifier to this QualType.
656 addFastQualifiers(Qualifiers::Const);
658 QualType withConst() const {
659 return withFastQualifiers(Qualifiers::Const);
662 /// addVolatile - add the specified type qualifier to this QualType.
664 addFastQualifiers(Qualifiers::Volatile);
666 QualType withVolatile() const {
667 return withFastQualifiers(Qualifiers::Volatile);
670 /// Add the restrict qualifier to this QualType.
672 addFastQualifiers(Qualifiers::Restrict);
674 QualType withRestrict() const {
675 return withFastQualifiers(Qualifiers::Restrict);
678 QualType withCVRQualifiers(unsigned CVR) const {
679 return withFastQualifiers(CVR);
682 void addFastQualifiers(unsigned TQs) {
683 assert(!(TQs & ~Qualifiers::FastMask)
684 && "non-fast qualifier bits set in mask!");
685 Value.setInt(Value.getInt() | TQs);
688 void removeLocalConst();
689 void removeLocalVolatile();
690 void removeLocalRestrict();
691 void removeLocalCVRQualifiers(unsigned Mask);
693 void removeLocalFastQualifiers() { Value.setInt(0); }
694 void removeLocalFastQualifiers(unsigned Mask) {
695 assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
696 Value.setInt(Value.getInt() & ~Mask);
699 // Creates a type with the given qualifiers in addition to any
700 // qualifiers already on this type.
701 QualType withFastQualifiers(unsigned TQs) const {
703 T.addFastQualifiers(TQs);
707 // Creates a type with exactly the given fast qualifiers, removing
708 // any existing fast qualifiers.
709 QualType withExactLocalFastQualifiers(unsigned TQs) const {
710 return withoutLocalFastQualifiers().withFastQualifiers(TQs);
713 // Removes fast qualifiers, but leaves any extended qualifiers in place.
714 QualType withoutLocalFastQualifiers() const {
716 T.removeLocalFastQualifiers();
720 QualType getCanonicalType() const;
722 /// \brief Return this type with all of the instance-specific qualifiers
723 /// removed, but without removing any qualifiers that may have been applied
724 /// through typedefs.
725 QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
727 /// \brief Retrieve the unqualified variant of the given type,
728 /// removing as little sugar as possible.
730 /// This routine looks through various kinds of sugar to find the
731 /// least-desugared type that is unqualified. For example, given:
734 /// typedef int Integer;
735 /// typedef const Integer CInteger;
736 /// typedef CInteger DifferenceType;
739 /// Executing \c getUnqualifiedType() on the type \c DifferenceType will
740 /// desugar until we hit the type \c Integer, which has no qualifiers on it.
742 /// The resulting type might still be qualified if it's an array
743 /// type. To strip qualifiers even from within an array type, use
744 /// ASTContext::getUnqualifiedArrayType.
745 inline QualType getUnqualifiedType() const;
747 /// getSplitUnqualifiedType - Retrieve the unqualified variant of the
748 /// given type, removing as little sugar as possible.
750 /// Like getUnqualifiedType(), but also returns the set of
751 /// qualifiers that were built up.
753 /// The resulting type might still be qualified if it's an array
754 /// type. To strip qualifiers even from within an array type, use
755 /// ASTContext::getUnqualifiedArrayType.
756 inline SplitQualType getSplitUnqualifiedType() const;
758 /// \brief Determine whether this type is more qualified than the other
759 /// given type, requiring exact equality for non-CVR qualifiers.
760 bool isMoreQualifiedThan(QualType Other) const;
762 /// \brief Determine whether this type is at least as qualified as the other
763 /// given type, requiring exact equality for non-CVR qualifiers.
764 bool isAtLeastAsQualifiedAs(QualType Other) const;
766 QualType getNonReferenceType() const;
768 /// \brief Determine the type of a (typically non-lvalue) expression with the
769 /// specified result type.
771 /// This routine should be used for expressions for which the return type is
772 /// explicitly specified (e.g., in a cast or call) and isn't necessarily
773 /// an lvalue. It removes a top-level reference (since there are no
774 /// expressions of reference type) and deletes top-level cvr-qualifiers
775 /// from non-class types (in C++) or all types (in C).
776 QualType getNonLValueExprType(ASTContext &Context) const;
778 /// getDesugaredType - Return the specified type with any "sugar" removed from
779 /// the type. This takes off typedefs, typeof's etc. If the outer level of
780 /// the type is already concrete, it returns it unmodified. This is similar
781 /// to getting the canonical type, but it doesn't remove *all* typedefs. For
782 /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
785 /// Qualifiers are left in place.
786 QualType getDesugaredType(const ASTContext &Context) const {
787 return getDesugaredType(*this, Context);
790 SplitQualType getSplitDesugaredType() const {
791 return getSplitDesugaredType(*this);
794 /// \brief Return the specified type with one level of "sugar" removed from
797 /// This routine takes off the first typedef, typeof, etc. If the outer level
798 /// of the type is already concrete, it returns it unmodified.
799 QualType getSingleStepDesugaredType(const ASTContext &Context) const {
800 return getSingleStepDesugaredTypeImpl(*this, Context);
803 /// IgnoreParens - Returns the specified type after dropping any
804 /// outer-level parentheses.
805 QualType IgnoreParens() const {
806 if (isa<ParenType>(*this))
807 return QualType::IgnoreParens(*this);
811 /// operator==/!= - Indicate whether the specified types and qualifiers are
813 friend bool operator==(const QualType &LHS, const QualType &RHS) {
814 return LHS.Value == RHS.Value;
816 friend bool operator!=(const QualType &LHS, const QualType &RHS) {
817 return LHS.Value != RHS.Value;
819 std::string getAsString() const {
820 return getAsString(split());
822 static std::string getAsString(SplitQualType split) {
823 return getAsString(split.Ty, split.Quals);
825 static std::string getAsString(const Type *ty, Qualifiers qs);
827 std::string getAsString(const PrintingPolicy &Policy) const {
829 getAsStringInternal(S, Policy);
832 void getAsStringInternal(std::string &Str,
833 const PrintingPolicy &Policy) const {
834 return getAsStringInternal(split(), Str, Policy);
836 static void getAsStringInternal(SplitQualType split, std::string &out,
837 const PrintingPolicy &policy) {
838 return getAsStringInternal(split.Ty, split.Quals, out, policy);
840 static void getAsStringInternal(const Type *ty, Qualifiers qs,
842 const PrintingPolicy &policy);
844 void dump(const char *s) const;
847 void Profile(llvm::FoldingSetNodeID &ID) const {
848 ID.AddPointer(getAsOpaquePtr());
851 /// getAddressSpace - Return the address space of this type.
852 inline unsigned getAddressSpace() const;
854 /// getObjCGCAttr - Returns gc attribute of this type.
855 inline Qualifiers::GC getObjCGCAttr() const;
857 /// isObjCGCWeak true when Type is objc's weak.
858 bool isObjCGCWeak() const {
859 return getObjCGCAttr() == Qualifiers::Weak;
862 /// isObjCGCStrong true when Type is objc's strong.
863 bool isObjCGCStrong() const {
864 return getObjCGCAttr() == Qualifiers::Strong;
867 /// getObjCLifetime - Returns lifetime attribute of this type.
868 Qualifiers::ObjCLifetime getObjCLifetime() const {
869 return getQualifiers().getObjCLifetime();
872 bool hasNonTrivialObjCLifetime() const {
873 return getQualifiers().hasNonTrivialObjCLifetime();
876 bool hasStrongOrWeakObjCLifetime() const {
877 return getQualifiers().hasStrongOrWeakObjCLifetime();
880 enum DestructionKind {
883 DK_objc_strong_lifetime,
884 DK_objc_weak_lifetime
887 /// isDestructedType - nonzero if objects of this type require
888 /// non-trivial work to clean up after. Non-zero because it's
889 /// conceivable that qualifiers (objc_gc(weak)?) could make
890 /// something require destruction.
891 DestructionKind isDestructedType() const {
892 return isDestructedTypeImpl(*this);
895 /// \brief Determine whether expressions of the given type are forbidden
896 /// from being lvalues in C.
898 /// The expression types that are forbidden to be lvalues are:
899 /// - 'void', but not qualified void
902 /// The exact rule here is C99 6.3.2.1:
903 /// An lvalue is an expression with an object type or an incomplete
904 /// type other than void.
905 bool isCForbiddenLValueType() const;
907 /// \brief Determine whether this type has trivial copy/move-assignment
909 bool hasTrivialAssignment(ASTContext &Context, bool Copying) const;
912 // These methods are implemented in a separate translation unit;
913 // "static"-ize them to avoid creating temporary QualTypes in the
915 static bool isConstant(QualType T, ASTContext& Ctx);
916 static QualType getDesugaredType(QualType T, const ASTContext &Context);
917 static SplitQualType getSplitDesugaredType(QualType T);
918 static SplitQualType getSplitUnqualifiedTypeImpl(QualType type);
919 static QualType getSingleStepDesugaredTypeImpl(QualType type,
920 const ASTContext &C);
921 static QualType IgnoreParens(QualType T);
922 static DestructionKind isDestructedTypeImpl(QualType type);
928 /// Implement simplify_type for QualType, so that we can dyn_cast from QualType
929 /// to a specific Type class.
930 template<> struct simplify_type<const ::clang::QualType> {
931 typedef const ::clang::Type *SimpleType;
932 static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
933 return Val.getTypePtr();
936 template<> struct simplify_type< ::clang::QualType>
937 : public simplify_type<const ::clang::QualType> {};
939 // Teach SmallPtrSet that QualType is "basically a pointer".
941 class PointerLikeTypeTraits<clang::QualType> {
943 static inline void *getAsVoidPointer(clang::QualType P) {
944 return P.getAsOpaquePtr();
946 static inline clang::QualType getFromVoidPointer(void *P) {
947 return clang::QualType::getFromOpaquePtr(P);
949 // Various qualifiers go in low bits.
950 enum { NumLowBitsAvailable = 0 };
953 } // end namespace llvm
957 /// \brief Base class that is common to both the \c ExtQuals and \c Type
958 /// classes, which allows \c QualType to access the common fields between the
961 class ExtQualsTypeCommonBase {
962 ExtQualsTypeCommonBase(const Type *baseType, QualType canon)
963 : BaseType(baseType), CanonicalType(canon) {}
965 /// \brief The "base" type of an extended qualifiers type (\c ExtQuals) or
966 /// a self-referential pointer (for \c Type).
968 /// This pointer allows an efficient mapping from a QualType to its
969 /// underlying type pointer.
970 const Type *const BaseType;
972 /// \brief The canonical type of this type. A QualType.
973 QualType CanonicalType;
975 friend class QualType;
977 friend class ExtQuals;
980 /// ExtQuals - We can encode up to four bits in the low bits of a
981 /// type pointer, but there are many more type qualifiers that we want
982 /// to be able to apply to an arbitrary type. Therefore we have this
983 /// struct, intended to be heap-allocated and used by QualType to
984 /// store qualifiers.
986 /// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
987 /// in three low bits on the QualType pointer; a fourth bit records whether
988 /// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
989 /// Objective-C GC attributes) are much more rare.
990 class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode {
991 // NOTE: changing the fast qualifiers should be straightforward as
992 // long as you don't make 'const' non-fast.
994 // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
995 // Fast qualifiers must occupy the low-order bits.
996 // b) Update Qualifiers::FastWidth and FastMask.
998 // a) Update is{Volatile,Restrict}Qualified(), defined inline.
999 // b) Update remove{Volatile,Restrict}, defined near the end of
1002 // a) Update get{Volatile,Restrict}Type.
1004 /// Quals - the immutable set of qualifiers applied by this
1005 /// node; always contains extended qualifiers.
1008 ExtQuals *this_() { return this; }
1011 ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
1012 : ExtQualsTypeCommonBase(baseType,
1013 canon.isNull() ? QualType(this_(), 0) : canon),
1016 assert(Quals.hasNonFastQualifiers()
1017 && "ExtQuals created with no fast qualifiers");
1018 assert(!Quals.hasFastQualifiers()
1019 && "ExtQuals created with fast qualifiers");
1022 Qualifiers getQualifiers() const { return Quals; }
1024 bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
1025 Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
1027 bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); }
1028 Qualifiers::ObjCLifetime getObjCLifetime() const {
1029 return Quals.getObjCLifetime();
1032 bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
1033 unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
1035 const Type *getBaseType() const { return BaseType; }
1038 void Profile(llvm::FoldingSetNodeID &ID) const {
1039 Profile(ID, getBaseType(), Quals);
1041 static void Profile(llvm::FoldingSetNodeID &ID,
1042 const Type *BaseType,
1044 assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
1045 ID.AddPointer(BaseType);
1050 /// \brief The kind of C++0x ref-qualifier associated with a function type,
1051 /// which determines whether a member function's "this" object can be an
1052 /// lvalue, rvalue, or neither.
1053 enum RefQualifierKind {
1054 /// \brief No ref-qualifier was provided.
1056 /// \brief An lvalue ref-qualifier was provided (\c &).
1058 /// \brief An rvalue ref-qualifier was provided (\c &&).
1062 /// Type - This is the base class of the type hierarchy. A central concept
1063 /// with types is that each type always has a canonical type. A canonical type
1064 /// is the type with any typedef names stripped out of it or the types it
1065 /// references. For example, consider:
1067 /// typedef int foo;
1068 /// typedef foo* bar;
1069 /// 'int *' 'foo *' 'bar'
1071 /// There will be a Type object created for 'int'. Since int is canonical, its
1072 /// canonicaltype pointer points to itself. There is also a Type for 'foo' (a
1073 /// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next
1074 /// there is a PointerType that represents 'int*', which, like 'int', is
1075 /// canonical. Finally, there is a PointerType type for 'foo*' whose canonical
1076 /// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
1079 /// Non-canonical types are useful for emitting diagnostics, without losing
1080 /// information about typedefs being used. Canonical types are useful for type
1081 /// comparisons (they allow by-pointer equality tests) and useful for reasoning
1082 /// about whether something has a particular form (e.g. is a function type),
1083 /// because they implicitly, recursively, strip all typedefs out of a type.
1085 /// Types, once created, are immutable.
1087 class Type : public ExtQualsTypeCommonBase {
1090 #define TYPE(Class, Base) Class,
1091 #define LAST_TYPE(Class) TypeLast = Class,
1092 #define ABSTRACT_TYPE(Class, Base)
1093 #include "clang/AST/TypeNodes.def"
1094 TagFirst = Record, TagLast = Enum
1098 Type(const Type&); // DO NOT IMPLEMENT.
1099 void operator=(const Type&); // DO NOT IMPLEMENT.
1101 /// Bitfields required by the Type class.
1102 class TypeBitfields {
1104 template <class T> friend class TypePropertyCache;
1106 /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
1109 /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
1110 /// Note that this should stay at the end of the ivars for Type so that
1111 /// subclasses can pack their bitfields into the same word.
1112 unsigned Dependent : 1;
1114 /// \brief Whether this type somehow involves a template parameter, even
1115 /// if the resolution of the type does not depend on a template parameter.
1116 unsigned InstantiationDependent : 1;
1118 /// \brief Whether this type is a variably-modified type (C99 6.7.5).
1119 unsigned VariablyModified : 1;
1121 /// \brief Whether this type contains an unexpanded parameter pack
1122 /// (for C++0x variadic templates).
1123 unsigned ContainsUnexpandedParameterPack : 1;
1125 /// \brief Nonzero if the cache (i.e. the bitfields here starting
1126 /// with 'Cache') is valid. If so, then this is a
1127 /// LangOptions::VisibilityMode+1.
1128 mutable unsigned CacheValidAndVisibility : 2;
1130 /// \brief True if the visibility was set explicitly in the source code.
1131 mutable unsigned CachedExplicitVisibility : 1;
1133 /// \brief Linkage of this type.
1134 mutable unsigned CachedLinkage : 2;
1136 /// \brief Whether this type involves and local or unnamed types.
1137 mutable unsigned CachedLocalOrUnnamed : 1;
1139 /// \brief FromAST - Whether this type comes from an AST file.
1140 mutable unsigned FromAST : 1;
1142 bool isCacheValid() const {
1143 return (CacheValidAndVisibility != 0);
1145 Visibility getVisibility() const {
1146 assert(isCacheValid() && "getting linkage from invalid cache");
1147 return static_cast<Visibility>(CacheValidAndVisibility-1);
1149 bool isVisibilityExplicit() const {
1150 assert(isCacheValid() && "getting linkage from invalid cache");
1151 return CachedExplicitVisibility;
1153 Linkage getLinkage() const {
1154 assert(isCacheValid() && "getting linkage from invalid cache");
1155 return static_cast<Linkage>(CachedLinkage);
1157 bool hasLocalOrUnnamedType() const {
1158 assert(isCacheValid() && "getting linkage from invalid cache");
1159 return CachedLocalOrUnnamed;
1162 enum { NumTypeBits = 19 };
1165 // These classes allow subclasses to somewhat cleanly pack bitfields
1168 class ArrayTypeBitfields {
1169 friend class ArrayType;
1171 unsigned : NumTypeBits;
1173 /// IndexTypeQuals - CVR qualifiers from declarations like
1174 /// 'int X[static restrict 4]'. For function parameters only.
1175 unsigned IndexTypeQuals : 3;
1177 /// SizeModifier - storage class qualifiers from declarations like
1178 /// 'int X[static restrict 4]'. For function parameters only.
1179 /// Actually an ArrayType::ArraySizeModifier.
1180 unsigned SizeModifier : 3;
1183 class BuiltinTypeBitfields {
1184 friend class BuiltinType;
1186 unsigned : NumTypeBits;
1188 /// The kind (BuiltinType::Kind) of builtin type this is.
1192 class FunctionTypeBitfields {
1193 friend class FunctionType;
1195 unsigned : NumTypeBits;
1197 /// Extra information which affects how the function is called, like
1198 /// regparm and the calling convention.
1199 unsigned ExtInfo : 8;
1201 /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
1202 /// other bitfields.
1203 /// The qualifiers are part of FunctionProtoType because...
1205 /// C++ 8.3.5p4: The return type, the parameter type list and the
1206 /// cv-qualifier-seq, [...], are part of the function type.
1207 unsigned TypeQuals : 3;
1209 /// \brief The ref-qualifier associated with a \c FunctionProtoType.
1211 /// This is a value of type \c RefQualifierKind.
1212 unsigned RefQualifier : 2;
1215 class ObjCObjectTypeBitfields {
1216 friend class ObjCObjectType;
1218 unsigned : NumTypeBits;
1220 /// NumProtocols - The number of protocols stored directly on this
1222 unsigned NumProtocols : 32 - NumTypeBits;
1225 class ReferenceTypeBitfields {
1226 friend class ReferenceType;
1228 unsigned : NumTypeBits;
1230 /// True if the type was originally spelled with an lvalue sigil.
1231 /// This is never true of rvalue references but can also be false
1232 /// on lvalue references because of C++0x [dcl.typedef]p9,
1235 /// typedef int &ref; // lvalue, spelled lvalue
1236 /// typedef int &&rvref; // rvalue
1237 /// ref &a; // lvalue, inner ref, spelled lvalue
1238 /// ref &&a; // lvalue, inner ref
1239 /// rvref &a; // lvalue, inner ref, spelled lvalue
1240 /// rvref &&a; // rvalue, inner ref
1241 unsigned SpelledAsLValue : 1;
1243 /// True if the inner type is a reference type. This only happens
1244 /// in non-canonical forms.
1245 unsigned InnerRef : 1;
1248 class TypeWithKeywordBitfields {
1249 friend class TypeWithKeyword;
1251 unsigned : NumTypeBits;
1253 /// An ElaboratedTypeKeyword. 8 bits for efficient access.
1254 unsigned Keyword : 8;
1257 class VectorTypeBitfields {
1258 friend class VectorType;
1260 unsigned : NumTypeBits;
1262 /// VecKind - The kind of vector, either a generic vector type or some
1263 /// target-specific vector type such as for AltiVec or Neon.
1264 unsigned VecKind : 3;
1266 /// NumElements - The number of elements in the vector.
1267 unsigned NumElements : 29 - NumTypeBits;
1270 class AttributedTypeBitfields {
1271 friend class AttributedType;
1273 unsigned : NumTypeBits;
1275 /// AttrKind - an AttributedType::Kind
1276 unsigned AttrKind : 32 - NumTypeBits;
1280 TypeBitfields TypeBits;
1281 ArrayTypeBitfields ArrayTypeBits;
1282 AttributedTypeBitfields AttributedTypeBits;
1283 BuiltinTypeBitfields BuiltinTypeBits;
1284 FunctionTypeBitfields FunctionTypeBits;
1285 ObjCObjectTypeBitfields ObjCObjectTypeBits;
1286 ReferenceTypeBitfields ReferenceTypeBits;
1287 TypeWithKeywordBitfields TypeWithKeywordBits;
1288 VectorTypeBitfields VectorTypeBits;
1292 /// \brief Set whether this type comes from an AST file.
1293 void setFromAST(bool V = true) const {
1294 TypeBits.FromAST = V;
1297 template <class T> friend class TypePropertyCache;
1300 // silence VC++ warning C4355: 'this' : used in base member initializer list
1301 Type *this_() { return this; }
1302 Type(TypeClass tc, QualType canon, bool Dependent,
1303 bool InstantiationDependent, bool VariablyModified,
1304 bool ContainsUnexpandedParameterPack)
1305 : ExtQualsTypeCommonBase(this,
1306 canon.isNull() ? QualType(this_(), 0) : canon) {
1308 TypeBits.Dependent = Dependent;
1309 TypeBits.InstantiationDependent = Dependent || InstantiationDependent;
1310 TypeBits.VariablyModified = VariablyModified;
1311 TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
1312 TypeBits.CacheValidAndVisibility = 0;
1313 TypeBits.CachedExplicitVisibility = false;
1314 TypeBits.CachedLocalOrUnnamed = false;
1315 TypeBits.CachedLinkage = NoLinkage;
1316 TypeBits.FromAST = false;
1318 friend class ASTContext;
1320 void setDependent(bool D = true) {
1321 TypeBits.Dependent = D;
1323 TypeBits.InstantiationDependent = true;
1325 void setInstantiationDependent(bool D = true) {
1326 TypeBits.InstantiationDependent = D; }
1327 void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM;
1329 void setContainsUnexpandedParameterPack(bool PP = true) {
1330 TypeBits.ContainsUnexpandedParameterPack = PP;
1334 TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
1336 /// \brief Whether this type comes from an AST file.
1337 bool isFromAST() const { return TypeBits.FromAST; }
1339 /// \brief Whether this type is or contains an unexpanded parameter
1340 /// pack, used to support C++0x variadic templates.
1342 /// A type that contains a parameter pack shall be expanded by the
1343 /// ellipsis operator at some point. For example, the typedef in the
1344 /// following example contains an unexpanded parameter pack 'T':
1347 /// template<typename ...T>
1349 /// typedef T* pointer_types; // ill-formed; T is a parameter pack.
1353 /// Note that this routine does not specify which
1354 bool containsUnexpandedParameterPack() const {
1355 return TypeBits.ContainsUnexpandedParameterPack;
1358 /// Determines if this type would be canonical if it had no further
1360 bool isCanonicalUnqualified() const {
1361 return CanonicalType == QualType(this, 0);
1364 /// Pull a single level of sugar off of this locally-unqualified type.
1365 /// Users should generally prefer SplitQualType::getSingleStepDesugaredType()
1366 /// or QualType::getSingleStepDesugaredType(const ASTContext&).
1367 QualType getLocallyUnqualifiedSingleStepDesugaredType() const;
1369 /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
1370 /// object types, function types, and incomplete types.
1372 /// isIncompleteType - Return true if this is an incomplete type.
1373 /// A type that can describe objects, but which lacks information needed to
1374 /// determine its size (e.g. void, or a fwd declared struct). Clients of this
1375 /// routine will need to determine if the size is actually required.
1377 /// \brief Def If non-NULL, and the type refers to some kind of declaration
1378 /// that can be completed (such as a C struct, C++ class, or Objective-C
1379 /// class), will be set to the declaration.
1380 bool isIncompleteType(NamedDecl **Def = 0) const;
1382 /// isIncompleteOrObjectType - Return true if this is an incomplete or object
1383 /// type, in other words, not a function type.
1384 bool isIncompleteOrObjectType() const {
1385 return !isFunctionType();
1388 /// \brief Determine whether this type is an object type.
1389 bool isObjectType() const {
1390 // C++ [basic.types]p8:
1391 // An object type is a (possibly cv-qualified) type that is not a
1392 // function type, not a reference type, and not a void type.
1393 return !isReferenceType() && !isFunctionType() && !isVoidType();
1396 /// isLiteralType - Return true if this is a literal type
1397 /// (C++0x [basic.types]p10)
1398 bool isLiteralType() const;
1400 /// \brief Test if this type is a standard-layout type.
1401 /// (C++0x [basic.type]p9)
1402 bool isStandardLayoutType() const;
1404 /// Helper methods to distinguish type categories. All type predicates
1405 /// operate on the canonical type, ignoring typedefs and qualifiers.
1407 /// isBuiltinType - returns true if the type is a builtin type.
1408 bool isBuiltinType() const;
1410 /// isSpecificBuiltinType - Test for a particular builtin type.
1411 bool isSpecificBuiltinType(unsigned K) const;
1413 /// isPlaceholderType - Test for a type which does not represent an
1414 /// actual type-system type but is instead used as a placeholder for
1415 /// various convenient purposes within Clang. All such types are
1417 bool isPlaceholderType() const;
1418 const BuiltinType *getAsPlaceholderType() const;
1420 /// isSpecificPlaceholderType - Test for a specific placeholder type.
1421 bool isSpecificPlaceholderType(unsigned K) const;
1423 /// isNonOverloadPlaceholderType - Test for a placeholder type
1424 /// other than Overload; see BuiltinType::isNonOverloadPlaceholderType.
1425 bool isNonOverloadPlaceholderType() const;
1427 /// isIntegerType() does *not* include complex integers (a GCC extension).
1428 /// isComplexIntegerType() can be used to test for complex integers.
1429 bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum)
1430 bool isEnumeralType() const;
1431 bool isBooleanType() const;
1432 bool isCharType() const;
1433 bool isWideCharType() const;
1434 bool isChar16Type() const;
1435 bool isChar32Type() const;
1436 bool isAnyCharacterType() const;
1437 bool isIntegralType(ASTContext &Ctx) const;
1439 /// \brief Determine whether this type is an integral or enumeration type.
1440 bool isIntegralOrEnumerationType() const;
1441 /// \brief Determine whether this type is an integral or unscoped enumeration
1443 bool isIntegralOrUnscopedEnumerationType() const;
1445 /// Floating point categories.
1446 bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
1447 /// isComplexType() does *not* include complex integers (a GCC extension).
1448 /// isComplexIntegerType() can be used to test for complex integers.
1449 bool isComplexType() const; // C99 6.2.5p11 (complex)
1450 bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int.
1451 bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex)
1452 bool isHalfType() const; // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half)
1453 bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
1454 bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating)
1455 bool isVoidType() const; // C99 6.2.5p19
1456 bool isDerivedType() const; // C99 6.2.5p20
1457 bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers)
1458 bool isAggregateType() const;
1459 bool isFundamentalType() const;
1460 bool isCompoundType() const;
1462 // Type Predicates: Check to see if this type is structurally the specified
1463 // type, ignoring typedefs and qualifiers.
1464 bool isFunctionType() const;
1465 bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
1466 bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
1467 bool isPointerType() const;
1468 bool isAnyPointerType() const; // Any C pointer or ObjC object pointer
1469 bool isBlockPointerType() const;
1470 bool isVoidPointerType() const;
1471 bool isReferenceType() const;
1472 bool isLValueReferenceType() const;
1473 bool isRValueReferenceType() const;
1474 bool isFunctionPointerType() const;
1475 bool isMemberPointerType() const;
1476 bool isMemberFunctionPointerType() const;
1477 bool isMemberDataPointerType() const;
1478 bool isArrayType() const;
1479 bool isConstantArrayType() const;
1480 bool isIncompleteArrayType() const;
1481 bool isVariableArrayType() const;
1482 bool isDependentSizedArrayType() const;
1483 bool isRecordType() const;
1484 bool isClassType() const;
1485 bool isStructureType() const;
1486 bool isStructureOrClassType() const;
1487 bool isUnionType() const;
1488 bool isComplexIntegerType() const; // GCC _Complex integer type.
1489 bool isVectorType() const; // GCC vector type.
1490 bool isExtVectorType() const; // Extended vector type.
1491 bool isObjCObjectPointerType() const; // pointer to ObjC object
1492 bool isObjCRetainableType() const; // ObjC object or block pointer
1493 bool isObjCLifetimeType() const; // (array of)* retainable type
1494 bool isObjCIndirectLifetimeType() const; // (pointer to)* lifetime type
1495 bool isObjCNSObjectType() const; // __attribute__((NSObject))
1496 // FIXME: change this to 'raw' interface type, so we can used 'interface' type
1497 // for the common case.
1498 bool isObjCObjectType() const; // NSString or typeof(*(id)0)
1499 bool isObjCQualifiedInterfaceType() const; // NSString<foo>
1500 bool isObjCQualifiedIdType() const; // id<foo>
1501 bool isObjCQualifiedClassType() const; // Class<foo>
1502 bool isObjCObjectOrInterfaceType() const;
1503 bool isObjCIdType() const; // id
1504 bool isObjCClassType() const; // Class
1505 bool isObjCSelType() const; // Class
1506 bool isObjCBuiltinType() const; // 'id' or 'Class'
1507 bool isObjCARCBridgableType() const;
1508 bool isCARCBridgableType() const;
1509 bool isTemplateTypeParmType() const; // C++ template type parameter
1510 bool isNullPtrType() const; // C++0x nullptr_t
1511 bool isAtomicType() const; // C11 _Atomic()
1513 /// Determines if this type, which must satisfy
1514 /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
1515 /// than implicitly __strong.
1516 bool isObjCARCImplicitlyUnretainedType() const;
1518 /// Return the implicit lifetime for this type, which must not be dependent.
1519 Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
1521 enum ScalarTypeKind {
1524 STK_ObjCObjectPointer,
1529 STK_IntegralComplex,
1532 /// getScalarTypeKind - Given that this is a scalar type, classify it.
1533 ScalarTypeKind getScalarTypeKind() const;
1535 /// isDependentType - Whether this type is a dependent type, meaning
1536 /// that its definition somehow depends on a template parameter
1537 /// (C++ [temp.dep.type]).
1538 bool isDependentType() const { return TypeBits.Dependent; }
1540 /// \brief Determine whether this type is an instantiation-dependent type,
1541 /// meaning that the type involves a template parameter (even if the
1542 /// definition does not actually depend on the type substituted for that
1543 /// template parameter).
1544 bool isInstantiationDependentType() const {
1545 return TypeBits.InstantiationDependent;
1548 /// \brief Whether this type is a variably-modified type (C99 6.7.5).
1549 bool isVariablyModifiedType() const { return TypeBits.VariablyModified; }
1551 /// \brief Whether this type involves a variable-length array type
1552 /// with a definite size.
1553 bool hasSizedVLAType() const;
1555 /// \brief Whether this type is or contains a local or unnamed type.
1556 bool hasUnnamedOrLocalType() const;
1558 bool isOverloadableType() const;
1560 /// \brief Determine wither this type is a C++ elaborated-type-specifier.
1561 bool isElaboratedTypeSpecifier() const;
1563 bool canDecayToPointerType() const;
1565 /// hasPointerRepresentation - Whether this type is represented
1566 /// natively as a pointer; this includes pointers, references, block
1567 /// pointers, and Objective-C interface, qualified id, and qualified
1568 /// interface types, as well as nullptr_t.
1569 bool hasPointerRepresentation() const;
1571 /// hasObjCPointerRepresentation - Whether this type can represent
1572 /// an objective pointer type for the purpose of GC'ability
1573 bool hasObjCPointerRepresentation() const;
1575 /// \brief Determine whether this type has an integer representation
1576 /// of some sort, e.g., it is an integer type or a vector.
1577 bool hasIntegerRepresentation() const;
1579 /// \brief Determine whether this type has an signed integer representation
1580 /// of some sort, e.g., it is an signed integer type or a vector.
1581 bool hasSignedIntegerRepresentation() const;
1583 /// \brief Determine whether this type has an unsigned integer representation
1584 /// of some sort, e.g., it is an unsigned integer type or a vector.
1585 bool hasUnsignedIntegerRepresentation() const;
1587 /// \brief Determine whether this type has a floating-point representation
1588 /// of some sort, e.g., it is a floating-point type or a vector thereof.
1589 bool hasFloatingRepresentation() const;
1591 // Type Checking Functions: Check to see if this type is structurally the
1592 // specified type, ignoring typedefs and qualifiers, and return a pointer to
1593 // the best type we can.
1594 const RecordType *getAsStructureType() const;
1595 /// NOTE: getAs*ArrayType are methods on ASTContext.
1596 const RecordType *getAsUnionType() const;
1597 const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
1598 // The following is a convenience method that returns an ObjCObjectPointerType
1599 // for object declared using an interface.
1600 const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
1601 const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
1602 const ObjCObjectPointerType *getAsObjCQualifiedClassType() const;
1603 const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
1604 const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
1606 /// \brief Retrieves the CXXRecordDecl that this type refers to, either
1607 /// because the type is a RecordType or because it is the injected-class-name
1608 /// type of a class template or class template partial specialization.
1609 CXXRecordDecl *getAsCXXRecordDecl() const;
1611 /// \brief Get the AutoType whose type will be deduced for a variable with
1612 /// an initializer of this type. This looks through declarators like pointer
1613 /// types, but not through decltype or typedefs.
1614 AutoType *getContainedAutoType() const;
1616 /// Member-template getAs<specific type>'. Look through sugar for
1617 /// an instance of <specific type>. This scheme will eventually
1618 /// replace the specific getAsXXXX methods above.
1620 /// There are some specializations of this member template listed
1621 /// immediately following this class.
1622 template <typename T> const T *getAs() const;
1624 /// A variant of getAs<> for array types which silently discards
1625 /// qualifiers from the outermost type.
1626 const ArrayType *getAsArrayTypeUnsafe() const;
1628 /// Member-template castAs<specific type>. Look through sugar for
1629 /// the underlying instance of <specific type>.
1631 /// This method has the same relationship to getAs<T> as cast<T> has
1632 /// to dyn_cast<T>; which is to say, the underlying type *must*
1633 /// have the intended type, and this method will never return null.
1634 template <typename T> const T *castAs() const;
1636 /// A variant of castAs<> for array type which silently discards
1637 /// qualifiers from the outermost type.
1638 const ArrayType *castAsArrayTypeUnsafe() const;
1640 /// getBaseElementTypeUnsafe - Get the base element type of this
1641 /// type, potentially discarding type qualifiers. This method
1642 /// should never be used when type qualifiers are meaningful.
1643 const Type *getBaseElementTypeUnsafe() const;
1645 /// getArrayElementTypeNoTypeQual - If this is an array type, return the
1646 /// element type of the array, potentially with type qualifiers missing.
1647 /// This method should never be used when type qualifiers are meaningful.
1648 const Type *getArrayElementTypeNoTypeQual() const;
1650 /// getPointeeType - If this is a pointer, ObjC object pointer, or block
1651 /// pointer, this returns the respective pointee.
1652 QualType getPointeeType() const;
1654 /// getUnqualifiedDesugaredType() - Return the specified type with
1655 /// any "sugar" removed from the type, removing any typedefs,
1656 /// typeofs, etc., as well as any qualifiers.
1657 const Type *getUnqualifiedDesugaredType() const;
1659 /// More type predicates useful for type checking/promotion
1660 bool isPromotableIntegerType() const; // C99 6.3.1.1p2
1662 /// isSignedIntegerType - Return true if this is an integer type that is
1663 /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
1664 /// or an enum decl which has a signed representation.
1665 bool isSignedIntegerType() const;
1667 /// isUnsignedIntegerType - Return true if this is an integer type that is
1668 /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool],
1669 /// or an enum decl which has an unsigned representation.
1670 bool isUnsignedIntegerType() const;
1672 /// Determines whether this is an integer type that is signed or an
1673 /// enumeration types whose underlying type is a signed integer type.
1674 bool isSignedIntegerOrEnumerationType() const;
1676 /// Determines whether this is an integer type that is unsigned or an
1677 /// enumeration types whose underlying type is a unsigned integer type.
1678 bool isUnsignedIntegerOrEnumerationType() const;
1680 /// isConstantSizeType - Return true if this is not a variable sized type,
1681 /// according to the rules of C99 6.7.5p3. It is not legal to call this on
1682 /// incomplete types.
1683 bool isConstantSizeType() const;
1685 /// isSpecifierType - Returns true if this type can be represented by some
1686 /// set of type specifiers.
1687 bool isSpecifierType() const;
1689 /// \brief Determine the linkage of this type.
1690 Linkage getLinkage() const;
1692 /// \brief Determine the visibility of this type.
1693 Visibility getVisibility() const;
1695 /// \brief Return true if the visibility was explicitly set is the code.
1696 bool isVisibilityExplicit() const;
1698 /// \brief Determine the linkage and visibility of this type.
1699 std::pair<Linkage,Visibility> getLinkageAndVisibility() const;
1701 /// \brief Note that the linkage is no longer known.
1702 void ClearLinkageCache();
1704 const char *getTypeClassName() const;
1706 QualType getCanonicalTypeInternal() const {
1707 return CanonicalType;
1709 CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
1710 LLVM_ATTRIBUTE_USED void dump() const;
1712 static bool classof(const Type *) { return true; }
1714 friend class ASTReader;
1715 friend class ASTWriter;
1718 template <> inline const TypedefType *Type::getAs() const {
1719 return dyn_cast<TypedefType>(this);
1722 // We can do canonical leaf types faster, because we don't have to
1723 // worry about preserving child type decoration.
1724 #define TYPE(Class, Base)
1725 #define LEAF_TYPE(Class) \
1726 template <> inline const Class##Type *Type::getAs() const { \
1727 return dyn_cast<Class##Type>(CanonicalType); \
1729 template <> inline const Class##Type *Type::castAs() const { \
1730 return cast<Class##Type>(CanonicalType); \
1732 #include "clang/AST/TypeNodes.def"
1735 /// BuiltinType - This class is used for builtin types like 'int'. Builtin
1736 /// types are always canonical and have a literal name field.
1737 class BuiltinType : public Type {
1740 #define BUILTIN_TYPE(Id, SingletonId) Id,
1741 #define LAST_BUILTIN_TYPE(Id) LastKind = Id
1742 #include "clang/AST/BuiltinTypes.def"
1747 : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent),
1748 /*InstantiationDependent=*/(K == Dependent),
1749 /*VariablyModified=*/false,
1750 /*Unexpanded paramter pack=*/false) {
1751 BuiltinTypeBits.Kind = K;
1754 Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
1755 const char *getName(const PrintingPolicy &Policy) const;
1757 bool isSugared() const { return false; }
1758 QualType desugar() const { return QualType(this, 0); }
1760 bool isInteger() const {
1761 return getKind() >= Bool && getKind() <= Int128;
1764 bool isSignedInteger() const {
1765 return getKind() >= Char_S && getKind() <= Int128;
1768 bool isUnsignedInteger() const {
1769 return getKind() >= Bool && getKind() <= UInt128;
1772 bool isFloatingPoint() const {
1773 return getKind() >= Half && getKind() <= LongDouble;
1776 /// Determines whether the given kind corresponds to a placeholder type.
1777 static bool isPlaceholderTypeKind(Kind K) {
1778 return K >= Overload;
1781 /// Determines whether this type is a placeholder type, i.e. a type
1782 /// which cannot appear in arbitrary positions in a fully-formed
1784 bool isPlaceholderType() const {
1785 return isPlaceholderTypeKind(getKind());
1788 /// Determines whether this type is a placeholder type other than
1789 /// Overload. Most placeholder types require only syntactic
1790 /// information about their context in order to be resolved (e.g.
1791 /// whether it is a call expression), which means they can (and
1792 /// should) be resolved in an earlier "phase" of analysis.
1793 /// Overload expressions sometimes pick up further information
1794 /// from their context, like whether the context expects a
1795 /// specific function-pointer type, and so frequently need
1796 /// special treatment.
1797 bool isNonOverloadPlaceholderType() const {
1798 return getKind() > Overload;
1801 static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
1802 static bool classof(const BuiltinType *) { return true; }
1805 /// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex
1806 /// types (_Complex float etc) as well as the GCC integer complex extensions.
1808 class ComplexType : public Type, public llvm::FoldingSetNode {
1809 QualType ElementType;
1810 ComplexType(QualType Element, QualType CanonicalPtr) :
1811 Type(Complex, CanonicalPtr, Element->isDependentType(),
1812 Element->isInstantiationDependentType(),
1813 Element->isVariablyModifiedType(),
1814 Element->containsUnexpandedParameterPack()),
1815 ElementType(Element) {
1817 friend class ASTContext; // ASTContext creates these.
1820 QualType getElementType() const { return ElementType; }
1822 bool isSugared() const { return false; }
1823 QualType desugar() const { return QualType(this, 0); }
1825 void Profile(llvm::FoldingSetNodeID &ID) {
1826 Profile(ID, getElementType());
1828 static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
1829 ID.AddPointer(Element.getAsOpaquePtr());
1832 static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
1833 static bool classof(const ComplexType *) { return true; }
1836 /// ParenType - Sugar for parentheses used when specifying types.
1838 class ParenType : public Type, public llvm::FoldingSetNode {
1841 ParenType(QualType InnerType, QualType CanonType) :
1842 Type(Paren, CanonType, InnerType->isDependentType(),
1843 InnerType->isInstantiationDependentType(),
1844 InnerType->isVariablyModifiedType(),
1845 InnerType->containsUnexpandedParameterPack()),
1848 friend class ASTContext; // ASTContext creates these.
1852 QualType getInnerType() const { return Inner; }
1854 bool isSugared() const { return true; }
1855 QualType desugar() const { return getInnerType(); }
1857 void Profile(llvm::FoldingSetNodeID &ID) {
1858 Profile(ID, getInnerType());
1860 static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
1864 static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
1865 static bool classof(const ParenType *) { return true; }
1868 /// PointerType - C99 6.7.5.1 - Pointer Declarators.
1870 class PointerType : public Type, public llvm::FoldingSetNode {
1871 QualType PointeeType;
1873 PointerType(QualType Pointee, QualType CanonicalPtr) :
1874 Type(Pointer, CanonicalPtr, Pointee->isDependentType(),
1875 Pointee->isInstantiationDependentType(),
1876 Pointee->isVariablyModifiedType(),
1877 Pointee->containsUnexpandedParameterPack()),
1878 PointeeType(Pointee) {
1880 friend class ASTContext; // ASTContext creates these.
1884 QualType getPointeeType() const { return PointeeType; }
1886 bool isSugared() const { return false; }
1887 QualType desugar() const { return QualType(this, 0); }
1889 void Profile(llvm::FoldingSetNodeID &ID) {
1890 Profile(ID, getPointeeType());
1892 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
1893 ID.AddPointer(Pointee.getAsOpaquePtr());
1896 static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
1897 static bool classof(const PointerType *) { return true; }
1900 /// BlockPointerType - pointer to a block type.
1901 /// This type is to represent types syntactically represented as
1902 /// "void (^)(int)", etc. Pointee is required to always be a function type.
1904 class BlockPointerType : public Type, public llvm::FoldingSetNode {
1905 QualType PointeeType; // Block is some kind of pointer type
1906 BlockPointerType(QualType Pointee, QualType CanonicalCls) :
1907 Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
1908 Pointee->isInstantiationDependentType(),
1909 Pointee->isVariablyModifiedType(),
1910 Pointee->containsUnexpandedParameterPack()),
1911 PointeeType(Pointee) {
1913 friend class ASTContext; // ASTContext creates these.
1917 // Get the pointee type. Pointee is required to always be a function type.
1918 QualType getPointeeType() const { return PointeeType; }
1920 bool isSugared() const { return false; }
1921 QualType desugar() const { return QualType(this, 0); }
1923 void Profile(llvm::FoldingSetNodeID &ID) {
1924 Profile(ID, getPointeeType());
1926 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
1927 ID.AddPointer(Pointee.getAsOpaquePtr());
1930 static bool classof(const Type *T) {
1931 return T->getTypeClass() == BlockPointer;
1933 static bool classof(const BlockPointerType *) { return true; }
1936 /// ReferenceType - Base for LValueReferenceType and RValueReferenceType
1938 class ReferenceType : public Type, public llvm::FoldingSetNode {
1939 QualType PointeeType;
1942 ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
1943 bool SpelledAsLValue) :
1944 Type(tc, CanonicalRef, Referencee->isDependentType(),
1945 Referencee->isInstantiationDependentType(),
1946 Referencee->isVariablyModifiedType(),
1947 Referencee->containsUnexpandedParameterPack()),
1948 PointeeType(Referencee)
1950 ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
1951 ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
1955 bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
1956 bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
1958 QualType getPointeeTypeAsWritten() const { return PointeeType; }
1959 QualType getPointeeType() const {
1960 // FIXME: this might strip inner qualifiers; okay?
1961 const ReferenceType *T = this;
1962 while (T->isInnerRef())
1963 T = T->PointeeType->castAs<ReferenceType>();
1964 return T->PointeeType;
1967 void Profile(llvm::FoldingSetNodeID &ID) {
1968 Profile(ID, PointeeType, isSpelledAsLValue());
1970 static void Profile(llvm::FoldingSetNodeID &ID,
1971 QualType Referencee,
1972 bool SpelledAsLValue) {
1973 ID.AddPointer(Referencee.getAsOpaquePtr());
1974 ID.AddBoolean(SpelledAsLValue);
1977 static bool classof(const Type *T) {
1978 return T->getTypeClass() == LValueReference ||
1979 T->getTypeClass() == RValueReference;
1981 static bool classof(const ReferenceType *) { return true; }
1984 /// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
1986 class LValueReferenceType : public ReferenceType {
1987 LValueReferenceType(QualType Referencee, QualType CanonicalRef,
1988 bool SpelledAsLValue) :
1989 ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue)
1991 friend class ASTContext; // ASTContext creates these
1993 bool isSugared() const { return false; }
1994 QualType desugar() const { return QualType(this, 0); }
1996 static bool classof(const Type *T) {
1997 return T->getTypeClass() == LValueReference;
1999 static bool classof(const LValueReferenceType *) { return true; }
2002 /// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
2004 class RValueReferenceType : public ReferenceType {
2005 RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
2006 ReferenceType(RValueReference, Referencee, CanonicalRef, false) {
2008 friend class ASTContext; // ASTContext creates these
2010 bool isSugared() const { return false; }
2011 QualType desugar() const { return QualType(this, 0); }
2013 static bool classof(const Type *T) {
2014 return T->getTypeClass() == RValueReference;
2016 static bool classof(const RValueReferenceType *) { return true; }
2019 /// MemberPointerType - C++ 8.3.3 - Pointers to members
2021 class MemberPointerType : public Type, public llvm::FoldingSetNode {
2022 QualType PointeeType;
2023 /// The class of which the pointee is a member. Must ultimately be a
2024 /// RecordType, but could be a typedef or a template parameter too.
2027 MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
2028 Type(MemberPointer, CanonicalPtr,
2029 Cls->isDependentType() || Pointee->isDependentType(),
2030 (Cls->isInstantiationDependentType() ||
2031 Pointee->isInstantiationDependentType()),
2032 Pointee->isVariablyModifiedType(),
2033 (Cls->containsUnexpandedParameterPack() ||
2034 Pointee->containsUnexpandedParameterPack())),
2035 PointeeType(Pointee), Class(Cls) {
2037 friend class ASTContext; // ASTContext creates these.
2040 QualType getPointeeType() const { return PointeeType; }
2042 /// Returns true if the member type (i.e. the pointee type) is a
2043 /// function type rather than a data-member type.
2044 bool isMemberFunctionPointer() const {
2045 return PointeeType->isFunctionProtoType();
2048 /// Returns true if the member type (i.e. the pointee type) is a
2049 /// data type rather than a function type.
2050 bool isMemberDataPointer() const {
2051 return !PointeeType->isFunctionProtoType();
2054 const Type *getClass() const { return Class; }
2056 bool isSugared() const { return false; }
2057 QualType desugar() const { return QualType(this, 0); }
2059 void Profile(llvm::FoldingSetNodeID &ID) {
2060 Profile(ID, getPointeeType(), getClass());
2062 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
2063 const Type *Class) {
2064 ID.AddPointer(Pointee.getAsOpaquePtr());
2065 ID.AddPointer(Class);
2068 static bool classof(const Type *T) {
2069 return T->getTypeClass() == MemberPointer;
2071 static bool classof(const MemberPointerType *) { return true; }
2074 /// ArrayType - C99 6.7.5.2 - Array Declarators.
2076 class ArrayType : public Type, public llvm::FoldingSetNode {
2078 /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
2079 /// an array with a static size (e.g. int X[static 4]), or an array
2080 /// with a star size (e.g. int X[*]).
2081 /// 'static' is only allowed on function parameters.
2082 enum ArraySizeModifier {
2083 Normal, Static, Star
2086 /// ElementType - The element type of the array.
2087 QualType ElementType;
2090 // C++ [temp.dep.type]p1:
2091 // A type is dependent if it is...
2092 // - an array type constructed from any dependent type or whose
2093 // size is specified by a constant expression that is
2095 ArrayType(TypeClass tc, QualType et, QualType can,
2096 ArraySizeModifier sm, unsigned tq,
2097 bool ContainsUnexpandedParameterPack)
2098 : Type(tc, can, et->isDependentType() || tc == DependentSizedArray,
2099 et->isInstantiationDependentType() || tc == DependentSizedArray,
2100 (tc == VariableArray || et->isVariablyModifiedType()),
2101 ContainsUnexpandedParameterPack),
2103 ArrayTypeBits.IndexTypeQuals = tq;
2104 ArrayTypeBits.SizeModifier = sm;
2107 friend class ASTContext; // ASTContext creates these.
2110 QualType getElementType() const { return ElementType; }
2111 ArraySizeModifier getSizeModifier() const {
2112 return ArraySizeModifier(ArrayTypeBits.SizeModifier);
2114 Qualifiers getIndexTypeQualifiers() const {
2115 return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
2117 unsigned getIndexTypeCVRQualifiers() const {
2118 return ArrayTypeBits.IndexTypeQuals;
2121 static bool classof(const Type *T) {
2122 return T->getTypeClass() == ConstantArray ||
2123 T->getTypeClass() == VariableArray ||
2124 T->getTypeClass() == IncompleteArray ||
2125 T->getTypeClass() == DependentSizedArray;
2127 static bool classof(const ArrayType *) { return true; }
2130 /// ConstantArrayType - This class represents the canonical version of
2131 /// C arrays with a specified constant size. For example, the canonical
2132 /// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element
2133 /// type is 'int' and the size is 404.
2134 class ConstantArrayType : public ArrayType {
2135 llvm::APInt Size; // Allows us to unique the type.
2137 ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
2138 ArraySizeModifier sm, unsigned tq)
2139 : ArrayType(ConstantArray, et, can, sm, tq,
2140 et->containsUnexpandedParameterPack()),
2143 ConstantArrayType(TypeClass tc, QualType et, QualType can,
2144 const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
2145 : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()),
2147 friend class ASTContext; // ASTContext creates these.
2149 const llvm::APInt &getSize() const { return Size; }
2150 bool isSugared() const { return false; }
2151 QualType desugar() const { return QualType(this, 0); }
2154 /// \brief Determine the number of bits required to address a member of
2155 // an array with the given element type and number of elements.
2156 static unsigned getNumAddressingBits(ASTContext &Context,
2157 QualType ElementType,
2158 const llvm::APInt &NumElements);
2160 /// \brief Determine the maximum number of active bits that an array's size
2161 /// can require, which limits the maximum size of the array.
2162 static unsigned getMaxSizeBits(ASTContext &Context);
2164 void Profile(llvm::FoldingSetNodeID &ID) {
2165 Profile(ID, getElementType(), getSize(),
2166 getSizeModifier(), getIndexTypeCVRQualifiers());
2168 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
2169 const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
2170 unsigned TypeQuals) {
2171 ID.AddPointer(ET.getAsOpaquePtr());
2172 ID.AddInteger(ArraySize.getZExtValue());
2173 ID.AddInteger(SizeMod);
2174 ID.AddInteger(TypeQuals);
2176 static bool classof(const Type *T) {
2177 return T->getTypeClass() == ConstantArray;
2179 static bool classof(const ConstantArrayType *) { return true; }
2182 /// IncompleteArrayType - This class represents C arrays with an unspecified
2183 /// size. For example 'int A[]' has an IncompleteArrayType where the element
2184 /// type is 'int' and the size is unspecified.
2185 class IncompleteArrayType : public ArrayType {
2187 IncompleteArrayType(QualType et, QualType can,
2188 ArraySizeModifier sm, unsigned tq)
2189 : ArrayType(IncompleteArray, et, can, sm, tq,
2190 et->containsUnexpandedParameterPack()) {}
2191 friend class ASTContext; // ASTContext creates these.
2193 bool isSugared() const { return false; }
2194 QualType desugar() const { return QualType(this, 0); }
2196 static bool classof(const Type *T) {
2197 return T->getTypeClass() == IncompleteArray;
2199 static bool classof(const IncompleteArrayType *) { return true; }
2201 friend class StmtIteratorBase;
2203 void Profile(llvm::FoldingSetNodeID &ID) {
2204 Profile(ID, getElementType(), getSizeModifier(),
2205 getIndexTypeCVRQualifiers());
2208 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
2209 ArraySizeModifier SizeMod, unsigned TypeQuals) {
2210 ID.AddPointer(ET.getAsOpaquePtr());
2211 ID.AddInteger(SizeMod);
2212 ID.AddInteger(TypeQuals);
2216 /// VariableArrayType - This class represents C arrays with a specified size
2217 /// which is not an integer-constant-expression. For example, 'int s[x+foo()]'.
2218 /// Since the size expression is an arbitrary expression, we store it as such.
2220 /// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
2221 /// should not be: two lexically equivalent variable array types could mean
2222 /// different things, for example, these variables do not have the same type
2225 /// void foo(int x) {
2231 class VariableArrayType : public ArrayType {
2232 /// SizeExpr - An assignment expression. VLA's are only permitted within
2233 /// a function block.
2235 /// Brackets - The left and right array brackets.
2236 SourceRange Brackets;
2238 VariableArrayType(QualType et, QualType can, Expr *e,
2239 ArraySizeModifier sm, unsigned tq,
2240 SourceRange brackets)
2241 : ArrayType(VariableArray, et, can, sm, tq,
2242 et->containsUnexpandedParameterPack()),
2243 SizeExpr((Stmt*) e), Brackets(brackets) {}
2244 friend class ASTContext; // ASTContext creates these.
2247 Expr *getSizeExpr() const {
2248 // We use C-style casts instead of cast<> here because we do not wish
2249 // to have a dependency of Type.h on Stmt.h/Expr.h.
2250 return (Expr*) SizeExpr;
2252 SourceRange getBracketsRange() const { return Brackets; }
2253 SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
2254 SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
2256 bool isSugared() const { return false; }
2257 QualType desugar() const { return QualType(this, 0); }
2259 static bool classof(const Type *T) {
2260 return T->getTypeClass() == VariableArray;
2262 static bool classof(const VariableArrayType *) { return true; }
2264 friend class StmtIteratorBase;
2266 void Profile(llvm::FoldingSetNodeID &ID) {
2267 llvm_unreachable("Cannot unique VariableArrayTypes.");
2271 /// DependentSizedArrayType - This type represents an array type in
2272 /// C++ whose size is a value-dependent expression. For example:
2275 /// template<typename T, int Size>
2281 /// For these types, we won't actually know what the array bound is
2282 /// until template instantiation occurs, at which point this will
2283 /// become either a ConstantArrayType or a VariableArrayType.
2284 class DependentSizedArrayType : public ArrayType {
2285 const ASTContext &Context;
2287 /// \brief An assignment expression that will instantiate to the
2288 /// size of the array.
2290 /// The expression itself might be NULL, in which case the array
2291 /// type will have its size deduced from an initializer.
2294 /// Brackets - The left and right array brackets.
2295 SourceRange Brackets;
2297 DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can,
2298 Expr *e, ArraySizeModifier sm, unsigned tq,
2299 SourceRange brackets);
2301 friend class ASTContext; // ASTContext creates these.
2304 Expr *getSizeExpr() const {
2305 // We use C-style casts instead of cast<> here because we do not wish
2306 // to have a dependency of Type.h on Stmt.h/Expr.h.
2307 return (Expr*) SizeExpr;
2309 SourceRange getBracketsRange() const { return Brackets; }
2310 SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
2311 SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
2313 bool isSugared() const { return false; }
2314 QualType desugar() const { return QualType(this, 0); }
2316 static bool classof(const Type *T) {
2317 return T->getTypeClass() == DependentSizedArray;
2319 static bool classof(const DependentSizedArrayType *) { return true; }
2321 friend class StmtIteratorBase;
2324 void Profile(llvm::FoldingSetNodeID &ID) {
2325 Profile(ID, Context, getElementType(),
2326 getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
2329 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
2330 QualType ET, ArraySizeModifier SizeMod,
2331 unsigned TypeQuals, Expr *E);
2334 /// DependentSizedExtVectorType - This type represent an extended vector type
2335 /// where either the type or size is dependent. For example:
2337 /// template<typename T, int Size>
2339 /// typedef T __attribute__((ext_vector_type(Size))) type;
2342 class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
2343 const ASTContext &Context;
2345 /// ElementType - The element type of the array.
2346 QualType ElementType;
2349 DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType,
2350 QualType can, Expr *SizeExpr, SourceLocation loc);
2352 friend class ASTContext;
2355 Expr *getSizeExpr() const { return SizeExpr; }
2356 QualType getElementType() const { return ElementType; }
2357 SourceLocation getAttributeLoc() const { return loc; }
2359 bool isSugared() const { return false; }
2360 QualType desugar() const { return QualType(this, 0); }
2362 static bool classof(const Type *T) {
2363 return T->getTypeClass() == DependentSizedExtVector;
2365 static bool classof(const DependentSizedExtVectorType *) { return true; }
2367 void Profile(llvm::FoldingSetNodeID &ID) {
2368 Profile(ID, Context, getElementType(), getSizeExpr());
2371 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
2372 QualType ElementType, Expr *SizeExpr);
2376 /// VectorType - GCC generic vector type. This type is created using
2377 /// __attribute__((vector_size(n)), where "n" specifies the vector size in
2378 /// bytes; or from an Altivec __vector or vector declaration.
2379 /// Since the constructor takes the number of vector elements, the
2380 /// client is responsible for converting the size into the number of elements.
2381 class VectorType : public Type, public llvm::FoldingSetNode {
2384 GenericVector, // not a target-specific vector type
2385 AltiVecVector, // is AltiVec vector
2386 AltiVecPixel, // is AltiVec 'vector Pixel'
2387 AltiVecBool, // is AltiVec 'vector bool ...'
2388 NeonVector, // is ARM Neon vector
2389 NeonPolyVector // is ARM Neon polynomial vector
2392 /// ElementType - The element type of the vector.
2393 QualType ElementType;
2395 VectorType(QualType vecType, unsigned nElements, QualType canonType,
2396 VectorKind vecKind);
2398 VectorType(TypeClass tc, QualType vecType, unsigned nElements,
2399 QualType canonType, VectorKind vecKind);
2401 friend class ASTContext; // ASTContext creates these.
2405 QualType getElementType() const { return ElementType; }
2406 unsigned getNumElements() const { return VectorTypeBits.NumElements; }
2408 bool isSugared() const { return false; }
2409 QualType desugar() const { return QualType(this, 0); }
2411 VectorKind getVectorKind() const {
2412 return VectorKind(VectorTypeBits.VecKind);
2415 void Profile(llvm::FoldingSetNodeID &ID) {
2416 Profile(ID, getElementType(), getNumElements(),
2417 getTypeClass(), getVectorKind());
2419 static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
2420 unsigned NumElements, TypeClass TypeClass,
2421 VectorKind VecKind) {
2422 ID.AddPointer(ElementType.getAsOpaquePtr());
2423 ID.AddInteger(NumElements);
2424 ID.AddInteger(TypeClass);
2425 ID.AddInteger(VecKind);
2428 static bool classof(const Type *T) {
2429 return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
2431 static bool classof(const VectorType *) { return true; }
2434 /// ExtVectorType - Extended vector type. This type is created using
2435 /// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
2436 /// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
2437 /// class enables syntactic extensions, like Vector Components for accessing
2438 /// points, colors, and textures (modeled after OpenGL Shading Language).
2439 class ExtVectorType : public VectorType {
2440 ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
2441 VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
2442 friend class ASTContext; // ASTContext creates these.
2444 static int getPointAccessorIdx(char c) {
2453 static int getNumericAccessorIdx(char c) {
2467 case 'a': return 10;
2469 case 'b': return 11;
2471 case 'c': return 12;
2473 case 'd': return 13;
2475 case 'e': return 14;
2477 case 'f': return 15;
2481 static int getAccessorIdx(char c) {
2482 if (int idx = getPointAccessorIdx(c)+1) return idx-1;
2483 return getNumericAccessorIdx(c);
2486 bool isAccessorWithinNumElements(char c) const {
2487 if (int idx = getAccessorIdx(c)+1)
2488 return unsigned(idx-1) < getNumElements();
2491 bool isSugared() const { return false; }
2492 QualType desugar() const { return QualType(this, 0); }
2494 static bool classof(const Type *T) {
2495 return T->getTypeClass() == ExtVector;
2497 static bool classof(const ExtVectorType *) { return true; }
2500 /// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base
2501 /// class of FunctionNoProtoType and FunctionProtoType.
2503 class FunctionType : public Type {
2504 // The type returned by the function.
2505 QualType ResultType;
2508 /// ExtInfo - A class which abstracts out some details necessary for
2511 /// It is not actually used directly for storing this information in
2512 /// a FunctionType, although FunctionType does currently use the
2513 /// same bit-pattern.
2515 // If you add a field (say Foo), other than the obvious places (both,
2516 // constructors, compile failures), what you need to update is
2520 // * functionType. Add Foo, getFoo.
2521 // * ASTContext::getFooType
2522 // * ASTContext::mergeFunctionTypes
2523 // * FunctionNoProtoType::Profile
2524 // * FunctionProtoType::Profile
2525 // * TypePrinter::PrintFunctionProto
2526 // * AST read and write
2529 // Feel free to rearrange or add bits, but if you go over 8,
2530 // you'll need to adjust both the Bits field below and
2531 // Type::FunctionTypeBitfields.
2533 // | CC |noreturn|produces|regparm|
2534 // |0 .. 2| 3 | 4 | 5 .. 7|
2536 // regparm is either 0 (no regparm attribute) or the regparm value+1.
2537 enum { CallConvMask = 0x7 };
2538 enum { NoReturnMask = 0x8 };
2539 enum { ProducesResultMask = 0x10 };
2540 enum { RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask),
2541 RegParmOffset = 5 }; // Assumed to be the last field
2545 ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
2547 friend class FunctionType;
2550 // Constructor with no defaults. Use this when you know that you
2551 // have all the elements (when reading an AST file for example).
2552 ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
2553 bool producesResult) {
2554 assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
2555 Bits = ((unsigned) cc) |
2556 (noReturn ? NoReturnMask : 0) |
2557 (producesResult ? ProducesResultMask : 0) |
2558 (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0);
2561 // Constructor with all defaults. Use when for example creating a
2562 // function know to use defaults.
2563 ExtInfo() : Bits(0) {}
2565 bool getNoReturn() const { return Bits & NoReturnMask; }
2566 bool getProducesResult() const { return Bits & ProducesResultMask; }
2567 bool getHasRegParm() const { return (Bits >> RegParmOffset) != 0; }
2568 unsigned getRegParm() const {
2569 unsigned RegParm = Bits >> RegParmOffset;
2574 CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
2576 bool operator==(ExtInfo Other) const {
2577 return Bits == Other.Bits;
2579 bool operator!=(ExtInfo Other) const {
2580 return Bits != Other.Bits;
2583 // Note that we don't have setters. That is by design, use
2584 // the following with methods instead of mutating these objects.
2586 ExtInfo withNoReturn(bool noReturn) const {
2588 return ExtInfo(Bits | NoReturnMask);
2590 return ExtInfo(Bits & ~NoReturnMask);
2593 ExtInfo withProducesResult(bool producesResult) const {
2595 return ExtInfo(Bits | ProducesResultMask);
2597 return ExtInfo(Bits & ~ProducesResultMask);
2600 ExtInfo withRegParm(unsigned RegParm) const {
2601 assert(RegParm < 7 && "Invalid regparm value");
2602 return ExtInfo((Bits & ~RegParmMask) |
2603 ((RegParm + 1) << RegParmOffset));
2606 ExtInfo withCallingConv(CallingConv cc) const {
2607 return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
2610 void Profile(llvm::FoldingSetNodeID &ID) const {
2611 ID.AddInteger(Bits);
2616 FunctionType(TypeClass tc, QualType res,
2617 unsigned typeQuals, RefQualifierKind RefQualifier,
2618 QualType Canonical, bool Dependent,
2619 bool InstantiationDependent,
2620 bool VariablyModified, bool ContainsUnexpandedParameterPack,
2622 : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
2623 ContainsUnexpandedParameterPack),
2625 FunctionTypeBits.ExtInfo = Info.Bits;
2626 FunctionTypeBits.TypeQuals = typeQuals;
2627 FunctionTypeBits.RefQualifier = static_cast<unsigned>(RefQualifier);
2629 unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; }
2631 RefQualifierKind getRefQualifier() const {
2632 return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
2637 QualType getResultType() const { return ResultType; }
2639 bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
2640 unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
2641 bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
2642 CallingConv getCallConv() const { return getExtInfo().getCC(); }
2643 ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
2645 /// \brief Determine the type of an expression that calls a function of
2647 QualType getCallResultType(ASTContext &Context) const {
2648 return getResultType().getNonLValueExprType(Context);
2651 static StringRef getNameForCallConv(CallingConv CC);
2653 static bool classof(const Type *T) {
2654 return T->getTypeClass() == FunctionNoProto ||
2655 T->getTypeClass() == FunctionProto;
2657 static bool classof(const FunctionType *) { return true; }
2660 /// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
2661 /// no information available about its arguments.
2662 class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
2663 FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
2664 : FunctionType(FunctionNoProto, Result, 0, RQ_None, Canonical,
2665 /*Dependent=*/false, /*InstantiationDependent=*/false,
2666 Result->isVariablyModifiedType(),
2667 /*ContainsUnexpandedParameterPack=*/false, Info) {}
2669 friend class ASTContext; // ASTContext creates these.
2672 // No additional state past what FunctionType provides.
2674 bool isSugared() const { return false; }
2675 QualType desugar() const { return QualType(this, 0); }
2677 void Profile(llvm::FoldingSetNodeID &ID) {
2678 Profile(ID, getResultType(), getExtInfo());
2680 static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
2683 ID.AddPointer(ResultType.getAsOpaquePtr());
2686 static bool classof(const Type *T) {
2687 return T->getTypeClass() == FunctionNoProto;
2689 static bool classof(const FunctionNoProtoType *) { return true; }
2692 /// FunctionProtoType - Represents a prototype with argument type info, e.g.
2693 /// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no
2694 /// arguments, not as having a single void argument. Such a type can have an
2695 /// exception specification, but this specification is not part of the canonical
2697 class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
2699 /// ExtProtoInfo - Extra information about a function prototype.
2700 struct ExtProtoInfo {
2702 Variadic(false), HasTrailingReturn(false), TypeQuals(0),
2703 ExceptionSpecType(EST_None), RefQualifier(RQ_None),
2704 NumExceptions(0), Exceptions(0), NoexceptExpr(0),
2705 ExceptionSpecDecl(0), ExceptionSpecTemplate(0),
2706 ConsumedArguments(0) {}
2708 FunctionType::ExtInfo ExtInfo;
2710 bool HasTrailingReturn : 1;
2711 unsigned char TypeQuals;
2712 ExceptionSpecificationType ExceptionSpecType;
2713 RefQualifierKind RefQualifier;
2714 unsigned NumExceptions;
2715 const QualType *Exceptions;
2717 FunctionDecl *ExceptionSpecDecl;
2718 FunctionDecl *ExceptionSpecTemplate;
2719 const bool *ConsumedArguments;
2723 /// \brief Determine whether there are any argument types that
2724 /// contain an unexpanded parameter pack.
2725 static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
2727 for (unsigned Idx = 0; Idx < numArgs; ++Idx)
2728 if (ArgArray[Idx]->containsUnexpandedParameterPack())
2734 FunctionProtoType(QualType result, const QualType *args, unsigned numArgs,
2735 QualType canonical, const ExtProtoInfo &epi);
2737 /// NumArgs - The number of arguments this function has, not counting '...'.
2738 unsigned NumArgs : 17;
2740 /// NumExceptions - The number of types in the exception spec, if any.
2741 unsigned NumExceptions : 9;
2743 /// ExceptionSpecType - The type of exception specification this function has.
2744 unsigned ExceptionSpecType : 3;
2746 /// HasAnyConsumedArgs - Whether this function has any consumed arguments.
2747 unsigned HasAnyConsumedArgs : 1;
2749 /// Variadic - Whether the function is variadic.
2750 unsigned Variadic : 1;
2752 /// HasTrailingReturn - Whether this function has a trailing return type.
2753 unsigned HasTrailingReturn : 1;
2755 // ArgInfo - There is an variable size array after the class in memory that
2756 // holds the argument types.
2758 // Exceptions - There is another variable size array after ArgInfo that
2759 // holds the exception types.
2761 // NoexceptExpr - Instead of Exceptions, there may be a single Expr* pointing
2762 // to the expression in the noexcept() specifier.
2764 // ExceptionSpecDecl, ExceptionSpecTemplate - Instead of Exceptions, there may
2765 // be a pair of FunctionDecl* pointing to the function which should be used to
2766 // instantiate this function type's exception specification, and the function
2767 // from which it should be instantiated.
2769 // ConsumedArgs - A variable size array, following Exceptions
2770 // and of length NumArgs, holding flags indicating which arguments
2771 // are consumed. This only appears if HasAnyConsumedArgs is true.
2773 friend class ASTContext; // ASTContext creates these.
2775 const bool *getConsumedArgsBuffer() const {
2776 assert(hasAnyConsumedArgs());
2778 // Find the end of the exceptions.
2779 Expr * const *eh_end = reinterpret_cast<Expr * const *>(arg_type_end());
2780 if (getExceptionSpecType() != EST_ComputedNoexcept)
2781 eh_end += NumExceptions;
2783 eh_end += 1; // NoexceptExpr
2785 return reinterpret_cast<const bool*>(eh_end);
2789 unsigned getNumArgs() const { return NumArgs; }
2790 QualType getArgType(unsigned i) const {
2791 assert(i < NumArgs && "Invalid argument number!");
2792 return arg_type_begin()[i];
2795 ExtProtoInfo getExtProtoInfo() const {
2797 EPI.ExtInfo = getExtInfo();
2798 EPI.Variadic = isVariadic();
2799 EPI.HasTrailingReturn = hasTrailingReturn();
2800 EPI.ExceptionSpecType = getExceptionSpecType();
2801 EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals());
2802 EPI.RefQualifier = getRefQualifier();
2803 if (EPI.ExceptionSpecType == EST_Dynamic) {
2804 EPI.NumExceptions = NumExceptions;
2805 EPI.Exceptions = exception_begin();
2806 } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) {
2807 EPI.NoexceptExpr = getNoexceptExpr();
2808 } else if (EPI.ExceptionSpecType == EST_Uninstantiated) {
2809 EPI.ExceptionSpecDecl = getExceptionSpecDecl();
2810 EPI.ExceptionSpecTemplate = getExceptionSpecTemplate();
2812 if (hasAnyConsumedArgs())
2813 EPI.ConsumedArguments = getConsumedArgsBuffer();
2817 /// \brief Get the kind of exception specification on this function.
2818 ExceptionSpecificationType getExceptionSpecType() const {
2819 return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
2821 /// \brief Return whether this function has any kind of exception spec.
2822 bool hasExceptionSpec() const {
2823 return getExceptionSpecType() != EST_None;
2825 /// \brief Return whether this function has a dynamic (throw) exception spec.
2826 bool hasDynamicExceptionSpec() const {
2827 return isDynamicExceptionSpec(getExceptionSpecType());
2829 /// \brief Return whether this function has a noexcept exception spec.
2830 bool hasNoexceptExceptionSpec() const {
2831 return isNoexceptExceptionSpec(getExceptionSpecType());
2833 /// \brief Result type of getNoexceptSpec().
2834 enum NoexceptResult {
2835 NR_NoNoexcept, ///< There is no noexcept specifier.
2836 NR_BadNoexcept, ///< The noexcept specifier has a bad expression.
2837 NR_Dependent, ///< The noexcept specifier is dependent.
2838 NR_Throw, ///< The noexcept specifier evaluates to false.
2839 NR_Nothrow ///< The noexcept specifier evaluates to true.
2841 /// \brief Get the meaning of the noexcept spec on this function, if any.
2842 NoexceptResult getNoexceptSpec(ASTContext &Ctx) const;
2843 unsigned getNumExceptions() const { return NumExceptions; }
2844 QualType getExceptionType(unsigned i) const {
2845 assert(i < NumExceptions && "Invalid exception number!");
2846 return exception_begin()[i];
2848 Expr *getNoexceptExpr() const {
2849 if (getExceptionSpecType() != EST_ComputedNoexcept)
2851 // NoexceptExpr sits where the arguments end.
2852 return *reinterpret_cast<Expr *const *>(arg_type_end());
2854 /// \brief If this function type has an uninstantiated exception
2855 /// specification, this is the function whose exception specification
2856 /// is represented by this type.
2857 FunctionDecl *getExceptionSpecDecl() const {
2858 if (getExceptionSpecType() != EST_Uninstantiated)
2860 return reinterpret_cast<FunctionDecl * const *>(arg_type_end())[0];
2862 /// \brief If this function type has an uninstantiated exception
2863 /// specification, this is the function whose exception specification
2864 /// should be instantiated to find the exception specification for
2866 FunctionDecl *getExceptionSpecTemplate() const {
2867 if (getExceptionSpecType() != EST_Uninstantiated)
2869 return reinterpret_cast<FunctionDecl * const *>(arg_type_end())[1];
2871 bool isNothrow(ASTContext &Ctx) const {
2872 ExceptionSpecificationType EST = getExceptionSpecType();
2873 assert(EST != EST_Delayed && EST != EST_Uninstantiated);
2874 if (EST == EST_DynamicNone || EST == EST_BasicNoexcept)
2876 if (EST != EST_ComputedNoexcept)
2878 return getNoexceptSpec(Ctx) == NR_Nothrow;
2881 bool isVariadic() const { return Variadic; }
2883 /// \brief Determines whether this function prototype contains a
2884 /// parameter pack at the end.
2886 /// A function template whose last parameter is a parameter pack can be
2887 /// called with an arbitrary number of arguments, much like a variadic
2889 bool isTemplateVariadic() const;
2891 bool hasTrailingReturn() const { return HasTrailingReturn; }
2893 unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
2896 /// \brief Retrieve the ref-qualifier associated with this function type.
2897 RefQualifierKind getRefQualifier() const {
2898 return FunctionType::getRefQualifier();
2901 typedef const QualType *arg_type_iterator;
2902 arg_type_iterator arg_type_begin() const {
2903 return reinterpret_cast<const QualType *>(this+1);
2905 arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
2907 typedef const QualType *exception_iterator;
2908 exception_iterator exception_begin() const {
2909 // exceptions begin where arguments end
2910 return arg_type_end();
2912 exception_iterator exception_end() const {
2913 if (getExceptionSpecType() != EST_Dynamic)
2914 return exception_begin();
2915 return exception_begin() + NumExceptions;
2918 bool hasAnyConsumedArgs() const {
2919 return HasAnyConsumedArgs;
2921 bool isArgConsumed(unsigned I) const {
2922 assert(I < getNumArgs() && "argument index out of range!");
2923 if (hasAnyConsumedArgs())
2924 return getConsumedArgsBuffer()[I];
2928 bool isSugared() const { return false; }
2929 QualType desugar() const { return QualType(this, 0); }
2931 void printExceptionSpecification(std::string &S,
2932 PrintingPolicy Policy) const;
2934 static bool classof(const Type *T) {
2935 return T->getTypeClass() == FunctionProto;
2937 static bool classof(const FunctionProtoType *) { return true; }
2939 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
2940 static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
2941 arg_type_iterator ArgTys, unsigned NumArgs,
2942 const ExtProtoInfo &EPI, const ASTContext &Context);
2946 /// \brief Represents the dependent type named by a dependently-scoped
2947 /// typename using declaration, e.g.
2948 /// using typename Base<T>::foo;
2949 /// Template instantiation turns these into the underlying type.
2950 class UnresolvedUsingType : public Type {
2951 UnresolvedUsingTypenameDecl *Decl;
2953 UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D)
2954 : Type(UnresolvedUsing, QualType(), true, true, false,
2955 /*ContainsUnexpandedParameterPack=*/false),
2956 Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {}
2957 friend class ASTContext; // ASTContext creates these.
2960 UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
2962 bool isSugared() const { return false; }
2963 QualType desugar() const { return QualType(this, 0); }
2965 static bool classof(const Type *T) {
2966 return T->getTypeClass() == UnresolvedUsing;
2968 static bool classof(const UnresolvedUsingType *) { return true; }
2970 void Profile(llvm::FoldingSetNodeID &ID) {
2971 return Profile(ID, Decl);
2973 static void Profile(llvm::FoldingSetNodeID &ID,
2974 UnresolvedUsingTypenameDecl *D) {
2980 class TypedefType : public Type {
2981 TypedefNameDecl *Decl;
2983 TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can)
2984 : Type(tc, can, can->isDependentType(),
2985 can->isInstantiationDependentType(),
2986 can->isVariablyModifiedType(),
2987 /*ContainsUnexpandedParameterPack=*/false),
2988 Decl(const_cast<TypedefNameDecl*>(D)) {
2989 assert(!isa<TypedefType>(can) && "Invalid canonical type");
2991 friend class ASTContext; // ASTContext creates these.
2994 TypedefNameDecl *getDecl() const { return Decl; }
2996 bool isSugared() const { return true; }
2997 QualType desugar() const;
2999 static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
3000 static bool classof(const TypedefType *) { return true; }
3003 /// TypeOfExprType (GCC extension).
3004 class TypeOfExprType : public Type {
3008 TypeOfExprType(Expr *E, QualType can = QualType());
3009 friend class ASTContext; // ASTContext creates these.
3011 Expr *getUnderlyingExpr() const { return TOExpr; }
3013 /// \brief Remove a single level of sugar.
3014 QualType desugar() const;
3016 /// \brief Returns whether this type directly provides sugar.
3017 bool isSugared() const;
3019 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
3020 static bool classof(const TypeOfExprType *) { return true; }
3023 /// \brief Internal representation of canonical, dependent
3024 /// typeof(expr) types.
3026 /// This class is used internally by the ASTContext to manage
3027 /// canonical, dependent types, only. Clients will only see instances
3028 /// of this class via TypeOfExprType nodes.
3029 class DependentTypeOfExprType
3030 : public TypeOfExprType, public llvm::FoldingSetNode {
3031 const ASTContext &Context;
3034 DependentTypeOfExprType(const ASTContext &Context, Expr *E)
3035 : TypeOfExprType(E), Context(Context) { }
3037 void Profile(llvm::FoldingSetNodeID &ID) {
3038 Profile(ID, Context, getUnderlyingExpr());
3041 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3045 /// TypeOfType (GCC extension).
3046 class TypeOfType : public Type {
3048 TypeOfType(QualType T, QualType can)
3049 : Type(TypeOf, can, T->isDependentType(),
3050 T->isInstantiationDependentType(),
3051 T->isVariablyModifiedType(),
3052 T->containsUnexpandedParameterPack()),
3054 assert(!isa<TypedefType>(can) && "Invalid canonical type");
3056 friend class ASTContext; // ASTContext creates these.
3058 QualType getUnderlyingType() const { return TOType; }
3060 /// \brief Remove a single level of sugar.
3061 QualType desugar() const { return getUnderlyingType(); }
3063 /// \brief Returns whether this type directly provides sugar.
3064 bool isSugared() const { return true; }
3066 static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
3067 static bool classof(const TypeOfType *) { return true; }
3070 /// DecltypeType (C++0x)
3071 class DecltypeType : public Type {
3073 QualType UnderlyingType;
3076 DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
3077 friend class ASTContext; // ASTContext creates these.
3079 Expr *getUnderlyingExpr() const { return E; }
3080 QualType getUnderlyingType() const { return UnderlyingType; }
3082 /// \brief Remove a single level of sugar.
3083 QualType desugar() const;
3085 /// \brief Returns whether this type directly provides sugar.
3086 bool isSugared() const;
3088 static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
3089 static bool classof(const DecltypeType *) { return true; }
3092 /// \brief Internal representation of canonical, dependent
3093 /// decltype(expr) types.
3095 /// This class is used internally by the ASTContext to manage
3096 /// canonical, dependent types, only. Clients will only see instances
3097 /// of this class via DecltypeType nodes.
3098 class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
3099 const ASTContext &Context;
3102 DependentDecltypeType(const ASTContext &Context, Expr *E);
3104 void Profile(llvm::FoldingSetNodeID &ID) {
3105 Profile(ID, Context, getUnderlyingExpr());
3108 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3112 /// \brief A unary type transform, which is a type constructed from another
3113 class UnaryTransformType : public Type {
3120 /// The untransformed type.
3122 /// The transformed type if not dependent, otherwise the same as BaseType.
3123 QualType UnderlyingType;
3127 UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind,
3128 QualType CanonicalTy);
3129 friend class ASTContext;
3131 bool isSugared() const { return !isDependentType(); }
3132 QualType desugar() const { return UnderlyingType; }
3134 QualType getUnderlyingType() const { return UnderlyingType; }
3135 QualType getBaseType() const { return BaseType; }
3137 UTTKind getUTTKind() const { return UKind; }
3139 static bool classof(const Type *T) {
3140 return T->getTypeClass() == UnaryTransform;
3142 static bool classof(const UnaryTransformType *) { return true; }
3145 class TagType : public Type {
3146 /// Stores the TagDecl associated with this type. The decl may point to any
3147 /// TagDecl that declares the entity.
3150 friend class ASTReader;
3153 TagType(TypeClass TC, const TagDecl *D, QualType can);
3156 TagDecl *getDecl() const;
3158 /// @brief Determines whether this type is in the process of being
3160 bool isBeingDefined() const;
3162 static bool classof(const Type *T) {
3163 return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
3165 static bool classof(const TagType *) { return true; }
3168 /// RecordType - This is a helper class that allows the use of isa/cast/dyncast
3169 /// to detect TagType objects of structs/unions/classes.
3170 class RecordType : public TagType {
3172 explicit RecordType(const RecordDecl *D)
3173 : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { }
3174 explicit RecordType(TypeClass TC, RecordDecl *D)
3175 : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { }
3176 friend class ASTContext; // ASTContext creates these.
3179 RecordDecl *getDecl() const {
3180 return reinterpret_cast<RecordDecl*>(TagType::getDecl());
3183 // FIXME: This predicate is a helper to QualType/Type. It needs to
3184 // recursively check all fields for const-ness. If any field is declared
3185 // const, it needs to return false.
3186 bool hasConstFields() const { return false; }
3188 bool isSugared() const { return false; }
3189 QualType desugar() const { return QualType(this, 0); }
3191 static bool classof(const Type *T) { return T->getTypeClass() == Record; }
3192 static bool classof(const RecordType *) { return true; }
3195 /// EnumType - This is a helper class that allows the use of isa/cast/dyncast
3196 /// to detect TagType objects of enums.
3197 class EnumType : public TagType {
3198 explicit EnumType(const EnumDecl *D)
3199 : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { }
3200 friend class ASTContext; // ASTContext creates these.
3203 EnumDecl *getDecl() const {
3204 return reinterpret_cast<EnumDecl*>(TagType::getDecl());
3207 bool isSugared() const { return false; }
3208 QualType desugar() const { return QualType(this, 0); }
3210 static bool classof(const Type *T) { return T->getTypeClass() == Enum; }
3211 static bool classof(const EnumType *) { return true; }
3214 /// AttributedType - An attributed type is a type to which a type
3215 /// attribute has been applied. The "modified type" is the
3216 /// fully-sugared type to which the attributed type was applied;
3217 /// generally it is not canonically equivalent to the attributed type.
3218 /// The "equivalent type" is the minimally-desugared type which the
3219 /// type is canonically equivalent to.
3221 /// For example, in the following attributed type:
3222 /// int32_t __attribute__((vector_size(16)))
3223 /// - the modified type is the TypedefType for int32_t
3224 /// - the equivalent type is VectorType(16, int32_t)
3225 /// - the canonical type is VectorType(16, int)
3226 class AttributedType : public Type, public llvm::FoldingSetNode {
3228 // It is really silly to have yet another attribute-kind enum, but
3229 // clang::attr::Kind doesn't currently cover the pure type attrs.
3231 // Expression operand.
3235 attr_neon_vector_type,
3236 attr_neon_polyvector_type,
3238 FirstExprOperandKind = attr_address_space,
3239 LastExprOperandKind = attr_neon_polyvector_type,
3241 // Enumerated operand (string or keyword).
3243 attr_objc_ownership,
3246 FirstEnumOperandKind = attr_objc_gc,
3247 LastEnumOperandKind = attr_pcs,
3259 QualType ModifiedType;
3260 QualType EquivalentType;
3262 friend class ASTContext; // creates these
3264 AttributedType(QualType canon, Kind attrKind,
3265 QualType modified, QualType equivalent)
3266 : Type(Attributed, canon, canon->isDependentType(),
3267 canon->isInstantiationDependentType(),
3268 canon->isVariablyModifiedType(),
3269 canon->containsUnexpandedParameterPack()),
3270 ModifiedType(modified), EquivalentType(equivalent) {
3271 AttributedTypeBits.AttrKind = attrKind;
3275 Kind getAttrKind() const {
3276 return static_cast<Kind>(AttributedTypeBits.AttrKind);
3279 QualType getModifiedType() const { return ModifiedType; }
3280 QualType getEquivalentType() const { return EquivalentType; }
3282 bool isSugared() const { return true; }
3283 QualType desugar() const { return getEquivalentType(); }
3285 void Profile(llvm::FoldingSetNodeID &ID) {
3286 Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
3289 static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind,
3290 QualType modified, QualType equivalent) {
3291 ID.AddInteger(attrKind);
3292 ID.AddPointer(modified.getAsOpaquePtr());
3293 ID.AddPointer(equivalent.getAsOpaquePtr());
3296 static bool classof(const Type *T) {
3297 return T->getTypeClass() == Attributed;
3299 static bool classof(const AttributedType *T) { return true; }
3302 class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
3303 // Helper data collector for canonical types.
3304 struct CanonicalTTPTInfo {
3305 unsigned Depth : 15;
3306 unsigned ParameterPack : 1;
3307 unsigned Index : 16;
3311 // Info for the canonical type.
3312 CanonicalTTPTInfo CanTTPTInfo;
3313 // Info for the non-canonical type.
3314 TemplateTypeParmDecl *TTPDecl;
3317 /// Build a non-canonical type.
3318 TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon)
3319 : Type(TemplateTypeParm, Canon, /*Dependent=*/true,
3320 /*InstantiationDependent=*/true,
3321 /*VariablyModified=*/false,
3322 Canon->containsUnexpandedParameterPack()),
3323 TTPDecl(TTPDecl) { }
3325 /// Build the canonical type.
3326 TemplateTypeParmType(unsigned D, unsigned I, bool PP)
3327 : Type(TemplateTypeParm, QualType(this, 0),
3329 /*InstantiationDependent=*/true,
3330 /*VariablyModified=*/false, PP) {
3331 CanTTPTInfo.Depth = D;
3332 CanTTPTInfo.Index = I;
3333 CanTTPTInfo.ParameterPack = PP;
3336 friend class ASTContext; // ASTContext creates these
3338 const CanonicalTTPTInfo& getCanTTPTInfo() const {
3339 QualType Can = getCanonicalTypeInternal();
3340 return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo;
3344 unsigned getDepth() const { return getCanTTPTInfo().Depth; }
3345 unsigned getIndex() const { return getCanTTPTInfo().Index; }
3346 bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; }
3348 TemplateTypeParmDecl *getDecl() const {
3349 return isCanonicalUnqualified() ? 0 : TTPDecl;
3352 IdentifierInfo *getIdentifier() const;
3354 bool isSugared() const { return false; }
3355 QualType desugar() const { return QualType(this, 0); }
3357 void Profile(llvm::FoldingSetNodeID &ID) {
3358 Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
3361 static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
3362 unsigned Index, bool ParameterPack,
3363 TemplateTypeParmDecl *TTPDecl) {
3364 ID.AddInteger(Depth);
3365 ID.AddInteger(Index);
3366 ID.AddBoolean(ParameterPack);
3367 ID.AddPointer(TTPDecl);
3370 static bool classof(const Type *T) {
3371 return T->getTypeClass() == TemplateTypeParm;
3373 static bool classof(const TemplateTypeParmType *T) { return true; }
3376 /// \brief Represents the result of substituting a type for a template
3379 /// Within an instantiated template, all template type parameters have
3380 /// been replaced with these. They are used solely to record that a
3381 /// type was originally written as a template type parameter;
3382 /// therefore they are never canonical.
3383 class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
3384 // The original type parameter.
3385 const TemplateTypeParmType *Replaced;
3387 SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon)
3388 : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
3389 Canon->isInstantiationDependentType(),
3390 Canon->isVariablyModifiedType(),
3391 Canon->containsUnexpandedParameterPack()),
3394 friend class ASTContext;
3397 /// Gets the template parameter that was substituted for.
3398 const TemplateTypeParmType *getReplacedParameter() const {
3402 /// Gets the type that was substituted for the template
3404 QualType getReplacementType() const {
3405 return getCanonicalTypeInternal();
3408 bool isSugared() const { return true; }
3409 QualType desugar() const { return getReplacementType(); }
3411 void Profile(llvm::FoldingSetNodeID &ID) {
3412 Profile(ID, getReplacedParameter(), getReplacementType());
3414 static void Profile(llvm::FoldingSetNodeID &ID,
3415 const TemplateTypeParmType *Replaced,
3416 QualType Replacement) {
3417 ID.AddPointer(Replaced);
3418 ID.AddPointer(Replacement.getAsOpaquePtr());
3421 static bool classof(const Type *T) {
3422 return T->getTypeClass() == SubstTemplateTypeParm;
3424 static bool classof(const SubstTemplateTypeParmType *T) { return true; }
3427 /// \brief Represents the result of substituting a set of types for a template
3428 /// type parameter pack.
3430 /// When a pack expansion in the source code contains multiple parameter packs
3431 /// and those parameter packs correspond to different levels of template
3432 /// parameter lists, this type node is used to represent a template type
3433 /// parameter pack from an outer level, which has already had its argument pack
3434 /// substituted but that still lives within a pack expansion that itself
3435 /// could not be instantiated. When actually performing a substitution into
3436 /// that pack expansion (e.g., when all template parameters have corresponding
3437 /// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
3438 /// at the current pack substitution index.
3439 class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
3440 /// \brief The original type parameter.
3441 const TemplateTypeParmType *Replaced;
3443 /// \brief A pointer to the set of template arguments that this
3444 /// parameter pack is instantiated with.
3445 const TemplateArgument *Arguments;
3447 /// \brief The number of template arguments in \c Arguments.
3448 unsigned NumArguments;
3450 SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param,
3452 const TemplateArgument &ArgPack);
3454 friend class ASTContext;
3457 IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); }
3459 /// Gets the template parameter that was substituted for.
3460 const TemplateTypeParmType *getReplacedParameter() const {
3464 bool isSugared() const { return false; }
3465 QualType desugar() const { return QualType(this, 0); }
3467 TemplateArgument getArgumentPack() const;
3469 void Profile(llvm::FoldingSetNodeID &ID);
3470 static void Profile(llvm::FoldingSetNodeID &ID,
3471 const TemplateTypeParmType *Replaced,
3472 const TemplateArgument &ArgPack);
3474 static bool classof(const Type *T) {
3475 return T->getTypeClass() == SubstTemplateTypeParmPack;
3477 static bool classof(const SubstTemplateTypeParmPackType *T) { return true; }
3480 /// \brief Represents a C++0x auto type.
3482 /// These types are usually a placeholder for a deduced type. However, within
3483 /// templates and before the initializer is attached, there is no deduced type
3484 /// and an auto type is type-dependent and canonical.
3485 class AutoType : public Type, public llvm::FoldingSetNode {
3486 AutoType(QualType DeducedType)
3487 : Type(Auto, DeducedType.isNull() ? QualType(this, 0) : DeducedType,
3488 /*Dependent=*/DeducedType.isNull(),
3489 /*InstantiationDependent=*/DeducedType.isNull(),
3490 /*VariablyModified=*/false, /*ContainsParameterPack=*/false) {
3491 assert((DeducedType.isNull() || !DeducedType->isDependentType()) &&
3492 "deduced a dependent type for auto");
3495 friend class ASTContext; // ASTContext creates these
3498 bool isSugared() const { return isDeduced(); }
3499 QualType desugar() const { return getCanonicalTypeInternal(); }
3501 QualType getDeducedType() const {
3502 return isDeduced() ? getCanonicalTypeInternal() : QualType();
3504 bool isDeduced() const {
3505 return !isDependentType();
3508 void Profile(llvm::FoldingSetNodeID &ID) {
3509 Profile(ID, getDeducedType());
3512 static void Profile(llvm::FoldingSetNodeID &ID,
3514 ID.AddPointer(Deduced.getAsOpaquePtr());
3517 static bool classof(const Type *T) {
3518 return T->getTypeClass() == Auto;
3520 static bool classof(const AutoType *T) { return true; }
3523 /// \brief Represents a type template specialization; the template
3524 /// must be a class template, a type alias template, or a template
3525 /// template parameter. A template which cannot be resolved to one of
3526 /// these, e.g. because it is written with a dependent scope
3527 /// specifier, is instead represented as a
3528 /// @c DependentTemplateSpecializationType.
3530 /// A non-dependent template specialization type is always "sugar",
3531 /// typically for a @c RecordType. For example, a class template
3532 /// specialization type of @c vector<int> will refer to a tag type for
3533 /// the instantiation @c std::vector<int, std::allocator<int>>
3535 /// Template specializations are dependent if either the template or
3536 /// any of the template arguments are dependent, in which case the
3537 /// type may also be canonical.
3539 /// Instances of this type are allocated with a trailing array of
3540 /// TemplateArguments, followed by a QualType representing the
3541 /// non-canonical aliased type when the template is a type alias
3543 class TemplateSpecializationType
3544 : public Type, public llvm::FoldingSetNode {
3545 /// \brief The name of the template being specialized. This is
3546 /// either a TemplateName::Template (in which case it is a
3547 /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a
3548 /// TypeAliasTemplateDecl*), a
3549 /// TemplateName::SubstTemplateTemplateParmPack, or a
3550 /// TemplateName::SubstTemplateTemplateParm (in which case the
3551 /// replacement must, recursively, be one of these).
3552 TemplateName Template;
3554 /// \brief - The number of template arguments named in this class
3555 /// template specialization.
3556 unsigned NumArgs : 31;
3558 /// \brief Whether this template specialization type is a substituted
3562 TemplateSpecializationType(TemplateName T,
3563 const TemplateArgument *Args,
3564 unsigned NumArgs, QualType Canon,
3567 friend class ASTContext; // ASTContext creates these
3570 /// \brief Determine whether any of the given template arguments are
3572 static bool anyDependentTemplateArguments(const TemplateArgument *Args,
3574 bool &InstantiationDependent);
3576 static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args,
3578 bool &InstantiationDependent);
3580 static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &,
3581 bool &InstantiationDependent);
3583 /// \brief Print a template argument list, including the '<' and '>'
3584 /// enclosing the template arguments.
3585 static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
3587 const PrintingPolicy &Policy,
3588 bool SkipBrackets = false);
3590 static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args,
3592 const PrintingPolicy &Policy);
3594 static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
3595 const PrintingPolicy &Policy);
3597 /// True if this template specialization type matches a current
3598 /// instantiation in the context in which it is found.
3599 bool isCurrentInstantiation() const {
3600 return isa<InjectedClassNameType>(getCanonicalTypeInternal());
3603 /// \brief Determine if this template specialization type is for a type alias
3604 /// template that has been substituted.
3606 /// Nearly every template specialization type whose template is an alias
3607 /// template will be substituted. However, this is not the case when
3608 /// the specialization contains a pack expansion but the template alias
3609 /// does not have a corresponding parameter pack, e.g.,
3612 /// template<typename T, typename U, typename V> struct S;
3613 /// template<typename T, typename U> using A = S<T, int, U>;
3614 /// template<typename... Ts> struct X {
3615 /// typedef A<Ts...> type; // not a type alias
3618 bool isTypeAlias() const { return TypeAlias; }
3620 /// Get the aliased type, if this is a specialization of a type alias
3622 QualType getAliasedType() const {
3623 assert(isTypeAlias() && "not a type alias template specialization");
3624 return *reinterpret_cast<const QualType*>(end());
3627 typedef const TemplateArgument * iterator;
3629 iterator begin() const { return getArgs(); }
3630 iterator end() const; // defined inline in TemplateBase.h
3632 /// \brief Retrieve the name of the template that we are specializing.
3633 TemplateName getTemplateName() const { return Template; }
3635 /// \brief Retrieve the template arguments.
3636 const TemplateArgument *getArgs() const {
3637 return reinterpret_cast<const TemplateArgument *>(this + 1);
3640 /// \brief Retrieve the number of template arguments.
3641 unsigned getNumArgs() const { return NumArgs; }
3643 /// \brief Retrieve a specific template argument as a type.
3644 /// \precondition @c isArgType(Arg)
3645 const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
3647 bool isSugared() const {
3648 return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
3650 QualType desugar() const { return getCanonicalTypeInternal(); }
3652 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
3653 Profile(ID, Template, getArgs(), NumArgs, Ctx);
3655 getAliasedType().Profile(ID);
3658 static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
3659 const TemplateArgument *Args,
3661 const ASTContext &Context);
3663 static bool classof(const Type *T) {
3664 return T->getTypeClass() == TemplateSpecialization;
3666 static bool classof(const TemplateSpecializationType *T) { return true; }
3669 /// \brief The injected class name of a C++ class template or class
3670 /// template partial specialization. Used to record that a type was
3671 /// spelled with a bare identifier rather than as a template-id; the
3672 /// equivalent for non-templated classes is just RecordType.
3674 /// Injected class name types are always dependent. Template
3675 /// instantiation turns these into RecordTypes.
3677 /// Injected class name types are always canonical. This works
3678 /// because it is impossible to compare an injected class name type
3679 /// with the corresponding non-injected template type, for the same
3680 /// reason that it is impossible to directly compare template
3681 /// parameters from different dependent contexts: injected class name
3682 /// types can only occur within the scope of a particular templated
3683 /// declaration, and within that scope every template specialization
3684 /// will canonicalize to the injected class name (when appropriate
3685 /// according to the rules of the language).
3686 class InjectedClassNameType : public Type {
3687 CXXRecordDecl *Decl;
3689 /// The template specialization which this type represents.
3691 /// template <class T> class A { ... };
3692 /// this is A<T>, whereas in
3693 /// template <class X, class Y> class A<B<X,Y> > { ... };
3694 /// this is A<B<X,Y> >.
3696 /// It is always unqualified, always a template specialization type,
3697 /// and always dependent.
3698 QualType InjectedType;
3700 friend class ASTContext; // ASTContext creates these.
3701 friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
3702 // currently suitable for AST reading, too much
3703 // interdependencies.
3704 InjectedClassNameType(CXXRecordDecl *D, QualType TST)
3705 : Type(InjectedClassName, QualType(), /*Dependent=*/true,
3706 /*InstantiationDependent=*/true,
3707 /*VariablyModified=*/false,
3708 /*ContainsUnexpandedParameterPack=*/false),
3709 Decl(D), InjectedType(TST) {
3710 assert(isa<TemplateSpecializationType>(TST));
3711 assert(!TST.hasQualifiers());
3712 assert(TST->isDependentType());
3716 QualType getInjectedSpecializationType() const { return InjectedType; }
3717 const TemplateSpecializationType *getInjectedTST() const {
3718 return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
3721 CXXRecordDecl *getDecl() const;
3723 bool isSugared() const { return false; }
3724 QualType desugar() const { return QualType(this, 0); }
3726 static bool classof(const Type *T) {
3727 return T->getTypeClass() == InjectedClassName;
3729 static bool classof(const InjectedClassNameType *T) { return true; }
3732 /// \brief The kind of a tag type.
3734 /// \brief The "struct" keyword.
3736 /// \brief The "union" keyword.
3738 /// \brief The "class" keyword.
3740 /// \brief The "enum" keyword.
3744 /// \brief The elaboration keyword that precedes a qualified type name or
3745 /// introduces an elaborated-type-specifier.
3746 enum ElaboratedTypeKeyword {
3747 /// \brief The "struct" keyword introduces the elaborated-type-specifier.
3749 /// \brief The "union" keyword introduces the elaborated-type-specifier.
3751 /// \brief The "class" keyword introduces the elaborated-type-specifier.
3753 /// \brief The "enum" keyword introduces the elaborated-type-specifier.
3755 /// \brief The "typename" keyword precedes the qualified type name, e.g.,
3756 /// \c typename T::type.
3758 /// \brief No keyword precedes the qualified type name.
3762 /// A helper class for Type nodes having an ElaboratedTypeKeyword.
3763 /// The keyword in stored in the free bits of the base class.
3764 /// Also provides a few static helpers for converting and printing
3765 /// elaborated type keyword and tag type kind enumerations.
3766 class TypeWithKeyword : public Type {
3768 TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc,
3769 QualType Canonical, bool Dependent,
3770 bool InstantiationDependent, bool VariablyModified,
3771 bool ContainsUnexpandedParameterPack)
3772 : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
3773 ContainsUnexpandedParameterPack) {
3774 TypeWithKeywordBits.Keyword = Keyword;
3778 ElaboratedTypeKeyword getKeyword() const {
3779 return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
3782 /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST)
3783 /// into an elaborated type keyword.
3784 static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
3786 /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST)
3787 /// into a tag type kind. It is an error to provide a type specifier
3788 /// which *isn't* a tag kind here.
3789 static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
3791 /// getKeywordForTagDeclKind - Converts a TagTypeKind into an
3792 /// elaborated type keyword.
3793 static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
3795 /// getTagTypeKindForKeyword - Converts an elaborated type keyword into
3796 // a TagTypeKind. It is an error to provide an elaborated type keyword
3797 /// which *isn't* a tag kind here.
3798 static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
3800 static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
3802 static const char *getKeywordName(ElaboratedTypeKeyword Keyword);
3804 static const char *getTagTypeKindName(TagTypeKind Kind) {
3805 return getKeywordName(getKeywordForTagTypeKind(Kind));
3808 class CannotCastToThisType {};
3809 static CannotCastToThisType classof(const Type *);
3812 /// \brief Represents a type that was referred to using an elaborated type
3813 /// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
3816 /// This type is used to keep track of a type name as written in the
3817 /// source code, including tag keywords and any nested-name-specifiers.
3818 /// The type itself is always "sugar", used to express what was written
3819 /// in the source code but containing no additional semantic information.
3820 class ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode {
3822 /// \brief The nested name specifier containing the qualifier.
3823 NestedNameSpecifier *NNS;
3825 /// \brief The type that this qualified name refers to.
3828 ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
3829 QualType NamedType, QualType CanonType)
3830 : TypeWithKeyword(Keyword, Elaborated, CanonType,
3831 NamedType->isDependentType(),
3832 NamedType->isInstantiationDependentType(),
3833 NamedType->isVariablyModifiedType(),
3834 NamedType->containsUnexpandedParameterPack()),
3835 NNS(NNS), NamedType(NamedType) {
3836 assert(!(Keyword == ETK_None && NNS == 0) &&
3837 "ElaboratedType cannot have elaborated type keyword "
3838 "and name qualifier both null.");
3841 friend class ASTContext; // ASTContext creates these
3846 /// \brief Retrieve the qualification on this type.
3847 NestedNameSpecifier *getQualifier() const { return NNS; }
3849 /// \brief Retrieve the type named by the qualified-id.
3850 QualType getNamedType() const { return NamedType; }
3852 /// \brief Remove a single level of sugar.
3853 QualType desugar() const { return getNamedType(); }
3855 /// \brief Returns whether this type directly provides sugar.
3856 bool isSugared() const { return true; }
3858 void Profile(llvm::FoldingSetNodeID &ID) {
3859 Profile(ID, getKeyword(), NNS, NamedType);
3862 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
3863 NestedNameSpecifier *NNS, QualType NamedType) {
3864 ID.AddInteger(Keyword);
3866 NamedType.Profile(ID);
3869 static bool classof(const Type *T) {
3870 return T->getTypeClass() == Elaborated;
3872 static bool classof(const ElaboratedType *T) { return true; }
3875 /// \brief Represents a qualified type name for which the type name is
3878 /// DependentNameType represents a class of dependent types that involve a
3879 /// dependent nested-name-specifier (e.g., "T::") followed by a (dependent)
3880 /// name of a type. The DependentNameType may start with a "typename" (for a
3881 /// typename-specifier), "class", "struct", "union", or "enum" (for a
3882 /// dependent elaborated-type-specifier), or nothing (in contexts where we
3883 /// know that we must be referring to a type, e.g., in a base class specifier).
3884 class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
3886 /// \brief The nested name specifier containing the qualifier.
3887 NestedNameSpecifier *NNS;
3889 /// \brief The type that this typename specifier refers to.
3890 const IdentifierInfo *Name;
3892 DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
3893 const IdentifierInfo *Name, QualType CanonType)
3894 : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true,
3895 /*InstantiationDependent=*/true,
3896 /*VariablyModified=*/false,
3897 NNS->containsUnexpandedParameterPack()),
3898 NNS(NNS), Name(Name) {
3899 assert(NNS->isDependent() &&
3900 "DependentNameType requires a dependent nested-name-specifier");
3903 friend class ASTContext; // ASTContext creates these
3906 /// \brief Retrieve the qualification on this type.
3907 NestedNameSpecifier *getQualifier() const { return NNS; }
3909 /// \brief Retrieve the type named by the typename specifier as an
3912 /// This routine will return a non-NULL identifier pointer when the
3913 /// form of the original typename was terminated by an identifier,
3914 /// e.g., "typename T::type".
3915 const IdentifierInfo *getIdentifier() const {
3919 bool isSugared() const { return false; }
3920 QualType desugar() const { return QualType(this, 0); }
3922 void Profile(llvm::FoldingSetNodeID &ID) {
3923 Profile(ID, getKeyword(), NNS, Name);
3926 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
3927 NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
3928 ID.AddInteger(Keyword);
3930 ID.AddPointer(Name);
3933 static bool classof(const Type *T) {
3934 return T->getTypeClass() == DependentName;
3936 static bool classof(const DependentNameType *T) { return true; }
3939 /// DependentTemplateSpecializationType - Represents a template
3940 /// specialization type whose template cannot be resolved, e.g.
3941 /// A<T>::template B<T>
3942 class DependentTemplateSpecializationType :
3943 public TypeWithKeyword, public llvm::FoldingSetNode {
3945 /// \brief The nested name specifier containing the qualifier.
3946 NestedNameSpecifier *NNS;
3948 /// \brief The identifier of the template.
3949 const IdentifierInfo *Name;
3951 /// \brief - The number of template arguments named in this class
3952 /// template specialization.
3955 const TemplateArgument *getArgBuffer() const {
3956 return reinterpret_cast<const TemplateArgument*>(this+1);
3958 TemplateArgument *getArgBuffer() {
3959 return reinterpret_cast<TemplateArgument*>(this+1);
3962 DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
3963 NestedNameSpecifier *NNS,
3964 const IdentifierInfo *Name,
3966 const TemplateArgument *Args,
3969 friend class ASTContext; // ASTContext creates these
3972 NestedNameSpecifier *getQualifier() const { return NNS; }
3973 const IdentifierInfo *getIdentifier() const { return Name; }
3975 /// \brief Retrieve the template arguments.
3976 const TemplateArgument *getArgs() const {
3977 return getArgBuffer();
3980 /// \brief Retrieve the number of template arguments.
3981 unsigned getNumArgs() const { return NumArgs; }
3983 const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
3985 typedef const TemplateArgument * iterator;
3986 iterator begin() const { return getArgs(); }
3987 iterator end() const; // inline in TemplateBase.h
3989 bool isSugared() const { return false; }
3990 QualType desugar() const { return QualType(this, 0); }
3992 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
3993 Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs());
3996 static void Profile(llvm::FoldingSetNodeID &ID,
3997 const ASTContext &Context,
3998 ElaboratedTypeKeyword Keyword,
3999 NestedNameSpecifier *Qualifier,
4000 const IdentifierInfo *Name,
4002 const TemplateArgument *Args);
4004 static bool classof(const Type *T) {
4005 return T->getTypeClass() == DependentTemplateSpecialization;
4007 static bool classof(const DependentTemplateSpecializationType *T) {
4012 /// \brief Represents a pack expansion of types.
4014 /// Pack expansions are part of C++0x variadic templates. A pack
4015 /// expansion contains a pattern, which itself contains one or more
4016 /// "unexpanded" parameter packs. When instantiated, a pack expansion
4017 /// produces a series of types, each instantiated from the pattern of
4018 /// the expansion, where the Ith instantiation of the pattern uses the
4019 /// Ith arguments bound to each of the unexpanded parameter packs. The
4020 /// pack expansion is considered to "expand" these unexpanded
4021 /// parameter packs.
4024 /// template<typename ...Types> struct tuple;
4026 /// template<typename ...Types>
4027 /// struct tuple_of_references {
4028 /// typedef tuple<Types&...> type;
4032 /// Here, the pack expansion \c Types&... is represented via a
4033 /// PackExpansionType whose pattern is Types&.
4034 class PackExpansionType : public Type, public llvm::FoldingSetNode {
4035 /// \brief The pattern of the pack expansion.
4038 /// \brief The number of expansions that this pack expansion will
4039 /// generate when substituted (+1), or indicates that
4041 /// This field will only have a non-zero value when some of the parameter
4042 /// packs that occur within the pattern have been substituted but others have
4044 unsigned NumExpansions;
4046 PackExpansionType(QualType Pattern, QualType Canon,
4047 llvm::Optional<unsigned> NumExpansions)
4048 : Type(PackExpansion, Canon, /*Dependent=*/true,
4049 /*InstantiationDependent=*/true,
4050 /*VariableModified=*/Pattern->isVariablyModifiedType(),
4051 /*ContainsUnexpandedParameterPack=*/false),
4053 NumExpansions(NumExpansions? *NumExpansions + 1: 0) { }
4055 friend class ASTContext; // ASTContext creates these
4058 /// \brief Retrieve the pattern of this pack expansion, which is the
4059 /// type that will be repeatedly instantiated when instantiating the
4060 /// pack expansion itself.
4061 QualType getPattern() const { return Pattern; }
4063 /// \brief Retrieve the number of expansions that this pack expansion will
4064 /// generate, if known.
4065 llvm::Optional<unsigned> getNumExpansions() const {
4067 return NumExpansions - 1;
4069 return llvm::Optional<unsigned>();
4072 bool isSugared() const { return false; }
4073 QualType desugar() const { return QualType(this, 0); }
4075 void Profile(llvm::FoldingSetNodeID &ID) {
4076 Profile(ID, getPattern(), getNumExpansions());
4079 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern,
4080 llvm::Optional<unsigned> NumExpansions) {
4081 ID.AddPointer(Pattern.getAsOpaquePtr());
4082 ID.AddBoolean(NumExpansions);
4084 ID.AddInteger(*NumExpansions);
4087 static bool classof(const Type *T) {
4088 return T->getTypeClass() == PackExpansion;
4090 static bool classof(const PackExpansionType *T) {
4095 /// ObjCObjectType - Represents a class type in Objective C.
4096 /// Every Objective C type is a combination of a base type and a
4097 /// list of protocols.
4099 /// Given the following declarations:
4103 /// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType
4104 /// with base C and no protocols.
4106 /// 'C<P>' is an ObjCObjectType with base C and protocol list [P].
4108 /// 'id' is a TypedefType which is sugar for an ObjCPointerType whose
4109 /// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
4110 /// and no protocols.
4112 /// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType
4113 /// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually
4114 /// this should get its own sugar class to better represent the source.
4115 class ObjCObjectType : public Type {
4116 // ObjCObjectType.NumProtocols - the number of protocols stored
4117 // after the ObjCObjectPointerType node.
4119 // These protocols are those written directly on the type. If
4120 // protocol qualifiers ever become additive, the iterators will need
4121 // to get kindof complicated.
4123 // In the canonical object type, these are sorted alphabetically
4126 /// Either a BuiltinType or an InterfaceType or sugar for either.
4129 ObjCProtocolDecl * const *getProtocolStorage() const {
4130 return const_cast<ObjCObjectType*>(this)->getProtocolStorage();
4133 ObjCProtocolDecl **getProtocolStorage();
4136 ObjCObjectType(QualType Canonical, QualType Base,
4137 ObjCProtocolDecl * const *Protocols, unsigned NumProtocols);
4139 enum Nonce_ObjCInterface { Nonce_ObjCInterface };
4140 ObjCObjectType(enum Nonce_ObjCInterface)
4141 : Type(ObjCInterface, QualType(), false, false, false, false),
4142 BaseType(QualType(this_(), 0)) {
4143 ObjCObjectTypeBits.NumProtocols = 0;
4147 /// getBaseType - Gets the base type of this object type. This is
4148 /// always (possibly sugar for) one of:
4149 /// - the 'id' builtin type (as opposed to the 'id' type visible to the
4150 /// user, which is a typedef for an ObjCPointerType)
4151 /// - the 'Class' builtin type (same caveat)
4152 /// - an ObjCObjectType (currently always an ObjCInterfaceType)
4153 QualType getBaseType() const { return BaseType; }
4155 bool isObjCId() const {
4156 return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
4158 bool isObjCClass() const {
4159 return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
4161 bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
4162 bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
4163 bool isObjCUnqualifiedIdOrClass() const {
4164 if (!qual_empty()) return false;
4165 if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
4166 return T->getKind() == BuiltinType::ObjCId ||
4167 T->getKind() == BuiltinType::ObjCClass;
4170 bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
4171 bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
4173 /// Gets the interface declaration for this object type, if the base type
4174 /// really is an interface.
4175 ObjCInterfaceDecl *getInterface() const;
4177 typedef ObjCProtocolDecl * const *qual_iterator;
4179 qual_iterator qual_begin() const { return getProtocolStorage(); }
4180 qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
4182 bool qual_empty() const { return getNumProtocols() == 0; }
4184 /// getNumProtocols - Return the number of qualifying protocols in this
4185 /// interface type, or 0 if there are none.
4186 unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; }
4188 /// \brief Fetch a protocol by index.
4189 ObjCProtocolDecl *getProtocol(unsigned I) const {
4190 assert(I < getNumProtocols() && "Out-of-range protocol access");
4191 return qual_begin()[I];
4194 bool isSugared() const { return false; }
4195 QualType desugar() const { return QualType(this, 0); }
4197 static bool classof(const Type *T) {
4198 return T->getTypeClass() == ObjCObject ||
4199 T->getTypeClass() == ObjCInterface;
4201 static bool classof(const ObjCObjectType *) { return true; }
4204 /// ObjCObjectTypeImpl - A class providing a concrete implementation
4205 /// of ObjCObjectType, so as to not increase the footprint of
4206 /// ObjCInterfaceType. Code outside of ASTContext and the core type
4207 /// system should not reference this type.
4208 class ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
4209 friend class ASTContext;
4211 // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
4212 // will need to be modified.
4214 ObjCObjectTypeImpl(QualType Canonical, QualType Base,
4215 ObjCProtocolDecl * const *Protocols,
4216 unsigned NumProtocols)
4217 : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {}
4220 void Profile(llvm::FoldingSetNodeID &ID);
4221 static void Profile(llvm::FoldingSetNodeID &ID,
4223 ObjCProtocolDecl *const *protocols,
4224 unsigned NumProtocols);
4227 inline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() {
4228 return reinterpret_cast<ObjCProtocolDecl**>(
4229 static_cast<ObjCObjectTypeImpl*>(this) + 1);
4232 /// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
4233 /// object oriented design. They basically correspond to C++ classes. There
4234 /// are two kinds of interface types, normal interfaces like "NSString" and
4235 /// qualified interfaces, which are qualified with a protocol list like
4236 /// "NSString<NSCopyable, NSAmazing>".
4238 /// ObjCInterfaceType guarantees the following properties when considered
4239 /// as a subtype of its superclass, ObjCObjectType:
4240 /// - There are no protocol qualifiers. To reinforce this, code which
4241 /// tries to invoke the protocol methods via an ObjCInterfaceType will
4242 /// fail to compile.
4243 /// - It is its own base type. That is, if T is an ObjCInterfaceType*,
4244 /// T->getBaseType() == QualType(T, 0).
4245 class ObjCInterfaceType : public ObjCObjectType {
4246 mutable ObjCInterfaceDecl *Decl;
4248 ObjCInterfaceType(const ObjCInterfaceDecl *D)
4249 : ObjCObjectType(Nonce_ObjCInterface),
4250 Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
4251 friend class ASTContext; // ASTContext creates these.
4252 friend class ASTReader;
4253 friend class ObjCInterfaceDecl;
4256 /// getDecl - Get the declaration of this interface.
4257 ObjCInterfaceDecl *getDecl() const { return Decl; }
4259 bool isSugared() const { return false; }
4260 QualType desugar() const { return QualType(this, 0); }
4262 static bool classof(const Type *T) {
4263 return T->getTypeClass() == ObjCInterface;
4265 static bool classof(const ObjCInterfaceType *) { return true; }
4267 // Nonsense to "hide" certain members of ObjCObjectType within this
4268 // class. People asking for protocols on an ObjCInterfaceType are
4269 // not going to get what they want: ObjCInterfaceTypes are
4270 // guaranteed to have no protocols.
4280 inline ObjCInterfaceDecl *ObjCObjectType::getInterface() const {
4281 if (const ObjCInterfaceType *T =
4282 getBaseType()->getAs<ObjCInterfaceType>())
4283 return T->getDecl();
4287 /// ObjCObjectPointerType - Used to represent a pointer to an
4288 /// Objective C object. These are constructed from pointer
4289 /// declarators when the pointee type is an ObjCObjectType (or sugar
4290 /// for one). In addition, the 'id' and 'Class' types are typedefs
4291 /// for these, and the protocol-qualified types 'id<P>' and 'Class<P>'
4292 /// are translated into these.
4294 /// Pointers to pointers to Objective C objects are still PointerTypes;
4295 /// only the first level of pointer gets it own type implementation.
4296 class ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
4297 QualType PointeeType;
4299 ObjCObjectPointerType(QualType Canonical, QualType Pointee)
4300 : Type(ObjCObjectPointer, Canonical, false, false, false, false),
4301 PointeeType(Pointee) {}
4302 friend class ASTContext; // ASTContext creates these.
4305 /// getPointeeType - Gets the type pointed to by this ObjC pointer.
4306 /// The result will always be an ObjCObjectType or sugar thereof.
4307 QualType getPointeeType() const { return PointeeType; }
4309 /// getObjCObjectType - Gets the type pointed to by this ObjC
4310 /// pointer. This method always returns non-null.
4312 /// This method is equivalent to getPointeeType() except that
4313 /// it discards any typedefs (or other sugar) between this
4314 /// type and the "outermost" object type. So for:
4315 /// @class A; @protocol P; @protocol Q;
4316 /// typedef A<P> AP;
4318 /// typedef A1<P> A1P;
4319 /// typedef A1P<Q> A1PQ;
4320 /// For 'A*', getObjectType() will return 'A'.
4321 /// For 'A<P>*', getObjectType() will return 'A<P>'.
4322 /// For 'AP*', getObjectType() will return 'A<P>'.
4323 /// For 'A1*', getObjectType() will return 'A'.
4324 /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
4325 /// For 'A1P*', getObjectType() will return 'A1<P>'.
4326 /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
4327 /// adding protocols to a protocol-qualified base discards the
4328 /// old qualifiers (for now). But if it didn't, getObjectType()
4329 /// would return 'A1P<Q>' (and we'd have to make iterating over
4330 /// qualifiers more complicated).
4331 const ObjCObjectType *getObjectType() const {
4332 return PointeeType->castAs<ObjCObjectType>();
4335 /// getInterfaceType - If this pointer points to an Objective C
4336 /// @interface type, gets the type for that interface. Any protocol
4337 /// qualifiers on the interface are ignored.
4339 /// \return null if the base type for this pointer is 'id' or 'Class'
4340 const ObjCInterfaceType *getInterfaceType() const {
4341 return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>();
4344 /// getInterfaceDecl - If this pointer points to an Objective @interface
4345 /// type, gets the declaration for that interface.
4347 /// \return null if the base type for this pointer is 'id' or 'Class'
4348 ObjCInterfaceDecl *getInterfaceDecl() const {
4349 return getObjectType()->getInterface();
4352 /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if
4353 /// its object type is the primitive 'id' type with no protocols.
4354 bool isObjCIdType() const {
4355 return getObjectType()->isObjCUnqualifiedId();
4358 /// isObjCClassType - True if this is equivalent to the 'Class' type,
4359 /// i.e. if its object tive is the primitive 'Class' type with no protocols.
4360 bool isObjCClassType() const {
4361 return getObjectType()->isObjCUnqualifiedClass();
4364 /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some
4365 /// non-empty set of protocols.
4366 bool isObjCQualifiedIdType() const {
4367 return getObjectType()->isObjCQualifiedId();
4370 /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for
4371 /// some non-empty set of protocols.
4372 bool isObjCQualifiedClassType() const {
4373 return getObjectType()->isObjCQualifiedClass();
4376 /// An iterator over the qualifiers on the object type. Provided
4377 /// for convenience. This will always iterate over the full set of
4378 /// protocols on a type, not just those provided directly.
4379 typedef ObjCObjectType::qual_iterator qual_iterator;
4381 qual_iterator qual_begin() const {
4382 return getObjectType()->qual_begin();
4384 qual_iterator qual_end() const {
4385 return getObjectType()->qual_end();
4387 bool qual_empty() const { return getObjectType()->qual_empty(); }
4389 /// getNumProtocols - Return the number of qualifying protocols on
4390 /// the object type.
4391 unsigned getNumProtocols() const {
4392 return getObjectType()->getNumProtocols();
4395 /// \brief Retrieve a qualifying protocol by index on the object
4397 ObjCProtocolDecl *getProtocol(unsigned I) const {
4398 return getObjectType()->getProtocol(I);
4401 bool isSugared() const { return false; }
4402 QualType desugar() const { return QualType(this, 0); }
4404 void Profile(llvm::FoldingSetNodeID &ID) {
4405 Profile(ID, getPointeeType());
4407 static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
4408 ID.AddPointer(T.getAsOpaquePtr());
4410 static bool classof(const Type *T) {
4411 return T->getTypeClass() == ObjCObjectPointer;
4413 static bool classof(const ObjCObjectPointerType *) { return true; }
4416 class AtomicType : public Type, public llvm::FoldingSetNode {
4419 AtomicType(QualType ValTy, QualType Canonical)
4420 : Type(Atomic, Canonical, ValTy->isDependentType(),
4421 ValTy->isInstantiationDependentType(),
4422 ValTy->isVariablyModifiedType(),
4423 ValTy->containsUnexpandedParameterPack()),
4425 friend class ASTContext; // ASTContext creates these.
4428 /// getValueType - Gets the type contained by this atomic type, i.e.
4429 /// the type returned by performing an atomic load of this atomic type.
4430 QualType getValueType() const { return ValueType; }
4432 bool isSugared() const { return false; }
4433 QualType desugar() const { return QualType(this, 0); }
4435 void Profile(llvm::FoldingSetNodeID &ID) {
4436 Profile(ID, getValueType());
4438 static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
4439 ID.AddPointer(T.getAsOpaquePtr());
4441 static bool classof(const Type *T) {
4442 return T->getTypeClass() == Atomic;
4444 static bool classof(const AtomicType *) { return true; }
4447 /// A qualifier set is used to build a set of qualifiers.
4448 class QualifierCollector : public Qualifiers {
4450 QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {}
4452 /// Collect any qualifiers on the given type and return an
4453 /// unqualified type. The qualifiers are assumed to be consistent
4454 /// with those already in the type.
4455 const Type *strip(QualType type) {
4456 addFastQualifiers(type.getLocalFastQualifiers());
4457 if (!type.hasLocalNonFastQualifiers())
4458 return type.getTypePtrUnsafe();
4460 const ExtQuals *extQuals = type.getExtQualsUnsafe();
4461 addConsistentQualifiers(extQuals->getQualifiers());
4462 return extQuals->getBaseType();
4465 /// Apply the collected qualifiers to the given type.
4466 QualType apply(const ASTContext &Context, QualType QT) const;
4468 /// Apply the collected qualifiers to the given type.
4469 QualType apply(const ASTContext &Context, const Type* T) const;
4473 // Inline function definitions.
4475 inline SplitQualType SplitQualType::getSingleStepDesugaredType() const {
4476 SplitQualType desugar =
4477 Ty->getLocallyUnqualifiedSingleStepDesugaredType().split();
4478 desugar.Quals.addConsistentQualifiers(Quals);
4482 inline const Type *QualType::getTypePtr() const {
4483 return getCommonPtr()->BaseType;
4486 inline const Type *QualType::getTypePtrOrNull() const {
4487 return (isNull() ? 0 : getCommonPtr()->BaseType);
4490 inline SplitQualType QualType::split() const {
4491 if (!hasLocalNonFastQualifiers())
4492 return SplitQualType(getTypePtrUnsafe(),
4493 Qualifiers::fromFastMask(getLocalFastQualifiers()));
4495 const ExtQuals *eq = getExtQualsUnsafe();
4496 Qualifiers qs = eq->getQualifiers();
4497 qs.addFastQualifiers(getLocalFastQualifiers());
4498 return SplitQualType(eq->getBaseType(), qs);
4501 inline Qualifiers QualType::getLocalQualifiers() const {
4503 if (hasLocalNonFastQualifiers())
4504 Quals = getExtQualsUnsafe()->getQualifiers();
4505 Quals.addFastQualifiers(getLocalFastQualifiers());
4509 inline Qualifiers QualType::getQualifiers() const {
4510 Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers();
4511 quals.addFastQualifiers(getLocalFastQualifiers());
4515 inline unsigned QualType::getCVRQualifiers() const {
4516 unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers();
4517 cvr |= getLocalCVRQualifiers();
4521 inline QualType QualType::getCanonicalType() const {
4522 QualType canon = getCommonPtr()->CanonicalType;
4523 return canon.withFastQualifiers(getLocalFastQualifiers());
4526 inline bool QualType::isCanonical() const {
4527 return getTypePtr()->isCanonicalUnqualified();
4530 inline bool QualType::isCanonicalAsParam() const {
4531 if (!isCanonical()) return false;
4532 if (hasLocalQualifiers()) return false;
4534 const Type *T = getTypePtr();
4535 if (T->isVariablyModifiedType() && T->hasSizedVLAType())
4538 return !isa<FunctionType>(T) && !isa<ArrayType>(T);
4541 inline bool QualType::isConstQualified() const {
4542 return isLocalConstQualified() ||
4543 getCommonPtr()->CanonicalType.isLocalConstQualified();
4546 inline bool QualType::isRestrictQualified() const {
4547 return isLocalRestrictQualified() ||
4548 getCommonPtr()->CanonicalType.isLocalRestrictQualified();
4552 inline bool QualType::isVolatileQualified() const {
4553 return isLocalVolatileQualified() ||
4554 getCommonPtr()->CanonicalType.isLocalVolatileQualified();
4557 inline bool QualType::hasQualifiers() const {
4558 return hasLocalQualifiers() ||
4559 getCommonPtr()->CanonicalType.hasLocalQualifiers();
4562 inline QualType QualType::getUnqualifiedType() const {
4563 if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
4564 return QualType(getTypePtr(), 0);
4566 return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0);
4569 inline SplitQualType QualType::getSplitUnqualifiedType() const {
4570 if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
4573 return getSplitUnqualifiedTypeImpl(*this);
4576 inline void QualType::removeLocalConst() {
4577 removeLocalFastQualifiers(Qualifiers::Const);
4580 inline void QualType::removeLocalRestrict() {
4581 removeLocalFastQualifiers(Qualifiers::Restrict);
4584 inline void QualType::removeLocalVolatile() {
4585 removeLocalFastQualifiers(Qualifiers::Volatile);
4588 inline void QualType::removeLocalCVRQualifiers(unsigned Mask) {
4589 assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
4590 assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask);
4592 // Fast path: we don't need to touch the slow qualifiers.
4593 removeLocalFastQualifiers(Mask);
4596 /// getAddressSpace - Return the address space of this type.
4597 inline unsigned QualType::getAddressSpace() const {
4598 return getQualifiers().getAddressSpace();
4601 /// getObjCGCAttr - Return the gc attribute of this type.
4602 inline Qualifiers::GC QualType::getObjCGCAttr() const {
4603 return getQualifiers().getObjCGCAttr();
4606 inline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) {
4607 if (const PointerType *PT = t.getAs<PointerType>()) {
4608 if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>())
4609 return FT->getExtInfo();
4610 } else if (const FunctionType *FT = t.getAs<FunctionType>())
4611 return FT->getExtInfo();
4613 return FunctionType::ExtInfo();
4616 inline FunctionType::ExtInfo getFunctionExtInfo(QualType t) {
4617 return getFunctionExtInfo(*t);
4620 /// isMoreQualifiedThan - Determine whether this type is more
4621 /// qualified than the Other type. For example, "const volatile int"
4622 /// is more qualified than "const int", "volatile int", and
4623 /// "int". However, it is not more qualified than "const volatile
4625 inline bool QualType::isMoreQualifiedThan(QualType other) const {
4626 Qualifiers myQuals = getQualifiers();
4627 Qualifiers otherQuals = other.getQualifiers();
4628 return (myQuals != otherQuals && myQuals.compatiblyIncludes(otherQuals));
4631 /// isAtLeastAsQualifiedAs - Determine whether this type is at last
4632 /// as qualified as the Other type. For example, "const volatile
4633 /// int" is at least as qualified as "const int", "volatile int",
4634 /// "int", and "const volatile int".
4635 inline bool QualType::isAtLeastAsQualifiedAs(QualType other) const {
4636 return getQualifiers().compatiblyIncludes(other.getQualifiers());
4639 /// getNonReferenceType - If Type is a reference type (e.g., const
4640 /// int&), returns the type that the reference refers to ("const
4641 /// int"). Otherwise, returns the type itself. This routine is used
4642 /// throughout Sema to implement C++ 5p6:
4644 /// If an expression initially has the type "reference to T" (8.3.2,
4645 /// 8.5.3), the type is adjusted to "T" prior to any further
4646 /// analysis, the expression designates the object or function
4647 /// denoted by the reference, and the expression is an lvalue.
4648 inline QualType QualType::getNonReferenceType() const {
4649 if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>())
4650 return RefType->getPointeeType();
4655 inline bool QualType::isCForbiddenLValueType() const {
4656 return ((getTypePtr()->isVoidType() && !hasQualifiers()) ||
4657 getTypePtr()->isFunctionType());
4660 /// \brief Tests whether the type is categorized as a fundamental type.
4662 /// \returns True for types specified in C++0x [basic.fundamental].
4663 inline bool Type::isFundamentalType() const {
4664 return isVoidType() ||
4665 // FIXME: It's really annoying that we don't have an
4666 // 'isArithmeticType()' which agrees with the standard definition.
4667 (isArithmeticType() && !isEnumeralType());
4670 /// \brief Tests whether the type is categorized as a compound type.
4672 /// \returns True for types specified in C++0x [basic.compound].
4673 inline bool Type::isCompoundType() const {
4674 // C++0x [basic.compound]p1:
4675 // Compound types can be constructed in the following ways:
4676 // -- arrays of objects of a given type [...];
4677 return isArrayType() ||
4678 // -- functions, which have parameters of given types [...];
4680 // -- pointers to void or objects or functions [...];
4682 // -- references to objects or functions of a given type. [...]
4683 isReferenceType() ||
4684 // -- classes containing a sequence of objects of various types, [...];
4686 // -- unions, which are classes capable of containing objects of different
4687 // types at different times;
4689 // -- enumerations, which comprise a set of named constant values. [...];
4691 // -- pointers to non-static class members, [...].
4692 isMemberPointerType();
4695 inline bool Type::isFunctionType() const {
4696 return isa<FunctionType>(CanonicalType);
4698 inline bool Type::isPointerType() const {
4699 return isa<PointerType>(CanonicalType);
4701 inline bool Type::isAnyPointerType() const {
4702 return isPointerType() || isObjCObjectPointerType();
4704 inline bool Type::isBlockPointerType() const {
4705 return isa<BlockPointerType>(CanonicalType);
4707 inline bool Type::isReferenceType() const {
4708 return isa<ReferenceType>(CanonicalType);
4710 inline bool Type::isLValueReferenceType() const {
4711 return isa<LValueReferenceType>(CanonicalType);
4713 inline bool Type::isRValueReferenceType() const {
4714 return isa<RValueReferenceType>(CanonicalType);
4716 inline bool Type::isFunctionPointerType() const {
4717 if (const PointerType *T = getAs<PointerType>())
4718 return T->getPointeeType()->isFunctionType();
4722 inline bool Type::isMemberPointerType() const {
4723 return isa<MemberPointerType>(CanonicalType);
4725 inline bool Type::isMemberFunctionPointerType() const {
4726 if (const MemberPointerType* T = getAs<MemberPointerType>())
4727 return T->isMemberFunctionPointer();
4731 inline bool Type::isMemberDataPointerType() const {
4732 if (const MemberPointerType* T = getAs<MemberPointerType>())
4733 return T->isMemberDataPointer();
4737 inline bool Type::isArrayType() const {
4738 return isa<ArrayType>(CanonicalType);
4740 inline bool Type::isConstantArrayType() const {
4741 return isa<ConstantArrayType>(CanonicalType);
4743 inline bool Type::isIncompleteArrayType() const {
4744 return isa<IncompleteArrayType>(CanonicalType);
4746 inline bool Type::isVariableArrayType() const {
4747 return isa<VariableArrayType>(CanonicalType);
4749 inline bool Type::isDependentSizedArrayType() const {
4750 return isa<DependentSizedArrayType>(CanonicalType);
4752 inline bool Type::isBuiltinType() const {
4753 return isa<BuiltinType>(CanonicalType);
4755 inline bool Type::isRecordType() const {
4756 return isa<RecordType>(CanonicalType);
4758 inline bool Type::isEnumeralType() const {
4759 return isa<EnumType>(CanonicalType);
4761 inline bool Type::isAnyComplexType() const {
4762 return isa<ComplexType>(CanonicalType);
4764 inline bool Type::isVectorType() const {
4765 return isa<VectorType>(CanonicalType);
4767 inline bool Type::isExtVectorType() const {
4768 return isa<ExtVectorType>(CanonicalType);
4770 inline bool Type::isObjCObjectPointerType() const {
4771 return isa<ObjCObjectPointerType>(CanonicalType);
4773 inline bool Type::isObjCObjectType() const {
4774 return isa<ObjCObjectType>(CanonicalType);
4776 inline bool Type::isObjCObjectOrInterfaceType() const {
4777 return isa<ObjCInterfaceType>(CanonicalType) ||
4778 isa<ObjCObjectType>(CanonicalType);
4780 inline bool Type::isAtomicType() const {
4781 return isa<AtomicType>(CanonicalType);
4784 inline bool Type::isObjCQualifiedIdType() const {
4785 if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
4786 return OPT->isObjCQualifiedIdType();
4789 inline bool Type::isObjCQualifiedClassType() const {
4790 if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
4791 return OPT->isObjCQualifiedClassType();
4794 inline bool Type::isObjCIdType() const {
4795 if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
4796 return OPT->isObjCIdType();
4799 inline bool Type::isObjCClassType() const {
4800 if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
4801 return OPT->isObjCClassType();
4804 inline bool Type::isObjCSelType() const {
4805 if (const PointerType *OPT = getAs<PointerType>())
4806 return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
4809 inline bool Type::isObjCBuiltinType() const {
4810 return isObjCIdType() || isObjCClassType() || isObjCSelType();
4812 inline bool Type::isTemplateTypeParmType() const {
4813 return isa<TemplateTypeParmType>(CanonicalType);
4816 inline bool Type::isSpecificBuiltinType(unsigned K) const {
4817 if (const BuiltinType *BT = getAs<BuiltinType>())
4818 if (BT->getKind() == (BuiltinType::Kind) K)
4823 inline bool Type::isPlaceholderType() const {
4824 if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
4825 return BT->isPlaceholderType();
4829 inline const BuiltinType *Type::getAsPlaceholderType() const {
4830 if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
4831 if (BT->isPlaceholderType())
4836 inline bool Type::isSpecificPlaceholderType(unsigned K) const {
4837 assert(BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K));
4838 if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
4839 return (BT->getKind() == (BuiltinType::Kind) K);
4843 inline bool Type::isNonOverloadPlaceholderType() const {
4844 if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
4845 return BT->isNonOverloadPlaceholderType();
4849 inline bool Type::isVoidType() const {
4850 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4851 return BT->getKind() == BuiltinType::Void;
4855 inline bool Type::isHalfType() const {
4856 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4857 return BT->getKind() == BuiltinType::Half;
4858 // FIXME: Should we allow complex __fp16? Probably not.
4862 inline bool Type::isNullPtrType() const {
4863 if (const BuiltinType *BT = getAs<BuiltinType>())
4864 return BT->getKind() == BuiltinType::NullPtr;
4868 extern bool IsEnumDeclComplete(EnumDecl *);
4869 extern bool IsEnumDeclScoped(EnumDecl *);
4871 inline bool Type::isIntegerType() const {
4872 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4873 return BT->getKind() >= BuiltinType::Bool &&
4874 BT->getKind() <= BuiltinType::Int128;
4875 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
4876 // Incomplete enum types are not treated as integer types.
4877 // FIXME: In C++, enum types are never integer types.
4878 return IsEnumDeclComplete(ET->getDecl()) &&
4879 !IsEnumDeclScoped(ET->getDecl());
4884 inline bool Type::isScalarType() const {
4885 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4886 return BT->getKind() > BuiltinType::Void &&
4887 BT->getKind() <= BuiltinType::NullPtr;
4888 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
4889 // Enums are scalar types, but only if they are defined. Incomplete enums
4890 // are not treated as scalar types.
4891 return IsEnumDeclComplete(ET->getDecl());
4892 return isa<PointerType>(CanonicalType) ||
4893 isa<BlockPointerType>(CanonicalType) ||
4894 isa<MemberPointerType>(CanonicalType) ||
4895 isa<ComplexType>(CanonicalType) ||
4896 isa<ObjCObjectPointerType>(CanonicalType);
4899 inline bool Type::isIntegralOrEnumerationType() const {
4900 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4901 return BT->getKind() >= BuiltinType::Bool &&
4902 BT->getKind() <= BuiltinType::Int128;
4904 // Check for a complete enum type; incomplete enum types are not properly an
4905 // enumeration type in the sense required here.
4906 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
4907 return IsEnumDeclComplete(ET->getDecl());
4912 inline bool Type::isBooleanType() const {
4913 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4914 return BT->getKind() == BuiltinType::Bool;
4918 /// \brief Determines whether this is a type for which one can define
4919 /// an overloaded operator.
4920 inline bool Type::isOverloadableType() const {
4921 return isDependentType() || isRecordType() || isEnumeralType();
4924 /// \brief Determines whether this type can decay to a pointer type.
4925 inline bool Type::canDecayToPointerType() const {
4926 return isFunctionType() || isArrayType();
4929 inline bool Type::hasPointerRepresentation() const {
4930 return (isPointerType() || isReferenceType() || isBlockPointerType() ||
4931 isObjCObjectPointerType() || isNullPtrType());
4934 inline bool Type::hasObjCPointerRepresentation() const {
4935 return isObjCObjectPointerType();
4938 inline const Type *Type::getBaseElementTypeUnsafe() const {
4939 const Type *type = this;
4940 while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe())
4941 type = arrayType->getElementType().getTypePtr();
4945 /// Insertion operator for diagnostics. This allows sending QualType's into a
4946 /// diagnostic with <<.
4947 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
4949 DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
4950 DiagnosticsEngine::ak_qualtype);
4954 /// Insertion operator for partial diagnostics. This allows sending QualType's
4955 /// into a diagnostic with <<.
4956 inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
4958 PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
4959 DiagnosticsEngine::ak_qualtype);
4963 // Helper class template that is used by Type::getAs to ensure that one does
4964 // not try to look through a qualified type to get to an array type.
4965 template<typename T,
4966 bool isArrayType = (llvm::is_same<T, ArrayType>::value ||
4967 llvm::is_base_of<ArrayType, T>::value)>
4968 struct ArrayType_cannot_be_used_with_getAs { };
4970 template<typename T>
4971 struct ArrayType_cannot_be_used_with_getAs<T, true>;
4973 /// Member-template getAs<specific type>'.
4974 template <typename T> const T *Type::getAs() const {
4975 ArrayType_cannot_be_used_with_getAs<T> at;
4978 // If this is directly a T type, return it.
4979 if (const T *Ty = dyn_cast<T>(this))
4982 // If the canonical form of this type isn't the right kind, reject it.
4983 if (!isa<T>(CanonicalType))
4986 // If this is a typedef for the type, strip the typedef off without
4987 // losing all typedef information.
4988 return cast<T>(getUnqualifiedDesugaredType());
4991 inline const ArrayType *Type::getAsArrayTypeUnsafe() const {
4992 // If this is directly an array type, return it.
4993 if (const ArrayType *arr = dyn_cast<ArrayType>(this))
4996 // If the canonical form of this type isn't the right kind, reject it.
4997 if (!isa<ArrayType>(CanonicalType))
5000 // If this is a typedef for the type, strip the typedef off without
5001 // losing all typedef information.
5002 return cast<ArrayType>(getUnqualifiedDesugaredType());
5005 template <typename T> const T *Type::castAs() const {
5006 ArrayType_cannot_be_used_with_getAs<T> at;
5009 assert(isa<T>(CanonicalType));
5010 if (const T *ty = dyn_cast<T>(this)) return ty;
5011 return cast<T>(getUnqualifiedDesugaredType());
5014 inline const ArrayType *Type::castAsArrayTypeUnsafe() const {
5015 assert(isa<ArrayType>(CanonicalType));
5016 if (const ArrayType *arr = dyn_cast<ArrayType>(this)) return arr;
5017 return cast<ArrayType>(getUnqualifiedDesugaredType());
5020 } // end namespace clang