Type.h revision fb87b89fc9eb103e19fb8e4b925c23f0bd091b99
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; 95e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor class QualifiedNameType; 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 2740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool operator==(Qualifiers Other) const { return Mask == Other.Mask; } 2750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; } 2760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall operator bool() const { return hasQualifiers(); } 2780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers &operator+=(Qualifiers R) { 2800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addQualifiers(R); 2810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return *this; 2820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Union two qualifier sets. If an enumerated qualifier appears 2850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // in both sets, use the one from the right. 2860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall friend Qualifiers operator+(Qualifiers L, Qualifiers R) { 2870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall L += R; 2880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return L; 2890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string getAsString() const; 2920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string getAsString(const PrintingPolicy &Policy) const { 2930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string Buffer; 2940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getAsStringInternal(Buffer, Policy); 2950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Buffer; 2960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const; 2980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 3000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ID.AddInteger(Mask); 3010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3030953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate: 3040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // bits: |0 1 2|3 .. 4|5 .. 31| 3060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // |C R V|GCAttr|AddrSpace| 3070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall uint32_t Mask; 3080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t GCAttrMask = 0x18; 3100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t GCAttrShift = 3; 3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask); 3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t AddressSpaceShift = 5; 3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// ExtQuals - We can encode up to three bits in the low bits of a 3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// type pointer, but there are many more type qualifiers that we want 3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// to be able to apply to an arbitrary type. Therefore we have this 3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// struct, intended to be heap-allocated and used by QualType to 3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// store qualifiers. 3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 3220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// The current design tags the 'const' and 'restrict' qualifiers in 3230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// two low bits on the QualType pointer; a third bit records whether 3240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// the pointer is an ExtQuals node. 'const' was chosen because it is 3250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// orders of magnitude more common than the other two qualifiers, in 3260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// both library and user code. It's relatively rare to see 3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'restrict' in user code, but many standard C headers are saturated 3280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// with 'restrict' declarations, so that representing them efficiently 3290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// is a critical goal of this representation. 3300953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass ExtQuals : public llvm::FoldingSetNode { 3310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // NOTE: changing the fast qualifiers should be straightforward as 3320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // long as you don't make 'const' non-fast. 3330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // 1. Qualifiers: 3340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ). 3350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Fast qualifiers must occupy the low-order bits. 3360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // b) Update Qualifiers::FastWidth and FastMask. 3370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // 2. QualType: 3380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // a) Update is{Volatile,Restrict}Qualified(), defined inline. 3390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // b) Update remove{Volatile,Restrict}, defined near the end of 3400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // this header. 3410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // 3. ASTContext: 3420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // a) Update get{Volatile,Restrict}Type. 3430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Context - the context to which this set belongs. We save this 3450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// here so that QualifierCollector can use it to reapply extended 3460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// qualifiers to an arbitrary type without requiring a context to 3470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// be pushed through every single API dealing with qualifiers. 3480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ASTContext& Context; 3490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// BaseType - the underlying type that this qualifies 3510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *BaseType; 3520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Quals - the immutable set of qualifiers applied by this 3540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// node; always contains extended qualifiers. 3550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Quals; 3560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3570953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 3580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ExtQuals(ASTContext& Context, const Type *Base, Qualifiers Quals) 3590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Context(Context), BaseType(Base), Quals(Quals) 3600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall { 3610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(Quals.hasNonFastQualifiers() 3620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall && "ExtQuals created with no fast qualifiers"); 3630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!Quals.hasFastQualifiers() 3640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall && "ExtQuals created with fast qualifiers"); 3650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers getQualifiers() const { return Quals; } 3680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasVolatile() const { return Quals.hasVolatile(); } 3700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); } 3720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); } 3730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasAddressSpace() const { return Quals.hasAddressSpace(); } 3750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getAddressSpace() const { return Quals.getAddressSpace(); } 3760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *getBaseType() const { return BaseType; } 3781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ASTContext &getContext() const { return Context; } 3800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3810953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 3820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 3830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Profile(ID, getBaseType(), Quals); 3840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, 3860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *BaseType, 3870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Quals) { 3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!"); 3890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ID.AddPointer(BaseType); 3900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.Profile(ID); 3910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 3930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 394ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses. 395ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv { 396ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_Default, 397ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_C, // __attribute__((cdecl)) 398ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_X86StdCall, // __attribute__((stdcall)) 399ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CC_X86FastCall // __attribute__((fastcall)) 400ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}; 401ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor 4020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on 4040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers. This 4050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for 4060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int', 4070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc). 4080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 4090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we 4100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the 4110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer. To handle the packing/unpacking, we make QualType be a 4120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer. A third bit 4130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which 4140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure. 4150953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType { 4160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Thankfully, these are efficiently composable. 4170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>, 4180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::FastWidth> Value; 4190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *getExtQualsUnsafe() const { 4210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().get<const ExtQuals*>(); 4220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *getTypePtrUnsafe() const { 4250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().get<const Type*>(); 4260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 428fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor QualType getUnqualifiedTypeSlow() const; 429fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 4300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall friend class QualifierCollector; 4310953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 4325cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType() {} 4331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4345cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType(const Type *Ptr, unsigned Quals) 4350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Value(Ptr, Quals) {} 4360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType(const ExtQuals *Ptr, unsigned Quals) 4370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Value(Ptr, Quals) {} 4380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 439a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor unsigned getLocalFastQualifiers() const { return Value.getInt(); } 440a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); } 4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Retrieves a pointer to the underlying (unqualified) type. 4430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// This should really return a const Type, but it's not worth 4440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// changing all the users right now. 4450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Type *getTypePtr() const { 446a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalNonFastQualifiers()) 4470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return const_cast<Type*>(getExtQualsUnsafe()->getBaseType()); 4480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return const_cast<Type*>(getTypePtrUnsafe()); 4490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4515cf243a883872441d73ca49cea7e20de5802629bChris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static QualType getFromOpaquePtr(void *Ptr) { 4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType T; 4545cf243a883872441d73ca49cea7e20de5802629bChris Lattner T.Value.setFromOpaqueValue(Ptr); 4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T; 4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type &operator*() const { 4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *getTypePtr(); 4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *operator->() const { 4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypePtr(); 4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 466467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall bool isCanonical() const; 46754e14c4db764c0636160d26c5bbf491637c83a76John McCall bool isCanonicalAsParam() const; 468467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall 4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNull - Return true if this QualType doesn't point to a type yet. 4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNull() const { 4710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().isNull(); 4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 474a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has the 475a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "const" qualifier set, without looking through typedefs that may have 476a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "const" at a different level. 477a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalConstQualified() const { 478a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Const); 4790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 480a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 481a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is const-qualified. 482fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isConstQualified() const; 483a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 484a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has the 485a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "restrict" qualifier set, without looking through typedefs that may have 486a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "restrict" at a different level. 487a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalRestrictQualified() const { 488a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Restrict); 489a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor } 490a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 491a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is restrict-qualified. 492fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isRestrictQualified() const; 493a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 494a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has the 495a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "volatile" qualifier set, without looking through typedefs that may have 496a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// added "volatile" at a different level. 497a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool isLocalVolatileQualified() const { 498a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return (hasLocalNonFastQualifiers() && getExtQualsUnsafe()->hasVolatile()); 4995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 501a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type is volatile-qualified. 502fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool isVolatileQualified() const; 503a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 504a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has any 505a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// qualifiers, without looking through any typedefs that might add 506a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// qualifiers at a different level. 507a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool hasLocalQualifiers() const { 508a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return getLocalFastQualifiers() || hasLocalNonFastQualifiers(); 5090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 511a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this type has any qualifiers. 512fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor bool hasQualifiers() const; 513a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 514a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Determine whether this particular QualType instance has any 515a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType 516a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// instance. 517a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor bool hasLocalNonFastQualifiers() const { 518a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return Value.getPointer().is<const ExtQuals*>(); 5190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 521a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of qualifiers local to this particular QualType 522a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// instance, not including any qualifiers acquired through typedefs or 523a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// other sugar. 524a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers getLocalQualifiers() const { 5250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Quals; 526a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalNonFastQualifiers()) 5270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals = getExtQualsUnsafe()->getQualifiers(); 528a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Quals.addFastQualifiers(getLocalFastQualifiers()); 5290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Quals; 5300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 532a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of qualifiers applied to this type. 533fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor Qualifiers getQualifiers() const; 534a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 535a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 536a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// local to this particular QualType instance, not including any qualifiers 537a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// acquired through typedefs or other sugar. 538a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor unsigned getLocalCVRQualifiers() const { 539a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor unsigned CVR = getLocalFastQualifiers(); 540a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (isLocalVolatileQualified()) 541a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor CVR |= Qualifiers::Volatile; 5420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return CVR; 5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 544b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 545a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 546a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// applied to this type. 547fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor unsigned getCVRQualifiers() const; 548e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth 549e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 550e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth /// applied to this type, looking through any number of unqualified array 551e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth /// types to their element types' qualifiers. 552e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth unsigned getCVRQualifiersThroughArrayTypes() const; 553e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth 554bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isConstant(ASTContext& Ctx) const { 555bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return QualType::isConstant(*this, Ctx); 556bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 5571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Don't promise in the API that anything besides 'const' can be 5590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // easily added. 5600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// addConst - add the specified type qualifier to this QualType. 5620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addConst() { 5630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addFastQualifiers(Qualifiers::Const); 5640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withConst() const { 5660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return withFastQualifiers(Qualifiers::Const); 5670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addFastQualifiers(unsigned TQs) { 5700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(TQs & ~Qualifiers::FastMask) 5710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall && "non-fast qualifier bits set in mask!"); 5720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Value.setInt(Value.getInt() | TQs); 5730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 575a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor // FIXME: The remove* functions are semantically broken, because they might 576a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor // not remove a qualifier stored on a typedef. Most of the with* functions 577a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor // have the same problem. 5780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeConst(); 5790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeVolatile(); 5800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeRestrict(); 5810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeCVRQualifiers(unsigned Mask); 5820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeFastQualifiers() { Value.setInt(0); } 5840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeFastQualifiers(unsigned Mask) { 5850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers"); 5860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Value.setInt(Value.getInt() & ~Mask); 5870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Creates a type with the given qualifiers in addition to any 5900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // qualifiers already on this type. 5910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withFastQualifiers(unsigned TQs) const { 5920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType T = *this; 5930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall T.addFastQualifiers(TQs); 5940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return T; 5950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5961c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta 5970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Creates a type with exactly the given fast qualifiers, removing 5980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // any existing fast qualifiers. 5990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withExactFastQualifiers(unsigned TQs) const { 6000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return withoutFastQualifiers().withFastQualifiers(TQs); 6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 6030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Removes fast qualifiers, but leaves any extended qualifiers in place. 6040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withoutFastQualifiers() const { 6050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType T = *this; 6060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall T.removeFastQualifiers(); 6070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return T; 608c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 609971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 610a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Return this type with all of the instance-specific qualifiers 611a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// removed, but without removing any qualifiers that may have been applied 612a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// through typedefs. 613a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); } 6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 615a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// \brief Return the unqualified form of the given type, which might be 616a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor /// desugared to eliminate qualifiers introduced via typedefs. 617fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor QualType getUnqualifiedType() const { 618fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor QualType T = getLocalUnqualifiedType(); 619fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor if (!T.hasQualifiers()) 620fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return T; 621fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 622fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return getUnqualifiedTypeSlow(); 623a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor } 624a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor 625e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 626e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 627e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getNonReferenceType() const; 6281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6292fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 6302fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 6312fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 6322fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 6332fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 6342fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// concrete. 6350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// 6360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Qualifiers are left in place. 637bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType getDesugaredType() const { 638bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return QualType::getDesugaredType(*this); 639bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 64098cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor 6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// operator==/!= - Indicate whether the specified types and qualifiers are 6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identical. 64350d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor friend bool operator==(const QualType &LHS, const QualType &RHS) { 64450d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return LHS.Value == RHS.Value; 6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 64650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor friend bool operator!=(const QualType &LHS, const QualType &RHS) { 64750d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return LHS.Value != RHS.Value; 6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 649d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString() const; 650d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 651d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString(const PrintingPolicy &Policy) const { 6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string S; 653d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor getAsStringInternal(S, Policy); 6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return S; 6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 656e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner void getAsStringInternal(std::string &Str, 657e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy) const; 6581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 659c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump(const char *s) const; 660c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 6611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6623f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 6633f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 6643f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek } 6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 666ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 667ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 6681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 669d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 6700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall inline Qualifiers::GC getObjCGCAttr() const; 671f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 672f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 673f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCWeak() const { 6740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getObjCGCAttr() == Qualifiers::Weak; 675f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 676f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 677f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 678f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCStrong() const { 6790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getObjCGCAttr() == Qualifiers::Strong; 680f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 6812455636163fdd18581d7fdae816433f886d88213Mike Stump 682bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate: 683bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // These methods are implemented in a separate translation unit; 684bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // "static"-ize them to avoid creating temporary QualTypes in the 685bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // caller. 686bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall static bool isConstant(QualType T, ASTContext& Ctx); 687bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall static QualType getDesugaredType(QualType T); 6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 6965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef ::clang::Type* SimpleType; 6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Val.getTypePtr(); 6995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 7031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7044e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 7054e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<> 706daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 7074e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic: 7084e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 7094e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return P.getAsOpaquePtr(); 7104e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 7114e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 7124e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return clang::QualType::getFromOpaquePtr(P); 7134e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 7140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Various qualifiers go in low bits. 7150eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 0 }; 7164e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}; 7171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71873af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 73372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 73672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type { 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 75072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class, 75127935ee59c30b0d8b610ab676aab8e65350af932John McCall#define LAST_TYPE(Class) TypeLast = Class, 75272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 75372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 75472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TagFirst = Record, TagLast = Enum 7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 7561bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType CanonicalType; 7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 76127935ee59c30b0d8b610ab676aab8e65350af932John McCall unsigned TC : 8; 76227935ee59c30b0d8b610ab676aab8e65350af932John McCall 76327935ee59c30b0d8b610ab676aab8e65350af932John McCall /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Note that this should stay at the end of the ivars for Type so that 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// subclasses can pack their bitfields into the same word. 76627935ee59c30b0d8b610ab676aab8e65350af932John McCall bool Dependent : 1; 767898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 76816ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner Type(const Type&); // DO NOT IMPLEMENT. 76916ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner void operator=(const Type&); // DO NOT IMPLEMENT. 7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 771124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 772124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 773898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 774f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 77527935ee59c30b0d8b610ab676aab8e65350af932John McCall TC(tc), Dependent(dependent) {} 776898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual ~Type() {} 7774b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 7791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7808b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 781a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 7821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 783467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall bool isCanonicalUnqualified() const { 784467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall return CanonicalType.getTypePtr() == this; 785467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall } 7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 7885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 7891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 790bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// \brief Determines whether the type describes an object in memory. 791bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// 792bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// Note that this definition of object type corresponds to the C++ 793bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// definition of object type, which includes incomplete types, as 794bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// opposed to the C definition (which does not include incomplete 795bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// types). 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isObjectType() const; 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 8011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// routine will need to determine if the size is actually required. 8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncompleteType() const; 803d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner 804d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 805d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// type, in other words, not a function type. 806d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner bool isIncompleteOrObjectType() const { 807d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner return !isFunctionType(); 808d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner } 80964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 81064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 81164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl bool isPODType() const; 81264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 813ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl /// isLiteralType - Return true if this is a literal type 814ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl /// (C++0x [basic.types]p10) 815ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl bool isLiteralType() const; 816ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 817d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 818d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// types that have a non-constant expression. This does not include "[]". 819d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff bool isVariablyModifiedType() const; 8201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 822ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 823e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 824e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 825e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 8261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 82796d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 82896d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 83013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 83113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 83213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 83377a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor bool isWideCharType() const; 83420093b4bf698f292c664676987541d5103b65b15Douglas Gregor bool isAnyCharacterType() const; 83533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian bool isIntegralType() const; 83620093b4bf698f292c664676987541d5103b65b15Douglas Gregor 8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 83902f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 84002f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 8415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 842f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 846c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 847c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 848c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 849d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor bool isAggregateType() const; 8501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 851c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 852ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 853c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 854183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } 855183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } 856befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 85758f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 8585618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff bool isBlockPointerType() const; 8597154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff bool isVoidPointerType() const; 860a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 8617c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isLValueReferenceType() const; 8627c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isRValueReferenceType() const; 863bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isFunctionPointerType() const; 864f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberPointerType() const; 865f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberFunctionPointerType() const; 866c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 867c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isConstantArrayType() const; 868c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isIncompleteArrayType() const; 869c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isVariableArrayType() const; 870898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentSizedArrayType() const; 871c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 8721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isClassType() const; 8731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isStructureType() const; 874fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor bool isStructureOrClassType() const; 8754cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 876368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 877368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isVectorType() const; // GCC vector type. 878213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman bool isExtVectorType() const; // Extended vector type. 879d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 88014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // FIXME: change this to 'raw' interface type, so we can used 'interface' type 88114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for the common case. 882368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCInterfaceType() const; // NSString or NSString<foo> 883368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 884368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedIdType() const; // id<foo> 885470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const; // Class<foo> 88614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const; // id 88714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const; // Class 88813dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian bool isObjCSelType() const; // Class 889de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff bool isObjCBuiltinType() const; // 'id' or 'Class' 89072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 8916e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 892898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 893898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 8941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// that its definition somehow depends on a template parameter 895898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.type]). 896898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentType() const { return Dependent; } 897063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor bool isOverloadableType() const; 89872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 8994033642464e8ba0982f88f34cffad808d247b393Douglas Gregor /// \brief Determine wither this type is a C++ elaborated-type-specifier. 9004033642464e8ba0982f88f34cffad808d247b393Douglas Gregor bool isElaboratedTypeSpecifier() const; 9014033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 9028958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 9038958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 9048958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 9056e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl /// interface types, as well as nullptr_t. 9068958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar bool hasPointerRepresentation() const; 9078958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 908820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 909820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 9101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool hasObjCPointerRepresentation() const; 911820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 912c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 913f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 914f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 915769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const RecordType *getAsStructureType() const; 916898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 917c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 9184cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 91914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // The following is a convenience method that returns an ObjCObjectPointerType 92014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for object declared using an interface. 92114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 92214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 923c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff const ObjCInterfaceType *getAsObjCQualifiedInterfaceType() const; 924a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 9251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9261a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // Member-template getAs<specific type>'. This scheme will eventually 9271a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // replace the specific getAsXXXX methods above. 928183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall // 929183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall // There are some specializations of this member template listed 930183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall // immediately following this class. 9311a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek template <typename T> const T *getAs() const; 9321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9332b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 9342b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// interface, return the interface type, otherwise return null. 9352b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 9362b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 937c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 938c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// element type of the array, potentially with type qualifiers missing. 939c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// This method should never be used when type qualifiers are meaningful. 940c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 9411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 942f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// getPointeeType - If this is a pointer, ObjC object pointer, or block 943f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// pointer, this returns the respective pointee. 94414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const; 9451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 946bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// getUnqualifiedDesugaredType() - Return the specified type with 947bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// any "sugar" removed from the type, removing any typedefs, 948bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// typeofs, etc., as well as any qualifiers. 949bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *getUnqualifiedDesugaredType() const; 9501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 955d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 956d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 957d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// integer element type. 9585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 961d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 962d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 963d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// element type. 9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 965d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 9679bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 9689bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 9693c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 970c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 97122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 97222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// set of type specifiers. 97322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman bool isSpecifierType() const; 97422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 975cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis const char *getTypeClassName() const; 976cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis 9770b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor /// \brief Determine the linkage of this type. 9780b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor virtual Linkage getLinkage() const; 9790b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 980ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall QualType getCanonicalTypeInternal() const { 981ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall return CanonicalType; 982ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall } 983ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h 984c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 9855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 988183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const { 989183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall return dyn_cast<TypedefType>(this); 990183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall} 991183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 992183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to 993183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration. 994183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base) 995183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \ 996183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \ 9970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return dyn_cast<Class##Type>(CanonicalType); \ 998183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall} 999183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def" 1000183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 1001183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Void, 10081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Bool, // This is bool and/or _Bool. 10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_U, // This is 'char' for targets where char is unsigned. 10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UChar, // This is explicitly qualified unsigned char. 1012f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char16, // This is 'char16_t' for C++. 1013f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char32, // This is 'char32_t' for C++. 10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UShort, 10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UInt, 10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULong, 10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULongLong, 10182df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner UInt128, // __uint128_t 10191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_S, // This is 'char' for targets where char is signed. 10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SChar, // This is explicitly qualified signed char. 10222ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis WChar, // This is 'wchar_t' for C++. 10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Short, 10245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Int, 10255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Long, 10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongLong, 10272df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner Int128, // __int128_t 10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10298e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor Float, Double, LongDouble, 10308e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 10316e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 10326e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 1033898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Overload, // This represents the type of an overloaded function declaration. 1034e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson Dependent, // This represents the type of a type-dependent expression. 10351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1036de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff UndeducedAuto, // In C++0x, this represents the type of an auto variable 1037e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson // that has not been deduced yet. 1038de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCId, // This represents the ObjC 'id' type. 103913dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian ObjCClass, // This represents the ObjC 'Class' type. 104013dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian ObjCSel // This represents the ObjC 'SEL' type. 10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 10425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 10435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind TypeKind; 10445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BuiltinType(Kind K) 10461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 1047898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeKind(K) {} 10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind getKind() const { return TypeKind; } 1050e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const char *getName(const LangOptions &LO) const; 10511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1052bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1053bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1054bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1055680523a91dd3351389667c8de17121ba7ae82673John McCall bool isInteger() const { 1056680523a91dd3351389667c8de17121ba7ae82673John McCall return TypeKind >= Bool && TypeKind <= Int128; 1057680523a91dd3351389667c8de17121ba7ae82673John McCall } 1058680523a91dd3351389667c8de17121ba7ae82673John McCall 1059680523a91dd3351389667c8de17121ba7ae82673John McCall bool isSignedInteger() const { 1060680523a91dd3351389667c8de17121ba7ae82673John McCall return TypeKind >= Char_S && TypeKind <= Int128; 1061680523a91dd3351389667c8de17121ba7ae82673John McCall } 1062680523a91dd3351389667c8de17121ba7ae82673John McCall 1063680523a91dd3351389667c8de17121ba7ae82673John McCall bool isUnsignedInteger() const { 1064680523a91dd3351389667c8de17121ba7ae82673John McCall return TypeKind >= Bool && TypeKind <= UInt128; 1065680523a91dd3351389667c8de17121ba7ae82673John McCall } 1066680523a91dd3351389667c8de17121ba7ae82673John McCall 1067680523a91dd3351389667c8de17121ba7ae82673John McCall bool isFloatingPoint() const { 1068680523a91dd3351389667c8de17121ba7ae82673John McCall return TypeKind >= Float && TypeKind <= LongDouble; 1069680523a91dd3351389667c8de17121ba7ae82673John McCall } 1070680523a91dd3351389667c8de17121ba7ae82673John McCall 10710b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor virtual Linkage getLinkage() const; 10720b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 10785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 10815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 10825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 10831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Type(Complex, CanonicalPtr, Element->isDependentType()), 1084898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(Element) { 10855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 10875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 10891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1090bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1091bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1092bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 10935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 10955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 10985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11000b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor virtual Linkage getLinkage() const; 11010b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 11035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 11045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 110668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 1107bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// 110868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 1109bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType PointeeType; 11105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 111268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 111768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 111868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 1119bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1120bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1121bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 11275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11290b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor virtual Linkage getLinkage() const; 11300b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 11315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 11325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 11335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11355618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type. 11365618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as 11375618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 11385618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// 11395618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 11405618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 11415618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 11421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 1143898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor PointeeType(Pointee) { 11445618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 11455618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff friend class ASTContext; // ASTContext creates these. 11465618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic: 11471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11485618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 11495618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType getPointeeType() const { return PointeeType; } 11505618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 1151bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1152bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1153bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 11545618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 11555618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Profile(ID, getPointeeType()); 11565618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 11575618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 11585618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 11595618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11610b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor virtual Linkage getLinkage() const; 11620b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 11631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 11641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == BlockPointer; 11655618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 11665618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 11675618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}; 11685618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 11697c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 11705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 117168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 117268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType PointeeType; 117368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 117454e14c4db764c0636160d26c5bbf491637c83a76John McCall /// True if the type was originally spelled with an lvalue sigil. 117554e14c4db764c0636160d26c5bbf491637c83a76John McCall /// This is never true of rvalue references but can also be false 117654e14c4db764c0636160d26c5bbf491637c83a76John McCall /// on lvalue references because of C++0x [dcl.typedef]p9, 117754e14c4db764c0636160d26c5bbf491637c83a76John McCall /// as follows: 117854e14c4db764c0636160d26c5bbf491637c83a76John McCall /// 117954e14c4db764c0636160d26c5bbf491637c83a76John McCall /// typedef int &ref; // lvalue, spelled lvalue 118054e14c4db764c0636160d26c5bbf491637c83a76John McCall /// typedef int &&rvref; // rvalue 118154e14c4db764c0636160d26c5bbf491637c83a76John McCall /// ref &a; // lvalue, inner ref, spelled lvalue 118254e14c4db764c0636160d26c5bbf491637c83a76John McCall /// ref &&a; // lvalue, inner ref 118354e14c4db764c0636160d26c5bbf491637c83a76John McCall /// rvref &a; // lvalue, inner ref, spelled lvalue 118454e14c4db764c0636160d26c5bbf491637c83a76John McCall /// rvref &&a; // rvalue, inner ref 118554e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue; 118654e14c4db764c0636160d26c5bbf491637c83a76John McCall 118754e14c4db764c0636160d26c5bbf491637c83a76John McCall /// True if the inner type is a reference type. This only happens 118854e14c4db764c0636160d26c5bbf491637c83a76John McCall /// in non-canonical forms. 118954e14c4db764c0636160d26c5bbf491637c83a76John McCall bool InnerRef; 119054e14c4db764c0636160d26c5bbf491637c83a76John McCall 11917c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected: 119254e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, 119354e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) : 11947c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Type(tc, CanonicalRef, Referencee->isDependentType()), 119554e14c4db764c0636160d26c5bbf491637c83a76John McCall PointeeType(Referencee), SpelledAsLValue(SpelledAsLValue), 119654e14c4db764c0636160d26c5bbf491637c83a76John McCall InnerRef(Referencee->isReferenceType()) { 11975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 119954e14c4db764c0636160d26c5bbf491637c83a76John McCall bool isSpelledAsLValue() const { return SpelledAsLValue; } 120073dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor bool isInnerRef() const { return InnerRef; } 120173dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor 120254e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType getPointeeTypeAsWritten() const { return PointeeType; } 120354e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType getPointeeType() const { 120454e14c4db764c0636160d26c5bbf491637c83a76John McCall // FIXME: this might strip inner qualifiers; okay? 120554e14c4db764c0636160d26c5bbf491637c83a76John McCall const ReferenceType *T = this; 120654e14c4db764c0636160d26c5bbf491637c83a76John McCall while (T->InnerRef) 120754e14c4db764c0636160d26c5bbf491637c83a76John McCall T = T->PointeeType->getAs<ReferenceType>(); 120854e14c4db764c0636160d26c5bbf491637c83a76John McCall return T->PointeeType; 120954e14c4db764c0636160d26c5bbf491637c83a76John McCall } 121068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 12115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 121254e14c4db764c0636160d26c5bbf491637c83a76John McCall Profile(ID, PointeeType, SpelledAsLValue); 12135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 121454e14c4db764c0636160d26c5bbf491637c83a76John McCall static void Profile(llvm::FoldingSetNodeID &ID, 121554e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType Referencee, 121654e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) { 12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 121854e14c4db764c0636160d26c5bbf491637c83a76John McCall ID.AddBoolean(SpelledAsLValue); 12195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12210b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor virtual Linkage getLinkage() const; 12220b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 12237c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 12247c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference || 12257c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl T->getTypeClass() == RValueReference; 12267c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 12287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 12297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 12317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 12327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType { 123354e14c4db764c0636160d26c5bbf491637c83a76John McCall LValueReferenceType(QualType Referencee, QualType CanonicalRef, 123454e14c4db764c0636160d26c5bbf491637c83a76John McCall bool SpelledAsLValue) : 123554e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue) 123654e14c4db764c0636160d26c5bbf491637c83a76John McCall {} 12377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 12387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 1239bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1240bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1241bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 12427c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 12437c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference; 12447c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 12457c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 12467c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 12477c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12487c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 12497c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 12507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType { 12517c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 125254e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType(RValueReference, Referencee, CanonicalRef, false) { 12537c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 12547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 12557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 1256bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1257bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1258bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 12597c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 12607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == RValueReference; 12617c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 12627c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 1263f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}; 1264f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1265f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 1266f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// 1267f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 1268f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType PointeeType; 1269f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 1270f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 1271f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class; 1272f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1273f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 1274f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Type(MemberPointer, CanonicalPtr, 1275f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Cls->isDependentType() || Pointee->isDependentType()), 1276f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointeeType(Pointee), Class(Cls) { 1277f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1278f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl friend class ASTContext; // ASTContext creates these. 1279f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic: 1280f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1281f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType getPointeeType() const { return PointeeType; } 1282f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1283f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *getClass() const { return Class; } 1284f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1285bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1286bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1287bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1288f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 1289f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Profile(ID, getPointeeType(), getClass()); 1290f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1291f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 1292f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class) { 1293f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 1294f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Class); 1295f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1296f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 12970b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor virtual Linkage getLinkage() const; 12980b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1299f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const Type *T) { 1300f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getTypeClass() == MemberPointer; 1301f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1302f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const MemberPointerType *) { return true; } 13035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 13065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 13072e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 1310898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 1311898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// with a star size (e.g. int X[*]). 1312898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// 'static' is only allowed on function parameters. 13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 13145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 1317fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 1318fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 13191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1320ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 1321c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 1322ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned SizeModifier : 2; 13231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1324c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 1325c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// 'int X[static restrict 4]'. For function parameters only. 1326c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned IndexTypeQuals : 3; 13271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1328fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 1329898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // C++ [temp.dep.type]p1: 1330898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // A type is dependent if it is... 1331898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // - an array type constructed from any dependent type or whose 1332898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // size is specified by a constant expression that is 1333898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // value-dependent, 1334c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 1335c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 1336898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 1337898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 1338898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1339fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 1340fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 1341fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 1342ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 1343ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ArraySizeModifier(SizeModifier); 1344ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 13450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers getIndexTypeQualifiers() const { 13460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qualifiers::fromCVRMask(IndexTypeQuals); 13470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 13480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getIndexTypeCVRQualifiers() const { return IndexTypeQuals; } 13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13500b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor virtual Linkage getLinkage() const; 13510b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1352fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 1353fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 1354c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 1355898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == IncompleteArray || 1356898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == DependentSizedArray; 1357fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1358fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 1359fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 1360fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 13617e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of 13627e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size. For example, the canonical 13637e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 13647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404. 13652e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 1366fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 13671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13680be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 1369c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 13707e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(ConstantArray, et, can, sm, tq), 13717e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Size(size) {} 13727e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected: 13737e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayType(TypeClass tc, QualType et, QualType can, 13747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 13757e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(tc, et, can, sm, tq), Size(size) {} 1376fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 1377fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 1378c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const llvm::APInt &getSize() const { return Size; } 1379bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1380bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1381bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1382fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 13831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, getElementType(), getSize(), 13840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers()); 1385fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1386fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 13870be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 13880be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner unsigned TypeQuals) { 1389fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 1390fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 13910be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 13920be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 1393fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 13947e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 139546a617a792bfab0d9b1e057371ea3b9540802226John McCall return T->getTypeClass() == ConstantArray; 1396fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1397fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 1398fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 1399fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 1400da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 1401da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 1402da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified. 1403c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 14047e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1405c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 14067e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq) 1407c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 1408c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 1409c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 1410bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1411bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1412bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 14131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 14141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == IncompleteArray; 1415c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 1416c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 14171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1418c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 14191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1420c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 14210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Profile(ID, getElementType(), getSizeModifier(), 14220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getIndexTypeCVRQualifiers()); 1423c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 14241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14250be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 14260be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 1427c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 14280be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 14290be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 1430c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 1431c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 1432c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1433da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 1434da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 1435da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 1436da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 1437da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 1438da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean 1439da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type 1440da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically: 1441da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 1442da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) { 1443da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Y[x]; 1444da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ++x; 1445da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Z[x]; 1446da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// } 1447da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 14482e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 14491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// SizeExpr - An assignment expression. VLA's are only permitted within 14501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// a function block. 1451b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek Stmt *SizeExpr; 14527e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 14537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 14547e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1455c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 14567e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 14577e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 14587e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(VariableArray, et, can, sm, tq), 14597e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 14605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 14614b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 14624b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 14635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getSizeExpr() const { 1465b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // We use C-style casts instead of cast<> here because we do not wish 1466b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 1467b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek return (Expr*) SizeExpr; 1468b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek } 14697e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 14707e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 14717e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 14721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1473bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1474bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1475bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 14761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 14771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == VariableArray; 14785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1479fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 14801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 148192866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 14821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14832bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 1484bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 14852bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 14865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1488898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in 1489898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example: 1490cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// 1491cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code 14921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size> 1493898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array { 1494898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// T data[Size]; 1495898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// }; 1496cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode 1497cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// 1498898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is 1499898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will 1500898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 1501898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType { 150204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ASTContext &Context; 15031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1504cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// \brief An assignment expression that will instantiate to the 1505898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// size of the array. 1506cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// 1507cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// The expression itself might be NULL, in which case the array 1508cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor /// type will have its size deduced from an initializer. 1509898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Stmt *SizeExpr; 1510cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor 15117e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 15127e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentSizedArrayType(ASTContext &Context, QualType et, QualType can, 151504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *e, ArraySizeModifier sm, unsigned tq, 15167e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 15177e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), 151804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {} 1519898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class ASTContext; // ASTContext creates these. 1520898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual void Destroy(ASTContext& C); 1521898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1522898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic: 15231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getSizeExpr() const { 1524898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // We use C-style casts instead of cast<> here because we do not wish 1525898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 1526898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return (Expr*) SizeExpr; 1527898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 15287e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 15297e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 15307e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 15311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1532bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1533bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1534bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 15351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 15361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == DependentSizedArray; 1537898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1538898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1540898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class StmtIteratorBase; 15411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1543898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 15441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, Context, getElementType(), 15450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); 1546898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 15471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 15491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType ET, ArraySizeModifier SizeMod, 155004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, Expr *E); 1551898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}; 1552898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1553f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 15549cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example: 15559cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code 15569cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size> 15579cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector { 15589cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 15599cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// } 15609cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode 15612ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { 15622ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor ASTContext &Context; 15639cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr; 15649cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor /// ElementType - The element type of the array. 15659cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType ElementType; 15669cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation loc; 15671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentSizedExtVectorType(ASTContext &Context, QualType ElementType, 15692ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType can, Expr *SizeExpr, SourceLocation loc) 15701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type (DependentSizedExtVector, can, true), 15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 15722ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor loc(loc) {} 15739cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor friend class ASTContext; 15749cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor virtual void Destroy(ASTContext& C); 15759cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 15769cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic: 15772ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 15789cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType getElementType() const { return ElementType; } 15799cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation getAttributeLoc() const { return loc; } 15809cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 1581bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1582bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1583bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 15841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 15851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == DependentSizedExtVector; 15869cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor } 15871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const DependentSizedExtVectorType *) { return true; } 15882ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 15892ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 15902ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor Profile(ID, Context, getElementType(), getSizeExpr()); 15912ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 15921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15932ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 15942ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr); 15959cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor}; 15961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15979cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 159873322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 15991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in 160082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration. 160182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the 160273322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 16035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 160473322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 16055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 16065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 16071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumElements - The number of elements in the vector. 16095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumElements; 16101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 161182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// AltiVec - True if this is for an Altivec vector. 161282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool AltiVec; 161382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson 161482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// Pixel - True if this is for an Altivec vector pixel. 161582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool Pixel; 161682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson 161782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson VectorType(QualType vecType, unsigned nElements, QualType canonType, 161882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool isAltiVec, bool isPixel) : 16191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Type(Vector, canonType, vecType->isDependentType()), 162082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson ElementType(vecType), NumElements(nElements), 162182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson AltiVec(isAltiVec), Pixel(isPixel) {} 16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump VectorType(TypeClass tc, QualType vecType, unsigned nElements, 162382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson QualType canonType, bool isAltiVec, bool isPixel) 16241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 162582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson NumElements(nElements), AltiVec(isAltiVec), Pixel(isPixel) {} 16265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 16275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 16281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 16301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumElements() const { return NumElements; } 16315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1632bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1633bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1634bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 163582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool isAltiVec() const { return AltiVec; } 163682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson 163782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool isPixel() const { return Pixel; } 163882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson 16395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 164082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson Profile(ID, getElementType(), getNumElements(), getTypeClass(), 164182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson AltiVec, Pixel); 16425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 164482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson unsigned NumElements, TypeClass TypeClass, 164582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool isAltiVec, bool isPixel) { 16465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 16475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 164873322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 164982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson ID.AddBoolean(isAltiVec); 165082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson ID.AddBoolean(isPixel); 165173322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 16520b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 16530b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor virtual Linkage getLinkage() const; 16540b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 16551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 16561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 16575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 16595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1661213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using 1662213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1663213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1664fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 1665fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1666213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType { 1667213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 166882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson VectorType(ExtVector, vecType, nElements, canonType, false, false) {} 166973322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 167073322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 167188dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 167288dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 167388dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 167488dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 167588dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 167688dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 167788dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 167888dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1679e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1680353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman static int getNumericAccessorIdx(char c) { 168188dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 1682353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman default: return -1; 1683353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '0': return 0; 1684353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '1': return 1; 1685353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '2': return 2; 1686353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '3': return 3; 1687353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '4': return 4; 1688353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '5': return 5; 1689353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '6': return 6; 1690353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '7': return 7; 1691353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '8': return 8; 1692353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '9': return 9; 1693131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'A': 1694353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'a': return 10; 1695131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'B': 1696353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'b': return 11; 1697131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'C': 1698353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'c': return 12; 1699131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'D': 1700353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'd': return 13; 1701131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'E': 1702353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'e': return 14; 1703131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'F': 1704353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'f': return 15; 170588dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1706e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 17071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1708b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 1709b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1710353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman return getNumericAccessorIdx(c); 1711b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 17121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 171388dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 1714b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 171588dca0464804b8b26ae605f89784c927e8493dddChris Lattner return unsigned(idx-1) < NumElements; 171688dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 1717e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1718bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1719bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1720bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 17211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 17221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ExtVector; 172373322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 1724213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman static bool classof(const ExtVectorType *) { return true; } 172573322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 172673322924127c873c13101b705dd823f5539ffa5fSteve Naroff 17275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 172872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 17295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 17305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 17315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SubClassData - This field is owned by the subclass, put here to pack 17325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tightly with the ivars in Type. 17335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SubClassData : 1; 1734971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 173572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1736971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// other bitfields. 173772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// The qualifiers are part of FunctionProtoType because... 1738971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1739971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 1740971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// cv-qualifier-seq, [...], are part of the function type. 1741971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1742971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned TypeQuals : 3; 17432455636163fdd18581d7fdae816433f886d88213Mike Stump 17442455636163fdd18581d7fdae816433f886d88213Mike Stump /// NoReturn - Indicates if the function type is attribute noreturn. 17452455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned NoReturn : 1; 17461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1747425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola /// RegParm - How many arguments to pass inreg. 1748425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola unsigned RegParm : 3; 1749425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola 1750ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor /// CallConv - The calling convention used by the function. 1751ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor unsigned CallConv : 2; 1752ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor 17535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 17545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 1755264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 1756264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public: 1757264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // This class is used for passing arround the information needed to 1758264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // construct a call. It is not actually used for storage, just for 1759264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // factoring together common arguments. 1760425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // If you add a field (say Foo), other than the obvious places (both, constructors, 1761425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // compile failures), what you need to update is 1762425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * Operetor== 1763425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * getFoo 1764425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * withFoo 1765425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * functionType. Add Foo, getFoo. 1766425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * ASTContext::getFooType 1767425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * ASTContext::mergeFunctionTypes 1768425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * FunctionNoProtoType::Profile 1769425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * FunctionProtoType::Profile 1770425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * TypePrinter::PrintFunctionProto 1771425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * PCH read and write 1772425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // * Codegen 1773425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola 1774264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola class ExtInfo { 1775264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public: 1776264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Constructor with no defaults. Use this when you know that you 1777264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // have all the elements (when reading a PCH file for example). 1778425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola ExtInfo(bool noReturn, unsigned regParm, CallingConv cc) : 1779425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola NoReturn(noReturn), RegParm(regParm), CC(cc) {} 1780264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 1781264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Constructor with all defaults. Use when for example creating a 1782264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // function know to use defaults. 1783425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola ExtInfo() : NoReturn(false), RegParm(0), CC(CC_Default) {} 1784264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 1785264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola bool getNoReturn() const { return NoReturn; } 1786425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola unsigned getRegParm() const { return RegParm; } 1787264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola CallingConv getCC() const { return CC; } 1788264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 1789264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola bool operator==(const ExtInfo &Other) const { 1790264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return getNoReturn() == Other.getNoReturn() && 1791425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola getRegParm() == Other.getRegParm() && 1792264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola getCC() == Other.getCC(); 1793264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 1794264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola bool operator!=(const ExtInfo &Other) const { 1795264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return !(*this == Other); 1796264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 1797264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 1798264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // Note that we don't have setters. That is by design, use 1799264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // the following with methods instead of mutating these objects. 1800264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 1801264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ExtInfo withNoReturn(bool noReturn) const { 1802425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola return ExtInfo(noReturn, getRegParm(), getCC()); 1803425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola } 1804425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola 1805425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola ExtInfo withRegParm(unsigned RegParm) const { 1806425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola return ExtInfo(getNoReturn(), RegParm, getCC()); 1807264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 1808264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 1809264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ExtInfo withCallingConv(CallingConv cc) const { 1810425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola return ExtInfo(getNoReturn(), getRegParm(), cc); 1811264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 1812264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 1813264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola private: 1814264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // True if we have __attribute__((noreturn)) 1815264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola bool NoReturn; 1816425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola // The value passed to __attribute__((regparm(x))) 1817425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola unsigned RegParm; 1818264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // The calling convention as specified via 1819264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola // __attribute__((cdecl|stdcall||fastcall)) 1820264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola CallingConv CC; 1821264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola }; 1822264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola 18235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 1824971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 18252455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned typeQuals, QualType Canonical, bool Dependent, 1826264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola const ExtInfo &Info) 1827898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, Canonical, Dependent), 1828264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola SubClassData(SubclassInfo), TypeQuals(typeQuals), 1829264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola NoReturn(Info.getNoReturn()), 1830425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola RegParm(Info.getRegParm()), CallConv(Info.getCC()), ResultType(res) {} 18315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool getSubClassData() const { return SubClassData; } 1832971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return TypeQuals; } 18335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 1836425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola unsigned getRegParmType() const { return RegParm; } 18372455636163fdd18581d7fdae816433f886d88213Mike Stump bool getNoReturnAttr() const { return NoReturn; } 1838ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor CallingConv getCallConv() const { return (CallingConv)CallConv; } 1839264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ExtInfo getExtInfo() const { 1840425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola return ExtInfo(NoReturn, RegParm, (CallingConv)CallConv); 1841264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } 18425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 184304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall static llvm::StringRef getNameForCallConv(CallingConv CC); 184404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 18455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 18465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 18475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 18485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 18505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 185272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 18535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 185472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 18552455636163fdd18581d7fdae816433f886d88213Mike Stump FunctionNoProtoType(QualType Result, QualType Canonical, 1856264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola const ExtInfo &Info) 18571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 1858264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola /*Dependent=*/false, Info) {} 18595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 18605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 18621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1863bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1864bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1865bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 18665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 1867264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Profile(ID, getResultType(), getExtInfo()); 18685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18692455636163fdd18581d7fdae816433f886d88213Mike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 1870264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola const ExtInfo &Info) { 1871264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ID.AddInteger(Info.getCC()); 1872425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola ID.AddInteger(Info.getRegParm()); 1873264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ID.AddInteger(Info.getNoReturn()); 18745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 18755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18770b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor virtual Linkage getLinkage() const; 18780b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 18795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 18805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 18815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 188272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 18835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 188572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 18865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 1887465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 1888465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical 1889465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type. 189072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 1891898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 1892898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// types within the arguments passed in. 1893898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 1894898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 1895898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (ArgArray[Idx]->isDependentType()) 18964b4218f48fef71a179c5a8287dae281580faf52fNate Begeman return true; 1897898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1898898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1899898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1900898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 190172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 1902465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned typeQuals, bool hasExs, 1903465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExs, const QualType *ExArray, 1904264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola unsigned numExs, QualType Canonical, 1905264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola const ExtInfo &Info) 1906898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 19071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (Result->isDependentType() || 1908264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola hasAnyDependentType(ArgArray, numArgs)), 1909264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Info), 1910465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 1911465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl AnyExceptionSpec(hasAnyExs) { 1912942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner // Fill in the trailing argument array. 1913465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 19145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numArgs; ++i) 19155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ArgInfo[i] = ArgArray[i]; 1916465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // Fill in the exception array. 1917465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *Ex = ArgInfo + numArgs; 1918465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl for (unsigned i = 0; i != numExs; ++i) 1919465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl Ex[i] = ExArray[i]; 19205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1921465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 19225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 1923465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumArgs : 20; 1924465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1925465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 1926465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumExceptions : 10; 1927465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1928465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// HasExceptionSpec - Whether this function has an exception spec at all. 1929465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool HasExceptionSpec : 1; 1930465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1931465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// AnyExceptionSpec - Whether this function has a throw(...) spec. 1932465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool AnyExceptionSpec : 1; 1933465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1934942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 1935942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// holds the argument types. 1936465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1937465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 1938465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// holds the exception types. 1939465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 19405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 19414b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 19425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 19435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 19445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 19455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 1946942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 19475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1948465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1949465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec() const { return HasExceptionSpec; } 1950465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 1951465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 1952465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType getExceptionType(unsigned i) const { 1953465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 1954465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin()[i]; 1955465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 19561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool hasEmptyExceptionSpec() const { 19571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return hasExceptionSpec() && !hasAnyExceptionSpec() && 1958a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson getNumExceptions() == 0; 1959d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson } 1960465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 19615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVariadic() const { return getSubClassData(); } 1962971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 19631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 1965942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 1966942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 1967942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 1968942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1969465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1970465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl typedef const QualType *exception_iterator; 1971465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_begin() const { 1972465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // exceptions begin where arguments end 1973465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return arg_type_end(); 1974465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1975465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_end() const { 1976465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin() + NumExceptions; 1977465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1978465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1979bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1980bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1981bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 19820b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor virtual Linkage getLinkage() const; 19830b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 19845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 19855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 19865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 198772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 1988465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 19895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID); 19905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1991942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 1992465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned TypeQuals, 1993465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec, bool anyExceptionSpec, 19942455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned NumExceptions, exception_iterator Exs, 1995264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola const ExtInfo &ExtInfo); 19965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1999ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped 2000ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g. 2001ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// using typename Base<T>::foo; 2002ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type. 2003ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type { 2004ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *Decl; 2005ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 200619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) 200719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : Type(UnresolvedUsing, QualType(), true), 200819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {} 2009ed97649e9574b9d854fa4d6109c9333ae0993554John McCall friend class ASTContext; // ASTContext creates these. 2010ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic: 2011ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2012ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *getDecl() const { return Decl; } 2013ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2014ed97649e9574b9d854fa4d6109c9333ae0993554John McCall bool isSugared() const { return false; } 2015ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType desugar() const { return QualType(this, 0); } 2016ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2017ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static bool classof(const Type *T) { 2018ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return T->getTypeClass() == UnresolvedUsing; 2019ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2020ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static bool classof(const UnresolvedUsingType *) { return true; } 2021ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2022ed97649e9574b9d854fa4d6109c9333ae0993554John McCall void Profile(llvm::FoldingSetNodeID &ID) { 2023ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Profile(ID, Decl); 2024ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2025ed97649e9574b9d854fa4d6109c9333ae0993554John McCall static void Profile(llvm::FoldingSetNodeID &ID, 2026ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *D) { 2027ed97649e9574b9d854fa4d6109c9333ae0993554John McCall ID.AddPointer(D); 2028ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 2029ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}; 2030ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2031ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 20325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 20335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *Decl; 2034c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 203519c8576b7328f4dc2d07682f5da552875c1912efJohn McCall TypedefType(TypeClass tc, const TypedefDecl *D, QualType can) 203619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : Type(tc, can, can->isDependentType()), 203719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall Decl(const_cast<TypedefDecl*>(D)) { 20385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 20395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 20415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 20421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *getDecl() const { return Decl; } 20441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2045a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 2046fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 2047a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// sum of the type qualifiers, so if you have: 2048a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef const int A; 2049a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef volatile A B; 2050a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// looking through the typedefs for B will give you "const volatile A". 2051a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType LookThroughTypedefs() const; 20521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2053bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2054bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const; 2055bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 205672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 20575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 20585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 20595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 206072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension). 206172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type { 2062d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 20631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2064b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected: 2065dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor TypeOfExprType(Expr *E, QualType can = QualType()); 2066d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 2067d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 2068d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 20691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2070bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2071bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const; 2072bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2073bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2074bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2075bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 207672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 207772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 2078d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 2079d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 2080c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent 20811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types. 2082c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// 2083c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage 2084c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances 2085c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via TypeOfExprType nodes. 20861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType 2087b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor : public TypeOfExprType, public llvm::FoldingSetNode { 2088b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor ASTContext &Context; 20891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2090b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic: 20911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentTypeOfExprType(ASTContext &Context, Expr *E) 2092b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor : TypeOfExprType(E), Context(Context) { } 20931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2094bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2095bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2096bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2097b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2098b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Profile(ID, Context, getUnderlyingExpr()); 2099b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } 21001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2101b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 2102b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Expr *E); 2103b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor}; 21041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2105d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 2106d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 2107d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 21081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypeOfType(QualType T, QualType can) 210972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : Type(TypeOf, can, T->isDependentType()), TOType(T) { 2110d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 2111d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 2112d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 2113d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 2114d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 21151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2116bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2117bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getUnderlyingType(); } 2118bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2119bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2120bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2121bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 212272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 2123d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 2124d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 21255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2126395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x) 2127395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type { 2128395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *E; 21291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2130563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 2131563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 2132563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // from it. 2133563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType UnderlyingType; 21341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21359d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected: 2136563a03b1338d31c2462def43253a722bc885d384Anders Carlsson DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 2137395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson friend class ASTContext; // ASTContext creates these. 2138395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic: 2139395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *getUnderlyingExpr() const { return E; } 2140563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType getUnderlyingType() const { return UnderlyingType; } 2141563a03b1338d31c2462def43253a722bc885d384Anders Carlsson 2142bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2143bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getUnderlyingType(); } 2144bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2145bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2146bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return !isDependentType(); } 2147bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2148395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 2149395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const DecltypeType *) { return true; } 2150395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson}; 21511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2152c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent 2153c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// decltype(expr) types. 2154c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// 2155c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage 2156c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances 2157c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via DecltypeType nodes. 21589d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { 21599d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor ASTContext &Context; 21601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21619d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic: 21629d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeType(ASTContext &Context, Expr *E); 21631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2164bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2165bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2166bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 21679d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 21689d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor Profile(ID, Context, getUnderlyingExpr()); 21699d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } 21701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21719d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 21721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *E); 21739d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor}; 21741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 21760b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// Stores the TagDecl associated with this type. The decl will 21770b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// point to the TagDecl that actually defines the entity (or is a 21780b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// definition in progress), if there is such a definition. The 21790b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// single-bit value will be non-zero when this tag is in the 21800b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// process of being defined. 2181fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor mutable llvm::PointerIntPair<TagDecl *, 1> decl; 21824b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek friend class ASTContext; 21830b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor friend class TagDecl; 21842ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 21852ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected: 218619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall TagType(TypeClass TC, const TagDecl *D, QualType can); 21872ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 21881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 21890b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor TagDecl *getDecl() const { return decl.getPointer(); } 21901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21910b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// @brief Determines whether this type is in the process of being 21921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// defined. 21930b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor bool isBeingDefined() const { return decl.getInt(); } 21940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setBeingDefined(bool Def) const { decl.setInt(Def? 1 : 0); } 21950b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 21960b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor virtual Linkage getLinkage() const; 21970b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 21981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 219972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 220072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor } 22015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 220272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const RecordType *) { return true; } 220372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const EnumType *) { return true; } 22045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 22055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22065edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 22075edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes. 22085edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType { 220949aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected: 221019c8576b7328f4dc2d07682f5da552875c1912efJohn McCall explicit RecordType(const RecordDecl *D) 221119c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { } 221272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 221319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { } 22142ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 22155edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 22161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22175edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordDecl *getDecl() const { 22185edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 22195edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 22201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: This predicate is a helper to QualType/Type. It needs to 22225edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // recursively check all fields for const-ness. If any field is declared 22231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // const, it needs to return false. 22245edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner bool hasConstFields() const { return false; } 22255edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 22265edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 22275edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // the same address space, and return that. 22285edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner unsigned getAddressSpace() const { return 0; } 22291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2230bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2231bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2232bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 22332daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 22342daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 22352daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 22362daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 22375edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const RecordType *) { return true; } 22385edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 22395edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 22405edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 22415edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums. 22425edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType { 224319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall explicit EnumType(const EnumDecl *D) 224419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { } 22452ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 22465edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 22471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22485edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumDecl *getDecl() const { 22495edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 22505edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 22511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2252bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2253bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2254bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 22552daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 22562daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 22572daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 22582daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 22595edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const EnumType *) { return true; } 22605edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 22615edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 22627da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// ElaboratedType - A non-canonical type used to represents uses of 22637da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// elaborated type specifiers in C++. For example: 22647da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// 22657da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// void foo(union MyUnion); 22667da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// ^^^^^^^^^^^^^ 22677da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// 22687da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// At the moment, for efficiency we do not create elaborated types in 22697da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// C, since outside of typedefs all references to structs would 22707da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// necessarily be elaborated. 22717da2431c23ef1ee8acb114e39692246e1801afc2John McCallclass ElaboratedType : public Type, public llvm::FoldingSetNode { 22727da2431c23ef1ee8acb114e39692246e1801afc2John McCallpublic: 22737da2431c23ef1ee8acb114e39692246e1801afc2John McCall enum TagKind { 22747da2431c23ef1ee8acb114e39692246e1801afc2John McCall TK_struct, 22757da2431c23ef1ee8acb114e39692246e1801afc2John McCall TK_union, 22767da2431c23ef1ee8acb114e39692246e1801afc2John McCall TK_class, 22777da2431c23ef1ee8acb114e39692246e1801afc2John McCall TK_enum 22787da2431c23ef1ee8acb114e39692246e1801afc2John McCall }; 22797da2431c23ef1ee8acb114e39692246e1801afc2John McCall 22807da2431c23ef1ee8acb114e39692246e1801afc2John McCallprivate: 22817da2431c23ef1ee8acb114e39692246e1801afc2John McCall /// The tag that was used in this elaborated type specifier. 22827da2431c23ef1ee8acb114e39692246e1801afc2John McCall TagKind Tag; 22837da2431c23ef1ee8acb114e39692246e1801afc2John McCall 22847da2431c23ef1ee8acb114e39692246e1801afc2John McCall /// The underlying type. 22857da2431c23ef1ee8acb114e39692246e1801afc2John McCall QualType UnderlyingType; 22867da2431c23ef1ee8acb114e39692246e1801afc2John McCall 22877da2431c23ef1ee8acb114e39692246e1801afc2John McCall explicit ElaboratedType(QualType Ty, TagKind Tag, QualType Canon) 22887da2431c23ef1ee8acb114e39692246e1801afc2John McCall : Type(Elaborated, Canon, Canon->isDependentType()), 22897da2431c23ef1ee8acb114e39692246e1801afc2John McCall Tag(Tag), UnderlyingType(Ty) { } 22907da2431c23ef1ee8acb114e39692246e1801afc2John McCall friend class ASTContext; // ASTContext creates these. 22917da2431c23ef1ee8acb114e39692246e1801afc2John McCall 22927da2431c23ef1ee8acb114e39692246e1801afc2John McCallpublic: 22937da2431c23ef1ee8acb114e39692246e1801afc2John McCall TagKind getTagKind() const { return Tag; } 22947da2431c23ef1ee8acb114e39692246e1801afc2John McCall QualType getUnderlyingType() const { return UnderlyingType; } 22957da2431c23ef1ee8acb114e39692246e1801afc2John McCall 2296bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2297bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getUnderlyingType(); } 2298bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2299bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2300bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2301bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 23027da2431c23ef1ee8acb114e39692246e1801afc2John McCall static const char *getNameForTagKind(TagKind Kind) { 23037da2431c23ef1ee8acb114e39692246e1801afc2John McCall switch (Kind) { 23047da2431c23ef1ee8acb114e39692246e1801afc2John McCall default: assert(0 && "Unknown TagKind!"); 23057da2431c23ef1ee8acb114e39692246e1801afc2John McCall case TK_struct: return "struct"; 23067da2431c23ef1ee8acb114e39692246e1801afc2John McCall case TK_union: return "union"; 23077da2431c23ef1ee8acb114e39692246e1801afc2John McCall case TK_class: return "class"; 23087da2431c23ef1ee8acb114e39692246e1801afc2John McCall case TK_enum: return "enum"; 23097da2431c23ef1ee8acb114e39692246e1801afc2John McCall } 23107da2431c23ef1ee8acb114e39692246e1801afc2John McCall } 23117da2431c23ef1ee8acb114e39692246e1801afc2John McCall 23127da2431c23ef1ee8acb114e39692246e1801afc2John McCall void Profile(llvm::FoldingSetNodeID &ID) { 23137da2431c23ef1ee8acb114e39692246e1801afc2John McCall Profile(ID, getUnderlyingType(), getTagKind()); 23147da2431c23ef1ee8acb114e39692246e1801afc2John McCall } 23157da2431c23ef1ee8acb114e39692246e1801afc2John McCall static void Profile(llvm::FoldingSetNodeID &ID, QualType T, TagKind Tag) { 23167da2431c23ef1ee8acb114e39692246e1801afc2John McCall ID.AddPointer(T.getAsOpaquePtr()); 23177da2431c23ef1ee8acb114e39692246e1801afc2John McCall ID.AddInteger(Tag); 23187da2431c23ef1ee8acb114e39692246e1801afc2John McCall } 23197da2431c23ef1ee8acb114e39692246e1801afc2John McCall 23207da2431c23ef1ee8acb114e39692246e1801afc2John McCall static bool classof(const ElaboratedType*) { return true; } 23217da2431c23ef1ee8acb114e39692246e1801afc2John McCall static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; } 23227da2431c23ef1ee8acb114e39692246e1801afc2John McCall}; 23237da2431c23ef1ee8acb114e39692246e1801afc2John McCall 2324fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 232576e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned Depth : 15; 2326fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned Index : 16; 232776e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned ParameterPack : 1; 2328fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *Name; 232972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 23301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 23311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Canon) 2332fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 233376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(N) { } 233472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 23351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP) 2336fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 233776e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(0) { } 233872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2339fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor friend class ASTContext; // ASTContext creates these 234072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2341fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic: 2342fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getDepth() const { return Depth; } 2343fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getIndex() const { return Index; } 234476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson bool isParameterPack() const { return ParameterPack; } 2345fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *getName() const { return Name; } 23461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2347bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2348bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2349bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2350fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 235176e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Profile(ID, Depth, Index, ParameterPack, Name); 2352fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 2353fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 23541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 23551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned Index, bool ParameterPack, 235676e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson IdentifierInfo *Name) { 2357fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Depth); 2358fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Index); 235976e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson ID.AddBoolean(ParameterPack); 2360fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddPointer(Name); 2361fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 2362fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 23631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 23641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == TemplateTypeParm; 236572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor } 236672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 236772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}; 2368fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 236949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template 237049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter. 237149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// 237249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have 237349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these. They are used solely to record that a 237449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter; 237549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical. 237649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode { 237749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall // The original type parameter. 237849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *Replaced; 237949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 238049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) 238149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType()), 238249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Replaced(Param) { } 238349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 238449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall friend class ASTContext; 238549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 238649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic: 238749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall IdentifierInfo *getName() const { return Replaced->getName(); } 238849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 238949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// Gets the template parameter that was substituted for. 239049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *getReplacedParameter() const { 239149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return Replaced; 239249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 239349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 239449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// Gets the type that was substituted for the template 239549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall /// parameter. 239649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType getReplacementType() const { 239749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return getCanonicalTypeInternal(); 239849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 239949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 240049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall bool isSugared() const { return true; } 240149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType desugar() const { return getReplacementType(); } 240249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 240349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall void Profile(llvm::FoldingSetNodeID &ID) { 240449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Profile(ID, getReplacedParameter(), getReplacementType()); 240549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 240649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, 240749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const TemplateTypeParmType *Replaced, 240849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall QualType Replacement) { 240949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall ID.AddPointer(Replaced); 241049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall ID.AddPointer(Replacement.getAsOpaquePtr()); 241149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 241249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 241349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static bool classof(const Type *T) { 241449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return T->getTypeClass() == SubstTemplateTypeParm; 241549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 241649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall static bool classof(const SubstTemplateTypeParmType *T) { return true; } 241749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}; 241849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 24197532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written 24207532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code. 242155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// 24227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a 24237532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 24247532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 24257532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the 24267532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a 242755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to 24281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// a tag type for the instantiation 242955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 24307532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// 24317532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name 24327532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always 24337532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent. 24341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType 243555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor : public Type, public llvm::FoldingSetNode { 243655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 2437828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor // FIXME: Currently needed for profiling expressions; can we avoid this? 2438828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor ASTContext &Context; 24391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2440828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor /// \brief The name of the template being specialized. 24417532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Template; 244255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 244340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief - The number of template arguments named in this class 244440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// template specialization. 244555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned NumArgs; 244655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 2447828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor TemplateSpecializationType(ASTContext &Context, 2448828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor TemplateName T, 24497532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 24507532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon); 245155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 24525908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor virtual void Destroy(ASTContext& C); 24535908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor 245455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor friend class ASTContext; // ASTContext creates these 245555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 245655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic: 245740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Determine whether any of the given template arguments are 245840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// dependent. 245940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 24601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned NumArgs); 246140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 2462833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args, 2463833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned NumArgs); 2464833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2465d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &); 2466d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 2467df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 2468df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// enclosing the template arguments. 2469df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 2470d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned NumArgs, 2471d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor const PrintingPolicy &Policy); 2472df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor 2473833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args, 2474833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned NumArgs, 2475833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const PrintingPolicy &Policy); 2476833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2477d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &, 2478d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const PrintingPolicy &Policy); 2479d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 248040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor typedef const TemplateArgument * iterator; 248140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 248240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator begin() const { return getArgs(); } 248340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator end() const; 248440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 24857532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 24867532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName getTemplateName() const { return Template; } 248755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 248840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the template arguments. 24891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *getArgs() const { 249040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 249140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 249240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 249340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the number of template arguments. 249455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 249555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 249655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \brief Retrieve a specific template argument as a type. 249755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \precondition @c isArgType(Arg) 249840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument &getArg(unsigned Idx) const; 249955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 2500bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return !isDependentType(); } 2501bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getCanonicalTypeInternal(); } 2502bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 250355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2504828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Profile(ID, Template, getArgs(), NumArgs, Context); 250555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 250655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 25077532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 2508828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor const TemplateArgument *Args, unsigned NumArgs, 2509828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor ASTContext &Context); 251055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 25111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 25121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == TemplateSpecialization; 251355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 25147532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 251555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}; 251655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 25173cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// \brief The injected class name of a C++ class template. Used to 25183cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// record that a type was spelled with a bare identifier rather than 25193cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// as a template-id; the equivalent for non-templated classes is just 25203cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// RecordType. 25213cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// 25223cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// For consistency, template instantiation turns these into RecordTypes. 25233cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// 25243cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// The desugared form is always a unqualified TemplateSpecializationType. 25253cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// The canonical form is always either a TemplateSpecializationType 25263cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// (when dependent) or a RecordType (otherwise). 25273cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameType : public Type { 25283cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall CXXRecordDecl *Decl; 25293cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 25303cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall QualType UnderlyingType; 25313cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 25323cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall friend class ASTContext; // ASTContext creates these. 25333cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall InjectedClassNameType(CXXRecordDecl *D, QualType TST, QualType Canon) 25343cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall : Type(InjectedClassName, Canon, Canon->isDependentType()), 25353cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Decl(D), UnderlyingType(TST) { 25363cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(isa<TemplateSpecializationType>(TST)); 25373cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(!TST.hasQualifiers()); 25383cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(TST->getCanonicalTypeInternal() == Canon); 25393cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 25403cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 25413cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallpublic: 25423cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall QualType getUnderlyingType() const { return UnderlyingType; } 25433cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall const TemplateSpecializationType *getUnderlyingTST() const { 25443cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return cast<TemplateSpecializationType>(UnderlyingType.getTypePtr()); 25453cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 25463cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 25473cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall CXXRecordDecl *getDecl() const { return Decl; } 25483cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 25493cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall bool isSugared() const { return true; } 25503cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall QualType desugar() const { return UnderlyingType; } 25513cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 25523cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall static bool classof(const Type *T) { 25533cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return T->getTypeClass() == InjectedClassName; 25543cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 25553cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall static bool classof(const InjectedClassNameType *T) { return true; } 25563cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}; 25573cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 25584a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or 25594a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// introduces an elaborated-type-specifier. 25604a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregorenum ElaboratedTypeKeyword { 25614a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief No keyword precedes the qualified type name. 25624a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ETK_None, 25634a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "typename" keyword precedes the qualified type name, e.g., 25644a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \c typename T::type. 25654a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ETK_Typename, 25664a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "class" keyword introduces the elaborated-type-specifier. 25674a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ETK_Class, 25684a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "struct" keyword introduces the elaborated-type-specifier. 25694a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ETK_Struct, 25704a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "union" keyword introduces the elaborated-type-specifier. 25714a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ETK_Union, 25724a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The "enum" keyword introduces the elaborated-type-specifier. 25734a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ETK_Enum 25744a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor}; 25754a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor 2576e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// \brief Represents a type that was referred to via a qualified 2577e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// name, e.g., N::M::type. 2578e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// 2579e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the 2580119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// source code, including any nested-name-specifiers. The type itself 2581119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// is always "sugar", used to express what was written in the source 2582119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// code but containing no additional semantic information. 2583e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode { 2584ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested name specifier containing the qualifier. 2585ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *NNS; 2586e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2587e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief The type that this qualified name refers to. 2588e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType; 2589e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2590ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 2591ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType CanonType) 2592ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor : Type(QualifiedName, CanonType, NamedType->isDependentType()), 2593ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NNS(NNS), NamedType(NamedType) { } 2594e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2595e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor friend class ASTContext; // ASTContext creates these 2596e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2597e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic: 2598ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the qualification on this type. 2599ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2600e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2601e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 2602e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType getNamedType() const { return NamedType; } 2603e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2604bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2605bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getNamedType(); } 2606bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2607bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2608bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2609bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2610e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2611ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor Profile(ID, NNS, NamedType); 2612e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 2613e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2614ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 2615ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType NamedType) { 2616ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor ID.AddPointer(NNS); 2617ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NamedType.Profile(ID); 2618ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor } 2619e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 26201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 26211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == QualifiedName; 2622e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 2623e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const QualifiedNameType *T) { return true; } 2624e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor}; 2625e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 26264a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief Represents a qualified type name for which the type name is 26274a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent. 2628d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// 26294a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// DependentNameType represents a class of dependent types that involve a 26304a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent) 26314a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a 26324a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// typename-specifier), "class", "struct", "union", or "enum" (for a 26334a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we 26344a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier). 26354714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregorclass DependentNameType : public Type, public llvm::FoldingSetNode { 26364a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief The keyword used to elaborate this type. 26374a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ElaboratedTypeKeyword Keyword; 26384a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor 2639d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The nested name specifier containing the qualifier. 2640d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *NNS; 2641d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 26421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump typedef llvm::PointerUnion<const IdentifierInfo *, 26431734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *> NameType; 26441734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 2645d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The type that this typename specifier refers to. 26461734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name; 2647d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 26484a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 26494a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor const IdentifierInfo *Name, QualType CanonType) 26504a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor : Type(DependentName, CanonType, true), 26514a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor Keyword(Keyword), NNS(NNS), Name(Name) { 26521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(NNS->isDependent() && 26534714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor "DependentNameType requires a dependent nested-name-specifier"); 2654d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2655d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 26564a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 26574a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor const TemplateSpecializationType *Ty, QualType CanonType) 26584a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor : Type(DependentName, CanonType, true), 26594a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor Keyword(Keyword), NNS(NNS), Name(Ty) { 26601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(NNS->isDependent() && 26614714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor "DependentNameType requires a dependent nested-name-specifier"); 26621734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 26631734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 2664d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor friend class ASTContext; // ASTContext creates these 2665d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2666d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic: 26674a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor /// \brief Retrieve the keyword used to elaborate this type. 26684a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ElaboratedTypeKeyword getKeyword() const { return Keyword; } 26694a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor 2670d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief Retrieve the qualification on this type. 2671d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2672d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 26731734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 26741734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// identifier. 26751734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// 26761734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 26771734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// form of the original typename was terminated by an identifier, 26781734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// e.g., "typename T::type". 26791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo *getIdentifier() const { 26801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Name.dyn_cast<const IdentifierInfo *>(); 26811734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 26821734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 26831734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as a 26841734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// type specialization. 26851734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *getTemplateId() const { 26861734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const TemplateSpecializationType *>(); 26871734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 2688d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2689bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2690bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2691bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2692d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 26934a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor Profile(ID, Keyword, NNS, Name); 2694d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2695d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 26964a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 26974a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor NestedNameSpecifier *NNS, NameType Name) { 26984a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ID.AddInteger(Keyword); 2699d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor ID.AddPointer(NNS); 27001734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor ID.AddPointer(Name.getOpaqueValue()); 2701d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2702d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 27031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 27044714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor return T->getTypeClass() == DependentName; 2705d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 27064714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor static bool classof(const DependentNameType *T) { return true; } 2707d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor}; 2708d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2709fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 2710fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// object oriented design. They basically correspond to C++ classes. There 2711fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and 2712fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// qualified interfaces, which are qualified with a protocol list like 2713c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff/// "NSString<NSCopyable, NSAmazing>". 2714c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffclass ObjCInterfaceType : public Type, public llvm::FoldingSetNode { 2715a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *Decl; 2716c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 2717fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor /// \brief The number of protocols stored after the ObjCInterfaceType node. 2718fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor /// The list of protocols is sorted on protocol name. No protocol is enterred 2719fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor /// more than once. 272071842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek unsigned NumProtocols; 2721c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 2722fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor ObjCInterfaceType(QualType Canonical, ObjCInterfaceDecl *D, 272371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek ObjCProtocolDecl **Protos, unsigned NumP); 27243536b443bc50d58a79f14fca9b6842541a434854Steve Naroff friend class ASTContext; // ASTContext creates these. 27253536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 272671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek void Destroy(ASTContext& C); 272771842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek 2728a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 27291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2730c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 2731c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// interface type, or 0 if there are none. 273271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek unsigned getNumProtocols() const { return NumProtocols; } 273314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 273473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor /// \brief Retrieve the Ith protocol. 273573dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor ObjCProtocolDecl *getProtocol(unsigned I) const { 273673dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor assert(I < getNumProtocols() && "Out-of-range protocol access"); 273773dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor return qual_begin()[I]; 273873dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor } 273973dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor 2740fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// qual_iterator and friends: this provides access to the (potentially empty) 2741c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// list of protocols qualifying this interface. 274271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek typedef ObjCProtocolDecl* const * qual_iterator; 274371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek qual_iterator qual_begin() const { 2744fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor return reinterpret_cast<qual_iterator>(this + 1); 274571842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek } 274671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek qual_iterator qual_end() const { 2747fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor return qual_begin() + NumProtocols; 274871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek } 274971842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek bool qual_empty() const { return NumProtocols == 0; } 27501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2751bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2752bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2753bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2754c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 27551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, 2756c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff const ObjCInterfaceDecl *Decl, 2757fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor ObjCProtocolDecl * const *protocols, 2758fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor unsigned NumProtocols); 27591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27600b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor virtual Linkage getLinkage() const; 27610b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 27621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 27631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ObjCInterface; 27643536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 2765a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 27663536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 27673536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 276814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// ObjCObjectPointerType - Used to represent 'id', 'Interface *', 'id <p>', 276914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// and 'Interface <p> *'. 277014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// 277114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// Duplicate protocols are removed and protocol list is canonicalized to be in 277214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// alphabetical order. 277314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 2774f6265efe7e35fb0fba315da6391368aeee1e57c9Steve Naroff QualType PointeeType; // A builtin or interface type. 27751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2776fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor /// \brief The number of protocols stored after the ObjCObjectPointerType 2777fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor /// node. 2778fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor /// 2779fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor /// The list of protocols is sorted on protocol name. No protocol is enterred 2780fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor /// more than once. 278171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek unsigned NumProtocols; 278214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 2783fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor ObjCObjectPointerType(QualType Canonical, QualType T, 278471842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek ObjCProtocolDecl **Protos, unsigned NumP); 278514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff friend class ASTContext; // ASTContext creates these. 27861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 278714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic: 278871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek void Destroy(ASTContext& C); 278971842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek 27908f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // Get the pointee type. Pointee will either be: 27918f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // - a built-in type (for 'id' and 'Class'). 27928f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // - an interface type (for user-defined types). 27938f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // - a TypedefType whose canonical type is an interface (as in 'T' below). 27948f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // For example: typedef NSObject T; T *var; 279514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const { return PointeeType; } 279614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 27971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const ObjCInterfaceType *getInterfaceType() const { 2798183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall return PointeeType->getAs<ObjCInterfaceType>(); 279914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 2800de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// getInterfaceDecl - returns an interface decl for user-defined types. 280114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCInterfaceDecl *getInterfaceDecl() const { 2802de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return getInterfaceType() ? getInterfaceType()->getDecl() : 0; 280314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 2804de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCIdType - true for "id". 280514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const { 28061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && 280771842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek !NumProtocols; 280814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 2809de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCClassType - true for "Class". 281014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const { 28111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) && 281271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek !NumProtocols; 2813de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 28148d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian 2815de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCQualifiedIdType - true for "id <p>". 28161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isObjCQualifiedIdType() const { 28171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && 281871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek NumProtocols; 2819de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 2820de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCQualifiedClassType - true for "Class <p>". 2821470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const { 28221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) && 282371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek NumProtocols; 282414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 282514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// qual_iterator and friends: this provides access to the (potentially empty) 282614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// list of protocols qualifying this interface. 282771842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek typedef ObjCProtocolDecl* const * qual_iterator; 282814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 282971842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek qual_iterator qual_begin() const { 2830fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor return reinterpret_cast<qual_iterator> (this + 1); 283171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek } 283271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek qual_iterator qual_end() const { 2833fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor return qual_begin() + NumProtocols; 283471842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek } 283571842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek bool qual_empty() const { return NumProtocols == 0; } 283614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 283714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 283814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// interface type, or 0 if there are none. 283971842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek unsigned getNumProtocols() const { return NumProtocols; } 284014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 284173dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor /// \brief Retrieve the Ith protocol. 284273dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor ObjCProtocolDecl *getProtocol(unsigned I) const { 284373dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor assert(I < getNumProtocols() && "Out-of-range protocol access"); 284473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor return qual_begin()[I]; 284573dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor } 284673dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor 2847bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2848bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2849bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 28500b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor virtual Linkage getLinkage() const; 28510b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 285214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff void Profile(llvm::FoldingSetNodeID &ID); 285314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType T, 2854fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor ObjCProtocolDecl *const *protocols, 2855fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor unsigned NumProtocols); 28561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 28571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ObjCObjectPointer; 285814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 285914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 286014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}; 28611bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 28620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers. 28630953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers { 28640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ASTContext *Context; 28650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 28660953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 28670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector(Qualifiers Qs = Qualifiers()) 28680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Qualifiers(Qs), Context(0) {} 28690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector(ASTContext &Context, Qualifiers Qs = Qualifiers()) 28700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Qualifiers(Qs), Context(&Context) {} 28710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 28720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setContext(ASTContext &C) { Context = &C; } 28730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 28740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Collect any qualifiers on the given type and return an 28750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// unqualified type. 28760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *strip(QualType QT) { 2877a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor addFastQualifiers(QT.getLocalFastQualifiers()); 2878a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (QT.hasLocalNonFastQualifiers()) { 28790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = QT.getExtQualsUnsafe(); 28800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Context = &EQ->getContext(); 28810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addQualifiers(EQ->getQualifiers()); 28820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getBaseType(); 28830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 28840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QT.getTypePtrUnsafe(); 28850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 28860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 28870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Apply the collected qualifiers to the given type. 28880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType apply(QualType QT) const; 28890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 28900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Apply the collected qualifiers to the given type. 28910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType apply(const Type* T) const; 28920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 28930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 28940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 28950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2896611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 28975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2898467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const { 2899467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall const Type *T = getTypePtr(); 2900a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalQualifiers()) 2901467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall return T->isCanonicalUnqualified() && !isa<ArrayType>(T); 2902467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall return T->isCanonicalUnqualified(); 2903467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall} 2904467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall 290554e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const { 2906a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalQualifiers()) return false; 290754e14c4db764c0636160d26c5bbf491637c83a76John McCall const Type *T = getTypePtr(); 290854e14c4db764c0636160d26c5bbf491637c83a76John McCall return T->isCanonicalUnqualified() && 290954e14c4db764c0636160d26c5bbf491637c83a76John McCall !isa<FunctionType>(T) && !isa<ArrayType>(T); 291054e14c4db764c0636160d26c5bbf491637c83a76John McCall} 291154e14c4db764c0636160d26c5bbf491637c83a76John McCall 2912fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const { 2913fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return isLocalConstQualified() || 2914fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalConstQualified(); 2915fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 2916fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 2917fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const { 2918fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return isLocalRestrictQualified() || 2919fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalRestrictQualified(); 2920fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 2921fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 2922fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 2923fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const { 2924fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return isLocalVolatileQualified() || 2925fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalVolatileQualified(); 2926fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 2927fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 2928fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const { 2929fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return hasLocalQualifiers() || 2930fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers(); 2931fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 2932fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 2933fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline Qualifiers QualType::getQualifiers() const { 2934fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor Qualifiers Quals = getLocalQualifiers(); 2935fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor Quals.addQualifiers( 2936fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor getTypePtr()->getCanonicalTypeInternal().getLocalQualifiers()); 2937fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return Quals; 2938fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 2939fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 2940fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline unsigned QualType::getCVRQualifiers() const { 2941fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return getLocalCVRQualifiers() | 2942fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor getTypePtr()->getCanonicalTypeInternal().getLocalCVRQualifiers(); 2943fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 2944e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth 2945e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// getCVRQualifiersThroughArrayTypes - If there are CVR qualifiers for this 2946e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// type, returns them. Otherwise, if this is an array type, recurses 2947e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// on the element type until some qualifiers have been found or a non-array 2948e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// type reached. 2949e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruthinline unsigned QualType::getCVRQualifiersThroughArrayTypes() const { 2950e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth if (unsigned Quals = getCVRQualifiers()) 2951e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth return Quals; 2952e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth QualType CT = getTypePtr()->getCanonicalTypeInternal(); 2953e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2954e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth return AT->getElementType().getCVRQualifiersThroughArrayTypes(); 2955e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth return 0; 2956e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth} 2957e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth 29580953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeConst() { 29590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeFastQualifiers(Qualifiers::Const); 29600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 29610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 29620953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeRestrict() { 29630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeFastQualifiers(Qualifiers::Restrict); 29640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 29650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 29660953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeVolatile() { 29670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qc; 29680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *Ty = Qc.strip(*this); 29690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Qc.hasVolatile()) { 29700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qc.removeVolatile(); 29710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall *this = Qc.apply(Ty); 29720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 29730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 29740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 29750953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeCVRQualifiers(unsigned Mask) { 29766b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits"); 29770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 29780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Fast path: we don't need to touch the slow qualifiers. 29790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!(Mask & ~Qualifiers::FastMask)) { 29800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeFastQualifiers(Mask); 29810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return; 29820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 29830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 29840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qc; 29850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *Ty = Qc.strip(*this); 29860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qc.removeCVRQualifiers(Mask); 29870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall *this = Qc.apply(Ty); 2988ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 2989ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 2990ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 2991ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 2992a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalNonFastQualifiers()) { 29930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = getExtQualsUnsafe(); 29940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (EQ->hasAddressSpace()) 29950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getAddressSpace(); 29960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 29970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 29984243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 2999a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (CT.hasLocalNonFastQualifiers()) { 30000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = CT.getExtQualsUnsafe(); 30010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (EQ->hasAddressSpace()) 30020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getAddressSpace(); 30030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 30040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 30054243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 3006c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT->getElementType().getAddressSpace(); 30074243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 30088e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman return RT->getAddressSpace(); 3009ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return 0; 3010ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 3011611c1fff195d32df97706e0920c92468b2509900Chris Lattner 3012d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 30130953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const { 3014a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (hasLocalNonFastQualifiers()) { 30150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = getExtQualsUnsafe(); 30160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (EQ->hasObjCGCAttr()) 30170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getObjCGCAttr(); 30180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 30190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3020d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 3021a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (CT.hasLocalNonFastQualifiers()) { 30220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = CT.getExtQualsUnsafe(); 30230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (EQ->hasObjCGCAttr()) 30240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getObjCGCAttr(); 30250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 30260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3027d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 3028d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return AT->getElementType().getObjCGCAttr(); 3029183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *PT = CT->getAs<ObjCObjectPointerType>()) 30301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return PT->getPointeeType().getObjCGCAttr(); 3031ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian // We most look at all pointer types, not just pointer to interface types. 3032ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian if (const PointerType *PT = CT->getAs<PointerType>()) 30331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return PT->getPointeeType().getObjCGCAttr(); 30340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qualifiers::GCNone; 3035d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 30362455636163fdd18581d7fdae816433f886d88213Mike Stump 3037264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { 3038264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola if (const PointerType *PT = t.getAs<PointerType>()) { 3039183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>()) 3040264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FT->getExtInfo(); 3041264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola } else if (const FunctionType *FT = t.getAs<FunctionType>()) 3042264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FT->getExtInfo(); 30432455636163fdd18581d7fdae816433f886d88213Mike Stump 3044264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return FunctionType::ExtInfo(); 30452455636163fdd18581d7fdae816433f886d88213Mike Stump} 30461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3047264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { 3048264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola return getFunctionExtInfo(*t); 3049ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor} 3050ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor 3051e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 3052e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 3053e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and 3054e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile 3055e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int". 3056e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 30570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // FIXME: work on arbitrary qualifiers 3058e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes(); 3059e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes(); 3060ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 3061ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 3062e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 3063e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 3064e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 3065e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 3066e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile 3067e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 3068e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int". 3069e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 30700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // FIXME: work on arbitrary qualifiers 3071e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes(); 3072e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes(); 3073ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 3074ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 3075e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 3076e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 3077e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 3078e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 3079e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const 3080e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 3081e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6: 3082e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 3083e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 3084e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 3085e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// analysis, the expression designates the object or function 3086e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 3087e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const { 30886217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 3089e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return RefType->getPointeeType(); 3090e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor else 3091e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return *this; 3092e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 3093e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 30942b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 30956217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 3096183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall return PT->getPointeeType()->getAs<ObjCInterfaceType>(); 30972b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return 0; 30982b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner} 30991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3100611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 3101a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<FunctionType>(CanonicalType); 3102611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 3103611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 3104a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<PointerType>(CanonicalType); 3105611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 310658f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const { 310758f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff return isPointerType() || isObjCObjectPointerType(); 310858f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff} 31095618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const { 3110a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<BlockPointerType>(CanonicalType); 31115618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 3112bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const { 3113a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ReferenceType>(CanonicalType); 3114bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 31157c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const { 3116a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<LValueReferenceType>(CanonicalType); 31177c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 31187c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const { 3119a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<RValueReferenceType>(CanonicalType); 31207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 3121498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 31226217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType* T = getAs<PointerType>()) 3123498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 3124498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 3125498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 3126498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 3127f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const { 3128a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<MemberPointerType>(CanonicalType); 3129f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 3130f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 31316217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const MemberPointerType* T = getAs<MemberPointerType>()) 3132f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getPointeeType()->isFunctionType(); 3133f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl else 3134f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return false; 3135f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 3136611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 3137a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ArrayType>(CanonicalType); 3138611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 3139c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const { 3140a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ConstantArrayType>(CanonicalType); 3141c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 3142c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const { 3143a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<IncompleteArrayType>(CanonicalType); 3144c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 3145c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const { 3146a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<VariableArrayType>(CanonicalType); 3147c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 3148898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const { 3149a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType); 3150898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 3151611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 3152a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<RecordType>(CanonicalType); 3153611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 3154f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const { 3155a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ComplexType>(CanonicalType); 3156f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner} 3157611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 3158a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<VectorType>(CanonicalType); 3159611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 3160213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const { 3161a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ExtVectorType>(CanonicalType); 3162611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 3163d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const { 3164a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ObjCObjectPointerType>(CanonicalType); 3165d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 3166a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCInterfaceType() const { 3167a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<ObjCInterfaceType>(CanonicalType); 3168368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 3169a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 3170183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3171d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT->isObjCQualifiedIdType(); 3172d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return false; 3173d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 3174470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const { 3175183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3176470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return OPT->isObjCQualifiedClassType(); 3177470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return false; 3178470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff} 317914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const { 3180183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 318114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCIdType(); 318214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 318314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 318414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const { 3185183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 318614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCClassType(); 318714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 318814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 318913dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const { 31908d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian if (const PointerType *OPT = getAs<PointerType>()) 31918d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); 319213dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian return false; 319313dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian} 3194de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const { 319513dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian return isObjCIdType() || isObjCClassType() || isObjCSelType(); 3196de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff} 319772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const { 3198a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType); 319972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor} 320072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 3201e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 3202183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 3203e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 3204e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return true; 3205e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return false; 3206e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar} 3207e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 3208063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define 3209063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator. 3210063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const { 3211063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 3212904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor} 3213904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 32148958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 32158958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 32161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isObjCInterfaceType() || isObjCObjectPointerType() || 32176e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl isObjCQualifiedInterfaceType() || isNullPtrType()); 32188958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar} 32198958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 3220820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 32211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return (isObjCInterfaceType() || isObjCObjectPointerType() || 3222820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian isObjCQualifiedInterfaceType()); 3223820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian} 3224820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 322522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 322622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<. 322722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 322822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner QualType T) { 322922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 323022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner Diagnostic::ak_qualtype); 323122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner return DB; 323222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner} 32331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 323447c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// Insertion operator for partial diagnostics. This allows sending QualType's 323547c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// into a diagnostic with <<. 323647c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruthinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, 323747c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth QualType T) { 323847c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 323947c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth Diagnostic::ak_qualtype); 324047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth return PD; 324147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth} 324247c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth 324389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does 324489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type. 324589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T, 324689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor bool isArrayType = (llvm::is_same<T, ArrayType>::value || 324789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor llvm::is_base_of<ArrayType, T>::value)> 324889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { }; 324989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor 325089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T> 325189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>; 325289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor 32531a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'. 32541a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const { 325589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor ArrayType_cannot_be_used_with_getAs<T> at; 325689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor (void)at; 325789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor 32581a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If this is directly a T type, return it. 32591a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek if (const T *Ty = dyn_cast<T>(this)) 32601a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return Ty; 32611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32621a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If the canonical form of this type isn't the right kind, reject it. 32630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<T>(CanonicalType)) 32641a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return 0; 32651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If this is a typedef for the type, strip the typedef off without 32671a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // losing all typedef information. 3268bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<T>(getUnqualifiedDesugaredType()); 32691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 327022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner 32715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 32725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 32735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 3274