Type.h revision b870b88df784c2940efce448ebfaf54dece14666
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Type interface and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_TYPE_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_TYPE_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner#include "clang/Basic/Diagnostic.h" 181734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "clang/Basic/IdentifierTable.h" 190b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor#include "clang/Basic/Linkage.h" 2047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth#include "clang/Basic/PartialDiagnostic.h" 21e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor#include "clang/AST/NestedNameSpecifier.h" 227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor#include "clang/AST/TemplateName.h" 235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/Casting.h" 2450d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor#include "llvm/Support/type_traits.h" 25fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff#include "llvm/ADT/APSInt.h" 265cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/FoldingSet.h" 275cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/PointerIntPair.h" 281734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "llvm/ADT/PointerUnion.h" 297532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa; 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast; 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null; 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast; 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null; 356b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCallnamespace clang { 366b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall enum { 376b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeAlignmentInBits = 3, 386b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeAlignment = 1 << TypeAlignmentInBits 396b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall }; 40aed1df80bf64228e1429c1edc408397f9174847cChris Lattner class Type; 41aed1df80bf64228e1429c1edc408397f9174847cChris Lattner class ExtQuals; 42aed1df80bf64228e1429c1edc408397f9174847cChris Lattner class QualType; 436b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall} 445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 454e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm { 464e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner template <typename T> 47daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner class PointerLikeTypeTraits; 48bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner template<> 49bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner class PointerLikeTypeTraits< ::clang::Type*> { 50bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner public: 51bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 52bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner static inline ::clang::Type *getFromVoidPointer(void *P) { 53bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner return static_cast< ::clang::Type*>(P); 54bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner } 556b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 56bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner }; 570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall template<> 580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall class PointerLikeTypeTraits< ::clang::ExtQuals*> { 590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall public: 600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; } 610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static inline ::clang::ExtQuals *getFromVoidPointer(void *P) { 620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return static_cast< ::clang::ExtQuals*>(P); 630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 646b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall }; 66aed1df80bf64228e1429c1edc408397f9174847cChris Lattner 67aed1df80bf64228e1429c1edc408397f9174847cChris Lattner template <> 68aed1df80bf64228e1429c1edc408397f9174847cChris Lattner struct isPodLike<clang::QualType> { static const bool value = true; }; 694e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner} 704e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner 715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class ASTContext; 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TypedefDecl; 7455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor class TemplateDecl; 7572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor class TemplateTypeParmDecl; 76aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor class NonTypeTemplateParmDecl; 777532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor class TemplateTemplateParmDecl; 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TagDecl; 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class RecordDecl; 8049aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis class CXXRecordDecl; 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class EnumDecl; 8221d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek class FieldDecl; 83a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCInterfaceDecl; 84a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCProtocolDecl; 85a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCMethodDecl; 86ed97649e9574b9d854fa4d6109c9333ae0993554John McCall class UnresolvedUsingTypenameDecl; 875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Expr; 88b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek class Stmt; 895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class SourceLocation; 9092866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek class StmtIteratorBase; 9140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor class TemplateArgument; 92833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall class TemplateArgumentLoc; 93d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall class TemplateArgumentListInfo; 94ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall class Type; 95465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara class ElaboratedType; 963b4ea54acf01f72f6eb74d96689dda86d950228fDaniel Dunbar struct PrintingPolicy; 9772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 98ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall 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 1250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall enum { 1260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// The maximum supported address space number. 1270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// 24 bits should be enough for anyone. 1280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall MaxAddressSpace = 0xffffffu, 1290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// The width of the "fast" qualifier mask. 1310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall FastWidth = 2, 1320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// The fast qualifier mask. 1340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall FastMask = (1 << FastWidth) - 1 1350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall }; 1360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers() : Mask(0) {} 1380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static Qualifiers fromFastMask(unsigned Mask) { 1400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Qs; 1410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qs.addFastQualifiers(Mask); 1420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs; 1430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static Qualifiers fromCVRMask(unsigned CVR) { 1460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Qs; 1470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qs.addCVRQualifiers(CVR); 1480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs; 1490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Deserialize qualifiers from an opaque representation. 1520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static Qualifiers fromOpaqueValue(unsigned opaque) { 1530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Qs; 1540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qs.Mask = opaque; 1550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs; 1560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Serialize these qualifiers into an opaque representation. 1590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getAsOpaqueValue() const { 1600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Mask; 1610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasConst() const { return Mask & Const; } 1640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setConst(bool flag) { 1650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~Const) | (flag ? Const : 0); 1660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeConst() { Mask &= ~Const; } 1680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addConst() { Mask |= Const; } 1690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasVolatile() const { return Mask & Volatile; } 1710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setVolatile(bool flag) { 1720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~Volatile) | (flag ? Volatile : 0); 1730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeVolatile() { Mask &= ~Volatile; } 1750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addVolatile() { Mask |= Volatile; } 1760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasRestrict() const { return Mask & Restrict; } 1780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setRestrict(bool flag) { 1790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~Restrict) | (flag ? Restrict : 0); 1800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeRestrict() { Mask &= ~Restrict; } 1820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addRestrict() { Mask |= Restrict; } 1830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasCVRQualifiers() const { return getCVRQualifiers(); } 1850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getCVRQualifiers() const { return Mask & CVRMask; } 1860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setCVRQualifiers(unsigned mask) { 1870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 1880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~CVRMask) | mask; 1890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeCVRQualifiers(unsigned mask) { 1910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 1920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask &= ~mask; 1930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeCVRQualifiers() { 1950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeCVRQualifiers(CVRMask); 1960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addCVRQualifiers(unsigned mask) { 1980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 1990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= mask; 2000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasObjCGCAttr() const { return Mask & GCAttrMask; } 2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); } 2040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setObjCGCAttr(GC type) { 2050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift); 2060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeObjCGCAttr() { setObjCGCAttr(GCNone); } 2080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addObjCGCAttr(GC type) { 2090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(type); 2100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall setObjCGCAttr(type); 2110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasAddressSpace() const { return Mask & AddressSpaceMask; } 2140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; } 2150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setAddressSpace(unsigned space) { 2160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(space <= MaxAddressSpace); 2170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~AddressSpaceMask) 2180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall | (((uint32_t) space) << AddressSpaceShift); 2190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeAddressSpace() { setAddressSpace(0); } 2210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addAddressSpace(unsigned space) { 2220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(space); 2230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall setAddressSpace(space); 2240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Fast qualifiers are those that can be allocated directly 2270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // on a QualType object. 2280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasFastQualifiers() const { return getFastQualifiers(); } 2290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getFastQualifiers() const { return Mask & FastMask; } 2300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setFastQualifiers(unsigned mask) { 2310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~FastMask) | mask; 2330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeFastQualifiers(unsigned mask) { 2350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask &= ~mask; 2370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeFastQualifiers() { 2390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeFastQualifiers(FastMask); 2400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addFastQualifiers(unsigned mask) { 2420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= mask; 2440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// hasNonFastQualifiers - Return true if the set contains any 2470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// qualifiers which require an ExtQuals node to be allocated. 2480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasNonFastQualifiers() const { return Mask & ~FastMask; } 2490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers getNonFastQualifiers() const { 2500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Quals = *this; 2510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.setFastQualifiers(0); 2520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Quals; 2530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// hasQualifiers - Return true if the set contains any qualifiers. 2560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasQualifiers() const { return Mask; } 2570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool empty() const { return !Mask; } 2580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// \brief Add the qualifiers from the given set to this set. 2600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addQualifiers(Qualifiers Q) { 2610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If the other set doesn't have any non-boolean qualifiers, just 2620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // bit-or it in. 2630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!(Q.Mask & ~CVRMask)) 2640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= Q.Mask; 2650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall else { 2660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= (Q.Mask & CVRMask); 2670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Q.hasAddressSpace()) 2680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addAddressSpace(Q.getAddressSpace()); 2690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Q.hasObjCGCAttr()) 2700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addObjCGCAttr(Q.getObjCGCAttr()); 2710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 274b87786f045d798b070980c108c922e1475d27b15Douglas Gregor bool isSupersetOf(Qualifiers Other) const; 275b87786f045d798b070980c108c922e1475d27b15Douglas Gregor 2760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool operator==(Qualifiers Other) const { return Mask == Other.Mask; } 2770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; } 2780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall operator bool() const { return hasQualifiers(); } 2800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers &operator+=(Qualifiers R) { 2820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addQualifiers(R); 2830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return *this; 2840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Union two qualifier sets. If an enumerated qualifier appears 2870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // in both sets, use the one from the right. 2880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall friend Qualifiers operator+(Qualifiers L, Qualifiers R) { 2890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall L += R; 2900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return L; 2910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2923cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor 2933cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor Qualifiers &operator-=(Qualifiers R) { 2943cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor Mask = Mask & ~(R.Mask); 2953cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor return *this; 2963cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor } 2970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2983cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor /// \brief Compute the difference between two qualifier sets. 2993cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor friend Qualifiers operator-(Qualifiers L, Qualifiers R) { 3003cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor L -= R; 3013cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor return L; 3023cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor } 3033cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor 3040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string getAsString() const; 3050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string getAsString(const PrintingPolicy &Policy) const { 3060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string Buffer; 3070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getAsStringInternal(Buffer, Policy); 3080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Buffer; 3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const; 3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ID.AddInteger(Mask); 3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate: 3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // bits: |0 1 2|3 .. 4|5 .. 31| 3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // |C R V|GCAttr|AddrSpace| 3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall uint32_t Mask; 3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t GCAttrMask = 0x18; 3230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t GCAttrShift = 3; 3240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask); 3250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t AddressSpaceShift = 5; 3260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// ExtQuals - We can encode up to three bits in the low bits of a 3300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// type pointer, but there are many more type qualifiers that we want 3310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// to be able to apply to an arbitrary type. Therefore we have this 3320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// struct, intended to be heap-allocated and used by QualType to 3330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// store qualifiers. 3340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 3350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// The current design tags the 'const' and 'restrict' qualifiers in 3360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// two low bits on the QualType pointer; a third bit records whether 3370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// the pointer is an ExtQuals node. 'const' was chosen because it is 3380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// orders of magnitude more common than the other two qualifiers, in 3390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// both library and user code. It's relatively rare to see 3400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'restrict' in user code, but many standard C headers are saturated 3410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// with 'restrict' declarations, so that representing them efficiently 3420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// is a critical goal of this representation. 3430953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass ExtQuals : public llvm::FoldingSetNode { 3440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // NOTE: changing the fast qualifiers should be straightforward as 3450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // long as you don't make 'const' non-fast. 3460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // 1. Qualifiers: 3470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ). 3480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Fast qualifiers must occupy the low-order bits. 3490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // b) Update Qualifiers::FastWidth and FastMask. 3500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // 2. QualType: 3510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // a) Update is{Volatile,Restrict}Qualified(), defined inline. 3520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // b) Update remove{Volatile,Restrict}, defined near the end of 3530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // this header. 3540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // 3. ASTContext: 3550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // a) Update get{Volatile,Restrict}Type. 3560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Context - the context to which this set belongs. We save this 3580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// here so that QualifierCollector can use it to reapply extended 3590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// qualifiers to an arbitrary type without requiring a context to 3600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// be pushed through every single API dealing with qualifiers. 3610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ASTContext& Context; 3620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// BaseType - the underlying type that this qualifies 3640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *BaseType; 3650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Quals - the immutable set of qualifiers applied by this 3670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// node; always contains extended qualifiers. 3680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Quals; 3690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3700953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 3710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ExtQuals(ASTContext& Context, const Type *Base, Qualifiers Quals) 3720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Context(Context), BaseType(Base), Quals(Quals) 3730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall { 3740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(Quals.hasNonFastQualifiers() 3750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall && "ExtQuals created with no fast qualifiers"); 3760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!Quals.hasFastQualifiers() 3770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall && "ExtQuals created with fast qualifiers"); 3780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers getQualifiers() const { return Quals; } 3810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasVolatile() const { return Quals.hasVolatile(); } 3830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); } 3850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); } 3860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasAddressSpace() const { return Quals.hasAddressSpace(); } 3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getAddressSpace() const { return Quals.getAddressSpace(); } 3890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *getBaseType() const { return BaseType; } 3911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ASTContext &getContext() const { return Context; } 3930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3940953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 3950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 3960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Profile(ID, getBaseType(), Quals); 3970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, 3990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *BaseType, 4000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Quals) { 4010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!"); 4020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ID.AddPointer(BaseType); 4030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.Profile(ID); 4040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 4060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 407ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses. 408ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv { 409ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_Default, 410ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_C, // __attribute__((cdecl)) 411ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_X86StdCall, // __attribute__((stdcall)) 412f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor CC_X86FastCall, // __attribute__((fastcall)) 41352fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik CC_X86ThisCall, // __attribute__((thiscall)) 41452fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik CC_X86Pascal // __attribute__((pascal)) 415ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}; 416ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor 4170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on 4190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers. This 4200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for 4210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int', 4220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc). 4230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 4240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we 4250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the 4260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer. To handle the packing/unpacking, we make QualType be a 4270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer. A third bit 4280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which 4290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure. 4300953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType { 4310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Thankfully, these are efficiently composable. 4320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>, 4330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::FastWidth> Value; 4340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *getExtQualsUnsafe() const { 4360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().get<const ExtQuals*>(); 4370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *getTypePtrUnsafe() const { 4400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().get<const Type*>(); 4410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 443fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor QualType getUnqualifiedTypeSlow() const; 444fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 4450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall friend class QualifierCollector; 4460953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 4475cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType() {} 4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4495cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType(const Type *Ptr, unsigned Quals) 4500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Value(Ptr, Quals) {} 4510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType(const ExtQuals *Ptr, unsigned Quals) 4520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Value(Ptr, Quals) {} 4530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 454a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor unsigned getLocalFastQualifiers() const { return Value.getInt(); } 455a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); } 4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Retrieves a pointer to the underlying (unqualified) type. 4580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// This should really return a const Type, but it's not worth 4590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// changing all the users right now. 4600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Type *getTypePtr() const { 461a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalNonFastQualifiers()) 4620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return const_cast<Type*>(getExtQualsUnsafe()->getBaseType()); 4630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return const_cast<Type*>(getTypePtrUnsafe()); 4640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4665cf243a883872441d73ca49cea7e20de5802629bChris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static QualType getFromOpaquePtr(void *Ptr) { 4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType T; 4695cf243a883872441d73ca49cea7e20de5802629bChris Lattner T.Value.setFromOpaqueValue(Ptr); 4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T; 4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type &operator*() const { 4745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *getTypePtr(); 4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *operator->() const { 4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypePtr(); 4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 481467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall bool isCanonical() const; 48254e14c4db764c0636160d26c5bbf491637c83a76John McCall bool isCanonicalAsParam() const; 483467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall 4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNull - Return true if this QualType doesn't point to a type yet. 4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNull() const { 4860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().isNull(); 4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 489a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has the 490a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "const" qualifier set, without looking through typedefs that may have 491a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "const" at a different level. 492a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalConstQualified() const { 493a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Const); 4940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 495a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 496a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is const-qualified. 497fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isConstQualified() const; 498a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 499a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has the 500a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "restrict" qualifier set, without looking through typedefs that may have 501a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "restrict" at a different level. 502a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalRestrictQualified() const { 503a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Restrict); 504a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor } 505a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 506a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is restrict-qualified. 507fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isRestrictQualified() const; 508a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 509a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has the 510a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "volatile" qualifier set, without looking through typedefs that may have 511a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "volatile" at a different level. 512a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalVolatileQualified() const { 513a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return (hasLocalNonFastQualifiers() && getExtQualsUnsafe()->hasVolatile()); 5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 516a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is volatile-qualified. 517fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isVolatileQualified() const; 518a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 519a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has any 520a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// qualifiers, without looking through any typedefs that might add 521a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// qualifiers at a different level. 522a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool hasLocalQualifiers() const { 523a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return getLocalFastQualifiers() || hasLocalNonFastQualifiers(); 5240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 526a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type has any qualifiers. 527fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool hasQualifiers() const; 528a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 529a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has any 530a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType 531a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// instance. 532a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool hasLocalNonFastQualifiers() const { 533a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return Value.getPointer().is<const ExtQuals*>(); 5340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 536a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of qualifiers local to this particular QualType 537a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// instance, not including any qualifiers acquired through typedefs or 538a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// other sugar. 539a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers getLocalQualifiers() const { 5400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Quals; 541a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalNonFastQualifiers()) 5420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals = getExtQualsUnsafe()->getQualifiers(); 543a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Quals.addFastQualifiers(getLocalFastQualifiers()); 5440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Quals; 5450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 547a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of qualifiers applied to this type. 548fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor Qualifiers getQualifiers() const; 549a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 550a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 551a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// local to this particular QualType instance, not including any qualifiers 552a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// acquired through typedefs or other sugar. 553a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor unsigned getLocalCVRQualifiers() const { 554a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor unsigned CVR = getLocalFastQualifiers(); 555a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (isLocalVolatileQualified()) 556a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor CVR |= Qualifiers::Volatile; 5570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return CVR; 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 559b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 560a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 561a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// applied to this type. 562fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor unsigned getCVRQualifiers() const; 563e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth 564e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 565e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth /// applied to this type, looking through any number of unqualified array 566e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth /// types to their element types' qualifiers. 567e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth unsigned getCVRQualifiersThroughArrayTypes() const; 568e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth 569bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isConstant(ASTContext& Ctx) const { 570bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return QualType::isConstant(*this, Ctx); 571bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 5721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Don't promise in the API that anything besides 'const' can be 5740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // easily added. 5750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// addConst - add the specified type qualifier to this QualType. 5770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addConst() { 5780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addFastQualifiers(Qualifiers::Const); 5790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withConst() const { 5810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return withFastQualifiers(Qualifiers::Const); 5820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addFastQualifiers(unsigned TQs) { 5850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(TQs & ~Qualifiers::FastMask) 5860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall && "non-fast qualifier bits set in mask!"); 5870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Value.setInt(Value.getInt() | TQs); 5880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 590a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor // FIXME: The remove* functions are semantically broken, because they might 591a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor // not remove a qualifier stored on a typedef. Most of the with* functions 592a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor // have the same problem. 5930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeConst(); 5940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeVolatile(); 5950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeRestrict(); 5960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeCVRQualifiers(unsigned Mask); 5970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeFastQualifiers() { Value.setInt(0); } 5990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeFastQualifiers(unsigned Mask) { 6000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers"); 6010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Value.setInt(Value.getInt() & ~Mask); 6020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 6035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Creates a type with the given qualifiers in addition to any 6050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // qualifiers already on this type. 6060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withFastQualifiers(unsigned TQs) const { 6070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType T = *this; 6080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall T.addFastQualifiers(TQs); 6090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return T; 6100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 6111c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta 6120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Creates a type with exactly the given fast qualifiers, removing 6130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // any existing fast qualifiers. 6140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withExactFastQualifiers(unsigned TQs) const { 6150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return withoutFastQualifiers().withFastQualifiers(TQs); 6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 6180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Removes fast qualifiers, but leaves any extended qualifiers in place. 6190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withoutFastQualifiers() const { 6200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType T = *this; 6210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall T.removeFastQualifiers(); 6220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return T; 623c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 624971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 625a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Return this type with all of the instance-specific qualifiers 626a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// removed, but without removing any qualifiers that may have been applied 627a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// through typedefs. 628a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); } 6291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 630a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Return the unqualified form of the given type, which might be 631a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// desugared to eliminate qualifiers introduced via typedefs. 632fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor QualType getUnqualifiedType() const { 633fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor QualType T = getLocalUnqualifiedType(); 634fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor if (!T.hasQualifiers()) 635fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return T; 636fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 637fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return getUnqualifiedTypeSlow(); 638a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor } 639a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 640e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 641e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 642e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getNonReferenceType() const; 6431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6446398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// \brief Determine the type of a (typically non-lvalue) expression with the 6456398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// specified result type. 6465291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// 6476398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// This routine should be used for expressions for which the return type is 6486398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// explicitly specified (e.g., in a cast or call) and isn't necessarily 6496398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor /// an lvalue. It removes a top-level reference (since there are no 6505291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// expressions of reference type) and deletes top-level cvr-qualifiers 6515291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// from non-class types (in C++) or all types (in C). 6526398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor QualType getNonLValueExprType(ASTContext &Context) const; 6535291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 6542fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 6552fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 6562fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 6572fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 6582fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 6592fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// concrete. 6600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// 6610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Qualifiers are left in place. 662bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType getDesugaredType() const { 663bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return QualType::getDesugaredType(*this); 664bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 66598cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor 6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// operator==/!= - Indicate whether the specified types and qualifiers are 6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identical. 66850d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor friend bool operator==(const QualType &LHS, const QualType &RHS) { 66950d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return LHS.Value == RHS.Value; 6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 67150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor friend bool operator!=(const QualType &LHS, const QualType &RHS) { 67250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return LHS.Value != RHS.Value; 6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 674d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString() const; 675d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 676d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString(const PrintingPolicy &Policy) const { 6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string S; 678d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor getAsStringInternal(S, Policy); 6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return S; 6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 681e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner void getAsStringInternal(std::string &Str, 682e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy) const; 6831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 684c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump(const char *s) const; 685c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 6861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6873f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 6883f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 6893f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek } 6905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 691ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 692ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 6931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 694d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 6950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall inline Qualifiers::GC getObjCGCAttr() const; 696f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 697f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 698f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCWeak() const { 6990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getObjCGCAttr() == Qualifiers::Weak; 700f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 701f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 702f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 703f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCStrong() const { 7040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getObjCGCAttr() == Qualifiers::Strong; 705f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 7062455636163fdd18581d7fdae816433f886d88213Mike Stump 707bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate: 708bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // These methods are implemented in a separate translation unit; 709bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // "static"-ize them to avoid creating temporary QualTypes in the 710bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // caller. 711bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall static bool isConstant(QualType T, ASTContext& Ctx); 712bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall static QualType getDesugaredType(QualType T); 7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef ::clang::Type* SimpleType; 7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Val.getTypePtr(); 7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7294e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 7304e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<> 731daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 7324e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic: 7334e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 7344e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return P.getAsOpaquePtr(); 7354e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 7364e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 7374e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return clang::QualType::getFromOpaquePtr(P); 7384e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 7390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Various qualifiers go in low bits. 7400eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 0 }; 7414e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}; 7421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 74373af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 75872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 76172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type { 7735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 77572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class, 77627935ee59c30b0d8b610ab676aab8e65350af932John McCall#define LAST_TYPE(Class) TypeLast = Class, 77772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 77872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 77972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TagFirst = Record, TagLast = Enum 7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 7811bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 783c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Type(const Type&); // DO NOT IMPLEMENT. 784c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall void operator=(const Type&); // DO NOT IMPLEMENT. 785c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType CanonicalType; 7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 788b870b88df784c2940efce448ebfaf54dece14666John McCall /// Bitfields required by the Type class. 789b870b88df784c2940efce448ebfaf54dece14666John McCall class TypeBitfields { 790b870b88df784c2940efce448ebfaf54dece14666John McCall friend class Type; 79127935ee59c30b0d8b610ab676aab8e65350af932John McCall 792b870b88df784c2940efce448ebfaf54dece14666John McCall /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 793b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned TC : 8; 794b870b88df784c2940efce448ebfaf54dece14666John McCall 795b870b88df784c2940efce448ebfaf54dece14666John McCall /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 796b870b88df784c2940efce448ebfaf54dece14666John McCall /// Note that this should stay at the end of the ivars for Type so that 797b870b88df784c2940efce448ebfaf54dece14666John McCall /// subclasses can pack their bitfields into the same word. 798b870b88df784c2940efce448ebfaf54dece14666John McCall bool Dependent : 1; 79960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 800b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief Whether this type is a variably-modified type (C99 6.7.5). 801b870b88df784c2940efce448ebfaf54dece14666John McCall bool VariablyModified : 1; 80235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 803b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief Whether the linkage of this type along with the presence of any 804b870b88df784c2940efce448ebfaf54dece14666John McCall /// local or unnamed types is already known. 805b870b88df784c2940efce448ebfaf54dece14666John McCall mutable bool LinkageKnown : 1; 80660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 807b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief Linkage of this type. 808b870b88df784c2940efce448ebfaf54dece14666John McCall mutable unsigned CachedLinkage : 2; 80907a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 810b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief Whether this type involves and local or unnamed types. 811b870b88df784c2940efce448ebfaf54dece14666John McCall mutable bool CachedLocalOrUnnamed : 1; 812db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 813b870b88df784c2940efce448ebfaf54dece14666John McCall /// \brief FromAST - Whether this type comes from an AST file. 814b870b88df784c2940efce448ebfaf54dece14666John McCall mutable bool FromAST : 1; 815b870b88df784c2940efce448ebfaf54dece14666John McCall 816b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned SpareBit : 1; 817b870b88df784c2940efce448ebfaf54dece14666John McCall }; 818b870b88df784c2940efce448ebfaf54dece14666John McCall enum { NumTypeBits = 16 }; 819b870b88df784c2940efce448ebfaf54dece14666John McCall 820b870b88df784c2940efce448ebfaf54dece14666John McCallprotected: 821b870b88df784c2940efce448ebfaf54dece14666John McCall // These classes allow subclasses to somewhat cleanly pack bitfields 822b870b88df784c2940efce448ebfaf54dece14666John McCall // into Type. 823b870b88df784c2940efce448ebfaf54dece14666John McCall 824b870b88df784c2940efce448ebfaf54dece14666John McCall class ArrayTypeBitfields { 825b870b88df784c2940efce448ebfaf54dece14666John McCall friend class ArrayType; 826b870b88df784c2940efce448ebfaf54dece14666John McCall 827b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 828b870b88df784c2940efce448ebfaf54dece14666John McCall 829b870b88df784c2940efce448ebfaf54dece14666John McCall /// IndexTypeQuals - CVR qualifiers from declarations like 830b870b88df784c2940efce448ebfaf54dece14666John McCall /// 'int X[static restrict 4]'. For function parameters only. 831b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned IndexTypeQuals : 3; 832b870b88df784c2940efce448ebfaf54dece14666John McCall 833b870b88df784c2940efce448ebfaf54dece14666John McCall /// SizeModifier - storage class qualifiers from declarations like 834b870b88df784c2940efce448ebfaf54dece14666John McCall /// 'int X[static restrict 4]'. For function parameters only. 835b870b88df784c2940efce448ebfaf54dece14666John McCall /// Actually an ArrayType::ArraySizeModifier. 836b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned SizeModifier : 3; 837b870b88df784c2940efce448ebfaf54dece14666John McCall }; 838b870b88df784c2940efce448ebfaf54dece14666John McCall 839b870b88df784c2940efce448ebfaf54dece14666John McCall class BuiltinTypeBitfields { 840b870b88df784c2940efce448ebfaf54dece14666John McCall friend class BuiltinType; 841b870b88df784c2940efce448ebfaf54dece14666John McCall 842b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 843b870b88df784c2940efce448ebfaf54dece14666John McCall 844b870b88df784c2940efce448ebfaf54dece14666John McCall /// The kind (BuiltinType::Kind) of builtin type this is. 845b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned Kind : 8; 846b870b88df784c2940efce448ebfaf54dece14666John McCall }; 847b870b88df784c2940efce448ebfaf54dece14666John McCall 848b870b88df784c2940efce448ebfaf54dece14666John McCall class FunctionTypeBitfields { 849b870b88df784c2940efce448ebfaf54dece14666John McCall friend class FunctionType; 850b870b88df784c2940efce448ebfaf54dece14666John McCall 851b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 852b870b88df784c2940efce448ebfaf54dece14666John McCall 853b870b88df784c2940efce448ebfaf54dece14666John McCall /// Extra information which affects how the function is called, like 854b870b88df784c2940efce448ebfaf54dece14666John McCall /// regparm and the calling convention. 855b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned ExtInfo : 8; 856b870b88df784c2940efce448ebfaf54dece14666John McCall 857b870b88df784c2940efce448ebfaf54dece14666John McCall /// A bit to be used by the subclass. 858b870b88df784c2940efce448ebfaf54dece14666John McCall bool SubclassInfo : 1; 859b870b88df784c2940efce448ebfaf54dece14666John McCall 860b870b88df784c2940efce448ebfaf54dece14666John McCall /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 861b870b88df784c2940efce448ebfaf54dece14666John McCall /// other bitfields. 862b870b88df784c2940efce448ebfaf54dece14666John McCall /// The qualifiers are part of FunctionProtoType because... 863b870b88df784c2940efce448ebfaf54dece14666John McCall /// 864b870b88df784c2940efce448ebfaf54dece14666John McCall /// C++ 8.3.5p4: The return type, the parameter type list and the 865b870b88df784c2940efce448ebfaf54dece14666John McCall /// cv-qualifier-seq, [...], are part of the function type. 866b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned TypeQuals : 3; 867b870b88df784c2940efce448ebfaf54dece14666John McCall }; 868b870b88df784c2940efce448ebfaf54dece14666John McCall 869b870b88df784c2940efce448ebfaf54dece14666John McCall class ObjCObjectTypeBitfields { 870b870b88df784c2940efce448ebfaf54dece14666John McCall friend class ObjCObjectType; 871b870b88df784c2940efce448ebfaf54dece14666John McCall 872b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 873b870b88df784c2940efce448ebfaf54dece14666John McCall 874b870b88df784c2940efce448ebfaf54dece14666John McCall /// NumProtocols - The number of protocols stored directly on this 875b870b88df784c2940efce448ebfaf54dece14666John McCall /// object type. 876b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned NumProtocols : 32 - NumTypeBits; 877b870b88df784c2940efce448ebfaf54dece14666John McCall }; 878b870b88df784c2940efce448ebfaf54dece14666John McCall 879b870b88df784c2940efce448ebfaf54dece14666John McCall class ReferenceTypeBitfields { 880b870b88df784c2940efce448ebfaf54dece14666John McCall friend class ReferenceType; 881b870b88df784c2940efce448ebfaf54dece14666John McCall 882b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 883b870b88df784c2940efce448ebfaf54dece14666John McCall 884b870b88df784c2940efce448ebfaf54dece14666John McCall /// True if the type was originally spelled with an lvalue sigil. 885b870b88df784c2940efce448ebfaf54dece14666John McCall /// This is never true of rvalue references but can also be false 886b870b88df784c2940efce448ebfaf54dece14666John McCall /// on lvalue references because of C++0x [dcl.typedef]p9, 887b870b88df784c2940efce448ebfaf54dece14666John McCall /// as follows: 888b870b88df784c2940efce448ebfaf54dece14666John McCall /// 889b870b88df784c2940efce448ebfaf54dece14666John McCall /// typedef int &ref; // lvalue, spelled lvalue 890b870b88df784c2940efce448ebfaf54dece14666John McCall /// typedef int &&rvref; // rvalue 891b870b88df784c2940efce448ebfaf54dece14666John McCall /// ref &a; // lvalue, inner ref, spelled lvalue 892b870b88df784c2940efce448ebfaf54dece14666John McCall /// ref &&a; // lvalue, inner ref 893b870b88df784c2940efce448ebfaf54dece14666John McCall /// rvref &a; // lvalue, inner ref, spelled lvalue 894b870b88df784c2940efce448ebfaf54dece14666John McCall /// rvref &&a; // rvalue, inner ref 895b870b88df784c2940efce448ebfaf54dece14666John McCall bool SpelledAsLValue : 1; 896b870b88df784c2940efce448ebfaf54dece14666John McCall 897b870b88df784c2940efce448ebfaf54dece14666John McCall /// True if the inner type is a reference type. This only happens 898b870b88df784c2940efce448ebfaf54dece14666John McCall /// in non-canonical forms. 899b870b88df784c2940efce448ebfaf54dece14666John McCall bool InnerRef : 1; 900b870b88df784c2940efce448ebfaf54dece14666John McCall }; 901b870b88df784c2940efce448ebfaf54dece14666John McCall 902b870b88df784c2940efce448ebfaf54dece14666John McCall class VectorTypeBitfields { 903b870b88df784c2940efce448ebfaf54dece14666John McCall friend class VectorType; 90407a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 905b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned : NumTypeBits; 90671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 907b870b88df784c2940efce448ebfaf54dece14666John McCall /// AltiVecSpec - AltiVec-specific vector information, used 908b870b88df784c2940efce448ebfaf54dece14666John McCall /// to differentiate things like 'pixel'. 909b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned AltiVecSpec : 2; 910b870b88df784c2940efce448ebfaf54dece14666John McCall 911b870b88df784c2940efce448ebfaf54dece14666John McCall /// NumElements - The number of elements in the vector. 912b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned NumElements : 30 - NumTypeBits; 913b870b88df784c2940efce448ebfaf54dece14666John McCall }; 914b870b88df784c2940efce448ebfaf54dece14666John McCall 915b870b88df784c2940efce448ebfaf54dece14666John McCall union { 916b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBitfields TypeBits; 917b870b88df784c2940efce448ebfaf54dece14666John McCall ArrayTypeBitfields ArrayTypeBits; 918b870b88df784c2940efce448ebfaf54dece14666John McCall BuiltinTypeBitfields BuiltinTypeBits; 919b870b88df784c2940efce448ebfaf54dece14666John McCall FunctionTypeBitfields FunctionTypeBits; 920b870b88df784c2940efce448ebfaf54dece14666John McCall ObjCObjectTypeBitfields ObjCObjectTypeBits; 921b870b88df784c2940efce448ebfaf54dece14666John McCall ReferenceTypeBitfields ReferenceTypeBits; 922b870b88df784c2940efce448ebfaf54dece14666John McCall VectorTypeBitfields VectorTypeBits; 923b870b88df784c2940efce448ebfaf54dece14666John McCall }; 924b870b88df784c2940efce448ebfaf54dece14666John McCall 925b870b88df784c2940efce448ebfaf54dece14666John McCallprivate: 9263c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl /// \brief Set whether this type comes from an AST file. 9273c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl void setFromAST(bool V = true) const { 928b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.FromAST = V; 92907a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl } 93007a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 93235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor /// \brief Compute the linkage of this type along with the presence of 93335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor /// any local or unnamed types. 934db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor virtual std::pair<Linkage, bool> getLinkageUnnamedLocalImpl() const; 93571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 936124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 937124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 93835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(TypeClass tc, QualType Canonical, bool Dependent, bool VariablyModified) 939b870b88df784c2940efce448ebfaf54dece14666John McCall : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical) { 940b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.TC = tc; 941b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.Dependent = Dependent; 942b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.VariablyModified = VariablyModified; 943b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.LinkageKnown = false; 944b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.CachedLocalOrUnnamed = false; 945b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.CachedLinkage = NoLinkage; 946b870b88df784c2940efce448ebfaf54dece14666John McCall TypeBits.FromAST = false; 947b870b88df784c2940efce448ebfaf54dece14666John McCall } 948afb6416bf7f04a00c44092e802f335bb3636489cDouglas Gregor virtual ~Type(); 9495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 9501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 951b870b88df784c2940efce448ebfaf54dece14666John McCall void setDependent(bool D = true) { TypeBits.Dependent = D; } 952b870b88df784c2940efce448ebfaf54dece14666John McCall void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; } 95335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 9548b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 955b870b88df784c2940efce448ebfaf54dece14666John McCall TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); } 9561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9573c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl /// \brief Whether this type comes from an AST file. 958b870b88df784c2940efce448ebfaf54dece14666John McCall bool isFromAST() const { return TypeBits.FromAST; } 95907a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl 960467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall bool isCanonicalUnqualified() const { 961467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall return CanonicalType.getTypePtr() == this; 962467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall } 9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 9661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 9695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 9701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// routine will need to determine if the size is actually required. 9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncompleteType() const; 972d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner 973d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 974d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// type, in other words, not a function type. 975d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner bool isIncompleteOrObjectType() const { 976d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner return !isFunctionType(); 977d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner } 97864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 97964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 98064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl bool isPODType() const; 98164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 982ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl /// isLiteralType - Return true if this is a literal type 983ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl /// (C++0x [basic.types]p10) 984ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl bool isLiteralType() const; 985ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 987ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 988e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 9899b065ddabf572772991a4aadad5bf4921fac5069Tom Care /// isBuiltinType - returns true if the type is a builtin type. 9909b065ddabf572772991a4aadad5bf4921fac5069Tom Care bool isBuiltinType() const; 9919b065ddabf572772991a4aadad5bf4921fac5069Tom Care 992e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 993e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 9941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9952a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// isPlaceholderType - Test for a type which does not represent an 9962a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// actual type-system type but is instead used as a placeholder for 9972a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// various convenient purposes within Clang. All such types are 9982a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// BuiltinTypes. 9992a984cad5ac3fdceeff2bd99daa7b90979313475John McCall bool isPlaceholderType() const; 10002a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 100196d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 100296d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 100413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 100513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 100613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 100777a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor bool isWideCharType() const; 100820093b4bf698f292c664676987541d5103b65b15Douglas Gregor bool isAnyCharacterType() const; 10099d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor bool isIntegralType(ASTContext &Ctx) const; 101020093b4bf698f292c664676987541d5103b65b15Douglas Gregor 10112ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor /// \brief Determine whether this type is an integral or enumeration type. 10122ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor bool isIntegralOrEnumerationType() const; 10131274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor /// \brief Determine whether this type is an integral or unscoped enumeration 10141274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor /// type. 10151274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor bool isIntegralOrUnscopedEnumerationType() const; 10162ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor 10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 101902f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 102002f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 1022f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 10245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 10255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 1026c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 1027c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 1028c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 1029d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor bool isAggregateType() const; 10301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1031c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 1032ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 1033c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 1034183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } 1035183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } 1036befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 103758f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 10385618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff bool isBlockPointerType() const; 10397154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff bool isVoidPointerType() const; 1040a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 10417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isLValueReferenceType() const; 10427c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isRValueReferenceType() const; 1043bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isFunctionPointerType() const; 1044f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberPointerType() const; 1045f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberFunctionPointerType() const; 1046db68e28c05a67735211e688009890cf834c22e75Douglas Gregor bool isMemberDataPointerType() const; 1047c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 1048c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isConstantArrayType() const; 1049c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isIncompleteArrayType() const; 1050c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isVariableArrayType() const; 1051898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentSizedArrayType() const; 1052c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 10531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isClassType() const; 10541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isStructureType() const; 1055fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor bool isStructureOrClassType() const; 10564cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 1057368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 1058368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isVectorType() const; // GCC vector type. 1059213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman bool isExtVectorType() const; // Extended vector type. 1060d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 106114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // FIXME: change this to 'raw' interface type, so we can used 'interface' type 106214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for the common case. 1063c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCObjectType() const; // NSString or typeof(*(id)0) 1064368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 1065368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedIdType() const; // id<foo> 1066470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const; // Class<foo> 1067569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor bool isObjCObjectOrInterfaceType() const; 106814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const; // id 106914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const; // Class 107013dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian bool isObjCSelType() const; // Class 1071de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff bool isObjCBuiltinType() const; // 'id' or 'Class' 107272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 10736e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 1074898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1075898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 10761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// that its definition somehow depends on a template parameter 1077898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.type]). 1078b870b88df784c2940efce448ebfaf54dece14666John McCall bool isDependentType() const { return TypeBits.Dependent; } 107935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 108035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor /// \brief Whether this type is a variably-modified type (C99 6.7.5). 1081b870b88df784c2940efce448ebfaf54dece14666John McCall bool isVariablyModifiedType() const { return TypeBits.VariablyModified; } 108235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 1083db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor /// \brief Whether this type is or contains a local or unnamed type. 1084db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor bool hasUnnamedOrLocalType() const; 1085db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 1086063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor bool isOverloadableType() const; 108772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 10884033642464e8ba0982f88f34cffad808d247b393Douglas Gregor /// \brief Determine wither this type is a C++ elaborated-type-specifier. 10894033642464e8ba0982f88f34cffad808d247b393Douglas Gregor bool isElaboratedTypeSpecifier() const; 10904033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 10918958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 10928958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 10938958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 10946e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl /// interface types, as well as nullptr_t. 10958958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar bool hasPointerRepresentation() const; 10968958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 1097820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 1098820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 10991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool hasObjCPointerRepresentation() const; 1100820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 1101f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// \brief Determine whether this type has an integer representation 1102f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// of some sort, e.g., it is an integer type or a vector. 1103f60946222721d9ba3c059563935c17b84703187aDouglas Gregor bool hasIntegerRepresentation() const; 1104f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 1105f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// \brief Determine whether this type has an signed integer representation 1106f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// of some sort, e.g., it is an signed integer type or a vector. 1107f60946222721d9ba3c059563935c17b84703187aDouglas Gregor bool hasSignedIntegerRepresentation() const; 1108f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 1109f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// \brief Determine whether this type has an unsigned integer representation 1110f60946222721d9ba3c059563935c17b84703187aDouglas Gregor /// of some sort, e.g., it is an unsigned integer type or a vector. 1111f60946222721d9ba3c059563935c17b84703187aDouglas Gregor bool hasUnsignedIntegerRepresentation() const; 1112f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 11138eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor /// \brief Determine whether this type has a floating-point representation 11148eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor /// of some sort, e.g., it is a floating-point type or a vector thereof. 11158eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor bool hasFloatingRepresentation() const; 1116f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 1117c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 1118f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 1119f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 1120769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const RecordType *getAsStructureType() const; 1121898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 1122c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 11234cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 112414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // The following is a convenience method that returns an ObjCObjectPointerType 112514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for object declared using an interface. 112614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 112714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 1128c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *getAsObjCQualifiedInterfaceType() const; 1129a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1131c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor /// \brief Retrieves the CXXRecordDecl that this type refers to, either 1132c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor /// because the type is a RecordType or because it is the injected-class-name 1133c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor /// type of a class template or class template partial specialization. 1134c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor CXXRecordDecl *getAsCXXRecordDecl() const; 1135c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 1136fa78c91c54dd99ec61a9e27e6b74a549f5c9fa9cDan Gohman // Member-template getAs<specific type>'. Look through sugar for 1137fa78c91c54dd99ec61a9e27e6b74a549f5c9fa9cDan Gohman // an instance of <specific type>. This scheme will eventually 11381a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // replace the specific getAsXXXX methods above. 1139183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall // 1140183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall // There are some specializations of this member template listed 1141183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall // immediately following this class. 11421a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek template <typename T> const T *getAs() const; 11431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1144c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 1145c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// element type of the array, potentially with type qualifiers missing. 1146c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// This method should never be used when type qualifiers are meaningful. 1147c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 11481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1149f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// getPointeeType - If this is a pointer, ObjC object pointer, or block 1150f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// pointer, this returns the respective pointee. 115114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const; 11521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1153bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// getUnqualifiedDesugaredType() - Return the specified type with 1154bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// any "sugar" removed from the type, removing any typedefs, 1155bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// typeofs, etc., as well as any qualifiers. 1156bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *getUnqualifiedDesugaredType() const; 11571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 1162d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 1163d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 1164d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// integer element type. 11655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 11665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 1168d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 1169d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 1170d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// element type. 11715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 1172d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 11749bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 11759bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 11763c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 1177c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 117822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 117922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// set of type specifiers. 118022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman bool isSpecifierType() const; 118122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 11820b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor /// \brief Determine the linkage of this type. 118360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor Linkage getLinkage() const; 118460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 118560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor /// \brief Note that the linkage is no longer known. 118660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor void ClearLinkageCache(); 118760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 118860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor const char *getTypeClassName() const; 11890b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1190ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall QualType getCanonicalTypeInternal() const { 1191ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall return CanonicalType; 1192ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall } 1193ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h 1194c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 11955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 1196be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis 1197c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl friend class ASTReader; 1198a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl friend class ASTWriter; 11995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1201183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const { 1202183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall return dyn_cast<TypedefType>(this); 1203183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall} 1204183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 1205183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to 1206183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration. 1207183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base) 1208183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \ 1209183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \ 12100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return dyn_cast<Class##Type>(CanonicalType); \ 1211183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall} 1212183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def" 1213183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 1214183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 12155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 12165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 12185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 12205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Void, 12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Bool, // This is bool and/or _Bool. 12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_U, // This is 'char' for targets where char is unsigned. 12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UChar, // This is explicitly qualified unsigned char. 1225f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char16, // This is 'char16_t' for C++. 1226f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char32, // This is 'char32_t' for C++. 12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UShort, 12285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UInt, 12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULong, 12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULongLong, 12312df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner UInt128, // __uint128_t 12321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_S, // This is 'char' for targets where char is signed. 12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SChar, // This is explicitly qualified signed char. 12352ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis WChar, // This is 'wchar_t' for C++. 12365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Short, 12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Int, 12385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Long, 12395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongLong, 12402df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner Int128, // __int128_t 12411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12428e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor Float, Double, LongDouble, 12438e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 12446e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 12456e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 12462a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// This represents the type of an expression whose type is 12472a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// totally unknown, e.g. 'T::foo'. It is permitted for this to 12482a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// appear in situations where the structure of the type is 12492a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// theoretically deducible. 12502a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Dependent, 12512a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 1252898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Overload, // This represents the type of an overloaded function declaration. 12531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1254de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff UndeducedAuto, // In C++0x, this represents the type of an auto variable 1255e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson // that has not been deduced yet. 1256e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 1257e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// The primitive Objective C 'id' type. The type pointed to by the 1258e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// user-visible 'id' type. Only ever shows up in an AST as the base 1259e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// type of an ObjCObjectType. 1260e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall ObjCId, 1261e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 1262e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// The primitive Objective C 'Class' type. The type pointed to by the 1263e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// user-visible 'Class' type. Only ever shows up in an AST as the 1264e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// base type of an ObjCObjectType. 1265e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall ObjCClass, 1266e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 126713dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian ObjCSel // This represents the ObjC 'SEL' type. 12685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 126971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 127060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected: 1271db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor virtual std::pair<Linkage, bool> getLinkageUnnamedLocalImpl() const; 127260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BuiltinType(Kind K) 127535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent), 127671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall /*VariablyModified=*/false) { 1277b870b88df784c2940efce448ebfaf54dece14666John McCall BuiltinTypeBits.Kind = K; 127871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1280b870b88df784c2940efce448ebfaf54dece14666John McCall Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); } 1281e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const char *getName(const LangOptions &LO) const; 12821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1283bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1284bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1285bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1286680523a91dd3351389667c8de17121ba7ae82673John McCall bool isInteger() const { 128771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Bool && getKind() <= Int128; 1288680523a91dd3351389667c8de17121ba7ae82673John McCall } 1289680523a91dd3351389667c8de17121ba7ae82673John McCall 1290680523a91dd3351389667c8de17121ba7ae82673John McCall bool isSignedInteger() const { 129171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Char_S && getKind() <= Int128; 1292680523a91dd3351389667c8de17121ba7ae82673John McCall } 1293680523a91dd3351389667c8de17121ba7ae82673John McCall 1294680523a91dd3351389667c8de17121ba7ae82673John McCall bool isUnsignedInteger() const { 129571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Bool && getKind() <= UInt128; 1296680523a91dd3351389667c8de17121ba7ae82673John McCall } 1297680523a91dd3351389667c8de17121ba7ae82673John McCall 1298680523a91dd3351389667c8de17121ba7ae82673John McCall bool isFloatingPoint() const { 129971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() >= Float && getKind() <= LongDouble; 1300680523a91dd3351389667c8de17121ba7ae82673John McCall } 1301680523a91dd3351389667c8de17121ba7ae82673John McCall 13022a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// Determines whether this type is a "forbidden" placeholder type, 13032a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// i.e. a type which cannot appear in arbitrary positions in a 13042a984cad5ac3fdceeff2bd99daa7b90979313475John McCall /// fully-formed expression. 13052a984cad5ac3fdceeff2bd99daa7b90979313475John McCall bool isPlaceholderType() const { 130671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return getKind() == Overload || 130771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall getKind() == UndeducedAuto; 13082a984cad5ac3fdceeff2bd99daa7b90979313475John McCall } 13092a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 13125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 13175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 13185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 132035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(Complex, CanonicalPtr, Element->isDependentType(), 132135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Element->isVariablyModifiedType()), 1322898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(Element) { 13235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 132560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 132660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected: 1327db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor virtual std::pair<Linkage, bool> getLinkageUnnamedLocalImpl() const; 132860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 13295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 13311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1332bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1333bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1334bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 13355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 13365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 13395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 13405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 13435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 13445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 134668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 1347bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// 134868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 1349bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType PointeeType; 13505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 135235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(Pointer, CanonicalPtr, Pointee->isDependentType(), 135335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Pointee->isVariablyModifiedType()), 135435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor PointeeType(Pointee) { 13555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 135760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 135860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected: 1359db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor virtual std::pair<Linkage, bool> getLinkageUnnamedLocalImpl() const; 136060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 13615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 136368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 136468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 1365bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1366bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1367bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 13685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 13695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 13705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 13725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 13735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 13765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 13775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13795618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type. 13805618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as 13815618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 13825618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// 13835618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 13845618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 13855618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 138635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(BlockPointer, CanonicalCls, Pointee->isDependentType(), 138735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Pointee->isVariablyModifiedType()), 1388898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor PointeeType(Pointee) { 13895618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 13905618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff friend class ASTContext; // ASTContext creates these. 139160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 139260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected: 1393db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor virtual std::pair<Linkage, bool> getLinkageUnnamedLocalImpl() const; 139460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 13955618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic: 13961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13975618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 13985618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType getPointeeType() const { return PointeeType; } 13995618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 1400bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1401bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1402bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 14035618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 14045618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Profile(ID, getPointeeType()); 14055618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 14065618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 14075618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 14085618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 14091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 14111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == BlockPointer; 14125618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 14135618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 14145618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}; 14155618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 14167c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 14175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 141868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 141968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType PointeeType; 142068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 14217c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected: 142254e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, 142354e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) : 142435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(tc, CanonicalRef, Referencee->isDependentType(), 142571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall Referencee->isVariablyModifiedType()), PointeeType(Referencee) { 1426b870b88df784c2940efce448ebfaf54dece14666John McCall ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue; 1427b870b88df784c2940efce448ebfaf54dece14666John McCall ReferenceTypeBits.InnerRef = Referencee->isReferenceType(); 14285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 142960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 1430db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor virtual std::pair<Linkage, bool> getLinkageUnnamedLocalImpl() const; 143160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 14325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1433b870b88df784c2940efce448ebfaf54dece14666John McCall bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; } 1434b870b88df784c2940efce448ebfaf54dece14666John McCall bool isInnerRef() const { return ReferenceTypeBits.InnerRef; } 143573dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor 143654e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType getPointeeTypeAsWritten() const { return PointeeType; } 143754e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType getPointeeType() const { 143854e14c4db764c0636160d26c5bbf491637c83a76John McCall // FIXME: this might strip inner qualifiers; okay? 143954e14c4db764c0636160d26c5bbf491637c83a76John McCall const ReferenceType *T = this; 144071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall while (T->isInnerRef()) 144154e14c4db764c0636160d26c5bbf491637c83a76John McCall T = T->PointeeType->getAs<ReferenceType>(); 144254e14c4db764c0636160d26c5bbf491637c83a76John McCall return T->PointeeType; 144354e14c4db764c0636160d26c5bbf491637c83a76John McCall } 144468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 14455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 144671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall Profile(ID, PointeeType, isSpelledAsLValue()); 14475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 144854e14c4db764c0636160d26c5bbf491637c83a76John McCall static void Profile(llvm::FoldingSetNodeID &ID, 144954e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType Referencee, 145054e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) { 14515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 145254e14c4db764c0636160d26c5bbf491637c83a76John McCall ID.AddBoolean(SpelledAsLValue); 14535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 14567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference || 14577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl T->getTypeClass() == RValueReference; 14587c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 14595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 14607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 14617c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 14627c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 14637c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 14647c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType { 146554e14c4db764c0636160d26c5bbf491637c83a76John McCall LValueReferenceType(QualType Referencee, QualType CanonicalRef, 146654e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) : 146754e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue) 146854e14c4db764c0636160d26c5bbf491637c83a76John McCall {} 14697c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 14707c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 1471bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1472bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1473bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 14747c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 14757c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference; 14767c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 14777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 14787c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 14797c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 14807c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 14817c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 14827c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType { 14837c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 148454e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(RValueReference, Referencee, CanonicalRef, false) { 14857c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 14867c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 14877c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 1488bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1489bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1490bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 14917c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 14927c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == RValueReference; 14937c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 14947c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 1495f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}; 1496f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1497f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 1498f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// 1499f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 1500f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType PointeeType; 1501f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 1502f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 1503f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class; 1504f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1505f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 1506f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Type(MemberPointer, CanonicalPtr, 150735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Cls->isDependentType() || Pointee->isDependentType(), 150835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Pointee->isVariablyModifiedType()), 1509f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointeeType(Pointee), Class(Cls) { 1510f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1511f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl friend class ASTContext; // ASTContext creates these. 151260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 151360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected: 1514db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor virtual std::pair<Linkage, bool> getLinkageUnnamedLocalImpl() const; 151560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 1516f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic: 1517f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType getPointeeType() const { return PointeeType; } 1518f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 15190bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Returns true if the member type (i.e. the pointee type) is a 15200bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// function type rather than a data-member type. 15210bab0cdab751248ca389a5592bcb70eac5d39260John McCall bool isMemberFunctionPointer() const { 15220bab0cdab751248ca389a5592bcb70eac5d39260John McCall return PointeeType->isFunctionProtoType(); 15230bab0cdab751248ca389a5592bcb70eac5d39260John McCall } 15240bab0cdab751248ca389a5592bcb70eac5d39260John McCall 15250bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Returns true if the member type (i.e. the pointee type) is a 15260bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// data type rather than a function type. 15270bab0cdab751248ca389a5592bcb70eac5d39260John McCall bool isMemberDataPointer() const { 15280bab0cdab751248ca389a5592bcb70eac5d39260John McCall return !PointeeType->isFunctionProtoType(); 15290bab0cdab751248ca389a5592bcb70eac5d39260John McCall } 15300bab0cdab751248ca389a5592bcb70eac5d39260John McCall 1531f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *getClass() const { return Class; } 1532f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1533bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1534bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1535bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1536f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 1537f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Profile(ID, getPointeeType(), getClass()); 1538f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1539f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 1540f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class) { 1541f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 1542f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Class); 1543f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1544f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1545f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const Type *T) { 1546f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getTypeClass() == MemberPointer; 1547f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1548f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const MemberPointerType *) { return true; } 15495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 15525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 15532e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 15545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 1556898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 1557898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// with a star size (e.g. int X[*]). 1558898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// 'static' is only allowed on function parameters. 15595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 15605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 15615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 15625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 1563fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 1564fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 15651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1566fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 1567898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // C++ [temp.dep.type]p1: 1568898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // A type is dependent if it is... 1569898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // - an array type constructed from any dependent type or whose 1570898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // size is specified by a constant expression that is 1571898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // value-dependent, 1572c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 1573c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 157435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray, 157535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor (tc == VariableArray || et->isVariablyModifiedType())), 157671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ElementType(et) { 1577b870b88df784c2940efce448ebfaf54dece14666John McCall ArrayTypeBits.IndexTypeQuals = tq; 1578b870b88df784c2940efce448ebfaf54dece14666John McCall ArrayTypeBits.SizeModifier = sm; 157971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 1580898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1581fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 158260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 1583db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor virtual std::pair<Linkage, bool> getLinkageUnnamedLocalImpl() const; 158460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 1585fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 1586fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 1587ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 1588b870b88df784c2940efce448ebfaf54dece14666John McCall return ArraySizeModifier(ArrayTypeBits.SizeModifier); 1589ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 15900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers getIndexTypeQualifiers() const { 159171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers()); 159271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 159371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall unsigned getIndexTypeCVRQualifiers() const { 1594b870b88df784c2940efce448ebfaf54dece14666John McCall return ArrayTypeBits.IndexTypeQuals; 15950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 15961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1597fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 1598fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 1599c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 1600898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == IncompleteArray || 1601898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == DependentSizedArray; 1602fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1603fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 1604fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 1605fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 16067e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of 16077e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size. For example, the canonical 16087e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 16097e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404. 16102e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 1611fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 16121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16130be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 1614c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 16157e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(ConstantArray, et, can, sm, tq), 16167e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Size(size) {} 16177e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected: 16187e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayType(TypeClass tc, QualType et, QualType can, 16197e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 16207e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(tc, et, can, sm, tq), Size(size) {} 1621fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 1622fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 1623c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const llvm::APInt &getSize() const { return Size; } 1624bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1625bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1626bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 16272767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 16282767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor /// \brief Determine the number of bits required to address a member of 16292767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // an array with the given element type and number of elements. 16302767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor static unsigned getNumAddressingBits(ASTContext &Context, 16312767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor QualType ElementType, 16322767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor const llvm::APInt &NumElements); 16332767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 16342767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor /// \brief Determine the maximum number of active bits that an array's size 16352767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor /// can require, which limits the maximum size of the array. 16362767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor static unsigned getMaxSizeBits(ASTContext &Context); 16372767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 1638fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 16391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, getElementType(), getSize(), 16400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers()); 1641fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1642fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 16430be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 16440be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner unsigned TypeQuals) { 1645fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 1646fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 16470be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 16480be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 1649fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 16507e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 165146a617a792bfab0d9b1e057371ea3b9540802226John McCall return T->getTypeClass() == ConstantArray; 1652fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1653fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 1654fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 1655fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 1656da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 1657da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 1658da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified. 1659c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 16607e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1661c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 16627e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq) 1663c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 1664c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 1665c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 1666bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1667bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1668bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 16691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 16701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == IncompleteArray; 1671c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 1672c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 16731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1674c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 16751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1676c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 16770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Profile(ID, getElementType(), getSizeModifier(), 16780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getIndexTypeCVRQualifiers()); 1679c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 16801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16810be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 16820be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 1683c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 16840be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 16850be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 1686c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 1687c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 1688c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1689da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 1690da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 1691da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 1692da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 1693da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 1694da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean 1695da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type 1696da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically: 1697da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 1698da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) { 1699da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Y[x]; 1700da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ++x; 1701da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Z[x]; 1702da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// } 1703da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 17042e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 17051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// SizeExpr - An assignment expression. VLA's are only permitted within 17061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// a function block. 1707b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek Stmt *SizeExpr; 17087e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 17097e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 17107e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1711c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 17127e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 17137e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 17147e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(VariableArray, et, can, sm, tq), 17157e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 17165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 17174b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 17185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 17191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getSizeExpr() const { 1720b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // We use C-style casts instead of cast<> here because we do not wish 1721b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 1722b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek return (Expr*) SizeExpr; 1723b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek } 17247e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 17257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 17267e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 17271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1728bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1729bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1730bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 17311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 17321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == VariableArray; 17335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1734fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 17351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 173692866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 17371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17382bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 1739bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 17402bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 17415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1743898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in 1744898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example: 1745cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// 1746cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code 17471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size> 1748898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array { 1749898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// T data[Size]; 1750898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// }; 1751cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode 1752cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// 1753898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is 1754898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will 1755898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 1756898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType { 175704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ASTContext &Context; 17581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1759cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// \brief An assignment expression that will instantiate to the 1760898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// size of the array. 1761cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// 1762cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// The expression itself might be NULL, in which case the array 1763cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// type will have its size deduced from an initializer. 1764898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Stmt *SizeExpr; 1765cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor 17667e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 17677e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 17681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentSizedArrayType(ASTContext &Context, QualType et, QualType can, 177004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *e, ArraySizeModifier sm, unsigned tq, 17717e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 17727e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), 177304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {} 1774898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class ASTContext; // ASTContext creates these. 1775898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1776898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic: 17771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getSizeExpr() const { 1778898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // We use C-style casts instead of cast<> here because we do not wish 1779898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 1780898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return (Expr*) SizeExpr; 1781898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 17827e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 17837e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 17847e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 17851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1786bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1787bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1788bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 17891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 17901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == DependentSizedArray; 1791898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1792898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 17931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1794898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class StmtIteratorBase; 17951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1797898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 17981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, Context, getElementType(), 17990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); 1800898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 18011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 18031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType ET, ArraySizeModifier SizeMod, 180404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, Expr *E); 1805898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}; 1806898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1807f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 18089cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example: 18099cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code 18109cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size> 18119cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector { 18129cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 18139cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// } 18149cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode 18152ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { 18162ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor ASTContext &Context; 18179cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr; 18189cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor /// ElementType - The element type of the array. 18199cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType ElementType; 18209cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation loc; 18211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentSizedExtVectorType(ASTContext &Context, QualType ElementType, 18232ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType can, Expr *SizeExpr, SourceLocation loc) 182435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(DependentSizedExtVector, can, /*Dependent=*/true, 182535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor ElementType->isVariablyModifiedType()), 18261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 18272ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor loc(loc) {} 18289cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor friend class ASTContext; 18299cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 18309cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic: 18312ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 18329cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType getElementType() const { return ElementType; } 18339cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation getAttributeLoc() const { return loc; } 18349cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 1835bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1836bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1837bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 18381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 18391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == DependentSizedExtVector; 18409cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor } 18411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const DependentSizedExtVectorType *) { return true; } 18422ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 18432ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 18442ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor Profile(ID, Context, getElementType(), getSizeExpr()); 18452ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 18461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18472ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 18482ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr); 18499cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor}; 18501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18519cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 185273322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 18531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in 185482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration. 185582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the 185673322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 18575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 1858788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattnerpublic: 1859788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner enum AltiVecSpecific { 1860788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner NotAltiVec, // is not AltiVec vector 1861788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner AltiVec, // is AltiVec vector 1862788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner Pixel, // is AltiVec 'vector Pixel' 1863788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner Bool // is AltiVec 'vector bool ...' 1864788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner }; 186573322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 18665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 18675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 18681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 186982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson VectorType(QualType vecType, unsigned nElements, QualType canonType, 1870788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner AltiVecSpecific altiVecSpec) : 187135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Type(Vector, canonType, vecType->isDependentType(), 187271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall vecType->isVariablyModifiedType()), ElementType(vecType) { 1873b870b88df784c2940efce448ebfaf54dece14666John McCall VectorTypeBits.AltiVecSpec = altiVecSpec; 1874b870b88df784c2940efce448ebfaf54dece14666John McCall VectorTypeBits.NumElements = nElements; 187571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 187635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 18771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump VectorType(TypeClass tc, QualType vecType, unsigned nElements, 1878788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner QualType canonType, AltiVecSpecific altiVecSpec) 187935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(tc, canonType, vecType->isDependentType(), 188071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall vecType->isVariablyModifiedType()), ElementType(vecType) { 1881b870b88df784c2940efce448ebfaf54dece14666John McCall VectorTypeBits.AltiVecSpec = altiVecSpec; 1882b870b88df784c2940efce448ebfaf54dece14666John McCall VectorTypeBits.NumElements = nElements; 188371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 18845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 188560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 1886db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor virtual std::pair<Linkage, bool> getLinkageUnnamedLocalImpl() const; 188760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 18885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 1891b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getNumElements() const { return VectorTypeBits.NumElements; } 18925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1893bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1894bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1895bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 189671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall AltiVecSpecific getAltiVecSpecific() const { 1897b870b88df784c2940efce448ebfaf54dece14666John McCall return AltiVecSpecific(VectorTypeBits.AltiVecSpec); 189871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 1899788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner 19005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 190171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall Profile(ID, getElementType(), getNumElements(), 190271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall getTypeClass(), getAltiVecSpecific()); 19035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 190582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson unsigned NumElements, TypeClass TypeClass, 190671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall AltiVecSpecific AltiVecSpec) { 19075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 19085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 190973322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 1910788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner ID.AddInteger(AltiVecSpec); 191173322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 19120b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 19131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 19141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 19155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 19175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1919213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using 1920213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1921213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1922fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 1923fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1924213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType { 1925213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1926788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner VectorType(ExtVector, vecType, nElements, canonType, NotAltiVec) {} 192773322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 192873322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 192988dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 193088dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 193188dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 193288dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 193388dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 193488dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 193588dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 193688dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1937e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1938353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman static int getNumericAccessorIdx(char c) { 193988dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 1940353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman default: return -1; 1941353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '0': return 0; 1942353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '1': return 1; 1943353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '2': return 2; 1944353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '3': return 3; 1945353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '4': return 4; 1946353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '5': return 5; 1947353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '6': return 6; 1948353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '7': return 7; 1949353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '8': return 8; 1950353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '9': return 9; 1951131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'A': 1952353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'a': return 10; 1953131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'B': 1954353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'b': return 11; 1955131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'C': 1956353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'c': return 12; 1957131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'D': 1958353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'd': return 13; 1959131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'E': 1960353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'e': return 14; 1961131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'F': 1962353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'f': return 15; 196388dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1964e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 19651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1966b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 1967b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1968353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman return getNumericAccessorIdx(c); 1969b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 19701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 197188dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 1972b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 197371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return unsigned(idx-1) < getNumElements(); 197488dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 1975e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1976bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1977bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1978bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 19791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 19801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ExtVector; 198173322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 1982213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman static bool classof(const ExtVectorType *) { return true; } 198373322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 198473322924127c873c13101b705dd823f5539ffa5fSteve Naroff 19855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 198672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 19875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 19885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 1989bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner virtual void ANCHOR(); // Key function for FunctionType. 199071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 19915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 19925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 1993264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 1994264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public: 1995264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // This class is used for passing arround the information needed to 1996264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // construct a call. It is not actually used for storage, just for 1997264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // factoring together common arguments. 1998425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // If you add a field (say Foo), other than the obvious places (both, constructors, 1999425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // compile failures), what you need to update is 2000425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * Operetor== 2001425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * getFoo 2002425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * withFoo 2003425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * functionType. Add Foo, getFoo. 2004425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * ASTContext::getFooType 2005425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * ASTContext::mergeFunctionTypes 2006425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * FunctionNoProtoType::Profile 2007425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * FunctionProtoType::Profile 2008425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * TypePrinter::PrintFunctionProto 20093c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl // * AST read and write 2010425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * Codegen 2011425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola 2012264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola class ExtInfo { 2013b870b88df784c2940efce448ebfaf54dece14666John McCall enum { CallConvMask = 0x7 }; 2014b870b88df784c2940efce448ebfaf54dece14666John McCall enum { NoReturnMask = 0x8 }; 2015b870b88df784c2940efce448ebfaf54dece14666John McCall enum { RegParmMask = ~(CallConvMask | NoReturnMask), 2016b870b88df784c2940efce448ebfaf54dece14666John McCall RegParmOffset = 4 }; 2017b870b88df784c2940efce448ebfaf54dece14666John McCall 201871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall unsigned Bits; 201971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 202071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ExtInfo(unsigned Bits) : Bits(Bits) {} 202171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 202271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall friend class FunctionType; 202371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall 2024264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public: 2025264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Constructor with no defaults. Use this when you know that you 20263c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl // have all the elements (when reading an AST file for example). 202771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ExtInfo(bool noReturn, unsigned regParm, CallingConv cc) { 2028b870b88df784c2940efce448ebfaf54dece14666John McCall Bits = ((unsigned) cc) | 2029b870b88df784c2940efce448ebfaf54dece14666John McCall (noReturn ? NoReturnMask : 0) | 2030b870b88df784c2940efce448ebfaf54dece14666John McCall (regParm << RegParmOffset); 203171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2032264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2033264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Constructor with all defaults. Use when for example creating a 2034264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // function know to use defaults. 203571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ExtInfo() : Bits(0) {} 2036264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2037b870b88df784c2940efce448ebfaf54dece14666John McCall bool getNoReturn() const { return Bits & NoReturnMask; } 2038b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getRegParm() const { return Bits >> RegParmOffset; } 2039b870b88df784c2940efce448ebfaf54dece14666John McCall CallingConv getCC() const { return CallingConv(Bits & CallConvMask); } 2040264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 204171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall bool operator==(ExtInfo Other) const { 204271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return Bits == Other.Bits; 2043264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 204471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall bool operator!=(ExtInfo Other) const { 204571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return Bits != Other.Bits; 2046264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 2047264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2048264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Note that we don't have setters. That is by design, use 2049264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // the following with methods instead of mutating these objects. 2050264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2051264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ExtInfo withNoReturn(bool noReturn) const { 205271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall if (noReturn) 205371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return ExtInfo(Bits | NoReturnMask); 205471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall else 205571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall return ExtInfo(Bits & ~NoReturnMask); 2056425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola } 2057425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola 2058425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola ExtInfo withRegParm(unsigned RegParm) const { 2059b870b88df784c2940efce448ebfaf54dece14666John McCall return ExtInfo((Bits & ~RegParmMask) | (RegParm << RegParmOffset)); 2060264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 2061264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 2062264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ExtInfo withCallingConv(CallingConv cc) const { 2063b870b88df784c2940efce448ebfaf54dece14666John McCall return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc); 2064264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 2065264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 206671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall void Profile(llvm::FoldingSetNodeID &ID) { 206771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ID.AddInteger(Bits); 206871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2069264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola }; 2070264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 20715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 2072971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 20732455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned typeQuals, QualType Canonical, bool Dependent, 207471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall bool VariablyModified, ExtInfo Info) 207571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall : Type(tc, Canonical, Dependent, VariablyModified), ResultType(res) { 2076b870b88df784c2940efce448ebfaf54dece14666John McCall FunctionTypeBits.ExtInfo = Info.Bits; 2077b870b88df784c2940efce448ebfaf54dece14666John McCall FunctionTypeBits.SubclassInfo = SubclassInfo; 2078b870b88df784c2940efce448ebfaf54dece14666John McCall FunctionTypeBits.TypeQuals = typeQuals; 207971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 2080b870b88df784c2940efce448ebfaf54dece14666John McCall bool getSubClassData() const { return FunctionTypeBits.SubclassInfo; } 2081b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; } 20825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 20831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 20855291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 2086b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getRegParmType() const { return getExtInfo().getRegParm(); } 2087b870b88df784c2940efce448ebfaf54dece14666John McCall bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); } 2088b870b88df784c2940efce448ebfaf54dece14666John McCall CallingConv getCallConv() const { return getExtInfo().getCC(); } 2089b870b88df784c2940efce448ebfaf54dece14666John McCall ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); } 20905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20915291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// \brief Determine the type of an expression that calls a function of 20925291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// this type. 20935291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor QualType getCallResultType(ASTContext &Context) const { 20946398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor return getResultType().getNonLValueExprType(Context); 20955291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor } 20965291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 209704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall static llvm::StringRef getNameForCallConv(CallingConv CC); 209804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 20995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 21005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 21015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 21025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 21045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 21055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 210672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 21075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 210872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 210971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info) 21101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 211135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor /*Dependent=*/false, Result->isVariablyModifiedType(), 211235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Info) {} 21135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 211460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 211560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected: 2116db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor virtual std::pair<Linkage, bool> getLinkageUnnamedLocalImpl() const; 211760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 21185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 21195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 21201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2121bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2122bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2123bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 21245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 2125264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Profile(ID, getResultType(), getExtInfo()); 21265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21272455636163fdd18581d7fdae816433f886d88213Mike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 212871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ExtInfo Info) { 212971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall Info.Profile(ID); 21305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 21315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 21345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 21355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 213672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 21375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 21385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 213972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 21405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 2141465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 2142465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical 2143465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type. 214472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 214572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 2146465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned typeQuals, bool hasExs, 2147465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExs, const QualType *ExArray, 2148264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola unsigned numExs, QualType Canonical, 214935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor const ExtInfo &Info); 2150465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 21515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 2152465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumArgs : 20; 2153465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2154465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 2155465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumExceptions : 10; 2156465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2157465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// HasExceptionSpec - Whether this function has an exception spec at all. 2158465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool HasExceptionSpec : 1; 2159465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2160465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// AnyExceptionSpec - Whether this function has a throw(...) spec. 2161465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool AnyExceptionSpec : 1; 2162465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2163942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 2164942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// holds the argument types. 2165465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2166465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 2167465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// holds the exception types. 2168465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 21695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 21704b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 217160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected: 2172db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor virtual std::pair<Linkage, bool> getLinkageUnnamedLocalImpl() const; 217360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 21745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 21755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 21765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 21775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 2178942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 21795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2180465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2181465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec() const { return HasExceptionSpec; } 2182465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 2183465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 2184465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType getExceptionType(unsigned i) const { 2185465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 2186465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin()[i]; 2187465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 21881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool hasEmptyExceptionSpec() const { 21891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return hasExceptionSpec() && !hasAnyExceptionSpec() && 2190a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson getNumExceptions() == 0; 2191d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson } 2192465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 21935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVariadic() const { return getSubClassData(); } 2194971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 21951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 2197942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 2198942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 2199942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 2200942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 2201465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2202465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl typedef const QualType *exception_iterator; 2203465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_begin() const { 2204465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // exceptions begin where arguments end 2205465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return arg_type_end(); 2206465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 2207465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_end() const { 2208465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin() + NumExceptions; 2209465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 2210465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2211bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2212bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2213bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 22145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 22155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 22165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 221772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 2218465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 22195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID); 22205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 2221942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 2222465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned TypeQuals, 2223465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec, bool anyExceptionSpec, 22242455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned NumExceptions, exception_iterator Exs, 222571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall ExtInfo ExtInfo); 22265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 22275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2229ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped 2230ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g. 2231ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// using typename Base<T>::foo; 2232ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type. 2233ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type { 2234ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *Decl; 2235ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 223619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) 223735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(UnresolvedUsing, QualType(), true, false), 223819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {} 2239ed97649e9574b9d854fa4d6109c9333ae0993554John McCall friend class ASTContext; // ASTContext creates these. 2240ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic: 2241ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2242ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *getDecl() const { return Decl; } 2243ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2244ed97649e9574b9d854fa4d6109c9333ae0993554John McCall bool isSugared() const { return false; } 2245ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType desugar() const { return QualType(this, 0); } 2246ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2247ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static bool classof(const Type *T) { 2248ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return T->getTypeClass() == UnresolvedUsing; 2249ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2250ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static bool classof(const UnresolvedUsingType *) { return true; } 2251ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2252ed97649e9574b9d854fa4d6109c9333ae0993554John McCall void Profile(llvm::FoldingSetNodeID &ID) { 2253ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Profile(ID, Decl); 2254ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2255ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static void Profile(llvm::FoldingSetNodeID &ID, 2256ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *D) { 2257ed97649e9574b9d854fa4d6109c9333ae0993554John McCall ID.AddPointer(D); 2258ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2259ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}; 2260ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2261ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 22625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 22635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *Decl; 2264c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 226519c8576b7328f4dc2d07682f5da552875c1912efJohn McCall TypedefType(TypeClass tc, const TypedefDecl *D, QualType can) 226635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(tc, can, can->isDependentType(), can->isVariablyModifiedType()), 226719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall Decl(const_cast<TypedefDecl*>(D)) { 22685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 22695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 22715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 22721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *getDecl() const { return Decl; } 22741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2275a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 2276fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 2277a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// sum of the type qualifiers, so if you have: 2278a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef const int A; 2279a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef volatile A B; 2280a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// looking through the typedefs for B will give you "const volatile A". 2281a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType LookThroughTypedefs() const; 22821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2283bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2284bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const; 2285bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 228672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 22875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 22885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 22895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 229072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension). 229172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type { 2292d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 22931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2294b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected: 2295dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor TypeOfExprType(Expr *E, QualType can = QualType()); 2296d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 2297d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 2298d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 22991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2300bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2301bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const; 2302bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2303bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2304bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2305bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 230672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 230772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 2308d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 2309d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 2310c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent 23111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types. 2312c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// 2313c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage 2314c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances 2315c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via TypeOfExprType nodes. 23161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType 2317b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor : public TypeOfExprType, public llvm::FoldingSetNode { 2318b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor ASTContext &Context; 23191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2320b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic: 23211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentTypeOfExprType(ASTContext &Context, Expr *E) 2322b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor : TypeOfExprType(E), Context(Context) { } 23231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2324bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2325bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2326bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2327b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2328b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Profile(ID, Context, getUnderlyingExpr()); 2329b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } 23301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2331b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 2332b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Expr *E); 2333b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor}; 23341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2335d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 2336d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 2337d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 23381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypeOfType(QualType T, QualType can) 233935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TypeOf, can, T->isDependentType(), T->isVariablyModifiedType()), 234035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor TOType(T) { 2341d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 2342d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 2343d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 2344d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 2345d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 23461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2347bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2348bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getUnderlyingType(); } 2349bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2350bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2351bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2352bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 235372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 2354d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 2355d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 23565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2357395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x) 2358395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type { 2359395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *E; 23601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2361563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 2362563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 2363563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // from it. 2364563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType UnderlyingType; 23651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23669d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected: 2367563a03b1338d31c2462def43253a722bc885d384Anders Carlsson DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 2368395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson friend class ASTContext; // ASTContext creates these. 2369395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic: 2370395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *getUnderlyingExpr() const { return E; } 2371563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType getUnderlyingType() const { return UnderlyingType; } 2372563a03b1338d31c2462def43253a722bc885d384Anders Carlsson 2373bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2374bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getUnderlyingType(); } 2375bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2376bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2377bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return !isDependentType(); } 2378bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2379395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 2380395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const DecltypeType *) { return true; } 2381395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson}; 23821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2383c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent 2384c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// decltype(expr) types. 2385c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// 2386c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage 2387c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances 2388c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via DecltypeType nodes. 23899d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { 23909d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor ASTContext &Context; 23911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23929d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic: 23939d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeType(ASTContext &Context, Expr *E); 23941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2395bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2396bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2397bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 23989d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 23999d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor Profile(ID, Context, getUnderlyingExpr()); 24009d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } 24011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24029d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 24031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *E); 24049d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor}; 24051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 2407ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl /// Stores the TagDecl associated with this type. The decl may point to any 2408ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl /// TagDecl that declares the entity. 2409ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl TagDecl * decl; 24102ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 24112ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected: 241219c8576b7328f4dc2d07682f5da552875c1912efJohn McCall TagType(TypeClass TC, const TagDecl *D, QualType can); 24132ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 2414db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor virtual std::pair<Linkage, bool> getLinkageUnnamedLocalImpl() const; 241560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 24161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 2417ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl TagDecl *getDecl() const; 24181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24190b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// @brief Determines whether this type is in the process of being 24201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// defined. 2421ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl bool isBeingDefined() const; 24220b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 24231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 242472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 242572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor } 24265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 242772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const RecordType *) { return true; } 242872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const EnumType *) { return true; } 24295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24315edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 24325edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes. 24335edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType { 243449aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected: 243519c8576b7328f4dc2d07682f5da552875c1912efJohn McCall explicit RecordType(const RecordDecl *D) 243619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { } 243772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 243819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { } 24392ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 24405edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 24411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24425edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordDecl *getDecl() const { 24435edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 24445edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 24451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: This predicate is a helper to QualType/Type. It needs to 24475edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // recursively check all fields for const-ness. If any field is declared 24481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // const, it needs to return false. 24495edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner bool hasConstFields() const { return false; } 24505edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 24515edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 24525edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // the same address space, and return that. 24535edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner unsigned getAddressSpace() const { return 0; } 24541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2455bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2456bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2457bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 24582daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 24592daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 24602daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 24612daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 24625edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const RecordType *) { return true; } 24635edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 24645edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 24655edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 24665edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums. 24675edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType { 246819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall explicit EnumType(const EnumDecl *D) 246919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { } 24702ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 24715edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 24721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24735edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumDecl *getDecl() const { 24745edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 24755edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 24761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2477bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2478bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2479bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 24802daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 24812daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 24822daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 24832daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 24845edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const EnumType *) { return true; } 24855edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 24865edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 2487fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 2488efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor unsigned Depth : 15; 2489efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor unsigned Index : 16; 2490efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor unsigned ParameterPack : 1; 2491efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor IdentifierInfo *Name; 249272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2493efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 2494efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor QualType Canon) 249535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true, 249635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor /*VariablyModified=*/false), 2497efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor Depth(D), Index(I), ParameterPack(PP), Name(N) { } 249872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 24991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP) 250035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true, 250135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor /*VariablyModified=*/false), 2502efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor Depth(D), Index(I), ParameterPack(PP), Name(0) { } 250372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2504fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor friend class ASTContext; // ASTContext creates these 250572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2506fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic: 2507efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor unsigned getDepth() const { return Depth; } 2508efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor unsigned getIndex() const { return Index; } 2509efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor bool isParameterPack() const { return ParameterPack; } 2510efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor IdentifierInfo *getName() const { return Name; } 25111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2512bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2513bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2514bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2515fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2516efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor Profile(ID, Depth, Index, ParameterPack, Name); 2517fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 2518fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 25191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 25201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned Index, bool ParameterPack, 2521efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor IdentifierInfo *Name) { 2522fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Depth); 2523fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Index); 252476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson ID.AddBoolean(ParameterPack); 2525efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor ID.AddPointer(Name); 2526fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 2527fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 25281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 25291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == TemplateTypeParm; 253072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor } 253172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 253272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}; 2533fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 253449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template 253549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter. 253649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// 253749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have 253849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these. They are used solely to record that a 253949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter; 254049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical. 254149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode { 254249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall // The original type parameter. 254349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *Replaced; 254449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 254549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) 254635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(), 254735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Canon->isVariablyModifiedType()), 254849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Replaced(Param) { } 254949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 255049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall friend class ASTContext; 255149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 255249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic: 2553efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor IdentifierInfo *getName() const { return Replaced->getName(); } 2554efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor 255549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// Gets the template parameter that was substituted for. 255649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *getReplacedParameter() const { 255749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return Replaced; 255849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 255949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 256049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// Gets the type that was substituted for the template 256149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// parameter. 256249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType getReplacementType() const { 256349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return getCanonicalTypeInternal(); 256449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 256549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 256649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall bool isSugared() const { return true; } 256749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType desugar() const { return getReplacementType(); } 256849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 256949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall void Profile(llvm::FoldingSetNodeID &ID) { 257049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Profile(ID, getReplacedParameter(), getReplacementType()); 257149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 257249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, 257349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *Replaced, 257449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType Replacement) { 257549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall ID.AddPointer(Replaced); 257649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall ID.AddPointer(Replacement.getAsOpaquePtr()); 257749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 257849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 257949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static bool classof(const Type *T) { 258049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return T->getTypeClass() == SubstTemplateTypeParm; 258149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 258249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static bool classof(const SubstTemplateTypeParmType *T) { return true; } 258349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}; 258449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 25857532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written 25867532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code. 258755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// 25887532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a 25897532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 25907532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 25917532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the 25927532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a 259355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to 25941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// a tag type for the instantiation 259555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 25967532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// 25977532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name 25987532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always 25997532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent. 26001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType 260155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor : public Type, public llvm::FoldingSetNode { 260233500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief The name of the template being specialized. 26037532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Template; 260455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 260540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief - The number of template arguments named in this class 260640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// template specialization. 260755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned NumArgs; 260855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 2609ef99001908e799c388f1363b1e607dad5f5b57d3John McCall TemplateSpecializationType(TemplateName T, 26107532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 26117532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon); 261255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 261355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor friend class ASTContext; // ASTContext creates these 261455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 261555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic: 261640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Determine whether any of the given template arguments are 261740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// dependent. 261840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 26191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned NumArgs); 262040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 2621833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args, 2622833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned NumArgs); 2623833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2624d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &); 2625d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 2626df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 2627df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// enclosing the template arguments. 2628df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 2629d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned NumArgs, 2630d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor const PrintingPolicy &Policy); 2631df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor 2632833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args, 2633833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned NumArgs, 2634833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const PrintingPolicy &Policy); 2635833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2636d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &, 2637d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const PrintingPolicy &Policy); 2638d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 263931f17ecbef57b5679c017c375db330546b7b5145John McCall /// True if this template specialization type matches a current 264031f17ecbef57b5679c017c375db330546b7b5145John McCall /// instantiation in the context in which it is found. 264131f17ecbef57b5679c017c375db330546b7b5145John McCall bool isCurrentInstantiation() const { 264271d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall return isa<InjectedClassNameType>(getCanonicalTypeInternal()); 264331f17ecbef57b5679c017c375db330546b7b5145John McCall } 264431f17ecbef57b5679c017c375db330546b7b5145John McCall 264540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor typedef const TemplateArgument * iterator; 264640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 264740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator begin() const { return getArgs(); } 264833500955d731c73717af52088b7fc0e7a85681e7John McCall iterator end() const; // defined inline in TemplateBase.h 264940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 26507532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 26517532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName getTemplateName() const { return Template; } 265255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 265340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the template arguments. 26541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *getArgs() const { 265540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 265640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 265740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 265840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the number of template arguments. 265955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 266055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 266155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \brief Retrieve a specific template argument as a type. 266255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \precondition @c isArgType(Arg) 266333500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 266455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 266531f17ecbef57b5679c017c375db330546b7b5145John McCall bool isSugared() const { 266631f17ecbef57b5679c017c375db330546b7b5145John McCall return !isDependentType() || isCurrentInstantiation(); 266731f17ecbef57b5679c017c375db330546b7b5145John McCall } 2668bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getCanonicalTypeInternal(); } 2669bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2670ef99001908e799c388f1363b1e607dad5f5b57d3John McCall void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Ctx) { 267171d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall Profile(ID, Template, getArgs(), NumArgs, Ctx); 267255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 267355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 26747532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 267531f17ecbef57b5679c017c375db330546b7b5145John McCall const TemplateArgument *Args, 267631f17ecbef57b5679c017c375db330546b7b5145John McCall unsigned NumArgs, 2677828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor ASTContext &Context); 267855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 26791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 26801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == TemplateSpecialization; 268155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 26827532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 268355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}; 268455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 268531f17ecbef57b5679c017c375db330546b7b5145John McCall/// \brief The injected class name of a C++ class template or class 268631f17ecbef57b5679c017c375db330546b7b5145John McCall/// template partial specialization. Used to record that a type was 268731f17ecbef57b5679c017c375db330546b7b5145John McCall/// spelled with a bare identifier rather than as a template-id; the 268831f17ecbef57b5679c017c375db330546b7b5145John McCall/// equivalent for non-templated classes is just RecordType. 26893cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// 269031f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always dependent. Template 269131f17ecbef57b5679c017c375db330546b7b5145John McCall/// instantiation turns these into RecordTypes. 26923cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// 269331f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always canonical. This works 269431f17ecbef57b5679c017c375db330546b7b5145John McCall/// because it is impossible to compare an injected class name type 269531f17ecbef57b5679c017c375db330546b7b5145John McCall/// with the corresponding non-injected template type, for the same 269631f17ecbef57b5679c017c375db330546b7b5145John McCall/// reason that it is impossible to directly compare template 269731f17ecbef57b5679c017c375db330546b7b5145John McCall/// parameters from different dependent contexts: injected class name 269831f17ecbef57b5679c017c375db330546b7b5145John McCall/// types can only occur within the scope of a particular templated 269931f17ecbef57b5679c017c375db330546b7b5145John McCall/// declaration, and within that scope every template specialization 270031f17ecbef57b5679c017c375db330546b7b5145John McCall/// will canonicalize to the injected class name (when appropriate 270131f17ecbef57b5679c017c375db330546b7b5145John McCall/// according to the rules of the language). 27023cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameType : public Type { 27033cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall CXXRecordDecl *Decl; 27043cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 270531f17ecbef57b5679c017c375db330546b7b5145John McCall /// The template specialization which this type represents. 270631f17ecbef57b5679c017c375db330546b7b5145John McCall /// For example, in 270731f17ecbef57b5679c017c375db330546b7b5145John McCall /// template <class T> class A { ... }; 270831f17ecbef57b5679c017c375db330546b7b5145John McCall /// this is A<T>, whereas in 270931f17ecbef57b5679c017c375db330546b7b5145John McCall /// template <class X, class Y> class A<B<X,Y> > { ... }; 271031f17ecbef57b5679c017c375db330546b7b5145John McCall /// this is A<B<X,Y> >. 271131f17ecbef57b5679c017c375db330546b7b5145John McCall /// 271231f17ecbef57b5679c017c375db330546b7b5145John McCall /// It is always unqualified, always a template specialization type, 271331f17ecbef57b5679c017c375db330546b7b5145John McCall /// and always dependent. 271431f17ecbef57b5679c017c375db330546b7b5145John McCall QualType InjectedType; 27153cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 27163cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall friend class ASTContext; // ASTContext creates these. 2717c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not 2718c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl // currently suitable for AST reading, too much 271943921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis // interdependencies. 272031f17ecbef57b5679c017c375db330546b7b5145John McCall InjectedClassNameType(CXXRecordDecl *D, QualType TST) 272135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(InjectedClassName, QualType(), /*Dependent=*/true, 272235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor /*VariablyModified=*/false), 272331f17ecbef57b5679c017c375db330546b7b5145John McCall Decl(D), InjectedType(TST) { 27243cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(isa<TemplateSpecializationType>(TST)); 27253cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(!TST.hasQualifiers()); 272631f17ecbef57b5679c017c375db330546b7b5145John McCall assert(TST->isDependentType()); 27273cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 27283cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 27293cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallpublic: 273031f17ecbef57b5679c017c375db330546b7b5145John McCall QualType getInjectedSpecializationType() const { return InjectedType; } 273131f17ecbef57b5679c017c375db330546b7b5145John McCall const TemplateSpecializationType *getInjectedTST() const { 273231f17ecbef57b5679c017c375db330546b7b5145John McCall return cast<TemplateSpecializationType>(InjectedType.getTypePtr()); 27333cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 27343cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 2735ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl CXXRecordDecl *getDecl() const; 27363cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 273731f17ecbef57b5679c017c375db330546b7b5145John McCall bool isSugared() const { return false; } 273831f17ecbef57b5679c017c375db330546b7b5145John McCall QualType desugar() const { return QualType(this, 0); } 27393cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 27403cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall static bool classof(const Type *T) { 27413cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return T->getTypeClass() == InjectedClassName; 27423cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 27433cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall static bool classof(const InjectedClassNameType *T) { return true; } 27443cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}; 27453cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 2746465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief The kind of a tag type. 2747465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraenum TagTypeKind { 2748465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "struct" keyword. 2749465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Struct, 2750465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "union" keyword. 2751465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Union, 2752465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "class" keyword. 2753465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Class, 2754465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "enum" keyword. 2755465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TTK_Enum 2756465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}; 2757465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 27584a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or 27594a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// introduces an elaborated-type-specifier. 27604a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregorenum ElaboratedTypeKeyword { 27614a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "struct" keyword introduces the elaborated-type-specifier. 27624a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ETK_Struct, 27634a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "union" keyword introduces the elaborated-type-specifier. 27644a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ETK_Union, 2765465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "class" keyword introduces the elaborated-type-specifier. 2766465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_Class, 27674a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "enum" keyword introduces the elaborated-type-specifier. 2768465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_Enum, 2769465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief The "typename" keyword precedes the qualified type name, e.g., 2770465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \c typename T::type. 2771465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_Typename, 2772465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// \brief No keyword precedes the qualified type name. 2773465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ETK_None 27744a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor}; 2775465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2776465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword. 2777465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The keyword in stored in the free bits of the base class. 2778465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// Also provides a few static helpers for converting and printing 2779465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// elaborated type keyword and tag type kind enumerations. 2780465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass TypeWithKeyword : public Type { 2781465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// Keyword - Encodes an ElaboratedTypeKeyword enumeration constant. 2782465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara unsigned Keyword : 3; 2783465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2784465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraprotected: 2785465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, 278635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor QualType Canonical, bool Dependent, bool VariablyModified) 278735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(tc, Canonical, Dependent, VariablyModified), 278835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Keyword(Keyword) {} 2789465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2790465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarapublic: 2791465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara virtual ~TypeWithKeyword(); // pin vtable to Type.cpp 2792465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2793465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeKeyword getKeyword() const { 2794465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return static_cast<ElaboratedTypeKeyword>(Keyword); 2795465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 2796465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2797465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST) 2798465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// into an elaborated type keyword. 2799465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec); 2800465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2801465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST) 2802465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// into a tag type kind. It is an error to provide a type specifier 2803465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// which *isn't* a tag kind here. 2804465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec); 2805465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2806465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getKeywordForTagDeclKind - Converts a TagTypeKind into an 2807465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// elaborated type keyword. 2808465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag); 2809465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2810465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// getTagTypeKindForKeyword - Converts an elaborated type keyword into 2811465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara // a TagTypeKind. It is an error to provide an elaborated type keyword 2812465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// which *isn't* a tag kind here. 2813465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword); 2814465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2815465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword); 2816465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2817465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static const char *getKeywordName(ElaboratedTypeKeyword Keyword); 2818465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2819465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static const char *getTagTypeKindName(TagTypeKind Kind) { 2820465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return getKeywordName(getKeywordForTagTypeKind(Kind)); 2821465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 2822465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2823465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara class CannotCastToThisType {}; 2824465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static CannotCastToThisType classof(const Type *); 2825465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}; 2826465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2827465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief Represents a type that was referred to using an elaborated type 2828465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type, 2829465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// or both. 2830e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// 2831e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the 2832465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// source code, including tag keywords and any nested-name-specifiers. 2833465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The type itself is always "sugar", used to express what was written 2834465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// in the source code but containing no additional semantic information. 2835465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode { 2836465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2837ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested name specifier containing the qualifier. 2838ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *NNS; 2839e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2840e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief The type that this qualified name refers to. 2841e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType; 2842e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2843465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 2844465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara QualType NamedType, QualType CanonType) 2845465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara : TypeWithKeyword(Keyword, Elaborated, CanonType, 284635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor NamedType->isDependentType(), 284735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor NamedType->isVariablyModifiedType()), 2848465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NNS(NNS), NamedType(NamedType) { 2849465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara assert(!(Keyword == ETK_None && NNS == 0) && 2850465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara "ElaboratedType cannot have elaborated type keyword " 2851465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara "and name qualifier both null."); 2852465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 2853e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2854e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor friend class ASTContext; // ASTContext creates these 2855e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2856e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic: 285733500955d731c73717af52088b7fc0e7a85681e7John McCall ~ElaboratedType(); 2858465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2859ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the qualification on this type. 2860ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2861e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2862e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 2863e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType getNamedType() const { return NamedType; } 2864e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2865bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2866bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getNamedType(); } 2867bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2868bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2869bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2870bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2871e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2872465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Profile(ID, getKeyword(), NNS, NamedType); 2873e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 2874e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2875465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 2876465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NestedNameSpecifier *NNS, QualType NamedType) { 2877465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ID.AddInteger(Keyword); 2878ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor ID.AddPointer(NNS); 2879ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NamedType.Profile(ID); 2880ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor } 2881e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 28821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 2883465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return T->getTypeClass() == Elaborated; 2884e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 2885465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara static bool classof(const ElaboratedType *T) { return true; } 2886e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor}; 2887e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 28884a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief Represents a qualified type name for which the type name is 28894a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent. 2890d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// 28914a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// DependentNameType represents a class of dependent types that involve a 28924a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent) 28934a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a 28944a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// typename-specifier), "class", "struct", "union", or "enum" (for a 28954a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we 28964a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier). 2897465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { 2898465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2899d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The nested name specifier containing the qualifier. 2900d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *NNS; 2901d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2902d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The type that this typename specifier refers to. 290333500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name; 2904d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 29054a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 29064a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor const IdentifierInfo *Name, QualType CanonType) 290735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true, 290835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor /*VariablyModified=*/false), 2909465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NNS(NNS), Name(Name) { 29101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(NNS->isDependent() && 29114714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor "DependentNameType requires a dependent nested-name-specifier"); 2912d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2913d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2914d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor friend class ASTContext; // ASTContext creates these 2915d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2916d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic: 291733500955d731c73717af52088b7fc0e7a85681e7John McCall virtual ~DependentNameType(); 2918465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 2919d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief Retrieve the qualification on this type. 2920d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2921d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 29221734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 29231734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// identifier. 29241734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// 29251734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 29261734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// form of the original typename was terminated by an identifier, 29271734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// e.g., "typename T::type". 29281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo *getIdentifier() const { 292933500955d731c73717af52088b7fc0e7a85681e7John McCall return Name; 29301734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 2931d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2932bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2933bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2934bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2935d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2936465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Profile(ID, getKeyword(), NNS, Name); 2937d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2938d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 29394a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 294033500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name) { 29414a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ID.AddInteger(Keyword); 2942d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor ID.AddPointer(NNS); 294333500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Name); 2944d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2945d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 29461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 29474714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor return T->getTypeClass() == DependentName; 2948d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 29494714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor static bool classof(const DependentNameType *T) { return true; } 2950d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor}; 2951d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 295233500955d731c73717af52088b7fc0e7a85681e7John McCall/// DependentTemplateSpecializationType - Represents a template 295333500955d731c73717af52088b7fc0e7a85681e7John McCall/// specialization type whose template cannot be resolved, e.g. 295433500955d731c73717af52088b7fc0e7a85681e7John McCall/// A<T>::template B<T> 295533500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationType : 295633500955d731c73717af52088b7fc0e7a85681e7John McCall public TypeWithKeyword, public llvm::FoldingSetNode { 295733500955d731c73717af52088b7fc0e7a85681e7John McCall 295833500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief The nested name specifier containing the qualifier. 295933500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS; 296033500955d731c73717af52088b7fc0e7a85681e7John McCall 296133500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief The identifier of the template. 296233500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name; 296333500955d731c73717af52088b7fc0e7a85681e7John McCall 296433500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief - The number of template arguments named in this class 296533500955d731c73717af52088b7fc0e7a85681e7John McCall /// template specialization. 296633500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs; 296733500955d731c73717af52088b7fc0e7a85681e7John McCall 296833500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *getArgBuffer() const { 296933500955d731c73717af52088b7fc0e7a85681e7John McCall return reinterpret_cast<const TemplateArgument*>(this+1); 297033500955d731c73717af52088b7fc0e7a85681e7John McCall } 297133500955d731c73717af52088b7fc0e7a85681e7John McCall TemplateArgument *getArgBuffer() { 297233500955d731c73717af52088b7fc0e7a85681e7John McCall return reinterpret_cast<TemplateArgument*>(this+1); 297333500955d731c73717af52088b7fc0e7a85681e7John McCall } 297433500955d731c73717af52088b7fc0e7a85681e7John McCall 2975ef99001908e799c388f1363b1e607dad5f5b57d3John McCall DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 297633500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, 297733500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 297833500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 297933500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args, 298033500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon); 298133500955d731c73717af52088b7fc0e7a85681e7John McCall 298233500955d731c73717af52088b7fc0e7a85681e7John McCall friend class ASTContext; // ASTContext creates these 298333500955d731c73717af52088b7fc0e7a85681e7John McCall 298433500955d731c73717af52088b7fc0e7a85681e7John McCallpublic: 298533500955d731c73717af52088b7fc0e7a85681e7John McCall virtual ~DependentTemplateSpecializationType(); 298633500955d731c73717af52088b7fc0e7a85681e7John McCall 298733500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *getQualifier() const { return NNS; } 298833500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *getIdentifier() const { return Name; } 298933500955d731c73717af52088b7fc0e7a85681e7John McCall 299033500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief Retrieve the template arguments. 299133500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *getArgs() const { 299233500955d731c73717af52088b7fc0e7a85681e7John McCall return getArgBuffer(); 299333500955d731c73717af52088b7fc0e7a85681e7John McCall } 299433500955d731c73717af52088b7fc0e7a85681e7John McCall 299533500955d731c73717af52088b7fc0e7a85681e7John McCall /// \brief Retrieve the number of template arguments. 299633500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned getNumArgs() const { return NumArgs; } 299733500955d731c73717af52088b7fc0e7a85681e7John McCall 299833500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 299933500955d731c73717af52088b7fc0e7a85681e7John McCall 300033500955d731c73717af52088b7fc0e7a85681e7John McCall typedef const TemplateArgument * iterator; 300133500955d731c73717af52088b7fc0e7a85681e7John McCall iterator begin() const { return getArgs(); } 300233500955d731c73717af52088b7fc0e7a85681e7John McCall iterator end() const; // inline in TemplateBase.h 300333500955d731c73717af52088b7fc0e7a85681e7John McCall 300433500955d731c73717af52088b7fc0e7a85681e7John McCall bool isSugared() const { return false; } 300533500955d731c73717af52088b7fc0e7a85681e7John McCall QualType desugar() const { return QualType(this, 0); } 300633500955d731c73717af52088b7fc0e7a85681e7John McCall 3007ef99001908e799c388f1363b1e607dad5f5b57d3John McCall void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context) { 300833500955d731c73717af52088b7fc0e7a85681e7John McCall Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs()); 300933500955d731c73717af52088b7fc0e7a85681e7John McCall } 301033500955d731c73717af52088b7fc0e7a85681e7John McCall 301133500955d731c73717af52088b7fc0e7a85681e7John McCall static void Profile(llvm::FoldingSetNodeID &ID, 301233500955d731c73717af52088b7fc0e7a85681e7John McCall ASTContext &Context, 301333500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 301433500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *Qualifier, 301533500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 301633500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 301733500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args); 301833500955d731c73717af52088b7fc0e7a85681e7John McCall 301933500955d731c73717af52088b7fc0e7a85681e7John McCall static bool classof(const Type *T) { 302033500955d731c73717af52088b7fc0e7a85681e7John McCall return T->getTypeClass() == DependentTemplateSpecialization; 302133500955d731c73717af52088b7fc0e7a85681e7John McCall } 302233500955d731c73717af52088b7fc0e7a85681e7John McCall static bool classof(const DependentTemplateSpecializationType *T) { 302333500955d731c73717af52088b7fc0e7a85681e7John McCall return true; 302433500955d731c73717af52088b7fc0e7a85681e7John McCall } 302533500955d731c73717af52088b7fc0e7a85681e7John McCall}; 302633500955d731c73717af52088b7fc0e7a85681e7John McCall 3027c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectType - Represents a class type in Objective C. 3028c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Every Objective C type is a combination of a base type and a 3029c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// list of protocols. 3030c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3031c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Given the following declarations: 3032c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// @class C; 3033c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// @protocol P; 3034c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3035c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType 3036c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// with base C and no protocols. 3037c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3038c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P]. 3039c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3040e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose 3041e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType 3042e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// and no protocols. 3043c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 3044e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType 3045e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually 3046e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// this should get its own sugar class to better represent the source. 3047c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectType : public Type { 3048b870b88df784c2940efce448ebfaf54dece14666John McCall // ObjCObjectType.NumProtocols - the number of protocols stored 3049b870b88df784c2940efce448ebfaf54dece14666John McCall // after the ObjCObjectPointerType node. 305071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // 305171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // These protocols are those written directly on the type. If 305271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // protocol qualifiers ever become additive, the iterators will need 305371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // to get kindof complicated. 305471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // 305571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // In the canonical object type, these are sorted alphabetically 305671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall // and uniqued. 3057c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 3058c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// Either a BuiltinType or an InterfaceType or sugar for either. 3059c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType BaseType; 3060c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3061c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *getProtocolStorage() const { 3062c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return const_cast<ObjCObjectType*>(this)->getProtocolStorage(); 3063c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3064c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3065c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl **getProtocolStorage(); 3066c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3067c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallprotected: 3068c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectType(QualType Canonical, QualType Base, 3069c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, unsigned NumProtocols); 3070c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3071c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall enum Nonce_ObjCInterface { Nonce_ObjCInterface }; 3072c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectType(enum Nonce_ObjCInterface) 307335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(ObjCInterface, QualType(), false, false), 307471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall BaseType(QualType(this_(), 0)) { 3075b870b88df784c2940efce448ebfaf54dece14666John McCall ObjCObjectTypeBits.NumProtocols = 0; 307671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall } 3077c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 307860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected: 3079db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor std::pair<Linkage, bool> getLinkageUnnamedLocalImpl() const; // key function 308060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 30813536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 3082e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getBaseType - Gets the base type of this object type. This is 3083e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// always (possibly sugar for) one of: 3084e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// - the 'id' builtin type (as opposed to the 'id' type visible to the 3085e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// user, which is a typedef for an ObjCPointerType) 3086e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// - the 'Class' builtin type (same caveat) 3087e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// - an ObjCObjectType (currently always an ObjCInterfaceType) 3088c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType getBaseType() const { return BaseType; } 308971842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek 3090c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCId() const { 3091c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId); 3092c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3093c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCClass() const { 3094c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass); 3095c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3096c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); } 3097c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); } 3098c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCUnqualifiedIdOrClass() const { 3099c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!qual_empty()) return false; 3100c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>()) 3101c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T->getKind() == BuiltinType::ObjCId || 3102c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall T->getKind() == BuiltinType::ObjCClass; 3103c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return false; 3104c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3105c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); } 3106c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); } 3107c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3108c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// Gets the interface declaration for this object type, if the base type 3109c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// really is an interface. 3110c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCInterfaceDecl *getInterface() const; 3111c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3112c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall typedef ObjCProtocolDecl * const *qual_iterator; 3113c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3114c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator qual_begin() const { return getProtocolStorage(); } 3115c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); } 3116c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3117c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool qual_empty() const { return getNumProtocols() == 0; } 31181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3119c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 3120c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// interface type, or 0 if there are none. 3121b870b88df784c2940efce448ebfaf54dece14666John McCall unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; } 312214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 3123c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall /// \brief Fetch a protocol by index. 312473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor ObjCProtocolDecl *getProtocol(unsigned I) const { 312573dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor assert(I < getNumProtocols() && "Out-of-range protocol access"); 312673dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor return qual_begin()[I]; 312773dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor } 312873dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor 3129bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 3130bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 3131bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3132c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static bool classof(const Type *T) { 3133c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T->getTypeClass() == ObjCObject || 3134c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall T->getTypeClass() == ObjCInterface; 3135c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3136c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static bool classof(const ObjCObjectType *) { return true; } 3137c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}; 3138c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3139c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation 3140c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// of ObjCObjectType, so as to not increase the footprint of 3141c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType. Code outside of ASTContext and the core type 3142c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// system should not reference this type. 3143c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode { 3144c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall friend class ASTContext; 3145c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3146c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // If anyone adds fields here, ObjCObjectType::getProtocolStorage() 3147c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // will need to be modified. 3148c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3149c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypeImpl(QualType Canonical, QualType Base, 3150c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 3151c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) 3152c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {} 3153c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3154c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic: 3155c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 31561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, 3157c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType Base, 3158c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl *const *protocols, 3159c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols); 3160c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}; 31611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3162c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() { 3163c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return reinterpret_cast<ObjCProtocolDecl**>( 3164c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static_cast<ObjCObjectTypeImpl*>(this) + 1); 3165c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 3166c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3167c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 3168c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// object oriented design. They basically correspond to C++ classes. There 3169c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// are two kinds of interface types, normal interfaces like "NSString" and 3170c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// qualified interfaces, which are qualified with a protocol list like 3171c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// "NSString<NSCopyable, NSAmazing>". 3172e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 3173e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCInterfaceType guarantees the following properties when considered 3174e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// as a subtype of its superclass, ObjCObjectType: 3175e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// - There are no protocol qualifiers. To reinforce this, code which 3176e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// tries to invoke the protocol methods via an ObjCInterfaceType will 3177e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// fail to compile. 3178e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// - It is its own base type. That is, if T is an ObjCInterfaceType*, 3179e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// T->getBaseType() == QualType(T, 0). 3180c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCInterfaceType : public ObjCObjectType { 3181c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCInterfaceDecl *Decl; 3182c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3183c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCInterfaceType(const ObjCInterfaceDecl *D) 3184c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall : ObjCObjectType(Nonce_ObjCInterface), 3185c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Decl(const_cast<ObjCInterfaceDecl*>(D)) {} 3186c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall friend class ASTContext; // ASTContext creates these. 3187c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic: 3188e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getDecl - Get the declaration of this interface. 3189deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor ObjCInterfaceDecl *getDecl() const { return Decl; } 3190c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3191c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool isSugared() const { return false; } 3192c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType desugar() const { return QualType(this, 0); } 31930b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 31941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 31951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ObjCInterface; 31963536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 3197a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 3198c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3199c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Nonsense to "hide" certain members of ObjCObjectType within this 3200c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // class. People asking for protocols on an ObjCInterfaceType are 3201c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // not going to get what they want: ObjCInterfaceTypes are 3202c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // guaranteed to have no protocols. 3203c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall enum { 3204c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator, 3205c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_begin, 3206c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_end, 3207c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getNumProtocols, 3208c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getProtocol 3209c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall }; 32103536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 32113536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 3212c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const { 3213c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCInterfaceType *T = 3214c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getBaseType()->getAs<ObjCInterfaceType>()) 3215c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T->getDecl(); 3216c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return 0; 3217c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 3218c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3219e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCObjectPointerType - Used to represent a pointer to an 3220e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Objective C object. These are constructed from pointer 3221e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar 3222e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for one). In addition, the 'id' and 'Class' types are typedefs 3223e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>' 3224e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// are translated into these. 322514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// 3226e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Pointers to pointers to Objective C objects are still PointerTypes; 3227e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// only the first level of pointer gets it own type implementation. 322814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 3229e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall QualType PointeeType; 32301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3231c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerType(QualType Canonical, QualType Pointee) 323235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(ObjCObjectPointer, Canonical, false, false), 3233c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall PointeeType(Pointee) {} 323414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff friend class ASTContext; // ASTContext creates these. 32351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 323660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected: 3237db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor virtual std::pair<Linkage, bool> getLinkageUnnamedLocalImpl() const; 323860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 323914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic: 3240e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getPointeeType - Gets the type pointed to by this ObjC pointer. 3241e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// The result will always be an ObjCObjectType or sugar thereof. 324214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const { return PointeeType; } 324314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 3244e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getObjCObjectType - Gets the type pointed to by this ObjC 3245e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// pointer. This method always returns non-null. 3246e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// 3247e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// This method is equivalent to getPointeeType() except that 3248e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// it discards any typedefs (or other sugar) between this 3249e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// type and the "outermost" object type. So for: 3250e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// @class A; @protocol P; @protocol Q; 3251e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A<P> AP; 3252e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A A1; 3253e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A1<P> A1P; 3254e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// typedef A1P<Q> A1PQ; 3255e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A*', getObjectType() will return 'A'. 3256e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A<P>*', getObjectType() will return 'A<P>'. 3257e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'AP*', getObjectType() will return 'A<P>'. 3258e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1*', getObjectType() will return 'A'. 3259e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1<P>*', getObjectType() will return 'A1<P>'. 3260e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1P*', getObjectType() will return 'A1<P>'. 3261e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because 3262e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// adding protocols to a protocol-qualified base discards the 3263e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// old qualifiers (for now). But if it didn't, getObjectType() 3264e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// would return 'A1P<Q>' (and we'd have to make iterating over 3265e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// qualifiers more complicated). 3266c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *getObjectType() const { 3267c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return PointeeType->getAs<ObjCObjectType>(); 3268c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 3269c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3270e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getInterfaceType - If this pointer points to an Objective C 3271e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// @interface type, gets the type for that interface. Any protocol 3272e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// qualifiers on the interface are ignored. 3273e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// 3274e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// \return null if the base type for this pointer is 'id' or 'Class' 32751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const ObjCInterfaceType *getInterfaceType() const { 3276c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>(); 327714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 3278e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 3279e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getInterfaceDecl - If this pointer points to an Objective @interface 3280e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// type, gets the declaration for that interface. 3281e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// 3282e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// \return null if the base type for this pointer is 'id' or 'Class' 328314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCInterfaceDecl *getInterfaceDecl() const { 3284e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall return getObjectType()->getInterface(); 328514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 3286e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 3287e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if 3288e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// its object type is the primitive 'id' type with no protocols. 328914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const { 3290c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCUnqualifiedId(); 329114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 3292e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 3293e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCClassType - True if this is equivalent to the 'Class' type, 3294e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// i.e. if its object tive is the primitive 'Class' type with no protocols. 329514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const { 3296c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCUnqualifiedClass(); 3297de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 32988d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian 3299e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some 3300e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// non-empty set of protocols. 33011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isObjCQualifiedIdType() const { 3302c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCQualifiedId(); 3303de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 3304e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 3305e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for 3306e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// some non-empty set of protocols. 3307470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const { 3308c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->isObjCQualifiedClass(); 330914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 3310e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall 3311e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// An iterator over the qualifiers on the object type. Provided 3312e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// for convenience. This will always iterate over the full set of 3313e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// protocols on a type, not just those provided directly. 3314c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall typedef ObjCObjectType::qual_iterator qual_iterator; 331514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 331671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek qual_iterator qual_begin() const { 3317c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->qual_begin(); 331871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek } 3319c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall qual_iterator qual_end() const { 3320c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->qual_end(); 332171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek } 3322c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool qual_empty() const { return getObjectType()->qual_empty(); } 332314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 3324e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// getNumProtocols - Return the number of qualifying protocols on 3325e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// the object type. 3326c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned getNumProtocols() const { 3327c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->getNumProtocols(); 3328c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 332914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 3330e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// \brief Retrieve a qualifying protocol by index on the object 3331e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall /// type. 333273dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor ObjCProtocolDecl *getProtocol(unsigned I) const { 3333c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getObjectType()->getProtocol(I); 333473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor } 333573dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor 3336bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 3337bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 3338bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 3339e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall void Profile(llvm::FoldingSetNodeID &ID) { 3340e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall Profile(ID, getPointeeType()); 3341e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall } 3342c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { 3343c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(T.getAsOpaquePtr()); 3344c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 33451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 33461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ObjCObjectPointer; 334714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 334814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 334914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}; 33501bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 33510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers. 33520953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers { 33530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ASTContext *Context; 33540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 33550953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 33560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector(Qualifiers Qs = Qualifiers()) 33570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Qualifiers(Qs), Context(0) {} 33580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector(ASTContext &Context, Qualifiers Qs = Qualifiers()) 33590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Qualifiers(Qs), Context(&Context) {} 33600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 33610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setContext(ASTContext &C) { Context = &C; } 33620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 33630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Collect any qualifiers on the given type and return an 33640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// unqualified type. 33650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *strip(QualType QT) { 3366a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor addFastQualifiers(QT.getLocalFastQualifiers()); 3367a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (QT.hasLocalNonFastQualifiers()) { 33680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = QT.getExtQualsUnsafe(); 33690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Context = &EQ->getContext(); 33700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addQualifiers(EQ->getQualifiers()); 33710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getBaseType(); 33720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 33730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QT.getTypePtrUnsafe(); 33740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 33750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 33760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Apply the collected qualifiers to the given type. 33770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType apply(QualType QT) const; 33780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 33790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Apply the collected qualifiers to the given type. 33800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType apply(const Type* T) const; 33810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 33820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 33830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 33840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3385611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 33865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3387467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const { 3388467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall const Type *T = getTypePtr(); 3389a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalQualifiers()) 3390467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall return T->isCanonicalUnqualified() && !isa<ArrayType>(T); 3391467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall return T->isCanonicalUnqualified(); 3392467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall} 3393467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall 339454e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const { 3395a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalQualifiers()) return false; 3396745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian 339754e14c4db764c0636160d26c5bbf491637c83a76John McCall const Type *T = getTypePtr(); 3398745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian if ((*this)->isPointerType()) { 3399745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian QualType BaseType = (*this)->getAs<PointerType>()->getPointeeType(); 3400745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian if (isa<VariableArrayType>(BaseType)) { 3401745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian ArrayType *AT = dyn_cast<ArrayType>(BaseType); 3402745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian VariableArrayType *VAT = cast<VariableArrayType>(AT); 3403745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian if (VAT->getSizeExpr()) 3404745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian T = BaseType.getTypePtr(); 3405745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 3406745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 340754e14c4db764c0636160d26c5bbf491637c83a76John McCall return T->isCanonicalUnqualified() && 340854e14c4db764c0636160d26c5bbf491637c83a76John McCall !isa<FunctionType>(T) && !isa<ArrayType>(T); 340954e14c4db764c0636160d26c5bbf491637c83a76John McCall} 341054e14c4db764c0636160d26c5bbf491637c83a76John McCall 3411fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const { 3412fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return isLocalConstQualified() || 3413fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalConstQualified(); 3414fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 3415fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 3416fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const { 3417fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return isLocalRestrictQualified() || 3418fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalRestrictQualified(); 3419fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 3420fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 3421fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 3422fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const { 3423fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return isLocalVolatileQualified() || 3424fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalVolatileQualified(); 3425fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 3426fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 3427fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const { 3428fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return hasLocalQualifiers() || 3429fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers(); 3430fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 3431fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 3432fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline Qualifiers QualType::getQualifiers() const { 3433fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor Qualifiers Quals = getLocalQualifiers(); 3434fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor Quals.addQualifiers( 3435fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor getTypePtr()->getCanonicalTypeInternal().getLocalQualifiers()); 3436fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return Quals; 3437fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 3438fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 3439fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline unsigned QualType::getCVRQualifiers() const { 3440fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return getLocalCVRQualifiers() | 3441fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor getTypePtr()->getCanonicalTypeInternal().getLocalCVRQualifiers(); 3442fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 3443e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth 3444e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// getCVRQualifiersThroughArrayTypes - If there are CVR qualifiers for this 3445e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// type, returns them. Otherwise, if this is an array type, recurses 3446e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// on the element type until some qualifiers have been found or a non-array 3447e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// type reached. 3448e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruthinline unsigned QualType::getCVRQualifiersThroughArrayTypes() const { 3449e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth if (unsigned Quals = getCVRQualifiers()) 3450e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth return Quals; 3451e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth QualType CT = getTypePtr()->getCanonicalTypeInternal(); 3452e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 3453e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth return AT->getElementType().getCVRQualifiersThroughArrayTypes(); 3454e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth return 0; 3455e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth} 3456e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth 34570953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeConst() { 34580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeFastQualifiers(Qualifiers::Const); 34590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 34600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 34610953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeRestrict() { 34620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeFastQualifiers(Qualifiers::Restrict); 34630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 34640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 34650953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeVolatile() { 34660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qc; 34670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *Ty = Qc.strip(*this); 34680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Qc.hasVolatile()) { 34690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qc.removeVolatile(); 34700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall *this = Qc.apply(Ty); 34710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 34720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 34730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 34740953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeCVRQualifiers(unsigned Mask) { 34756b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits"); 34760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 34770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Fast path: we don't need to touch the slow qualifiers. 34780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!(Mask & ~Qualifiers::FastMask)) { 34790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeFastQualifiers(Mask); 34800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return; 34810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 34820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 34830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qc; 34840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *Ty = Qc.strip(*this); 34850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qc.removeCVRQualifiers(Mask); 34860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall *this = Qc.apply(Ty); 3487ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 3488ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 3489ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 3490ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 3491a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalNonFastQualifiers()) { 34920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = getExtQualsUnsafe(); 34930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (EQ->hasAddressSpace()) 34940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getAddressSpace(); 34950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 34960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 34974243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 3498a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (CT.hasLocalNonFastQualifiers()) { 34990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = CT.getExtQualsUnsafe(); 35000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (EQ->hasAddressSpace()) 35010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getAddressSpace(); 35020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 35030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 35044243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 3505c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT->getElementType().getAddressSpace(); 35064243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 35078e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman return RT->getAddressSpace(); 3508ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return 0; 3509ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 3510611c1fff195d32df97706e0920c92468b2509900Chris Lattner 3511d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 35120953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const { 3513a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalNonFastQualifiers()) { 35140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = getExtQualsUnsafe(); 35150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (EQ->hasObjCGCAttr()) 35160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getObjCGCAttr(); 35170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 35180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3519d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 3520a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (CT.hasLocalNonFastQualifiers()) { 35210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = CT.getExtQualsUnsafe(); 35220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (EQ->hasObjCGCAttr()) 35230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getObjCGCAttr(); 35240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 35250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3526d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 3527d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return AT->getElementType().getObjCGCAttr(); 3528183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *PT = CT->getAs<ObjCObjectPointerType>()) 35291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return PT->getPointeeType().getObjCGCAttr(); 3530ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian // We most look at all pointer types, not just pointer to interface types. 3531ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian if (const PointerType *PT = CT->getAs<PointerType>()) 35321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return PT->getPointeeType().getObjCGCAttr(); 35330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qualifiers::GCNone; 3534d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 35352455636163fdd18581d7fdae816433f886d88213Mike Stump 3536264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { 3537264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola if (const PointerType *PT = t.getAs<PointerType>()) { 3538183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>()) 3539264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FT->getExtInfo(); 3540264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } else if (const FunctionType *FT = t.getAs<FunctionType>()) 3541264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FT->getExtInfo(); 35422455636163fdd18581d7fdae816433f886d88213Mike Stump 3543264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FunctionType::ExtInfo(); 35442455636163fdd18581d7fdae816433f886d88213Mike Stump} 35451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3546264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { 3547264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return getFunctionExtInfo(*t); 3548ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor} 3549ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor 3550b87786f045d798b070980c108c922e1475d27b15Douglas Gregor/// \brief Determine whether this set of qualifiers is a superset of the given 3551b87786f045d798b070980c108c922e1475d27b15Douglas Gregor/// set of qualifiers. 3552b87786f045d798b070980c108c922e1475d27b15Douglas Gregorinline bool Qualifiers::isSupersetOf(Qualifiers Other) const { 3553b87786f045d798b070980c108c922e1475d27b15Douglas Gregor return Mask != Other.Mask && (Mask | Other.Mask) == Mask; 3554b87786f045d798b070980c108c922e1475d27b15Douglas Gregor} 3555b87786f045d798b070980c108c922e1475d27b15Douglas Gregor 3556e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 3557e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 3558e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and 3559e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile 3560e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int". 3561e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 35620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // FIXME: work on arbitrary qualifiers 3563e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes(); 3564e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes(); 3565ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 3566ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 3567e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 3568e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 3569e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 3570e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 3571e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile 3572e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 3573e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int". 3574e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 35750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // FIXME: work on arbitrary qualifiers 3576e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes(); 3577e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes(); 3578ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 3579ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 3580e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 3581e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 3582e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 3583e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 3584e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const 3585e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 3586e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6: 3587e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 3588e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 3589e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 3590e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// analysis, the expression designates the object or function 3591e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 3592e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const { 35936217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 3594e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return RefType->getPointeeType(); 3595e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor else 3596e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return *this; 3597e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 3598e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 3599611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 3600a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<FunctionType>(CanonicalType); 3601611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 3602611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 3603a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<PointerType>(CanonicalType); 3604611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 360558f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const { 360658f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff return isPointerType() || isObjCObjectPointerType(); 360758f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff} 36085618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const { 3609a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<BlockPointerType>(CanonicalType); 36105618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 3611bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const { 3612a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ReferenceType>(CanonicalType); 3613bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 36147c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const { 3615a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<LValueReferenceType>(CanonicalType); 36167c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 36177c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const { 3618a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<RValueReferenceType>(CanonicalType); 36197c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 3620498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 36216217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType* T = getAs<PointerType>()) 3622498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 3623498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 3624498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 3625498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 3626f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const { 3627a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<MemberPointerType>(CanonicalType); 3628f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 3629f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 36306217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const MemberPointerType* T = getAs<MemberPointerType>()) 36310bab0cdab751248ca389a5592bcb70eac5d39260John McCall return T->isMemberFunctionPointer(); 3632f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl else 3633f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return false; 3634f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 3635db68e28c05a67735211e688009890cf834c22e75Douglas Gregorinline bool Type::isMemberDataPointerType() const { 3636db68e28c05a67735211e688009890cf834c22e75Douglas Gregor if (const MemberPointerType* T = getAs<MemberPointerType>()) 36370bab0cdab751248ca389a5592bcb70eac5d39260John McCall return T->isMemberDataPointer(); 3638db68e28c05a67735211e688009890cf834c22e75Douglas Gregor else 3639db68e28c05a67735211e688009890cf834c22e75Douglas Gregor return false; 3640db68e28c05a67735211e688009890cf834c22e75Douglas Gregor} 3641611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 3642a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ArrayType>(CanonicalType); 3643611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 3644c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const { 3645a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ConstantArrayType>(CanonicalType); 3646c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 3647c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const { 3648a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<IncompleteArrayType>(CanonicalType); 3649c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 3650c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const { 3651a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<VariableArrayType>(CanonicalType); 3652c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 3653898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const { 3654a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType); 3655898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 36563ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isBuiltinType() const { 36573ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall return isa<BuiltinType>(CanonicalType); 36583ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall} 3659611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 3660a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<RecordType>(CanonicalType); 3661611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 36623ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isEnumeralType() const { 36633ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall return isa<EnumType>(CanonicalType); 36643ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall} 3665f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const { 3666a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ComplexType>(CanonicalType); 3667f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner} 3668611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 3669a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<VectorType>(CanonicalType); 3670611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 3671213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const { 3672a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ExtVectorType>(CanonicalType); 3673611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 3674d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const { 3675a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ObjCObjectPointerType>(CanonicalType); 3676d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 3677c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline bool Type::isObjCObjectType() const { 3678c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return isa<ObjCObjectType>(CanonicalType); 3679368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 3680569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorinline bool Type::isObjCObjectOrInterfaceType() const { 3681569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor return isa<ObjCInterfaceType>(CanonicalType) || 3682569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor isa<ObjCObjectType>(CanonicalType); 3683569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor} 3684569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor 3685a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 3686183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3687d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT->isObjCQualifiedIdType(); 3688d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return false; 3689d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 3690470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const { 3691183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3692470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return OPT->isObjCQualifiedClassType(); 3693470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return false; 3694470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff} 369514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const { 3696183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 369714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCIdType(); 369814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 369914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 370014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const { 3701183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 370214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCClassType(); 370314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 370414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 370513dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const { 37068d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian if (const PointerType *OPT = getAs<PointerType>()) 37078d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); 370813dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian return false; 370913dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian} 3710de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const { 371113dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian return isObjCIdType() || isObjCClassType() || isObjCSelType(); 3712de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff} 371372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const { 3714a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType); 371572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor} 371672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 3717e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 3718183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 3719e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 3720e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return true; 3721e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return false; 3722e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar} 3723e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 37242a984cad5ac3fdceeff2bd99daa7b90979313475John McCallinline bool Type::isPlaceholderType() const { 37252a984cad5ac3fdceeff2bd99daa7b90979313475John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 37262a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return BT->isPlaceholderType(); 37272a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return false; 37282a984cad5ac3fdceeff2bd99daa7b90979313475John McCall} 37292a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 3730063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define 3731063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator. 3732063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const { 3733063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 3734904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor} 3735904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 37368958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 37378958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 3738c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall isObjCObjectPointerType() || isNullPtrType()); 37398958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar} 37408958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 3741820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 3742c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return isObjCObjectPointerType(); 3743820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian} 3744820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 374522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 374622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<. 374722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 374822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner QualType T) { 374922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 375022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner Diagnostic::ak_qualtype); 375122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner return DB; 375222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner} 37531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 375447c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// Insertion operator for partial diagnostics. This allows sending QualType's 375547c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// into a diagnostic with <<. 375647c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruthinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, 375747c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth QualType T) { 375847c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 375947c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth Diagnostic::ak_qualtype); 376047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth return PD; 376147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth} 376247c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth 376389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does 376489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type. 376589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T, 376689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor bool isArrayType = (llvm::is_same<T, ArrayType>::value || 376789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor llvm::is_base_of<ArrayType, T>::value)> 376889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { }; 376989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor 377089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T> 377189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>; 377289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor 37731a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'. 37741a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const { 377589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor ArrayType_cannot_be_used_with_getAs<T> at; 377689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor (void)at; 377789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor 37781a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If this is directly a T type, return it. 37791a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek if (const T *Ty = dyn_cast<T>(this)) 37801a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return Ty; 37811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37821a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If the canonical form of this type isn't the right kind, reject it. 37830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<T>(CanonicalType)) 37841a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return 0; 37851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If this is a typedef for the type, strip the typedef off without 37871a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // losing all typedef information. 3788bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<T>(getUnqualifiedDesugaredType()); 37891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 379022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner 37915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 37925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 37935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 3794