Type.h revision 0e2e13f4daa71edac982633120531333b45e77b5
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 17d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer#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" 21d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer#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" 2550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor#include "llvm/Support/type_traits.h" 269fe8c74a93ac8e92512615c5f83e7a328b3b0544David Blaikie#include "llvm/Support/ErrorHandling.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" 329594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "clang/Basic/LLVM.h" 337532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 346b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCallnamespace clang { 356b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall enum { 36f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor TypeAlignmentInBits = 4, 376b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeAlignment = 1 << TypeAlignmentInBits 386b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall }; 39aed1df80bf64228e1429c1edc408397f9174847cChris Lattner class Type; 40aed1df80bf64228e1429c1edc408397f9174847cChris Lattner class ExtQuals; 41aed1df80bf64228e1429c1edc408397f9174847cChris Lattner class QualType; 426b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall} 435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 444e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm { 454e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner template <typename T> 46daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner class PointerLikeTypeTraits; 47bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner template<> 48bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner class PointerLikeTypeTraits< ::clang::Type*> { 49bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner public: 50bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 51bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner static inline ::clang::Type *getFromVoidPointer(void *P) { 52bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner return static_cast< ::clang::Type*>(P); 53bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner } 546b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 55bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner }; 560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall template<> 570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall class PointerLikeTypeTraits< ::clang::ExtQuals*> { 580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall public: 590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; } 600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static inline ::clang::ExtQuals *getFromVoidPointer(void *P) { 610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return static_cast< ::clang::ExtQuals*>(P); 620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 636b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall }; 65aed1df80bf64228e1429c1edc408397f9174847cChris Lattner 66aed1df80bf64228e1429c1edc408397f9174847cChris Lattner template <> 67aed1df80bf64228e1429c1edc408397f9174847cChris Lattner struct isPodLike<clang::QualType> { static const bool value = true; }; 684e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner} 694e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class ASTContext; 72162e1c1b487352434552147967c3dd296ebee2f7Richard Smith class TypedefNameDecl; 7355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor class TemplateDecl; 7472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor class TemplateTypeParmDecl; 75aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor class NonTypeTemplateParmDecl; 767532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor class TemplateTemplateParmDecl; 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TagDecl; 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class RecordDecl; 7949aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis class CXXRecordDecl; 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class EnumDecl; 8121d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek class FieldDecl; 82a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCInterfaceDecl; 83a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCProtocolDecl; 84a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCMethodDecl; 85ed97649e9574b9d854fa4d6109c9333ae0993554John McCall class UnresolvedUsingTypenameDecl; 865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Expr; 87b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek class Stmt; 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class SourceLocation; 8992866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek class StmtIteratorBase; 9040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor class TemplateArgument; 91833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall class TemplateArgumentLoc; 92d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall class TemplateArgumentListInfo; 93465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara class ElaboratedType; 943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall class ExtQuals; 953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall class ExtQualsTypeCommonBase; 963b4ea54acf01f72f6eb74d96689dda86d950228fDaniel Dunbar struct PrintingPolicy; 9772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 98ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie template <typename> class CanQual; 99ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall typedef CanQual<Type> CanQualType; 100ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall 10172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor // Provide forward declarations for all of the *Type classes 10272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type; 10372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 104f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Qualifiers - The collection of all-type qualifiers we support. 1060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Clang supports five independent qualifiers: 1070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * C99: const, volatile, and restrict 1080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Embedded C (TR18037): address spaces 1090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Objective C: the GC attributes (none, weak, or strong) 1100953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass Qualifiers { 1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Const = 0x1, 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Restrict = 0x2, 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Volatile = 0x4, 1160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall CVRMask = Const | Volatile | Restrict 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall enum GC { 120d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian GCNone = 0, 121d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Weak, 122d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Strong 123d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian }; 124efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall 125f85e193739c953358c865005855253af4f68a497John McCall enum ObjCLifetime { 126f85e193739c953358c865005855253af4f68a497John McCall /// There is no lifetime qualification on this type. 127f85e193739c953358c865005855253af4f68a497John McCall OCL_None, 128f85e193739c953358c865005855253af4f68a497John McCall 129f85e193739c953358c865005855253af4f68a497John McCall /// This object can be modified without requiring retains or 130f85e193739c953358c865005855253af4f68a497John McCall /// releases. 131f85e193739c953358c865005855253af4f68a497John McCall OCL_ExplicitNone, 132f85e193739c953358c865005855253af4f68a497John McCall 133f85e193739c953358c865005855253af4f68a497John McCall /// Assigning into this object requires the old value to be 134f85e193739c953358c865005855253af4f68a497John McCall /// released and the new value to be retained. The timing of the 135f85e193739c953358c865005855253af4f68a497John McCall /// release of the old value is inexact: it may be moved to 136f85e193739c953358c865005855253af4f68a497John McCall /// immediately after the last known point where the value is 137f85e193739c953358c865005855253af4f68a497John McCall /// live. 138f85e193739c953358c865005855253af4f68a497John McCall OCL_Strong, 139f85e193739c953358c865005855253af4f68a497John McCall 140f85e193739c953358c865005855253af4f68a497John McCall /// Reading or writing from this object requires a barrier call. 141f85e193739c953358c865005855253af4f68a497John McCall OCL_Weak, 142f85e193739c953358c865005855253af4f68a497John McCall 143f85e193739c953358c865005855253af4f68a497John McCall /// Assigning into this object requires a lifetime extension. 144f85e193739c953358c865005855253af4f68a497John McCall OCL_Autoreleasing 145f85e193739c953358c865005855253af4f68a497John McCall }; 146f85e193739c953358c865005855253af4f68a497John McCall 1470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall enum { 1480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// The maximum supported address space number. 1490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// 24 bits should be enough for anyone. 1500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall MaxAddressSpace = 0xffffffu, 1510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// The width of the "fast" qualifier mask. 153f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor FastWidth = 3, 1540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// The fast qualifier mask. 1560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall FastMask = (1 << FastWidth) - 1 1570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall }; 1580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers() : Mask(0) {} 1600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static Qualifiers fromFastMask(unsigned Mask) { 1620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Qs; 1630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qs.addFastQualifiers(Mask); 1640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs; 1650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static Qualifiers fromCVRMask(unsigned CVR) { 1680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Qs; 1690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qs.addCVRQualifiers(CVR); 1700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs; 1710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Deserialize qualifiers from an opaque representation. 1740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static Qualifiers fromOpaqueValue(unsigned opaque) { 1750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Qs; 1760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qs.Mask = opaque; 1770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs; 1780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Serialize these qualifiers into an opaque representation. 1810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getAsOpaqueValue() const { 1820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Mask; 1830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasConst() const { return Mask & Const; } 1860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setConst(bool flag) { 1870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~Const) | (flag ? Const : 0); 1880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeConst() { Mask &= ~Const; } 1900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addConst() { Mask |= Const; } 1910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasVolatile() const { return Mask & Volatile; } 1930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setVolatile(bool flag) { 1940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~Volatile) | (flag ? Volatile : 0); 1950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeVolatile() { Mask &= ~Volatile; } 1970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addVolatile() { Mask |= Volatile; } 1980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasRestrict() const { return Mask & Restrict; } 2000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setRestrict(bool flag) { 2010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~Restrict) | (flag ? Restrict : 0); 2020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeRestrict() { Mask &= ~Restrict; } 2040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addRestrict() { Mask |= Restrict; } 2050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasCVRQualifiers() const { return getCVRQualifiers(); } 2070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getCVRQualifiers() const { return Mask & CVRMask; } 2080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setCVRQualifiers(unsigned mask) { 2090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 2100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~CVRMask) | mask; 2110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeCVRQualifiers(unsigned mask) { 2130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 2140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask &= ~mask; 2150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeCVRQualifiers() { 2170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeCVRQualifiers(CVRMask); 2180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addCVRQualifiers(unsigned mask) { 2200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 2210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= mask; 2220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasObjCGCAttr() const { return Mask & GCAttrMask; } 2250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); } 2260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setObjCGCAttr(GC type) { 2270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift); 2280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeObjCGCAttr() { setObjCGCAttr(GCNone); } 2300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addObjCGCAttr(GC type) { 2310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(type); 2320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall setObjCGCAttr(type); 2330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2342234873111009eb8655d63362cedc422eb9fc517John McCall Qualifiers withoutObjCGCAttr() const { 2352234873111009eb8655d63362cedc422eb9fc517John McCall Qualifiers qs = *this; 2362234873111009eb8655d63362cedc422eb9fc517John McCall qs.removeObjCGCAttr(); 2372234873111009eb8655d63362cedc422eb9fc517John McCall return qs; 2382234873111009eb8655d63362cedc422eb9fc517John McCall } 239200fa53fd420aa8369586f569dbece04930ad6a3John McCall Qualifiers withoutObjCLifetime() const { 240f85e193739c953358c865005855253af4f68a497John McCall Qualifiers qs = *this; 241f85e193739c953358c865005855253af4f68a497John McCall qs.removeObjCLifetime(); 242f85e193739c953358c865005855253af4f68a497John McCall return qs; 243f85e193739c953358c865005855253af4f68a497John McCall } 2440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 245f85e193739c953358c865005855253af4f68a497John McCall bool hasObjCLifetime() const { return Mask & LifetimeMask; } 246f85e193739c953358c865005855253af4f68a497John McCall ObjCLifetime getObjCLifetime() const { 247f85e193739c953358c865005855253af4f68a497John McCall return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift); 248f85e193739c953358c865005855253af4f68a497John McCall } 249f85e193739c953358c865005855253af4f68a497John McCall void setObjCLifetime(ObjCLifetime type) { 250f85e193739c953358c865005855253af4f68a497John McCall Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift); 251f85e193739c953358c865005855253af4f68a497John McCall } 252f85e193739c953358c865005855253af4f68a497John McCall void removeObjCLifetime() { setObjCLifetime(OCL_None); } 253f85e193739c953358c865005855253af4f68a497John McCall void addObjCLifetime(ObjCLifetime type) { 254f85e193739c953358c865005855253af4f68a497John McCall assert(type); 255200fa53fd420aa8369586f569dbece04930ad6a3John McCall assert(!hasObjCLifetime()); 256200fa53fd420aa8369586f569dbece04930ad6a3John McCall Mask |= (type << LifetimeShift); 257f85e193739c953358c865005855253af4f68a497John McCall } 258f85e193739c953358c865005855253af4f68a497John McCall 259f85e193739c953358c865005855253af4f68a497John McCall /// True if the lifetime is neither None or ExplicitNone. 260f85e193739c953358c865005855253af4f68a497John McCall bool hasNonTrivialObjCLifetime() const { 261f85e193739c953358c865005855253af4f68a497John McCall ObjCLifetime lifetime = getObjCLifetime(); 262f85e193739c953358c865005855253af4f68a497John McCall return (lifetime > OCL_ExplicitNone); 263f85e193739c953358c865005855253af4f68a497John McCall } 264f85e193739c953358c865005855253af4f68a497John McCall 265f85e193739c953358c865005855253af4f68a497John McCall /// True if the lifetime is either strong or weak. 266f85e193739c953358c865005855253af4f68a497John McCall bool hasStrongOrWeakObjCLifetime() const { 267f85e193739c953358c865005855253af4f68a497John McCall ObjCLifetime lifetime = getObjCLifetime(); 268f85e193739c953358c865005855253af4f68a497John McCall return (lifetime == OCL_Strong || lifetime == OCL_Weak); 269f85e193739c953358c865005855253af4f68a497John McCall } 270ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasAddressSpace() const { return Mask & AddressSpaceMask; } 2720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; } 2730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setAddressSpace(unsigned space) { 2740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(space <= MaxAddressSpace); 2750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~AddressSpaceMask) 2760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall | (((uint32_t) space) << AddressSpaceShift); 2770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeAddressSpace() { setAddressSpace(0); } 2790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addAddressSpace(unsigned space) { 2800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(space); 2810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall setAddressSpace(space); 2820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Fast qualifiers are those that can be allocated directly 2850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // on a QualType object. 2860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasFastQualifiers() const { return getFastQualifiers(); } 2870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getFastQualifiers() const { return Mask & FastMask; } 2880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setFastQualifiers(unsigned mask) { 2890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~FastMask) | mask; 2910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeFastQualifiers(unsigned mask) { 2930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask &= ~mask; 2950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeFastQualifiers() { 2970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeFastQualifiers(FastMask); 2980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addFastQualifiers(unsigned mask) { 3000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 3010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= mask; 3020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// hasNonFastQualifiers - Return true if the set contains any 3050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// qualifiers which require an ExtQuals node to be allocated. 3060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasNonFastQualifiers() const { return Mask & ~FastMask; } 3070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers getNonFastQualifiers() const { 3080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Quals = *this; 3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.setFastQualifiers(0); 3100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Quals; 3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// hasQualifiers - Return true if the set contains any qualifiers. 3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasQualifiers() const { return Mask; } 3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool empty() const { return !Mask; } 3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// \brief Add the qualifiers from the given set to this set. 3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addQualifiers(Qualifiers Q) { 3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If the other set doesn't have any non-boolean qualifiers, just 3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // bit-or it in. 3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!(Q.Mask & ~CVRMask)) 3220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= Q.Mask; 3230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall else { 3240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= (Q.Mask & CVRMask); 3250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Q.hasAddressSpace()) 3260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addAddressSpace(Q.getAddressSpace()); 3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Q.hasObjCGCAttr()) 3280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addObjCGCAttr(Q.getObjCGCAttr()); 329f85e193739c953358c865005855253af4f68a497John McCall if (Q.hasObjCLifetime()) 330f85e193739c953358c865005855253af4f68a497John McCall addObjCLifetime(Q.getObjCLifetime()); 3310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 33462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \brief Add the qualifiers from the given set to this set, given that 33562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// they don't conflict. 33662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall void addConsistentQualifiers(Qualifiers qs) { 33762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall assert(getAddressSpace() == qs.getAddressSpace() || 33862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall !hasAddressSpace() || !qs.hasAddressSpace()); 33962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall assert(getObjCGCAttr() == qs.getObjCGCAttr() || 34062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall !hasObjCGCAttr() || !qs.hasObjCGCAttr()); 341f85e193739c953358c865005855253af4f68a497John McCall assert(getObjCLifetime() == qs.getObjCLifetime() || 342f85e193739c953358c865005855253af4f68a497John McCall !hasObjCLifetime() || !qs.hasObjCLifetime()); 34362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Mask |= qs.Mask; 34462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 34562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 34662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \brief Determines if these qualifiers compatibly include another set. 34762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// Generally this answers the question of whether an object with the other 34862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// qualifiers can be safely used as an object with these qualifiers. 34962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall bool compatiblyIncludes(Qualifiers other) const { 350ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return 351377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor // Address spaces must match exactly. 352377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor getAddressSpace() == other.getAddressSpace() && 353377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor // ObjC GC qualifiers can match, be added, or be removed, but can't be 354377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor // changed. 355377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor (getObjCGCAttr() == other.getObjCGCAttr() || 356377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor !hasObjCGCAttr() || !other.hasObjCGCAttr()) && 357f85e193739c953358c865005855253af4f68a497John McCall // ObjC lifetime qualifiers must match exactly. 358f85e193739c953358c865005855253af4f68a497John McCall getObjCLifetime() == other.getObjCLifetime() && 359377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor // CVR qualifiers may subset. 360377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)); 36162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 36262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 363f85e193739c953358c865005855253af4f68a497John McCall /// \brief Determines if these qualifiers compatibly include another set of 364f85e193739c953358c865005855253af4f68a497John McCall /// qualifiers from the narrow perspective of Objective-C ARC lifetime. 365f85e193739c953358c865005855253af4f68a497John McCall /// 366f85e193739c953358c865005855253af4f68a497John McCall /// One set of Objective-C lifetime qualifiers compatibly includes the other 367ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// if the lifetime qualifiers match, or if both are non-__weak and the 368f85e193739c953358c865005855253af4f68a497John McCall /// including set also contains the 'const' qualifier. 369f85e193739c953358c865005855253af4f68a497John McCall bool compatiblyIncludesObjCLifetime(Qualifiers other) const { 370f85e193739c953358c865005855253af4f68a497John McCall if (getObjCLifetime() == other.getObjCLifetime()) 371f85e193739c953358c865005855253af4f68a497John McCall return true; 372ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 373f85e193739c953358c865005855253af4f68a497John McCall if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak) 374f85e193739c953358c865005855253af4f68a497John McCall return false; 375ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 376f85e193739c953358c865005855253af4f68a497John McCall return hasConst(); 377f85e193739c953358c865005855253af4f68a497John McCall } 378ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 379f85e193739c953358c865005855253af4f68a497John McCall bool isSupersetOf(Qualifiers Other) const; 380f85e193739c953358c865005855253af4f68a497John McCall 381769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor /// \brief Determine whether this set of qualifiers is a strict superset of 382769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor /// another set of qualifiers, not considering qualifier compatibility. 383769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor bool isStrictSupersetOf(Qualifiers Other) const; 384ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool operator==(Qualifiers Other) const { return Mask == Other.Mask; } 3860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; } 3870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall operator bool() const { return hasQualifiers(); } 3890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers &operator+=(Qualifiers R) { 3910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addQualifiers(R); 3920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return *this; 3930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Union two qualifier sets. If an enumerated qualifier appears 3960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // in both sets, use the one from the right. 3970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall friend Qualifiers operator+(Qualifiers L, Qualifiers R) { 3980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall L += R; 3990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return L; 4000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 401ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4023cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor Qualifiers &operator-=(Qualifiers R) { 4033cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor Mask = Mask & ~(R.Mask); 4043cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor return *this; 4053cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor } 4060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4073cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor /// \brief Compute the difference between two qualifier sets. 4083cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor friend Qualifiers operator-(Qualifiers L, Qualifiers R) { 4093cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor L -= R; 4103cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor return L; 4113cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor } 412ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string getAsString() const; 4140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string getAsString(const PrintingPolicy &Policy) const { 4150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string Buffer; 4160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getAsStringInternal(Buffer, Policy); 4170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Buffer; 4180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const; 4200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 4220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ID.AddInteger(Mask); 4230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4250953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate: 4260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 427f85e193739c953358c865005855253af4f68a497John McCall // bits: |0 1 2|3 .. 4|5 .. 7|8 ... 31| 428f85e193739c953358c865005855253af4f68a497John McCall // |C R V|GCAttr|Lifetime|AddressSpace| 4290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall uint32_t Mask; 4300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t GCAttrMask = 0x18; 4320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t GCAttrShift = 3; 433f85e193739c953358c865005855253af4f68a497John McCall static const uint32_t LifetimeMask = 0xE0; 434f85e193739c953358c865005855253af4f68a497John McCall static const uint32_t LifetimeShift = 5; 435f85e193739c953358c865005855253af4f68a497John McCall static const uint32_t AddressSpaceMask = ~(CVRMask|GCAttrMask|LifetimeMask); 436f85e193739c953358c865005855253af4f68a497John McCall static const uint32_t AddressSpaceShift = 8; 4370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 4380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 439ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses. 440ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv { 441ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_Default, 442ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_C, // __attribute__((cdecl)) 443ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_X86StdCall, // __attribute__((stdcall)) 444f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor CC_X86FastCall, // __attribute__((fastcall)) 44552fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik CC_X86ThisCall, // __attribute__((thiscall)) 446414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov CC_X86Pascal, // __attribute__((pascal)) 447414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov CC_AAPCS, // __attribute__((pcs("aapcs"))) 448414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov CC_AAPCS_VFP // __attribute__((pcs("aapcs-vfp"))) 449ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}; 450ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor 451200fa53fd420aa8369586f569dbece04930ad6a3John McCall/// A std::pair-like structure for storing a qualified type split 452200fa53fd420aa8369586f569dbece04930ad6a3John McCall/// into its local qualifiers and its locally-unqualified type. 453200fa53fd420aa8369586f569dbece04930ad6a3John McCallstruct SplitQualType { 454200fa53fd420aa8369586f569dbece04930ad6a3John McCall /// The locally-unqualified type. 455200fa53fd420aa8369586f569dbece04930ad6a3John McCall const Type *Ty; 456200fa53fd420aa8369586f569dbece04930ad6a3John McCall 457200fa53fd420aa8369586f569dbece04930ad6a3John McCall /// The local qualifiers. 458200fa53fd420aa8369586f569dbece04930ad6a3John McCall Qualifiers Quals; 459200fa53fd420aa8369586f569dbece04930ad6a3John McCall 460200fa53fd420aa8369586f569dbece04930ad6a3John McCall SplitQualType() : Ty(0), Quals() {} 461200fa53fd420aa8369586f569dbece04930ad6a3John McCall SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {} 462200fa53fd420aa8369586f569dbece04930ad6a3John McCall 463200fa53fd420aa8369586f569dbece04930ad6a3John McCall SplitQualType getSingleStepDesugaredType() const; // end of this file 464200fa53fd420aa8369586f569dbece04930ad6a3John McCall 465200fa53fd420aa8369586f569dbece04930ad6a3John McCall // Make llvm::tie work. 466200fa53fd420aa8369586f569dbece04930ad6a3John McCall operator std::pair<const Type *,Qualifiers>() const { 467200fa53fd420aa8369586f569dbece04930ad6a3John McCall return std::pair<const Type *,Qualifiers>(Ty, Quals); 468200fa53fd420aa8369586f569dbece04930ad6a3John McCall } 469200fa53fd420aa8369586f569dbece04930ad6a3John McCall 470200fa53fd420aa8369586f569dbece04930ad6a3John McCall friend bool operator==(SplitQualType a, SplitQualType b) { 471200fa53fd420aa8369586f569dbece04930ad6a3John McCall return a.Ty == b.Ty && a.Quals == b.Quals; 472200fa53fd420aa8369586f569dbece04930ad6a3John McCall } 473200fa53fd420aa8369586f569dbece04930ad6a3John McCall friend bool operator!=(SplitQualType a, SplitQualType b) { 474200fa53fd420aa8369586f569dbece04930ad6a3John McCall return a.Ty != b.Ty || a.Quals != b.Quals; 475200fa53fd420aa8369586f569dbece04930ad6a3John McCall } 476200fa53fd420aa8369586f569dbece04930ad6a3John McCall}; 4770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on 4790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers. This 4800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for 4810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int', 4820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc). 4830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 4840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we 4850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the 4860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer. To handle the packing/unpacking, we make QualType be a 4870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer. A third bit 4880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which 4890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure. 4900953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType { 4910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Thankfully, these are efficiently composable. 4920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>, 4930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::FastWidth> Value; 4940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *getExtQualsUnsafe() const { 4960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().get<const ExtQuals*>(); 4970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *getTypePtrUnsafe() const { 5000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().get<const Type*>(); 5010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ExtQualsTypeCommonBase *getCommonPtr() const { 5043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!isNull() && "Cannot retrieve a NULL type pointer"); 5053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall uintptr_t CommonPtrVal 5063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = reinterpret_cast<uintptr_t>(Value.getOpaqueValue()); 5073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1); 5083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal); 5093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 5103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 5110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall friend class QualifierCollector; 5120953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 5135cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType() {} 5141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5155cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType(const Type *Ptr, unsigned Quals) 5160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Value(Ptr, Quals) {} 5170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType(const ExtQuals *Ptr, unsigned Quals) 5180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Value(Ptr, Quals) {} 5190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 520a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor unsigned getLocalFastQualifiers() const { return Value.getInt(); } 521a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); } 5225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Retrieves a pointer to the underlying (unqualified) type. 5240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// This should really return a const Type, but it's not worth 5250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// changing all the users right now. 5261ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor /// 5271ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor /// This function requires that the type not be NULL. If the type might be 5281ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor /// NULL, use the (slightly less efficient) \c getTypePtrOrNull(). 5293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *getTypePtr() const; 530ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 5313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *getTypePtrOrNull() const; 5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5334d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain /// Retrieves a pointer to the name of the base type. 5344d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain const IdentifierInfo *getBaseTypeIdentifier() const; 5354d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain 53649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall /// Divides a QualType into its unqualified type and a set of local 53749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall /// qualifiers. 5383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType split() const; 53949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall 5405cf243a883872441d73ca49cea7e20de5802629bChris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 541f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall static QualType getFromOpaquePtr(const void *Ptr) { 5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType T; 543f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall T.Value.setFromOpaqueValue(const_cast<void*>(Ptr)); 5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T; 5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 547f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type &operator*() const { 5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *getTypePtr(); 5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 551f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type *operator->() const { 5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypePtr(); 5535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 555467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall bool isCanonical() const; 55654e14c4db764c0636160d26c5bbf491637c83a76John McCall bool isCanonicalAsParam() const; 557467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNull - Return true if this QualType doesn't point to a type yet. 5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNull() const { 5600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().isNull(); 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 563ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Determine whether this particular QualType instance has the 564a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "const" qualifier set, without looking through typedefs that may have 565a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "const" at a different level. 566a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalConstQualified() const { 567a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Const); 5680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 569ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 570a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is const-qualified. 571fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isConstQualified() const; 572ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 573ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Determine whether this particular QualType instance has the 574a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "restrict" qualifier set, without looking through typedefs that may have 575a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "restrict" at a different level. 576a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalRestrictQualified() const { 577a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Restrict); 578a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor } 579ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 580a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is restrict-qualified. 581fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isRestrictQualified() const; 582ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 583ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Determine whether this particular QualType instance has the 584a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "volatile" qualifier set, without looking through typedefs that may have 585a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "volatile" at a different level. 586a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalVolatileQualified() const { 587f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor return (getLocalFastQualifiers() & Qualifiers::Volatile); 5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 590a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is volatile-qualified. 591fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isVolatileQualified() const; 592ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 593a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has any 594ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// qualifiers, without looking through any typedefs that might add 595a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// qualifiers at a different level. 596a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool hasLocalQualifiers() const { 597a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return getLocalFastQualifiers() || hasLocalNonFastQualifiers(); 5980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 600a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type has any qualifiers. 601fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool hasQualifiers() const; 602ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 603a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has any 604a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType 605a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// instance. 606a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool hasLocalNonFastQualifiers() const { 607a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return Value.getPointer().is<const ExtQuals*>(); 6080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 6090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 610a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of qualifiers local to this particular QualType 611a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// instance, not including any qualifiers acquired through typedefs or 612a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// other sugar. 6133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers getLocalQualifiers() const; 6140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 615a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of qualifiers applied to this type. 616fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor Qualifiers getQualifiers() const; 617ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 618ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 619a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// local to this particular QualType instance, not including any qualifiers 620a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// acquired through typedefs or other sugar. 621a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor unsigned getLocalCVRQualifiers() const { 622f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor return getLocalFastQualifiers(); 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 624b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 625ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 626a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// applied to this type. 627fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor unsigned getCVRQualifiers() const; 628e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth 629bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isConstant(ASTContext& Ctx) const { 630bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return QualType::isConstant(*this, Ctx); 631bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 6321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 633f85e193739c953358c865005855253af4f68a497John McCall /// \brief Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10). 634f85e193739c953358c865005855253af4f68a497John McCall bool isPODType(ASTContext &Context) const; 635f85e193739c953358c865005855253af4f68a497John McCall 636f85e193739c953358c865005855253af4f68a497John McCall /// isCXX11PODType() - Return true if this is a POD type according to the 637f85e193739c953358c865005855253af4f68a497John McCall /// more relaxed rules of the C++11 standard, regardless of the current 638f85e193739c953358c865005855253af4f68a497John McCall /// compilation's language. 639f85e193739c953358c865005855253af4f68a497John McCall /// (C++0x [basic.types]p9) 640f85e193739c953358c865005855253af4f68a497John McCall bool isCXX11PODType(ASTContext &Context) const; 641ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 642f85e193739c953358c865005855253af4f68a497John McCall /// isTrivialType - Return true if this is a trivial type 643f85e193739c953358c865005855253af4f68a497John McCall /// (C++0x [basic.types]p9) 644ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool isTrivialType(ASTContext &Context) const; 645f85e193739c953358c865005855253af4f68a497John McCall 646f85e193739c953358c865005855253af4f68a497John McCall /// isTriviallyCopyableType - Return true if this is a trivially 647f85e193739c953358c865005855253af4f68a497John McCall /// copyable type (C++0x [basic.types]p9) 648f85e193739c953358c865005855253af4f68a497John McCall bool isTriviallyCopyableType(ASTContext &Context) const; 649f85e193739c953358c865005855253af4f68a497John McCall 6500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Don't promise in the API that anything besides 'const' can be 6510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // easily added. 6520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 653ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// addConst - add the specified type qualifier to this QualType. 6540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addConst() { 6550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addFastQualifiers(Qualifiers::Const); 6560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 6570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withConst() const { 6580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return withFastQualifiers(Qualifiers::Const); 6590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 6600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 661ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// addVolatile - add the specified type qualifier to this QualType. 662308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt void addVolatile() { 663308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt addFastQualifiers(Qualifiers::Volatile); 664308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt } 665308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt QualType withVolatile() const { 666308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt return withFastQualifiers(Qualifiers::Volatile); 667308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt } 66818932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek 66918932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek /// Add the restrict qualifier to this QualType. 67018932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek void addRestrict() { 67118932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek addFastQualifiers(Qualifiers::Restrict); 67218932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek } 67318932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek QualType withRestrict() const { 67418932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek return withFastQualifiers(Qualifiers::Restrict); 67518932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek } 676308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt 677a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall QualType withCVRQualifiers(unsigned CVR) const { 678a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall return withFastQualifiers(CVR); 679a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall } 680a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall 6810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addFastQualifiers(unsigned TQs) { 6820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(TQs & ~Qualifiers::FastMask) 6830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall && "non-fast qualifier bits set in mask!"); 6840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Value.setInt(Value.getInt() | TQs); 6850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 6860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 68749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalConst(); 68849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalVolatile(); 68949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalRestrict(); 69049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalCVRQualifiers(unsigned Mask); 6910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 69249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalFastQualifiers() { Value.setInt(0); } 69349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalFastQualifiers(unsigned Mask) { 6940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers"); 6950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Value.setInt(Value.getInt() & ~Mask); 6960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Creates a type with the given qualifiers in addition to any 6990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // qualifiers already on this type. 7000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withFastQualifiers(unsigned TQs) const { 7010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType T = *this; 7020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall T.addFastQualifiers(TQs); 7030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return T; 7040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 7051c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta 7060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Creates a type with exactly the given fast qualifiers, removing 7070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // any existing fast qualifiers. 70849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall QualType withExactLocalFastQualifiers(unsigned TQs) const { 70949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return withoutLocalFastQualifiers().withFastQualifiers(TQs); 7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 7120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Removes fast qualifiers, but leaves any extended qualifiers in place. 71349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall QualType withoutLocalFastQualifiers() const { 7140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType T = *this; 71549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall T.removeLocalFastQualifiers(); 7160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return T; 717c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 718971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 7193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType getCanonicalType() const; 7203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 721a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Return this type with all of the instance-specific qualifiers 722a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// removed, but without removing any qualifiers that may have been applied 723a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// through typedefs. 724a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); } 7251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 72662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \brief Retrieve the unqualified variant of the given type, 72762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// removing as little sugar as possible. 72862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 72962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// This routine looks through various kinds of sugar to find the 73062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// least-desugared type that is unqualified. For example, given: 73162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 73262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \code 73362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// typedef int Integer; 73462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// typedef const Integer CInteger; 73562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// typedef CInteger DifferenceType; 73662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \endcode 73762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 73862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// Executing \c getUnqualifiedType() on the type \c DifferenceType will 73962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// desugar until we hit the type \c Integer, which has no qualifiers on it. 74062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 74162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// The resulting type might still be qualified if it's an array 74262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// type. To strip qualifiers even from within an array type, use 74362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// ASTContext::getUnqualifiedArrayType. 74462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall inline QualType getUnqualifiedType() const; 74562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 74662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// getSplitUnqualifiedType - Retrieve the unqualified variant of the 74762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// given type, removing as little sugar as possible. 74862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 74962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// Like getUnqualifiedType(), but also returns the set of 75062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// qualifiers that were built up. 75162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 75262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// The resulting type might still be qualified if it's an array 75362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// type. To strip qualifiers even from within an array type, use 75462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// ASTContext::getUnqualifiedArrayType. 75562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall inline SplitQualType getSplitUnqualifiedType() const; 756ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 75761d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// \brief Determine whether this type is more qualified than the other 75861d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// given type, requiring exact equality for non-CVR qualifiers. 759e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 76061d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor 76161d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// \brief Determine whether this type is at least as qualified as the other 76261d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// given type, requiring exact equality for non-CVR qualifiers. 763e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 764ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 765e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getNonReferenceType() const; 7661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7676398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// \brief Determine the type of a (typically non-lvalue) expression with the 7686398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// specified result type. 769ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// 7706398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// This routine should be used for expressions for which the return type is 7716398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// explicitly specified (e.g., in a cast or call) and isn't necessarily 772ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// an lvalue. It removes a top-level reference (since there are no 7735291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// expressions of reference type) and deletes top-level cvr-qualifiers 7745291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// from non-class types (in C++) or all types (in C). 7756398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor QualType getNonLValueExprType(ASTContext &Context) const; 776ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 7772fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 7782fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 7792fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 7802fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 7812fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 7822fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// concrete. 7830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// 7840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Qualifiers are left in place. 7854ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType getDesugaredType(const ASTContext &Context) const { 78649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getDesugaredType(*this, Context); 78749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 78849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall 78949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall SplitQualType getSplitDesugaredType() const { 79049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getSplitDesugaredType(*this); 791bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 79298cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor 793f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor /// \brief Return the specified type with one level of "sugar" removed from 794ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// the type. 795f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor /// 796f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor /// This routine takes off the first typedef, typeof, etc. If the outer level 797f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor /// of the type is already concrete, it returns it unmodified. 798200fa53fd420aa8369586f569dbece04930ad6a3John McCall QualType getSingleStepDesugaredType(const ASTContext &Context) const { 799200fa53fd420aa8369586f569dbece04930ad6a3John McCall return getSingleStepDesugaredTypeImpl(*this, Context); 800200fa53fd420aa8369586f569dbece04930ad6a3John McCall } 801ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 802075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// IgnoreParens - Returns the specified type after dropping any 803075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// outer-level parentheses. 804075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType IgnoreParens() const { 805723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara if (isa<ParenType>(*this)) 806723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara return QualType::IgnoreParens(*this); 807723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara return *this; 808075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 809075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// operator==/!= - Indicate whether the specified types and qualifiers are 8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identical. 81250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor friend bool operator==(const QualType &LHS, const QualType &RHS) { 81350d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return LHS.Value == RHS.Value; 8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 81550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor friend bool operator!=(const QualType &LHS, const QualType &RHS) { 81650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return LHS.Value != RHS.Value; 8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 81849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall std::string getAsString() const { 81949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getAsString(split()); 82049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 82149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static std::string getAsString(SplitQualType split) { 822200fa53fd420aa8369586f569dbece04930ad6a3John McCall return getAsString(split.Ty, split.Quals); 82349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 82449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static std::string getAsString(const Type *ty, Qualifiers qs); 825d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 826d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString(const PrintingPolicy &Policy) const { 8275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string S; 828d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor getAsStringInternal(S, Policy); 8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return S; 8305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 831e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner void getAsStringInternal(std::string &Str, 83249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall const PrintingPolicy &Policy) const { 83349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getAsStringInternal(split(), Str, Policy); 83449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 83549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static void getAsStringInternal(SplitQualType split, std::string &out, 83649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall const PrintingPolicy &policy) { 837200fa53fd420aa8369586f569dbece04930ad6a3John McCall return getAsStringInternal(split.Ty, split.Quals, out, policy); 83849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 83949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static void getAsStringInternal(const Type *ty, Qualifiers qs, 84049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall std::string &out, 84149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall const PrintingPolicy &policy); 8421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 843c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump(const char *s) const; 844c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 8451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8463f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 8473f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 8483f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek } 8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 850ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 851ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 8521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 853f85e193739c953358c865005855253af4f68a497John McCall /// getObjCGCAttr - Returns gc attribute of this type. 8540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall inline Qualifiers::GC getObjCGCAttr() const; 855f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 856f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 857f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCWeak() const { 8580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getObjCGCAttr() == Qualifiers::Weak; 859f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 860f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 861f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 862f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCStrong() const { 8630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getObjCGCAttr() == Qualifiers::Strong; 864f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 8652455636163fdd18581d7fdae816433f886d88213Mike Stump 866f85e193739c953358c865005855253af4f68a497John McCall /// getObjCLifetime - Returns lifetime attribute of this type. 867f85e193739c953358c865005855253af4f68a497John McCall Qualifiers::ObjCLifetime getObjCLifetime() const { 868f85e193739c953358c865005855253af4f68a497John McCall return getQualifiers().getObjCLifetime(); 869f85e193739c953358c865005855253af4f68a497John McCall } 870f85e193739c953358c865005855253af4f68a497John McCall 871f85e193739c953358c865005855253af4f68a497John McCall bool hasNonTrivialObjCLifetime() const { 872f85e193739c953358c865005855253af4f68a497John McCall return getQualifiers().hasNonTrivialObjCLifetime(); 873f85e193739c953358c865005855253af4f68a497John McCall } 874f85e193739c953358c865005855253af4f68a497John McCall 875f85e193739c953358c865005855253af4f68a497John McCall bool hasStrongOrWeakObjCLifetime() const { 876f85e193739c953358c865005855253af4f68a497John McCall return getQualifiers().hasStrongOrWeakObjCLifetime(); 877f85e193739c953358c865005855253af4f68a497John McCall } 878f85e193739c953358c865005855253af4f68a497John McCall 8790d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall enum DestructionKind { 8800d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall DK_none, 881f85e193739c953358c865005855253af4f68a497John McCall DK_cxx_destructor, 882f85e193739c953358c865005855253af4f68a497John McCall DK_objc_strong_lifetime, 883f85e193739c953358c865005855253af4f68a497John McCall DK_objc_weak_lifetime 8840d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall }; 8850d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 8860d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// isDestructedType - nonzero if objects of this type require 8870d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// non-trivial work to clean up after. Non-zero because it's 8880d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// conceivable that qualifiers (objc_gc(weak)?) could make 8890d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// something require destruction. 8900d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall DestructionKind isDestructedType() const { 8910d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall return isDestructedTypeImpl(*this); 8920d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall } 8930d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 894ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Determine whether expressions of the given type are forbidden 8952b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// from being lvalues in C. 8962b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// 8972b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// The expression types that are forbidden to be lvalues are: 8982b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// - 'void', but not qualified void 8992b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// - function types 9002b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// 9012b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// The exact rule here is C99 6.3.2.1: 9022b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// An lvalue is an expression with an object type or an incomplete 9032b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// type other than void. 9042b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor bool isCForbiddenLValueType() const; 9052b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor 90685ea7aa961deac1d754f610af8062ae3f8b4e2a5Sebastian Redl /// \brief Determine whether this type has trivial copy/move-assignment 90785ea7aa961deac1d754f610af8062ae3f8b4e2a5Sebastian Redl /// semantics. 90885ea7aa961deac1d754f610af8062ae3f8b4e2a5Sebastian Redl bool hasTrivialAssignment(ASTContext &Context, bool Copying) const; 909ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 910bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate: 911bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // These methods are implemented in a separate translation unit; 912bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // "static"-ize them to avoid creating temporary QualTypes in the 913bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // caller. 914bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall static bool isConstant(QualType T, ASTContext& Ctx); 9154ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static QualType getDesugaredType(QualType T, const ASTContext &Context); 91649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static SplitQualType getSplitDesugaredType(QualType T); 91762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall static SplitQualType getSplitUnqualifiedTypeImpl(QualType type); 918200fa53fd420aa8369586f569dbece04930ad6a3John McCall static QualType getSingleStepDesugaredTypeImpl(QualType type, 919200fa53fd420aa8369586f569dbece04930ad6a3John McCall const ASTContext &C); 920075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static QualType IgnoreParens(QualType T); 9210d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall static DestructionKind isDestructedTypeImpl(QualType type); 9225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 9275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 9285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 930f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall typedef const ::clang::Type *SimpleType; 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 9324472fc641ea3069463798fb56a04043c28ea2910Douglas Gregor return Val.getTypePtr(); 9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 9371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9384e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 9394e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<> 940daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 9414e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic: 9424e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 9434e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return P.getAsOpaquePtr(); 9444e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 9454e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 9464e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return clang::QualType::getFromOpaquePtr(P); 9474e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 9480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Various qualifiers go in low bits. 9490eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 0 }; 9504e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}; 9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 95273af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 956ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Base class that is common to both the \c ExtQuals and \c Type 9573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// classes, which allows \c QualType to access the common fields between the 9583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// two. 9593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// 9603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQualsTypeCommonBase { 9613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQualsTypeCommonBase(const Type *baseType, QualType canon) 9623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall : BaseType(baseType), CanonicalType(canon) {} 9633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 9643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// \brief The "base" type of an extended qualifiers type (\c ExtQuals) or 9653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// a self-referential pointer (for \c Type). 9663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// 967ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// This pointer allows an efficient mapping from a QualType to its 9683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// underlying type pointer. 9693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *const BaseType; 9703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 9713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// \brief The canonical type of this type. A QualType. 9723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType CanonicalType; 9733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 9743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall friend class QualType; 9753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall friend class Type; 9763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall friend class ExtQuals; 9773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}; 978ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 9793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// ExtQuals - We can encode up to four bits in the low bits of a 9803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// type pointer, but there are many more type qualifiers that we want 9813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// to be able to apply to an arbitrary type. Therefore we have this 9823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// struct, intended to be heap-allocated and used by QualType to 9833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// store qualifiers. 9843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// 985ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers 9863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// in three low bits on the QualType pointer; a fourth bit records whether 9873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// the pointer is an ExtQuals node. The extended qualifiers (address spaces, 9883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// Objective-C GC attributes) are much more rare. 9893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { 9903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // NOTE: changing the fast qualifiers should be straightforward as 9913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // long as you don't make 'const' non-fast. 9923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // 1. Qualifiers: 9933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ). 9943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Fast qualifiers must occupy the low-order bits. 9953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // b) Update Qualifiers::FastWidth and FastMask. 9963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // 2. QualType: 9973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // a) Update is{Volatile,Restrict}Qualified(), defined inline. 9983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // b) Update remove{Volatile,Restrict}, defined near the end of 9993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // this header. 10003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // 3. ASTContext: 10013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // a) Update get{Volatile,Restrict}Type. 10023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 10033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// Quals - the immutable set of qualifiers applied by this 10043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// node; always contains extended qualifiers. 10053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers Quals; 10063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 10073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQuals *this_() { return this; } 10083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 10093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic: 1010ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ExtQuals(const Type *baseType, QualType canon, Qualifiers quals) 10113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall : ExtQualsTypeCommonBase(baseType, 10123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall canon.isNull() ? QualType(this_(), 0) : canon), 10133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals(quals) 10143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall { 10153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(Quals.hasNonFastQualifiers() 10163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall && "ExtQuals created with no fast qualifiers"); 10173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!Quals.hasFastQualifiers() 10183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall && "ExtQuals created with fast qualifiers"); 10193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 10203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 10213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers getQualifiers() const { return Quals; } 10223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 10233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); } 10243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); } 10253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 1026f85e193739c953358c865005855253af4f68a497John McCall bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); } 1027f85e193739c953358c865005855253af4f68a497John McCall Qualifiers::ObjCLifetime getObjCLifetime() const { 1028f85e193739c953358c865005855253af4f68a497John McCall return Quals.getObjCLifetime(); 1029f85e193739c953358c865005855253af4f68a497John McCall } 1030f85e193739c953358c865005855253af4f68a497John McCall 10313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall bool hasAddressSpace() const { return Quals.hasAddressSpace(); } 10323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned getAddressSpace() const { return Quals.getAddressSpace(); } 10333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 10343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *getBaseType() const { return BaseType; } 10353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 10363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic: 10373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall void Profile(llvm::FoldingSetNodeID &ID) const { 10383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Profile(ID, getBaseType(), Quals); 10393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 10403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall static void Profile(llvm::FoldingSetNodeID &ID, 10413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *BaseType, 10423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers Quals) { 10433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!"); 10443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ID.AddPointer(BaseType); 10453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals.Profile(ID); 10463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 10473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}; 10483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 1049ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief The kind of C++0x ref-qualifier associated with a function type, 1050ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// which determines whether a member function's "this" object can be an 1051c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// lvalue, rvalue, or neither. 1052c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregorenum RefQualifierKind { 1053c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief No ref-qualifier was provided. 1054c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RQ_None = 0, 1055c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief An lvalue ref-qualifier was provided (\c &). 1056c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RQ_LValue, 1057c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief An rvalue ref-qualifier was provided (\c &&). 1058c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RQ_RValue 1059c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor}; 1060ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 10615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 10635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 10645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 10655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 107272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 107572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 10805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 10815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 10825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 10855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10861ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass Type : public ExtQualsTypeCommonBase { 10875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 108972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class, 109027935ee59c30b0d8b610ab676aab8e65350af932John McCall#define LAST_TYPE(Class) TypeLast = Class, 109172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 109272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 109372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TagFirst = Record, TagLast = Enum 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 10951bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 10965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 1097c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Type(const Type&); // DO NOT IMPLEMENT. 1098c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall void operator=(const Type&); // DO NOT IMPLEMENT. 1099c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 1100b870b88df784c2940efce448ebfaf54dece14666John McCall /// Bitfields required by the Type class. 1101b870b88df784c2940efce448ebfaf54dece14666John McCall class TypeBitfields { 1102b870b88df784c2940efce448ebfaf54dece14666John McCall friend class Type; 1103b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall template <class T> friend class TypePropertyCache; 110427935ee59c30b0d8b610ab676aab8e65350af932John McCall 1105b870b88df784c2940efce448ebfaf54dece14666John McCall /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 1106b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned TC : 8; 1107b870b88df784c2940efce448ebfaf54dece14666John McCall 1108b870b88df784c2940efce448ebfaf54dece14666John McCall /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 1109b870b88df784c2940efce448ebfaf54dece14666John McCall /// Note that this should stay at the end of the ivars for Type so that 1110b870b88df784c2940efce448ebfaf54dece14666John McCall /// subclasses can pack their bitfields into the same word. 1111bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet unsigned Dependent : 1; 1112ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1113ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Whether this type somehow involves a template parameter, even 1114561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// if the resolution of the type does not depend on a template parameter. 1115561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor unsigned InstantiationDependent : 1; 1116ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1117b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief Whether this type is a variably-modified type (C99 6.7.5). 1118bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet unsigned VariablyModified : 1; 1119d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1120d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this type contains an unexpanded parameter pack 1121d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// (for C++0x variadic templates). 1122d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned ContainsUnexpandedParameterPack : 1; 1123ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 11241fb0caaa7bef765b85972274e3b434af2572c141John McCall /// \brief Nonzero if the cache (i.e. the bitfields here starting 11251fb0caaa7bef765b85972274e3b434af2572c141John McCall /// with 'Cache') is valid. If so, then this is a 11261fb0caaa7bef765b85972274e3b434af2572c141John McCall /// LangOptions::VisibilityMode+1. 11271fb0caaa7bef765b85972274e3b434af2572c141John McCall mutable unsigned CacheValidAndVisibility : 2; 1128ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1129093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola /// \brief True if the visibility was set explicitly in the source code. 1130093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola mutable unsigned CachedExplicitVisibility : 1; 1131093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola 1132b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief Linkage of this type. 1133b870b88df784c2940efce448ebfaf54dece14666John McCall mutable unsigned CachedLinkage : 2; 113407a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 1135ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Whether this type involves and local or unnamed types. 1136bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet mutable unsigned CachedLocalOrUnnamed : 1; 1137ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1138b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief FromAST - Whether this type comes from an AST file. 1139bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet mutable unsigned FromAST : 1; 1140b870b88df784c2940efce448ebfaf54dece14666John McCall 11411fb0caaa7bef765b85972274e3b434af2572c141John McCall bool isCacheValid() const { 11421fb0caaa7bef765b85972274e3b434af2572c141John McCall return (CacheValidAndVisibility != 0); 11431fb0caaa7bef765b85972274e3b434af2572c141John McCall } 11441fb0caaa7bef765b85972274e3b434af2572c141John McCall Visibility getVisibility() const { 11451fb0caaa7bef765b85972274e3b434af2572c141John McCall assert(isCacheValid() && "getting linkage from invalid cache"); 11461fb0caaa7bef765b85972274e3b434af2572c141John McCall return static_cast<Visibility>(CacheValidAndVisibility-1); 11471fb0caaa7bef765b85972274e3b434af2572c141John McCall } 1148093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola bool isVisibilityExplicit() const { 1149093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola assert(isCacheValid() && "getting linkage from invalid cache"); 1150093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola return CachedExplicitVisibility; 1151093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola } 11521fb0caaa7bef765b85972274e3b434af2572c141John McCall Linkage getLinkage() const { 11531fb0caaa7bef765b85972274e3b434af2572c141John McCall assert(isCacheValid() && "getting linkage from invalid cache"); 11541fb0caaa7bef765b85972274e3b434af2572c141John McCall return static_cast<Linkage>(CachedLinkage); 11551fb0caaa7bef765b85972274e3b434af2572c141John McCall } 11561fb0caaa7bef765b85972274e3b434af2572c141John McCall bool hasLocalOrUnnamedType() const { 11571fb0caaa7bef765b85972274e3b434af2572c141John McCall assert(isCacheValid() && "getting linkage from invalid cache"); 11581fb0caaa7bef765b85972274e3b434af2572c141John McCall return CachedLocalOrUnnamed; 11591fb0caaa7bef765b85972274e3b434af2572c141John McCall } 1160b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1161093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola enum { NumTypeBits = 19 }; 1162b870b88df784c2940efce448ebfaf54dece14666John McCall 1163b870b88df784c2940efce448ebfaf54dece14666John McCallprotected: 1164b870b88df784c2940efce448ebfaf54dece14666John McCall // These classes allow subclasses to somewhat cleanly pack bitfields 1165b870b88df784c2940efce448ebfaf54dece14666John McCall // into Type. 1166b870b88df784c2940efce448ebfaf54dece14666John McCall 1167b870b88df784c2940efce448ebfaf54dece14666John McCall class ArrayTypeBitfields { 1168b870b88df784c2940efce448ebfaf54dece14666John McCall friend class ArrayType; 1169b870b88df784c2940efce448ebfaf54dece14666John McCall 1170b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 1171b870b88df784c2940efce448ebfaf54dece14666John McCall 1172b870b88df784c2940efce448ebfaf54dece14666John McCall /// IndexTypeQuals - CVR qualifiers from declarations like 1173b870b88df784c2940efce448ebfaf54dece14666John McCall /// 'int X[static restrict 4]'. For function parameters only. 1174b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned IndexTypeQuals : 3; 1175b870b88df784c2940efce448ebfaf54dece14666John McCall 1176b870b88df784c2940efce448ebfaf54dece14666John McCall /// SizeModifier - storage class qualifiers from declarations like 1177b870b88df784c2940efce448ebfaf54dece14666John McCall /// 'int X[static restrict 4]'. For function parameters only. 1178b870b88df784c2940efce448ebfaf54dece14666John McCall /// Actually an ArrayType::ArraySizeModifier. 1179b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned SizeModifier : 3; 1180b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1181b870b88df784c2940efce448ebfaf54dece14666John McCall 1182b870b88df784c2940efce448ebfaf54dece14666John McCall class BuiltinTypeBitfields { 1183b870b88df784c2940efce448ebfaf54dece14666John McCall friend class BuiltinType; 1184b870b88df784c2940efce448ebfaf54dece14666John McCall 1185b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 1186b870b88df784c2940efce448ebfaf54dece14666John McCall 1187b870b88df784c2940efce448ebfaf54dece14666John McCall /// The kind (BuiltinType::Kind) of builtin type this is. 1188b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned Kind : 8; 1189b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1190b870b88df784c2940efce448ebfaf54dece14666John McCall 1191b870b88df784c2940efce448ebfaf54dece14666John McCall class FunctionTypeBitfields { 1192b870b88df784c2940efce448ebfaf54dece14666John McCall friend class FunctionType; 1193b870b88df784c2940efce448ebfaf54dece14666John McCall 1194b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 1195b870b88df784c2940efce448ebfaf54dece14666John McCall 1196b870b88df784c2940efce448ebfaf54dece14666John McCall /// Extra information which affects how the function is called, like 1197b870b88df784c2940efce448ebfaf54dece14666John McCall /// regparm and the calling convention. 11987e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor unsigned ExtInfo : 8; 1199b870b88df784c2940efce448ebfaf54dece14666John McCall 1200b870b88df784c2940efce448ebfaf54dece14666John McCall /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1201b870b88df784c2940efce448ebfaf54dece14666John McCall /// other bitfields. 1202b870b88df784c2940efce448ebfaf54dece14666John McCall /// The qualifiers are part of FunctionProtoType because... 1203b870b88df784c2940efce448ebfaf54dece14666John McCall /// 1204b870b88df784c2940efce448ebfaf54dece14666John McCall /// C++ 8.3.5p4: The return type, the parameter type list and the 1205b870b88df784c2940efce448ebfaf54dece14666John McCall /// cv-qualifier-seq, [...], are part of the function type. 1206b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned TypeQuals : 3; 1207ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1208c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief The ref-qualifier associated with a \c FunctionProtoType. 1209c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// 1210c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// This is a value of type \c RefQualifierKind. 1211c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor unsigned RefQualifier : 2; 1212b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1213b870b88df784c2940efce448ebfaf54dece14666John McCall 1214b870b88df784c2940efce448ebfaf54dece14666John McCall class ObjCObjectTypeBitfields { 1215b870b88df784c2940efce448ebfaf54dece14666John McCall friend class ObjCObjectType; 1216b870b88df784c2940efce448ebfaf54dece14666John McCall 1217b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 1218b870b88df784c2940efce448ebfaf54dece14666John McCall 1219b870b88df784c2940efce448ebfaf54dece14666John McCall /// NumProtocols - The number of protocols stored directly on this 1220b870b88df784c2940efce448ebfaf54dece14666John McCall /// object type. 1221b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned NumProtocols : 32 - NumTypeBits; 1222b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1223b870b88df784c2940efce448ebfaf54dece14666John McCall 1224b870b88df784c2940efce448ebfaf54dece14666John McCall class ReferenceTypeBitfields { 1225b870b88df784c2940efce448ebfaf54dece14666John McCall friend class ReferenceType; 1226b870b88df784c2940efce448ebfaf54dece14666John McCall 1227b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 1228b870b88df784c2940efce448ebfaf54dece14666John McCall 1229b870b88df784c2940efce448ebfaf54dece14666John McCall /// True if the type was originally spelled with an lvalue sigil. 1230b870b88df784c2940efce448ebfaf54dece14666John McCall /// This is never true of rvalue references but can also be false 1231b870b88df784c2940efce448ebfaf54dece14666John McCall /// on lvalue references because of C++0x [dcl.typedef]p9, 1232b870b88df784c2940efce448ebfaf54dece14666John McCall /// as follows: 1233b870b88df784c2940efce448ebfaf54dece14666John McCall /// 1234b870b88df784c2940efce448ebfaf54dece14666John McCall /// typedef int &ref; // lvalue, spelled lvalue 1235b870b88df784c2940efce448ebfaf54dece14666John McCall /// typedef int &&rvref; // rvalue 1236b870b88df784c2940efce448ebfaf54dece14666John McCall /// ref &a; // lvalue, inner ref, spelled lvalue 1237b870b88df784c2940efce448ebfaf54dece14666John McCall /// ref &&a; // lvalue, inner ref 1238b870b88df784c2940efce448ebfaf54dece14666John McCall /// rvref &a; // lvalue, inner ref, spelled lvalue 1239b870b88df784c2940efce448ebfaf54dece14666John McCall /// rvref &&a; // rvalue, inner ref 1240bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet unsigned SpelledAsLValue : 1; 1241b870b88df784c2940efce448ebfaf54dece14666John McCall 1242b870b88df784c2940efce448ebfaf54dece14666John McCall /// True if the inner type is a reference type. This only happens 1243b870b88df784c2940efce448ebfaf54dece14666John McCall /// in non-canonical forms. 1244bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet unsigned InnerRef : 1; 1245b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1246b870b88df784c2940efce448ebfaf54dece14666John McCall 124777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall class TypeWithKeywordBitfields { 124877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall friend class TypeWithKeyword; 124977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall 125077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall unsigned : NumTypeBits; 125177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall 125277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall /// An ElaboratedTypeKeyword. 8 bits for efficient access. 125377be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall unsigned Keyword : 8; 125477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall }; 125577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall 1256b870b88df784c2940efce448ebfaf54dece14666John McCall class VectorTypeBitfields { 1257b870b88df784c2940efce448ebfaf54dece14666John McCall friend class VectorType; 125807a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 1259b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 126071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 1261e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson /// VecKind - The kind of vector, either a generic vector type or some 1262e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson /// target-specific vector type such as for AltiVec or Neon. 1263cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson unsigned VecKind : 3; 1264b870b88df784c2940efce448ebfaf54dece14666John McCall 1265b870b88df784c2940efce448ebfaf54dece14666John McCall /// NumElements - The number of elements in the vector. 1266cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson unsigned NumElements : 29 - NumTypeBits; 1267b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1268b870b88df784c2940efce448ebfaf54dece14666John McCall 12699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall class AttributedTypeBitfields { 12709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall friend class AttributedType; 12719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 12729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall unsigned : NumTypeBits; 12739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 12749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// AttrKind - an AttributedType::Kind 12759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall unsigned AttrKind : 32 - NumTypeBits; 12769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall }; 12779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 1278b870b88df784c2940efce448ebfaf54dece14666John McCall union { 1279b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBitfields TypeBits; 1280b870b88df784c2940efce448ebfaf54dece14666John McCall ArrayTypeBitfields ArrayTypeBits; 12819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeBitfields AttributedTypeBits; 1282b870b88df784c2940efce448ebfaf54dece14666John McCall BuiltinTypeBitfields BuiltinTypeBits; 1283b870b88df784c2940efce448ebfaf54dece14666John McCall FunctionTypeBitfields FunctionTypeBits; 1284b870b88df784c2940efce448ebfaf54dece14666John McCall ObjCObjectTypeBitfields ObjCObjectTypeBits; 1285b870b88df784c2940efce448ebfaf54dece14666John McCall ReferenceTypeBitfields ReferenceTypeBits; 128677be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall TypeWithKeywordBitfields TypeWithKeywordBits; 1287b870b88df784c2940efce448ebfaf54dece14666John McCall VectorTypeBitfields VectorTypeBits; 1288b870b88df784c2940efce448ebfaf54dece14666John McCall }; 1289b870b88df784c2940efce448ebfaf54dece14666John McCall 1290b870b88df784c2940efce448ebfaf54dece14666John McCallprivate: 12913c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl /// \brief Set whether this type comes from an AST file. 1292ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setFromAST(bool V = true) const { 1293b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.FromAST = V; 129407a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl } 129507a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 1296b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall template <class T> friend class TypePropertyCache; 12971fb0caaa7bef765b85972274e3b434af2572c141John McCall 12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 1299124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 1300124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 1301ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Type(TypeClass tc, QualType canon, bool Dependent, 1302561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent, bool VariablyModified, 1303d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool ContainsUnexpandedParameterPack) 13043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall : ExtQualsTypeCommonBase(this, 13053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall canon.isNull() ? QualType(this_(), 0) : canon) { 1306b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.TC = tc; 1307b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.Dependent = Dependent; 1308561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TypeBits.InstantiationDependent = Dependent || InstantiationDependent; 1309b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.VariablyModified = VariablyModified; 1310d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 13111fb0caaa7bef765b85972274e3b434af2572c141John McCall TypeBits.CacheValidAndVisibility = 0; 1312093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola TypeBits.CachedExplicitVisibility = false; 1313b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.CachedLocalOrUnnamed = false; 1314b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.CachedLinkage = NoLinkage; 1315b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.FromAST = false; 1316b870b88df784c2940efce448ebfaf54dece14666John McCall } 13175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 13181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1319ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setDependent(bool D = true) { 1320ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeBits.Dependent = D; 1321561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (D) 1322561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TypeBits.InstantiationDependent = true; 1323561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1324ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setInstantiationDependent(bool D = true) { 1325561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TypeBits.InstantiationDependent = D; } 1326ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; 1327561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1328d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor void setContainsUnexpandedParameterPack(bool PP = true) { 1329d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor TypeBits.ContainsUnexpandedParameterPack = PP; 1330d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 1331d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 13328b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 1333b870b88df784c2940efce448ebfaf54dece14666John McCall TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); } 13341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13353c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl /// \brief Whether this type comes from an AST file. 1336b870b88df784c2940efce448ebfaf54dece14666John McCall bool isFromAST() const { return TypeBits.FromAST; } 133707a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 1338d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this type is or contains an unexpanded parameter 1339d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// pack, used to support C++0x variadic templates. 1340d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 1341d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// A type that contains a parameter pack shall be expanded by the 1342d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// ellipsis operator at some point. For example, the typedef in the 1343d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// following example contains an unexpanded parameter pack 'T': 1344d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 1345d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \code 1346d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// template<typename ...T> 1347d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// struct X { 1348d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// typedef T* pointer_types; // ill-formed; T is a parameter pack. 1349d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// }; 1350d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \endcode 1351d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 1352ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// Note that this routine does not specify which 1353ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool containsUnexpandedParameterPack() const { 1354d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return TypeBits.ContainsUnexpandedParameterPack; 1355d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 1356d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 13573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// Determines if this type would be canonical if it had no further 13583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// qualification. 1359467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall bool isCanonicalUnqualified() const { 13603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return CanonicalType == QualType(this, 0); 1361467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall } 13625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1363200fa53fd420aa8369586f569dbece04930ad6a3John McCall /// Pull a single level of sugar off of this locally-unqualified type. 1364200fa53fd420aa8369586f569dbece04930ad6a3John McCall /// Users should generally prefer SplitQualType::getSingleStepDesugaredType() 1365200fa53fd420aa8369586f569dbece04930ad6a3John McCall /// or QualType::getSingleStepDesugaredType(const ASTContext&). 1366200fa53fd420aa8369586f569dbece04930ad6a3John McCall QualType getLocallyUnqualifiedSingleStepDesugaredType() const; 1367200fa53fd420aa8369586f569dbece04930ad6a3John McCall 13681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 13695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 13701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 13725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 13735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 13741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// routine will need to determine if the size is actually required. 1375d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor /// 1376d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor /// \brief Def If non-NULL, and the type refers to some kind of declaration 1377d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor /// that can be completed (such as a C struct, C++ class, or Objective-C 1378d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor /// class), will be set to the declaration. 1379d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor bool isIncompleteType(NamedDecl **Def = 0) const; 1380d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner 1381d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 1382d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// type, in other words, not a function type. 1383d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner bool isIncompleteOrObjectType() const { 1384d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner return !isFunctionType(); 1385d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner } 1386ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 13872fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor /// \brief Determine whether this type is an object type. 13882fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor bool isObjectType() const { 13892fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor // C++ [basic.types]p8: 1390ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie // An object type is a (possibly cv-qualified) type that is not a 13912fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor // function type, not a reference type, and not a void type. 13922fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor return !isReferenceType() && !isFunctionType() && !isVoidType(); 13932fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor } 139464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 1395ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl /// isLiteralType - Return true if this is a literal type 1396ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl /// (C++0x [basic.types]p10) 1397ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl bool isLiteralType() const; 1398ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 1399636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth /// \brief Test if this type is a standard-layout type. 1400636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth /// (C++0x [basic.type]p9) 1401636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth bool isStandardLayoutType() const; 1402636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 14035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 1404ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 1405e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 14069b065ddabf572772991a4aadad5bf4921fac5069Tom Care /// isBuiltinType - returns true if the type is a builtin type. 14079b065ddabf572772991a4aadad5bf4921fac5069Tom Care bool isBuiltinType() const; 14089b065ddabf572772991a4aadad5bf4921fac5069Tom Care 1409e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 1410e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 14111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14122a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// isPlaceholderType - Test for a type which does not represent an 14132a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// actual type-system type but is instead used as a placeholder for 14142a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// various convenient purposes within Clang. All such types are 14152a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// BuiltinTypes. 14162a984cad5ac3fdceeff2bd99daa7b90979313475John McCall bool isPlaceholderType() const; 1417a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall const BuiltinType *getAsPlaceholderType() const; 14182a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 1419864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// isSpecificPlaceholderType - Test for a specific placeholder type. 1420864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall bool isSpecificPlaceholderType(unsigned K) const; 1421864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 142232509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall /// isNonOverloadPlaceholderType - Test for a placeholder type 142332509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall /// other than Overload; see BuiltinType::isNonOverloadPlaceholderType. 142432509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall bool isNonOverloadPlaceholderType() const; 142532509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall 142696d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 142796d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 14285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 142913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 143013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 143113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 143277a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor bool isWideCharType() const; 14335cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isChar16Type() const; 14345cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isChar32Type() const; 143520093b4bf698f292c664676987541d5103b65b15Douglas Gregor bool isAnyCharacterType() const; 14369d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor bool isIntegralType(ASTContext &Ctx) const; 1437ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 14382ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor /// \brief Determine whether this type is an integral or enumeration type. 14392ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor bool isIntegralOrEnumerationType() const; 14401274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor /// \brief Determine whether this type is an integral or unscoped enumeration 14411274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor /// type. 14421274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor bool isIntegralOrUnscopedEnumerationType() const; 1443ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 14445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 14455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 144602f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 144702f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 14485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 1449f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 14505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 1451aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov bool isHalfType() const; // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half) 14525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 14535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 1454c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 1455c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 1456c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 1457d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor bool isAggregateType() const; 1458aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth bool isFundamentalType() const; 1459aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth bool isCompoundType() const; 14601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1461c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 1462ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 1463c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 1464183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } 1465183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } 1466befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 146758f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 14685618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff bool isBlockPointerType() const; 14697154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff bool isVoidPointerType() const; 1470a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 14717c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isLValueReferenceType() const; 14727c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isRValueReferenceType() const; 1473bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isFunctionPointerType() const; 1474f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberPointerType() const; 1475f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberFunctionPointerType() const; 1476db68e28c05a67735211e688009890cf834c22e75Douglas Gregor bool isMemberDataPointerType() const; 1477c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 1478c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isConstantArrayType() const; 1479c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isIncompleteArrayType() const; 1480c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isVariableArrayType() const; 1481898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentSizedArrayType() const; 1482c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 14831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isClassType() const; 14841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isStructureType() const; 1485fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor bool isStructureOrClassType() const; 14864cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 1487368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 1488368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isVectorType() const; // GCC vector type. 1489213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman bool isExtVectorType() const; // Extended vector type. 1490f85e193739c953358c865005855253af4f68a497John McCall bool isObjCObjectPointerType() const; // pointer to ObjC object 1491f85e193739c953358c865005855253af4f68a497John McCall bool isObjCRetainableType() const; // ObjC object or block pointer 1492f85e193739c953358c865005855253af4f68a497John McCall bool isObjCLifetimeType() const; // (array of)* retainable type 1493f85e193739c953358c865005855253af4f68a497John McCall bool isObjCIndirectLifetimeType() const; // (pointer to)* lifetime type 1494f85e193739c953358c865005855253af4f68a497John McCall bool isObjCNSObjectType() const; // __attribute__((NSObject)) 149514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // FIXME: change this to 'raw' interface type, so we can used 'interface' type 149614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for the common case. 1497c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCObjectType() const; // NSString or typeof(*(id)0) 1498368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 1499368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedIdType() const; // id<foo> 1500470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const; // Class<foo> 1501569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor bool isObjCObjectOrInterfaceType() const; 150214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const; // id 150314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const; // Class 150413dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian bool isObjCSelType() const; // Class 1505de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff bool isObjCBuiltinType() const; // 'id' or 'Class' 1506f85e193739c953358c865005855253af4f68a497John McCall bool isObjCARCBridgableType() const; 1507f85e193739c953358c865005855253af4f68a497John McCall bool isCARCBridgableType() const; 150872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 15096e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 1510ffbe9b9c64ab2e94b9d48ec56e511f75826fc80aBenjamin Kramer bool isAtomicType() const; // C11 _Atomic() 1511898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1512f85e193739c953358c865005855253af4f68a497John McCall /// Determines if this type, which must satisfy 1513f85e193739c953358c865005855253af4f68a497John McCall /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather 1514f85e193739c953358c865005855253af4f68a497John McCall /// than implicitly __strong. 1515f85e193739c953358c865005855253af4f68a497John McCall bool isObjCARCImplicitlyUnretainedType() const; 1516f85e193739c953358c865005855253af4f68a497John McCall 1517f85e193739c953358c865005855253af4f68a497John McCall /// Return the implicit lifetime for this type, which must not be dependent. 1518f85e193739c953358c865005855253af4f68a497John McCall Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const; 1519f85e193739c953358c865005855253af4f68a497John McCall 1520daa8e4e888758d55a7a759dd4a91b83921cef222John McCall enum ScalarTypeKind { 15211d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall STK_CPointer, 15221d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall STK_BlockPointer, 15231d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall STK_ObjCObjectPointer, 1524daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_MemberPointer, 1525daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_Bool, 1526daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_Integral, 1527daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_Floating, 1528daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_IntegralComplex, 1529daa8e4e888758d55a7a759dd4a91b83921cef222John McCall STK_FloatingComplex 1530daa8e4e888758d55a7a759dd4a91b83921cef222John McCall }; 1531daa8e4e888758d55a7a759dd4a91b83921cef222John McCall /// getScalarTypeKind - Given that this is a scalar type, classify it. 1532daa8e4e888758d55a7a759dd4a91b83921cef222John McCall ScalarTypeKind getScalarTypeKind() const; 1533daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 1534898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 15351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// that its definition somehow depends on a template parameter 1536898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.type]). 1537b870b88df784c2940efce448ebfaf54dece14666John McCall bool isDependentType() const { return TypeBits.Dependent; } 1538ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1539561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Determine whether this type is an instantiation-dependent type, 1540561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// meaning that the type involves a template parameter (even if the 1541561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// definition does not actually depend on the type substituted for that 1542561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// template parameter). 1543ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool isInstantiationDependentType() const { 1544ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return TypeBits.InstantiationDependent; 1545561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1546ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 154735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor /// \brief Whether this type is a variably-modified type (C99 6.7.5). 1548b870b88df784c2940efce448ebfaf54dece14666John McCall bool isVariablyModifiedType() const { return TypeBits.VariablyModified; } 15493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 15503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// \brief Whether this type involves a variable-length array type 15513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// with a definite size. 15523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall bool hasSizedVLAType() const; 1553ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1554db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor /// \brief Whether this type is or contains a local or unnamed type. 1555db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor bool hasUnnamedOrLocalType() const; 1556ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1557063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor bool isOverloadableType() const; 155872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 15594033642464e8ba0982f88f34cffad808d247b393Douglas Gregor /// \brief Determine wither this type is a C++ elaborated-type-specifier. 15604033642464e8ba0982f88f34cffad808d247b393Douglas Gregor bool isElaboratedTypeSpecifier() const; 1561bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth 1562bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth bool canDecayToPointerType() const; 1563ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 15648958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 15658958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 15668958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 15676e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl /// interface types, as well as nullptr_t. 15688958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar bool hasPointerRepresentation() const; 15698958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 1570820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 1571820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 15721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool hasObjCPointerRepresentation() const; 1573820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 1574f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// \brief Determine whether this type has an integer representation 1575f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// of some sort, e.g., it is an integer type or a vector. 1576f60946222721d9ba3c059563935c17b84703187aDouglas Gregor bool hasIntegerRepresentation() const; 1577f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 1578f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// \brief Determine whether this type has an signed integer representation 1579f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// of some sort, e.g., it is an signed integer type or a vector. 1580f60946222721d9ba3c059563935c17b84703187aDouglas Gregor bool hasSignedIntegerRepresentation() const; 1581f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 1582f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// \brief Determine whether this type has an unsigned integer representation 1583f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// of some sort, e.g., it is an unsigned integer type or a vector. 1584f60946222721d9ba3c059563935c17b84703187aDouglas Gregor bool hasUnsignedIntegerRepresentation() const; 1585f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 15868eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor /// \brief Determine whether this type has a floating-point representation 15878eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor /// of some sort, e.g., it is a floating-point type or a vector thereof. 15888eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor bool hasFloatingRepresentation() const; 1589f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 1590c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 1591f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 1592f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 1593769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const RecordType *getAsStructureType() const; 1594898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 1595c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 15964cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 159714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // The following is a convenience method that returns an ObjCObjectPointerType 159814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for object declared using an interface. 159914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 160014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 1601759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian const ObjCObjectPointerType *getAsObjCQualifiedClassType() const; 1602c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *getAsObjCQualifiedInterfaceType() const; 1603a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 16041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1605c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor /// \brief Retrieves the CXXRecordDecl that this type refers to, either 1606ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// because the type is a RecordType or because it is the injected-class-name 1607c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor /// type of a class template or class template partial specialization. 1608c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor CXXRecordDecl *getAsCXXRecordDecl() const; 160934b41d939a1328f484511c6002ba2456db879a29Richard Smith 161034b41d939a1328f484511c6002ba2456db879a29Richard Smith /// \brief Get the AutoType whose type will be deduced for a variable with 161134b41d939a1328f484511c6002ba2456db879a29Richard Smith /// an initializer of this type. This looks through declarators like pointer 161234b41d939a1328f484511c6002ba2456db879a29Richard Smith /// types, but not through decltype or typedefs. 161334b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *getContainedAutoType() const; 1614ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1615d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// Member-template getAs<specific type>'. Look through sugar for 1616d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// an instance of <specific type>. This scheme will eventually 1617d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// replace the specific getAsXXXX methods above. 1618d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// 1619d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// There are some specializations of this member template listed 1620d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// immediately following this class. 16211a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek template <typename T> const T *getAs() const; 16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// A variant of getAs<> for array types which silently discards 16243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// qualifiers from the outermost type. 16253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ArrayType *getAsArrayTypeUnsafe() const; 16263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 1627d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// Member-template castAs<specific type>. Look through sugar for 1628d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// the underlying instance of <specific type>. 1629d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// 1630d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// This method has the same relationship to getAs<T> as cast<T> has 1631d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// to dyn_cast<T>; which is to say, the underlying type *must* 1632d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// have the intended type, and this method will never return null. 1633d0370f59e79702ac908c81bf556519f91e9ca297John McCall template <typename T> const T *castAs() const; 1634d0370f59e79702ac908c81bf556519f91e9ca297John McCall 1635d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// A variant of castAs<> for array type which silently discards 1636d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// qualifiers from the outermost type. 1637d0370f59e79702ac908c81bf556519f91e9ca297John McCall const ArrayType *castAsArrayTypeUnsafe() const; 1638d0370f59e79702ac908c81bf556519f91e9ca297John McCall 1639d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// getBaseElementTypeUnsafe - Get the base element type of this 1640d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// type, potentially discarding type qualifiers. This method 1641d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// should never be used when type qualifiers are meaningful. 1642d0370f59e79702ac908c81bf556519f91e9ca297John McCall const Type *getBaseElementTypeUnsafe() const; 1643d0370f59e79702ac908c81bf556519f91e9ca297John McCall 1644c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 1645c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// element type of the array, potentially with type qualifiers missing. 1646c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// This method should never be used when type qualifiers are meaningful. 1647c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 16481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1649f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// getPointeeType - If this is a pointer, ObjC object pointer, or block 1650f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// pointer, this returns the respective pointee. 165114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const; 16521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1653bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// getUnqualifiedDesugaredType() - Return the specified type with 1654bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// any "sugar" removed from the type, removing any typedefs, 1655bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// typeofs, etc., as well as any qualifiers. 1656bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *getUnqualifiedDesugaredType() const; 16571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 16595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 16605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 1662d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 16635f3827cabd526d0dd5f291d46c310103cebe7a44Eli Friedman /// or an enum decl which has a signed representation. 16645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 16655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 1667ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], 16685f3827cabd526d0dd5f291d46c310103cebe7a44Eli Friedman /// or an enum decl which has an unsigned representation. 16695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 1670d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 1671ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// Determines whether this is an integer type that is signed or an 1672575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor /// enumeration types whose underlying type is a signed integer type. 1673575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor bool isSignedIntegerOrEnumerationType() const; 1674ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1675ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// Determines whether this is an integer type that is unsigned or an 1676575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor /// enumeration types whose underlying type is a unsigned integer type. 1677575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor bool isUnsignedIntegerOrEnumerationType() const; 1678575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 16795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 16809bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 16819bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 16823c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 1683c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 168422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 168522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// set of type specifiers. 168622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman bool isSpecifierType() const; 168722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 16880b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor /// \brief Determine the linkage of this type. 168960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor Linkage getLinkage() const; 16901fb0caaa7bef765b85972274e3b434af2572c141John McCall 16911fb0caaa7bef765b85972274e3b434af2572c141John McCall /// \brief Determine the visibility of this type. 16921fb0caaa7bef765b85972274e3b434af2572c141John McCall Visibility getVisibility() const; 16931fb0caaa7bef765b85972274e3b434af2572c141John McCall 1694093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola /// \brief Return true if the visibility was explicitly set is the code. 1695093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola bool isVisibilityExplicit() const; 1696093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola 16971fb0caaa7bef765b85972274e3b434af2572c141John McCall /// \brief Determine the linkage and visibility of this type. 16981fb0caaa7bef765b85972274e3b434af2572c141John McCall std::pair<Linkage,Visibility> getLinkageAndVisibility() const; 1699ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 170060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor /// \brief Note that the linkage is no longer known. 170160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor void ClearLinkageCache(); 1702ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 170360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor const char *getTypeClassName() const; 17040b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1705ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall QualType getCanonicalTypeInternal() const { 1706ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall return CanonicalType; 1707ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall } 1708ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h 1709b5f2c419842d016892b9c976d4d6e91880e0e43aArgyrios Kyrtzidis LLVM_ATTRIBUTE_USED void dump() const; 1710f85e193739c953358c865005855253af4f68a497John McCall 17115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 1712be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis 1713c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl friend class ASTReader; 1714a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl friend class ASTWriter; 17155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1717183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const { 1718183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall return dyn_cast<TypedefType>(this); 1719183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall} 1720183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 1721183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to 1722183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration. 1723183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base) 1724183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \ 1725183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \ 17260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return dyn_cast<Class##Type>(CanonicalType); \ 1727d0370f59e79702ac908c81bf556519f91e9ca297John McCall} \ 1728d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <> inline const Class##Type *Type::castAs() const { \ 1729d0370f59e79702ac908c81bf556519f91e9ca297John McCall return cast<Class##Type>(CanonicalType); \ 1730183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall} 1731183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def" 1732183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 1733183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 17345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 17355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 17365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 17375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 17385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 1739e0a22d06888c13989b3f72db319f1d498bf69153John McCall#define BUILTIN_TYPE(Id, SingletonId) Id, 1740e0a22d06888c13989b3f72db319f1d498bf69153John McCall#define LAST_BUILTIN_TYPE(Id) LastKind = Id 1741e0a22d06888c13989b3f72db319f1d498bf69153John McCall#include "clang/AST/BuiltinTypes.def" 17425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 174371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 17445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 17451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BuiltinType(Kind K) 174635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent), 1747561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/(K == Dependent), 1748d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 1749d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*Unexpanded paramter pack=*/false) { 1750b870b88df784c2940efce448ebfaf54dece14666John McCall BuiltinTypeBits.Kind = K; 175171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 17521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1753b870b88df784c2940efce448ebfaf54dece14666John McCall Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); } 175430c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor const char *getName(const PrintingPolicy &Policy) const; 17551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1756bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1757bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1758bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1759680523a91dd3351389667c8de17121ba7ae82673John McCall bool isInteger() const { 176071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Bool && getKind() <= Int128; 1761680523a91dd3351389667c8de17121ba7ae82673John McCall } 1762680523a91dd3351389667c8de17121ba7ae82673John McCall 1763680523a91dd3351389667c8de17121ba7ae82673John McCall bool isSignedInteger() const { 176471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Char_S && getKind() <= Int128; 1765680523a91dd3351389667c8de17121ba7ae82673John McCall } 1766680523a91dd3351389667c8de17121ba7ae82673John McCall 1767680523a91dd3351389667c8de17121ba7ae82673John McCall bool isUnsignedInteger() const { 176871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Bool && getKind() <= UInt128; 1769680523a91dd3351389667c8de17121ba7ae82673John McCall } 1770680523a91dd3351389667c8de17121ba7ae82673John McCall 1771680523a91dd3351389667c8de17121ba7ae82673John McCall bool isFloatingPoint() const { 1772aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov return getKind() >= Half && getKind() <= LongDouble; 1773680523a91dd3351389667c8de17121ba7ae82673John McCall } 1774680523a91dd3351389667c8de17121ba7ae82673John McCall 177585def357129b6cdfd69a66ad0e6994506418a2a9John McCall /// Determines whether the given kind corresponds to a placeholder type. 177685def357129b6cdfd69a66ad0e6994506418a2a9John McCall static bool isPlaceholderTypeKind(Kind K) { 177785def357129b6cdfd69a66ad0e6994506418a2a9John McCall return K >= Overload; 177885def357129b6cdfd69a66ad0e6994506418a2a9John McCall } 177985def357129b6cdfd69a66ad0e6994506418a2a9John McCall 1780864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// Determines whether this type is a placeholder type, i.e. a type 1781864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// which cannot appear in arbitrary positions in a fully-formed 1782864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// expression. 17832a984cad5ac3fdceeff2bd99daa7b90979313475John McCall bool isPlaceholderType() const { 178485def357129b6cdfd69a66ad0e6994506418a2a9John McCall return isPlaceholderTypeKind(getKind()); 17852a984cad5ac3fdceeff2bd99daa7b90979313475John McCall } 17862a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 178732509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall /// Determines whether this type is a placeholder type other than 178832509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall /// Overload. Most placeholder types require only syntactic 178932509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall /// information about their context in order to be resolved (e.g. 179032509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall /// whether it is a call expression), which means they can (and 179132509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall /// should) be resolved in an earlier "phase" of analysis. 179232509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall /// Overload expressions sometimes pick up further information 179332509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall /// from their context, like whether the context expects a 179432509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall /// specific function-pointer type, and so frequently need 179532509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall /// special treatment. 179632509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall bool isNonOverloadPlaceholderType() const { 179732509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall return getKind() > Overload; 179832509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall } 179932509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall 18005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 18015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 18025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 18055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 18065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 18075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 18085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 18095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 181035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(Complex, CanonicalPtr, Element->isDependentType(), 1811561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Element->isInstantiationDependentType(), 1812d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Element->isVariablyModifiedType(), 1813d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Element->containsUnexpandedParameterPack()), 1814898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(Element) { 18155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 181760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 18185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 18201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1821bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1822bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1823bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 18245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 18255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 18265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 18285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 18295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 18325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 18335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1835075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// ParenType - Sugar for parentheses used when specifying types. 1836075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// 1837075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenType : public Type, public llvm::FoldingSetNode { 1838075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Inner; 1839075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1840075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenType(QualType InnerType, QualType CanonType) : 1841075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Type(Paren, CanonType, InnerType->isDependentType(), 1842561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InnerType->isInstantiationDependentType(), 1843d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor InnerType->isVariablyModifiedType(), 1844d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor InnerType->containsUnexpandedParameterPack()), 1845075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner(InnerType) { 1846075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1847075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara friend class ASTContext; // ASTContext creates these. 1848075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1849075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic: 1850075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1851075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType getInnerType() const { return Inner; } 1852075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1853075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara bool isSugared() const { return true; } 1854075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType desugar() const { return getInnerType(); } 1855075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1856075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara void Profile(llvm::FoldingSetNodeID &ID) { 1857075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Profile(ID, getInnerType()); 1858075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1859075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) { 1860075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner.Profile(ID); 1861075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1862075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1863075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static bool classof(const Type *T) { return T->getTypeClass() == Paren; } 1864075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static bool classof(const ParenType *) { return true; } 1865075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}; 1866075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 186768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 1868bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// 186968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 1870bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType PointeeType; 18715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 187335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(Pointer, CanonicalPtr, Pointee->isDependentType(), 1874561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Pointee->isInstantiationDependentType(), 1875d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->isVariablyModifiedType(), 1876ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Pointee->containsUnexpandedParameterPack()), 187735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor PointeeType(Pointee) { 18785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 188060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 18815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 188368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 188468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 1885bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1886bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1887bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 18885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 18895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 18905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 18925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 18935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 18965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 18975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18995618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type. 19005618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as 19015618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 19025618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// 19035618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 19045618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 19055618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 190635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(BlockPointer, CanonicalCls, Pointee->isDependentType(), 1907561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Pointee->isInstantiationDependentType(), 1908d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->isVariablyModifiedType(), 1909d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->containsUnexpandedParameterPack()), 1910898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor PointeeType(Pointee) { 19115618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 19125618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff friend class ASTContext; // ASTContext creates these. 1913ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 19145618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic: 19151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19165618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 19175618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType getPointeeType() const { return PointeeType; } 19185618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 1919bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1920bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1921bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 19225618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 19235618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Profile(ID, getPointeeType()); 19245618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 19255618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 19265618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 19275618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 19281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 19301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == BlockPointer; 19315618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 19325618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 19335618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}; 19345618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 19357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 19365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 193768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 193868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType PointeeType; 193968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 19407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected: 194154e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, 194254e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) : 194335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(tc, CanonicalRef, Referencee->isDependentType(), 1944561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Referencee->isInstantiationDependentType(), 1945d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Referencee->isVariablyModifiedType(), 1946ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Referencee->containsUnexpandedParameterPack()), 1947ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie PointeeType(Referencee) 1948d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor { 1949b870b88df784c2940efce448ebfaf54dece14666John McCall ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue; 1950b870b88df784c2940efce448ebfaf54dece14666John McCall ReferenceTypeBits.InnerRef = Referencee->isReferenceType(); 19515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1952ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 19535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1954b870b88df784c2940efce448ebfaf54dece14666John McCall bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; } 1955b870b88df784c2940efce448ebfaf54dece14666John McCall bool isInnerRef() const { return ReferenceTypeBits.InnerRef; } 1956ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 195754e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType getPointeeTypeAsWritten() const { return PointeeType; } 195854e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType getPointeeType() const { 195954e14c4db764c0636160d26c5bbf491637c83a76John McCall // FIXME: this might strip inner qualifiers; okay? 196054e14c4db764c0636160d26c5bbf491637c83a76John McCall const ReferenceType *T = this; 196171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall while (T->isInnerRef()) 1962d0370f59e79702ac908c81bf556519f91e9ca297John McCall T = T->PointeeType->castAs<ReferenceType>(); 196354e14c4db764c0636160d26c5bbf491637c83a76John McCall return T->PointeeType; 196454e14c4db764c0636160d26c5bbf491637c83a76John McCall } 196568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 19665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 196771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall Profile(ID, PointeeType, isSpelledAsLValue()); 19685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 196954e14c4db764c0636160d26c5bbf491637c83a76John McCall static void Profile(llvm::FoldingSetNodeID &ID, 197054e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType Referencee, 197154e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) { 19725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 197354e14c4db764c0636160d26c5bbf491637c83a76John McCall ID.AddBoolean(SpelledAsLValue); 19745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19767c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 19777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference || 19787c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl T->getTypeClass() == RValueReference; 19797c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 19805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 19817c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 19827c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 19837c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 19847c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 19857c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType { 198654e14c4db764c0636160d26c5bbf491637c83a76John McCall LValueReferenceType(QualType Referencee, QualType CanonicalRef, 198754e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) : 198854e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue) 198954e14c4db764c0636160d26c5bbf491637c83a76John McCall {} 19907c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 19917c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 1992bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1993bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1994bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 19957c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 19967c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference; 19977c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 19987c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 19997c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 20007c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 20017c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 20027c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 20037c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType { 20047c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 200554e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(RValueReference, Referencee, CanonicalRef, false) { 20067c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 20077c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 20087c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 2009bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2010bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2011bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 20127c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 20137c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == RValueReference; 20147c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 20157c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 2016f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}; 2017f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 2018f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 2019f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// 2020f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 2021f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType PointeeType; 2022f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 2023f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 2024f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class; 2025f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 2026f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 2027f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Type(MemberPointer, CanonicalPtr, 202835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Cls->isDependentType() || Pointee->isDependentType(), 2029ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie (Cls->isInstantiationDependentType() || 2030561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Pointee->isInstantiationDependentType()), 2031d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->isVariablyModifiedType(), 2032ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie (Cls->containsUnexpandedParameterPack() || 2033d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->containsUnexpandedParameterPack())), 2034f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointeeType(Pointee), Class(Cls) { 2035f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 2036f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl friend class ASTContext; // ASTContext creates these. 2037ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2038f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic: 2039f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType getPointeeType() const { return PointeeType; } 2040f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 20410bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Returns true if the member type (i.e. the pointee type) is a 20420bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// function type rather than a data-member type. 20430bab0cdab751248ca389a5592bcb70eac5d39260John McCall bool isMemberFunctionPointer() const { 20440bab0cdab751248ca389a5592bcb70eac5d39260John McCall return PointeeType->isFunctionProtoType(); 20450bab0cdab751248ca389a5592bcb70eac5d39260John McCall } 20460bab0cdab751248ca389a5592bcb70eac5d39260John McCall 20470bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Returns true if the member type (i.e. the pointee type) is a 20480bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// data type rather than a function type. 20490bab0cdab751248ca389a5592bcb70eac5d39260John McCall bool isMemberDataPointer() const { 20500bab0cdab751248ca389a5592bcb70eac5d39260John McCall return !PointeeType->isFunctionProtoType(); 20510bab0cdab751248ca389a5592bcb70eac5d39260John McCall } 20520bab0cdab751248ca389a5592bcb70eac5d39260John McCall 2053f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *getClass() const { return Class; } 2054f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 2055bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2056bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2057bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2058f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 2059f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Profile(ID, getPointeeType(), getClass()); 2060f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 2061f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 2062f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class) { 2063f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 2064f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Class); 2065f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 2066f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 2067f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const Type *T) { 2068f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getTypeClass() == MemberPointer; 2069f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 2070f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const MemberPointerType *) { return true; } 20715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 20725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 20745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 20752e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 20765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 20775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 2078898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 2079898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// with a star size (e.g. int X[*]). 2080898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// 'static' is only allowed on function parameters. 20815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 20825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 20835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 20845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2085fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 2086fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 20871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2088fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 2089898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // C++ [temp.dep.type]p1: 2090898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // A type is dependent if it is... 2091898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // - an array type constructed from any dependent type or whose 2092898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // size is specified by a constant expression that is 2093898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // value-dependent, 2094c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 2095d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ArraySizeModifier sm, unsigned tq, 2096d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool ContainsUnexpandedParameterPack) 209735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray, 2098561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor et->isInstantiationDependentType() || tc == DependentSizedArray, 2099d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (tc == VariableArray || et->isVariablyModifiedType()), 2100d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ContainsUnexpandedParameterPack), 210171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ElementType(et) { 2102b870b88df784c2940efce448ebfaf54dece14666John McCall ArrayTypeBits.IndexTypeQuals = tq; 2103b870b88df784c2940efce448ebfaf54dece14666John McCall ArrayTypeBits.SizeModifier = sm; 210471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2106fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 210760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 2108fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 2109fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 2110ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 2111b870b88df784c2940efce448ebfaf54dece14666John McCall return ArraySizeModifier(ArrayTypeBits.SizeModifier); 2112ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 21130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers getIndexTypeQualifiers() const { 211471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers()); 211571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 211671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall unsigned getIndexTypeCVRQualifiers() const { 2117b870b88df784c2940efce448ebfaf54dece14666John McCall return ArrayTypeBits.IndexTypeQuals; 21180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 21191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2120fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 2121fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 2122c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 2123898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == IncompleteArray || 2124898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == DependentSizedArray; 2125fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 2126fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 2127fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 2128fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 21297e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of 21307e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size. For example, the canonical 21317e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 21327e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404. 21332e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 2134fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 21351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21360be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 2137c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 2138d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(ConstantArray, et, can, sm, tq, 2139d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor et->containsUnexpandedParameterPack()), 21407e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Size(size) {} 21417e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected: 21427e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayType(TypeClass tc, QualType et, QualType can, 21437e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 2144ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()), 2145d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Size(size) {} 2146fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 2147fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 2148c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const llvm::APInt &getSize() const { return Size; } 2149bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2150bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2151bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2152ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 21532767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor /// \brief Determine the number of bits required to address a member of 21542767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // an array with the given element type and number of elements. 21552767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor static unsigned getNumAddressingBits(ASTContext &Context, 21562767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor QualType ElementType, 21572767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor const llvm::APInt &NumElements); 2158ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 21592767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor /// \brief Determine the maximum number of active bits that an array's size 21602767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor /// can require, which limits the maximum size of the array. 21612767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor static unsigned getMaxSizeBits(ASTContext &Context); 2162ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2163fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 21641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, getElementType(), getSize(), 21650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers()); 2166fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 2167fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 21680be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 21690be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner unsigned TypeQuals) { 2170fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 2171fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 21720be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 21730be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 2174fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 21757e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 217646a617a792bfab0d9b1e057371ea3b9540802226John McCall return T->getTypeClass() == ConstantArray; 2177fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 2178fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 2179fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 2180fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 2181da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 2182da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 2183da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified. 2184c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 21857e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 2186c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 21877e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq) 2188ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : ArrayType(IncompleteArray, et, can, sm, tq, 2189d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor et->containsUnexpandedParameterPack()) {} 2190c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 2191c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 2192bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2193bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2194bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 21951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 21961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == IncompleteArray; 2197c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 2198c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 21991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2200c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 22011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2202c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 22030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Profile(ID, getElementType(), getSizeModifier(), 22040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getIndexTypeCVRQualifiers()); 2205c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 22061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22070be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 22080be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 2209c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 22100be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 22110be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 2212c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 2213c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 2214c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2215da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 2216da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 2217da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 2218da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 2219da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 2220da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean 2221da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type 2222da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically: 2223da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 2224da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) { 2225da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Y[x]; 2226da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ++x; 2227da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Z[x]; 2228da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// } 2229da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 22302e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 22311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// SizeExpr - An assignment expression. VLA's are only permitted within 22321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// a function block. 2233b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek Stmt *SizeExpr; 22347e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 22357e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 22367e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 2237c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 22387e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 22397e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 2240ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : ArrayType(VariableArray, et, can, sm, tq, 2241d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor et->containsUnexpandedParameterPack()), 22427e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 22435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 22444b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 22455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 22461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getSizeExpr() const { 2247b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // We use C-style casts instead of cast<> here because we do not wish 2248b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 2249b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek return (Expr*) SizeExpr; 2250b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek } 22517e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 22527e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 22537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 22541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2255bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2256bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2257bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 22581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 22591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == VariableArray; 22605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2261fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 22621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 226392866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 22641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22652bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 2266b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Cannot unique VariableArrayTypes."); 22672bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 22685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 22695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2270898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in 2271898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example: 2272cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// 2273cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code 22741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size> 2275898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array { 2276898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// T data[Size]; 2277898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// }; 2278cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode 2279cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// 2280898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is 2281898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will 2282898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 2283898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType { 22844ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 22851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2286cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// \brief An assignment expression that will instantiate to the 2287898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// size of the array. 2288cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// 2289cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// The expression itself might be NULL, in which case the array 2290cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// type will have its size deduced from an initializer. 2291898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Stmt *SizeExpr; 2292cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor 22937e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 22947e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 22951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22964ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can, 229704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *e, ArraySizeModifier sm, unsigned tq, 2298d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceRange brackets); 2299d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2300898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class ASTContext; // ASTContext creates these. 2301898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2302898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic: 23031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getSizeExpr() const { 2304898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // We use C-style casts instead of cast<> here because we do not wish 2305898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 2306898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return (Expr*) SizeExpr; 2307898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 23087e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 23097e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 23107e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 23111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2312bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2313bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2314bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 23151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 23161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == DependentSizedArray; 2317898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 2318898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 23191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2320898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class StmtIteratorBase; 23211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2323898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 23241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, Context, getElementType(), 23250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); 2326898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 23271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23284ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 23291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType ET, ArraySizeModifier SizeMod, 233004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, Expr *E); 2331898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}; 2332898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2333f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 23349cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example: 23359cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code 23369cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size> 23379cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector { 23389cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 23399cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// } 23409cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode 23412ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { 23424ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 23439cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr; 23449cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor /// ElementType - The element type of the array. 23459cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType ElementType; 23469cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation loc; 23471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23484ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType, 2349d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType can, Expr *SizeExpr, SourceLocation loc); 2350d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 23519cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor friend class ASTContext; 23529cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 23539cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic: 23542ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 23559cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType getElementType() const { return ElementType; } 23569cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation getAttributeLoc() const { return loc; } 23579cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 2358bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2359bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2360bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 23611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 23621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == DependentSizedExtVector; 23639cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor } 23641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const DependentSizedExtVectorType *) { return true; } 23652ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 23662ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 23672ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor Profile(ID, Context, getElementType(), getSizeExpr()); 23682ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 23691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23704ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 23712ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr); 23729cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor}; 23731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23749cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 237573322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 23761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in 237782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration. 237882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the 237973322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 23805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 2381788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattnerpublic: 2382e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson enum VectorKind { 2383e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson GenericVector, // not a target-specific vector type 2384e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson AltiVecVector, // is AltiVec vector 2385e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson AltiVecPixel, // is AltiVec 'vector Pixel' 2386e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson AltiVecBool, // is AltiVec 'vector bool ...' 2387491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson NeonVector, // is ARM Neon vector 2388491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson NeonPolyVector // is ARM Neon polynomial vector 2389788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner }; 239073322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 23915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 23925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 23931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 239482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson VectorType(QualType vecType, unsigned nElements, QualType canonType, 2395d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorKind vecKind); 2396ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 23971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump VectorType(TypeClass tc, QualType vecType, unsigned nElements, 2398d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType canonType, VectorKind vecKind); 2399d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 24005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 2401ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 24025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 24031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 2405b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getNumElements() const { return VectorTypeBits.NumElements; } 24065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2407bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2408bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2409bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2410e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorKind getVectorKind() const { 2411e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson return VectorKind(VectorTypeBits.VecKind); 241271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2413788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner 24145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 241571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall Profile(ID, getElementType(), getNumElements(), 2416e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson getTypeClass(), getVectorKind()); 24175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 241982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson unsigned NumElements, TypeClass TypeClass, 2420e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorKind VecKind) { 24215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 24225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 242373322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 2424e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson ID.AddInteger(VecKind); 242573322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 24260b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 24271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 24281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 24295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 24315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2433213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using 2434213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 2435213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 2436fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 2437fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 2438213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType { 2439213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 2440e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {} 244173322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 244273322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 244388dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 244488dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 244588dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 244688dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 244788dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 244888dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 244988dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 245088dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 2451e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 2452353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman static int getNumericAccessorIdx(char c) { 245388dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 2454353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman default: return -1; 2455353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '0': return 0; 2456353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '1': return 1; 2457353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '2': return 2; 2458353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '3': return 3; 2459353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '4': return 4; 2460353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '5': return 5; 2461353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '6': return 6; 2462353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '7': return 7; 2463353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '8': return 8; 2464353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '9': return 9; 2465131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'A': 2466353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'a': return 10; 2467131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'B': 2468353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'b': return 11; 2469131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'C': 2470353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'c': return 12; 2471131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'D': 2472353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'd': return 13; 2473131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'E': 2474353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'e': return 14; 2475131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'F': 2476353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'f': return 15; 247788dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 2478e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 24791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2480b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 2481b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 2482353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman return getNumericAccessorIdx(c); 2483b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 24841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 248588dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 2486b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 248771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return unsigned(idx-1) < getNumElements(); 248888dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 2489e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 2490bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2491bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2492bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 24931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 24941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ExtVector; 249573322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 2496213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman static bool classof(const ExtVectorType *) { return true; } 249773322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 249873322924127c873c13101b705dd823f5539ffa5fSteve Naroff 24995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 250072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 25015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 25025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 25035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 25045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 2505264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2506264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public: 2507373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// ExtInfo - A class which abstracts out some details necessary for 2508373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// making a call. 2509373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// 2510373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// It is not actually used directly for storing this information in 2511373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// a FunctionType, although FunctionType does currently use the 2512373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// same bit-pattern. 2513373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// 2514075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara // If you add a field (say Foo), other than the obvious places (both, 2515075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara // constructors, compile failures), what you need to update is 2516075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara // * Operator== 2517425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * getFoo 2518425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * withFoo 2519425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * functionType. Add Foo, getFoo. 2520425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * ASTContext::getFooType 2521425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * ASTContext::mergeFunctionTypes 2522425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * FunctionNoProtoType::Profile 2523425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * FunctionProtoType::Profile 2524425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * TypePrinter::PrintFunctionProto 25253c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl // * AST read and write 2526425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * Codegen 2527264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola class ExtInfo { 25287e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor // Feel free to rearrange or add bits, but if you go over 8, 2529373920bd733b1d28fe7bf209945a62eb9248d948John McCall // you'll need to adjust both the Bits field below and 2530373920bd733b1d28fe7bf209945a62eb9248d948John McCall // Type::FunctionTypeBitfields. 2531373920bd733b1d28fe7bf209945a62eb9248d948John McCall 25327e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor // | CC |noreturn|produces|regparm| 25337e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor // |0 .. 2| 3 | 4 | 5 .. 7| 25347e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor // 25357e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor // regparm is either 0 (no regparm attribute) or the regparm value+1. 2536b870b88df784c2940efce448ebfaf54dece14666John McCall enum { CallConvMask = 0x7 }; 2537b870b88df784c2940efce448ebfaf54dece14666John McCall enum { NoReturnMask = 0x8 }; 2538f85e193739c953358c865005855253af4f68a497John McCall enum { ProducesResultMask = 0x10 }; 2539f85e193739c953358c865005855253af4f68a497John McCall enum { RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask), 25407e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor RegParmOffset = 5 }; // Assumed to be the last field 2541b870b88df784c2940efce448ebfaf54dece14666John McCall 2542f85e193739c953358c865005855253af4f68a497John McCall uint16_t Bits; 254371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 2544f85e193739c953358c865005855253af4f68a497John McCall ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {} 254571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 254671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall friend class FunctionType; 254771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 2548264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public: 2549264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Constructor with no defaults. Use this when you know that you 25503c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl // have all the elements (when reading an AST file for example). 2551f85e193739c953358c865005855253af4f68a497John McCall ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc, 2552f85e193739c953358c865005855253af4f68a497John McCall bool producesResult) { 25537e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor assert((!hasRegParm || regParm < 7) && "Invalid regparm value"); 2554b870b88df784c2940efce448ebfaf54dece14666John McCall Bits = ((unsigned) cc) | 2555b870b88df784c2940efce448ebfaf54dece14666John McCall (noReturn ? NoReturnMask : 0) | 2556f85e193739c953358c865005855253af4f68a497John McCall (producesResult ? ProducesResultMask : 0) | 25577e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0); 255871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2559264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2560264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Constructor with all defaults. Use when for example creating a 2561264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // function know to use defaults. 256271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ExtInfo() : Bits(0) {} 2563264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2564b870b88df784c2940efce448ebfaf54dece14666John McCall bool getNoReturn() const { return Bits & NoReturnMask; } 2565f85e193739c953358c865005855253af4f68a497John McCall bool getProducesResult() const { return Bits & ProducesResultMask; } 25667e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor bool getHasRegParm() const { return (Bits >> RegParmOffset) != 0; } 2567ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie unsigned getRegParm() const { 25687e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor unsigned RegParm = Bits >> RegParmOffset; 25697e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor if (RegParm > 0) 25707e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor --RegParm; 25717e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor return RegParm; 25727e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor } 2573b870b88df784c2940efce448ebfaf54dece14666John McCall CallingConv getCC() const { return CallingConv(Bits & CallConvMask); } 2574264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 257571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall bool operator==(ExtInfo Other) const { 257671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return Bits == Other.Bits; 2577264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 257871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall bool operator!=(ExtInfo Other) const { 257971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return Bits != Other.Bits; 2580264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 2581264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2582264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Note that we don't have setters. That is by design, use 2583264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // the following with methods instead of mutating these objects. 2584264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2585264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ExtInfo withNoReturn(bool noReturn) const { 258671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall if (noReturn) 258771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return ExtInfo(Bits | NoReturnMask); 258871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall else 258971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return ExtInfo(Bits & ~NoReturnMask); 2590425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola } 2591425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola 2592f85e193739c953358c865005855253af4f68a497John McCall ExtInfo withProducesResult(bool producesResult) const { 2593f85e193739c953358c865005855253af4f68a497John McCall if (producesResult) 2594f85e193739c953358c865005855253af4f68a497John McCall return ExtInfo(Bits | ProducesResultMask); 2595f85e193739c953358c865005855253af4f68a497John McCall else 2596f85e193739c953358c865005855253af4f68a497John McCall return ExtInfo(Bits & ~ProducesResultMask); 2597f85e193739c953358c865005855253af4f68a497John McCall } 2598f85e193739c953358c865005855253af4f68a497John McCall 2599425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola ExtInfo withRegParm(unsigned RegParm) const { 26007e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor assert(RegParm < 7 && "Invalid regparm value"); 2601f85e193739c953358c865005855253af4f68a497John McCall return ExtInfo((Bits & ~RegParmMask) | 26027e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor ((RegParm + 1) << RegParmOffset)); 2603264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 2604264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2605264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ExtInfo withCallingConv(CallingConv cc) const { 2606b870b88df784c2940efce448ebfaf54dece14666John McCall return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc); 2607264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 2608264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2609e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall void Profile(llvm::FoldingSetNodeID &ID) const { 261071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ID.AddInteger(Bits); 261171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2612264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola }; 2613264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 26145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 2615eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith FunctionType(TypeClass tc, QualType res, 2616c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor unsigned typeQuals, RefQualifierKind RefQualifier, 2617c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor QualType Canonical, bool Dependent, 2618561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent, 2619ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool VariablyModified, bool ContainsUnexpandedParameterPack, 2620d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ExtInfo Info) 2621ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified, 2622ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ContainsUnexpandedParameterPack), 2623d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ResultType(res) { 2624b870b88df784c2940efce448ebfaf54dece14666John McCall FunctionTypeBits.ExtInfo = Info.Bits; 2625b870b88df784c2940efce448ebfaf54dece14666John McCall FunctionTypeBits.TypeQuals = typeQuals; 2626c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor FunctionTypeBits.RefQualifier = static_cast<unsigned>(RefQualifier); 262771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2628b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; } 2629ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2630c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind getRefQualifier() const { 2631c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier); 2632c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor } 2633c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 26345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 26351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 2637a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman 2638a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman bool getHasRegParm() const { return getExtInfo().getHasRegParm(); } 2639b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getRegParmType() const { return getExtInfo().getRegParm(); } 2640b870b88df784c2940efce448ebfaf54dece14666John McCall bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); } 2641b870b88df784c2940efce448ebfaf54dece14666John McCall CallingConv getCallConv() const { return getExtInfo().getCC(); } 2642b870b88df784c2940efce448ebfaf54dece14666John McCall ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); } 26435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26445291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// \brief Determine the type of an expression that calls a function of 26455291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// this type. 2646ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie QualType getCallResultType(ASTContext &Context) const { 26476398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor return getResultType().getNonLValueExprType(Context); 26485291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor } 26495291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 2650686775deca8b8685eb90801495880e3abdd844c2Chris Lattner static StringRef getNameForCallConv(CallingConv CC); 265104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 26525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 26535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 26545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 26555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 26575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 26585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 265972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 26605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 266172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 266271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info) 2663eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith : FunctionType(FunctionNoProto, Result, 0, RQ_None, Canonical, 2664561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*Dependent=*/false, /*InstantiationDependent=*/false, 2665ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Result->isVariablyModifiedType(), 2666d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false, Info) {} 2667d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 26685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 2669ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 26705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 26715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 26721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2673bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2674bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2675bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 26765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 2677264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Profile(ID, getResultType(), getExtInfo()); 26785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26792455636163fdd18581d7fdae816433f886d88213Mike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 268071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ExtInfo Info) { 268171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall Info.Profile(ID); 26825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 26835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 26865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 26875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 268872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 26895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 26905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 269172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 26925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 2693465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 2694465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical 2695465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type. 269672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 2697e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallpublic: 2698e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall /// ExtProtoInfo - Extra information about a function prototype. 2699e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall struct ExtProtoInfo { 2700e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ExtProtoInfo() : 2701eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith Variadic(false), HasTrailingReturn(false), ExceptionSpecType(EST_None), 27020e2e13f4daa71edac982633120531333b45e77b5Benjamin Kramer RefQualifier(RQ_None), TypeQuals(0), NumExceptions(0), Exceptions(0), 2703eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith NoexceptExpr(0), ConsumedArguments(0) {} 2704e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 2705e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionType::ExtInfo ExtInfo; 27060e2e13f4daa71edac982633120531333b45e77b5Benjamin Kramer bool Variadic : 1; 27070e2e13f4daa71edac982633120531333b45e77b5Benjamin Kramer bool HasTrailingReturn : 1; 27080e2e13f4daa71edac982633120531333b45e77b5Benjamin Kramer ExceptionSpecificationType ExceptionSpecType : 4; 27090e2e13f4daa71edac982633120531333b45e77b5Benjamin Kramer RefQualifierKind RefQualifier : 2; 2710e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned char TypeQuals; 2711e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned NumExceptions; 2712e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall const QualType *Exceptions; 27138b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl Expr *NoexceptExpr; 2714f85e193739c953358c865005855253af4f68a497John McCall const bool *ConsumedArguments; 2715e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall }; 2716e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 2717e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallprivate: 2718d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Determine whether there are any argument types that 2719d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// contain an unexpanded parameter pack. 2720ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray, 2721d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned numArgs) { 2722d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 2723d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor if (ArgArray[Idx]->containsUnexpandedParameterPack()) 2724d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return true; 2725d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2726d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return false; 2727d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 2728d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2729e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType(QualType result, const QualType *args, unsigned numArgs, 27308026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl QualType canonical, const ExtProtoInfo &epi); 2731465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 27325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 2733eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith unsigned NumArgs : 17; 2734465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2735465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 273660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl unsigned NumExceptions : 9; 2737465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 273860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// ExceptionSpecType - The type of exception specification this function has. 273960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl unsigned ExceptionSpecType : 3; 2740465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2741f85e193739c953358c865005855253af4f68a497John McCall /// HasAnyConsumedArgs - Whether this function has any consumed arguments. 2742f85e193739c953358c865005855253af4f68a497John McCall unsigned HasAnyConsumedArgs : 1; 2743f85e193739c953358c865005855253af4f68a497John McCall 2744eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith /// Variadic - Whether the function is variadic. 2745eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith unsigned Variadic : 1; 2746eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith 2747eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith /// HasTrailingReturn - Whether this function has a trailing return type. 2748eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith unsigned HasTrailingReturn : 1; 2749eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith 27506a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // ArgInfo - There is an variable size array after the class in memory that 27516a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // holds the argument types. 2752b8706f95eae8f85af01a26eee899c5daf8d6fcdeTed Kremenek 27536a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // Exceptions - There is another variable size array after ArgInfo that 27546a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // holds the exception types. 2755b8706f95eae8f85af01a26eee899c5daf8d6fcdeTed Kremenek 27566a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // NoexceptExpr - Instead of Exceptions, there may be a single Expr* pointing 27576a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // to the expression in the noexcept() specifier. 2758b8706f95eae8f85af01a26eee899c5daf8d6fcdeTed Kremenek 27596a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // ConsumedArgs - A variable size array, following Exceptions 27606a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // and of length NumArgs, holding flags indicating which arguments 27616a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // are consumed. This only appears if HasAnyConsumedArgs is true. 2762b8706f95eae8f85af01a26eee899c5daf8d6fcdeTed Kremenek 27635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 27644b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 2765f85e193739c953358c865005855253af4f68a497John McCall const bool *getConsumedArgsBuffer() const { 2766f85e193739c953358c865005855253af4f68a497John McCall assert(hasAnyConsumedArgs()); 2767f85e193739c953358c865005855253af4f68a497John McCall 2768f85e193739c953358c865005855253af4f68a497John McCall // Find the end of the exceptions. 2769f85e193739c953358c865005855253af4f68a497John McCall Expr * const *eh_end = reinterpret_cast<Expr * const *>(arg_type_end()); 2770f85e193739c953358c865005855253af4f68a497John McCall if (getExceptionSpecType() != EST_ComputedNoexcept) 2771f85e193739c953358c865005855253af4f68a497John McCall eh_end += NumExceptions; 2772f85e193739c953358c865005855253af4f68a497John McCall else 2773f85e193739c953358c865005855253af4f68a497John McCall eh_end += 1; // NoexceptExpr 2774f85e193739c953358c865005855253af4f68a497John McCall 2775f85e193739c953358c865005855253af4f68a497John McCall return reinterpret_cast<const bool*>(eh_end); 2776f85e193739c953358c865005855253af4f68a497John McCall } 2777f85e193739c953358c865005855253af4f68a497John McCall 27785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 27795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 27805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 27815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 2782942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 27835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2784465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2785e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ExtProtoInfo getExtProtoInfo() const { 2786e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ExtProtoInfo EPI; 2787e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.ExtInfo = getExtInfo(); 2788e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.Variadic = isVariadic(); 2789eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith EPI.HasTrailingReturn = hasTrailingReturn(); 279060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.ExceptionSpecType = getExceptionSpecType(); 2791e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals()); 2792c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor EPI.RefQualifier = getRefQualifier(); 279360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (EPI.ExceptionSpecType == EST_Dynamic) { 279460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.NumExceptions = NumExceptions; 279560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.Exceptions = exception_begin(); 279660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) { 279760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.NoexceptExpr = getNoexceptExpr(); 279860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 2799f85e193739c953358c865005855253af4f68a497John McCall if (hasAnyConsumedArgs()) 2800f85e193739c953358c865005855253af4f68a497John McCall EPI.ConsumedArguments = getConsumedArgsBuffer(); 2801e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall return EPI; 2802e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall } 2803e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 280460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Get the kind of exception specification on this function. 280560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecificationType getExceptionSpecType() const { 280660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return static_cast<ExceptionSpecificationType>(ExceptionSpecType); 280760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 280860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Return whether this function has any kind of exception spec. 280960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool hasExceptionSpec() const { 281060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return getExceptionSpecType() != EST_None; 281160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 281260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Return whether this function has a dynamic (throw) exception spec. 281360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool hasDynamicExceptionSpec() const { 281460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return isDynamicExceptionSpec(getExceptionSpecType()); 281560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 2816fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// \brief Return whether this function has a noexcept exception spec. 281760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool hasNoexceptExceptionSpec() const { 281860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return isNoexceptExceptionSpec(getExceptionSpecType()); 281960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 282060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Result type of getNoexceptSpec(). 282160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl enum NoexceptResult { 282260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_NoNoexcept, ///< There is no noexcept specifier. 282360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_BadNoexcept, ///< The noexcept specifier has a bad expression. 282460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_Dependent, ///< The noexcept specifier is dependent. 282560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_Throw, ///< The noexcept specifier evaluates to false. 282660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_Nothrow ///< The noexcept specifier evaluates to true. 282760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl }; 282860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Get the meaning of the noexcept spec on this function, if any. 28298026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl NoexceptResult getNoexceptSpec(ASTContext &Ctx) const; 2830465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 2831465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType getExceptionType(unsigned i) const { 2832465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 2833465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin()[i]; 2834465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 283560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Expr *getNoexceptExpr() const { 283660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (getExceptionSpecType() != EST_ComputedNoexcept) 283760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return 0; 283860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // NoexceptExpr sits where the arguments end. 283960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return *reinterpret_cast<Expr *const *>(arg_type_end()); 2840d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson } 28418026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl bool isNothrow(ASTContext &Ctx) const { 284260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecificationType EST = getExceptionSpecType(); 28437a614d8380297fcd2bc23986241905d97222948cRichard Smith assert(EST != EST_Delayed); 284460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (EST == EST_DynamicNone || EST == EST_BasicNoexcept) 284560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return true; 284660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (EST != EST_ComputedNoexcept) 284760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return false; 28488026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl return getNoexceptSpec(Ctx) == NR_Nothrow; 2849c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall } 2850c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall 2851eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith bool isVariadic() const { return Variadic; } 285260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 2853f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// \brief Determines whether this function prototype contains a 2854f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// parameter pack at the end. 2855f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// 2856f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// A function template whose last parameter is a parameter pack can be 2857f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// called with an arbitrary number of arguments, much like a variadic 2858eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith /// function. 2859f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor bool isTemplateVariadic() const; 2860ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2861eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith bool hasTrailingReturn() const { return HasTrailingReturn; } 2862eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith 2863971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 28641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2865ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2866c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief Retrieve the ref-qualifier associated with this function type. 2867c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind getRefQualifier() const { 2868c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor return FunctionType::getRefQualifier(); 2869c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor } 2870ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 28715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 2872942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 2873942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 2874942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 2875942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 2876465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2877465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl typedef const QualType *exception_iterator; 2878465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_begin() const { 2879465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // exceptions begin where arguments end 2880465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return arg_type_end(); 2881465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 2882465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_end() const { 288360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (getExceptionSpecType() != EST_Dynamic) 288460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return exception_begin(); 2885465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin() + NumExceptions; 2886465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 2887465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2888f85e193739c953358c865005855253af4f68a497John McCall bool hasAnyConsumedArgs() const { 2889f85e193739c953358c865005855253af4f68a497John McCall return HasAnyConsumedArgs; 2890f85e193739c953358c865005855253af4f68a497John McCall } 2891f85e193739c953358c865005855253af4f68a497John McCall bool isArgConsumed(unsigned I) const { 2892f85e193739c953358c865005855253af4f68a497John McCall assert(I < getNumArgs() && "argument index out of range!"); 2893f85e193739c953358c865005855253af4f68a497John McCall if (hasAnyConsumedArgs()) 2894f85e193739c953358c865005855253af4f68a497John McCall return getConsumedArgsBuffer()[I]; 2895f85e193739c953358c865005855253af4f68a497John McCall return false; 2896f85e193739c953358c865005855253af4f68a497John McCall } 2897f85e193739c953358c865005855253af4f68a497John McCall 2898bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2899bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2900bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 290101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor void printExceptionSpecification(std::string &S, 290201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor PrintingPolicy Policy) const; 290301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 29045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 29055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 29065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 290772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 2908465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 29098026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx); 29105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 2911942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 29128026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ExtProtoInfo &EPI, const ASTContext &Context); 29135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 29145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 29155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2916ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped 2917ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g. 2918ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// using typename Base<T>::foo; 2919ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type. 2920ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type { 2921ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *Decl; 2922ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 292319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) 2924ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Type(UnresolvedUsing, QualType(), true, true, false, 2925d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 292619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {} 2927ed97649e9574b9d854fa4d6109c9333ae0993554John McCall friend class ASTContext; // ASTContext creates these. 2928ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic: 2929ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2930ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *getDecl() const { return Decl; } 2931ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2932ed97649e9574b9d854fa4d6109c9333ae0993554John McCall bool isSugared() const { return false; } 2933ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType desugar() const { return QualType(this, 0); } 2934ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2935ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static bool classof(const Type *T) { 2936ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return T->getTypeClass() == UnresolvedUsing; 2937ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2938ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static bool classof(const UnresolvedUsingType *) { return true; } 2939ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2940ed97649e9574b9d854fa4d6109c9333ae0993554John McCall void Profile(llvm::FoldingSetNodeID &ID) { 2941ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Profile(ID, Decl); 2942ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2943ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static void Profile(llvm::FoldingSetNodeID &ID, 2944ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *D) { 2945ed97649e9574b9d854fa4d6109c9333ae0993554John McCall ID.AddPointer(D); 2946ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2947ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}; 2948ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2949ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 29505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 2951162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *Decl; 2952c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 2953162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can) 2954ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Type(tc, can, can->isDependentType(), 2955561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor can->isInstantiationDependentType(), 2956ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie can->isVariablyModifiedType(), 2957d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 2958162e1c1b487352434552147967c3dd296ebee2f7Richard Smith Decl(const_cast<TypedefNameDecl*>(D)) { 29595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 29605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 29615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 29625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 29631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2964162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *getDecl() const { return Decl; } 29651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2966bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2967bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const; 2968bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 296972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 29705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 29715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 29725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 297372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension). 297472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type { 2975d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 29761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2977b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected: 2978dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor TypeOfExprType(Expr *E, QualType can = QualType()); 2979d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 2980d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 2981d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 29821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2983bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2984bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const; 2985bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2986bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 29876af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor bool isSugared() const; 2988bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 298972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 299072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 2991d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 2992d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 2993c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent 29941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types. 2995c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// 2996c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage 2997c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances 2998c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via TypeOfExprType nodes. 29991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType 3000b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor : public TypeOfExprType, public llvm::FoldingSetNode { 30014ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 30021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3003b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic: 30044ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentTypeOfExprType(const ASTContext &Context, Expr *E) 3005b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor : TypeOfExprType(E), Context(Context) { } 30061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3007b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 3008b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Profile(ID, Context, getUnderlyingExpr()); 3009b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } 30101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30114ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 3012b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Expr *E); 3013b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor}; 30141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3015d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 3016d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 3017d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 30181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypeOfType(QualType T, QualType can) 3019ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Type(TypeOf, can, T->isDependentType(), 3020561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isInstantiationDependentType(), 3021ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie T->isVariablyModifiedType(), 3022ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie T->containsUnexpandedParameterPack()), 302335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor TOType(T) { 3024d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 3025d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 3026d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 3027d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 3028d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 30291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3030bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 3031bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getUnderlyingType(); } 3032bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3033bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 3034bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 3035bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 303672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 3037d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 3038d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 30395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3040395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x) 3041395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type { 3042395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *E; 3043563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType UnderlyingType; 30441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30459d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected: 3046563a03b1338d31c2462def43253a722bc885d384Anders Carlsson DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 3047395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson friend class ASTContext; // ASTContext creates these. 3048395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic: 3049395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *getUnderlyingExpr() const { return E; } 3050563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType getUnderlyingType() const { return UnderlyingType; } 3051563a03b1338d31c2462def43253a722bc885d384Anders Carlsson 3052bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 30536af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor QualType desugar() const; 3054bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3055bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 30566af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor bool isSugared() const; 3057bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3058395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 3059395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const DecltypeType *) { return true; } 3060395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson}; 30611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3062c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent 3063c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// decltype(expr) types. 3064c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// 3065c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage 3066c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances 3067c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via DecltypeType nodes. 30689d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { 30694ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 30701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30719d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic: 30724ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentDecltypeType(const ASTContext &Context, Expr *E); 30731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30749d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 30759d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor Profile(ID, Context, getUnderlyingExpr()); 30769d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } 30771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30784ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 30791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *E); 30809d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor}; 30811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3082ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt/// \brief A unary type transform, which is a type constructed from another 3083ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntclass UnaryTransformType : public Type { 3084ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntpublic: 3085ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt enum UTTKind { 3086ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt EnumUnderlyingType 3087ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt }; 3088ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 3089ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntprivate: 3090ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt /// The untransformed type. 3091ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType BaseType; 3092ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt /// The transformed type if not dependent, otherwise the same as BaseType. 3093ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType UnderlyingType; 3094ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 3095ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UTTKind UKind; 3096ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntprotected: 3097ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind, 3098ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType CanonicalTy); 3099ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt friend class ASTContext; 3100ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntpublic: 3101ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt bool isSugared() const { return !isDependentType(); } 3102ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType desugar() const { return UnderlyingType; } 3103ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 3104ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType getUnderlyingType() const { return UnderlyingType; } 3105ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType getBaseType() const { return BaseType; } 3106ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 3107ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UTTKind getUTTKind() const { return UKind; } 3108ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3109ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt static bool classof(const Type *T) { 3110ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return T->getTypeClass() == UnaryTransform; 3111ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 3112ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt static bool classof(const UnaryTransformType *) { return true; } 3113ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}; 3114ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 31155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 3116ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl /// Stores the TagDecl associated with this type. The decl may point to any 3117ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl /// TagDecl that declares the entity. 3118ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl TagDecl * decl; 31192ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 312056ca8a9c0fabd65418e9b2fd85140f4ed7d3c187Douglas Gregor friend class ASTReader; 312156ca8a9c0fabd65418e9b2fd85140f4ed7d3c187Douglas Gregor 31222ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected: 312319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall TagType(TypeClass TC, const TagDecl *D, QualType can); 31242ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 31251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 3126ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl TagDecl *getDecl() const; 31271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31280b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// @brief Determines whether this type is in the process of being 31291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// defined. 3130ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl bool isBeingDefined() const; 31310b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 31321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 313372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 313472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor } 31355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 31365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 31375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 31385edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 31395edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes. 31405edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType { 314149aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected: 314219c8576b7328f4dc2d07682f5da552875c1912efJohn McCall explicit RecordType(const RecordDecl *D) 314319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { } 314472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 314519c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { } 31462ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 31475edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 31481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31495edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordDecl *getDecl() const { 31505edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 31515edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 31521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: This predicate is a helper to QualType/Type. It needs to 31545edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // recursively check all fields for const-ness. If any field is declared 31551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // const, it needs to return false. 31565edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner bool hasConstFields() const { return false; } 31575edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 3158bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 3159bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 3160bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 316195b68f94d28a4b94f4c3fb029b9f1690e1bb728bPeter Collingbourne static bool classof(const Type *T) { return T->getTypeClass() == Record; } 31625edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const RecordType *) { return true; } 31635edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 31645edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 31655edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 31665edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums. 31675edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType { 316819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall explicit EnumType(const EnumDecl *D) 316919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { } 31702ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 31715edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 31721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31735edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumDecl *getDecl() const { 31745edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 31755edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 31761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3177bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 3178bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 3179bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 318095b68f94d28a4b94f4c3fb029b9f1690e1bb728bPeter Collingbourne static bool classof(const Type *T) { return T->getTypeClass() == Enum; } 31815edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const EnumType *) { return true; } 31825edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 31835edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 31849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// AttributedType - An attributed type is a type to which a type 31859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// attribute has been applied. The "modified type" is the 31869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// fully-sugared type to which the attributed type was applied; 31879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// generally it is not canonically equivalent to the attributed type. 31889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// The "equivalent type" is the minimally-desugared type which the 31899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// type is canonically equivalent to. 31909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// 31919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// For example, in the following attributed type: 31929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// int32_t __attribute__((vector_size(16))) 31939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// - the modified type is the TypedefType for int32_t 31949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// - the equivalent type is VectorType(16, int32_t) 31959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// - the canonical type is VectorType(16, int) 31969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallclass AttributedType : public Type, public llvm::FoldingSetNode { 31979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic: 31989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // It is really silly to have yet another attribute-kind enum, but 31999d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // clang::attr::Kind doesn't currently cover the pure type attrs. 32009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall enum Kind { 32019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // Expression operand. 3202170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_address_space, 3203170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_regparm, 3204170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_vector_size, 3205170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_neon_vector_type, 3206170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_neon_polyvector_type, 32079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 3208170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet FirstExprOperandKind = attr_address_space, 3209170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet LastExprOperandKind = attr_neon_polyvector_type, 32109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 32119d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // Enumerated operand (string or keyword). 3212170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_objc_gc, 3213b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis attr_objc_ownership, 3214414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov attr_pcs, 32159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 3216170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet FirstEnumOperandKind = attr_objc_gc, 3217414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov LastEnumOperandKind = attr_pcs, 32189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 32199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // No operand. 32203cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_noreturn, 32213cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_cdecl, 32223cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_fastcall, 32233cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_stdcall, 32243cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_thiscall, 32253cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_pascal 32269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall }; 32279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 32289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallprivate: 32299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType ModifiedType; 32309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType EquivalentType; 32319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 32329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall friend class ASTContext; // creates these 32339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 32349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType(QualType canon, Kind attrKind, 32359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modified, QualType equivalent) 32369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall : Type(Attributed, canon, canon->isDependentType(), 3237561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor canon->isInstantiationDependentType(), 32389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall canon->isVariablyModifiedType(), 32399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall canon->containsUnexpandedParameterPack()), 32409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ModifiedType(modified), EquivalentType(equivalent) { 32419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeBits.AttrKind = attrKind; 32429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 32439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 32449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic: 32459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Kind getAttrKind() const { 32469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return static_cast<Kind>(AttributedTypeBits.AttrKind); 32479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 32489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 32499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType getModifiedType() const { return ModifiedType; } 32509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType getEquivalentType() const { return EquivalentType; } 32519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 32529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall bool isSugared() const { return true; } 32539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType desugar() const { return getEquivalentType(); } 32549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 32559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall void Profile(llvm::FoldingSetNodeID &ID) { 32569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Profile(ID, getAttrKind(), ModifiedType, EquivalentType); 32579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 32589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 32599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind, 32609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modified, QualType equivalent) { 32619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ID.AddInteger(attrKind); 32629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ID.AddPointer(modified.getAsOpaquePtr()); 32639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ID.AddPointer(equivalent.getAsOpaquePtr()); 32649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 32659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 32669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall static bool classof(const Type *T) { 32679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return T->getTypeClass() == Attributed; 32689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 32699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall static bool classof(const AttributedType *T) { return true; } 32709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}; 32719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 3272fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 32734fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth // Helper data collector for canonical types. 32744fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth struct CanonicalTTPTInfo { 32754fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned Depth : 15; 32764fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned ParameterPack : 1; 32774fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned Index : 16; 32784fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth }; 32794fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 32804fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth union { 32814fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth // Info for the canonical type. 32824fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth CanonicalTTPTInfo CanTTPTInfo; 32834fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth // Info for the non-canonical type. 32844fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmDecl *TTPDecl; 32854fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth }; 328672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 32874fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth /// Build a non-canonical type. 32884fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon) 328935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true, 3290561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 32914fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth /*VariablyModified=*/false, 32925d65e34b08b3e57a4da834195757d0d15baaffd0Chandler Carruth Canon->containsUnexpandedParameterPack()), 32934fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TTPDecl(TTPDecl) { } 329472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 32954fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth /// Build the canonical type. 32961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP) 3297ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Type(TemplateTypeParm, QualType(this, 0), 3298561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*Dependent=*/true, 3299561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 33004fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth /*VariablyModified=*/false, PP) { 33014fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth CanTTPTInfo.Depth = D; 33024fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth CanTTPTInfo.Index = I; 33034fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth CanTTPTInfo.ParameterPack = PP; 33044fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth } 330572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 3306fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor friend class ASTContext; // ASTContext creates these 330772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 33084fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth const CanonicalTTPTInfo& getCanTTPTInfo() const { 33094fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth QualType Can = getCanonicalTypeInternal(); 33105d65e34b08b3e57a4da834195757d0d15baaffd0Chandler Carruth return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo; 33114fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth } 33124fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 3313fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic: 33144fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned getDepth() const { return getCanTTPTInfo().Depth; } 33154fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned getIndex() const { return getCanTTPTInfo().Index; } 33164fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; } 33174fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 33184fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmDecl *getDecl() const { 33194fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth return isCanonicalUnqualified() ? 0 : TTPDecl; 33204fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth } 33214fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 3322b7efff4bae117604f442bb6859c844f90b15f3ffChandler Carruth IdentifierInfo *getIdentifier() const; 33231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3324bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 3325bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 3326bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3327fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 33284fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl()); 3329fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 3330fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 33311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 33321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned Index, bool ParameterPack, 33334fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmDecl *TTPDecl) { 3334fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Depth); 3335fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Index); 333676e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson ID.AddBoolean(ParameterPack); 33374fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth ID.AddPointer(TTPDecl); 3338fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 3339fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 33401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 33411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == TemplateTypeParm; 334272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor } 334372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 334472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}; 3345fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 334649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template 334749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter. 334849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// 334949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have 335049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these. They are used solely to record that a 335149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter; 335249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical. 335349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode { 335449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall // The original type parameter. 335549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *Replaced; 335649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 335749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) 335835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(), 3359561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Canon->isInstantiationDependentType(), 3360d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Canon->isVariablyModifiedType(), 3361d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Canon->containsUnexpandedParameterPack()), 336249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Replaced(Param) { } 336349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 336449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall friend class ASTContext; 336549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 336649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic: 336749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// Gets the template parameter that was substituted for. 336849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *getReplacedParameter() const { 336949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return Replaced; 337049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 337149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 337249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// Gets the type that was substituted for the template 337349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// parameter. 337449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType getReplacementType() const { 337549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return getCanonicalTypeInternal(); 337649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 337749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 337849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall bool isSugared() const { return true; } 337949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType desugar() const { return getReplacementType(); } 338049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 338149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall void Profile(llvm::FoldingSetNodeID &ID) { 338249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Profile(ID, getReplacedParameter(), getReplacementType()); 338349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 338449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, 338549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *Replaced, 338649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType Replacement) { 338749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall ID.AddPointer(Replaced); 338849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall ID.AddPointer(Replacement.getAsOpaquePtr()); 338949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 339049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 339149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static bool classof(const Type *T) { 339249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return T->getTypeClass() == SubstTemplateTypeParm; 339349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 339449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static bool classof(const SubstTemplateTypeParmType *T) { return true; } 339549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}; 339649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 3397c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// \brief Represents the result of substituting a set of types for a template 3398c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// type parameter pack. 3399c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// 3400c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs 3401c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// and those parameter packs correspond to different levels of template 3402ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// parameter lists, this type node is used to represent a template type 3403c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack 3404c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// substituted but that still lives within a pack expansion that itself 3405c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// could not be instantiated. When actually performing a substitution into 3406c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding 3407c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType 3408c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// at the current pack substitution index. 3409c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorclass SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode { 3410c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// \brief The original type parameter. 3411c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Replaced; 3412ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3413c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// \brief A pointer to the set of template arguments that this 3414c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// parameter pack is instantiated with. 3415c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument *Arguments; 3416ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3417c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// \brief The number of template arguments in \c Arguments. 3418c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor unsigned NumArguments; 3419ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3420ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param, 3421c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType Canon, 3422c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack); 3423ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3424c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor friend class ASTContext; 3425ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3426c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorpublic: 3427b7efff4bae117604f442bb6859c844f90b15f3ffChandler Carruth IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); } 3428ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3429c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// Gets the template parameter that was substituted for. 3430c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *getReplacedParameter() const { 3431c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return Replaced; 3432c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor } 3433ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3434c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor bool isSugared() const { return false; } 3435c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType desugar() const { return QualType(this, 0); } 3436ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3437c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor TemplateArgument getArgumentPack() const; 3438ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3439c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID); 3440c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, 3441c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Replaced, 3442c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack); 3443ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3444c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor static bool classof(const Type *T) { 3445c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return T->getTypeClass() == SubstTemplateTypeParmPack; 3446c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor } 3447c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor static bool classof(const SubstTemplateTypeParmPackType *T) { return true; } 3448c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor}; 3449c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 345034b41d939a1328f484511c6002ba2456db879a29Richard Smith/// \brief Represents a C++0x auto type. 345134b41d939a1328f484511c6002ba2456db879a29Richard Smith/// 345234b41d939a1328f484511c6002ba2456db879a29Richard Smith/// These types are usually a placeholder for a deduced type. However, within 345334b41d939a1328f484511c6002ba2456db879a29Richard Smith/// templates and before the initializer is attached, there is no deduced type 345434b41d939a1328f484511c6002ba2456db879a29Richard Smith/// and an auto type is type-dependent and canonical. 345534b41d939a1328f484511c6002ba2456db879a29Richard Smithclass AutoType : public Type, public llvm::FoldingSetNode { 345634b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType(QualType DeducedType) 345734b41d939a1328f484511c6002ba2456db879a29Richard Smith : Type(Auto, DeducedType.isNull() ? QualType(this, 0) : DeducedType, 345834b41d939a1328f484511c6002ba2456db879a29Richard Smith /*Dependent=*/DeducedType.isNull(), 3459561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/DeducedType.isNull(), 346034b41d939a1328f484511c6002ba2456db879a29Richard Smith /*VariablyModified=*/false, /*ContainsParameterPack=*/false) { 346134b41d939a1328f484511c6002ba2456db879a29Richard Smith assert((DeducedType.isNull() || !DeducedType->isDependentType()) && 346234b41d939a1328f484511c6002ba2456db879a29Richard Smith "deduced a dependent type for auto"); 346334b41d939a1328f484511c6002ba2456db879a29Richard Smith } 346434b41d939a1328f484511c6002ba2456db879a29Richard Smith 346534b41d939a1328f484511c6002ba2456db879a29Richard Smith friend class ASTContext; // ASTContext creates these 346634b41d939a1328f484511c6002ba2456db879a29Richard Smith 346734b41d939a1328f484511c6002ba2456db879a29Richard Smithpublic: 346834b41d939a1328f484511c6002ba2456db879a29Richard Smith bool isSugared() const { return isDeduced(); } 346934b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType desugar() const { return getCanonicalTypeInternal(); } 347034b41d939a1328f484511c6002ba2456db879a29Richard Smith 347134b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType getDeducedType() const { 347234b41d939a1328f484511c6002ba2456db879a29Richard Smith return isDeduced() ? getCanonicalTypeInternal() : QualType(); 347334b41d939a1328f484511c6002ba2456db879a29Richard Smith } 347434b41d939a1328f484511c6002ba2456db879a29Richard Smith bool isDeduced() const { 347534b41d939a1328f484511c6002ba2456db879a29Richard Smith return !isDependentType(); 347634b41d939a1328f484511c6002ba2456db879a29Richard Smith } 347734b41d939a1328f484511c6002ba2456db879a29Richard Smith 347834b41d939a1328f484511c6002ba2456db879a29Richard Smith void Profile(llvm::FoldingSetNodeID &ID) { 347934b41d939a1328f484511c6002ba2456db879a29Richard Smith Profile(ID, getDeducedType()); 348034b41d939a1328f484511c6002ba2456db879a29Richard Smith } 348134b41d939a1328f484511c6002ba2456db879a29Richard Smith 348234b41d939a1328f484511c6002ba2456db879a29Richard Smith static void Profile(llvm::FoldingSetNodeID &ID, 348334b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType Deduced) { 348434b41d939a1328f484511c6002ba2456db879a29Richard Smith ID.AddPointer(Deduced.getAsOpaquePtr()); 348534b41d939a1328f484511c6002ba2456db879a29Richard Smith } 348634b41d939a1328f484511c6002ba2456db879a29Richard Smith 348734b41d939a1328f484511c6002ba2456db879a29Richard Smith static bool classof(const Type *T) { 348834b41d939a1328f484511c6002ba2456db879a29Richard Smith return T->getTypeClass() == Auto; 348934b41d939a1328f484511c6002ba2456db879a29Richard Smith } 349034b41d939a1328f484511c6002ba2456db879a29Richard Smith static bool classof(const AutoType *T) { return true; } 349134b41d939a1328f484511c6002ba2456db879a29Richard Smith}; 349234b41d939a1328f484511c6002ba2456db879a29Richard Smith 34931901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// \brief Represents a type template specialization; the template 34941901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// must be a class template, a type alias template, or a template 34951901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// template parameter. A template which cannot be resolved to one of 34961901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// these, e.g. because it is written with a dependent scope 34971901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// specifier, is instead represented as a 34981901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// @c DependentTemplateSpecializationType. 349955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// 35001901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// A non-dependent template specialization type is always "sugar", 35011901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// typically for a @c RecordType. For example, a class template 35021901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// specialization type of @c vector<int> will refer to a tag type for 35031901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// the instantiation @c std::vector<int, std::allocator<int>> 35047532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// 35051901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// Template specializations are dependent if either the template or 35061901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// any of the template arguments are dependent, in which case the 35071901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// type may also be canonical. 35083e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith/// 35091901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// Instances of this type are allocated with a trailing array of 35101901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// TemplateArguments, followed by a QualType representing the 35111901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// non-canonical aliased type when the template is a type alias 35121901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// template. 35131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType 351455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor : public Type, public llvm::FoldingSetNode { 35151901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall /// \brief The name of the template being specialized. This is 35161901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall /// either a TemplateName::Template (in which case it is a 35171901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a 3518146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall /// TypeAliasTemplateDecl*), a 3519146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall /// TemplateName::SubstTemplateTemplateParmPack, or a 3520146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall /// TemplateName::SubstTemplateTemplateParm (in which case the 3521146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall /// replacement must, recursively, be one of these). 35227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Template; 352355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 352440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief - The number of template arguments named in this class 352540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// template specialization. 3526b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor unsigned NumArgs : 31; 352755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 3528b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// \brief Whether this template specialization type is a substituted 3529b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// type alias. 3530b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor bool TypeAlias : 1; 3531b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor 3532ef99001908e799c388f1363b1e607dad5f5b57d3John McCall TemplateSpecializationType(TemplateName T, 35337532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 35343e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith unsigned NumArgs, QualType Canon, 35353e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Aliased); 353655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 353755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor friend class ASTContext; // ASTContext creates these 353855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 353955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic: 354040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Determine whether any of the given template arguments are 354140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// dependent. 354240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 3543561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor unsigned NumArgs, 3544561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent); 354540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 3546833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args, 3547561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor unsigned NumArgs, 3548561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent); 3549833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3550561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &, 3551561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent); 3552d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 3553df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 3554df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// enclosing the template arguments. 3555df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 3556d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned NumArgs, 3557dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor const PrintingPolicy &Policy, 3558dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor bool SkipBrackets = false); 3559df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor 3560833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args, 3561833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned NumArgs, 3562833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const PrintingPolicy &Policy); 3563833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3564d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &, 3565d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const PrintingPolicy &Policy); 3566d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 356731f17ecbef57b5679c017c375db330546b7b5145John McCall /// True if this template specialization type matches a current 356831f17ecbef57b5679c017c375db330546b7b5145John McCall /// instantiation in the context in which it is found. 356931f17ecbef57b5679c017c375db330546b7b5145John McCall bool isCurrentInstantiation() const { 357071d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall return isa<InjectedClassNameType>(getCanonicalTypeInternal()); 357131f17ecbef57b5679c017c375db330546b7b5145John McCall } 357231f17ecbef57b5679c017c375db330546b7b5145John McCall 3573b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// \brief Determine if this template specialization type is for a type alias 3574b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// template that has been substituted. 3575b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// 3576b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// Nearly every template specialization type whose template is an alias 3577b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// template will be substituted. However, this is not the case when 3578b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// the specialization contains a pack expansion but the template alias 3579b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// does not have a corresponding parameter pack, e.g., 3580b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// 3581b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// \code 3582b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// template<typename T, typename U, typename V> struct S; 3583b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// template<typename T, typename U> using A = S<T, int, U>; 3584b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// template<typename... Ts> struct X { 3585b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// typedef A<Ts...> type; // not a type alias 3586b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// }; 3587b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor /// \endcode 3588b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor bool isTypeAlias() const { return TypeAlias; } 3589b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor 35903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith /// Get the aliased type, if this is a specialization of a type alias 35913e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith /// template. 35923e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType getAliasedType() const { 35933e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith assert(isTypeAlias() && "not a type alias template specialization"); 35943e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return *reinterpret_cast<const QualType*>(end()); 35953e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 35963e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 359740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor typedef const TemplateArgument * iterator; 359840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 359940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator begin() const { return getArgs(); } 360033500955d731c73717af52088b7fc0e7a85681e7John McCall iterator end() const; // defined inline in TemplateBase.h 360140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 36027532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 36037532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName getTemplateName() const { return Template; } 360455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 360540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the template arguments. 36061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *getArgs() const { 360740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 360840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 360940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 361040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the number of template arguments. 361155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 361255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 361355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \brief Retrieve a specific template argument as a type. 361455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \precondition @c isArgType(Arg) 361533500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 361655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 361731f17ecbef57b5679c017c375db330546b7b5145John McCall bool isSugared() const { 36183e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return !isDependentType() || isCurrentInstantiation() || isTypeAlias(); 361931f17ecbef57b5679c017c375db330546b7b5145John McCall } 3620bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getCanonicalTypeInternal(); } 3621bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 36224ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) { 362371d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall Profile(ID, Template, getArgs(), NumArgs, Ctx); 36243e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (isTypeAlias()) 36253e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith getAliasedType().Profile(ID); 362655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 362755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 36287532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 362931f17ecbef57b5679c017c375db330546b7b5145John McCall const TemplateArgument *Args, 363031f17ecbef57b5679c017c375db330546b7b5145John McCall unsigned NumArgs, 36314ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context); 363255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 36331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 36341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == TemplateSpecialization; 363555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 36367532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 363755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}; 363855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 363931f17ecbef57b5679c017c375db330546b7b5145John McCall/// \brief The injected class name of a C++ class template or class 364031f17ecbef57b5679c017c375db330546b7b5145John McCall/// template partial specialization. Used to record that a type was 364131f17ecbef57b5679c017c375db330546b7b5145John McCall/// spelled with a bare identifier rather than as a template-id; the 364231f17ecbef57b5679c017c375db330546b7b5145John McCall/// equivalent for non-templated classes is just RecordType. 36433cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// 364431f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always dependent. Template 364531f17ecbef57b5679c017c375db330546b7b5145John McCall/// instantiation turns these into RecordTypes. 36463cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// 364731f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always canonical. This works 364831f17ecbef57b5679c017c375db330546b7b5145John McCall/// because it is impossible to compare an injected class name type 364931f17ecbef57b5679c017c375db330546b7b5145John McCall/// with the corresponding non-injected template type, for the same 365031f17ecbef57b5679c017c375db330546b7b5145John McCall/// reason that it is impossible to directly compare template 365131f17ecbef57b5679c017c375db330546b7b5145John McCall/// parameters from different dependent contexts: injected class name 365231f17ecbef57b5679c017c375db330546b7b5145John McCall/// types can only occur within the scope of a particular templated 365331f17ecbef57b5679c017c375db330546b7b5145John McCall/// declaration, and within that scope every template specialization 365431f17ecbef57b5679c017c375db330546b7b5145John McCall/// will canonicalize to the injected class name (when appropriate 365531f17ecbef57b5679c017c375db330546b7b5145John McCall/// according to the rules of the language). 36563cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameType : public Type { 36573cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall CXXRecordDecl *Decl; 36583cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 365931f17ecbef57b5679c017c375db330546b7b5145John McCall /// The template specialization which this type represents. 366031f17ecbef57b5679c017c375db330546b7b5145John McCall /// For example, in 366131f17ecbef57b5679c017c375db330546b7b5145John McCall /// template <class T> class A { ... }; 366231f17ecbef57b5679c017c375db330546b7b5145John McCall /// this is A<T>, whereas in 366331f17ecbef57b5679c017c375db330546b7b5145John McCall /// template <class X, class Y> class A<B<X,Y> > { ... }; 366431f17ecbef57b5679c017c375db330546b7b5145John McCall /// this is A<B<X,Y> >. 366531f17ecbef57b5679c017c375db330546b7b5145John McCall /// 366631f17ecbef57b5679c017c375db330546b7b5145John McCall /// It is always unqualified, always a template specialization type, 366731f17ecbef57b5679c017c375db330546b7b5145John McCall /// and always dependent. 366831f17ecbef57b5679c017c375db330546b7b5145John McCall QualType InjectedType; 36693cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 36703cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall friend class ASTContext; // ASTContext creates these. 3671c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not 3672c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl // currently suitable for AST reading, too much 367343921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis // interdependencies. 367431f17ecbef57b5679c017c375db330546b7b5145John McCall InjectedClassNameType(CXXRecordDecl *D, QualType TST) 367535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(InjectedClassName, QualType(), /*Dependent=*/true, 3676561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 3677ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /*VariablyModified=*/false, 3678d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 367931f17ecbef57b5679c017c375db330546b7b5145John McCall Decl(D), InjectedType(TST) { 36803cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(isa<TemplateSpecializationType>(TST)); 36813cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(!TST.hasQualifiers()); 368231f17ecbef57b5679c017c375db330546b7b5145John McCall assert(TST->isDependentType()); 36833cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 36843cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 36853cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallpublic: 368631f17ecbef57b5679c017c375db330546b7b5145John McCall QualType getInjectedSpecializationType() const { return InjectedType; } 368731f17ecbef57b5679c017c375db330546b7b5145John McCall const TemplateSpecializationType *getInjectedTST() const { 368831f17ecbef57b5679c017c375db330546b7b5145John McCall return cast<TemplateSpecializationType>(InjectedType.getTypePtr()); 36893cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 36903cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 3691ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl CXXRecordDecl *getDecl() const; 36923cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 369331f17ecbef57b5679c017c375db330546b7b5145John McCall bool isSugared() const { return false; } 369431f17ecbef57b5679c017c375db330546b7b5145John McCall QualType desugar() const { return QualType(this, 0); } 36953cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 36963cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall static bool classof(const Type *T) { 36973cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return T->getTypeClass() == InjectedClassName; 36983cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 36993cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall static bool classof(const InjectedClassNameType *T) { return true; } 37003cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}; 37013cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 3702465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief The kind of a tag type. 3703465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraenum TagTypeKind { 3704465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "struct" keyword. 3705465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Struct, 3706465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "union" keyword. 3707465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Union, 3708465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "class" keyword. 3709465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Class, 3710465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "enum" keyword. 3711465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Enum 3712465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}; 3713465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 37144a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or 37154a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// introduces an elaborated-type-specifier. 37164a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregorenum ElaboratedTypeKeyword { 37174a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "struct" keyword introduces the elaborated-type-specifier. 37184a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ETK_Struct, 37194a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "union" keyword introduces the elaborated-type-specifier. 37204a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ETK_Union, 3721465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "class" keyword introduces the elaborated-type-specifier. 3722465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_Class, 37234a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "enum" keyword introduces the elaborated-type-specifier. 3724465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_Enum, 3725465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "typename" keyword precedes the qualified type name, e.g., 3726465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \c typename T::type. 3727465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_Typename, 3728465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief No keyword precedes the qualified type name. 3729465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_None 37304a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor}; 3731465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3732465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword. 3733465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The keyword in stored in the free bits of the base class. 3734465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// Also provides a few static helpers for converting and printing 3735465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// elaborated type keyword and tag type kind enumerations. 3736465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass TypeWithKeyword : public Type { 3737465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraprotected: 3738465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, 3739ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie QualType Canonical, bool Dependent, 3740ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool InstantiationDependent, bool VariablyModified, 3741d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool ContainsUnexpandedParameterPack) 3742ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified, 3743d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ContainsUnexpandedParameterPack) { 374477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall TypeWithKeywordBits.Keyword = Keyword; 374577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall } 3746465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3747465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarapublic: 3748465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeKeyword getKeyword() const { 374977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword); 3750465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 3751465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3752465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST) 3753465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// into an elaborated type keyword. 3754465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec); 3755465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3756465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST) 3757465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// into a tag type kind. It is an error to provide a type specifier 3758465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// which *isn't* a tag kind here. 3759465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec); 3760465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3761465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getKeywordForTagDeclKind - Converts a TagTypeKind into an 3762465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// elaborated type keyword. 3763465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag); 3764465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3765465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getTagTypeKindForKeyword - Converts an elaborated type keyword into 3766465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara // a TagTypeKind. It is an error to provide an elaborated type keyword 3767465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// which *isn't* a tag kind here. 3768465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword); 3769465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3770465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword); 3771465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3772465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static const char *getKeywordName(ElaboratedTypeKeyword Keyword); 3773465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3774465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static const char *getTagTypeKindName(TagTypeKind Kind) { 3775465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return getKeywordName(getKeywordForTagTypeKind(Kind)); 3776465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 3777465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3778465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara class CannotCastToThisType {}; 3779465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static CannotCastToThisType classof(const Type *); 3780465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}; 3781465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3782465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief Represents a type that was referred to using an elaborated type 3783465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type, 3784465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// or both. 3785e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// 3786e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the 3787465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// source code, including tag keywords and any nested-name-specifiers. 3788465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The type itself is always "sugar", used to express what was written 3789465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// in the source code but containing no additional semantic information. 3790465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode { 3791465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3792ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested name specifier containing the qualifier. 3793ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *NNS; 3794e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3795e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief The type that this qualified name refers to. 3796e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType; 3797e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3798465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 3799465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara QualType NamedType, QualType CanonType) 3800465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara : TypeWithKeyword(Keyword, Elaborated, CanonType, 380135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor NamedType->isDependentType(), 3802561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor NamedType->isInstantiationDependentType(), 3803d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor NamedType->isVariablyModifiedType(), 3804d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor NamedType->containsUnexpandedParameterPack()), 3805465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NNS(NNS), NamedType(NamedType) { 3806465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara assert(!(Keyword == ETK_None && NNS == 0) && 3807465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara "ElaboratedType cannot have elaborated type keyword " 3808465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara "and name qualifier both null."); 3809465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 3810e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3811e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor friend class ASTContext; // ASTContext creates these 3812e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3813e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic: 381433500955d731c73717af52088b7fc0e7a85681e7John McCall ~ElaboratedType(); 3815465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3816ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the qualification on this type. 3817ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 3818e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3819e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 3820e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType getNamedType() const { return NamedType; } 3821e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3822bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 3823bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getNamedType(); } 3824bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3825bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 3826bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 3827bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3828e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 3829465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Profile(ID, getKeyword(), NNS, NamedType); 3830e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 3831e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3832465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 3833465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NestedNameSpecifier *NNS, QualType NamedType) { 3834465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ID.AddInteger(Keyword); 3835ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor ID.AddPointer(NNS); 3836ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NamedType.Profile(ID); 3837ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor } 3838e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 38391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 3840465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return T->getTypeClass() == Elaborated; 3841e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 3842465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static bool classof(const ElaboratedType *T) { return true; } 3843e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor}; 3844e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 38454a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief Represents a qualified type name for which the type name is 3846ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// dependent. 3847d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// 3848ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// DependentNameType represents a class of dependent types that involve a 3849ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent) 38504a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a 3851ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// typename-specifier), "class", "struct", "union", or "enum" (for a 38524a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we 38534a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier). 3854465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { 3855465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3856d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The nested name specifier containing the qualifier. 3857d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *NNS; 3858d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3859d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The type that this typename specifier refers to. 386033500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name; 3861d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3862ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 38634a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor const IdentifierInfo *Name, QualType CanonType) 386435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true, 3865561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 3866d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 3867d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor NNS->containsUnexpandedParameterPack()), 3868465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NNS(NNS), Name(Name) { 38691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(NNS->isDependent() && 38704714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor "DependentNameType requires a dependent nested-name-specifier"); 3871d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3872d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3873d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor friend class ASTContext; // ASTContext creates these 3874d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3875d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic: 3876d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief Retrieve the qualification on this type. 3877d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 3878d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 38791734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 38801734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// identifier. 38811734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// 38821734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 38831734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// form of the original typename was terminated by an identifier, 38841734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// e.g., "typename T::type". 38851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo *getIdentifier() const { 388633500955d731c73717af52088b7fc0e7a85681e7John McCall return Name; 38871734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 3888d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3889bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 3890bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 3891bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3892d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 3893465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Profile(ID, getKeyword(), NNS, Name); 3894d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3895d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 38964a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 389733500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name) { 38984a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ID.AddInteger(Keyword); 3899d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor ID.AddPointer(NNS); 390033500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Name); 3901d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3902d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 39031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 39044714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor return T->getTypeClass() == DependentName; 3905d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 39064714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor static bool classof(const DependentNameType *T) { return true; } 3907d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor}; 3908d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 390933500955d731c73717af52088b7fc0e7a85681e7John McCall/// DependentTemplateSpecializationType - Represents a template 391033500955d731c73717af52088b7fc0e7a85681e7John McCall/// specialization type whose template cannot be resolved, e.g. 391133500955d731c73717af52088b7fc0e7a85681e7John McCall/// A<T>::template B<T> 391233500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationType : 391333500955d731c73717af52088b7fc0e7a85681e7John McCall public TypeWithKeyword, public llvm::FoldingSetNode { 391433500955d731c73717af52088b7fc0e7a85681e7John McCall 391533500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief The nested name specifier containing the qualifier. 391633500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS; 391733500955d731c73717af52088b7fc0e7a85681e7John McCall 391833500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief The identifier of the template. 391933500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name; 392033500955d731c73717af52088b7fc0e7a85681e7John McCall 392133500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief - The number of template arguments named in this class 392233500955d731c73717af52088b7fc0e7a85681e7John McCall /// template specialization. 392333500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs; 392433500955d731c73717af52088b7fc0e7a85681e7John McCall 392533500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *getArgBuffer() const { 392633500955d731c73717af52088b7fc0e7a85681e7John McCall return reinterpret_cast<const TemplateArgument*>(this+1); 392733500955d731c73717af52088b7fc0e7a85681e7John McCall } 392833500955d731c73717af52088b7fc0e7a85681e7John McCall TemplateArgument *getArgBuffer() { 392933500955d731c73717af52088b7fc0e7a85681e7John McCall return reinterpret_cast<TemplateArgument*>(this+1); 393033500955d731c73717af52088b7fc0e7a85681e7John McCall } 393133500955d731c73717af52088b7fc0e7a85681e7John McCall 3932ef99001908e799c388f1363b1e607dad5f5b57d3John McCall DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 393333500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, 393433500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 393533500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 393633500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args, 393733500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon); 393833500955d731c73717af52088b7fc0e7a85681e7John McCall 393933500955d731c73717af52088b7fc0e7a85681e7John McCall friend class ASTContext; // ASTContext creates these 394033500955d731c73717af52088b7fc0e7a85681e7John McCall 394133500955d731c73717af52088b7fc0e7a85681e7John McCallpublic: 394233500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *getQualifier() const { return NNS; } 394333500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *getIdentifier() const { return Name; } 394433500955d731c73717af52088b7fc0e7a85681e7John McCall 394533500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief Retrieve the template arguments. 394633500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *getArgs() const { 394733500955d731c73717af52088b7fc0e7a85681e7John McCall return getArgBuffer(); 394833500955d731c73717af52088b7fc0e7a85681e7John McCall } 394933500955d731c73717af52088b7fc0e7a85681e7John McCall 395033500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief Retrieve the number of template arguments. 395133500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned getNumArgs() const { return NumArgs; } 395233500955d731c73717af52088b7fc0e7a85681e7John McCall 395333500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 395433500955d731c73717af52088b7fc0e7a85681e7John McCall 395533500955d731c73717af52088b7fc0e7a85681e7John McCall typedef const TemplateArgument * iterator; 395633500955d731c73717af52088b7fc0e7a85681e7John McCall iterator begin() const { return getArgs(); } 395733500955d731c73717af52088b7fc0e7a85681e7John McCall iterator end() const; // inline in TemplateBase.h 395833500955d731c73717af52088b7fc0e7a85681e7John McCall 395933500955d731c73717af52088b7fc0e7a85681e7John McCall bool isSugared() const { return false; } 396033500955d731c73717af52088b7fc0e7a85681e7John McCall QualType desugar() const { return QualType(this, 0); } 396133500955d731c73717af52088b7fc0e7a85681e7John McCall 39624ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) { 396333500955d731c73717af52088b7fc0e7a85681e7John McCall Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs()); 396433500955d731c73717af52088b7fc0e7a85681e7John McCall } 396533500955d731c73717af52088b7fc0e7a85681e7John McCall 396633500955d731c73717af52088b7fc0e7a85681e7John McCall static void Profile(llvm::FoldingSetNodeID &ID, 39674ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 396833500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 396933500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *Qualifier, 397033500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 397133500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 397233500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args); 397333500955d731c73717af52088b7fc0e7a85681e7John McCall 397433500955d731c73717af52088b7fc0e7a85681e7John McCall static bool classof(const Type *T) { 397533500955d731c73717af52088b7fc0e7a85681e7John McCall return T->getTypeClass() == DependentTemplateSpecialization; 397633500955d731c73717af52088b7fc0e7a85681e7John McCall } 397733500955d731c73717af52088b7fc0e7a85681e7John McCall static bool classof(const DependentTemplateSpecializationType *T) { 397833500955d731c73717af52088b7fc0e7a85681e7John McCall return true; 3979ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 398033500955d731c73717af52088b7fc0e7a85681e7John McCall}; 398133500955d731c73717af52088b7fc0e7a85681e7John McCall 39827536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \brief Represents a pack expansion of types. 39837536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 39847536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Pack expansions are part of C++0x variadic templates. A pack 39857536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// expansion contains a pattern, which itself contains one or more 39867536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// "unexpanded" parameter packs. When instantiated, a pack expansion 39877536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// produces a series of types, each instantiated from the pattern of 39887536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// the expansion, where the Ith instantiation of the pattern uses the 39897536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Ith arguments bound to each of the unexpanded parameter packs. The 39907536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// pack expansion is considered to "expand" these unexpanded 39917536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// parameter packs. 39927536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 39937536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \code 39947536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types> struct tuple; 39957536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 3996ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// template<typename ...Types> 39977536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// struct tuple_of_references { 39987536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// typedef tuple<Types&...> type; 39997536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// }; 40007536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \endcode 40017536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 40027536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Here, the pack expansion \c Types&... is represented via a 40037536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// PackExpansionType whose pattern is Types&. 40047536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorclass PackExpansionType : public Type, public llvm::FoldingSetNode { 40057536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// \brief The pattern of the pack expansion. 40067536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType Pattern; 40077536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 4008cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// \brief The number of expansions that this pack expansion will 4009ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// generate when substituted (+1), or indicates that 4010cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// 4011ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// This field will only have a non-zero value when some of the parameter 4012ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// packs that occur within the pattern have been substituted but others have 4013cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// not. 4014cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor unsigned NumExpansions; 4015ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4016cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor PackExpansionType(QualType Pattern, QualType Canon, 4017cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) 40187536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor : Type(PackExpansion, Canon, /*Dependent=*/true, 4019561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 40207536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /*VariableModified=*/Pattern->isVariablyModifiedType(), 40217536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 4022ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Pattern(Pattern), 4023cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions(NumExpansions? *NumExpansions + 1: 0) { } 40247536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 40257536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor friend class ASTContext; // ASTContext creates these 4026ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 40277536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorpublic: 40287536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// \brief Retrieve the pattern of this pack expansion, which is the 40297536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// type that will be repeatedly instantiated when instantiating the 40307536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// pack expansion itself. 40317536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType getPattern() const { return Pattern; } 40327536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 4033cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// \brief Retrieve the number of expansions that this pack expansion will 4034cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// generate, if known. 4035cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> getNumExpansions() const { 4036cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor if (NumExpansions) 4037cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor return NumExpansions - 1; 4038ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4039cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor return llvm::Optional<unsigned>(); 4040cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor } 4041ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 40427536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor bool isSugared() const { return false; } 40437536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType desugar() const { return QualType(this, 0); } 40447536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 40457536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 4046cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Profile(ID, getPattern(), getNumExpansions()); 40477536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 40487536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 4049cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern, 4050cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 40517536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor ID.AddPointer(Pattern.getAsOpaquePtr()); 4052cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor ID.AddBoolean(NumExpansions); 4053cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor if (NumExpansions) 4054cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor ID.AddInteger(*NumExpansions); 40557536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 40567536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 40577536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor static bool classof(const Type *T) { 40587536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return T->getTypeClass() == PackExpansion; 40597536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 40607536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor static bool classof(const PackExpansionType *T) { 40617536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return true; 4062ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 40637536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor}; 40647536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 4065c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectType - Represents a class type in Objective C. 4066c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Every Objective C type is a combination of a base type and a 4067c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// list of protocols. 4068c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 4069c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Given the following declarations: 4070c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// @class C; 4071c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// @protocol P; 4072c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 4073c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType 4074c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// with base C and no protocols. 4075c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 4076c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P]. 4077c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 4078e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose 4079e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType 4080e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// and no protocols. 4081c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 4082e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType 4083e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually 4084e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// this should get its own sugar class to better represent the source. 4085c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectType : public Type { 4086b870b88df784c2940efce448ebfaf54dece14666John McCall // ObjCObjectType.NumProtocols - the number of protocols stored 4087b870b88df784c2940efce448ebfaf54dece14666John McCall // after the ObjCObjectPointerType node. 408871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // 408971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // These protocols are those written directly on the type. If 409071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // protocol qualifiers ever become additive, the iterators will need 409171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // to get kindof complicated. 409271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // 409371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // In the canonical object type, these are sorted alphabetically 409471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // and uniqued. 4095c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 4096c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// Either a BuiltinType or an InterfaceType or sugar for either. 4097c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType BaseType; 4098c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4099c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *getProtocolStorage() const { 4100c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return const_cast<ObjCObjectType*>(this)->getProtocolStorage(); 4101c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 4102c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4103c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl **getProtocolStorage(); 4104c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4105c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallprotected: 4106ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ObjCObjectType(QualType Canonical, QualType Base, 4107c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, unsigned NumProtocols); 4108c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4109c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall enum Nonce_ObjCInterface { Nonce_ObjCInterface }; 4110c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectType(enum Nonce_ObjCInterface) 4111561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Type(ObjCInterface, QualType(), false, false, false, false), 411271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall BaseType(QualType(this_(), 0)) { 4113b870b88df784c2940efce448ebfaf54dece14666John McCall ObjCObjectTypeBits.NumProtocols = 0; 411471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 4115c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 41163536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 4117e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getBaseType - Gets the base type of this object type. This is 4118e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// always (possibly sugar for) one of: 4119e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// - the 'id' builtin type (as opposed to the 'id' type visible to the 4120e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// user, which is a typedef for an ObjCPointerType) 4121e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// - the 'Class' builtin type (same caveat) 4122e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// - an ObjCObjectType (currently always an ObjCInterfaceType) 4123c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType getBaseType() const { return BaseType; } 412471842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek 4125c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCId() const { 4126c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId); 4127c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 4128c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCClass() const { 4129c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass); 4130c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 4131c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); } 4132c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); } 4133c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCUnqualifiedIdOrClass() const { 4134c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!qual_empty()) return false; 4135c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>()) 4136c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T->getKind() == BuiltinType::ObjCId || 4137c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall T->getKind() == BuiltinType::ObjCClass; 4138c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return false; 4139c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 4140c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); } 4141c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); } 4142c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4143c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// Gets the interface declaration for this object type, if the base type 4144c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// really is an interface. 4145c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCInterfaceDecl *getInterface() const; 4146c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4147c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall typedef ObjCProtocolDecl * const *qual_iterator; 4148c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4149c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator qual_begin() const { return getProtocolStorage(); } 4150c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); } 4151c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4152c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool qual_empty() const { return getNumProtocols() == 0; } 41531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4154c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 4155c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// interface type, or 0 if there are none. 4156b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; } 415714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 4158c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// \brief Fetch a protocol by index. 415973dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor ObjCProtocolDecl *getProtocol(unsigned I) const { 416073dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor assert(I < getNumProtocols() && "Out-of-range protocol access"); 416173dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor return qual_begin()[I]; 416273dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor } 4163ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4164bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 4165bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 4166bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 4167c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static bool classof(const Type *T) { 4168c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T->getTypeClass() == ObjCObject || 4169c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall T->getTypeClass() == ObjCInterface; 4170c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 4171c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static bool classof(const ObjCObjectType *) { return true; } 4172c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}; 4173c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4174c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation 4175c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// of ObjCObjectType, so as to not increase the footprint of 4176c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType. Code outside of ASTContext and the core type 4177c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// system should not reference this type. 4178c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode { 4179c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall friend class ASTContext; 4180c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4181c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // If anyone adds fields here, ObjCObjectType::getProtocolStorage() 4182c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // will need to be modified. 4183c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4184ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ObjCObjectTypeImpl(QualType Canonical, QualType Base, 4185c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 4186c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) 4187c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {} 4188c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4189c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic: 4190c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 41911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, 4192c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType Base, 4193ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ObjCProtocolDecl *const *protocols, 4194ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie unsigned NumProtocols); 4195c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}; 41961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4197c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() { 4198c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return reinterpret_cast<ObjCProtocolDecl**>( 4199c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static_cast<ObjCObjectTypeImpl*>(this) + 1); 4200c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 4201c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4202c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 4203c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// object oriented design. They basically correspond to C++ classes. There 4204c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// are two kinds of interface types, normal interfaces like "NSString" and 4205c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// qualified interfaces, which are qualified with a protocol list like 4206c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// "NSString<NSCopyable, NSAmazing>". 4207e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 4208e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCInterfaceType guarantees the following properties when considered 4209e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// as a subtype of its superclass, ObjCObjectType: 4210e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// - There are no protocol qualifiers. To reinforce this, code which 4211e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// tries to invoke the protocol methods via an ObjCInterfaceType will 4212e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// fail to compile. 4213e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// - It is its own base type. That is, if T is an ObjCInterfaceType*, 4214e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// T->getBaseType() == QualType(T, 0). 4215c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCInterfaceType : public ObjCObjectType { 42168d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor mutable ObjCInterfaceDecl *Decl; 4217c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4218c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCInterfaceType(const ObjCInterfaceDecl *D) 4219c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall : ObjCObjectType(Nonce_ObjCInterface), 4220c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Decl(const_cast<ObjCInterfaceDecl*>(D)) {} 4221c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall friend class ASTContext; // ASTContext creates these. 422256ca8a9c0fabd65418e9b2fd85140f4ed7d3c187Douglas Gregor friend class ASTReader; 42238d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor friend class ObjCInterfaceDecl; 42241fb0caaa7bef765b85972274e3b434af2572c141John McCall 4225c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic: 4226e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getDecl - Get the declaration of this interface. 4227deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor ObjCInterfaceDecl *getDecl() const { return Decl; } 4228c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4229c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isSugared() const { return false; } 4230c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType desugar() const { return QualType(this, 0); } 42310b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 42321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 42331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ObjCInterface; 42343536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 4235a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 4236c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4237c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Nonsense to "hide" certain members of ObjCObjectType within this 4238c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // class. People asking for protocols on an ObjCInterfaceType are 4239c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // not going to get what they want: ObjCInterfaceTypes are 4240c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // guaranteed to have no protocols. 4241c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall enum { 4242c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator, 4243c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_begin, 4244c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_end, 4245c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getNumProtocols, 4246c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getProtocol 4247c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall }; 42483536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 42493536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 4250c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const { 4251c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCInterfaceType *T = 4252c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getBaseType()->getAs<ObjCInterfaceType>()) 4253c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T->getDecl(); 4254c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return 0; 4255c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 4256c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4257e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCObjectPointerType - Used to represent a pointer to an 4258e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Objective C object. These are constructed from pointer 4259e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar 4260e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for one). In addition, the 'id' and 'Class' types are typedefs 4261e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>' 4262e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// are translated into these. 426314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// 4264e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Pointers to pointers to Objective C objects are still PointerTypes; 4265e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// only the first level of pointer gets it own type implementation. 426614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 4267e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall QualType PointeeType; 42681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4269c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerType(QualType Canonical, QualType Pointee) 4270561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Type(ObjCObjectPointer, Canonical, false, false, false, false), 4271c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall PointeeType(Pointee) {} 427214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff friend class ASTContext; // ASTContext creates these. 42731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 427414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic: 4275e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getPointeeType - Gets the type pointed to by this ObjC pointer. 4276e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// The result will always be an ObjCObjectType or sugar thereof. 427714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const { return PointeeType; } 427814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 4279e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getObjCObjectType - Gets the type pointed to by this ObjC 4280e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// pointer. This method always returns non-null. 4281e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// 4282e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// This method is equivalent to getPointeeType() except that 4283e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// it discards any typedefs (or other sugar) between this 4284e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// type and the "outermost" object type. So for: 4285e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// @class A; @protocol P; @protocol Q; 4286e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A<P> AP; 4287e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A A1; 4288e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A1<P> A1P; 4289e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A1P<Q> A1PQ; 4290e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A*', getObjectType() will return 'A'. 4291e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A<P>*', getObjectType() will return 'A<P>'. 4292e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'AP*', getObjectType() will return 'A<P>'. 4293e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1*', getObjectType() will return 'A'. 4294e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1<P>*', getObjectType() will return 'A1<P>'. 4295e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1P*', getObjectType() will return 'A1<P>'. 4296e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because 4297e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// adding protocols to a protocol-qualified base discards the 4298e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// old qualifiers (for now). But if it didn't, getObjectType() 4299e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// would return 'A1P<Q>' (and we'd have to make iterating over 4300e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// qualifiers more complicated). 4301c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *getObjectType() const { 4302d0370f59e79702ac908c81bf556519f91e9ca297John McCall return PointeeType->castAs<ObjCObjectType>(); 4303c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 4304c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4305e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getInterfaceType - If this pointer points to an Objective C 4306e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// @interface type, gets the type for that interface. Any protocol 4307e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// qualifiers on the interface are ignored. 4308e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// 4309e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// \return null if the base type for this pointer is 'id' or 'Class' 43101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const ObjCInterfaceType *getInterfaceType() const { 4311c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>(); 431214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 4313e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 4314e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getInterfaceDecl - If this pointer points to an Objective @interface 4315e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// type, gets the declaration for that interface. 4316e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// 4317e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// \return null if the base type for this pointer is 'id' or 'Class' 431814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCInterfaceDecl *getInterfaceDecl() const { 4319e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall return getObjectType()->getInterface(); 432014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 4321e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 4322e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if 4323e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// its object type is the primitive 'id' type with no protocols. 432414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const { 4325c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCUnqualifiedId(); 432614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 4327e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 4328e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCClassType - True if this is equivalent to the 'Class' type, 4329e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// i.e. if its object tive is the primitive 'Class' type with no protocols. 433014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const { 4331c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCUnqualifiedClass(); 4332de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 4333ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4334e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some 4335e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// non-empty set of protocols. 43361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isObjCQualifiedIdType() const { 4337c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCQualifiedId(); 4338de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 4339e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 4340e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for 4341e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// some non-empty set of protocols. 4342470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const { 4343c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCQualifiedClass(); 434414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 4345e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 4346e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// An iterator over the qualifiers on the object type. Provided 4347e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// for convenience. This will always iterate over the full set of 4348e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// protocols on a type, not just those provided directly. 4349c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall typedef ObjCObjectType::qual_iterator qual_iterator; 435014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 435171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek qual_iterator qual_begin() const { 4352c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->qual_begin(); 435371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek } 4354c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator qual_end() const { 4355c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->qual_end(); 435671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek } 4357c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool qual_empty() const { return getObjectType()->qual_empty(); } 435814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 4359e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getNumProtocols - Return the number of qualifying protocols on 4360e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// the object type. 4361c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned getNumProtocols() const { 4362c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->getNumProtocols(); 4363c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 436414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 4365e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// \brief Retrieve a qualifying protocol by index on the object 4366e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// type. 436773dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor ObjCProtocolDecl *getProtocol(unsigned I) const { 4368c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->getProtocol(I); 436973dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor } 4370ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4371bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 4372bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 4373bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 4374e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall void Profile(llvm::FoldingSetNodeID &ID) { 4375e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall Profile(ID, getPointeeType()); 4376e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall } 4377c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { 4378c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(T.getAsOpaquePtr()); 4379c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 43801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 43811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ObjCObjectPointer; 438214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 438314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 438414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}; 43851bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 4386b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmanclass AtomicType : public Type, public llvm::FoldingSetNode { 4387b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType ValueType; 4388b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4389b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicType(QualType ValTy, QualType Canonical) 4390b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman : Type(Atomic, Canonical, ValTy->isDependentType(), 4391b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ValTy->isInstantiationDependentType(), 4392b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ValTy->isVariablyModifiedType(), 4393b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ValTy->containsUnexpandedParameterPack()), 4394b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ValueType(ValTy) {} 4395b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman friend class ASTContext; // ASTContext creates these. 4396b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4397b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman public: 4398b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// getValueType - Gets the type contained by this atomic type, i.e. 4399b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// the type returned by performing an atomic load of this atomic type. 4400b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType getValueType() const { return ValueType; } 4401b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4402b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman bool isSugared() const { return false; } 4403b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType desugar() const { return QualType(this, 0); } 4404b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4405b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 4406b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Profile(ID, getValueType()); 4407b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 4408b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { 4409b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ID.AddPointer(T.getAsOpaquePtr()); 4410b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 4411b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman static bool classof(const Type *T) { 4412b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return T->getTypeClass() == Atomic; 4413b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 4414b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman static bool classof(const AtomicType *) { return true; } 4415b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman}; 4416b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 44170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers. 44180953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers { 44190953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 442049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {} 44210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 44220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Collect any qualifiers on the given type and return an 44233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// unqualified type. The qualifiers are assumed to be consistent 44243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// with those already in the type. 44253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *strip(QualType type) { 44263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall addFastQualifiers(type.getLocalFastQualifiers()); 44273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!type.hasLocalNonFastQualifiers()) 44283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return type.getTypePtrUnsafe(); 4429ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 44303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ExtQuals *extQuals = type.getExtQualsUnsafe(); 44313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall addConsistentQualifiers(extQuals->getQualifiers()); 44323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return extQuals->getBaseType(); 44330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 44340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 44350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Apply the collected qualifiers to the given type. 44364ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType apply(const ASTContext &Context, QualType QT) const; 44370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 44380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Apply the collected qualifiers to the given type. 44394ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType apply(const ASTContext &Context, const Type* T) const; 44400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 44410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 44420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4443611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 44445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4445200fa53fd420aa8369586f569dbece04930ad6a3John McCallinline SplitQualType SplitQualType::getSingleStepDesugaredType() const { 4446200fa53fd420aa8369586f569dbece04930ad6a3John McCall SplitQualType desugar = 4447200fa53fd420aa8369586f569dbece04930ad6a3John McCall Ty->getLocallyUnqualifiedSingleStepDesugaredType().split(); 4448200fa53fd420aa8369586f569dbece04930ad6a3John McCall desugar.Quals.addConsistentQualifiers(Quals); 4449200fa53fd420aa8369586f569dbece04930ad6a3John McCall return desugar; 4450200fa53fd420aa8369586f569dbece04930ad6a3John McCall} 4451200fa53fd420aa8369586f569dbece04930ad6a3John McCall 44523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtr() const { 44533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getCommonPtr()->BaseType; 44543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 44553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 44563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtrOrNull() const { 44573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return (isNull() ? 0 : getCommonPtr()->BaseType); 44583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 44593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 44603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline SplitQualType QualType::split() const { 44613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!hasLocalNonFastQualifiers()) 44623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return SplitQualType(getTypePtrUnsafe(), 44633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers::fromFastMask(getLocalFastQualifiers())); 44643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 44653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ExtQuals *eq = getExtQualsUnsafe(); 44663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers qs = eq->getQualifiers(); 44673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall qs.addFastQualifiers(getLocalFastQualifiers()); 44683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return SplitQualType(eq->getBaseType(), qs); 44693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 44703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 44713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getLocalQualifiers() const { 44723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers Quals; 44733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (hasLocalNonFastQualifiers()) 44743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals = getExtQualsUnsafe()->getQualifiers(); 44753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals.addFastQualifiers(getLocalFastQualifiers()); 44763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return Quals; 44773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 44783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 44793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getQualifiers() const { 44803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers(); 44813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall quals.addFastQualifiers(getLocalFastQualifiers()); 44823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return quals; 44833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 44843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 44853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline unsigned QualType::getCVRQualifiers() const { 44863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers(); 44873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall cvr |= getLocalCVRQualifiers(); 44883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return cvr; 44893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 44903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 44913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline QualType QualType::getCanonicalType() const { 44923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType canon = getCommonPtr()->CanonicalType; 44933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return canon.withFastQualifiers(getLocalFastQualifiers()); 44943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 44953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 4496467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const { 44973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getTypePtr()->isCanonicalUnqualified(); 4498467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall} 4499467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall 450054e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const { 45013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isCanonical()) return false; 4502a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalQualifiers()) return false; 4503ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 450454e14c4db764c0636160d26c5bbf491637c83a76John McCall const Type *T = getTypePtr(); 45053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (T->isVariablyModifiedType() && T->hasSizedVLAType()) 45063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return false; 45073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 45083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return !isa<FunctionType>(T) && !isa<ArrayType>(T); 450954e14c4db764c0636160d26c5bbf491637c83a76John McCall} 451054e14c4db764c0636160d26c5bbf491637c83a76John McCall 4511fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const { 4512ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return isLocalConstQualified() || 45133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.isLocalConstQualified(); 4514fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 4515fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 4516fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const { 4517ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return isLocalRestrictQualified() || 45183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.isLocalRestrictQualified(); 4519fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 4520fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 4521fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 4522fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const { 4523ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return isLocalVolatileQualified() || 45243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.isLocalVolatileQualified(); 4525fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 4526ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4527fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const { 4528fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return hasLocalQualifiers() || 45293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.hasLocalQualifiers(); 4530fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 453162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 453262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline QualType QualType::getUnqualifiedType() const { 453362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) 453462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return QualType(getTypePtr(), 0); 453562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 4536200fa53fd420aa8369586f569dbece04930ad6a3John McCall return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0); 453762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall} 453862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 453962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline SplitQualType QualType::getSplitUnqualifiedType() const { 454062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) 454162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return split(); 454262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 454362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getSplitUnqualifiedTypeImpl(*this); 4544fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 4545ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 454649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalConst() { 454749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Qualifiers::Const); 45480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 45490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 455049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalRestrict() { 455149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Qualifiers::Restrict); 45520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 45530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 455449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalVolatile() { 455549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Qualifiers::Volatile); 45560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 45570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 455849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalCVRQualifiers(unsigned Mask) { 45596b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits"); 4560c3c0af36bac3d71f61dd758585ab307892545de4Douglas Gregor assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask); 45610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 45620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Fast path: we don't need to touch the slow qualifiers. 456349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Mask); 4564ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 4565ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 4566ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 4567ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 45683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getQualifiers().getAddressSpace(); 4569ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 4570611c1fff195d32df97706e0920c92468b2509900Chris Lattner 4571d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 45720953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const { 45733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getQualifiers().getObjCGCAttr(); 4574d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 45752455636163fdd18581d7fdae816433f886d88213Mike Stump 4576264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { 4577264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola if (const PointerType *PT = t.getAs<PointerType>()) { 4578183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>()) 4579264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FT->getExtInfo(); 4580264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } else if (const FunctionType *FT = t.getAs<FunctionType>()) 4581264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FT->getExtInfo(); 45822455636163fdd18581d7fdae816433f886d88213Mike Stump 4583264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FunctionType::ExtInfo(); 45842455636163fdd18581d7fdae816433f886d88213Mike Stump} 45851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4586264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { 4587264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return getFunctionExtInfo(*t); 4588ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor} 4589ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor 4590e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 4591e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 4592e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and 4593e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile 4594e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int". 459562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isMoreQualifiedThan(QualType other) const { 459662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Qualifiers myQuals = getQualifiers(); 459762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Qualifiers otherQuals = other.getQualifiers(); 459862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return (myQuals != otherQuals && myQuals.compatiblyIncludes(otherQuals)); 4599e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 4600e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 4601e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 4602e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile 4603e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 4604e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int". 460562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isAtLeastAsQualifiedAs(QualType other) const { 460662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getQualifiers().compatiblyIncludes(other.getQualifiers()); 4607e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 4608e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 4609e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 4610e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const 4611e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 4612e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6: 4613e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 4614e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 4615e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 4616e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// analysis, the expression designates the object or function 4617e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 4618e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const { 46196217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 4620e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return RefType->getPointeeType(); 4621e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor else 4622e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return *this; 4623e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 4624e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 46252b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregorinline bool QualType::isCForbiddenLValueType() const { 46262b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor return ((getTypePtr()->isVoidType() && !hasQualifiers()) || 46272b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor getTypePtr()->isFunctionType()); 46282b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor} 46292b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor 4630aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \brief Tests whether the type is categorized as a fundamental type. 4631aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// 4632aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \returns True for types specified in C++0x [basic.fundamental]. 4633aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruthinline bool Type::isFundamentalType() const { 4634aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth return isVoidType() || 4635aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // FIXME: It's really annoying that we don't have an 4636aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // 'isArithmeticType()' which agrees with the standard definition. 4637aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth (isArithmeticType() && !isEnumeralType()); 4638aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth} 4639aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth 4640aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \brief Tests whether the type is categorized as a compound type. 4641aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// 4642aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \returns True for types specified in C++0x [basic.compound]. 4643aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruthinline bool Type::isCompoundType() const { 4644aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // C++0x [basic.compound]p1: 4645aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // Compound types can be constructed in the following ways: 4646aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- arrays of objects of a given type [...]; 4647aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth return isArrayType() || 4648aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- functions, which have parameters of given types [...]; 4649aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isFunctionType() || 4650aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- pointers to void or objects or functions [...]; 4651aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isPointerType() || 4652aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- references to objects or functions of a given type. [...] 4653aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isReferenceType() || 4654aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- classes containing a sequence of objects of various types, [...]; 4655aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isRecordType() || 4656ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie // -- unions, which are classes capable of containing objects of different 4657ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie // types at different times; 4658aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isUnionType() || 4659aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- enumerations, which comprise a set of named constant values. [...]; 4660aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isEnumeralType() || 4661aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- pointers to non-static class members, [...]. 4662aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isMemberPointerType(); 4663aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth} 4664aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth 4665611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 4666a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<FunctionType>(CanonicalType); 4667611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 4668611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 4669a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<PointerType>(CanonicalType); 4670611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 467158f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const { 467258f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff return isPointerType() || isObjCObjectPointerType(); 467358f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff} 46745618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const { 4675a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<BlockPointerType>(CanonicalType); 46765618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 4677bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const { 4678a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ReferenceType>(CanonicalType); 4679bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 46807c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const { 4681a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<LValueReferenceType>(CanonicalType); 46827c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 46837c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const { 4684a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<RValueReferenceType>(CanonicalType); 46857c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 4686498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 4687d0370f59e79702ac908c81bf556519f91e9ca297John McCall if (const PointerType *T = getAs<PointerType>()) 4688498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 4689498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 4690498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 4691498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 4692f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const { 4693a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<MemberPointerType>(CanonicalType); 4694f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 4695f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 46966217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const MemberPointerType* T = getAs<MemberPointerType>()) 46970bab0cdab751248ca389a5592bcb70eac5d39260John McCall return T->isMemberFunctionPointer(); 4698f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl else 4699f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return false; 4700f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 4701db68e28c05a67735211e688009890cf834c22e75Douglas Gregorinline bool Type::isMemberDataPointerType() const { 4702db68e28c05a67735211e688009890cf834c22e75Douglas Gregor if (const MemberPointerType* T = getAs<MemberPointerType>()) 47030bab0cdab751248ca389a5592bcb70eac5d39260John McCall return T->isMemberDataPointer(); 4704db68e28c05a67735211e688009890cf834c22e75Douglas Gregor else 4705db68e28c05a67735211e688009890cf834c22e75Douglas Gregor return false; 4706db68e28c05a67735211e688009890cf834c22e75Douglas Gregor} 4707611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 4708a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ArrayType>(CanonicalType); 4709611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 4710c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const { 4711a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ConstantArrayType>(CanonicalType); 4712c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 4713c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const { 4714a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<IncompleteArrayType>(CanonicalType); 4715c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 4716c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const { 4717a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<VariableArrayType>(CanonicalType); 4718c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 4719898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const { 4720a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType); 4721898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 47223ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isBuiltinType() const { 47233ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall return isa<BuiltinType>(CanonicalType); 47243ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall} 4725611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 4726a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<RecordType>(CanonicalType); 4727611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 47283ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isEnumeralType() const { 47293ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall return isa<EnumType>(CanonicalType); 47303ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall} 4731f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const { 4732a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ComplexType>(CanonicalType); 4733f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner} 4734611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 4735a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<VectorType>(CanonicalType); 4736611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 4737213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const { 4738a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ExtVectorType>(CanonicalType); 4739611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 4740d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const { 4741a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ObjCObjectPointerType>(CanonicalType); 4742d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 4743c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline bool Type::isObjCObjectType() const { 4744c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return isa<ObjCObjectType>(CanonicalType); 4745368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 4746569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorinline bool Type::isObjCObjectOrInterfaceType() const { 4747ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return isa<ObjCInterfaceType>(CanonicalType) || 4748569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor isa<ObjCObjectType>(CanonicalType); 4749569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor} 4750b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmaninline bool Type::isAtomicType() const { 4751b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return isa<AtomicType>(CanonicalType); 4752b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 4753569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor 4754a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 4755183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 4756d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT->isObjCQualifiedIdType(); 4757d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return false; 4758d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 4759470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const { 4760183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 4761470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return OPT->isObjCQualifiedClassType(); 4762470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return false; 4763470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff} 476414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const { 4765183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 476614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCIdType(); 476714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 476814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 476914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const { 4770183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 477114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCClassType(); 477214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 477314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 477413dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const { 47758d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian if (const PointerType *OPT = getAs<PointerType>()) 47768d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); 477713dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian return false; 477813dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian} 4779de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const { 478013dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian return isObjCIdType() || isObjCClassType() || isObjCSelType(); 4781de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff} 478272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const { 4783a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType); 478472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor} 478572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4786e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 4787183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 4788e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 4789e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return true; 4790e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return false; 4791e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar} 4792e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 47932a984cad5ac3fdceeff2bd99daa7b90979313475John McCallinline bool Type::isPlaceholderType() const { 4794a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(this)) 47952a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return BT->isPlaceholderType(); 47962a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return false; 47972a984cad5ac3fdceeff2bd99daa7b90979313475John McCall} 47982a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 4799a180f04c091bf3ede4fe292ba6a29d61da09e936John McCallinline const BuiltinType *Type::getAsPlaceholderType() const { 4800a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(this)) 4801a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall if (BT->isPlaceholderType()) 4802a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall return BT; 4803a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall return 0; 4804a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall} 4805a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall 4806864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCallinline bool Type::isSpecificPlaceholderType(unsigned K) const { 480785def357129b6cdfd69a66ad0e6994506418a2a9John McCall assert(BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K)); 4808864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(this)) 4809864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return (BT->getKind() == (BuiltinType::Kind) K); 4810864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return false; 4811864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall} 4812864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 481332509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCallinline bool Type::isNonOverloadPlaceholderType() const { 481432509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(this)) 481532509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall return BT->isNonOverloadPlaceholderType(); 481632509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall return false; 481732509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall} 481832509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall 4819063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define 4820063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator. 4821063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const { 4822063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 4823904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor} 4824904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 4825bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth/// \brief Determines whether this type can decay to a pointer type. 4826bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruthinline bool Type::canDecayToPointerType() const { 4827bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth return isFunctionType() || isArrayType(); 4828bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth} 4829bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth 48308958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 48318958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 4832c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall isObjCObjectPointerType() || isNullPtrType()); 48338958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar} 48348958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 4835820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 4836c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return isObjCObjectPointerType(); 4837820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian} 4838820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 4839d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const Type *Type::getBaseElementTypeUnsafe() const { 4840d0370f59e79702ac908c81bf556519f91e9ca297John McCall const Type *type = this; 4841d0370f59e79702ac908c81bf556519f91e9ca297John McCall while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe()) 4842d0370f59e79702ac908c81bf556519f91e9ca297John McCall type = arrayType->getElementType().getTypePtr(); 4843d0370f59e79702ac908c81bf556519f91e9ca297John McCall return type; 4844d0370f59e79702ac908c81bf556519f91e9ca297John McCall} 4845d0370f59e79702ac908c81bf556519f91e9ca297John McCall 484622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 484722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<. 4848d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 4849d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer QualType T) { 4850d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 4851d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer DiagnosticsEngine::ak_qualtype); 4852d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer return DB; 4853d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer} 48541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 485547c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// Insertion operator for partial diagnostics. This allows sending QualType's 485647c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// into a diagnostic with <<. 4857d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramerinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, 4858d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer QualType T) { 4859d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 4860d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer DiagnosticsEngine::ak_qualtype); 4861d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer return PD; 4862d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer} 486347c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth 486489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does 486589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type. 486689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T, 486789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor bool isArrayType = (llvm::is_same<T, ArrayType>::value || 486889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor llvm::is_base_of<ArrayType, T>::value)> 486989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { }; 4870ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 487189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T> 487289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>; 4873ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 48741a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'. 48751a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const { 487689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor ArrayType_cannot_be_used_with_getAs<T> at; 487789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor (void)at; 4878ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 48791a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If this is directly a T type, return it. 48801a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek if (const T *Ty = dyn_cast<T>(this)) 48811a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return Ty; 48821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48831a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If the canonical form of this type isn't the right kind, reject it. 48840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<T>(CanonicalType)) 48851a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return 0; 48861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If this is a typedef for the type, strip the typedef off without 48881a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // losing all typedef information. 4889bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<T>(getUnqualifiedDesugaredType()); 48901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 489122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner 48923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const ArrayType *Type::getAsArrayTypeUnsafe() const { 48933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If this is directly an array type, return it. 48943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const ArrayType *arr = dyn_cast<ArrayType>(this)) 48953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return arr; 48963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 48973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If the canonical form of this type isn't the right kind, reject it. 48983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isa<ArrayType>(CanonicalType)) 48993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return 0; 49003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 49013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If this is a typedef for the type, strip the typedef off without 49023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // losing all typedef information. 49033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()); 49043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 49053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 4906d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <typename T> const T *Type::castAs() const { 4907d0370f59e79702ac908c81bf556519f91e9ca297John McCall ArrayType_cannot_be_used_with_getAs<T> at; 4908d0370f59e79702ac908c81bf556519f91e9ca297John McCall (void) at; 4909d0370f59e79702ac908c81bf556519f91e9ca297John McCall 4910d0370f59e79702ac908c81bf556519f91e9ca297John McCall assert(isa<T>(CanonicalType)); 4911d0370f59e79702ac908c81bf556519f91e9ca297John McCall if (const T *ty = dyn_cast<T>(this)) return ty; 4912d0370f59e79702ac908c81bf556519f91e9ca297John McCall return cast<T>(getUnqualifiedDesugaredType()); 4913d0370f59e79702ac908c81bf556519f91e9ca297John McCall} 4914d0370f59e79702ac908c81bf556519f91e9ca297John McCall 4915d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const ArrayType *Type::castAsArrayTypeUnsafe() const { 4916d0370f59e79702ac908c81bf556519f91e9ca297John McCall assert(isa<ArrayType>(CanonicalType)); 4917d0370f59e79702ac908c81bf556519f91e9ca297John McCall if (const ArrayType *arr = dyn_cast<ArrayType>(this)) return arr; 4918d0370f59e79702ac908c81bf556519f91e9ca297John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()); 4919d0370f59e79702ac908c81bf556519f91e9ca297John McCall} 4920d0370f59e79702ac908c81bf556519f91e9ca297John McCall 49215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 49225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 49235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 4924