Type.h revision 9484f8eade39f9d22deb26abdd6c1c804b820eac
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" 208edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth#include "clang/Basic/PartialDiagnostic.h" 21734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor#include "clang/AST/NestedNameSpecifier.h" 22dd13e8468462e60971487bcd5915419762dab814Douglas Gregor#include "clang/AST/TemplateName.h" 234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#include "llvm/Support/Casting.h" 24cfe6ae592450d8466b4d78b59ff4526266549a9aDouglas Gregor#include "llvm/Support/type_traits.h" 2583c13010359c33354c581acee65d0c986a75247eSteve Naroff#include "llvm/ADT/APSInt.h" 2648a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner#include "llvm/ADT/FoldingSet.h" 2748a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner#include "llvm/ADT/PointerIntPair.h" 2877da58034d00866f3261d2c657a5823578f73028Douglas Gregor#include "llvm/ADT/PointerUnion.h" 29dd13e8468462e60971487bcd5915419762dab814Douglas Gregor 304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::isa; 314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::cast; 324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::cast_or_null; 334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::dyn_cast; 344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::dyn_cast_or_null; 35451b7b9a60208869cf5d6d958134cb104343949fJohn McCallnamespace clang { 36451b7b9a60208869cf5d6d958134cb104343949fJohn McCall enum { 37451b7b9a60208869cf5d6d958134cb104343949fJohn McCall TypeAlignmentInBits = 3, 38451b7b9a60208869cf5d6d958134cb104343949fJohn McCall TypeAlignment = 1 << TypeAlignmentInBits 39451b7b9a60208869cf5d6d958134cb104343949fJohn McCall }; 40e38592f880f425a6d9ea856a81703522a8ae345bChris Lattner class Type; 41e38592f880f425a6d9ea856a81703522a8ae345bChris Lattner class ExtQuals; 42e38592f880f425a6d9ea856a81703522a8ae345bChris Lattner class QualType; 43451b7b9a60208869cf5d6d958134cb104343949fJohn McCall} 444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 45cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattnernamespace llvm { 46cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner template <typename T> 47d776b2da9bd694c41f1506e152aeb35d1babeba6Chris Lattner class PointerLikeTypeTraits; 488813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner template<> 498813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner class PointerLikeTypeTraits< ::clang::Type*> { 508813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner public: 518813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 528813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner static inline ::clang::Type *getFromVoidPointer(void *P) { 538813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner return static_cast< ::clang::Type*>(P); 548813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner } 55451b7b9a60208869cf5d6d958134cb104343949fJohn McCall enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 568813477d35efbfe22f9bb0436ec948e72913fb45Chris Lattner }; 573ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall template<> 583ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall class PointerLikeTypeTraits< ::clang::ExtQuals*> { 593ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall public: 603ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; } 613ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static inline ::clang::ExtQuals *getFromVoidPointer(void *P) { 623ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return static_cast< ::clang::ExtQuals*>(P); 633ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 64451b7b9a60208869cf5d6d958134cb104343949fJohn McCall enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 653ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall }; 66e38592f880f425a6d9ea856a81703522a8ae345bChris Lattner 67e38592f880f425a6d9ea856a81703522a8ae345bChris Lattner template <> 68e38592f880f425a6d9ea856a81703522a8ae345bChris Lattner struct isPodLike<clang::QualType> { static const bool value = true; }; 69cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner} 70cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner 714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace clang { 724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class ASTContext; 734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class TypedefDecl; 748e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor class TemplateDecl; 75dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor class TemplateTypeParmDecl; 76279272e63b321f89c8fa0bb198acd3a834459aebDouglas Gregor class NonTypeTemplateParmDecl; 77dd13e8468462e60971487bcd5915419762dab814Douglas Gregor class TemplateTemplateParmDecl; 784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class TagDecl; 794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class RecordDecl; 80ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis class CXXRecordDecl; 814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class EnumDecl; 8264be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek class FieldDecl; 8342730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek class ObjCInterfaceDecl; 8442730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek class ObjCProtocolDecl; 8542730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek class ObjCMethodDecl; 86caf383ae337966d67380b6b161fab17ec2b53d04John McCall class UnresolvedUsingTypenameDecl; 874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class Expr; 88718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek class Stmt; 894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class SourceLocation; 90fce813e3159a67a57a03cdca45ac4e10d4cffac3Ted Kremenek class StmtIteratorBase; 91f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor class TemplateArgument; 92588613178e3a10e2b840c8f4db9e058f2fec0005John McCall class TemplateArgumentLoc; 93ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall class TemplateArgumentListInfo; 94cc392fc654e59b8d55df3901a82b193845ee44f4John McCall class Type; 95ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara class ElaboratedType; 96198e8e46d0bfe535f044df35d1b87da86a148a84Daniel Dunbar struct PrintingPolicy; 974fa58905062efa6a12137b1983a1367220182a20Douglas Gregor 98cc392fc654e59b8d55df3901a82b193845ee44f4John McCall template <typename> class CanQual; 99cc392fc654e59b8d55df3901a82b193845ee44f4John McCall typedef CanQual<Type> CanQualType; 100cc392fc654e59b8d55df3901a82b193845ee44f4John McCall 1014fa58905062efa6a12137b1983a1367220182a20Douglas Gregor // Provide forward declarations for all of the *Type classes 1024fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define TYPE(Class, Base) class Class##Type; 1034fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#include "clang/AST/TypeNodes.def" 1047555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 1053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// Qualifiers - The collection of all-type qualifiers we support. 1063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// Clang supports five independent qualifiers: 1073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// * C99: const, volatile, and restrict 1083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// * Embedded C (TR18037): address spaces 1093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// * Objective C: the GC attributes (none, weak, or strong) 1103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallclass Qualifiers { 1114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 1123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 1134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Const = 0x1, 1144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Restrict = 0x2, 1154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Volatile = 0x4, 1163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall CVRMask = Const | Volatile | Restrict 1174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 11825cf760b54d3b88633827501013bc51a29b28abaMike Stump 1193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall enum GC { 120af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian GCNone = 0, 121af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian Weak, 122af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian Strong 123af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian }; 124fda7da669298c7428a1c963013d9a8c71cbedbc5John McCall 1253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall enum { 1263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// The maximum supported address space number. 1273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// 24 bits should be enough for anyone. 1283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall MaxAddressSpace = 0xffffffu, 1293ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// The width of the "fast" qualifier mask. 1313ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall FastWidth = 2, 1323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// The fast qualifier mask. 1343ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall FastMask = (1 << FastWidth) - 1 1353ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall }; 1363ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1373ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers() : Mask(0) {} 1383ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1393ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static Qualifiers fromFastMask(unsigned Mask) { 1403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Qs; 1413ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qs.addFastQualifiers(Mask); 1423ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Qs; 1433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1443ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1453ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static Qualifiers fromCVRMask(unsigned CVR) { 1463ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Qs; 1473ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qs.addCVRQualifiers(CVR); 1483ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Qs; 1493ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1503ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1513ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Deserialize qualifiers from an opaque representation. 1523ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static Qualifiers fromOpaqueValue(unsigned opaque) { 1533ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Qs; 1543ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qs.Mask = opaque; 1553ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Qs; 1563ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1573ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1583ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Serialize these qualifiers into an opaque representation. 1593ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getAsOpaqueValue() const { 1603ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Mask; 1613ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1623ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1633ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasConst() const { return Mask & Const; } 1643ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setConst(bool flag) { 1653ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask = (Mask & ~Const) | (flag ? Const : 0); 1663ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1673ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeConst() { Mask &= ~Const; } 1683ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addConst() { Mask |= Const; } 1693ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1703ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasVolatile() const { return Mask & Volatile; } 1713ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setVolatile(bool flag) { 1723ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask = (Mask & ~Volatile) | (flag ? Volatile : 0); 1733ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1743ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeVolatile() { Mask &= ~Volatile; } 1753ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addVolatile() { Mask |= Volatile; } 1763ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1773ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasRestrict() const { return Mask & Restrict; } 1783ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setRestrict(bool flag) { 1793ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask = (Mask & ~Restrict) | (flag ? Restrict : 0); 1803ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1813ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeRestrict() { Mask &= ~Restrict; } 1823ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addRestrict() { Mask |= Restrict; } 1833ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 1843ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasCVRQualifiers() const { return getCVRQualifiers(); } 1853ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getCVRQualifiers() const { return Mask & CVRMask; } 1863ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setCVRQualifiers(unsigned mask) { 1873ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 1883ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask = (Mask & ~CVRMask) | mask; 1893ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1903ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeCVRQualifiers(unsigned mask) { 1913ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 1923ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask &= ~mask; 1933ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1943ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeCVRQualifiers() { 1953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeCVRQualifiers(CVRMask); 1963ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 1973ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addCVRQualifiers(unsigned mask) { 1983ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 1993ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask |= mask; 2003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasObjCGCAttr() const { return Mask & GCAttrMask; } 2033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); } 2043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setObjCGCAttr(GC type) { 2053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift); 2063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeObjCGCAttr() { setObjCGCAttr(GCNone); } 2083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addObjCGCAttr(GC type) { 2093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(type); 2103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall setObjCGCAttr(type); 2113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasAddressSpace() const { return Mask & AddressSpaceMask; } 2143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; } 2153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setAddressSpace(unsigned space) { 2163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(space <= MaxAddressSpace); 2173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask = (Mask & ~AddressSpaceMask) 2183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall | (((uint32_t) space) << AddressSpaceShift); 2193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeAddressSpace() { setAddressSpace(0); } 2213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addAddressSpace(unsigned space) { 2223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(space); 2233ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall setAddressSpace(space); 2243ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Fast qualifiers are those that can be allocated directly 2273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // on a QualType object. 2283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasFastQualifiers() const { return getFastQualifiers(); } 2293ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getFastQualifiers() const { return Mask & FastMask; } 2303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setFastQualifiers(unsigned mask) { 2313ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask = (Mask & ~FastMask) | mask; 2333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2343ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeFastQualifiers(unsigned mask) { 2353ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2363ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask &= ~mask; 2373ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2383ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeFastQualifiers() { 2393ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeFastQualifiers(FastMask); 2403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2413ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addFastQualifiers(unsigned mask) { 2423ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 2433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask |= mask; 2443ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2453ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2463ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// hasNonFastQualifiers - Return true if the set contains any 2473ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// qualifiers which require an ExtQuals node to be allocated. 2483ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasNonFastQualifiers() const { return Mask & ~FastMask; } 2493ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers getNonFastQualifiers() const { 2503ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Quals = *this; 2513ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Quals.setFastQualifiers(0); 2523ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Quals; 2533ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2543ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2553ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// hasQualifiers - Return true if the set contains any qualifiers. 2563ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasQualifiers() const { return Mask; } 2573ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool empty() const { return !Mask; } 2583ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2593ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// \brief Add the qualifiers from the given set to this set. 2603ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addQualifiers(Qualifiers Q) { 2613ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // If the other set doesn't have any non-boolean qualifiers, just 2623ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // bit-or it in. 2633ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (!(Q.Mask & ~CVRMask)) 2643ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask |= Q.Mask; 2653ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall else { 2663ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Mask |= (Q.Mask & CVRMask); 2673ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (Q.hasAddressSpace()) 2683ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall addAddressSpace(Q.getAddressSpace()); 2693ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (Q.hasObjCGCAttr()) 2703ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall addObjCGCAttr(Q.getObjCGCAttr()); 2713ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2723ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2733ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2743ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool operator==(Qualifiers Other) const { return Mask == Other.Mask; } 2753ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; } 2763ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2773ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall operator bool() const { return hasQualifiers(); } 2783ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2793ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers &operator+=(Qualifiers R) { 2803ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall addQualifiers(R); 2813ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return *this; 2823ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2833ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2843ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Union two qualifier sets. If an enumerated qualifier appears 2853ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // in both sets, use the one from the right. 2863ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall friend Qualifiers operator+(Qualifiers L, Qualifiers R) { 2873ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall L += R; 2883ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return L; 2893ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2903ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2913ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall std::string getAsString() const; 2923ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall std::string getAsString(const PrintingPolicy &Policy) const { 2933ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall std::string Buffer; 2943ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getAsStringInternal(Buffer, Policy); 2953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Buffer; 2963ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2973ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const; 2983ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2993ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 3003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ID.AddInteger(Mask); 3013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 3023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallprivate: 3043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // bits: |0 1 2|3 .. 4|5 .. 31| 3063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // |C R V|GCAttr|AddrSpace| 3073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall uint32_t Mask; 3083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static const uint32_t GCAttrMask = 0x18; 3103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static const uint32_t GCAttrShift = 3; 3113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask); 3123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static const uint32_t AddressSpaceShift = 5; 3133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall}; 3143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// ExtQuals - We can encode up to three bits in the low bits of a 3173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// type pointer, but there are many more type qualifiers that we want 3183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// to be able to apply to an arbitrary type. Therefore we have this 3193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// struct, intended to be heap-allocated and used by QualType to 3203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// store qualifiers. 3213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// 3223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// The current design tags the 'const' and 'restrict' qualifiers in 3233ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// two low bits on the QualType pointer; a third bit records whether 3243ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// the pointer is an ExtQuals node. 'const' was chosen because it is 3253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// orders of magnitude more common than the other two qualifiers, in 3263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// both library and user code. It's relatively rare to see 3273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// 'restrict' in user code, but many standard C headers are saturated 3283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// with 'restrict' declarations, so that representing them efficiently 3293ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// is a critical goal of this representation. 3303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallclass ExtQuals : public llvm::FoldingSetNode { 3313ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // NOTE: changing the fast qualifiers should be straightforward as 3323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // long as you don't make 'const' non-fast. 3333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // 1. Qualifiers: 3343ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ). 3353ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Fast qualifiers must occupy the low-order bits. 3363ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // b) Update Qualifiers::FastWidth and FastMask. 3373ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // 2. QualType: 3383ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // a) Update is{Volatile,Restrict}Qualified(), defined inline. 3393ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // b) Update remove{Volatile,Restrict}, defined near the end of 3403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // this header. 3413ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // 3. ASTContext: 3423ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // a) Update get{Volatile,Restrict}Type. 3433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3443ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Context - the context to which this set belongs. We save this 3453ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// here so that QualifierCollector can use it to reapply extended 3463ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// qualifiers to an arbitrary type without requiring a context to 3473ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// be pushed through every single API dealing with qualifiers. 3483ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ASTContext& Context; 3493ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3503ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// BaseType - the underlying type that this qualifies 3513ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *BaseType; 3523ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3533ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Quals - the immutable set of qualifiers applied by this 3543ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// node; always contains extended qualifiers. 3553ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Quals; 3563ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3573ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallpublic: 3583ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ExtQuals(ASTContext& Context, const Type *Base, Qualifiers Quals) 3593ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Context(Context), BaseType(Base), Quals(Quals) 3603ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall { 3613ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(Quals.hasNonFastQualifiers() 3623ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall && "ExtQuals created with no fast qualifiers"); 3633ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!Quals.hasFastQualifiers() 3643ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall && "ExtQuals created with fast qualifiers"); 3653ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 3663ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3673ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers getQualifiers() const { return Quals; } 3683ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3693ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasVolatile() const { return Quals.hasVolatile(); } 3703ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3713ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); } 3723ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); } 3733ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3743ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasAddressSpace() const { return Quals.hasAddressSpace(); } 3753ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getAddressSpace() const { return Quals.getAddressSpace(); } 3763ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3773ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *getBaseType() const { return BaseType; } 37825cf760b54d3b88633827501013bc51a29b28abaMike Stump 3793ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ASTContext &getContext() const { return Context; } 3803ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3813ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallpublic: 3823ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 3833ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Profile(ID, getBaseType(), Quals); 3843ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 3853ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, 3863ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *BaseType, 3873ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Quals) { 3883ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!"); 3893ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ID.AddPointer(BaseType); 3903ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Quals.Profile(ID); 3913ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 3923ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall}; 3933ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 39431cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor/// CallingConv - Specifies the calling convention that a function uses. 39531cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregorenum CallingConv { 39631cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CC_Default, 39731cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CC_C, // __attribute__((cdecl)) 39831cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CC_X86StdCall, // __attribute__((stdcall)) 39901890a8487ae3330abc501b455e2092545d54775Douglas Gregor CC_X86FastCall, // __attribute__((fastcall)) 40001890a8487ae3330abc501b455e2092545d54775Douglas Gregor CC_X86ThisCall // __attribute__((thiscall)) 40131cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor}; 40231cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor 4033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 4043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on 4053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// their own: instead each reference to a type stores the qualifiers. This 4063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for 4073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// example we only need one for 'int', 'const int', 'volatile int', 4083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// 'const volatile int', etc). 4093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// 4103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// As an added efficiency bonus, instead of making this a pair, we 4113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// just store the two bits we care about in the low bits of the 4123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// pointer. To handle the packing/unpacking, we make QualType be a 4133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// simple wrapper class that acts like a smart pointer. A third bit 4143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// indicates whether there are extended qualifiers present, in which 4153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// case the pointer points to a special structure. 4163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallclass QualType { 4173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Thankfully, these are efficiently composable. 4183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>, 4193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers::FastWidth> Value; 4203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 4213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *getExtQualsUnsafe() const { 4223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Value.getPointer().get<const ExtQuals*>(); 4233ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 4243ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 4253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *getTypePtrUnsafe() const { 4263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Value.getPointer().get<const Type*>(); 4273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 4283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 4294f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor QualType getUnqualifiedTypeSlow() const; 4304f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 4313ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall friend class QualifierCollector; 4323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallpublic: 43348a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner QualType() {} 43425cf760b54d3b88633827501013bc51a29b28abaMike Stump 43548a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner QualType(const Type *Ptr, unsigned Quals) 4363ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Value(Ptr, Quals) {} 4373ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType(const ExtQuals *Ptr, unsigned Quals) 4383ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Value(Ptr, Quals) {} 4393ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 440c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor unsigned getLocalFastQualifiers() const { return Value.getInt(); } 441c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); } 4424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 4433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Retrieves a pointer to the underlying (unqualified) type. 4443ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// This should really return a const Type, but it's not worth 4453ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// changing all the users right now. 4463ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Type *getTypePtr() const { 447c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalNonFastQualifiers()) 4483ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return const_cast<Type*>(getExtQualsUnsafe()->getBaseType()); 4493ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return const_cast<Type*>(getTypePtrUnsafe()); 4503ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 45125cf760b54d3b88633827501013bc51a29b28abaMike Stump 45248a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 4534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static QualType getFromOpaquePtr(void *Ptr) { 4544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType T; 45548a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner T.Value.setFromOpaqueValue(Ptr); 4564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T; 4574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 45825cf760b54d3b88633827501013bc51a29b28abaMike Stump 4594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Type &operator*() const { 4604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return *getTypePtr(); 4614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 4624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 4634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Type *operator->() const { 4644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return getTypePtr(); 4654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 46625cf760b54d3b88633827501013bc51a29b28abaMike Stump 4677480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall bool isCanonical() const; 4684ea8425c9601895fa137f877bc784f75f20adac6John McCall bool isCanonicalAsParam() const; 4697480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall 4704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isNull - Return true if this QualType doesn't point to a type yet. 4714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isNull() const { 4723ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Value.getPointer().isNull(); 4734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 4744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 475c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has the 476c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// "const" qualifier set, without looking through typedefs that may have 477c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// added "const" at a different level. 478c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool isLocalConstQualified() const { 479c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Const); 4803ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 481c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 482c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this type is const-qualified. 4834f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor bool isConstQualified() const; 484c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 485c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has the 486c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// "restrict" qualifier set, without looking through typedefs that may have 487c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// added "restrict" at a different level. 488c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool isLocalRestrictQualified() const { 489c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Restrict); 490c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor } 491c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 492c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this type is restrict-qualified. 4934f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor bool isRestrictQualified() const; 494c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 495c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has the 496c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// "volatile" qualifier set, without looking through typedefs that may have 497c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// added "volatile" at a different level. 498c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool isLocalVolatileQualified() const { 499c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return (hasLocalNonFastQualifiers() && getExtQualsUnsafe()->hasVolatile()); 5004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 5013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 502c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this type is volatile-qualified. 5034f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor bool isVolatileQualified() const; 504c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 505c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has any 506c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// qualifiers, without looking through any typedefs that might add 507c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// qualifiers at a different level. 508c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool hasLocalQualifiers() const { 509c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return getLocalFastQualifiers() || hasLocalNonFastQualifiers(); 5103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 512c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this type has any qualifiers. 5134f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor bool hasQualifiers() const; 514c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 515c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has any 516c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType 517c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// instance. 518c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool hasLocalNonFastQualifiers() const { 519c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return Value.getPointer().is<const ExtQuals*>(); 5203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 522c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Retrieve the set of qualifiers local to this particular QualType 523c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// instance, not including any qualifiers acquired through typedefs or 524c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// other sugar. 525c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor Qualifiers getLocalQualifiers() const { 5263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Quals; 527c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalNonFastQualifiers()) 5283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Quals = getExtQualsUnsafe()->getQualifiers(); 529c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor Quals.addFastQualifiers(getLocalFastQualifiers()); 5303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Quals; 5313ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 533c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Retrieve the set of qualifiers applied to this type. 5344f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor Qualifiers getQualifiers() const; 535c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 536c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 537c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// local to this particular QualType instance, not including any qualifiers 538c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// acquired through typedefs or other sugar. 539c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor unsigned getLocalCVRQualifiers() const { 540c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor unsigned CVR = getLocalFastQualifiers(); 541c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (isLocalVolatileQualified()) 542c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor CVR |= Qualifiers::Volatile; 5433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return CVR; 5444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 545a7bbf567dac9dfd58f12c9ff14584d64104694f3Nuno Lopes 546c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 547c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// applied to this type. 5484f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor unsigned getCVRQualifiers() const; 5496d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth 5506d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 5516d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth /// applied to this type, looking through any number of unqualified array 5526d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth /// types to their element types' qualifiers. 5536d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned getCVRQualifiersThroughArrayTypes() const; 5546d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth 5550afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isConstant(ASTContext& Ctx) const { 5560afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall return QualType::isConstant(*this, Ctx); 5570afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall } 55825cf760b54d3b88633827501013bc51a29b28abaMike Stump 5593ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Don't promise in the API that anything besides 'const' can be 5603ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // easily added. 5613ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 5623ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// addConst - add the specified type qualifier to this QualType. 5633ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addConst() { 5643ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall addFastQualifiers(Qualifiers::Const); 5653ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5663ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType withConst() const { 5673ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return withFastQualifiers(Qualifiers::Const); 5683ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5693ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 5703ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addFastQualifiers(unsigned TQs) { 5713ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(TQs & ~Qualifiers::FastMask) 5723ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall && "non-fast qualifier bits set in mask!"); 5733ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Value.setInt(Value.getInt() | TQs); 5743ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5753ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 576c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor // FIXME: The remove* functions are semantically broken, because they might 577c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor // not remove a qualifier stored on a typedef. Most of the with* functions 578c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor // have the same problem. 5793ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeConst(); 5803ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeVolatile(); 5813ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeRestrict(); 5823ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeCVRQualifiers(unsigned Mask); 5833ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 5843ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeFastQualifiers() { Value.setInt(0); } 5853ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeFastQualifiers(unsigned Mask) { 5863ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers"); 5873ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Value.setInt(Value.getInt() & ~Mask); 5883ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5903ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Creates a type with the given qualifiers in addition to any 5913ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // qualifiers already on this type. 5923ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType withFastQualifiers(unsigned TQs) const { 5933ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType T = *this; 5943ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall T.addFastQualifiers(TQs); 5953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return T; 5963ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 59793eb82549eec82d75ce5dd3afbeeaf6fdb0e2a27Sanjiv Gupta 5983ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Creates a type with exactly the given fast qualifiers, removing 5993ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // any existing fast qualifiers. 6003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType withExactFastQualifiers(unsigned TQs) const { 6013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return withoutFastQualifiers().withFastQualifiers(TQs); 6024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 6043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Removes fast qualifiers, but leaves any extended qualifiers in place. 6053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType withoutFastQualifiers() const { 6063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType T = *this; 6073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall T.removeFastQualifiers(); 6083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return T; 609a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner } 6104b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis 611c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Return this type with all of the instance-specific qualifiers 612c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// removed, but without removing any qualifiers that may have been applied 613c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// through typedefs. 614c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); } 61525cf760b54d3b88633827501013bc51a29b28abaMike Stump 616c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Return the unqualified form of the given type, which might be 617c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// desugared to eliminate qualifiers introduced via typedefs. 6184f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor QualType getUnqualifiedType() const { 6194f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor QualType T = getLocalUnqualifiedType(); 6204f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor if (!T.hasQualifiers()) 6214f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return T; 6224f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 6234f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return getUnqualifiedTypeSlow(); 624c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor } 625c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 6263fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 6273fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 6283fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor QualType getNonReferenceType() const; 62925cf760b54d3b88633827501013bc51a29b28abaMike Stump 630835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 631835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 632835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 633835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 634835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 635835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// concrete. 6363ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// 6373ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Qualifiers are left in place. 6380afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType getDesugaredType() const { 6390afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall return QualType::getDesugaredType(*this); 6400afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall } 6416573cfd6fc32eab0b696cfc318bb21f4e3933f35Douglas Gregor 6424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// operator==/!= - Indicate whether the specified types and qualifiers are 6434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// identical. 644cfe6ae592450d8466b4d78b59ff4526266549a9aDouglas Gregor friend bool operator==(const QualType &LHS, const QualType &RHS) { 645cfe6ae592450d8466b4d78b59ff4526266549a9aDouglas Gregor return LHS.Value == RHS.Value; 6464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 647cfe6ae592450d8466b4d78b59ff4526266549a9aDouglas Gregor friend bool operator!=(const QualType &LHS, const QualType &RHS) { 648cfe6ae592450d8466b4d78b59ff4526266549a9aDouglas Gregor return LHS.Value != RHS.Value; 6494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6503bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor std::string getAsString() const; 6513bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor 6523bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor std::string getAsString(const PrintingPolicy &Policy) const { 6534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner std::string S; 6543bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor getAsStringInternal(S, Policy); 6554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return S; 6564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6577099c789f054f1e7480f498d60aa94b0326c285fChris Lattner void getAsStringInternal(std::string &Str, 6587099c789f054f1e7480f498d60aa94b0326c285fChris Lattner const PrintingPolicy &Policy) const; 65925cf760b54d3b88633827501013bc51a29b28abaMike Stump 660a55e321bd645398b514e246981c04a4889ee2472Chris Lattner void dump(const char *s) const; 661a55e321bd645398b514e246981c04a4889ee2472Chris Lattner void dump() const; 66225cf760b54d3b88633827501013bc51a29b28abaMike Stump 6639d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 6649d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 6659d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek } 6664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6672a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb /// getAddressSpace - Return the address space of this type. 6682a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb inline unsigned getAddressSpace() const; 66925cf760b54d3b88633827501013bc51a29b28abaMike Stump 670af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 6713ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall inline Qualifiers::GC getObjCGCAttr() const; 67285534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian 67385534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 67485534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian bool isObjCGCWeak() const { 6753ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return getObjCGCAttr() == Qualifiers::Weak; 67685534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian } 67785534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian 67885534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 67985534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian bool isObjCGCStrong() const { 6803ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return getObjCGCAttr() == Qualifiers::Strong; 68185534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian } 6821bb806498909a43a7829edb21c42606335d69694Mike Stump 6830afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCallprivate: 6840afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall // These methods are implemented in a separate translation unit; 6850afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall // "static"-ize them to avoid creating temporary QualTypes in the 6860afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall // caller. 6870afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall static bool isConstant(QualType T, ASTContext& Ctx); 6880afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall static QualType getDesugaredType(QualType T); 6894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 6904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner} // end clang. 6924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace llvm { 6944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 6954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// to a specific Type class. 6964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnertemplate<> struct simplify_type<const ::clang::QualType> { 6974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner typedef ::clang::Type* SimpleType; 6984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 6994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return Val.getTypePtr(); 7004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 7014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 7024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnertemplate<> struct simplify_type< ::clang::QualType> 7034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner : public simplify_type<const ::clang::QualType> {}; 70425cf760b54d3b88633827501013bc51a29b28abaMike Stump 705cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 706cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattnertemplate<> 707d776b2da9bd694c41f1506e152aeb35d1babeba6Chris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 708cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattnerpublic: 709cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 710cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner return P.getAsOpaquePtr(); 711cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner } 712cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 713cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner return clang::QualType::getFromOpaquePtr(P); 714cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner } 7153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Various qualifiers go in low bits. 716e41419144a0a01456f5426efcd9b919f68284527Chris Lattner enum { NumLowBitsAvailable = 0 }; 717cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner}; 71825cf760b54d3b88633827501013bc51a29b28abaMike Stump 71978f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek} // end namespace llvm 7204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 7214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace clang { 7224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 7234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Type - This is the base class of the type hierarchy. A central concept 7244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// with types is that each type always has a canonical type. A canonical type 7254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// is the type with any typedef names stripped out of it or the types it 7264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// references. For example, consider: 7274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// typedef int foo; 7294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// typedef foo* bar; 7304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'int *' 'foo *' 'bar' 7314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// There will be a Type object created for 'int'. Since int is canonical, its 7334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 7344fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 7354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// there is a PointerType that represents 'int*', which, like 'int', is 7364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 7374fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 7384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// is also 'int*'. 7394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Non-canonical types are useful for emitting diagnostics, without losing 7414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// information about typedefs being used. Canonical types are useful for type 7424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// comparisons (they allow by-pointer equality tests) and useful for reasoning 7434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// about whether something has a particular form (e.g. is a function type), 7444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// because they implicitly, recursively, strip all typedefs out of a type. 7454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Types, once created, are immutable. 7474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass Type { 7494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 7504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum TypeClass { 7514fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define TYPE(Class, Base) Class, 752d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall#define LAST_TYPE(Class) TypeLast = Class, 7534fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 7544fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#include "clang/AST/TypeNodes.def" 7554fa58905062efa6a12137b1983a1367220182a20Douglas Gregor TagFirst = Record, TagLast = Enum 7564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 757fd3d5fdac0d25464e1b9c36bc646965494d44f66Argiris Kirtzidis 7584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 759f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall Type(const Type&); // DO NOT IMPLEMENT. 760f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall void operator=(const Type&); // DO NOT IMPLEMENT. 761f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 7624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType CanonicalType; 7634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 7644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 765d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall unsigned TC : 8; 766d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall 767d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 7684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Note that this should stay at the end of the ivars for Type so that 7694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// subclasses can pack their bitfields into the same word. 770d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall bool Dependent : 1; 771949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 772949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor /// \brief Whether the linkage of this type is already known. 773949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor mutable bool LinkageKnown : 1; 774949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 775949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor /// \brief Linkage of this type. 776949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor mutable unsigned CachedLinkage : 2; 777949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 7784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 779949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor /// \brief Compute the linkage of this type. 780949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 781949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 782949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor enum { BitsRemainingInType = 20 }; 783f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 7847c6f0c755e48a2782bc0a0a4cfc63dc84e0f11d5Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 7857c6f0c755e48a2782bc0a0a4cfc63dc84e0f11d5Hartmut Kaiser Type *this_() { return this; } 7861b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 78735fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 788949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor TC(tc), Dependent(dependent), LinkageKnown(false), 789949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor CachedLinkage(NoLinkage) {} 7901b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual ~Type() {} 791db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek virtual void Destroy(ASTContext& C); 7924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; 79325cf760b54d3b88633827501013bc51a29b28abaMike Stump 7944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 79592803daaa6a40a3899c2e599bddc42732c2ce593Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 79625cf760b54d3b88633827501013bc51a29b28abaMike Stump 7977480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall bool isCanonicalUnqualified() const { 7987480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall return CanonicalType.getTypePtr() == this; 7997480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall } 8004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 80125cf760b54d3b88633827501013bc51a29b28abaMike Stump /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 8024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// object types, function types, and incomplete types. 80325cf760b54d3b88633827501013bc51a29b28abaMike Stump 80426ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// \brief Determines whether the type describes an object in memory. 80526ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// 80626ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// Note that this definition of object type corresponds to the C++ 80726ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// definition of object type, which includes incomplete types, as 80826ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// opposed to the C definition (which does not include incomplete 80926ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// types). 8104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isObjectType() const; 8114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 8124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isIncompleteType - Return true if this is an incomplete type. 8134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// A type that can describe objects, but which lacks information needed to 8144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// determine its size (e.g. void, or a fwd declared struct). Clients of this 81525cf760b54d3b88633827501013bc51a29b28abaMike Stump /// routine will need to determine if the size is actually required. 8164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isIncompleteType() const; 8179db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner 8189db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 8199db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner /// type, in other words, not a function type. 8209db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner bool isIncompleteOrObjectType() const { 8219db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner return !isFunctionType(); 8229db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner } 82339c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl 82439c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 82539c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl bool isPODType() const; 82639c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl 82775067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl /// isLiteralType - Return true if this is a literal type 82875067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl /// (C++0x [basic.types]p10) 82975067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl bool isLiteralType() const; 83075067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl 8315eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 8325eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff /// types that have a non-constant expression. This does not include "[]". 8335eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff bool isVariablyModifiedType() const; 83425cf760b54d3b88633827501013bc51a29b28abaMike Stump 8354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Helper methods to distinguish type categories. All type predicates 8362a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 837c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar 838522fb671290dd5462bfd819401768686fa53e925Tom Care /// isBuiltinType - returns true if the type is a builtin type. 839522fb671290dd5462bfd819401768686fa53e925Tom Care bool isBuiltinType() const; 840522fb671290dd5462bfd819401768686fa53e925Tom Care 841c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 842c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 84325cf760b54d3b88633827501013bc51a29b28abaMike Stump 8448888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 8458888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 8464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 8478d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isEnumeralType() const; 8488d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isBooleanType() const; 8498d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isCharType() const; 8501815b3bfc1382c88bee771bd158755b2426f0780Douglas Gregor bool isWideCharType() const; 851da86f093507a7733ae955d7511b88f8bf4f61752Douglas Gregor bool isAnyCharacterType() const; 8527fcbab0d9ed96afbdcc3dd4ad876bcbf452fd25fDouglas Gregor bool isIntegralType(ASTContext &Ctx) const; 853da86f093507a7733ae955d7511b88f8bf4f61752Douglas Gregor 85459327f06fa557d652e0560e6895c93db70ea5ec7Douglas Gregor /// \brief Determine whether this type is an integral or enumeration type. 85559327f06fa557d652e0560e6895c93db70ea5ec7Douglas Gregor bool isIntegralOrEnumerationType() const; 85659327f06fa557d652e0560e6895c93db70ea5ec7Douglas Gregor 8574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Floating point categories. 8584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 8594300121ffff80d4b23d17689930e2aa2a83086b9Steve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 8604300121ffff80d4b23d17689930e2aa2a83086b9Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 8614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isComplexType() const; // C99 6.2.5p11 (complex) 8623277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 8634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 8644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 8654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 866e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isVoidType() const; // C99 6.2.5p19 867e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isDerivedType() const; // C99 6.2.5p20 868e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 869e7ef500151147ba851db502fc4d36319f863db80Douglas Gregor bool isAggregateType() const; 87025cf760b54d3b88633827501013bc51a29b28abaMike Stump 871e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner // Type Predicates: Check to see if this type is structurally the specified 8722a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb // type, ignoring typedefs and qualifiers. 873e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isFunctionType() const; 874cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } 875cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } 8767931f4a186bc76b21dd4629ee74d64264a7fb8a2Chris Lattner bool isPointerType() const; 87779ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroff bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 8787aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff bool isBlockPointerType() const; 8795ca84bccd83982d3941d68dd88139ca43f6322a0Steve Naroff bool isVoidPointerType() const; 880f0c4a0a830c9154b1ae72e497c2ce586c10e9b71Chris Lattner bool isReferenceType() const; 881ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl bool isLValueReferenceType() const; 882ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl bool isRValueReferenceType() const; 883cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner bool isFunctionPointerType() const; 8847555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl bool isMemberPointerType() const; 8857555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl bool isMemberFunctionPointerType() const; 886e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isArrayType() const; 887a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isConstantArrayType() const; 888a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isIncompleteArrayType() const; 889a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isVariableArrayType() const; 8901b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool isDependentSizedArrayType() const; 891e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isRecordType() const; 89225cf760b54d3b88633827501013bc51a29b28abaMike Stump bool isClassType() const; 89325cf760b54d3b88633827501013bc51a29b28abaMike Stump bool isStructureType() const; 8946cb535784c071d1a662aeac8e548e8757dd1a969Douglas Gregor bool isStructureOrClassType() const; 89536e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff bool isUnionType() const; 896b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 897b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isVectorType() const; // GCC vector type. 898af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman bool isExtVectorType() const; // Extended vector type. 899c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 900329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // FIXME: change this to 'raw' interface type, so we can used 'interface' type 901329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // for the common case. 902f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCObjectType() const; // NSString or typeof(*(id)0) 903b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 904b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCQualifiedIdType() const; // id<foo> 90527bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff bool isObjCQualifiedClassType() const; // Class<foo> 906329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCIdType() const; // id 907329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCClassType() const; // Class 908a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian bool isObjCSelType() const; // Class 9097bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff bool isObjCBuiltinType() const; // 'id' or 'Class' 910dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 9115d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 9121b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 9131b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 91425cf760b54d3b88633827501013bc51a29b28abaMike Stump /// that its definition somehow depends on a template parameter 9151b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// (C++ [temp.dep.type]). 9161b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool isDependentType() const { return Dependent; } 91700fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor bool isOverloadableType() const; 918dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 919ec6d392c816684e9679a3d04f742fa3991f5fe1eDouglas Gregor /// \brief Determine wither this type is a C++ elaborated-type-specifier. 920ec6d392c816684e9679a3d04f742fa3991f5fe1eDouglas Gregor bool isElaboratedTypeSpecifier() const; 921ec6d392c816684e9679a3d04f742fa3991f5fe1eDouglas Gregor 922fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 923fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 924fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 9255d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl /// interface types, as well as nullptr_t. 926fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar bool hasPointerRepresentation() const; 927fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar 9287c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 9297c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 93025cf760b54d3b88633827501013bc51a29b28abaMike Stump bool hasObjCPointerRepresentation() const; 9317c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian 9321a7c1b12a61ed17f914c9d557dd6666e0253c133Douglas Gregor /// \brief Determine whether this type has a floating-point representation 9331a7c1b12a61ed17f914c9d557dd6666e0253c133Douglas Gregor /// of some sort, e.g., it is a floating-point type or a vector thereof. 9341a7c1b12a61ed17f914c9d557dd6666e0253c133Douglas Gregor bool hasFloatingRepresentation() const; 9351a7c1b12a61ed17f914c9d557dd6666e0253c133Douglas Gregor 936e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner // Type Checking Functions: Check to see if this type is structurally the 93735fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 93835fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner // the best type we can. 9395c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek const RecordType *getAsStructureType() const; 9401b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 941e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner const RecordType *getAsUnionType() const; 94236e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 943329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // The following is a convenience method that returns an ObjCObjectPointerType 944329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // for object declared using an interface. 945329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 946329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 947f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall const ObjCObjectType *getAsObjCQualifiedInterfaceType() const; 94890e18745436d0889e8bb7fba650263b38f05694eFariborz Jahanian const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 94925cf760b54d3b88633827501013bc51a29b28abaMike Stump 95095c54dfa43c5159d2854910c21cc03374238e94eDouglas Gregor /// \brief Retrieves the CXXRecordDecl that this type refers to, either 95195c54dfa43c5159d2854910c21cc03374238e94eDouglas Gregor /// because the type is a RecordType or because it is the injected-class-name 95295c54dfa43c5159d2854910c21cc03374238e94eDouglas Gregor /// type of a class template or class template partial specialization. 95395c54dfa43c5159d2854910c21cc03374238e94eDouglas Gregor CXXRecordDecl *getAsCXXRecordDecl() const; 95495c54dfa43c5159d2854910c21cc03374238e94eDouglas Gregor 955f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // Member-template getAs<specific type>'. This scheme will eventually 956f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // replace the specific getAsXXXX methods above. 957cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall // 958cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall // There are some specializations of this member template listed 959cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall // immediately following this class. 960f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek template <typename T> const T *getAs() const; 96125cf760b54d3b88633827501013bc51a29b28abaMike Stump 962a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 963a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// element type of the array, potentially with type qualifiers missing. 964a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// This method should never be used when type qualifiers are meaningful. 965a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 96625cf760b54d3b88633827501013bc51a29b28abaMike Stump 967898111463b64a26d55af56474ad8cca1fdb76268Steve Naroff /// getPointeeType - If this is a pointer, ObjC object pointer, or block 968898111463b64a26d55af56474ad8cca1fdb76268Steve Naroff /// pointer, this returns the respective pointee. 969329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff QualType getPointeeType() const; 97025cf760b54d3b88633827501013bc51a29b28abaMike Stump 9710afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// getUnqualifiedDesugaredType() - Return the specified type with 9720afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// any "sugar" removed from the type, removing any typedefs, 9730afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// typeofs, etc., as well as any qualifiers. 9740afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall const Type *getUnqualifiedDesugaredType() const; 97525cf760b54d3b88633827501013bc51a29b28abaMike Stump 9764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// More type predicates useful for type checking/promotion 9774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isPromotableIntegerType() const; // C99 6.3.1.1p2 9784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isSignedIntegerType - Return true if this is an integer type that is 980bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 981bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 982bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// integer element type. 9834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isSignedIntegerType() const; 9844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isUnsignedIntegerType - Return true if this is an integer type that is 986bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 987bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 988bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// element type. 9894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isUnsignedIntegerType() const; 990bbe686be29157b575e53fbed328613117b525f26Chris Lattner 9914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isConstantSizeType - Return true if this is not a variable sized type, 9920448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 9930448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner /// incomplete types. 99462f67fd7f670f1a8b222c6565b257c05e8e80faeEli Friedman bool isConstantSizeType() const; 995a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner 99684bca951282f362c439cc7993fcb4d145384e416Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 99784bca951282f362c439cc7993fcb4d145384e416Eli Friedman /// set of type specifiers. 99884bca951282f362c439cc7993fcb4d145384e416Eli Friedman bool isSpecifierType() const; 99984bca951282f362c439cc7993fcb4d145384e416Eli Friedman 1000b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor /// \brief Determine the linkage of this type. 1001949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor Linkage getLinkage() const; 1002949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1003949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor /// \brief Note that the linkage is no longer known. 1004949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor void ClearLinkageCache(); 1005949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1006949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor const char *getTypeClassName() const; 1007b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 1008cc392fc654e59b8d55df3901a82b193845ee44f4John McCall QualType getCanonicalTypeInternal() const { 1009cc392fc654e59b8d55df3901a82b193845ee44f4John McCall return CanonicalType; 1010cc392fc654e59b8d55df3901a82b193845ee44f4John McCall } 1011cc392fc654e59b8d55df3901a82b193845ee44f4John McCall CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h 1012a55e321bd645398b514e246981c04a4889ee2472Chris Lattner void dump() const; 10134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *) { return true; } 10144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 10154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1016cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCalltemplate <> inline const TypedefType *Type::getAs() const { 1017cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall return dyn_cast<TypedefType>(this); 1018cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall} 1019cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall 1020cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall// We can do canonical leaf types faster, because we don't have to 1021cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall// worry about preserving child type decoration. 1022cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall#define TYPE(Class, Base) 1023cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall#define LEAF_TYPE(Class) \ 1024cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCalltemplate <> inline const Class##Type *Type::getAs() const { \ 10253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return dyn_cast<Class##Type>(CanonicalType); \ 1026cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall} 1027cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall#include "clang/AST/TypeNodes.def" 1028cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall 1029cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall 10304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// BuiltinType - This class is used for builtin types like 'int'. Builtin 10314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types are always canonical and have a literal name field. 10324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass BuiltinType : public Type { 10334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 10344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum Kind { 10354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Void, 103625cf760b54d3b88633827501013bc51a29b28abaMike Stump 10374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Bool, // This is bool and/or _Bool. 10384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Char_U, // This is 'char' for targets where char is unsigned. 10394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UChar, // This is explicitly qualified unsigned char. 10402bcacb61cf94b71e5c87f29d517f8dc29fe3993eAlisdair Meredith Char16, // This is 'char16_t' for C++. 10412bcacb61cf94b71e5c87f29d517f8dc29fe3993eAlisdair Meredith Char32, // This is 'char32_t' for C++. 10424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UShort, 10434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UInt, 10444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ULong, 10454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ULongLong, 10466cc7e415d42291bf01e0295d9d6344e106613c48Chris Lattner UInt128, // __uint128_t 104725cf760b54d3b88633827501013bc51a29b28abaMike Stump 10484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Char_S, // This is 'char' for targets where char is signed. 10494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner SChar, // This is explicitly qualified signed char. 105085bd81edce4057156d7f49408147f07daa675096Argiris Kirtzidis WChar, // This is 'wchar_t' for C++. 10514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Short, 10524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Int, 10534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Long, 10544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner LongLong, 10556cc7e415d42291bf01e0295d9d6344e106613c48Chris Lattner Int128, // __int128_t 105625cf760b54d3b88633827501013bc51a29b28abaMike Stump 1057d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor Float, Double, LongDouble, 1058d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor 10595d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 10605d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl 10611b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Overload, // This represents the type of an overloaded function declaration. 10624a8498cc0f251e839912285112a014a5d1248648Anders Carlsson Dependent, // This represents the type of a type-dependent expression. 106325cf760b54d3b88633827501013bc51a29b28abaMike Stump 10647bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff UndeducedAuto, // In C++0x, this represents the type of an auto variable 10654a8498cc0f251e839912285112a014a5d1248648Anders Carlsson // that has not been deduced yet. 1066cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 1067cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// The primitive Objective C 'id' type. The type pointed to by the 1068cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// user-visible 'id' type. Only ever shows up in an AST as the base 1069cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// type of an ObjCObjectType. 1070cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall ObjCId, 1071cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 1072cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// The primitive Objective C 'Class' type. The type pointed to by the 1073cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// user-visible 'Class' type. Only ever shows up in an AST as the 1074cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// base type of an ObjCObjectType. 1075cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall ObjCClass, 1076cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 1077a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian ObjCSel // This represents the ObjC 'SEL' type. 10784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 10794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 10804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Kind TypeKind; 1081949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1082949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 1083949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1084949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 10854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 108625cf760b54d3b88633827501013bc51a29b28abaMike Stump BuiltinType(Kind K) 108725cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 10881b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor TypeKind(K) {} 108925cf760b54d3b88633827501013bc51a29b28abaMike Stump 10904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Kind getKind() const { return TypeKind; } 10917099c789f054f1e7480f498d60aa94b0326c285fChris Lattner const char *getName(const LangOptions &LO) const; 109225cf760b54d3b88633827501013bc51a29b28abaMike Stump 10930afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 10940afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 10950afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1096afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isInteger() const { 1097afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Bool && TypeKind <= Int128; 1098afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1099afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1100afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isSignedInteger() const { 1101afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Char_S && TypeKind <= Int128; 1102afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1103afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1104afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isUnsignedInteger() const { 1105afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Bool && TypeKind <= UInt128; 1106afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1107afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1108afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isFloatingPoint() const { 1109afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Float && TypeKind <= LongDouble; 1110afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1111afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 11124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 11134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const BuiltinType *) { return true; } 11144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 11154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 11174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types (_Complex float etc) as well as the GCC integer complex extensions. 11184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 11194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass ComplexType : public Type, public llvm::FoldingSetNode { 11204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ElementType; 11214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ComplexType(QualType Element, QualType CanonicalPtr) : 112225cf760b54d3b88633827501013bc51a29b28abaMike Stump Type(Complex, CanonicalPtr, Element->isDependentType()), 11231b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ElementType(Element) { 11244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1126949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1127949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 1128949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1129949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 11304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 11314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getElementType() const { return ElementType; } 113225cf760b54d3b88633827501013bc51a29b28abaMike Stump 11330afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 11340afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 11350afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 11364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 11374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getElementType()); 11384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 11404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Element.getAsOpaquePtr()); 11414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 114225cf760b54d3b88633827501013bc51a29b28abaMike Stump 11434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 11444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const ComplexType *) { return true; } 11454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 11464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1147554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 1148cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner/// 1149554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 1150cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner QualType PointeeType; 11514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner PointerType(QualType Pointee, QualType CanonicalPtr) : 1153554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 11544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1156949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1157949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 1158949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1159949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 11604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 116125cf760b54d3b88633827501013bc51a29b28abaMike Stump 1162554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 1163554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 11640afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 11650afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 11660afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 11674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 11684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getPointeeType()); 11694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 11714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Pointee.getAsOpaquePtr()); 11724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 117325cf760b54d3b88633827501013bc51a29b28abaMike Stump 11744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 11754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const PointerType *) { return true; } 11764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 11774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11787aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// BlockPointerType - pointer to a block type. 11797aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// This type is to represent types syntactically represented as 11807aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 11817aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// 11827aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 11837aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 11847aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 118525cf760b54d3b88633827501013bc51a29b28abaMike Stump Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 11861b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor PointeeType(Pointee) { 11877aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 11887aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff friend class ASTContext; // ASTContext creates these. 1189949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1190949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 1191949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1192949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 11937aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffpublic: 119425cf760b54d3b88633827501013bc51a29b28abaMike Stump 11957aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 11967aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff QualType getPointeeType() const { return PointeeType; } 11977aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 11980afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 11990afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 12000afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 12017aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 12027aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff Profile(ID, getPointeeType()); 12037aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 12047aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 12057aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 12067aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 120725cf760b54d3b88633827501013bc51a29b28abaMike Stump 120825cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 120925cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == BlockPointer; 12107aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 12117aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 12127aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff}; 12137aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 1214ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 12154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 1216554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 1217554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar QualType PointeeType; 1218554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 12194ea8425c9601895fa137f877bc784f75f20adac6John McCall /// True if the type was originally spelled with an lvalue sigil. 12204ea8425c9601895fa137f877bc784f75f20adac6John McCall /// This is never true of rvalue references but can also be false 12214ea8425c9601895fa137f877bc784f75f20adac6John McCall /// on lvalue references because of C++0x [dcl.typedef]p9, 12224ea8425c9601895fa137f877bc784f75f20adac6John McCall /// as follows: 12234ea8425c9601895fa137f877bc784f75f20adac6John McCall /// 12244ea8425c9601895fa137f877bc784f75f20adac6John McCall /// typedef int &ref; // lvalue, spelled lvalue 12254ea8425c9601895fa137f877bc784f75f20adac6John McCall /// typedef int &&rvref; // rvalue 12264ea8425c9601895fa137f877bc784f75f20adac6John McCall /// ref &a; // lvalue, inner ref, spelled lvalue 12274ea8425c9601895fa137f877bc784f75f20adac6John McCall /// ref &&a; // lvalue, inner ref 12284ea8425c9601895fa137f877bc784f75f20adac6John McCall /// rvref &a; // lvalue, inner ref, spelled lvalue 12294ea8425c9601895fa137f877bc784f75f20adac6John McCall /// rvref &&a; // rvalue, inner ref 12304ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue; 12314ea8425c9601895fa137f877bc784f75f20adac6John McCall 12324ea8425c9601895fa137f877bc784f75f20adac6John McCall /// True if the inner type is a reference type. This only happens 12334ea8425c9601895fa137f877bc784f75f20adac6John McCall /// in non-canonical forms. 12344ea8425c9601895fa137f877bc784f75f20adac6John McCall bool InnerRef; 12354ea8425c9601895fa137f877bc784f75f20adac6John McCall 1236ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlprotected: 12374ea8425c9601895fa137f877bc784f75f20adac6John McCall ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, 12384ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue) : 1239ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl Type(tc, CanonicalRef, Referencee->isDependentType()), 12404ea8425c9601895fa137f877bc784f75f20adac6John McCall PointeeType(Referencee), SpelledAsLValue(SpelledAsLValue), 12414ea8425c9601895fa137f877bc784f75f20adac6John McCall InnerRef(Referencee->isReferenceType()) { 12424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1243949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1244949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1245949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 12464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 12474ea8425c9601895fa137f877bc784f75f20adac6John McCall bool isSpelledAsLValue() const { return SpelledAsLValue; } 1248f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor bool isInnerRef() const { return InnerRef; } 1249f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor 12504ea8425c9601895fa137f877bc784f75f20adac6John McCall QualType getPointeeTypeAsWritten() const { return PointeeType; } 12514ea8425c9601895fa137f877bc784f75f20adac6John McCall QualType getPointeeType() const { 12524ea8425c9601895fa137f877bc784f75f20adac6John McCall // FIXME: this might strip inner qualifiers; okay? 12534ea8425c9601895fa137f877bc784f75f20adac6John McCall const ReferenceType *T = this; 12544ea8425c9601895fa137f877bc784f75f20adac6John McCall while (T->InnerRef) 12554ea8425c9601895fa137f877bc784f75f20adac6John McCall T = T->PointeeType->getAs<ReferenceType>(); 12564ea8425c9601895fa137f877bc784f75f20adac6John McCall return T->PointeeType; 12574ea8425c9601895fa137f877bc784f75f20adac6John McCall } 1258554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 12594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 12604ea8425c9601895fa137f877bc784f75f20adac6John McCall Profile(ID, PointeeType, SpelledAsLValue); 12614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 12624ea8425c9601895fa137f877bc784f75f20adac6John McCall static void Profile(llvm::FoldingSetNodeID &ID, 12634ea8425c9601895fa137f877bc784f75f20adac6John McCall QualType Referencee, 12644ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue) { 12654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Referencee.getAsOpaquePtr()); 12664ea8425c9601895fa137f877bc784f75f20adac6John McCall ID.AddBoolean(SpelledAsLValue); 12674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 12684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1269ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 1270ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == LValueReference || 1271ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl T->getTypeClass() == RValueReference; 1272ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 12734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const ReferenceType *) { return true; } 1274ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl}; 1275ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl 1276ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 1277ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// 1278ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlclass LValueReferenceType : public ReferenceType { 12794ea8425c9601895fa137f877bc784f75f20adac6John McCall LValueReferenceType(QualType Referencee, QualType CanonicalRef, 12804ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue) : 12814ea8425c9601895fa137f877bc784f75f20adac6John McCall ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue) 12824ea8425c9601895fa137f877bc784f75f20adac6John McCall {} 1283ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl friend class ASTContext; // ASTContext creates these 1284ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlpublic: 12850afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 12860afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 12870afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1288ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 1289ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == LValueReference; 1290ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 1291ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 1292ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl}; 1293ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl 1294ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 1295ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// 1296ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlclass RValueReferenceType : public ReferenceType { 1297ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 12984ea8425c9601895fa137f877bc784f75f20adac6John McCall ReferenceType(RValueReference, Referencee, CanonicalRef, false) { 1299ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 1300ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl friend class ASTContext; // ASTContext creates these 1301ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlpublic: 13020afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 13030afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 13040afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1305ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 1306ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == RValueReference; 1307ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 1308ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 13097555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl}; 13107555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 13117555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 13127555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl/// 13137555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 13147555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl QualType PointeeType; 13157555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 13167555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 13177555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *Class; 13187555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 13197555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 13207555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Type(MemberPointer, CanonicalPtr, 13217555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Cls->isDependentType() || Pointee->isDependentType()), 13227555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl PointeeType(Pointee), Class(Cls) { 13237555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 13247555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl friend class ASTContext; // ASTContext creates these. 1325949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1326949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 1327949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1328949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 13297555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlpublic: 13307555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 13317555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl QualType getPointeeType() const { return PointeeType; } 13327555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 13337555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *getClass() const { return Class; } 13347555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 13350afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 13360afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 13370afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 13387555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 13397555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Profile(ID, getPointeeType(), getClass()); 13407555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 13417555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 13427555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *Class) { 13437555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 13447555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl ID.AddPointer(Class); 13457555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 13467555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 13477555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static bool classof(const Type *T) { 13487555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return T->getTypeClass() == MemberPointer; 13497555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 13507555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static bool classof(const MemberPointerType *) { return true; } 13514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 13524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 13534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ArrayType - C99 6.7.5.2 - Array Declarators. 13544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 1355c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 13564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 13574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 13581b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 13591b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// with a star size (e.g. int X[*]). 13601b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// 'static' is only allowed on function parameters. 13614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum ArraySizeModifier { 13624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Normal, Static, Star 13634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 13644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 136583c13010359c33354c581acee65d0c986a75247eSteve Naroff /// ElementType - The element type of the array. 136683c13010359c33354c581acee65d0c986a75247eSteve Naroff QualType ElementType; 136725cf760b54d3b88633827501013bc51a29b28abaMike Stump 1368dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 136924c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 1370dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek unsigned SizeModifier : 2; 137125cf760b54d3b88633827501013bc51a29b28abaMike Stump 137224c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 137324c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// 'int X[static restrict 4]'. For function parameters only. 137424c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff unsigned IndexTypeQuals : 3; 137525cf760b54d3b88633827501013bc51a29b28abaMike Stump 137683c13010359c33354c581acee65d0c986a75247eSteve Naroffprotected: 13771b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // C++ [temp.dep.type]p1: 13781b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // A type is dependent if it is... 13791b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // - an array type constructed from any dependent type or whose 13801b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // size is specified by a constant expression that is 13811b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // value-dependent, 138224c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 138324c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArraySizeModifier sm, unsigned tq) 13841b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 13851b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 13861b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 138783c13010359c33354c581acee65d0c986a75247eSteve Naroff friend class ASTContext; // ASTContext creates these. 1388949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1389949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1390949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 139183c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic: 139283c13010359c33354c581acee65d0c986a75247eSteve Naroff QualType getElementType() const { return ElementType; } 1393dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek ArraySizeModifier getSizeModifier() const { 1394dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek return ArraySizeModifier(SizeModifier); 1395dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek } 13963ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers getIndexTypeQualifiers() const { 13973ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Qualifiers::fromCVRMask(IndexTypeQuals); 13983ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 13993ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getIndexTypeCVRQualifiers() const { return IndexTypeQuals; } 140025cf760b54d3b88633827501013bc51a29b28abaMike Stump 140183c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const Type *T) { 140283c13010359c33354c581acee65d0c986a75247eSteve Naroff return T->getTypeClass() == ConstantArray || 14038ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman T->getTypeClass() == VariableArray || 14041b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor T->getTypeClass() == IncompleteArray || 14051b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor T->getTypeClass() == DependentSizedArray; 140683c13010359c33354c581acee65d0c986a75247eSteve Naroff } 140783c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const ArrayType *) { return true; } 140883c13010359c33354c581acee65d0c986a75247eSteve Naroff}; 140983c13010359c33354c581acee65d0c986a75247eSteve Naroff 14101d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// ConstantArrayType - This class represents the canonical version of 14111d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// C arrays with a specified constant size. For example, the canonical 14121d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 14131d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// type is 'int' and the size is 404. 1414c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ConstantArrayType : public ArrayType { 141583c13010359c33354c581acee65d0c986a75247eSteve Naroff llvm::APInt Size; // Allows us to unique the type. 141625cf760b54d3b88633827501013bc51a29b28abaMike Stump 14173f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 141824c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArraySizeModifier sm, unsigned tq) 14191d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(ConstantArray, et, can, sm, tq), 14201d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor Size(size) {} 14211d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregorprotected: 14221d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor ConstantArrayType(TypeClass tc, QualType et, QualType can, 14231d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 14241d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(tc, et, can, sm, tq), Size(size) {} 142583c13010359c33354c581acee65d0c986a75247eSteve Naroff friend class ASTContext; // ASTContext creates these. 142683c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic: 1427a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner const llvm::APInt &getSize() const { return Size; } 14280afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 14290afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 14300afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 143183c13010359c33354c581acee65d0c986a75247eSteve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 143225cf760b54d3b88633827501013bc51a29b28abaMike Stump Profile(ID, getElementType(), getSize(), 14333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers()); 143483c13010359c33354c581acee65d0c986a75247eSteve Naroff } 143583c13010359c33354c581acee65d0c986a75247eSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 14363f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 14373f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner unsigned TypeQuals) { 143883c13010359c33354c581acee65d0c986a75247eSteve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 143983c13010359c33354c581acee65d0c986a75247eSteve Naroff ID.AddInteger(ArraySize.getZExtValue()); 14403f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(SizeMod); 14413f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(TypeQuals); 144283c13010359c33354c581acee65d0c986a75247eSteve Naroff } 14431d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor static bool classof(const Type *T) { 144432b25ab7d4b3355b804e367c90f5cd55f4c9187eJohn McCall return T->getTypeClass() == ConstantArray; 144583c13010359c33354c581acee65d0c986a75247eSteve Naroff } 144683c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const ConstantArrayType *) { return true; } 144783c13010359c33354c581acee65d0c986a75247eSteve Naroff}; 144883c13010359c33354c581acee65d0c986a75247eSteve Naroff 144956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 145056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 145156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// type is 'int' and the size is unspecified. 14528ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanclass IncompleteArrayType : public ArrayType { 14531d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor 14548ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman IncompleteArrayType(QualType et, QualType can, 14551d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor ArraySizeModifier sm, unsigned tq) 14568ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 14578ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman friend class ASTContext; // ASTContext creates these. 14588ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanpublic: 14590afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 14600afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 14610afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 146225cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 146325cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == IncompleteArray; 14648ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 14658ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 146625cf760b54d3b88633827501013bc51a29b28abaMike Stump 14678ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman friend class StmtIteratorBase; 146825cf760b54d3b88633827501013bc51a29b28abaMike Stump 14698ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 14703ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Profile(ID, getElementType(), getSizeModifier(), 14713ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getIndexTypeCVRQualifiers()); 14728ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 147325cf760b54d3b88633827501013bc51a29b28abaMike Stump 14743f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 14753f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 14768ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 14773f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(SizeMod); 14783f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(TypeQuals); 14798ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 14808ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman}; 14818ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 148256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 148356846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 148456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 148556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 148656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 148756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// should not be: two lexically equivalent variable array types could mean 148856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// different things, for example, these variables do not have the same type 148956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// dynamically: 149056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 149156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// void foo(int x) { 149256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// int Y[x]; 149356846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// ++x; 149456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// int Z[x]; 149556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// } 149656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 1497c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass VariableArrayType : public ArrayType { 149825cf760b54d3b88633827501013bc51a29b28abaMike Stump /// SizeExpr - An assignment expression. VLA's are only permitted within 149925cf760b54d3b88633827501013bc51a29b28abaMike Stump /// a function block. 1500718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek Stmt *SizeExpr; 15011d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor /// Brackets - The left and right array brackets. 15021d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange Brackets; 15031d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor 150424c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 15051d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor ArraySizeModifier sm, unsigned tq, 15061d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange brackets) 15071d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(VariableArray, et, can, sm, tq), 15081d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 15094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1510db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek virtual void Destroy(ASTContext& C); 1511db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek 15124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 151325cf760b54d3b88633827501013bc51a29b28abaMike Stump Expr *getSizeExpr() const { 1514718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek // We use C-style casts instead of cast<> here because we do not wish 1515718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 1516718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek return (Expr*) SizeExpr; 1517718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek } 15181d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange getBracketsRange() const { return Brackets; } 15191d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 15201d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 152125cf760b54d3b88633827501013bc51a29b28abaMike Stump 15220afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 15230afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 15240afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 152525cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 152625cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == VariableArray; 15274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 152883c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const VariableArrayType *) { return true; } 152925cf760b54d3b88633827501013bc51a29b28abaMike Stump 1530fce813e3159a67a57a03cdca45ac4e10d4cffac3Ted Kremenek friend class StmtIteratorBase; 153125cf760b54d3b88633827501013bc51a29b28abaMike Stump 15323793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 15337029ee3fdeee514a79eafb2508723d27c97fe158Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 15343793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek } 15354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 15364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 15371b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// DependentSizedArrayType - This type represents an array type in 15381b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// C++ whose size is a value-dependent expression. For example: 1539393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// 1540393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// \code 154125cf760b54d3b88633827501013bc51a29b28abaMike Stump/// template<typename T, int Size> 15421b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// class array { 15431b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// T data[Size]; 15441b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// }; 1545393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// \endcode 1546393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// 15471b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// For these types, we won't actually know what the array bound is 15481b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// until template instantiation occurs, at which point this will 15491b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 15501b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorclass DependentSizedArrayType : public ArrayType { 15517fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor ASTContext &Context; 155225cf760b54d3b88633827501013bc51a29b28abaMike Stump 1553393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// \brief An assignment expression that will instantiate to the 15541b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// size of the array. 1555393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// 1556393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// The expression itself might be NULL, in which case the array 1557393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// type will have its size deduced from an initializer. 15581b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Stmt *SizeExpr; 1559393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor 15601d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor /// Brackets - The left and right array brackets. 15611d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange Brackets; 156225cf760b54d3b88633827501013bc51a29b28abaMike Stump 156325cf760b54d3b88633827501013bc51a29b28abaMike Stump DependentSizedArrayType(ASTContext &Context, QualType et, QualType can, 15647fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor Expr *e, ArraySizeModifier sm, unsigned tq, 15651d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange brackets) 15661d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), 15677fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {} 15681b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor friend class ASTContext; // ASTContext creates these. 15691b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual void Destroy(ASTContext& C); 15701b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 15711b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorpublic: 157225cf760b54d3b88633827501013bc51a29b28abaMike Stump Expr *getSizeExpr() const { 15731b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // We use C-style casts instead of cast<> here because we do not wish 15741b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 15751b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return (Expr*) SizeExpr; 15761b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 15771d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange getBracketsRange() const { return Brackets; } 15781d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 15791d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 158025cf760b54d3b88633827501013bc51a29b28abaMike Stump 15810afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 15820afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 15830afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 158425cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 158525cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == DependentSizedArray; 15861b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 15871b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 158825cf760b54d3b88633827501013bc51a29b28abaMike Stump 15891b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor friend class StmtIteratorBase; 159025cf760b54d3b88633827501013bc51a29b28abaMike Stump 159125cf760b54d3b88633827501013bc51a29b28abaMike Stump 15921b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 159325cf760b54d3b88633827501013bc51a29b28abaMike Stump Profile(ID, Context, getElementType(), 15943ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); 15951b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 159625cf760b54d3b88633827501013bc51a29b28abaMike Stump 159725cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 159825cf760b54d3b88633827501013bc51a29b28abaMike Stump QualType ET, ArraySizeModifier SizeMod, 15997fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor unsigned TypeQuals, Expr *E); 16001b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor}; 16011b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 160268a7a6db3693e6df54a2198f3ee4e3f87e7f9ac0Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 16032a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// where either the type or size is dependent. For example: 16042a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// @code 16052a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// template<typename T, int Size> 16062a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// class vector { 16072a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 16082a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// } 16092a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// @endcode 16100c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { 16110c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor ASTContext &Context; 16122a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor Expr *SizeExpr; 16132a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor /// ElementType - The element type of the array. 16142a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor QualType ElementType; 16152a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor SourceLocation loc; 161625cf760b54d3b88633827501013bc51a29b28abaMike Stump 161725cf760b54d3b88633827501013bc51a29b28abaMike Stump DependentSizedExtVectorType(ASTContext &Context, QualType ElementType, 16180c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor QualType can, Expr *SizeExpr, SourceLocation loc) 161925cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type (DependentSizedExtVector, can, true), 162025cf760b54d3b88633827501013bc51a29b28abaMike Stump Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 16210c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor loc(loc) {} 16222a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor friend class ASTContext; 16232a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor virtual void Destroy(ASTContext& C); 16242a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor 16252a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregorpublic: 16260c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 16272a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor QualType getElementType() const { return ElementType; } 16282a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor SourceLocation getAttributeLoc() const { return loc; } 16292a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor 16300afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 16310afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 16320afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 163325cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 163425cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == DependentSizedExtVector; 16352a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor } 163625cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const DependentSizedExtVectorType *) { return true; } 16370c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor 16380c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 16390c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor Profile(ID, Context, getElementType(), getSizeExpr()); 16400c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor } 164125cf760b54d3b88633827501013bc51a29b28abaMike Stump 16420c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 16430c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor QualType ElementType, Expr *SizeExpr); 16442a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor}; 164525cf760b54d3b88633827501013bc51a29b28abaMike Stump 16462a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor 16474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// VectorType - GCC generic vector type. This type is created using 164825cf760b54d3b88633827501013bc51a29b28abaMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in 1649438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson/// bytes; or from an Altivec __vector or vector declaration. 1650438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson/// Since the constructor takes the number of vector elements, the 16514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// client is responsible for converting the size into the number of elements. 16524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass VectorType : public Type, public llvm::FoldingSetNode { 16539484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattnerpublic: 16549484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner enum AltiVecSpecific { 16559484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner NotAltiVec, // is not AltiVec vector 16569484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner AltiVec, // is AltiVec vector 16579484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner Pixel, // is AltiVec 'vector Pixel' 16589484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner Bool // is AltiVec 'vector bool ...' 16599484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner }; 16604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 16614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ElementType - The element type of the vector. 16624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ElementType; 166325cf760b54d3b88633827501013bc51a29b28abaMike Stump 16644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// NumElements - The number of elements in the vector. 16654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned NumElements; 166625cf760b54d3b88633827501013bc51a29b28abaMike Stump 16679484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner AltiVecSpecific AltiVecSpec; 1668438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson 1669438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson VectorType(QualType vecType, unsigned nElements, QualType canonType, 16709484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner AltiVecSpecific altiVecSpec) : 167125cf760b54d3b88633827501013bc51a29b28abaMike Stump Type(Vector, canonType, vecType->isDependentType()), 16729484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner ElementType(vecType), NumElements(nElements), AltiVecSpec(altiVecSpec) {} 167325cf760b54d3b88633827501013bc51a29b28abaMike Stump VectorType(TypeClass tc, QualType vecType, unsigned nElements, 16749484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner QualType canonType, AltiVecSpecific altiVecSpec) 167525cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 16769484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner NumElements(nElements), AltiVecSpec(altiVecSpec) {} 16774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1678949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1679949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1680949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 16814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 168225cf760b54d3b88633827501013bc51a29b28abaMike Stump 16834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getElementType() const { return ElementType; } 168425cf760b54d3b88633827501013bc51a29b28abaMike Stump unsigned getNumElements() const { return NumElements; } 16854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 16860afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 16870afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 16880afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 16899484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner AltiVecSpecific getAltiVecSpecific() const { return AltiVecSpec; } 16909484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner 16914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 16929484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner Profile(ID, getElementType(), getNumElements(), getTypeClass(), AltiVecSpec); 16934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 169425cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 1695438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson unsigned NumElements, TypeClass TypeClass, 16969484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner unsigned AltiVecSpec) { 16974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(ElementType.getAsOpaquePtr()); 16984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddInteger(NumElements); 16994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddInteger(TypeClass); 17009484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner ID.AddInteger(AltiVecSpec); 17014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1702b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 170325cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 170425cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 17054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 17064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const VectorType *) { return true; } 17074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 17084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1709af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// ExtVectorType - Extended vector type. This type is created using 1710af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1711af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 17126154214e20225a883a8a00226499534e9b514315Steve Naroff/// class enables syntactic extensions, like Vector Components for accessing 17136154214e20225a883a8a00226499534e9b514315Steve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1714af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemanclass ExtVectorType : public VectorType { 1715af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 17169484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner VectorType(ExtVector, vecType, nElements, canonType, NotAltiVec) {} 17174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 17184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 17199096b795541c783297fb19684a58c54d0fe823b8Chris Lattner static int getPointAccessorIdx(char c) { 17209096b795541c783297fb19684a58c54d0fe823b8Chris Lattner switch (c) { 17219096b795541c783297fb19684a58c54d0fe823b8Chris Lattner default: return -1; 17229096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'x': return 0; 17239096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'y': return 1; 17249096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'z': return 2; 17259096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'w': return 3; 17269096b795541c783297fb19684a58c54d0fe823b8Chris Lattner } 17271b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 17281486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman static int getNumericAccessorIdx(char c) { 17299096b795541c783297fb19684a58c54d0fe823b8Chris Lattner switch (c) { 17301486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman default: return -1; 17311486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '0': return 0; 17321486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '1': return 1; 17331486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '2': return 2; 17341486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '3': return 3; 17351486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '4': return 4; 17361486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '5': return 5; 17371486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '6': return 6; 17381486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '7': return 7; 17391486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '8': return 8; 17401486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '9': return 9; 1741e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'A': 17421486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'a': return 10; 1743e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'B': 17441486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'b': return 11; 1745e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'C': 17461486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'c': return 12; 1747e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'D': 17481486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'd': return 13; 1749e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'E': 17501486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'e': return 14; 1751e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'F': 17521486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'f': return 15; 17539096b795541c783297fb19684a58c54d0fe823b8Chris Lattner } 17541b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 175525cf760b54d3b88633827501013bc51a29b28abaMike Stump 175642158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner static int getAccessorIdx(char c) { 175742158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 17581486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman return getNumericAccessorIdx(c); 175942158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner } 176025cf760b54d3b88633827501013bc51a29b28abaMike Stump 17619096b795541c783297fb19684a58c54d0fe823b8Chris Lattner bool isAccessorWithinNumElements(char c) const { 176242158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner if (int idx = getAccessorIdx(c)+1) 17639096b795541c783297fb19684a58c54d0fe823b8Chris Lattner return unsigned(idx-1) < NumElements; 17649096b795541c783297fb19684a58c54d0fe823b8Chris Lattner return false; 17651b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 17660afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 17670afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 17680afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 176925cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 177025cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == ExtVector; 17714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1772af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman static bool classof(const ExtVectorType *) { return true; } 17734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 17744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 17754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 17764fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 17774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 17784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass FunctionType : public Type { 17796f52e3c5663a669ec61379e933e0fe7ad2f1a566Chris Lattner virtual void ANCHOR(); // Key function for FunctionType. 17806f52e3c5663a669ec61379e933e0fe7ad2f1a566Chris Lattner 17814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// SubClassData - This field is owned by the subclass, put here to pack 17824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// tightly with the ivars in Type. 17834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool SubClassData : 1; 17844b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis 17854fa58905062efa6a12137b1983a1367220182a20Douglas Gregor /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 17864b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// other bitfields. 17874fa58905062efa6a12137b1983a1367220182a20Douglas Gregor /// The qualifiers are part of FunctionProtoType because... 17884b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// 17894b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 17904b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// cv-qualifier-seq, [...], are part of the function type. 17914b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// 17924b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned TypeQuals : 3; 17931bb806498909a43a7829edb21c42606335d69694Mike Stump 17941bb806498909a43a7829edb21c42606335d69694Mike Stump /// NoReturn - Indicates if the function type is attribute noreturn. 17951bb806498909a43a7829edb21c42606335d69694Mike Stump unsigned NoReturn : 1; 179625cf760b54d3b88633827501013bc51a29b28abaMike Stump 17972ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola /// RegParm - How many arguments to pass inreg. 17982ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola unsigned RegParm : 3; 17992ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola 180031cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor /// CallConv - The calling convention used by the function. 180101890a8487ae3330abc501b455e2092545d54775Douglas Gregor unsigned CallConv : 3; 180231cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor 18034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // The type returned by the function. 18044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ResultType; 1805433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1806433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola public: 1807433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // This class is used for passing arround the information needed to 1808433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // construct a call. It is not actually used for storage, just for 1809433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // factoring together common arguments. 18102ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // If you add a field (say Foo), other than the obvious places (both, constructors, 18112ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // compile failures), what you need to update is 18122ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * Operetor== 18132ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * getFoo 18142ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * withFoo 18152ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * functionType. Add Foo, getFoo. 18162ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * ASTContext::getFooType 18172ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * ASTContext::mergeFunctionTypes 18182ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * FunctionNoProtoType::Profile 18192ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * FunctionProtoType::Profile 18202ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * TypePrinter::PrintFunctionProto 18212ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * PCH read and write 18222ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * Codegen 18232ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola 1824433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola class ExtInfo { 1825433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola public: 1826433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // Constructor with no defaults. Use this when you know that you 1827433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // have all the elements (when reading a PCH file for example). 18282ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola ExtInfo(bool noReturn, unsigned regParm, CallingConv cc) : 18292ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola NoReturn(noReturn), RegParm(regParm), CC(cc) {} 1830433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1831433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // Constructor with all defaults. Use when for example creating a 1832433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // function know to use defaults. 18332ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola ExtInfo() : NoReturn(false), RegParm(0), CC(CC_Default) {} 1834433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1835433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola bool getNoReturn() const { return NoReturn; } 18362ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola unsigned getRegParm() const { return RegParm; } 1837433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola CallingConv getCC() const { return CC; } 1838433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1839433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola bool operator==(const ExtInfo &Other) const { 1840433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola return getNoReturn() == Other.getNoReturn() && 18412ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola getRegParm() == Other.getRegParm() && 1842433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola getCC() == Other.getCC(); 1843433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola } 1844433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola bool operator!=(const ExtInfo &Other) const { 1845433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola return !(*this == Other); 1846433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola } 1847433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1848433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // Note that we don't have setters. That is by design, use 1849433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // the following with methods instead of mutating these objects. 1850433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1851433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola ExtInfo withNoReturn(bool noReturn) const { 18522ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola return ExtInfo(noReturn, getRegParm(), getCC()); 18532ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola } 18542ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola 18552ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola ExtInfo withRegParm(unsigned RegParm) const { 18562ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola return ExtInfo(getNoReturn(), RegParm, getCC()); 1857433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola } 1858433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1859433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola ExtInfo withCallingConv(CallingConv cc) const { 18602ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola return ExtInfo(getNoReturn(), getRegParm(), cc); 1861433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola } 1862433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1863433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola private: 1864433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // True if we have __attribute__((noreturn)) 1865433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola bool NoReturn; 18662ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // The value passed to __attribute__((regparm(x))) 18672ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola unsigned RegParm; 1868433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // The calling convention as specified via 186901890a8487ae3330abc501b455e2092545d54775Douglas Gregor // __attribute__((cdecl|stdcall|fastcall|thiscall)) 1870433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola CallingConv CC; 1871433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola }; 1872433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 18734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 18744b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 18751bb806498909a43a7829edb21c42606335d69694Mike Stump unsigned typeQuals, QualType Canonical, bool Dependent, 1876433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola const ExtInfo &Info) 18771b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, Canonical, Dependent), 1878433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola SubClassData(SubclassInfo), TypeQuals(typeQuals), 1879433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola NoReturn(Info.getNoReturn()), 18802ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola RegParm(Info.getRegParm()), CallConv(Info.getCC()), ResultType(res) {} 18814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool getSubClassData() const { return SubClassData; } 18824b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned getTypeQuals() const { return TypeQuals; } 18834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 188425cf760b54d3b88633827501013bc51a29b28abaMike Stump 18854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getResultType() const { return ResultType; } 18862ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola unsigned getRegParmType() const { return RegParm; } 18871bb806498909a43a7829edb21c42606335d69694Mike Stump bool getNoReturnAttr() const { return NoReturn; } 188831cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CallingConv getCallConv() const { return (CallingConv)CallConv; } 1889433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola ExtInfo getExtInfo() const { 18902ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola return ExtInfo(NoReturn, RegParm, (CallingConv)CallConv); 1891433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola } 18924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1893ad760b38613b3f7f1024b011f6109bed1487b32eJohn McCall static llvm::StringRef getNameForCallConv(CallingConv CC); 1894ad760b38613b3f7f1024b011f6109bed1487b32eJohn McCall 18954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 18964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionNoProto || 18974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner T->getTypeClass() == FunctionProto; 18984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 18994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const FunctionType *) { return true; } 19004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 19014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 19024fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 19034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// no information available about its arguments. 19044fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 19051bb806498909a43a7829edb21c42606335d69694Mike Stump FunctionNoProtoType(QualType Result, QualType Canonical, 1906433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola const ExtInfo &Info) 190725cf760b54d3b88633827501013bc51a29b28abaMike Stump : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 1908433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola /*Dependent=*/false, Info) {} 19094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1910949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1911949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 1912949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1913949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 19144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 19154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // No additional state past what FunctionType provides. 191625cf760b54d3b88633827501013bc51a29b28abaMike Stump 19170afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 19180afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 19190afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 19204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 1921433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola Profile(ID, getResultType(), getExtInfo()); 19224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 19231bb806498909a43a7829edb21c42606335d69694Mike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 1924433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola const ExtInfo &Info) { 1925433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola ID.AddInteger(Info.getCC()); 19262ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola ID.AddInteger(Info.getRegParm()); 1927433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola ID.AddInteger(Info.getNoReturn()); 19284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(ResultType.getAsOpaquePtr()); 19294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 193025cf760b54d3b88633827501013bc51a29b28abaMike Stump 19314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 19324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionNoProto; 19334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 19344fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 19354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 19364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 19374fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 19384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 19392767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 19402767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl/// exception specification, but this specification is not part of the canonical 19412767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl/// type. 19424fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 19431b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 19441b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// types within the arguments passed in. 19451b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 19461b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 19471b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor if (ArgArray[Idx]->isDependentType()) 1948f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman return true; 19491b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 19501b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return false; 19511b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 19521b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 19534fa58905062efa6a12137b1983a1367220182a20Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 19542767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool isVariadic, unsigned typeQuals, bool hasExs, 19552767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasAnyExs, const QualType *ExArray, 1956433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola unsigned numExs, QualType Canonical, 1957433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola const ExtInfo &Info) 19581b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 195925cf760b54d3b88633827501013bc51a29b28abaMike Stump (Result->isDependentType() || 1960433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola hasAnyDependentType(ArgArray, numArgs)), 1961433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola Info), 19622767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 19632767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl AnyExceptionSpec(hasAnyExs) { 19644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // Fill in the trailing argument array. 19652767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 19664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner for (unsigned i = 0; i != numArgs; ++i) 19674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ArgInfo[i] = ArgArray[i]; 19682767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl // Fill in the exception array. 19692767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl QualType *Ex = ArgInfo + numArgs; 19702767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl for (unsigned i = 0; i != numExs; ++i) 19712767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl Ex[i] = ExArray[i]; 19724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 19732767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 19744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// NumArgs - The number of arguments this function has, not counting '...'. 19752767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl unsigned NumArgs : 20; 19762767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 19772767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 19782767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl unsigned NumExceptions : 10; 19792767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 19802767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// HasExceptionSpec - Whether this function has an exception spec at all. 19812767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool HasExceptionSpec : 1; 19822767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 19832767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// AnyExceptionSpec - Whether this function has a throw(...) spec. 19842767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool AnyExceptionSpec : 1; 19852767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 19864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 19874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// holds the argument types. 19882767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 19892767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 19902767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// holds the exception types. 19912767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 19924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1993db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek 1994949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 1995949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1996949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 19974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 19984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned getNumArgs() const { return NumArgs; } 19994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getArgType(unsigned i) const { 20004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner assert(i < NumArgs && "Invalid argument number!"); 20014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return arg_type_begin()[i]; 20024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 20032767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20042767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasExceptionSpec() const { return HasExceptionSpec; } 20052767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 20062767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 20072767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl QualType getExceptionType(unsigned i) const { 20082767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 20092767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl return exception_begin()[i]; 20102767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl } 201125cf760b54d3b88633827501013bc51a29b28abaMike Stump bool hasEmptyExceptionSpec() const { 201225cf760b54d3b88633827501013bc51a29b28abaMike Stump return hasExceptionSpec() && !hasAnyExceptionSpec() && 2013ac5e9f9de0959d5b1d390dc9bdad2d6f3d77c5cbAnders Carlsson getNumExceptions() == 0; 201411269048f03d91e991150c429dc874ae3999acb0Anders Carlsson } 20152767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isVariadic() const { return getSubClassData(); } 20174b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 201825cf760b54d3b88633827501013bc51a29b28abaMike Stump 20194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner typedef const QualType *arg_type_iterator; 20204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator arg_type_begin() const { 20214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return reinterpret_cast<const QualType *>(this+1); 20224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 20234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 20242767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20252767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl typedef const QualType *exception_iterator; 20262767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl exception_iterator exception_begin() const { 20272767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl // exceptions begin where arguments end 20282767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl return arg_type_end(); 20292767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl } 20302767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl exception_iterator exception_end() const { 20312767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl return exception_begin() + NumExceptions; 20322767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl } 20332767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20340afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 20350afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 20360afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 20374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 20384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionProto; 20394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 20404fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 20412767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID); 20434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 20444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 20452767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool isVariadic, unsigned TypeQuals, 20462767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasExceptionSpec, bool anyExceptionSpec, 20471bb806498909a43a7829edb21c42606335d69694Mike Stump unsigned NumExceptions, exception_iterator Exs, 2048433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola const ExtInfo &ExtInfo); 20494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 20504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 20514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2052caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// \brief Represents the dependent type named by a dependently-scoped 2053caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// typename using declaration, e.g. 2054caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// using typename Base<T>::foo; 2055caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// Template instantiation turns these into the underlying type. 2056caf383ae337966d67380b6b161fab17ec2b53d04John McCallclass UnresolvedUsingType : public Type { 2057caf383ae337966d67380b6b161fab17ec2b53d04John McCall UnresolvedUsingTypenameDecl *Decl; 2058caf383ae337966d67380b6b161fab17ec2b53d04John McCall 2059d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) 2060d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall : Type(UnresolvedUsing, QualType(), true), 2061d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {} 2062caf383ae337966d67380b6b161fab17ec2b53d04John McCall friend class ASTContext; // ASTContext creates these. 2063caf383ae337966d67380b6b161fab17ec2b53d04John McCallpublic: 2064caf383ae337966d67380b6b161fab17ec2b53d04John McCall 2065caf383ae337966d67380b6b161fab17ec2b53d04John McCall UnresolvedUsingTypenameDecl *getDecl() const { return Decl; } 2066caf383ae337966d67380b6b161fab17ec2b53d04John McCall 2067caf383ae337966d67380b6b161fab17ec2b53d04John McCall bool isSugared() const { return false; } 2068caf383ae337966d67380b6b161fab17ec2b53d04John McCall QualType desugar() const { return QualType(this, 0); } 2069caf383ae337966d67380b6b161fab17ec2b53d04John McCall 2070caf383ae337966d67380b6b161fab17ec2b53d04John McCall static bool classof(const Type *T) { 2071caf383ae337966d67380b6b161fab17ec2b53d04John McCall return T->getTypeClass() == UnresolvedUsing; 2072caf383ae337966d67380b6b161fab17ec2b53d04John McCall } 2073caf383ae337966d67380b6b161fab17ec2b53d04John McCall static bool classof(const UnresolvedUsingType *) { return true; } 2074caf383ae337966d67380b6b161fab17ec2b53d04John McCall 2075caf383ae337966d67380b6b161fab17ec2b53d04John McCall void Profile(llvm::FoldingSetNodeID &ID) { 2076caf383ae337966d67380b6b161fab17ec2b53d04John McCall return Profile(ID, Decl); 2077caf383ae337966d67380b6b161fab17ec2b53d04John McCall } 2078caf383ae337966d67380b6b161fab17ec2b53d04John McCall static void Profile(llvm::FoldingSetNodeID &ID, 2079caf383ae337966d67380b6b161fab17ec2b53d04John McCall UnresolvedUsingTypenameDecl *D) { 2080caf383ae337966d67380b6b161fab17ec2b53d04John McCall ID.AddPointer(D); 2081caf383ae337966d67380b6b161fab17ec2b53d04John McCall } 2082caf383ae337966d67380b6b161fab17ec2b53d04John McCall}; 2083caf383ae337966d67380b6b161fab17ec2b53d04John McCall 2084caf383ae337966d67380b6b161fab17ec2b53d04John McCall 20854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TypedefType : public Type { 20864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner TypedefDecl *Decl; 2087e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanianprotected: 2088d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall TypedefType(TypeClass tc, const TypedefDecl *D, QualType can) 2089d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall : Type(tc, can, can->isDependentType()), 2090d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall Decl(const_cast<TypedefDecl*>(D)) { 20914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner assert(!isa<TypedefType>(can) && "Invalid canonical type"); 20924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 20934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 20944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 209525cf760b54d3b88633827501013bc51a29b28abaMike Stump 20964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner TypedefDecl *getDecl() const { return Decl; } 209725cf760b54d3b88633827501013bc51a29b28abaMike Stump 20984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 2099a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 21004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// sum of the type qualifiers, so if you have: 21014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// typedef const int A; 21024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// typedef volatile A B; 21034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// looking through the typedefs for B will give you "const volatile A". 21044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType LookThroughTypedefs() const; 210525cf760b54d3b88633827501013bc51a29b28abaMike Stump 21060afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 21070afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const; 21080afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 21094fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 21104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const TypedefType *) { return true; } 21114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 21124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 21134fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// TypeOfExprType (GCC extension). 21144fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass TypeOfExprType : public Type { 21157cbb14653934a298c09002b87704dc6531261771Steve Naroff Expr *TOExpr; 211625cf760b54d3b88633827501013bc51a29b28abaMike Stump 211763d22fa6071690209b339451e4939de120a45e70Douglas Gregorprotected: 2118d1c0b682af81784cb991a5479097e795b5868bc4Douglas Gregor TypeOfExprType(Expr *E, QualType can = QualType()); 21197cbb14653934a298c09002b87704dc6531261771Steve Naroff friend class ASTContext; // ASTContext creates these. 21207cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic: 21217cbb14653934a298c09002b87704dc6531261771Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 212225cf760b54d3b88633827501013bc51a29b28abaMike Stump 21230afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 21240afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const; 21250afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 21260afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 21270afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 21280afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 21294fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 21304fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 21317cbb14653934a298c09002b87704dc6531261771Steve Naroff}; 21327cbb14653934a298c09002b87704dc6531261771Steve Naroff 213327dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// \brief Internal representation of canonical, dependent 213425cf760b54d3b88633827501013bc51a29b28abaMike Stump/// typeof(expr) types. 213527dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// 213627dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// This class is used internally by the ASTContext to manage 213727dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// canonical, dependent types, only. Clients will only see instances 213827dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// of this class via TypeOfExprType nodes. 213925cf760b54d3b88633827501013bc51a29b28abaMike Stumpclass DependentTypeOfExprType 214063d22fa6071690209b339451e4939de120a45e70Douglas Gregor : public TypeOfExprType, public llvm::FoldingSetNode { 214163d22fa6071690209b339451e4939de120a45e70Douglas Gregor ASTContext &Context; 214225cf760b54d3b88633827501013bc51a29b28abaMike Stump 214363d22fa6071690209b339451e4939de120a45e70Douglas Gregorpublic: 214425cf760b54d3b88633827501013bc51a29b28abaMike Stump DependentTypeOfExprType(ASTContext &Context, Expr *E) 214563d22fa6071690209b339451e4939de120a45e70Douglas Gregor : TypeOfExprType(E), Context(Context) { } 214625cf760b54d3b88633827501013bc51a29b28abaMike Stump 21470afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 21480afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 21490afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 215063d22fa6071690209b339451e4939de120a45e70Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 215163d22fa6071690209b339451e4939de120a45e70Douglas Gregor Profile(ID, Context, getUnderlyingExpr()); 215263d22fa6071690209b339451e4939de120a45e70Douglas Gregor } 215325cf760b54d3b88633827501013bc51a29b28abaMike Stump 215463d22fa6071690209b339451e4939de120a45e70Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 215563d22fa6071690209b339451e4939de120a45e70Douglas Gregor Expr *E); 215663d22fa6071690209b339451e4939de120a45e70Douglas Gregor}; 215725cf760b54d3b88633827501013bc51a29b28abaMike Stump 21587cbb14653934a298c09002b87704dc6531261771Steve Naroff/// TypeOfType (GCC extension). 21597cbb14653934a298c09002b87704dc6531261771Steve Naroffclass TypeOfType : public Type { 21607cbb14653934a298c09002b87704dc6531261771Steve Naroff QualType TOType; 216125cf760b54d3b88633827501013bc51a29b28abaMike Stump TypeOfType(QualType T, QualType can) 21624fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : Type(TypeOf, can, T->isDependentType()), TOType(T) { 21637cbb14653934a298c09002b87704dc6531261771Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 21647cbb14653934a298c09002b87704dc6531261771Steve Naroff } 21657cbb14653934a298c09002b87704dc6531261771Steve Naroff friend class ASTContext; // ASTContext creates these. 21667cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic: 21677cbb14653934a298c09002b87704dc6531261771Steve Naroff QualType getUnderlyingType() const { return TOType; } 216825cf760b54d3b88633827501013bc51a29b28abaMike Stump 21690afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 21700afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getUnderlyingType(); } 21710afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 21720afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 21730afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 21740afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 21754fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 21767cbb14653934a298c09002b87704dc6531261771Steve Naroff static bool classof(const TypeOfType *) { return true; } 21777cbb14653934a298c09002b87704dc6531261771Steve Naroff}; 21784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 217993ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson/// DecltypeType (C++0x) 218093ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlssonclass DecltypeType : public Type { 218193ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson Expr *E; 218225cf760b54d3b88633827501013bc51a29b28abaMike Stump 218342f394e67047624dcc15d22239f615885ad712acAnders Carlsson // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 218442f394e67047624dcc15d22239f615885ad712acAnders Carlsson // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 218542f394e67047624dcc15d22239f615885ad712acAnders Carlsson // from it. 218642f394e67047624dcc15d22239f615885ad712acAnders Carlsson QualType UnderlyingType; 218725cf760b54d3b88633827501013bc51a29b28abaMike Stump 2188d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregorprotected: 218942f394e67047624dcc15d22239f615885ad712acAnders Carlsson DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 219093ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson friend class ASTContext; // ASTContext creates these. 219193ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlssonpublic: 219293ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson Expr *getUnderlyingExpr() const { return E; } 219342f394e67047624dcc15d22239f615885ad712acAnders Carlsson QualType getUnderlyingType() const { return UnderlyingType; } 219442f394e67047624dcc15d22239f615885ad712acAnders Carlsson 21950afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 21960afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getUnderlyingType(); } 21970afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 21980afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 21990afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return !isDependentType(); } 22000afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 220193ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 220293ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson static bool classof(const DecltypeType *) { return true; } 220393ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson}; 220425cf760b54d3b88633827501013bc51a29b28abaMike Stump 220527dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// \brief Internal representation of canonical, dependent 220627dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// decltype(expr) types. 220727dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// 220827dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// This class is used internally by the ASTContext to manage 220927dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// canonical, dependent types, only. Clients will only see instances 221027dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// of this class via DecltypeType nodes. 2211d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { 2212d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor ASTContext &Context; 221325cf760b54d3b88633827501013bc51a29b28abaMike Stump 2214d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregorpublic: 2215d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor DependentDecltypeType(ASTContext &Context, Expr *E); 221625cf760b54d3b88633827501013bc51a29b28abaMike Stump 22170afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 22180afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 22190afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2220d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2221d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor Profile(ID, Context, getUnderlyingExpr()); 2222d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor } 222325cf760b54d3b88633827501013bc51a29b28abaMike Stump 2224d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 222525cf760b54d3b88633827501013bc51a29b28abaMike Stump Expr *E); 2226d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor}; 222725cf760b54d3b88633827501013bc51a29b28abaMike Stump 22284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TagType : public Type { 222998b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// Stores the TagDecl associated with this type. The decl will 223098b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// point to the TagDecl that actually defines the entity (or is a 223198b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// definition in progress), if there is such a definition. The 223298b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// single-bit value will be non-zero when this tag is in the 223398b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// process of being defined. 22349c7825b737617339724d43bd04960852271f08e2Douglas Gregor mutable llvm::PointerIntPair<TagDecl *, 1> decl; 223546a837c7ced306c55d1686cea5f77cb7a2f3b908Ted Kremenek friend class ASTContext; 223698b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor friend class TagDecl; 22371d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor 22381d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregorprotected: 2239d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall TagType(TypeClass TC, const TagDecl *D, QualType can); 22401d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor 2241949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 2242949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 224325cf760b54d3b88633827501013bc51a29b28abaMike Stumppublic: 224498b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor TagDecl *getDecl() const { return decl.getPointer(); } 224525cf760b54d3b88633827501013bc51a29b28abaMike Stump 224698b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// @brief Determines whether this type is in the process of being 224725cf760b54d3b88633827501013bc51a29b28abaMike Stump /// defined. 224898b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor bool isBeingDefined() const { return decl.getInt(); } 22493ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setBeingDefined(bool Def) const { decl.setInt(Def? 1 : 0); } 225098b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor 225125cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 22524fa58905062efa6a12137b1983a1367220182a20Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 22534fa58905062efa6a12137b1983a1367220182a20Douglas Gregor } 22544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const TagType *) { return true; } 22554fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const RecordType *) { return true; } 22564fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const EnumType *) { return true; } 22574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 22584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 22591baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 22601baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of structs/unions/classes. 22611baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass RecordType : public TagType { 2262ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidisprotected: 2263d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall explicit RecordType(const RecordDecl *D) 2264d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { } 22654fa58905062efa6a12137b1983a1367220182a20Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 2266d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { } 22671d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor friend class ASTContext; // ASTContext creates these. 22681baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic: 226925cf760b54d3b88633827501013bc51a29b28abaMike Stump 22701baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner RecordDecl *getDecl() const { 22711baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 22721baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner } 227325cf760b54d3b88633827501013bc51a29b28abaMike Stump 227425cf760b54d3b88633827501013bc51a29b28abaMike Stump // FIXME: This predicate is a helper to QualType/Type. It needs to 22751baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // recursively check all fields for const-ness. If any field is declared 227625cf760b54d3b88633827501013bc51a29b28abaMike Stump // const, it needs to return false. 22771baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner bool hasConstFields() const { return false; } 22781baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 22791baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 22801baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // the same address space, and return that. 22811baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner unsigned getAddressSpace() const { return 0; } 228225cf760b54d3b88633827501013bc51a29b28abaMike Stump 22830afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 22840afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 22850afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2286eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const TagType *T); 2287eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const Type *T) { 2288eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 2289eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner } 22901baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner static bool classof(const RecordType *) { return true; } 22911baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner}; 22921baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 22931baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 22941baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of enums. 22951baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass EnumType : public TagType { 2296d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall explicit EnumType(const EnumDecl *D) 2297d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { } 22981d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor friend class ASTContext; // ASTContext creates these. 22991baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic: 230025cf760b54d3b88633827501013bc51a29b28abaMike Stump 23011baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner EnumDecl *getDecl() const { 23021baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 23031baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner } 230425cf760b54d3b88633827501013bc51a29b28abaMike Stump 23050afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 23060afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 23070afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2308eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const TagType *T); 2309eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const Type *T) { 2310eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 2311eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner } 23121baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner static bool classof(const EnumType *) { return true; } 23131baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner}; 23141baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 2315a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 231625560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor unsigned Depth : 15; 231725560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor unsigned Index : 16; 231825560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor unsigned ParameterPack : 1; 231925560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor IdentifierInfo *Name; 2320dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 232125560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 232225560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor QualType Canon) 2323a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 232425560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor Depth(D), Index(I), ParameterPack(PP), Name(N) { } 2325dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 232625cf760b54d3b88633827501013bc51a29b28abaMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP) 232725560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 232825560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor Depth(D), Index(I), ParameterPack(PP), Name(0) { } 2329dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 2330a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor friend class ASTContext; // ASTContext creates these 2331dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 2332a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregorpublic: 233325560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor unsigned getDepth() const { return Depth; } 233425560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor unsigned getIndex() const { return Index; } 233525560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor bool isParameterPack() const { return ParameterPack; } 233625560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor IdentifierInfo *getName() const { return Name; } 233725cf760b54d3b88633827501013bc51a29b28abaMike Stump 23380afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 23390afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 23400afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2341a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 234225560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor Profile(ID, Depth, Index, ParameterPack, Name); 2343a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor } 2344a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 234525cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 234625cf760b54d3b88633827501013bc51a29b28abaMike Stump unsigned Index, bool ParameterPack, 234725560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor IdentifierInfo *Name) { 2348a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor ID.AddInteger(Depth); 2349a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor ID.AddInteger(Index); 23504e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson ID.AddBoolean(ParameterPack); 235125560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor ID.AddPointer(Name); 2352a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor } 2353a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 235425cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 235525cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == TemplateTypeParm; 2356dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor } 2357dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 2358dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor}; 2359a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 23605cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// \brief Represents the result of substituting a type for a template 23615cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// type parameter. 23625cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// 23635cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// Within an instantiated template, all template type parameters have 23645cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// been replaced with these. They are used solely to record that a 23655cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// type was originally written as a template type parameter; 23665cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// therefore they are never canonical. 23675cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode { 23685cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall // The original type parameter. 23695cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall const TemplateTypeParmType *Replaced; 23705cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23715cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) 23725cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType()), 23735cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall Replaced(Param) { } 23745cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23755cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall friend class ASTContext; 23765cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23775cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCallpublic: 237825560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor IdentifierInfo *getName() const { return Replaced->getName(); } 237925560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor 23805cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall /// Gets the template parameter that was substituted for. 23815cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall const TemplateTypeParmType *getReplacedParameter() const { 23825cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall return Replaced; 23835cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 23845cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23855cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall /// Gets the type that was substituted for the template 23865cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall /// parameter. 23875cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall QualType getReplacementType() const { 23885cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall return getCanonicalTypeInternal(); 23895cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 23905cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23915cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall bool isSugared() const { return true; } 23925cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall QualType desugar() const { return getReplacementType(); } 23935cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23945cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall void Profile(llvm::FoldingSetNodeID &ID) { 23955cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall Profile(ID, getReplacedParameter(), getReplacementType()); 23965cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 23975cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall static void Profile(llvm::FoldingSetNodeID &ID, 23985cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall const TemplateTypeParmType *Replaced, 23995cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall QualType Replacement) { 24005cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall ID.AddPointer(Replaced); 24015cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall ID.AddPointer(Replacement.getAsOpaquePtr()); 24025cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 24035cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 24045cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall static bool classof(const Type *T) { 24055cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall return T->getTypeClass() == SubstTemplateTypeParm; 24065cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 24075cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall static bool classof(const SubstTemplateTypeParmType *T) { return true; } 24085cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall}; 24095cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 2410dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// \brief Represents the type of a template specialization as written 2411dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// in the source code. 24128e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// 2413dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// Template specialization types represent the syntactic form of a 2414dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 2415dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 2416dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// type will point to some other type node that represents the 2417dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// instantiation or class template specialization. For example, a 24188e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// class template specialization type of @c vector<int> will refer to 241925cf760b54d3b88633827501013bc51a29b28abaMike Stump/// a tag type for the instantiation 24208e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 2421dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// 2422dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// Other template specialization types, for which the template name 2423dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// is dependent, may be canonical types. These types are always 2424dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// dependent. 242525cf760b54d3b88633827501013bc51a29b28abaMike Stumpclass TemplateSpecializationType 24268e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor : public Type, public llvm::FoldingSetNode { 242752b136ace347ee82e11145927e37980157bacb35John McCall /// \brief The name of the template being specialized. 2428dd13e8468462e60971487bcd5915419762dab814Douglas Gregor TemplateName Template; 24298e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 2430f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief - The number of template arguments named in this class 2431f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// template specialization. 24328e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor unsigned NumArgs; 24338e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 243402cd8e64ab4b62f88c62f63320ddd17466764022John McCall TemplateSpecializationType(TemplateName T, 2435dd13e8468462e60971487bcd5915419762dab814Douglas Gregor const TemplateArgument *Args, 2436dd13e8468462e60971487bcd5915419762dab814Douglas Gregor unsigned NumArgs, QualType Canon); 24378e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 24386f37b58716e89420c13ac067fe605c3b6d5821d0Douglas Gregor virtual void Destroy(ASTContext& C); 24396f37b58716e89420c13ac067fe605c3b6d5821d0Douglas Gregor 24408e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor friend class ASTContext; // ASTContext creates these 24418e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 24428e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregorpublic: 2443f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Determine whether any of the given template arguments are 2444f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// dependent. 2445f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 244625cf760b54d3b88633827501013bc51a29b28abaMike Stump unsigned NumArgs); 2447f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2448588613178e3a10e2b840c8f4db9e058f2fec0005John McCall static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args, 2449588613178e3a10e2b840c8f4db9e058f2fec0005John McCall unsigned NumArgs); 2450588613178e3a10e2b840c8f4db9e058f2fec0005John McCall 2451ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &); 2452ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall 245356d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 245456d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor /// enclosing the template arguments. 245556d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 24563bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor unsigned NumArgs, 24573bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor const PrintingPolicy &Policy); 245856d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor 2459588613178e3a10e2b840c8f4db9e058f2fec0005John McCall static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args, 2460588613178e3a10e2b840c8f4db9e058f2fec0005John McCall unsigned NumArgs, 2461588613178e3a10e2b840c8f4db9e058f2fec0005John McCall const PrintingPolicy &Policy); 2462588613178e3a10e2b840c8f4db9e058f2fec0005John McCall 2463ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &, 2464ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall const PrintingPolicy &Policy); 2465ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall 24664578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// True if this template specialization type matches a current 24674578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// instantiation in the context in which it is found. 24684578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall bool isCurrentInstantiation() const { 2469486c883ca29f6b50bb8ded372ad5bb2970fd4101John McCall return isa<InjectedClassNameType>(getCanonicalTypeInternal()); 24704578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall } 24714578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall 2472f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor typedef const TemplateArgument * iterator; 2473f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2474f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor iterator begin() const { return getArgs(); } 247552b136ace347ee82e11145927e37980157bacb35John McCall iterator end() const; // defined inline in TemplateBase.h 2476f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2477dd13e8468462e60971487bcd5915419762dab814Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 2478dd13e8468462e60971487bcd5915419762dab814Douglas Gregor TemplateName getTemplateName() const { return Template; } 24798e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 2480f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Retrieve the template arguments. 248125cf760b54d3b88633827501013bc51a29b28abaMike Stump const TemplateArgument *getArgs() const { 2482f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 2483f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor } 2484f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2485f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Retrieve the number of template arguments. 24868e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 24878e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 24888e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor /// \brief Retrieve a specific template argument as a type. 24898e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor /// \precondition @c isArgType(Arg) 249052b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 24918e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 24924578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall bool isSugared() const { 24934578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall return !isDependentType() || isCurrentInstantiation(); 24944578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall } 24950afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getCanonicalTypeInternal(); } 24960afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 249702cd8e64ab4b62f88c62f63320ddd17466764022John McCall void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Ctx) { 2498486c883ca29f6b50bb8ded372ad5bb2970fd4101John McCall Profile(ID, Template, getArgs(), NumArgs, Ctx); 24998e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor } 25008e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 2501dd13e8468462e60971487bcd5915419762dab814Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 25024578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall const TemplateArgument *Args, 25034578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall unsigned NumArgs, 250499eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor ASTContext &Context); 25058e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 250625cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 250725cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == TemplateSpecialization; 25088e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor } 2509dd13e8468462e60971487bcd5915419762dab814Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 25108e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor}; 25118e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 25124578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// \brief The injected class name of a C++ class template or class 25134578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// template partial specialization. Used to record that a type was 25144578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// spelled with a bare identifier rather than as a template-id; the 25154578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// equivalent for non-templated classes is just RecordType. 251655851d6d117e79db3a891bcb821acd19592b2178John McCall/// 25174578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// Injected class name types are always dependent. Template 25184578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// instantiation turns these into RecordTypes. 251955851d6d117e79db3a891bcb821acd19592b2178John McCall/// 25204578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// Injected class name types are always canonical. This works 25214578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// because it is impossible to compare an injected class name type 25224578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// with the corresponding non-injected template type, for the same 25234578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// reason that it is impossible to directly compare template 25244578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// parameters from different dependent contexts: injected class name 25254578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// types can only occur within the scope of a particular templated 25264578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// declaration, and within that scope every template specialization 25274578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// will canonicalize to the injected class name (when appropriate 25284578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// according to the rules of the language). 252955851d6d117e79db3a891bcb821acd19592b2178John McCallclass InjectedClassNameType : public Type { 253055851d6d117e79db3a891bcb821acd19592b2178John McCall CXXRecordDecl *Decl; 253155851d6d117e79db3a891bcb821acd19592b2178John McCall 25324578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// The template specialization which this type represents. 25334578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// For example, in 25344578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// template <class T> class A { ... }; 25354578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// this is A<T>, whereas in 25364578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// template <class X, class Y> class A<B<X,Y> > { ... }; 25374578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// this is A<B<X,Y> >. 25384578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// 25394578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// It is always unqualified, always a template specialization type, 25404578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// and always dependent. 25414578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall QualType InjectedType; 254255851d6d117e79db3a891bcb821acd19592b2178John McCall 254355851d6d117e79db3a891bcb821acd19592b2178John McCall friend class ASTContext; // ASTContext creates these. 2544a8d7ca6e37fb2aba356c16ca9c31cafa7ae68584Douglas Gregor friend class TagDecl; // TagDecl mutilates the Decl 25454578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall InjectedClassNameType(CXXRecordDecl *D, QualType TST) 25464578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall : Type(InjectedClassName, QualType(), true), 25474578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall Decl(D), InjectedType(TST) { 254855851d6d117e79db3a891bcb821acd19592b2178John McCall assert(isa<TemplateSpecializationType>(TST)); 254955851d6d117e79db3a891bcb821acd19592b2178John McCall assert(!TST.hasQualifiers()); 25504578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall assert(TST->isDependentType()); 255155851d6d117e79db3a891bcb821acd19592b2178John McCall } 255255851d6d117e79db3a891bcb821acd19592b2178John McCall 255355851d6d117e79db3a891bcb821acd19592b2178John McCallpublic: 25544578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall QualType getInjectedSpecializationType() const { return InjectedType; } 25554578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall const TemplateSpecializationType *getInjectedTST() const { 25564578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall return cast<TemplateSpecializationType>(InjectedType.getTypePtr()); 255755851d6d117e79db3a891bcb821acd19592b2178John McCall } 255855851d6d117e79db3a891bcb821acd19592b2178John McCall 255955851d6d117e79db3a891bcb821acd19592b2178John McCall CXXRecordDecl *getDecl() const { return Decl; } 256055851d6d117e79db3a891bcb821acd19592b2178John McCall 25614578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall bool isSugared() const { return false; } 25624578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall QualType desugar() const { return QualType(this, 0); } 256355851d6d117e79db3a891bcb821acd19592b2178John McCall 256455851d6d117e79db3a891bcb821acd19592b2178John McCall static bool classof(const Type *T) { 256555851d6d117e79db3a891bcb821acd19592b2178John McCall return T->getTypeClass() == InjectedClassName; 256655851d6d117e79db3a891bcb821acd19592b2178John McCall } 256755851d6d117e79db3a891bcb821acd19592b2178John McCall static bool classof(const InjectedClassNameType *T) { return true; } 256855851d6d117e79db3a891bcb821acd19592b2178John McCall}; 256955851d6d117e79db3a891bcb821acd19592b2178John McCall 2570ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// \brief The kind of a tag type. 2571ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraenum TagTypeKind { 2572ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "struct" keyword. 2573ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TTK_Struct, 2574ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "union" keyword. 2575ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TTK_Union, 2576ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "class" keyword. 2577ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TTK_Class, 2578ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "enum" keyword. 2579ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TTK_Enum 2580ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara}; 2581ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2582ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or 2583ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// introduces an elaborated-type-specifier. 2584ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregorenum ElaboratedTypeKeyword { 2585ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor /// \brief The "struct" keyword introduces the elaborated-type-specifier. 2586ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor ETK_Struct, 2587ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor /// \brief The "union" keyword introduces the elaborated-type-specifier. 2588ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor ETK_Union, 2589ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "class" keyword introduces the elaborated-type-specifier. 2590ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ETK_Class, 2591ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor /// \brief The "enum" keyword introduces the elaborated-type-specifier. 2592ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ETK_Enum, 2593ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "typename" keyword precedes the qualified type name, e.g., 2594ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \c typename T::type. 2595ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ETK_Typename, 2596ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief No keyword precedes the qualified type name. 2597ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ETK_None 2598ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor}; 2599ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2600ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword. 2601ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// The keyword in stored in the free bits of the base class. 2602ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// Also provides a few static helpers for converting and printing 2603ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// elaborated type keyword and tag type kind enumerations. 2604ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraclass TypeWithKeyword : public Type { 2605ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// Keyword - Encodes an ElaboratedTypeKeyword enumeration constant. 2606ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara unsigned Keyword : 3; 2607ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2608ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraprotected: 2609ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, 2610ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara QualType Canonical, bool dependent) 2611ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara : Type(tc, Canonical, dependent), Keyword(Keyword) {} 2612ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2613ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnarapublic: 2614ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara virtual ~TypeWithKeyword(); // pin vtable to Type.cpp 2615ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2616ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ElaboratedTypeKeyword getKeyword() const { 2617ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara return static_cast<ElaboratedTypeKeyword>(Keyword); 2618ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara } 2619ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2620ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST) 2621ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// into an elaborated type keyword. 2622ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec); 2623ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2624ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST) 2625ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// into a tag type kind. It is an error to provide a type specifier 2626ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// which *isn't* a tag kind here. 2627ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec); 2628ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2629ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// getKeywordForTagDeclKind - Converts a TagTypeKind into an 2630ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// elaborated type keyword. 2631ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag); 2632ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2633ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// getTagTypeKindForKeyword - Converts an elaborated type keyword into 2634ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara // a TagTypeKind. It is an error to provide an elaborated type keyword 2635ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// which *isn't* a tag kind here. 2636ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword); 2637ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2638ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword); 2639ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2640ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static const char *getKeywordName(ElaboratedTypeKeyword Keyword); 2641ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2642ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static const char *getTagTypeKindName(TagTypeKind Kind) { 2643ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara return getKeywordName(getKeywordForTagTypeKind(Kind)); 2644ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara } 2645ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2646ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara class CannotCastToThisType {}; 2647ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static CannotCastToThisType classof(const Type *); 2648ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara}; 2649ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2650ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// \brief Represents a type that was referred to using an elaborated type 2651ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type, 2652ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// or both. 2653734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// 2654734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// This type is used to keep track of a type name as written in the 2655ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// source code, including tag keywords and any nested-name-specifiers. 2656ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// The type itself is always "sugar", used to express what was written 2657ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// in the source code but containing no additional semantic information. 2658ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode { 2659ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 26601e589cc31d339860b9df61870930961601d68120Douglas Gregor /// \brief The nested name specifier containing the qualifier. 26611e589cc31d339860b9df61870930961601d68120Douglas Gregor NestedNameSpecifier *NNS; 2662734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2663734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor /// \brief The type that this qualified name refers to. 2664734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor QualType NamedType; 2665734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2666ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 2667ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara QualType NamedType, QualType CanonType) 2668ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara : TypeWithKeyword(Keyword, Elaborated, CanonType, 2669ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara NamedType->isDependentType()), 2670ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara NNS(NNS), NamedType(NamedType) { 2671ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara assert(!(Keyword == ETK_None && NNS == 0) && 2672ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara "ElaboratedType cannot have elaborated type keyword " 2673ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara "and name qualifier both null."); 2674ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara } 2675734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2676734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor friend class ASTContext; // ASTContext creates these 2677734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2678734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorpublic: 267952b136ace347ee82e11145927e37980157bacb35John McCall ~ElaboratedType(); 2680ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 26811e589cc31d339860b9df61870930961601d68120Douglas Gregor /// \brief Retrieve the qualification on this type. 26821e589cc31d339860b9df61870930961601d68120Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2683734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2684734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 2685734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor QualType getNamedType() const { return NamedType; } 2686734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 26870afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 26880afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getNamedType(); } 26890afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 26900afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 26910afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 26920afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2693734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2694ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara Profile(ID, getKeyword(), NNS, NamedType); 2695734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor } 2696734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2697ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 2698ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara NestedNameSpecifier *NNS, QualType NamedType) { 2699ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ID.AddInteger(Keyword); 27001e589cc31d339860b9df61870930961601d68120Douglas Gregor ID.AddPointer(NNS); 27011e589cc31d339860b9df61870930961601d68120Douglas Gregor NamedType.Profile(ID); 27021e589cc31d339860b9df61870930961601d68120Douglas Gregor } 2703734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 270425cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 2705ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara return T->getTypeClass() == Elaborated; 2706734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor } 2707ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static bool classof(const ElaboratedType *T) { return true; } 2708734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor}; 2709734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2710ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// \brief Represents a qualified type name for which the type name is 2711ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// dependent. 2712d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// 2713ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// DependentNameType represents a class of dependent types that involve a 2714ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent) 2715ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a 2716ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// typename-specifier), "class", "struct", "union", or "enum" (for a 2717ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we 2718ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier). 2719ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { 2720ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2721d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor /// \brief The nested name specifier containing the qualifier. 2722d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor NestedNameSpecifier *NNS; 2723d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2724d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor /// \brief The type that this typename specifier refers to. 272552b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *Name; 2726d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2727ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 2728ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor const IdentifierInfo *Name, QualType CanonType) 2729ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara : TypeWithKeyword(Keyword, DependentName, CanonType, true), 2730ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara NNS(NNS), Name(Name) { 273125cf760b54d3b88633827501013bc51a29b28abaMike Stump assert(NNS->isDependent() && 2732725b41e4eefc6d19b6215f24489acbc2e1641765Douglas Gregor "DependentNameType requires a dependent nested-name-specifier"); 2733d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2734d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2735d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor friend class ASTContext; // ASTContext creates these 2736d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2737d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregorpublic: 273852b136ace347ee82e11145927e37980157bacb35John McCall virtual ~DependentNameType(); 2739ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2740d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor /// \brief Retrieve the qualification on this type. 2741d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2742d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 274377da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 274477da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// identifier. 274577da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// 274677da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 274777da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// form of the original typename was terminated by an identifier, 274877da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// e.g., "typename T::type". 274925cf760b54d3b88633827501013bc51a29b28abaMike Stump const IdentifierInfo *getIdentifier() const { 275052b136ace347ee82e11145927e37980157bacb35John McCall return Name; 275177da58034d00866f3261d2c657a5823578f73028Douglas Gregor } 2752d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 27530afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 27540afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 27550afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2756d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2757ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara Profile(ID, getKeyword(), NNS, Name); 2758d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2759d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2760ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 276152b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name) { 2762ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor ID.AddInteger(Keyword); 2763d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor ID.AddPointer(NNS); 276452b136ace347ee82e11145927e37980157bacb35John McCall ID.AddPointer(Name); 2765d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2766d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 276725cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 2768725b41e4eefc6d19b6215f24489acbc2e1641765Douglas Gregor return T->getTypeClass() == DependentName; 2769d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2770725b41e4eefc6d19b6215f24489acbc2e1641765Douglas Gregor static bool classof(const DependentNameType *T) { return true; } 2771d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor}; 2772d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 277352b136ace347ee82e11145927e37980157bacb35John McCall/// DependentTemplateSpecializationType - Represents a template 277452b136ace347ee82e11145927e37980157bacb35John McCall/// specialization type whose template cannot be resolved, e.g. 277552b136ace347ee82e11145927e37980157bacb35John McCall/// A<T>::template B<T> 277652b136ace347ee82e11145927e37980157bacb35John McCallclass DependentTemplateSpecializationType : 277752b136ace347ee82e11145927e37980157bacb35John McCall public TypeWithKeyword, public llvm::FoldingSetNode { 277852b136ace347ee82e11145927e37980157bacb35John McCall 277952b136ace347ee82e11145927e37980157bacb35John McCall /// \brief The nested name specifier containing the qualifier. 278052b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *NNS; 278152b136ace347ee82e11145927e37980157bacb35John McCall 278252b136ace347ee82e11145927e37980157bacb35John McCall /// \brief The identifier of the template. 278352b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *Name; 278452b136ace347ee82e11145927e37980157bacb35John McCall 278552b136ace347ee82e11145927e37980157bacb35John McCall /// \brief - The number of template arguments named in this class 278652b136ace347ee82e11145927e37980157bacb35John McCall /// template specialization. 278752b136ace347ee82e11145927e37980157bacb35John McCall unsigned NumArgs; 278852b136ace347ee82e11145927e37980157bacb35John McCall 278952b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument *getArgBuffer() const { 279052b136ace347ee82e11145927e37980157bacb35John McCall return reinterpret_cast<const TemplateArgument*>(this+1); 279152b136ace347ee82e11145927e37980157bacb35John McCall } 279252b136ace347ee82e11145927e37980157bacb35John McCall TemplateArgument *getArgBuffer() { 279352b136ace347ee82e11145927e37980157bacb35John McCall return reinterpret_cast<TemplateArgument*>(this+1); 279452b136ace347ee82e11145927e37980157bacb35John McCall } 279552b136ace347ee82e11145927e37980157bacb35John McCall 279602cd8e64ab4b62f88c62f63320ddd17466764022John McCall DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 279752b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *NNS, 279852b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *Name, 279952b136ace347ee82e11145927e37980157bacb35John McCall unsigned NumArgs, 280052b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument *Args, 280152b136ace347ee82e11145927e37980157bacb35John McCall QualType Canon); 280252b136ace347ee82e11145927e37980157bacb35John McCall 280352b136ace347ee82e11145927e37980157bacb35John McCall virtual void Destroy(ASTContext& C); 280452b136ace347ee82e11145927e37980157bacb35John McCall 280552b136ace347ee82e11145927e37980157bacb35John McCall friend class ASTContext; // ASTContext creates these 280652b136ace347ee82e11145927e37980157bacb35John McCall 280752b136ace347ee82e11145927e37980157bacb35John McCallpublic: 280852b136ace347ee82e11145927e37980157bacb35John McCall virtual ~DependentTemplateSpecializationType(); 280952b136ace347ee82e11145927e37980157bacb35John McCall 281052b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *getQualifier() const { return NNS; } 281152b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *getIdentifier() const { return Name; } 281252b136ace347ee82e11145927e37980157bacb35John McCall 281352b136ace347ee82e11145927e37980157bacb35John McCall /// \brief Retrieve the template arguments. 281452b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument *getArgs() const { 281552b136ace347ee82e11145927e37980157bacb35John McCall return getArgBuffer(); 281652b136ace347ee82e11145927e37980157bacb35John McCall } 281752b136ace347ee82e11145927e37980157bacb35John McCall 281852b136ace347ee82e11145927e37980157bacb35John McCall /// \brief Retrieve the number of template arguments. 281952b136ace347ee82e11145927e37980157bacb35John McCall unsigned getNumArgs() const { return NumArgs; } 282052b136ace347ee82e11145927e37980157bacb35John McCall 282152b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 282252b136ace347ee82e11145927e37980157bacb35John McCall 282352b136ace347ee82e11145927e37980157bacb35John McCall typedef const TemplateArgument * iterator; 282452b136ace347ee82e11145927e37980157bacb35John McCall iterator begin() const { return getArgs(); } 282552b136ace347ee82e11145927e37980157bacb35John McCall iterator end() const; // inline in TemplateBase.h 282652b136ace347ee82e11145927e37980157bacb35John McCall 282752b136ace347ee82e11145927e37980157bacb35John McCall bool isSugared() const { return false; } 282852b136ace347ee82e11145927e37980157bacb35John McCall QualType desugar() const { return QualType(this, 0); } 282952b136ace347ee82e11145927e37980157bacb35John McCall 283002cd8e64ab4b62f88c62f63320ddd17466764022John McCall void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context) { 283152b136ace347ee82e11145927e37980157bacb35John McCall Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs()); 283252b136ace347ee82e11145927e37980157bacb35John McCall } 283352b136ace347ee82e11145927e37980157bacb35John McCall 283452b136ace347ee82e11145927e37980157bacb35John McCall static void Profile(llvm::FoldingSetNodeID &ID, 283552b136ace347ee82e11145927e37980157bacb35John McCall ASTContext &Context, 283652b136ace347ee82e11145927e37980157bacb35John McCall ElaboratedTypeKeyword Keyword, 283752b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *Qualifier, 283852b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *Name, 283952b136ace347ee82e11145927e37980157bacb35John McCall unsigned NumArgs, 284052b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument *Args); 284152b136ace347ee82e11145927e37980157bacb35John McCall 284252b136ace347ee82e11145927e37980157bacb35John McCall static bool classof(const Type *T) { 284352b136ace347ee82e11145927e37980157bacb35John McCall return T->getTypeClass() == DependentTemplateSpecialization; 284452b136ace347ee82e11145927e37980157bacb35John McCall } 284552b136ace347ee82e11145927e37980157bacb35John McCall static bool classof(const DependentTemplateSpecializationType *T) { 284652b136ace347ee82e11145927e37980157bacb35John McCall return true; 284752b136ace347ee82e11145927e37980157bacb35John McCall } 284852b136ace347ee82e11145927e37980157bacb35John McCall}; 284952b136ace347ee82e11145927e37980157bacb35John McCall 2850f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// ObjCObjectType - Represents a class type in Objective C. 2851f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// Every Objective C type is a combination of a base type and a 2852f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// list of protocols. 2853f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 2854f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// Given the following declarations: 2855f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// @class C; 2856f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// @protocol P; 2857f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 2858f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType 2859f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// with base C and no protocols. 2860f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 2861f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P]. 2862f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 2863cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose 2864cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType 2865cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// and no protocols. 2866f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 2867cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType 2868cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually 2869cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// this should get its own sugar class to better represent the source. 2870f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallclass ObjCObjectType : public Type { 2871f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // Pad the bit count up so that NumProtocols is 2-byte aligned 2872f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall unsigned : BitsRemainingInType - 16; 2873f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2874f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// \brief The number of protocols stored after the 2875f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// ObjCObjectPointerType node. 2876f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// 2877cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// These protocols are those written directly on the type. If 2878cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// protocol qualifiers ever become additive, the iterators will 2879cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// get kindof complicated. 2880cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// 2881f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// In the canonical object type, these are sorted alphabetically 2882f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// and uniqued. 2883f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall unsigned NumProtocols : 16; 288477763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff 2885f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// Either a BuiltinType or an InterfaceType or sugar for either. 2886f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall QualType BaseType; 2887f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2888f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCProtocolDecl * const *getProtocolStorage() const { 2889f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return const_cast<ObjCObjectType*>(this)->getProtocolStorage(); 2890f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 2891f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2892f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCProtocolDecl **getProtocolStorage(); 2893f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2894f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallprotected: 2895f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCObjectType(QualType Canonical, QualType Base, 2896f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCProtocolDecl * const *Protocols, unsigned NumProtocols); 2897f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2898f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall enum Nonce_ObjCInterface { Nonce_ObjCInterface }; 2899f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCObjectType(enum Nonce_ObjCInterface) 2900f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall : Type(ObjCInterface, QualType(), false), 2901f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall NumProtocols(0), 2902f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall BaseType(QualType(this_(), 0)) {} 290377763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff 2904949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 2905949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor Linkage getLinkageImpl() const; // key function 2906949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 290781f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroffpublic: 2908cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getBaseType - Gets the base type of this object type. This is 2909cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// always (possibly sugar for) one of: 2910cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// - the 'id' builtin type (as opposed to the 'id' type visible to the 2911cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// user, which is a typedef for an ObjCPointerType) 2912cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// - the 'Class' builtin type (same caveat) 2913cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// - an ObjCObjectType (currently always an ObjCInterfaceType) 2914f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall QualType getBaseType() const { return BaseType; } 291539abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek 2916f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCId() const { 2917f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId); 2918f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 2919f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCClass() const { 2920f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass); 2921f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 2922f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); } 2923f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); } 2924f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCUnqualifiedIdOrClass() const { 2925f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall if (!qual_empty()) return false; 2926f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>()) 2927f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return T->getKind() == BuiltinType::ObjCId || 2928f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall T->getKind() == BuiltinType::ObjCClass; 2929f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return false; 2930f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 2931f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); } 2932f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); } 2933f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2934f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// Gets the interface declaration for this object type, if the base type 2935f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// really is an interface. 2936f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCInterfaceDecl *getInterface() const; 2937f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2938f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall typedef ObjCProtocolDecl * const *qual_iterator; 2939f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2940f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_iterator qual_begin() const { return getProtocolStorage(); } 2941f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); } 2942f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2943f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool qual_empty() const { return getNumProtocols() == 0; } 294425cf760b54d3b88633827501013bc51a29b28abaMike Stump 294577763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 294677763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff /// interface type, or 0 if there are none. 294739abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek unsigned getNumProtocols() const { return NumProtocols; } 2948329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 2949f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// \brief Fetch a protocol by index. 2950f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor ObjCProtocolDecl *getProtocol(unsigned I) const { 2951f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor assert(I < getNumProtocols() && "Out-of-range protocol access"); 2952f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor return qual_begin()[I]; 2953f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor } 2954f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor 29550afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 29560afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 29570afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2958f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall static bool classof(const Type *T) { 2959f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return T->getTypeClass() == ObjCObject || 2960f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall T->getTypeClass() == ObjCInterface; 2961f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 2962f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall static bool classof(const ObjCObjectType *) { return true; } 2963f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall}; 2964f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2965f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation 2966f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// of ObjCObjectType, so as to not increase the footprint of 2967f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// ObjCInterfaceType. Code outside of ASTContext and the core type 2968f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// system should not reference this type. 2969f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode { 2970f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall friend class ASTContext; 2971f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2972f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // If anyone adds fields here, ObjCObjectType::getProtocolStorage() 2973f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // will need to be modified. 2974f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2975f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCObjectTypeImpl(QualType Canonical, QualType Base, 2976f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCProtocolDecl * const *Protocols, 2977f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall unsigned NumProtocols) 2978f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {} 2979f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2980f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallpublic: 2981f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall void Destroy(ASTContext& C); // key function 2982f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 298377763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 298425cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, 2985f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall QualType Base, 2986f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCProtocolDecl *const *protocols, 2987f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall unsigned NumProtocols); 2988f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall}; 298925cf760b54d3b88633827501013bc51a29b28abaMike Stump 2990f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() { 2991f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return reinterpret_cast<ObjCProtocolDecl**>( 2992f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall static_cast<ObjCObjectTypeImpl*>(this) + 1); 2993f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall} 2994f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2995f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 2996f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// object oriented design. They basically correspond to C++ classes. There 2997f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// are two kinds of interface types, normal interfaces like "NSString" and 2998f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// qualified interfaces, which are qualified with a protocol list like 2999f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// "NSString<NSCopyable, NSAmazing>". 3000cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// 3001cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// ObjCInterfaceType guarantees the following properties when considered 3002cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// as a subtype of its superclass, ObjCObjectType: 3003cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// - There are no protocol qualifiers. To reinforce this, code which 3004cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// tries to invoke the protocol methods via an ObjCInterfaceType will 3005cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// fail to compile. 3006cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// - It is its own base type. That is, if T is an ObjCInterfaceType*, 3007cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// T->getBaseType() == QualType(T, 0). 3008f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallclass ObjCInterfaceType : public ObjCObjectType { 3009f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCInterfaceDecl *Decl; 3010f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3011f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCInterfaceType(const ObjCInterfaceDecl *D) 3012f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall : ObjCObjectType(Nonce_ObjCInterface), 3013f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall Decl(const_cast<ObjCInterfaceDecl*>(D)) {} 3014f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall friend class ASTContext; // ASTContext creates these. 3015f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallpublic: 3016f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall void Destroy(ASTContext& C); // key function 3017f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3018cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getDecl - Get the declaration of this interface. 3019f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCInterfaceDecl *getDecl() const { return Decl; } 3020f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3021f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isSugared() const { return false; } 3022f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall QualType desugar() const { return QualType(this, 0); } 3023b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 302425cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 302525cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == ObjCInterface; 302681f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff } 302742730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 3028f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3029f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // Nonsense to "hide" certain members of ObjCObjectType within this 3030f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // class. People asking for protocols on an ObjCInterfaceType are 3031f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // not going to get what they want: ObjCInterfaceTypes are 3032f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // guaranteed to have no protocols. 3033f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall enum { 3034f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_iterator, 3035f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_begin, 3036f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_end, 3037f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall getNumProtocols, 3038f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall getProtocol 3039f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall }; 304081f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff}; 304181f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff 3042f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const { 3043f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall if (const ObjCInterfaceType *T = 3044f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall getBaseType()->getAs<ObjCInterfaceType>()) 3045f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return T->getDecl(); 3046f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return 0; 3047f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall} 3048f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3049cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// ObjCObjectPointerType - Used to represent a pointer to an 3050cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// Objective C object. These are constructed from pointer 3051cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar 3052cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// for one). In addition, the 'id' and 'Class' types are typedefs 3053cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>' 3054cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// are translated into these. 3055329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff/// 3056cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// Pointers to pointers to Objective C objects are still PointerTypes; 3057cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// only the first level of pointer gets it own type implementation. 3058329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 3059cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall QualType PointeeType; 306025cf760b54d3b88633827501013bc51a29b28abaMike Stump 3061f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCObjectPointerType(QualType Canonical, QualType Pointee) 3062f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall : Type(ObjCObjectPointer, Canonical, false), 3063f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall PointeeType(Pointee) {} 3064329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff friend class ASTContext; // ASTContext creates these. 306525cf760b54d3b88633827501013bc51a29b28abaMike Stump 3066949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 3067949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 3068949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 3069329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffpublic: 307039abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek void Destroy(ASTContext& C); 307139abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek 3072cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getPointeeType - Gets the type pointed to by this ObjC pointer. 3073cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// The result will always be an ObjCObjectType or sugar thereof. 3074329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff QualType getPointeeType() const { return PointeeType; } 3075329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 3076cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getObjCObjectType - Gets the type pointed to by this ObjC 3077cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// pointer. This method always returns non-null. 3078cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// 3079cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// This method is equivalent to getPointeeType() except that 3080cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// it discards any typedefs (or other sugar) between this 3081cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// type and the "outermost" object type. So for: 3082cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// @class A; @protocol P; @protocol Q; 3083cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// typedef A<P> AP; 3084cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// typedef A A1; 3085cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// typedef A1<P> A1P; 3086cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// typedef A1P<Q> A1PQ; 3087cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A*', getObjectType() will return 'A'. 3088cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A<P>*', getObjectType() will return 'A<P>'. 3089cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'AP*', getObjectType() will return 'A<P>'. 3090cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A1*', getObjectType() will return 'A'. 3091cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A1<P>*', getObjectType() will return 'A1<P>'. 3092cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A1P*', getObjectType() will return 'A1<P>'. 3093cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because 3094cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// adding protocols to a protocol-qualified base discards the 3095cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// old qualifiers (for now). But if it didn't, getObjectType() 3096cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// would return 'A1P<Q>' (and we'd have to make iterating over 3097cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// qualifiers more complicated). 3098f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall const ObjCObjectType *getObjectType() const { 3099f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return PointeeType->getAs<ObjCObjectType>(); 3100f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 3101f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3102cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getInterfaceType - If this pointer points to an Objective C 3103cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// @interface type, gets the type for that interface. Any protocol 3104cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// qualifiers on the interface are ignored. 3105cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// 3106cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// \return null if the base type for this pointer is 'id' or 'Class' 310725cf760b54d3b88633827501013bc51a29b28abaMike Stump const ObjCInterfaceType *getInterfaceType() const { 3108f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>(); 3109329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 3110cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 3111cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getInterfaceDecl - If this pointer points to an Objective @interface 3112cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// type, gets the declaration for that interface. 3113cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// 3114cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// \return null if the base type for this pointer is 'id' or 'Class' 3115329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff ObjCInterfaceDecl *getInterfaceDecl() const { 3116cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall return getObjectType()->getInterface(); 3117329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 3118cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 3119cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if 3120cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// its object type is the primitive 'id' type with no protocols. 3121329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCIdType() const { 3122f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->isObjCUnqualifiedId(); 3123329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 3124cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 3125cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// isObjCClassType - True if this is equivalent to the 'Class' type, 3126cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// i.e. if its object tive is the primitive 'Class' type with no protocols. 3127329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCClassType() const { 3128f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->isObjCUnqualifiedClass(); 31297bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff } 31302818bd26562e1a2b7d7e9fb31d72f698a5748289Fariborz Jahanian 3131cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some 3132cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// non-empty set of protocols. 313325cf760b54d3b88633827501013bc51a29b28abaMike Stump bool isObjCQualifiedIdType() const { 3134f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->isObjCQualifiedId(); 31357bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff } 3136cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 3137cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for 3138cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// some non-empty set of protocols. 313927bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff bool isObjCQualifiedClassType() const { 3140f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->isObjCQualifiedClass(); 3141329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 3142cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 3143cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// An iterator over the qualifiers on the object type. Provided 3144cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// for convenience. This will always iterate over the full set of 3145cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// protocols on a type, not just those provided directly. 3146f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall typedef ObjCObjectType::qual_iterator qual_iterator; 3147329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 314839abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek qual_iterator qual_begin() const { 3149f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->qual_begin(); 315039abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek } 3151f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_iterator qual_end() const { 3152f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->qual_end(); 315339abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek } 3154f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool qual_empty() const { return getObjectType()->qual_empty(); } 3155329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 3156cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getNumProtocols - Return the number of qualifying protocols on 3157cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// the object type. 3158f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall unsigned getNumProtocols() const { 3159f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->getNumProtocols(); 3160f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 3161329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 3162cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// \brief Retrieve a qualifying protocol by index on the object 3163cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// type. 3164f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor ObjCProtocolDecl *getProtocol(unsigned I) const { 3165f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->getProtocol(I); 3166f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor } 3167f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor 31680afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 31690afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 31700afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 3171cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall void Profile(llvm::FoldingSetNodeID &ID) { 3172cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall Profile(ID, getPointeeType()); 3173cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall } 3174f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { 3175f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ID.AddPointer(T.getAsOpaquePtr()); 3176f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 317725cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 317825cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == ObjCObjectPointer; 3179329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 3180329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 3181329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff}; 3182fd3d5fdac0d25464e1b9c36bc646965494d44f66Argiris Kirtzidis 31833ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// A qualifier set is used to build a set of qualifiers. 31843ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallclass QualifierCollector : public Qualifiers { 31853ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ASTContext *Context; 31863ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 31873ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallpublic: 31883ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector(Qualifiers Qs = Qualifiers()) 31893ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Qualifiers(Qs), Context(0) {} 31903ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector(ASTContext &Context, Qualifiers Qs = Qualifiers()) 31913ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Qualifiers(Qs), Context(&Context) {} 31923ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 31933ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setContext(ASTContext &C) { Context = &C; } 31943ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 31953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Collect any qualifiers on the given type and return an 31963ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// unqualified type. 31973ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *strip(QualType QT) { 3198c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor addFastQualifiers(QT.getLocalFastQualifiers()); 3199c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (QT.hasLocalNonFastQualifiers()) { 32003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = QT.getExtQualsUnsafe(); 32013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Context = &EQ->getContext(); 32023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall addQualifiers(EQ->getQualifiers()); 32033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getBaseType(); 32043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 32053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return QT.getTypePtrUnsafe(); 32063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 32073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Apply the collected qualifiers to the given type. 32093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType apply(QualType QT) const; 32103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Apply the collected qualifiers to the given type. 32123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType apply(const Type* T) const; 32133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall}; 32153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3217b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner// Inline function definitions. 32184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 32197480534aa1979f5c8a6c1d59ede223ba21f280e5John McCallinline bool QualType::isCanonical() const { 32207480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall const Type *T = getTypePtr(); 3221c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalQualifiers()) 32227480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall return T->isCanonicalUnqualified() && !isa<ArrayType>(T); 32237480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall return T->isCanonicalUnqualified(); 32247480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall} 32257480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall 32264ea8425c9601895fa137f877bc784f75f20adac6John McCallinline bool QualType::isCanonicalAsParam() const { 3227c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalQualifiers()) return false; 32284ea8425c9601895fa137f877bc784f75f20adac6John McCall const Type *T = getTypePtr(); 32294ea8425c9601895fa137f877bc784f75f20adac6John McCall return T->isCanonicalUnqualified() && 32304ea8425c9601895fa137f877bc784f75f20adac6John McCall !isa<FunctionType>(T) && !isa<ArrayType>(T); 32314ea8425c9601895fa137f877bc784f75f20adac6John McCall} 32324ea8425c9601895fa137f877bc784f75f20adac6John McCall 32334f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::isConstQualified() const { 32344f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return isLocalConstQualified() || 32354f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalConstQualified(); 32364f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 32374f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 32384f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::isRestrictQualified() const { 32394f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return isLocalRestrictQualified() || 32404f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalRestrictQualified(); 32414f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 32424f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 32434f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 32444f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::isVolatileQualified() const { 32454f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return isLocalVolatileQualified() || 32464f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalVolatileQualified(); 32474f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 32484f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 32494f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::hasQualifiers() const { 32504f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return hasLocalQualifiers() || 32514f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers(); 32524f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 32534f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 32544f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline Qualifiers QualType::getQualifiers() const { 32554f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor Qualifiers Quals = getLocalQualifiers(); 32564f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor Quals.addQualifiers( 32574f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().getLocalQualifiers()); 32584f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return Quals; 32594f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 32604f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 32614f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline unsigned QualType::getCVRQualifiers() const { 32624f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return getLocalCVRQualifiers() | 32634f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().getLocalCVRQualifiers(); 32644f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 32656d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth 32666d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// getCVRQualifiersThroughArrayTypes - If there are CVR qualifiers for this 32676d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// type, returns them. Otherwise, if this is an array type, recurses 32686d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// on the element type until some qualifiers have been found or a non-array 32696d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// type reached. 32706d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruthinline unsigned QualType::getCVRQualifiersThroughArrayTypes() const { 32716d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth if (unsigned Quals = getCVRQualifiers()) 32726d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth return Quals; 32736d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth QualType CT = getTypePtr()->getCanonicalTypeInternal(); 32746d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 32756d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth return AT->getElementType().getCVRQualifiersThroughArrayTypes(); 32766d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth return 0; 32776d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth} 32786d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth 32793ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeConst() { 32803ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeFastQualifiers(Qualifiers::Const); 32813ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall} 32823ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32833ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeRestrict() { 32843ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeFastQualifiers(Qualifiers::Restrict); 32853ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall} 32863ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32873ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeVolatile() { 32883ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector Qc; 32893ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *Ty = Qc.strip(*this); 32903ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (Qc.hasVolatile()) { 32913ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qc.removeVolatile(); 32923ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall *this = Qc.apply(Ty); 32933ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 32943ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall} 32953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32963ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeCVRQualifiers(unsigned Mask) { 3297451b7b9a60208869cf5d6d958134cb104343949fJohn McCall assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits"); 32983ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32993ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Fast path: we don't need to touch the slow qualifiers. 33003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (!(Mask & ~Qualifiers::FastMask)) { 33013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeFastQualifiers(Mask); 33023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return; 33033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 33043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 33053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector Qc; 33063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *Ty = Qc.strip(*this); 33073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qc.removeCVRQualifiers(Mask); 33083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall *this = Qc.apply(Ty); 33092a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb} 33102a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 33112a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// getAddressSpace - Return the address space of this type. 33122a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambinline unsigned QualType::getAddressSpace() const { 3313c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalNonFastQualifiers()) { 33143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = getExtQualsUnsafe(); 33153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasAddressSpace()) 33163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getAddressSpace(); 33173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 33183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 331901ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 3320c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (CT.hasLocalNonFastQualifiers()) { 33213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = CT.getExtQualsUnsafe(); 33223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasAddressSpace()) 33233ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getAddressSpace(); 33243ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 33253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 332601ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 3327a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return AT->getElementType().getAddressSpace(); 332801ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 3329efc11216a5755f69b5540289aa2dd374d4bc82abNate Begeman return RT->getAddressSpace(); 33302a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return 0; 33312a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb} 3332b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner 3333af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 33343ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const { 3335c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalNonFastQualifiers()) { 33363ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = getExtQualsUnsafe(); 33373ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasObjCGCAttr()) 33383ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getObjCGCAttr(); 33393ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 33403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3341af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 3342c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (CT.hasLocalNonFastQualifiers()) { 33433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = CT.getExtQualsUnsafe(); 33443ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasObjCGCAttr()) 33453ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getObjCGCAttr(); 33463ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 33473ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3348af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 3349af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian return AT->getElementType().getObjCGCAttr(); 3350cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *PT = CT->getAs<ObjCObjectPointerType>()) 335125cf760b54d3b88633827501013bc51a29b28abaMike Stump return PT->getPointeeType().getObjCGCAttr(); 33524bb774e2352b6c5f459b345a5e0f41bd244e70a7Fariborz Jahanian // We most look at all pointer types, not just pointer to interface types. 33534bb774e2352b6c5f459b345a5e0f41bd244e70a7Fariborz Jahanian if (const PointerType *PT = CT->getAs<PointerType>()) 335425cf760b54d3b88633827501013bc51a29b28abaMike Stump return PT->getPointeeType().getObjCGCAttr(); 33553ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Qualifiers::GCNone; 3356af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian} 33571bb806498909a43a7829edb21c42606335d69694Mike Stump 3358433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { 3359433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola if (const PointerType *PT = t.getAs<PointerType>()) { 3360cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>()) 3361433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola return FT->getExtInfo(); 3362433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola } else if (const FunctionType *FT = t.getAs<FunctionType>()) 3363433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola return FT->getExtInfo(); 33641bb806498909a43a7829edb21c42606335d69694Mike Stump 3365433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola return FunctionType::ExtInfo(); 33661bb806498909a43a7829edb21c42606335d69694Mike Stump} 336725cf760b54d3b88633827501013bc51a29b28abaMike Stump 3368433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { 3369433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola return getFunctionExtInfo(*t); 337031cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor} 337131cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor 33723fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 33733fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 33743fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// is more qualified than "const int", "volatile int", and 33753fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int". However, it is not more qualified than "const volatile 33763fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int". 33773fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 33783ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // FIXME: work on arbitrary qualifiers 33796d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes(); 33806d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes(); 33818fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner if (getAddressSpace() != Other.getAddressSpace()) 33828fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner return false; 33833fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 33843fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 33853fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 33863fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 33873fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// as qualified as the Other type. For example, "const volatile 33883fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 33893fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int", and "const volatile int". 33903fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 33913ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // FIXME: work on arbitrary qualifiers 33926d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes(); 33936d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes(); 33948fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner if (getAddressSpace() != Other.getAddressSpace()) 33958fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner return false; 33963fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 33973fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 33983fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 33993fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 34003fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int&), returns the type that the reference refers to ("const 34013fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 34023fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// throughout Sema to implement C++ 5p6: 34033fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// 34043fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 34053fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 34063fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// analysis, the expression designates the object or function 34073fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 34083fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline QualType QualType::getNonReferenceType() const { 3409d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 34103fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return RefType->getPointeeType(); 34113fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor else 34123fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return *this; 34133fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 34143fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 3415b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isFunctionType() const { 3416c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<FunctionType>(CanonicalType); 3417b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 3418b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isPointerType() const { 3419c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<PointerType>(CanonicalType); 3420b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 342179ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroffinline bool Type::isAnyPointerType() const { 342279ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroff return isPointerType() || isObjCObjectPointerType(); 342379ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroff} 34247aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffinline bool Type::isBlockPointerType() const { 3425c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<BlockPointerType>(CanonicalType); 34267aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff} 3427cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattnerinline bool Type::isReferenceType() const { 3428c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ReferenceType>(CanonicalType); 3429cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner} 3430ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlinline bool Type::isLValueReferenceType() const { 3431c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<LValueReferenceType>(CanonicalType); 3432ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl} 3433ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlinline bool Type::isRValueReferenceType() const { 3434c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<RValueReferenceType>(CanonicalType); 3435ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl} 343683b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenekinline bool Type::isFunctionPointerType() const { 3437d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const PointerType* T = getAs<PointerType>()) 343883b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek return T->getPointeeType()->isFunctionType(); 343983b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek else 344083b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek return false; 344183b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek} 34427555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlinline bool Type::isMemberPointerType() const { 3443c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<MemberPointerType>(CanonicalType); 34447555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl} 34457555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 3446d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const MemberPointerType* T = getAs<MemberPointerType>()) 34477555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return T->getPointeeType()->isFunctionType(); 34487555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl else 34497555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return false; 34507555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl} 3451b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isArrayType() const { 3452c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ArrayType>(CanonicalType); 3453b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 3454a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isConstantArrayType() const { 3455c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ConstantArrayType>(CanonicalType); 3456a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 3457a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isIncompleteArrayType() const { 3458c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<IncompleteArrayType>(CanonicalType); 3459a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 3460a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isVariableArrayType() const { 3461c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<VariableArrayType>(CanonicalType); 3462a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 34631b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorinline bool Type::isDependentSizedArrayType() const { 3464c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType); 34651b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor} 3466b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isRecordType() const { 3467c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<RecordType>(CanonicalType); 3468b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 34693277df47de6b65b55721726dc3f7b294e70ef6feChris Lattnerinline bool Type::isAnyComplexType() const { 3470c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ComplexType>(CanonicalType); 34713277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner} 3472b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isVectorType() const { 3473c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<VectorType>(CanonicalType); 3474b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 3475af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemaninline bool Type::isExtVectorType() const { 3476c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ExtVectorType>(CanonicalType); 3477b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 3478c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroffinline bool Type::isObjCObjectPointerType() const { 3479c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ObjCObjectPointerType>(CanonicalType); 3480c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff} 3481f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallinline bool Type::isObjCObjectType() const { 3482f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return isa<ObjCObjectType>(CanonicalType); 3483b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner} 348442730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 3485cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3486c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff return OPT->isObjCQualifiedIdType(); 3487c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff return false; 3488dcb2b1e489948a570ee07ca65e12d42edffa20efFariborz Jahanian} 348927bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroffinline bool Type::isObjCQualifiedClassType() const { 3490cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 349127bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff return OPT->isObjCQualifiedClassType(); 349227bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff return false; 349327bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff} 3494329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffinline bool Type::isObjCIdType() const { 3495cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3496329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return OPT->isObjCIdType(); 3497329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return false; 3498329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff} 3499329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffinline bool Type::isObjCClassType() const { 3500cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3501329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return OPT->isObjCClassType(); 3502329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return false; 3503329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff} 3504a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanianinline bool Type::isObjCSelType() const { 35052818bd26562e1a2b7d7e9fb31d72f698a5748289Fariborz Jahanian if (const PointerType *OPT = getAs<PointerType>()) 35062818bd26562e1a2b7d7e9fb31d72f698a5748289Fariborz Jahanian return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); 3507a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian return false; 3508a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian} 35097bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroffinline bool Type::isObjCBuiltinType() const { 3510a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian return isObjCIdType() || isObjCClassType() || isObjCSelType(); 35117bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff} 3512dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorinline bool Type::isTemplateTypeParmType() const { 3513c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType); 3514dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor} 3515dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 3516522fb671290dd5462bfd819401768686fa53e925Tom Careinline bool Type::isBuiltinType() const { 3517522fb671290dd5462bfd819401768686fa53e925Tom Care return getAs<BuiltinType>(); 3518522fb671290dd5462bfd819401768686fa53e925Tom Care} 3519522fb671290dd5462bfd819401768686fa53e925Tom Care 3520c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 3521cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 3522c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 3523c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar return true; 3524c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar return false; 3525c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar} 3526c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar 352700fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor/// \brief Determines whether this is a type for which one can define 352800fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor/// an overloaded operator. 352900fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregorinline bool Type::isOverloadableType() const { 353000fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 353145014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor} 353245014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor 3533fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 3534fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 3535f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall isObjCObjectPointerType() || isNullPtrType()); 3536fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar} 3537fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar 35387c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 3539f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return isObjCObjectPointerType(); 35407c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian} 35417c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian 3542da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 3543da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// diagnostic with <<. 3544da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 3545da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner QualType T) { 3546da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 3547da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner Diagnostic::ak_qualtype); 3548da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner return DB; 3549da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner} 355025cf760b54d3b88633827501013bc51a29b28abaMike Stump 35518edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth/// Insertion operator for partial diagnostics. This allows sending QualType's 35528edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth/// into a diagnostic with <<. 35538edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruthinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, 35548edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth QualType T) { 35558edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 35568edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth Diagnostic::ak_qualtype); 35578edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth return PD; 35588edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth} 35598edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth 3560406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does 3561406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor// not try to look through a qualified type to get to an array type. 3562406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregortemplate<typename T, 3563406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor bool isArrayType = (llvm::is_same<T, ArrayType>::value || 3564406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor llvm::is_base_of<ArrayType, T>::value)> 3565406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { }; 3566406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor 3567406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregortemplate<typename T> 3568406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>; 3569406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor 3570f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek/// Member-template getAs<specific type>'. 3571f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenektemplate <typename T> const T *Type::getAs() const { 3572406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor ArrayType_cannot_be_used_with_getAs<T> at; 3573406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor (void)at; 3574406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor 3575f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // If this is directly a T type, return it. 3576f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek if (const T *Ty = dyn_cast<T>(this)) 3577f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek return Ty; 357825cf760b54d3b88633827501013bc51a29b28abaMike Stump 3579f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // If the canonical form of this type isn't the right kind, reject it. 35803ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (!isa<T>(CanonicalType)) 3581f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek return 0; 358225cf760b54d3b88633827501013bc51a29b28abaMike Stump 35833ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // If this is a typedef for the type, strip the typedef off without 3584f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // losing all typedef information. 35850afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall return cast<T>(getUnqualifiedDesugaredType()); 358625cf760b54d3b88633827501013bc51a29b28abaMike Stump} 3587da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner 35884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner} // end namespace clang 35894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 35904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#endif 3591