Type.h revision 27dc8619071ac2ef47318bf4ff21b99a3e3793ae
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, 754d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall#define LAST_TYPE(Class) TypeLast = Class, 7554fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 7564fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#include "clang/AST/TypeNodes.def" 7574fa58905062efa6a12137b1983a1367220182a20Douglas Gregor TagFirst = Record, TagLast = Enum 7584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 759fd3d5fdac0d25464e1b9c36bc646965494d44f66Argiris Kirtzidis 7604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 7614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType CanonicalType; 7624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 7634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 764d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall unsigned TC : 8; 765d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall 766d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 7674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Note that this should stay at the end of the ivars for Type so that 7684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// subclasses can pack their bitfields into the same word. 769d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall bool Dependent : 1; 7701b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 77141b780c6caa012115bfdcccff94b9965d4de71f0Chris Lattner Type(const Type&); // DO NOT IMPLEMENT. 77241b780c6caa012115bfdcccff94b9965d4de71f0Chris Lattner void operator=(const Type&); // DO NOT IMPLEMENT. 7734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 7747c6f0c755e48a2782bc0a0a4cfc63dc84e0f11d5Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 7757c6f0c755e48a2782bc0a0a4cfc63dc84e0f11d5Hartmut Kaiser Type *this_() { return this; } 7761b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 77735fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 778d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall TC(tc), Dependent(dependent) {} 7791b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual ~Type() {} 780db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek virtual void Destroy(ASTContext& C); 7814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; 78225cf760b54d3b88633827501013bc51a29b28abaMike Stump 7834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 78492803daaa6a40a3899c2e599bddc42732c2ce593Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 78525cf760b54d3b88633827501013bc51a29b28abaMike Stump 7867480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall bool isCanonicalUnqualified() const { 7877480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall return CanonicalType.getTypePtr() == this; 7887480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall } 7894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 79025cf760b54d3b88633827501013bc51a29b28abaMike Stump /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 7914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// object types, function types, and incomplete types. 79225cf760b54d3b88633827501013bc51a29b28abaMike Stump 79326ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// \brief Determines whether the type describes an object in memory. 79426ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// 79526ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// Note that this definition of object type corresponds to the C++ 79626ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// definition of object type, which includes incomplete types, as 79726ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// opposed to the C definition (which does not include incomplete 79826ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// types). 7994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isObjectType() const; 8004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 8014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isIncompleteType - Return true if this is an incomplete type. 8024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// A type that can describe objects, but which lacks information needed to 8034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// determine its size (e.g. void, or a fwd declared struct). Clients of this 80425cf760b54d3b88633827501013bc51a29b28abaMike Stump /// routine will need to determine if the size is actually required. 8054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isIncompleteType() const; 8069db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner 8079db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 8089db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner /// type, in other words, not a function type. 8099db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner bool isIncompleteOrObjectType() const { 8109db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner return !isFunctionType(); 8119db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner } 81239c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl 81339c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 81439c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl bool isPODType() const; 81539c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl 81675067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl /// isLiteralType - Return true if this is a literal type 81775067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl /// (C++0x [basic.types]p10) 81875067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl bool isLiteralType() const; 81975067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl 8205eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 8215eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff /// types that have a non-constant expression. This does not include "[]". 8225eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff bool isVariablyModifiedType() const; 82325cf760b54d3b88633827501013bc51a29b28abaMike Stump 8244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Helper methods to distinguish type categories. All type predicates 8252a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 826c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar 827c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 828c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 82925cf760b54d3b88633827501013bc51a29b28abaMike Stump 8308888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 8318888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 8324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 8338d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isEnumeralType() const; 8348d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isBooleanType() const; 8358d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isCharType() const; 8361815b3bfc1382c88bee771bd158755b2426f0780Douglas Gregor bool isWideCharType() const; 837da86f093507a7733ae955d7511b88f8bf4f61752Douglas Gregor bool isAnyCharacterType() const; 838c81f316d260b8b8b9da21a0f9a22baa334e063fbFariborz Jahanian bool isIntegralType() const; 839da86f093507a7733ae955d7511b88f8bf4f61752Douglas Gregor 8404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Floating point categories. 8414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 8424300121ffff80d4b23d17689930e2aa2a83086b9Steve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 8434300121ffff80d4b23d17689930e2aa2a83086b9Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 8444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isComplexType() const; // C99 6.2.5p11 (complex) 8453277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 8464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 8474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 8484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 849e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isVoidType() const; // C99 6.2.5p19 850e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isDerivedType() const; // C99 6.2.5p20 851e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 852e7ef500151147ba851db502fc4d36319f863db80Douglas Gregor bool isAggregateType() const; 85325cf760b54d3b88633827501013bc51a29b28abaMike Stump 854e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner // Type Predicates: Check to see if this type is structurally the specified 8552a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb // type, ignoring typedefs and qualifiers. 856e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isFunctionType() const; 857cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } 858cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } 8597931f4a186bc76b21dd4629ee74d64264a7fb8a2Chris Lattner bool isPointerType() const; 86079ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroff bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 8617aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff bool isBlockPointerType() const; 8625ca84bccd83982d3941d68dd88139ca43f6322a0Steve Naroff bool isVoidPointerType() const; 863f0c4a0a830c9154b1ae72e497c2ce586c10e9b71Chris Lattner bool isReferenceType() const; 864ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl bool isLValueReferenceType() const; 865ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl bool isRValueReferenceType() const; 866cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner bool isFunctionPointerType() const; 8677555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl bool isMemberPointerType() const; 8687555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl bool isMemberFunctionPointerType() const; 869e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isArrayType() const; 870a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isConstantArrayType() const; 871a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isIncompleteArrayType() const; 872a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isVariableArrayType() const; 8731b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool isDependentSizedArrayType() const; 874e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isRecordType() const; 87525cf760b54d3b88633827501013bc51a29b28abaMike Stump bool isClassType() const; 87625cf760b54d3b88633827501013bc51a29b28abaMike Stump bool isStructureType() const; 87736e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff bool isUnionType() const; 878b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 879b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isVectorType() const; // GCC vector type. 880af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman bool isExtVectorType() const; // Extended vector type. 881c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 882329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // FIXME: change this to 'raw' interface type, so we can used 'interface' type 883329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // for the common case. 884b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCInterfaceType() const; // NSString or NSString<foo> 885b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 886b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCQualifiedIdType() const; // id<foo> 88727bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff bool isObjCQualifiedClassType() const; // Class<foo> 888329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCIdType() const; // id 889329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCClassType() const; // Class 890a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian bool isObjCSelType() const; // Class 8917bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff bool isObjCBuiltinType() const; // 'id' or 'Class' 892dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 8935d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 8941b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 8951b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 89625cf760b54d3b88633827501013bc51a29b28abaMike Stump /// that its definition somehow depends on a template parameter 8971b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// (C++ [temp.dep.type]). 8981b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool isDependentType() const { return Dependent; } 89900fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor bool isOverloadableType() const; 900dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 901fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 902fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 903fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 9045d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl /// interface types, as well as nullptr_t. 905fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar bool hasPointerRepresentation() const; 906fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar 9077c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 9087c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 90925cf760b54d3b88633827501013bc51a29b28abaMike Stump bool hasObjCPointerRepresentation() const; 9107c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian 911e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner // Type Checking Functions: Check to see if this type is structurally the 91235fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 91335fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner // the best type we can. 9145c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek const RecordType *getAsStructureType() const; 9151b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 916e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner const RecordType *getAsUnionType() const; 91736e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 918329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // The following is a convenience method that returns an ObjCObjectPointerType 919329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // for object declared using an interface. 920329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 921329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 92277763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff const ObjCInterfaceType *getAsObjCQualifiedInterfaceType() const; 92390e18745436d0889e8bb7fba650263b38f05694eFariborz Jahanian const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 92425cf760b54d3b88633827501013bc51a29b28abaMike Stump 925f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // Member-template getAs<specific type>'. This scheme will eventually 926f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // replace the specific getAsXXXX methods above. 927cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall // 928cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall // There are some specializations of this member template listed 929cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall // immediately following this class. 930f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek template <typename T> const T *getAs() const; 93125cf760b54d3b88633827501013bc51a29b28abaMike Stump 932f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 933f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner /// interface, return the interface type, otherwise return null. 934f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 935f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner 936a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 937a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// element type of the array, potentially with type qualifiers missing. 938a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// This method should never be used when type qualifiers are meaningful. 939a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 94025cf760b54d3b88633827501013bc51a29b28abaMike Stump 941898111463b64a26d55af56474ad8cca1fdb76268Steve Naroff /// getPointeeType - If this is a pointer, ObjC object pointer, or block 942898111463b64a26d55af56474ad8cca1fdb76268Steve Naroff /// pointer, this returns the respective pointee. 943329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff QualType getPointeeType() const; 94425cf760b54d3b88633827501013bc51a29b28abaMike Stump 9450afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// getUnqualifiedDesugaredType() - Return the specified type with 9460afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// any "sugar" removed from the type, removing any typedefs, 9470afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// typeofs, etc., as well as any qualifiers. 9480afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall const Type *getUnqualifiedDesugaredType() const; 94925cf760b54d3b88633827501013bc51a29b28abaMike Stump 9504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// More type predicates useful for type checking/promotion 9514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isPromotableIntegerType() const; // C99 6.3.1.1p2 9524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isSignedIntegerType - Return true if this is an integer type that is 954bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 955bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 956bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// integer element type. 9574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isSignedIntegerType() const; 9584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isUnsignedIntegerType - Return true if this is an integer type that is 960bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 961bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 962bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// element type. 9634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isUnsignedIntegerType() const; 964bbe686be29157b575e53fbed328613117b525f26Chris Lattner 9654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isConstantSizeType - Return true if this is not a variable sized type, 9660448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 9670448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner /// incomplete types. 96862f67fd7f670f1a8b222c6565b257c05e8e80faeEli Friedman bool isConstantSizeType() const; 969a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner 97084bca951282f362c439cc7993fcb4d145384e416Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 97184bca951282f362c439cc7993fcb4d145384e416Eli Friedman /// set of type specifiers. 97284bca951282f362c439cc7993fcb4d145384e416Eli Friedman bool isSpecifierType() const; 97384bca951282f362c439cc7993fcb4d145384e416Eli Friedman 9746cbe8f397e8fd4aa01310bcefdcbe36639eea7e0Argiris Kirtzidis const char *getTypeClassName() const; 9756cbe8f397e8fd4aa01310bcefdcbe36639eea7e0Argiris Kirtzidis 976b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor /// \brief Determine the linkage of this type. 977b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 978b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 9794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getCanonicalTypeInternal() const { return CanonicalType; } 980a55e321bd645398b514e246981c04a4889ee2472Chris Lattner void dump() const; 9814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *) { return true; } 9824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 9834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 984cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCalltemplate <> inline const TypedefType *Type::getAs() const { 985cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall return dyn_cast<TypedefType>(this); 986cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall} 987cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall 988cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall// We can do canonical leaf types faster, because we don't have to 989cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall// worry about preserving child type decoration. 990cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall#define TYPE(Class, Base) 991cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall#define LEAF_TYPE(Class) \ 992cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCalltemplate <> inline const Class##Type *Type::getAs() const { \ 9933ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return dyn_cast<Class##Type>(CanonicalType); \ 994cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall} 995cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall#include "clang/AST/TypeNodes.def" 996cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall 997cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall 9984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// BuiltinType - This class is used for builtin types like 'int'. Builtin 9994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types are always canonical and have a literal name field. 10004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass BuiltinType : public Type { 10014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 10024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum Kind { 10034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Void, 100425cf760b54d3b88633827501013bc51a29b28abaMike Stump 10054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Bool, // This is bool and/or _Bool. 10064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Char_U, // This is 'char' for targets where char is unsigned. 10074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UChar, // This is explicitly qualified unsigned char. 10082bcacb61cf94b71e5c87f29d517f8dc29fe3993eAlisdair Meredith Char16, // This is 'char16_t' for C++. 10092bcacb61cf94b71e5c87f29d517f8dc29fe3993eAlisdair Meredith Char32, // This is 'char32_t' for C++. 10104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UShort, 10114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UInt, 10124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ULong, 10134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ULongLong, 10146cc7e415d42291bf01e0295d9d6344e106613c48Chris Lattner UInt128, // __uint128_t 101525cf760b54d3b88633827501013bc51a29b28abaMike Stump 10164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Char_S, // This is 'char' for targets where char is signed. 10174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner SChar, // This is explicitly qualified signed char. 101885bd81edce4057156d7f49408147f07daa675096Argiris Kirtzidis WChar, // This is 'wchar_t' for C++. 10194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Short, 10204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Int, 10214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Long, 10224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner LongLong, 10236cc7e415d42291bf01e0295d9d6344e106613c48Chris Lattner Int128, // __int128_t 102425cf760b54d3b88633827501013bc51a29b28abaMike Stump 1025d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor Float, Double, LongDouble, 1026d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor 10275d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 10285d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl 10291b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Overload, // This represents the type of an overloaded function declaration. 10304a8498cc0f251e839912285112a014a5d1248648Anders Carlsson Dependent, // This represents the type of a type-dependent expression. 103125cf760b54d3b88633827501013bc51a29b28abaMike Stump 10327bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff UndeducedAuto, // In C++0x, this represents the type of an auto variable 10334a8498cc0f251e839912285112a014a5d1248648Anders Carlsson // that has not been deduced yet. 10347bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff ObjCId, // This represents the ObjC 'id' type. 1035a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian ObjCClass, // This represents the ObjC 'Class' type. 1036a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian ObjCSel // This represents the ObjC 'SEL' type. 10374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 10384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 10394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Kind TypeKind; 10404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 104125cf760b54d3b88633827501013bc51a29b28abaMike Stump BuiltinType(Kind K) 104225cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 10431b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor TypeKind(K) {} 104425cf760b54d3b88633827501013bc51a29b28abaMike Stump 10454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Kind getKind() const { return TypeKind; } 10467099c789f054f1e7480f498d60aa94b0326c285fChris Lattner const char *getName(const LangOptions &LO) const; 104725cf760b54d3b88633827501013bc51a29b28abaMike Stump 10480afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 10490afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 10500afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1051afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isInteger() const { 1052afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Bool && TypeKind <= Int128; 1053afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1054afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1055afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isSignedInteger() const { 1056afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Char_S && TypeKind <= Int128; 1057afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1058afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1059afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isUnsignedInteger() const { 1060afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Bool && TypeKind <= UInt128; 1061afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1062afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1063afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isFloatingPoint() const { 1064afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Float && TypeKind <= LongDouble; 1065afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1066afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1067b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1068b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 10694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 10704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const BuiltinType *) { return true; } 10714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 10724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 10744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types (_Complex float etc) as well as the GCC integer complex extensions. 10754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 10764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass ComplexType : public Type, public llvm::FoldingSetNode { 10774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ElementType; 10784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ComplexType(QualType Element, QualType CanonicalPtr) : 107925cf760b54d3b88633827501013bc51a29b28abaMike Stump Type(Complex, CanonicalPtr, Element->isDependentType()), 10801b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ElementType(Element) { 10814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 10824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 10834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 10844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getElementType() const { return ElementType; } 108525cf760b54d3b88633827501013bc51a29b28abaMike Stump 10860afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 10870afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 10880afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 10894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 10904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getElementType()); 10914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 10924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 10934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Element.getAsOpaquePtr()); 10944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 109525cf760b54d3b88633827501013bc51a29b28abaMike Stump 1096b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1097b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 10984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 10994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const ComplexType *) { return true; } 11004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 11014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1102554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 1103cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner/// 1104554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 1105cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner QualType PointeeType; 11064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner PointerType(QualType Pointee, QualType CanonicalPtr) : 1108554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 11094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 11114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 111225cf760b54d3b88633827501013bc51a29b28abaMike Stump 1113554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 1114554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 11150afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 11160afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 11170afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 11184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 11194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getPointeeType()); 11204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 11224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Pointee.getAsOpaquePtr()); 11234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 112425cf760b54d3b88633827501013bc51a29b28abaMike Stump 1125b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1126b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 11274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 11284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const PointerType *) { return true; } 11294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 11304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11317aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// BlockPointerType - pointer to a block type. 11327aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// This type is to represent types syntactically represented as 11337aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 11347aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// 11357aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 11367aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 11377aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 113825cf760b54d3b88633827501013bc51a29b28abaMike Stump Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 11391b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor PointeeType(Pointee) { 11407aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 11417aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff friend class ASTContext; // ASTContext creates these. 11427aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffpublic: 114325cf760b54d3b88633827501013bc51a29b28abaMike Stump 11447aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 11457aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff QualType getPointeeType() const { return PointeeType; } 11467aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 11470afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 11480afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 11490afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 11507aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 11517aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff Profile(ID, getPointeeType()); 11527aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 11537aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 11547aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 11557aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 115625cf760b54d3b88633827501013bc51a29b28abaMike Stump 1157b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1158b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 115925cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 116025cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == BlockPointer; 11617aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 11627aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 11637aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff}; 11647aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 1165ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 11664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 1167554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 1168554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar QualType PointeeType; 1169554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 11704ea8425c9601895fa137f877bc784f75f20adac6John McCall /// True if the type was originally spelled with an lvalue sigil. 11714ea8425c9601895fa137f877bc784f75f20adac6John McCall /// This is never true of rvalue references but can also be false 11724ea8425c9601895fa137f877bc784f75f20adac6John McCall /// on lvalue references because of C++0x [dcl.typedef]p9, 11734ea8425c9601895fa137f877bc784f75f20adac6John McCall /// as follows: 11744ea8425c9601895fa137f877bc784f75f20adac6John McCall /// 11754ea8425c9601895fa137f877bc784f75f20adac6John McCall /// typedef int &ref; // lvalue, spelled lvalue 11764ea8425c9601895fa137f877bc784f75f20adac6John McCall /// typedef int &&rvref; // rvalue 11774ea8425c9601895fa137f877bc784f75f20adac6John McCall /// ref &a; // lvalue, inner ref, spelled lvalue 11784ea8425c9601895fa137f877bc784f75f20adac6John McCall /// ref &&a; // lvalue, inner ref 11794ea8425c9601895fa137f877bc784f75f20adac6John McCall /// rvref &a; // lvalue, inner ref, spelled lvalue 11804ea8425c9601895fa137f877bc784f75f20adac6John McCall /// rvref &&a; // rvalue, inner ref 11814ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue; 11824ea8425c9601895fa137f877bc784f75f20adac6John McCall 11834ea8425c9601895fa137f877bc784f75f20adac6John McCall /// True if the inner type is a reference type. This only happens 11844ea8425c9601895fa137f877bc784f75f20adac6John McCall /// in non-canonical forms. 11854ea8425c9601895fa137f877bc784f75f20adac6John McCall bool InnerRef; 11864ea8425c9601895fa137f877bc784f75f20adac6John McCall 1187ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlprotected: 11884ea8425c9601895fa137f877bc784f75f20adac6John McCall ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, 11894ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue) : 1190ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl Type(tc, CanonicalRef, Referencee->isDependentType()), 11914ea8425c9601895fa137f877bc784f75f20adac6John McCall PointeeType(Referencee), SpelledAsLValue(SpelledAsLValue), 11924ea8425c9601895fa137f877bc784f75f20adac6John McCall InnerRef(Referencee->isReferenceType()) { 11934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 11954ea8425c9601895fa137f877bc784f75f20adac6John McCall bool isSpelledAsLValue() const { return SpelledAsLValue; } 11964ea8425c9601895fa137f877bc784f75f20adac6John McCall 11974ea8425c9601895fa137f877bc784f75f20adac6John McCall QualType getPointeeTypeAsWritten() const { return PointeeType; } 11984ea8425c9601895fa137f877bc784f75f20adac6John McCall QualType getPointeeType() const { 11994ea8425c9601895fa137f877bc784f75f20adac6John McCall // FIXME: this might strip inner qualifiers; okay? 12004ea8425c9601895fa137f877bc784f75f20adac6John McCall const ReferenceType *T = this; 12014ea8425c9601895fa137f877bc784f75f20adac6John McCall while (T->InnerRef) 12024ea8425c9601895fa137f877bc784f75f20adac6John McCall T = T->PointeeType->getAs<ReferenceType>(); 12034ea8425c9601895fa137f877bc784f75f20adac6John McCall return T->PointeeType; 12044ea8425c9601895fa137f877bc784f75f20adac6John McCall } 1205554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 12064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 12074ea8425c9601895fa137f877bc784f75f20adac6John McCall Profile(ID, PointeeType, SpelledAsLValue); 12084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 12094ea8425c9601895fa137f877bc784f75f20adac6John McCall static void Profile(llvm::FoldingSetNodeID &ID, 12104ea8425c9601895fa137f877bc784f75f20adac6John McCall QualType Referencee, 12114ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue) { 12124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Referencee.getAsOpaquePtr()); 12134ea8425c9601895fa137f877bc784f75f20adac6John McCall ID.AddBoolean(SpelledAsLValue); 12144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 12154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1216b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1217b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 1218ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 1219ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == LValueReference || 1220ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl T->getTypeClass() == RValueReference; 1221ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 12224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const ReferenceType *) { return true; } 1223ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl}; 1224ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl 1225ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 1226ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// 1227ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlclass LValueReferenceType : public ReferenceType { 12284ea8425c9601895fa137f877bc784f75f20adac6John McCall LValueReferenceType(QualType Referencee, QualType CanonicalRef, 12294ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue) : 12304ea8425c9601895fa137f877bc784f75f20adac6John McCall ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue) 12314ea8425c9601895fa137f877bc784f75f20adac6John McCall {} 1232ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl friend class ASTContext; // ASTContext creates these 1233ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlpublic: 12340afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 12350afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 12360afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1237ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 1238ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == LValueReference; 1239ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 1240ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 1241ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl}; 1242ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl 1243ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 1244ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// 1245ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlclass RValueReferenceType : public ReferenceType { 1246ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 12474ea8425c9601895fa137f877bc784f75f20adac6John McCall ReferenceType(RValueReference, Referencee, CanonicalRef, false) { 1248ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 1249ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl friend class ASTContext; // ASTContext creates these 1250ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlpublic: 12510afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 12520afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 12530afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1254ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 1255ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == RValueReference; 1256ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 1257ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 12587555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl}; 12597555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 12607555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 12617555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl/// 12627555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 12637555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl QualType PointeeType; 12647555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 12657555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 12667555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *Class; 12677555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 12687555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 12697555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Type(MemberPointer, CanonicalPtr, 12707555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Cls->isDependentType() || Pointee->isDependentType()), 12717555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl PointeeType(Pointee), Class(Cls) { 12727555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 12737555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl friend class ASTContext; // ASTContext creates these. 12747555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlpublic: 12757555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 12767555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl QualType getPointeeType() const { return PointeeType; } 12777555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 12787555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *getClass() const { return Class; } 12797555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 12800afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 12810afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 12820afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 12837555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 12847555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Profile(ID, getPointeeType(), getClass()); 12857555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 12867555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 12877555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *Class) { 12887555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 12897555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl ID.AddPointer(Class); 12907555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 12917555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 1292b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1293b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 12947555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static bool classof(const Type *T) { 12957555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return T->getTypeClass() == MemberPointer; 12967555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 12977555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static bool classof(const MemberPointerType *) { return true; } 12984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 12994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 13004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ArrayType - C99 6.7.5.2 - Array Declarators. 13014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 1302c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 13034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 13044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 13051b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 13061b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// with a star size (e.g. int X[*]). 13071b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// 'static' is only allowed on function parameters. 13084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum ArraySizeModifier { 13094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Normal, Static, Star 13104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 13114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 131283c13010359c33354c581acee65d0c986a75247eSteve Naroff /// ElementType - The element type of the array. 131383c13010359c33354c581acee65d0c986a75247eSteve Naroff QualType ElementType; 131425cf760b54d3b88633827501013bc51a29b28abaMike Stump 1315dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 131624c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 1317dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek unsigned SizeModifier : 2; 131825cf760b54d3b88633827501013bc51a29b28abaMike Stump 131924c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 132024c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// 'int X[static restrict 4]'. For function parameters only. 132124c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff unsigned IndexTypeQuals : 3; 132225cf760b54d3b88633827501013bc51a29b28abaMike Stump 132383c13010359c33354c581acee65d0c986a75247eSteve Naroffprotected: 13241b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // C++ [temp.dep.type]p1: 13251b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // A type is dependent if it is... 13261b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // - an array type constructed from any dependent type or whose 13271b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // size is specified by a constant expression that is 13281b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // value-dependent, 132924c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 133024c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArraySizeModifier sm, unsigned tq) 13311b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 13321b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 13331b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 133483c13010359c33354c581acee65d0c986a75247eSteve Naroff friend class ASTContext; // ASTContext creates these. 133583c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic: 133683c13010359c33354c581acee65d0c986a75247eSteve Naroff QualType getElementType() const { return ElementType; } 1337dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek ArraySizeModifier getSizeModifier() const { 1338dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek return ArraySizeModifier(SizeModifier); 1339dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek } 13403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers getIndexTypeQualifiers() const { 13413ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Qualifiers::fromCVRMask(IndexTypeQuals); 13423ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 13433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getIndexTypeCVRQualifiers() const { return IndexTypeQuals; } 134425cf760b54d3b88633827501013bc51a29b28abaMike Stump 1345b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1346b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 134783c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const Type *T) { 134883c13010359c33354c581acee65d0c986a75247eSteve Naroff return T->getTypeClass() == ConstantArray || 13498ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman T->getTypeClass() == VariableArray || 13501b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor T->getTypeClass() == IncompleteArray || 13511b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor T->getTypeClass() == DependentSizedArray; 135283c13010359c33354c581acee65d0c986a75247eSteve Naroff } 135383c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const ArrayType *) { return true; } 135483c13010359c33354c581acee65d0c986a75247eSteve Naroff}; 135583c13010359c33354c581acee65d0c986a75247eSteve Naroff 13561d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// ConstantArrayType - This class represents the canonical version of 13571d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// C arrays with a specified constant size. For example, the canonical 13581d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 13591d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// type is 'int' and the size is 404. 1360c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ConstantArrayType : public ArrayType { 136183c13010359c33354c581acee65d0c986a75247eSteve Naroff llvm::APInt Size; // Allows us to unique the type. 136225cf760b54d3b88633827501013bc51a29b28abaMike Stump 13633f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 136424c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArraySizeModifier sm, unsigned tq) 13651d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(ConstantArray, et, can, sm, tq), 13661d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor Size(size) {} 13671d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregorprotected: 13681d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor ConstantArrayType(TypeClass tc, QualType et, QualType can, 13691d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 13701d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(tc, et, can, sm, tq), Size(size) {} 137183c13010359c33354c581acee65d0c986a75247eSteve Naroff friend class ASTContext; // ASTContext creates these. 137283c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic: 1373a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner const llvm::APInt &getSize() const { return Size; } 13740afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 13750afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 13760afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 137783c13010359c33354c581acee65d0c986a75247eSteve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 137825cf760b54d3b88633827501013bc51a29b28abaMike Stump Profile(ID, getElementType(), getSize(), 13793ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers()); 138083c13010359c33354c581acee65d0c986a75247eSteve Naroff } 138183c13010359c33354c581acee65d0c986a75247eSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 13823f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 13833f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner unsigned TypeQuals) { 138483c13010359c33354c581acee65d0c986a75247eSteve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 138583c13010359c33354c581acee65d0c986a75247eSteve Naroff ID.AddInteger(ArraySize.getZExtValue()); 13863f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(SizeMod); 13873f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(TypeQuals); 138883c13010359c33354c581acee65d0c986a75247eSteve Naroff } 13891d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor static bool classof(const Type *T) { 139032b25ab7d4b3355b804e367c90f5cd55f4c9187eJohn McCall return T->getTypeClass() == ConstantArray; 139183c13010359c33354c581acee65d0c986a75247eSteve Naroff } 139283c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const ConstantArrayType *) { return true; } 139383c13010359c33354c581acee65d0c986a75247eSteve Naroff}; 139483c13010359c33354c581acee65d0c986a75247eSteve Naroff 139556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 139656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 139756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// type is 'int' and the size is unspecified. 13988ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanclass IncompleteArrayType : public ArrayType { 13991d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor 14008ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman IncompleteArrayType(QualType et, QualType can, 14011d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor ArraySizeModifier sm, unsigned tq) 14028ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 14038ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman friend class ASTContext; // ASTContext creates these. 14048ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanpublic: 14050afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 14060afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 14070afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 140825cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 140925cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == IncompleteArray; 14108ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 14118ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 141225cf760b54d3b88633827501013bc51a29b28abaMike Stump 14138ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman friend class StmtIteratorBase; 141425cf760b54d3b88633827501013bc51a29b28abaMike Stump 14158ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 14163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Profile(ID, getElementType(), getSizeModifier(), 14173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getIndexTypeCVRQualifiers()); 14188ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 141925cf760b54d3b88633827501013bc51a29b28abaMike Stump 14203f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 14213f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 14228ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 14233f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(SizeMod); 14243f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(TypeQuals); 14258ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 14268ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman}; 14278ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 142856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 142956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 143056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 143156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 143256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 143356846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// should not be: two lexically equivalent variable array types could mean 143456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// different things, for example, these variables do not have the same type 143556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// dynamically: 143656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 143756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// void foo(int x) { 143856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// int Y[x]; 143956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// ++x; 144056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// int Z[x]; 144156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// } 144256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 1443c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass VariableArrayType : public ArrayType { 144425cf760b54d3b88633827501013bc51a29b28abaMike Stump /// SizeExpr - An assignment expression. VLA's are only permitted within 144525cf760b54d3b88633827501013bc51a29b28abaMike Stump /// a function block. 1446718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek Stmt *SizeExpr; 14471d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor /// Brackets - The left and right array brackets. 14481d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange Brackets; 14491d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor 145024c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 14511d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor ArraySizeModifier sm, unsigned tq, 14521d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange brackets) 14531d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(VariableArray, et, can, sm, tq), 14541d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 14554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1456db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek virtual void Destroy(ASTContext& C); 1457db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek 14584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 145925cf760b54d3b88633827501013bc51a29b28abaMike Stump Expr *getSizeExpr() const { 1460718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek // We use C-style casts instead of cast<> here because we do not wish 1461718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 1462718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek return (Expr*) SizeExpr; 1463718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek } 14641d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange getBracketsRange() const { return Brackets; } 14651d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 14661d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 146725cf760b54d3b88633827501013bc51a29b28abaMike Stump 14680afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 14690afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 14700afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 147125cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 147225cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == VariableArray; 14734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 147483c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const VariableArrayType *) { return true; } 147525cf760b54d3b88633827501013bc51a29b28abaMike Stump 1476fce813e3159a67a57a03cdca45ac4e10d4cffac3Ted Kremenek friend class StmtIteratorBase; 147725cf760b54d3b88633827501013bc51a29b28abaMike Stump 14783793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 14797029ee3fdeee514a79eafb2508723d27c97fe158Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 14803793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek } 14814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 14824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 14831b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// DependentSizedArrayType - This type represents an array type in 14841b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// C++ whose size is a value-dependent expression. For example: 1485393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// 1486393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// \code 148725cf760b54d3b88633827501013bc51a29b28abaMike Stump/// template<typename T, int Size> 14881b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// class array { 14891b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// T data[Size]; 14901b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// }; 1491393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// \endcode 1492393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// 14931b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// For these types, we won't actually know what the array bound is 14941b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// until template instantiation occurs, at which point this will 14951b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 14961b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorclass DependentSizedArrayType : public ArrayType { 14977fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor ASTContext &Context; 149825cf760b54d3b88633827501013bc51a29b28abaMike Stump 1499393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// \brief An assignment expression that will instantiate to the 15001b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// size of the array. 1501393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// 1502393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// The expression itself might be NULL, in which case the array 1503393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// type will have its size deduced from an initializer. 15041b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Stmt *SizeExpr; 1505393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor 15061d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor /// Brackets - The left and right array brackets. 15071d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange Brackets; 150825cf760b54d3b88633827501013bc51a29b28abaMike Stump 150925cf760b54d3b88633827501013bc51a29b28abaMike Stump DependentSizedArrayType(ASTContext &Context, QualType et, QualType can, 15107fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor Expr *e, ArraySizeModifier sm, unsigned tq, 15111d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange brackets) 15121d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), 15137fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {} 15141b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor friend class ASTContext; // ASTContext creates these. 15151b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual void Destroy(ASTContext& C); 15161b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 15171b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorpublic: 151825cf760b54d3b88633827501013bc51a29b28abaMike Stump Expr *getSizeExpr() const { 15191b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // We use C-style casts instead of cast<> here because we do not wish 15201b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 15211b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return (Expr*) SizeExpr; 15221b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 15231d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange getBracketsRange() const { return Brackets; } 15241d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 15251d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 152625cf760b54d3b88633827501013bc51a29b28abaMike Stump 15270afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 15280afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 15290afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 153025cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 153125cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == DependentSizedArray; 15321b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 15331b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 153425cf760b54d3b88633827501013bc51a29b28abaMike Stump 15351b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor friend class StmtIteratorBase; 153625cf760b54d3b88633827501013bc51a29b28abaMike Stump 153725cf760b54d3b88633827501013bc51a29b28abaMike Stump 15381b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 153925cf760b54d3b88633827501013bc51a29b28abaMike Stump Profile(ID, Context, getElementType(), 15403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); 15411b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 154225cf760b54d3b88633827501013bc51a29b28abaMike Stump 154325cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 154425cf760b54d3b88633827501013bc51a29b28abaMike Stump QualType ET, ArraySizeModifier SizeMod, 15457fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor unsigned TypeQuals, Expr *E); 15461b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor}; 15471b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 154868a7a6db3693e6df54a2198f3ee4e3f87e7f9ac0Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 15492a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// where either the type or size is dependent. For example: 15502a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// @code 15512a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// template<typename T, int Size> 15522a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// class vector { 15532a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 15542a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// } 15552a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// @endcode 15560c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { 15570c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor ASTContext &Context; 15582a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor Expr *SizeExpr; 15592a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor /// ElementType - The element type of the array. 15602a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor QualType ElementType; 15612a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor SourceLocation loc; 156225cf760b54d3b88633827501013bc51a29b28abaMike Stump 156325cf760b54d3b88633827501013bc51a29b28abaMike Stump DependentSizedExtVectorType(ASTContext &Context, QualType ElementType, 15640c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor QualType can, Expr *SizeExpr, SourceLocation loc) 156525cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type (DependentSizedExtVector, can, true), 156625cf760b54d3b88633827501013bc51a29b28abaMike Stump Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 15670c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor loc(loc) {} 15682a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor friend class ASTContext; 15692a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor virtual void Destroy(ASTContext& C); 15702a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor 15712a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregorpublic: 15720c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 15732a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor QualType getElementType() const { return ElementType; } 15742a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor SourceLocation getAttributeLoc() const { return loc; } 15752a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor 15760afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 15770afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 15780afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 157925cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 158025cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == DependentSizedExtVector; 15812a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor } 158225cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const DependentSizedExtVectorType *) { return true; } 15830c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor 15840c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 15850c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor Profile(ID, Context, getElementType(), getSizeExpr()); 15860c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor } 158725cf760b54d3b88633827501013bc51a29b28abaMike Stump 15880c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 15890c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor QualType ElementType, Expr *SizeExpr); 15902a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor}; 159125cf760b54d3b88633827501013bc51a29b28abaMike Stump 15922a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor 15934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// VectorType - GCC generic vector type. This type is created using 159425cf760b54d3b88633827501013bc51a29b28abaMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in 1595438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson/// bytes; or from an Altivec __vector or vector declaration. 1596438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson/// Since the constructor takes the number of vector elements, the 15974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// client is responsible for converting the size into the number of elements. 15984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass VectorType : public Type, public llvm::FoldingSetNode { 15994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 16004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ElementType - The element type of the vector. 16014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ElementType; 160225cf760b54d3b88633827501013bc51a29b28abaMike Stump 16034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// NumElements - The number of elements in the vector. 16044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned NumElements; 160525cf760b54d3b88633827501013bc51a29b28abaMike Stump 1606438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson /// AltiVec - True if this is for an Altivec vector. 1607438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson bool AltiVec; 1608438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson 1609438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson /// Pixel - True if this is for an Altivec vector pixel. 1610438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson bool Pixel; 1611438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson 1612438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson VectorType(QualType vecType, unsigned nElements, QualType canonType, 1613438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson bool isAltiVec, bool isPixel) : 161425cf760b54d3b88633827501013bc51a29b28abaMike Stump Type(Vector, canonType, vecType->isDependentType()), 1615438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson ElementType(vecType), NumElements(nElements), 1616438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson AltiVec(isAltiVec), Pixel(isPixel) {} 161725cf760b54d3b88633827501013bc51a29b28abaMike Stump VectorType(TypeClass tc, QualType vecType, unsigned nElements, 1618438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson QualType canonType, bool isAltiVec, bool isPixel) 161925cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 1620438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson NumElements(nElements), AltiVec(isAltiVec), Pixel(isPixel) {} 16214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 16224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 162325cf760b54d3b88633827501013bc51a29b28abaMike Stump 16244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getElementType() const { return ElementType; } 162525cf760b54d3b88633827501013bc51a29b28abaMike Stump unsigned getNumElements() const { return NumElements; } 16264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 16270afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 16280afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 16290afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1630438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson bool isAltiVec() const { return AltiVec; } 1631438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson 1632438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson bool isPixel() const { return Pixel; } 1633438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson 16344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 1635438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson Profile(ID, getElementType(), getNumElements(), getTypeClass(), 1636438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson AltiVec, Pixel); 16374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 163825cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 1639438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson unsigned NumElements, TypeClass TypeClass, 1640438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson bool isAltiVec, bool isPixel) { 16414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(ElementType.getAsOpaquePtr()); 16424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddInteger(NumElements); 16434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddInteger(TypeClass); 1644438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson ID.AddBoolean(isAltiVec); 1645438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson ID.AddBoolean(isPixel); 16464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1647b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 1648b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1649b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 165025cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 165125cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 16524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 16534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const VectorType *) { return true; } 16544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 16554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1656af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// ExtVectorType - Extended vector type. This type is created using 1657af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1658af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 16596154214e20225a883a8a00226499534e9b514315Steve Naroff/// class enables syntactic extensions, like Vector Components for accessing 16606154214e20225a883a8a00226499534e9b514315Steve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1661af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemanclass ExtVectorType : public VectorType { 1662af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1663438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson VectorType(ExtVector, vecType, nElements, canonType, false, false) {} 16644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 16654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 16669096b795541c783297fb19684a58c54d0fe823b8Chris Lattner static int getPointAccessorIdx(char c) { 16679096b795541c783297fb19684a58c54d0fe823b8Chris Lattner switch (c) { 16689096b795541c783297fb19684a58c54d0fe823b8Chris Lattner default: return -1; 16699096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'x': return 0; 16709096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'y': return 1; 16719096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'z': return 2; 16729096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'w': return 3; 16739096b795541c783297fb19684a58c54d0fe823b8Chris Lattner } 16741b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 16751486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman static int getNumericAccessorIdx(char c) { 16769096b795541c783297fb19684a58c54d0fe823b8Chris Lattner switch (c) { 16771486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman default: return -1; 16781486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '0': return 0; 16791486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '1': return 1; 16801486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '2': return 2; 16811486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '3': return 3; 16821486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '4': return 4; 16831486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '5': return 5; 16841486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '6': return 6; 16851486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '7': return 7; 16861486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '8': return 8; 16871486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '9': return 9; 1688e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'A': 16891486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'a': return 10; 1690e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'B': 16911486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'b': return 11; 1692e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'C': 16931486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'c': return 12; 1694e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'D': 16951486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'd': return 13; 1696e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'E': 16971486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'e': return 14; 1698e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'F': 16991486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'f': return 15; 17009096b795541c783297fb19684a58c54d0fe823b8Chris Lattner } 17011b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 170225cf760b54d3b88633827501013bc51a29b28abaMike Stump 170342158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner static int getAccessorIdx(char c) { 170442158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 17051486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman return getNumericAccessorIdx(c); 170642158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner } 170725cf760b54d3b88633827501013bc51a29b28abaMike Stump 17089096b795541c783297fb19684a58c54d0fe823b8Chris Lattner bool isAccessorWithinNumElements(char c) const { 170942158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner if (int idx = getAccessorIdx(c)+1) 17109096b795541c783297fb19684a58c54d0fe823b8Chris Lattner return unsigned(idx-1) < NumElements; 17119096b795541c783297fb19684a58c54d0fe823b8Chris Lattner return false; 17121b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 17130afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 17140afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 17150afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 171625cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 171725cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == ExtVector; 17184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1719af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman static bool classof(const ExtVectorType *) { return true; } 17204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 17214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 17224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 17234fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 17244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 17254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass FunctionType : public Type { 17264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// SubClassData - This field is owned by the subclass, put here to pack 17274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// tightly with the ivars in Type. 17284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool SubClassData : 1; 17294b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis 17304fa58905062efa6a12137b1983a1367220182a20Douglas Gregor /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 17314b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// other bitfields. 17324fa58905062efa6a12137b1983a1367220182a20Douglas Gregor /// The qualifiers are part of FunctionProtoType because... 17334b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// 17344b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 17354b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// cv-qualifier-seq, [...], are part of the function type. 17364b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// 17374b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned TypeQuals : 3; 17381bb806498909a43a7829edb21c42606335d69694Mike Stump 17391bb806498909a43a7829edb21c42606335d69694Mike Stump /// NoReturn - Indicates if the function type is attribute noreturn. 17401bb806498909a43a7829edb21c42606335d69694Mike Stump unsigned NoReturn : 1; 174125cf760b54d3b88633827501013bc51a29b28abaMike Stump 174231cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor /// CallConv - The calling convention used by the function. 174331cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor unsigned CallConv : 2; 174431cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor 17454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // The type returned by the function. 17464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ResultType; 17474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 17484b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 17491bb806498909a43a7829edb21c42606335d69694Mike Stump unsigned typeQuals, QualType Canonical, bool Dependent, 175031cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor bool noReturn = false, CallingConv callConv = CC_Default) 17511b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, Canonical, Dependent), 17521bb806498909a43a7829edb21c42606335d69694Mike Stump SubClassData(SubclassInfo), TypeQuals(typeQuals), NoReturn(noReturn), 175331cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CallConv(callConv), ResultType(res) {} 17544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool getSubClassData() const { return SubClassData; } 17554b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned getTypeQuals() const { return TypeQuals; } 17564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 175725cf760b54d3b88633827501013bc51a29b28abaMike Stump 17584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getResultType() const { return ResultType; } 17591bb806498909a43a7829edb21c42606335d69694Mike Stump bool getNoReturnAttr() const { return NoReturn; } 176031cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CallingConv getCallConv() const { return (CallingConv)CallConv; } 17614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1762ad760b38613b3f7f1024b011f6109bed1487b32eJohn McCall static llvm::StringRef getNameForCallConv(CallingConv CC); 1763ad760b38613b3f7f1024b011f6109bed1487b32eJohn McCall 17644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 17654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionNoProto || 17664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner T->getTypeClass() == FunctionProto; 17674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 17684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const FunctionType *) { return true; } 17694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 17704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 17714fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 17724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// no information available about its arguments. 17734fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 17741bb806498909a43a7829edb21c42606335d69694Mike Stump FunctionNoProtoType(QualType Result, QualType Canonical, 177531cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor bool NoReturn = false, CallingConv CallConv = CC_Default) 177625cf760b54d3b88633827501013bc51a29b28abaMike Stump : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 177731cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor /*Dependent=*/false, NoReturn, CallConv) {} 17784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 17794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 17804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // No additional state past what FunctionType provides. 178125cf760b54d3b88633827501013bc51a29b28abaMike Stump 17820afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 17830afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 17840afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 17854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 1786db5993538c7f29ea7331dcb7292c083e1bab798cJohn McCall Profile(ID, getResultType(), getNoReturnAttr(), getCallConv()); 17874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 17881bb806498909a43a7829edb21c42606335d69694Mike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 1789db5993538c7f29ea7331dcb7292c083e1bab798cJohn McCall bool NoReturn, CallingConv CallConv) { 1790db5993538c7f29ea7331dcb7292c083e1bab798cJohn McCall ID.AddInteger(CallConv); 17911bb806498909a43a7829edb21c42606335d69694Mike Stump ID.AddInteger(NoReturn); 17924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(ResultType.getAsOpaquePtr()); 17934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 179425cf760b54d3b88633827501013bc51a29b28abaMike Stump 1795b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1796b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 17974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 17984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionNoProto; 17994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 18004fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 18014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 18024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 18034fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 18044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 18052767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 18062767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl/// exception specification, but this specification is not part of the canonical 18072767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl/// type. 18084fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 18091b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 18101b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// types within the arguments passed in. 18111b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 18121b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 18131b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor if (ArgArray[Idx]->isDependentType()) 1814f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman return true; 18151b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 18161b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return false; 18171b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 18181b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 18194fa58905062efa6a12137b1983a1367220182a20Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 18202767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool isVariadic, unsigned typeQuals, bool hasExs, 18212767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasAnyExs, const QualType *ExArray, 182231cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor unsigned numExs, QualType Canonical, bool NoReturn, 182331cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CallingConv CallConv) 18241b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 182525cf760b54d3b88633827501013bc51a29b28abaMike Stump (Result->isDependentType() || 182631cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor hasAnyDependentType(ArgArray, numArgs)), NoReturn, 182731cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CallConv), 18282767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 18292767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl AnyExceptionSpec(hasAnyExs) { 18304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // Fill in the trailing argument array. 18312767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 18324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner for (unsigned i = 0; i != numArgs; ++i) 18334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ArgInfo[i] = ArgArray[i]; 18342767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl // Fill in the exception array. 18352767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl QualType *Ex = ArgInfo + numArgs; 18362767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl for (unsigned i = 0; i != numExs; ++i) 18372767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl Ex[i] = ExArray[i]; 18384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 18392767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// NumArgs - The number of arguments this function has, not counting '...'. 18412767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl unsigned NumArgs : 20; 18422767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18432767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 18442767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl unsigned NumExceptions : 10; 18452767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18462767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// HasExceptionSpec - Whether this function has an exception spec at all. 18472767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool HasExceptionSpec : 1; 18482767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18492767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// AnyExceptionSpec - Whether this function has a throw(...) spec. 18502767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool AnyExceptionSpec : 1; 18512767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 18534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// holds the argument types. 18542767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18552767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 18562767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// holds the exception types. 18572767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1859db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek 18604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 18614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned getNumArgs() const { return NumArgs; } 18624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getArgType(unsigned i) const { 18634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner assert(i < NumArgs && "Invalid argument number!"); 18644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return arg_type_begin()[i]; 18654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 18662767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18672767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasExceptionSpec() const { return HasExceptionSpec; } 18682767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 18692767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 18702767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl QualType getExceptionType(unsigned i) const { 18712767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 18722767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl return exception_begin()[i]; 18732767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl } 187425cf760b54d3b88633827501013bc51a29b28abaMike Stump bool hasEmptyExceptionSpec() const { 187525cf760b54d3b88633827501013bc51a29b28abaMike Stump return hasExceptionSpec() && !hasAnyExceptionSpec() && 1876ac5e9f9de0959d5b1d390dc9bdad2d6f3d77c5cbAnders Carlsson getNumExceptions() == 0; 187711269048f03d91e991150c429dc874ae3999acb0Anders Carlsson } 18782767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isVariadic() const { return getSubClassData(); } 18804b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 188125cf760b54d3b88633827501013bc51a29b28abaMike Stump 18824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner typedef const QualType *arg_type_iterator; 18834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator arg_type_begin() const { 18844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return reinterpret_cast<const QualType *>(this+1); 18854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 18864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 18872767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18882767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl typedef const QualType *exception_iterator; 18892767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl exception_iterator exception_begin() const { 18902767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl // exceptions begin where arguments end 18912767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl return arg_type_end(); 18922767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl } 18932767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl exception_iterator exception_end() const { 18942767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl return exception_begin() + NumExceptions; 18952767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl } 18962767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 18970afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 18980afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 18990afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1900b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 1901b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 19024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 19034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionProto; 19044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 19054fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 19062767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 19074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID); 19084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 19094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 19102767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool isVariadic, unsigned TypeQuals, 19112767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasExceptionSpec, bool anyExceptionSpec, 19121bb806498909a43a7829edb21c42606335d69694Mike Stump unsigned NumExceptions, exception_iterator Exs, 1913db5993538c7f29ea7331dcb7292c083e1bab798cJohn McCall bool NoReturn, CallingConv CallConv); 19144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 19154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 19164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1917caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// \brief Represents the dependent type named by a dependently-scoped 1918caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// typename using declaration, e.g. 1919caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// using typename Base<T>::foo; 1920caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// Template instantiation turns these into the underlying type. 1921caf383ae337966d67380b6b161fab17ec2b53d04John McCallclass UnresolvedUsingType : public Type { 1922caf383ae337966d67380b6b161fab17ec2b53d04John McCall UnresolvedUsingTypenameDecl *Decl; 1923caf383ae337966d67380b6b161fab17ec2b53d04John McCall 1924caf383ae337966d67380b6b161fab17ec2b53d04John McCall UnresolvedUsingType(UnresolvedUsingTypenameDecl *D) 1925caf383ae337966d67380b6b161fab17ec2b53d04John McCall : Type(UnresolvedUsing, QualType(), true), Decl(D) {} 1926caf383ae337966d67380b6b161fab17ec2b53d04John McCall friend class ASTContext; // ASTContext creates these. 1927caf383ae337966d67380b6b161fab17ec2b53d04John McCallpublic: 1928caf383ae337966d67380b6b161fab17ec2b53d04John McCall 1929caf383ae337966d67380b6b161fab17ec2b53d04John McCall UnresolvedUsingTypenameDecl *getDecl() const { return Decl; } 1930caf383ae337966d67380b6b161fab17ec2b53d04John McCall 1931caf383ae337966d67380b6b161fab17ec2b53d04John McCall bool isSugared() const { return false; } 1932caf383ae337966d67380b6b161fab17ec2b53d04John McCall QualType desugar() const { return QualType(this, 0); } 1933caf383ae337966d67380b6b161fab17ec2b53d04John McCall 1934caf383ae337966d67380b6b161fab17ec2b53d04John McCall static bool classof(const Type *T) { 1935caf383ae337966d67380b6b161fab17ec2b53d04John McCall return T->getTypeClass() == UnresolvedUsing; 1936caf383ae337966d67380b6b161fab17ec2b53d04John McCall } 1937caf383ae337966d67380b6b161fab17ec2b53d04John McCall static bool classof(const UnresolvedUsingType *) { return true; } 1938caf383ae337966d67380b6b161fab17ec2b53d04John McCall 1939caf383ae337966d67380b6b161fab17ec2b53d04John McCall void Profile(llvm::FoldingSetNodeID &ID) { 1940caf383ae337966d67380b6b161fab17ec2b53d04John McCall return Profile(ID, Decl); 1941caf383ae337966d67380b6b161fab17ec2b53d04John McCall } 1942caf383ae337966d67380b6b161fab17ec2b53d04John McCall static void Profile(llvm::FoldingSetNodeID &ID, 1943caf383ae337966d67380b6b161fab17ec2b53d04John McCall UnresolvedUsingTypenameDecl *D) { 1944caf383ae337966d67380b6b161fab17ec2b53d04John McCall ID.AddPointer(D); 1945caf383ae337966d67380b6b161fab17ec2b53d04John McCall } 1946caf383ae337966d67380b6b161fab17ec2b53d04John McCall}; 1947caf383ae337966d67380b6b161fab17ec2b53d04John McCall 1948caf383ae337966d67380b6b161fab17ec2b53d04John McCall 19494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TypedefType : public Type { 19504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner TypedefDecl *Decl; 1951e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanianprotected: 195225cf760b54d3b88633827501013bc51a29b28abaMike Stump TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 19531b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, can, can->isDependentType()), Decl(D) { 19544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner assert(!isa<TypedefType>(can) && "Invalid canonical type"); 19554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 19564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 19574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 195825cf760b54d3b88633827501013bc51a29b28abaMike Stump 19594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner TypedefDecl *getDecl() const { return Decl; } 196025cf760b54d3b88633827501013bc51a29b28abaMike Stump 19614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1962a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 19634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// sum of the type qualifiers, so if you have: 19644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// typedef const int A; 19654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// typedef volatile A B; 19664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// looking through the typedefs for B will give you "const volatile A". 19674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType LookThroughTypedefs() const; 196825cf760b54d3b88633827501013bc51a29b28abaMike Stump 19690afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 19700afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const; 19710afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 19724fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 19734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const TypedefType *) { return true; } 19744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 19754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 19764fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// TypeOfExprType (GCC extension). 19774fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass TypeOfExprType : public Type { 19787cbb14653934a298c09002b87704dc6531261771Steve Naroff Expr *TOExpr; 197925cf760b54d3b88633827501013bc51a29b28abaMike Stump 198063d22fa6071690209b339451e4939de120a45e70Douglas Gregorprotected: 1981d1c0b682af81784cb991a5479097e795b5868bc4Douglas Gregor TypeOfExprType(Expr *E, QualType can = QualType()); 19827cbb14653934a298c09002b87704dc6531261771Steve Naroff friend class ASTContext; // ASTContext creates these. 19837cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic: 19847cbb14653934a298c09002b87704dc6531261771Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 198525cf760b54d3b88633827501013bc51a29b28abaMike Stump 19860afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 19870afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const; 19880afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 19890afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 19900afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 19910afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 19924fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 19934fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 19947cbb14653934a298c09002b87704dc6531261771Steve Naroff}; 19957cbb14653934a298c09002b87704dc6531261771Steve Naroff 199627dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// \brief Internal representation of canonical, dependent 199725cf760b54d3b88633827501013bc51a29b28abaMike Stump/// typeof(expr) types. 199827dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// 199927dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// This class is used internally by the ASTContext to manage 200027dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// canonical, dependent types, only. Clients will only see instances 200127dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// of this class via TypeOfExprType nodes. 200225cf760b54d3b88633827501013bc51a29b28abaMike Stumpclass DependentTypeOfExprType 200363d22fa6071690209b339451e4939de120a45e70Douglas Gregor : public TypeOfExprType, public llvm::FoldingSetNode { 200463d22fa6071690209b339451e4939de120a45e70Douglas Gregor ASTContext &Context; 200525cf760b54d3b88633827501013bc51a29b28abaMike Stump 200663d22fa6071690209b339451e4939de120a45e70Douglas Gregorpublic: 200725cf760b54d3b88633827501013bc51a29b28abaMike Stump DependentTypeOfExprType(ASTContext &Context, Expr *E) 200863d22fa6071690209b339451e4939de120a45e70Douglas Gregor : TypeOfExprType(E), Context(Context) { } 200925cf760b54d3b88633827501013bc51a29b28abaMike Stump 20100afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 20110afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 20120afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 201363d22fa6071690209b339451e4939de120a45e70Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 201463d22fa6071690209b339451e4939de120a45e70Douglas Gregor Profile(ID, Context, getUnderlyingExpr()); 201563d22fa6071690209b339451e4939de120a45e70Douglas Gregor } 201625cf760b54d3b88633827501013bc51a29b28abaMike Stump 201763d22fa6071690209b339451e4939de120a45e70Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 201863d22fa6071690209b339451e4939de120a45e70Douglas Gregor Expr *E); 201963d22fa6071690209b339451e4939de120a45e70Douglas Gregor}; 202025cf760b54d3b88633827501013bc51a29b28abaMike Stump 20217cbb14653934a298c09002b87704dc6531261771Steve Naroff/// TypeOfType (GCC extension). 20227cbb14653934a298c09002b87704dc6531261771Steve Naroffclass TypeOfType : public Type { 20237cbb14653934a298c09002b87704dc6531261771Steve Naroff QualType TOType; 202425cf760b54d3b88633827501013bc51a29b28abaMike Stump TypeOfType(QualType T, QualType can) 20254fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : Type(TypeOf, can, T->isDependentType()), TOType(T) { 20267cbb14653934a298c09002b87704dc6531261771Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 20277cbb14653934a298c09002b87704dc6531261771Steve Naroff } 20287cbb14653934a298c09002b87704dc6531261771Steve Naroff friend class ASTContext; // ASTContext creates these. 20297cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic: 20307cbb14653934a298c09002b87704dc6531261771Steve Naroff QualType getUnderlyingType() const { return TOType; } 203125cf760b54d3b88633827501013bc51a29b28abaMike Stump 20320afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 20330afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getUnderlyingType(); } 20340afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 20350afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 20360afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 20370afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 20384fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 20397cbb14653934a298c09002b87704dc6531261771Steve Naroff static bool classof(const TypeOfType *) { return true; } 20407cbb14653934a298c09002b87704dc6531261771Steve Naroff}; 20414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 204293ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson/// DecltypeType (C++0x) 204393ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlssonclass DecltypeType : public Type { 204493ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson Expr *E; 204525cf760b54d3b88633827501013bc51a29b28abaMike Stump 204642f394e67047624dcc15d22239f615885ad712acAnders Carlsson // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 204742f394e67047624dcc15d22239f615885ad712acAnders Carlsson // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 204842f394e67047624dcc15d22239f615885ad712acAnders Carlsson // from it. 204942f394e67047624dcc15d22239f615885ad712acAnders Carlsson QualType UnderlyingType; 205025cf760b54d3b88633827501013bc51a29b28abaMike Stump 2051d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregorprotected: 205242f394e67047624dcc15d22239f615885ad712acAnders Carlsson DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 205393ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson friend class ASTContext; // ASTContext creates these. 205493ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlssonpublic: 205593ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson Expr *getUnderlyingExpr() const { return E; } 205642f394e67047624dcc15d22239f615885ad712acAnders Carlsson QualType getUnderlyingType() const { return UnderlyingType; } 205742f394e67047624dcc15d22239f615885ad712acAnders Carlsson 20580afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 20590afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getUnderlyingType(); } 20600afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 20610afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 20620afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return !isDependentType(); } 20630afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 206493ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 206593ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson static bool classof(const DecltypeType *) { return true; } 206693ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson}; 206725cf760b54d3b88633827501013bc51a29b28abaMike Stump 206827dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// \brief Internal representation of canonical, dependent 206927dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// decltype(expr) types. 207027dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// 207127dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// This class is used internally by the ASTContext to manage 207227dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// canonical, dependent types, only. Clients will only see instances 207327dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// of this class via DecltypeType nodes. 2074d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { 2075d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor ASTContext &Context; 207625cf760b54d3b88633827501013bc51a29b28abaMike Stump 2077d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregorpublic: 2078d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor DependentDecltypeType(ASTContext &Context, Expr *E); 207925cf760b54d3b88633827501013bc51a29b28abaMike Stump 20800afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 20810afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 20820afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2083d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2084d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor Profile(ID, Context, getUnderlyingExpr()); 2085d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor } 208625cf760b54d3b88633827501013bc51a29b28abaMike Stump 2087d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 208825cf760b54d3b88633827501013bc51a29b28abaMike Stump Expr *E); 2089d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor}; 209025cf760b54d3b88633827501013bc51a29b28abaMike Stump 20914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TagType : public Type { 209298b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// Stores the TagDecl associated with this type. The decl will 209398b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// point to the TagDecl that actually defines the entity (or is a 209498b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// definition in progress), if there is such a definition. The 209598b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// single-bit value will be non-zero when this tag is in the 209698b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// process of being defined. 20979c7825b737617339724d43bd04960852271f08e2Douglas Gregor mutable llvm::PointerIntPair<TagDecl *, 1> decl; 209846a837c7ced306c55d1686cea5f77cb7a2f3b908Ted Kremenek friend class ASTContext; 209998b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor friend class TagDecl; 21001d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor 21011d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregorprotected: 21029054f9878dbe2b1b8384c951ad07759d9de9dc8cDouglas Gregor TagType(TypeClass TC, TagDecl *D, QualType can); 21031d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor 210425cf760b54d3b88633827501013bc51a29b28abaMike Stumppublic: 210598b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor TagDecl *getDecl() const { return decl.getPointer(); } 210625cf760b54d3b88633827501013bc51a29b28abaMike Stump 210798b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// @brief Determines whether this type is in the process of being 210825cf760b54d3b88633827501013bc51a29b28abaMike Stump /// defined. 210998b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor bool isBeingDefined() const { return decl.getInt(); } 21103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setBeingDefined(bool Def) const { decl.setInt(Def? 1 : 0); } 211198b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor 2112b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 2113b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 211425cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 21154fa58905062efa6a12137b1983a1367220182a20Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 21164fa58905062efa6a12137b1983a1367220182a20Douglas Gregor } 21174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const TagType *) { return true; } 21184fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const RecordType *) { return true; } 21194fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const EnumType *) { return true; } 21204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 21214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 21221baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 21231baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of structs/unions/classes. 21241baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass RecordType : public TagType { 2125ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidisprotected: 21263cbc064cf343c2151488b7822430ed327ade176eArgiris Kirtzidis explicit RecordType(RecordDecl *D) 21274fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 21284fa58905062efa6a12137b1983a1367220182a20Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 21294fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 21301d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor friend class ASTContext; // ASTContext creates these. 21311baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic: 213225cf760b54d3b88633827501013bc51a29b28abaMike Stump 21331baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner RecordDecl *getDecl() const { 21341baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 21351baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner } 213625cf760b54d3b88633827501013bc51a29b28abaMike Stump 213725cf760b54d3b88633827501013bc51a29b28abaMike Stump // FIXME: This predicate is a helper to QualType/Type. It needs to 21381baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // recursively check all fields for const-ness. If any field is declared 213925cf760b54d3b88633827501013bc51a29b28abaMike Stump // const, it needs to return false. 21401baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner bool hasConstFields() const { return false; } 21411baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 21421baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 21431baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // the same address space, and return that. 21441baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner unsigned getAddressSpace() const { return 0; } 214525cf760b54d3b88633827501013bc51a29b28abaMike Stump 21460afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 21470afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 21480afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2149eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const TagType *T); 2150eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const Type *T) { 2151eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 2152eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner } 21531baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner static bool classof(const RecordType *) { return true; } 21541baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner}; 21551baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 21561baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 21571baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of enums. 21581baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass EnumType : public TagType { 21593cbc064cf343c2151488b7822430ed327ade176eArgiris Kirtzidis explicit EnumType(EnumDecl *D) 21604fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 21611d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor friend class ASTContext; // ASTContext creates these. 21621baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic: 216325cf760b54d3b88633827501013bc51a29b28abaMike Stump 21641baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner EnumDecl *getDecl() const { 21651baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 21661baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner } 216725cf760b54d3b88633827501013bc51a29b28abaMike Stump 21680afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 21690afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 21700afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2171eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const TagType *T); 2172eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const Type *T) { 2173eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 2174eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner } 21751baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner static bool classof(const EnumType *) { return true; } 21761baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner}; 21771baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 2178379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// ElaboratedType - A non-canonical type used to represents uses of 2179379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// elaborated type specifiers in C++. For example: 2180379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// 2181379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// void foo(union MyUnion); 2182379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// ^^^^^^^^^^^^^ 2183379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// 2184379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// At the moment, for efficiency we do not create elaborated types in 2185379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// C, since outside of typedefs all references to structs would 2186379448fc7bc91bba33e3d2df073f6cf011960b96John McCall/// necessarily be elaborated. 2187379448fc7bc91bba33e3d2df073f6cf011960b96John McCallclass ElaboratedType : public Type, public llvm::FoldingSetNode { 2188379448fc7bc91bba33e3d2df073f6cf011960b96John McCallpublic: 2189379448fc7bc91bba33e3d2df073f6cf011960b96John McCall enum TagKind { 2190379448fc7bc91bba33e3d2df073f6cf011960b96John McCall TK_struct, 2191379448fc7bc91bba33e3d2df073f6cf011960b96John McCall TK_union, 2192379448fc7bc91bba33e3d2df073f6cf011960b96John McCall TK_class, 2193379448fc7bc91bba33e3d2df073f6cf011960b96John McCall TK_enum 2194379448fc7bc91bba33e3d2df073f6cf011960b96John McCall }; 2195379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 2196379448fc7bc91bba33e3d2df073f6cf011960b96John McCallprivate: 2197379448fc7bc91bba33e3d2df073f6cf011960b96John McCall /// The tag that was used in this elaborated type specifier. 2198379448fc7bc91bba33e3d2df073f6cf011960b96John McCall TagKind Tag; 2199379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 2200379448fc7bc91bba33e3d2df073f6cf011960b96John McCall /// The underlying type. 2201379448fc7bc91bba33e3d2df073f6cf011960b96John McCall QualType UnderlyingType; 2202379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 2203379448fc7bc91bba33e3d2df073f6cf011960b96John McCall explicit ElaboratedType(QualType Ty, TagKind Tag, QualType Canon) 2204379448fc7bc91bba33e3d2df073f6cf011960b96John McCall : Type(Elaborated, Canon, Canon->isDependentType()), 2205379448fc7bc91bba33e3d2df073f6cf011960b96John McCall Tag(Tag), UnderlyingType(Ty) { } 2206379448fc7bc91bba33e3d2df073f6cf011960b96John McCall friend class ASTContext; // ASTContext creates these. 2207379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 2208379448fc7bc91bba33e3d2df073f6cf011960b96John McCallpublic: 2209379448fc7bc91bba33e3d2df073f6cf011960b96John McCall TagKind getTagKind() const { return Tag; } 2210379448fc7bc91bba33e3d2df073f6cf011960b96John McCall QualType getUnderlyingType() const { return UnderlyingType; } 2211379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 22120afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 22130afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getUnderlyingType(); } 22140afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 22150afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 22160afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 22170afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2218379448fc7bc91bba33e3d2df073f6cf011960b96John McCall static const char *getNameForTagKind(TagKind Kind) { 2219379448fc7bc91bba33e3d2df073f6cf011960b96John McCall switch (Kind) { 2220379448fc7bc91bba33e3d2df073f6cf011960b96John McCall default: assert(0 && "Unknown TagKind!"); 2221379448fc7bc91bba33e3d2df073f6cf011960b96John McCall case TK_struct: return "struct"; 2222379448fc7bc91bba33e3d2df073f6cf011960b96John McCall case TK_union: return "union"; 2223379448fc7bc91bba33e3d2df073f6cf011960b96John McCall case TK_class: return "class"; 2224379448fc7bc91bba33e3d2df073f6cf011960b96John McCall case TK_enum: return "enum"; 2225379448fc7bc91bba33e3d2df073f6cf011960b96John McCall } 2226379448fc7bc91bba33e3d2df073f6cf011960b96John McCall } 2227379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 2228379448fc7bc91bba33e3d2df073f6cf011960b96John McCall void Profile(llvm::FoldingSetNodeID &ID) { 2229379448fc7bc91bba33e3d2df073f6cf011960b96John McCall Profile(ID, getUnderlyingType(), getTagKind()); 2230379448fc7bc91bba33e3d2df073f6cf011960b96John McCall } 2231379448fc7bc91bba33e3d2df073f6cf011960b96John McCall static void Profile(llvm::FoldingSetNodeID &ID, QualType T, TagKind Tag) { 2232379448fc7bc91bba33e3d2df073f6cf011960b96John McCall ID.AddPointer(T.getAsOpaquePtr()); 2233379448fc7bc91bba33e3d2df073f6cf011960b96John McCall ID.AddInteger(Tag); 2234379448fc7bc91bba33e3d2df073f6cf011960b96John McCall } 2235379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 2236379448fc7bc91bba33e3d2df073f6cf011960b96John McCall static bool classof(const ElaboratedType*) { return true; } 2237379448fc7bc91bba33e3d2df073f6cf011960b96John McCall static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; } 2238379448fc7bc91bba33e3d2df073f6cf011960b96John McCall}; 2239379448fc7bc91bba33e3d2df073f6cf011960b96John McCall 2240a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 22414e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson unsigned Depth : 15; 2242a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor unsigned Index : 16; 22434e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson unsigned ParameterPack : 1; 2244a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor IdentifierInfo *Name; 2245dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 224625cf760b54d3b88633827501013bc51a29b28abaMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 224725cf760b54d3b88633827501013bc51a29b28abaMike Stump QualType Canon) 2248a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 22494e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(N) { } 2250dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 225125cf760b54d3b88633827501013bc51a29b28abaMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP) 2252a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 22534e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(0) { } 2254dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 2255a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor friend class ASTContext; // ASTContext creates these 2256dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 2257a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregorpublic: 2258a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor unsigned getDepth() const { return Depth; } 2259a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor unsigned getIndex() const { return Index; } 22604e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson bool isParameterPack() const { return ParameterPack; } 2261a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor IdentifierInfo *getName() const { return Name; } 226225cf760b54d3b88633827501013bc51a29b28abaMike Stump 22630afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 22640afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 22650afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2266a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 22674e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson Profile(ID, Depth, Index, ParameterPack, Name); 2268a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor } 2269a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 227025cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 227125cf760b54d3b88633827501013bc51a29b28abaMike Stump unsigned Index, bool ParameterPack, 22724e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson IdentifierInfo *Name) { 2273a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor ID.AddInteger(Depth); 2274a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor ID.AddInteger(Index); 22754e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson ID.AddBoolean(ParameterPack); 2276a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor ID.AddPointer(Name); 2277a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor } 2278a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 227925cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 228025cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == TemplateTypeParm; 2281dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor } 2282dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 2283dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor}; 2284a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 22855cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// \brief Represents the result of substituting a type for a template 22865cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// type parameter. 22875cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// 22885cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// Within an instantiated template, all template type parameters have 22895cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// been replaced with these. They are used solely to record that a 22905cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// type was originally written as a template type parameter; 22915cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// therefore they are never canonical. 22925cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode { 22935cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall // The original type parameter. 22945cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall const TemplateTypeParmType *Replaced; 22955cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 22965cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) 22975cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType()), 22985cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall Replaced(Param) { } 22995cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23005cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall friend class ASTContext; 23015cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23025cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCallpublic: 23035cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall IdentifierInfo *getName() const { return Replaced->getName(); } 23045cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23055cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall /// Gets the template parameter that was substituted for. 23065cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall const TemplateTypeParmType *getReplacedParameter() const { 23075cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall return Replaced; 23085cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 23095cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23105cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall /// Gets the type that was substituted for the template 23115cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall /// parameter. 23125cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall QualType getReplacementType() const { 23135cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall return getCanonicalTypeInternal(); 23145cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 23155cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23165cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall bool isSugared() const { return true; } 23175cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall QualType desugar() const { return getReplacementType(); } 23185cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23195cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall void Profile(llvm::FoldingSetNodeID &ID) { 23205cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall Profile(ID, getReplacedParameter(), getReplacementType()); 23215cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 23225cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall static void Profile(llvm::FoldingSetNodeID &ID, 23235cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall const TemplateTypeParmType *Replaced, 23245cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall QualType Replacement) { 23255cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall ID.AddPointer(Replaced); 23265cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall ID.AddPointer(Replacement.getAsOpaquePtr()); 23275cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 23285cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23295cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall static bool classof(const Type *T) { 23305cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall return T->getTypeClass() == SubstTemplateTypeParm; 23315cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 23325cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall static bool classof(const SubstTemplateTypeParmType *T) { return true; } 23335cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall}; 23345cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 2335dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// \brief Represents the type of a template specialization as written 2336dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// in the source code. 23378e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// 2338dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// Template specialization types represent the syntactic form of a 2339dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 2340dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 2341dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// type will point to some other type node that represents the 2342dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// instantiation or class template specialization. For example, a 23438e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// class template specialization type of @c vector<int> will refer to 234425cf760b54d3b88633827501013bc51a29b28abaMike Stump/// a tag type for the instantiation 23458e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 2346dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// 2347dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// Other template specialization types, for which the template name 2348dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// is dependent, may be canonical types. These types are always 2349dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// dependent. 235025cf760b54d3b88633827501013bc51a29b28abaMike Stumpclass TemplateSpecializationType 23518e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor : public Type, public llvm::FoldingSetNode { 23528e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 235399eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor // FIXME: Currently needed for profiling expressions; can we avoid this? 235499eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor ASTContext &Context; 235525cf760b54d3b88633827501013bc51a29b28abaMike Stump 235699eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor /// \brief The name of the template being specialized. 2357dd13e8468462e60971487bcd5915419762dab814Douglas Gregor TemplateName Template; 23588e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 2359f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief - The number of template arguments named in this class 2360f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// template specialization. 23618e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor unsigned NumArgs; 23628e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 236399eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor TemplateSpecializationType(ASTContext &Context, 236499eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor TemplateName T, 2365dd13e8468462e60971487bcd5915419762dab814Douglas Gregor const TemplateArgument *Args, 2366dd13e8468462e60971487bcd5915419762dab814Douglas Gregor unsigned NumArgs, QualType Canon); 23678e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 23686f37b58716e89420c13ac067fe605c3b6d5821d0Douglas Gregor virtual void Destroy(ASTContext& C); 23696f37b58716e89420c13ac067fe605c3b6d5821d0Douglas Gregor 23708e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor friend class ASTContext; // ASTContext creates these 23718e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 23728e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregorpublic: 2373f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Determine whether any of the given template arguments are 2374f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// dependent. 2375f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 237625cf760b54d3b88633827501013bc51a29b28abaMike Stump unsigned NumArgs); 2377f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2378588613178e3a10e2b840c8f4db9e058f2fec0005John McCall static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args, 2379588613178e3a10e2b840c8f4db9e058f2fec0005John McCall unsigned NumArgs); 2380588613178e3a10e2b840c8f4db9e058f2fec0005John McCall 2381ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &); 2382ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall 238356d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 238456d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor /// enclosing the template arguments. 238556d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 23863bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor unsigned NumArgs, 23873bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor const PrintingPolicy &Policy); 238856d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor 2389588613178e3a10e2b840c8f4db9e058f2fec0005John McCall static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args, 2390588613178e3a10e2b840c8f4db9e058f2fec0005John McCall unsigned NumArgs, 2391588613178e3a10e2b840c8f4db9e058f2fec0005John McCall const PrintingPolicy &Policy); 2392588613178e3a10e2b840c8f4db9e058f2fec0005John McCall 2393ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &, 2394ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall const PrintingPolicy &Policy); 2395ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall 2396f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor typedef const TemplateArgument * iterator; 2397f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2398f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor iterator begin() const { return getArgs(); } 2399f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor iterator end() const; 2400f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2401dd13e8468462e60971487bcd5915419762dab814Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 2402dd13e8468462e60971487bcd5915419762dab814Douglas Gregor TemplateName getTemplateName() const { return Template; } 24038e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 2404f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Retrieve the template arguments. 240525cf760b54d3b88633827501013bc51a29b28abaMike Stump const TemplateArgument *getArgs() const { 2406f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 2407f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor } 2408f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2409f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Retrieve the number of template arguments. 24108e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 24118e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 24128e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor /// \brief Retrieve a specific template argument as a type. 24138e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor /// \precondition @c isArgType(Arg) 2414f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor const TemplateArgument &getArg(unsigned Idx) const; 24158e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 24160afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return !isDependentType(); } 24170afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getCanonicalTypeInternal(); } 24180afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 24198e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 242099eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor Profile(ID, Template, getArgs(), NumArgs, Context); 24218e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor } 24228e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 2423dd13e8468462e60971487bcd5915419762dab814Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 242499eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor const TemplateArgument *Args, unsigned NumArgs, 242599eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor ASTContext &Context); 24268e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 242725cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 242825cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == TemplateSpecialization; 24298e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor } 2430dd13e8468462e60971487bcd5915419762dab814Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 24318e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor}; 24328e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 2433734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// \brief Represents a type that was referred to via a qualified 2434734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// name, e.g., N::M::type. 2435734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// 2436734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// This type is used to keep track of a type name as written in the 2437e615803e1c4a70ba66b6687b2b95e1fdcd16cd3bDouglas Gregor/// source code, including any nested-name-specifiers. The type itself 2438e615803e1c4a70ba66b6687b2b95e1fdcd16cd3bDouglas Gregor/// is always "sugar", used to express what was written in the source 2439e615803e1c4a70ba66b6687b2b95e1fdcd16cd3bDouglas Gregor/// code but containing no additional semantic information. 2440734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode { 24411e589cc31d339860b9df61870930961601d68120Douglas Gregor /// \brief The nested name specifier containing the qualifier. 24421e589cc31d339860b9df61870930961601d68120Douglas Gregor NestedNameSpecifier *NNS; 2443734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2444734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor /// \brief The type that this qualified name refers to. 2445734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor QualType NamedType; 2446734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 24471e589cc31d339860b9df61870930961601d68120Douglas Gregor QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 24481e589cc31d339860b9df61870930961601d68120Douglas Gregor QualType CanonType) 24491e589cc31d339860b9df61870930961601d68120Douglas Gregor : Type(QualifiedName, CanonType, NamedType->isDependentType()), 24501e589cc31d339860b9df61870930961601d68120Douglas Gregor NNS(NNS), NamedType(NamedType) { } 2451734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2452734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor friend class ASTContext; // ASTContext creates these 2453734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2454734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorpublic: 24551e589cc31d339860b9df61870930961601d68120Douglas Gregor /// \brief Retrieve the qualification on this type. 24561e589cc31d339860b9df61870930961601d68120Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2457734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2458734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 2459734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor QualType getNamedType() const { return NamedType; } 2460734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 24610afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 24620afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getNamedType(); } 24630afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 24640afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 24650afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 24660afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2467734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 24681e589cc31d339860b9df61870930961601d68120Douglas Gregor Profile(ID, NNS, NamedType); 2469734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor } 2470734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 24711e589cc31d339860b9df61870930961601d68120Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 24721e589cc31d339860b9df61870930961601d68120Douglas Gregor QualType NamedType) { 24731e589cc31d339860b9df61870930961601d68120Douglas Gregor ID.AddPointer(NNS); 24741e589cc31d339860b9df61870930961601d68120Douglas Gregor NamedType.Profile(ID); 24751e589cc31d339860b9df61870930961601d68120Douglas Gregor } 2476734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 247725cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 247825cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == QualifiedName; 2479734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor } 2480734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor static bool classof(const QualifiedNameType *T) { return true; } 2481734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor}; 2482734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2483d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// \brief Represents a 'typename' specifier that names a type within 2484d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// a dependent type, e.g., "typename T::type". 2485d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// 2486d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// TypenameType has a very similar structure to QualifiedNameType, 2487d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// which also involves a nested-name-specifier following by a type, 2488d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// and (FIXME!) both can even be prefixed by the 'typename' 2489d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// keyword. However, the two types serve very different roles: 2490d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// QualifiedNameType is a non-semantic type that serves only as sugar 2491d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// to show how a particular type was written in the source 2492d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// code. TypenameType, on the other hand, only occurs when the 2493d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// nested-name-specifier is dependent, such that we cannot resolve 2494d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// the actual type until after instantiation. 2495d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregorclass TypenameType : public Type, public llvm::FoldingSetNode { 2496d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor /// \brief The nested name specifier containing the qualifier. 2497d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor NestedNameSpecifier *NNS; 2498d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 249925cf760b54d3b88633827501013bc51a29b28abaMike Stump typedef llvm::PointerUnion<const IdentifierInfo *, 250077da58034d00866f3261d2c657a5823578f73028Douglas Gregor const TemplateSpecializationType *> NameType; 250177da58034d00866f3261d2c657a5823578f73028Douglas Gregor 2502d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor /// \brief The type that this typename specifier refers to. 250377da58034d00866f3261d2c657a5823578f73028Douglas Gregor NameType Name; 2504d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2505d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 2506d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor QualType CanonType) 250725cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 250825cf760b54d3b88633827501013bc51a29b28abaMike Stump assert(NNS->isDependent() && 2509d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 2510d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2511d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 251277da58034d00866f3261d2c657a5823578f73028Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 251377da58034d00866f3261d2c657a5823578f73028Douglas Gregor QualType CanonType) 251425cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 251525cf760b54d3b88633827501013bc51a29b28abaMike Stump assert(NNS->isDependent() && 251677da58034d00866f3261d2c657a5823578f73028Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 251777da58034d00866f3261d2c657a5823578f73028Douglas Gregor } 251877da58034d00866f3261d2c657a5823578f73028Douglas Gregor 2519d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor friend class ASTContext; // ASTContext creates these 2520d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2521d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregorpublic: 2522d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor /// \brief Retrieve the qualification on this type. 2523d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2524d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 252577da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 252677da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// identifier. 252777da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// 252877da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 252977da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// form of the original typename was terminated by an identifier, 253077da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// e.g., "typename T::type". 253125cf760b54d3b88633827501013bc51a29b28abaMike Stump const IdentifierInfo *getIdentifier() const { 253225cf760b54d3b88633827501013bc51a29b28abaMike Stump return Name.dyn_cast<const IdentifierInfo *>(); 253377da58034d00866f3261d2c657a5823578f73028Douglas Gregor } 253477da58034d00866f3261d2c657a5823578f73028Douglas Gregor 253577da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// \brief Retrieve the type named by the typename specifier as a 253677da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// type specialization. 253777da58034d00866f3261d2c657a5823578f73028Douglas Gregor const TemplateSpecializationType *getTemplateId() const { 253877da58034d00866f3261d2c657a5823578f73028Douglas Gregor return Name.dyn_cast<const TemplateSpecializationType *>(); 253977da58034d00866f3261d2c657a5823578f73028Douglas Gregor } 2540d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 25410afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 25420afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 25430afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2544d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2545d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor Profile(ID, NNS, Name); 2546d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2547d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2548d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 254977da58034d00866f3261d2c657a5823578f73028Douglas Gregor NameType Name) { 2550d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor ID.AddPointer(NNS); 255177da58034d00866f3261d2c657a5823578f73028Douglas Gregor ID.AddPointer(Name.getOpaqueValue()); 2552d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2553d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 255425cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 255525cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == Typename; 2556d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2557d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor static bool classof(const TypenameType *T) { return true; } 2558d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor}; 2559d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2560f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 2561f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// object oriented design. They basically correspond to C++ classes. There 2562f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and 2563f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// qualified interfaces, which are qualified with a protocol list like 256477763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff/// "NSString<NSCopyable, NSAmazing>". 256577763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroffclass ObjCInterfaceType : public Type, public llvm::FoldingSetNode { 256642730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCInterfaceDecl *Decl; 256777763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff 25681b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// \brief The number of protocols stored after the ObjCInterfaceType node. 25691b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// The list of protocols is sorted on protocol name. No protocol is enterred 25701b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// more than once. 257139abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek unsigned NumProtocols; 257277763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff 25731b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor ObjCInterfaceType(QualType Canonical, ObjCInterfaceDecl *D, 257439abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek ObjCProtocolDecl **Protos, unsigned NumP); 257581f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff friend class ASTContext; // ASTContext creates these. 257681f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroffpublic: 257739abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek void Destroy(ASTContext& C); 257839abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek 257942730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 258025cf760b54d3b88633827501013bc51a29b28abaMike Stump 258177763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 258277763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff /// interface type, or 0 if there are none. 258339abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek unsigned getNumProtocols() const { return NumProtocols; } 2584329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 2585f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner /// qual_iterator and friends: this provides access to the (potentially empty) 258677763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff /// list of protocols qualifying this interface. 258739abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek typedef ObjCProtocolDecl* const * qual_iterator; 258839abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek qual_iterator qual_begin() const { 25891b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor return reinterpret_cast<qual_iterator>(this + 1); 259039abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek } 259139abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek qual_iterator qual_end() const { 25921b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor return qual_begin() + NumProtocols; 259339abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek } 259439abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek bool qual_empty() const { return NumProtocols == 0; } 259525cf760b54d3b88633827501013bc51a29b28abaMike Stump 25960afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 25970afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 25980afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 259977763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 260025cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, 260177763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff const ObjCInterfaceDecl *Decl, 26021b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor ObjCProtocolDecl * const *protocols, 26031b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor unsigned NumProtocols); 260425cf760b54d3b88633827501013bc51a29b28abaMike Stump 2605b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 2606b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 260725cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 260825cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == ObjCInterface; 260981f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff } 261042730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 261181f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff}; 261281f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff 2613329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff/// ObjCObjectPointerType - Used to represent 'id', 'Interface *', 'id <p>', 2614329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff/// and 'Interface <p> *'. 2615329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff/// 2616329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff/// Duplicate protocols are removed and protocol list is canonicalized to be in 2617329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff/// alphabetical order. 2618329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 26199f324ae90f87c56d3c1fc87b27bb9b6ebdf277b0Steve Naroff QualType PointeeType; // A builtin or interface type. 262025cf760b54d3b88633827501013bc51a29b28abaMike Stump 26211b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// \brief The number of protocols stored after the ObjCObjectPointerType 26221b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// node. 26231b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// 26241b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// The list of protocols is sorted on protocol name. No protocol is enterred 26251b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor /// more than once. 262639abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek unsigned NumProtocols; 2627329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 26281b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor ObjCObjectPointerType(QualType Canonical, QualType T, 262939abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek ObjCProtocolDecl **Protos, unsigned NumP); 2630329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff friend class ASTContext; // ASTContext creates these. 263125cf760b54d3b88633827501013bc51a29b28abaMike Stump 2632329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffpublic: 263339abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek void Destroy(ASTContext& C); 263439abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek 2635a960479e82ebf6c28dfc5843f0d8bf34db5702e3Steve Naroff // Get the pointee type. Pointee will either be: 2636a960479e82ebf6c28dfc5843f0d8bf34db5702e3Steve Naroff // - a built-in type (for 'id' and 'Class'). 2637a960479e82ebf6c28dfc5843f0d8bf34db5702e3Steve Naroff // - an interface type (for user-defined types). 2638a960479e82ebf6c28dfc5843f0d8bf34db5702e3Steve Naroff // - a TypedefType whose canonical type is an interface (as in 'T' below). 2639a960479e82ebf6c28dfc5843f0d8bf34db5702e3Steve Naroff // For example: typedef NSObject T; T *var; 2640329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff QualType getPointeeType() const { return PointeeType; } 2641329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 264225cf760b54d3b88633827501013bc51a29b28abaMike Stump const ObjCInterfaceType *getInterfaceType() const { 2643cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall return PointeeType->getAs<ObjCInterfaceType>(); 2644329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 26457bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff /// getInterfaceDecl - returns an interface decl for user-defined types. 2646329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff ObjCInterfaceDecl *getInterfaceDecl() const { 26477bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff return getInterfaceType() ? getInterfaceType()->getDecl() : 0; 2648329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 26497bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff /// isObjCIdType - true for "id". 2650329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCIdType() const { 265125cf760b54d3b88633827501013bc51a29b28abaMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && 265239abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek !NumProtocols; 2653329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 26547bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff /// isObjCClassType - true for "Class". 2655329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCClassType() const { 265625cf760b54d3b88633827501013bc51a29b28abaMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) && 265739abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek !NumProtocols; 26587bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff } 26592818bd26562e1a2b7d7e9fb31d72f698a5748289Fariborz Jahanian 26607bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff /// isObjCQualifiedIdType - true for "id <p>". 266125cf760b54d3b88633827501013bc51a29b28abaMike Stump bool isObjCQualifiedIdType() const { 266225cf760b54d3b88633827501013bc51a29b28abaMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && 266339abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek NumProtocols; 26647bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff } 26657bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff /// isObjCQualifiedClassType - true for "Class <p>". 266627bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff bool isObjCQualifiedClassType() const { 266725cf760b54d3b88633827501013bc51a29b28abaMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) && 266839abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek NumProtocols; 2669329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 2670329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff /// qual_iterator and friends: this provides access to the (potentially empty) 2671329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff /// list of protocols qualifying this interface. 267239abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek typedef ObjCProtocolDecl* const * qual_iterator; 2673329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 267439abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek qual_iterator qual_begin() const { 26751b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor return reinterpret_cast<qual_iterator> (this + 1); 267639abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek } 267739abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek qual_iterator qual_end() const { 26781b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor return qual_begin() + NumProtocols; 267939abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek } 268039abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek bool qual_empty() const { return NumProtocols == 0; } 2681329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 2682329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 2683329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff /// interface type, or 0 if there are none. 268439abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek unsigned getNumProtocols() const { return NumProtocols; } 2685329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 26860afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 26870afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 26880afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2689b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor virtual Linkage getLinkage() const; 2690b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 2691329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff void Profile(llvm::FoldingSetNodeID &ID); 2692329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType T, 26931b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor ObjCProtocolDecl *const *protocols, 26941b60285d38b1d9c443b897cf42d85a7cfee54309Douglas Gregor unsigned NumProtocols); 269525cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 269625cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == ObjCObjectPointer; 2697329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 2698329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 2699329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff}; 2700fd3d5fdac0d25464e1b9c36bc646965494d44f66Argiris Kirtzidis 27013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// A qualifier set is used to build a set of qualifiers. 27023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallclass QualifierCollector : public Qualifiers { 27033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ASTContext *Context; 27043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallpublic: 27063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector(Qualifiers Qs = Qualifiers()) 27073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Qualifiers(Qs), Context(0) {} 27083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector(ASTContext &Context, Qualifiers Qs = Qualifiers()) 27093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Qualifiers(Qs), Context(&Context) {} 27103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setContext(ASTContext &C) { Context = &C; } 27123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Collect any qualifiers on the given type and return an 27143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// unqualified type. 27153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *strip(QualType QT) { 2716c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor addFastQualifiers(QT.getLocalFastQualifiers()); 2717c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (QT.hasLocalNonFastQualifiers()) { 27183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = QT.getExtQualsUnsafe(); 27193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Context = &EQ->getContext(); 27203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall addQualifiers(EQ->getQualifiers()); 27213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getBaseType(); 27223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 27233ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return QT.getTypePtrUnsafe(); 27243ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 27253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Apply the collected qualifiers to the given type. 27273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType apply(QualType QT) const; 27283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27293ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Apply the collected qualifiers to the given type. 27303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType apply(const Type* T) const; 27313ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall}; 27333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 27343ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2735b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner// Inline function definitions. 27364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 27377480534aa1979f5c8a6c1d59ede223ba21f280e5John McCallinline bool QualType::isCanonical() const { 27387480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall const Type *T = getTypePtr(); 2739c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalQualifiers()) 27407480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall return T->isCanonicalUnqualified() && !isa<ArrayType>(T); 27417480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall return T->isCanonicalUnqualified(); 27427480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall} 27437480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall 27444ea8425c9601895fa137f877bc784f75f20adac6John McCallinline bool QualType::isCanonicalAsParam() const { 2745c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalQualifiers()) return false; 27464ea8425c9601895fa137f877bc784f75f20adac6John McCall const Type *T = getTypePtr(); 27474ea8425c9601895fa137f877bc784f75f20adac6John McCall return T->isCanonicalUnqualified() && 27484ea8425c9601895fa137f877bc784f75f20adac6John McCall !isa<FunctionType>(T) && !isa<ArrayType>(T); 27494ea8425c9601895fa137f877bc784f75f20adac6John McCall} 27504ea8425c9601895fa137f877bc784f75f20adac6John McCall 27514f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::isConstQualified() const { 27524f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return isLocalConstQualified() || 27534f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalConstQualified(); 27544f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 27554f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 27564f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::isRestrictQualified() const { 27574f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return isLocalRestrictQualified() || 27584f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalRestrictQualified(); 27594f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 27604f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 27614f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 27624f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::isVolatileQualified() const { 27634f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return isLocalVolatileQualified() || 27644f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalVolatileQualified(); 27654f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 27664f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 27674f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::hasQualifiers() const { 27684f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return hasLocalQualifiers() || 27694f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers(); 27704f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 27714f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 27724f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline Qualifiers QualType::getQualifiers() const { 27734f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor Qualifiers Quals = getLocalQualifiers(); 27744f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor Quals.addQualifiers( 27754f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().getLocalQualifiers()); 27764f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return Quals; 27774f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 27784f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 27794f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline unsigned QualType::getCVRQualifiers() const { 27804f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return getLocalCVRQualifiers() | 27814f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().getLocalCVRQualifiers(); 27824f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 27836d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth 27846d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// getCVRQualifiersThroughArrayTypes - If there are CVR qualifiers for this 27856d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// type, returns them. Otherwise, if this is an array type, recurses 27866d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// on the element type until some qualifiers have been found or a non-array 27876d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// type reached. 27886d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruthinline unsigned QualType::getCVRQualifiersThroughArrayTypes() const { 27896d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth if (unsigned Quals = getCVRQualifiers()) 27906d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth return Quals; 27916d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth QualType CT = getTypePtr()->getCanonicalTypeInternal(); 27926d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 27936d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth return AT->getElementType().getCVRQualifiersThroughArrayTypes(); 27946d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth return 0; 27956d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth} 27966d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth 27973ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeConst() { 27983ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeFastQualifiers(Qualifiers::Const); 27993ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall} 28003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 28013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeRestrict() { 28023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeFastQualifiers(Qualifiers::Restrict); 28033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall} 28043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 28053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeVolatile() { 28063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector Qc; 28073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *Ty = Qc.strip(*this); 28083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (Qc.hasVolatile()) { 28093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qc.removeVolatile(); 28103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall *this = Qc.apply(Ty); 28113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 28123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall} 28133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 28143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeCVRQualifiers(unsigned Mask) { 2815451b7b9a60208869cf5d6d958134cb104343949fJohn McCall assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits"); 28163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 28173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Fast path: we don't need to touch the slow qualifiers. 28183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (!(Mask & ~Qualifiers::FastMask)) { 28193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeFastQualifiers(Mask); 28203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return; 28213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 28223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 28233ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector Qc; 28243ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *Ty = Qc.strip(*this); 28253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qc.removeCVRQualifiers(Mask); 28263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall *this = Qc.apply(Ty); 28272a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb} 28282a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 28292a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// getAddressSpace - Return the address space of this type. 28302a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambinline unsigned QualType::getAddressSpace() const { 2831c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalNonFastQualifiers()) { 28323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = getExtQualsUnsafe(); 28333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasAddressSpace()) 28343ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getAddressSpace(); 28353ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 28363ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 283701ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 2838c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (CT.hasLocalNonFastQualifiers()) { 28393ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = CT.getExtQualsUnsafe(); 28403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasAddressSpace()) 28413ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getAddressSpace(); 28423ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 28433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 284401ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2845a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return AT->getElementType().getAddressSpace(); 284601ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 2847efc11216a5755f69b5540289aa2dd374d4bc82abNate Begeman return RT->getAddressSpace(); 28482a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return 0; 28492a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb} 2850b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner 2851af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 28523ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const { 2853c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalNonFastQualifiers()) { 28543ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = getExtQualsUnsafe(); 28553ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasObjCGCAttr()) 28563ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getObjCGCAttr(); 28573ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 28583ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2859af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 2860c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (CT.hasLocalNonFastQualifiers()) { 28613ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = CT.getExtQualsUnsafe(); 28623ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasObjCGCAttr()) 28633ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getObjCGCAttr(); 28643ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 28653ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2866af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2867af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian return AT->getElementType().getObjCGCAttr(); 2868cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *PT = CT->getAs<ObjCObjectPointerType>()) 286925cf760b54d3b88633827501013bc51a29b28abaMike Stump return PT->getPointeeType().getObjCGCAttr(); 28704bb774e2352b6c5f459b345a5e0f41bd244e70a7Fariborz Jahanian // We most look at all pointer types, not just pointer to interface types. 28714bb774e2352b6c5f459b345a5e0f41bd244e70a7Fariborz Jahanian if (const PointerType *PT = CT->getAs<PointerType>()) 287225cf760b54d3b88633827501013bc51a29b28abaMike Stump return PT->getPointeeType().getObjCGCAttr(); 28733ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Qualifiers::GCNone; 2874af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian} 28751bb806498909a43a7829edb21c42606335d69694Mike Stump 28760f95d329cc0ba37faa0f3d522991a581a407482cMike Stump /// getNoReturnAttr - Returns true if the type has the noreturn attribute, 28770f95d329cc0ba37faa0f3d522991a581a407482cMike Stump /// false otherwise. 28781bb806498909a43a7829edb21c42606335d69694Mike Stumpinline bool QualType::getNoReturnAttr() const { 28791bb806498909a43a7829edb21c42606335d69694Mike Stump QualType CT = getTypePtr()->getCanonicalTypeInternal(); 2880d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const PointerType *PT = getTypePtr()->getAs<PointerType>()) { 2881cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>()) 28821bb806498909a43a7829edb21c42606335d69694Mike Stump return FT->getNoReturnAttr(); 2883cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall } else if (const FunctionType *FT = getTypePtr()->getAs<FunctionType>()) 28841bb806498909a43a7829edb21c42606335d69694Mike Stump return FT->getNoReturnAttr(); 28851bb806498909a43a7829edb21c42606335d69694Mike Stump 28861bb806498909a43a7829edb21c42606335d69694Mike Stump return false; 28871bb806498909a43a7829edb21c42606335d69694Mike Stump} 288825cf760b54d3b88633827501013bc51a29b28abaMike Stump 288931cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor/// getCallConv - Returns the calling convention of the type if the type 289031cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor/// is a function type, CC_Default otherwise. 289131cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregorinline CallingConv QualType::getCallConv() const { 289231cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor if (const PointerType *PT = getTypePtr()->getAs<PointerType>()) 289331cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor return PT->getPointeeType().getCallConv(); 289431cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor else if (const ReferenceType *RT = getTypePtr()->getAs<ReferenceType>()) 289531cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor return RT->getPointeeType().getCallConv(); 289631cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor else if (const MemberPointerType *MPT = 289731cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor getTypePtr()->getAs<MemberPointerType>()) 289831cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor return MPT->getPointeeType().getCallConv(); 289931cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor else if (const BlockPointerType *BPT = 290031cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor getTypePtr()->getAs<BlockPointerType>()) { 290131cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor if (const FunctionType *FT = BPT->getPointeeType()->getAs<FunctionType>()) 290231cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor return FT->getCallConv(); 290331cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor } else if (const FunctionType *FT = getTypePtr()->getAs<FunctionType>()) 290431cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor return FT->getCallConv(); 290531cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor 290631cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor return CC_Default; 290731cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor} 290831cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor 29093fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 29103fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 29113fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// is more qualified than "const int", "volatile int", and 29123fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int". However, it is not more qualified than "const volatile 29133fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int". 29143fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 29153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // FIXME: work on arbitrary qualifiers 29166d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes(); 29176d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes(); 29188fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner if (getAddressSpace() != Other.getAddressSpace()) 29198fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner return false; 29203fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 29213fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 29223fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 29233fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 29243fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// as qualified as the Other type. For example, "const volatile 29253fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 29263fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int", and "const volatile int". 29273fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 29283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // FIXME: work on arbitrary qualifiers 29296d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes(); 29306d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes(); 29318fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner if (getAddressSpace() != Other.getAddressSpace()) 29328fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner return false; 29333fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 29343fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 29353fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 29363fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 29373fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int&), returns the type that the reference refers to ("const 29383fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 29393fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// throughout Sema to implement C++ 5p6: 29403fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// 29413fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 29423fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 29433fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// analysis, the expression designates the object or function 29443fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 29453fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline QualType QualType::getNonReferenceType() const { 2946d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 29473fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return RefType->getPointeeType(); 29483fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor else 29493fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return *this; 29503fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 29513fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 2952f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 2953d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const PointerType *PT = getAs<PointerType>()) 2954cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall return PT->getPointeeType()->getAs<ObjCInterfaceType>(); 2955f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner return 0; 2956f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner} 295725cf760b54d3b88633827501013bc51a29b28abaMike Stump 2958b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isFunctionType() const { 2959c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<FunctionType>(CanonicalType); 2960b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 2961b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isPointerType() const { 2962c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<PointerType>(CanonicalType); 2963b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 296479ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroffinline bool Type::isAnyPointerType() const { 296579ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroff return isPointerType() || isObjCObjectPointerType(); 296679ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroff} 29677aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffinline bool Type::isBlockPointerType() const { 2968c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<BlockPointerType>(CanonicalType); 29697aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff} 2970cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattnerinline bool Type::isReferenceType() const { 2971c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ReferenceType>(CanonicalType); 2972cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner} 2973ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlinline bool Type::isLValueReferenceType() const { 2974c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<LValueReferenceType>(CanonicalType); 2975ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl} 2976ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlinline bool Type::isRValueReferenceType() const { 2977c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<RValueReferenceType>(CanonicalType); 2978ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl} 297983b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenekinline bool Type::isFunctionPointerType() const { 2980d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const PointerType* T = getAs<PointerType>()) 298183b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek return T->getPointeeType()->isFunctionType(); 298283b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek else 298383b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek return false; 298483b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek} 29857555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlinline bool Type::isMemberPointerType() const { 2986c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<MemberPointerType>(CanonicalType); 29877555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl} 29887555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 2989d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const MemberPointerType* T = getAs<MemberPointerType>()) 29907555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return T->getPointeeType()->isFunctionType(); 29917555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl else 29927555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return false; 29937555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl} 2994b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isArrayType() const { 2995c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ArrayType>(CanonicalType); 2996b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 2997a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isConstantArrayType() const { 2998c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ConstantArrayType>(CanonicalType); 2999a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 3000a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isIncompleteArrayType() const { 3001c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<IncompleteArrayType>(CanonicalType); 3002a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 3003a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isVariableArrayType() const { 3004c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<VariableArrayType>(CanonicalType); 3005a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 30061b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorinline bool Type::isDependentSizedArrayType() const { 3007c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType); 30081b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor} 3009b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isRecordType() const { 3010c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<RecordType>(CanonicalType); 3011b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 30123277df47de6b65b55721726dc3f7b294e70ef6feChris Lattnerinline bool Type::isAnyComplexType() const { 3013c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ComplexType>(CanonicalType); 30143277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner} 3015b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isVectorType() const { 3016c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<VectorType>(CanonicalType); 3017b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 3018af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemaninline bool Type::isExtVectorType() const { 3019c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ExtVectorType>(CanonicalType); 3020b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 3021c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroffinline bool Type::isObjCObjectPointerType() const { 3022c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ObjCObjectPointerType>(CanonicalType); 3023c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff} 302442730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekinline bool Type::isObjCInterfaceType() const { 3025c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ObjCInterfaceType>(CanonicalType); 3026b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner} 302742730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 3028cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3029c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff return OPT->isObjCQualifiedIdType(); 3030c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff return false; 3031dcb2b1e489948a570ee07ca65e12d42edffa20efFariborz Jahanian} 303227bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroffinline bool Type::isObjCQualifiedClassType() const { 3033cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 303427bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff return OPT->isObjCQualifiedClassType(); 303527bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff return false; 303627bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff} 3037329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffinline bool Type::isObjCIdType() const { 3038cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3039329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return OPT->isObjCIdType(); 3040329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return false; 3041329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff} 3042329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffinline bool Type::isObjCClassType() const { 3043cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3044329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return OPT->isObjCClassType(); 3045329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return false; 3046329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff} 3047a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanianinline bool Type::isObjCSelType() const { 30482818bd26562e1a2b7d7e9fb31d72f698a5748289Fariborz Jahanian if (const PointerType *OPT = getAs<PointerType>()) 30492818bd26562e1a2b7d7e9fb31d72f698a5748289Fariborz Jahanian return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); 3050a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian return false; 3051a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian} 30527bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroffinline bool Type::isObjCBuiltinType() const { 3053a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian return isObjCIdType() || isObjCClassType() || isObjCSelType(); 30547bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff} 3055dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorinline bool Type::isTemplateTypeParmType() const { 3056c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType); 3057dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor} 3058dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 3059c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 3060cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 3061c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 3062c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar return true; 3063c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar return false; 3064c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar} 3065c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar 306600fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor/// \brief Determines whether this is a type for which one can define 306700fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor/// an overloaded operator. 306800fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregorinline bool Type::isOverloadableType() const { 306900fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 307045014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor} 307145014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor 3072fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 3073fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 307425cf760b54d3b88633827501013bc51a29b28abaMike Stump isObjCInterfaceType() || isObjCObjectPointerType() || 30755d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl isObjCQualifiedInterfaceType() || isNullPtrType()); 3076fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar} 3077fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar 30787c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 307925cf760b54d3b88633827501013bc51a29b28abaMike Stump return (isObjCInterfaceType() || isObjCObjectPointerType() || 30807c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian isObjCQualifiedInterfaceType()); 30817c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian} 30827c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian 3083da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 3084da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// diagnostic with <<. 3085da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 3086da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner QualType T) { 3087da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 3088da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner Diagnostic::ak_qualtype); 3089da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner return DB; 3090da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner} 309125cf760b54d3b88633827501013bc51a29b28abaMike Stump 3092406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does 3093406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor// not try to look through a qualified type to get to an array type. 3094406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregortemplate<typename T, 3095406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor bool isArrayType = (llvm::is_same<T, ArrayType>::value || 3096406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor llvm::is_base_of<ArrayType, T>::value)> 3097406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { }; 3098406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor 3099406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregortemplate<typename T> 3100406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>; 3101406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor 3102f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek/// Member-template getAs<specific type>'. 3103f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenektemplate <typename T> const T *Type::getAs() const { 3104406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor ArrayType_cannot_be_used_with_getAs<T> at; 3105406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor (void)at; 3106406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor 3107f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // If this is directly a T type, return it. 3108f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek if (const T *Ty = dyn_cast<T>(this)) 3109f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek return Ty; 311025cf760b54d3b88633827501013bc51a29b28abaMike Stump 3111f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // If the canonical form of this type isn't the right kind, reject it. 31123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (!isa<T>(CanonicalType)) 3113f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek return 0; 311425cf760b54d3b88633827501013bc51a29b28abaMike Stump 31153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // If this is a typedef for the type, strip the typedef off without 3116f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // losing all typedef information. 31170afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall return cast<T>(getUnqualifiedDesugaredType()); 311825cf760b54d3b88633827501013bc51a29b28abaMike Stump} 3119da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner 31204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner} // end namespace clang 31214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 31224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#endif 3123