Type.h revision 769d0cc72b1831785596d0e76f327bdb887823be
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 { 29762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Non-CVR qualifiers must match exactly. CVR qualifiers may subset. 29862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return ((Mask & ~CVRMask) == (other.Mask & ~CVRMask)) && 29962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)); 30062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 30162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 302769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor /// \brief Determine whether this set of qualifiers is a strict superset of 303769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor /// another set of qualifiers, not considering qualifier compatibility. 304769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor bool isStrictSupersetOf(Qualifiers Other) const; 305769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor 3060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool operator==(Qualifiers Other) const { return Mask == Other.Mask; } 3070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; } 3080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall operator bool() const { return hasQualifiers(); } 3100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers &operator+=(Qualifiers R) { 3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addQualifiers(R); 3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return *this; 3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Union two qualifier sets. If an enumerated qualifier appears 3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // in both sets, use the one from the right. 3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall friend Qualifiers operator+(Qualifiers L, Qualifiers R) { 3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall L += R; 3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return L; 3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3223cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor 3233cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor Qualifiers &operator-=(Qualifiers R) { 3243cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor Mask = Mask & ~(R.Mask); 3253cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor return *this; 3263cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor } 3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3283cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor /// \brief Compute the difference between two qualifier sets. 3293cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor friend Qualifiers operator-(Qualifiers L, Qualifiers R) { 3303cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor L -= R; 3313cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor return L; 3323cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor } 3333cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor 3340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string getAsString() const; 3350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string getAsString(const PrintingPolicy &Policy) const { 3360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string Buffer; 3370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getAsStringInternal(Buffer, Policy); 3380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Buffer; 3390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const; 3410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 3430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ID.AddInteger(Mask); 3440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3460953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate: 3470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // bits: |0 1 2|3 .. 4|5 .. 31| 3490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // |C R V|GCAttr|AddrSpace| 3500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall uint32_t Mask; 3510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t GCAttrMask = 0x18; 3530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t GCAttrShift = 3; 3540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask); 3550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t AddressSpaceShift = 5; 3560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 3570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 358ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses. 359ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv { 360ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_Default, 361ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_C, // __attribute__((cdecl)) 362ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_X86StdCall, // __attribute__((stdcall)) 363f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor CC_X86FastCall, // __attribute__((fastcall)) 36452fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik CC_X86ThisCall, // __attribute__((thiscall)) 365414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov CC_X86Pascal, // __attribute__((pascal)) 366414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov CC_AAPCS, // __attribute__((pcs("aapcs"))) 367414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov CC_AAPCS_VFP // __attribute__((pcs("aapcs-vfp"))) 368ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}; 369ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor 37049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCalltypedef std::pair<const Type*, Qualifiers> SplitQualType; 3710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on 3730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers. This 3740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for 3750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int', 3760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc). 3770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 3780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we 3790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the 3800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer. To handle the packing/unpacking, we make QualType be a 3810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer. A third bit 3820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which 3830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure. 3840953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType { 3850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Thankfully, these are efficiently composable. 3860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>, 3870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::FastWidth> Value; 3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *getExtQualsUnsafe() const { 3900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().get<const ExtQuals*>(); 3910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *getTypePtrUnsafe() const { 3940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().get<const Type*>(); 3950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ExtQualsTypeCommonBase *getCommonPtr() const { 3983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!isNull() && "Cannot retrieve a NULL type pointer"); 3993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall uintptr_t CommonPtrVal 4003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = reinterpret_cast<uintptr_t>(Value.getOpaqueValue()); 4013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1); 4023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal); 4033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 4043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 4050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall friend class QualifierCollector; 4060953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 4075cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType() {} 4081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4095cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType(const Type *Ptr, unsigned Quals) 4100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Value(Ptr, Quals) {} 4110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType(const ExtQuals *Ptr, unsigned Quals) 4120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Value(Ptr, Quals) {} 4130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 414a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor unsigned getLocalFastQualifiers() const { return Value.getInt(); } 415a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); } 4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Retrieves a pointer to the underlying (unqualified) type. 4180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// This should really return a const Type, but it's not worth 4190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// changing all the users right now. 4201ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor /// 4211ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor /// This function requires that the type not be NULL. If the type might be 4221ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor /// NULL, use the (slightly less efficient) \c getTypePtrOrNull(). 4233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *getTypePtr() const; 4241ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor 4253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *getTypePtrOrNull() const; 4261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall /// Divides a QualType into its unqualified type and a set of local 42849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall /// qualifiers. 4293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType split() const; 43049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall 4315cf243a883872441d73ca49cea7e20de5802629bChris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 432f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall static QualType getFromOpaquePtr(const void *Ptr) { 4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType T; 434f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall T.Value.setFromOpaqueValue(const_cast<void*>(Ptr)); 4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T; 4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 438f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type &operator*() const { 4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *getTypePtr(); 4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 442f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type *operator->() const { 4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypePtr(); 4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 446467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall bool isCanonical() const; 44754e14c4db764c0636160d26c5bbf491637c83a76John McCall bool isCanonicalAsParam() const; 448467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall 4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNull - Return true if this QualType doesn't point to a type yet. 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNull() const { 4510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().isNull(); 4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 454a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has the 455a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "const" qualifier set, without looking through typedefs that may have 456a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "const" at a different level. 457a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalConstQualified() const { 458a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Const); 4590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 460a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 461a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is const-qualified. 462fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isConstQualified() const; 463a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 464a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has the 465a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "restrict" qualifier set, without looking through typedefs that may have 466a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "restrict" at a different level. 467a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalRestrictQualified() const { 468a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Restrict); 469a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor } 470a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 471a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is restrict-qualified. 472fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isRestrictQualified() const; 473a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 474a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has the 475a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "volatile" qualifier set, without looking through typedefs that may have 476a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "volatile" at a different level. 477a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalVolatileQualified() const { 478f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor return (getLocalFastQualifiers() & Qualifiers::Volatile); 4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 481a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is volatile-qualified. 482fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isVolatileQualified() const; 483a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 484a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has any 485a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// qualifiers, without looking through any typedefs that might add 486a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// qualifiers at a different level. 487a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool hasLocalQualifiers() const { 488a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return getLocalFastQualifiers() || hasLocalNonFastQualifiers(); 4890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 491a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type has any qualifiers. 492fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool hasQualifiers() const; 493a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 494a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has any 495a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType 496a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// instance. 497a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool hasLocalNonFastQualifiers() const { 498a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return Value.getPointer().is<const ExtQuals*>(); 4990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 501a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of qualifiers local to this particular QualType 502a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// instance, not including any qualifiers acquired through typedefs or 503a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// other sugar. 5043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers getLocalQualifiers() const; 5050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 506a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of qualifiers applied to this type. 507fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor Qualifiers getQualifiers() const; 508a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 509a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 510a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// local to this particular QualType instance, not including any qualifiers 511a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// acquired through typedefs or other sugar. 512a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor unsigned getLocalCVRQualifiers() const { 513f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor return getLocalFastQualifiers(); 5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 515b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 516a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 517a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// applied to this type. 518fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor unsigned getCVRQualifiers() const; 519e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth 520bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isConstant(ASTContext& Ctx) const { 521bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return QualType::isConstant(*this, Ctx); 522bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 5231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Don't promise in the API that anything besides 'const' can be 5250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // easily added. 5260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// addConst - add the specified type qualifier to this QualType. 5280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addConst() { 5290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addFastQualifiers(Qualifiers::Const); 5300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withConst() const { 5320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return withFastQualifiers(Qualifiers::Const); 5330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addFastQualifiers(unsigned TQs) { 5360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(TQs & ~Qualifiers::FastMask) 5370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall && "non-fast qualifier bits set in mask!"); 5380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Value.setInt(Value.getInt() | TQs); 5390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 54149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalConst(); 54249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalVolatile(); 54349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalRestrict(); 54449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalCVRQualifiers(unsigned Mask); 5450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 54649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalFastQualifiers() { Value.setInt(0); } 54749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalFastQualifiers(unsigned Mask) { 5480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers"); 5490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Value.setInt(Value.getInt() & ~Mask); 5500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Creates a type with the given qualifiers in addition to any 5530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // qualifiers already on this type. 5540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withFastQualifiers(unsigned TQs) const { 5550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType T = *this; 5560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall T.addFastQualifiers(TQs); 5570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return T; 5580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5591c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta 5600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Creates a type with exactly the given fast qualifiers, removing 5610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // any existing fast qualifiers. 56249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall QualType withExactLocalFastQualifiers(unsigned TQs) const { 56349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return withoutLocalFastQualifiers().withFastQualifiers(TQs); 5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Removes fast qualifiers, but leaves any extended qualifiers in place. 56749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall QualType withoutLocalFastQualifiers() const { 5680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType T = *this; 56949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall T.removeLocalFastQualifiers(); 5700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return T; 571c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 572971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 5733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType getCanonicalType() const; 5743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 575a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Return this type with all of the instance-specific qualifiers 576a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// removed, but without removing any qualifiers that may have been applied 577a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// through typedefs. 578a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); } 5791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \brief Retrieve the unqualified variant of the given type, 58162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// removing as little sugar as possible. 58262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 58362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// This routine looks through various kinds of sugar to find the 58462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// least-desugared type that is unqualified. For example, given: 58562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 58662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \code 58762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// typedef int Integer; 58862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// typedef const Integer CInteger; 58962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// typedef CInteger DifferenceType; 59062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \endcode 59162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 59262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// Executing \c getUnqualifiedType() on the type \c DifferenceType will 59362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// desugar until we hit the type \c Integer, which has no qualifiers on it. 59462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 59562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// The resulting type might still be qualified if it's an array 59662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// type. To strip qualifiers even from within an array type, use 59762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// ASTContext::getUnqualifiedArrayType. 59862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall inline QualType getUnqualifiedType() const; 59962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 60062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// getSplitUnqualifiedType - Retrieve the unqualified variant of the 60162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// given type, removing as little sugar as possible. 60262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 60362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// Like getUnqualifiedType(), but also returns the set of 60462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// qualifiers that were built up. 60562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 60662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// The resulting type might still be qualified if it's an array 60762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// type. To strip qualifiers even from within an array type, use 60862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// ASTContext::getUnqualifiedArrayType. 60962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall inline SplitQualType getSplitUnqualifiedType() const; 610a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 61161d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// \brief Determine whether this type is more qualified than the other 61261d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// given type, requiring exact equality for non-CVR qualifiers. 613e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 61461d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor 61561d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// \brief Determine whether this type is at least as qualified as the other 61661d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// given type, requiring exact equality for non-CVR qualifiers. 617e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 61861d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor 619e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getNonReferenceType() const; 6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6216398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// \brief Determine the type of a (typically non-lvalue) expression with the 6226398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// specified result type. 6235291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// 6246398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// This routine should be used for expressions for which the return type is 6256398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// explicitly specified (e.g., in a cast or call) and isn't necessarily 6266398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// an lvalue. It removes a top-level reference (since there are no 6275291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// expressions of reference type) and deletes top-level cvr-qualifiers 6285291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// from non-class types (in C++) or all types (in C). 6296398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor QualType getNonLValueExprType(ASTContext &Context) const; 6305291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 6312fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 6322fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 6332fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 6342fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 6352fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 6362fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// concrete. 6370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// 6380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Qualifiers are left in place. 6394ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType getDesugaredType(const ASTContext &Context) const { 64049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getDesugaredType(*this, Context); 64149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 64249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall 64349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall SplitQualType getSplitDesugaredType() const { 64449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getSplitDesugaredType(*this); 645bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 64698cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor 647075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// IgnoreParens - Returns the specified type after dropping any 648075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// outer-level parentheses. 649075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType IgnoreParens() const { 650723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara if (isa<ParenType>(*this)) 651723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara return QualType::IgnoreParens(*this); 652723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara return *this; 653075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 654075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// operator==/!= - Indicate whether the specified types and qualifiers are 6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identical. 65750d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor friend bool operator==(const QualType &LHS, const QualType &RHS) { 65850d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return LHS.Value == RHS.Value; 6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 66050d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor friend bool operator!=(const QualType &LHS, const QualType &RHS) { 66150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return LHS.Value != RHS.Value; 6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 66349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall std::string getAsString() const { 66449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getAsString(split()); 66549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 66649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static std::string getAsString(SplitQualType split) { 66749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getAsString(split.first, split.second); 66849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 66949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static std::string getAsString(const Type *ty, Qualifiers qs); 670d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 671d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString(const PrintingPolicy &Policy) const { 6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string S; 673d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor getAsStringInternal(S, Policy); 6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return S; 6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 676e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner void getAsStringInternal(std::string &Str, 67749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall const PrintingPolicy &Policy) const { 67849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getAsStringInternal(split(), Str, Policy); 67949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 68049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static void getAsStringInternal(SplitQualType split, std::string &out, 68149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall const PrintingPolicy &policy) { 68249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getAsStringInternal(split.first, split.second, out, policy); 68349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 68449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static void getAsStringInternal(const Type *ty, Qualifiers qs, 68549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall std::string &out, 68649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall const PrintingPolicy &policy); 6871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 688c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump(const char *s) const; 689c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 6901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6913f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 6923f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 6933f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek } 6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 695ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 696ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 6971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 698d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 6990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall inline Qualifiers::GC getObjCGCAttr() const; 700f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 701f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 702f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCWeak() const { 7030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getObjCGCAttr() == Qualifiers::Weak; 704f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 705f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 706f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 707f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCStrong() const { 7080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getObjCGCAttr() == Qualifiers::Strong; 709f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 7102455636163fdd18581d7fdae816433f886d88213Mike Stump 7110d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall enum DestructionKind { 7120d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall DK_none, 7130d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall DK_cxx_destructor 7140d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall }; 7150d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 7160d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// isDestructedType - nonzero if objects of this type require 7170d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// non-trivial work to clean up after. Non-zero because it's 7180d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// conceivable that qualifiers (objc_gc(weak)?) could make 7190d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// something require destruction. 7200d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall DestructionKind isDestructedType() const { 7210d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall return isDestructedTypeImpl(*this); 7220d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall } 7230d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 724bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate: 725bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // These methods are implemented in a separate translation unit; 726bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // "static"-ize them to avoid creating temporary QualTypes in the 727bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // caller. 728bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall static bool isConstant(QualType T, ASTContext& Ctx); 7294ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static QualType getDesugaredType(QualType T, const ASTContext &Context); 73049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static SplitQualType getSplitDesugaredType(QualType T); 73162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall static SplitQualType getSplitUnqualifiedTypeImpl(QualType type); 732075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static QualType IgnoreParens(QualType T); 7330d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall static DestructionKind isDestructedTypeImpl(QualType type); 7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 742f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall typedef const ::clang::Type *SimpleType; 7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 7444472fc641ea3069463798fb56a04043c28ea2910Douglas Gregor return Val.getTypePtr(); 7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 7491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7504e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 7514e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<> 752daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 7534e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic: 7544e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 7554e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return P.getAsOpaquePtr(); 7564e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 7574e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 7584e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return clang::QualType::getFromOpaquePtr(P); 7594e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 7600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Various qualifiers go in low bits. 7610eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 0 }; 7624e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}; 7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76473af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// \brief Base class that is common to both the \c ExtQuals and \c Type 7693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// classes, which allows \c QualType to access the common fields between the 7703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// two. 7713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// 7723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQualsTypeCommonBase { 7733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQualsTypeCommonBase(const Type *baseType, QualType canon) 7743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall : BaseType(baseType), CanonicalType(canon) {} 7753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 7763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// \brief The "base" type of an extended qualifiers type (\c ExtQuals) or 7773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// a self-referential pointer (for \c Type). 7783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// 7793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// This pointer allows an efficient mapping from a QualType to its 7803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// underlying type pointer. 7813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *const BaseType; 7823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 7833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// \brief The canonical type of this type. A QualType. 7843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType CanonicalType; 7853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 7863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall friend class QualType; 7873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall friend class Type; 7883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall friend class ExtQuals; 7893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}; 7903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 7913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// ExtQuals - We can encode up to four bits in the low bits of a 7923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// type pointer, but there are many more type qualifiers that we want 7933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// to be able to apply to an arbitrary type. Therefore we have this 7943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// struct, intended to be heap-allocated and used by QualType to 7953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// store qualifiers. 7963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// 7973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers 7983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// in three low bits on the QualType pointer; a fourth bit records whether 7993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// the pointer is an ExtQuals node. The extended qualifiers (address spaces, 8003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// Objective-C GC attributes) are much more rare. 8013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { 8023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // NOTE: changing the fast qualifiers should be straightforward as 8033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // long as you don't make 'const' non-fast. 8043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // 1. Qualifiers: 8053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ). 8063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Fast qualifiers must occupy the low-order bits. 8073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // b) Update Qualifiers::FastWidth and FastMask. 8083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // 2. QualType: 8093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // a) Update is{Volatile,Restrict}Qualified(), defined inline. 8103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // b) Update remove{Volatile,Restrict}, defined near the end of 8113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // this header. 8123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // 3. ASTContext: 8133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // a) Update get{Volatile,Restrict}Type. 8143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// Quals - the immutable set of qualifiers applied by this 8163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// node; always contains extended qualifiers. 8173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers Quals; 8183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQuals *this_() { return this; } 8203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic: 8223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQuals(const Type *baseType, QualType canon, Qualifiers quals) 8233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall : ExtQualsTypeCommonBase(baseType, 8243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall canon.isNull() ? QualType(this_(), 0) : canon), 8253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals(quals) 8263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall { 8273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(Quals.hasNonFastQualifiers() 8283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall && "ExtQuals created with no fast qualifiers"); 8293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!Quals.hasFastQualifiers() 8303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall && "ExtQuals created with fast qualifiers"); 8313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 8323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers getQualifiers() const { return Quals; } 8343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); } 8363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); } 8373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall bool hasAddressSpace() const { return Quals.hasAddressSpace(); } 8393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned getAddressSpace() const { return Quals.getAddressSpace(); } 8403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *getBaseType() const { return BaseType; } 8423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 8433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic: 8443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall void Profile(llvm::FoldingSetNodeID &ID) const { 8453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Profile(ID, getBaseType(), Quals); 8463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 8473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall static void Profile(llvm::FoldingSetNodeID &ID, 8483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *BaseType, 8493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers Quals) { 8503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!"); 8513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ID.AddPointer(BaseType); 8523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals.Profile(ID); 8533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 8543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}; 8553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 856c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// \brief The kind of C++0x ref-qualifier associated with a function type, 857c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// which determines whether a member function's "this" object can be an 858c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// lvalue, rvalue, or neither. 859c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregorenum RefQualifierKind { 860c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief No ref-qualifier was provided. 861c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RQ_None = 0, 862c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief An lvalue ref-qualifier was provided (\c &). 863c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RQ_LValue, 864c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief An rvalue ref-qualifier was provided (\c &&). 865c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RQ_RValue 866c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor}; 867c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 8695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 8715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 87972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 88272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 8865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8931ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass Type : public ExtQualsTypeCommonBase { 8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 89672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class, 89727935ee59c30b0d8b610ab676aab8e65350af932John McCall#define LAST_TYPE(Class) TypeLast = Class, 89872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 89972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 90072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TagFirst = Record, TagLast = Enum 9015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 9021bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 904c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Type(const Type&); // DO NOT IMPLEMENT. 905c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall void operator=(const Type&); // DO NOT IMPLEMENT. 906c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 907b870b88df784c2940efce448ebfaf54dece14666John McCall /// Bitfields required by the Type class. 908b870b88df784c2940efce448ebfaf54dece14666John McCall class TypeBitfields { 909b870b88df784c2940efce448ebfaf54dece14666John McCall friend class Type; 910b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall template <class T> friend class TypePropertyCache; 91127935ee59c30b0d8b610ab676aab8e65350af932John McCall 912b870b88df784c2940efce448ebfaf54dece14666John McCall /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 913b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned TC : 8; 914b870b88df784c2940efce448ebfaf54dece14666John McCall 915b870b88df784c2940efce448ebfaf54dece14666John McCall /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 916b870b88df784c2940efce448ebfaf54dece14666John McCall /// Note that this should stay at the end of the ivars for Type so that 917b870b88df784c2940efce448ebfaf54dece14666John McCall /// subclasses can pack their bitfields into the same word. 918bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet unsigned Dependent : 1; 91960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 920b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief Whether this type is a variably-modified type (C99 6.7.5). 921bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet unsigned VariablyModified : 1; 922d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 923d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this type contains an unexpanded parameter pack 924d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// (for C++0x variadic templates). 925d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned ContainsUnexpandedParameterPack : 1; 92635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 9271fb0caaa7bef765b85972274e3b434af2572c141John McCall /// \brief Nonzero if the cache (i.e. the bitfields here starting 9281fb0caaa7bef765b85972274e3b434af2572c141John McCall /// with 'Cache') is valid. If so, then this is a 9291fb0caaa7bef765b85972274e3b434af2572c141John McCall /// LangOptions::VisibilityMode+1. 9301fb0caaa7bef765b85972274e3b434af2572c141John McCall mutable unsigned CacheValidAndVisibility : 2; 93160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 932b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief Linkage of this type. 933b870b88df784c2940efce448ebfaf54dece14666John McCall mutable unsigned CachedLinkage : 2; 93407a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 935b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief Whether this type involves and local or unnamed types. 936bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet mutable unsigned CachedLocalOrUnnamed : 1; 937db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 938b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief FromAST - Whether this type comes from an AST file. 939bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet mutable unsigned FromAST : 1; 940b870b88df784c2940efce448ebfaf54dece14666John McCall 9411fb0caaa7bef765b85972274e3b434af2572c141John McCall bool isCacheValid() const { 9421fb0caaa7bef765b85972274e3b434af2572c141John McCall return (CacheValidAndVisibility != 0); 9431fb0caaa7bef765b85972274e3b434af2572c141John McCall } 9441fb0caaa7bef765b85972274e3b434af2572c141John McCall Visibility getVisibility() const { 9451fb0caaa7bef765b85972274e3b434af2572c141John McCall assert(isCacheValid() && "getting linkage from invalid cache"); 9461fb0caaa7bef765b85972274e3b434af2572c141John McCall return static_cast<Visibility>(CacheValidAndVisibility-1); 9471fb0caaa7bef765b85972274e3b434af2572c141John McCall } 9481fb0caaa7bef765b85972274e3b434af2572c141John McCall Linkage getLinkage() const { 9491fb0caaa7bef765b85972274e3b434af2572c141John McCall assert(isCacheValid() && "getting linkage from invalid cache"); 9501fb0caaa7bef765b85972274e3b434af2572c141John McCall return static_cast<Linkage>(CachedLinkage); 9511fb0caaa7bef765b85972274e3b434af2572c141John McCall } 9521fb0caaa7bef765b85972274e3b434af2572c141John McCall bool hasLocalOrUnnamedType() const { 9531fb0caaa7bef765b85972274e3b434af2572c141John McCall assert(isCacheValid() && "getting linkage from invalid cache"); 9541fb0caaa7bef765b85972274e3b434af2572c141John McCall return CachedLocalOrUnnamed; 9551fb0caaa7bef765b85972274e3b434af2572c141John McCall } 956b870b88df784c2940efce448ebfaf54dece14666John McCall }; 957d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor enum { NumTypeBits = 17 }; 958b870b88df784c2940efce448ebfaf54dece14666John McCall 959b870b88df784c2940efce448ebfaf54dece14666John McCallprotected: 960b870b88df784c2940efce448ebfaf54dece14666John McCall // These classes allow subclasses to somewhat cleanly pack bitfields 961b870b88df784c2940efce448ebfaf54dece14666John McCall // into Type. 962b870b88df784c2940efce448ebfaf54dece14666John McCall 963b870b88df784c2940efce448ebfaf54dece14666John McCall class ArrayTypeBitfields { 964b870b88df784c2940efce448ebfaf54dece14666John McCall friend class ArrayType; 965b870b88df784c2940efce448ebfaf54dece14666John McCall 966b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 967b870b88df784c2940efce448ebfaf54dece14666John McCall 968b870b88df784c2940efce448ebfaf54dece14666John McCall /// IndexTypeQuals - CVR qualifiers from declarations like 969b870b88df784c2940efce448ebfaf54dece14666John McCall /// 'int X[static restrict 4]'. For function parameters only. 970b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned IndexTypeQuals : 3; 971b870b88df784c2940efce448ebfaf54dece14666John McCall 972b870b88df784c2940efce448ebfaf54dece14666John McCall /// SizeModifier - storage class qualifiers from declarations like 973b870b88df784c2940efce448ebfaf54dece14666John McCall /// 'int X[static restrict 4]'. For function parameters only. 974b870b88df784c2940efce448ebfaf54dece14666John McCall /// Actually an ArrayType::ArraySizeModifier. 975b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned SizeModifier : 3; 976b870b88df784c2940efce448ebfaf54dece14666John McCall }; 977b870b88df784c2940efce448ebfaf54dece14666John McCall 978b870b88df784c2940efce448ebfaf54dece14666John McCall class BuiltinTypeBitfields { 979b870b88df784c2940efce448ebfaf54dece14666John McCall friend class BuiltinType; 980b870b88df784c2940efce448ebfaf54dece14666John McCall 981b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 982b870b88df784c2940efce448ebfaf54dece14666John McCall 983b870b88df784c2940efce448ebfaf54dece14666John McCall /// The kind (BuiltinType::Kind) of builtin type this is. 984b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned Kind : 8; 985b870b88df784c2940efce448ebfaf54dece14666John McCall }; 986b870b88df784c2940efce448ebfaf54dece14666John McCall 987b870b88df784c2940efce448ebfaf54dece14666John McCall class FunctionTypeBitfields { 988b870b88df784c2940efce448ebfaf54dece14666John McCall friend class FunctionType; 989b870b88df784c2940efce448ebfaf54dece14666John McCall 990b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 991b870b88df784c2940efce448ebfaf54dece14666John McCall 992b870b88df784c2940efce448ebfaf54dece14666John McCall /// Extra information which affects how the function is called, like 993b870b88df784c2940efce448ebfaf54dece14666John McCall /// regparm and the calling convention. 994b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned ExtInfo : 8; 995b870b88df784c2940efce448ebfaf54dece14666John McCall 996e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall /// Whether the function is variadic. Only used by FunctionProtoType. 997e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned Variadic : 1; 998b870b88df784c2940efce448ebfaf54dece14666John McCall 999b870b88df784c2940efce448ebfaf54dece14666John McCall /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1000b870b88df784c2940efce448ebfaf54dece14666John McCall /// other bitfields. 1001b870b88df784c2940efce448ebfaf54dece14666John McCall /// The qualifiers are part of FunctionProtoType because... 1002b870b88df784c2940efce448ebfaf54dece14666John McCall /// 1003b870b88df784c2940efce448ebfaf54dece14666John McCall /// C++ 8.3.5p4: The return type, the parameter type list and the 1004b870b88df784c2940efce448ebfaf54dece14666John McCall /// cv-qualifier-seq, [...], are part of the function type. 1005b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned TypeQuals : 3; 1006c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 1007c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief The ref-qualifier associated with a \c FunctionProtoType. 1008c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// 1009c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// This is a value of type \c RefQualifierKind. 1010c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor unsigned RefQualifier : 2; 1011b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1012b870b88df784c2940efce448ebfaf54dece14666John McCall 1013b870b88df784c2940efce448ebfaf54dece14666John McCall class ObjCObjectTypeBitfields { 1014b870b88df784c2940efce448ebfaf54dece14666John McCall friend class ObjCObjectType; 1015b870b88df784c2940efce448ebfaf54dece14666John McCall 1016b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 1017b870b88df784c2940efce448ebfaf54dece14666John McCall 1018b870b88df784c2940efce448ebfaf54dece14666John McCall /// NumProtocols - The number of protocols stored directly on this 1019b870b88df784c2940efce448ebfaf54dece14666John McCall /// object type. 1020b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned NumProtocols : 32 - NumTypeBits; 1021b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1022b870b88df784c2940efce448ebfaf54dece14666John McCall 1023b870b88df784c2940efce448ebfaf54dece14666John McCall class ReferenceTypeBitfields { 1024b870b88df784c2940efce448ebfaf54dece14666John McCall friend class ReferenceType; 1025b870b88df784c2940efce448ebfaf54dece14666John McCall 1026b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 1027b870b88df784c2940efce448ebfaf54dece14666John McCall 1028b870b88df784c2940efce448ebfaf54dece14666John McCall /// True if the type was originally spelled with an lvalue sigil. 1029b870b88df784c2940efce448ebfaf54dece14666John McCall /// This is never true of rvalue references but can also be false 1030b870b88df784c2940efce448ebfaf54dece14666John McCall /// on lvalue references because of C++0x [dcl.typedef]p9, 1031b870b88df784c2940efce448ebfaf54dece14666John McCall /// as follows: 1032b870b88df784c2940efce448ebfaf54dece14666John McCall /// 1033b870b88df784c2940efce448ebfaf54dece14666John McCall /// typedef int &ref; // lvalue, spelled lvalue 1034b870b88df784c2940efce448ebfaf54dece14666John McCall /// typedef int &&rvref; // rvalue 1035b870b88df784c2940efce448ebfaf54dece14666John McCall /// ref &a; // lvalue, inner ref, spelled lvalue 1036b870b88df784c2940efce448ebfaf54dece14666John McCall /// ref &&a; // lvalue, inner ref 1037b870b88df784c2940efce448ebfaf54dece14666John McCall /// rvref &a; // lvalue, inner ref, spelled lvalue 1038b870b88df784c2940efce448ebfaf54dece14666John McCall /// rvref &&a; // rvalue, inner ref 1039bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet unsigned SpelledAsLValue : 1; 1040b870b88df784c2940efce448ebfaf54dece14666John McCall 1041b870b88df784c2940efce448ebfaf54dece14666John McCall /// True if the inner type is a reference type. This only happens 1042b870b88df784c2940efce448ebfaf54dece14666John McCall /// in non-canonical forms. 1043bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet unsigned InnerRef : 1; 1044b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1045b870b88df784c2940efce448ebfaf54dece14666John McCall 104677be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall class TypeWithKeywordBitfields { 104777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall friend class TypeWithKeyword; 104877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall 104977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall unsigned : NumTypeBits; 105077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall 105177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall /// An ElaboratedTypeKeyword. 8 bits for efficient access. 105277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall unsigned Keyword : 8; 105377be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall }; 105477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall 1055b870b88df784c2940efce448ebfaf54dece14666John McCall class VectorTypeBitfields { 1056b870b88df784c2940efce448ebfaf54dece14666John McCall friend class VectorType; 105707a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 1058b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 105971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 1060e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson /// VecKind - The kind of vector, either a generic vector type or some 1061e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson /// target-specific vector type such as for AltiVec or Neon. 1062cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson unsigned VecKind : 3; 1063b870b88df784c2940efce448ebfaf54dece14666John McCall 1064b870b88df784c2940efce448ebfaf54dece14666John McCall /// NumElements - The number of elements in the vector. 1065cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson unsigned NumElements : 29 - NumTypeBits; 1066b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1067b870b88df784c2940efce448ebfaf54dece14666John McCall 10689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall class AttributedTypeBitfields { 10699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall friend class AttributedType; 10709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 10719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall unsigned : NumTypeBits; 10729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 10739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// AttrKind - an AttributedType::Kind 10749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall unsigned AttrKind : 32 - NumTypeBits; 10759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall }; 10769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 1077b870b88df784c2940efce448ebfaf54dece14666John McCall union { 1078b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBitfields TypeBits; 1079b870b88df784c2940efce448ebfaf54dece14666John McCall ArrayTypeBitfields ArrayTypeBits; 10809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeBitfields AttributedTypeBits; 1081b870b88df784c2940efce448ebfaf54dece14666John McCall BuiltinTypeBitfields BuiltinTypeBits; 1082b870b88df784c2940efce448ebfaf54dece14666John McCall FunctionTypeBitfields FunctionTypeBits; 1083b870b88df784c2940efce448ebfaf54dece14666John McCall ObjCObjectTypeBitfields ObjCObjectTypeBits; 1084b870b88df784c2940efce448ebfaf54dece14666John McCall ReferenceTypeBitfields ReferenceTypeBits; 108577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall TypeWithKeywordBitfields TypeWithKeywordBits; 1086b870b88df784c2940efce448ebfaf54dece14666John McCall VectorTypeBitfields VectorTypeBits; 1087b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1088b870b88df784c2940efce448ebfaf54dece14666John McCall 1089b870b88df784c2940efce448ebfaf54dece14666John McCallprivate: 10903c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl /// \brief Set whether this type comes from an AST file. 10913c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl void setFromAST(bool V = true) const { 1092b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.FromAST = V; 109307a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl } 109407a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 1095b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall template <class T> friend class TypePropertyCache; 10961fb0caaa7bef765b85972274e3b434af2572c141John McCall 10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 1098124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 1099124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 11003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Type(TypeClass tc, QualType canon, bool Dependent, bool VariablyModified, 1101d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool ContainsUnexpandedParameterPack) 11023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall : ExtQualsTypeCommonBase(this, 11033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall canon.isNull() ? QualType(this_(), 0) : canon) { 1104b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.TC = tc; 1105b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.Dependent = Dependent; 1106b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.VariablyModified = VariablyModified; 1107d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 11081fb0caaa7bef765b85972274e3b434af2572c141John McCall TypeBits.CacheValidAndVisibility = 0; 1109b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.CachedLocalOrUnnamed = false; 1110b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.CachedLinkage = NoLinkage; 1111b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.FromAST = false; 1112b870b88df784c2940efce448ebfaf54dece14666John McCall } 11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1115b870b88df784c2940efce448ebfaf54dece14666John McCall void setDependent(bool D = true) { TypeBits.Dependent = D; } 1116b870b88df784c2940efce448ebfaf54dece14666John McCall void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; } 1117d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor void setContainsUnexpandedParameterPack(bool PP = true) { 1118d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor TypeBits.ContainsUnexpandedParameterPack = PP; 1119d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 1120d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 11218b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 1122b870b88df784c2940efce448ebfaf54dece14666John McCall TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); } 11231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11243c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl /// \brief Whether this type comes from an AST file. 1125b870b88df784c2940efce448ebfaf54dece14666John McCall bool isFromAST() const { return TypeBits.FromAST; } 112607a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 1127d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this type is or contains an unexpanded parameter 1128d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// pack, used to support C++0x variadic templates. 1129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 1130d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// A type that contains a parameter pack shall be expanded by the 1131d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// ellipsis operator at some point. For example, the typedef in the 1132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// following example contains an unexpanded parameter pack 'T': 1133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 1134d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \code 1135d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// template<typename ...T> 1136d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// struct X { 1137d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// typedef T* pointer_types; // ill-formed; T is a parameter pack. 1138d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// }; 1139d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \endcode 1140d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 1141d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// Note that this routine does not specify which 1142d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool containsUnexpandedParameterPack() const { 1143d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return TypeBits.ContainsUnexpandedParameterPack; 1144d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 1145d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 11463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// Determines if this type would be canonical if it had no further 11473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// qualification. 1148467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall bool isCanonicalUnqualified() const { 11493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return CanonicalType == QualType(this, 0); 1150467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall } 11515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 11535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 11541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// routine will need to determine if the size is actually required. 11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncompleteType() const; 1160d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner 1161d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 1162d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// type, in other words, not a function type. 1163d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner bool isIncompleteOrObjectType() const { 1164d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner return !isFunctionType(); 1165d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner } 11662fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor 11672fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor /// \brief Determine whether this type is an object type. 11682fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor bool isObjectType() const { 11692fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor // C++ [basic.types]p8: 11702fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor // An object type is a (possibly cv-qualified) type that is not a 11712fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor // function type, not a reference type, and not a void type. 11722fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor return !isReferenceType() && !isFunctionType() && !isVoidType(); 11732fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor } 117464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 117564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 117664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl bool isPODType() const; 117764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 1178ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl /// isLiteralType - Return true if this is a literal type 1179ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl /// (C++0x [basic.types]p10) 1180ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl bool isLiteralType() const; 1181ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 118220c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley /// isTrivialType - Return true if this is a trivial type 1183b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth /// (C++0x [basic.types]p9) 1184b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth bool isTrivialType() const; 1185b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth 1186636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth /// \brief Test if this type is a standard-layout type. 1187636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth /// (C++0x [basic.type]p9) 1188636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth bool isStandardLayoutType() const; 1189636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 119043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth /// isCXX11PODType() - Return true if this is a POD type according to the 119143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth /// more relaxed rules of the C++11 standard, regardless of the current 119243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth /// compilation's language. 119343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth /// (C++0x [basic.types]p9) 119443fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth bool isCXX11PODType() const; 119543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 1197ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 1198e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 11999b065ddabf572772991a4aadad5bf4921fac5069Tom Care /// isBuiltinType - returns true if the type is a builtin type. 12009b065ddabf572772991a4aadad5bf4921fac5069Tom Care bool isBuiltinType() const; 12019b065ddabf572772991a4aadad5bf4921fac5069Tom Care 1202e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 1203e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 12041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12052a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// isPlaceholderType - Test for a type which does not represent an 12062a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// actual type-system type but is instead used as a placeholder for 12072a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// various convenient purposes within Clang. All such types are 12082a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// BuiltinTypes. 12092a984cad5ac3fdceeff2bd99daa7b90979313475John McCall bool isPlaceholderType() const; 12102a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 1211864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// isSpecificPlaceholderType - Test for a specific placeholder type. 1212864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall bool isSpecificPlaceholderType(unsigned K) const; 1213864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 121496d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 121596d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 12165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 121713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 121813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 121913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 122077a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor bool isWideCharType() const; 122120093b4bf698f292c664676987541d5103b65b15Douglas Gregor bool isAnyCharacterType() const; 12229d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor bool isIntegralType(ASTContext &Ctx) const; 122320093b4bf698f292c664676987541d5103b65b15Douglas Gregor 12242ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor /// \brief Determine whether this type is an integral or enumeration type. 12252ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor bool isIntegralOrEnumerationType() const; 12261274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor /// \brief Determine whether this type is an integral or unscoped enumeration 12271274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor /// type. 12281274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor bool isIntegralOrUnscopedEnumerationType() const; 12292ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor 12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 12315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 123202f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 123302f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 1235f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 12365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 12385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 1239c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 1240c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 1241c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 1242d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor bool isAggregateType() const; 12431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1244c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 1245ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 1246c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 1247183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } 1248183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } 1249befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 125058f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 12515618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff bool isBlockPointerType() const; 12527154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff bool isVoidPointerType() const; 1253a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 12547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isLValueReferenceType() const; 12557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isRValueReferenceType() const; 1256bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isFunctionPointerType() const; 1257f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberPointerType() const; 1258f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberFunctionPointerType() const; 1259db68e28c05a67735211e688009890cf834c22e75Douglas Gregor bool isMemberDataPointerType() const; 1260c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 1261c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isConstantArrayType() const; 1262c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isIncompleteArrayType() const; 1263c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isVariableArrayType() const; 1264898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentSizedArrayType() const; 1265c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 12661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isClassType() const; 12671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isStructureType() const; 1268fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor bool isStructureOrClassType() const; 12694cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 1270368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 1271368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isVectorType() const; // GCC vector type. 1272213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman bool isExtVectorType() const; // Extended vector type. 1273d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 127414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // FIXME: change this to 'raw' interface type, so we can used 'interface' type 127514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for the common case. 1276c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCObjectType() const; // NSString or typeof(*(id)0) 1277368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 1278368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedIdType() const; // id<foo> 1279470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const; // Class<foo> 1280569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor bool isObjCObjectOrInterfaceType() const; 128114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const; // id 128214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const; // Class 128313dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian bool isObjCSelType() const; // Class 1284de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff bool isObjCBuiltinType() const; // 'id' or 'Class' 128572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 12866e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 1287898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1288daa8e4e888758d55a7a759dd4a91b83921cef222John McCall enum ScalarTypeKind { 1289daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_Pointer, 1290daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_MemberPointer, 1291daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_Bool, 1292daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_Integral, 1293daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_Floating, 1294daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_IntegralComplex, 1295daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_FloatingComplex 1296daa8e4e888758d55a7a759dd4a91b83921cef222John McCall }; 1297daa8e4e888758d55a7a759dd4a91b83921cef222John McCall /// getScalarTypeKind - Given that this is a scalar type, classify it. 1298daa8e4e888758d55a7a759dd4a91b83921cef222John McCall ScalarTypeKind getScalarTypeKind() const; 1299daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 1300898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 13011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// that its definition somehow depends on a template parameter 1302898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.type]). 1303b870b88df784c2940efce448ebfaf54dece14666John McCall bool isDependentType() const { return TypeBits.Dependent; } 130435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 130535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor /// \brief Whether this type is a variably-modified type (C99 6.7.5). 1306b870b88df784c2940efce448ebfaf54dece14666John McCall bool isVariablyModifiedType() const { return TypeBits.VariablyModified; } 13073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 13083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// \brief Whether this type involves a variable-length array type 13093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// with a definite size. 13103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall bool hasSizedVLAType() const; 131135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 1312db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor /// \brief Whether this type is or contains a local or unnamed type. 1313db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor bool hasUnnamedOrLocalType() const; 1314db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 1315063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor bool isOverloadableType() const; 131672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 13174033642464e8ba0982f88f34cffad808d247b393Douglas Gregor /// \brief Determine wither this type is a C++ elaborated-type-specifier. 13184033642464e8ba0982f88f34cffad808d247b393Douglas Gregor bool isElaboratedTypeSpecifier() const; 13194033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 13208958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 13218958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 13228958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 13236e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl /// interface types, as well as nullptr_t. 13248958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar bool hasPointerRepresentation() const; 13258958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 1326820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 1327820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 13281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool hasObjCPointerRepresentation() const; 1329820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 1330f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// \brief Determine whether this type has an integer representation 1331f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// of some sort, e.g., it is an integer type or a vector. 1332f60946222721d9ba3c059563935c17b84703187aDouglas Gregor bool hasIntegerRepresentation() const; 1333f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 1334f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// \brief Determine whether this type has an signed integer representation 1335f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// of some sort, e.g., it is an signed integer type or a vector. 1336f60946222721d9ba3c059563935c17b84703187aDouglas Gregor bool hasSignedIntegerRepresentation() const; 1337f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 1338f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// \brief Determine whether this type has an unsigned integer representation 1339f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// of some sort, e.g., it is an unsigned integer type or a vector. 1340f60946222721d9ba3c059563935c17b84703187aDouglas Gregor bool hasUnsignedIntegerRepresentation() const; 1341f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 13428eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor /// \brief Determine whether this type has a floating-point representation 13438eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor /// of some sort, e.g., it is a floating-point type or a vector thereof. 13448eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor bool hasFloatingRepresentation() const; 1345f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 1346c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 1347f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 1348f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 1349769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const RecordType *getAsStructureType() const; 1350898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 1351c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 13524cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 135314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // The following is a convenience method that returns an ObjCObjectPointerType 135414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for object declared using an interface. 135514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 135614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 1357759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian const ObjCObjectPointerType *getAsObjCQualifiedClassType() const; 1358c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *getAsObjCQualifiedInterfaceType() const; 1359a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 13601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1361c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor /// \brief Retrieves the CXXRecordDecl that this type refers to, either 1362c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor /// because the type is a RecordType or because it is the injected-class-name 1363c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor /// type of a class template or class template partial specialization. 1364c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor CXXRecordDecl *getAsCXXRecordDecl() const; 136534b41d939a1328f484511c6002ba2456db879a29Richard Smith 136634b41d939a1328f484511c6002ba2456db879a29Richard Smith /// \brief Get the AutoType whose type will be deduced for a variable with 136734b41d939a1328f484511c6002ba2456db879a29Richard Smith /// an initializer of this type. This looks through declarators like pointer 136834b41d939a1328f484511c6002ba2456db879a29Richard Smith /// types, but not through decltype or typedefs. 136934b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *getContainedAutoType() const; 1370c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 1371d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// Member-template getAs<specific type>'. Look through sugar for 1372d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// an instance of <specific type>. This scheme will eventually 1373d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// replace the specific getAsXXXX methods above. 1374d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// 1375d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// There are some specializations of this member template listed 1376d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// immediately following this class. 13771a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek template <typename T> const T *getAs() const; 13781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// A variant of getAs<> for array types which silently discards 13803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// qualifiers from the outermost type. 13813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ArrayType *getAsArrayTypeUnsafe() const; 13823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 1383d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// Member-template castAs<specific type>. Look through sugar for 1384d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// the underlying instance of <specific type>. 1385d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// 1386d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// This method has the same relationship to getAs<T> as cast<T> has 1387d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// to dyn_cast<T>; which is to say, the underlying type *must* 1388d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// have the intended type, and this method will never return null. 1389d0370f59e79702ac908c81bf556519f91e9ca297John McCall template <typename T> const T *castAs() const; 1390d0370f59e79702ac908c81bf556519f91e9ca297John McCall 1391d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// A variant of castAs<> for array type which silently discards 1392d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// qualifiers from the outermost type. 1393d0370f59e79702ac908c81bf556519f91e9ca297John McCall const ArrayType *castAsArrayTypeUnsafe() const; 1394d0370f59e79702ac908c81bf556519f91e9ca297John McCall 1395d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// getBaseElementTypeUnsafe - Get the base element type of this 1396d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// type, potentially discarding type qualifiers. This method 1397d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// should never be used when type qualifiers are meaningful. 1398d0370f59e79702ac908c81bf556519f91e9ca297John McCall const Type *getBaseElementTypeUnsafe() const; 1399d0370f59e79702ac908c81bf556519f91e9ca297John McCall 1400c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 1401c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// element type of the array, potentially with type qualifiers missing. 1402c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// This method should never be used when type qualifiers are meaningful. 1403c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 14041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1405f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// getPointeeType - If this is a pointer, ObjC object pointer, or block 1406f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// pointer, this returns the respective pointee. 140714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const; 14081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1409bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// getUnqualifiedDesugaredType() - Return the specified type with 1410bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// any "sugar" removed from the type, removing any typedefs, 1411bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// typeofs, etc., as well as any qualifiers. 1412bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *getUnqualifiedDesugaredType() const; 14131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 14155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 14165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 1418d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 1419d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 1420d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// integer element type. 14215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 14225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 1424d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 1425d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 1426d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// element type. 14275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 1428d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 14295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 14309bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 14319bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 14323c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 1433c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 143422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 143522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// set of type specifiers. 143622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman bool isSpecifierType() const; 143722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 14380b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor /// \brief Determine the linkage of this type. 143960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor Linkage getLinkage() const; 14401fb0caaa7bef765b85972274e3b434af2572c141John McCall 14411fb0caaa7bef765b85972274e3b434af2572c141John McCall /// \brief Determine the visibility of this type. 14421fb0caaa7bef765b85972274e3b434af2572c141John McCall Visibility getVisibility() const; 14431fb0caaa7bef765b85972274e3b434af2572c141John McCall 14441fb0caaa7bef765b85972274e3b434af2572c141John McCall /// \brief Determine the linkage and visibility of this type. 14451fb0caaa7bef765b85972274e3b434af2572c141John McCall std::pair<Linkage,Visibility> getLinkageAndVisibility() const; 144660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 144760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor /// \brief Note that the linkage is no longer known. 144860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor void ClearLinkageCache(); 144960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 145060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor const char *getTypeClassName() const; 14510b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1452ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall QualType getCanonicalTypeInternal() const { 1453ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall return CanonicalType; 1454ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall } 1455ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h 1456c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 14575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 1458be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis 1459c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl friend class ASTReader; 1460a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl friend class ASTWriter; 14615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1463183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const { 1464183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall return dyn_cast<TypedefType>(this); 1465183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall} 1466183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 1467183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to 1468183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration. 1469183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base) 1470183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \ 1471183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \ 14720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return dyn_cast<Class##Type>(CanonicalType); \ 1473d0370f59e79702ac908c81bf556519f91e9ca297John McCall} \ 1474d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <> inline const Class##Type *Type::castAs() const { \ 1475d0370f59e79702ac908c81bf556519f91e9ca297John McCall return cast<Class##Type>(CanonicalType); \ 1476183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall} 1477183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def" 1478183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 1479183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 14805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 14815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 14825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 14855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Void, 14861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Bool, // This is bool and/or _Bool. 14885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_U, // This is 'char' for targets where char is unsigned. 14895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UChar, // This is explicitly qualified unsigned char. 14903f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner WChar_U, // This is 'wchar_t' for C++, when unsigned. 1491f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char16, // This is 'char16_t' for C++. 1492f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char32, // This is 'char32_t' for C++. 14935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UShort, 14945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UInt, 14955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULong, 14965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULongLong, 14972df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner UInt128, // __uint128_t 14981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_S, // This is 'char' for targets where char is signed. 15005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SChar, // This is explicitly qualified signed char. 15013f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner WChar_S, // This is 'wchar_t' for C++, when signed. 15025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Short, 15035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Int, 15045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Long, 15055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongLong, 15062df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner Int128, // __int128_t 15071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15088e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor Float, Double, LongDouble, 15098e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 15106e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 15116e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 1512864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// The primitive Objective C 'id' type. The user-visible 'id' 1513864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// type is a typedef of an ObjCObjectPointerType to an 1514864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// ObjCObjectType with this as its base. In fact, this only ever 1515864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// shows up in an AST as the base type of an ObjCObjectType. 1516864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall ObjCId, 1517864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 1518864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// The primitive Objective C 'Class' type. The user-visible 1519864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// 'Class' type is a typedef of an ObjCObjectPointerType to an 1520864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// ObjCObjectType with this as its base. In fact, this only ever 1521864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// shows up in an AST as the base type of an ObjCObjectType. 1522864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall ObjCClass, 1523864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 1524864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// The primitive Objective C 'SEL' type. The user-visible 'SEL' 1525864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// type is a typedef of a PointerType to this. 1526864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall ObjCSel, 1527864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 15282a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// This represents the type of an expression whose type is 15292a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// totally unknown, e.g. 'T::foo'. It is permitted for this to 15302a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// appear in situations where the structure of the type is 15312a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// theoretically deducible. 15322a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Dependent, 15332a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 1534864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// The type of an unresolved overload set. A placeholder type. 1535864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// Expressions with this type have one of the following basic 1536864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// forms, with parentheses generally permitted: 1537864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// foo # possibly qualified, not if an implicit access 1538864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// foo # possibly qualified, not if an implicit access 1539864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// &foo # possibly qualified, not if an implicit access 1540864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// x->foo # only if might be a static member function 1541864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// &x->foo # only if might be a static member function 1542864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// &Class::foo # when a pointer-to-member; sub-expr also has this type 1543864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// OverloadExpr::find can be used to analyze the expression. 15441de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall Overload, 15451de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall 1546864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// The type of a bound C++ non-static member function. 1547864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// A placeholder type. Expressions with this type have one of the 1548864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// following basic forms: 1549864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// foo # if an implicit access 1550864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// x->foo # if only contains non-static members 1551864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall BoundMember, 1552864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 1553864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// __builtin_any_type. A placeholder type. Useful for clients 1554864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// like debuggers that don't know what type to give something. 1555864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// Only a small number of operations are valid on expressions of 1556864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// unknown type, most notably explicit casts. 1557864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall UnknownAny 15585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 155971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 15605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BuiltinType(Kind K) 156235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent), 1563d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 1564d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*Unexpanded paramter pack=*/false) { 1565b870b88df784c2940efce448ebfaf54dece14666John McCall BuiltinTypeBits.Kind = K; 156671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 15671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1568b870b88df784c2940efce448ebfaf54dece14666John McCall Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); } 1569e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const char *getName(const LangOptions &LO) const; 15701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1571bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1572bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1573bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1574680523a91dd3351389667c8de17121ba7ae82673John McCall bool isInteger() const { 157571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Bool && getKind() <= Int128; 1576680523a91dd3351389667c8de17121ba7ae82673John McCall } 1577680523a91dd3351389667c8de17121ba7ae82673John McCall 1578680523a91dd3351389667c8de17121ba7ae82673John McCall bool isSignedInteger() const { 157971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Char_S && getKind() <= Int128; 1580680523a91dd3351389667c8de17121ba7ae82673John McCall } 1581680523a91dd3351389667c8de17121ba7ae82673John McCall 1582680523a91dd3351389667c8de17121ba7ae82673John McCall bool isUnsignedInteger() const { 158371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Bool && getKind() <= UInt128; 1584680523a91dd3351389667c8de17121ba7ae82673John McCall } 1585680523a91dd3351389667c8de17121ba7ae82673John McCall 1586680523a91dd3351389667c8de17121ba7ae82673John McCall bool isFloatingPoint() const { 158771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Float && getKind() <= LongDouble; 1588680523a91dd3351389667c8de17121ba7ae82673John McCall } 1589680523a91dd3351389667c8de17121ba7ae82673John McCall 1590864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// Determines whether this type is a placeholder type, i.e. a type 1591864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// which cannot appear in arbitrary positions in a fully-formed 1592864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// expression. 15932a984cad5ac3fdceeff2bd99daa7b90979313475John McCall bool isPlaceholderType() const { 1594864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return getKind() >= Overload; 15952a984cad5ac3fdceeff2bd99daa7b90979313475John McCall } 15962a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 15975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 15985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 15995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 16025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 16035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 16045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 16055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 16065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 160735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(Complex, CanonicalPtr, Element->isDependentType(), 1608d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Element->isVariablyModifiedType(), 1609d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Element->containsUnexpandedParameterPack()), 1610898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(Element) { 16115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 161360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 16145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 16155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 16161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1617bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1618bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1619bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 16205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 16215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 16225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 16245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 16255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 16285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 16295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1631075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// ParenType - Sugar for parentheses used when specifying types. 1632075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// 1633075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenType : public Type, public llvm::FoldingSetNode { 1634075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Inner; 1635075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1636075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenType(QualType InnerType, QualType CanonType) : 1637075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Type(Paren, CanonType, InnerType->isDependentType(), 1638d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor InnerType->isVariablyModifiedType(), 1639d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor InnerType->containsUnexpandedParameterPack()), 1640075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner(InnerType) { 1641075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1642075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara friend class ASTContext; // ASTContext creates these. 1643075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1644075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic: 1645075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1646075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType getInnerType() const { return Inner; } 1647075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1648075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara bool isSugared() const { return true; } 1649075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType desugar() const { return getInnerType(); } 1650075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1651075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara void Profile(llvm::FoldingSetNodeID &ID) { 1652075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Profile(ID, getInnerType()); 1653075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1654075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) { 1655075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner.Profile(ID); 1656075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1657075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1658075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static bool classof(const Type *T) { return T->getTypeClass() == Paren; } 1659075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static bool classof(const ParenType *) { return true; } 1660075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}; 1661075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 166268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 1663bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// 166468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 1665bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType PointeeType; 16665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 166835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(Pointer, CanonicalPtr, Pointee->isDependentType(), 1669d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->isVariablyModifiedType(), 1670d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->containsUnexpandedParameterPack()), 167135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor PointeeType(Pointee) { 16725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 167460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 16755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 16761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 167768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 167868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 1679bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1680bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1681bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 16825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 16835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 16845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 16865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 16875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 16905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 16915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16935618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type. 16945618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as 16955618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 16965618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// 16975618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 16985618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 16995618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 170035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(BlockPointer, CanonicalCls, Pointee->isDependentType(), 1701d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->isVariablyModifiedType(), 1702d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->containsUnexpandedParameterPack()), 1703898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor PointeeType(Pointee) { 17045618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 17055618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff friend class ASTContext; // ASTContext creates these. 170660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 17075618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic: 17081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17095618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 17105618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType getPointeeType() const { return PointeeType; } 17115618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 1712bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1713bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1714bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 17155618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 17165618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Profile(ID, getPointeeType()); 17175618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 17185618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 17195618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 17205618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 17211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 17231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == BlockPointer; 17245618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 17255618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 17265618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}; 17275618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 17287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 17295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 173068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 173168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType PointeeType; 173268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 17337c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected: 173454e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, 173554e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) : 173635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(tc, CanonicalRef, Referencee->isDependentType(), 1737d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Referencee->isVariablyModifiedType(), 1738d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Referencee->containsUnexpandedParameterPack()), 1739d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor PointeeType(Referencee) 1740d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor { 1741b870b88df784c2940efce448ebfaf54dece14666John McCall ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue; 1742b870b88df784c2940efce448ebfaf54dece14666John McCall ReferenceTypeBits.InnerRef = Referencee->isReferenceType(); 17435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 174460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 17455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1746b870b88df784c2940efce448ebfaf54dece14666John McCall bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; } 1747b870b88df784c2940efce448ebfaf54dece14666John McCall bool isInnerRef() const { return ReferenceTypeBits.InnerRef; } 174873dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor 174954e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType getPointeeTypeAsWritten() const { return PointeeType; } 175054e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType getPointeeType() const { 175154e14c4db764c0636160d26c5bbf491637c83a76John McCall // FIXME: this might strip inner qualifiers; okay? 175254e14c4db764c0636160d26c5bbf491637c83a76John McCall const ReferenceType *T = this; 175371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall while (T->isInnerRef()) 1754d0370f59e79702ac908c81bf556519f91e9ca297John McCall T = T->PointeeType->castAs<ReferenceType>(); 175554e14c4db764c0636160d26c5bbf491637c83a76John McCall return T->PointeeType; 175654e14c4db764c0636160d26c5bbf491637c83a76John McCall } 175768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 17585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 175971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall Profile(ID, PointeeType, isSpelledAsLValue()); 17605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 176154e14c4db764c0636160d26c5bbf491637c83a76John McCall static void Profile(llvm::FoldingSetNodeID &ID, 176254e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType Referencee, 176354e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) { 17645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 176554e14c4db764c0636160d26c5bbf491637c83a76John McCall ID.AddBoolean(SpelledAsLValue); 17665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17687c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 17697c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference || 17707c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl T->getTypeClass() == RValueReference; 17717c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 17725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 17737c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 17747c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 17757c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 17767c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 17777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType { 177854e14c4db764c0636160d26c5bbf491637c83a76John McCall LValueReferenceType(QualType Referencee, QualType CanonicalRef, 177954e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) : 178054e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue) 178154e14c4db764c0636160d26c5bbf491637c83a76John McCall {} 17827c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 17837c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 1784bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1785bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1786bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 17877c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 17887c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference; 17897c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 17907c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 17917c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 17927c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 17937c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 17947c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 17957c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType { 17967c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 179754e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(RValueReference, Referencee, CanonicalRef, false) { 17987c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 17997c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 18007c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 1801bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1802bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1803bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 18047c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 18057c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == RValueReference; 18067c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 18077c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 1808f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}; 1809f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1810f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 1811f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// 1812f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 1813f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType PointeeType; 1814f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 1815f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 1816f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class; 1817f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1818f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 1819f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Type(MemberPointer, CanonicalPtr, 182035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Cls->isDependentType() || Pointee->isDependentType(), 1821d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->isVariablyModifiedType(), 1822d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (Cls->containsUnexpandedParameterPack() || 1823d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->containsUnexpandedParameterPack())), 1824f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointeeType(Pointee), Class(Cls) { 1825f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1826f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl friend class ASTContext; // ASTContext creates these. 182760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 1828f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic: 1829f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType getPointeeType() const { return PointeeType; } 1830f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 18310bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Returns true if the member type (i.e. the pointee type) is a 18320bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// function type rather than a data-member type. 18330bab0cdab751248ca389a5592bcb70eac5d39260John McCall bool isMemberFunctionPointer() const { 18340bab0cdab751248ca389a5592bcb70eac5d39260John McCall return PointeeType->isFunctionProtoType(); 18350bab0cdab751248ca389a5592bcb70eac5d39260John McCall } 18360bab0cdab751248ca389a5592bcb70eac5d39260John McCall 18370bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Returns true if the member type (i.e. the pointee type) is a 18380bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// data type rather than a function type. 18390bab0cdab751248ca389a5592bcb70eac5d39260John McCall bool isMemberDataPointer() const { 18400bab0cdab751248ca389a5592bcb70eac5d39260John McCall return !PointeeType->isFunctionProtoType(); 18410bab0cdab751248ca389a5592bcb70eac5d39260John McCall } 18420bab0cdab751248ca389a5592bcb70eac5d39260John McCall 1843f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *getClass() const { return Class; } 1844f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1845bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1846bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1847bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1848f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 1849f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Profile(ID, getPointeeType(), getClass()); 1850f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1851f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 1852f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class) { 1853f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 1854f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Class); 1855f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1856f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1857f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const Type *T) { 1858f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getTypeClass() == MemberPointer; 1859f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1860f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const MemberPointerType *) { return true; } 18615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 18645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 18652e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 18665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 1868898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 1869898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// with a star size (e.g. int X[*]). 1870898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// 'static' is only allowed on function parameters. 18715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 18725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 18735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 18745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 1875fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 1876fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 18771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1878fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 1879898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // C++ [temp.dep.type]p1: 1880898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // A type is dependent if it is... 1881898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // - an array type constructed from any dependent type or whose 1882898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // size is specified by a constant expression that is 1883898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // value-dependent, 1884c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 1885d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ArraySizeModifier sm, unsigned tq, 1886d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool ContainsUnexpandedParameterPack) 188735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray, 1888d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (tc == VariableArray || et->isVariablyModifiedType()), 1889d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ContainsUnexpandedParameterPack), 189071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ElementType(et) { 1891b870b88df784c2940efce448ebfaf54dece14666John McCall ArrayTypeBits.IndexTypeQuals = tq; 1892b870b88df784c2940efce448ebfaf54dece14666John McCall ArrayTypeBits.SizeModifier = sm; 189371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 1894898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1895fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 189660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 1897fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 1898fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 1899ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 1900b870b88df784c2940efce448ebfaf54dece14666John McCall return ArraySizeModifier(ArrayTypeBits.SizeModifier); 1901ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 19020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers getIndexTypeQualifiers() const { 190371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers()); 190471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 190571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall unsigned getIndexTypeCVRQualifiers() const { 1906b870b88df784c2940efce448ebfaf54dece14666John McCall return ArrayTypeBits.IndexTypeQuals; 19070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 19081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1909fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 1910fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 1911c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 1912898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == IncompleteArray || 1913898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == DependentSizedArray; 1914fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1915fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 1916fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 1917fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 19187e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of 19197e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size. For example, the canonical 19207e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 19217e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404. 19222e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 1923fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 19241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19250be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 1926c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 1927d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(ConstantArray, et, can, sm, tq, 1928d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor et->containsUnexpandedParameterPack()), 19297e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Size(size) {} 19307e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected: 19317e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayType(TypeClass tc, QualType et, QualType can, 19327e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 1933d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()), 1934d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Size(size) {} 1935fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 1936fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 1937c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const llvm::APInt &getSize() const { return Size; } 1938bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1939bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1940bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 19412767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 19422767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor /// \brief Determine the number of bits required to address a member of 19432767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // an array with the given element type and number of elements. 19442767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor static unsigned getNumAddressingBits(ASTContext &Context, 19452767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor QualType ElementType, 19462767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor const llvm::APInt &NumElements); 19472767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 19482767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor /// \brief Determine the maximum number of active bits that an array's size 19492767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor /// can require, which limits the maximum size of the array. 19502767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor static unsigned getMaxSizeBits(ASTContext &Context); 19512767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 1952fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 19531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, getElementType(), getSize(), 19540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers()); 1955fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1956fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 19570be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 19580be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner unsigned TypeQuals) { 1959fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 1960fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 19610be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 19620be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 1963fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 19647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 196546a617a792bfab0d9b1e057371ea3b9540802226John McCall return T->getTypeClass() == ConstantArray; 1966fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1967fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 1968fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 1969fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 1970da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 1971da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 1972da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified. 1973c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 19747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1975c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 19767e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq) 1977d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(IncompleteArray, et, can, sm, tq, 1978d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor et->containsUnexpandedParameterPack()) {} 1979c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 1980c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 1981bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1982bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1983bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 19841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 19851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == IncompleteArray; 1986c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 1987c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 19881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1989c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 19901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1991c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 19920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Profile(ID, getElementType(), getSizeModifier(), 19930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getIndexTypeCVRQualifiers()); 1994c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 19951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19960be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 19970be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 1998c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 19990be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 20000be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 2001c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 2002c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 2003c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2004da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 2005da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 2006da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 2007da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 2008da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 2009da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean 2010da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type 2011da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically: 2012da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 2013da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) { 2014da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Y[x]; 2015da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ++x; 2016da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Z[x]; 2017da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// } 2018da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 20192e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 20201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// SizeExpr - An assignment expression. VLA's are only permitted within 20211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// a function block. 2022b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek Stmt *SizeExpr; 20237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 20247e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 20257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 2026c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 20277e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 20287e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 2029d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(VariableArray, et, can, sm, tq, 2030d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor et->containsUnexpandedParameterPack()), 20317e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 20325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 20334b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 20345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 20351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getSizeExpr() const { 2036b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // We use C-style casts instead of cast<> here because we do not wish 2037b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 2038b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek return (Expr*) SizeExpr; 2039b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek } 20407e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 20417e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 20427e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 20431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2044bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2045bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2046bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 20471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 20481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == VariableArray; 20495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2050fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 20511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 205292866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 20531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20542bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 2055fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner assert(0 && "Cannot unique VariableArrayTypes."); 20562bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 20575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 20585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2059898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in 2060898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example: 2061cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// 2062cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code 20631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size> 2064898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array { 2065898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// T data[Size]; 2066898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// }; 2067cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode 2068cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// 2069898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is 2070898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will 2071898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 2072898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType { 20734ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 20741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2075cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// \brief An assignment expression that will instantiate to the 2076898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// size of the array. 2077cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// 2078cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// The expression itself might be NULL, in which case the array 2079cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// type will have its size deduced from an initializer. 2080898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Stmt *SizeExpr; 2081cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor 20827e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 20837e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 20841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20854ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can, 208604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *e, ArraySizeModifier sm, unsigned tq, 2087d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceRange brackets); 2088d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2089898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class ASTContext; // ASTContext creates these. 2090898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2091898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic: 20921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getSizeExpr() const { 2093898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // We use C-style casts instead of cast<> here because we do not wish 2094898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 2095898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return (Expr*) SizeExpr; 2096898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 20977e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 20987e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 20997e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 21001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2101bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2102bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2103bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 21041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 21051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == DependentSizedArray; 2106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 2107898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 21081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class StmtIteratorBase; 21101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 21131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, Context, getElementType(), 21140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); 2115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 21161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21174ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 21181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType ET, ArraySizeModifier SizeMod, 211904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, Expr *E); 2120898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}; 2121898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2122f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 21239cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example: 21249cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code 21259cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size> 21269cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector { 21279cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 21289cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// } 21299cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode 21302ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { 21314ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 21329cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr; 21339cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor /// ElementType - The element type of the array. 21349cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType ElementType; 21359cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation loc; 21361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21374ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType, 2138d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType can, Expr *SizeExpr, SourceLocation loc); 2139d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 21409cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor friend class ASTContext; 21419cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 21429cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic: 21432ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 21449cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType getElementType() const { return ElementType; } 21459cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation getAttributeLoc() const { return loc; } 21469cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 2147bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2148bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2149bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 21501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 21511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == DependentSizedExtVector; 21529cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor } 21531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const DependentSizedExtVectorType *) { return true; } 21542ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 21552ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 21562ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor Profile(ID, Context, getElementType(), getSizeExpr()); 21572ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 21581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21594ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 21602ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr); 21619cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor}; 21621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21639cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 216473322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 21651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in 216682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration. 216782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the 216873322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 21695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 2170788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattnerpublic: 2171e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson enum VectorKind { 2172e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson GenericVector, // not a target-specific vector type 2173e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson AltiVecVector, // is AltiVec vector 2174e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson AltiVecPixel, // is AltiVec 'vector Pixel' 2175e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson AltiVecBool, // is AltiVec 'vector bool ...' 2176491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson NeonVector, // is ARM Neon vector 2177491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson NeonPolyVector // is ARM Neon polynomial vector 2178788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner }; 217973322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 21805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 21815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 21821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 218382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson VectorType(QualType vecType, unsigned nElements, QualType canonType, 2184d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorKind vecKind); 218535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 21861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump VectorType(TypeClass tc, QualType vecType, unsigned nElements, 2187d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType canonType, VectorKind vecKind); 2188d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 21895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 219060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 21915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 21921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 2194b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getNumElements() const { return VectorTypeBits.NumElements; } 21955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2196bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2197bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2198bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2199e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorKind getVectorKind() const { 2200e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson return VectorKind(VectorTypeBits.VecKind); 220171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2202788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner 22035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 220471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall Profile(ID, getElementType(), getNumElements(), 2205e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson getTypeClass(), getVectorKind()); 22065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 220882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson unsigned NumElements, TypeClass TypeClass, 2209e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorKind VecKind) { 22105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 22115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 221273322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 2213e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson ID.AddInteger(VecKind); 221473322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 22150b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 22161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 22171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 22185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 22205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 22215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2222213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using 2223213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 2224213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 2225fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 2226fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 2227213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType { 2228213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 2229e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {} 223073322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 223173322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 223288dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 223388dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 223488dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 223588dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 223688dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 223788dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 223888dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 223988dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 2240e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 2241353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman static int getNumericAccessorIdx(char c) { 224288dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 2243353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman default: return -1; 2244353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '0': return 0; 2245353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '1': return 1; 2246353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '2': return 2; 2247353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '3': return 3; 2248353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '4': return 4; 2249353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '5': return 5; 2250353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '6': return 6; 2251353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '7': return 7; 2252353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '8': return 8; 2253353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '9': return 9; 2254131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'A': 2255353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'a': return 10; 2256131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'B': 2257353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'b': return 11; 2258131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'C': 2259353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'c': return 12; 2260131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'D': 2261353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'd': return 13; 2262131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'E': 2263353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'e': return 14; 2264131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'F': 2265353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'f': return 15; 226688dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 2267e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 22681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2269b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 2270b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 2271353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman return getNumericAccessorIdx(c); 2272b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 22731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 227488dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 2275b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 227671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return unsigned(idx-1) < getNumElements(); 227788dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 2278e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 2279bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2280bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2281bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 22821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 22831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ExtVector; 228473322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 2285213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman static bool classof(const ExtVectorType *) { return true; } 228673322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 228773322924127c873c13101b705dd823f5539ffa5fSteve Naroff 22885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 228972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 22905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 22915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 22925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 22935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 2294264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2295264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public: 2296373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// ExtInfo - A class which abstracts out some details necessary for 2297373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// making a call. 2298373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// 2299373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// It is not actually used directly for storing this information in 2300373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// a FunctionType, although FunctionType does currently use the 2301373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// same bit-pattern. 2302373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// 2303075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara // If you add a field (say Foo), other than the obvious places (both, 2304075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara // constructors, compile failures), what you need to update is 2305075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara // * Operator== 2306425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * getFoo 2307425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * withFoo 2308425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * functionType. Add Foo, getFoo. 2309425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * ASTContext::getFooType 2310425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * ASTContext::mergeFunctionTypes 2311425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * FunctionNoProtoType::Profile 2312425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * FunctionProtoType::Profile 2313425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * TypePrinter::PrintFunctionProto 23143c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl // * AST read and write 2315425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * Codegen 2316264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola class ExtInfo { 2317373920bd733b1d28fe7bf209945a62eb9248d948John McCall // Feel free to rearrange or add bits, but if you go over 8, 2318373920bd733b1d28fe7bf209945a62eb9248d948John McCall // you'll need to adjust both the Bits field below and 2319373920bd733b1d28fe7bf209945a62eb9248d948John McCall // Type::FunctionTypeBitfields. 2320373920bd733b1d28fe7bf209945a62eb9248d948John McCall 2321a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman // | CC |noreturn|hasregparm|regparm 2322a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman // |0 .. 2| 3 | 4 |5 .. 7 2323b870b88df784c2940efce448ebfaf54dece14666John McCall enum { CallConvMask = 0x7 }; 2324b870b88df784c2940efce448ebfaf54dece14666John McCall enum { NoReturnMask = 0x8 }; 2325a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman enum { HasRegParmMask = 0x10 }; 2326b870b88df784c2940efce448ebfaf54dece14666John McCall enum { RegParmMask = ~(CallConvMask | NoReturnMask), 2327a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman RegParmOffset = 5 }; 2328b870b88df784c2940efce448ebfaf54dece14666John McCall 2329373920bd733b1d28fe7bf209945a62eb9248d948John McCall unsigned char Bits; 233071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 2331373920bd733b1d28fe7bf209945a62eb9248d948John McCall ExtInfo(unsigned Bits) : Bits(static_cast<unsigned char>(Bits)) {} 233271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 233371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall friend class FunctionType; 233471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 2335264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public: 2336264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Constructor with no defaults. Use this when you know that you 23373c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl // have all the elements (when reading an AST file for example). 2338a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc) { 2339b870b88df784c2940efce448ebfaf54dece14666John McCall Bits = ((unsigned) cc) | 2340b870b88df784c2940efce448ebfaf54dece14666John McCall (noReturn ? NoReturnMask : 0) | 2341a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman (hasRegParm ? HasRegParmMask : 0) | 2342b870b88df784c2940efce448ebfaf54dece14666John McCall (regParm << RegParmOffset); 234371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2344264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2345264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Constructor with all defaults. Use when for example creating a 2346264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // function know to use defaults. 234771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ExtInfo() : Bits(0) {} 2348264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2349b870b88df784c2940efce448ebfaf54dece14666John McCall bool getNoReturn() const { return Bits & NoReturnMask; } 2350a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman bool getHasRegParm() const { return Bits & HasRegParmMask; } 2351b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getRegParm() const { return Bits >> RegParmOffset; } 2352b870b88df784c2940efce448ebfaf54dece14666John McCall CallingConv getCC() const { return CallingConv(Bits & CallConvMask); } 2353264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 235471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall bool operator==(ExtInfo Other) const { 235571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return Bits == Other.Bits; 2356264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 235771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall bool operator!=(ExtInfo Other) const { 235871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return Bits != Other.Bits; 2359264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 2360264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2361264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Note that we don't have setters. That is by design, use 2362264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // the following with methods instead of mutating these objects. 2363264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2364264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ExtInfo withNoReturn(bool noReturn) const { 236571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall if (noReturn) 236671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return ExtInfo(Bits | NoReturnMask); 236771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall else 236871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return ExtInfo(Bits & ~NoReturnMask); 2369425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola } 2370425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola 2371425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola ExtInfo withRegParm(unsigned RegParm) const { 2372a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman return ExtInfo(HasRegParmMask | (Bits & ~RegParmMask) | (RegParm << RegParmOffset)); 2373264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 2374264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2375264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ExtInfo withCallingConv(CallingConv cc) const { 2376b870b88df784c2940efce448ebfaf54dece14666John McCall return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc); 2377264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 2378264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2379e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall void Profile(llvm::FoldingSetNodeID &ID) const { 238071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ID.AddInteger(Bits); 238171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2382264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola }; 2383264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 23845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 2385e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionType(TypeClass tc, QualType res, bool variadic, 2386c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor unsigned typeQuals, RefQualifierKind RefQualifier, 2387c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor QualType Canonical, bool Dependent, 2388d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool VariablyModified, bool ContainsUnexpandedParameterPack, 2389d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ExtInfo Info) 2390d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(tc, Canonical, Dependent, VariablyModified, 2391d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ContainsUnexpandedParameterPack), 2392d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ResultType(res) { 2393b870b88df784c2940efce448ebfaf54dece14666John McCall FunctionTypeBits.ExtInfo = Info.Bits; 2394e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionTypeBits.Variadic = variadic; 2395b870b88df784c2940efce448ebfaf54dece14666John McCall FunctionTypeBits.TypeQuals = typeQuals; 2396c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor FunctionTypeBits.RefQualifier = static_cast<unsigned>(RefQualifier); 239771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2398e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall bool isVariadic() const { return FunctionTypeBits.Variadic; } 2399b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; } 2400c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 2401c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind getRefQualifier() const { 2402c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier); 2403c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor } 2404c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 24055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 24061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 2408a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman 2409a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman bool getHasRegParm() const { return getExtInfo().getHasRegParm(); } 2410b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getRegParmType() const { return getExtInfo().getRegParm(); } 2411b870b88df784c2940efce448ebfaf54dece14666John McCall bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); } 2412b870b88df784c2940efce448ebfaf54dece14666John McCall CallingConv getCallConv() const { return getExtInfo().getCC(); } 2413b870b88df784c2940efce448ebfaf54dece14666John McCall ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); } 24145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24155291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// \brief Determine the type of an expression that calls a function of 24165291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// this type. 24175291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor QualType getCallResultType(ASTContext &Context) const { 24186398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor return getResultType().getNonLValueExprType(Context); 24195291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor } 24205291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 242104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall static llvm::StringRef getNameForCallConv(CallingConv CC); 242204a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 24235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 24245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 24255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 24265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 24285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 243072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 24315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 243272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 243371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info) 2434c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor : FunctionType(FunctionNoProto, Result, false, 0, RQ_None, Canonical, 243535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor /*Dependent=*/false, Result->isVariablyModifiedType(), 2436d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false, Info) {} 2437d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 24385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 243960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 24405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 24415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 24421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2443bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2444bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2445bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 24465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 2447264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Profile(ID, getResultType(), getExtInfo()); 24485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24492455636163fdd18581d7fdae816433f886d88213Mike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 245071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ExtInfo Info) { 245171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall Info.Profile(ID); 24525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 24535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 24565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 24575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 245872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 24595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 246172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 24625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 2463465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 2464465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical 2465465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type. 246672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 2467e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallpublic: 2468e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall /// ExtProtoInfo - Extra information about a function prototype. 2469e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall struct ExtProtoInfo { 2470e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ExtProtoInfo() : 24718b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl Variadic(false), ExceptionSpecType(EST_None), TypeQuals(0), 24728b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl RefQualifier(RQ_None), NumExceptions(0), Exceptions(0), NoexceptExpr(0) {} 2473e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 2474e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionType::ExtInfo ExtInfo; 2475e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall bool Variadic; 24768b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl ExceptionSpecificationType ExceptionSpecType; 2477e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned char TypeQuals; 2478c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier; 2479e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned NumExceptions; 2480e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall const QualType *Exceptions; 24818b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl Expr *NoexceptExpr; 2482e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall }; 2483e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 2484e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallprivate: 2485d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Determine whether there are any argument types that 2486d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// contain an unexpanded parameter pack. 2487d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray, 2488d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned numArgs) { 2489d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 2490d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor if (ArgArray[Idx]->containsUnexpandedParameterPack()) 2491d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return true; 2492d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2493d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return false; 2494d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 2495d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2496e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType(QualType result, const QualType *args, unsigned numArgs, 24978026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl QualType canonical, const ExtProtoInfo &epi); 2498465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 24995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 2500465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumArgs : 20; 2501465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2502465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 250360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl unsigned NumExceptions : 9; 2504465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 250560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// ExceptionSpecType - The type of exception specification this function has. 250660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl unsigned ExceptionSpecType : 3; 2507465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2508942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 2509942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// holds the argument types. 2510465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2511465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 2512465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// holds the exception types. 2513465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 251460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// NoexceptExpr - Instead of Exceptions, there may be a single Expr* pointing 251560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// to the expression in the noexcept() specifier. 251660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 25175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 25184b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 25195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 25205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 25215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 25225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 2523942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 25245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2525465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2526e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ExtProtoInfo getExtProtoInfo() const { 2527e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ExtProtoInfo EPI; 2528e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.ExtInfo = getExtInfo(); 2529e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.Variadic = isVariadic(); 253060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.ExceptionSpecType = getExceptionSpecType(); 2531e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals()); 2532c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor EPI.RefQualifier = getRefQualifier(); 253360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (EPI.ExceptionSpecType == EST_Dynamic) { 253460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.NumExceptions = NumExceptions; 253560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.Exceptions = exception_begin(); 253660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) { 253760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.NoexceptExpr = getNoexceptExpr(); 253860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 2539e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall return EPI; 2540e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall } 2541e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 254260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Get the kind of exception specification on this function. 254360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecificationType getExceptionSpecType() const { 254460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return static_cast<ExceptionSpecificationType>(ExceptionSpecType); 254560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 254660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Return whether this function has any kind of exception spec. 254760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool hasExceptionSpec() const { 254860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return getExceptionSpecType() != EST_None; 254960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 255060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Return whether this function has a dynamic (throw) exception spec. 255160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool hasDynamicExceptionSpec() const { 255260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return isDynamicExceptionSpec(getExceptionSpecType()); 255360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 2554fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// \brief Return whether this function has a noexcept exception spec. 255560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool hasNoexceptExceptionSpec() const { 255660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return isNoexceptExceptionSpec(getExceptionSpecType()); 255760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 255860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Result type of getNoexceptSpec(). 255960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl enum NoexceptResult { 256060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_NoNoexcept, ///< There is no noexcept specifier. 256160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_BadNoexcept, ///< The noexcept specifier has a bad expression. 256260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_Dependent, ///< The noexcept specifier is dependent. 256360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_Throw, ///< The noexcept specifier evaluates to false. 256460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_Nothrow ///< The noexcept specifier evaluates to true. 256560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl }; 256660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Get the meaning of the noexcept spec on this function, if any. 25678026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl NoexceptResult getNoexceptSpec(ASTContext &Ctx) const; 2568465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 2569465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType getExceptionType(unsigned i) const { 2570465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 2571465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin()[i]; 2572465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 257360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Expr *getNoexceptExpr() const { 257460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (getExceptionSpecType() != EST_ComputedNoexcept) 257560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return 0; 257660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // NoexceptExpr sits where the arguments end. 257760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return *reinterpret_cast<Expr *const *>(arg_type_end()); 2578d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson } 25798026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl bool isNothrow(ASTContext &Ctx) const { 258060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecificationType EST = getExceptionSpecType(); 258160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (EST == EST_DynamicNone || EST == EST_BasicNoexcept) 258260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return true; 258360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (EST != EST_ComputedNoexcept) 258460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return false; 25858026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl return getNoexceptSpec(Ctx) == NR_Nothrow; 2586c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall } 2587c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall 2588e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall using FunctionType::isVariadic; 258960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 2590f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// \brief Determines whether this function prototype contains a 2591f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// parameter pack at the end. 2592f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// 2593f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// A function template whose last parameter is a parameter pack can be 2594f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// called with an arbitrary number of arguments, much like a variadic 2595f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// function. However, 2596f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor bool isTemplateVariadic() const; 2597f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor 2598971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 25991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2600c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 2601c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief Retrieve the ref-qualifier associated with this function type. 2602c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind getRefQualifier() const { 2603c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor return FunctionType::getRefQualifier(); 2604c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor } 2605c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 26065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 2607942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 2608942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 2609942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 2610942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 2611465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2612465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl typedef const QualType *exception_iterator; 2613465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_begin() const { 2614465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // exceptions begin where arguments end 2615465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return arg_type_end(); 2616465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 2617465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_end() const { 261860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (getExceptionSpecType() != EST_Dynamic) 261960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return exception_begin(); 2620465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin() + NumExceptions; 2621465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 2622465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2623bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2624bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2625bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 26265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 26275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 26285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 262972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 2630465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 26318026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx); 26325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 2633942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 26348026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ExtProtoInfo &EPI, const ASTContext &Context); 26355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 26365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2638ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped 2639ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g. 2640ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// using typename Base<T>::foo; 2641ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type. 2642ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type { 2643ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *Decl; 2644ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 264519c8576b7328f4dc2d07682f5da552875c1912efJohn McCall UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) 2646d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(UnresolvedUsing, QualType(), true, false, 2647d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 264819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {} 2649ed97649e9574b9d854fa4d6109c9333ae0993554John McCall friend class ASTContext; // ASTContext creates these. 2650ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic: 2651ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2652ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *getDecl() const { return Decl; } 2653ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2654ed97649e9574b9d854fa4d6109c9333ae0993554John McCall bool isSugared() const { return false; } 2655ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType desugar() const { return QualType(this, 0); } 2656ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2657ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static bool classof(const Type *T) { 2658ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return T->getTypeClass() == UnresolvedUsing; 2659ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2660ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static bool classof(const UnresolvedUsingType *) { return true; } 2661ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2662ed97649e9574b9d854fa4d6109c9333ae0993554John McCall void Profile(llvm::FoldingSetNodeID &ID) { 2663ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Profile(ID, Decl); 2664ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2665ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static void Profile(llvm::FoldingSetNodeID &ID, 2666ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *D) { 2667ed97649e9574b9d854fa4d6109c9333ae0993554John McCall ID.AddPointer(D); 2668ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2669ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}; 2670ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2671ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 26725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 2673162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *Decl; 2674c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 2675162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can) 2676d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(tc, can, can->isDependentType(), can->isVariablyModifiedType(), 2677d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 2678162e1c1b487352434552147967c3dd296ebee2f7Richard Smith Decl(const_cast<TypedefNameDecl*>(D)) { 26795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 26805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 26825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 26831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2684162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *getDecl() const { return Decl; } 26851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2686bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2687bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const; 2688bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 268972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 26905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 26915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 26925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 269372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension). 269472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type { 2695d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 26961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2697b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected: 2698dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor TypeOfExprType(Expr *E, QualType can = QualType()); 2699d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 2700d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 2701d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 27021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2703bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2704bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const; 2705bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2706bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2707bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2708bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 270972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 271072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 2711d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 2712d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 2713c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent 27141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types. 2715c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// 2716c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage 2717c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances 2718c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via TypeOfExprType nodes. 27191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType 2720b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor : public TypeOfExprType, public llvm::FoldingSetNode { 27214ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 27221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2723b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic: 27244ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentTypeOfExprType(const ASTContext &Context, Expr *E) 2725b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor : TypeOfExprType(E), Context(Context) { } 27261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2727bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2728bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2729bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2730b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2731b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Profile(ID, Context, getUnderlyingExpr()); 2732b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } 27331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27344ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 2735b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Expr *E); 2736b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor}; 27371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2738d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 2739d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 2740d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 27411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypeOfType(QualType T, QualType can) 2742d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(TypeOf, can, T->isDependentType(), T->isVariablyModifiedType(), 2743d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor T->containsUnexpandedParameterPack()), 274435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor TOType(T) { 2745d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 2746d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 2747d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 2748d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 2749d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 27501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2751bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2752bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getUnderlyingType(); } 2753bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2754bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2755bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2756bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 275772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 2758d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 2759d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 27605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2761395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x) 2762395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type { 2763395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *E; 27641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2765563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 2766563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 2767563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // from it. 2768563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType UnderlyingType; 27691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27709d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected: 2771563a03b1338d31c2462def43253a722bc885d384Anders Carlsson DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 2772395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson friend class ASTContext; // ASTContext creates these. 2773395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic: 2774395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *getUnderlyingExpr() const { return E; } 2775563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType getUnderlyingType() const { return UnderlyingType; } 2776563a03b1338d31c2462def43253a722bc885d384Anders Carlsson 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 !isDependentType(); } 2782bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2783395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 2784395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const DecltypeType *) { return true; } 2785395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson}; 27861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2787c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent 2788c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// decltype(expr) types. 2789c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// 2790c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage 2791c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances 2792c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via DecltypeType nodes. 27939d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { 27944ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 27951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27969d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic: 27974ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentDecltypeType(const ASTContext &Context, Expr *E); 27981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2799bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2800bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2801bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 28029d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 28039d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor Profile(ID, Context, getUnderlyingExpr()); 28049d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } 28051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28064ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 28071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *E); 28089d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor}; 28091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 2811ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl /// Stores the TagDecl associated with this type. The decl may point to any 2812ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl /// TagDecl that declares the entity. 2813ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl TagDecl * decl; 28142ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 28152ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected: 281619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall TagType(TypeClass TC, const TagDecl *D, QualType can); 28172ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 28181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 2819ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl TagDecl *getDecl() const; 28201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28210b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// @brief Determines whether this type is in the process of being 28221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// defined. 2823ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl bool isBeingDefined() const; 28240b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 28251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 282672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 282772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor } 28285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 282972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const RecordType *) { return true; } 283072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const EnumType *) { return true; } 28315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 28325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 28335edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 28345edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes. 28355edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType { 283649aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected: 283719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall explicit RecordType(const RecordDecl *D) 283819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { } 283972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 284019c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { } 28412ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 28425edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 28431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28445edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordDecl *getDecl() const { 28455edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 28465edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 28471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: This predicate is a helper to QualType/Type. It needs to 28495edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // recursively check all fields for const-ness. If any field is declared 28501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // const, it needs to return false. 28515edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner bool hasConstFields() const { return false; } 28525edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 2853bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2854bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2855bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 28562daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 28572daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 28582daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 28592daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 28605edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const RecordType *) { return true; } 28615edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 28625edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 28635edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 28645edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums. 28655edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType { 286619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall explicit EnumType(const EnumDecl *D) 286719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { } 28682ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 28695edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 28701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28715edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumDecl *getDecl() const { 28725edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 28735edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 28741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2875bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2876bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2877bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 28782daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 28792daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 28802daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 28812daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 28825edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const EnumType *) { return true; } 28835edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 28845edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 28859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// AttributedType - An attributed type is a type to which a type 28869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// attribute has been applied. The "modified type" is the 28879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// fully-sugared type to which the attributed type was applied; 28889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// generally it is not canonically equivalent to the attributed type. 28899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// The "equivalent type" is the minimally-desugared type which the 28909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// type is canonically equivalent to. 28919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// 28929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// For example, in the following attributed type: 28939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// int32_t __attribute__((vector_size(16))) 28949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// - the modified type is the TypedefType for int32_t 28959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// - the equivalent type is VectorType(16, int32_t) 28969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// - the canonical type is VectorType(16, int) 28979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallclass AttributedType : public Type, public llvm::FoldingSetNode { 28989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic: 28999d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // It is really silly to have yet another attribute-kind enum, but 29009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // clang::attr::Kind doesn't currently cover the pure type attrs. 29019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall enum Kind { 29029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // Expression operand. 2903170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_address_space, 2904170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_regparm, 2905170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_vector_size, 2906170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_neon_vector_type, 2907170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_neon_polyvector_type, 29089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 2909170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet FirstExprOperandKind = attr_address_space, 2910170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet LastExprOperandKind = attr_neon_polyvector_type, 29119d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // Enumerated operand (string or keyword). 2913170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_objc_gc, 2914414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov attr_pcs, 29159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 2916170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet FirstEnumOperandKind = attr_objc_gc, 2917414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov LastEnumOperandKind = attr_pcs, 29189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // No operand. 29203cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_noreturn, 29213cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_cdecl, 29223cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_fastcall, 29233cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_stdcall, 29243cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_thiscall, 29253cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_pascal 29269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall }; 29279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallprivate: 29299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType ModifiedType; 29309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType EquivalentType; 29319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall friend class ASTContext; // creates these 29339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType(QualType canon, Kind attrKind, 29359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modified, QualType equivalent) 29369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall : Type(Attributed, canon, canon->isDependentType(), 29379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall canon->isVariablyModifiedType(), 29389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall canon->containsUnexpandedParameterPack()), 29399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ModifiedType(modified), EquivalentType(equivalent) { 29409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeBits.AttrKind = attrKind; 29419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 29429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic: 29449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Kind getAttrKind() const { 29459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return static_cast<Kind>(AttributedTypeBits.AttrKind); 29469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 29479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType getModifiedType() const { return ModifiedType; } 29499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType getEquivalentType() const { return EquivalentType; } 29509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall bool isSugared() const { return true; } 29529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType desugar() const { return getEquivalentType(); } 29539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall void Profile(llvm::FoldingSetNodeID &ID) { 29559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Profile(ID, getAttrKind(), ModifiedType, EquivalentType); 29569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 29579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind, 29599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modified, QualType equivalent) { 29609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ID.AddInteger(attrKind); 29619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ID.AddPointer(modified.getAsOpaquePtr()); 29629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ID.AddPointer(equivalent.getAsOpaquePtr()); 29639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 29649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 29659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall static bool classof(const Type *T) { 29669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return T->getTypeClass() == Attributed; 29679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 29689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall static bool classof(const AttributedType *T) { return true; } 29699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}; 29709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 2971fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 2972efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor unsigned Depth : 15; 2973efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor unsigned ParameterPack : 1; 297477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall unsigned Index : 16; 2975efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor IdentifierInfo *Name; 297672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2977efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 2978efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor QualType Canon) 297935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true, 2980d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, PP), 298177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall Depth(D), ParameterPack(PP), Index(I), Name(N) { } 298272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 29831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP) 298435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true, 2985d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, PP), 298677be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall Depth(D), ParameterPack(PP), Index(I), Name(0) { } 298772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2988fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor friend class ASTContext; // ASTContext creates these 298972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2990fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic: 2991efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor unsigned getDepth() const { return Depth; } 2992efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor unsigned getIndex() const { return Index; } 2993efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor bool isParameterPack() const { return ParameterPack; } 2994efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor IdentifierInfo *getName() const { return Name; } 29951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2996bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2997bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2998bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2999fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 3000efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor Profile(ID, Depth, Index, ParameterPack, Name); 3001fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 3002fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 30031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 30041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned Index, bool ParameterPack, 3005efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor IdentifierInfo *Name) { 3006fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Depth); 3007fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Index); 300876e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson ID.AddBoolean(ParameterPack); 3009efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor ID.AddPointer(Name); 3010fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 3011fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 30121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 30131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == TemplateTypeParm; 301472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor } 301572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 301672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}; 3017fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 301849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template 301949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter. 302049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// 302149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have 302249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these. They are used solely to record that a 302349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter; 302449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical. 302549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode { 302649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall // The original type parameter. 302749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *Replaced; 302849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 302949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) 303035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(), 3031d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Canon->isVariablyModifiedType(), 3032d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Canon->containsUnexpandedParameterPack()), 303349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Replaced(Param) { } 303449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 303549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall friend class ASTContext; 303649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 303749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic: 3038efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor IdentifierInfo *getName() const { return Replaced->getName(); } 3039efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor 304049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// Gets the template parameter that was substituted for. 304149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *getReplacedParameter() const { 304249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return Replaced; 304349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 304449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 304549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// Gets the type that was substituted for the template 304649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// parameter. 304749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType getReplacementType() const { 304849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return getCanonicalTypeInternal(); 304949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 305049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 305149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall bool isSugared() const { return true; } 305249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType desugar() const { return getReplacementType(); } 305349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 305449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall void Profile(llvm::FoldingSetNodeID &ID) { 305549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Profile(ID, getReplacedParameter(), getReplacementType()); 305649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 305749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, 305849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *Replaced, 305949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType Replacement) { 306049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall ID.AddPointer(Replaced); 306149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall ID.AddPointer(Replacement.getAsOpaquePtr()); 306249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 306349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 306449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static bool classof(const Type *T) { 306549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return T->getTypeClass() == SubstTemplateTypeParm; 306649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 306749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static bool classof(const SubstTemplateTypeParmType *T) { return true; } 306849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}; 306949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 3070c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// \brief Represents the result of substituting a set of types for a template 3071c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// type parameter pack. 3072c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// 3073c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs 3074c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// and those parameter packs correspond to different levels of template 3075c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// parameter lists, this type node is used to represent a template type 3076c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack 3077c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// substituted but that still lives within a pack expansion that itself 3078c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// could not be instantiated. When actually performing a substitution into 3079c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding 3080c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType 3081c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// at the current pack substitution index. 3082c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorclass SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode { 3083c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// \brief The original type parameter. 3084c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Replaced; 3085c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3086c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// \brief A pointer to the set of template arguments that this 3087c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// parameter pack is instantiated with. 3088c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument *Arguments; 3089c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3090c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// \brief The number of template arguments in \c Arguments. 3091c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor unsigned NumArguments; 3092c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3093c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param, 3094c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType Canon, 3095c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack); 3096c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3097c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor friend class ASTContext; 3098c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3099c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorpublic: 3100c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor IdentifierInfo *getName() const { return Replaced->getName(); } 3101c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3102c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// Gets the template parameter that was substituted for. 3103c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *getReplacedParameter() const { 3104c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return Replaced; 3105c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor } 3106c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3107c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor bool isSugared() const { return false; } 3108c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType desugar() const { return QualType(this, 0); } 3109c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3110c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor TemplateArgument getArgumentPack() const; 3111c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3112c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID); 3113c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, 3114c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Replaced, 3115c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack); 3116c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 3117c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor static bool classof(const Type *T) { 3118c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return T->getTypeClass() == SubstTemplateTypeParmPack; 3119c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor } 3120c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor static bool classof(const SubstTemplateTypeParmPackType *T) { return true; } 3121c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor}; 3122c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 312334b41d939a1328f484511c6002ba2456db879a29Richard Smith/// \brief Represents a C++0x auto type. 312434b41d939a1328f484511c6002ba2456db879a29Richard Smith/// 312534b41d939a1328f484511c6002ba2456db879a29Richard Smith/// These types are usually a placeholder for a deduced type. However, within 312634b41d939a1328f484511c6002ba2456db879a29Richard Smith/// templates and before the initializer is attached, there is no deduced type 312734b41d939a1328f484511c6002ba2456db879a29Richard Smith/// and an auto type is type-dependent and canonical. 312834b41d939a1328f484511c6002ba2456db879a29Richard Smithclass AutoType : public Type, public llvm::FoldingSetNode { 312934b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType(QualType DeducedType) 313034b41d939a1328f484511c6002ba2456db879a29Richard Smith : Type(Auto, DeducedType.isNull() ? QualType(this, 0) : DeducedType, 313134b41d939a1328f484511c6002ba2456db879a29Richard Smith /*Dependent=*/DeducedType.isNull(), 313234b41d939a1328f484511c6002ba2456db879a29Richard Smith /*VariablyModified=*/false, /*ContainsParameterPack=*/false) { 313334b41d939a1328f484511c6002ba2456db879a29Richard Smith assert((DeducedType.isNull() || !DeducedType->isDependentType()) && 313434b41d939a1328f484511c6002ba2456db879a29Richard Smith "deduced a dependent type for auto"); 313534b41d939a1328f484511c6002ba2456db879a29Richard Smith } 313634b41d939a1328f484511c6002ba2456db879a29Richard Smith 313734b41d939a1328f484511c6002ba2456db879a29Richard Smith friend class ASTContext; // ASTContext creates these 313834b41d939a1328f484511c6002ba2456db879a29Richard Smith 313934b41d939a1328f484511c6002ba2456db879a29Richard Smithpublic: 314034b41d939a1328f484511c6002ba2456db879a29Richard Smith bool isSugared() const { return isDeduced(); } 314134b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType desugar() const { return getCanonicalTypeInternal(); } 314234b41d939a1328f484511c6002ba2456db879a29Richard Smith 314334b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType getDeducedType() const { 314434b41d939a1328f484511c6002ba2456db879a29Richard Smith return isDeduced() ? getCanonicalTypeInternal() : QualType(); 314534b41d939a1328f484511c6002ba2456db879a29Richard Smith } 314634b41d939a1328f484511c6002ba2456db879a29Richard Smith bool isDeduced() const { 314734b41d939a1328f484511c6002ba2456db879a29Richard Smith return !isDependentType(); 314834b41d939a1328f484511c6002ba2456db879a29Richard Smith } 314934b41d939a1328f484511c6002ba2456db879a29Richard Smith 315034b41d939a1328f484511c6002ba2456db879a29Richard Smith void Profile(llvm::FoldingSetNodeID &ID) { 315134b41d939a1328f484511c6002ba2456db879a29Richard Smith Profile(ID, getDeducedType()); 315234b41d939a1328f484511c6002ba2456db879a29Richard Smith } 315334b41d939a1328f484511c6002ba2456db879a29Richard Smith 315434b41d939a1328f484511c6002ba2456db879a29Richard Smith static void Profile(llvm::FoldingSetNodeID &ID, 315534b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType Deduced) { 315634b41d939a1328f484511c6002ba2456db879a29Richard Smith ID.AddPointer(Deduced.getAsOpaquePtr()); 315734b41d939a1328f484511c6002ba2456db879a29Richard Smith } 315834b41d939a1328f484511c6002ba2456db879a29Richard Smith 315934b41d939a1328f484511c6002ba2456db879a29Richard Smith static bool classof(const Type *T) { 316034b41d939a1328f484511c6002ba2456db879a29Richard Smith return T->getTypeClass() == Auto; 316134b41d939a1328f484511c6002ba2456db879a29Richard Smith } 316234b41d939a1328f484511c6002ba2456db879a29Richard Smith static bool classof(const AutoType *T) { return true; } 316334b41d939a1328f484511c6002ba2456db879a29Richard Smith}; 316434b41d939a1328f484511c6002ba2456db879a29Richard Smith 31657532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written 31667532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code. 316755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// 31687532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a 31697532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 31707532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 31717532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the 31727532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a 317355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to 31741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// a tag type for the instantiation 317555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 31767532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// 31777532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name 31787532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always 31797532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent. 31801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType 318155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor : public Type, public llvm::FoldingSetNode { 318233500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief The name of the template being specialized. 31837532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Template; 318455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 318540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief - The number of template arguments named in this class 318640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// template specialization. 318755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned NumArgs; 318855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 3189ef99001908e799c388f1363b1e607dad5f5b57d3John McCall TemplateSpecializationType(TemplateName T, 31907532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 31917532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon); 319255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 319355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor friend class ASTContext; // ASTContext creates these 319455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 319555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic: 319640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Determine whether any of the given template arguments are 319740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// dependent. 319840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 31991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned NumArgs); 320040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 3201833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args, 3202833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned NumArgs); 3203833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3204d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &); 3205d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 3206df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 3207df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// enclosing the template arguments. 3208df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 3209d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned NumArgs, 3210dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor const PrintingPolicy &Policy, 3211dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor bool SkipBrackets = false); 3212df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor 3213833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args, 3214833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned NumArgs, 3215833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const PrintingPolicy &Policy); 3216833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3217d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &, 3218d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const PrintingPolicy &Policy); 3219d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 322031f17ecbef57b5679c017c375db330546b7b5145John McCall /// True if this template specialization type matches a current 322131f17ecbef57b5679c017c375db330546b7b5145John McCall /// instantiation in the context in which it is found. 322231f17ecbef57b5679c017c375db330546b7b5145John McCall bool isCurrentInstantiation() const { 322371d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall return isa<InjectedClassNameType>(getCanonicalTypeInternal()); 322431f17ecbef57b5679c017c375db330546b7b5145John McCall } 322531f17ecbef57b5679c017c375db330546b7b5145John McCall 322640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor typedef const TemplateArgument * iterator; 322740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 322840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator begin() const { return getArgs(); } 322933500955d731c73717af52088b7fc0e7a85681e7John McCall iterator end() const; // defined inline in TemplateBase.h 323040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 32317532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 32327532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName getTemplateName() const { return Template; } 323355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 323440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the template arguments. 32351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *getArgs() const { 323640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 323740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 323840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 323940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the number of template arguments. 324055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 324155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 324255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \brief Retrieve a specific template argument as a type. 324355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \precondition @c isArgType(Arg) 324433500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 324555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 324631f17ecbef57b5679c017c375db330546b7b5145John McCall bool isSugared() const { 324731f17ecbef57b5679c017c375db330546b7b5145John McCall return !isDependentType() || isCurrentInstantiation(); 324831f17ecbef57b5679c017c375db330546b7b5145John McCall } 3249bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getCanonicalTypeInternal(); } 3250bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 32514ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) { 325271d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall Profile(ID, Template, getArgs(), NumArgs, Ctx); 325355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 325455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 32557532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 325631f17ecbef57b5679c017c375db330546b7b5145John McCall const TemplateArgument *Args, 325731f17ecbef57b5679c017c375db330546b7b5145John McCall unsigned NumArgs, 32584ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context); 325955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 32601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 32611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == TemplateSpecialization; 326255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 32637532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 326455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}; 326555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 326631f17ecbef57b5679c017c375db330546b7b5145John McCall/// \brief The injected class name of a C++ class template or class 326731f17ecbef57b5679c017c375db330546b7b5145John McCall/// template partial specialization. Used to record that a type was 326831f17ecbef57b5679c017c375db330546b7b5145John McCall/// spelled with a bare identifier rather than as a template-id; the 326931f17ecbef57b5679c017c375db330546b7b5145John McCall/// equivalent for non-templated classes is just RecordType. 32703cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// 327131f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always dependent. Template 327231f17ecbef57b5679c017c375db330546b7b5145John McCall/// instantiation turns these into RecordTypes. 32733cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// 327431f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always canonical. This works 327531f17ecbef57b5679c017c375db330546b7b5145John McCall/// because it is impossible to compare an injected class name type 327631f17ecbef57b5679c017c375db330546b7b5145John McCall/// with the corresponding non-injected template type, for the same 327731f17ecbef57b5679c017c375db330546b7b5145John McCall/// reason that it is impossible to directly compare template 327831f17ecbef57b5679c017c375db330546b7b5145John McCall/// parameters from different dependent contexts: injected class name 327931f17ecbef57b5679c017c375db330546b7b5145John McCall/// types can only occur within the scope of a particular templated 328031f17ecbef57b5679c017c375db330546b7b5145John McCall/// declaration, and within that scope every template specialization 328131f17ecbef57b5679c017c375db330546b7b5145John McCall/// will canonicalize to the injected class name (when appropriate 328231f17ecbef57b5679c017c375db330546b7b5145John McCall/// according to the rules of the language). 32833cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameType : public Type { 32843cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall CXXRecordDecl *Decl; 32853cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 328631f17ecbef57b5679c017c375db330546b7b5145John McCall /// The template specialization which this type represents. 328731f17ecbef57b5679c017c375db330546b7b5145John McCall /// For example, in 328831f17ecbef57b5679c017c375db330546b7b5145John McCall /// template <class T> class A { ... }; 328931f17ecbef57b5679c017c375db330546b7b5145John McCall /// this is A<T>, whereas in 329031f17ecbef57b5679c017c375db330546b7b5145John McCall /// template <class X, class Y> class A<B<X,Y> > { ... }; 329131f17ecbef57b5679c017c375db330546b7b5145John McCall /// this is A<B<X,Y> >. 329231f17ecbef57b5679c017c375db330546b7b5145John McCall /// 329331f17ecbef57b5679c017c375db330546b7b5145John McCall /// It is always unqualified, always a template specialization type, 329431f17ecbef57b5679c017c375db330546b7b5145John McCall /// and always dependent. 329531f17ecbef57b5679c017c375db330546b7b5145John McCall QualType InjectedType; 32963cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 32973cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall friend class ASTContext; // ASTContext creates these. 3298c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not 3299c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl // currently suitable for AST reading, too much 330043921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis // interdependencies. 330131f17ecbef57b5679c017c375db330546b7b5145John McCall InjectedClassNameType(CXXRecordDecl *D, QualType TST) 330235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(InjectedClassName, QualType(), /*Dependent=*/true, 3303d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 3304d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 330531f17ecbef57b5679c017c375db330546b7b5145John McCall Decl(D), InjectedType(TST) { 33063cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(isa<TemplateSpecializationType>(TST)); 33073cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(!TST.hasQualifiers()); 330831f17ecbef57b5679c017c375db330546b7b5145John McCall assert(TST->isDependentType()); 33093cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 33103cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 33113cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallpublic: 331231f17ecbef57b5679c017c375db330546b7b5145John McCall QualType getInjectedSpecializationType() const { return InjectedType; } 331331f17ecbef57b5679c017c375db330546b7b5145John McCall const TemplateSpecializationType *getInjectedTST() const { 331431f17ecbef57b5679c017c375db330546b7b5145John McCall return cast<TemplateSpecializationType>(InjectedType.getTypePtr()); 33153cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 33163cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 3317ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl CXXRecordDecl *getDecl() const; 33183cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 331931f17ecbef57b5679c017c375db330546b7b5145John McCall bool isSugared() const { return false; } 332031f17ecbef57b5679c017c375db330546b7b5145John McCall QualType desugar() const { return QualType(this, 0); } 33213cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 33223cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall static bool classof(const Type *T) { 33233cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return T->getTypeClass() == InjectedClassName; 33243cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 33253cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall static bool classof(const InjectedClassNameType *T) { return true; } 33263cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}; 33273cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 3328465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief The kind of a tag type. 3329465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraenum TagTypeKind { 3330465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "struct" keyword. 3331465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Struct, 3332465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "union" keyword. 3333465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Union, 3334465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "class" keyword. 3335465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Class, 3336465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "enum" keyword. 3337465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Enum 3338465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}; 3339465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 33404a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or 33414a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// introduces an elaborated-type-specifier. 33424a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregorenum ElaboratedTypeKeyword { 33434a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "struct" keyword introduces the elaborated-type-specifier. 33444a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ETK_Struct, 33454a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "union" keyword introduces the elaborated-type-specifier. 33464a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ETK_Union, 3347465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "class" keyword introduces the elaborated-type-specifier. 3348465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_Class, 33494a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "enum" keyword introduces the elaborated-type-specifier. 3350465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_Enum, 3351465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "typename" keyword precedes the qualified type name, e.g., 3352465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \c typename T::type. 3353465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_Typename, 3354465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief No keyword precedes the qualified type name. 3355465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_None 33564a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor}; 3357465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3358465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword. 3359465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The keyword in stored in the free bits of the base class. 3360465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// Also provides a few static helpers for converting and printing 3361465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// elaborated type keyword and tag type kind enumerations. 3362465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass TypeWithKeyword : public Type { 3363465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraprotected: 3364465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, 3365d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType Canonical, bool Dependent, bool VariablyModified, 3366d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool ContainsUnexpandedParameterPack) 3367d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(tc, Canonical, Dependent, VariablyModified, 3368d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ContainsUnexpandedParameterPack) { 336977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall TypeWithKeywordBits.Keyword = Keyword; 337077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall } 3371465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3372465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarapublic: 3373465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeKeyword getKeyword() const { 337477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword); 3375465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 3376465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3377465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST) 3378465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// into an elaborated type keyword. 3379465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec); 3380465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3381465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST) 3382465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// into a tag type kind. It is an error to provide a type specifier 3383465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// which *isn't* a tag kind here. 3384465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec); 3385465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3386465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getKeywordForTagDeclKind - Converts a TagTypeKind into an 3387465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// elaborated type keyword. 3388465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag); 3389465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3390465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getTagTypeKindForKeyword - Converts an elaborated type keyword into 3391465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara // a TagTypeKind. It is an error to provide an elaborated type keyword 3392465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// which *isn't* a tag kind here. 3393465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword); 3394465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3395465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword); 3396465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3397465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static const char *getKeywordName(ElaboratedTypeKeyword Keyword); 3398465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3399465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static const char *getTagTypeKindName(TagTypeKind Kind) { 3400465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return getKeywordName(getKeywordForTagTypeKind(Kind)); 3401465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 3402465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3403465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara class CannotCastToThisType {}; 3404465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static CannotCastToThisType classof(const Type *); 3405465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}; 3406465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3407465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief Represents a type that was referred to using an elaborated type 3408465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type, 3409465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// or both. 3410e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// 3411e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the 3412465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// source code, including tag keywords and any nested-name-specifiers. 3413465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The type itself is always "sugar", used to express what was written 3414465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// in the source code but containing no additional semantic information. 3415465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode { 3416465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3417ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested name specifier containing the qualifier. 3418ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *NNS; 3419e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3420e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief The type that this qualified name refers to. 3421e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType; 3422e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3423465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 3424465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara QualType NamedType, QualType CanonType) 3425465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara : TypeWithKeyword(Keyword, Elaborated, CanonType, 342635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor NamedType->isDependentType(), 3427d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor NamedType->isVariablyModifiedType(), 3428d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor NamedType->containsUnexpandedParameterPack()), 3429465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NNS(NNS), NamedType(NamedType) { 3430465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara assert(!(Keyword == ETK_None && NNS == 0) && 3431465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara "ElaboratedType cannot have elaborated type keyword " 3432465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara "and name qualifier both null."); 3433465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 3434e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3435e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor friend class ASTContext; // ASTContext creates these 3436e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3437e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic: 343833500955d731c73717af52088b7fc0e7a85681e7John McCall ~ElaboratedType(); 3439465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3440ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the qualification on this type. 3441ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 3442e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3443e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 3444e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType getNamedType() const { return NamedType; } 3445e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3446bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 3447bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getNamedType(); } 3448bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3449bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 3450bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 3451bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3452e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 3453465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Profile(ID, getKeyword(), NNS, NamedType); 3454e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 3455e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3456465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 3457465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NestedNameSpecifier *NNS, QualType NamedType) { 3458465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ID.AddInteger(Keyword); 3459ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor ID.AddPointer(NNS); 3460ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NamedType.Profile(ID); 3461ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor } 3462e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 34631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 3464465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return T->getTypeClass() == Elaborated; 3465e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 3466465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static bool classof(const ElaboratedType *T) { return true; } 3467e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor}; 3468e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 34694a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief Represents a qualified type name for which the type name is 34704a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent. 3471d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// 34724a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// DependentNameType represents a class of dependent types that involve a 34734a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent) 34744a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a 34754a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// typename-specifier), "class", "struct", "union", or "enum" (for a 34764a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we 34774a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier). 3478465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { 3479465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3480d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The nested name specifier containing the qualifier. 3481d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *NNS; 3482d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3483d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The type that this typename specifier refers to. 348433500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name; 3485d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 34864a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 34874a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor const IdentifierInfo *Name, QualType CanonType) 348835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true, 3489d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 3490d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor NNS->containsUnexpandedParameterPack()), 3491465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NNS(NNS), Name(Name) { 34921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(NNS->isDependent() && 34934714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor "DependentNameType requires a dependent nested-name-specifier"); 3494d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3495d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3496d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor friend class ASTContext; // ASTContext creates these 3497d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3498d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic: 3499d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief Retrieve the qualification on this type. 3500d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 3501d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 35021734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 35031734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// identifier. 35041734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// 35051734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 35061734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// form of the original typename was terminated by an identifier, 35071734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// e.g., "typename T::type". 35081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo *getIdentifier() const { 350933500955d731c73717af52088b7fc0e7a85681e7John McCall return Name; 35101734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 3511d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3512bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 3513bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 3514bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3515d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 3516465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Profile(ID, getKeyword(), NNS, Name); 3517d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3518d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 35194a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 352033500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name) { 35214a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ID.AddInteger(Keyword); 3522d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor ID.AddPointer(NNS); 352333500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Name); 3524d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3525d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 35261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 35274714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor return T->getTypeClass() == DependentName; 3528d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 35294714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor static bool classof(const DependentNameType *T) { return true; } 3530d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor}; 3531d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 353233500955d731c73717af52088b7fc0e7a85681e7John McCall/// DependentTemplateSpecializationType - Represents a template 353333500955d731c73717af52088b7fc0e7a85681e7John McCall/// specialization type whose template cannot be resolved, e.g. 353433500955d731c73717af52088b7fc0e7a85681e7John McCall/// A<T>::template B<T> 353533500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationType : 353633500955d731c73717af52088b7fc0e7a85681e7John McCall public TypeWithKeyword, public llvm::FoldingSetNode { 353733500955d731c73717af52088b7fc0e7a85681e7John McCall 353833500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief The nested name specifier containing the qualifier. 353933500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS; 354033500955d731c73717af52088b7fc0e7a85681e7John McCall 354133500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief The identifier of the template. 354233500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name; 354333500955d731c73717af52088b7fc0e7a85681e7John McCall 354433500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief - The number of template arguments named in this class 354533500955d731c73717af52088b7fc0e7a85681e7John McCall /// template specialization. 354633500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs; 354733500955d731c73717af52088b7fc0e7a85681e7John McCall 354833500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *getArgBuffer() const { 354933500955d731c73717af52088b7fc0e7a85681e7John McCall return reinterpret_cast<const TemplateArgument*>(this+1); 355033500955d731c73717af52088b7fc0e7a85681e7John McCall } 355133500955d731c73717af52088b7fc0e7a85681e7John McCall TemplateArgument *getArgBuffer() { 355233500955d731c73717af52088b7fc0e7a85681e7John McCall return reinterpret_cast<TemplateArgument*>(this+1); 355333500955d731c73717af52088b7fc0e7a85681e7John McCall } 355433500955d731c73717af52088b7fc0e7a85681e7John McCall 3555ef99001908e799c388f1363b1e607dad5f5b57d3John McCall DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 355633500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, 355733500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 355833500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 355933500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args, 356033500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon); 356133500955d731c73717af52088b7fc0e7a85681e7John McCall 356233500955d731c73717af52088b7fc0e7a85681e7John McCall friend class ASTContext; // ASTContext creates these 356333500955d731c73717af52088b7fc0e7a85681e7John McCall 356433500955d731c73717af52088b7fc0e7a85681e7John McCallpublic: 356533500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *getQualifier() const { return NNS; } 356633500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *getIdentifier() const { return Name; } 356733500955d731c73717af52088b7fc0e7a85681e7John McCall 356833500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief Retrieve the template arguments. 356933500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *getArgs() const { 357033500955d731c73717af52088b7fc0e7a85681e7John McCall return getArgBuffer(); 357133500955d731c73717af52088b7fc0e7a85681e7John McCall } 357233500955d731c73717af52088b7fc0e7a85681e7John McCall 357333500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief Retrieve the number of template arguments. 357433500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned getNumArgs() const { return NumArgs; } 357533500955d731c73717af52088b7fc0e7a85681e7John McCall 357633500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 357733500955d731c73717af52088b7fc0e7a85681e7John McCall 357833500955d731c73717af52088b7fc0e7a85681e7John McCall typedef const TemplateArgument * iterator; 357933500955d731c73717af52088b7fc0e7a85681e7John McCall iterator begin() const { return getArgs(); } 358033500955d731c73717af52088b7fc0e7a85681e7John McCall iterator end() const; // inline in TemplateBase.h 358133500955d731c73717af52088b7fc0e7a85681e7John McCall 358233500955d731c73717af52088b7fc0e7a85681e7John McCall bool isSugared() const { return false; } 358333500955d731c73717af52088b7fc0e7a85681e7John McCall QualType desugar() const { return QualType(this, 0); } 358433500955d731c73717af52088b7fc0e7a85681e7John McCall 35854ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) { 358633500955d731c73717af52088b7fc0e7a85681e7John McCall Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs()); 358733500955d731c73717af52088b7fc0e7a85681e7John McCall } 358833500955d731c73717af52088b7fc0e7a85681e7John McCall 358933500955d731c73717af52088b7fc0e7a85681e7John McCall static void Profile(llvm::FoldingSetNodeID &ID, 35904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 359133500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 359233500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *Qualifier, 359333500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 359433500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 359533500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args); 359633500955d731c73717af52088b7fc0e7a85681e7John McCall 359733500955d731c73717af52088b7fc0e7a85681e7John McCall static bool classof(const Type *T) { 359833500955d731c73717af52088b7fc0e7a85681e7John McCall return T->getTypeClass() == DependentTemplateSpecialization; 359933500955d731c73717af52088b7fc0e7a85681e7John McCall } 360033500955d731c73717af52088b7fc0e7a85681e7John McCall static bool classof(const DependentTemplateSpecializationType *T) { 360133500955d731c73717af52088b7fc0e7a85681e7John McCall return true; 360233500955d731c73717af52088b7fc0e7a85681e7John McCall } 360333500955d731c73717af52088b7fc0e7a85681e7John McCall}; 360433500955d731c73717af52088b7fc0e7a85681e7John McCall 36057536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \brief Represents a pack expansion of types. 36067536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 36077536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Pack expansions are part of C++0x variadic templates. A pack 36087536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// expansion contains a pattern, which itself contains one or more 36097536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// "unexpanded" parameter packs. When instantiated, a pack expansion 36107536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// produces a series of types, each instantiated from the pattern of 36117536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// the expansion, where the Ith instantiation of the pattern uses the 36127536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Ith arguments bound to each of the unexpanded parameter packs. The 36137536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// pack expansion is considered to "expand" these unexpanded 36147536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// parameter packs. 36157536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 36167536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \code 36177536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types> struct tuple; 36187536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 36197536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types> 36207536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// struct tuple_of_references { 36217536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// typedef tuple<Types&...> type; 36227536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// }; 36237536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \endcode 36247536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 36257536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Here, the pack expansion \c Types&... is represented via a 36267536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// PackExpansionType whose pattern is Types&. 36277536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorclass PackExpansionType : public Type, public llvm::FoldingSetNode { 36287536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// \brief The pattern of the pack expansion. 36297536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType Pattern; 36307536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 3631cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// \brief The number of expansions that this pack expansion will 3632cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// generate when substituted (+1), or indicates that 3633cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// 3634cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// This field will only have a non-zero value when some of the parameter 3635cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// packs that occur within the pattern have been substituted but others have 3636cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// not. 3637cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor unsigned NumExpansions; 3638cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor 3639cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor PackExpansionType(QualType Pattern, QualType Canon, 3640cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) 36417536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor : Type(PackExpansion, Canon, /*Dependent=*/true, 36427536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /*VariableModified=*/Pattern->isVariablyModifiedType(), 36437536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3644cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Pattern(Pattern), 3645cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions(NumExpansions? *NumExpansions + 1: 0) { } 36467536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 36477536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor friend class ASTContext; // ASTContext creates these 3648cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor 36497536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorpublic: 36507536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// \brief Retrieve the pattern of this pack expansion, which is the 36517536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// type that will be repeatedly instantiated when instantiating the 36527536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// pack expansion itself. 36537536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType getPattern() const { return Pattern; } 36547536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 3655cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// \brief Retrieve the number of expansions that this pack expansion will 3656cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// generate, if known. 3657cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> getNumExpansions() const { 3658cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor if (NumExpansions) 3659cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor return NumExpansions - 1; 3660cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor 3661cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor return llvm::Optional<unsigned>(); 3662cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor } 3663cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor 36647536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor bool isSugared() const { return false; } 36657536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType desugar() const { return QualType(this, 0); } 36667536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 36677536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 3668cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Profile(ID, getPattern(), getNumExpansions()); 36697536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 36707536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 3671cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern, 3672cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 36737536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor ID.AddPointer(Pattern.getAsOpaquePtr()); 3674cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor ID.AddBoolean(NumExpansions); 3675cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor if (NumExpansions) 3676cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor ID.AddInteger(*NumExpansions); 36777536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 36787536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 36797536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor static bool classof(const Type *T) { 36807536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return T->getTypeClass() == PackExpansion; 36817536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 36827536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor static bool classof(const PackExpansionType *T) { 36837536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return true; 36847536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 36857536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor}; 36867536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 3687c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectType - Represents a class type in Objective C. 3688c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Every Objective C type is a combination of a base type and a 3689c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// list of protocols. 3690c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3691c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Given the following declarations: 3692c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// @class C; 3693c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// @protocol P; 3694c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3695c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType 3696c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// with base C and no protocols. 3697c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3698c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P]. 3699c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3700e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose 3701e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType 3702e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// and no protocols. 3703c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3704e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType 3705e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually 3706e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// this should get its own sugar class to better represent the source. 3707c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectType : public Type { 3708b870b88df784c2940efce448ebfaf54dece14666John McCall // ObjCObjectType.NumProtocols - the number of protocols stored 3709b870b88df784c2940efce448ebfaf54dece14666John McCall // after the ObjCObjectPointerType node. 371071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // 371171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // These protocols are those written directly on the type. If 371271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // protocol qualifiers ever become additive, the iterators will need 371371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // to get kindof complicated. 371471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // 371571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // In the canonical object type, these are sorted alphabetically 371671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // and uniqued. 3717c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 3718c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// Either a BuiltinType or an InterfaceType or sugar for either. 3719c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType BaseType; 3720c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3721c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *getProtocolStorage() const { 3722c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return const_cast<ObjCObjectType*>(this)->getProtocolStorage(); 3723c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3724c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3725c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl **getProtocolStorage(); 3726c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3727c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallprotected: 3728c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectType(QualType Canonical, QualType Base, 3729c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, unsigned NumProtocols); 3730c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3731c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall enum Nonce_ObjCInterface { Nonce_ObjCInterface }; 3732c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectType(enum Nonce_ObjCInterface) 3733d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(ObjCInterface, QualType(), false, false, false), 373471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall BaseType(QualType(this_(), 0)) { 3735b870b88df784c2940efce448ebfaf54dece14666John McCall ObjCObjectTypeBits.NumProtocols = 0; 373671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 3737c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 37383536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 3739e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getBaseType - Gets the base type of this object type. This is 3740e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// always (possibly sugar for) one of: 3741e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// - the 'id' builtin type (as opposed to the 'id' type visible to the 3742e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// user, which is a typedef for an ObjCPointerType) 3743e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// - the 'Class' builtin type (same caveat) 3744e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// - an ObjCObjectType (currently always an ObjCInterfaceType) 3745c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType getBaseType() const { return BaseType; } 374671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek 3747c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCId() const { 3748c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId); 3749c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3750c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCClass() const { 3751c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass); 3752c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3753c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); } 3754c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); } 3755c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCUnqualifiedIdOrClass() const { 3756c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!qual_empty()) return false; 3757c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>()) 3758c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T->getKind() == BuiltinType::ObjCId || 3759c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall T->getKind() == BuiltinType::ObjCClass; 3760c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return false; 3761c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3762c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); } 3763c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); } 3764c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3765c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// Gets the interface declaration for this object type, if the base type 3766c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// really is an interface. 3767c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCInterfaceDecl *getInterface() const; 3768c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3769c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall typedef ObjCProtocolDecl * const *qual_iterator; 3770c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3771c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator qual_begin() const { return getProtocolStorage(); } 3772c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); } 3773c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3774c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool qual_empty() const { return getNumProtocols() == 0; } 37751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3776c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 3777c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// interface type, or 0 if there are none. 3778b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; } 377914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 3780c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// \brief Fetch a protocol by index. 378173dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor ObjCProtocolDecl *getProtocol(unsigned I) const { 378273dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor assert(I < getNumProtocols() && "Out-of-range protocol access"); 378373dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor return qual_begin()[I]; 378473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor } 378573dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor 3786bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 3787bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 3788bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3789c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static bool classof(const Type *T) { 3790c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T->getTypeClass() == ObjCObject || 3791c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall T->getTypeClass() == ObjCInterface; 3792c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3793c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static bool classof(const ObjCObjectType *) { return true; } 3794c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}; 3795c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3796c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation 3797c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// of ObjCObjectType, so as to not increase the footprint of 3798c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType. Code outside of ASTContext and the core type 3799c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// system should not reference this type. 3800c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode { 3801c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall friend class ASTContext; 3802c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3803c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // If anyone adds fields here, ObjCObjectType::getProtocolStorage() 3804c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // will need to be modified. 3805c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3806c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypeImpl(QualType Canonical, QualType Base, 3807c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 3808c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) 3809c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {} 3810c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3811c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic: 3812c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 38131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, 3814c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType Base, 3815c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl *const *protocols, 3816c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols); 3817c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}; 38181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3819c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() { 3820c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return reinterpret_cast<ObjCProtocolDecl**>( 3821c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static_cast<ObjCObjectTypeImpl*>(this) + 1); 3822c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 3823c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3824c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 3825c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// object oriented design. They basically correspond to C++ classes. There 3826c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// are two kinds of interface types, normal interfaces like "NSString" and 3827c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// qualified interfaces, which are qualified with a protocol list like 3828c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// "NSString<NSCopyable, NSAmazing>". 3829e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 3830e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCInterfaceType guarantees the following properties when considered 3831e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// as a subtype of its superclass, ObjCObjectType: 3832e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// - There are no protocol qualifiers. To reinforce this, code which 3833e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// tries to invoke the protocol methods via an ObjCInterfaceType will 3834e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// fail to compile. 3835e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// - It is its own base type. That is, if T is an ObjCInterfaceType*, 3836e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// T->getBaseType() == QualType(T, 0). 3837c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCInterfaceType : public ObjCObjectType { 3838c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCInterfaceDecl *Decl; 3839c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3840c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCInterfaceType(const ObjCInterfaceDecl *D) 3841c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall : ObjCObjectType(Nonce_ObjCInterface), 3842c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Decl(const_cast<ObjCInterfaceDecl*>(D)) {} 3843c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall friend class ASTContext; // ASTContext creates these. 38441fb0caaa7bef765b85972274e3b434af2572c141John McCall 3845c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic: 3846e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getDecl - Get the declaration of this interface. 3847deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor ObjCInterfaceDecl *getDecl() const { return Decl; } 3848c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3849c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isSugared() const { return false; } 3850c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType desugar() const { return QualType(this, 0); } 38510b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 38521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 38531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ObjCInterface; 38543536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 3855a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 3856c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3857c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Nonsense to "hide" certain members of ObjCObjectType within this 3858c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // class. People asking for protocols on an ObjCInterfaceType are 3859c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // not going to get what they want: ObjCInterfaceTypes are 3860c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // guaranteed to have no protocols. 3861c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall enum { 3862c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator, 3863c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_begin, 3864c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_end, 3865c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getNumProtocols, 3866c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getProtocol 3867c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall }; 38683536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 38693536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 3870c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const { 3871c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCInterfaceType *T = 3872c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getBaseType()->getAs<ObjCInterfaceType>()) 3873c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T->getDecl(); 3874c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return 0; 3875c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 3876c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3877e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCObjectPointerType - Used to represent a pointer to an 3878e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Objective C object. These are constructed from pointer 3879e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar 3880e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for one). In addition, the 'id' and 'Class' types are typedefs 3881e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>' 3882e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// are translated into these. 388314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// 3884e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Pointers to pointers to Objective C objects are still PointerTypes; 3885e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// only the first level of pointer gets it own type implementation. 388614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 3887e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall QualType PointeeType; 38881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3889c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerType(QualType Canonical, QualType Pointee) 3890d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(ObjCObjectPointer, Canonical, false, false, false), 3891c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall PointeeType(Pointee) {} 389214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff friend class ASTContext; // ASTContext creates these. 38931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 389414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic: 3895e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getPointeeType - Gets the type pointed to by this ObjC pointer. 3896e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// The result will always be an ObjCObjectType or sugar thereof. 389714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const { return PointeeType; } 389814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 3899e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getObjCObjectType - Gets the type pointed to by this ObjC 3900e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// pointer. This method always returns non-null. 3901e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// 3902e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// This method is equivalent to getPointeeType() except that 3903e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// it discards any typedefs (or other sugar) between this 3904e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// type and the "outermost" object type. So for: 3905e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// @class A; @protocol P; @protocol Q; 3906e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A<P> AP; 3907e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A A1; 3908e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A1<P> A1P; 3909e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A1P<Q> A1PQ; 3910e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A*', getObjectType() will return 'A'. 3911e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A<P>*', getObjectType() will return 'A<P>'. 3912e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'AP*', getObjectType() will return 'A<P>'. 3913e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1*', getObjectType() will return 'A'. 3914e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1<P>*', getObjectType() will return 'A1<P>'. 3915e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1P*', getObjectType() will return 'A1<P>'. 3916e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because 3917e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// adding protocols to a protocol-qualified base discards the 3918e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// old qualifiers (for now). But if it didn't, getObjectType() 3919e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// would return 'A1P<Q>' (and we'd have to make iterating over 3920e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// qualifiers more complicated). 3921c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *getObjectType() const { 3922d0370f59e79702ac908c81bf556519f91e9ca297John McCall return PointeeType->castAs<ObjCObjectType>(); 3923c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3924c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3925e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getInterfaceType - If this pointer points to an Objective C 3926e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// @interface type, gets the type for that interface. Any protocol 3927e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// qualifiers on the interface are ignored. 3928e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// 3929e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// \return null if the base type for this pointer is 'id' or 'Class' 39301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const ObjCInterfaceType *getInterfaceType() const { 3931c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>(); 393214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 3933e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 3934e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getInterfaceDecl - If this pointer points to an Objective @interface 3935e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// type, gets the declaration for that interface. 3936e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// 3937e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// \return null if the base type for this pointer is 'id' or 'Class' 393814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCInterfaceDecl *getInterfaceDecl() const { 3939e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall return getObjectType()->getInterface(); 394014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 3941e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 3942e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if 3943e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// its object type is the primitive 'id' type with no protocols. 394414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const { 3945c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCUnqualifiedId(); 394614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 3947e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 3948e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCClassType - True if this is equivalent to the 'Class' type, 3949e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// i.e. if its object tive is the primitive 'Class' type with no protocols. 395014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const { 3951c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCUnqualifiedClass(); 3952de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 39538d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian 3954e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some 3955e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// non-empty set of protocols. 39561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isObjCQualifiedIdType() const { 3957c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCQualifiedId(); 3958de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 3959e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 3960e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for 3961e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// some non-empty set of protocols. 3962470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const { 3963c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCQualifiedClass(); 396414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 3965e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 3966e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// An iterator over the qualifiers on the object type. Provided 3967e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// for convenience. This will always iterate over the full set of 3968e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// protocols on a type, not just those provided directly. 3969c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall typedef ObjCObjectType::qual_iterator qual_iterator; 397014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 397171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek qual_iterator qual_begin() const { 3972c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->qual_begin(); 397371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek } 3974c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator qual_end() const { 3975c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->qual_end(); 397671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek } 3977c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool qual_empty() const { return getObjectType()->qual_empty(); } 397814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 3979e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getNumProtocols - Return the number of qualifying protocols on 3980e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// the object type. 3981c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned getNumProtocols() const { 3982c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->getNumProtocols(); 3983c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 398414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 3985e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// \brief Retrieve a qualifying protocol by index on the object 3986e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// type. 398773dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor ObjCProtocolDecl *getProtocol(unsigned I) const { 3988c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->getProtocol(I); 398973dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor } 399073dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor 3991bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 3992bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 3993bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3994e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall void Profile(llvm::FoldingSetNodeID &ID) { 3995e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall Profile(ID, getPointeeType()); 3996e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall } 3997c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { 3998c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(T.getAsOpaquePtr()); 3999c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 40001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 40011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ObjCObjectPointer; 400214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 400314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 400414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}; 40051bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 40060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers. 40070953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers { 40080953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 400949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {} 40100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 40110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Collect any qualifiers on the given type and return an 40123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// unqualified type. The qualifiers are assumed to be consistent 40133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// with those already in the type. 40143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *strip(QualType type) { 40153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall addFastQualifiers(type.getLocalFastQualifiers()); 40163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!type.hasLocalNonFastQualifiers()) 40173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return type.getTypePtrUnsafe(); 40183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 40193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ExtQuals *extQuals = type.getExtQualsUnsafe(); 40203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall addConsistentQualifiers(extQuals->getQualifiers()); 40213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return extQuals->getBaseType(); 40220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 40230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 40240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Apply the collected qualifiers to the given type. 40254ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType apply(const ASTContext &Context, QualType QT) const; 40260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 40270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Apply the collected qualifiers to the given type. 40284ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType apply(const ASTContext &Context, const Type* T) const; 40290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 40300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 40310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4032611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 40335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 40343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtr() const { 40353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getCommonPtr()->BaseType; 40363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 40373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 40383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtrOrNull() const { 40393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return (isNull() ? 0 : getCommonPtr()->BaseType); 40403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 40413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 40423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline SplitQualType QualType::split() const { 40433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!hasLocalNonFastQualifiers()) 40443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return SplitQualType(getTypePtrUnsafe(), 40453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers::fromFastMask(getLocalFastQualifiers())); 40463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 40473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ExtQuals *eq = getExtQualsUnsafe(); 40483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers qs = eq->getQualifiers(); 40493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall qs.addFastQualifiers(getLocalFastQualifiers()); 40503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return SplitQualType(eq->getBaseType(), qs); 40513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 40523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 40533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getLocalQualifiers() const { 40543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers Quals; 40553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (hasLocalNonFastQualifiers()) 40563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals = getExtQualsUnsafe()->getQualifiers(); 40573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals.addFastQualifiers(getLocalFastQualifiers()); 40583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return Quals; 40593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 40603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 40613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getQualifiers() const { 40623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers(); 40633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall quals.addFastQualifiers(getLocalFastQualifiers()); 40643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return quals; 40653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 40663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 40673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline unsigned QualType::getCVRQualifiers() const { 40683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers(); 40693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall cvr |= getLocalCVRQualifiers(); 40703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return cvr; 40713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 40723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 40733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline QualType QualType::getCanonicalType() const { 40743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType canon = getCommonPtr()->CanonicalType; 40753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return canon.withFastQualifiers(getLocalFastQualifiers()); 40763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 40773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 4078467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const { 40793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getTypePtr()->isCanonicalUnqualified(); 4080467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall} 4081467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall 408254e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const { 40833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isCanonical()) return false; 4084a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalQualifiers()) return false; 4085745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian 408654e14c4db764c0636160d26c5bbf491637c83a76John McCall const Type *T = getTypePtr(); 40873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (T->isVariablyModifiedType() && T->hasSizedVLAType()) 40883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return false; 40893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 40903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return !isa<FunctionType>(T) && !isa<ArrayType>(T); 409154e14c4db764c0636160d26c5bbf491637c83a76John McCall} 409254e14c4db764c0636160d26c5bbf491637c83a76John McCall 4093fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const { 4094fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return isLocalConstQualified() || 40953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.isLocalConstQualified(); 4096fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 4097fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 4098fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const { 4099fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return isLocalRestrictQualified() || 41003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.isLocalRestrictQualified(); 4101fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 4102fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 4103fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 4104fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const { 4105fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return isLocalVolatileQualified() || 41063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.isLocalVolatileQualified(); 4107fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 4108fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 4109fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const { 4110fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return hasLocalQualifiers() || 41113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.hasLocalQualifiers(); 4112fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 411362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 411462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline QualType QualType::getUnqualifiedType() const { 411562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) 411662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return QualType(getTypePtr(), 0); 411762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 411862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return QualType(getSplitUnqualifiedTypeImpl(*this).first, 0); 411962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall} 412062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 412162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline SplitQualType QualType::getSplitUnqualifiedType() const { 412262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) 412362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return split(); 412462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 412562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getSplitUnqualifiedTypeImpl(*this); 4126fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 4127fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 412849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalConst() { 412949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Qualifiers::Const); 41300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 41310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 413249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalRestrict() { 413349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Qualifiers::Restrict); 41340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 41350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 413649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalVolatile() { 413749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Qualifiers::Volatile); 41380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 41390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 414049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalCVRQualifiers(unsigned Mask) { 41416b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits"); 4142c3c0af36bac3d71f61dd758585ab307892545de4Douglas Gregor assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask); 41430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 41440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Fast path: we don't need to touch the slow qualifiers. 414549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Mask); 4146ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 4147ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 4148ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 4149ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 41503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getQualifiers().getAddressSpace(); 4151ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 4152611c1fff195d32df97706e0920c92468b2509900Chris Lattner 4153d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 41540953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const { 41553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getQualifiers().getObjCGCAttr(); 4156d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 41572455636163fdd18581d7fdae816433f886d88213Mike Stump 4158264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { 4159264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola if (const PointerType *PT = t.getAs<PointerType>()) { 4160183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>()) 4161264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FT->getExtInfo(); 4162264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } else if (const FunctionType *FT = t.getAs<FunctionType>()) 4163264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FT->getExtInfo(); 41642455636163fdd18581d7fdae816433f886d88213Mike Stump 4165264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FunctionType::ExtInfo(); 41662455636163fdd18581d7fdae816433f886d88213Mike Stump} 41671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4168264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { 4169264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return getFunctionExtInfo(*t); 4170ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor} 4171ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor 4172e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 4173e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 4174e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and 4175e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile 4176e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int". 417762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isMoreQualifiedThan(QualType other) const { 417862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Qualifiers myQuals = getQualifiers(); 417962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Qualifiers otherQuals = other.getQualifiers(); 418062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return (myQuals != otherQuals && myQuals.compatiblyIncludes(otherQuals)); 4181e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 4182e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 4183e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 4184e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile 4185e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 4186e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int". 418762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isAtLeastAsQualifiedAs(QualType other) const { 418862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getQualifiers().compatiblyIncludes(other.getQualifiers()); 4189e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 4190e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 4191e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 4192e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const 4193e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 4194e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6: 4195e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 4196e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 4197e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 4198e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// analysis, the expression designates the object or function 4199e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 4200e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const { 42016217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 4202e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return RefType->getPointeeType(); 4203e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor else 4204e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return *this; 4205e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 4206e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 4207611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 4208a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<FunctionType>(CanonicalType); 4209611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 4210611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 4211a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<PointerType>(CanonicalType); 4212611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 421358f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const { 421458f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff return isPointerType() || isObjCObjectPointerType(); 421558f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff} 42165618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const { 4217a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<BlockPointerType>(CanonicalType); 42185618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 4219bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const { 4220a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ReferenceType>(CanonicalType); 4221bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 42227c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const { 4223a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<LValueReferenceType>(CanonicalType); 42247c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 42257c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const { 4226a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<RValueReferenceType>(CanonicalType); 42277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 4228498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 4229d0370f59e79702ac908c81bf556519f91e9ca297John McCall if (const PointerType *T = getAs<PointerType>()) 4230498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 4231498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 4232498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 4233498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 4234f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const { 4235a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<MemberPointerType>(CanonicalType); 4236f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 4237f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 42386217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const MemberPointerType* T = getAs<MemberPointerType>()) 42390bab0cdab751248ca389a5592bcb70eac5d39260John McCall return T->isMemberFunctionPointer(); 4240f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl else 4241f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return false; 4242f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 4243db68e28c05a67735211e688009890cf834c22e75Douglas Gregorinline bool Type::isMemberDataPointerType() const { 4244db68e28c05a67735211e688009890cf834c22e75Douglas Gregor if (const MemberPointerType* T = getAs<MemberPointerType>()) 42450bab0cdab751248ca389a5592bcb70eac5d39260John McCall return T->isMemberDataPointer(); 4246db68e28c05a67735211e688009890cf834c22e75Douglas Gregor else 4247db68e28c05a67735211e688009890cf834c22e75Douglas Gregor return false; 4248db68e28c05a67735211e688009890cf834c22e75Douglas Gregor} 4249611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 4250a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ArrayType>(CanonicalType); 4251611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 4252c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const { 4253a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ConstantArrayType>(CanonicalType); 4254c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 4255c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const { 4256a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<IncompleteArrayType>(CanonicalType); 4257c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 4258c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const { 4259a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<VariableArrayType>(CanonicalType); 4260c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 4261898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const { 4262a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType); 4263898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 42643ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isBuiltinType() const { 42653ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall return isa<BuiltinType>(CanonicalType); 42663ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall} 4267611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 4268a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<RecordType>(CanonicalType); 4269611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 42703ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isEnumeralType() const { 42713ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall return isa<EnumType>(CanonicalType); 42723ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall} 4273f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const { 4274a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ComplexType>(CanonicalType); 4275f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner} 4276611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 4277a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<VectorType>(CanonicalType); 4278611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 4279213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const { 4280a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ExtVectorType>(CanonicalType); 4281611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 4282d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const { 4283a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ObjCObjectPointerType>(CanonicalType); 4284d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 4285c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline bool Type::isObjCObjectType() const { 4286c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return isa<ObjCObjectType>(CanonicalType); 4287368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 4288569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorinline bool Type::isObjCObjectOrInterfaceType() const { 4289569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor return isa<ObjCInterfaceType>(CanonicalType) || 4290569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor isa<ObjCObjectType>(CanonicalType); 4291569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor} 4292569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor 4293a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 4294183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 4295d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT->isObjCQualifiedIdType(); 4296d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return false; 4297d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 4298470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const { 4299183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 4300470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return OPT->isObjCQualifiedClassType(); 4301470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return false; 4302470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff} 430314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const { 4304183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 430514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCIdType(); 430614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 430714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 430814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const { 4309183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 431014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCClassType(); 431114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 431214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 431313dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const { 43148d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian if (const PointerType *OPT = getAs<PointerType>()) 43158d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); 431613dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian return false; 431713dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian} 4318de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const { 431913dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian return isObjCIdType() || isObjCClassType() || isObjCSelType(); 4320de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff} 432172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const { 4322a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType); 432372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor} 432472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4325e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 4326183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 4327e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 4328e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return true; 4329e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return false; 4330e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar} 4331e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 43322a984cad5ac3fdceeff2bd99daa7b90979313475John McCallinline bool Type::isPlaceholderType() const { 43332a984cad5ac3fdceeff2bd99daa7b90979313475John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 43342a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return BT->isPlaceholderType(); 43352a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return false; 43362a984cad5ac3fdceeff2bd99daa7b90979313475John McCall} 43372a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 4338864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCallinline bool Type::isSpecificPlaceholderType(unsigned K) const { 4339864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(this)) 4340864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return (BT->getKind() == (BuiltinType::Kind) K); 4341864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return false; 4342864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall} 4343864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 4344063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define 4345063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator. 4346063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const { 4347063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 4348904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor} 4349904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 43508958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 43518958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 4352c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall isObjCObjectPointerType() || isNullPtrType()); 43538958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar} 43548958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 4355820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 4356c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return isObjCObjectPointerType(); 4357820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian} 4358820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 4359d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const Type *Type::getBaseElementTypeUnsafe() const { 4360d0370f59e79702ac908c81bf556519f91e9ca297John McCall const Type *type = this; 4361d0370f59e79702ac908c81bf556519f91e9ca297John McCall while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe()) 4362d0370f59e79702ac908c81bf556519f91e9ca297John McCall type = arrayType->getElementType().getTypePtr(); 4363d0370f59e79702ac908c81bf556519f91e9ca297John McCall return type; 4364d0370f59e79702ac908c81bf556519f91e9ca297John McCall} 4365d0370f59e79702ac908c81bf556519f91e9ca297John McCall 436622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 436722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<. 436822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 436922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner QualType T) { 437022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 437122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner Diagnostic::ak_qualtype); 437222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner return DB; 437322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner} 43741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 437547c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// Insertion operator for partial diagnostics. This allows sending QualType's 437647c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// into a diagnostic with <<. 437747c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruthinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, 437847c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth QualType T) { 437947c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 438047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth Diagnostic::ak_qualtype); 438147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth return PD; 438247c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth} 438347c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth 438489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does 438589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type. 438689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T, 438789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor bool isArrayType = (llvm::is_same<T, ArrayType>::value || 438889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor llvm::is_base_of<ArrayType, T>::value)> 438989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { }; 439089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor 439189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T> 439289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>; 439389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor 43941a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'. 43951a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const { 439689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor ArrayType_cannot_be_used_with_getAs<T> at; 439789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor (void)at; 439889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor 43991a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If this is directly a T type, return it. 44001a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek if (const T *Ty = dyn_cast<T>(this)) 44011a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return Ty; 44021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 44031a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If the canonical form of this type isn't the right kind, reject it. 44040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<T>(CanonicalType)) 44051a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return 0; 44061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 44070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If this is a typedef for the type, strip the typedef off without 44081a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // losing all typedef information. 4409bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<T>(getUnqualifiedDesugaredType()); 44101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 441122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner 44123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const ArrayType *Type::getAsArrayTypeUnsafe() const { 44133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If this is directly an array type, return it. 44143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const ArrayType *arr = dyn_cast<ArrayType>(this)) 44153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return arr; 44163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 44173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If the canonical form of this type isn't the right kind, reject it. 44183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isa<ArrayType>(CanonicalType)) 44193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return 0; 44203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 44213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If this is a typedef for the type, strip the typedef off without 44223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // losing all typedef information. 44233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()); 44243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 44253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 4426d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <typename T> const T *Type::castAs() const { 4427d0370f59e79702ac908c81bf556519f91e9ca297John McCall ArrayType_cannot_be_used_with_getAs<T> at; 4428d0370f59e79702ac908c81bf556519f91e9ca297John McCall (void) at; 4429d0370f59e79702ac908c81bf556519f91e9ca297John McCall 4430d0370f59e79702ac908c81bf556519f91e9ca297John McCall assert(isa<T>(CanonicalType)); 4431d0370f59e79702ac908c81bf556519f91e9ca297John McCall if (const T *ty = dyn_cast<T>(this)) return ty; 4432d0370f59e79702ac908c81bf556519f91e9ca297John McCall return cast<T>(getUnqualifiedDesugaredType()); 4433d0370f59e79702ac908c81bf556519f91e9ca297John McCall} 4434d0370f59e79702ac908c81bf556519f91e9ca297John McCall 4435d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const ArrayType *Type::castAsArrayTypeUnsafe() const { 4436d0370f59e79702ac908c81bf556519f91e9ca297John McCall assert(isa<ArrayType>(CanonicalType)); 4437d0370f59e79702ac908c81bf556519f91e9ca297John McCall if (const ArrayType *arr = dyn_cast<ArrayType>(this)) return arr; 4438d0370f59e79702ac908c81bf556519f91e9ca297John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()); 4439d0370f59e79702ac908c81bf556519f91e9ca297John McCall} 4440d0370f59e79702ac908c81bf556519f91e9ca297John McCall 44415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 44425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 44435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 4444