Type.h revision 308742c87e2311c3f349092e5b823c3821e61b10
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Type interface and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_TYPE_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_TYPE_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner#include "clang/Basic/Diagnostic.h" 188b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl#include "clang/Basic/ExceptionSpecificationType.h" 191734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "clang/Basic/IdentifierTable.h" 200b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor#include "clang/Basic/Linkage.h" 2147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth#include "clang/Basic/PartialDiagnostic.h" 221fb0caaa7bef765b85972274e3b434af2572c141John McCall#include "clang/Basic/Visibility.h" 23e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor#include "clang/AST/NestedNameSpecifier.h" 247532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor#include "clang/AST/TemplateName.h" 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/Casting.h" 2650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor#include "llvm/Support/type_traits.h" 27fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff#include "llvm/ADT/APSInt.h" 285cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/FoldingSet.h" 29cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor#include "llvm/ADT/Optional.h" 305cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/PointerIntPair.h" 311734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "llvm/ADT/PointerUnion.h" 327532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa; 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast; 355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null; 365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast; 375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null; 386b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCallnamespace clang { 396b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall enum { 40f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor TypeAlignmentInBits = 4, 416b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeAlignment = 1 << TypeAlignmentInBits 426b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall }; 43aed1df80bf64228e1429c1edc408397f9174847cChris Lattner class Type; 44aed1df80bf64228e1429c1edc408397f9174847cChris Lattner class ExtQuals; 45aed1df80bf64228e1429c1edc408397f9174847cChris Lattner class QualType; 466b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall} 475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 484e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm { 494e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner template <typename T> 50daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner class PointerLikeTypeTraits; 51bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner template<> 52bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner class PointerLikeTypeTraits< ::clang::Type*> { 53bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner public: 54bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 55bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner static inline ::clang::Type *getFromVoidPointer(void *P) { 56bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner return static_cast< ::clang::Type*>(P); 57bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner } 586b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 59bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner }; 600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall template<> 610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall class PointerLikeTypeTraits< ::clang::ExtQuals*> { 620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall public: 630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; } 640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static inline ::clang::ExtQuals *getFromVoidPointer(void *P) { 650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return static_cast< ::clang::ExtQuals*>(P); 660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 676b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall }; 69aed1df80bf64228e1429c1edc408397f9174847cChris Lattner 70aed1df80bf64228e1429c1edc408397f9174847cChris Lattner template <> 71aed1df80bf64228e1429c1edc408397f9174847cChris Lattner struct isPodLike<clang::QualType> { static const bool value = true; }; 724e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner} 734e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class ASTContext; 76162e1c1b487352434552147967c3dd296ebee2f7Richard Smith class TypedefNameDecl; 7755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor class TemplateDecl; 7872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor class TemplateTypeParmDecl; 79aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor class NonTypeTemplateParmDecl; 807532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor class TemplateTemplateParmDecl; 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TagDecl; 825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class RecordDecl; 8349aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis class CXXRecordDecl; 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class EnumDecl; 8521d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek class FieldDecl; 86a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCInterfaceDecl; 87a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCProtocolDecl; 88a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCMethodDecl; 89ed97649e9574b9d854fa4d6109c9333ae0993554John McCall class UnresolvedUsingTypenameDecl; 905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Expr; 91b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek class Stmt; 925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class SourceLocation; 9392866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek class StmtIteratorBase; 9440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor class TemplateArgument; 95833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall class TemplateArgumentLoc; 96d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall class TemplateArgumentListInfo; 97465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara class ElaboratedType; 983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall class ExtQuals; 993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall class ExtQualsTypeCommonBase; 1003b4ea54acf01f72f6eb74d96689dda86d950228fDaniel Dunbar struct PrintingPolicy; 10172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 102ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall template <typename> class CanQual; 103ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall typedef CanQual<Type> CanQualType; 104ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall 10572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor // Provide forward declarations for all of the *Type classes 10672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type; 10772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 108f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Qualifiers - The collection of all-type qualifiers we support. 1100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Clang supports five independent qualifiers: 1110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * C99: const, volatile, and restrict 1120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Embedded C (TR18037): address spaces 1130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Objective C: the GC attributes (none, weak, or strong) 1140953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass Qualifiers { 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Const = 0x1, 1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Restrict = 0x2, 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Volatile = 0x4, 1200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall CVRMask = Const | Volatile | Restrict 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall enum GC { 124d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian GCNone = 0, 125d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Weak, 126d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Strong 127d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian }; 128efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall 1290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall enum { 1300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// The maximum supported address space number. 1310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// 24 bits should be enough for anyone. 1320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall MaxAddressSpace = 0xffffffu, 1330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// The width of the "fast" qualifier mask. 135f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor FastWidth = 3, 1360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// The fast qualifier mask. 1380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall FastMask = (1 << FastWidth) - 1 1390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall }; 1400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers() : Mask(0) {} 1420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static Qualifiers fromFastMask(unsigned Mask) { 1440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Qs; 1450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qs.addFastQualifiers(Mask); 1460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs; 1470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static Qualifiers fromCVRMask(unsigned CVR) { 1500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Qs; 1510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qs.addCVRQualifiers(CVR); 1520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs; 1530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Deserialize qualifiers from an opaque representation. 1560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static Qualifiers fromOpaqueValue(unsigned opaque) { 1570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Qs; 1580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qs.Mask = opaque; 1590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs; 1600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Serialize these qualifiers into an opaque representation. 1630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getAsOpaqueValue() const { 1640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Mask; 1650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasConst() const { return Mask & Const; } 1680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setConst(bool flag) { 1690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~Const) | (flag ? Const : 0); 1700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeConst() { Mask &= ~Const; } 1720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addConst() { Mask |= Const; } 1730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasVolatile() const { return Mask & Volatile; } 1750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setVolatile(bool flag) { 1760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~Volatile) | (flag ? Volatile : 0); 1770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeVolatile() { Mask &= ~Volatile; } 1790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addVolatile() { Mask |= Volatile; } 1800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasRestrict() const { return Mask & Restrict; } 1820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setRestrict(bool flag) { 1830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~Restrict) | (flag ? Restrict : 0); 1840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeRestrict() { Mask &= ~Restrict; } 1860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addRestrict() { Mask |= Restrict; } 1870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasCVRQualifiers() const { return getCVRQualifiers(); } 1890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getCVRQualifiers() const { return Mask & CVRMask; } 1900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setCVRQualifiers(unsigned mask) { 1910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 1920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~CVRMask) | mask; 1930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeCVRQualifiers(unsigned mask) { 1950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 1960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask &= ~mask; 1970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeCVRQualifiers() { 1990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeCVRQualifiers(CVRMask); 2000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addCVRQualifiers(unsigned mask) { 2020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= mask; 2040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasObjCGCAttr() const { return Mask & GCAttrMask; } 2070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); } 2080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setObjCGCAttr(GC type) { 2090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift); 2100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeObjCGCAttr() { setObjCGCAttr(GCNone); } 2120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addObjCGCAttr(GC type) { 2130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(type); 2140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall setObjCGCAttr(type); 2150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2162234873111009eb8655d63362cedc422eb9fc517John McCall Qualifiers withoutObjCGCAttr() const { 2172234873111009eb8655d63362cedc422eb9fc517John McCall Qualifiers qs = *this; 2182234873111009eb8655d63362cedc422eb9fc517John McCall qs.removeObjCGCAttr(); 2192234873111009eb8655d63362cedc422eb9fc517John McCall return qs; 2202234873111009eb8655d63362cedc422eb9fc517John McCall } 2210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasAddressSpace() const { return Mask & AddressSpaceMask; } 2230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; } 2240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setAddressSpace(unsigned space) { 2250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(space <= MaxAddressSpace); 2260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~AddressSpaceMask) 2270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall | (((uint32_t) space) << AddressSpaceShift); 2280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeAddressSpace() { setAddressSpace(0); } 2300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addAddressSpace(unsigned space) { 2310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(space); 2320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall setAddressSpace(space); 2330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Fast qualifiers are those that can be allocated directly 2360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // on a QualType object. 2370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasFastQualifiers() const { return getFastQualifiers(); } 2380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getFastQualifiers() const { return Mask & FastMask; } 2390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setFastQualifiers(unsigned mask) { 2400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~FastMask) | mask; 2420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeFastQualifiers(unsigned mask) { 2440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask &= ~mask; 2460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeFastQualifiers() { 2480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeFastQualifiers(FastMask); 2490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addFastQualifiers(unsigned mask) { 2510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= mask; 2530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// hasNonFastQualifiers - Return true if the set contains any 2560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// qualifiers which require an ExtQuals node to be allocated. 2570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasNonFastQualifiers() const { return Mask & ~FastMask; } 2580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers getNonFastQualifiers() const { 2590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Quals = *this; 2600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.setFastQualifiers(0); 2610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Quals; 2620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// hasQualifiers - Return true if the set contains any qualifiers. 2650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasQualifiers() const { return Mask; } 2660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool empty() const { return !Mask; } 2670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// \brief Add the qualifiers from the given set to this set. 2690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addQualifiers(Qualifiers Q) { 2700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If the other set doesn't have any non-boolean qualifiers, just 2710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // bit-or it in. 2720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!(Q.Mask & ~CVRMask)) 2730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= Q.Mask; 2740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall else { 2750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= (Q.Mask & CVRMask); 2760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Q.hasAddressSpace()) 2770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addAddressSpace(Q.getAddressSpace()); 2780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Q.hasObjCGCAttr()) 2790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addObjCGCAttr(Q.getObjCGCAttr()); 2800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 28362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \brief Add the qualifiers from the given set to this set, given that 28462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// they don't conflict. 28562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall void addConsistentQualifiers(Qualifiers qs) { 28662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall assert(getAddressSpace() == qs.getAddressSpace() || 28762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall !hasAddressSpace() || !qs.hasAddressSpace()); 28862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall assert(getObjCGCAttr() == qs.getObjCGCAttr() || 28962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall !hasObjCGCAttr() || !qs.hasObjCGCAttr()); 29062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Mask |= qs.Mask; 29162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 29262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 29362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \brief Determines if these qualifiers compatibly include another set. 29462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// Generally this answers the question of whether an object with the other 29562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// qualifiers can be safely used as an object with these qualifiers. 29662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall bool compatiblyIncludes(Qualifiers other) const { 297377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor return 298377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor // Address spaces must match exactly. 299377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor getAddressSpace() == other.getAddressSpace() && 300377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor // ObjC GC qualifiers can match, be added, or be removed, but can't be 301377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor // changed. 302377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor (getObjCGCAttr() == other.getObjCGCAttr() || 303377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor !hasObjCGCAttr() || !other.hasObjCGCAttr()) && 304377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor // CVR qualifiers may subset. 305377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)); 30662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 30762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 308769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor /// \brief Determine whether this set of qualifiers is a strict superset of 309769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor /// another set of qualifiers, not considering qualifier compatibility. 310769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor bool isStrictSupersetOf(Qualifiers Other) const; 311769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor 3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool operator==(Qualifiers Other) const { return Mask == Other.Mask; } 3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; } 3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall operator bool() const { return hasQualifiers(); } 3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers &operator+=(Qualifiers R) { 3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addQualifiers(R); 3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return *this; 3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Union two qualifier sets. If an enumerated qualifier appears 3230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // in both sets, use the one from the right. 3240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall friend Qualifiers operator+(Qualifiers L, Qualifiers R) { 3250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall L += R; 3260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return L; 3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3283cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor 3293cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor Qualifiers &operator-=(Qualifiers R) { 3303cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor Mask = Mask & ~(R.Mask); 3313cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor return *this; 3323cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor } 3330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3343cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor /// \brief Compute the difference between two qualifier sets. 3353cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor friend Qualifiers operator-(Qualifiers L, Qualifiers R) { 3363cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor L -= R; 3373cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor return L; 3383cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor } 3393cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor 3400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string getAsString() const; 3410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string getAsString(const PrintingPolicy &Policy) const { 3420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string Buffer; 3430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getAsStringInternal(Buffer, Policy); 3440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Buffer; 3450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const; 3470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 3490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ID.AddInteger(Mask); 3500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3520953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate: 3530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // bits: |0 1 2|3 .. 4|5 .. 31| 3550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // |C R V|GCAttr|AddrSpace| 3560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall uint32_t Mask; 3570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t GCAttrMask = 0x18; 3590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t GCAttrShift = 3; 3600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask); 3610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t AddressSpaceShift = 5; 3620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 3630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 364ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses. 365ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv { 366ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_Default, 367ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_C, // __attribute__((cdecl)) 368ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_X86StdCall, // __attribute__((stdcall)) 369f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor CC_X86FastCall, // __attribute__((fastcall)) 37052fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik CC_X86ThisCall, // __attribute__((thiscall)) 371414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov CC_X86Pascal, // __attribute__((pascal)) 372414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov CC_AAPCS, // __attribute__((pcs("aapcs"))) 373414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov CC_AAPCS_VFP // __attribute__((pcs("aapcs-vfp"))) 374ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}; 375ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor 37649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCalltypedef std::pair<const Type*, Qualifiers> SplitQualType; 3770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on 3790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers. This 3800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for 3810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int', 3820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc). 3830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 3840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we 3850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the 3860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer. To handle the packing/unpacking, we make QualType be a 3870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer. A third bit 3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which 3890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure. 3900953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType { 3910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Thankfully, these are efficiently composable. 3920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>, 3930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::FastWidth> Value; 3940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *getExtQualsUnsafe() const { 3960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().get<const ExtQuals*>(); 3970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *getTypePtrUnsafe() const { 4000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().get<const Type*>(); 4010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ExtQualsTypeCommonBase *getCommonPtr() const { 4043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!isNull() && "Cannot retrieve a NULL type pointer"); 4053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall uintptr_t CommonPtrVal 4063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = reinterpret_cast<uintptr_t>(Value.getOpaqueValue()); 4073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1); 4083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal); 4093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 4103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 4110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall friend class QualifierCollector; 4120953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 4135cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType() {} 4141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4155cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType(const Type *Ptr, unsigned Quals) 4160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Value(Ptr, Quals) {} 4170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType(const ExtQuals *Ptr, unsigned Quals) 4180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Value(Ptr, Quals) {} 4190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 420a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor unsigned getLocalFastQualifiers() const { return Value.getInt(); } 421a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); } 4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Retrieves a pointer to the underlying (unqualified) type. 4240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// This should really return a const Type, but it's not worth 4250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// changing all the users right now. 4261ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor /// 4271ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor /// This function requires that the type not be NULL. If the type might be 4281ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor /// NULL, use the (slightly less efficient) \c getTypePtrOrNull(). 4293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *getTypePtr() const; 4301ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor 4313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *getTypePtrOrNull() const; 4321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall /// Divides a QualType into its unqualified type and a set of local 43449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall /// qualifiers. 4353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType split() const; 43649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall 4375cf243a883872441d73ca49cea7e20de5802629bChris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 438f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall static QualType getFromOpaquePtr(const void *Ptr) { 4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType T; 440f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall T.Value.setFromOpaqueValue(const_cast<void*>(Ptr)); 4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T; 4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 444f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type &operator*() const { 4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *getTypePtr(); 4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 448f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type *operator->() const { 4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypePtr(); 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 452467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall bool isCanonical() const; 45354e14c4db764c0636160d26c5bbf491637c83a76John McCall bool isCanonicalAsParam() const; 454467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall 4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNull - Return true if this QualType doesn't point to a type yet. 4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNull() const { 4570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().isNull(); 4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 460a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has the 461a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "const" qualifier set, without looking through typedefs that may have 462a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "const" at a different level. 463a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalConstQualified() const { 464a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Const); 4650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 466a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 467a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is const-qualified. 468fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isConstQualified() const; 469a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 470a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has the 471a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "restrict" qualifier set, without looking through typedefs that may have 472a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "restrict" at a different level. 473a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalRestrictQualified() const { 474a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Restrict); 475a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor } 476a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 477a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is restrict-qualified. 478fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isRestrictQualified() const; 479a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 480a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has the 481a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "volatile" qualifier set, without looking through typedefs that may have 482a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "volatile" at a different level. 483a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalVolatileQualified() const { 484f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor return (getLocalFastQualifiers() & Qualifiers::Volatile); 4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 487a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is volatile-qualified. 488fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isVolatileQualified() const; 489a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 490a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has any 491a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// qualifiers, without looking through any typedefs that might add 492a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// qualifiers at a different level. 493a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool hasLocalQualifiers() const { 494a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return getLocalFastQualifiers() || hasLocalNonFastQualifiers(); 4950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 497a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type has any qualifiers. 498fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool hasQualifiers() const; 499a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 500a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has any 501a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType 502a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// instance. 503a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool hasLocalNonFastQualifiers() const { 504a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return Value.getPointer().is<const ExtQuals*>(); 5050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 507a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of qualifiers local to this particular QualType 508a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// instance, not including any qualifiers acquired through typedefs or 509a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// other sugar. 5103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers getLocalQualifiers() const; 5110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 512a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of qualifiers applied to this type. 513fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor Qualifiers getQualifiers() const; 514a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 515a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 516a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// local to this particular QualType instance, not including any qualifiers 517a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// acquired through typedefs or other sugar. 518a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor unsigned getLocalCVRQualifiers() const { 519f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor return getLocalFastQualifiers(); 5205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 521b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 522a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 523a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// applied to this type. 524fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor unsigned getCVRQualifiers() const; 525e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth 526bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isConstant(ASTContext& Ctx) const { 527bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return QualType::isConstant(*this, Ctx); 528bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 5291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Don't promise in the API that anything besides 'const' can be 5310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // easily added. 5320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// addConst - add the specified type qualifier to this QualType. 5340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addConst() { 5350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addFastQualifiers(Qualifiers::Const); 5360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withConst() const { 5380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return withFastQualifiers(Qualifiers::Const); 5390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 541308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt /// addVolatile - add the specified type qualifier to this QualType. 542308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt void addVolatile() { 543308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt addFastQualifiers(Qualifiers::Volatile); 544308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt } 545308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt QualType withVolatile() const { 546308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt return withFastQualifiers(Qualifiers::Volatile); 547308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt } 548308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt 5490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addFastQualifiers(unsigned TQs) { 5500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(TQs & ~Qualifiers::FastMask) 5510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall && "non-fast qualifier bits set in mask!"); 5520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Value.setInt(Value.getInt() | TQs); 5530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 55549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalConst(); 55649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalVolatile(); 55749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalRestrict(); 55849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalCVRQualifiers(unsigned Mask); 5590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 56049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalFastQualifiers() { Value.setInt(0); } 56149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalFastQualifiers(unsigned Mask) { 5620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers"); 5630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Value.setInt(Value.getInt() & ~Mask); 5640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Creates a type with the given qualifiers in addition to any 5670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // qualifiers already on this type. 5680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withFastQualifiers(unsigned TQs) const { 5690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType T = *this; 5700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall T.addFastQualifiers(TQs); 5710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return T; 5720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5731c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta 5740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Creates a type with exactly the given fast qualifiers, removing 5750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // any existing fast qualifiers. 57649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall QualType withExactLocalFastQualifiers(unsigned TQs) const { 57749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return withoutLocalFastQualifiers().withFastQualifiers(TQs); 5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Removes fast qualifiers, but leaves any extended qualifiers in place. 58149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall QualType withoutLocalFastQualifiers() const { 5820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType T = *this; 58349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall T.removeLocalFastQualifiers(); 5840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return T; 585c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 586971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 5873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType getCanonicalType() const; 5883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 589a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Return this type with all of the instance-specific qualifiers 590a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// removed, but without removing any qualifiers that may have been applied 591a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// through typedefs. 592a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); } 5931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \brief Retrieve the unqualified variant of the given type, 59562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// removing as little sugar as possible. 59662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 59762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// This routine looks through various kinds of sugar to find the 59862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// least-desugared type that is unqualified. For example, given: 59962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 60062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \code 60162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// typedef int Integer; 60262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// typedef const Integer CInteger; 60362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// typedef CInteger DifferenceType; 60462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \endcode 60562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 60662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// Executing \c getUnqualifiedType() on the type \c DifferenceType will 60762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// desugar until we hit the type \c Integer, which has no qualifiers on it. 60862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 60962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// The resulting type might still be qualified if it's an array 61062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// type. To strip qualifiers even from within an array type, use 61162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// ASTContext::getUnqualifiedArrayType. 61262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall inline QualType getUnqualifiedType() const; 61362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 61462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// getSplitUnqualifiedType - Retrieve the unqualified variant of the 61562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// given type, removing as little sugar as possible. 61662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 61762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// Like getUnqualifiedType(), but also returns the set of 61862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// qualifiers that were built up. 61962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 62062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// The resulting type might still be qualified if it's an array 62162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// type. To strip qualifiers even from within an array type, use 62262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// ASTContext::getUnqualifiedArrayType. 62362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall inline SplitQualType getSplitUnqualifiedType() const; 624a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 62561d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// \brief Determine whether this type is more qualified than the other 62661d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// given type, requiring exact equality for non-CVR qualifiers. 627e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 62861d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor 62961d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// \brief Determine whether this type is at least as qualified as the other 63061d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// given type, requiring exact equality for non-CVR qualifiers. 631e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 63261d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor 633e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getNonReferenceType() const; 6341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6356398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// \brief Determine the type of a (typically non-lvalue) expression with the 6366398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// specified result type. 6375291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// 6386398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// This routine should be used for expressions for which the return type is 6396398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// explicitly specified (e.g., in a cast or call) and isn't necessarily 6406398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// an lvalue. It removes a top-level reference (since there are no 6415291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// expressions of reference type) and deletes top-level cvr-qualifiers 6425291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// from non-class types (in C++) or all types (in C). 6436398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor QualType getNonLValueExprType(ASTContext &Context) const; 6445291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 6452fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 6462fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 6472fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 6482fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 6492fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 6502fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// concrete. 6510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// 6520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Qualifiers are left in place. 6534ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType getDesugaredType(const ASTContext &Context) const { 65449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getDesugaredType(*this, Context); 65549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 65649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall 65749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall SplitQualType getSplitDesugaredType() const { 65849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getSplitDesugaredType(*this); 659bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 66098cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor 661075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// IgnoreParens - Returns the specified type after dropping any 662075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// outer-level parentheses. 663075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType IgnoreParens() const { 664723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara if (isa<ParenType>(*this)) 665723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara return QualType::IgnoreParens(*this); 666723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara return *this; 667075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 668075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// operator==/!= - Indicate whether the specified types and qualifiers are 6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identical. 67150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor friend bool operator==(const QualType &LHS, const QualType &RHS) { 67250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return LHS.Value == RHS.Value; 6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 67450d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor friend bool operator!=(const QualType &LHS, const QualType &RHS) { 67550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return LHS.Value != RHS.Value; 6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 67749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall std::string getAsString() const { 67849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getAsString(split()); 67949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 68049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static std::string getAsString(SplitQualType split) { 68149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getAsString(split.first, split.second); 68249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 68349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static std::string getAsString(const Type *ty, Qualifiers qs); 684d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 685d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString(const PrintingPolicy &Policy) const { 6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string S; 687d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor getAsStringInternal(S, Policy); 6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return S; 6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 690e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner void getAsStringInternal(std::string &Str, 69149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall const PrintingPolicy &Policy) const { 69249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getAsStringInternal(split(), Str, Policy); 69349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 69449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static void getAsStringInternal(SplitQualType split, std::string &out, 69549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall const PrintingPolicy &policy) { 69649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getAsStringInternal(split.first, split.second, out, policy); 69749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 69849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static void getAsStringInternal(const Type *ty, Qualifiers qs, 69949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall std::string &out, 70049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall const PrintingPolicy &policy); 7011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 702c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump(const char *s) const; 703c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 7041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7053f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 7063f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 7073f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek } 7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 709ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 710ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 7111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 712d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 7130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall inline Qualifiers::GC getObjCGCAttr() const; 714f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 715f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 716f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCWeak() const { 7170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getObjCGCAttr() == Qualifiers::Weak; 718f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 719f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 720f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 721f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCStrong() const { 7220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getObjCGCAttr() == Qualifiers::Strong; 723f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 7242455636163fdd18581d7fdae816433f886d88213Mike Stump 7250d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall enum DestructionKind { 7260d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall DK_none, 7270d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall DK_cxx_destructor 7280d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall }; 7290d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 7300d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// isDestructedType - nonzero if objects of this type require 7310d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// non-trivial work to clean up after. Non-zero because it's 7320d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// conceivable that qualifiers (objc_gc(weak)?) could make 7330d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// something require destruction. 7340d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall DestructionKind isDestructedType() const { 7350d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall return isDestructedTypeImpl(*this); 7360d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall } 7370d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 738bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate: 739bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // These methods are implemented in a separate translation unit; 740bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // "static"-ize them to avoid creating temporary QualTypes in the 741bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // caller. 742bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall static bool isConstant(QualType T, ASTContext& Ctx); 7434ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static QualType getDesugaredType(QualType T, const ASTContext &Context); 74449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static SplitQualType getSplitDesugaredType(QualType T); 74562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall static SplitQualType getSplitUnqualifiedTypeImpl(QualType type); 746075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static QualType IgnoreParens(QualType T); 7470d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall static DestructionKind isDestructedTypeImpl(QualType type); 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 756f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall typedef const ::clang::Type *SimpleType; 7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 7584472fc641ea3069463798fb56a04043c28ea2910Douglas Gregor return Val.getTypePtr(); 7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7644e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 7654e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<> 766daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 7674e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic: 7684e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 7694e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return P.getAsOpaquePtr(); 7704e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 7714e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 7724e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return clang::QualType::getFromOpaquePtr(P); 7734e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 7740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Various qualifiers go in low bits. 7750eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 0 }; 7764e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}; 7771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 77873af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// \brief Base class that is common to both the \c ExtQuals and \c Type 7833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// classes, which allows \c QualType to access the common fields between the 7843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// two. 7853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// 7863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQualsTypeCommonBase { 7873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQualsTypeCommonBase(const Type *baseType, QualType canon) 7883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall : BaseType(baseType), CanonicalType(canon) {} 7893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 7903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// \brief The "base" type of an extended qualifiers type (\c ExtQuals) or 7913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// a self-referential pointer (for \c Type). 7923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// 7933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// This pointer allows an efficient mapping from a QualType to its 7943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// underlying type pointer. 7953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *const BaseType; 7963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 7973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// \brief The canonical type of this type. A QualType. 7983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType CanonicalType; 7993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall friend class QualType; 8013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall friend class Type; 8023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall friend class ExtQuals; 8033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}; 8043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// ExtQuals - We can encode up to four bits in the low bits of a 8063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// type pointer, but there are many more type qualifiers that we want 8073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// to be able to apply to an arbitrary type. Therefore we have this 8083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// struct, intended to be heap-allocated and used by QualType to 8093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// store qualifiers. 8103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// 8113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers 8123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// in three low bits on the QualType pointer; a fourth bit records whether 8133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// the pointer is an ExtQuals node. The extended qualifiers (address spaces, 8143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// Objective-C GC attributes) are much more rare. 8153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { 8163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // NOTE: changing the fast qualifiers should be straightforward as 8173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // long as you don't make 'const' non-fast. 8183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // 1. Qualifiers: 8193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ). 8203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Fast qualifiers must occupy the low-order bits. 8213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // b) Update Qualifiers::FastWidth and FastMask. 8223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // 2. QualType: 8233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // a) Update is{Volatile,Restrict}Qualified(), defined inline. 8243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // b) Update remove{Volatile,Restrict}, defined near the end of 8253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // this header. 8263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // 3. ASTContext: 8273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // a) Update get{Volatile,Restrict}Type. 8283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// Quals - the immutable set of qualifiers applied by this 8303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// node; always contains extended qualifiers. 8313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers Quals; 8323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQuals *this_() { return this; } 8343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic: 8363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQuals(const Type *baseType, QualType canon, Qualifiers quals) 8373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall : ExtQualsTypeCommonBase(baseType, 8383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall canon.isNull() ? QualType(this_(), 0) : canon), 8393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals(quals) 8403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall { 8413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(Quals.hasNonFastQualifiers() 8423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall && "ExtQuals created with no fast qualifiers"); 8433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!Quals.hasFastQualifiers() 8443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall && "ExtQuals created with fast qualifiers"); 8453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 8463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers getQualifiers() const { return Quals; } 8483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); } 8503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); } 8513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall bool hasAddressSpace() const { return Quals.hasAddressSpace(); } 8533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned getAddressSpace() const { return Quals.getAddressSpace(); } 8543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *getBaseType() const { return BaseType; } 8563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic: 8583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall void Profile(llvm::FoldingSetNodeID &ID) const { 8593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Profile(ID, getBaseType(), Quals); 8603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 8613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall static void Profile(llvm::FoldingSetNodeID &ID, 8623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *BaseType, 8633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers Quals) { 8643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!"); 8653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ID.AddPointer(BaseType); 8663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals.Profile(ID); 8673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 8683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}; 8693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 870c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// \brief The kind of C++0x ref-qualifier associated with a function type, 871c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// which determines whether a member function's "this" object can be an 872c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// lvalue, rvalue, or neither. 873c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregorenum RefQualifierKind { 874c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief No ref-qualifier was provided. 875c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RQ_None = 0, 876c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief An lvalue ref-qualifier was provided (\c &). 877c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RQ_LValue, 878c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief An rvalue ref-qualifier was provided (\c &&). 879c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RQ_RValue 880c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor}; 881c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 8865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 89372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 89672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 8985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 9015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 9045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 9065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9071ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass Type : public ExtQualsTypeCommonBase { 9085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 91072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class, 91127935ee59c30b0d8b610ab676aab8e65350af932John McCall#define LAST_TYPE(Class) TypeLast = Class, 91272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 91372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 91472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TagFirst = Record, TagLast = Enum 9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 9161bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 918c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Type(const Type&); // DO NOT IMPLEMENT. 919c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall void operator=(const Type&); // DO NOT IMPLEMENT. 920c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 921b870b88df784c2940efce448ebfaf54dece14666John McCall /// Bitfields required by the Type class. 922b870b88df784c2940efce448ebfaf54dece14666John McCall class TypeBitfields { 923b870b88df784c2940efce448ebfaf54dece14666John McCall friend class Type; 924b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall template <class T> friend class TypePropertyCache; 92527935ee59c30b0d8b610ab676aab8e65350af932John McCall 926b870b88df784c2940efce448ebfaf54dece14666John McCall /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 927b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned TC : 8; 928b870b88df784c2940efce448ebfaf54dece14666John McCall 929b870b88df784c2940efce448ebfaf54dece14666John McCall /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 930b870b88df784c2940efce448ebfaf54dece14666John McCall /// Note that this should stay at the end of the ivars for Type so that 931b870b88df784c2940efce448ebfaf54dece14666John McCall /// subclasses can pack their bitfields into the same word. 932bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet unsigned Dependent : 1; 93360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 934b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief Whether this type is a variably-modified type (C99 6.7.5). 935bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet unsigned VariablyModified : 1; 936d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 937d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this type contains an unexpanded parameter pack 938d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// (for C++0x variadic templates). 939d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned ContainsUnexpandedParameterPack : 1; 94035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 9411fb0caaa7bef765b85972274e3b434af2572c141John McCall /// \brief Nonzero if the cache (i.e. the bitfields here starting 9421fb0caaa7bef765b85972274e3b434af2572c141John McCall /// with 'Cache') is valid. If so, then this is a 9431fb0caaa7bef765b85972274e3b434af2572c141John McCall /// LangOptions::VisibilityMode+1. 9441fb0caaa7bef765b85972274e3b434af2572c141John McCall mutable unsigned CacheValidAndVisibility : 2; 94560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 946b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief Linkage of this type. 947b870b88df784c2940efce448ebfaf54dece14666John McCall mutable unsigned CachedLinkage : 2; 94807a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 949b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief Whether this type involves and local or unnamed types. 950bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet mutable unsigned CachedLocalOrUnnamed : 1; 951db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 952b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief FromAST - Whether this type comes from an AST file. 953bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet mutable unsigned FromAST : 1; 954b870b88df784c2940efce448ebfaf54dece14666John McCall 9551fb0caaa7bef765b85972274e3b434af2572c141John McCall bool isCacheValid() const { 9561fb0caaa7bef765b85972274e3b434af2572c141John McCall return (CacheValidAndVisibility != 0); 9571fb0caaa7bef765b85972274e3b434af2572c141John McCall } 9581fb0caaa7bef765b85972274e3b434af2572c141John McCall Visibility getVisibility() const { 9591fb0caaa7bef765b85972274e3b434af2572c141John McCall assert(isCacheValid() && "getting linkage from invalid cache"); 9601fb0caaa7bef765b85972274e3b434af2572c141John McCall return static_cast<Visibility>(CacheValidAndVisibility-1); 9611fb0caaa7bef765b85972274e3b434af2572c141John McCall } 9621fb0caaa7bef765b85972274e3b434af2572c141John McCall Linkage getLinkage() const { 9631fb0caaa7bef765b85972274e3b434af2572c141John McCall assert(isCacheValid() && "getting linkage from invalid cache"); 9641fb0caaa7bef765b85972274e3b434af2572c141John McCall return static_cast<Linkage>(CachedLinkage); 9651fb0caaa7bef765b85972274e3b434af2572c141John McCall } 9661fb0caaa7bef765b85972274e3b434af2572c141John McCall bool hasLocalOrUnnamedType() const { 9671fb0caaa7bef765b85972274e3b434af2572c141John McCall assert(isCacheValid() && "getting linkage from invalid cache"); 9681fb0caaa7bef765b85972274e3b434af2572c141John McCall return CachedLocalOrUnnamed; 9691fb0caaa7bef765b85972274e3b434af2572c141John McCall } 970b870b88df784c2940efce448ebfaf54dece14666John McCall }; 971d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor enum { NumTypeBits = 17 }; 972b870b88df784c2940efce448ebfaf54dece14666John McCall 973b870b88df784c2940efce448ebfaf54dece14666John McCallprotected: 974b870b88df784c2940efce448ebfaf54dece14666John McCall // These classes allow subclasses to somewhat cleanly pack bitfields 975b870b88df784c2940efce448ebfaf54dece14666John McCall // into Type. 976b870b88df784c2940efce448ebfaf54dece14666John McCall 977b870b88df784c2940efce448ebfaf54dece14666John McCall class ArrayTypeBitfields { 978b870b88df784c2940efce448ebfaf54dece14666John McCall friend class ArrayType; 979b870b88df784c2940efce448ebfaf54dece14666John McCall 980b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 981b870b88df784c2940efce448ebfaf54dece14666John McCall 982b870b88df784c2940efce448ebfaf54dece14666John McCall /// IndexTypeQuals - CVR qualifiers from declarations like 983b870b88df784c2940efce448ebfaf54dece14666John McCall /// 'int X[static restrict 4]'. For function parameters only. 984b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned IndexTypeQuals : 3; 985b870b88df784c2940efce448ebfaf54dece14666John McCall 986b870b88df784c2940efce448ebfaf54dece14666John McCall /// SizeModifier - storage class qualifiers from declarations like 987b870b88df784c2940efce448ebfaf54dece14666John McCall /// 'int X[static restrict 4]'. For function parameters only. 988b870b88df784c2940efce448ebfaf54dece14666John McCall /// Actually an ArrayType::ArraySizeModifier. 989b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned SizeModifier : 3; 990b870b88df784c2940efce448ebfaf54dece14666John McCall }; 991b870b88df784c2940efce448ebfaf54dece14666John McCall 992b870b88df784c2940efce448ebfaf54dece14666John McCall class BuiltinTypeBitfields { 993b870b88df784c2940efce448ebfaf54dece14666John McCall friend class BuiltinType; 994b870b88df784c2940efce448ebfaf54dece14666John McCall 995b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 996b870b88df784c2940efce448ebfaf54dece14666John McCall 997b870b88df784c2940efce448ebfaf54dece14666John McCall /// The kind (BuiltinType::Kind) of builtin type this is. 998b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned Kind : 8; 999b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1000b870b88df784c2940efce448ebfaf54dece14666John McCall 1001b870b88df784c2940efce448ebfaf54dece14666John McCall class FunctionTypeBitfields { 1002b870b88df784c2940efce448ebfaf54dece14666John McCall friend class FunctionType; 1003b870b88df784c2940efce448ebfaf54dece14666John McCall 1004b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 1005b870b88df784c2940efce448ebfaf54dece14666John McCall 1006b870b88df784c2940efce448ebfaf54dece14666John McCall /// Extra information which affects how the function is called, like 1007b870b88df784c2940efce448ebfaf54dece14666John McCall /// regparm and the calling convention. 1008b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned ExtInfo : 8; 1009b870b88df784c2940efce448ebfaf54dece14666John McCall 1010e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall /// Whether the function is variadic. Only used by FunctionProtoType. 1011e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned Variadic : 1; 1012b870b88df784c2940efce448ebfaf54dece14666John McCall 1013b870b88df784c2940efce448ebfaf54dece14666John McCall /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1014b870b88df784c2940efce448ebfaf54dece14666John McCall /// other bitfields. 1015b870b88df784c2940efce448ebfaf54dece14666John McCall /// The qualifiers are part of FunctionProtoType because... 1016b870b88df784c2940efce448ebfaf54dece14666John McCall /// 1017b870b88df784c2940efce448ebfaf54dece14666John McCall /// C++ 8.3.5p4: The return type, the parameter type list and the 1018b870b88df784c2940efce448ebfaf54dece14666John McCall /// cv-qualifier-seq, [...], are part of the function type. 1019b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned TypeQuals : 3; 1020c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 1021c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief The ref-qualifier associated with a \c FunctionProtoType. 1022c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// 1023c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// This is a value of type \c RefQualifierKind. 1024c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor unsigned RefQualifier : 2; 1025b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1026b870b88df784c2940efce448ebfaf54dece14666John McCall 1027b870b88df784c2940efce448ebfaf54dece14666John McCall class ObjCObjectTypeBitfields { 1028b870b88df784c2940efce448ebfaf54dece14666John McCall friend class ObjCObjectType; 1029b870b88df784c2940efce448ebfaf54dece14666John McCall 1030b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 1031b870b88df784c2940efce448ebfaf54dece14666John McCall 1032b870b88df784c2940efce448ebfaf54dece14666John McCall /// NumProtocols - The number of protocols stored directly on this 1033b870b88df784c2940efce448ebfaf54dece14666John McCall /// object type. 1034b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned NumProtocols : 32 - NumTypeBits; 1035b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1036b870b88df784c2940efce448ebfaf54dece14666John McCall 1037b870b88df784c2940efce448ebfaf54dece14666John McCall class ReferenceTypeBitfields { 1038b870b88df784c2940efce448ebfaf54dece14666John McCall friend class ReferenceType; 1039b870b88df784c2940efce448ebfaf54dece14666John McCall 1040b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 1041b870b88df784c2940efce448ebfaf54dece14666John McCall 1042b870b88df784c2940efce448ebfaf54dece14666John McCall /// True if the type was originally spelled with an lvalue sigil. 1043b870b88df784c2940efce448ebfaf54dece14666John McCall /// This is never true of rvalue references but can also be false 1044b870b88df784c2940efce448ebfaf54dece14666John McCall /// on lvalue references because of C++0x [dcl.typedef]p9, 1045b870b88df784c2940efce448ebfaf54dece14666John McCall /// as follows: 1046b870b88df784c2940efce448ebfaf54dece14666John McCall /// 1047b870b88df784c2940efce448ebfaf54dece14666John McCall /// typedef int &ref; // lvalue, spelled lvalue 1048b870b88df784c2940efce448ebfaf54dece14666John McCall /// typedef int &&rvref; // rvalue 1049b870b88df784c2940efce448ebfaf54dece14666John McCall /// ref &a; // lvalue, inner ref, spelled lvalue 1050b870b88df784c2940efce448ebfaf54dece14666John McCall /// ref &&a; // lvalue, inner ref 1051b870b88df784c2940efce448ebfaf54dece14666John McCall /// rvref &a; // lvalue, inner ref, spelled lvalue 1052b870b88df784c2940efce448ebfaf54dece14666John McCall /// rvref &&a; // rvalue, inner ref 1053bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet unsigned SpelledAsLValue : 1; 1054b870b88df784c2940efce448ebfaf54dece14666John McCall 1055b870b88df784c2940efce448ebfaf54dece14666John McCall /// True if the inner type is a reference type. This only happens 1056b870b88df784c2940efce448ebfaf54dece14666John McCall /// in non-canonical forms. 1057bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet unsigned InnerRef : 1; 1058b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1059b870b88df784c2940efce448ebfaf54dece14666John McCall 106077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall class TypeWithKeywordBitfields { 106177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall friend class TypeWithKeyword; 106277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall 106377be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall unsigned : NumTypeBits; 106477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall 106577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall /// An ElaboratedTypeKeyword. 8 bits for efficient access. 106677be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall unsigned Keyword : 8; 106777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall }; 106877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall 1069b870b88df784c2940efce448ebfaf54dece14666John McCall class VectorTypeBitfields { 1070b870b88df784c2940efce448ebfaf54dece14666John McCall friend class VectorType; 107107a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 1072b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 107371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 1074e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson /// VecKind - The kind of vector, either a generic vector type or some 1075e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson /// target-specific vector type such as for AltiVec or Neon. 1076cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson unsigned VecKind : 3; 1077b870b88df784c2940efce448ebfaf54dece14666John McCall 1078b870b88df784c2940efce448ebfaf54dece14666John McCall /// NumElements - The number of elements in the vector. 1079cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson unsigned NumElements : 29 - NumTypeBits; 1080b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1081b870b88df784c2940efce448ebfaf54dece14666John McCall 10829d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall class AttributedTypeBitfields { 10839d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall friend class AttributedType; 10849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 10859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall unsigned : NumTypeBits; 10869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 10879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// AttrKind - an AttributedType::Kind 10889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall unsigned AttrKind : 32 - NumTypeBits; 10899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall }; 10909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 1091b870b88df784c2940efce448ebfaf54dece14666John McCall union { 1092b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBitfields TypeBits; 1093b870b88df784c2940efce448ebfaf54dece14666John McCall ArrayTypeBitfields ArrayTypeBits; 10949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeBitfields AttributedTypeBits; 1095b870b88df784c2940efce448ebfaf54dece14666John McCall BuiltinTypeBitfields BuiltinTypeBits; 1096b870b88df784c2940efce448ebfaf54dece14666John McCall FunctionTypeBitfields FunctionTypeBits; 1097b870b88df784c2940efce448ebfaf54dece14666John McCall ObjCObjectTypeBitfields ObjCObjectTypeBits; 1098b870b88df784c2940efce448ebfaf54dece14666John McCall ReferenceTypeBitfields ReferenceTypeBits; 109977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall TypeWithKeywordBitfields TypeWithKeywordBits; 1100b870b88df784c2940efce448ebfaf54dece14666John McCall VectorTypeBitfields VectorTypeBits; 1101b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1102b870b88df784c2940efce448ebfaf54dece14666John McCall 1103b870b88df784c2940efce448ebfaf54dece14666John McCallprivate: 11043c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl /// \brief Set whether this type comes from an AST file. 11053c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl void setFromAST(bool V = true) const { 1106b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.FromAST = V; 110707a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl } 110807a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 1109b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall template <class T> friend class TypePropertyCache; 11101fb0caaa7bef765b85972274e3b434af2572c141John McCall 11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 1112124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 1113124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 11143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Type(TypeClass tc, QualType canon, bool Dependent, bool VariablyModified, 1115d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool ContainsUnexpandedParameterPack) 11163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall : ExtQualsTypeCommonBase(this, 11173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall canon.isNull() ? QualType(this_(), 0) : canon) { 1118b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.TC = tc; 1119b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.Dependent = Dependent; 1120b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.VariablyModified = VariablyModified; 1121d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 11221fb0caaa7bef765b85972274e3b434af2572c141John McCall TypeBits.CacheValidAndVisibility = 0; 1123b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.CachedLocalOrUnnamed = false; 1124b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.CachedLinkage = NoLinkage; 1125b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.FromAST = false; 1126b870b88df784c2940efce448ebfaf54dece14666John McCall } 11275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 11281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1129b870b88df784c2940efce448ebfaf54dece14666John McCall void setDependent(bool D = true) { TypeBits.Dependent = D; } 1130b870b88df784c2940efce448ebfaf54dece14666John McCall void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; } 1131d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor void setContainsUnexpandedParameterPack(bool PP = true) { 1132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor TypeBits.ContainsUnexpandedParameterPack = PP; 1133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 1134d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 11358b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 1136b870b88df784c2940efce448ebfaf54dece14666John McCall TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); } 11371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11383c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl /// \brief Whether this type comes from an AST file. 1139b870b88df784c2940efce448ebfaf54dece14666John McCall bool isFromAST() const { return TypeBits.FromAST; } 114007a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 1141d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this type is or contains an unexpanded parameter 1142d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// pack, used to support C++0x variadic templates. 1143d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 1144d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// A type that contains a parameter pack shall be expanded by the 1145d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// ellipsis operator at some point. For example, the typedef in the 1146d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// following example contains an unexpanded parameter pack 'T': 1147d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 1148d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \code 1149d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// template<typename ...T> 1150d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// struct X { 1151d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// typedef T* pointer_types; // ill-formed; T is a parameter pack. 1152d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// }; 1153d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \endcode 1154d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 1155d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// Note that this routine does not specify which 1156d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool containsUnexpandedParameterPack() const { 1157d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return TypeBits.ContainsUnexpandedParameterPack; 1158d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 1159d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 11603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// Determines if this type would be canonical if it had no further 11613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// qualification. 1162467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall bool isCanonicalUnqualified() const { 11633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return CanonicalType == QualType(this, 0); 1164467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall } 11655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 11675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 11681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 11705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 11715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 11721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// routine will need to determine if the size is actually required. 11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncompleteType() const; 1174d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner 1175d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 1176d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// type, in other words, not a function type. 1177d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner bool isIncompleteOrObjectType() const { 1178d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner return !isFunctionType(); 1179d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner } 11802fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor 11812fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor /// \brief Determine whether this type is an object type. 11822fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor bool isObjectType() const { 11832fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor // C++ [basic.types]p8: 11842fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor // An object type is a (possibly cv-qualified) type that is not a 11852fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor // function type, not a reference type, and not a void type. 11862fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor return !isReferenceType() && !isFunctionType() && !isVoidType(); 11872fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor } 118864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 118964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 119064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl bool isPODType() const; 119164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 1192ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl /// isLiteralType - Return true if this is a literal type 1193ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl /// (C++0x [basic.types]p10) 1194ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl bool isLiteralType() const; 1195ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 119620c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley /// isTrivialType - Return true if this is a trivial type 1197b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth /// (C++0x [basic.types]p9) 1198b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth bool isTrivialType() const; 1199b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth 1200feb375d31b7e9108b04a9f55b721d5e0c793a558Sean Hunt /// isTriviallyCopyableType - Return true if this is a trivially copyable type 1201feb375d31b7e9108b04a9f55b721d5e0c793a558Sean Hunt /// (C++0x [basic.types]p9 1202feb375d31b7e9108b04a9f55b721d5e0c793a558Sean Hunt bool isTriviallyCopyableType() const; 1203feb375d31b7e9108b04a9f55b721d5e0c793a558Sean Hunt 1204636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth /// \brief Test if this type is a standard-layout type. 1205636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth /// (C++0x [basic.type]p9) 1206636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth bool isStandardLayoutType() const; 1207636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 120843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth /// isCXX11PODType() - Return true if this is a POD type according to the 120943fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth /// more relaxed rules of the C++11 standard, regardless of the current 121043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth /// compilation's language. 121143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth /// (C++0x [basic.types]p9) 121243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth bool isCXX11PODType() const; 121343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 12145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 1215ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 1216e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 12179b065ddabf572772991a4aadad5bf4921fac5069Tom Care /// isBuiltinType - returns true if the type is a builtin type. 12189b065ddabf572772991a4aadad5bf4921fac5069Tom Care bool isBuiltinType() const; 12199b065ddabf572772991a4aadad5bf4921fac5069Tom Care 1220e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 1221e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 12221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12232a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// isPlaceholderType - Test for a type which does not represent an 12242a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// actual type-system type but is instead used as a placeholder for 12252a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// various convenient purposes within Clang. All such types are 12262a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// BuiltinTypes. 12272a984cad5ac3fdceeff2bd99daa7b90979313475John McCall bool isPlaceholderType() const; 12282a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 1229864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// isSpecificPlaceholderType - Test for a specific placeholder type. 1230864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall bool isSpecificPlaceholderType(unsigned K) const; 1231864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 123296d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 123396d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 123513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 123613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 123713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 123877a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor bool isWideCharType() const; 123920093b4bf698f292c664676987541d5103b65b15Douglas Gregor bool isAnyCharacterType() const; 12409d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor bool isIntegralType(ASTContext &Ctx) const; 124120093b4bf698f292c664676987541d5103b65b15Douglas Gregor 12422ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor /// \brief Determine whether this type is an integral or enumeration type. 12432ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor bool isIntegralOrEnumerationType() const; 12441274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor /// \brief Determine whether this type is an integral or unscoped enumeration 12451274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor /// type. 12461274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor bool isIntegralOrUnscopedEnumerationType() const; 12472ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor 12485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 12495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 125002f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 125102f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 12525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 1253f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 12545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 12555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 12565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 1257c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 1258c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 1259c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 1260d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor bool isAggregateType() const; 1261aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth bool isFundamentalType() const; 1262aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth bool isCompoundType() const; 12631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1264c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 1265ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 1266c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 1267183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } 1268183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } 1269befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 127058f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 12715618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff bool isBlockPointerType() const; 12727154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff bool isVoidPointerType() const; 1273a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 12747c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isLValueReferenceType() const; 12757c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isRValueReferenceType() const; 1276bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isFunctionPointerType() const; 1277f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberPointerType() const; 1278f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberFunctionPointerType() const; 1279db68e28c05a67735211e688009890cf834c22e75Douglas Gregor bool isMemberDataPointerType() const; 1280c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 1281c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isConstantArrayType() const; 1282c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isIncompleteArrayType() const; 1283c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isVariableArrayType() const; 1284898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentSizedArrayType() const; 1285c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 12861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isClassType() const; 12871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isStructureType() const; 1288fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor bool isStructureOrClassType() const; 12894cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 1290368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 1291368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isVectorType() const; // GCC vector type. 1292213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman bool isExtVectorType() const; // Extended vector type. 1293d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 129414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // FIXME: change this to 'raw' interface type, so we can used 'interface' type 129514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for the common case. 1296c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCObjectType() const; // NSString or typeof(*(id)0) 1297368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 1298368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedIdType() const; // id<foo> 1299470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const; // Class<foo> 1300569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor bool isObjCObjectOrInterfaceType() const; 130114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const; // id 130214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const; // Class 130313dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian bool isObjCSelType() const; // Class 1304de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff bool isObjCBuiltinType() const; // 'id' or 'Class' 130572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 13066e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 1307898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1308daa8e4e888758d55a7a759dd4a91b83921cef222John McCall enum ScalarTypeKind { 1309daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_Pointer, 1310daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_MemberPointer, 1311daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_Bool, 1312daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_Integral, 1313daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_Floating, 1314daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_IntegralComplex, 1315daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_FloatingComplex 1316daa8e4e888758d55a7a759dd4a91b83921cef222John McCall }; 1317daa8e4e888758d55a7a759dd4a91b83921cef222John McCall /// getScalarTypeKind - Given that this is a scalar type, classify it. 1318daa8e4e888758d55a7a759dd4a91b83921cef222John McCall ScalarTypeKind getScalarTypeKind() const; 1319daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 1320898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// that its definition somehow depends on a template parameter 1322898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.type]). 1323b870b88df784c2940efce448ebfaf54dece14666John McCall bool isDependentType() const { return TypeBits.Dependent; } 132435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 132535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor /// \brief Whether this type is a variably-modified type (C99 6.7.5). 1326b870b88df784c2940efce448ebfaf54dece14666John McCall bool isVariablyModifiedType() const { return TypeBits.VariablyModified; } 13273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 13283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// \brief Whether this type involves a variable-length array type 13293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// with a definite size. 13303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall bool hasSizedVLAType() const; 133135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 1332db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor /// \brief Whether this type is or contains a local or unnamed type. 1333db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor bool hasUnnamedOrLocalType() const; 1334db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 1335063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor bool isOverloadableType() const; 133672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 13374033642464e8ba0982f88f34cffad808d247b393Douglas Gregor /// \brief Determine wither this type is a C++ elaborated-type-specifier. 13384033642464e8ba0982f88f34cffad808d247b393Douglas Gregor bool isElaboratedTypeSpecifier() const; 13394033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 13408958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 13418958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 13428958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 13436e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl /// interface types, as well as nullptr_t. 13448958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar bool hasPointerRepresentation() const; 13458958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 1346820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 1347820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 13481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool hasObjCPointerRepresentation() const; 1349820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 1350f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// \brief Determine whether this type has an integer representation 1351f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// of some sort, e.g., it is an integer type or a vector. 1352f60946222721d9ba3c059563935c17b84703187aDouglas Gregor bool hasIntegerRepresentation() const; 1353f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 1354f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// \brief Determine whether this type has an signed integer representation 1355f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// of some sort, e.g., it is an signed integer type or a vector. 1356f60946222721d9ba3c059563935c17b84703187aDouglas Gregor bool hasSignedIntegerRepresentation() const; 1357f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 1358f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// \brief Determine whether this type has an unsigned integer representation 1359f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// of some sort, e.g., it is an unsigned integer type or a vector. 1360f60946222721d9ba3c059563935c17b84703187aDouglas Gregor bool hasUnsignedIntegerRepresentation() const; 1361f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 13628eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor /// \brief Determine whether this type has a floating-point representation 13638eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor /// of some sort, e.g., it is a floating-point type or a vector thereof. 13648eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor bool hasFloatingRepresentation() const; 1365f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 1366c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 1367f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 1368f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 1369769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const RecordType *getAsStructureType() const; 1370898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 1371c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 13724cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 137314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // The following is a convenience method that returns an ObjCObjectPointerType 137414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for object declared using an interface. 137514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 137614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 1377759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian const ObjCObjectPointerType *getAsObjCQualifiedClassType() const; 1378c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *getAsObjCQualifiedInterfaceType() const; 1379a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1381c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor /// \brief Retrieves the CXXRecordDecl that this type refers to, either 1382c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor /// because the type is a RecordType or because it is the injected-class-name 1383c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor /// type of a class template or class template partial specialization. 1384c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor CXXRecordDecl *getAsCXXRecordDecl() const; 138534b41d939a1328f484511c6002ba2456db879a29Richard Smith 138634b41d939a1328f484511c6002ba2456db879a29Richard Smith /// \brief Get the AutoType whose type will be deduced for a variable with 138734b41d939a1328f484511c6002ba2456db879a29Richard Smith /// an initializer of this type. This looks through declarators like pointer 138834b41d939a1328f484511c6002ba2456db879a29Richard Smith /// types, but not through decltype or typedefs. 138934b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *getContainedAutoType() const; 1390c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 1391d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// Member-template getAs<specific type>'. Look through sugar for 1392d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// an instance of <specific type>. This scheme will eventually 1393d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// replace the specific getAsXXXX methods above. 1394d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// 1395d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// There are some specializations of this member template listed 1396d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// immediately following this class. 13971a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek template <typename T> const T *getAs() const; 13981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// A variant of getAs<> for array types which silently discards 14003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// qualifiers from the outermost type. 14013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ArrayType *getAsArrayTypeUnsafe() const; 14023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 1403d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// Member-template castAs<specific type>. Look through sugar for 1404d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// the underlying instance of <specific type>. 1405d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// 1406d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// This method has the same relationship to getAs<T> as cast<T> has 1407d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// to dyn_cast<T>; which is to say, the underlying type *must* 1408d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// have the intended type, and this method will never return null. 1409d0370f59e79702ac908c81bf556519f91e9ca297John McCall template <typename T> const T *castAs() const; 1410d0370f59e79702ac908c81bf556519f91e9ca297John McCall 1411d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// A variant of castAs<> for array type which silently discards 1412d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// qualifiers from the outermost type. 1413d0370f59e79702ac908c81bf556519f91e9ca297John McCall const ArrayType *castAsArrayTypeUnsafe() const; 1414d0370f59e79702ac908c81bf556519f91e9ca297John McCall 1415d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// getBaseElementTypeUnsafe - Get the base element type of this 1416d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// type, potentially discarding type qualifiers. This method 1417d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// should never be used when type qualifiers are meaningful. 1418d0370f59e79702ac908c81bf556519f91e9ca297John McCall const Type *getBaseElementTypeUnsafe() const; 1419d0370f59e79702ac908c81bf556519f91e9ca297John McCall 1420c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 1421c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// element type of the array, potentially with type qualifiers missing. 1422c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// This method should never be used when type qualifiers are meaningful. 1423c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 14241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1425f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// getPointeeType - If this is a pointer, ObjC object pointer, or block 1426f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// pointer, this returns the respective pointee. 142714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const; 14281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1429bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// getUnqualifiedDesugaredType() - Return the specified type with 1430bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// any "sugar" removed from the type, removing any typedefs, 1431bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// typeofs, etc., as well as any qualifiers. 1432bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *getUnqualifiedDesugaredType() const; 14331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 14355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 14365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 1438d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 14395f3827cabd526d0dd5f291d46c310103cebe7a44Eli Friedman /// or an enum decl which has a signed representation. 14405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 14415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 14435f3827cabd526d0dd5f291d46c310103cebe7a44Eli Friedman /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], 14445f3827cabd526d0dd5f291d46c310103cebe7a44Eli Friedman /// or an enum decl which has an unsigned representation. 14455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 1446d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 1447575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor /// Determines whether this is an integer type that is signed or an 1448575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor /// enumeration types whose underlying type is a signed integer type. 1449575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor bool isSignedIntegerOrEnumerationType() const; 1450575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 1451575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor /// Determines whether this is an integer type that is unsigned or an 1452575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor /// enumeration types whose underlying type is a unsigned integer type. 1453575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor bool isUnsignedIntegerOrEnumerationType() const; 1454575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 14555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 14569bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 14579bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 14583c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 1459c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 146022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 146122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// set of type specifiers. 146222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman bool isSpecifierType() const; 146322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 14640b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor /// \brief Determine the linkage of this type. 146560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor Linkage getLinkage() const; 14661fb0caaa7bef765b85972274e3b434af2572c141John McCall 14671fb0caaa7bef765b85972274e3b434af2572c141John McCall /// \brief Determine the visibility of this type. 14681fb0caaa7bef765b85972274e3b434af2572c141John McCall Visibility getVisibility() const; 14691fb0caaa7bef765b85972274e3b434af2572c141John McCall 14701fb0caaa7bef765b85972274e3b434af2572c141John McCall /// \brief Determine the linkage and visibility of this type. 14711fb0caaa7bef765b85972274e3b434af2572c141John McCall std::pair<Linkage,Visibility> getLinkageAndVisibility() const; 147260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 147360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor /// \brief Note that the linkage is no longer known. 147460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor void ClearLinkageCache(); 147560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 147660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor const char *getTypeClassName() const; 14770b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1478ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall QualType getCanonicalTypeInternal() const { 1479ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall return CanonicalType; 1480ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall } 1481ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h 1482c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 1484be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis 1485c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl friend class ASTReader; 1486a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl friend class ASTWriter; 14875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1489183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const { 1490183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall return dyn_cast<TypedefType>(this); 1491183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall} 1492183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 1493183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to 1494183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration. 1495183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base) 1496183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \ 1497183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \ 14980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return dyn_cast<Class##Type>(CanonicalType); \ 1499d0370f59e79702ac908c81bf556519f91e9ca297John McCall} \ 1500d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <> inline const Class##Type *Type::castAs() const { \ 1501d0370f59e79702ac908c81bf556519f91e9ca297John McCall return cast<Class##Type>(CanonicalType); \ 1502183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall} 1503183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def" 1504183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 1505183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 15065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 15075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 15085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 15095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 15115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Void, 15121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Bool, // This is bool and/or _Bool. 15145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_U, // This is 'char' for targets where char is unsigned. 15155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UChar, // This is explicitly qualified unsigned char. 15163f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner WChar_U, // This is 'wchar_t' for C++, when unsigned. 1517f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char16, // This is 'char16_t' for C++. 1518f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char32, // This is 'char32_t' for C++. 15195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UShort, 15205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UInt, 15215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULong, 15225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULongLong, 15232df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner UInt128, // __uint128_t 15241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_S, // This is 'char' for targets where char is signed. 15265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SChar, // This is explicitly qualified signed char. 15273f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner WChar_S, // This is 'wchar_t' for C++, when signed. 15285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Short, 15295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Int, 15305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Long, 15315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongLong, 15322df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner Int128, // __int128_t 15331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15348e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor Float, Double, LongDouble, 15358e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 15366e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 15376e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 1538864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// The primitive Objective C 'id' type. The user-visible 'id' 1539864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// type is a typedef of an ObjCObjectPointerType to an 1540864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// ObjCObjectType with this as its base. In fact, this only ever 1541864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// shows up in an AST as the base type of an ObjCObjectType. 1542864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall ObjCId, 1543864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 1544864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// The primitive Objective C 'Class' type. The user-visible 1545864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// 'Class' type is a typedef of an ObjCObjectPointerType to an 1546864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// ObjCObjectType with this as its base. In fact, this only ever 1547864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// shows up in an AST as the base type of an ObjCObjectType. 1548864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall ObjCClass, 1549864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 1550864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// The primitive Objective C 'SEL' type. The user-visible 'SEL' 1551864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// type is a typedef of a PointerType to this. 1552864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall ObjCSel, 1553864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 15542a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// This represents the type of an expression whose type is 15552a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// totally unknown, e.g. 'T::foo'. It is permitted for this to 15562a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// appear in situations where the structure of the type is 15572a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// theoretically deducible. 15582a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Dependent, 15592a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 1560864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// The type of an unresolved overload set. A placeholder type. 1561864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// Expressions with this type have one of the following basic 1562864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// forms, with parentheses generally permitted: 1563864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// foo # possibly qualified, not if an implicit access 1564864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// foo # possibly qualified, not if an implicit access 1565864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// &foo # possibly qualified, not if an implicit access 1566864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// x->foo # only if might be a static member function 1567864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// &x->foo # only if might be a static member function 1568864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// &Class::foo # when a pointer-to-member; sub-expr also has this type 1569864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// OverloadExpr::find can be used to analyze the expression. 15701de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall Overload, 15711de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall 1572864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// The type of a bound C++ non-static member function. 1573864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// A placeholder type. Expressions with this type have one of the 1574864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// following basic forms: 1575864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// foo # if an implicit access 1576864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// x->foo # if only contains non-static members 1577864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall BoundMember, 1578864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 1579864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// __builtin_any_type. A placeholder type. Useful for clients 1580864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// like debuggers that don't know what type to give something. 1581864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// Only a small number of operations are valid on expressions of 1582864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// unknown type, most notably explicit casts. 1583864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall UnknownAny 15845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 158571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 15865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BuiltinType(Kind K) 158835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent), 1589d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 1590d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*Unexpanded paramter pack=*/false) { 1591b870b88df784c2940efce448ebfaf54dece14666John McCall BuiltinTypeBits.Kind = K; 159271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1594b870b88df784c2940efce448ebfaf54dece14666John McCall Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); } 1595e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const char *getName(const LangOptions &LO) const; 15961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1597bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1598bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1599bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1600680523a91dd3351389667c8de17121ba7ae82673John McCall bool isInteger() const { 160171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Bool && getKind() <= Int128; 1602680523a91dd3351389667c8de17121ba7ae82673John McCall } 1603680523a91dd3351389667c8de17121ba7ae82673John McCall 1604680523a91dd3351389667c8de17121ba7ae82673John McCall bool isSignedInteger() const { 160571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Char_S && getKind() <= Int128; 1606680523a91dd3351389667c8de17121ba7ae82673John McCall } 1607680523a91dd3351389667c8de17121ba7ae82673John McCall 1608680523a91dd3351389667c8de17121ba7ae82673John McCall bool isUnsignedInteger() const { 160971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Bool && getKind() <= UInt128; 1610680523a91dd3351389667c8de17121ba7ae82673John McCall } 1611680523a91dd3351389667c8de17121ba7ae82673John McCall 1612680523a91dd3351389667c8de17121ba7ae82673John McCall bool isFloatingPoint() const { 161371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Float && getKind() <= LongDouble; 1614680523a91dd3351389667c8de17121ba7ae82673John McCall } 1615680523a91dd3351389667c8de17121ba7ae82673John McCall 1616864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// Determines whether this type is a placeholder type, i.e. a type 1617864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// which cannot appear in arbitrary positions in a fully-formed 1618864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// expression. 16192a984cad5ac3fdceeff2bd99daa7b90979313475John McCall bool isPlaceholderType() const { 1620864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return getKind() >= Overload; 16212a984cad5ac3fdceeff2bd99daa7b90979313475John McCall } 16222a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 16235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 16245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 16255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 16285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 16295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 16305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 16315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 16325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 163335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(Complex, CanonicalPtr, Element->isDependentType(), 1634d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Element->isVariablyModifiedType(), 1635d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Element->containsUnexpandedParameterPack()), 1636898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(Element) { 16375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 163960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 16405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 16415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 16421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1643bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1644bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1645bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 16465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 16475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 16485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 16505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 16515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 16545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 16555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1657075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// ParenType - Sugar for parentheses used when specifying types. 1658075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// 1659075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenType : public Type, public llvm::FoldingSetNode { 1660075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Inner; 1661075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1662075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenType(QualType InnerType, QualType CanonType) : 1663075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Type(Paren, CanonType, InnerType->isDependentType(), 1664d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor InnerType->isVariablyModifiedType(), 1665d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor InnerType->containsUnexpandedParameterPack()), 1666075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner(InnerType) { 1667075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1668075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara friend class ASTContext; // ASTContext creates these. 1669075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1670075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic: 1671075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1672075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType getInnerType() const { return Inner; } 1673075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1674075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara bool isSugared() const { return true; } 1675075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType desugar() const { return getInnerType(); } 1676075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1677075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara void Profile(llvm::FoldingSetNodeID &ID) { 1678075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Profile(ID, getInnerType()); 1679075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1680075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) { 1681075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner.Profile(ID); 1682075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1683075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1684075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static bool classof(const Type *T) { return T->getTypeClass() == Paren; } 1685075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static bool classof(const ParenType *) { return true; } 1686075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}; 1687075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 168868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 1689bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// 169068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 1691bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType PointeeType; 16925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 169435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(Pointer, CanonicalPtr, Pointee->isDependentType(), 1695d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->isVariablyModifiedType(), 1696d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->containsUnexpandedParameterPack()), 169735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor PointeeType(Pointee) { 16985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 170060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 17015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 17021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 170368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 170468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 1705bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1706bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1707bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 17085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 17095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 17105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 17125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 17135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 17165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 17175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17195618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type. 17205618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as 17215618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 17225618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// 17235618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 17245618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 17255618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 172635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(BlockPointer, CanonicalCls, Pointee->isDependentType(), 1727d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->isVariablyModifiedType(), 1728d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->containsUnexpandedParameterPack()), 1729898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor PointeeType(Pointee) { 17305618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 17315618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff friend class ASTContext; // ASTContext creates these. 173260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 17335618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic: 17341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17355618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 17365618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType getPointeeType() const { return PointeeType; } 17375618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 1738bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1739bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1740bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 17415618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 17425618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Profile(ID, getPointeeType()); 17435618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 17445618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 17455618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 17465618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 17471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 17491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == BlockPointer; 17505618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 17515618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 17525618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}; 17535618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 17547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 17555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 175668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 175768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType PointeeType; 175868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 17597c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected: 176054e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, 176154e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) : 176235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(tc, CanonicalRef, Referencee->isDependentType(), 1763d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Referencee->isVariablyModifiedType(), 1764d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Referencee->containsUnexpandedParameterPack()), 1765d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor PointeeType(Referencee) 1766d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor { 1767b870b88df784c2940efce448ebfaf54dece14666John McCall ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue; 1768b870b88df784c2940efce448ebfaf54dece14666John McCall ReferenceTypeBits.InnerRef = Referencee->isReferenceType(); 17695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 177060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 17715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1772b870b88df784c2940efce448ebfaf54dece14666John McCall bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; } 1773b870b88df784c2940efce448ebfaf54dece14666John McCall bool isInnerRef() const { return ReferenceTypeBits.InnerRef; } 177473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor 177554e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType getPointeeTypeAsWritten() const { return PointeeType; } 177654e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType getPointeeType() const { 177754e14c4db764c0636160d26c5bbf491637c83a76John McCall // FIXME: this might strip inner qualifiers; okay? 177854e14c4db764c0636160d26c5bbf491637c83a76John McCall const ReferenceType *T = this; 177971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall while (T->isInnerRef()) 1780d0370f59e79702ac908c81bf556519f91e9ca297John McCall T = T->PointeeType->castAs<ReferenceType>(); 178154e14c4db764c0636160d26c5bbf491637c83a76John McCall return T->PointeeType; 178254e14c4db764c0636160d26c5bbf491637c83a76John McCall } 178368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 17845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 178571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall Profile(ID, PointeeType, isSpelledAsLValue()); 17865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 178754e14c4db764c0636160d26c5bbf491637c83a76John McCall static void Profile(llvm::FoldingSetNodeID &ID, 178854e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType Referencee, 178954e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) { 17905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 179154e14c4db764c0636160d26c5bbf491637c83a76John McCall ID.AddBoolean(SpelledAsLValue); 17925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17947c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 17957c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference || 17967c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl T->getTypeClass() == RValueReference; 17977c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 17985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 17997c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 18007c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 18017c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 18027c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 18037c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType { 180454e14c4db764c0636160d26c5bbf491637c83a76John McCall LValueReferenceType(QualType Referencee, QualType CanonicalRef, 180554e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) : 180654e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue) 180754e14c4db764c0636160d26c5bbf491637c83a76John McCall {} 18087c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 18097c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 1810bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1811bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1812bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 18137c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 18147c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference; 18157c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 18167c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 18177c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 18187c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 18197c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 18207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 18217c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType { 18227c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 182354e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(RValueReference, Referencee, CanonicalRef, false) { 18247c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 18257c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 18267c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 1827bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1828bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1829bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 18307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 18317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == RValueReference; 18327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 18337c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 1834f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}; 1835f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1836f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 1837f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// 1838f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 1839f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType PointeeType; 1840f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 1841f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 1842f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class; 1843f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1844f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 1845f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Type(MemberPointer, CanonicalPtr, 184635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Cls->isDependentType() || Pointee->isDependentType(), 1847d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->isVariablyModifiedType(), 1848d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (Cls->containsUnexpandedParameterPack() || 1849d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->containsUnexpandedParameterPack())), 1850f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointeeType(Pointee), Class(Cls) { 1851f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1852f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl friend class ASTContext; // ASTContext creates these. 185360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 1854f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic: 1855f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType getPointeeType() const { return PointeeType; } 1856f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 18570bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Returns true if the member type (i.e. the pointee type) is a 18580bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// function type rather than a data-member type. 18590bab0cdab751248ca389a5592bcb70eac5d39260John McCall bool isMemberFunctionPointer() const { 18600bab0cdab751248ca389a5592bcb70eac5d39260John McCall return PointeeType->isFunctionProtoType(); 18610bab0cdab751248ca389a5592bcb70eac5d39260John McCall } 18620bab0cdab751248ca389a5592bcb70eac5d39260John McCall 18630bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Returns true if the member type (i.e. the pointee type) is a 18640bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// data type rather than a function type. 18650bab0cdab751248ca389a5592bcb70eac5d39260John McCall bool isMemberDataPointer() const { 18660bab0cdab751248ca389a5592bcb70eac5d39260John McCall return !PointeeType->isFunctionProtoType(); 18670bab0cdab751248ca389a5592bcb70eac5d39260John McCall } 18680bab0cdab751248ca389a5592bcb70eac5d39260John McCall 1869f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *getClass() const { return Class; } 1870f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1871bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1872bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1873bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1874f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 1875f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Profile(ID, getPointeeType(), getClass()); 1876f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1877f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 1878f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class) { 1879f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 1880f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Class); 1881f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1882f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1883f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const Type *T) { 1884f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getTypeClass() == MemberPointer; 1885f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1886f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const MemberPointerType *) { return true; } 18875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 18905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 18912e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 18925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 1894898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 1895898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// with a star size (e.g. int X[*]). 1896898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// 'static' is only allowed on function parameters. 18975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 18985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 18995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 19005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 1901fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 1902fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 19031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1904fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 1905898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // C++ [temp.dep.type]p1: 1906898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // A type is dependent if it is... 1907898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // - an array type constructed from any dependent type or whose 1908898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // size is specified by a constant expression that is 1909898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // value-dependent, 1910c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 1911d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ArraySizeModifier sm, unsigned tq, 1912d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool ContainsUnexpandedParameterPack) 191335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray, 1914d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (tc == VariableArray || et->isVariablyModifiedType()), 1915d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ContainsUnexpandedParameterPack), 191671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ElementType(et) { 1917b870b88df784c2940efce448ebfaf54dece14666John McCall ArrayTypeBits.IndexTypeQuals = tq; 1918b870b88df784c2940efce448ebfaf54dece14666John McCall ArrayTypeBits.SizeModifier = sm; 191971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 1920898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1921fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 192260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 1923fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 1924fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 1925ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 1926b870b88df784c2940efce448ebfaf54dece14666John McCall return ArraySizeModifier(ArrayTypeBits.SizeModifier); 1927ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 19280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers getIndexTypeQualifiers() const { 192971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers()); 193071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 193171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall unsigned getIndexTypeCVRQualifiers() const { 1932b870b88df784c2940efce448ebfaf54dece14666John McCall return ArrayTypeBits.IndexTypeQuals; 19330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 19341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1935fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 1936fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 1937c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 1938898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == IncompleteArray || 1939898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == DependentSizedArray; 1940fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1941fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 1942fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 1943fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 19447e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of 19457e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size. For example, the canonical 19467e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 19477e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404. 19482e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 1949fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 19501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19510be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 1952c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 1953d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(ConstantArray, et, can, sm, tq, 1954d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor et->containsUnexpandedParameterPack()), 19557e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Size(size) {} 19567e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected: 19577e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayType(TypeClass tc, QualType et, QualType can, 19587e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 1959d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()), 1960d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Size(size) {} 1961fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 1962fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 1963c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const llvm::APInt &getSize() const { return Size; } 1964bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1965bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1966bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 19672767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 19682767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor /// \brief Determine the number of bits required to address a member of 19692767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // an array with the given element type and number of elements. 19702767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor static unsigned getNumAddressingBits(ASTContext &Context, 19712767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor QualType ElementType, 19722767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor const llvm::APInt &NumElements); 19732767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 19742767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor /// \brief Determine the maximum number of active bits that an array's size 19752767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor /// can require, which limits the maximum size of the array. 19762767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor static unsigned getMaxSizeBits(ASTContext &Context); 19772767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 1978fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 19791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, getElementType(), getSize(), 19800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers()); 1981fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1982fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 19830be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 19840be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner unsigned TypeQuals) { 1985fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 1986fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 19870be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 19880be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 1989fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 19907e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 199146a617a792bfab0d9b1e057371ea3b9540802226John McCall return T->getTypeClass() == ConstantArray; 1992fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1993fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 1994fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 1995fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 1996da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 1997da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 1998da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified. 1999c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 20007e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 2001c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 20027e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq) 2003d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(IncompleteArray, et, can, sm, tq, 2004d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor et->containsUnexpandedParameterPack()) {} 2005c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 2006c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 2007bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2008bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2009bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 20101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 20111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == IncompleteArray; 2012c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 2013c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 20141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2015c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 20161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2017c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 20180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Profile(ID, getElementType(), getSizeModifier(), 20190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getIndexTypeCVRQualifiers()); 2020c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 20211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20220be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 20230be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 2024c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 20250be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 20260be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 2027c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 2028c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 2029c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2030da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 2031da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 2032da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 2033da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 2034da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 2035da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean 2036da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type 2037da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically: 2038da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 2039da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) { 2040da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Y[x]; 2041da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ++x; 2042da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Z[x]; 2043da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// } 2044da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 20452e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 20461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// SizeExpr - An assignment expression. VLA's are only permitted within 20471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// a function block. 2048b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek Stmt *SizeExpr; 20497e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 20507e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 20517e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 2052c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 20537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 20547e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 2055d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(VariableArray, et, can, sm, tq, 2056d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor et->containsUnexpandedParameterPack()), 20577e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 20585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 20594b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 20605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 20611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getSizeExpr() const { 2062b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // We use C-style casts instead of cast<> here because we do not wish 2063b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 2064b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek return (Expr*) SizeExpr; 2065b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek } 20667e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 20677e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 20687e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 20691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2070bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2071bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2072bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 20731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 20741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == VariableArray; 20755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2076fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 20771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 207892866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 20791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20802bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 2081fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner assert(0 && "Cannot unique VariableArrayTypes."); 20822bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 20835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 20845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2085898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in 2086898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example: 2087cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// 2088cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code 20891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size> 2090898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array { 2091898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// T data[Size]; 2092898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// }; 2093cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode 2094cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// 2095898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is 2096898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will 2097898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 2098898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType { 20994ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 21001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2101cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// \brief An assignment expression that will instantiate to the 2102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// size of the array. 2103cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// 2104cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// The expression itself might be NULL, in which case the array 2105cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// type will have its size deduced from an initializer. 2106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Stmt *SizeExpr; 2107cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor 21087e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 21097e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 21101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21114ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can, 211204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *e, ArraySizeModifier sm, unsigned tq, 2113d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceRange brackets); 2114d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class ASTContext; // ASTContext creates these. 2116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic: 21181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getSizeExpr() const { 2119898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // We use C-style casts instead of cast<> here because we do not wish 2120898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 2121898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return (Expr*) SizeExpr; 2122898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 21237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 21247e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 21257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 21261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2127bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2128bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2129bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 21301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 21311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == DependentSizedArray; 2132898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 2133898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 21341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2135898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class StmtIteratorBase; 21361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2138898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 21391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, Context, getElementType(), 21400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); 2141898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 21421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21434ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 21441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType ET, ArraySizeModifier SizeMod, 214504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, Expr *E); 2146898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}; 2147898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2148f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 21499cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example: 21509cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code 21519cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size> 21529cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector { 21539cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 21549cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// } 21559cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode 21562ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { 21574ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 21589cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr; 21599cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor /// ElementType - The element type of the array. 21609cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType ElementType; 21619cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation loc; 21621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21634ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType, 2164d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType can, Expr *SizeExpr, SourceLocation loc); 2165d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 21669cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor friend class ASTContext; 21679cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 21689cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic: 21692ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 21709cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType getElementType() const { return ElementType; } 21719cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation getAttributeLoc() const { return loc; } 21729cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 2173bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2174bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2175bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 21761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 21771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == DependentSizedExtVector; 21789cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor } 21791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const DependentSizedExtVectorType *) { return true; } 21802ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 21812ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 21822ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor Profile(ID, Context, getElementType(), getSizeExpr()); 21832ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 21841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21854ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 21862ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr); 21879cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor}; 21881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21899cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 219073322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 21911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in 219282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration. 219382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the 219473322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 21955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 2196788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattnerpublic: 2197e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson enum VectorKind { 2198e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson GenericVector, // not a target-specific vector type 2199e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson AltiVecVector, // is AltiVec vector 2200e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson AltiVecPixel, // is AltiVec 'vector Pixel' 2201e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson AltiVecBool, // is AltiVec 'vector bool ...' 2202491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson NeonVector, // is ARM Neon vector 2203491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson NeonPolyVector // is ARM Neon polynomial vector 2204788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner }; 220573322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 22065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 22075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 22081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 220982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson VectorType(QualType vecType, unsigned nElements, QualType canonType, 2210d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorKind vecKind); 221135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 22121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump VectorType(TypeClass tc, QualType vecType, unsigned nElements, 2213d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType canonType, VectorKind vecKind); 2214d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 22155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 221660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 22175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 22181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 2220b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getNumElements() const { return VectorTypeBits.NumElements; } 22215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2222bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2223bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2224bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2225e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorKind getVectorKind() const { 2226e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson return VectorKind(VectorTypeBits.VecKind); 222771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2228788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner 22295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 223071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall Profile(ID, getElementType(), getNumElements(), 2231e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson getTypeClass(), getVectorKind()); 22325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 223482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson unsigned NumElements, TypeClass TypeClass, 2235e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorKind VecKind) { 22365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 22375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 223873322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 2239e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson ID.AddInteger(VecKind); 224073322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 22410b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 22421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 22431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 22445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 22465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 22475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2248213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using 2249213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 2250213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 2251fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 2252fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 2253213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType { 2254213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 2255e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {} 225673322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 225773322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 225888dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 225988dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 226088dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 226188dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 226288dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 226388dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 226488dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 226588dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 2266e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 2267353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman static int getNumericAccessorIdx(char c) { 226888dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 2269353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman default: return -1; 2270353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '0': return 0; 2271353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '1': return 1; 2272353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '2': return 2; 2273353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '3': return 3; 2274353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '4': return 4; 2275353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '5': return 5; 2276353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '6': return 6; 2277353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '7': return 7; 2278353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '8': return 8; 2279353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '9': return 9; 2280131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'A': 2281353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'a': return 10; 2282131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'B': 2283353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'b': return 11; 2284131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'C': 2285353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'c': return 12; 2286131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'D': 2287353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'd': return 13; 2288131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'E': 2289353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'e': return 14; 2290131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'F': 2291353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'f': return 15; 229288dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 2293e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 22941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2295b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 2296b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 2297353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman return getNumericAccessorIdx(c); 2298b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 22991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 230088dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 2301b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 230271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return unsigned(idx-1) < getNumElements(); 230388dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 2304e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 2305bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2306bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2307bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 23081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 23091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ExtVector; 231073322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 2311213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman static bool classof(const ExtVectorType *) { return true; } 231273322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 231373322924127c873c13101b705dd823f5539ffa5fSteve Naroff 23145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 231572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 23165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 23175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 23185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 23195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 2320264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2321264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public: 2322373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// ExtInfo - A class which abstracts out some details necessary for 2323373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// making a call. 2324373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// 2325373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// It is not actually used directly for storing this information in 2326373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// a FunctionType, although FunctionType does currently use the 2327373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// same bit-pattern. 2328373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// 2329075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara // If you add a field (say Foo), other than the obvious places (both, 2330075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara // constructors, compile failures), what you need to update is 2331075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara // * Operator== 2332425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * getFoo 2333425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * withFoo 2334425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * functionType. Add Foo, getFoo. 2335425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * ASTContext::getFooType 2336425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * ASTContext::mergeFunctionTypes 2337425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * FunctionNoProtoType::Profile 2338425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * FunctionProtoType::Profile 2339425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * TypePrinter::PrintFunctionProto 23403c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl // * AST read and write 2341425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * Codegen 2342264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola class ExtInfo { 2343373920bd733b1d28fe7bf209945a62eb9248d948John McCall // Feel free to rearrange or add bits, but if you go over 8, 2344373920bd733b1d28fe7bf209945a62eb9248d948John McCall // you'll need to adjust both the Bits field below and 2345373920bd733b1d28fe7bf209945a62eb9248d948John McCall // Type::FunctionTypeBitfields. 2346373920bd733b1d28fe7bf209945a62eb9248d948John McCall 2347a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman // | CC |noreturn|hasregparm|regparm 2348a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman // |0 .. 2| 3 | 4 |5 .. 7 2349b870b88df784c2940efce448ebfaf54dece14666John McCall enum { CallConvMask = 0x7 }; 2350b870b88df784c2940efce448ebfaf54dece14666John McCall enum { NoReturnMask = 0x8 }; 2351a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman enum { HasRegParmMask = 0x10 }; 2352b870b88df784c2940efce448ebfaf54dece14666John McCall enum { RegParmMask = ~(CallConvMask | NoReturnMask), 2353a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman RegParmOffset = 5 }; 2354b870b88df784c2940efce448ebfaf54dece14666John McCall 2355373920bd733b1d28fe7bf209945a62eb9248d948John McCall unsigned char Bits; 235671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 2357373920bd733b1d28fe7bf209945a62eb9248d948John McCall ExtInfo(unsigned Bits) : Bits(static_cast<unsigned char>(Bits)) {} 235871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 235971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall friend class FunctionType; 236071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 2361264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public: 2362264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Constructor with no defaults. Use this when you know that you 23633c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl // have all the elements (when reading an AST file for example). 2364a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc) { 2365b870b88df784c2940efce448ebfaf54dece14666John McCall Bits = ((unsigned) cc) | 2366b870b88df784c2940efce448ebfaf54dece14666John McCall (noReturn ? NoReturnMask : 0) | 2367a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman (hasRegParm ? HasRegParmMask : 0) | 2368b870b88df784c2940efce448ebfaf54dece14666John McCall (regParm << RegParmOffset); 236971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2370264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2371264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Constructor with all defaults. Use when for example creating a 2372264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // function know to use defaults. 237371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ExtInfo() : Bits(0) {} 2374264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2375b870b88df784c2940efce448ebfaf54dece14666John McCall bool getNoReturn() const { return Bits & NoReturnMask; } 2376a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman bool getHasRegParm() const { return Bits & HasRegParmMask; } 2377b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getRegParm() const { return Bits >> RegParmOffset; } 2378b870b88df784c2940efce448ebfaf54dece14666John McCall CallingConv getCC() const { return CallingConv(Bits & CallConvMask); } 2379264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 238071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall bool operator==(ExtInfo Other) const { 238171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return Bits == Other.Bits; 2382264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 238371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall bool operator!=(ExtInfo Other) const { 238471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return Bits != Other.Bits; 2385264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 2386264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2387264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Note that we don't have setters. That is by design, use 2388264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // the following with methods instead of mutating these objects. 2389264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2390264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ExtInfo withNoReturn(bool noReturn) const { 239171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall if (noReturn) 239271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return ExtInfo(Bits | NoReturnMask); 239371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall else 239471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return ExtInfo(Bits & ~NoReturnMask); 2395425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola } 2396425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola 2397425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola ExtInfo withRegParm(unsigned RegParm) const { 2398a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman return ExtInfo(HasRegParmMask | (Bits & ~RegParmMask) | (RegParm << RegParmOffset)); 2399264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 2400264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2401264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ExtInfo withCallingConv(CallingConv cc) const { 2402b870b88df784c2940efce448ebfaf54dece14666John McCall return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc); 2403264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 2404264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2405e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall void Profile(llvm::FoldingSetNodeID &ID) const { 240671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ID.AddInteger(Bits); 240771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2408264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola }; 2409264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 24105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 2411e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionType(TypeClass tc, QualType res, bool variadic, 2412c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor unsigned typeQuals, RefQualifierKind RefQualifier, 2413c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor QualType Canonical, bool Dependent, 2414d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool VariablyModified, bool ContainsUnexpandedParameterPack, 2415d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ExtInfo Info) 2416d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(tc, Canonical, Dependent, VariablyModified, 2417d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ContainsUnexpandedParameterPack), 2418d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ResultType(res) { 2419b870b88df784c2940efce448ebfaf54dece14666John McCall FunctionTypeBits.ExtInfo = Info.Bits; 2420e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionTypeBits.Variadic = variadic; 2421b870b88df784c2940efce448ebfaf54dece14666John McCall FunctionTypeBits.TypeQuals = typeQuals; 2422c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor FunctionTypeBits.RefQualifier = static_cast<unsigned>(RefQualifier); 242371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2424e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall bool isVariadic() const { return FunctionTypeBits.Variadic; } 2425b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; } 2426c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 2427c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind getRefQualifier() const { 2428c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier); 2429c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor } 2430c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 24315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 24321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 2434a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman 2435a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman bool getHasRegParm() const { return getExtInfo().getHasRegParm(); } 2436b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getRegParmType() const { return getExtInfo().getRegParm(); } 2437b870b88df784c2940efce448ebfaf54dece14666John McCall bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); } 2438b870b88df784c2940efce448ebfaf54dece14666John McCall CallingConv getCallConv() const { return getExtInfo().getCC(); } 2439b870b88df784c2940efce448ebfaf54dece14666John McCall ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); } 24405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24415291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// \brief Determine the type of an expression that calls a function of 24425291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// this type. 24435291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor QualType getCallResultType(ASTContext &Context) const { 24446398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor return getResultType().getNonLValueExprType(Context); 24455291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor } 24465291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 244704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall static llvm::StringRef getNameForCallConv(CallingConv CC); 244804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 24495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 24505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 24515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 24525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 24545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 245672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 24575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 245872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 245971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info) 2460c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor : FunctionType(FunctionNoProto, Result, false, 0, RQ_None, Canonical, 246135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor /*Dependent=*/false, Result->isVariablyModifiedType(), 2462d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false, Info) {} 2463d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 24645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 246560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 24665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 24675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 24681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2469bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2470bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2471bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 24725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 2473264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Profile(ID, getResultType(), getExtInfo()); 24745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24752455636163fdd18581d7fdae816433f886d88213Mike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 247671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ExtInfo Info) { 247771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall Info.Profile(ID); 24785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 24795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 24825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 24835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 248472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 24855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 248772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 24885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 2489465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 2490465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical 2491465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type. 249272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 2493e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallpublic: 2494e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall /// ExtProtoInfo - Extra information about a function prototype. 2495e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall struct ExtProtoInfo { 2496e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ExtProtoInfo() : 24978b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl Variadic(false), ExceptionSpecType(EST_None), TypeQuals(0), 24988b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl RefQualifier(RQ_None), NumExceptions(0), Exceptions(0), NoexceptExpr(0) {} 2499e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 2500e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionType::ExtInfo ExtInfo; 2501e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall bool Variadic; 25028b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl ExceptionSpecificationType ExceptionSpecType; 2503e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned char TypeQuals; 2504c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier; 2505e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned NumExceptions; 2506e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall const QualType *Exceptions; 25078b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl Expr *NoexceptExpr; 2508e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall }; 2509e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 2510e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallprivate: 2511d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Determine whether there are any argument types that 2512d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// contain an unexpanded parameter pack. 2513d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray, 2514d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned numArgs) { 2515d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 2516d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor if (ArgArray[Idx]->containsUnexpandedParameterPack()) 2517d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return true; 2518d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2519d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return false; 2520d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 2521d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2522e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType(QualType result, const QualType *args, unsigned numArgs, 25238026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl QualType canonical, const ExtProtoInfo &epi); 2524465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 25255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 2526465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumArgs : 20; 2527465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2528465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 252960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl unsigned NumExceptions : 9; 2530465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 253160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// ExceptionSpecType - The type of exception specification this function has. 253260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl unsigned ExceptionSpecType : 3; 2533465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2534942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 2535942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// holds the argument types. 2536465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2537465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 2538465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// holds the exception types. 2539465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 254060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// NoexceptExpr - Instead of Exceptions, there may be a single Expr* pointing 254160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// to the expression in the noexcept() specifier. 254260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 25435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 25444b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 25455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 25465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 25475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 25485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 2549942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 25505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2551465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2552e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ExtProtoInfo getExtProtoInfo() const { 2553e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ExtProtoInfo EPI; 2554e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.ExtInfo = getExtInfo(); 2555e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.Variadic = isVariadic(); 255660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.ExceptionSpecType = getExceptionSpecType(); 2557e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals()); 2558c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor EPI.RefQualifier = getRefQualifier(); 255960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (EPI.ExceptionSpecType == EST_Dynamic) { 256060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.NumExceptions = NumExceptions; 256160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.Exceptions = exception_begin(); 256260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) { 256360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.NoexceptExpr = getNoexceptExpr(); 256460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 2565e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall return EPI; 2566e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall } 2567e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 256860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Get the kind of exception specification on this function. 256960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecificationType getExceptionSpecType() const { 257060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return static_cast<ExceptionSpecificationType>(ExceptionSpecType); 257160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 257260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Return whether this function has any kind of exception spec. 257360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool hasExceptionSpec() const { 257460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return getExceptionSpecType() != EST_None; 257560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 257660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Return whether this function has a dynamic (throw) exception spec. 257760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool hasDynamicExceptionSpec() const { 257860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return isDynamicExceptionSpec(getExceptionSpecType()); 257960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 2580fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// \brief Return whether this function has a noexcept exception spec. 258160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool hasNoexceptExceptionSpec() const { 258260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return isNoexceptExceptionSpec(getExceptionSpecType()); 258360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 258460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Result type of getNoexceptSpec(). 258560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl enum NoexceptResult { 258660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_NoNoexcept, ///< There is no noexcept specifier. 258760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_BadNoexcept, ///< The noexcept specifier has a bad expression. 258860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_Dependent, ///< The noexcept specifier is dependent. 258960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_Throw, ///< The noexcept specifier evaluates to false. 259060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_Nothrow ///< The noexcept specifier evaluates to true. 259160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl }; 259260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Get the meaning of the noexcept spec on this function, if any. 25938026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl NoexceptResult getNoexceptSpec(ASTContext &Ctx) const; 2594465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 2595465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType getExceptionType(unsigned i) const { 2596465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 2597465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin()[i]; 2598465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 259960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Expr *getNoexceptExpr() const { 260060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (getExceptionSpecType() != EST_ComputedNoexcept) 260160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return 0; 260260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // NoexceptExpr sits where the arguments end. 260360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return *reinterpret_cast<Expr *const *>(arg_type_end()); 2604d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson } 26058026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl bool isNothrow(ASTContext &Ctx) const { 260660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecificationType EST = getExceptionSpecType(); 260760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (EST == EST_DynamicNone || EST == EST_BasicNoexcept) 260860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return true; 260960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (EST != EST_ComputedNoexcept) 261060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return false; 26118026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl return getNoexceptSpec(Ctx) == NR_Nothrow; 2612c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall } 2613c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall 2614e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall using FunctionType::isVariadic; 261560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 2616f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// \brief Determines whether this function prototype contains a 2617f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// parameter pack at the end. 2618f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// 2619f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// A function template whose last parameter is a parameter pack can be 2620f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// called with an arbitrary number of arguments, much like a variadic 2621f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// function. However, 2622f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor bool isTemplateVariadic() const; 2623f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor 2624971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 26251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2626c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 2627c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief Retrieve the ref-qualifier associated with this function type. 2628c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind getRefQualifier() const { 2629c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor return FunctionType::getRefQualifier(); 2630c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor } 2631c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 26325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 2633942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 2634942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 2635942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 2636942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 2637465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2638465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl typedef const QualType *exception_iterator; 2639465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_begin() const { 2640465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // exceptions begin where arguments end 2641465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return arg_type_end(); 2642465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 2643465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_end() const { 264460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (getExceptionSpecType() != EST_Dynamic) 264560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return exception_begin(); 2646465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin() + NumExceptions; 2647465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 2648465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2649bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2650bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2651bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 26525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 26535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 26545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 265572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 2656465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 26578026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx); 26585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 2659942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 26608026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ExtProtoInfo &EPI, const ASTContext &Context); 26615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 26625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2664ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped 2665ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g. 2666ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// using typename Base<T>::foo; 2667ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type. 2668ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type { 2669ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *Decl; 2670ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 267119c8576b7328f4dc2d07682f5da552875c1912efJohn McCall UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) 2672d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(UnresolvedUsing, QualType(), true, false, 2673d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 267419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {} 2675ed97649e9574b9d854fa4d6109c9333ae0993554John McCall friend class ASTContext; // ASTContext creates these. 2676ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic: 2677ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2678ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *getDecl() const { return Decl; } 2679ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2680ed97649e9574b9d854fa4d6109c9333ae0993554John McCall bool isSugared() const { return false; } 2681ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType desugar() const { return QualType(this, 0); } 2682ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2683ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static bool classof(const Type *T) { 2684ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return T->getTypeClass() == UnresolvedUsing; 2685ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2686ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static bool classof(const UnresolvedUsingType *) { return true; } 2687ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2688ed97649e9574b9d854fa4d6109c9333ae0993554John McCall void Profile(llvm::FoldingSetNodeID &ID) { 2689ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Profile(ID, Decl); 2690ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2691ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static void Profile(llvm::FoldingSetNodeID &ID, 2692ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *D) { 2693ed97649e9574b9d854fa4d6109c9333ae0993554John McCall ID.AddPointer(D); 2694ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2695ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}; 2696ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2697ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 26985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 2699162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *Decl; 2700c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 2701162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can) 2702d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(tc, can, can->isDependentType(), can->isVariablyModifiedType(), 2703d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 2704162e1c1b487352434552147967c3dd296ebee2f7Richard Smith Decl(const_cast<TypedefNameDecl*>(D)) { 27055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 27065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 27085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 27091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2710162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *getDecl() const { return Decl; } 27111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2712bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2713bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const; 2714bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 271572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 27165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 27175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 27185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 271972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension). 272072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type { 2721d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 27221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2723b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected: 2724dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor TypeOfExprType(Expr *E, QualType can = QualType()); 2725d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 2726d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 2727d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 27281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2729bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2730bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const; 2731bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2732bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2733bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2734bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 273572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 273672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 2737d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 2738d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 2739c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent 27401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types. 2741c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// 2742c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage 2743c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances 2744c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via TypeOfExprType nodes. 27451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType 2746b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor : public TypeOfExprType, public llvm::FoldingSetNode { 27474ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 27481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2749b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic: 27504ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentTypeOfExprType(const ASTContext &Context, Expr *E) 2751b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor : TypeOfExprType(E), Context(Context) { } 27521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2753bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2754bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2755bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2756b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2757b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Profile(ID, Context, getUnderlyingExpr()); 2758b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } 27591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27604ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 2761b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Expr *E); 2762b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor}; 27631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2764d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 2765d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 2766d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 27671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypeOfType(QualType T, QualType can) 2768d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(TypeOf, can, T->isDependentType(), T->isVariablyModifiedType(), 2769d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor T->containsUnexpandedParameterPack()), 277035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor TOType(T) { 2771d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 2772d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 2773d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 2774d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 2775d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 27761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2777bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2778bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getUnderlyingType(); } 2779bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2780bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2781bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2782bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 278372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 2784d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 2785d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 27865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2787395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x) 2788395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type { 2789395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *E; 27901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2791563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 2792563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 2793563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // from it. 2794563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType UnderlyingType; 27951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27969d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected: 2797563a03b1338d31c2462def43253a722bc885d384Anders Carlsson DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 2798395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson friend class ASTContext; // ASTContext creates these. 2799395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic: 2800395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *getUnderlyingExpr() const { return E; } 2801563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType getUnderlyingType() const { return UnderlyingType; } 2802563a03b1338d31c2462def43253a722bc885d384Anders Carlsson 2803bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2804bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getUnderlyingType(); } 2805bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2806bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2807bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return !isDependentType(); } 2808bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2809395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 2810395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const DecltypeType *) { return true; } 2811395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson}; 28121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2813c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent 2814c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// decltype(expr) types. 2815c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// 2816c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage 2817c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances 2818c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via DecltypeType nodes. 28199d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { 28204ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 28211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28229d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic: 28234ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentDecltypeType(const ASTContext &Context, Expr *E); 28241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2825bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2826bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2827bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 28289d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 28299d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor Profile(ID, Context, getUnderlyingExpr()); 28309d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } 28311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28324ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 28331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *E); 28349d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor}; 28351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2836ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt/// \brief A unary type transform, which is a type constructed from another 2837ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntclass UnaryTransformType : public Type { 2838ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntpublic: 2839ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt enum UTTKind { 2840ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt EnumUnderlyingType 2841ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt }; 2842ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 2843ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntprivate: 2844ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt /// The untransformed type. 2845ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType BaseType; 2846ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt /// The transformed type if not dependent, otherwise the same as BaseType. 2847ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType UnderlyingType; 2848ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 2849ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UTTKind UKind; 2850ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntprotected: 2851ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind, 2852ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType CanonicalTy); 2853ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt friend class ASTContext; 2854ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntpublic: 2855ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt bool isSugared() const { return !isDependentType(); } 2856ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType desugar() const { return UnderlyingType; } 2857ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 2858ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType getUnderlyingType() const { return UnderlyingType; } 2859ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType getBaseType() const { return BaseType; } 2860ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 2861ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UTTKind getUTTKind() const { return UKind; } 2862ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 2863ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt static bool classof(const Type *T) { 2864ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return T->getTypeClass() == UnaryTransform; 2865ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 2866ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt static bool classof(const UnaryTransformType *) { return true; } 2867ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}; 2868ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 28695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 2870ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl /// Stores the TagDecl associated with this type. The decl may point to any 2871ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl /// TagDecl that declares the entity. 2872ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl TagDecl * decl; 28732ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 28742ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected: 287519c8576b7328f4dc2d07682f5da552875c1912efJohn McCall TagType(TypeClass TC, const TagDecl *D, QualType can); 28762ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 28771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 2878ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl TagDecl *getDecl() const; 28791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28800b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// @brief Determines whether this type is in the process of being 28811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// defined. 2882ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl bool isBeingDefined() const; 28830b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 28841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 288572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 288672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor } 28875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 288872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const RecordType *) { return true; } 288972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const EnumType *) { return true; } 28905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 28915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 28925edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 28935edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes. 28945edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType { 289549aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected: 289619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall explicit RecordType(const RecordDecl *D) 289719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { } 289872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 289919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { } 29002ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 29015edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 29021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29035edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordDecl *getDecl() const { 29045edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 29055edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 29061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: This predicate is a helper to QualType/Type. It needs to 29085edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // recursively check all fields for const-ness. If any field is declared 29091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // const, it needs to return false. 29105edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner bool hasConstFields() const { return false; } 29115edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 2912bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2913bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2914bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 29152daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 29162daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 29172daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 29182daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 29195edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const RecordType *) { return true; } 29205edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 29215edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 29225edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 29235edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums. 29245edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType { 292519c8576b7328f4dc2d07682f5da552875c1912efJohn McCall explicit EnumType(const EnumDecl *D) 292619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { } 29272ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 29285edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 29291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29305edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumDecl *getDecl() const { 29315edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 29325edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 29331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2934bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2935bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2936bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 29372daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 29382daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 29392daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 29402daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 29415edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const EnumType *) { return true; } 29425edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 29435edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 29449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// AttributedType - An attributed type is a type to which a type 29459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// attribute has been applied. The "modified type" is the 29469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// fully-sugared type to which the attributed type was applied; 29479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// generally it is not canonically equivalent to the attributed type. 29489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// The "equivalent type" is the minimally-desugared type which the 29499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// type is canonically equivalent to. 29509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// 29519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// For example, in the following attributed type: 29529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// int32_t __attribute__((vector_size(16))) 29539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// - the modified type is the TypedefType for int32_t 29549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// - the equivalent type is VectorType(16, int32_t) 29559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// - the canonical type is VectorType(16, int) 29569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallclass AttributedType : public Type, public llvm::FoldingSetNode { 29579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic: 29589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // It is really silly to have yet another attribute-kind enum, but 29599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // clang::attr::Kind doesn't currently cover the pure type attrs. 29609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall enum Kind { 29619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // Expression operand. 2962170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_address_space, 2963170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_regparm, 2964170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_vector_size, 2965170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_neon_vector_type, 2966170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_neon_polyvector_type, 29679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 2968170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet FirstExprOperandKind = attr_address_space, 2969170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet LastExprOperandKind = attr_neon_polyvector_type, 29709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // Enumerated operand (string or keyword). 2972170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_objc_gc, 2973414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov attr_pcs, 29749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 2975170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet FirstEnumOperandKind = attr_objc_gc, 2976414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov LastEnumOperandKind = attr_pcs, 29779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29789d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // No operand. 29793cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_noreturn, 29803cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_cdecl, 29813cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_fastcall, 29823cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_stdcall, 29833cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_thiscall, 29843cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_pascal 29859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall }; 29869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallprivate: 29889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType ModifiedType; 29899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType EquivalentType; 29909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall friend class ASTContext; // creates these 29929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType(QualType canon, Kind attrKind, 29949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modified, QualType equivalent) 29959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall : Type(Attributed, canon, canon->isDependentType(), 29969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall canon->isVariablyModifiedType(), 29979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall canon->containsUnexpandedParameterPack()), 29989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ModifiedType(modified), EquivalentType(equivalent) { 29999d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeBits.AttrKind = attrKind; 30009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 30019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 30029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic: 30039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Kind getAttrKind() const { 30049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return static_cast<Kind>(AttributedTypeBits.AttrKind); 30059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 30069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 30079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType getModifiedType() const { return ModifiedType; } 30089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType getEquivalentType() const { return EquivalentType; } 30099d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 30109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall bool isSugared() const { return true; } 30119d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType desugar() const { return getEquivalentType(); } 30129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 30139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall void Profile(llvm::FoldingSetNodeID &ID) { 30149d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Profile(ID, getAttrKind(), ModifiedType, EquivalentType); 30159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 30169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 30179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind, 30189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modified, QualType equivalent) { 30199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ID.AddInteger(attrKind); 30209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ID.AddPointer(modified.getAsOpaquePtr()); 30219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ID.AddPointer(equivalent.getAsOpaquePtr()); 30229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 30239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 30249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall static bool classof(const Type *T) { 30259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return T->getTypeClass() == Attributed; 30269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 30279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall static bool classof(const AttributedType *T) { return true; } 30289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}; 30299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 3030fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 30314fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth // Helper data collector for canonical types. 30324fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth struct CanonicalTTPTInfo { 30334fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned Depth : 15; 30344fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned ParameterPack : 1; 30354fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned Index : 16; 30364fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth }; 30374fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 30384fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth union { 30394fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth // Info for the canonical type. 30404fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth CanonicalTTPTInfo CanTTPTInfo; 30414fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth // Info for the non-canonical type. 30424fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmDecl *TTPDecl; 30434fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth }; 304472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 30454fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth /// Build a non-canonical type. 30464fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon) 304735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true, 30484fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth /*VariablyModified=*/false, 30495d65e34b08b3e57a4da834195757d0d15baaffd0Chandler Carruth Canon->containsUnexpandedParameterPack()), 30504fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TTPDecl(TTPDecl) { } 305172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 30524fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth /// Build the canonical type. 30531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP) 305435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true, 30554fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth /*VariablyModified=*/false, PP) { 30564fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth CanTTPTInfo.Depth = D; 30574fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth CanTTPTInfo.Index = I; 30584fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth CanTTPTInfo.ParameterPack = PP; 30594fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth } 306072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 3061fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor friend class ASTContext; // ASTContext creates these 306272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 30634fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth const CanonicalTTPTInfo& getCanTTPTInfo() const { 30644fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth QualType Can = getCanonicalTypeInternal(); 30655d65e34b08b3e57a4da834195757d0d15baaffd0Chandler Carruth return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo; 30664fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth } 30674fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 3068fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic: 30694fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned getDepth() const { return getCanTTPTInfo().Depth; } 30704fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned getIndex() const { return getCanTTPTInfo().Index; } 30714fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; } 30724fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 30734fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmDecl *getDecl() const { 30744fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth return isCanonicalUnqualified() ? 0 : TTPDecl; 30754fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth } 30764fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 3077b7efff4bae117604f442bb6859c844f90b15f3ffChandler Carruth IdentifierInfo *getIdentifier() const; 30781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3079bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 3080bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 3081bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3082fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 30834fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl()); 3084fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 3085fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 30861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 30871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned Index, bool ParameterPack, 30884fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmDecl *TTPDecl) { 3089fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Depth); 3090fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Index); 309176e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson ID.AddBoolean(ParameterPack); 30924fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth ID.AddPointer(TTPDecl); 3093fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 3094fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 30951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 30961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == TemplateTypeParm; 309772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor } 309872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 309972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}; 3100fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 310149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template 310249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter. 310349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// 310449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have 310549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these. They are used solely to record that a 310649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter; 310749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical. 310849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode { 310949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall // The original type parameter. 311049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *Replaced; 311149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 311249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) 311335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(), 3114d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Canon->isVariablyModifiedType(), 3115d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Canon->containsUnexpandedParameterPack()), 311649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Replaced(Param) { } 311749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 311849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall friend class ASTContext; 311949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 312049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic: 312149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// Gets the template parameter that was substituted for. 312249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *getReplacedParameter() const { 312349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return Replaced; 312449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 312549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 312649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// Gets the type that was substituted for the template 312749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// parameter. 312849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType getReplacementType() const { 312949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return getCanonicalTypeInternal(); 313049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 313149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 313249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall bool isSugared() const { return true; } 313349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType desugar() const { return getReplacementType(); } 313449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 313549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall void Profile(llvm::FoldingSetNodeID &ID) { 313649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Profile(ID, getReplacedParameter(), getReplacementType()); 313749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 313849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, 313949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *Replaced, 314049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType Replacement) { 314149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall ID.AddPointer(Replaced); 314249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall ID.AddPointer(Replacement.getAsOpaquePtr()); 314349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 314449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 314549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static bool classof(const Type *T) { 314649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return T->getTypeClass() == SubstTemplateTypeParm; 314749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 314849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static bool classof(const SubstTemplateTypeParmType *T) { return true; } 314949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}; 315049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 3151c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// \brief Represents the result of substituting a set of types for a template 3152c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// type parameter pack. 3153c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// 3154c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs 3155c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// and those parameter packs correspond to different levels of template 3156c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// parameter lists, this type node is used to represent a template type 3157c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack 3158c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// substituted but that still lives within a pack expansion that itself 3159c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// could not be instantiated. When actually performing a substitution into 3160c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding 3161c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType 3162c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// at the current pack substitution index. 3163c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorclass SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode { 3164c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// \brief The original type parameter. 3165c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Replaced; 3166c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3167c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// \brief A pointer to the set of template arguments that this 3168c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// parameter pack is instantiated with. 3169c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument *Arguments; 3170c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3171c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// \brief The number of template arguments in \c Arguments. 3172c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor unsigned NumArguments; 3173c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3174c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param, 3175c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType Canon, 3176c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack); 3177c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3178c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor friend class ASTContext; 3179c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3180c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorpublic: 3181b7efff4bae117604f442bb6859c844f90b15f3ffChandler Carruth IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); } 3182c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3183c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// Gets the template parameter that was substituted for. 3184c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *getReplacedParameter() const { 3185c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return Replaced; 3186c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor } 3187c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3188c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor bool isSugared() const { return false; } 3189c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType desugar() const { return QualType(this, 0); } 3190c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3191c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor TemplateArgument getArgumentPack() const; 3192c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3193c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID); 3194c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, 3195c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Replaced, 3196c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack); 3197c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3198c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor static bool classof(const Type *T) { 3199c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return T->getTypeClass() == SubstTemplateTypeParmPack; 3200c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor } 3201c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor static bool classof(const SubstTemplateTypeParmPackType *T) { return true; } 3202c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor}; 3203c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 320434b41d939a1328f484511c6002ba2456db879a29Richard Smith/// \brief Represents a C++0x auto type. 320534b41d939a1328f484511c6002ba2456db879a29Richard Smith/// 320634b41d939a1328f484511c6002ba2456db879a29Richard Smith/// These types are usually a placeholder for a deduced type. However, within 320734b41d939a1328f484511c6002ba2456db879a29Richard Smith/// templates and before the initializer is attached, there is no deduced type 320834b41d939a1328f484511c6002ba2456db879a29Richard Smith/// and an auto type is type-dependent and canonical. 320934b41d939a1328f484511c6002ba2456db879a29Richard Smithclass AutoType : public Type, public llvm::FoldingSetNode { 321034b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType(QualType DeducedType) 321134b41d939a1328f484511c6002ba2456db879a29Richard Smith : Type(Auto, DeducedType.isNull() ? QualType(this, 0) : DeducedType, 321234b41d939a1328f484511c6002ba2456db879a29Richard Smith /*Dependent=*/DeducedType.isNull(), 321334b41d939a1328f484511c6002ba2456db879a29Richard Smith /*VariablyModified=*/false, /*ContainsParameterPack=*/false) { 321434b41d939a1328f484511c6002ba2456db879a29Richard Smith assert((DeducedType.isNull() || !DeducedType->isDependentType()) && 321534b41d939a1328f484511c6002ba2456db879a29Richard Smith "deduced a dependent type for auto"); 321634b41d939a1328f484511c6002ba2456db879a29Richard Smith } 321734b41d939a1328f484511c6002ba2456db879a29Richard Smith 321834b41d939a1328f484511c6002ba2456db879a29Richard Smith friend class ASTContext; // ASTContext creates these 321934b41d939a1328f484511c6002ba2456db879a29Richard Smith 322034b41d939a1328f484511c6002ba2456db879a29Richard Smithpublic: 322134b41d939a1328f484511c6002ba2456db879a29Richard Smith bool isSugared() const { return isDeduced(); } 322234b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType desugar() const { return getCanonicalTypeInternal(); } 322334b41d939a1328f484511c6002ba2456db879a29Richard Smith 322434b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType getDeducedType() const { 322534b41d939a1328f484511c6002ba2456db879a29Richard Smith return isDeduced() ? getCanonicalTypeInternal() : QualType(); 322634b41d939a1328f484511c6002ba2456db879a29Richard Smith } 322734b41d939a1328f484511c6002ba2456db879a29Richard Smith bool isDeduced() const { 322834b41d939a1328f484511c6002ba2456db879a29Richard Smith return !isDependentType(); 322934b41d939a1328f484511c6002ba2456db879a29Richard Smith } 323034b41d939a1328f484511c6002ba2456db879a29Richard Smith 323134b41d939a1328f484511c6002ba2456db879a29Richard Smith void Profile(llvm::FoldingSetNodeID &ID) { 323234b41d939a1328f484511c6002ba2456db879a29Richard Smith Profile(ID, getDeducedType()); 323334b41d939a1328f484511c6002ba2456db879a29Richard Smith } 323434b41d939a1328f484511c6002ba2456db879a29Richard Smith 323534b41d939a1328f484511c6002ba2456db879a29Richard Smith static void Profile(llvm::FoldingSetNodeID &ID, 323634b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType Deduced) { 323734b41d939a1328f484511c6002ba2456db879a29Richard Smith ID.AddPointer(Deduced.getAsOpaquePtr()); 323834b41d939a1328f484511c6002ba2456db879a29Richard Smith } 323934b41d939a1328f484511c6002ba2456db879a29Richard Smith 324034b41d939a1328f484511c6002ba2456db879a29Richard Smith static bool classof(const Type *T) { 324134b41d939a1328f484511c6002ba2456db879a29Richard Smith return T->getTypeClass() == Auto; 324234b41d939a1328f484511c6002ba2456db879a29Richard Smith } 324334b41d939a1328f484511c6002ba2456db879a29Richard Smith static bool classof(const AutoType *T) { return true; } 324434b41d939a1328f484511c6002ba2456db879a29Richard Smith}; 324534b41d939a1328f484511c6002ba2456db879a29Richard Smith 32467532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written 32477532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code. 324855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// 32497532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a 32507532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 32517532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 32527532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the 32537532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a 325455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to 32551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// a tag type for the instantiation 325655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 32577532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// 32587532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name 32597532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always 32607532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent. 32613e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith/// 32623e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith/// An instance of this type is followed by an array of TemplateArgument*s, 32633e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith/// then, if the template specialization type is for a type alias template, 32643e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith/// a QualType representing the non-canonical aliased type. 32651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType 326655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor : public Type, public llvm::FoldingSetNode { 326733500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief The name of the template being specialized. 32687532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Template; 326955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 327040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief - The number of template arguments named in this class 327140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// template specialization. 327255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned NumArgs; 327355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 3274ef99001908e799c388f1363b1e607dad5f5b57d3John McCall TemplateSpecializationType(TemplateName T, 32757532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 32763e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith unsigned NumArgs, QualType Canon, 32773e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Aliased); 327855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 327955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor friend class ASTContext; // ASTContext creates these 328055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 328155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic: 328240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Determine whether any of the given template arguments are 328340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// dependent. 328440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 32851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned NumArgs); 328640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 3287833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args, 3288833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned NumArgs); 3289833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3290d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &); 3291d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 3292df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 3293df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// enclosing the template arguments. 3294df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 3295d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned NumArgs, 3296dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor const PrintingPolicy &Policy, 3297dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor bool SkipBrackets = false); 3298df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor 3299833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args, 3300833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned NumArgs, 3301833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const PrintingPolicy &Policy); 3302833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3303d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &, 3304d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const PrintingPolicy &Policy); 3305d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 330631f17ecbef57b5679c017c375db330546b7b5145John McCall /// True if this template specialization type matches a current 330731f17ecbef57b5679c017c375db330546b7b5145John McCall /// instantiation in the context in which it is found. 330831f17ecbef57b5679c017c375db330546b7b5145John McCall bool isCurrentInstantiation() const { 330971d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall return isa<InjectedClassNameType>(getCanonicalTypeInternal()); 331031f17ecbef57b5679c017c375db330546b7b5145John McCall } 331131f17ecbef57b5679c017c375db330546b7b5145John McCall 33123e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith /// True if this template specialization type is for a type alias 33133e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith /// template. 33143e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith bool isTypeAlias() const; 33153e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith /// Get the aliased type, if this is a specialization of a type alias 33163e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith /// template. 33173e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType getAliasedType() const { 33183e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith assert(isTypeAlias() && "not a type alias template specialization"); 33193e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return *reinterpret_cast<const QualType*>(end()); 33203e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 33213e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 332240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor typedef const TemplateArgument * iterator; 332340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 332440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator begin() const { return getArgs(); } 332533500955d731c73717af52088b7fc0e7a85681e7John McCall iterator end() const; // defined inline in TemplateBase.h 332640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 33277532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 33287532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName getTemplateName() const { return Template; } 332955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 333040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the template arguments. 33311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *getArgs() const { 333240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 333340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 333440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 333540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the number of template arguments. 333655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 333755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 333855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \brief Retrieve a specific template argument as a type. 333955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \precondition @c isArgType(Arg) 334033500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 334155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 334231f17ecbef57b5679c017c375db330546b7b5145John McCall bool isSugared() const { 33433e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return !isDependentType() || isCurrentInstantiation() || isTypeAlias(); 334431f17ecbef57b5679c017c375db330546b7b5145John McCall } 3345bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getCanonicalTypeInternal(); } 3346bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 33474ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) { 334871d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall Profile(ID, Template, getArgs(), NumArgs, Ctx); 33493e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (isTypeAlias()) 33503e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith getAliasedType().Profile(ID); 335155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 335255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 33537532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 335431f17ecbef57b5679c017c375db330546b7b5145John McCall const TemplateArgument *Args, 335531f17ecbef57b5679c017c375db330546b7b5145John McCall unsigned NumArgs, 33564ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context); 335755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 33581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 33591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == TemplateSpecialization; 336055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 33617532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 336255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}; 336355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 336431f17ecbef57b5679c017c375db330546b7b5145John McCall/// \brief The injected class name of a C++ class template or class 336531f17ecbef57b5679c017c375db330546b7b5145John McCall/// template partial specialization. Used to record that a type was 336631f17ecbef57b5679c017c375db330546b7b5145John McCall/// spelled with a bare identifier rather than as a template-id; the 336731f17ecbef57b5679c017c375db330546b7b5145John McCall/// equivalent for non-templated classes is just RecordType. 33683cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// 336931f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always dependent. Template 337031f17ecbef57b5679c017c375db330546b7b5145John McCall/// instantiation turns these into RecordTypes. 33713cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// 337231f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always canonical. This works 337331f17ecbef57b5679c017c375db330546b7b5145John McCall/// because it is impossible to compare an injected class name type 337431f17ecbef57b5679c017c375db330546b7b5145John McCall/// with the corresponding non-injected template type, for the same 337531f17ecbef57b5679c017c375db330546b7b5145John McCall/// reason that it is impossible to directly compare template 337631f17ecbef57b5679c017c375db330546b7b5145John McCall/// parameters from different dependent contexts: injected class name 337731f17ecbef57b5679c017c375db330546b7b5145John McCall/// types can only occur within the scope of a particular templated 337831f17ecbef57b5679c017c375db330546b7b5145John McCall/// declaration, and within that scope every template specialization 337931f17ecbef57b5679c017c375db330546b7b5145John McCall/// will canonicalize to the injected class name (when appropriate 338031f17ecbef57b5679c017c375db330546b7b5145John McCall/// according to the rules of the language). 33813cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameType : public Type { 33823cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall CXXRecordDecl *Decl; 33833cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 338431f17ecbef57b5679c017c375db330546b7b5145John McCall /// The template specialization which this type represents. 338531f17ecbef57b5679c017c375db330546b7b5145John McCall /// For example, in 338631f17ecbef57b5679c017c375db330546b7b5145John McCall /// template <class T> class A { ... }; 338731f17ecbef57b5679c017c375db330546b7b5145John McCall /// this is A<T>, whereas in 338831f17ecbef57b5679c017c375db330546b7b5145John McCall /// template <class X, class Y> class A<B<X,Y> > { ... }; 338931f17ecbef57b5679c017c375db330546b7b5145John McCall /// this is A<B<X,Y> >. 339031f17ecbef57b5679c017c375db330546b7b5145John McCall /// 339131f17ecbef57b5679c017c375db330546b7b5145John McCall /// It is always unqualified, always a template specialization type, 339231f17ecbef57b5679c017c375db330546b7b5145John McCall /// and always dependent. 339331f17ecbef57b5679c017c375db330546b7b5145John McCall QualType InjectedType; 33943cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 33953cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall friend class ASTContext; // ASTContext creates these. 3396c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not 3397c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl // currently suitable for AST reading, too much 339843921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis // interdependencies. 339931f17ecbef57b5679c017c375db330546b7b5145John McCall InjectedClassNameType(CXXRecordDecl *D, QualType TST) 340035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(InjectedClassName, QualType(), /*Dependent=*/true, 3401d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 3402d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 340331f17ecbef57b5679c017c375db330546b7b5145John McCall Decl(D), InjectedType(TST) { 34043cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(isa<TemplateSpecializationType>(TST)); 34053cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(!TST.hasQualifiers()); 340631f17ecbef57b5679c017c375db330546b7b5145John McCall assert(TST->isDependentType()); 34073cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 34083cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 34093cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallpublic: 341031f17ecbef57b5679c017c375db330546b7b5145John McCall QualType getInjectedSpecializationType() const { return InjectedType; } 341131f17ecbef57b5679c017c375db330546b7b5145John McCall const TemplateSpecializationType *getInjectedTST() const { 341231f17ecbef57b5679c017c375db330546b7b5145John McCall return cast<TemplateSpecializationType>(InjectedType.getTypePtr()); 34133cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 34143cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 3415ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl CXXRecordDecl *getDecl() const; 34163cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 341731f17ecbef57b5679c017c375db330546b7b5145John McCall bool isSugared() const { return false; } 341831f17ecbef57b5679c017c375db330546b7b5145John McCall QualType desugar() const { return QualType(this, 0); } 34193cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 34203cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall static bool classof(const Type *T) { 34213cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return T->getTypeClass() == InjectedClassName; 34223cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 34233cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall static bool classof(const InjectedClassNameType *T) { return true; } 34243cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}; 34253cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 3426465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief The kind of a tag type. 3427465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraenum TagTypeKind { 3428465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "struct" keyword. 3429465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Struct, 3430465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "union" keyword. 3431465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Union, 3432465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "class" keyword. 3433465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Class, 3434465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "enum" keyword. 3435465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Enum 3436465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}; 3437465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 34384a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or 34394a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// introduces an elaborated-type-specifier. 34404a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregorenum ElaboratedTypeKeyword { 34414a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "struct" keyword introduces the elaborated-type-specifier. 34424a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ETK_Struct, 34434a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "union" keyword introduces the elaborated-type-specifier. 34444a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ETK_Union, 3445465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "class" keyword introduces the elaborated-type-specifier. 3446465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_Class, 34474a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "enum" keyword introduces the elaborated-type-specifier. 3448465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_Enum, 3449465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "typename" keyword precedes the qualified type name, e.g., 3450465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \c typename T::type. 3451465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_Typename, 3452465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief No keyword precedes the qualified type name. 3453465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_None 34544a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor}; 3455465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3456465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword. 3457465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The keyword in stored in the free bits of the base class. 3458465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// Also provides a few static helpers for converting and printing 3459465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// elaborated type keyword and tag type kind enumerations. 3460465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass TypeWithKeyword : public Type { 3461465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraprotected: 3462465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, 3463d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType Canonical, bool Dependent, bool VariablyModified, 3464d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool ContainsUnexpandedParameterPack) 3465d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(tc, Canonical, Dependent, VariablyModified, 3466d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ContainsUnexpandedParameterPack) { 346777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall TypeWithKeywordBits.Keyword = Keyword; 346877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall } 3469465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3470465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarapublic: 3471465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeKeyword getKeyword() const { 347277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword); 3473465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 3474465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3475465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST) 3476465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// into an elaborated type keyword. 3477465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec); 3478465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3479465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST) 3480465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// into a tag type kind. It is an error to provide a type specifier 3481465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// which *isn't* a tag kind here. 3482465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec); 3483465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3484465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getKeywordForTagDeclKind - Converts a TagTypeKind into an 3485465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// elaborated type keyword. 3486465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag); 3487465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3488465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getTagTypeKindForKeyword - Converts an elaborated type keyword into 3489465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara // a TagTypeKind. It is an error to provide an elaborated type keyword 3490465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// which *isn't* a tag kind here. 3491465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword); 3492465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3493465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword); 3494465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3495465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static const char *getKeywordName(ElaboratedTypeKeyword Keyword); 3496465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3497465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static const char *getTagTypeKindName(TagTypeKind Kind) { 3498465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return getKeywordName(getKeywordForTagTypeKind(Kind)); 3499465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 3500465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3501465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara class CannotCastToThisType {}; 3502465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static CannotCastToThisType classof(const Type *); 3503465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}; 3504465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3505465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief Represents a type that was referred to using an elaborated type 3506465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type, 3507465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// or both. 3508e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// 3509e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the 3510465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// source code, including tag keywords and any nested-name-specifiers. 3511465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The type itself is always "sugar", used to express what was written 3512465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// in the source code but containing no additional semantic information. 3513465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode { 3514465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3515ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested name specifier containing the qualifier. 3516ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *NNS; 3517e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3518e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief The type that this qualified name refers to. 3519e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType; 3520e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3521465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 3522465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara QualType NamedType, QualType CanonType) 3523465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara : TypeWithKeyword(Keyword, Elaborated, CanonType, 352435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor NamedType->isDependentType(), 3525d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor NamedType->isVariablyModifiedType(), 3526d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor NamedType->containsUnexpandedParameterPack()), 3527465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NNS(NNS), NamedType(NamedType) { 3528465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara assert(!(Keyword == ETK_None && NNS == 0) && 3529465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara "ElaboratedType cannot have elaborated type keyword " 3530465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara "and name qualifier both null."); 3531465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 3532e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3533e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor friend class ASTContext; // ASTContext creates these 3534e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3535e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic: 353633500955d731c73717af52088b7fc0e7a85681e7John McCall ~ElaboratedType(); 3537465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3538ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the qualification on this type. 3539ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 3540e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3541e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 3542e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType getNamedType() const { return NamedType; } 3543e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3544bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 3545bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getNamedType(); } 3546bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3547bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 3548bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 3549bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3550e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 3551465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Profile(ID, getKeyword(), NNS, NamedType); 3552e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 3553e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3554465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 3555465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NestedNameSpecifier *NNS, QualType NamedType) { 3556465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ID.AddInteger(Keyword); 3557ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor ID.AddPointer(NNS); 3558ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NamedType.Profile(ID); 3559ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor } 3560e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 35611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 3562465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return T->getTypeClass() == Elaborated; 3563e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 3564465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static bool classof(const ElaboratedType *T) { return true; } 3565e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor}; 3566e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 35674a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief Represents a qualified type name for which the type name is 35684a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent. 3569d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// 35704a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// DependentNameType represents a class of dependent types that involve a 35714a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent) 35724a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a 35734a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// typename-specifier), "class", "struct", "union", or "enum" (for a 35744a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we 35754a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier). 3576465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { 3577465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3578d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The nested name specifier containing the qualifier. 3579d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *NNS; 3580d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3581d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The type that this typename specifier refers to. 358233500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name; 3583d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 35844a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 35854a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor const IdentifierInfo *Name, QualType CanonType) 358635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true, 3587d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 3588d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor NNS->containsUnexpandedParameterPack()), 3589465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NNS(NNS), Name(Name) { 35901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(NNS->isDependent() && 35914714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor "DependentNameType requires a dependent nested-name-specifier"); 3592d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3593d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3594d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor friend class ASTContext; // ASTContext creates these 3595d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3596d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic: 3597d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief Retrieve the qualification on this type. 3598d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 3599d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 36001734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 36011734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// identifier. 36021734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// 36031734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 36041734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// form of the original typename was terminated by an identifier, 36051734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// e.g., "typename T::type". 36061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo *getIdentifier() const { 360733500955d731c73717af52088b7fc0e7a85681e7John McCall return Name; 36081734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 3609d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3610bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 3611bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 3612bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3613d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 3614465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Profile(ID, getKeyword(), NNS, Name); 3615d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3616d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 36174a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 361833500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name) { 36194a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ID.AddInteger(Keyword); 3620d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor ID.AddPointer(NNS); 362133500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Name); 3622d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3623d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 36241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 36254714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor return T->getTypeClass() == DependentName; 3626d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 36274714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor static bool classof(const DependentNameType *T) { return true; } 3628d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor}; 3629d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 363033500955d731c73717af52088b7fc0e7a85681e7John McCall/// DependentTemplateSpecializationType - Represents a template 363133500955d731c73717af52088b7fc0e7a85681e7John McCall/// specialization type whose template cannot be resolved, e.g. 363233500955d731c73717af52088b7fc0e7a85681e7John McCall/// A<T>::template B<T> 363333500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationType : 363433500955d731c73717af52088b7fc0e7a85681e7John McCall public TypeWithKeyword, public llvm::FoldingSetNode { 363533500955d731c73717af52088b7fc0e7a85681e7John McCall 363633500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief The nested name specifier containing the qualifier. 363733500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS; 363833500955d731c73717af52088b7fc0e7a85681e7John McCall 363933500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief The identifier of the template. 364033500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name; 364133500955d731c73717af52088b7fc0e7a85681e7John McCall 364233500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief - The number of template arguments named in this class 364333500955d731c73717af52088b7fc0e7a85681e7John McCall /// template specialization. 364433500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs; 364533500955d731c73717af52088b7fc0e7a85681e7John McCall 364633500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *getArgBuffer() const { 364733500955d731c73717af52088b7fc0e7a85681e7John McCall return reinterpret_cast<const TemplateArgument*>(this+1); 364833500955d731c73717af52088b7fc0e7a85681e7John McCall } 364933500955d731c73717af52088b7fc0e7a85681e7John McCall TemplateArgument *getArgBuffer() { 365033500955d731c73717af52088b7fc0e7a85681e7John McCall return reinterpret_cast<TemplateArgument*>(this+1); 365133500955d731c73717af52088b7fc0e7a85681e7John McCall } 365233500955d731c73717af52088b7fc0e7a85681e7John McCall 3653ef99001908e799c388f1363b1e607dad5f5b57d3John McCall DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 365433500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, 365533500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 365633500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 365733500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args, 365833500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon); 365933500955d731c73717af52088b7fc0e7a85681e7John McCall 366033500955d731c73717af52088b7fc0e7a85681e7John McCall friend class ASTContext; // ASTContext creates these 366133500955d731c73717af52088b7fc0e7a85681e7John McCall 366233500955d731c73717af52088b7fc0e7a85681e7John McCallpublic: 366333500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *getQualifier() const { return NNS; } 366433500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *getIdentifier() const { return Name; } 366533500955d731c73717af52088b7fc0e7a85681e7John McCall 366633500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief Retrieve the template arguments. 366733500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *getArgs() const { 366833500955d731c73717af52088b7fc0e7a85681e7John McCall return getArgBuffer(); 366933500955d731c73717af52088b7fc0e7a85681e7John McCall } 367033500955d731c73717af52088b7fc0e7a85681e7John McCall 367133500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief Retrieve the number of template arguments. 367233500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned getNumArgs() const { return NumArgs; } 367333500955d731c73717af52088b7fc0e7a85681e7John McCall 367433500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 367533500955d731c73717af52088b7fc0e7a85681e7John McCall 367633500955d731c73717af52088b7fc0e7a85681e7John McCall typedef const TemplateArgument * iterator; 367733500955d731c73717af52088b7fc0e7a85681e7John McCall iterator begin() const { return getArgs(); } 367833500955d731c73717af52088b7fc0e7a85681e7John McCall iterator end() const; // inline in TemplateBase.h 367933500955d731c73717af52088b7fc0e7a85681e7John McCall 368033500955d731c73717af52088b7fc0e7a85681e7John McCall bool isSugared() const { return false; } 368133500955d731c73717af52088b7fc0e7a85681e7John McCall QualType desugar() const { return QualType(this, 0); } 368233500955d731c73717af52088b7fc0e7a85681e7John McCall 36834ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) { 368433500955d731c73717af52088b7fc0e7a85681e7John McCall Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs()); 368533500955d731c73717af52088b7fc0e7a85681e7John McCall } 368633500955d731c73717af52088b7fc0e7a85681e7John McCall 368733500955d731c73717af52088b7fc0e7a85681e7John McCall static void Profile(llvm::FoldingSetNodeID &ID, 36884ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 368933500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 369033500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *Qualifier, 369133500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 369233500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 369333500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args); 369433500955d731c73717af52088b7fc0e7a85681e7John McCall 369533500955d731c73717af52088b7fc0e7a85681e7John McCall static bool classof(const Type *T) { 369633500955d731c73717af52088b7fc0e7a85681e7John McCall return T->getTypeClass() == DependentTemplateSpecialization; 369733500955d731c73717af52088b7fc0e7a85681e7John McCall } 369833500955d731c73717af52088b7fc0e7a85681e7John McCall static bool classof(const DependentTemplateSpecializationType *T) { 369933500955d731c73717af52088b7fc0e7a85681e7John McCall return true; 370033500955d731c73717af52088b7fc0e7a85681e7John McCall } 370133500955d731c73717af52088b7fc0e7a85681e7John McCall}; 370233500955d731c73717af52088b7fc0e7a85681e7John McCall 37037536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \brief Represents a pack expansion of types. 37047536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 37057536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Pack expansions are part of C++0x variadic templates. A pack 37067536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// expansion contains a pattern, which itself contains one or more 37077536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// "unexpanded" parameter packs. When instantiated, a pack expansion 37087536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// produces a series of types, each instantiated from the pattern of 37097536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// the expansion, where the Ith instantiation of the pattern uses the 37107536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Ith arguments bound to each of the unexpanded parameter packs. The 37117536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// pack expansion is considered to "expand" these unexpanded 37127536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// parameter packs. 37137536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 37147536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \code 37157536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types> struct tuple; 37167536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 37177536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types> 37187536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// struct tuple_of_references { 37197536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// typedef tuple<Types&...> type; 37207536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// }; 37217536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \endcode 37227536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 37237536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Here, the pack expansion \c Types&... is represented via a 37247536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// PackExpansionType whose pattern is Types&. 37257536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorclass PackExpansionType : public Type, public llvm::FoldingSetNode { 37267536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// \brief The pattern of the pack expansion. 37277536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType Pattern; 37287536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 3729cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// \brief The number of expansions that this pack expansion will 3730cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// generate when substituted (+1), or indicates that 3731cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// 3732cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// This field will only have a non-zero value when some of the parameter 3733cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// packs that occur within the pattern have been substituted but others have 3734cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// not. 3735cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor unsigned NumExpansions; 3736cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor 3737cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor PackExpansionType(QualType Pattern, QualType Canon, 3738cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) 37397536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor : Type(PackExpansion, Canon, /*Dependent=*/true, 37407536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /*VariableModified=*/Pattern->isVariablyModifiedType(), 37417536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3742cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Pattern(Pattern), 3743cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions(NumExpansions? *NumExpansions + 1: 0) { } 37447536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 37457536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor friend class ASTContext; // ASTContext creates these 3746cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor 37477536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorpublic: 37487536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// \brief Retrieve the pattern of this pack expansion, which is the 37497536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// type that will be repeatedly instantiated when instantiating the 37507536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// pack expansion itself. 37517536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType getPattern() const { return Pattern; } 37527536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 3753cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// \brief Retrieve the number of expansions that this pack expansion will 3754cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// generate, if known. 3755cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> getNumExpansions() const { 3756cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor if (NumExpansions) 3757cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor return NumExpansions - 1; 3758cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor 3759cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor return llvm::Optional<unsigned>(); 3760cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor } 3761cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor 37627536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor bool isSugared() const { return false; } 37637536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType desugar() const { return QualType(this, 0); } 37647536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 37657536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 3766cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Profile(ID, getPattern(), getNumExpansions()); 37677536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 37687536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 3769cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern, 3770cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 37717536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor ID.AddPointer(Pattern.getAsOpaquePtr()); 3772cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor ID.AddBoolean(NumExpansions); 3773cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor if (NumExpansions) 3774cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor ID.AddInteger(*NumExpansions); 37757536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 37767536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 37777536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor static bool classof(const Type *T) { 37787536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return T->getTypeClass() == PackExpansion; 37797536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 37807536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor static bool classof(const PackExpansionType *T) { 37817536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return true; 37827536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 37837536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor}; 37847536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 3785c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectType - Represents a class type in Objective C. 3786c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Every Objective C type is a combination of a base type and a 3787c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// list of protocols. 3788c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3789c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Given the following declarations: 3790c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// @class C; 3791c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// @protocol P; 3792c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3793c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType 3794c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// with base C and no protocols. 3795c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3796c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P]. 3797c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3798e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose 3799e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType 3800e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// and no protocols. 3801c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3802e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType 3803e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually 3804e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// this should get its own sugar class to better represent the source. 3805c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectType : public Type { 3806b870b88df784c2940efce448ebfaf54dece14666John McCall // ObjCObjectType.NumProtocols - the number of protocols stored 3807b870b88df784c2940efce448ebfaf54dece14666John McCall // after the ObjCObjectPointerType node. 380871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // 380971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // These protocols are those written directly on the type. If 381071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // protocol qualifiers ever become additive, the iterators will need 381171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // to get kindof complicated. 381271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // 381371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // In the canonical object type, these are sorted alphabetically 381471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // and uniqued. 3815c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 3816c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// Either a BuiltinType or an InterfaceType or sugar for either. 3817c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType BaseType; 3818c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3819c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *getProtocolStorage() const { 3820c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return const_cast<ObjCObjectType*>(this)->getProtocolStorage(); 3821c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3822c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3823c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl **getProtocolStorage(); 3824c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3825c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallprotected: 3826c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectType(QualType Canonical, QualType Base, 3827c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, unsigned NumProtocols); 3828c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3829c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall enum Nonce_ObjCInterface { Nonce_ObjCInterface }; 3830c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectType(enum Nonce_ObjCInterface) 3831d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(ObjCInterface, QualType(), false, false, false), 383271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall BaseType(QualType(this_(), 0)) { 3833b870b88df784c2940efce448ebfaf54dece14666John McCall ObjCObjectTypeBits.NumProtocols = 0; 383471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 3835c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 38363536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 3837e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getBaseType - Gets the base type of this object type. This is 3838e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// always (possibly sugar for) one of: 3839e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// - the 'id' builtin type (as opposed to the 'id' type visible to the 3840e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// user, which is a typedef for an ObjCPointerType) 3841e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// - the 'Class' builtin type (same caveat) 3842e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// - an ObjCObjectType (currently always an ObjCInterfaceType) 3843c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType getBaseType() const { return BaseType; } 384471842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek 3845c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCId() const { 3846c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId); 3847c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3848c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCClass() const { 3849c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass); 3850c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3851c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); } 3852c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); } 3853c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCUnqualifiedIdOrClass() const { 3854c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!qual_empty()) return false; 3855c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>()) 3856c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T->getKind() == BuiltinType::ObjCId || 3857c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall T->getKind() == BuiltinType::ObjCClass; 3858c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return false; 3859c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3860c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); } 3861c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); } 3862c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3863c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// Gets the interface declaration for this object type, if the base type 3864c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// really is an interface. 3865c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCInterfaceDecl *getInterface() const; 3866c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3867c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall typedef ObjCProtocolDecl * const *qual_iterator; 3868c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3869c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator qual_begin() const { return getProtocolStorage(); } 3870c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); } 3871c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3872c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool qual_empty() const { return getNumProtocols() == 0; } 38731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3874c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 3875c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// interface type, or 0 if there are none. 3876b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; } 387714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 3878c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// \brief Fetch a protocol by index. 387973dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor ObjCProtocolDecl *getProtocol(unsigned I) const { 388073dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor assert(I < getNumProtocols() && "Out-of-range protocol access"); 388173dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor return qual_begin()[I]; 388273dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor } 388373dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor 3884bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 3885bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 3886bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3887c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static bool classof(const Type *T) { 3888c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T->getTypeClass() == ObjCObject || 3889c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall T->getTypeClass() == ObjCInterface; 3890c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3891c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static bool classof(const ObjCObjectType *) { return true; } 3892c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}; 3893c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3894c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation 3895c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// of ObjCObjectType, so as to not increase the footprint of 3896c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType. Code outside of ASTContext and the core type 3897c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// system should not reference this type. 3898c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode { 3899c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall friend class ASTContext; 3900c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3901c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // If anyone adds fields here, ObjCObjectType::getProtocolStorage() 3902c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // will need to be modified. 3903c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3904c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypeImpl(QualType Canonical, QualType Base, 3905c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 3906c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) 3907c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {} 3908c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3909c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic: 3910c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 39111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, 3912c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType Base, 3913c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl *const *protocols, 3914c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols); 3915c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}; 39161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3917c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() { 3918c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return reinterpret_cast<ObjCProtocolDecl**>( 3919c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static_cast<ObjCObjectTypeImpl*>(this) + 1); 3920c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 3921c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3922c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 3923c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// object oriented design. They basically correspond to C++ classes. There 3924c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// are two kinds of interface types, normal interfaces like "NSString" and 3925c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// qualified interfaces, which are qualified with a protocol list like 3926c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// "NSString<NSCopyable, NSAmazing>". 3927e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 3928e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCInterfaceType guarantees the following properties when considered 3929e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// as a subtype of its superclass, ObjCObjectType: 3930e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// - There are no protocol qualifiers. To reinforce this, code which 3931e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// tries to invoke the protocol methods via an ObjCInterfaceType will 3932e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// fail to compile. 3933e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// - It is its own base type. That is, if T is an ObjCInterfaceType*, 3934e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// T->getBaseType() == QualType(T, 0). 3935c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCInterfaceType : public ObjCObjectType { 3936c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCInterfaceDecl *Decl; 3937c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3938c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCInterfaceType(const ObjCInterfaceDecl *D) 3939c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall : ObjCObjectType(Nonce_ObjCInterface), 3940c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Decl(const_cast<ObjCInterfaceDecl*>(D)) {} 3941c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall friend class ASTContext; // ASTContext creates these. 39421fb0caaa7bef765b85972274e3b434af2572c141John McCall 3943c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic: 3944e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getDecl - Get the declaration of this interface. 3945deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor ObjCInterfaceDecl *getDecl() const { return Decl; } 3946c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3947c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isSugared() const { return false; } 3948c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType desugar() const { return QualType(this, 0); } 39490b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 39501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 39511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ObjCInterface; 39523536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 3953a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 3954c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3955c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Nonsense to "hide" certain members of ObjCObjectType within this 3956c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // class. People asking for protocols on an ObjCInterfaceType are 3957c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // not going to get what they want: ObjCInterfaceTypes are 3958c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // guaranteed to have no protocols. 3959c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall enum { 3960c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator, 3961c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_begin, 3962c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_end, 3963c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getNumProtocols, 3964c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getProtocol 3965c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall }; 39663536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 39673536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 3968c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const { 3969c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCInterfaceType *T = 3970c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getBaseType()->getAs<ObjCInterfaceType>()) 3971c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T->getDecl(); 3972c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return 0; 3973c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 3974c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3975e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCObjectPointerType - Used to represent a pointer to an 3976e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Objective C object. These are constructed from pointer 3977e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar 3978e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for one). In addition, the 'id' and 'Class' types are typedefs 3979e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>' 3980e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// are translated into these. 398114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// 3982e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Pointers to pointers to Objective C objects are still PointerTypes; 3983e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// only the first level of pointer gets it own type implementation. 398414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 3985e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall QualType PointeeType; 39861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3987c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerType(QualType Canonical, QualType Pointee) 3988d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(ObjCObjectPointer, Canonical, false, false, false), 3989c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall PointeeType(Pointee) {} 399014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff friend class ASTContext; // ASTContext creates these. 39911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 399214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic: 3993e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getPointeeType - Gets the type pointed to by this ObjC pointer. 3994e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// The result will always be an ObjCObjectType or sugar thereof. 399514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const { return PointeeType; } 399614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 3997e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getObjCObjectType - Gets the type pointed to by this ObjC 3998e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// pointer. This method always returns non-null. 3999e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// 4000e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// This method is equivalent to getPointeeType() except that 4001e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// it discards any typedefs (or other sugar) between this 4002e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// type and the "outermost" object type. So for: 4003e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// @class A; @protocol P; @protocol Q; 4004e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A<P> AP; 4005e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A A1; 4006e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A1<P> A1P; 4007e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A1P<Q> A1PQ; 4008e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A*', getObjectType() will return 'A'. 4009e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A<P>*', getObjectType() will return 'A<P>'. 4010e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'AP*', getObjectType() will return 'A<P>'. 4011e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1*', getObjectType() will return 'A'. 4012e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1<P>*', getObjectType() will return 'A1<P>'. 4013e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1P*', getObjectType() will return 'A1<P>'. 4014e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because 4015e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// adding protocols to a protocol-qualified base discards the 4016e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// old qualifiers (for now). But if it didn't, getObjectType() 4017e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// would return 'A1P<Q>' (and we'd have to make iterating over 4018e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// qualifiers more complicated). 4019c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *getObjectType() const { 4020d0370f59e79702ac908c81bf556519f91e9ca297John McCall return PointeeType->castAs<ObjCObjectType>(); 4021c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 4022c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4023e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getInterfaceType - If this pointer points to an Objective C 4024e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// @interface type, gets the type for that interface. Any protocol 4025e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// qualifiers on the interface are ignored. 4026e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// 4027e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// \return null if the base type for this pointer is 'id' or 'Class' 40281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const ObjCInterfaceType *getInterfaceType() const { 4029c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>(); 403014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 4031e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 4032e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getInterfaceDecl - If this pointer points to an Objective @interface 4033e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// type, gets the declaration for that interface. 4034e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// 4035e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// \return null if the base type for this pointer is 'id' or 'Class' 403614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCInterfaceDecl *getInterfaceDecl() const { 4037e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall return getObjectType()->getInterface(); 403814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 4039e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 4040e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if 4041e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// its object type is the primitive 'id' type with no protocols. 404214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const { 4043c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCUnqualifiedId(); 404414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 4045e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 4046e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCClassType - True if this is equivalent to the 'Class' type, 4047e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// i.e. if its object tive is the primitive 'Class' type with no protocols. 404814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const { 4049c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCUnqualifiedClass(); 4050de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 40518d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian 4052e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some 4053e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// non-empty set of protocols. 40541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isObjCQualifiedIdType() const { 4055c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCQualifiedId(); 4056de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 4057e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 4058e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for 4059e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// some non-empty set of protocols. 4060470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const { 4061c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCQualifiedClass(); 406214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 4063e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 4064e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// An iterator over the qualifiers on the object type. Provided 4065e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// for convenience. This will always iterate over the full set of 4066e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// protocols on a type, not just those provided directly. 4067c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall typedef ObjCObjectType::qual_iterator qual_iterator; 406814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 406971842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek qual_iterator qual_begin() const { 4070c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->qual_begin(); 407171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek } 4072c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator qual_end() const { 4073c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->qual_end(); 407471842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek } 4075c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool qual_empty() const { return getObjectType()->qual_empty(); } 407614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 4077e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getNumProtocols - Return the number of qualifying protocols on 4078e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// the object type. 4079c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned getNumProtocols() const { 4080c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->getNumProtocols(); 4081c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 408214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 4083e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// \brief Retrieve a qualifying protocol by index on the object 4084e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// type. 408573dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor ObjCProtocolDecl *getProtocol(unsigned I) const { 4086c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->getProtocol(I); 408773dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor } 408873dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor 4089bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 4090bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 4091bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 4092e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall void Profile(llvm::FoldingSetNodeID &ID) { 4093e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall Profile(ID, getPointeeType()); 4094e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall } 4095c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { 4096c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(T.getAsOpaquePtr()); 4097c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 40981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 40991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ObjCObjectPointer; 410014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 410114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 410214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}; 41031bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 41040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers. 41050953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers { 41060953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 410749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {} 41080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 41090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Collect any qualifiers on the given type and return an 41103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// unqualified type. The qualifiers are assumed to be consistent 41113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// with those already in the type. 41123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *strip(QualType type) { 41133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall addFastQualifiers(type.getLocalFastQualifiers()); 41143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!type.hasLocalNonFastQualifiers()) 41153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return type.getTypePtrUnsafe(); 41163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 41173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ExtQuals *extQuals = type.getExtQualsUnsafe(); 41183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall addConsistentQualifiers(extQuals->getQualifiers()); 41193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return extQuals->getBaseType(); 41200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 41210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 41220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Apply the collected qualifiers to the given type. 41234ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType apply(const ASTContext &Context, QualType QT) const; 41240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 41250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Apply the collected qualifiers to the given type. 41264ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType apply(const ASTContext &Context, const Type* T) const; 41270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 41280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 41290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4130611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 41315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 41323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtr() const { 41333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getCommonPtr()->BaseType; 41343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 41353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 41363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtrOrNull() const { 41373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return (isNull() ? 0 : getCommonPtr()->BaseType); 41383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 41393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 41403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline SplitQualType QualType::split() const { 41413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!hasLocalNonFastQualifiers()) 41423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return SplitQualType(getTypePtrUnsafe(), 41433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers::fromFastMask(getLocalFastQualifiers())); 41443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 41453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ExtQuals *eq = getExtQualsUnsafe(); 41463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers qs = eq->getQualifiers(); 41473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall qs.addFastQualifiers(getLocalFastQualifiers()); 41483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return SplitQualType(eq->getBaseType(), qs); 41493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 41503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 41513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getLocalQualifiers() const { 41523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers Quals; 41533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (hasLocalNonFastQualifiers()) 41543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals = getExtQualsUnsafe()->getQualifiers(); 41553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals.addFastQualifiers(getLocalFastQualifiers()); 41563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return Quals; 41573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 41583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 41593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getQualifiers() const { 41603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers(); 41613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall quals.addFastQualifiers(getLocalFastQualifiers()); 41623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return quals; 41633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 41643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 41653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline unsigned QualType::getCVRQualifiers() const { 41663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers(); 41673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall cvr |= getLocalCVRQualifiers(); 41683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return cvr; 41693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 41703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 41713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline QualType QualType::getCanonicalType() const { 41723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType canon = getCommonPtr()->CanonicalType; 41733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return canon.withFastQualifiers(getLocalFastQualifiers()); 41743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 41753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 4176467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const { 41773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getTypePtr()->isCanonicalUnqualified(); 4178467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall} 4179467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall 418054e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const { 41813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isCanonical()) return false; 4182a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalQualifiers()) return false; 4183745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian 418454e14c4db764c0636160d26c5bbf491637c83a76John McCall const Type *T = getTypePtr(); 41853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (T->isVariablyModifiedType() && T->hasSizedVLAType()) 41863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return false; 41873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 41883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return !isa<FunctionType>(T) && !isa<ArrayType>(T); 418954e14c4db764c0636160d26c5bbf491637c83a76John McCall} 419054e14c4db764c0636160d26c5bbf491637c83a76John McCall 4191fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const { 4192fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return isLocalConstQualified() || 41933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.isLocalConstQualified(); 4194fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 4195fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 4196fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const { 4197fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return isLocalRestrictQualified() || 41983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.isLocalRestrictQualified(); 4199fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 4200fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 4201fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 4202fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const { 4203fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return isLocalVolatileQualified() || 42043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.isLocalVolatileQualified(); 4205fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 4206fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 4207fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const { 4208fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return hasLocalQualifiers() || 42093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.hasLocalQualifiers(); 4210fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 421162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 421262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline QualType QualType::getUnqualifiedType() const { 421362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) 421462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return QualType(getTypePtr(), 0); 421562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 421662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return QualType(getSplitUnqualifiedTypeImpl(*this).first, 0); 421762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall} 421862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 421962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline SplitQualType QualType::getSplitUnqualifiedType() const { 422062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) 422162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return split(); 422262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 422362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getSplitUnqualifiedTypeImpl(*this); 4224fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 4225fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 422649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalConst() { 422749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Qualifiers::Const); 42280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 42290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 423049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalRestrict() { 423149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Qualifiers::Restrict); 42320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 42330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 423449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalVolatile() { 423549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Qualifiers::Volatile); 42360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 42370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 423849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalCVRQualifiers(unsigned Mask) { 42396b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits"); 4240c3c0af36bac3d71f61dd758585ab307892545de4Douglas Gregor assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask); 42410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 42420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Fast path: we don't need to touch the slow qualifiers. 424349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Mask); 4244ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 4245ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 4246ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 4247ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 42483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getQualifiers().getAddressSpace(); 4249ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 4250611c1fff195d32df97706e0920c92468b2509900Chris Lattner 4251d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 42520953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const { 42533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getQualifiers().getObjCGCAttr(); 4254d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 42552455636163fdd18581d7fdae816433f886d88213Mike Stump 4256264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { 4257264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola if (const PointerType *PT = t.getAs<PointerType>()) { 4258183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>()) 4259264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FT->getExtInfo(); 4260264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } else if (const FunctionType *FT = t.getAs<FunctionType>()) 4261264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FT->getExtInfo(); 42622455636163fdd18581d7fdae816433f886d88213Mike Stump 4263264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FunctionType::ExtInfo(); 42642455636163fdd18581d7fdae816433f886d88213Mike Stump} 42651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4266264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { 4267264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return getFunctionExtInfo(*t); 4268ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor} 4269ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor 4270e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 4271e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 4272e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and 4273e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile 4274e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int". 427562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isMoreQualifiedThan(QualType other) const { 427662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Qualifiers myQuals = getQualifiers(); 427762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Qualifiers otherQuals = other.getQualifiers(); 427862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return (myQuals != otherQuals && myQuals.compatiblyIncludes(otherQuals)); 4279e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 4280e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 4281e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 4282e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile 4283e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 4284e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int". 428562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isAtLeastAsQualifiedAs(QualType other) const { 428662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getQualifiers().compatiblyIncludes(other.getQualifiers()); 4287e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 4288e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 4289e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 4290e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const 4291e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 4292e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6: 4293e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 4294e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 4295e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 4296e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// analysis, the expression designates the object or function 4297e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 4298e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const { 42996217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 4300e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return RefType->getPointeeType(); 4301e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor else 4302e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return *this; 4303e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 4304e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 4305aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \brief Tests whether the type is categorized as a fundamental type. 4306aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// 4307aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \returns True for types specified in C++0x [basic.fundamental]. 4308aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruthinline bool Type::isFundamentalType() const { 4309aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth return isVoidType() || 4310aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // FIXME: It's really annoying that we don't have an 4311aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // 'isArithmeticType()' which agrees with the standard definition. 4312aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth (isArithmeticType() && !isEnumeralType()); 4313aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth} 4314aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth 4315aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \brief Tests whether the type is categorized as a compound type. 4316aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// 4317aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \returns True for types specified in C++0x [basic.compound]. 4318aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruthinline bool Type::isCompoundType() const { 4319aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // C++0x [basic.compound]p1: 4320aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // Compound types can be constructed in the following ways: 4321aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- arrays of objects of a given type [...]; 4322aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth return isArrayType() || 4323aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- functions, which have parameters of given types [...]; 4324aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isFunctionType() || 4325aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- pointers to void or objects or functions [...]; 4326aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isPointerType() || 4327aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- references to objects or functions of a given type. [...] 4328aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isReferenceType() || 4329aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- classes containing a sequence of objects of various types, [...]; 4330aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isRecordType() || 4331aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- unions, which ar classes capable of containing objects of different types at different times; 4332aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isUnionType() || 4333aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- enumerations, which comprise a set of named constant values. [...]; 4334aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isEnumeralType() || 4335aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- pointers to non-static class members, [...]. 4336aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isMemberPointerType(); 4337aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth} 4338aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth 4339611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 4340a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<FunctionType>(CanonicalType); 4341611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 4342611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 4343a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<PointerType>(CanonicalType); 4344611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 434558f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const { 434658f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff return isPointerType() || isObjCObjectPointerType(); 434758f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff} 43485618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const { 4349a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<BlockPointerType>(CanonicalType); 43505618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 4351bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const { 4352a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ReferenceType>(CanonicalType); 4353bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 43547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const { 4355a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<LValueReferenceType>(CanonicalType); 43567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 43577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const { 4358a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<RValueReferenceType>(CanonicalType); 43597c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 4360498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 4361d0370f59e79702ac908c81bf556519f91e9ca297John McCall if (const PointerType *T = getAs<PointerType>()) 4362498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 4363498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 4364498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 4365498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 4366f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const { 4367a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<MemberPointerType>(CanonicalType); 4368f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 4369f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 43706217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const MemberPointerType* T = getAs<MemberPointerType>()) 43710bab0cdab751248ca389a5592bcb70eac5d39260John McCall return T->isMemberFunctionPointer(); 4372f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl else 4373f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return false; 4374f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 4375db68e28c05a67735211e688009890cf834c22e75Douglas Gregorinline bool Type::isMemberDataPointerType() const { 4376db68e28c05a67735211e688009890cf834c22e75Douglas Gregor if (const MemberPointerType* T = getAs<MemberPointerType>()) 43770bab0cdab751248ca389a5592bcb70eac5d39260John McCall return T->isMemberDataPointer(); 4378db68e28c05a67735211e688009890cf834c22e75Douglas Gregor else 4379db68e28c05a67735211e688009890cf834c22e75Douglas Gregor return false; 4380db68e28c05a67735211e688009890cf834c22e75Douglas Gregor} 4381611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 4382a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ArrayType>(CanonicalType); 4383611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 4384c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const { 4385a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ConstantArrayType>(CanonicalType); 4386c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 4387c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const { 4388a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<IncompleteArrayType>(CanonicalType); 4389c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 4390c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const { 4391a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<VariableArrayType>(CanonicalType); 4392c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 4393898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const { 4394a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType); 4395898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 43963ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isBuiltinType() const { 43973ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall return isa<BuiltinType>(CanonicalType); 43983ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall} 4399611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 4400a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<RecordType>(CanonicalType); 4401611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 44023ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isEnumeralType() const { 44033ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall return isa<EnumType>(CanonicalType); 44043ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall} 4405f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const { 4406a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ComplexType>(CanonicalType); 4407f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner} 4408611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 4409a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<VectorType>(CanonicalType); 4410611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 4411213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const { 4412a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ExtVectorType>(CanonicalType); 4413611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 4414d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const { 4415a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ObjCObjectPointerType>(CanonicalType); 4416d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 4417c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline bool Type::isObjCObjectType() const { 4418c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return isa<ObjCObjectType>(CanonicalType); 4419368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 4420569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorinline bool Type::isObjCObjectOrInterfaceType() const { 4421569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor return isa<ObjCInterfaceType>(CanonicalType) || 4422569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor isa<ObjCObjectType>(CanonicalType); 4423569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor} 4424569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor 4425a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 4426183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 4427d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT->isObjCQualifiedIdType(); 4428d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return false; 4429d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 4430470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const { 4431183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 4432470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return OPT->isObjCQualifiedClassType(); 4433470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return false; 4434470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff} 443514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const { 4436183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 443714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCIdType(); 443814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 443914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 444014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const { 4441183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 444214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCClassType(); 444314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 444414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 444513dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const { 44468d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian if (const PointerType *OPT = getAs<PointerType>()) 44478d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); 444813dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian return false; 444913dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian} 4450de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const { 445113dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian return isObjCIdType() || isObjCClassType() || isObjCSelType(); 4452de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff} 445372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const { 4454a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType); 445572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor} 445672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4457e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 4458183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 4459e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 4460e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return true; 4461e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return false; 4462e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar} 4463e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 44642a984cad5ac3fdceeff2bd99daa7b90979313475John McCallinline bool Type::isPlaceholderType() const { 44652a984cad5ac3fdceeff2bd99daa7b90979313475John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 44662a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return BT->isPlaceholderType(); 44672a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return false; 44682a984cad5ac3fdceeff2bd99daa7b90979313475John McCall} 44692a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 4470864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCallinline bool Type::isSpecificPlaceholderType(unsigned K) const { 4471864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(this)) 4472864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return (BT->getKind() == (BuiltinType::Kind) K); 4473864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return false; 4474864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall} 4475864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 4476063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define 4477063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator. 4478063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const { 4479063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 4480904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor} 4481904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 44828958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 44838958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 4484c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall isObjCObjectPointerType() || isNullPtrType()); 44858958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar} 44868958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 4487820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 4488c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return isObjCObjectPointerType(); 4489820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian} 4490820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 4491d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const Type *Type::getBaseElementTypeUnsafe() const { 4492d0370f59e79702ac908c81bf556519f91e9ca297John McCall const Type *type = this; 4493d0370f59e79702ac908c81bf556519f91e9ca297John McCall while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe()) 4494d0370f59e79702ac908c81bf556519f91e9ca297John McCall type = arrayType->getElementType().getTypePtr(); 4495d0370f59e79702ac908c81bf556519f91e9ca297John McCall return type; 4496d0370f59e79702ac908c81bf556519f91e9ca297John McCall} 4497d0370f59e79702ac908c81bf556519f91e9ca297John McCall 449822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 449922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<. 450022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 450122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner QualType T) { 450222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 450322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner Diagnostic::ak_qualtype); 450422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner return DB; 450522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner} 45061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 450747c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// Insertion operator for partial diagnostics. This allows sending QualType's 450847c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// into a diagnostic with <<. 450947c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruthinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, 451047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth QualType T) { 451147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 451247c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth Diagnostic::ak_qualtype); 451347c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth return PD; 451447c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth} 451547c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth 451689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does 451789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type. 451889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T, 451989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor bool isArrayType = (llvm::is_same<T, ArrayType>::value || 452089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor llvm::is_base_of<ArrayType, T>::value)> 452189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { }; 452289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor 452389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T> 452489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>; 452589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor 45261a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'. 45271a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const { 452889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor ArrayType_cannot_be_used_with_getAs<T> at; 452989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor (void)at; 453089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor 45311a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If this is directly a T type, return it. 45321a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek if (const T *Ty = dyn_cast<T>(this)) 45331a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return Ty; 45341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 45351a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If the canonical form of this type isn't the right kind, reject it. 45360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<T>(CanonicalType)) 45371a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return 0; 45381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 45390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If this is a typedef for the type, strip the typedef off without 45401a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // losing all typedef information. 4541bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<T>(getUnqualifiedDesugaredType()); 45421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 454322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner 45443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const ArrayType *Type::getAsArrayTypeUnsafe() const { 45453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If this is directly an array type, return it. 45463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const ArrayType *arr = dyn_cast<ArrayType>(this)) 45473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return arr; 45483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 45493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If the canonical form of this type isn't the right kind, reject it. 45503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isa<ArrayType>(CanonicalType)) 45513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return 0; 45523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 45533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If this is a typedef for the type, strip the typedef off without 45543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // losing all typedef information. 45553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()); 45563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 45573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 4558d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <typename T> const T *Type::castAs() const { 4559d0370f59e79702ac908c81bf556519f91e9ca297John McCall ArrayType_cannot_be_used_with_getAs<T> at; 4560d0370f59e79702ac908c81bf556519f91e9ca297John McCall (void) at; 4561d0370f59e79702ac908c81bf556519f91e9ca297John McCall 4562d0370f59e79702ac908c81bf556519f91e9ca297John McCall assert(isa<T>(CanonicalType)); 4563d0370f59e79702ac908c81bf556519f91e9ca297John McCall if (const T *ty = dyn_cast<T>(this)) return ty; 4564d0370f59e79702ac908c81bf556519f91e9ca297John McCall return cast<T>(getUnqualifiedDesugaredType()); 4565d0370f59e79702ac908c81bf556519f91e9ca297John McCall} 4566d0370f59e79702ac908c81bf556519f91e9ca297John McCall 4567d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const ArrayType *Type::castAsArrayTypeUnsafe() const { 4568d0370f59e79702ac908c81bf556519f91e9ca297John McCall assert(isa<ArrayType>(CanonicalType)); 4569d0370f59e79702ac908c81bf556519f91e9ca297John McCall if (const ArrayType *arr = dyn_cast<ArrayType>(this)) return arr; 4570d0370f59e79702ac908c81bf556519f91e9ca297John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()); 4571d0370f59e79702ac908c81bf556519f91e9ca297John McCall} 4572d0370f59e79702ac908c81bf556519f91e9ca297John McCall 45735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 45745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 45755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 4576