Type.h revision 1b60285d38b1d9c443b897cf42d85a7cfee54309
14b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===// 24b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner// 34b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner// The LLVM Compiler Infrastructure 44b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner// 5959e5be188a505881058777f35abaaa3fe2de40bChris Lattner// This file is distributed under the University of Illinois Open Source 6959e5be188a505881058777f35abaaa3fe2de40bChris Lattner// License. See LICENSE.TXT for details. 74b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner// 84b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//===----------------------------------------------------------------------===// 94b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner// 104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner// This file defines the Type interface and subclasses. 114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner// 124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//===----------------------------------------------------------------------===// 134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#ifndef LLVM_CLANG_AST_TYPE_H 154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#define LLVM_CLANG_AST_TYPE_H 164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 17da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner#include "clang/Basic/Diagnostic.h" 1877da58034d00866f3261d2c657a5823578f73028Douglas Gregor#include "clang/Basic/IdentifierTable.h" 19b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor#include "clang/Basic/Linkage.h" 20734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor#include "clang/AST/NestedNameSpecifier.h" 21dd13e8468462e60971487bcd5915419762dab814Douglas Gregor#include "clang/AST/TemplateName.h" 224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#include "llvm/Support/Casting.h" 23cfe6ae592450d8466b4d78b59ff4526266549a9aDouglas Gregor#include "llvm/Support/type_traits.h" 2483c13010359c33354c581acee65d0c986a75247eSteve Naroff#include "llvm/ADT/APSInt.h" 2548a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner#include "llvm/ADT/FoldingSet.h" 2648a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner#include "llvm/ADT/PointerIntPair.h" 2777da58034d00866f3261d2c657a5823578f73028Douglas Gregor#include "llvm/ADT/PointerUnion.h" 28dd13e8468462e60971487bcd5915419762dab814Douglas Gregor 294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::isa; 304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::cast; 314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::cast_or_null; 324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::dyn_cast; 334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::dyn_cast_or_null; 34451b7b9a60208869cf5d6d958134cb104343949fJohn McCallnamespace clang { 35451b7b9a60208869cf5d6d958134cb104343949fJohn McCall enum { 36451b7b9a60208869cf5d6d958134cb104343949fJohn McCall TypeAlignmentInBits = 3, 37451b7b9a60208869cf5d6d958134cb104343949fJohn McCall TypeAlignment = 1 << TypeAlignmentInBits 38451b7b9a60208869cf5d6d958134cb104343949fJohn McCall }; 39e38592f880f425a6d9ea856a81703522a8ae345bChris Lattner class Type; 40e38592f880f425a6d9ea856a81703522a8ae345bChris Lattner class ExtQuals; 41e38592f880f425a6d9ea856a81703522a8ae345bChris Lattner class QualType; 42451b7b9a60208869cf5d6d958134cb104343949fJohn McCall} 434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 44cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattnernamespace llvm { 45cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner template <typename T> 46d776b2da9bd694c41f1506e152aeb35d1babeba6Chris Lattner class PointerLikeTypeTraits; 478813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner template<> 488813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner class PointerLikeTypeTraits< ::clang::Type*> { 498813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner public: 508813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 518813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner static inline ::clang::Type *getFromVoidPointer(void *P) { 528813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner return static_cast< ::clang::Type*>(P); 538813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner } 54451b7b9a60208869cf5d6d958134cb104343949fJohn McCall enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 558813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner }; 563ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall template<> 573ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall class PointerLikeTypeTraits< ::clang::ExtQuals*> { 583ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall public: 593ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; } 603ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static inline ::clang::ExtQuals *getFromVoidPointer(void *P) { 613ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return static_cast< ::clang::ExtQuals*>(P); 623ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 63451b7b9a60208869cf5d6d958134cb104343949fJohn McCall enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 643ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall }; 65e38592f880f425a6d9ea856a81703522a8ae345bChris Lattner 66e38592f880f425a6d9ea856a81703522a8ae345bChris Lattner template <> 67e38592f880f425a6d9ea856a81703522a8ae345bChris Lattner struct isPodLike<clang::QualType> { static const bool value = true; }; 68cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner} 69cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner 704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace clang { 714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class ASTContext; 724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class TypedefDecl; 738e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor class TemplateDecl; 74dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor class TemplateTypeParmDecl; 75279272e63b321f89c8fa0bb198acd3a834459aebDouglas Gregor class NonTypeTemplateParmDecl; 76dd13e8468462e60971487bcd5915419762dab814Douglas Gregor class TemplateTemplateParmDecl; 774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class TagDecl; 784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class RecordDecl; 79ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis class CXXRecordDecl; 804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class EnumDecl; 8164be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek class FieldDecl; 8242730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek class ObjCInterfaceDecl; 8342730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek class ObjCProtocolDecl; 8442730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek class ObjCMethodDecl; 85caf383ae337966d67380b6b161fab17ec2b53d04John McCall class UnresolvedUsingTypenameDecl; 864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class Expr; 87718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek class Stmt; 884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class SourceLocation; 89fce813e3159a67a57a03cdca45ac4e10d4cffac3Ted Kremenek class StmtIteratorBase; 90f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor class TemplateArgument; 91588613178e3a10e2b840c8f4db9e058f2fec0005John McCall class TemplateArgumentLoc; 92ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall class TemplateArgumentListInfo; 93734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor class QualifiedNameType; 94198e8e46d0bfe535f044df35d1b87da86a148a84Daniel Dunbar struct PrintingPolicy; 954fa58905062efa6a12137b1983a1367220182a20Douglas Gregor 964fa58905062efa6a12137b1983a1367220182a20Douglas Gregor // Provide forward declarations for all of the *Type classes 974fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define TYPE(Class, Base) class Class##Type; 984fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#include "clang/AST/TypeNodes.def" 997555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 1003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// Qualifiers - The collection of all-type qualifiers we support. 1013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// Clang supports five independent qualifiers: 1023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// * C99: const, volatile, and restrict 1033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// * Embedded C (TR18037): address spaces 1043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// * Objective C: the GC attributes (none, weak, or strong) 1053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallclass Qualifiers { 1064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 1073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 1084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Const = 0x1, 1094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Restrict = 0x2, 1104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Volatile = 0x4, 1113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall CVRMask = Const | Volatile | Restrict 1124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 11325cf760b54d3b88633827501013bc51a29b28abaMike Stump 1143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall enum GC { 115af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian GCNone = 0, 116af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian Weak, 117af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian Strong 118af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian }; 119fda7da669298c7428a1c963013d9a8c71cbedbc5John McCall 1203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall enum { 1213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// The maximum supported address space number. 1223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// 24 bits should be enough for anyone. 1233ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall MaxAddressSpace = 0xffffffu, 1243ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// The width of the "fast" qualifier mask. 1263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall FastWidth = 2, 1273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// The fast qualifier mask. 1293ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall FastMask = (1 << FastWidth) - 1 1303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall }; 1313ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers() : Mask(0) {} 1333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1343ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static Qualifiers fromFastMask(unsigned Mask) { 1353ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Qs; 1363ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qs.addFastQualifiers(Mask); 1373ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Qs; 1383ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1393ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static Qualifiers fromCVRMask(unsigned CVR) { 1413ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Qs; 1423ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qs.addCVRQualifiers(CVR); 1433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Qs; 1443ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1453ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1463ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Deserialize qualifiers from an opaque representation. 1473ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static Qualifiers fromOpaqueValue(unsigned opaque) { 1483ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Qs; 1493ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qs.Mask = opaque; 1503ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Qs; 1513ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1523ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1533ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Serialize these qualifiers into an opaque representation. 1543ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getAsOpaqueValue() const { 1553ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Mask; 1563ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1573ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1583ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasConst() const { return Mask & Const; } 1593ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setConst(bool flag) { 1603ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask = (Mask & ~Const) | (flag ? Const : 0); 1613ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1623ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeConst() { Mask &= ~Const; } 1633ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addConst() { Mask |= Const; } 1643ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1653ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasVolatile() const { return Mask & Volatile; } 1663ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setVolatile(bool flag) { 1673ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask = (Mask & ~Volatile) | (flag ? Volatile : 0); 1683ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1693ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeVolatile() { Mask &= ~Volatile; } 1703ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addVolatile() { Mask |= Volatile; } 1713ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1723ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasRestrict() const { return Mask & Restrict; } 1733ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setRestrict(bool flag) { 1743ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask = (Mask & ~Restrict) | (flag ? Restrict : 0); 1753ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1763ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeRestrict() { Mask &= ~Restrict; } 1773ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addRestrict() { Mask |= Restrict; } 1783ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1793ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasCVRQualifiers() const { return getCVRQualifiers(); } 1803ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getCVRQualifiers() const { return Mask & CVRMask; } 1813ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setCVRQualifiers(unsigned mask) { 1823ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 1833ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask = (Mask & ~CVRMask) | mask; 1843ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1853ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeCVRQualifiers(unsigned mask) { 1863ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 1873ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask &= ~mask; 1883ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1893ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeCVRQualifiers() { 1903ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeCVRQualifiers(CVRMask); 1913ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1923ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addCVRQualifiers(unsigned mask) { 1933ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 1943ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask |= mask; 1953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1963ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1973ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasObjCGCAttr() const { return Mask & GCAttrMask; } 1983ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); } 1993ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setObjCGCAttr(GC type) { 2003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift); 2013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeObjCGCAttr() { setObjCGCAttr(GCNone); } 2033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addObjCGCAttr(GC type) { 2043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(type); 2053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall setObjCGCAttr(type); 2063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasAddressSpace() const { return Mask & AddressSpaceMask; } 2093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; } 2103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setAddressSpace(unsigned space) { 2113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(space <= MaxAddressSpace); 2123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask = (Mask & ~AddressSpaceMask) 2133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall | (((uint32_t) space) << AddressSpaceShift); 2143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeAddressSpace() { setAddressSpace(0); } 2163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addAddressSpace(unsigned space) { 2173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(space); 2183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall setAddressSpace(space); 2193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Fast qualifiers are those that can be allocated directly 2223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // on a QualType object. 2233ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasFastQualifiers() const { return getFastQualifiers(); } 2243ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getFastQualifiers() const { return Mask & FastMask; } 2253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setFastQualifiers(unsigned mask) { 2263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask = (Mask & ~FastMask) | mask; 2283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2293ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeFastQualifiers(unsigned mask) { 2303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2313ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask &= ~mask; 2323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeFastQualifiers() { 2343ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeFastQualifiers(FastMask); 2353ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2363ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addFastQualifiers(unsigned mask) { 2373ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2383ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask |= mask; 2393ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2413ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// hasNonFastQualifiers - Return true if the set contains any 2423ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// qualifiers which require an ExtQuals node to be allocated. 2433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasNonFastQualifiers() const { return Mask & ~FastMask; } 2443ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers getNonFastQualifiers() const { 2453ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Quals = *this; 2463ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Quals.setFastQualifiers(0); 2473ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Quals; 2483ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2493ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2503ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// hasQualifiers - Return true if the set contains any qualifiers. 2513ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasQualifiers() const { return Mask; } 2523ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool empty() const { return !Mask; } 2533ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2543ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// \brief Add the qualifiers from the given set to this set. 2553ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addQualifiers(Qualifiers Q) { 2563ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // If the other set doesn't have any non-boolean qualifiers, just 2573ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // bit-or it in. 2583ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (!(Q.Mask & ~CVRMask)) 2593ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask |= Q.Mask; 2603ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall else { 2613ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask |= (Q.Mask & CVRMask); 2623ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (Q.hasAddressSpace()) 2633ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall addAddressSpace(Q.getAddressSpace()); 2643ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (Q.hasObjCGCAttr()) 2653ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall addObjCGCAttr(Q.getObjCGCAttr()); 2663ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2673ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2683ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2693ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool operator==(Qualifiers Other) const { return Mask == Other.Mask; } 2703ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; } 2713ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2723ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall operator bool() const { return hasQualifiers(); } 2733ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2743ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers &operator+=(Qualifiers R) { 2753ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall addQualifiers(R); 2763ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return *this; 2773ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2783ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2793ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Union two qualifier sets. If an enumerated qualifier appears 2803ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // in both sets, use the one from the right. 2813ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall friend Qualifiers operator+(Qualifiers L, Qualifiers R) { 2823ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall L += R; 2833ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return L; 2843ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2853ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2863ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall std::string getAsString() const; 2873ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall std::string getAsString(const PrintingPolicy &Policy) const { 2883ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall std::string Buffer; 2893ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getAsStringInternal(Buffer, Policy); 2903ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Buffer; 2913ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2923ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const; 2933ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2943ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 2953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ID.AddInteger(Mask); 2963ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2973ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2983ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallprivate: 2993ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // bits: |0 1 2|3 .. 4|5 .. 31| 3013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // |C R V|GCAttr|AddrSpace| 3023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall uint32_t Mask; 3033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static const uint32_t GCAttrMask = 0x18; 3053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static const uint32_t GCAttrShift = 3; 3063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask); 3073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static const uint32_t AddressSpaceShift = 5; 3083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall}; 3093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// ExtQuals - We can encode up to three bits in the low bits of a 3123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// type pointer, but there are many more type qualifiers that we want 3133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// to be able to apply to an arbitrary type. Therefore we have this 3143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// struct, intended to be heap-allocated and used by QualType to 3153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// store qualifiers. 3163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// 3173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// The current design tags the 'const' and 'restrict' qualifiers in 3183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// two low bits on the QualType pointer; a third bit records whether 3193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// the pointer is an ExtQuals node. 'const' was chosen because it is 3203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// orders of magnitude more common than the other two qualifiers, in 3213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// both library and user code. It's relatively rare to see 3223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// 'restrict' in user code, but many standard C headers are saturated 3233ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// with 'restrict' declarations, so that representing them efficiently 3243ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// is a critical goal of this representation. 3253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallclass ExtQuals : public llvm::FoldingSetNode { 3263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // NOTE: changing the fast qualifiers should be straightforward as 3273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // long as you don't make 'const' non-fast. 3283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // 1. Qualifiers: 3293ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ). 3303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Fast qualifiers must occupy the low-order bits. 3313ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // b) Update Qualifiers::FastWidth and FastMask. 3323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // 2. QualType: 3333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // a) Update is{Volatile,Restrict}Qualified(), defined inline. 3343ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // b) Update remove{Volatile,Restrict}, defined near the end of 3353ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // this header. 3363ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // 3. ASTContext: 3373ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // a) Update get{Volatile,Restrict}Type. 3383ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3393ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Context - the context to which this set belongs. We save this 3403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// here so that QualifierCollector can use it to reapply extended 3413ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// qualifiers to an arbitrary type without requiring a context to 3423ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// be pushed through every single API dealing with qualifiers. 3433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ASTContext& Context; 3443ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3453ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// BaseType - the underlying type that this qualifies 3463ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *BaseType; 3473ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3483ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Quals - the immutable set of qualifiers applied by this 3493ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// node; always contains extended qualifiers. 3503ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Quals; 3513ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3523ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallpublic: 3533ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ExtQuals(ASTContext& Context, const Type *Base, Qualifiers Quals) 3543ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Context(Context), BaseType(Base), Quals(Quals) 3553ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall { 3563ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(Quals.hasNonFastQualifiers() 3573ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall && "ExtQuals created with no fast qualifiers"); 3583ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!Quals.hasFastQualifiers() 3593ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall && "ExtQuals created with fast qualifiers"); 3603ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 3613ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3623ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers getQualifiers() const { return Quals; } 3633ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3643ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasVolatile() const { return Quals.hasVolatile(); } 3653ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3663ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); } 3673ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); } 3683ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3693ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasAddressSpace() const { return Quals.hasAddressSpace(); } 3703ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getAddressSpace() const { return Quals.getAddressSpace(); } 3713ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3723ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *getBaseType() const { return BaseType; } 37325cf760b54d3b88633827501013bc51a29b28abaMike Stump 3743ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ASTContext &getContext() const { return Context; } 3753ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3763ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallpublic: 3773ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 3783ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Profile(ID, getBaseType(), Quals); 3793ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 3803ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, 3813ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *BaseType, 3823ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Quals) { 3833ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!"); 3843ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ID.AddPointer(BaseType); 3853ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Quals.Profile(ID); 3863ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 3873ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall}; 3883ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 38931cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor/// CallingConv - Specifies the calling convention that a function uses. 39031cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregorenum CallingConv { 39131cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CC_Default, 39231cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CC_C, // __attribute__((cdecl)) 39331cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CC_X86StdCall, // __attribute__((stdcall)) 39431cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CC_X86FastCall // __attribute__((fastcall)) 39531cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor}; 39631cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor 3973ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3983ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on 3993ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// their own: instead each reference to a type stores the qualifiers. This 4003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for 4013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// example we only need one for 'int', 'const int', 'volatile int', 4023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// 'const volatile int', etc). 4033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// 4043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// As an added efficiency bonus, instead of making this a pair, we 4053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// just store the two bits we care about in the low bits of the 4063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// pointer. To handle the packing/unpacking, we make QualType be a 4073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// simple wrapper class that acts like a smart pointer. A third bit 4083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// indicates whether there are extended qualifiers present, in which 4093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// case the pointer points to a special structure. 4103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallclass QualType { 4113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Thankfully, these are efficiently composable. 4123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>, 4133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers::FastWidth> Value; 4143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 4153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *getExtQualsUnsafe() const { 4163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Value.getPointer().get<const ExtQuals*>(); 4173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 4183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 4193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *getTypePtrUnsafe() const { 4203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Value.getPointer().get<const Type*>(); 4213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 4223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 4234f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor QualType getUnqualifiedTypeSlow() const; 4244f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 4253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall friend class QualifierCollector; 4263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallpublic: 42748a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner QualType() {} 42825cf760b54d3b88633827501013bc51a29b28abaMike Stump 42948a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner QualType(const Type *Ptr, unsigned Quals) 4303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Value(Ptr, Quals) {} 4313ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType(const ExtQuals *Ptr, unsigned Quals) 4323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Value(Ptr, Quals) {} 4333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 434c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor unsigned getLocalFastQualifiers() const { return Value.getInt(); } 435c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); } 4364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 4373ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Retrieves a pointer to the underlying (unqualified) type. 4383ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// This should really return a const Type, but it's not worth 4393ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// changing all the users right now. 4403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Type *getTypePtr() const { 441c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalNonFastQualifiers()) 4423ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return const_cast<Type*>(getExtQualsUnsafe()->getBaseType()); 4433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return const_cast<Type*>(getTypePtrUnsafe()); 4443ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 44525cf760b54d3b88633827501013bc51a29b28abaMike Stump 44648a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 4474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static QualType getFromOpaquePtr(void *Ptr) { 4484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType T; 44948a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner T.Value.setFromOpaqueValue(Ptr); 4504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T; 4514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 45225cf760b54d3b88633827501013bc51a29b28abaMike Stump 4534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Type &operator*() const { 4544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return *getTypePtr(); 4554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 4564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 4574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Type *operator->() const { 4584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return getTypePtr(); 4594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 46025cf760b54d3b88633827501013bc51a29b28abaMike Stump 4617480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall bool isCanonical() const; 4624ea8425c9601895fa137f877bc784f75f20adac6John McCall bool isCanonicalAsParam() const; 4637480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall 4644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isNull - Return true if this QualType doesn't point to a type yet. 4654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isNull() const { 4663ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Value.getPointer().isNull(); 4674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 4684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 469c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has the 470c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// "const" qualifier set, without looking through typedefs that may have 471c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// added "const" at a different level. 472c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool isLocalConstQualified() const { 473c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Const); 4743ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 475c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 476c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this type is const-qualified. 4774f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor bool isConstQualified() const; 478c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 479c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has the 480c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// "restrict" qualifier set, without looking through typedefs that may have 481c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// added "restrict" at a different level. 482c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool isLocalRestrictQualified() const { 483c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Restrict); 484c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor } 485c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 486c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this type is restrict-qualified. 4874f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor bool isRestrictQualified() const; 488c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 489c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has the 490c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// "volatile" qualifier set, without looking through typedefs that may have 491c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// added "volatile" at a different level. 492c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool isLocalVolatileQualified() const { 493c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return (hasLocalNonFastQualifiers() && getExtQualsUnsafe()->hasVolatile()); 4944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 4953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 496c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this type is volatile-qualified. 4974f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor bool isVolatileQualified() const; 498c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 499c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has any 500c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// qualifiers, without looking through any typedefs that might add 501c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// qualifiers at a different level. 502c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool hasLocalQualifiers() const { 503c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return getLocalFastQualifiers() || hasLocalNonFastQualifiers(); 5043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 506c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this type has any qualifiers. 5074f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor bool hasQualifiers() const; 508c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 509c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has any 510c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType 511c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// instance. 512c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool hasLocalNonFastQualifiers() const { 513c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return Value.getPointer().is<const ExtQuals*>(); 5143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 516c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Retrieve the set of qualifiers local to this particular QualType 517c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// instance, not including any qualifiers acquired through typedefs or 518c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// other sugar. 519c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor Qualifiers getLocalQualifiers() const { 5203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Quals; 521c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalNonFastQualifiers()) 5223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Quals = getExtQualsUnsafe()->getQualifiers(); 523c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor Quals.addFastQualifiers(getLocalFastQualifiers()); 5243ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Quals; 5253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 527c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Retrieve the set of qualifiers applied to this type. 5284f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor Qualifiers getQualifiers() const; 529c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 530c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 531c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// local to this particular QualType instance, not including any qualifiers 532c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// acquired through typedefs or other sugar. 533c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor unsigned getLocalCVRQualifiers() const { 534c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor unsigned CVR = getLocalFastQualifiers(); 535c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (isLocalVolatileQualified()) 536c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor CVR |= Qualifiers::Volatile; 5373ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return CVR; 5384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 539a7bbf567dac9dfd58f12c9ff14584d64104694f3Nuno Lopes 540c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 541c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// applied to this type. 5424f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor unsigned getCVRQualifiers() const; 5436d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth 5446d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 5456d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth /// applied to this type, looking through any number of unqualified array 5466d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth /// types to their element types' qualifiers. 5476d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned getCVRQualifiersThroughArrayTypes() const; 5486d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth 5490afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isConstant(ASTContext& Ctx) const { 5500afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall return QualType::isConstant(*this, Ctx); 5510afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall } 55225cf760b54d3b88633827501013bc51a29b28abaMike Stump 5533ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Don't promise in the API that anything besides 'const' can be 5543ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // easily added. 5553ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 5563ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// addConst - add the specified type qualifier to this QualType. 5573ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addConst() { 5583ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall addFastQualifiers(Qualifiers::Const); 5593ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5603ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType withConst() const { 5613ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return withFastQualifiers(Qualifiers::Const); 5623ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5633ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 5643ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addFastQualifiers(unsigned TQs) { 5653ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(TQs & ~Qualifiers::FastMask) 5663ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall && "non-fast qualifier bits set in mask!"); 5673ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Value.setInt(Value.getInt() | TQs); 5683ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5693ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 570c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor // FIXME: The remove* functions are semantically broken, because they might 571c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor // not remove a qualifier stored on a typedef. Most of the with* functions 572c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor // have the same problem. 5733ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeConst(); 5743ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeVolatile(); 5753ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeRestrict(); 5763ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeCVRQualifiers(unsigned Mask); 5773ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 5783ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeFastQualifiers() { Value.setInt(0); } 5793ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeFastQualifiers(unsigned Mask) { 5803ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers"); 5813ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Value.setInt(Value.getInt() & ~Mask); 5823ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5843ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Creates a type with the given qualifiers in addition to any 5853ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // qualifiers already on this type. 5863ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType withFastQualifiers(unsigned TQs) const { 5873ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType T = *this; 5883ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall T.addFastQualifiers(TQs); 5893ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return T; 5903ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 59193eb82549eec82d75ce5dd3afbeeaf6fdb0e2a27Sanjiv Gupta 5923ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Creates a type with exactly the given fast qualifiers, removing 5933ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // any existing fast qualifiers. 5943ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType withExactFastQualifiers(unsigned TQs) const { 5953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return withoutFastQualifiers().withFastQualifiers(TQs); 5964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 5973ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 5983ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Removes fast qualifiers, but leaves any extended qualifiers in place. 5993ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType withoutFastQualifiers() const { 6003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType T = *this; 6013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall T.removeFastQualifiers(); 6023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return T; 603a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner } 6044b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis 605c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Return this type with all of the instance-specific qualifiers 606c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// removed, but without removing any qualifiers that may have been applied 607c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// through typedefs. 608c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); } 60925cf760b54d3b88633827501013bc51a29b28abaMike Stump 610c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Return the unqualified form of the given type, which might be 611c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// desugared to eliminate qualifiers introduced via typedefs. 6124f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor QualType getUnqualifiedType() const { 6134f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor QualType T = getLocalUnqualifiedType(); 6144f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor if (!T.hasQualifiers()) 6154f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return T; 6164f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 6174f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return getUnqualifiedTypeSlow(); 618c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor } 619c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 6203fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 6213fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 6223fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor QualType getNonReferenceType() const; 62325cf760b54d3b88633827501013bc51a29b28abaMike Stump 624835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 625835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 626835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 627835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 628835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 629835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// concrete. 6303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// 6313ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Qualifiers are left in place. 6320afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType getDesugaredType() const { 6330afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall return QualType::getDesugaredType(*this); 6340afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall } 6356573cfd6fc32eab0b696cfc318bb21f4e3933f35Douglas Gregor 6364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// operator==/!= - Indicate whether the specified types and qualifiers are 6374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// identical. 638cfe6ae592450d8466b4d78b59ff4526266549a9aDouglas Gregor friend bool operator==(const QualType &LHS, const QualType &RHS) { 639cfe6ae592450d8466b4d78b59ff4526266549a9aDouglas Gregor return LHS.Value == RHS.Value; 6404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 641cfe6ae592450d8466b4d78b59ff4526266549a9aDouglas Gregor friend bool operator!=(const QualType &LHS, const QualType &RHS) { 642cfe6ae592450d8466b4d78b59ff4526266549a9aDouglas Gregor return LHS.Value != RHS.Value; 6434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6443bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor std::string getAsString() const; 6453bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor 6463bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor std::string getAsString(const PrintingPolicy &Policy) const { 6474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner std::string S; 6483bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor getAsStringInternal(S, Policy); 6494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return S; 6504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6517099c789f054f1e7480f498d60aa94b0326c285fChris Lattner void getAsStringInternal(std::string &Str, 6527099c789f054f1e7480f498d60aa94b0326c285fChris Lattner const PrintingPolicy &Policy) const; 65325cf760b54d3b88633827501013bc51a29b28abaMike Stump 654a55e321bd645398b514e246981c04a4889ee2472Chris Lattner void dump(const char *s) const; 655a55e321bd645398b514e246981c04a4889ee2472Chris Lattner void dump() const; 65625cf760b54d3b88633827501013bc51a29b28abaMike Stump 6579d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 6589d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 6599d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek } 6604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6612a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb /// getAddressSpace - Return the address space of this type. 6622a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb inline unsigned getAddressSpace() const; 66325cf760b54d3b88633827501013bc51a29b28abaMike Stump 664af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 6653ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall inline Qualifiers::GC getObjCGCAttr() const; 66685534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian 66785534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 66885534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian bool isObjCGCWeak() const { 6693ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return getObjCGCAttr() == Qualifiers::Weak; 67085534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian } 67185534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian 67285534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 67385534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian bool isObjCGCStrong() const { 6743ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return getObjCGCAttr() == Qualifiers::Strong; 67585534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian } 6761bb806498909a43a7829edb21c42606335d69694Mike Stump 6770f95d329cc0ba37faa0f3d522991a581a407482cMike Stump /// getNoReturnAttr - Returns true if the type has the noreturn attribute, 6780f95d329cc0ba37faa0f3d522991a581a407482cMike Stump /// false otherwise. 6791bb806498909a43a7829edb21c42606335d69694Mike Stump bool getNoReturnAttr() const; 6800afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 68131cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor /// getCallConv - Returns the calling convention of the type if the type 68231cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor /// is a function type, CC_Default otherwise. 68331cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CallingConv getCallConv() const; 68431cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor 6850afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCallprivate: 6860afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall // These methods are implemented in a separate translation unit; 6870afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall // "static"-ize them to avoid creating temporary QualTypes in the 6880afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall // caller. 6890afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall static bool isConstant(QualType T, ASTContext& Ctx); 6900afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall static QualType getDesugaredType(QualType T); 6914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 6924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner} // end clang. 6944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace llvm { 6964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 6974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// to a specific Type class. 6984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnertemplate<> struct simplify_type<const ::clang::QualType> { 6994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner typedef ::clang::Type* SimpleType; 7004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 7014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return Val.getTypePtr(); 7024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 7034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 7044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnertemplate<> struct simplify_type< ::clang::QualType> 7054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner : public simplify_type<const ::clang::QualType> {}; 70625cf760b54d3b88633827501013bc51a29b28abaMike Stump 707cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 708cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattnertemplate<> 709d776b2da9bd694c41f1506e152aeb35d1babeba6Chris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 710cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattnerpublic: 711cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 712cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner return P.getAsOpaquePtr(); 713cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner } 714cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 715cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner return clang::QualType::getFromOpaquePtr(P); 716cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner } 7173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Various qualifiers go in low bits. 718e41419144a0a01456f5426efcd9b919f68284527Chris Lattner enum { NumLowBitsAvailable = 0 }; 719cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner}; 72025cf760b54d3b88633827501013bc51a29b28abaMike Stump 72178f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek} // end namespace llvm 7224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 7234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace clang { 7244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 7254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Type - This is the base class of the type hierarchy. A central concept 7264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// with types is that each type always has a canonical type. A canonical type 7274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// is the type with any typedef names stripped out of it or the types it 7284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// references. For example, consider: 7294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// typedef int foo; 7314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// typedef foo* bar; 7324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'int *' 'foo *' 'bar' 7334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// There will be a Type object created for 'int'. Since int is canonical, its 7354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 7364fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 7374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// there is a PointerType that represents 'int*', which, like 'int', is 7384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 7394fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 7404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// is also 'int*'. 7414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Non-canonical types are useful for emitting diagnostics, without losing 7434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// information about typedefs being used. Canonical types are useful for type 7444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// comparisons (they allow by-pointer equality tests) and useful for reasoning 7454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// about whether something has a particular form (e.g. is a function type), 7464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// because they implicitly, recursively, strip all typedefs out of a type. 7474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Types, once created, are immutable. 7494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass Type { 7514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 7524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum TypeClass { 7534fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define TYPE(Class, Base) Class, 7544fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 7554fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#include "clang/AST/TypeNodes.def" 7564fa58905062efa6a12137b1983a1367220182a20Douglas Gregor TagFirst = Record, TagLast = Enum 7574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 758fd3d5fdac0d25464e1b9c36bc646965494d44f66Argiris Kirtzidis 759fd3d5fdac0d25464e1b9c36bc646965494d44f66Argiris Kirtzidisprotected: 760fd3d5fdac0d25464e1b9c36bc646965494d44f66Argiris Kirtzidis enum { TypeClassBitSize = 6 }; 761fd3d5fdac0d25464e1b9c36bc646965494d44f66Argiris Kirtzidis 7624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 7634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType CanonicalType; 7644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 7651b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 7661b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool Dependent : 1; 7671b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 7684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 7694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Note that this should stay at the end of the ivars for Type so that 7704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// subclasses can pack their bitfields into the same word. 771fd3d5fdac0d25464e1b9c36bc646965494d44f66Argiris Kirtzidis unsigned TC : TypeClassBitSize; 7721b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 77341b780c6caa012115bfdcccff94b9965d4de71f0Chris Lattner Type(const Type&); // DO NOT IMPLEMENT. 77441b780c6caa012115bfdcccff94b9965d4de71f0Chris Lattner void operator=(const Type&); // DO NOT IMPLEMENT. 7754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 7767c6f0c755e48a2782bc0a0a4cfc63dc84e0f11d5Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 7777c6f0c755e48a2782bc0a0a4cfc63dc84e0f11d5Hartmut Kaiser Type *this_() { return this; } 7781b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 77935fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 7801b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Dependent(dependent), TC(tc) {} 7811b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual ~Type() {} 782db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek virtual void Destroy(ASTContext& C); 7834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; 78425cf760b54d3b88633827501013bc51a29b28abaMike Stump 7854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 78692803daaa6a40a3899c2e599bddc42732c2ce593Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 78725cf760b54d3b88633827501013bc51a29b28abaMike Stump 7887480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall bool isCanonicalUnqualified() const { 7897480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall return CanonicalType.getTypePtr() == this; 7907480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall } 7914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 79225cf760b54d3b88633827501013bc51a29b28abaMike Stump /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 7934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// object types, function types, and incomplete types. 79425cf760b54d3b88633827501013bc51a29b28abaMike Stump 79526ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// \brief Determines whether the type describes an object in memory. 79626ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// 79726ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// Note that this definition of object type corresponds to the C++ 79826ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// definition of object type, which includes incomplete types, as 79926ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// opposed to the C definition (which does not include incomplete 80026ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// types). 8014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isObjectType() const; 8024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 8034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isIncompleteType - Return true if this is an incomplete type. 8044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// A type that can describe objects, but which lacks information needed to 8054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// determine its size (e.g. void, or a fwd declared struct). Clients of this 80625cf760b54d3b88633827501013bc51a29b28abaMike Stump /// routine will need to determine if the size is actually required. 8074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isIncompleteType() const; 8089db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner 8099db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 8109db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner /// type, in other words, not a function type. 8119db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner bool isIncompleteOrObjectType() const { 8129db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner return !isFunctionType(); 8139db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner } 81439c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl 81539c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 81639c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl bool isPODType() const; 81739c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl 81875067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl /// isLiteralType - Return true if this is a literal type 81975067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl /// (C++0x [basic.types]p10) 82075067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl bool isLiteralType() const; 82175067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl 8225eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 8235eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff /// types that have a non-constant expression. This does not include "[]". 8245eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff bool isVariablyModifiedType() const; 82525cf760b54d3b88633827501013bc51a29b28abaMike Stump 8264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Helper methods to distinguish type categories. All type predicates 8272a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 828c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar 829c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 830c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 83125cf760b54d3b88633827501013bc51a29b28abaMike Stump 8328888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 8338888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 8344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 8358d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isEnumeralType() const; 8368d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isBooleanType() const; 8378d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isCharType() const; 8381815b3bfc1382c88bee771bd158755b2426f0780Douglas Gregor bool isWideCharType() const; 839da86f093507a7733ae955d7511b88f8bf4f61752Douglas Gregor bool isAnyCharacterType() const; 840c81f316d260b8b8b9da21a0f9a22baa334e063fbFariborz Jahanian bool isIntegralType() const; 841da86f093507a7733ae955d7511b88f8bf4f61752Douglas Gregor 8424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Floating point categories. 8434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 8444300121ffff80d4b23d17689930e2aa2a83086b9Steve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 8454300121ffff80d4b23d17689930e2aa2a83086b9Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 8464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isComplexType() const; // C99 6.2.5p11 (complex) 8473277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 8484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 8494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 8504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 851e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isVoidType() const; // C99 6.2.5p19 852e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isDerivedType() const; // C99 6.2.5p20 853e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 854e7ef500151147ba851db502fc4d36319f863db80Douglas Gregor bool isAggregateType() const; 85525cf760b54d3b88633827501013bc51a29b28abaMike Stump 856e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner // Type Predicates: Check to see if this type is structurally the specified 8572a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb // type, ignoring typedefs and qualifiers. 858e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isFunctionType() const; 859cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } 860cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } 8617931f4a186bc76b21dd4629ee74d64264a7fb8a2Chris Lattner bool isPointerType() const; 86279ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroff bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 8637aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff bool isBlockPointerType() const; 8645ca84bccd83982d3941d68dd88139ca43f6322a0Steve Naroff bool isVoidPointerType() const; 865f0c4a0a830c9154b1ae72e497c2ce586c10e9b71Chris Lattner bool isReferenceType() const; 866ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl bool isLValueReferenceType() const; 867ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl bool isRValueReferenceType() const; 868cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner bool isFunctionPointerType() const; 8697555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl bool isMemberPointerType() const; 8707555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl bool isMemberFunctionPointerType() const; 871e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isArrayType() const; 872a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isConstantArrayType() const; 873a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isIncompleteArrayType() const; 874a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isVariableArrayType() const; 8751b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool isDependentSizedArrayType() const; 876e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isRecordType() const; 87725cf760b54d3b88633827501013bc51a29b28abaMike Stump bool isClassType() const; 87825cf760b54d3b88633827501013bc51a29b28abaMike Stump bool isStructureType() const; 87936e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff bool isUnionType() const; 880b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 881b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isVectorType() const; // GCC vector type. 882af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman bool isExtVectorType() const; // Extended vector type. 883c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 884329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // FIXME: change this to 'raw' interface type, so we can used 'interface' type 885329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // for the common case. 886b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCInterfaceType() const; // NSString or NSString<foo> 887b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 888b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCQualifiedIdType() const; // id<foo> 88927bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff bool isObjCQualifiedClassType() const; // Class<foo> 890329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCIdType() const; // id 891329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCClassType() const; // Class 892a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian bool isObjCSelType() const; // Class 8937bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff bool isObjCBuiltinType() const; // 'id' or 'Class' 894dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 8955d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 8961b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 8971b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 89825cf760b54d3b88633827501013bc51a29b28abaMike Stump /// that its definition somehow depends on a template parameter 8991b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// (C++ [temp.dep.type]). 9001b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool isDependentType() const { return Dependent; } 90100fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor bool isOverloadableType() const; 902dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 903fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 904fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 905fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 9065d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl /// interface types, as well as nullptr_t. 907fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar bool hasPointerRepresentation() const; 908fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar 9097c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 9107c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 91125cf760b54d3b88633827501013bc51a29b28abaMike Stump bool hasObjCPointerRepresentation() const; 9127c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian 913e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner // Type Checking Functions: Check to see if this type is structurally the 91435fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 91535fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner // the best type we can. 9165c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek const RecordType *getAsStructureType() const; 9171b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 918e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner const RecordType *getAsUnionType() const; 91936e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 920329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // The following is a convenience method that returns an ObjCObjectPointerType 921329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // for object declared using an interface. 922329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 923329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 92477763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff const ObjCInterfaceType *getAsObjCQualifiedInterfaceType() const; 92590e18745436d0889e8bb7fba650263b38f05694eFariborz Jahanian const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 92625cf760b54d3b88633827501013bc51a29b28abaMike Stump 927f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // Member-template getAs<specific type>'. This scheme will eventually 928f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // replace the specific getAsXXXX methods above. 929cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall // 930cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall // There are some specializations of this member template listed 931cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall // immediately following this class. 932f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek template <typename T> const T *getAs() const; 93325cf760b54d3b88633827501013bc51a29b28abaMike Stump 934f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 935f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner /// interface, return the interface type, otherwise return null. 936f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 937f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner 938a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 939a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// element type of the array, potentially with type qualifiers missing. 940a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// This method should never be used when type qualifiers are meaningful. 941a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 94225cf760b54d3b88633827501013bc51a29b28abaMike Stump 943898111463b64a26d55af56474ad8cca1fdb76268Steve Naroff /// getPointeeType - If this is a pointer, ObjC object pointer, or block 944898111463b64a26d55af56474ad8cca1fdb76268Steve Naroff /// pointer, this returns the respective pointee. 945329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff QualType getPointeeType() const; 94625cf760b54d3b88633827501013bc51a29b28abaMike Stump 9470afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// getUnqualifiedDesugaredType() - Return the specified type with 9480afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// any "sugar" removed from the type, removing any typedefs, 9490afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// typeofs, etc., as well as any qualifiers. 9500afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall const Type *getUnqualifiedDesugaredType() const; 95125cf760b54d3b88633827501013bc51a29b28abaMike Stump 9524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// More type predicates useful for type checking/promotion 9534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isPromotableIntegerType() const; // C99 6.3.1.1p2 9544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isSignedIntegerType - Return true if this is an integer type that is 956bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 957bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 958bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// integer element type. 9594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isSignedIntegerType() const; 9604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isUnsignedIntegerType - Return true if this is an integer type that is 962bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 963bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 964bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// element type. 9654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isUnsignedIntegerType() const; 966bbe686be29157b575e53fbed328613117b525f26Chris Lattner 9674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isConstantSizeType - Return true if this is not a variable sized type, 9680448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 9690448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner /// incomplete types. 97062f67fd7f670f1a8b222c6565b257c05e8e80faeEli Friedman bool isConstantSizeType() const; 971a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner 97284bca951282f362c439cc7993fcb4d145384e416Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 97384bca951282f362c439cc7993fcb4d145384e416Eli Friedman /// set of type specifiers. 97484bca951282f362c439cc7993fcb4d145384e416Eli Friedman bool isSpecifierType() const; 97584bca951282f362c439cc7993fcb4d145384e416Eli Friedman 9766cbe8f397e8fd4aa01310bcefdcbe36639eea7e0Argiris Kirtzidis const char *getTypeClassName() const; 9776cbe8f397e8fd4aa01310bcefdcbe36639eea7e0Argiris Kirtzidis 978b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor /// \brief Determine the linkage of this type. 979b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 980b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 9814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getCanonicalTypeInternal() const { return CanonicalType; } 982a55e321bd645398b514e246981c04a4889ee2472Chris Lattner void dump() const; 9834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *) { return true; } 9844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 9854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 986cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCalltemplate <> inline const TypedefType *Type::getAs() const { 987cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall return dyn_cast<TypedefType>(this); 988cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall} 989cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall 990cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall// We can do canonical leaf types faster, because we don't have to 991cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall// worry about preserving child type decoration. 992cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall#define TYPE(Class, Base) 993cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall#define LEAF_TYPE(Class) \ 994cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCalltemplate <> inline const Class##Type *Type::getAs() const { \ 9953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return dyn_cast<Class##Type>(CanonicalType); \ 996cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall} 997cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall#include "clang/AST/TypeNodes.def" 998cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall 999cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall 10004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// BuiltinType - This class is used for builtin types like 'int'. Builtin 10014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types are always canonical and have a literal name field. 10024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass BuiltinType : public Type { 10034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 10044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum Kind { 10054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Void, 100625cf760b54d3b88633827501013bc51a29b28abaMike Stump 10074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Bool, // This is bool and/or _Bool. 10084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Char_U, // This is 'char' for targets where char is unsigned. 10094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UChar, // This is explicitly qualified unsigned char. 10102bcacb61cf94b71e5c87f29d517f8dc29fe3993eAlisdair Meredith Char16, // This is 'char16_t' for C++. 10112bcacb61cf94b71e5c87f29d517f8dc29fe3993eAlisdair Meredith Char32, // This is 'char32_t' for C++. 10124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UShort, 10134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UInt, 10144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ULong, 10154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ULongLong, 10166cc7e415d42291bf01e0295d9d6344e106613c48Chris Lattner UInt128, // __uint128_t 101725cf760b54d3b88633827501013bc51a29b28abaMike Stump 10184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Char_S, // This is 'char' for targets where char is signed. 10194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner SChar, // This is explicitly qualified signed char. 102085bd81edce4057156d7f49408147f07daa675096Argiris Kirtzidis WChar, // This is 'wchar_t' for C++. 10214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Short, 10224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Int, 10234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Long, 10244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner LongLong, 10256cc7e415d42291bf01e0295d9d6344e106613c48Chris Lattner Int128, // __int128_t 102625cf760b54d3b88633827501013bc51a29b28abaMike Stump 1027d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor Float, Double, LongDouble, 1028d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor 10295d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 10305d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl 10311b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Overload, // This represents the type of an overloaded function declaration. 10324a8498cc0f251e839912285112a014a5d1248648Anders Carlsson Dependent, // This represents the type of a type-dependent expression. 103325cf760b54d3b88633827501013bc51a29b28abaMike Stump 10347bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff UndeducedAuto, // In C++0x, this represents the type of an auto variable 10354a8498cc0f251e839912285112a014a5d1248648Anders Carlsson // that has not been deduced yet. 10367bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff ObjCId, // This represents the ObjC 'id' type. 1037a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian ObjCClass, // This represents the ObjC 'Class' type. 1038a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian ObjCSel // This represents the ObjC 'SEL' type. 10394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 10404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 10414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Kind TypeKind; 10424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 104325cf760b54d3b88633827501013bc51a29b28abaMike Stump BuiltinType(Kind K) 104425cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 10451b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor TypeKind(K) {} 104625cf760b54d3b88633827501013bc51a29b28abaMike Stump 10474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Kind getKind() const { return TypeKind; } 10487099c789f054f1e7480f498d60aa94b0326c285fChris Lattner const char *getName(const LangOptions &LO) const; 104925cf760b54d3b88633827501013bc51a29b28abaMike Stump 10500afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 10510afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 10520afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1053afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isInteger() const { 1054afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Bool && TypeKind <= Int128; 1055afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1056afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1057afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isSignedInteger() const { 1058afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Char_S && TypeKind <= Int128; 1059afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1060afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1061afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isUnsignedInteger() const { 1062afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Bool && TypeKind <= UInt128; 1063afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1064afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1065afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isFloatingPoint() const { 1066afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Float && TypeKind <= LongDouble; 1067afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1068afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1069b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1070b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 10714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 10724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const BuiltinType *) { return true; } 10734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 10744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 10764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types (_Complex float etc) as well as the GCC integer complex extensions. 10774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 10784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass ComplexType : public Type, public llvm::FoldingSetNode { 10794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ElementType; 10804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ComplexType(QualType Element, QualType CanonicalPtr) : 108125cf760b54d3b88633827501013bc51a29b28abaMike Stump Type(Complex, CanonicalPtr, Element->isDependentType()), 10821b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ElementType(Element) { 10834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 10844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 10854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 10864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getElementType() const { return ElementType; } 108725cf760b54d3b88633827501013bc51a29b28abaMike Stump 10880afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 10890afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 10900afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 10914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 10924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getElementType()); 10934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 10944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 10954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Element.getAsOpaquePtr()); 10964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 109725cf760b54d3b88633827501013bc51a29b28abaMike Stump 1098b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1099b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 11004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 11014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const ComplexType *) { return true; } 11024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 11034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1104554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 1105cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner/// 1106554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 1107cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner QualType PointeeType; 11084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner PointerType(QualType Pointee, QualType CanonicalPtr) : 1110554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 11114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 11134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 111425cf760b54d3b88633827501013bc51a29b28abaMike Stump 1115554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 1116554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 11170afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 11180afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 11190afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 11204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 11214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getPointeeType()); 11224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 11244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Pointee.getAsOpaquePtr()); 11254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 112625cf760b54d3b88633827501013bc51a29b28abaMike Stump 1127b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1128b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 11294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 11304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const PointerType *) { return true; } 11314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 11324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11337aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// BlockPointerType - pointer to a block type. 11347aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// This type is to represent types syntactically represented as 11357aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 11367aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// 11377aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 11387aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 11397aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 114025cf760b54d3b88633827501013bc51a29b28abaMike Stump Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 11411b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor PointeeType(Pointee) { 11427aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 11437aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff friend class ASTContext; // ASTContext creates these. 11447aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffpublic: 114525cf760b54d3b88633827501013bc51a29b28abaMike Stump 11467aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 11477aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff QualType getPointeeType() const { return PointeeType; } 11487aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 11490afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 11500afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 11510afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 11527aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 11537aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff Profile(ID, getPointeeType()); 11547aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 11557aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 11567aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 11577aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 115825cf760b54d3b88633827501013bc51a29b28abaMike Stump 1159b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1160b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 116125cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 116225cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == BlockPointer; 11637aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 11647aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 11657aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff}; 11667aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 1167ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 11684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 1169554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 1170554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar QualType PointeeType; 1171554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 11724ea8425c9601895fa137f877bc784f75f20adac6John McCall /// True if the type was originally spelled with an lvalue sigil. 11734ea8425c9601895fa137f877bc784f75f20adac6John McCall /// This is never true of rvalue references but can also be false 11744ea8425c9601895fa137f877bc784f75f20adac6John McCall /// on lvalue references because of C++0x [dcl.typedef]p9, 11754ea8425c9601895fa137f877bc784f75f20adac6John McCall /// as follows: 11764ea8425c9601895fa137f877bc784f75f20adac6John McCall /// 11774ea8425c9601895fa137f877bc784f75f20adac6John McCall /// typedef int &ref; // lvalue, spelled lvalue 11784ea8425c9601895fa137f877bc784f75f20adac6John McCall /// typedef int &&rvref; // rvalue 11794ea8425c9601895fa137f877bc784f75f20adac6John McCall /// ref &a; // lvalue, inner ref, spelled lvalue 11804ea8425c9601895fa137f877bc784f75f20adac6John McCall /// ref &&a; // lvalue, inner ref 11814ea8425c9601895fa137f877bc784f75f20adac6John McCall /// rvref &a; // lvalue, inner ref, spelled lvalue 11824ea8425c9601895fa137f877bc784f75f20adac6John McCall /// rvref &&a; // rvalue, inner ref 11834ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue; 11844ea8425c9601895fa137f877bc784f75f20adac6John McCall 11854ea8425c9601895fa137f877bc784f75f20adac6John McCall /// True if the inner type is a reference type. This only happens 11864ea8425c9601895fa137f877bc784f75f20adac6John McCall /// in non-canonical forms. 11874ea8425c9601895fa137f877bc784f75f20adac6John McCall bool InnerRef; 11884ea8425c9601895fa137f877bc784f75f20adac6John McCall 1189ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlprotected: 11904ea8425c9601895fa137f877bc784f75f20adac6John McCall ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, 11914ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue) : 1192ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl Type(tc, CanonicalRef, Referencee->isDependentType()), 11934ea8425c9601895fa137f877bc784f75f20adac6John McCall PointeeType(Referencee), SpelledAsLValue(SpelledAsLValue), 11944ea8425c9601895fa137f877bc784f75f20adac6John McCall InnerRef(Referencee->isReferenceType()) { 11954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 11974ea8425c9601895fa137f877bc784f75f20adac6John McCall bool isSpelledAsLValue() const { return SpelledAsLValue; } 11984ea8425c9601895fa137f877bc784f75f20adac6John McCall 11994ea8425c9601895fa137f877bc784f75f20adac6John McCall QualType getPointeeTypeAsWritten() const { return PointeeType; } 12004ea8425c9601895fa137f877bc784f75f20adac6John McCall QualType getPointeeType() const { 12014ea8425c9601895fa137f877bc784f75f20adac6John McCall // FIXME: this might strip inner qualifiers; okay? 12024ea8425c9601895fa137f877bc784f75f20adac6John McCall const ReferenceType *T = this; 12034ea8425c9601895fa137f877bc784f75f20adac6John McCall while (T->InnerRef) 12044ea8425c9601895fa137f877bc784f75f20adac6John McCall T = T->PointeeType->getAs<ReferenceType>(); 12054ea8425c9601895fa137f877bc784f75f20adac6John McCall return T->PointeeType; 12064ea8425c9601895fa137f877bc784f75f20adac6John McCall } 1207554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 12084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 12094ea8425c9601895fa137f877bc784f75f20adac6John McCall Profile(ID, PointeeType, SpelledAsLValue); 12104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 12114ea8425c9601895fa137f877bc784f75f20adac6John McCall static void Profile(llvm::FoldingSetNodeID &ID, 12124ea8425c9601895fa137f877bc784f75f20adac6John McCall QualType Referencee, 12134ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue) { 12144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Referencee.getAsOpaquePtr()); 12154ea8425c9601895fa137f877bc784f75f20adac6John McCall ID.AddBoolean(SpelledAsLValue); 12164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 12174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1218b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1219b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 1220ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 1221ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == LValueReference || 1222ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl T->getTypeClass() == RValueReference; 1223ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 12244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const ReferenceType *) { return true; } 1225ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl}; 1226ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl 1227ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 1228ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// 1229ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlclass LValueReferenceType : public ReferenceType { 12304ea8425c9601895fa137f877bc784f75f20adac6John McCall LValueReferenceType(QualType Referencee, QualType CanonicalRef, 12314ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue) : 12324ea8425c9601895fa137f877bc784f75f20adac6John McCall ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue) 12334ea8425c9601895fa137f877bc784f75f20adac6John McCall {} 1234ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl friend class ASTContext; // ASTContext creates these 1235ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlpublic: 12360afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 12370afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 12380afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1239ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 1240ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == LValueReference; 1241ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 1242ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 1243ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl}; 1244ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl 1245ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 1246ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// 1247ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlclass RValueReferenceType : public ReferenceType { 1248ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 12494ea8425c9601895fa137f877bc784f75f20adac6John McCall ReferenceType(RValueReference, Referencee, CanonicalRef, false) { 1250ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 1251ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl friend class ASTContext; // ASTContext creates these 1252ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlpublic: 12530afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 12540afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 12550afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1256ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 1257ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == RValueReference; 1258ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 1259ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 12607555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl}; 12617555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 12627555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 12637555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl/// 12647555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 12657555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl QualType PointeeType; 12667555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 12677555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 12687555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *Class; 12697555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 12707555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 12717555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Type(MemberPointer, CanonicalPtr, 12727555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Cls->isDependentType() || Pointee->isDependentType()), 12737555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl PointeeType(Pointee), Class(Cls) { 12747555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 12757555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl friend class ASTContext; // ASTContext creates these. 12767555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlpublic: 12777555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 12787555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl QualType getPointeeType() const { return PointeeType; } 12797555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 12807555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *getClass() const { return Class; } 12817555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 12820afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 12830afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 12840afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 12857555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 12867555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Profile(ID, getPointeeType(), getClass()); 12877555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 12887555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 12897555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *Class) { 12907555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 12917555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl ID.AddPointer(Class); 12927555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 12937555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 1294b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1295b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 12967555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static bool classof(const Type *T) { 12977555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return T->getTypeClass() == MemberPointer; 12987555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 12997555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static bool classof(const MemberPointerType *) { return true; } 13004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 13014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 13024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ArrayType - C99 6.7.5.2 - Array Declarators. 13034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 1304c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 13054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 13064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 13071b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 13081b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// with a star size (e.g. int X[*]). 13091b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// 'static' is only allowed on function parameters. 13104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum ArraySizeModifier { 13114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Normal, Static, Star 13124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 13134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 131483c13010359c33354c581acee65d0c986a75247eSteve Naroff /// ElementType - The element type of the array. 131583c13010359c33354c581acee65d0c986a75247eSteve Naroff QualType ElementType; 131625cf760b54d3b88633827501013bc51a29b28abaMike Stump 1317dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 131824c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 1319dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek unsigned SizeModifier : 2; 132025cf760b54d3b88633827501013bc51a29b28abaMike Stump 132124c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 132224c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// 'int X[static restrict 4]'. For function parameters only. 132324c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff unsigned IndexTypeQuals : 3; 132425cf760b54d3b88633827501013bc51a29b28abaMike Stump 132583c13010359c33354c581acee65d0c986a75247eSteve Naroffprotected: 13261b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // C++ [temp.dep.type]p1: 13271b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // A type is dependent if it is... 13281b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // - an array type constructed from any dependent type or whose 13291b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // size is specified by a constant expression that is 13301b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // value-dependent, 133124c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 133224c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArraySizeModifier sm, unsigned tq) 13331b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 13341b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 13351b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 133683c13010359c33354c581acee65d0c986a75247eSteve Naroff friend class ASTContext; // ASTContext creates these. 133783c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic: 133883c13010359c33354c581acee65d0c986a75247eSteve Naroff QualType getElementType() const { return ElementType; } 1339dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek ArraySizeModifier getSizeModifier() const { 1340dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek return ArraySizeModifier(SizeModifier); 1341dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek } 13423ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers getIndexTypeQualifiers() const { 13433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Qualifiers::fromCVRMask(IndexTypeQuals); 13443ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 13453ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getIndexTypeCVRQualifiers() const { return IndexTypeQuals; } 134625cf760b54d3b88633827501013bc51a29b28abaMike Stump 1347b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1348b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 134983c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const Type *T) { 135083c13010359c33354c581acee65d0c986a75247eSteve Naroff return T->getTypeClass() == ConstantArray || 13518ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman T->getTypeClass() == VariableArray || 13521b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor T->getTypeClass() == IncompleteArray || 13531b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor T->getTypeClass() == DependentSizedArray; 135483c13010359c33354c581acee65d0c986a75247eSteve Naroff } 135583c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const ArrayType *) { return true; } 135683c13010359c33354c581acee65d0c986a75247eSteve Naroff}; 135783c13010359c33354c581acee65d0c986a75247eSteve Naroff 13581d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// ConstantArrayType - This class represents the canonical version of 13591d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// C arrays with a specified constant size. For example, the canonical 13601d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 13611d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// type is 'int' and the size is 404. 1362c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ConstantArrayType : public ArrayType { 136383c13010359c33354c581acee65d0c986a75247eSteve Naroff llvm::APInt Size; // Allows us to unique the type. 136425cf760b54d3b88633827501013bc51a29b28abaMike Stump 13653f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 136624c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArraySizeModifier sm, unsigned tq) 13671d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(ConstantArray, et, can, sm, tq), 13681d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor Size(size) {} 13691d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregorprotected: 13701d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor ConstantArrayType(TypeClass tc, QualType et, QualType can, 13711d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 13721d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(tc, et, can, sm, tq), Size(size) {} 137383c13010359c33354c581acee65d0c986a75247eSteve Naroff friend class ASTContext; // ASTContext creates these. 137483c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic: 1375a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner const llvm::APInt &getSize() const { return Size; } 13760afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 13770afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 13780afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 137983c13010359c33354c581acee65d0c986a75247eSteve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 138025cf760b54d3b88633827501013bc51a29b28abaMike Stump Profile(ID, getElementType(), getSize(), 13813ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers()); 138283c13010359c33354c581acee65d0c986a75247eSteve Naroff } 138383c13010359c33354c581acee65d0c986a75247eSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 13843f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 13853f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner unsigned TypeQuals) { 138683c13010359c33354c581acee65d0c986a75247eSteve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 138783c13010359c33354c581acee65d0c986a75247eSteve Naroff ID.AddInteger(ArraySize.getZExtValue()); 13883f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(SizeMod); 13893f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(TypeQuals); 139083c13010359c33354c581acee65d0c986a75247eSteve Naroff } 13911d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor static bool classof(const Type *T) { 139232b25ab7d4b3355b804e367c90f5cd55f4c9187eJohn McCall return T->getTypeClass() == ConstantArray; 139383c13010359c33354c581acee65d0c986a75247eSteve Naroff } 139483c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const ConstantArrayType *) { return true; } 139583c13010359c33354c581acee65d0c986a75247eSteve Naroff}; 139683c13010359c33354c581acee65d0c986a75247eSteve Naroff 139756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 139856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 139956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// type is 'int' and the size is unspecified. 14008ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanclass IncompleteArrayType : public ArrayType { 14011d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor 14028ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman IncompleteArrayType(QualType et, QualType can, 14031d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor ArraySizeModifier sm, unsigned tq) 14048ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 14058ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman friend class ASTContext; // ASTContext creates these. 14068ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanpublic: 14070afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 14080afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 14090afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 141025cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 141125cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == IncompleteArray; 14128ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 14138ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 141425cf760b54d3b88633827501013bc51a29b28abaMike Stump 14158ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman friend class StmtIteratorBase; 141625cf760b54d3b88633827501013bc51a29b28abaMike Stump 14178ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 14183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Profile(ID, getElementType(), getSizeModifier(), 14193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getIndexTypeCVRQualifiers()); 14208ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 142125cf760b54d3b88633827501013bc51a29b28abaMike Stump 14223f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 14233f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 14248ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 14253f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(SizeMod); 14263f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(TypeQuals); 14278ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 14288ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman}; 14298ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 143056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 143156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 143256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 143356846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 143456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 143556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// should not be: two lexically equivalent variable array types could mean 143656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// different things, for example, these variables do not have the same type 143756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// dynamically: 143856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 143956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// void foo(int x) { 144056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// int Y[x]; 144156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// ++x; 144256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// int Z[x]; 144356846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// } 144456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 1445c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass VariableArrayType : public ArrayType { 144625cf760b54d3b88633827501013bc51a29b28abaMike Stump /// SizeExpr - An assignment expression. VLA's are only permitted within 144725cf760b54d3b88633827501013bc51a29b28abaMike Stump /// a function block. 1448718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek Stmt *SizeExpr; 14491d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor /// Brackets - The left and right array brackets. 14501d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange Brackets; 14511d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor 145224c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 14531d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor ArraySizeModifier sm, unsigned tq, 14541d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange brackets) 14551d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(VariableArray, et, can, sm, tq), 14561d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 14574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1458db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek virtual void Destroy(ASTContext& C); 1459db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek 14604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 146125cf760b54d3b88633827501013bc51a29b28abaMike Stump Expr *getSizeExpr() const { 1462718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek // We use C-style casts instead of cast<> here because we do not wish 1463718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 1464718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek return (Expr*) SizeExpr; 1465718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek } 14661d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange getBracketsRange() const { return Brackets; } 14671d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 14681d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 146925cf760b54d3b88633827501013bc51a29b28abaMike Stump 14700afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 14710afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 14720afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 147325cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 147425cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == VariableArray; 14754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 147683c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const VariableArrayType *) { return true; } 147725cf760b54d3b88633827501013bc51a29b28abaMike Stump 1478fce813e3159a67a57a03cdca45ac4e10d4cffac3Ted Kremenek friend class StmtIteratorBase; 147925cf760b54d3b88633827501013bc51a29b28abaMike Stump 14803793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 14817029ee3fdeee514a79eafb2508723d27c97fe158Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 14823793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek } 14834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 14844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 14851b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// DependentSizedArrayType - This type represents an array type in 14861b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// C++ whose size is a value-dependent expression. For example: 1487393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// 1488393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// \code 148925cf760b54d3b88633827501013bc51a29b28abaMike Stump/// template<typename T, int Size> 14901b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// class array { 14911b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// T data[Size]; 14921b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// }; 1493393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// \endcode 1494393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// 14951b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// For these types, we won't actually know what the array bound is 14961b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// until template instantiation occurs, at which point this will 14971b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 14981b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorclass DependentSizedArrayType : public ArrayType { 14997fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor ASTContext &Context; 150025cf760b54d3b88633827501013bc51a29b28abaMike Stump 1501393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// \brief An assignment expression that will instantiate to the 15021b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// size of the array. 1503393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// 1504393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// The expression itself might be NULL, in which case the array 1505393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// type will have its size deduced from an initializer. 15061b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Stmt *SizeExpr; 1507393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor 15081d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor /// Brackets - The left and right array brackets. 15091d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange Brackets; 151025cf760b54d3b88633827501013bc51a29b28abaMike Stump 151125cf760b54d3b88633827501013bc51a29b28abaMike Stump DependentSizedArrayType(ASTContext &Context, QualType et, QualType can, 15127fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor Expr *e, ArraySizeModifier sm, unsigned tq, 15131d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange brackets) 15141d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), 15157fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {} 15161b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor friend class ASTContext; // ASTContext creates these. 15171b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual void Destroy(ASTContext& C); 15181b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 15191b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorpublic: 152025cf760b54d3b88633827501013bc51a29b28abaMike Stump Expr *getSizeExpr() const { 15211b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // We use C-style casts instead of cast<> here because we do not wish 15221b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 15231b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return (Expr*) SizeExpr; 15241b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 15251d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange getBracketsRange() const { return Brackets; } 15261d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 15271d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 152825cf760b54d3b88633827501013bc51a29b28abaMike Stump 15290afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 15300afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 15310afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 153225cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 153325cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == DependentSizedArray; 15341b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 15351b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 153625cf760b54d3b88633827501013bc51a29b28abaMike Stump 15371b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor friend class StmtIteratorBase; 153825cf760b54d3b88633827501013bc51a29b28abaMike Stump 153925cf760b54d3b88633827501013bc51a29b28abaMike Stump 15401b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 154125cf760b54d3b88633827501013bc51a29b28abaMike Stump Profile(ID, Context, getElementType(), 15423ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); 15431b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 154425cf760b54d3b88633827501013bc51a29b28abaMike Stump 154525cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 154625cf760b54d3b88633827501013bc51a29b28abaMike Stump QualType ET, ArraySizeModifier SizeMod, 15477fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor unsigned TypeQuals, Expr *E); 15481b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor}; 15491b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 155068a7a6db3693e6df54a2198f3ee4e3f87e7f9ac0Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 15512a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// where either the type or size is dependent. For example: 15522a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// @code 15532a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// template<typename T, int Size> 15542a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// class vector { 15552a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 15562a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// } 15572a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// @endcode 15580c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { 15590c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor ASTContext &Context; 15602a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor Expr *SizeExpr; 15612a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor /// ElementType - The element type of the array. 15622a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor QualType ElementType; 15632a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor SourceLocation loc; 156425cf760b54d3b88633827501013bc51a29b28abaMike Stump 156525cf760b54d3b88633827501013bc51a29b28abaMike Stump DependentSizedExtVectorType(ASTContext &Context, QualType ElementType, 15660c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor QualType can, Expr *SizeExpr, SourceLocation loc) 156725cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type (DependentSizedExtVector, can, true), 156825cf760b54d3b88633827501013bc51a29b28abaMike Stump Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 15690c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor loc(loc) {} 15702a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor friend class ASTContext; 15712a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor virtual void Destroy(ASTContext& C); 15722a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor 15732a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregorpublic: 15740c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 15752a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor QualType getElementType() const { return ElementType; } 15762a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor SourceLocation getAttributeLoc() const { return loc; } 15772a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor 15780afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 15790afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 15800afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 158125cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 158225cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == DependentSizedExtVector; 15832a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor } 158425cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const DependentSizedExtVectorType *) { return true; } 15850c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor 15860c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 15870c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor Profile(ID, Context, getElementType(), getSizeExpr()); 15880c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor } 158925cf760b54d3b88633827501013bc51a29b28abaMike Stump 15900c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 15910c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor QualType ElementType, Expr *SizeExpr); 15922a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor}; 159325cf760b54d3b88633827501013bc51a29b28abaMike Stump 15942a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor 15954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// VectorType - GCC generic vector type. This type is created using 159625cf760b54d3b88633827501013bc51a29b28abaMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in 1597438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson/// bytes; or from an Altivec __vector or vector declaration. 1598438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson/// Since the constructor takes the number of vector elements, the 15994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// client is responsible for converting the size into the number of elements. 16004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass VectorType : public Type, public llvm::FoldingSetNode { 16014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 16024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ElementType - The element type of the vector. 16034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ElementType; 160425cf760b54d3b88633827501013bc51a29b28abaMike Stump 16054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// NumElements - The number of elements in the vector. 16064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned NumElements; 160725cf760b54d3b88633827501013bc51a29b28abaMike Stump 1608438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson /// AltiVec - True if this is for an Altivec vector. 1609438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson bool AltiVec; 1610438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson 1611438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson /// Pixel - True if this is for an Altivec vector pixel. 1612438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson bool Pixel; 1613438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson 1614438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson VectorType(QualType vecType, unsigned nElements, QualType canonType, 1615438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson bool isAltiVec, bool isPixel) : 161625cf760b54d3b88633827501013bc51a29b28abaMike Stump Type(Vector, canonType, vecType->isDependentType()), 1617438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson ElementType(vecType), NumElements(nElements), 1618438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson AltiVec(isAltiVec), Pixel(isPixel) {} 161925cf760b54d3b88633827501013bc51a29b28abaMike Stump VectorType(TypeClass tc, QualType vecType, unsigned nElements, 1620438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson QualType canonType, bool isAltiVec, bool isPixel) 162125cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 1622438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson NumElements(nElements), AltiVec(isAltiVec), Pixel(isPixel) {} 16234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 16244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 162525cf760b54d3b88633827501013bc51a29b28abaMike Stump 16264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getElementType() const { return ElementType; } 162725cf760b54d3b88633827501013bc51a29b28abaMike Stump unsigned getNumElements() const { return NumElements; } 16284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 16290afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 16300afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 16310afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1632438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson bool isAltiVec() const { return AltiVec; } 1633438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson 1634438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson bool isPixel() const { return Pixel; } 1635438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson 16364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 1637438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson Profile(ID, getElementType(), getNumElements(), getTypeClass(), 1638438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson AltiVec, Pixel); 16394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 164025cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 1641438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson unsigned NumElements, TypeClass TypeClass, 1642438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson bool isAltiVec, bool isPixel) { 16434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(ElementType.getAsOpaquePtr()); 16444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddInteger(NumElements); 16454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddInteger(TypeClass); 1646438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson ID.AddBoolean(isAltiVec); 1647438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson ID.AddBoolean(isPixel); 16484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1649b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 1650b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1651b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 165225cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 165325cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 16544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 16554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const VectorType *) { return true; } 16564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 16574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1658af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// ExtVectorType - Extended vector type. This type is created using 1659af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1660af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 16616154214e20225a883a8a00226499534e9b514315Steve Naroff/// class enables syntactic extensions, like Vector Components for accessing 16626154214e20225a883a8a00226499534e9b514315Steve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1663af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemanclass ExtVectorType : public VectorType { 1664af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1665438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson VectorType(ExtVector, vecType, nElements, canonType, false, false) {} 16664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 16674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 16689096b795541c783297fb19684a58c54d0fe823b8Chris Lattner static int getPointAccessorIdx(char c) { 16699096b795541c783297fb19684a58c54d0fe823b8Chris Lattner switch (c) { 16709096b795541c783297fb19684a58c54d0fe823b8Chris Lattner default: return -1; 16719096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'x': return 0; 16729096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'y': return 1; 16739096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'z': return 2; 16749096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'w': return 3; 16759096b795541c783297fb19684a58c54d0fe823b8Chris Lattner } 16761b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 16771486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman static int getNumericAccessorIdx(char c) { 16789096b795541c783297fb19684a58c54d0fe823b8Chris Lattner switch (c) { 16791486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman default: return -1; 16801486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '0': return 0; 16811486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '1': return 1; 16821486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '2': return 2; 16831486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '3': return 3; 16841486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '4': return 4; 16851486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '5': return 5; 16861486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '6': return 6; 16871486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '7': return 7; 16881486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '8': return 8; 16891486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '9': return 9; 1690e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'A': 16911486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'a': return 10; 1692e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'B': 16931486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'b': return 11; 1694e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'C': 16951486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'c': return 12; 1696e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'D': 16971486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'd': return 13; 1698e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'E': 16991486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'e': return 14; 1700e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'F': 17011486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'f': return 15; 17029096b795541c783297fb19684a58c54d0fe823b8Chris Lattner } 17031b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 170425cf760b54d3b88633827501013bc51a29b28abaMike Stump 170542158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner static int getAccessorIdx(char c) { 170642158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 17071486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman return getNumericAccessorIdx(c); 170842158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner } 170925cf760b54d3b88633827501013bc51a29b28abaMike Stump 17109096b795541c783297fb19684a58c54d0fe823b8Chris Lattner bool isAccessorWithinNumElements(char c) const { 171142158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner if (int idx = getAccessorIdx(c)+1) 17129096b795541c783297fb19684a58c54d0fe823b8Chris Lattner return unsigned(idx-1) < NumElements; 17139096b795541c783297fb19684a58c54d0fe823b8Chris Lattner return false; 17141b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 17150afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 17160afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 17170afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 171825cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 171925cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == ExtVector; 17204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1721af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman static bool classof(const ExtVectorType *) { return true; } 17224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 17234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 17244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 17254fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 17264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 17274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass FunctionType : public Type { 17284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// SubClassData - This field is owned by the subclass, put here to pack 17294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// tightly with the ivars in Type. 17304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool SubClassData : 1; 17314b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis 17324fa58905062efa6a12137b1983a1367220182a20Douglas Gregor /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 17334b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// other bitfields. 17344fa58905062efa6a12137b1983a1367220182a20Douglas Gregor /// The qualifiers are part of FunctionProtoType because... 17354b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// 17364b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 17374b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// cv-qualifier-seq, [...], are part of the function type. 17384b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// 17394b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned TypeQuals : 3; 17401bb806498909a43a7829edb21c42606335d69694Mike Stump 17411bb806498909a43a7829edb21c42606335d69694Mike Stump /// NoReturn - Indicates if the function type is attribute noreturn. 17421bb806498909a43a7829edb21c42606335d69694Mike Stump unsigned NoReturn : 1; 174325cf760b54d3b88633827501013bc51a29b28abaMike Stump 174431cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor /// CallConv - The calling convention used by the function. 174531cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor unsigned CallConv : 2; 174631cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor 17474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // The type returned by the function. 17484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ResultType; 17494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 17504b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 17511bb806498909a43a7829edb21c42606335d69694Mike Stump unsigned typeQuals, QualType Canonical, bool Dependent, 175231cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor bool noReturn = false, CallingConv callConv = CC_Default) 17531b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, Canonical, Dependent), 17541bb806498909a43a7829edb21c42606335d69694Mike Stump SubClassData(SubclassInfo), TypeQuals(typeQuals), NoReturn(noReturn), 175531cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CallConv(callConv), ResultType(res) {} 17564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool getSubClassData() const { return SubClassData; } 17574b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned getTypeQuals() const { return TypeQuals; } 17584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 175925cf760b54d3b88633827501013bc51a29b28abaMike Stump 17604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getResultType() const { return ResultType; } 17611bb806498909a43a7829edb21c42606335d69694Mike Stump bool getNoReturnAttr() const { return NoReturn; } 176231cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CallingConv getCallConv() const { return (CallingConv)CallConv; } 17634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1764ad760b38613b3f7f1024b011f6109bed1487b32eJohn McCall static llvm::StringRef getNameForCallConv(CallingConv CC); 1765ad760b38613b3f7f1024b011f6109bed1487b32eJohn McCall 17664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 17674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionNoProto || 17684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner T->getTypeClass() == FunctionProto; 17694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 17704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const FunctionType *) { return true; } 17714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 17724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 17734fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 17744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// no information available about its arguments. 17754fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 17761bb806498909a43a7829edb21c42606335d69694Mike Stump FunctionNoProtoType(QualType Result, QualType Canonical, 177731cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor bool NoReturn = false, CallingConv CallConv = CC_Default) 177825cf760b54d3b88633827501013bc51a29b28abaMike Stump : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 177931cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor /*Dependent=*/false, NoReturn, CallConv) {} 17804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 17814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 17824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // No additional state past what FunctionType provides. 178325cf760b54d3b88633827501013bc51a29b28abaMike Stump 17840afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 17850afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 17860afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 17874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 1788db5993538c7f29ea7331dcb7292c083e1bab798cJohn McCall Profile(ID, getResultType(), getNoReturnAttr(), getCallConv()); 17894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 17901bb806498909a43a7829edb21c42606335d69694Mike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 1791db5993538c7f29ea7331dcb7292c083e1bab798cJohn McCall bool NoReturn, CallingConv CallConv) { 1792db5993538c7f29ea7331dcb7292c083e1bab798cJohn McCall ID.AddInteger(CallConv); 17931bb806498909a43a7829edb21c42606335d69694Mike Stump ID.AddInteger(NoReturn); 17944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(ResultType.getAsOpaquePtr()); 17954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 179625cf760b54d3b88633827501013bc51a29b28abaMike Stump 1797b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1798b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 17994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 18004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionNoProto; 18014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 18024fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 18034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 18044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 18054fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 18064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 18072767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 18082767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl/// exception specification, but this specification is not part of the canonical 18092767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl/// type. 18104fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 18111b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 18121b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// types within the arguments passed in. 18131b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 18141b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 18151b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor if (ArgArray[Idx]->isDependentType()) 1816f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman return true; 18171b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 18181b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return false; 18191b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 18201b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 18214fa58905062efa6a12137b1983a1367220182a20Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 18222767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool isVariadic, unsigned typeQuals, bool hasExs, 18232767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasAnyExs, const QualType *ExArray, 182431cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor unsigned numExs, QualType Canonical, bool NoReturn, 182531cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CallingConv CallConv) 18261b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 182725cf760b54d3b88633827501013bc51a29b28abaMike Stump (Result->isDependentType() || 182831cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor hasAnyDependentType(ArgArray, numArgs)), NoReturn, 182931cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CallConv), 18302767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 18312767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl AnyExceptionSpec(hasAnyExs) { 18324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // Fill in the trailing argument array. 18332767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 18344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner for (unsigned i = 0; i != numArgs; ++i) 18354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ArgInfo[i] = ArgArray[i]; 18362767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl // Fill in the exception array. 18372767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl QualType *Ex = ArgInfo + numArgs; 18382767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl for (unsigned i = 0; i != numExs; ++i) 18392767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl Ex[i] = ExArray[i]; 18404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 18412767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// NumArgs - The number of arguments this function has, not counting '...'. 18432767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl unsigned NumArgs : 20; 18442767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18452767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 18462767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl unsigned NumExceptions : 10; 18472767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18482767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// HasExceptionSpec - Whether this function has an exception spec at all. 18492767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool HasExceptionSpec : 1; 18502767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18512767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// AnyExceptionSpec - Whether this function has a throw(...) spec. 18522767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool AnyExceptionSpec : 1; 18532767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 18554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// holds the argument types. 18562767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18572767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 18582767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// holds the exception types. 18592767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1861db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek 18624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 18634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned getNumArgs() const { return NumArgs; } 18644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getArgType(unsigned i) const { 18654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner assert(i < NumArgs && "Invalid argument number!"); 18664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return arg_type_begin()[i]; 18674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 18682767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18692767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasExceptionSpec() const { return HasExceptionSpec; } 18702767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 18712767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 18722767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl QualType getExceptionType(unsigned i) const { 18732767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 18742767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl return exception_begin()[i]; 18752767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl } 187625cf760b54d3b88633827501013bc51a29b28abaMike Stump bool hasEmptyExceptionSpec() const { 187725cf760b54d3b88633827501013bc51a29b28abaMike Stump return hasExceptionSpec() && !hasAnyExceptionSpec() && 1878ac5e9f9de0959d5b1d390dc9bdad2d6f3d77c5cbAnders Carlsson getNumExceptions() == 0; 187911269048f03d91e991150c429dc874ae3999acb0Anders Carlsson } 18802767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isVariadic() const { return getSubClassData(); } 18824b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 188325cf760b54d3b88633827501013bc51a29b28abaMike Stump 18844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner typedef const QualType *arg_type_iterator; 18854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator arg_type_begin() const { 18864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return reinterpret_cast<const QualType *>(this+1); 18874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 18884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 18892767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18902767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl typedef const QualType *exception_iterator; 18912767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl exception_iterator exception_begin() const { 18922767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl // exceptions begin where arguments end 18932767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl return arg_type_end(); 18942767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl } 18952767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl exception_iterator exception_end() const { 18962767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl return exception_begin() + NumExceptions; 18972767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl } 18982767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18990afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 19000afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 19010afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1902b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1903b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 19044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 19054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionProto; 19064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 19074fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 19082767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 19094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID); 19104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 19114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 19122767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool isVariadic, unsigned TypeQuals, 19132767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasExceptionSpec, bool anyExceptionSpec, 19141bb806498909a43a7829edb21c42606335d69694Mike Stump unsigned NumExceptions, exception_iterator Exs, 1915db5993538c7f29ea7331dcb7292c083e1bab798cJohn McCall bool NoReturn, CallingConv CallConv); 19164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 19174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 19184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1919caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// \brief Represents the dependent type named by a dependently-scoped 1920caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// typename using declaration, e.g. 1921caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// using typename Base<T>::foo; 1922caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// Template instantiation turns these into the underlying type. 1923caf383ae337966d67380b6b161fab17ec2b53d04John McCallclass UnresolvedUsingType : public Type { 1924caf383ae337966d67380b6b161fab17ec2b53d04John McCall UnresolvedUsingTypenameDecl *Decl; 1925caf383ae337966d67380b6b161fab17ec2b53d04John McCall 1926caf383ae337966d67380b6b161fab17ec2b53d04John McCall UnresolvedUsingType(UnresolvedUsingTypenameDecl *D) 1927caf383ae337966d67380b6b161fab17ec2b53d04John McCall : Type(UnresolvedUsing, QualType(), true), Decl(D) {} 1928caf383ae337966d67380b6b161fab17ec2b53d04John McCall friend class ASTContext; // ASTContext creates these. 1929caf383ae337966d67380b6b161fab17ec2b53d04John McCallpublic: 1930caf383ae337966d67380b6b161fab17ec2b53d04John McCall 1931caf383ae337966d67380b6b161fab17ec2b53d04John McCall UnresolvedUsingTypenameDecl *getDecl() const { return Decl; } 1932caf383ae337966d67380b6b161fab17ec2b53d04John McCall 1933caf383ae337966d67380b6b161fab17ec2b53d04John McCall bool isSugared() const { return false; } 1934caf383ae337966d67380b6b161fab17ec2b53d04John McCall QualType desugar() const { return QualType(this, 0); } 1935caf383ae337966d67380b6b161fab17ec2b53d04John McCall 1936caf383ae337966d67380b6b161fab17ec2b53d04John McCall static bool classof(const Type *T) { 1937caf383ae337966d67380b6b161fab17ec2b53d04John McCall return T->getTypeClass() == UnresolvedUsing; 1938caf383ae337966d67380b6b161fab17ec2b53d04John McCall } 1939caf383ae337966d67380b6b161fab17ec2b53d04John McCall static bool classof(const UnresolvedUsingType *) { return true; } 1940caf383ae337966d67380b6b161fab17ec2b53d04John McCall 1941caf383ae337966d67380b6b161fab17ec2b53d04John McCall void Profile(llvm::FoldingSetNodeID &ID) { 1942caf383ae337966d67380b6b161fab17ec2b53d04John McCall return Profile(ID, Decl); 1943caf383ae337966d67380b6b161fab17ec2b53d04John McCall } 1944caf383ae337966d67380b6b161fab17ec2b53d04John McCall static void Profile(llvm::FoldingSetNodeID &ID, 1945caf383ae337966d67380b6b161fab17ec2b53d04John McCall UnresolvedUsingTypenameDecl *D) { 1946caf383ae337966d67380b6b161fab17ec2b53d04John McCall ID.AddPointer(D); 1947caf383ae337966d67380b6b161fab17ec2b53d04John McCall } 1948caf383ae337966d67380b6b161fab17ec2b53d04John McCall}; 1949caf383ae337966d67380b6b161fab17ec2b53d04John McCall 1950caf383ae337966d67380b6b161fab17ec2b53d04John McCall 19514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TypedefType : public Type { 19524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner TypedefDecl *Decl; 1953e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanianprotected: 195425cf760b54d3b88633827501013bc51a29b28abaMike Stump TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 19551b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, can, can->isDependentType()), Decl(D) { 19564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner assert(!isa<TypedefType>(can) && "Invalid canonical type"); 19574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 19584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 19594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 196025cf760b54d3b88633827501013bc51a29b28abaMike Stump 19614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner TypedefDecl *getDecl() const { return Decl; } 196225cf760b54d3b88633827501013bc51a29b28abaMike Stump 19634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1964a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 19654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// sum of the type qualifiers, so if you have: 19664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// typedef const int A; 19674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// typedef volatile A B; 19684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// looking through the typedefs for B will give you "const volatile A". 19694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType LookThroughTypedefs() const; 197025cf760b54d3b88633827501013bc51a29b28abaMike Stump 19710afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 19720afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const; 19730afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 19744fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 19754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const TypedefType *) { return true; } 19764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 19774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 19784fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// TypeOfExprType (GCC extension). 19794fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass TypeOfExprType : public Type { 19807cbb14653934a298c09002b87704dc6531261771Steve Naroff Expr *TOExpr; 198125cf760b54d3b88633827501013bc51a29b28abaMike Stump 198263d22fa6071690209b339451e4939de120a45e70Douglas Gregorprotected: 1983d1c0b682af81784cb991a5479097e795b5868bc4Douglas Gregor TypeOfExprType(Expr *E, QualType can = QualType()); 19847cbb14653934a298c09002b87704dc6531261771Steve Naroff friend class ASTContext; // ASTContext creates these. 19857cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic: 19867cbb14653934a298c09002b87704dc6531261771Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 198725cf760b54d3b88633827501013bc51a29b28abaMike Stump 19880afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 19890afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const; 19900afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 19910afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 19920afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 19930afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 19944fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 19954fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 19967cbb14653934a298c09002b87704dc6531261771Steve Naroff}; 19977cbb14653934a298c09002b87704dc6531261771Steve Naroff 199825cf760b54d3b88633827501013bc51a29b28abaMike Stump/// Subclass of TypeOfExprType that is used for canonical, dependent 199925cf760b54d3b88633827501013bc51a29b28abaMike Stump/// typeof(expr) types. 200025cf760b54d3b88633827501013bc51a29b28abaMike Stumpclass DependentTypeOfExprType 200163d22fa6071690209b339451e4939de120a45e70Douglas Gregor : public TypeOfExprType, public llvm::FoldingSetNode { 200263d22fa6071690209b339451e4939de120a45e70Douglas Gregor ASTContext &Context; 200325cf760b54d3b88633827501013bc51a29b28abaMike Stump 200463d22fa6071690209b339451e4939de120a45e70Douglas Gregorpublic: 200525cf760b54d3b88633827501013bc51a29b28abaMike Stump DependentTypeOfExprType(ASTContext &Context, Expr *E) 200663d22fa6071690209b339451e4939de120a45e70Douglas Gregor : TypeOfExprType(E), Context(Context) { } 200725cf760b54d3b88633827501013bc51a29b28abaMike Stump 20080afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 20090afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 20100afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 201163d22fa6071690209b339451e4939de120a45e70Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 201263d22fa6071690209b339451e4939de120a45e70Douglas Gregor Profile(ID, Context, getUnderlyingExpr()); 201363d22fa6071690209b339451e4939de120a45e70Douglas Gregor } 201425cf760b54d3b88633827501013bc51a29b28abaMike Stump 201563d22fa6071690209b339451e4939de120a45e70Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 201663d22fa6071690209b339451e4939de120a45e70Douglas Gregor Expr *E); 201763d22fa6071690209b339451e4939de120a45e70Douglas Gregor}; 201825cf760b54d3b88633827501013bc51a29b28abaMike Stump 20197cbb14653934a298c09002b87704dc6531261771Steve Naroff/// TypeOfType (GCC extension). 20207cbb14653934a298c09002b87704dc6531261771Steve Naroffclass TypeOfType : public Type { 20217cbb14653934a298c09002b87704dc6531261771Steve Naroff QualType TOType; 202225cf760b54d3b88633827501013bc51a29b28abaMike Stump TypeOfType(QualType T, QualType can) 20234fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : Type(TypeOf, can, T->isDependentType()), TOType(T) { 20247cbb14653934a298c09002b87704dc6531261771Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 20257cbb14653934a298c09002b87704dc6531261771Steve Naroff } 20267cbb14653934a298c09002b87704dc6531261771Steve Naroff friend class ASTContext; // ASTContext creates these. 20277cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic: 20287cbb14653934a298c09002b87704dc6531261771Steve Naroff QualType getUnderlyingType() const { return TOType; } 202925cf760b54d3b88633827501013bc51a29b28abaMike Stump 20300afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 20310afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getUnderlyingType(); } 20320afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 20330afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 20340afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 20350afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 20364fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 20377cbb14653934a298c09002b87704dc6531261771Steve Naroff static bool classof(const TypeOfType *) { return true; } 20387cbb14653934a298c09002b87704dc6531261771Steve Naroff}; 20394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 204093ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson/// DecltypeType (C++0x) 204193ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlssonclass DecltypeType : public Type { 204293ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson Expr *E; 204325cf760b54d3b88633827501013bc51a29b28abaMike Stump 204442f394e67047624dcc15d22239f615885ad712acAnders Carlsson // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 204542f394e67047624dcc15d22239f615885ad712acAnders Carlsson // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 204642f394e67047624dcc15d22239f615885ad712acAnders Carlsson // from it. 204742f394e67047624dcc15d22239f615885ad712acAnders Carlsson QualType UnderlyingType; 204825cf760b54d3b88633827501013bc51a29b28abaMike Stump 2049d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregorprotected: 205042f394e67047624dcc15d22239f615885ad712acAnders Carlsson DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 205193ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson friend class ASTContext; // ASTContext creates these. 205293ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlssonpublic: 205393ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson Expr *getUnderlyingExpr() const { return E; } 205442f394e67047624dcc15d22239f615885ad712acAnders Carlsson QualType getUnderlyingType() const { return UnderlyingType; } 205542f394e67047624dcc15d22239f615885ad712acAnders Carlsson 20560afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 20570afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getUnderlyingType(); } 20580afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 20590afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 20600afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return !isDependentType(); } 20610afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 206293ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 206393ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson static bool classof(const DecltypeType *) { return true; } 206493ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson}; 206525cf760b54d3b88633827501013bc51a29b28abaMike Stump 206625cf760b54d3b88633827501013bc51a29b28abaMike Stump/// Subclass of DecltypeType that is used for canonical, dependent 206725cf760b54d3b88633827501013bc51a29b28abaMike Stump/// C++0x decltype types. 2068d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { 2069d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor ASTContext &Context; 207025cf760b54d3b88633827501013bc51a29b28abaMike Stump 2071d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregorpublic: 2072d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor DependentDecltypeType(ASTContext &Context, Expr *E); 207325cf760b54d3b88633827501013bc51a29b28abaMike Stump 20740afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 20750afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 20760afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2077d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2078d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor Profile(ID, Context, getUnderlyingExpr()); 2079d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor } 208025cf760b54d3b88633827501013bc51a29b28abaMike Stump 2081d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 208225cf760b54d3b88633827501013bc51a29b28abaMike Stump Expr *E); 2083d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor}; 208425cf760b54d3b88633827501013bc51a29b28abaMike Stump 20854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TagType : public Type { 208698b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// Stores the TagDecl associated with this type. The decl will 208798b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// point to the TagDecl that actually defines the entity (or is a 208898b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// definition in progress), if there is such a definition. The 208998b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// single-bit value will be non-zero when this tag is in the 209098b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// process of being defined. 20919c7825b737617339724d43bd04960852271f08e2Douglas Gregor mutable llvm::PointerIntPair<TagDecl *, 1> decl; 209246a837c7ced306c55d1686cea5f77cb7a2f3b908Ted Kremenek friend class ASTContext; 209398b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor friend class TagDecl; 20941d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor 20951d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregorprotected: 20969054f9878dbe2b1b8384c951ad07759d9de9dc8cDouglas Gregor TagType(TypeClass TC, TagDecl *D, QualType can); 20971d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor 209825cf760b54d3b88633827501013bc51a29b28abaMike Stumppublic: 209998b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor TagDecl *getDecl() const { return decl.getPointer(); } 210025cf760b54d3b88633827501013bc51a29b28abaMike Stump 210198b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// @brief Determines whether this type is in the process of being 210225cf760b54d3b88633827501013bc51a29b28abaMike Stump /// defined. 210398b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor bool isBeingDefined() const { return decl.getInt(); } 21043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setBeingDefined(bool Def) const { decl.setInt(Def? 1 : 0); } 210598b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor 2106b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 2107b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 210825cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 21094fa58905062efa6a12137b1983a1367220182a20Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 21104fa58905062efa6a12137b1983a1367220182a20Douglas Gregor } 21114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const TagType *) { return true; } 21124fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const RecordType *) { return true; } 21134fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const EnumType *) { return true; } 21144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 21154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 21161baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 21171baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of structs/unions/classes. 21181baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass RecordType : public TagType { 2119ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidisprotected: 21203cbc064cf343c2151488b7822430ed327ade176eArgiris Kirtzidis explicit RecordType(RecordDecl *D) 21214fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 21224fa58905062efa6a12137b1983a1367220182a20Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 21234fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 21241d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor friend class ASTContext; // ASTContext creates these. 21251baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic: 212625cf760b54d3b88633827501013bc51a29b28abaMike Stump 21271baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner RecordDecl *getDecl() const { 21281baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 21291baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner } 213025cf760b54d3b88633827501013bc51a29b28abaMike Stump 213125cf760b54d3b88633827501013bc51a29b28abaMike Stump // FIXME: This predicate is a helper to QualType/Type. It needs to 21321baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // recursively check all fields for const-ness. If any field is declared 213325cf760b54d3b88633827501013bc51a29b28abaMike Stump // const, it needs to return false. 21341baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner bool hasConstFields() const { return false; } 21351baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 21361baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 21371baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // the same address space, and return that. 21381baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner unsigned getAddressSpace() const { return 0; } 213925cf760b54d3b88633827501013bc51a29b28abaMike Stump 21400afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 21410afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 21420afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2143eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const TagType *T); 2144eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const Type *T) { 2145eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 2146eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner } 21471baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner static bool classof(const RecordType *) { return true; } 21481baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner}; 21491baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 21501baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 21511baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of enums. 21521baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass EnumType : public TagType { 21533cbc064cf343c2151488b7822430ed327ade176eArgiris Kirtzidis explicit EnumType(EnumDecl *D) 21544fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 21551d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor friend class ASTContext; // ASTContext creates these. 21561baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic: 215725cf760b54d3b88633827501013bc51a29b28abaMike Stump 21581baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner EnumDecl *getDecl() const { 21591baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 21601baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner } 216125cf760b54d3b88633827501013bc51a29b28abaMike Stump 21620afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 21630afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 21640afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2165eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const TagType *T); 2166eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const Type *T) { 2167eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 2168eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner } 21691baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner static bool classof(const EnumType *) { return true; } 21701baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner}; 21711baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 2172379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// ElaboratedType - A non-canonical type used to represents uses of 2173379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// elaborated type specifiers in C++. For example: 2174379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// 2175379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// void foo(union MyUnion); 2176379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// ^^^^^^^^^^^^^ 2177379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// 2178379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// At the moment, for efficiency we do not create elaborated types in 2179379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// C, since outside of typedefs all references to structs would 2180379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// necessarily be elaborated. 2181379448fc7bc91bba33e3d2df073f6cf011960b96John McCallclass ElaboratedType : public Type, public llvm::FoldingSetNode { 2182379448fc7bc91bba33e3d2df073f6cf011960b96John McCallpublic: 2183379448fc7bc91bba33e3d2df073f6cf011960b96John McCall enum TagKind { 2184379448fc7bc91bba33e3d2df073f6cf011960b96John McCall TK_struct, 2185379448fc7bc91bba33e3d2df073f6cf011960b96John McCall TK_union, 2186379448fc7bc91bba33e3d2df073f6cf011960b96John McCall TK_class, 2187379448fc7bc91bba33e3d2df073f6cf011960b96John McCall TK_enum 2188379448fc7bc91bba33e3d2df073f6cf011960b96John McCall }; 2189379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 2190379448fc7bc91bba33e3d2df073f6cf011960b96John McCallprivate: 2191379448fc7bc91bba33e3d2df073f6cf011960b96John McCall /// The tag that was used in this elaborated type specifier. 2192379448fc7bc91bba33e3d2df073f6cf011960b96John McCall TagKind Tag; 2193379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 2194379448fc7bc91bba33e3d2df073f6cf011960b96John McCall /// The underlying type. 2195379448fc7bc91bba33e3d2df073f6cf011960b96John McCall QualType UnderlyingType; 2196379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 2197379448fc7bc91bba33e3d2df073f6cf011960b96John McCall explicit ElaboratedType(QualType Ty, TagKind Tag, QualType Canon) 2198379448fc7bc91bba33e3d2df073f6cf011960b96John McCall : Type(Elaborated, Canon, Canon->isDependentType()), 2199379448fc7bc91bba33e3d2df073f6cf011960b96John McCall Tag(Tag), UnderlyingType(Ty) { } 2200379448fc7bc91bba33e3d2df073f6cf011960b96John McCall friend class ASTContext; // ASTContext creates these. 2201379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 2202379448fc7bc91bba33e3d2df073f6cf011960b96John McCallpublic: 2203379448fc7bc91bba33e3d2df073f6cf011960b96John McCall TagKind getTagKind() const { return Tag; } 2204379448fc7bc91bba33e3d2df073f6cf011960b96John McCall QualType getUnderlyingType() const { return UnderlyingType; } 2205379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 22060afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 22070afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getUnderlyingType(); } 22080afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 22090afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 22100afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 22110afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2212379448fc7bc91bba33e3d2df073f6cf011960b96John McCall static const char *getNameForTagKind(TagKind Kind) { 2213379448fc7bc91bba33e3d2df073f6cf011960b96John McCall switch (Kind) { 2214379448fc7bc91bba33e3d2df073f6cf011960b96John McCall default: assert(0 && "Unknown TagKind!"); 2215379448fc7bc91bba33e3d2df073f6cf011960b96John McCall case TK_struct: return "struct"; 2216379448fc7bc91bba33e3d2df073f6cf011960b96John McCall case TK_union: return "union"; 2217379448fc7bc91bba33e3d2df073f6cf011960b96John McCall case TK_class: return "class"; 2218379448fc7bc91bba33e3d2df073f6cf011960b96John McCall case TK_enum: return "enum"; 2219379448fc7bc91bba33e3d2df073f6cf011960b96John McCall } 2220379448fc7bc91bba33e3d2df073f6cf011960b96John McCall } 2221379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 2222379448fc7bc91bba33e3d2df073f6cf011960b96John McCall void Profile(llvm::FoldingSetNodeID &ID) { 2223379448fc7bc91bba33e3d2df073f6cf011960b96John McCall Profile(ID, getUnderlyingType(), getTagKind()); 2224379448fc7bc91bba33e3d2df073f6cf011960b96John McCall } 2225379448fc7bc91bba33e3d2df073f6cf011960b96John McCall static void Profile(llvm::FoldingSetNodeID &ID, QualType T, TagKind Tag) { 2226379448fc7bc91bba33e3d2df073f6cf011960b96John McCall ID.AddPointer(T.getAsOpaquePtr()); 2227379448fc7bc91bba33e3d2df073f6cf011960b96John McCall ID.AddInteger(Tag); 2228379448fc7bc91bba33e3d2df073f6cf011960b96John McCall } 2229379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 2230379448fc7bc91bba33e3d2df073f6cf011960b96John McCall static bool classof(const ElaboratedType*) { return true; } 2231379448fc7bc91bba33e3d2df073f6cf011960b96John McCall static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; } 2232379448fc7bc91bba33e3d2df073f6cf011960b96John McCall}; 2233379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 2234a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 22354e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson unsigned Depth : 15; 2236a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor unsigned Index : 16; 22374e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson unsigned ParameterPack : 1; 2238a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor IdentifierInfo *Name; 2239dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 224025cf760b54d3b88633827501013bc51a29b28abaMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 224125cf760b54d3b88633827501013bc51a29b28abaMike Stump QualType Canon) 2242a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 22434e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(N) { } 2244dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 224525cf760b54d3b88633827501013bc51a29b28abaMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP) 2246a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 22474e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(0) { } 2248dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 2249a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor friend class ASTContext; // ASTContext creates these 2250dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 2251a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregorpublic: 2252a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor unsigned getDepth() const { return Depth; } 2253a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor unsigned getIndex() const { return Index; } 22544e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson bool isParameterPack() const { return ParameterPack; } 2255a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor IdentifierInfo *getName() const { return Name; } 225625cf760b54d3b88633827501013bc51a29b28abaMike Stump 22570afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 22580afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 22590afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2260a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 22614e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson Profile(ID, Depth, Index, ParameterPack, Name); 2262a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor } 2263a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 226425cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 226525cf760b54d3b88633827501013bc51a29b28abaMike Stump unsigned Index, bool ParameterPack, 22664e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson IdentifierInfo *Name) { 2267a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor ID.AddInteger(Depth); 2268a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor ID.AddInteger(Index); 22694e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson ID.AddBoolean(ParameterPack); 2270a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor ID.AddPointer(Name); 2271a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor } 2272a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 227325cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 227425cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == TemplateTypeParm; 2275dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor } 2276dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 2277dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor}; 2278a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 22795cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// \brief Represents the result of substituting a type for a template 22805cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// type parameter. 22815cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// 22825cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// Within an instantiated template, all template type parameters have 22835cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// been replaced with these. They are used solely to record that a 22845cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// type was originally written as a template type parameter; 22855cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// therefore they are never canonical. 22865cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode { 22875cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall // The original type parameter. 22885cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall const TemplateTypeParmType *Replaced; 22895cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 22905cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) 22915cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType()), 22925cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall Replaced(Param) { } 22935cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 22945cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall friend class ASTContext; 22955cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 22965cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCallpublic: 22975cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall IdentifierInfo *getName() const { return Replaced->getName(); } 22985cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 22995cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall /// Gets the template parameter that was substituted for. 23005cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall const TemplateTypeParmType *getReplacedParameter() const { 23015cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall return Replaced; 23025cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 23035cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23045cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall /// Gets the type that was substituted for the template 23055cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall /// parameter. 23065cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall QualType getReplacementType() const { 23075cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall return getCanonicalTypeInternal(); 23085cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 23095cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23105cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall bool isSugared() const { return true; } 23115cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall QualType desugar() const { return getReplacementType(); } 23125cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23135cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall void Profile(llvm::FoldingSetNodeID &ID) { 23145cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall Profile(ID, getReplacedParameter(), getReplacementType()); 23155cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 23165cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall static void Profile(llvm::FoldingSetNodeID &ID, 23175cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall const TemplateTypeParmType *Replaced, 23185cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall QualType Replacement) { 23195cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall ID.AddPointer(Replaced); 23205cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall ID.AddPointer(Replacement.getAsOpaquePtr()); 23215cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 23225cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23235cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall static bool classof(const Type *T) { 23245cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall return T->getTypeClass() == SubstTemplateTypeParm; 23255cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 23265cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall static bool classof(const SubstTemplateTypeParmType *T) { return true; } 23275cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall}; 23285cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 2329dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// \brief Represents the type of a template specialization as written 2330dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// in the source code. 23318e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// 2332dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// Template specialization types represent the syntactic form of a 2333dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 2334dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 2335dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// type will point to some other type node that represents the 2336dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// instantiation or class template specialization. For example, a 23378e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// class template specialization type of @c vector<int> will refer to 233825cf760b54d3b88633827501013bc51a29b28abaMike Stump/// a tag type for the instantiation 23398e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 2340dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// 2341dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// Other template specialization types, for which the template name 2342dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// is dependent, may be canonical types. These types are always 2343dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// dependent. 234425cf760b54d3b88633827501013bc51a29b28abaMike Stumpclass TemplateSpecializationType 23458e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor : public Type, public llvm::FoldingSetNode { 23468e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 234799eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor // FIXME: Currently needed for profiling expressions; can we avoid this? 234899eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor ASTContext &Context; 234925cf760b54d3b88633827501013bc51a29b28abaMike Stump 235099eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor /// \brief The name of the template being specialized. 2351dd13e8468462e60971487bcd5915419762dab814Douglas Gregor TemplateName Template; 23528e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 2353f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief - The number of template arguments named in this class 2354f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// template specialization. 23558e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor unsigned NumArgs; 23568e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 235799eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor TemplateSpecializationType(ASTContext &Context, 235899eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor TemplateName T, 2359dd13e8468462e60971487bcd5915419762dab814Douglas Gregor const TemplateArgument *Args, 2360dd13e8468462e60971487bcd5915419762dab814Douglas Gregor unsigned NumArgs, QualType Canon); 23618e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 23626f37b58716e89420c13ac067fe605c3b6d5821d0Douglas Gregor virtual void Destroy(ASTContext& C); 23636f37b58716e89420c13ac067fe605c3b6d5821d0Douglas Gregor 23648e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor friend class ASTContext; // ASTContext creates these 23658e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 23668e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregorpublic: 2367f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Determine whether any of the given template arguments are 2368f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// dependent. 2369f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 237025cf760b54d3b88633827501013bc51a29b28abaMike Stump unsigned NumArgs); 2371f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2372588613178e3a10e2b840c8f4db9e058f2fec0005John McCall static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args, 2373588613178e3a10e2b840c8f4db9e058f2fec0005John McCall unsigned NumArgs); 2374588613178e3a10e2b840c8f4db9e058f2fec0005John McCall 2375ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &); 2376ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall 237756d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 237856d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor /// enclosing the template arguments. 237956d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 23803bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor unsigned NumArgs, 23813bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor const PrintingPolicy &Policy); 238256d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor 2383588613178e3a10e2b840c8f4db9e058f2fec0005John McCall static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args, 2384588613178e3a10e2b840c8f4db9e058f2fec0005John McCall unsigned NumArgs, 2385588613178e3a10e2b840c8f4db9e058f2fec0005John McCall const PrintingPolicy &Policy); 2386588613178e3a10e2b840c8f4db9e058f2fec0005John McCall 2387ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &, 2388ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall const PrintingPolicy &Policy); 2389ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall 2390f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor typedef const TemplateArgument * iterator; 2391f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2392f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor iterator begin() const { return getArgs(); } 2393f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor iterator end() const; 2394f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2395dd13e8468462e60971487bcd5915419762dab814Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 2396dd13e8468462e60971487bcd5915419762dab814Douglas Gregor TemplateName getTemplateName() const { return Template; } 23978e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 2398f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Retrieve the template arguments. 239925cf760b54d3b88633827501013bc51a29b28abaMike Stump const TemplateArgument *getArgs() const { 2400f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 2401f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor } 2402f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2403f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Retrieve the number of template arguments. 24048e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 24058e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 24068e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor /// \brief Retrieve a specific template argument as a type. 24078e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor /// \precondition @c isArgType(Arg) 2408f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor const TemplateArgument &getArg(unsigned Idx) const; 24098e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 24100afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return !isDependentType(); } 24110afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getCanonicalTypeInternal(); } 24120afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 24138e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 241499eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor Profile(ID, Template, getArgs(), NumArgs, Context); 24158e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor } 24168e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 2417dd13e8468462e60971487bcd5915419762dab814Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 241899eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor const TemplateArgument *Args, unsigned NumArgs, 241999eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor ASTContext &Context); 24208e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 242125cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 242225cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == TemplateSpecialization; 24238e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor } 2424dd13e8468462e60971487bcd5915419762dab814Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 24258e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor}; 24268e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 2427734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// \brief Represents a type that was referred to via a qualified 2428734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// name, e.g., N::M::type. 2429734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// 2430734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// This type is used to keep track of a type name as written in the 2431e615803e1c4a70ba66b6687b2b95e1fdcd16cd3bDouglas Gregor/// source code, including any nested-name-specifiers. The type itself 2432e615803e1c4a70ba66b6687b2b95e1fdcd16cd3bDouglas Gregor/// is always "sugar", used to express what was written in the source 2433e615803e1c4a70ba66b6687b2b95e1fdcd16cd3bDouglas Gregor/// code but containing no additional semantic information. 2434734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode { 24351e589cc31d339860b9df61870930961601d68120Douglas Gregor /// \brief The nested name specifier containing the qualifier. 24361e589cc31d339860b9df61870930961601d68120Douglas Gregor NestedNameSpecifier *NNS; 2437734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2438734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor /// \brief The type that this qualified name refers to. 2439734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor QualType NamedType; 2440734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 24411e589cc31d339860b9df61870930961601d68120Douglas Gregor QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 24421e589cc31d339860b9df61870930961601d68120Douglas Gregor QualType CanonType) 24431e589cc31d339860b9df61870930961601d68120Douglas Gregor : Type(QualifiedName, CanonType, NamedType->isDependentType()), 24441e589cc31d339860b9df61870930961601d68120Douglas Gregor NNS(NNS), NamedType(NamedType) { } 2445734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2446734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor friend class ASTContext; // ASTContext creates these 2447734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2448734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorpublic: 24491e589cc31d339860b9df61870930961601d68120Douglas Gregor /// \brief Retrieve the qualification on this type. 24501e589cc31d339860b9df61870930961601d68120Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2451734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2452734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 2453734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor QualType getNamedType() const { return NamedType; } 2454734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 24550afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 24560afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getNamedType(); } 24570afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 24580afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 24590afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 24600afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2461734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 24621e589cc31d339860b9df61870930961601d68120Douglas Gregor Profile(ID, NNS, NamedType); 2463734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor } 2464734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 24651e589cc31d339860b9df61870930961601d68120Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 24661e589cc31d339860b9df61870930961601d68120Douglas Gregor QualType NamedType) { 24671e589cc31d339860b9df61870930961601d68120Douglas Gregor ID.AddPointer(NNS); 24681e589cc31d339860b9df61870930961601d68120Douglas Gregor NamedType.Profile(ID); 24691e589cc31d339860b9df61870930961601d68120Douglas Gregor } 2470734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 247125cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 247225cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == QualifiedName; 2473734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor } 2474734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor static bool classof(const QualifiedNameType *T) { return true; } 2475734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor}; 2476734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2477d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// \brief Represents a 'typename' specifier that names a type within 2478d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// a dependent type, e.g., "typename T::type". 2479d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// 2480d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// TypenameType has a very similar structure to QualifiedNameType, 2481d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// which also involves a nested-name-specifier following by a type, 2482d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// and (FIXME!) both can even be prefixed by the 'typename' 2483d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// keyword. However, the two types serve very different roles: 2484d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// QualifiedNameType is a non-semantic type that serves only as sugar 2485d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// to show how a particular type was written in the source 2486d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// code. TypenameType, on the other hand, only occurs when the 2487d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// nested-name-specifier is dependent, such that we cannot resolve 2488d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// the actual type until after instantiation. 2489d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregorclass TypenameType : public Type, public llvm::FoldingSetNode { 2490d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor /// \brief The nested name specifier containing the qualifier. 2491d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor NestedNameSpecifier *NNS; 2492d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 249325cf760b54d3b88633827501013bc51a29b28abaMike Stump typedef llvm::PointerUnion<const IdentifierInfo *, 249477da58034d00866f3261d2c657a5823578f73028Douglas Gregor const TemplateSpecializationType *> NameType; 249577da58034d00866f3261d2c657a5823578f73028Douglas Gregor 2496d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor /// \brief The type that this typename specifier refers to. 249777da58034d00866f3261d2c657a5823578f73028Douglas Gregor NameType Name; 2498d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2499d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 2500d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor QualType CanonType) 250125cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 250225cf760b54d3b88633827501013bc51a29b28abaMike Stump assert(NNS->isDependent() && 2503d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 2504d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2505d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 250677da58034d00866f3261d2c657a5823578f73028Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 250777da58034d00866f3261d2c657a5823578f73028Douglas Gregor QualType CanonType) 250825cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 250925cf760b54d3b88633827501013bc51a29b28abaMike Stump assert(NNS->isDependent() && 251077da58034d00866f3261d2c657a5823578f73028Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 251177da58034d00866f3261d2c657a5823578f73028Douglas Gregor } 251277da58034d00866f3261d2c657a5823578f73028Douglas Gregor 2513d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor friend class ASTContext; // ASTContext creates these 2514d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2515d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregorpublic: 2516d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor /// \brief Retrieve the qualification on this type. 2517d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2518d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 251977da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 252077da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// identifier. 252177da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// 252277da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 252377da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// form of the original typename was terminated by an identifier, 252477da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// e.g., "typename T::type". 252525cf760b54d3b88633827501013bc51a29b28abaMike Stump const IdentifierInfo *getIdentifier() const { 252625cf760b54d3b88633827501013bc51a29b28abaMike Stump return Name.dyn_cast<const IdentifierInfo *>(); 252777da58034d00866f3261d2c657a5823578f73028Douglas Gregor } 252877da58034d00866f3261d2c657a5823578f73028Douglas Gregor 252977da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// \brief Retrieve the type named by the typename specifier as a 253077da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// type specialization. 253177da58034d00866f3261d2c657a5823578f73028Douglas Gregor const TemplateSpecializationType *getTemplateId() const { 253277da58034d00866f3261d2c657a5823578f73028Douglas Gregor return Name.dyn_cast<const TemplateSpecializationType *>(); 253377da58034d00866f3261d2c657a5823578f73028Douglas Gregor } 2534d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 25350afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 25360afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 25370afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2538d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2539d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor Profile(ID, NNS, Name); 2540d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2541d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2542d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 254377da58034d00866f3261d2c657a5823578f73028Douglas Gregor NameType Name) { 2544d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor ID.AddPointer(NNS); 254577da58034d00866f3261d2c657a5823578f73028Douglas Gregor ID.AddPointer(Name.getOpaqueValue()); 2546d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2547d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 254825cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 254925cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == Typename; 2550d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2551d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor static bool classof(const TypenameType *T) { return true; } 2552d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor}; 2553d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2554f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 2555f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// object oriented design. They basically correspond to C++ classes. There 2556f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and 2557f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// qualified interfaces, which are qualified with a protocol list like 255877763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff/// "NSString<NSCopyable, NSAmazing>". 255977763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroffclass ObjCInterfaceType : public Type, public llvm::FoldingSetNode { 256042730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCInterfaceDecl *Decl; 256177763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff 25621b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// \brief The number of protocols stored after the ObjCInterfaceType node. 25631b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// The list of protocols is sorted on protocol name. No protocol is enterred 25641b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// more than once. 256539abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek unsigned NumProtocols; 256677763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff 25671b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor ObjCInterfaceType(QualType Canonical, ObjCInterfaceDecl *D, 256839abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek ObjCProtocolDecl **Protos, unsigned NumP); 256981f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff friend class ASTContext; // ASTContext creates these. 257081f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroffpublic: 257139abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek void Destroy(ASTContext& C); 257239abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek 257342730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 257425cf760b54d3b88633827501013bc51a29b28abaMike Stump 257577763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 257677763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff /// interface type, or 0 if there are none. 257739abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek unsigned getNumProtocols() const { return NumProtocols; } 2578329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 2579f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner /// qual_iterator and friends: this provides access to the (potentially empty) 258077763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff /// list of protocols qualifying this interface. 258139abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek typedef ObjCProtocolDecl* const * qual_iterator; 258239abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek qual_iterator qual_begin() const { 25831b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor return reinterpret_cast<qual_iterator>(this + 1); 258439abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek } 258539abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek qual_iterator qual_end() const { 25861b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor return qual_begin() + NumProtocols; 258739abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek } 258839abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek bool qual_empty() const { return NumProtocols == 0; } 258925cf760b54d3b88633827501013bc51a29b28abaMike Stump 25900afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 25910afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 25920afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 259377763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 259425cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, 259577763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff const ObjCInterfaceDecl *Decl, 25961b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor ObjCProtocolDecl * const *protocols, 25971b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor unsigned NumProtocols); 259825cf760b54d3b88633827501013bc51a29b28abaMike Stump 2599b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 2600b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 260125cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 260225cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == ObjCInterface; 260381f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff } 260442730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 260581f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff}; 260681f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff 2607329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff/// ObjCObjectPointerType - Used to represent 'id', 'Interface *', 'id <p>', 2608329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff/// and 'Interface <p> *'. 2609329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff/// 2610329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff/// Duplicate protocols are removed and protocol list is canonicalized to be in 2611329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff/// alphabetical order. 2612329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 26139f324ae90f87c56d3c1fc87b27bb9b6ebdf277b0Steve Naroff QualType PointeeType; // A builtin or interface type. 261425cf760b54d3b88633827501013bc51a29b28abaMike Stump 26151b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// \brief The number of protocols stored after the ObjCObjectPointerType 26161b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// node. 26171b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// 26181b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// The list of protocols is sorted on protocol name. No protocol is enterred 26191b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// more than once. 262039abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek unsigned NumProtocols; 2621329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 26221b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor ObjCObjectPointerType(QualType Canonical, QualType T, 262339abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek ObjCProtocolDecl **Protos, unsigned NumP); 2624329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff friend class ASTContext; // ASTContext creates these. 262525cf760b54d3b88633827501013bc51a29b28abaMike Stump 2626329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffpublic: 262739abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek void Destroy(ASTContext& C); 262839abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek 2629a960479e82ebf6c28dfc5843f0d8bf34db5702e3Steve Naroff // Get the pointee type. Pointee will either be: 2630a960479e82ebf6c28dfc5843f0d8bf34db5702e3Steve Naroff // - a built-in type (for 'id' and 'Class'). 2631a960479e82ebf6c28dfc5843f0d8bf34db5702e3Steve Naroff // - an interface type (for user-defined types). 2632a960479e82ebf6c28dfc5843f0d8bf34db5702e3Steve Naroff // - a TypedefType whose canonical type is an interface (as in 'T' below). 2633a960479e82ebf6c28dfc5843f0d8bf34db5702e3Steve Naroff // For example: typedef NSObject T; T *var; 2634329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff QualType getPointeeType() const { return PointeeType; } 2635329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 263625cf760b54d3b88633827501013bc51a29b28abaMike Stump const ObjCInterfaceType *getInterfaceType() const { 2637cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall return PointeeType->getAs<ObjCInterfaceType>(); 2638329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 26397bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff /// getInterfaceDecl - returns an interface decl for user-defined types. 2640329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff ObjCInterfaceDecl *getInterfaceDecl() const { 26417bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff return getInterfaceType() ? getInterfaceType()->getDecl() : 0; 2642329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 26437bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff /// isObjCIdType - true for "id". 2644329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCIdType() const { 264525cf760b54d3b88633827501013bc51a29b28abaMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && 264639abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek !NumProtocols; 2647329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 26487bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff /// isObjCClassType - true for "Class". 2649329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCClassType() const { 265025cf760b54d3b88633827501013bc51a29b28abaMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) && 265139abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek !NumProtocols; 26527bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff } 26532818bd26562e1a2b7d7e9fb31d72f698a5748289Fariborz Jahanian 26547bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff /// isObjCQualifiedIdType - true for "id <p>". 265525cf760b54d3b88633827501013bc51a29b28abaMike Stump bool isObjCQualifiedIdType() const { 265625cf760b54d3b88633827501013bc51a29b28abaMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && 265739abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek NumProtocols; 26587bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff } 26597bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff /// isObjCQualifiedClassType - true for "Class <p>". 266027bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff bool isObjCQualifiedClassType() const { 266125cf760b54d3b88633827501013bc51a29b28abaMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) && 266239abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek NumProtocols; 2663329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 2664329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff /// qual_iterator and friends: this provides access to the (potentially empty) 2665329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff /// list of protocols qualifying this interface. 266639abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek typedef ObjCProtocolDecl* const * qual_iterator; 2667329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 266839abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek qual_iterator qual_begin() const { 26691b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor return reinterpret_cast<qual_iterator> (this + 1); 267039abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek } 267139abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek qual_iterator qual_end() const { 26721b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor return qual_begin() + NumProtocols; 267339abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek } 267439abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek bool qual_empty() const { return NumProtocols == 0; } 2675329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 2676329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 2677329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff /// interface type, or 0 if there are none. 267839abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek unsigned getNumProtocols() const { return NumProtocols; } 2679329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 26800afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 26810afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 26820afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2683b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 2684b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 2685329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff void Profile(llvm::FoldingSetNodeID &ID); 2686329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType T, 26871b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor ObjCProtocolDecl *const *protocols, 26881b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor unsigned NumProtocols); 268925cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 269025cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == ObjCObjectPointer; 2691329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 2692329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 2693329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff}; 2694fd3d5fdac0d25464e1b9c36bc646965494d44f66Argiris Kirtzidis 26953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// A qualifier set is used to build a set of qualifiers. 26963ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallclass QualifierCollector : public Qualifiers { 26973ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ASTContext *Context; 26983ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 26993ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallpublic: 27003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector(Qualifiers Qs = Qualifiers()) 27013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Qualifiers(Qs), Context(0) {} 27023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector(ASTContext &Context, Qualifiers Qs = Qualifiers()) 27033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Qualifiers(Qs), Context(&Context) {} 27043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setContext(ASTContext &C) { Context = &C; } 27063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Collect any qualifiers on the given type and return an 27083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// unqualified type. 27093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *strip(QualType QT) { 2710c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor addFastQualifiers(QT.getLocalFastQualifiers()); 2711c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (QT.hasLocalNonFastQualifiers()) { 27123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = QT.getExtQualsUnsafe(); 27133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Context = &EQ->getContext(); 27143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall addQualifiers(EQ->getQualifiers()); 27153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getBaseType(); 27163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 27173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return QT.getTypePtrUnsafe(); 27183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 27193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Apply the collected qualifiers to the given type. 27213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType apply(QualType QT) const; 27223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27233ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Apply the collected qualifiers to the given type. 27243ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType apply(const Type* T) const; 27253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall}; 27273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2729b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner// Inline function definitions. 27304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 27317480534aa1979f5c8a6c1d59ede223ba21f280e5John McCallinline bool QualType::isCanonical() const { 27327480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall const Type *T = getTypePtr(); 2733c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalQualifiers()) 27347480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall return T->isCanonicalUnqualified() && !isa<ArrayType>(T); 27357480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall return T->isCanonicalUnqualified(); 27367480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall} 27377480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall 27384ea8425c9601895fa137f877bc784f75f20adac6John McCallinline bool QualType::isCanonicalAsParam() const { 2739c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalQualifiers()) return false; 27404ea8425c9601895fa137f877bc784f75f20adac6John McCall const Type *T = getTypePtr(); 27414ea8425c9601895fa137f877bc784f75f20adac6John McCall return T->isCanonicalUnqualified() && 27424ea8425c9601895fa137f877bc784f75f20adac6John McCall !isa<FunctionType>(T) && !isa<ArrayType>(T); 27434ea8425c9601895fa137f877bc784f75f20adac6John McCall} 27444ea8425c9601895fa137f877bc784f75f20adac6John McCall 27454f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::isConstQualified() const { 27464f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return isLocalConstQualified() || 27474f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalConstQualified(); 27484f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 27494f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 27504f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::isRestrictQualified() const { 27514f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return isLocalRestrictQualified() || 27524f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalRestrictQualified(); 27534f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 27544f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 27554f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 27564f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::isVolatileQualified() const { 27574f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return isLocalVolatileQualified() || 27584f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalVolatileQualified(); 27594f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 27604f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 27614f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::hasQualifiers() const { 27624f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return hasLocalQualifiers() || 27634f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers(); 27644f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 27654f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 27664f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline Qualifiers QualType::getQualifiers() const { 27674f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor Qualifiers Quals = getLocalQualifiers(); 27684f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor Quals.addQualifiers( 27694f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().getLocalQualifiers()); 27704f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return Quals; 27714f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 27724f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 27734f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline unsigned QualType::getCVRQualifiers() const { 27744f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return getLocalCVRQualifiers() | 27754f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().getLocalCVRQualifiers(); 27764f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 27776d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth 27786d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// getCVRQualifiersThroughArrayTypes - If there are CVR qualifiers for this 27796d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// type, returns them. Otherwise, if this is an array type, recurses 27806d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// on the element type until some qualifiers have been found or a non-array 27816d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// type reached. 27826d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruthinline unsigned QualType::getCVRQualifiersThroughArrayTypes() const { 27836d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth if (unsigned Quals = getCVRQualifiers()) 27846d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth return Quals; 27856d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth QualType CT = getTypePtr()->getCanonicalTypeInternal(); 27866d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 27876d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth return AT->getElementType().getCVRQualifiersThroughArrayTypes(); 27886d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth return 0; 27896d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth} 27906d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth 27913ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeConst() { 27923ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeFastQualifiers(Qualifiers::Const); 27933ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall} 27943ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeRestrict() { 27963ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeFastQualifiers(Qualifiers::Restrict); 27973ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall} 27983ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27993ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeVolatile() { 28003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector Qc; 28013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *Ty = Qc.strip(*this); 28023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (Qc.hasVolatile()) { 28033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qc.removeVolatile(); 28043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall *this = Qc.apply(Ty); 28053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 28063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall} 28073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 28083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeCVRQualifiers(unsigned Mask) { 2809451b7b9a60208869cf5d6d958134cb104343949fJohn McCall assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits"); 28103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 28113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Fast path: we don't need to touch the slow qualifiers. 28123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (!(Mask & ~Qualifiers::FastMask)) { 28133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeFastQualifiers(Mask); 28143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return; 28153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 28163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 28173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector Qc; 28183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *Ty = Qc.strip(*this); 28193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qc.removeCVRQualifiers(Mask); 28203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall *this = Qc.apply(Ty); 28212a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb} 28222a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 28232a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// getAddressSpace - Return the address space of this type. 28242a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambinline unsigned QualType::getAddressSpace() const { 2825c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalNonFastQualifiers()) { 28263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = getExtQualsUnsafe(); 28273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasAddressSpace()) 28283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getAddressSpace(); 28293ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 28303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 283101ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 2832c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (CT.hasLocalNonFastQualifiers()) { 28333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = CT.getExtQualsUnsafe(); 28343ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasAddressSpace()) 28353ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getAddressSpace(); 28363ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 28373ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 283801ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2839a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return AT->getElementType().getAddressSpace(); 284001ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 2841efc11216a5755f69b5540289aa2dd374d4bc82abNate Begeman return RT->getAddressSpace(); 28422a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return 0; 28432a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb} 2844b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner 2845af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 28463ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const { 2847c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalNonFastQualifiers()) { 28483ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = getExtQualsUnsafe(); 28493ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasObjCGCAttr()) 28503ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getObjCGCAttr(); 28513ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 28523ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2853af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 2854c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (CT.hasLocalNonFastQualifiers()) { 28553ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = CT.getExtQualsUnsafe(); 28563ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasObjCGCAttr()) 28573ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getObjCGCAttr(); 28583ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 28593ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2860af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2861af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian return AT->getElementType().getObjCGCAttr(); 2862cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *PT = CT->getAs<ObjCObjectPointerType>()) 286325cf760b54d3b88633827501013bc51a29b28abaMike Stump return PT->getPointeeType().getObjCGCAttr(); 28644bb774e2352b6c5f459b345a5e0f41bd244e70a7Fariborz Jahanian // We most look at all pointer types, not just pointer to interface types. 28654bb774e2352b6c5f459b345a5e0f41bd244e70a7Fariborz Jahanian if (const PointerType *PT = CT->getAs<PointerType>()) 286625cf760b54d3b88633827501013bc51a29b28abaMike Stump return PT->getPointeeType().getObjCGCAttr(); 28673ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Qualifiers::GCNone; 2868af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian} 28691bb806498909a43a7829edb21c42606335d69694Mike Stump 28700f95d329cc0ba37faa0f3d522991a581a407482cMike Stump /// getNoReturnAttr - Returns true if the type has the noreturn attribute, 28710f95d329cc0ba37faa0f3d522991a581a407482cMike Stump /// false otherwise. 28721bb806498909a43a7829edb21c42606335d69694Mike Stumpinline bool QualType::getNoReturnAttr() const { 28731bb806498909a43a7829edb21c42606335d69694Mike Stump QualType CT = getTypePtr()->getCanonicalTypeInternal(); 2874d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const PointerType *PT = getTypePtr()->getAs<PointerType>()) { 2875cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>()) 28761bb806498909a43a7829edb21c42606335d69694Mike Stump return FT->getNoReturnAttr(); 2877cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall } else if (const FunctionType *FT = getTypePtr()->getAs<FunctionType>()) 28781bb806498909a43a7829edb21c42606335d69694Mike Stump return FT->getNoReturnAttr(); 28791bb806498909a43a7829edb21c42606335d69694Mike Stump 28801bb806498909a43a7829edb21c42606335d69694Mike Stump return false; 28811bb806498909a43a7829edb21c42606335d69694Mike Stump} 288225cf760b54d3b88633827501013bc51a29b28abaMike Stump 288331cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor/// getCallConv - Returns the calling convention of the type if the type 288431cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor/// is a function type, CC_Default otherwise. 288531cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregorinline CallingConv QualType::getCallConv() const { 288631cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor if (const PointerType *PT = getTypePtr()->getAs<PointerType>()) 288731cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor return PT->getPointeeType().getCallConv(); 288831cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor else if (const ReferenceType *RT = getTypePtr()->getAs<ReferenceType>()) 288931cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor return RT->getPointeeType().getCallConv(); 289031cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor else if (const MemberPointerType *MPT = 289131cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor getTypePtr()->getAs<MemberPointerType>()) 289231cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor return MPT->getPointeeType().getCallConv(); 289331cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor else if (const BlockPointerType *BPT = 289431cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor getTypePtr()->getAs<BlockPointerType>()) { 289531cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor if (const FunctionType *FT = BPT->getPointeeType()->getAs<FunctionType>()) 289631cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor return FT->getCallConv(); 289731cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor } else if (const FunctionType *FT = getTypePtr()->getAs<FunctionType>()) 289831cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor return FT->getCallConv(); 289931cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor 290031cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor return CC_Default; 290131cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor} 290231cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor 29033fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 29043fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 29053fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// is more qualified than "const int", "volatile int", and 29063fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int". However, it is not more qualified than "const volatile 29073fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int". 29083fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 29093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // FIXME: work on arbitrary qualifiers 29106d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes(); 29116d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes(); 29128fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner if (getAddressSpace() != Other.getAddressSpace()) 29138fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner return false; 29143fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 29153fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 29163fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 29173fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 29183fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// as qualified as the Other type. For example, "const volatile 29193fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 29203fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int", and "const volatile int". 29213fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 29223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // FIXME: work on arbitrary qualifiers 29236d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes(); 29246d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes(); 29258fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner if (getAddressSpace() != Other.getAddressSpace()) 29268fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner return false; 29273fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 29283fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 29293fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 29303fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 29313fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int&), returns the type that the reference refers to ("const 29323fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 29333fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// throughout Sema to implement C++ 5p6: 29343fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// 29353fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 29363fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 29373fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// analysis, the expression designates the object or function 29383fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 29393fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline QualType QualType::getNonReferenceType() const { 2940d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 29413fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return RefType->getPointeeType(); 29423fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor else 29433fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return *this; 29443fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 29453fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 2946f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 2947d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const PointerType *PT = getAs<PointerType>()) 2948cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall return PT->getPointeeType()->getAs<ObjCInterfaceType>(); 2949f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner return 0; 2950f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner} 295125cf760b54d3b88633827501013bc51a29b28abaMike Stump 2952b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isFunctionType() const { 2953c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<FunctionType>(CanonicalType); 2954b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 2955b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isPointerType() const { 2956c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<PointerType>(CanonicalType); 2957b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 295879ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroffinline bool Type::isAnyPointerType() const { 295979ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroff return isPointerType() || isObjCObjectPointerType(); 296079ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroff} 29617aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffinline bool Type::isBlockPointerType() const { 2962c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<BlockPointerType>(CanonicalType); 29637aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff} 2964cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattnerinline bool Type::isReferenceType() const { 2965c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ReferenceType>(CanonicalType); 2966cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner} 2967ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlinline bool Type::isLValueReferenceType() const { 2968c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<LValueReferenceType>(CanonicalType); 2969ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl} 2970ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlinline bool Type::isRValueReferenceType() const { 2971c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<RValueReferenceType>(CanonicalType); 2972ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl} 297383b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenekinline bool Type::isFunctionPointerType() const { 2974d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const PointerType* T = getAs<PointerType>()) 297583b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek return T->getPointeeType()->isFunctionType(); 297683b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek else 297783b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek return false; 297883b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek} 29797555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlinline bool Type::isMemberPointerType() const { 2980c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<MemberPointerType>(CanonicalType); 29817555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl} 29827555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 2983d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const MemberPointerType* T = getAs<MemberPointerType>()) 29847555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return T->getPointeeType()->isFunctionType(); 29857555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl else 29867555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return false; 29877555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl} 2988b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isArrayType() const { 2989c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ArrayType>(CanonicalType); 2990b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 2991a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isConstantArrayType() const { 2992c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ConstantArrayType>(CanonicalType); 2993a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 2994a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isIncompleteArrayType() const { 2995c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<IncompleteArrayType>(CanonicalType); 2996a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 2997a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isVariableArrayType() const { 2998c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<VariableArrayType>(CanonicalType); 2999a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 30001b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorinline bool Type::isDependentSizedArrayType() const { 3001c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType); 30021b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor} 3003b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isRecordType() const { 3004c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<RecordType>(CanonicalType); 3005b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 30063277df47de6b65b55721726dc3f7b294e70ef6feChris Lattnerinline bool Type::isAnyComplexType() const { 3007c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ComplexType>(CanonicalType); 30083277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner} 3009b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isVectorType() const { 3010c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<VectorType>(CanonicalType); 3011b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 3012af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemaninline bool Type::isExtVectorType() const { 3013c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ExtVectorType>(CanonicalType); 3014b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 3015c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroffinline bool Type::isObjCObjectPointerType() const { 3016c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ObjCObjectPointerType>(CanonicalType); 3017c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff} 301842730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekinline bool Type::isObjCInterfaceType() const { 3019c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ObjCInterfaceType>(CanonicalType); 3020b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner} 302142730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 3022cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3023c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff return OPT->isObjCQualifiedIdType(); 3024c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff return false; 3025dcb2b1e489948a570ee07ca65e12d42edffa20efFariborz Jahanian} 302627bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroffinline bool Type::isObjCQualifiedClassType() const { 3027cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 302827bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff return OPT->isObjCQualifiedClassType(); 302927bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff return false; 303027bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff} 3031329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffinline bool Type::isObjCIdType() const { 3032cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3033329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return OPT->isObjCIdType(); 3034329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return false; 3035329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff} 3036329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffinline bool Type::isObjCClassType() const { 3037cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3038329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return OPT->isObjCClassType(); 3039329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return false; 3040329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff} 3041a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanianinline bool Type::isObjCSelType() const { 30422818bd26562e1a2b7d7e9fb31d72f698a5748289Fariborz Jahanian if (const PointerType *OPT = getAs<PointerType>()) 30432818bd26562e1a2b7d7e9fb31d72f698a5748289Fariborz Jahanian return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); 3044a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian return false; 3045a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian} 30467bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroffinline bool Type::isObjCBuiltinType() const { 3047a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian return isObjCIdType() || isObjCClassType() || isObjCSelType(); 30487bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff} 3049dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorinline bool Type::isTemplateTypeParmType() const { 3050c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType); 3051dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor} 3052dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 3053c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 3054cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 3055c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 3056c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar return true; 3057c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar return false; 3058c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar} 3059c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar 306000fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor/// \brief Determines whether this is a type for which one can define 306100fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor/// an overloaded operator. 306200fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregorinline bool Type::isOverloadableType() const { 306300fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 306445014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor} 306545014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor 3066fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 3067fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 306825cf760b54d3b88633827501013bc51a29b28abaMike Stump isObjCInterfaceType() || isObjCObjectPointerType() || 30695d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl isObjCQualifiedInterfaceType() || isNullPtrType()); 3070fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar} 3071fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar 30727c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 307325cf760b54d3b88633827501013bc51a29b28abaMike Stump return (isObjCInterfaceType() || isObjCObjectPointerType() || 30747c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian isObjCQualifiedInterfaceType()); 30757c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian} 30767c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian 3077da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 3078da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// diagnostic with <<. 3079da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 3080da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner QualType T) { 3081da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 3082da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner Diagnostic::ak_qualtype); 3083da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner return DB; 3084da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner} 308525cf760b54d3b88633827501013bc51a29b28abaMike Stump 3086406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does 3087406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor// not try to look through a qualified type to get to an array type. 3088406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregortemplate<typename T, 3089406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor bool isArrayType = (llvm::is_same<T, ArrayType>::value || 3090406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor llvm::is_base_of<ArrayType, T>::value)> 3091406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { }; 3092406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor 3093406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregortemplate<typename T> 3094406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>; 3095406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor 3096f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek/// Member-template getAs<specific type>'. 3097f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenektemplate <typename T> const T *Type::getAs() const { 3098406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor ArrayType_cannot_be_used_with_getAs<T> at; 3099406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor (void)at; 3100406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor 3101f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // If this is directly a T type, return it. 3102f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek if (const T *Ty = dyn_cast<T>(this)) 3103f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek return Ty; 310425cf760b54d3b88633827501013bc51a29b28abaMike Stump 3105f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // If the canonical form of this type isn't the right kind, reject it. 31063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (!isa<T>(CanonicalType)) 3107f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek return 0; 310825cf760b54d3b88633827501013bc51a29b28abaMike Stump 31093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // If this is a typedef for the type, strip the typedef off without 3110f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // losing all typedef information. 31110afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall return cast<T>(getUnqualifiedDesugaredType()); 311225cf760b54d3b88633827501013bc51a29b28abaMike Stump} 3113da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner 31144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner} // end namespace clang 31154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 31164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#endif 3117