Type.h revision bf1cc05907ceb2081e8158b26f3d3f48b31caad3
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" 19e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor#include "clang/AST/NestedNameSpecifier.h" 207532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor#include "clang/AST/TemplateName.h" 215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/Casting.h" 2250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor#include "llvm/Support/type_traits.h" 23fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff#include "llvm/ADT/APSInt.h" 245cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/FoldingSet.h" 255cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/PointerIntPair.h" 261734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "llvm/ADT/PointerUnion.h" 277532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa; 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast; 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null; 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast; 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null; 336b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCallnamespace clang { 346b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall enum { 356b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeAlignmentInBits = 3, 366b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeAlignment = 1 << TypeAlignmentInBits 376b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall }; 386b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall class Type; class ExtQuals; 396b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall} 405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 414e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm { 424e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner template <typename T> 43daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner class PointerLikeTypeTraits; 44bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner template<> 45bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner class PointerLikeTypeTraits< ::clang::Type*> { 46bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner public: 47bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 48bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner static inline ::clang::Type *getFromVoidPointer(void *P) { 49bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner return static_cast< ::clang::Type*>(P); 50bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner } 516b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 52bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner }; 530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall template<> 540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall class PointerLikeTypeTraits< ::clang::ExtQuals*> { 550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall public: 560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; } 570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static inline ::clang::ExtQuals *getFromVoidPointer(void *P) { 580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return static_cast< ::clang::ExtQuals*>(P); 590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 606b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall }; 624e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner} 634e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner 645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class ASTContext; 665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TypedefDecl; 6755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor class TemplateDecl; 6872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor class TemplateTypeParmDecl; 69aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor class NonTypeTemplateParmDecl; 707532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor class TemplateTemplateParmDecl; 715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TagDecl; 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class RecordDecl; 7349aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis class CXXRecordDecl; 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class EnumDecl; 7521d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek class FieldDecl; 76a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCInterfaceDecl; 77a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCProtocolDecl; 78a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCMethodDecl; 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Expr; 80b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek class Stmt; 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class SourceLocation; 8292866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek class StmtIteratorBase; 8340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor class TemplateArgument; 84e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor class QualifiedNameType; 853b4ea54acf01f72f6eb74d96689dda86d950228fDaniel Dunbar struct PrintingPolicy; 8672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 8772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor // Provide forward declarations for all of the *Type classes 8872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type; 8972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 90f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Qualifiers - The collection of all-type qualifiers we support. 920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Clang supports five independent qualifiers: 930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * C99: const, volatile, and restrict 940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Embedded C (TR18037): address spaces 950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Objective C: the GC attributes (none, weak, or strong) 960953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass Qualifiers { 975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Const = 0x1, 1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Restrict = 0x2, 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Volatile = 0x4, 1020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall CVRMask = Const | Volatile | Restrict 1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall enum GC { 106d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian GCNone = 0, 107d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Weak, 108d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Strong 109d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian }; 110efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall 1110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall enum { 1120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// The maximum supported address space number. 1130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// 24 bits should be enough for anyone. 1140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall MaxAddressSpace = 0xffffffu, 1150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// The width of the "fast" qualifier mask. 1170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall FastWidth = 2, 1180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// The fast qualifier mask. 1200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall FastMask = (1 << FastWidth) - 1 1210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall }; 1220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers() : Mask(0) {} 1240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static Qualifiers fromFastMask(unsigned Mask) { 1260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Qs; 1270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qs.addFastQualifiers(Mask); 1280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs; 1290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static Qualifiers fromCVRMask(unsigned CVR) { 1320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Qs; 1330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qs.addCVRQualifiers(CVR); 1340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs; 1350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Deserialize qualifiers from an opaque representation. 1380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static Qualifiers fromOpaqueValue(unsigned opaque) { 1390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Qs; 1400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qs.Mask = opaque; 1410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs; 1420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Serialize these qualifiers into an opaque representation. 1450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getAsOpaqueValue() const { 1460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Mask; 1470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasConst() const { return Mask & Const; } 1500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setConst(bool flag) { 1510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~Const) | (flag ? Const : 0); 1520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeConst() { Mask &= ~Const; } 1540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addConst() { Mask |= Const; } 1550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasVolatile() const { return Mask & Volatile; } 1570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setVolatile(bool flag) { 1580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~Volatile) | (flag ? Volatile : 0); 1590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeVolatile() { Mask &= ~Volatile; } 1610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addVolatile() { Mask |= Volatile; } 1620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasRestrict() const { return Mask & Restrict; } 1640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setRestrict(bool flag) { 1650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~Restrict) | (flag ? Restrict : 0); 1660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeRestrict() { Mask &= ~Restrict; } 1680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addRestrict() { Mask |= Restrict; } 1690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasCVRQualifiers() const { return getCVRQualifiers(); } 1710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getCVRQualifiers() const { return Mask & CVRMask; } 1720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setCVRQualifiers(unsigned mask) { 1730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 1740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~CVRMask) | mask; 1750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeCVRQualifiers(unsigned mask) { 1770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 1780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask &= ~mask; 1790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeCVRQualifiers() { 1810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeCVRQualifiers(CVRMask); 1820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addCVRQualifiers(unsigned mask) { 1840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 1850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= mask; 1860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasObjCGCAttr() const { return Mask & GCAttrMask; } 1890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); } 1900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setObjCGCAttr(GC type) { 1910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift); 1920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeObjCGCAttr() { setObjCGCAttr(GCNone); } 1940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addObjCGCAttr(GC type) { 1950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(type); 1960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall setObjCGCAttr(type); 1970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 1980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasAddressSpace() const { return Mask & AddressSpaceMask; } 2000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; } 2010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setAddressSpace(unsigned space) { 2020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(space <= MaxAddressSpace); 2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~AddressSpaceMask) 2040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall | (((uint32_t) space) << AddressSpaceShift); 2050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeAddressSpace() { setAddressSpace(0); } 2070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addAddressSpace(unsigned space) { 2080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(space); 2090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall setAddressSpace(space); 2100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Fast qualifiers are those that can be allocated directly 2130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // on a QualType object. 2140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasFastQualifiers() const { return getFastQualifiers(); } 2150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getFastQualifiers() const { return Mask & FastMask; } 2160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setFastQualifiers(unsigned mask) { 2170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask = (Mask & ~FastMask) | mask; 2190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeFastQualifiers(unsigned mask) { 2210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask &= ~mask; 2230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeFastQualifiers() { 2250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeFastQualifiers(FastMask); 2260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addFastQualifiers(unsigned mask) { 2280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= mask; 2300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// hasNonFastQualifiers - Return true if the set contains any 2330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// qualifiers which require an ExtQuals node to be allocated. 2340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasNonFastQualifiers() const { return Mask & ~FastMask; } 2350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers getNonFastQualifiers() const { 2360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Quals = *this; 2370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.setFastQualifiers(0); 2380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Quals; 2390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// hasQualifiers - Return true if the set contains any qualifiers. 2420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasQualifiers() const { return Mask; } 2430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool empty() const { return !Mask; } 2440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// \brief Add the qualifiers from the given set to this set. 2460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addQualifiers(Qualifiers Q) { 2470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If the other set doesn't have any non-boolean qualifiers, just 2480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // bit-or it in. 2490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!(Q.Mask & ~CVRMask)) 2500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= Q.Mask; 2510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall else { 2520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Mask |= (Q.Mask & CVRMask); 2530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Q.hasAddressSpace()) 2540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addAddressSpace(Q.getAddressSpace()); 2550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Q.hasObjCGCAttr()) 2560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addObjCGCAttr(Q.getObjCGCAttr()); 2570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool operator==(Qualifiers Other) const { return Mask == Other.Mask; } 2610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; } 2620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall operator bool() const { return hasQualifiers(); } 2640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers &operator+=(Qualifiers R) { 2660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addQualifiers(R); 2670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return *this; 2680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Union two qualifier sets. If an enumerated qualifier appears 2710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // in both sets, use the one from the right. 2720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall friend Qualifiers operator+(Qualifiers L, Qualifiers R) { 2730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall L += R; 2740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return L; 2750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string getAsString() const; 2780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string getAsString(const PrintingPolicy &Policy) const { 2790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall std::string Buffer; 2800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getAsStringInternal(Buffer, Policy); 2810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Buffer; 2820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const; 2840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 2860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ID.AddInteger(Mask); 2870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 2880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2890953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate: 2900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // bits: |0 1 2|3 .. 4|5 .. 31| 2920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // |C R V|GCAttr|AddrSpace| 2930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall uint32_t Mask; 2940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t GCAttrMask = 0x18; 2960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t GCAttrShift = 3; 2970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask); 2980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static const uint32_t AddressSpaceShift = 5; 2990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 3000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// ExtQuals - We can encode up to three bits in the low bits of a 3030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// type pointer, but there are many more type qualifiers that we want 3040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// to be able to apply to an arbitrary type. Therefore we have this 3050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// struct, intended to be heap-allocated and used by QualType to 3060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// store qualifiers. 3070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 3080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// The current design tags the 'const' and 'restrict' qualifiers in 3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// two low bits on the QualType pointer; a third bit records whether 3100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// the pointer is an ExtQuals node. 'const' was chosen because it is 3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// orders of magnitude more common than the other two qualifiers, in 3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// both library and user code. It's relatively rare to see 3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'restrict' in user code, but many standard C headers are saturated 3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// with 'restrict' declarations, so that representing them efficiently 3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// is a critical goal of this representation. 3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass ExtQuals : public llvm::FoldingSetNode { 3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // NOTE: changing the fast qualifiers should be straightforward as 3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // long as you don't make 'const' non-fast. 3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // 1. Qualifiers: 3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ). 3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Fast qualifiers must occupy the low-order bits. 3220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // b) Update Qualifiers::FastWidth and FastMask. 3230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // 2. QualType: 3240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // a) Update is{Volatile,Restrict}Qualified(), defined inline. 3250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // b) Update remove{Volatile,Restrict}, defined near the end of 3260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // this header. 3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // 3. ASTContext: 3280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // a) Update get{Volatile,Restrict}Type. 3290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Context - the context to which this set belongs. We save this 3310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// here so that QualifierCollector can use it to reapply extended 3320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// qualifiers to an arbitrary type without requiring a context to 3330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// be pushed through every single API dealing with qualifiers. 3340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ASTContext& Context; 3350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// BaseType - the underlying type that this qualifies 3370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *BaseType; 3380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Quals - the immutable set of qualifiers applied by this 3400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// node; always contains extended qualifiers. 3410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Quals; 3420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3430953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 3440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ExtQuals(ASTContext& Context, const Type *Base, Qualifiers Quals) 3450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Context(Context), BaseType(Base), Quals(Quals) 3460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall { 3470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(Quals.hasNonFastQualifiers() 3480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall && "ExtQuals created with no fast qualifiers"); 3490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!Quals.hasFastQualifiers() 3500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall && "ExtQuals created with fast qualifiers"); 3510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers getQualifiers() const { return Quals; } 3540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasVolatile() const { return Quals.hasVolatile(); } 3560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); } 3580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); } 3590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasAddressSpace() const { return Quals.hasAddressSpace(); } 3610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getAddressSpace() const { return Quals.getAddressSpace(); } 3620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *getBaseType() const { return BaseType; } 3641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ASTContext &getContext() const { return Context; } 3660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3670953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 3680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 3690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Profile(ID, getBaseType(), Quals); 3700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, 3720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *BaseType, 3730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Quals) { 3740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!"); 3750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ID.AddPointer(BaseType); 3760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.Profile(ID); 3770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 3780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 3790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on 3820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers. This 3830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for 3840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int', 3850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc). 3860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 3870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we 3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the 3890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer. To handle the packing/unpacking, we make QualType be a 3900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer. A third bit 3910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which 3920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure. 3930953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType { 3940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Thankfully, these are efficiently composable. 3950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>, 3960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::FastWidth> Value; 3970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 3980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasExtQuals() const { 3990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().is<const ExtQuals*>(); 4000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *getExtQualsUnsafe() const { 4030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().get<const ExtQuals*>(); 4040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *getTypePtrUnsafe() const { 4070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().get<const Type*>(); 4080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall friend class QualifierCollector; 4110953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 4125cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType() {} 4131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4145cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType(const Type *Ptr, unsigned Quals) 4150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Value(Ptr, Quals) {} 4160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType(const ExtQuals *Ptr, unsigned Quals) 4170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Value(Ptr, Quals) {} 4180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getFastQualifiers() const { return Value.getInt(); } 4200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setFastQualifiers(unsigned Quals) { Value.setInt(Quals); } 4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Retrieves a pointer to the underlying (unqualified) type. 4230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// This should really return a const Type, but it's not worth 4240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// changing all the users right now. 4250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Type *getTypePtr() const { 4260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (hasNonFastQualifiers()) 4270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return const_cast<Type*>(getExtQualsUnsafe()->getBaseType()); 4280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return const_cast<Type*>(getTypePtrUnsafe()); 4290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4315cf243a883872441d73ca49cea7e20de5802629bChris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static QualType getFromOpaquePtr(void *Ptr) { 4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType T; 4345cf243a883872441d73ca49cea7e20de5802629bChris Lattner T.Value.setFromOpaqueValue(Ptr); 4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T; 4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type &operator*() const { 4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *getTypePtr(); 4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *operator->() const { 4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypePtr(); 4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNull - Return true if this QualType doesn't point to a type yet. 4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNull() const { 4480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Value.getPointer().isNull(); 4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isConstQualified() const { 4520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return (getFastQualifiers() & Qualifiers::Const); 4530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool isRestrictQualified() const { 4550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return (getFastQualifiers() & Qualifiers::Restrict); 4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVolatileQualified() const { 4580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return (hasNonFastQualifiers() && getExtQualsUnsafe()->hasVolatile()); 4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Determines whether this type has any direct qualifiers. 4620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasQualifiers() const { 4630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getFastQualifiers() || hasNonFastQualifiers(); 4640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall bool hasNonFastQualifiers() const { 4670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return hasExtQuals(); 4680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Retrieves the set of qualifiers belonging to this type. 4710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers getQualifiers() const { 4720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers Quals; 4730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (hasNonFastQualifiers()) 4740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals = getExtQualsUnsafe()->getQualifiers(); 4750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.addFastQualifiers(getFastQualifiers()); 4760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Quals; 4770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Retrieves the CVR qualifiers of this type. 4800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getCVRQualifiers() const { 4810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned CVR = getFastQualifiers(); 4820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (isVolatileQualified()) CVR |= Qualifiers::Volatile; 4830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return CVR; 4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 485b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 486bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isConstant(ASTContext& Ctx) const { 487bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return QualType::isConstant(*this, Ctx); 488bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 4891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Don't promise in the API that anything besides 'const' can be 4910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // easily added. 4920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 4930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// addConst - add the specified type qualifier to this QualType. 4940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addConst() { 4950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addFastQualifiers(Qualifiers::Const); 4960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 4970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withConst() const { 4980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return withFastQualifiers(Qualifiers::Const); 4990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void addFastQualifiers(unsigned TQs) { 5020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(TQs & ~Qualifiers::FastMask) 5030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall && "non-fast qualifier bits set in mask!"); 5040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Value.setInt(Value.getInt() | TQs); 5050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeConst(); 5080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeVolatile(); 5090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeRestrict(); 5100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeCVRQualifiers(unsigned Mask); 5110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeFastQualifiers() { Value.setInt(0); } 5130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void removeFastQualifiers(unsigned Mask) { 5140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers"); 5150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Value.setInt(Value.getInt() & ~Mask); 5160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Creates a type with the given qualifiers in addition to any 5190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // qualifiers already on this type. 5200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withFastQualifiers(unsigned TQs) const { 5210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType T = *this; 5220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall T.addFastQualifiers(TQs); 5230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return T; 5240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 5251c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta 5260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Creates a type with exactly the given fast qualifiers, removing 5270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // any existing fast qualifiers. 5280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withExactFastQualifiers(unsigned TQs) const { 5290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return withoutFastQualifiers().withFastQualifiers(TQs); 5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 5320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Removes fast qualifiers, but leaves any extended qualifiers in place. 5330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType withoutFastQualifiers() const { 5340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType T = *this; 5350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall T.removeFastQualifiers(); 5360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return T; 537c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 538971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 5390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType getUnqualifiedType() const { return QualType(getTypePtr(), 0); } 5401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 541e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 542e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 543e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getNonReferenceType() const; 5441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5452fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 5462fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 5472fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 5482fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 5492fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 5502fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// concrete. 5510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// 5520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Qualifiers are left in place. 553bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType getDesugaredType() const { 554bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return QualType::getDesugaredType(*this); 555bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 55698cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor 5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// operator==/!= - Indicate whether the specified types and qualifiers are 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identical. 55950d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor friend bool operator==(const QualType &LHS, const QualType &RHS) { 56050d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return LHS.Value == RHS.Value; 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 56250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor friend bool operator!=(const QualType &LHS, const QualType &RHS) { 56350d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return LHS.Value != RHS.Value; 5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 565d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString() const; 566d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 567d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString(const PrintingPolicy &Policy) const { 5685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string S; 569d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor getAsStringInternal(S, Policy); 5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return S; 5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 572e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner void getAsStringInternal(std::string &Str, 573e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy) const; 5741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 575c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump(const char *s) const; 576c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 5771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5783f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 5793f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 5803f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek } 5815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 582ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 583ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 5841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 585d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 5860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall inline Qualifiers::GC getObjCGCAttr() const; 587f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 588f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 589f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCWeak() const { 5900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getObjCGCAttr() == Qualifiers::Weak; 591f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 592f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 593f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 594f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCStrong() const { 5950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getObjCGCAttr() == Qualifiers::Strong; 596f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 5972455636163fdd18581d7fdae816433f886d88213Mike Stump 598ae92140b542d5c1c096e39e74e59526184819b30Mike Stump /// getNoReturnAttr - Returns true if the type has the noreturn attribute, 599ae92140b542d5c1c096e39e74e59526184819b30Mike Stump /// false otherwise. 6002455636163fdd18581d7fdae816433f886d88213Mike Stump bool getNoReturnAttr() const; 601bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 602bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate: 603bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // These methods are implemented in a separate translation unit; 604bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // "static"-ize them to avoid creating temporary QualTypes in the 605bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall // caller. 606bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall static bool isConstant(QualType T, ASTContext& Ctx); 607bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall static QualType getDesugaredType(QualType T); 6085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 6115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef ::clang::Type* SimpleType; 6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Val.getTypePtr(); 6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 6231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6244e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 6254e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<> 626daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 6274e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic: 6284e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 6294e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return P.getAsOpaquePtr(); 6304e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 6314e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 6324e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return clang::QualType::getFromOpaquePtr(P); 6334e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 6340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Various qualifiers go in low bits. 6350eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 0 }; 6364e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}; 6371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63873af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 65372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 65672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type { 6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 67072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class, 67172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 67272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 67372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TagFirst = Record, TagLast = Enum 6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 6751bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 6761bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidisprotected: 6771bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis enum { TypeClassBitSize = 6 }; 6781bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType CanonicalType; 6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 682898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 683898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool Dependent : 1; 684898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 6855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Note that this should stay at the end of the ivars for Type so that 6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// subclasses can pack their bitfields into the same word. 6881bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis unsigned TC : TypeClassBitSize; 689898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 69016ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner Type(const Type&); // DO NOT IMPLEMENT. 69116ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner void operator=(const Type&); // DO NOT IMPLEMENT. 6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 693124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 694124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 695898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 696f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 697898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Dependent(dependent), TC(tc) {} 698898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual ~Type() {} 6994b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 7011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7028b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 703a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 7041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 7091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 710bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// \brief Determines whether the type describes an object in memory. 711bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// 712bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// Note that this definition of object type corresponds to the C++ 713bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// definition of object type, which includes incomplete types, as 714bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// opposed to the C definition (which does not include incomplete 715bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// types). 7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isObjectType() const; 7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 7211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// routine will need to determine if the size is actually required. 7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncompleteType() const; 723d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner 724d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 725d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// type, in other words, not a function type. 726d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner bool isIncompleteOrObjectType() const { 727d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner return !isFunctionType(); 728d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner } 72964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 73064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 73164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl bool isPODType() const; 73264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 733d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 734d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// types that have a non-constant expression. This does not include "[]". 735d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff bool isVariablyModifiedType() const; 7361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 738ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 739e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 740e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 741e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 7421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 74396d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 74496d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 74613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 74713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 74813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 74977a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor bool isWideCharType() const; 75033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian bool isIntegralType() const; 7511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 75402f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 75502f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 757f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 761c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 762c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 763c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 764d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor bool isAggregateType() const; 7651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 766c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 767ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 768c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 769183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } 770183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } 771befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 77258f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 7735618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff bool isBlockPointerType() const; 7747154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff bool isVoidPointerType() const; 775a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 7767c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isLValueReferenceType() const; 7777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isRValueReferenceType() const; 778bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isFunctionPointerType() const; 779f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberPointerType() const; 780f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberFunctionPointerType() const; 781c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 782c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isConstantArrayType() const; 783c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isIncompleteArrayType() const; 784c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isVariableArrayType() const; 785898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentSizedArrayType() const; 786c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 7871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isClassType() const; 7881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isStructureType() const; 7894cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 790368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 791368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isVectorType() const; // GCC vector type. 792213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman bool isExtVectorType() const; // Extended vector type. 793d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 79414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // FIXME: change this to 'raw' interface type, so we can used 'interface' type 79514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for the common case. 796368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCInterfaceType() const; // NSString or NSString<foo> 797368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 798368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedIdType() const; // id<foo> 799470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const; // Class<foo> 80014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const; // id 80114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const; // Class 802de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff bool isObjCBuiltinType() const; // 'id' or 'Class' 80372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 8046e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 805898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 806898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 8071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// that its definition somehow depends on a template parameter 808898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.type]). 809898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentType() const { return Dependent; } 810063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor bool isOverloadableType() const; 81172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 8128958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 8138958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 8148958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 8156e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl /// interface types, as well as nullptr_t. 8168958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar bool hasPointerRepresentation() const; 8178958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 818820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 819820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 8201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool hasObjCPointerRepresentation() const; 821820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 822c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 823f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 824f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 825769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const RecordType *getAsStructureType() const; 826898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 827c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 8284cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 82914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // The following is a convenience method that returns an ObjCObjectPointerType 83014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for object declared using an interface. 83114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 83214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 833c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff const ObjCInterfaceType *getAsObjCQualifiedInterfaceType() const; 834a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 8351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8361a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // Member-template getAs<specific type>'. This scheme will eventually 8371a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // replace the specific getAsXXXX methods above. 838183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall // 839183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall // There are some specializations of this member template listed 840183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall // immediately following this class. 8411a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek template <typename T> const T *getAs() const; 8421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8432b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 8442b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// interface, return the interface type, otherwise return null. 8452b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 8462b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 847c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 848c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// element type of the array, potentially with type qualifiers missing. 849c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// This method should never be used when type qualifiers are meaningful. 850c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 8511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 852f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// getPointeeType - If this is a pointer, ObjC object pointer, or block 853f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// pointer, this returns the respective pointee. 85414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const; 8551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 856bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// getUnqualifiedDesugaredType() - Return the specified type with 857bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// any "sugar" removed from the type, removing any typedefs, 858bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// typeofs, etc., as well as any qualifiers. 859bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *getUnqualifiedDesugaredType() const; 8601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 865d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 866d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 867d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// integer element type. 8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 8695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 871d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 872d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 873d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// element type. 8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 875d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 8779bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 8789bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 8793c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 880c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 88122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 88222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// set of type specifiers. 88322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman bool isSpecifierType() const; 88422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 885cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis const char *getTypeClassName() const; 886cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis 8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getCanonicalTypeInternal() const { return CanonicalType; } 888c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 8891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 890f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const = 0; 8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 894183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const { 895183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall return dyn_cast<TypedefType>(this); 896183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall} 897183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 898183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to 899183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration. 900183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base) 901183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \ 902183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \ 9030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return dyn_cast<Class##Type>(CanonicalType); \ 904183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall} 905183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def" 906183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 907183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall 9085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 9135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Void, 9141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Bool, // This is bool and/or _Bool. 9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_U, // This is 'char' for targets where char is unsigned. 9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UChar, // This is explicitly qualified unsigned char. 918f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char16, // This is 'char16_t' for C++. 919f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char32, // This is 'char32_t' for C++. 9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UShort, 9215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UInt, 9225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULong, 9235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULongLong, 9242df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner UInt128, // __uint128_t 9251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_S, // This is 'char' for targets where char is signed. 9275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SChar, // This is explicitly qualified signed char. 9282ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis WChar, // This is 'wchar_t' for C++. 9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Short, 9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Int, 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Long, 9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongLong, 9332df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner Int128, // __int128_t 9341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9358e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor Float, Double, LongDouble, 9368e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 9376e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 9386e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 939898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Overload, // This represents the type of an overloaded function declaration. 940e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson Dependent, // This represents the type of a type-dependent expression. 9411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 942de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff UndeducedAuto, // In C++0x, this represents the type of an auto variable 943e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson // that has not been deduced yet. 944de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCId, // This represents the ObjC 'id' type. 945de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCClass // This represents the ObjC 'Class' type. 9465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 9485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind TypeKind; 9495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BuiltinType(Kind K) 9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 952898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeKind(K) {} 9531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind getKind() const { return TypeKind; } 955e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const char *getName(const LangOptions &LO) const; 9561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 957bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 958bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 959bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 9601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 961f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 9621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 967f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// FixedWidthIntType - Used for arbitrary width types that we either don't 968f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// want to or can't map to named integer types. These always have a lower 969f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// integer rank than builtin types of the same width. 970f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanclass FixedWidthIntType : public Type { 971f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanprivate: 972f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned Width; 973f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool Signed; 974f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanpublic: 975f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false), 976f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman Width(W), Signed(S) {} 9771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 978f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned getWidth() const { return Width; } 979f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool isSigned() const { return Signed; } 980f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman const char *getName() const; 9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 982bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 983bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 984bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 9851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 986f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 9871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 988f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; } 989f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const FixedWidthIntType *) { return true; } 990f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman}; 991f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 9981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Type(Complex, CanonicalPtr, Element->isDependentType()), 999898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(Element) { 10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 10041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1006f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 10071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1008bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1009bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1010bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 102268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 1023bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// 102468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 1025bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType PointeeType; 10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 102868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 10295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1034f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 10351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 103668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 103768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 1038bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1039bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1040bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 10425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 10435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 10455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 10465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 10495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 10505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10525618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type. 10535618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as 10545618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 10555618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// 10565618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 10575618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 10585618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 10591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 1060898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor PointeeType(Pointee) { 10615618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 10625618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff friend class ASTContext; // ASTContext creates these. 10635618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic: 10641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10655618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 10665618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType getPointeeType() const { return PointeeType; } 10675618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 10681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1069f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 10701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1071bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1072bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1073bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 10745618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 10755618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Profile(ID, getPointeeType()); 10765618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 10775618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 10785618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 10795618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 10821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == BlockPointer; 10835618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 10845618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 10855618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}; 10865618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 10877c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 10885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 108968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 109068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType PointeeType; 109168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 10927c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected: 10937c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) : 10947c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Type(tc, CanonicalRef, Referencee->isDependentType()), 109568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar PointeeType(Referencee) { 10965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 109868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 109968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 1101bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner Profile(ID, getPointeeType()); 11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 11045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 11055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11077c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 11087c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference || 11097c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl T->getTypeClass() == RValueReference; 11107c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 11127c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 11137c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 11147c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 11157c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 11167c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType { 11177c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceType(QualType Referencee, QualType CanonicalRef) : 11187c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(LValueReference, Referencee, CanonicalRef) { 11197c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 11207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 11217c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 11221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1123f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 11247c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 1125bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1126bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1127bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 11287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 11297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference; 11307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 11317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 11327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 11337c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 11347c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 11357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 11367c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType { 11377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 11387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(RValueReference, Referencee, CanonicalRef) { 11397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 11407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 11417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 11421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1143f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 11447c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 1145bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1146bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1147bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 11487c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 11497c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == RValueReference; 11507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 11517c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 1152f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}; 1153f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1154f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 1155f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// 1156f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 1157f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType PointeeType; 1158f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 1159f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 1160f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class; 1161f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1162f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 1163f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Type(MemberPointer, CanonicalPtr, 1164f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Cls->isDependentType() || Pointee->isDependentType()), 1165f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointeeType(Pointee), Class(Cls) { 1166f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1167f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl friend class ASTContext; // ASTContext creates these. 1168f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic: 1169f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1170f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType getPointeeType() const { return PointeeType; } 1171f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1172f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *getClass() const { return Class; } 1173f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 11741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1175f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1176f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1177bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1178bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1179bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1180f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 1181f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Profile(ID, getPointeeType(), getClass()); 1182f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1183f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 1184f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class) { 1185f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 1186f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Class); 1187f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1188f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1189f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const Type *T) { 1190f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getTypeClass() == MemberPointer; 1191f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1192f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const MemberPointerType *) { return true; } 11935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11972e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 11985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 1200898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 1201898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// with a star size (e.g. int X[*]). 1202898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// 'static' is only allowed on function parameters. 12035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 12045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 12065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 1207fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 1208fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 12091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1210ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 1211c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 1212ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned SizeModifier : 2; 12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1214c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 1215c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// 'int X[static restrict 4]'. For function parameters only. 1216c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned IndexTypeQuals : 3; 12171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1218fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 1219898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // C++ [temp.dep.type]p1: 1220898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // A type is dependent if it is... 1221898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // - an array type constructed from any dependent type or whose 1222898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // size is specified by a constant expression that is 1223898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // value-dependent, 1224c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 1225c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 1226898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 1227898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 1228898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1229fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 1230fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 1231fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 1232ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 1233ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ArraySizeModifier(SizeModifier); 1234ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 12350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers getIndexTypeQualifiers() const { 12360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qualifiers::fromCVRMask(IndexTypeQuals); 12370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 12380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned getIndexTypeCVRQualifiers() const { return IndexTypeQuals; } 12391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1240fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 1241fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 12427e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithExpr || 12437e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithoutExpr || 1244c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 1245898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == IncompleteArray || 1246898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == DependentSizedArray; 1247fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1248fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 1249fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 1250fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 12517e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of 12527e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size. For example, the canonical 12537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 12547e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404. 12552e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 1256fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12580be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 1259c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 12607e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(ConstantArray, et, can, sm, tq), 12617e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Size(size) {} 12627e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected: 12637e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayType(TypeClass tc, QualType et, QualType can, 12647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 12657e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(tc, et, can, sm, tq), Size(size) {} 1266fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 1267fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 1268c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const llvm::APInt &getSize() const { return Size; } 12691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1270f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1272bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1273bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1274bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1275fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 12761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, getElementType(), getSize(), 12770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers()); 1278fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1279fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 12800be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 12810be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner unsigned TypeQuals) { 1282fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 1283fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 12840be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 12850be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 1286fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 12877e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 12887e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return T->getTypeClass() == ConstantArray || 12897e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithExpr || 12907e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithoutExpr; 1291fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1292fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 1293fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 1294fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 12957e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayWithExprType - This class represents C arrays with a 12967e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// constant size specified by means of an integer constant expression. 12977e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// For example 'int A[sizeof(int)]' has ConstantArrayWithExprType where 12987e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// the element type is 'int' and the size expression is 'sizeof(int)'. 12997e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// These types are non-canonical. 13007e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorclass ConstantArrayWithExprType : public ConstantArrayType { 13017e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// SizeExpr - The ICE occurring in the concrete syntax. 13027e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *SizeExpr; 13037e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 13047e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 13057e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 13067e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayWithExprType(QualType et, QualType can, 13077e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, Expr *e, 13087e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 13097e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 13107e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ConstantArrayType(ConstantArrayWithExpr, et, can, size, sm, tq), 13117e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr(e), Brackets(brackets) {} 13127e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor friend class ASTContext; // ASTContext creates these. 13137e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor virtual void Destroy(ASTContext& C); 13147e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 13157e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorpublic: 13167e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 13177e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 13187e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 13197e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 13207e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 13217e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor virtual void getAsStringInternal(std::string &InnerString, 13227e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const PrintingPolicy &Policy) const; 13237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1324bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1325bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1326bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 13277e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 13287e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return T->getTypeClass() == ConstantArrayWithExpr; 13297e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 13307e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const ConstantArrayWithExprType *) { return true; } 13317e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 13327e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 13337e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor assert(0 && "Cannot unique ConstantArrayWithExprTypes."); 13347e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 13357e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor}; 13367e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 13377e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayWithoutExprType - This class represents C arrays with a 13387e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// constant size that was not specified by an integer constant expression, 13397e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// but inferred by static semantics. 13407e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// For example 'int A[] = { 0, 1, 2 }' has ConstantArrayWithoutExprType. 13417e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// These types are non-canonical: the corresponding canonical type, 13427e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// having the size specified in an APInt object, is a ConstantArrayType. 13437e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorclass ConstantArrayWithoutExprType : public ConstantArrayType { 13447e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 13457e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayWithoutExprType(QualType et, QualType can, 13467e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, 13477e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq) 13487e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ConstantArrayType(ConstantArrayWithoutExpr, et, can, size, sm, tq) {} 13497e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor friend class ASTContext; // ASTContext creates these. 13507e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 13517e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorpublic: 13527e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor virtual void getAsStringInternal(std::string &InnerString, 13537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const PrintingPolicy &Policy) const; 13547e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1355bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1356bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1357bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 13587e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 13597e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return T->getTypeClass() == ConstantArrayWithoutExpr; 13607e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 13617e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const ConstantArrayWithoutExprType *) { return true; } 13627e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 13637e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 13647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor assert(0 && "Cannot unique ConstantArrayWithoutExprTypes."); 13657e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 13667e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor}; 13677e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1368da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 1369da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 1370da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified. 1371c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 13727e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1373c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 13747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq) 1375c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 1376c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 1377c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 13781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1379f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1380c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1381bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1382bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1383bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 13841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == IncompleteArray; 1386c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 1387c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 13881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1389c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 13901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1391c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 13920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Profile(ID, getElementType(), getSizeModifier(), 13930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getIndexTypeCVRQualifiers()); 1394c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 13951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13960be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 13970be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 1398c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 13990be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 14000be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 1401c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 1402c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 1403c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1404da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 1405da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 1406da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 1407da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 1408da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 1409da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean 1410da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type 1411da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically: 1412da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 1413da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) { 1414da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Y[x]; 1415da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ++x; 1416da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Z[x]; 1417da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// } 1418da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 14192e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 14201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// SizeExpr - An assignment expression. VLA's are only permitted within 14211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// a function block. 1422b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek Stmt *SizeExpr; 14237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 14247e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 14257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1426c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 14277e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 14287e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 14297e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(VariableArray, et, can, sm, tq), 14307e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 14315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 14324b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 14334b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 14345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getSizeExpr() const { 1436b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // We use C-style casts instead of cast<> here because we do not wish 1437b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 1438b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek return (Expr*) SizeExpr; 1439b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek } 14407e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 14417e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 14427e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 14431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1445f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 14461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1447bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1448bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1449bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 14501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 14511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == VariableArray; 14525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1453fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 14541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 145592866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 14561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14572bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 1458bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 14592bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 14605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1462898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in 1463898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example: 1464898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @code 14651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size> 1466898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array { 1467898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// T data[Size]; 1468898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// }; 1469898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @endcode 1470898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is 1471898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will 1472898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 1473898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType { 147404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ASTContext &Context; 14751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1476898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// SizeExpr - An assignment expression that will instantiate to the 1477898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// size of the array. 1478898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Stmt *SizeExpr; 14797e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 14807e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 14811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentSizedArrayType(ASTContext &Context, QualType et, QualType can, 148304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *e, ArraySizeModifier sm, unsigned tq, 14847e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 14857e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), 148604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {} 1487898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class ASTContext; // ASTContext creates these. 1488898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual void Destroy(ASTContext& C); 1489898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1490898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic: 14911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getSizeExpr() const { 1492898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // We use C-style casts instead of cast<> here because we do not wish 1493898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 1494898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return (Expr*) SizeExpr; 1495898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 14967e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 14977e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 14987e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 14991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1501f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 15021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1503bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1504bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1505bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 15061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 15071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == DependentSizedArray; 1508898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1509898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 15101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1511898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class StmtIteratorBase; 15121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1514898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 15151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, Context, getElementType(), 15160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); 1517898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 15181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 15201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType ET, ArraySizeModifier SizeMod, 152104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, Expr *E); 1522898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}; 1523898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1524f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 15259cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example: 15269cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code 15279cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size> 15289cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector { 15299cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 15309cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// } 15319cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode 15322ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { 15332ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor ASTContext &Context; 15349cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr; 15359cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor /// ElementType - The element type of the array. 15369cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType ElementType; 15379cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation loc; 15381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentSizedExtVectorType(ASTContext &Context, QualType ElementType, 15402ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType can, Expr *SizeExpr, SourceLocation loc) 15411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type (DependentSizedExtVector, can, true), 15421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 15432ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor loc(loc) {} 15449cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor friend class ASTContext; 15459cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor virtual void Destroy(ASTContext& C); 15469cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 15479cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic: 15482ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 15499cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType getElementType() const { return ElementType; } 15509cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation getAttributeLoc() const { return loc; } 15519cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 15521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1553f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 15541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1555bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1556bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1557bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 15581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 15591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == DependentSizedExtVector; 15609cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor } 15611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const DependentSizedExtVectorType *) { return true; } 15622ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 15632ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 15642ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor Profile(ID, Context, getElementType(), getSizeExpr()); 15652ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 15661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15672ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 15682ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr); 15699cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor}; 15701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15719cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 157273322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 15731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in 15741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// bytes. Since the constructor takes the number of vector elements, the 157573322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 15765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 157773322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 15785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 15795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 15801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumElements - The number of elements in the vector. 15825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumElements; 15831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 158473322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(QualType vecType, unsigned nElements, QualType canonType) : 15851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Type(Vector, canonType, vecType->isDependentType()), 15861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ElementType(vecType), NumElements(nElements) {} 15871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump VectorType(TypeClass tc, QualType vecType, unsigned nElements, 15881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType canonType) 15891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 15901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NumElements(nElements) {} 15915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 15925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 15951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumElements() const { return NumElements; } 15965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1598f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 15991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1600bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1601bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1602bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 16035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 160473322924127c873c13101b705dd823f5539ffa5fSteve Naroff Profile(ID, getElementType(), getNumElements(), getTypeClass()); 16055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 160773322924127c873c13101b705dd823f5539ffa5fSteve Naroff unsigned NumElements, TypeClass TypeClass) { 16085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 16095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 161073322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 161173322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 16121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 16131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 16145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 16165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1618213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using 1619213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1620213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1621fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 1622fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1623213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType { 1624213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 16251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump VectorType(ExtVector, vecType, nElements, canonType) {} 162673322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 162773322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 162888dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 162988dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 163088dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 163188dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 163288dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 163388dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 163488dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 163588dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1636e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1637353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman static int getNumericAccessorIdx(char c) { 163888dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 1639353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman default: return -1; 1640353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '0': return 0; 1641353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '1': return 1; 1642353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '2': return 2; 1643353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '3': return 3; 1644353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '4': return 4; 1645353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '5': return 5; 1646353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '6': return 6; 1647353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '7': return 7; 1648353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '8': return 8; 1649353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '9': return 9; 1650131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'A': 1651353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'a': return 10; 1652131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'B': 1653353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'b': return 11; 1654131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'C': 1655353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'c': return 12; 1656131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'D': 1657353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'd': return 13; 1658131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'E': 1659353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'e': return 14; 1660131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'F': 1661353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'f': return 15; 166288dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1663e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 16641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1665b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 1666b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1667353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman return getNumericAccessorIdx(c); 1668b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 16691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 167088dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 1671b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 167288dca0464804b8b26ae605f89784c927e8493dddChris Lattner return unsigned(idx-1) < NumElements; 167388dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 1674e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 16751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1676f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 167731a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 1678bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1679bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1680bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 16811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 16821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ExtVector; 168373322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 1684213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman static bool classof(const ExtVectorType *) { return true; } 168573322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 168673322924127c873c13101b705dd823f5539ffa5fSteve Naroff 16875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 168872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 16895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 16905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 16915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SubClassData - This field is owned by the subclass, put here to pack 16925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tightly with the ivars in Type. 16935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SubClassData : 1; 1694971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 169572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1696971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// other bitfields. 169772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// The qualifiers are part of FunctionProtoType because... 1698971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1699971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 1700971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// cv-qualifier-seq, [...], are part of the function type. 1701971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1702971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned TypeQuals : 3; 17032455636163fdd18581d7fdae816433f886d88213Mike Stump 17042455636163fdd18581d7fdae816433f886d88213Mike Stump /// NoReturn - Indicates if the function type is attribute noreturn. 17052455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned NoReturn : 1; 17061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 17085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 17095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 1710971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 17112455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned typeQuals, QualType Canonical, bool Dependent, 17122455636163fdd18581d7fdae816433f886d88213Mike Stump bool noReturn = false) 1713898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, Canonical, Dependent), 17142455636163fdd18581d7fdae816433f886d88213Mike Stump SubClassData(SubclassInfo), TypeQuals(typeQuals), NoReturn(noReturn), 17152455636163fdd18581d7fdae816433f886d88213Mike Stump ResultType(res) {} 17165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool getSubClassData() const { return SubClassData; } 1717971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return TypeQuals; } 17185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 17191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 17212455636163fdd18581d7fdae816433f886d88213Mike Stump bool getNoReturnAttr() const { return NoReturn; } 17225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 17245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 17255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 17265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 17285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 173072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 17315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 173272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 17332455636163fdd18581d7fdae816433f886d88213Mike Stump FunctionNoProtoType(QualType Result, QualType Canonical, 17342455636163fdd18581d7fdae816433f886d88213Mike Stump bool NoReturn = false) 17351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 17362455636163fdd18581d7fdae816433f886d88213Mike Stump /*Dependent=*/false, NoReturn) {} 17375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 17385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 17395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 17401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1742f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 17435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1744bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1745bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1746bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 17475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 17482455636163fdd18581d7fdae816433f886d88213Mike Stump Profile(ID, getResultType(), getNoReturnAttr()); 17495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17502455636163fdd18581d7fdae816433f886d88213Mike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 17512455636163fdd18581d7fdae816433f886d88213Mike Stump bool NoReturn) { 17522455636163fdd18581d7fdae816433f886d88213Mike Stump ID.AddInteger(NoReturn); 17535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 17545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 17575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 17585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 175972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 17605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 176272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 17635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 1764465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 1765465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical 1766465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type. 176772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 1768898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 1769898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// types within the arguments passed in. 1770898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 1771898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 1772898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (ArgArray[Idx]->isDependentType()) 17734b4218f48fef71a179c5a8287dae281580faf52fNate Begeman return true; 1774898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1775898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1776898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1777898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 177872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 1779465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned typeQuals, bool hasExs, 1780465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExs, const QualType *ExArray, 17812455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned numExs, QualType Canonical, bool NoReturn) 1782898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 17831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (Result->isDependentType() || 17842455636163fdd18581d7fdae816433f886d88213Mike Stump hasAnyDependentType(ArgArray, numArgs)), NoReturn), 1785465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 1786465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl AnyExceptionSpec(hasAnyExs) { 1787942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner // Fill in the trailing argument array. 1788465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 17895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numArgs; ++i) 17905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ArgInfo[i] = ArgArray[i]; 1791465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // Fill in the exception array. 1792465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *Ex = ArgInfo + numArgs; 1793465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl for (unsigned i = 0; i != numExs; ++i) 1794465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl Ex[i] = ExArray[i]; 17955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1796465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 17975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 1798465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumArgs : 20; 1799465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1800465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 1801465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumExceptions : 10; 1802465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1803465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// HasExceptionSpec - Whether this function has an exception spec at all. 1804465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool HasExceptionSpec : 1; 1805465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1806465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// AnyExceptionSpec - Whether this function has a throw(...) spec. 1807465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool AnyExceptionSpec : 1; 1808465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1809942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 1810942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// holds the argument types. 1811465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1812465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 1813465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// holds the exception types. 1814465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 18155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 18164b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 18175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 18195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 18205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 1821942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 18225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1823465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1824465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec() const { return HasExceptionSpec; } 1825465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 1826465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 1827465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType getExceptionType(unsigned i) const { 1828465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 1829465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin()[i]; 1830465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 18311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool hasEmptyExceptionSpec() const { 18321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return hasExceptionSpec() && !hasAnyExceptionSpec() && 1833a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson getNumExceptions() == 0; 1834d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson } 1835465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 18365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVariadic() const { return getSubClassData(); } 1837971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 18381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 1840942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 1841942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 1842942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 1843942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1844465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1845465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl typedef const QualType *exception_iterator; 1846465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_begin() const { 1847465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // exceptions begin where arguments end 1848465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return arg_type_end(); 1849465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1850465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_end() const { 1851465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin() + NumExceptions; 1852465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1853465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 18541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1855f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 18565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1857bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1858bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1859bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 18605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 18615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 18625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 186372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 1864465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 18655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID); 18665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1867942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 1868465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned TypeQuals, 1869465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec, bool anyExceptionSpec, 18702455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned NumExceptions, exception_iterator Exs, 18712455636163fdd18581d7fdae816433f886d88213Mike Stump bool NoReturn); 18725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 18765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *Decl; 1877c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 18781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 1879898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, can->isDependentType()), Decl(D) { 18805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 18815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 18835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *getDecl() const { return Decl; } 18861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1887a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1888fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 1889a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// sum of the type qualifiers, so if you have: 1890a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef const int A; 1891a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef volatile A B; 1892a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// looking through the typedefs for B will give you "const volatile A". 1893a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType LookThroughTypedefs() const; 18941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1895bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 1896bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const; 1897bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 18981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1899f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 19005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 190172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 19025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 19035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 190572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension). 190672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type { 1907d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 19081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1909b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected: 1910dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor TypeOfExprType(Expr *E, QualType can = QualType()); 1911d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1912d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1913d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 19141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1915bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 1916bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const; 1917bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1918bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 1919bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 1920bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 19211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1922f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1923d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 192472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 192572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 1926d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 1927d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 19281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclass of TypeOfExprType that is used for canonical, dependent 19291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types. 19301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType 1931b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor : public TypeOfExprType, public llvm::FoldingSetNode { 1932b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor ASTContext &Context; 19331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1934b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic: 19351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentTypeOfExprType(ASTContext &Context, Expr *E) 1936b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor : TypeOfExprType(E), Context(Context) { } 19371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1938bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 1939bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 1940bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1941b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1942b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Profile(ID, Context, getUnderlyingExpr()); 1943b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } 19441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1945b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 1946b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Expr *E); 1947b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor}; 19481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1949d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 1950d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 1951d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 19521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypeOfType(QualType T, QualType can) 195372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : Type(TypeOf, can, T->isDependentType()), TOType(T) { 1954d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1955d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 1956d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1957d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1958d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 19591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1960bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 1961bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getUnderlyingType(); } 1962bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1963bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 1964bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 1965bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 19661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1967f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1968d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 196972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 1970d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 1971d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 19725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1973395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x) 1974395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type { 1975395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *E; 19761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1977563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 1978563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 1979563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // from it. 1980563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType UnderlyingType; 19811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19829d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected: 1983563a03b1338d31c2462def43253a722bc885d384Anders Carlsson DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 1984395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson friend class ASTContext; // ASTContext creates these. 1985395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic: 1986395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *getUnderlyingExpr() const { return E; } 1987563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType getUnderlyingType() const { return UnderlyingType; } 1988563a03b1338d31c2462def43253a722bc885d384Anders Carlsson 1989bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 1990bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getUnderlyingType(); } 1991bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 1992bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 1993bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return !isDependentType(); } 1994bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 19951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1996395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson const PrintingPolicy &Policy) const; 19971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1998395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 1999395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const DecltypeType *) { return true; } 2000395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson}; 20011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclass of DecltypeType that is used for canonical, dependent 20031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// C++0x decltype types. 20049d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { 20059d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor ASTContext &Context; 20061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20079d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic: 20089d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeType(ASTContext &Context, Expr *E); 20091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2010bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2011bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2012bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 20139d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 20149d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor Profile(ID, Context, getUnderlyingExpr()); 20159d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } 20161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20179d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 20181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *E); 20199d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor}; 20201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 20220b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// Stores the TagDecl associated with this type. The decl will 20230b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// point to the TagDecl that actually defines the entity (or is a 20240b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// definition in progress), if there is such a definition. The 20250b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// single-bit value will be non-zero when this tag is in the 20260b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// process of being defined. 2027fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor mutable llvm::PointerIntPair<TagDecl *, 1> decl; 20284b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek friend class ASTContext; 20290b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor friend class TagDecl; 20302ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 20312ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected: 20327da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor TagType(TypeClass TC, TagDecl *D, QualType can); 20332ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 20341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 20350b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor TagDecl *getDecl() const { return decl.getPointer(); } 20361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20370b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// @brief Determines whether this type is in the process of being 20381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// defined. 20390b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor bool isBeingDefined() const { return decl.getInt(); } 20400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setBeingDefined(bool Def) const { decl.setInt(Def? 1 : 0); } 20410b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 20421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 2043f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 2044e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 20451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 204672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 204772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor } 20485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 204972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const RecordType *) { return true; } 205072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const EnumType *) { return true; } 20515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 20525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20535edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 20545edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes. 20555edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType { 205649aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected: 2057509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit RecordType(RecordDecl *D) 205872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 205972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 206072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 20612ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 20625edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 20631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20645edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordDecl *getDecl() const { 20655edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 20665edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 20671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: This predicate is a helper to QualType/Type. It needs to 20695edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // recursively check all fields for const-ness. If any field is declared 20701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // const, it needs to return false. 20715edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner bool hasConstFields() const { return false; } 20725edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 20735edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 20745edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // the same address space, and return that. 20755edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner unsigned getAddressSpace() const { return 0; } 20761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2077bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2078bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2079bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 20802daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 20812daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 20822daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 20832daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 20845edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const RecordType *) { return true; } 20855edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 20865edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 20875edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 20885edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums. 20895edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType { 2090509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit EnumType(EnumDecl *D) 209172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 20922ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 20935edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 20941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20955edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumDecl *getDecl() const { 20965edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 20975edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 20981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2099bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2100bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2101bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 21022daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 21032daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 21042daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 21052daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 21065edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const EnumType *) { return true; } 21075edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 21085edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 21097da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// ElaboratedType - A non-canonical type used to represents uses of 21107da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// elaborated type specifiers in C++. For example: 21117da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// 21127da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// void foo(union MyUnion); 21137da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// ^^^^^^^^^^^^^ 21147da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// 21157da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// At the moment, for efficiency we do not create elaborated types in 21167da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// C, since outside of typedefs all references to structs would 21177da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// necessarily be elaborated. 21187da2431c23ef1ee8acb114e39692246e1801afc2John McCallclass ElaboratedType : public Type, public llvm::FoldingSetNode { 21197da2431c23ef1ee8acb114e39692246e1801afc2John McCallpublic: 21207da2431c23ef1ee8acb114e39692246e1801afc2John McCall enum TagKind { 21217da2431c23ef1ee8acb114e39692246e1801afc2John McCall TK_struct, 21227da2431c23ef1ee8acb114e39692246e1801afc2John McCall TK_union, 21237da2431c23ef1ee8acb114e39692246e1801afc2John McCall TK_class, 21247da2431c23ef1ee8acb114e39692246e1801afc2John McCall TK_enum 21257da2431c23ef1ee8acb114e39692246e1801afc2John McCall }; 21267da2431c23ef1ee8acb114e39692246e1801afc2John McCall 21277da2431c23ef1ee8acb114e39692246e1801afc2John McCallprivate: 21287da2431c23ef1ee8acb114e39692246e1801afc2John McCall /// The tag that was used in this elaborated type specifier. 21297da2431c23ef1ee8acb114e39692246e1801afc2John McCall TagKind Tag; 21307da2431c23ef1ee8acb114e39692246e1801afc2John McCall 21317da2431c23ef1ee8acb114e39692246e1801afc2John McCall /// The underlying type. 21327da2431c23ef1ee8acb114e39692246e1801afc2John McCall QualType UnderlyingType; 21337da2431c23ef1ee8acb114e39692246e1801afc2John McCall 21347da2431c23ef1ee8acb114e39692246e1801afc2John McCall explicit ElaboratedType(QualType Ty, TagKind Tag, QualType Canon) 21357da2431c23ef1ee8acb114e39692246e1801afc2John McCall : Type(Elaborated, Canon, Canon->isDependentType()), 21367da2431c23ef1ee8acb114e39692246e1801afc2John McCall Tag(Tag), UnderlyingType(Ty) { } 21377da2431c23ef1ee8acb114e39692246e1801afc2John McCall friend class ASTContext; // ASTContext creates these. 21387da2431c23ef1ee8acb114e39692246e1801afc2John McCall 21397da2431c23ef1ee8acb114e39692246e1801afc2John McCallpublic: 21407da2431c23ef1ee8acb114e39692246e1801afc2John McCall TagKind getTagKind() const { return Tag; } 21417da2431c23ef1ee8acb114e39692246e1801afc2John McCall QualType getUnderlyingType() const { return UnderlyingType; } 21427da2431c23ef1ee8acb114e39692246e1801afc2John McCall 2143bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2144bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getUnderlyingType(); } 2145bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2146bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2147bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2148bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 21497da2431c23ef1ee8acb114e39692246e1801afc2John McCall static const char *getNameForTagKind(TagKind Kind) { 21507da2431c23ef1ee8acb114e39692246e1801afc2John McCall switch (Kind) { 21517da2431c23ef1ee8acb114e39692246e1801afc2John McCall default: assert(0 && "Unknown TagKind!"); 21527da2431c23ef1ee8acb114e39692246e1801afc2John McCall case TK_struct: return "struct"; 21537da2431c23ef1ee8acb114e39692246e1801afc2John McCall case TK_union: return "union"; 21547da2431c23ef1ee8acb114e39692246e1801afc2John McCall case TK_class: return "class"; 21557da2431c23ef1ee8acb114e39692246e1801afc2John McCall case TK_enum: return "enum"; 21567da2431c23ef1ee8acb114e39692246e1801afc2John McCall } 21577da2431c23ef1ee8acb114e39692246e1801afc2John McCall } 21587da2431c23ef1ee8acb114e39692246e1801afc2John McCall 21591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 21607da2431c23ef1ee8acb114e39692246e1801afc2John McCall const PrintingPolicy &Policy) const; 21617da2431c23ef1ee8acb114e39692246e1801afc2John McCall 21627da2431c23ef1ee8acb114e39692246e1801afc2John McCall void Profile(llvm::FoldingSetNodeID &ID) { 21637da2431c23ef1ee8acb114e39692246e1801afc2John McCall Profile(ID, getUnderlyingType(), getTagKind()); 21647da2431c23ef1ee8acb114e39692246e1801afc2John McCall } 21657da2431c23ef1ee8acb114e39692246e1801afc2John McCall static void Profile(llvm::FoldingSetNodeID &ID, QualType T, TagKind Tag) { 21667da2431c23ef1ee8acb114e39692246e1801afc2John McCall ID.AddPointer(T.getAsOpaquePtr()); 21677da2431c23ef1ee8acb114e39692246e1801afc2John McCall ID.AddInteger(Tag); 21687da2431c23ef1ee8acb114e39692246e1801afc2John McCall } 21697da2431c23ef1ee8acb114e39692246e1801afc2John McCall 21707da2431c23ef1ee8acb114e39692246e1801afc2John McCall static bool classof(const ElaboratedType*) { return true; } 21717da2431c23ef1ee8acb114e39692246e1801afc2John McCall static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; } 21727da2431c23ef1ee8acb114e39692246e1801afc2John McCall}; 21737da2431c23ef1ee8acb114e39692246e1801afc2John McCall 2174fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 217576e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned Depth : 15; 2176fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned Index : 16; 217776e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned ParameterPack : 1; 2178fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *Name; 217972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 21801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 21811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Canon) 2182fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 218376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(N) { } 218472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 21851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP) 2186fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 218776e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(0) { } 218872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2189fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor friend class ASTContext; // ASTContext creates these 219072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2191fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic: 2192fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getDepth() const { return Depth; } 2193fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getIndex() const { return Index; } 219476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson bool isParameterPack() const { return ParameterPack; } 2195fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *getName() const { return Name; } 21961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 2198f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 21995edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 2200bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2201bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2202bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2203fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 220476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Profile(ID, Depth, Index, ParameterPack, Name); 2205fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 2206fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 22071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 22081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned Index, bool ParameterPack, 220976e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson IdentifierInfo *Name) { 2210fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Depth); 2211fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Index); 221276e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson ID.AddBoolean(ParameterPack); 2213fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddPointer(Name); 2214fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 2215fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 22161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 22171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == TemplateTypeParm; 221872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor } 221972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 222072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}; 2221fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 22227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written 22237532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code. 222455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// 22257532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a 22267532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 22277532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 22287532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the 22297532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a 223055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to 22311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// a tag type for the instantiation 223255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 22337532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// 22347532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name 22357532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always 22367532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent. 22371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType 223855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor : public Type, public llvm::FoldingSetNode { 223955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 2240828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor // FIXME: Currently needed for profiling expressions; can we avoid this? 2241828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor ASTContext &Context; 22421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2243828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor /// \brief The name of the template being specialized. 22447532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Template; 224555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 224640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief - The number of template arguments named in this class 224740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// template specialization. 224855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned NumArgs; 224955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 2250828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor TemplateSpecializationType(ASTContext &Context, 2251828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor TemplateName T, 22527532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 22537532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon); 225455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 22555908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor virtual void Destroy(ASTContext& C); 22565908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor 225755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor friend class ASTContext; // ASTContext creates these 225855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 225955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic: 226040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Determine whether any of the given template arguments are 226140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// dependent. 226240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 22631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned NumArgs); 226440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 2265df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 2266df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// enclosing the template arguments. 2267df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 2268d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned NumArgs, 2269d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor const PrintingPolicy &Policy); 2270df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor 227140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor typedef const TemplateArgument * iterator; 227240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 227340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator begin() const { return getArgs(); } 227440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator end() const; 227540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 22767532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 22777532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName getTemplateName() const { return Template; } 227855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 227940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the template arguments. 22801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *getArgs() const { 228140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 228240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 228340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 228440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the number of template arguments. 228555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 228655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 228755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \brief Retrieve a specific template argument as a type. 228855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \precondition @c isArgType(Arg) 228940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument &getArg(unsigned Idx) const; 229055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 22911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 2292f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 229355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 2294bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return !isDependentType(); } 2295bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getCanonicalTypeInternal(); } 2296bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 229755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2298828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Profile(ID, Template, getArgs(), NumArgs, Context); 229955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 230055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 23017532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 2302828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor const TemplateArgument *Args, unsigned NumArgs, 2303828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor ASTContext &Context); 230455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 23051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 23061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == TemplateSpecialization; 230755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 23087532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 230955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}; 231055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 2311e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// \brief Represents a type that was referred to via a qualified 2312e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// name, e.g., N::M::type. 2313e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// 2314e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the 2315119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// source code, including any nested-name-specifiers. The type itself 2316119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// is always "sugar", used to express what was written in the source 2317119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// code but containing no additional semantic information. 2318e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode { 2319ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested name specifier containing the qualifier. 2320ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *NNS; 2321e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2322e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief The type that this qualified name refers to. 2323e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType; 2324e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2325ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 2326ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType CanonType) 2327ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor : Type(QualifiedName, CanonType, NamedType->isDependentType()), 2328ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NNS(NNS), NamedType(NamedType) { } 2329e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2330e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor friend class ASTContext; // ASTContext creates these 2331e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2332e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic: 2333ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the qualification on this type. 2334ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2335e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2336e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 2337e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType getNamedType() const { return NamedType; } 2338e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2339bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Remove a single level of sugar. 2340bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return getNamedType(); } 2341bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2342bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall /// \brief Returns whether this type directly provides sugar. 2343bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return true; } 2344bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 23451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 2346f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 2347e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2348e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2349ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor Profile(ID, NNS, NamedType); 2350e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 2351e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2352ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 2353ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType NamedType) { 2354ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor ID.AddPointer(NNS); 2355ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NamedType.Profile(ID); 2356ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor } 2357e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 23581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 23591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == QualifiedName; 2360e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 2361e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const QualifiedNameType *T) { return true; } 2362e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor}; 2363e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2364d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// \brief Represents a 'typename' specifier that names a type within 2365d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// a dependent type, e.g., "typename T::type". 2366d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// 2367d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// TypenameType has a very similar structure to QualifiedNameType, 2368d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// which also involves a nested-name-specifier following by a type, 2369d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// and (FIXME!) both can even be prefixed by the 'typename' 2370d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// keyword. However, the two types serve very different roles: 2371d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// QualifiedNameType is a non-semantic type that serves only as sugar 2372d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// to show how a particular type was written in the source 2373d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// code. TypenameType, on the other hand, only occurs when the 2374d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// nested-name-specifier is dependent, such that we cannot resolve 2375d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// the actual type until after instantiation. 2376d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorclass TypenameType : public Type, public llvm::FoldingSetNode { 2377d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The nested name specifier containing the qualifier. 2378d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *NNS; 2379d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 23801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump typedef llvm::PointerUnion<const IdentifierInfo *, 23811734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *> NameType; 23821734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 2383d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The type that this typename specifier refers to. 23841734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name; 2385d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2386d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 2387d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType CanonType) 23881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 23891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(NNS->isDependent() && 2390d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 2391d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2392d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 23931734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 23941734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor QualType CanonType) 23951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 23961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(NNS->isDependent() && 23971734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 23981734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 23991734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 2400d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor friend class ASTContext; // ASTContext creates these 2401d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2402d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic: 2403d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief Retrieve the qualification on this type. 2404d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2405d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 24061734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 24071734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// identifier. 24081734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// 24091734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 24101734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// form of the original typename was terminated by an identifier, 24111734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// e.g., "typename T::type". 24121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo *getIdentifier() const { 24131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Name.dyn_cast<const IdentifierInfo *>(); 24141734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 24151734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 24161734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as a 24171734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// type specialization. 24181734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *getTemplateId() const { 24191734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const TemplateSpecializationType *>(); 24201734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 2421d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 24221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 2423f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 2424d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2425bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2426bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2427bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2428d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2429d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Profile(ID, NNS, Name); 2430d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2431d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2432d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 24331734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name) { 2434d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor ID.AddPointer(NNS); 24351734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor ID.AddPointer(Name.getOpaqueValue()); 2436d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2437d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 24381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 24391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == Typename; 2440d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2441d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static bool classof(const TypenameType *T) { return true; } 2442d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor}; 2443d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2444fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 2445fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// object oriented design. They basically correspond to C++ classes. There 2446fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and 2447fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// qualified interfaces, which are qualified with a protocol list like 2448c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff/// "NSString<NSCopyable, NSAmazing>". 2449c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffclass ObjCInterfaceType : public Type, public llvm::FoldingSetNode { 2450a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *Decl; 2451c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 2452c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // List of protocols for this protocol conforming object type 2453c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // List is sorted on protocol name. No protocol is enterred more than once. 2454c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 2455c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 2456c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ObjCInterfaceType(ObjCInterfaceDecl *D, 24571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCProtocolDecl **Protos, unsigned NumP) : 24581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Type(ObjCInterface, QualType(), /*Dependent=*/false), 2459c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff Decl(D), Protocols(Protos, Protos+NumP) { } 24603536b443bc50d58a79f14fca9b6842541a434854Steve Naroff friend class ASTContext; // ASTContext creates these. 24613536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 2462a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 24631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2464c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 2465c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// interface type, or 0 if there are none. 2466c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff unsigned getNumProtocols() const { return Protocols.size(); } 246714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 2468fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// qual_iterator and friends: this provides access to the (potentially empty) 2469c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// list of protocols qualifying this interface. 2470fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 2471c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff qual_iterator qual_begin() const { return Protocols.begin(); } 2472c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff qual_iterator qual_end() const { return Protocols.end(); } 2473c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff bool qual_empty() const { return Protocols.size() == 0; } 24741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 2476f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 24771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2478bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2479bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2480bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 2481c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 24821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, 2483c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff const ObjCInterfaceDecl *Decl, 2484c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ObjCProtocolDecl **protocols, unsigned NumProtocols); 24851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 24871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ObjCInterface; 24883536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 2489a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 24903536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 24913536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 249214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// ObjCObjectPointerType - Used to represent 'id', 'Interface *', 'id <p>', 249314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// and 'Interface <p> *'. 249414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// 249514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// Duplicate protocols are removed and protocol list is canonicalized to be in 249614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// alphabetical order. 249714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 2498f6265efe7e35fb0fba315da6391368aeee1e57c9Steve Naroff QualType PointeeType; // A builtin or interface type. 24991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 250014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // List of protocols for this protocol conforming object type 250114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // List is sorted on protocol name. No protocol is entered more than once. 250214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 250314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 250414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCObjectPointerType(QualType T, ObjCProtocolDecl **Protos, unsigned NumP) : 250514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff Type(ObjCObjectPointer, QualType(), /*Dependent=*/false), 250614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff PointeeType(T), Protocols(Protos, Protos+NumP) { } 250714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff friend class ASTContext; // ASTContext creates these. 25081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 250914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic: 25108f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // Get the pointee type. Pointee will either be: 25118f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // - a built-in type (for 'id' and 'Class'). 25128f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // - an interface type (for user-defined types). 25138f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // - a TypedefType whose canonical type is an interface (as in 'T' below). 25148f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // For example: typedef NSObject T; T *var; 251514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const { return PointeeType; } 251614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 25171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const ObjCInterfaceType *getInterfaceType() const { 2518183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall return PointeeType->getAs<ObjCInterfaceType>(); 251914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 2520de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// getInterfaceDecl - returns an interface decl for user-defined types. 252114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCInterfaceDecl *getInterfaceDecl() const { 2522de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return getInterfaceType() ? getInterfaceType()->getDecl() : 0; 252314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 2524de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCIdType - true for "id". 252514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const { 25261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && 2527de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff !Protocols.size(); 252814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 2529de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCClassType - true for "Class". 253014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const { 25311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) && 2532de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff !Protocols.size(); 2533de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 2534de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCQualifiedIdType - true for "id <p>". 25351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isObjCQualifiedIdType() const { 25361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && 25371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Protocols.size(); 2538de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 2539de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCQualifiedClassType - true for "Class <p>". 2540470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const { 25411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) && 2542de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff Protocols.size(); 254314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 254414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// qual_iterator and friends: this provides access to the (potentially empty) 254514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// list of protocols qualifying this interface. 254614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 254714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 254814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff qual_iterator qual_begin() const { return Protocols.begin(); } 254914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff qual_iterator qual_end() const { return Protocols.end(); } 255014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool qual_empty() const { return Protocols.size() == 0; } 255114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 255214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 255314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// interface type, or 0 if there are none. 255414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff unsigned getNumProtocols() const { return Protocols.size(); } 255514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 2556bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2557bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2558bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 255914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff void Profile(llvm::FoldingSetNodeID &ID); 256014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType T, 256114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCProtocolDecl **protocols, unsigned NumProtocols); 25621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 256314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const PrintingPolicy &Policy) const; 25641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 25651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ObjCObjectPointer; 256614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 256714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 256814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}; 25691bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 257024fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis/// \brief An ObjC Protocol list that qualifies a type. 257124fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis/// 257224fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis/// This is used only for keeping detailed type source information, it should 257324fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis/// not participate in the semantics of the type system. 257424fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis/// The protocol list is not canonicalized. 257524fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidisclass ObjCProtocolListType : public Type, public llvm::FoldingSetNode { 257624fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis QualType BaseType; 257724fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 257824fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis // List of protocols for this protocol conforming object type. 257924fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 258024fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 258124fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis ObjCProtocolListType(QualType T, ObjCProtocolDecl **Protos, unsigned NumP) : 258224fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis Type(ObjCProtocolList, QualType(), /*Dependent=*/false), 258324fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis BaseType(T), Protocols(Protos, Protos+NumP) { } 258424fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis friend class ASTContext; // ASTContext creates these. 258524fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 258624fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidispublic: 258724fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis QualType getBaseType() const { return BaseType; } 258824fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 258924fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis /// \brief Provides access to the list of protocols qualifying the base type. 259024fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis typedef llvm::SmallVector<ObjCProtocolDecl*, 4>::const_iterator qual_iterator; 259124fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 259224fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis qual_iterator qual_begin() const { return Protocols.begin(); } 259324fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis qual_iterator qual_end() const { return Protocols.end(); } 259424fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis bool qual_empty() const { return Protocols.size() == 0; } 259524fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 259624fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis /// \brief Return the number of qualifying protocols. 259724fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis unsigned getNumProtocols() const { return Protocols.size(); } 259824fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 2599bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall bool isSugared() const { return false; } 2600bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType desugar() const { return QualType(this, 0); } 2601bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 260224fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis void Profile(llvm::FoldingSetNodeID &ID); 260324fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis static void Profile(llvm::FoldingSetNodeID &ID, QualType T, 260424fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis ObjCProtocolDecl **protocols, unsigned NumProtocols); 260524fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis virtual void getAsStringInternal(std::string &InnerString, 260624fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis const PrintingPolicy &Policy) const; 260724fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis static bool classof(const Type *T) { 260824fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis return T->getTypeClass() == ObjCProtocolList; 260924fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis } 261024fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis static bool classof(const ObjCProtocolListType *) { return true; } 261124fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis}; 261224fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 26130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers. 26140953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers { 26150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ASTContext *Context; 26160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 26170953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic: 26180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector(Qualifiers Qs = Qualifiers()) 26190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Qualifiers(Qs), Context(0) {} 26200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector(ASTContext &Context, Qualifiers Qs = Qualifiers()) 26210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall : Qualifiers(Qs), Context(&Context) {} 26220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 26230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void setContext(ASTContext &C) { Context = &C; } 26240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 26250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Collect any qualifiers on the given type and return an 26260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// unqualified type. 26270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *strip(QualType QT) { 26280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addFastQualifiers(QT.getFastQualifiers()); 26290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (QT.hasNonFastQualifiers()) { 26300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = QT.getExtQualsUnsafe(); 26310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Context = &EQ->getContext(); 26320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall addQualifiers(EQ->getQualifiers()); 26330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getBaseType(); 26340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 26350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QT.getTypePtrUnsafe(); 26360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 26370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 26380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Apply the collected qualifiers to the given type. 26390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType apply(QualType QT) const; 26400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 26410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall /// Apply the collected qualifiers to the given type. 26420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType apply(const Type* T) const; 26430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 26440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}; 26450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 26460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2647611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 26485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26490953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeConst() { 26500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeFastQualifiers(Qualifiers::Const); 26510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 26520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 26530953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeRestrict() { 26540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeFastQualifiers(Qualifiers::Restrict); 26550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 26560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 26570953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeVolatile() { 26580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qc; 26590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *Ty = Qc.strip(*this); 26600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Qc.hasVolatile()) { 26610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qc.removeVolatile(); 26620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall *this = Qc.apply(Ty); 26630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 26640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 26650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 26660953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeCVRQualifiers(unsigned Mask) { 26676b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits"); 26680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 26690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Fast path: we don't need to touch the slow qualifiers. 26700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!(Mask & ~Qualifiers::FastMask)) { 26710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall removeFastQualifiers(Mask); 26720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return; 26730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 26740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 26750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qc; 26760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *Ty = Qc.strip(*this); 26770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qc.removeCVRQualifiers(Mask); 26780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall *this = Qc.apply(Ty); 2679ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 2680ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 2681ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 2682ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 26830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (hasNonFastQualifiers()) { 26840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = getExtQualsUnsafe(); 26850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (EQ->hasAddressSpace()) 26860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getAddressSpace(); 26870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 26880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 26894243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 26900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (CT.hasNonFastQualifiers()) { 26910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = CT.getExtQualsUnsafe(); 26920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (EQ->hasAddressSpace()) 26930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getAddressSpace(); 26940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 26950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 26964243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2697c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT->getElementType().getAddressSpace(); 26984243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 26998e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman return RT->getAddressSpace(); 2700ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return 0; 2701ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 2702611c1fff195d32df97706e0920c92468b2509900Chris Lattner 2703d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 27040953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const { 27050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (hasNonFastQualifiers()) { 27060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = getExtQualsUnsafe(); 27070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (EQ->hasObjCGCAttr()) 27080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getObjCGCAttr(); 27090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 27100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2711d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 27120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (CT.hasNonFastQualifiers()) { 27130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const ExtQuals *EQ = CT.getExtQualsUnsafe(); 27140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (EQ->hasObjCGCAttr()) 27150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return EQ->getObjCGCAttr(); 27160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 27170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2718d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2719d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return AT->getElementType().getObjCGCAttr(); 2720183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *PT = CT->getAs<ObjCObjectPointerType>()) 27211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return PT->getPointeeType().getObjCGCAttr(); 2722ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian // We most look at all pointer types, not just pointer to interface types. 2723ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian if (const PointerType *PT = CT->getAs<PointerType>()) 27241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return PT->getPointeeType().getObjCGCAttr(); 27250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qualifiers::GCNone; 2726d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 27272455636163fdd18581d7fdae816433f886d88213Mike Stump 2728ae92140b542d5c1c096e39e74e59526184819b30Mike Stump /// getNoReturnAttr - Returns true if the type has the noreturn attribute, 2729ae92140b542d5c1c096e39e74e59526184819b30Mike Stump /// false otherwise. 27302455636163fdd18581d7fdae816433f886d88213Mike Stumpinline bool QualType::getNoReturnAttr() const { 27312455636163fdd18581d7fdae816433f886d88213Mike Stump QualType CT = getTypePtr()->getCanonicalTypeInternal(); 27326217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getTypePtr()->getAs<PointerType>()) { 2733183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>()) 27342455636163fdd18581d7fdae816433f886d88213Mike Stump return FT->getNoReturnAttr(); 2735183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall } else if (const FunctionType *FT = getTypePtr()->getAs<FunctionType>()) 27362455636163fdd18581d7fdae816433f886d88213Mike Stump return FT->getNoReturnAttr(); 27372455636163fdd18581d7fdae816433f886d88213Mike Stump 27382455636163fdd18581d7fdae816433f886d88213Mike Stump return false; 27392455636163fdd18581d7fdae816433f886d88213Mike Stump} 27401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2741e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 2742e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 2743e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and 2744e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile 2745e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int". 2746e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 27470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // FIXME: work on arbitrary qualifiers 2748e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 2749e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 2750ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 2751ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 2752e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 2753e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 2754e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 2755e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 2756e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile 2757e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 2758e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int". 2759e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 27600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // FIXME: work on arbitrary qualifiers 2761e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 2762e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 2763ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 2764ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 2765e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 2766e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 2767e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 2768e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 2769e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const 2770e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 2771e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6: 2772e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 2773e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 2774e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 2775e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// analysis, the expression designates the object or function 2776e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 2777e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const { 27786217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 2779e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return RefType->getPointeeType(); 2780e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor else 2781e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return *this; 2782e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 2783e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 27842b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 27856217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 2786183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall return PT->getPointeeType()->getAs<ObjCInterfaceType>(); 27872b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return 0; 27882b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner} 27891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2790c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// NOTE: All of these methods use "getUnqualifiedType" to strip off address 2791c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// space qualifiers if present. 2792611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 2793ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 2794611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2795611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 27961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return isa<PointerType>(CanonicalType.getUnqualifiedType()); 2797611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 279858f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const { 279958f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff return isPointerType() || isObjCObjectPointerType(); 280058f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff} 28015618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const { 28021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return isa<BlockPointerType>(CanonicalType.getUnqualifiedType()); 28035618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 2804bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const { 2805bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 2806bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 28077c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const { 28087c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()); 28097c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 28107c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const { 28117c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()); 28127c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 2813498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 28146217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType* T = getAs<PointerType>()) 2815498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 2816498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 2817498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 2818498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 2819f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const { 2820f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 2821f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 2822f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 28236217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const MemberPointerType* T = getAs<MemberPointerType>()) 2824f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getPointeeType()->isFunctionType(); 2825f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl else 2826f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return false; 2827f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 2828611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 2829ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 2830611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2831c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const { 2832c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 2833c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 2834c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const { 2835c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 2836c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 2837c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const { 2838c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 2839c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 2840898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const { 2841898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 2842898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 2843611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 2844ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<RecordType>(CanonicalType.getUnqualifiedType()); 2845611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2846f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const { 2847c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 2848f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner} 2849611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 2850ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<VectorType>(CanonicalType.getUnqualifiedType()); 2851611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2852213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const { 2853213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 2854611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2855d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const { 2856d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return isa<ObjCObjectPointerType>(CanonicalType.getUnqualifiedType()); 2857d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 2858a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCInterfaceType() const { 2859c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 2860368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 2861a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 2862183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 2863d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT->isObjCQualifiedIdType(); 2864d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return false; 2865d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 2866470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const { 2867183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 2868470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return OPT->isObjCQualifiedClassType(); 2869470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return false; 2870470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff} 287114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const { 2872183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 287314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCIdType(); 287414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 287514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 287614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const { 2877183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 287814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCClassType(); 287914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 288014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 2881de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const { 2882de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return isObjCIdType() || isObjCClassType(); 2883de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff} 288472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const { 288572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 288672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor} 288772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2888e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 2889183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 2890e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 2891e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return true; 2892e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return false; 2893e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar} 2894e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 2895063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define 2896063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator. 2897063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const { 2898063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 2899904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor} 2900904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 29018958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 29028958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 29031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isObjCInterfaceType() || isObjCObjectPointerType() || 29046e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl isObjCQualifiedInterfaceType() || isNullPtrType()); 29058958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar} 29068958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 2907820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 29081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return (isObjCInterfaceType() || isObjCObjectPointerType() || 2909820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian isObjCQualifiedInterfaceType()); 2910820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian} 2911820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 291222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 291322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<. 291422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 291522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner QualType T) { 291622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 291722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner Diagnostic::ak_qualtype); 291822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner return DB; 291922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner} 29201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29211a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'. 29221a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const { 29231a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If this is directly a T type, return it. 29241a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek if (const T *Ty = dyn_cast<T>(this)) 29251a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return Ty; 29261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29271a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If the canonical form of this type isn't the right kind, reject it. 29280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<T>(CanonicalType)) 29291a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return 0; 29301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If this is a typedef for the type, strip the typedef off without 29321a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // losing all typedef information. 2933bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<T>(getUnqualifiedDesugaredType()); 29341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 293522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner 29365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 29375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 29385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2939