Type.h revision 2350fb26d59692c6006ec5d33b8215e96055bdb6
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 27445c5e7c236f638b5a783dd5843c7a52b3d279a89Douglas Gregor bool isSupersetOf(Qualifiers Other) const; 27545c5e7c236f638b5a783dd5843c7a52b3d279a89Douglas Gregor 2763ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool operator==(Qualifiers Other) const { return Mask == Other.Mask; } 2773ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; } 2783ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2793ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall operator bool() const { return hasQualifiers(); } 2803ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2813ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers &operator+=(Qualifiers R) { 2823ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall addQualifiers(R); 2833ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return *this; 2843ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2853ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2863ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Union two qualifier sets. If an enumerated qualifier appears 2873ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // in both sets, use the one from the right. 2883ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall friend Qualifiers operator+(Qualifiers L, Qualifiers R) { 2893ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall L += R; 2903ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return L; 2913ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2923ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 2933ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall std::string getAsString() const; 2943ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall std::string getAsString(const PrintingPolicy &Policy) const { 2953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall std::string Buffer; 2963ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getAsStringInternal(Buffer, Policy); 2973ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Buffer; 2983ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 2993ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const; 3003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 3023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ID.AddInteger(Mask); 3033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 3043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallprivate: 3063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // bits: |0 1 2|3 .. 4|5 .. 31| 3083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // |C R V|GCAttr|AddrSpace| 3093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall uint32_t Mask; 3103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static const uint32_t GCAttrMask = 0x18; 3123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static const uint32_t GCAttrShift = 3; 3133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask); 3143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static const uint32_t AddressSpaceShift = 5; 3153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall}; 3163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// ExtQuals - We can encode up to three bits in the low bits of a 3193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// type pointer, but there are many more type qualifiers that we want 3203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// to be able to apply to an arbitrary type. Therefore we have this 3213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// struct, intended to be heap-allocated and used by QualType to 3223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// store qualifiers. 3233ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// 3243ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// The current design tags the 'const' and 'restrict' qualifiers in 3253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// two low bits on the QualType pointer; a third bit records whether 3263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// the pointer is an ExtQuals node. 'const' was chosen because it is 3273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// orders of magnitude more common than the other two qualifiers, in 3283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// both library and user code. It's relatively rare to see 3293ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// 'restrict' in user code, but many standard C headers are saturated 3303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// with 'restrict' declarations, so that representing them efficiently 3313ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// is a critical goal of this representation. 3323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallclass ExtQuals : public llvm::FoldingSetNode { 3333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // NOTE: changing the fast qualifiers should be straightforward as 3343ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // long as you don't make 'const' non-fast. 3353ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // 1. Qualifiers: 3363ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ). 3373ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Fast qualifiers must occupy the low-order bits. 3383ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // b) Update Qualifiers::FastWidth and FastMask. 3393ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // 2. QualType: 3403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // a) Update is{Volatile,Restrict}Qualified(), defined inline. 3413ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // b) Update remove{Volatile,Restrict}, defined near the end of 3423ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // this header. 3433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // 3. ASTContext: 3443ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // a) Update get{Volatile,Restrict}Type. 3453ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3463ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Context - the context to which this set belongs. We save this 3473ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// here so that QualifierCollector can use it to reapply extended 3483ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// qualifiers to an arbitrary type without requiring a context to 3493ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// be pushed through every single API dealing with qualifiers. 3503ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ASTContext& Context; 3513ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3523ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// BaseType - the underlying type that this qualifies 3533ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *BaseType; 3543ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3553ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Quals - the immutable set of qualifiers applied by this 3563ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// node; always contains extended qualifiers. 3573ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Quals; 3583ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3593ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallpublic: 3603ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ExtQuals(ASTContext& Context, const Type *Base, Qualifiers Quals) 3613ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Context(Context), BaseType(Base), Quals(Quals) 3623ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall { 3633ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(Quals.hasNonFastQualifiers() 3643ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall && "ExtQuals created with no fast qualifiers"); 3653ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!Quals.hasFastQualifiers() 3663ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall && "ExtQuals created with fast qualifiers"); 3673ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 3683ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3693ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers getQualifiers() const { return Quals; } 3703ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3713ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasVolatile() const { return Quals.hasVolatile(); } 3723ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3733ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); } 3743ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); } 3753ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3763ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall bool hasAddressSpace() const { return Quals.hasAddressSpace(); } 3773ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getAddressSpace() const { return Quals.getAddressSpace(); } 3783ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3793ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *getBaseType() const { return BaseType; } 38025cf760b54d3b88633827501013bc51a29b28abaMike Stump 3813ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ASTContext &getContext() const { return Context; } 3823ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3833ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallpublic: 3843ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void Profile(llvm::FoldingSetNodeID &ID) const { 3853ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Profile(ID, getBaseType(), Quals); 3863ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 3873ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, 3883ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *BaseType, 3893ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Quals) { 3903ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!"); 3913ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ID.AddPointer(BaseType); 3923ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Quals.Profile(ID); 3933ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 3943ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall}; 3953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 39631cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor/// CallingConv - Specifies the calling convention that a function uses. 39731cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregorenum CallingConv { 39831cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CC_Default, 39931cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CC_C, // __attribute__((cdecl)) 40031cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CC_X86StdCall, // __attribute__((stdcall)) 40101890a8487ae3330abc501b455e2092545d54775Douglas Gregor CC_X86FastCall, // __attribute__((fastcall)) 40201890a8487ae3330abc501b455e2092545d54775Douglas Gregor CC_X86ThisCall // __attribute__((thiscall)) 40331cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor}; 40431cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor 4053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 4063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on 4073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// their own: instead each reference to a type stores the qualifiers. This 4083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for 4093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// example we only need one for 'int', 'const int', 'volatile int', 4103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// 'const volatile int', etc). 4113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// 4123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// As an added efficiency bonus, instead of making this a pair, we 4133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// just store the two bits we care about in the low bits of the 4143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// pointer. To handle the packing/unpacking, we make QualType be a 4153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// simple wrapper class that acts like a smart pointer. A third bit 4163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// indicates whether there are extended qualifiers present, in which 4173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// case the pointer points to a special structure. 4183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallclass QualType { 4193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Thankfully, these are efficiently composable. 4203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>, 4213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers::FastWidth> Value; 4223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 4233ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *getExtQualsUnsafe() const { 4243ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Value.getPointer().get<const ExtQuals*>(); 4253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 4263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 4273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *getTypePtrUnsafe() const { 4283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Value.getPointer().get<const Type*>(); 4293ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 4303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 4314f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor QualType getUnqualifiedTypeSlow() const; 4324f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 4333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall friend class QualifierCollector; 4343ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallpublic: 43548a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner QualType() {} 43625cf760b54d3b88633827501013bc51a29b28abaMike Stump 43748a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner QualType(const Type *Ptr, unsigned Quals) 4383ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Value(Ptr, Quals) {} 4393ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType(const ExtQuals *Ptr, unsigned Quals) 4403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Value(Ptr, Quals) {} 4413ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 442c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor unsigned getLocalFastQualifiers() const { return Value.getInt(); } 443c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); } 4444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 4453ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Retrieves a pointer to the underlying (unqualified) type. 4463ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// This should really return a const Type, but it's not worth 4473ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// changing all the users right now. 4483ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Type *getTypePtr() const { 449c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalNonFastQualifiers()) 4503ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return const_cast<Type*>(getExtQualsUnsafe()->getBaseType()); 4513ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return const_cast<Type*>(getTypePtrUnsafe()); 4523ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 45325cf760b54d3b88633827501013bc51a29b28abaMike Stump 45448a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 4554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static QualType getFromOpaquePtr(void *Ptr) { 4564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType T; 45748a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner T.Value.setFromOpaqueValue(Ptr); 4584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T; 4594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 46025cf760b54d3b88633827501013bc51a29b28abaMike Stump 4614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Type &operator*() const { 4624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return *getTypePtr(); 4634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 4644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 4654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Type *operator->() const { 4664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return getTypePtr(); 4674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 46825cf760b54d3b88633827501013bc51a29b28abaMike Stump 4697480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall bool isCanonical() const; 4704ea8425c9601895fa137f877bc784f75f20adac6John McCall bool isCanonicalAsParam() const; 4717480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall 4724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isNull - Return true if this QualType doesn't point to a type yet. 4734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isNull() const { 4743ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Value.getPointer().isNull(); 4754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 4764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 477c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has the 478c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// "const" qualifier set, without looking through typedefs that may have 479c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// added "const" at a different level. 480c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool isLocalConstQualified() const { 481c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Const); 4823ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 483c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 484c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this type is const-qualified. 4854f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor bool isConstQualified() const; 486c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 487c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has the 488c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// "restrict" qualifier set, without looking through typedefs that may have 489c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// added "restrict" at a different level. 490c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool isLocalRestrictQualified() const { 491c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return (getLocalFastQualifiers() & Qualifiers::Restrict); 492c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor } 493c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 494c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this type is restrict-qualified. 4954f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor bool isRestrictQualified() const; 496c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 497c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has the 498c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// "volatile" qualifier set, without looking through typedefs that may have 499c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// added "volatile" at a different level. 500c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool isLocalVolatileQualified() const { 501c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return (hasLocalNonFastQualifiers() && getExtQualsUnsafe()->hasVolatile()); 5024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 5033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 504c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this type is volatile-qualified. 5054f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor bool isVolatileQualified() const; 506c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 507c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has any 508c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// qualifiers, without looking through any typedefs that might add 509c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// qualifiers at a different level. 510c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool hasLocalQualifiers() const { 511c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return getLocalFastQualifiers() || hasLocalNonFastQualifiers(); 5123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 514c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this type has any qualifiers. 5154f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor bool hasQualifiers() const; 516c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 517c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Determine whether this particular QualType instance has any 518c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType 519c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// instance. 520c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor bool hasLocalNonFastQualifiers() const { 521c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return Value.getPointer().is<const ExtQuals*>(); 5223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5233ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 524c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Retrieve the set of qualifiers local to this particular QualType 525c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// instance, not including any qualifiers acquired through typedefs or 526c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// other sugar. 527c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor Qualifiers getLocalQualifiers() const { 5283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers Quals; 529c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalNonFastQualifiers()) 5303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Quals = getExtQualsUnsafe()->getQualifiers(); 531c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor Quals.addFastQualifiers(getLocalFastQualifiers()); 5323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Quals; 5333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5343ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 535c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Retrieve the set of qualifiers applied to this type. 5364f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor Qualifiers getQualifiers() const; 537c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 538c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 539c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// local to this particular QualType instance, not including any qualifiers 540c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// acquired through typedefs or other sugar. 541c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor unsigned getLocalCVRQualifiers() const { 542c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor unsigned CVR = getLocalFastQualifiers(); 543c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (isLocalVolatileQualified()) 544c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor CVR |= Qualifiers::Volatile; 5453ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return CVR; 5464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 547a7bbf567dac9dfd58f12c9ff14584d64104694f3Nuno Lopes 548c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 549c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// applied to this type. 5504f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor unsigned getCVRQualifiers() const; 5516d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth 5526d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 5536d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth /// applied to this type, looking through any number of unqualified array 5546d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth /// types to their element types' qualifiers. 5556d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned getCVRQualifiersThroughArrayTypes() const; 5566d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth 5570afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isConstant(ASTContext& Ctx) const { 5580afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall return QualType::isConstant(*this, Ctx); 5590afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall } 56025cf760b54d3b88633827501013bc51a29b28abaMike Stump 5613ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Don't promise in the API that anything besides 'const' can be 5623ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // easily added. 5633ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 5643ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// addConst - add the specified type qualifier to this QualType. 5653ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addConst() { 5663ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall addFastQualifiers(Qualifiers::Const); 5673ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5683ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType withConst() const { 5693ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return withFastQualifiers(Qualifiers::Const); 5703ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5713ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 5723ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void addFastQualifiers(unsigned TQs) { 5733ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(TQs & ~Qualifiers::FastMask) 5743ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall && "non-fast qualifier bits set in mask!"); 5753ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Value.setInt(Value.getInt() | TQs); 5763ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5773ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 578c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor // FIXME: The remove* functions are semantically broken, because they might 579c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor // not remove a qualifier stored on a typedef. Most of the with* functions 580c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor // have the same problem. 5813ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeConst(); 5823ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeVolatile(); 5833ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeRestrict(); 5843ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeCVRQualifiers(unsigned Mask); 5853ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 5863ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeFastQualifiers() { Value.setInt(0); } 5873ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void removeFastQualifiers(unsigned Mask) { 5883ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers"); 5893ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Value.setInt(Value.getInt() & ~Mask); 5903ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 5914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5923ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Creates a type with the given qualifiers in addition to any 5933ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // qualifiers already on this type. 5943ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType withFastQualifiers(unsigned TQs) const { 5953ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType T = *this; 5963ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall T.addFastQualifiers(TQs); 5973ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return T; 5983ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 59993eb82549eec82d75ce5dd3afbeeaf6fdb0e2a27Sanjiv Gupta 6003ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Creates a type with exactly the given fast qualifiers, removing 6013ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // any existing fast qualifiers. 6023ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType withExactFastQualifiers(unsigned TQs) const { 6033ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return withoutFastQualifiers().withFastQualifiers(TQs); 6044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 6063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Removes fast qualifiers, but leaves any extended qualifiers in place. 6073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType withoutFastQualifiers() const { 6083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType T = *this; 6093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall T.removeFastQualifiers(); 6103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return T; 611a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner } 6124b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis 613c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Return this type with all of the instance-specific qualifiers 614c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// removed, but without removing any qualifiers that may have been applied 615c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// through typedefs. 616c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); } 61725cf760b54d3b88633827501013bc51a29b28abaMike Stump 618c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// \brief Return the unqualified form of the given type, which might be 619c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor /// desugared to eliminate qualifiers introduced via typedefs. 6204f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor QualType getUnqualifiedType() const { 6214f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor QualType T = getLocalUnqualifiedType(); 6224f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor if (!T.hasQualifiers()) 6234f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return T; 6244f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 6254f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return getUnqualifiedTypeSlow(); 626c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor } 627c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor 6283fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 6293fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 6303fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor QualType getNonReferenceType() const; 63125cf760b54d3b88633827501013bc51a29b28abaMike Stump 6322350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor /// \brief Determine the type of a (typically non-lvalue) expression with the 6332350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor /// specified result type. 6348079eee9128444d02bebf24410126f9d55399f84Douglas Gregor /// 6352350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor /// This routine should be used for expressions for which the return type is 6362350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor /// explicitly specified (e.g., in a cast or call) and isn't necessarily 6372350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor /// an lvalue. It removes a top-level reference (since there are no 6388079eee9128444d02bebf24410126f9d55399f84Douglas Gregor /// expressions of reference type) and deletes top-level cvr-qualifiers 6398079eee9128444d02bebf24410126f9d55399f84Douglas Gregor /// from non-class types (in C++) or all types (in C). 6402350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor QualType getNonLValueExprType(ASTContext &Context) const; 6418079eee9128444d02bebf24410126f9d55399f84Douglas Gregor 642835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 643835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 644835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 645835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 646835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 647835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// concrete. 6483ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// 6493ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Qualifiers are left in place. 6500afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType getDesugaredType() const { 6510afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall return QualType::getDesugaredType(*this); 6520afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall } 6536573cfd6fc32eab0b696cfc318bb21f4e3933f35Douglas Gregor 6544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// operator==/!= - Indicate whether the specified types and qualifiers are 6554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// identical. 656cfe6ae592450d8466b4d78b59ff4526266549a9aDouglas Gregor friend bool operator==(const QualType &LHS, const QualType &RHS) { 657cfe6ae592450d8466b4d78b59ff4526266549a9aDouglas Gregor return LHS.Value == RHS.Value; 6584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 659cfe6ae592450d8466b4d78b59ff4526266549a9aDouglas Gregor friend bool operator!=(const QualType &LHS, const QualType &RHS) { 660cfe6ae592450d8466b4d78b59ff4526266549a9aDouglas Gregor return LHS.Value != RHS.Value; 6614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6623bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor std::string getAsString() const; 6633bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor 6643bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor std::string getAsString(const PrintingPolicy &Policy) const { 6654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner std::string S; 6663bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor getAsStringInternal(S, Policy); 6674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return S; 6684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6697099c789f054f1e7480f498d60aa94b0326c285fChris Lattner void getAsStringInternal(std::string &Str, 6707099c789f054f1e7480f498d60aa94b0326c285fChris Lattner const PrintingPolicy &Policy) const; 67125cf760b54d3b88633827501013bc51a29b28abaMike Stump 672a55e321bd645398b514e246981c04a4889ee2472Chris Lattner void dump(const char *s) const; 673a55e321bd645398b514e246981c04a4889ee2472Chris Lattner void dump() const; 67425cf760b54d3b88633827501013bc51a29b28abaMike Stump 6759d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 6769d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 6779d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek } 6784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6792a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb /// getAddressSpace - Return the address space of this type. 6802a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb inline unsigned getAddressSpace() const; 68125cf760b54d3b88633827501013bc51a29b28abaMike Stump 682af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 6833ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall inline Qualifiers::GC getObjCGCAttr() const; 68485534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian 68585534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 68685534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian bool isObjCGCWeak() const { 6873ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return getObjCGCAttr() == Qualifiers::Weak; 68885534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian } 68985534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian 69085534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 69185534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian bool isObjCGCStrong() const { 6923ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return getObjCGCAttr() == Qualifiers::Strong; 69385534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian } 6941bb806498909a43a7829edb21c42606335d69694Mike Stump 6950afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCallprivate: 6960afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall // These methods are implemented in a separate translation unit; 6970afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall // "static"-ize them to avoid creating temporary QualTypes in the 6980afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall // caller. 6990afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall static bool isConstant(QualType T, ASTContext& Ctx); 7000afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall static QualType getDesugaredType(QualType T); 7014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 7024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 7034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner} // end clang. 7044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 7054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace llvm { 7064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 7074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// to a specific Type class. 7084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnertemplate<> struct simplify_type<const ::clang::QualType> { 7094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner typedef ::clang::Type* SimpleType; 7104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 7114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return Val.getTypePtr(); 7124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 7134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 7144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnertemplate<> struct simplify_type< ::clang::QualType> 7154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner : public simplify_type<const ::clang::QualType> {}; 71625cf760b54d3b88633827501013bc51a29b28abaMike Stump 717cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 718cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattnertemplate<> 719d776b2da9bd694c41f1506e152aeb35d1babeba6Chris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 720cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattnerpublic: 721cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 722cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner return P.getAsOpaquePtr(); 723cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner } 724cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 725cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner return clang::QualType::getFromOpaquePtr(P); 726cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner } 7273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Various qualifiers go in low bits. 728e41419144a0a01456f5426efcd9b919f68284527Chris Lattner enum { NumLowBitsAvailable = 0 }; 729cdd67caf66a2aa1a95da3ed9726bea7a3659b35bChris Lattner}; 73025cf760b54d3b88633827501013bc51a29b28abaMike Stump 73178f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek} // end namespace llvm 7324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 7334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace clang { 7344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 7354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Type - This is the base class of the type hierarchy. A central concept 7364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// with types is that each type always has a canonical type. A canonical type 7374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// is the type with any typedef names stripped out of it or the types it 7384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// references. For example, consider: 7394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// typedef int foo; 7414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// typedef foo* bar; 7424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'int *' 'foo *' 'bar' 7434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// There will be a Type object created for 'int'. Since int is canonical, its 7454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 7464fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 7474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// there is a PointerType that represents 'int*', which, like 'int', is 7484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 7494fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 7504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// is also 'int*'. 7514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Non-canonical types are useful for emitting diagnostics, without losing 7534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// information about typedefs being used. Canonical types are useful for type 7544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// comparisons (they allow by-pointer equality tests) and useful for reasoning 7554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// about whether something has a particular form (e.g. is a function type), 7564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// because they implicitly, recursively, strip all typedefs out of a type. 7574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Types, once created, are immutable. 7594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 7604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass Type { 7614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 7624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum TypeClass { 7634fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define TYPE(Class, Base) Class, 764d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall#define LAST_TYPE(Class) TypeLast = Class, 7654fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 7664fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#include "clang/AST/TypeNodes.def" 7674fa58905062efa6a12137b1983a1367220182a20Douglas Gregor TagFirst = Record, TagLast = Enum 7684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 769fd3d5fdac0d25464e1b9c36bc646965494d44f66Argiris Kirtzidis 7704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 771f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall Type(const Type&); // DO NOT IMPLEMENT. 772f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall void operator=(const Type&); // DO NOT IMPLEMENT. 773f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 7744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType CanonicalType; 7754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 7764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 777d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall unsigned TC : 8; 778d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall 779d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 7804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Note that this should stay at the end of the ivars for Type so that 7814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// subclasses can pack their bitfields into the same word. 782d665afdb7e5fdcb4a295c91863cc13c90c3bf4c4John McCall bool Dependent : 1; 783949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 784949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor /// \brief Whether the linkage of this type is already known. 785949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor mutable bool LinkageKnown : 1; 786949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 787949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor /// \brief Linkage of this type. 788949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor mutable unsigned CachedLinkage : 2; 789949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 7904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 791949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor /// \brief Compute the linkage of this type. 792949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 793949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 794949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor enum { BitsRemainingInType = 20 }; 795f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 7967c6f0c755e48a2782bc0a0a4cfc63dc84e0f11d5Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 7977c6f0c755e48a2782bc0a0a4cfc63dc84e0f11d5Hartmut Kaiser Type *this_() { return this; } 7981b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 79935fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 800949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor TC(tc), Dependent(dependent), LinkageKnown(false), 801949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor CachedLinkage(NoLinkage) {} 8021b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual ~Type() {} 803db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek virtual void Destroy(ASTContext& C); 8044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; 80525cf760b54d3b88633827501013bc51a29b28abaMike Stump 8064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 80792803daaa6a40a3899c2e599bddc42732c2ce593Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 80825cf760b54d3b88633827501013bc51a29b28abaMike Stump 8097480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall bool isCanonicalUnqualified() const { 8107480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall return CanonicalType.getTypePtr() == this; 8117480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall } 8124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 81325cf760b54d3b88633827501013bc51a29b28abaMike Stump /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 8144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// object types, function types, and incomplete types. 81525cf760b54d3b88633827501013bc51a29b28abaMike Stump 81626ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// \brief Determines whether the type describes an object in memory. 81726ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// 81826ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// Note that this definition of object type corresponds to the C++ 81926ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// definition of object type, which includes incomplete types, as 82026ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// opposed to the C definition (which does not include incomplete 82126ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// types). 8224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isObjectType() const; 8234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 8244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isIncompleteType - Return true if this is an incomplete type. 8254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// A type that can describe objects, but which lacks information needed to 8264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// determine its size (e.g. void, or a fwd declared struct). Clients of this 82725cf760b54d3b88633827501013bc51a29b28abaMike Stump /// routine will need to determine if the size is actually required. 8284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isIncompleteType() const; 8299db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner 8309db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 8319db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner /// type, in other words, not a function type. 8329db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner bool isIncompleteOrObjectType() const { 8339db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner return !isFunctionType(); 8349db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner } 83539c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl 83639c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 83739c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl bool isPODType() const; 83839c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl 83975067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl /// isLiteralType - Return true if this is a literal type 84075067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl /// (C++0x [basic.types]p10) 84175067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl bool isLiteralType() const; 84275067d2c35093b2c9cd4f96a3d5e2df0b5383d17Sebastian Redl 8435eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 8445eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff /// types that have a non-constant expression. This does not include "[]". 8455eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff bool isVariablyModifiedType() const; 84625cf760b54d3b88633827501013bc51a29b28abaMike Stump 8474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Helper methods to distinguish type categories. All type predicates 8482a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 849c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar 850522fb671290dd5462bfd819401768686fa53e925Tom Care /// isBuiltinType - returns true if the type is a builtin type. 851522fb671290dd5462bfd819401768686fa53e925Tom Care bool isBuiltinType() const; 852522fb671290dd5462bfd819401768686fa53e925Tom Care 853c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 854c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 85525cf760b54d3b88633827501013bc51a29b28abaMike Stump 8568888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 8578888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 8584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 8598d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isEnumeralType() const; 8608d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isBooleanType() const; 8618d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isCharType() const; 8621815b3bfc1382c88bee771bd158755b2426f0780Douglas Gregor bool isWideCharType() const; 863da86f093507a7733ae955d7511b88f8bf4f61752Douglas Gregor bool isAnyCharacterType() const; 8647fcbab0d9ed96afbdcc3dd4ad876bcbf452fd25fDouglas Gregor bool isIntegralType(ASTContext &Ctx) const; 865da86f093507a7733ae955d7511b88f8bf4f61752Douglas Gregor 86659327f06fa557d652e0560e6895c93db70ea5ec7Douglas Gregor /// \brief Determine whether this type is an integral or enumeration type. 86759327f06fa557d652e0560e6895c93db70ea5ec7Douglas Gregor bool isIntegralOrEnumerationType() const; 86859327f06fa557d652e0560e6895c93db70ea5ec7Douglas Gregor 8694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Floating point categories. 8704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 8714300121ffff80d4b23d17689930e2aa2a83086b9Steve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 8724300121ffff80d4b23d17689930e2aa2a83086b9Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 8734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isComplexType() const; // C99 6.2.5p11 (complex) 8743277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 8754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 8764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 8774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 878e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isVoidType() const; // C99 6.2.5p19 879e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isDerivedType() const; // C99 6.2.5p20 880e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 881e7ef500151147ba851db502fc4d36319f863db80Douglas Gregor bool isAggregateType() const; 88225cf760b54d3b88633827501013bc51a29b28abaMike Stump 883e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner // Type Predicates: Check to see if this type is structurally the specified 8842a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb // type, ignoring typedefs and qualifiers. 885e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isFunctionType() const; 886cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } 887cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } 8887931f4a186bc76b21dd4629ee74d64264a7fb8a2Chris Lattner bool isPointerType() const; 88979ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroff bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 8907aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff bool isBlockPointerType() const; 8915ca84bccd83982d3941d68dd88139ca43f6322a0Steve Naroff bool isVoidPointerType() const; 892f0c4a0a830c9154b1ae72e497c2ce586c10e9b71Chris Lattner bool isReferenceType() const; 893ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl bool isLValueReferenceType() const; 894ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl bool isRValueReferenceType() const; 895cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner bool isFunctionPointerType() const; 8967555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl bool isMemberPointerType() const; 8977555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl bool isMemberFunctionPointerType() const; 898e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isArrayType() const; 899a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isConstantArrayType() const; 900a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isIncompleteArrayType() const; 901a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isVariableArrayType() const; 9021b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool isDependentSizedArrayType() const; 903e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isRecordType() const; 90425cf760b54d3b88633827501013bc51a29b28abaMike Stump bool isClassType() const; 90525cf760b54d3b88633827501013bc51a29b28abaMike Stump bool isStructureType() const; 9066cb535784c071d1a662aeac8e548e8757dd1a969Douglas Gregor bool isStructureOrClassType() const; 90736e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff bool isUnionType() const; 908b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 909b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isVectorType() const; // GCC vector type. 910af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman bool isExtVectorType() const; // Extended vector type. 911c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 912329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // FIXME: change this to 'raw' interface type, so we can used 'interface' type 913329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // for the common case. 914f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCObjectType() const; // NSString or typeof(*(id)0) 915b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 916b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCQualifiedIdType() const; // id<foo> 91727bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff bool isObjCQualifiedClassType() const; // Class<foo> 918329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCIdType() const; // id 919329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCClassType() const; // Class 920a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian bool isObjCSelType() const; // Class 9217bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff bool isObjCBuiltinType() const; // 'id' or 'Class' 922dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 9235d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 9241b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 9251b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 92625cf760b54d3b88633827501013bc51a29b28abaMike Stump /// that its definition somehow depends on a template parameter 9271b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// (C++ [temp.dep.type]). 9281b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool isDependentType() const { return Dependent; } 92900fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor bool isOverloadableType() const; 930dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 931ec6d392c816684e9679a3d04f742fa3991f5fe1eDouglas Gregor /// \brief Determine wither this type is a C++ elaborated-type-specifier. 932ec6d392c816684e9679a3d04f742fa3991f5fe1eDouglas Gregor bool isElaboratedTypeSpecifier() const; 933ec6d392c816684e9679a3d04f742fa3991f5fe1eDouglas Gregor 934fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 935fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 936fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 9375d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl /// interface types, as well as nullptr_t. 938fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar bool hasPointerRepresentation() const; 939fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar 9407c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 9417c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 94225cf760b54d3b88633827501013bc51a29b28abaMike Stump bool hasObjCPointerRepresentation() const; 9437c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian 9441a7c1b12a61ed17f914c9d557dd6666e0253c133Douglas Gregor /// \brief Determine whether this type has a floating-point representation 9451a7c1b12a61ed17f914c9d557dd6666e0253c133Douglas Gregor /// of some sort, e.g., it is a floating-point type or a vector thereof. 9461a7c1b12a61ed17f914c9d557dd6666e0253c133Douglas Gregor bool hasFloatingRepresentation() const; 9471a7c1b12a61ed17f914c9d557dd6666e0253c133Douglas Gregor 948e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner // Type Checking Functions: Check to see if this type is structurally the 94935fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 95035fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner // the best type we can. 9515c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek const RecordType *getAsStructureType() const; 9521b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 953e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner const RecordType *getAsUnionType() const; 95436e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 955329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // The following is a convenience method that returns an ObjCObjectPointerType 956329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff // for object declared using an interface. 957329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 958329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 959f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall const ObjCObjectType *getAsObjCQualifiedInterfaceType() const; 96090e18745436d0889e8bb7fba650263b38f05694eFariborz Jahanian const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 96125cf760b54d3b88633827501013bc51a29b28abaMike Stump 96295c54dfa43c5159d2854910c21cc03374238e94eDouglas Gregor /// \brief Retrieves the CXXRecordDecl that this type refers to, either 96395c54dfa43c5159d2854910c21cc03374238e94eDouglas Gregor /// because the type is a RecordType or because it is the injected-class-name 96495c54dfa43c5159d2854910c21cc03374238e94eDouglas Gregor /// type of a class template or class template partial specialization. 96595c54dfa43c5159d2854910c21cc03374238e94eDouglas Gregor CXXRecordDecl *getAsCXXRecordDecl() const; 96695c54dfa43c5159d2854910c21cc03374238e94eDouglas Gregor 967f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // Member-template getAs<specific type>'. This scheme will eventually 968f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // replace the specific getAsXXXX methods above. 969cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall // 970cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall // There are some specializations of this member template listed 971cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall // immediately following this class. 972f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek template <typename T> const T *getAs() const; 97325cf760b54d3b88633827501013bc51a29b28abaMike Stump 974a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 975a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// element type of the array, potentially with type qualifiers missing. 976a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// This method should never be used when type qualifiers are meaningful. 977a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 97825cf760b54d3b88633827501013bc51a29b28abaMike Stump 979898111463b64a26d55af56474ad8cca1fdb76268Steve Naroff /// getPointeeType - If this is a pointer, ObjC object pointer, or block 980898111463b64a26d55af56474ad8cca1fdb76268Steve Naroff /// pointer, this returns the respective pointee. 981329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff QualType getPointeeType() const; 98225cf760b54d3b88633827501013bc51a29b28abaMike Stump 9830afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// getUnqualifiedDesugaredType() - Return the specified type with 9840afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// any "sugar" removed from the type, removing any typedefs, 9850afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// typeofs, etc., as well as any qualifiers. 9860afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall const Type *getUnqualifiedDesugaredType() const; 98725cf760b54d3b88633827501013bc51a29b28abaMike Stump 9884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// More type predicates useful for type checking/promotion 9894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isPromotableIntegerType() const; // C99 6.3.1.1p2 9904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isSignedIntegerType - Return true if this is an integer type that is 992bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 993bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 994bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// integer element type. 9954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isSignedIntegerType() const; 9964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isUnsignedIntegerType - Return true if this is an integer type that is 998bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 999bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 1000bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// element type. 10014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isUnsignedIntegerType() const; 1002bbe686be29157b575e53fbed328613117b525f26Chris Lattner 10034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isConstantSizeType - Return true if this is not a variable sized type, 10040448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 10050448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner /// incomplete types. 100662f67fd7f670f1a8b222c6565b257c05e8e80faeEli Friedman bool isConstantSizeType() const; 1007a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner 100884bca951282f362c439cc7993fcb4d145384e416Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 100984bca951282f362c439cc7993fcb4d145384e416Eli Friedman /// set of type specifiers. 101084bca951282f362c439cc7993fcb4d145384e416Eli Friedman bool isSpecifierType() const; 101184bca951282f362c439cc7993fcb4d145384e416Eli Friedman 1012b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor /// \brief Determine the linkage of this type. 1013949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor Linkage getLinkage() const; 1014949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1015949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor /// \brief Note that the linkage is no longer known. 1016949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor void ClearLinkageCache(); 1017949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1018949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor const char *getTypeClassName() const; 1019b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 1020cc392fc654e59b8d55df3901a82b193845ee44f4John McCall QualType getCanonicalTypeInternal() const { 1021cc392fc654e59b8d55df3901a82b193845ee44f4John McCall return CanonicalType; 1022cc392fc654e59b8d55df3901a82b193845ee44f4John McCall } 1023cc392fc654e59b8d55df3901a82b193845ee44f4John McCall CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h 1024a55e321bd645398b514e246981c04a4889ee2472Chris Lattner void dump() const; 10254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *) { return true; } 1026b69c35fbf8635a267215a83b4e9fd980019f003aArgiris Kirtzidis 1027b69c35fbf8635a267215a83b4e9fd980019f003aArgiris Kirtzidis friend class PCHReader; 1028b69c35fbf8635a267215a83b4e9fd980019f003aArgiris Kirtzidis friend class PCHWriter; 10294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 10304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1031cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCalltemplate <> inline const TypedefType *Type::getAs() const { 1032cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall return dyn_cast<TypedefType>(this); 1033cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall} 1034cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall 1035cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall// We can do canonical leaf types faster, because we don't have to 1036cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall// worry about preserving child type decoration. 1037cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall#define TYPE(Class, Base) 1038cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall#define LEAF_TYPE(Class) \ 1039cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCalltemplate <> inline const Class##Type *Type::getAs() const { \ 10403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return dyn_cast<Class##Type>(CanonicalType); \ 1041cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall} 1042cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall#include "clang/AST/TypeNodes.def" 1043cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall 1044cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall 10454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// BuiltinType - This class is used for builtin types like 'int'. Builtin 10464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types are always canonical and have a literal name field. 10474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass BuiltinType : public Type { 10484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 10494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum Kind { 10504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Void, 105125cf760b54d3b88633827501013bc51a29b28abaMike Stump 10524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Bool, // This is bool and/or _Bool. 10534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Char_U, // This is 'char' for targets where char is unsigned. 10544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UChar, // This is explicitly qualified unsigned char. 10552bcacb61cf94b71e5c87f29d517f8dc29fe3993eAlisdair Meredith Char16, // This is 'char16_t' for C++. 10562bcacb61cf94b71e5c87f29d517f8dc29fe3993eAlisdair Meredith Char32, // This is 'char32_t' for C++. 10574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UShort, 10584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UInt, 10594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ULong, 10604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ULongLong, 10616cc7e415d42291bf01e0295d9d6344e106613c48Chris Lattner UInt128, // __uint128_t 106225cf760b54d3b88633827501013bc51a29b28abaMike Stump 10634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Char_S, // This is 'char' for targets where char is signed. 10644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner SChar, // This is explicitly qualified signed char. 106585bd81edce4057156d7f49408147f07daa675096Argiris Kirtzidis WChar, // This is 'wchar_t' for C++. 10664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Short, 10674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Int, 10684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Long, 10694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner LongLong, 10706cc7e415d42291bf01e0295d9d6344e106613c48Chris Lattner Int128, // __int128_t 107125cf760b54d3b88633827501013bc51a29b28abaMike Stump 1072d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor Float, Double, LongDouble, 1073d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor 10745d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 10755d0ead717d57405b4a3b34a55b77579ea8b2774eSebastian Redl 10761b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Overload, // This represents the type of an overloaded function declaration. 10774a8498cc0f251e839912285112a014a5d1248648Anders Carlsson Dependent, // This represents the type of a type-dependent expression. 107825cf760b54d3b88633827501013bc51a29b28abaMike Stump 10797bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff UndeducedAuto, // In C++0x, this represents the type of an auto variable 10804a8498cc0f251e839912285112a014a5d1248648Anders Carlsson // that has not been deduced yet. 1081cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 1082cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// The primitive Objective C 'id' type. The type pointed to by the 1083cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// user-visible 'id' type. Only ever shows up in an AST as the base 1084cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// type of an ObjCObjectType. 1085cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall ObjCId, 1086cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 1087cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// The primitive Objective C 'Class' type. The type pointed to by the 1088cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// user-visible 'Class' type. Only ever shows up in an AST as the 1089cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// base type of an ObjCObjectType. 1090cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall ObjCClass, 1091cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 1092a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian ObjCSel // This represents the ObjC 'SEL' type. 10934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 10944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 10954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Kind TypeKind; 1096949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1097949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 1098949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1099949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 11004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 110125cf760b54d3b88633827501013bc51a29b28abaMike Stump BuiltinType(Kind K) 110225cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 11031b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor TypeKind(K) {} 110425cf760b54d3b88633827501013bc51a29b28abaMike Stump 11054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Kind getKind() const { return TypeKind; } 11067099c789f054f1e7480f498d60aa94b0326c285fChris Lattner const char *getName(const LangOptions &LO) const; 110725cf760b54d3b88633827501013bc51a29b28abaMike Stump 11080afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 11090afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 11100afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1111afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isInteger() const { 1112afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Bool && TypeKind <= Int128; 1113afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1114afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1115afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isSignedInteger() const { 1116afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Char_S && TypeKind <= Int128; 1117afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1118afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1119afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isUnsignedInteger() const { 1120afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Bool && TypeKind <= UInt128; 1121afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1122afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1123afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall bool isFloatingPoint() const { 1124afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall return TypeKind >= Float && TypeKind <= LongDouble; 1125afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1126afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 11274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 11284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const BuiltinType *) { return true; } 11294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 11304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 11324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types (_Complex float etc) as well as the GCC integer complex extensions. 11334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 11344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass ComplexType : public Type, public llvm::FoldingSetNode { 11354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ElementType; 11364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ComplexType(QualType Element, QualType CanonicalPtr) : 113725cf760b54d3b88633827501013bc51a29b28abaMike Stump Type(Complex, CanonicalPtr, Element->isDependentType()), 11381b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ElementType(Element) { 11394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1141949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1142949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 1143949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1144949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 11454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 11464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getElementType() const { return ElementType; } 114725cf760b54d3b88633827501013bc51a29b28abaMike Stump 11480afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 11490afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 11500afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 11514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 11524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getElementType()); 11534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 11554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Element.getAsOpaquePtr()); 11564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 115725cf760b54d3b88633827501013bc51a29b28abaMike Stump 11584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 11594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const ComplexType *) { return true; } 11604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 11614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1162554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 1163cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner/// 1164554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 1165cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner QualType PointeeType; 11664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner PointerType(QualType Pointee, QualType CanonicalPtr) : 1168554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 11694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1171949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1172949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 1173949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1174949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 11754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 117625cf760b54d3b88633827501013bc51a29b28abaMike Stump 1177554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 1178554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 11790afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 11800afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 11810afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 11824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 11834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getPointeeType()); 11844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 11864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Pointee.getAsOpaquePtr()); 11874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 118825cf760b54d3b88633827501013bc51a29b28abaMike Stump 11894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 11904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const PointerType *) { return true; } 11914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 11924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11937aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// BlockPointerType - pointer to a block type. 11947aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// This type is to represent types syntactically represented as 11957aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 11967aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// 11977aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 11987aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 11997aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 120025cf760b54d3b88633827501013bc51a29b28abaMike Stump Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 12011b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor PointeeType(Pointee) { 12027aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 12037aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff friend class ASTContext; // ASTContext creates these. 1204949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1205949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 1206949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1207949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 12087aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffpublic: 120925cf760b54d3b88633827501013bc51a29b28abaMike Stump 12107aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 12117aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff QualType getPointeeType() const { return PointeeType; } 12127aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 12130afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 12140afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 12150afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 12167aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 12177aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff Profile(ID, getPointeeType()); 12187aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 12197aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 12207aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 12217aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 122225cf760b54d3b88633827501013bc51a29b28abaMike Stump 122325cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 122425cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == BlockPointer; 12257aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 12267aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 12277aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff}; 12287aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 1229ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 12304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 1231554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 1232554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar QualType PointeeType; 1233554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 12344ea8425c9601895fa137f877bc784f75f20adac6John McCall /// True if the type was originally spelled with an lvalue sigil. 12354ea8425c9601895fa137f877bc784f75f20adac6John McCall /// This is never true of rvalue references but can also be false 12364ea8425c9601895fa137f877bc784f75f20adac6John McCall /// on lvalue references because of C++0x [dcl.typedef]p9, 12374ea8425c9601895fa137f877bc784f75f20adac6John McCall /// as follows: 12384ea8425c9601895fa137f877bc784f75f20adac6John McCall /// 12394ea8425c9601895fa137f877bc784f75f20adac6John McCall /// typedef int &ref; // lvalue, spelled lvalue 12404ea8425c9601895fa137f877bc784f75f20adac6John McCall /// typedef int &&rvref; // rvalue 12414ea8425c9601895fa137f877bc784f75f20adac6John McCall /// ref &a; // lvalue, inner ref, spelled lvalue 12424ea8425c9601895fa137f877bc784f75f20adac6John McCall /// ref &&a; // lvalue, inner ref 12434ea8425c9601895fa137f877bc784f75f20adac6John McCall /// rvref &a; // lvalue, inner ref, spelled lvalue 12444ea8425c9601895fa137f877bc784f75f20adac6John McCall /// rvref &&a; // rvalue, inner ref 12454ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue; 12464ea8425c9601895fa137f877bc784f75f20adac6John McCall 12474ea8425c9601895fa137f877bc784f75f20adac6John McCall /// True if the inner type is a reference type. This only happens 12484ea8425c9601895fa137f877bc784f75f20adac6John McCall /// in non-canonical forms. 12494ea8425c9601895fa137f877bc784f75f20adac6John McCall bool InnerRef; 12504ea8425c9601895fa137f877bc784f75f20adac6John McCall 1251ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlprotected: 12524ea8425c9601895fa137f877bc784f75f20adac6John McCall ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, 12534ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue) : 1254ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl Type(tc, CanonicalRef, Referencee->isDependentType()), 12554ea8425c9601895fa137f877bc784f75f20adac6John McCall PointeeType(Referencee), SpelledAsLValue(SpelledAsLValue), 12564ea8425c9601895fa137f877bc784f75f20adac6John McCall InnerRef(Referencee->isReferenceType()) { 12574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1258949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1259949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1260949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 12614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 12624ea8425c9601895fa137f877bc784f75f20adac6John McCall bool isSpelledAsLValue() const { return SpelledAsLValue; } 1263f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor bool isInnerRef() const { return InnerRef; } 1264f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor 12654ea8425c9601895fa137f877bc784f75f20adac6John McCall QualType getPointeeTypeAsWritten() const { return PointeeType; } 12664ea8425c9601895fa137f877bc784f75f20adac6John McCall QualType getPointeeType() const { 12674ea8425c9601895fa137f877bc784f75f20adac6John McCall // FIXME: this might strip inner qualifiers; okay? 12684ea8425c9601895fa137f877bc784f75f20adac6John McCall const ReferenceType *T = this; 12694ea8425c9601895fa137f877bc784f75f20adac6John McCall while (T->InnerRef) 12704ea8425c9601895fa137f877bc784f75f20adac6John McCall T = T->PointeeType->getAs<ReferenceType>(); 12714ea8425c9601895fa137f877bc784f75f20adac6John McCall return T->PointeeType; 12724ea8425c9601895fa137f877bc784f75f20adac6John McCall } 1273554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 12744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 12754ea8425c9601895fa137f877bc784f75f20adac6John McCall Profile(ID, PointeeType, SpelledAsLValue); 12764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 12774ea8425c9601895fa137f877bc784f75f20adac6John McCall static void Profile(llvm::FoldingSetNodeID &ID, 12784ea8425c9601895fa137f877bc784f75f20adac6John McCall QualType Referencee, 12794ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue) { 12804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Referencee.getAsOpaquePtr()); 12814ea8425c9601895fa137f877bc784f75f20adac6John McCall ID.AddBoolean(SpelledAsLValue); 12824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 12834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1284ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 1285ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == LValueReference || 1286ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl T->getTypeClass() == RValueReference; 1287ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 12884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const ReferenceType *) { return true; } 1289ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl}; 1290ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl 1291ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 1292ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// 1293ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlclass LValueReferenceType : public ReferenceType { 12944ea8425c9601895fa137f877bc784f75f20adac6John McCall LValueReferenceType(QualType Referencee, QualType CanonicalRef, 12954ea8425c9601895fa137f877bc784f75f20adac6John McCall bool SpelledAsLValue) : 12964ea8425c9601895fa137f877bc784f75f20adac6John McCall ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue) 12974ea8425c9601895fa137f877bc784f75f20adac6John McCall {} 1298ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl friend class ASTContext; // ASTContext creates these 1299ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlpublic: 13000afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 13010afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 13020afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1303ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 1304ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == LValueReference; 1305ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 1306ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 1307ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl}; 1308ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl 1309ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 1310ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// 1311ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlclass RValueReferenceType : public ReferenceType { 1312ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 13134ea8425c9601895fa137f877bc784f75f20adac6John McCall ReferenceType(RValueReference, Referencee, CanonicalRef, false) { 1314ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 1315ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl friend class ASTContext; // ASTContext creates these 1316ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlpublic: 13170afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 13180afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 13190afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 1320ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 1321ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == RValueReference; 1322ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 1323ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 13247555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl}; 13257555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 13267555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 13277555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl/// 13287555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 13297555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl QualType PointeeType; 13307555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 13317555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 13327555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *Class; 13337555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 13347555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 13357555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Type(MemberPointer, CanonicalPtr, 13367555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Cls->isDependentType() || Pointee->isDependentType()), 13377555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl PointeeType(Pointee), Class(Cls) { 13387555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 13397555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl friend class ASTContext; // ASTContext creates these. 1340949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1341949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 1342949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1343949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 13447555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlpublic: 13457555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 13467555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl QualType getPointeeType() const { return PointeeType; } 13477555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 13487555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *getClass() const { return Class; } 13497555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 13500afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 13510afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 13520afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 13537555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 13547555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Profile(ID, getPointeeType(), getClass()); 13557555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 13567555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 13577555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *Class) { 13587555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 13597555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl ID.AddPointer(Class); 13607555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 13617555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 13627555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static bool classof(const Type *T) { 13637555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return T->getTypeClass() == MemberPointer; 13647555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 13657555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static bool classof(const MemberPointerType *) { return true; } 13664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 13674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 13684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ArrayType - C99 6.7.5.2 - Array Declarators. 13694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 1370c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 13714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 13724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 13731b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 13741b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// with a star size (e.g. int X[*]). 13751b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// 'static' is only allowed on function parameters. 13764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum ArraySizeModifier { 13774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Normal, Static, Star 13784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 13794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 138083c13010359c33354c581acee65d0c986a75247eSteve Naroff /// ElementType - The element type of the array. 138183c13010359c33354c581acee65d0c986a75247eSteve Naroff QualType ElementType; 138225cf760b54d3b88633827501013bc51a29b28abaMike Stump 1383dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 138424c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 1385dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek unsigned SizeModifier : 2; 138625cf760b54d3b88633827501013bc51a29b28abaMike Stump 138724c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 138824c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// 'int X[static restrict 4]'. For function parameters only. 138924c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff unsigned IndexTypeQuals : 3; 139025cf760b54d3b88633827501013bc51a29b28abaMike Stump 139183c13010359c33354c581acee65d0c986a75247eSteve Naroffprotected: 13921b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // C++ [temp.dep.type]p1: 13931b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // A type is dependent if it is... 13941b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // - an array type constructed from any dependent type or whose 13951b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // size is specified by a constant expression that is 13961b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // value-dependent, 139724c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 139824c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArraySizeModifier sm, unsigned tq) 13991b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 14001b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 14011b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 140283c13010359c33354c581acee65d0c986a75247eSteve Naroff friend class ASTContext; // ASTContext creates these. 1403949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1404949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1405949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 140683c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic: 140783c13010359c33354c581acee65d0c986a75247eSteve Naroff QualType getElementType() const { return ElementType; } 1408dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek ArraySizeModifier getSizeModifier() const { 1409dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek return ArraySizeModifier(SizeModifier); 1410dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek } 14113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qualifiers getIndexTypeQualifiers() const { 14123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Qualifiers::fromCVRMask(IndexTypeQuals); 14133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 14143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall unsigned getIndexTypeCVRQualifiers() const { return IndexTypeQuals; } 141525cf760b54d3b88633827501013bc51a29b28abaMike Stump 141683c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const Type *T) { 141783c13010359c33354c581acee65d0c986a75247eSteve Naroff return T->getTypeClass() == ConstantArray || 14188ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman T->getTypeClass() == VariableArray || 14191b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor T->getTypeClass() == IncompleteArray || 14201b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor T->getTypeClass() == DependentSizedArray; 142183c13010359c33354c581acee65d0c986a75247eSteve Naroff } 142283c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const ArrayType *) { return true; } 142383c13010359c33354c581acee65d0c986a75247eSteve Naroff}; 142483c13010359c33354c581acee65d0c986a75247eSteve Naroff 14251d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// ConstantArrayType - This class represents the canonical version of 14261d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// C arrays with a specified constant size. For example, the canonical 14271d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 14281d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor/// type is 'int' and the size is 404. 1429c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ConstantArrayType : public ArrayType { 143083c13010359c33354c581acee65d0c986a75247eSteve Naroff llvm::APInt Size; // Allows us to unique the type. 143125cf760b54d3b88633827501013bc51a29b28abaMike Stump 14323f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 143324c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArraySizeModifier sm, unsigned tq) 14341d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(ConstantArray, et, can, sm, tq), 14351d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor Size(size) {} 14361d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregorprotected: 14371d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor ConstantArrayType(TypeClass tc, QualType et, QualType can, 14381d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 14391d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(tc, et, can, sm, tq), Size(size) {} 144083c13010359c33354c581acee65d0c986a75247eSteve Naroff friend class ASTContext; // ASTContext creates these. 144183c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic: 1442a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner const llvm::APInt &getSize() const { return Size; } 14430afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 14440afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 14450afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 144683c13010359c33354c581acee65d0c986a75247eSteve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 144725cf760b54d3b88633827501013bc51a29b28abaMike Stump Profile(ID, getElementType(), getSize(), 14483ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers()); 144983c13010359c33354c581acee65d0c986a75247eSteve Naroff } 145083c13010359c33354c581acee65d0c986a75247eSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 14513f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 14523f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner unsigned TypeQuals) { 145383c13010359c33354c581acee65d0c986a75247eSteve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 145483c13010359c33354c581acee65d0c986a75247eSteve Naroff ID.AddInteger(ArraySize.getZExtValue()); 14553f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(SizeMod); 14563f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(TypeQuals); 145783c13010359c33354c581acee65d0c986a75247eSteve Naroff } 14581d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor static bool classof(const Type *T) { 145932b25ab7d4b3355b804e367c90f5cd55f4c9187eJohn McCall return T->getTypeClass() == ConstantArray; 146083c13010359c33354c581acee65d0c986a75247eSteve Naroff } 146183c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const ConstantArrayType *) { return true; } 146283c13010359c33354c581acee65d0c986a75247eSteve Naroff}; 146383c13010359c33354c581acee65d0c986a75247eSteve Naroff 146456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 146556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 146656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// type is 'int' and the size is unspecified. 14678ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanclass IncompleteArrayType : public ArrayType { 14681d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor 14698ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman IncompleteArrayType(QualType et, QualType can, 14701d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor ArraySizeModifier sm, unsigned tq) 14718ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 14728ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman friend class ASTContext; // ASTContext creates these. 14738ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanpublic: 14740afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 14750afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 14760afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 147725cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 147825cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == IncompleteArray; 14798ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 14808ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 148125cf760b54d3b88633827501013bc51a29b28abaMike Stump 14828ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman friend class StmtIteratorBase; 148325cf760b54d3b88633827501013bc51a29b28abaMike Stump 14848ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 14853ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Profile(ID, getElementType(), getSizeModifier(), 14863ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getIndexTypeCVRQualifiers()); 14878ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 148825cf760b54d3b88633827501013bc51a29b28abaMike Stump 14893f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 14903f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 14918ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 14923f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(SizeMod); 14933f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(TypeQuals); 14948ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 14958ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman}; 14968ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 149756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 149856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 149956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 150056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 150156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 150256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// should not be: two lexically equivalent variable array types could mean 150356846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// different things, for example, these variables do not have the same type 150456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// dynamically: 150556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 150656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// void foo(int x) { 150756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// int Y[x]; 150856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// ++x; 150956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// int Z[x]; 151056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// } 151156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 1512c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass VariableArrayType : public ArrayType { 151325cf760b54d3b88633827501013bc51a29b28abaMike Stump /// SizeExpr - An assignment expression. VLA's are only permitted within 151425cf760b54d3b88633827501013bc51a29b28abaMike Stump /// a function block. 1515718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek Stmt *SizeExpr; 15161d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor /// Brackets - The left and right array brackets. 15171d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange Brackets; 15181d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor 151924c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 15201d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor ArraySizeModifier sm, unsigned tq, 15211d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange brackets) 15221d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(VariableArray, et, can, sm, tq), 15231d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 15244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1525db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek virtual void Destroy(ASTContext& C); 1526db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek 15274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 152825cf760b54d3b88633827501013bc51a29b28abaMike Stump Expr *getSizeExpr() const { 1529718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek // We use C-style casts instead of cast<> here because we do not wish 1530718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 1531718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek return (Expr*) SizeExpr; 1532718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek } 15331d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange getBracketsRange() const { return Brackets; } 15341d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 15351d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 153625cf760b54d3b88633827501013bc51a29b28abaMike Stump 15370afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 15380afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 15390afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 154025cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 154125cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == VariableArray; 15424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 154383c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const VariableArrayType *) { return true; } 154425cf760b54d3b88633827501013bc51a29b28abaMike Stump 1545fce813e3159a67a57a03cdca45ac4e10d4cffac3Ted Kremenek friend class StmtIteratorBase; 154625cf760b54d3b88633827501013bc51a29b28abaMike Stump 15473793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 15487029ee3fdeee514a79eafb2508723d27c97fe158Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 15493793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek } 15504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 15514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 15521b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// DependentSizedArrayType - This type represents an array type in 15531b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// C++ whose size is a value-dependent expression. For example: 1554393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// 1555393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// \code 155625cf760b54d3b88633827501013bc51a29b28abaMike Stump/// template<typename T, int Size> 15571b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// class array { 15581b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// T data[Size]; 15591b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// }; 1560393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// \endcode 1561393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor/// 15621b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// For these types, we won't actually know what the array bound is 15631b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// until template instantiation occurs, at which point this will 15641b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 15651b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorclass DependentSizedArrayType : public ArrayType { 15667fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor ASTContext &Context; 156725cf760b54d3b88633827501013bc51a29b28abaMike Stump 1568393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// \brief An assignment expression that will instantiate to the 15691b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// size of the array. 1570393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// 1571393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// The expression itself might be NULL, in which case the array 1572393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor /// type will have its size deduced from an initializer. 15731b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Stmt *SizeExpr; 1574393c00d16a75731eceb7f815751722e4b4a950e4Douglas Gregor 15751d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor /// Brackets - The left and right array brackets. 15761d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange Brackets; 157725cf760b54d3b88633827501013bc51a29b28abaMike Stump 157825cf760b54d3b88633827501013bc51a29b28abaMike Stump DependentSizedArrayType(ASTContext &Context, QualType et, QualType can, 15797fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor Expr *e, ArraySizeModifier sm, unsigned tq, 15801d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange brackets) 15811d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), 15827fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {} 15831b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor friend class ASTContext; // ASTContext creates these. 15841b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual void Destroy(ASTContext& C); 15851b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 15861b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorpublic: 158725cf760b54d3b88633827501013bc51a29b28abaMike Stump Expr *getSizeExpr() const { 15881b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // We use C-style casts instead of cast<> here because we do not wish 15891b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 15901b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return (Expr*) SizeExpr; 15911b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 15921d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceRange getBracketsRange() const { return Brackets; } 15931d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 15941d381135f0c9dcbac521112b3f6936caf871b91aDouglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 159525cf760b54d3b88633827501013bc51a29b28abaMike Stump 15960afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 15970afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 15980afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 159925cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 160025cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == DependentSizedArray; 16011b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 16021b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 160325cf760b54d3b88633827501013bc51a29b28abaMike Stump 16041b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor friend class StmtIteratorBase; 160525cf760b54d3b88633827501013bc51a29b28abaMike Stump 160625cf760b54d3b88633827501013bc51a29b28abaMike Stump 16071b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 160825cf760b54d3b88633827501013bc51a29b28abaMike Stump Profile(ID, Context, getElementType(), 16093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); 16101b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 161125cf760b54d3b88633827501013bc51a29b28abaMike Stump 161225cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 161325cf760b54d3b88633827501013bc51a29b28abaMike Stump QualType ET, ArraySizeModifier SizeMod, 16147fc8ed7fb83dd8bcd680756624e290d0702d281dDouglas Gregor unsigned TypeQuals, Expr *E); 16151b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor}; 16161b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 161768a7a6db3693e6df54a2198f3ee4e3f87e7f9ac0Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 16182a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// where either the type or size is dependent. For example: 16192a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// @code 16202a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// template<typename T, int Size> 16212a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// class vector { 16222a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 16232a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// } 16242a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor/// @endcode 16250c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { 16260c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor ASTContext &Context; 16272a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor Expr *SizeExpr; 16282a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor /// ElementType - The element type of the array. 16292a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor QualType ElementType; 16302a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor SourceLocation loc; 163125cf760b54d3b88633827501013bc51a29b28abaMike Stump 163225cf760b54d3b88633827501013bc51a29b28abaMike Stump DependentSizedExtVectorType(ASTContext &Context, QualType ElementType, 16330c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor QualType can, Expr *SizeExpr, SourceLocation loc) 163425cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type (DependentSizedExtVector, can, true), 163525cf760b54d3b88633827501013bc51a29b28abaMike Stump Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 16360c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor loc(loc) {} 16372a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor friend class ASTContext; 16382a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor virtual void Destroy(ASTContext& C); 16392a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor 16402a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregorpublic: 16410c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 16422a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor QualType getElementType() const { return ElementType; } 16432a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor SourceLocation getAttributeLoc() const { return loc; } 16442a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor 16450afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 16460afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 16470afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 164825cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 164925cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == DependentSizedExtVector; 16502a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor } 165125cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const DependentSizedExtVectorType *) { return true; } 16520c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor 16530c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 16540c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor Profile(ID, Context, getElementType(), getSizeExpr()); 16550c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor } 165625cf760b54d3b88633827501013bc51a29b28abaMike Stump 16570c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 16580c1d966bf0f3c5f7a787840c514c3d92fb4cbb3bDouglas Gregor QualType ElementType, Expr *SizeExpr); 16592a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor}; 166025cf760b54d3b88633827501013bc51a29b28abaMike Stump 16612a2e0405001f22e9026cb0dec219146996d1e7b6Douglas Gregor 16624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// VectorType - GCC generic vector type. This type is created using 166325cf760b54d3b88633827501013bc51a29b28abaMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in 1664438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson/// bytes; or from an Altivec __vector or vector declaration. 1665438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson/// Since the constructor takes the number of vector elements, the 16664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// client is responsible for converting the size into the number of elements. 16674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass VectorType : public Type, public llvm::FoldingSetNode { 16689484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattnerpublic: 16699484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner enum AltiVecSpecific { 16709484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner NotAltiVec, // is not AltiVec vector 16719484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner AltiVec, // is AltiVec vector 16729484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner Pixel, // is AltiVec 'vector Pixel' 16739484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner Bool // is AltiVec 'vector bool ...' 16749484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner }; 16754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 16764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ElementType - The element type of the vector. 16774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ElementType; 167825cf760b54d3b88633827501013bc51a29b28abaMike Stump 16794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// NumElements - The number of elements in the vector. 16804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned NumElements; 168125cf760b54d3b88633827501013bc51a29b28abaMike Stump 16829484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner AltiVecSpecific AltiVecSpec; 1683438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson 1684438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson VectorType(QualType vecType, unsigned nElements, QualType canonType, 16859484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner AltiVecSpecific altiVecSpec) : 168625cf760b54d3b88633827501013bc51a29b28abaMike Stump Type(Vector, canonType, vecType->isDependentType()), 16879484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner ElementType(vecType), NumElements(nElements), AltiVecSpec(altiVecSpec) {} 168825cf760b54d3b88633827501013bc51a29b28abaMike Stump VectorType(TypeClass tc, QualType vecType, unsigned nElements, 16899484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner QualType canonType, AltiVecSpecific altiVecSpec) 169025cf760b54d3b88633827501013bc51a29b28abaMike Stump : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 16919484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner NumElements(nElements), AltiVecSpec(altiVecSpec) {} 16924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1693949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1694949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1695949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 16964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 169725cf760b54d3b88633827501013bc51a29b28abaMike Stump 16984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getElementType() const { return ElementType; } 169925cf760b54d3b88633827501013bc51a29b28abaMike Stump unsigned getNumElements() const { return NumElements; } 17004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 17010afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 17020afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 17030afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 17049484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner AltiVecSpecific getAltiVecSpecific() const { return AltiVecSpec; } 17059484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner 17064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 17079484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner Profile(ID, getElementType(), getNumElements(), getTypeClass(), AltiVecSpec); 17084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 170925cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 1710438d00a23413bb5e63afa12a975fd2f2e6216293John Thompson unsigned NumElements, TypeClass TypeClass, 17119484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner unsigned AltiVecSpec) { 17124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(ElementType.getAsOpaquePtr()); 17134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddInteger(NumElements); 17144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddInteger(TypeClass); 17159484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner ID.AddInteger(AltiVecSpec); 17164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1717b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 171825cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 171925cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 17204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 17214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const VectorType *) { return true; } 17224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 17234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1724af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// ExtVectorType - Extended vector type. This type is created using 1725af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1726af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 17276154214e20225a883a8a00226499534e9b514315Steve Naroff/// class enables syntactic extensions, like Vector Components for accessing 17286154214e20225a883a8a00226499534e9b514315Steve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1729af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemanclass ExtVectorType : public VectorType { 1730af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 17319484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner VectorType(ExtVector, vecType, nElements, canonType, NotAltiVec) {} 17324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 17334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 17349096b795541c783297fb19684a58c54d0fe823b8Chris Lattner static int getPointAccessorIdx(char c) { 17359096b795541c783297fb19684a58c54d0fe823b8Chris Lattner switch (c) { 17369096b795541c783297fb19684a58c54d0fe823b8Chris Lattner default: return -1; 17379096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'x': return 0; 17389096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'y': return 1; 17399096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'z': return 2; 17409096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'w': return 3; 17419096b795541c783297fb19684a58c54d0fe823b8Chris Lattner } 17421b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 17431486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman static int getNumericAccessorIdx(char c) { 17449096b795541c783297fb19684a58c54d0fe823b8Chris Lattner switch (c) { 17451486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman default: return -1; 17461486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '0': return 0; 17471486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '1': return 1; 17481486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '2': return 2; 17491486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '3': return 3; 17501486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '4': return 4; 17511486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '5': return 5; 17521486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '6': return 6; 17531486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '7': return 7; 17541486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '8': return 8; 17551486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '9': return 9; 1756e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'A': 17571486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'a': return 10; 1758e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'B': 17591486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'b': return 11; 1760e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'C': 17611486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'c': return 12; 1762e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'D': 17631486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'd': return 13; 1764e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'E': 17651486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'e': return 14; 1766e2ed6f7a96d7cc444f4a7f15775164b3eccc3c34Nate Begeman case 'F': 17671486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'f': return 15; 17689096b795541c783297fb19684a58c54d0fe823b8Chris Lattner } 17691b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 177025cf760b54d3b88633827501013bc51a29b28abaMike Stump 177142158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner static int getAccessorIdx(char c) { 177242158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 17731486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman return getNumericAccessorIdx(c); 177442158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner } 177525cf760b54d3b88633827501013bc51a29b28abaMike Stump 17769096b795541c783297fb19684a58c54d0fe823b8Chris Lattner bool isAccessorWithinNumElements(char c) const { 177742158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner if (int idx = getAccessorIdx(c)+1) 17789096b795541c783297fb19684a58c54d0fe823b8Chris Lattner return unsigned(idx-1) < NumElements; 17799096b795541c783297fb19684a58c54d0fe823b8Chris Lattner return false; 17801b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 17810afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 17820afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 17830afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 178425cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 178525cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == ExtVector; 17864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1787af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman static bool classof(const ExtVectorType *) { return true; } 17884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 17894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 17904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 17914fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 17924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 17934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass FunctionType : public Type { 17946f52e3c5663a669ec61379e933e0fe7ad2f1a566Chris Lattner virtual void ANCHOR(); // Key function for FunctionType. 17956f52e3c5663a669ec61379e933e0fe7ad2f1a566Chris Lattner 17964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// SubClassData - This field is owned by the subclass, put here to pack 17974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// tightly with the ivars in Type. 17984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool SubClassData : 1; 17994b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis 18004fa58905062efa6a12137b1983a1367220182a20Douglas Gregor /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 18014b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// other bitfields. 18024fa58905062efa6a12137b1983a1367220182a20Douglas Gregor /// The qualifiers are part of FunctionProtoType because... 18034b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// 18044b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 18054b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// cv-qualifier-seq, [...], are part of the function type. 18064b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// 18074b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned TypeQuals : 3; 18081bb806498909a43a7829edb21c42606335d69694Mike Stump 18091bb806498909a43a7829edb21c42606335d69694Mike Stump /// NoReturn - Indicates if the function type is attribute noreturn. 18101bb806498909a43a7829edb21c42606335d69694Mike Stump unsigned NoReturn : 1; 181125cf760b54d3b88633827501013bc51a29b28abaMike Stump 18122ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola /// RegParm - How many arguments to pass inreg. 18132ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola unsigned RegParm : 3; 18142ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola 181531cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor /// CallConv - The calling convention used by the function. 181601890a8487ae3330abc501b455e2092545d54775Douglas Gregor unsigned CallConv : 3; 181731cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor 18184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // The type returned by the function. 18194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ResultType; 1820433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1821433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola public: 1822433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // This class is used for passing arround the information needed to 1823433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // construct a call. It is not actually used for storage, just for 1824433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // factoring together common arguments. 18252ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // If you add a field (say Foo), other than the obvious places (both, constructors, 18262ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // compile failures), what you need to update is 18272ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * Operetor== 18282ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * getFoo 18292ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * withFoo 18302ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * functionType. Add Foo, getFoo. 18312ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * ASTContext::getFooType 18322ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * ASTContext::mergeFunctionTypes 18332ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * FunctionNoProtoType::Profile 18342ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * FunctionProtoType::Profile 18352ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * TypePrinter::PrintFunctionProto 18362ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * PCH read and write 18372ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // * Codegen 18382ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola 1839433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola class ExtInfo { 1840433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola public: 1841433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // Constructor with no defaults. Use this when you know that you 1842433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // have all the elements (when reading a PCH file for example). 18432ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola ExtInfo(bool noReturn, unsigned regParm, CallingConv cc) : 18442ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola NoReturn(noReturn), RegParm(regParm), CC(cc) {} 1845433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1846433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // Constructor with all defaults. Use when for example creating a 1847433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // function know to use defaults. 18482ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola ExtInfo() : NoReturn(false), RegParm(0), CC(CC_Default) {} 1849433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1850433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola bool getNoReturn() const { return NoReturn; } 18512ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola unsigned getRegParm() const { return RegParm; } 1852433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola CallingConv getCC() const { return CC; } 1853433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1854433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola bool operator==(const ExtInfo &Other) const { 1855433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola return getNoReturn() == Other.getNoReturn() && 18562ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola getRegParm() == Other.getRegParm() && 1857433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola getCC() == Other.getCC(); 1858433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola } 1859433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola bool operator!=(const ExtInfo &Other) const { 1860433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola return !(*this == Other); 1861433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola } 1862433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1863433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // Note that we don't have setters. That is by design, use 1864433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // the following with methods instead of mutating these objects. 1865433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1866433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola ExtInfo withNoReturn(bool noReturn) const { 18672ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola return ExtInfo(noReturn, getRegParm(), getCC()); 18682ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola } 18692ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola 18702ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola ExtInfo withRegParm(unsigned RegParm) const { 18712ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola return ExtInfo(getNoReturn(), RegParm, getCC()); 1872433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola } 1873433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1874433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola ExtInfo withCallingConv(CallingConv cc) const { 18752ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola return ExtInfo(getNoReturn(), getRegParm(), cc); 1876433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola } 1877433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 1878433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola private: 1879433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // True if we have __attribute__((noreturn)) 1880433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola bool NoReturn; 18812ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola // The value passed to __attribute__((regparm(x))) 18822ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola unsigned RegParm; 1883433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola // The calling convention as specified via 188401890a8487ae3330abc501b455e2092545d54775Douglas Gregor // __attribute__((cdecl|stdcall|fastcall|thiscall)) 1885433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola CallingConv CC; 1886433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola }; 1887433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola 18884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 18894b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 18901bb806498909a43a7829edb21c42606335d69694Mike Stump unsigned typeQuals, QualType Canonical, bool Dependent, 1891433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola const ExtInfo &Info) 18921b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, Canonical, Dependent), 1893433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola SubClassData(SubclassInfo), TypeQuals(typeQuals), 1894433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola NoReturn(Info.getNoReturn()), 18952ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola RegParm(Info.getRegParm()), CallConv(Info.getCC()), ResultType(res) {} 18964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool getSubClassData() const { return SubClassData; } 18974b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned getTypeQuals() const { return TypeQuals; } 18984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 189925cf760b54d3b88633827501013bc51a29b28abaMike Stump 19004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getResultType() const { return ResultType; } 19018079eee9128444d02bebf24410126f9d55399f84Douglas Gregor 19022ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola unsigned getRegParmType() const { return RegParm; } 19031bb806498909a43a7829edb21c42606335d69694Mike Stump bool getNoReturnAttr() const { return NoReturn; } 190431cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor CallingConv getCallConv() const { return (CallingConv)CallConv; } 1905433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola ExtInfo getExtInfo() const { 19062ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola return ExtInfo(NoReturn, RegParm, (CallingConv)CallConv); 1907433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola } 19084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 19098079eee9128444d02bebf24410126f9d55399f84Douglas Gregor /// \brief Determine the type of an expression that calls a function of 19108079eee9128444d02bebf24410126f9d55399f84Douglas Gregor /// this type. 19118079eee9128444d02bebf24410126f9d55399f84Douglas Gregor QualType getCallResultType(ASTContext &Context) const { 19122350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor return getResultType().getNonLValueExprType(Context); 19138079eee9128444d02bebf24410126f9d55399f84Douglas Gregor } 19148079eee9128444d02bebf24410126f9d55399f84Douglas Gregor 1915ad760b38613b3f7f1024b011f6109bed1487b32eJohn McCall static llvm::StringRef getNameForCallConv(CallingConv CC); 1916ad760b38613b3f7f1024b011f6109bed1487b32eJohn McCall 19174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 19184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionNoProto || 19194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner T->getTypeClass() == FunctionProto; 19204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 19214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const FunctionType *) { return true; } 19224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 19234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 19244fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 19254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// no information available about its arguments. 19264fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 19271bb806498909a43a7829edb21c42606335d69694Mike Stump FunctionNoProtoType(QualType Result, QualType Canonical, 1928433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola const ExtInfo &Info) 192925cf760b54d3b88633827501013bc51a29b28abaMike Stump : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 1930433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola /*Dependent=*/false, Info) {} 19314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1932949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1933949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 1934949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 1935949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 19364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 19374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // No additional state past what FunctionType provides. 193825cf760b54d3b88633827501013bc51a29b28abaMike Stump 19390afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 19400afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 19410afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 19424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 1943433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola Profile(ID, getResultType(), getExtInfo()); 19444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 19451bb806498909a43a7829edb21c42606335d69694Mike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 1946433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola const ExtInfo &Info) { 1947433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola ID.AddInteger(Info.getCC()); 19482ffdc0f8242c22c4bca8bbc2390be61a8a80e4b8Rafael Espindola ID.AddInteger(Info.getRegParm()); 1949433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola ID.AddInteger(Info.getNoReturn()); 19504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(ResultType.getAsOpaquePtr()); 19514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 195225cf760b54d3b88633827501013bc51a29b28abaMike Stump 19534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 19544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionNoProto; 19554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 19564fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 19574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 19584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 19594fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 19604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 19612767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 19622767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl/// exception specification, but this specification is not part of the canonical 19632767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl/// type. 19644fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 19651b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 19661b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// types within the arguments passed in. 19671b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 19681b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 19691b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor if (ArgArray[Idx]->isDependentType()) 1970f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman return true; 19711b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 19721b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return false; 19731b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 19741b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 19754fa58905062efa6a12137b1983a1367220182a20Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 19762767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool isVariadic, unsigned typeQuals, bool hasExs, 19772767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasAnyExs, const QualType *ExArray, 1978433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola unsigned numExs, QualType Canonical, 1979433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola const ExtInfo &Info) 19801b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 198125cf760b54d3b88633827501013bc51a29b28abaMike Stump (Result->isDependentType() || 1982433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola hasAnyDependentType(ArgArray, numArgs)), 1983433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola Info), 19842767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 19852767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl AnyExceptionSpec(hasAnyExs) { 19864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // Fill in the trailing argument array. 19872767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 19884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner for (unsigned i = 0; i != numArgs; ++i) 19894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ArgInfo[i] = ArgArray[i]; 19902767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl // Fill in the exception array. 19912767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl QualType *Ex = ArgInfo + numArgs; 19922767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl for (unsigned i = 0; i != numExs; ++i) 19932767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl Ex[i] = ExArray[i]; 19944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 19952767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 19964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// NumArgs - The number of arguments this function has, not counting '...'. 19972767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl unsigned NumArgs : 20; 19982767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 19992767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 20002767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl unsigned NumExceptions : 10; 20012767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20022767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// HasExceptionSpec - Whether this function has an exception spec at all. 20032767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool HasExceptionSpec : 1; 20042767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20052767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// AnyExceptionSpec - Whether this function has a throw(...) spec. 20062767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool AnyExceptionSpec : 1; 20072767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 20094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// holds the argument types. 20102767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20112767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 20122767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl /// holds the exception types. 20132767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 2015db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek 2016949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 2017949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 2018949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 20194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 20204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned getNumArgs() const { return NumArgs; } 20214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getArgType(unsigned i) const { 20224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner assert(i < NumArgs && "Invalid argument number!"); 20234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return arg_type_begin()[i]; 20244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 20252767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20262767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasExceptionSpec() const { return HasExceptionSpec; } 20272767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 20282767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 20292767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl QualType getExceptionType(unsigned i) const { 20302767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 20312767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl return exception_begin()[i]; 20322767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl } 203325cf760b54d3b88633827501013bc51a29b28abaMike Stump bool hasEmptyExceptionSpec() const { 203425cf760b54d3b88633827501013bc51a29b28abaMike Stump return hasExceptionSpec() && !hasAnyExceptionSpec() && 2035ac5e9f9de0959d5b1d390dc9bdad2d6f3d77c5cbAnders Carlsson getNumExceptions() == 0; 203611269048f03d91e991150c429dc874ae3999acb0Anders Carlsson } 20372767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isVariadic() const { return getSubClassData(); } 20394b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 204025cf760b54d3b88633827501013bc51a29b28abaMike Stump 20414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner typedef const QualType *arg_type_iterator; 20424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator arg_type_begin() const { 20434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return reinterpret_cast<const QualType *>(this+1); 20444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 20454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 20462767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20472767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl typedef const QualType *exception_iterator; 20482767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl exception_iterator exception_begin() const { 20492767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl // exceptions begin where arguments end 20502767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl return arg_type_end(); 20512767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl } 20522767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl exception_iterator exception_end() const { 20532767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl return exception_begin() + NumExceptions; 20542767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl } 20552767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20560afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 20570afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 20580afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 20594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 20604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionProto; 20614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 20624fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 20632767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl 20644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID); 20654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 20664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 20672767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool isVariadic, unsigned TypeQuals, 20682767d88f088ce07f489e6a64592950f9c0a91ebdSebastian Redl bool hasExceptionSpec, bool anyExceptionSpec, 20691bb806498909a43a7829edb21c42606335d69694Mike Stump unsigned NumExceptions, exception_iterator Exs, 2070433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola const ExtInfo &ExtInfo); 20714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 20724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 20734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2074caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// \brief Represents the dependent type named by a dependently-scoped 2075caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// typename using declaration, e.g. 2076caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// using typename Base<T>::foo; 2077caf383ae337966d67380b6b161fab17ec2b53d04John McCall/// Template instantiation turns these into the underlying type. 2078caf383ae337966d67380b6b161fab17ec2b53d04John McCallclass UnresolvedUsingType : public Type { 2079caf383ae337966d67380b6b161fab17ec2b53d04John McCall UnresolvedUsingTypenameDecl *Decl; 2080caf383ae337966d67380b6b161fab17ec2b53d04John McCall 2081d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) 2082d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall : Type(UnresolvedUsing, QualType(), true), 2083d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {} 2084caf383ae337966d67380b6b161fab17ec2b53d04John McCall friend class ASTContext; // ASTContext creates these. 2085caf383ae337966d67380b6b161fab17ec2b53d04John McCallpublic: 2086caf383ae337966d67380b6b161fab17ec2b53d04John McCall 2087caf383ae337966d67380b6b161fab17ec2b53d04John McCall UnresolvedUsingTypenameDecl *getDecl() const { return Decl; } 2088caf383ae337966d67380b6b161fab17ec2b53d04John McCall 2089caf383ae337966d67380b6b161fab17ec2b53d04John McCall bool isSugared() const { return false; } 2090caf383ae337966d67380b6b161fab17ec2b53d04John McCall QualType desugar() const { return QualType(this, 0); } 2091caf383ae337966d67380b6b161fab17ec2b53d04John McCall 2092caf383ae337966d67380b6b161fab17ec2b53d04John McCall static bool classof(const Type *T) { 2093caf383ae337966d67380b6b161fab17ec2b53d04John McCall return T->getTypeClass() == UnresolvedUsing; 2094caf383ae337966d67380b6b161fab17ec2b53d04John McCall } 2095caf383ae337966d67380b6b161fab17ec2b53d04John McCall static bool classof(const UnresolvedUsingType *) { return true; } 2096caf383ae337966d67380b6b161fab17ec2b53d04John McCall 2097caf383ae337966d67380b6b161fab17ec2b53d04John McCall void Profile(llvm::FoldingSetNodeID &ID) { 2098caf383ae337966d67380b6b161fab17ec2b53d04John McCall return Profile(ID, Decl); 2099caf383ae337966d67380b6b161fab17ec2b53d04John McCall } 2100caf383ae337966d67380b6b161fab17ec2b53d04John McCall static void Profile(llvm::FoldingSetNodeID &ID, 2101caf383ae337966d67380b6b161fab17ec2b53d04John McCall UnresolvedUsingTypenameDecl *D) { 2102caf383ae337966d67380b6b161fab17ec2b53d04John McCall ID.AddPointer(D); 2103caf383ae337966d67380b6b161fab17ec2b53d04John McCall } 2104caf383ae337966d67380b6b161fab17ec2b53d04John McCall}; 2105caf383ae337966d67380b6b161fab17ec2b53d04John McCall 2106caf383ae337966d67380b6b161fab17ec2b53d04John McCall 21074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TypedefType : public Type { 21084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner TypedefDecl *Decl; 2109e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanianprotected: 2110d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall TypedefType(TypeClass tc, const TypedefDecl *D, QualType can) 2111d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall : Type(tc, can, can->isDependentType()), 2112d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall Decl(const_cast<TypedefDecl*>(D)) { 21134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner assert(!isa<TypedefType>(can) && "Invalid canonical type"); 21144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 21154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 21164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 211725cf760b54d3b88633827501013bc51a29b28abaMike Stump 21184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner TypedefDecl *getDecl() const { return Decl; } 211925cf760b54d3b88633827501013bc51a29b28abaMike Stump 21204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 2121a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 21224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// sum of the type qualifiers, so if you have: 21234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// typedef const int A; 21244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// typedef volatile A B; 21254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// looking through the typedefs for B will give you "const volatile A". 21264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType LookThroughTypedefs() const; 212725cf760b54d3b88633827501013bc51a29b28abaMike Stump 21280afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 21290afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const; 21300afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 21314fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 21324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const TypedefType *) { return true; } 21334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 21344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 21354fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// TypeOfExprType (GCC extension). 21364fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass TypeOfExprType : public Type { 21377cbb14653934a298c09002b87704dc6531261771Steve Naroff Expr *TOExpr; 213825cf760b54d3b88633827501013bc51a29b28abaMike Stump 213963d22fa6071690209b339451e4939de120a45e70Douglas Gregorprotected: 2140d1c0b682af81784cb991a5479097e795b5868bc4Douglas Gregor TypeOfExprType(Expr *E, QualType can = QualType()); 21417cbb14653934a298c09002b87704dc6531261771Steve Naroff friend class ASTContext; // ASTContext creates these. 21427cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic: 21437cbb14653934a298c09002b87704dc6531261771Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 214425cf760b54d3b88633827501013bc51a29b28abaMike Stump 21450afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 21460afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const; 21470afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 21480afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 21490afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 21500afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 21514fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 21524fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 21537cbb14653934a298c09002b87704dc6531261771Steve Naroff}; 21547cbb14653934a298c09002b87704dc6531261771Steve Naroff 215527dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// \brief Internal representation of canonical, dependent 215625cf760b54d3b88633827501013bc51a29b28abaMike Stump/// typeof(expr) types. 215727dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// 215827dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// This class is used internally by the ASTContext to manage 215927dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// canonical, dependent types, only. Clients will only see instances 216027dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// of this class via TypeOfExprType nodes. 216125cf760b54d3b88633827501013bc51a29b28abaMike Stumpclass DependentTypeOfExprType 216263d22fa6071690209b339451e4939de120a45e70Douglas Gregor : public TypeOfExprType, public llvm::FoldingSetNode { 216363d22fa6071690209b339451e4939de120a45e70Douglas Gregor ASTContext &Context; 216425cf760b54d3b88633827501013bc51a29b28abaMike Stump 216563d22fa6071690209b339451e4939de120a45e70Douglas Gregorpublic: 216625cf760b54d3b88633827501013bc51a29b28abaMike Stump DependentTypeOfExprType(ASTContext &Context, Expr *E) 216763d22fa6071690209b339451e4939de120a45e70Douglas Gregor : TypeOfExprType(E), Context(Context) { } 216825cf760b54d3b88633827501013bc51a29b28abaMike Stump 21690afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 21700afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 21710afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 217263d22fa6071690209b339451e4939de120a45e70Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 217363d22fa6071690209b339451e4939de120a45e70Douglas Gregor Profile(ID, Context, getUnderlyingExpr()); 217463d22fa6071690209b339451e4939de120a45e70Douglas Gregor } 217525cf760b54d3b88633827501013bc51a29b28abaMike Stump 217663d22fa6071690209b339451e4939de120a45e70Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 217763d22fa6071690209b339451e4939de120a45e70Douglas Gregor Expr *E); 217863d22fa6071690209b339451e4939de120a45e70Douglas Gregor}; 217925cf760b54d3b88633827501013bc51a29b28abaMike Stump 21807cbb14653934a298c09002b87704dc6531261771Steve Naroff/// TypeOfType (GCC extension). 21817cbb14653934a298c09002b87704dc6531261771Steve Naroffclass TypeOfType : public Type { 21827cbb14653934a298c09002b87704dc6531261771Steve Naroff QualType TOType; 218325cf760b54d3b88633827501013bc51a29b28abaMike Stump TypeOfType(QualType T, QualType can) 21844fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : Type(TypeOf, can, T->isDependentType()), TOType(T) { 21857cbb14653934a298c09002b87704dc6531261771Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 21867cbb14653934a298c09002b87704dc6531261771Steve Naroff } 21877cbb14653934a298c09002b87704dc6531261771Steve Naroff friend class ASTContext; // ASTContext creates these. 21887cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic: 21897cbb14653934a298c09002b87704dc6531261771Steve Naroff QualType getUnderlyingType() const { return TOType; } 219025cf760b54d3b88633827501013bc51a29b28abaMike Stump 21910afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 21920afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getUnderlyingType(); } 21930afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 21940afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 21950afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 21960afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 21974fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 21987cbb14653934a298c09002b87704dc6531261771Steve Naroff static bool classof(const TypeOfType *) { return true; } 21997cbb14653934a298c09002b87704dc6531261771Steve Naroff}; 22004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 220193ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson/// DecltypeType (C++0x) 220293ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlssonclass DecltypeType : public Type { 220393ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson Expr *E; 220425cf760b54d3b88633827501013bc51a29b28abaMike Stump 220542f394e67047624dcc15d22239f615885ad712acAnders Carlsson // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 220642f394e67047624dcc15d22239f615885ad712acAnders Carlsson // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 220742f394e67047624dcc15d22239f615885ad712acAnders Carlsson // from it. 220842f394e67047624dcc15d22239f615885ad712acAnders Carlsson QualType UnderlyingType; 220925cf760b54d3b88633827501013bc51a29b28abaMike Stump 2210d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregorprotected: 221142f394e67047624dcc15d22239f615885ad712acAnders Carlsson DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 221293ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson friend class ASTContext; // ASTContext creates these. 221393ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlssonpublic: 221493ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson Expr *getUnderlyingExpr() const { return E; } 221542f394e67047624dcc15d22239f615885ad712acAnders Carlsson QualType getUnderlyingType() const { return UnderlyingType; } 221642f394e67047624dcc15d22239f615885ad712acAnders Carlsson 22170afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 22180afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getUnderlyingType(); } 22190afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 22200afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 22210afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return !isDependentType(); } 22220afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 222393ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 222493ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson static bool classof(const DecltypeType *) { return true; } 222593ab533a2e9522a2e9a7695cb7446812fc9e70a6Anders Carlsson}; 222625cf760b54d3b88633827501013bc51a29b28abaMike Stump 222727dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// \brief Internal representation of canonical, dependent 222827dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// decltype(expr) types. 222927dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// 223027dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// This class is used internally by the ASTContext to manage 223127dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// canonical, dependent types, only. Clients will only see instances 223227dc8619071ac2ef47318bf4ff21b99a3e3793aeDouglas Gregor/// of this class via DecltypeType nodes. 2233d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { 2234d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor ASTContext &Context; 223525cf760b54d3b88633827501013bc51a29b28abaMike Stump 2236d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregorpublic: 2237d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor DependentDecltypeType(ASTContext &Context, Expr *E); 223825cf760b54d3b88633827501013bc51a29b28abaMike Stump 22390afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 22400afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 22410afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2242d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2243d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor Profile(ID, Context, getUnderlyingExpr()); 2244d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor } 224525cf760b54d3b88633827501013bc51a29b28abaMike Stump 2246d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 224725cf760b54d3b88633827501013bc51a29b28abaMike Stump Expr *E); 2248d63e16cae1577c934a6637baebd04c2bdcd2ebf8Douglas Gregor}; 224925cf760b54d3b88633827501013bc51a29b28abaMike Stump 22504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TagType : public Type { 225198b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// Stores the TagDecl associated with this type. The decl will 225298b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// point to the TagDecl that actually defines the entity (or is a 225398b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// definition in progress), if there is such a definition. The 225498b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// single-bit value will be non-zero when this tag is in the 225598b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// process of being defined. 22569c7825b737617339724d43bd04960852271f08e2Douglas Gregor mutable llvm::PointerIntPair<TagDecl *, 1> decl; 225746a837c7ced306c55d1686cea5f77cb7a2f3b908Ted Kremenek friend class ASTContext; 225898b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor friend class TagDecl; 22591d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor 22601d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregorprotected: 2261d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall TagType(TypeClass TC, const TagDecl *D, QualType can); 22621d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor 2263949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 2264949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 226525cf760b54d3b88633827501013bc51a29b28abaMike Stumppublic: 226698b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor TagDecl *getDecl() const { return decl.getPointer(); } 226725cf760b54d3b88633827501013bc51a29b28abaMike Stump 226898b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// @brief Determines whether this type is in the process of being 226925cf760b54d3b88633827501013bc51a29b28abaMike Stump /// defined. 227098b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor bool isBeingDefined() const { return decl.getInt(); } 22713ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setBeingDefined(bool Def) const { decl.setInt(Def? 1 : 0); } 227298b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor 227325cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 22744fa58905062efa6a12137b1983a1367220182a20Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 22754fa58905062efa6a12137b1983a1367220182a20Douglas Gregor } 22764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const TagType *) { return true; } 22774fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const RecordType *) { return true; } 22784fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const EnumType *) { return true; } 22794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 22804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 22811baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 22821baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of structs/unions/classes. 22831baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass RecordType : public TagType { 2284ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidisprotected: 2285d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall explicit RecordType(const RecordDecl *D) 2286d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { } 22874fa58905062efa6a12137b1983a1367220182a20Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 2288d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { } 22891d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor friend class ASTContext; // ASTContext creates these. 22901baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic: 229125cf760b54d3b88633827501013bc51a29b28abaMike Stump 22921baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner RecordDecl *getDecl() const { 22931baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 22941baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner } 229525cf760b54d3b88633827501013bc51a29b28abaMike Stump 229625cf760b54d3b88633827501013bc51a29b28abaMike Stump // FIXME: This predicate is a helper to QualType/Type. It needs to 22971baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // recursively check all fields for const-ness. If any field is declared 229825cf760b54d3b88633827501013bc51a29b28abaMike Stump // const, it needs to return false. 22991baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner bool hasConstFields() const { return false; } 23001baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 23011baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 23021baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // the same address space, and return that. 23031baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner unsigned getAddressSpace() const { return 0; } 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 RecordType *) { return true; } 23131baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner}; 23141baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 23151baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 23161baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of enums. 23171baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass EnumType : public TagType { 2318d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall explicit EnumType(const EnumDecl *D) 2319d7757931fd2f6fb2dc272e3cde0f2251c392e1edJohn McCall : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { } 23201d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor friend class ASTContext; // ASTContext creates these. 23211baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic: 232225cf760b54d3b88633827501013bc51a29b28abaMike Stump 23231baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner EnumDecl *getDecl() const { 23241baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 23251baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner } 232625cf760b54d3b88633827501013bc51a29b28abaMike Stump 23270afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 23280afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 23290afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2330eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const TagType *T); 2331eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const Type *T) { 2332eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 2333eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner } 23341baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner static bool classof(const EnumType *) { return true; } 23351baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner}; 23361baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 2337a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 233825560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor unsigned Depth : 15; 233925560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor unsigned Index : 16; 234025560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor unsigned ParameterPack : 1; 234125560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor IdentifierInfo *Name; 2342dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 234325560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 234425560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor QualType Canon) 2345a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 234625560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor Depth(D), Index(I), ParameterPack(PP), Name(N) { } 2347dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 234825cf760b54d3b88633827501013bc51a29b28abaMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP) 234925560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 235025560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor Depth(D), Index(I), ParameterPack(PP), Name(0) { } 2351dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 2352a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor friend class ASTContext; // ASTContext creates these 2353dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 2354a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregorpublic: 235525560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor unsigned getDepth() const { return Depth; } 235625560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor unsigned getIndex() const { return Index; } 235725560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor bool isParameterPack() const { return ParameterPack; } 235825560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor IdentifierInfo *getName() const { return Name; } 235925cf760b54d3b88633827501013bc51a29b28abaMike Stump 23600afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 23610afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 23620afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2363a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 236425560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor Profile(ID, Depth, Index, ParameterPack, Name); 2365a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor } 2366a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 236725cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 236825cf760b54d3b88633827501013bc51a29b28abaMike Stump unsigned Index, bool ParameterPack, 236925560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor IdentifierInfo *Name) { 2370a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor ID.AddInteger(Depth); 2371a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor ID.AddInteger(Index); 23724e3d355931542dc1a40c35c108f7e0b72876584cAnders Carlsson ID.AddBoolean(ParameterPack); 237325560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor ID.AddPointer(Name); 2374a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor } 2375a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 237625cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 237725cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == TemplateTypeParm; 2378dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor } 2379dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 2380dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor}; 2381a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 23825cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// \brief Represents the result of substituting a type for a template 23835cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// type parameter. 23845cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// 23855cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// Within an instantiated template, all template type parameters have 23865cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// been replaced with these. They are used solely to record that a 23875cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// type was originally written as a template type parameter; 23885cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall/// therefore they are never canonical. 23895cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode { 23905cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall // The original type parameter. 23915cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall const TemplateTypeParmType *Replaced; 23925cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23935cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) 23945cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType()), 23955cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall Replaced(Param) { } 23965cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23975cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall friend class ASTContext; 23985cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 23995cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCallpublic: 240025560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor IdentifierInfo *getName() const { return Replaced->getName(); } 240125560122fbc4a39c864695b170e4ff9009e1f273Douglas Gregor 24025cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall /// Gets the template parameter that was substituted for. 24035cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall const TemplateTypeParmType *getReplacedParameter() const { 24045cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall return Replaced; 24055cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 24065cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 24075cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall /// Gets the type that was substituted for the template 24085cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall /// parameter. 24095cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall QualType getReplacementType() const { 24105cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall return getCanonicalTypeInternal(); 24115cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 24125cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 24135cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall bool isSugared() const { return true; } 24145cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall QualType desugar() const { return getReplacementType(); } 24155cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 24165cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall void Profile(llvm::FoldingSetNodeID &ID) { 24175cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall Profile(ID, getReplacedParameter(), getReplacementType()); 24185cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 24195cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall static void Profile(llvm::FoldingSetNodeID &ID, 24205cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall const TemplateTypeParmType *Replaced, 24215cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall QualType Replacement) { 24225cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall ID.AddPointer(Replaced); 24235cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall ID.AddPointer(Replacement.getAsOpaquePtr()); 24245cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 24255cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 24265cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall static bool classof(const Type *T) { 24275cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall return T->getTypeClass() == SubstTemplateTypeParm; 24285cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall } 24295cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall static bool classof(const SubstTemplateTypeParmType *T) { return true; } 24305cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall}; 24315cc4b067c9a94ff7a98c34b4a8b14f2643980c79John McCall 2432dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// \brief Represents the type of a template specialization as written 2433dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// in the source code. 24348e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// 2435dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// Template specialization types represent the syntactic form of a 2436dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 2437dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 2438dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// type will point to some other type node that represents the 2439dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// instantiation or class template specialization. For example, a 24408e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// class template specialization type of @c vector<int> will refer to 244125cf760b54d3b88633827501013bc51a29b28abaMike Stump/// a tag type for the instantiation 24428e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 2443dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// 2444dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// Other template specialization types, for which the template name 2445dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// is dependent, may be canonical types. These types are always 2446dd13e8468462e60971487bcd5915419762dab814Douglas Gregor/// dependent. 244725cf760b54d3b88633827501013bc51a29b28abaMike Stumpclass TemplateSpecializationType 24488e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor : public Type, public llvm::FoldingSetNode { 244952b136ace347ee82e11145927e37980157bacb35John McCall /// \brief The name of the template being specialized. 2450dd13e8468462e60971487bcd5915419762dab814Douglas Gregor TemplateName Template; 24518e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 2452f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief - The number of template arguments named in this class 2453f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// template specialization. 24548e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor unsigned NumArgs; 24558e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 245602cd8e64ab4b62f88c62f63320ddd17466764022John McCall TemplateSpecializationType(TemplateName T, 2457dd13e8468462e60971487bcd5915419762dab814Douglas Gregor const TemplateArgument *Args, 2458dd13e8468462e60971487bcd5915419762dab814Douglas Gregor unsigned NumArgs, QualType Canon); 24598e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 24606f37b58716e89420c13ac067fe605c3b6d5821d0Douglas Gregor virtual void Destroy(ASTContext& C); 24616f37b58716e89420c13ac067fe605c3b6d5821d0Douglas Gregor 24628e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor friend class ASTContext; // ASTContext creates these 24638e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 24648e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregorpublic: 2465f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Determine whether any of the given template arguments are 2466f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// dependent. 2467f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 246825cf760b54d3b88633827501013bc51a29b28abaMike Stump unsigned NumArgs); 2469f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2470588613178e3a10e2b840c8f4db9e058f2fec0005John McCall static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args, 2471588613178e3a10e2b840c8f4db9e058f2fec0005John McCall unsigned NumArgs); 2472588613178e3a10e2b840c8f4db9e058f2fec0005John McCall 2473ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &); 2474ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall 247556d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 247656d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor /// enclosing the template arguments. 247756d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 24783bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor unsigned NumArgs, 24793bf3bbcb3cf79cc5bc065a011f5ae195667d3a29Douglas Gregor const PrintingPolicy &Policy); 248056d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor 2481588613178e3a10e2b840c8f4db9e058f2fec0005John McCall static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args, 2482588613178e3a10e2b840c8f4db9e058f2fec0005John McCall unsigned NumArgs, 2483588613178e3a10e2b840c8f4db9e058f2fec0005John McCall const PrintingPolicy &Policy); 2484588613178e3a10e2b840c8f4db9e058f2fec0005John McCall 2485ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &, 2486ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall const PrintingPolicy &Policy); 2487ed9480970db65f8705eeba0760fbe8feefe6389bJohn McCall 24884578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// True if this template specialization type matches a current 24894578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// instantiation in the context in which it is found. 24904578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall bool isCurrentInstantiation() const { 2491486c883ca29f6b50bb8ded372ad5bb2970fd4101John McCall return isa<InjectedClassNameType>(getCanonicalTypeInternal()); 24924578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall } 24934578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall 2494f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor typedef const TemplateArgument * iterator; 2495f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2496f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor iterator begin() const { return getArgs(); } 249752b136ace347ee82e11145927e37980157bacb35John McCall iterator end() const; // defined inline in TemplateBase.h 2498f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2499dd13e8468462e60971487bcd5915419762dab814Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 2500dd13e8468462e60971487bcd5915419762dab814Douglas Gregor TemplateName getTemplateName() const { return Template; } 25018e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 2502f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Retrieve the template arguments. 250325cf760b54d3b88633827501013bc51a29b28abaMike Stump const TemplateArgument *getArgs() const { 2504f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 2505f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor } 2506f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 2507f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Retrieve the number of template arguments. 25088e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 25098e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 25108e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor /// \brief Retrieve a specific template argument as a type. 25118e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor /// \precondition @c isArgType(Arg) 251252b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 25138e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 25144578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall bool isSugared() const { 25154578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall return !isDependentType() || isCurrentInstantiation(); 25164578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall } 25170afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getCanonicalTypeInternal(); } 25180afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 251902cd8e64ab4b62f88c62f63320ddd17466764022John McCall void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Ctx) { 2520486c883ca29f6b50bb8ded372ad5bb2970fd4101John McCall Profile(ID, Template, getArgs(), NumArgs, Ctx); 25218e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor } 25228e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 2523dd13e8468462e60971487bcd5915419762dab814Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 25244578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall const TemplateArgument *Args, 25254578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall unsigned NumArgs, 252699eef4a6d3632a78155e7639a9f91d10b33e8218Douglas Gregor ASTContext &Context); 25278e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 252825cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 252925cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == TemplateSpecialization; 25308e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor } 2531dd13e8468462e60971487bcd5915419762dab814Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 25328e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor}; 25338e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 25344578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// \brief The injected class name of a C++ class template or class 25354578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// template partial specialization. Used to record that a type was 25364578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// spelled with a bare identifier rather than as a template-id; the 25374578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// equivalent for non-templated classes is just RecordType. 253855851d6d117e79db3a891bcb821acd19592b2178John McCall/// 25394578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// Injected class name types are always dependent. Template 25404578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// instantiation turns these into RecordTypes. 254155851d6d117e79db3a891bcb821acd19592b2178John McCall/// 25424578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// Injected class name types are always canonical. This works 25434578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// because it is impossible to compare an injected class name type 25444578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// with the corresponding non-injected template type, for the same 25454578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// reason that it is impossible to directly compare template 25464578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// parameters from different dependent contexts: injected class name 25474578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// types can only occur within the scope of a particular templated 25484578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// declaration, and within that scope every template specialization 25494578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// will canonicalize to the injected class name (when appropriate 25504578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall/// according to the rules of the language). 255155851d6d117e79db3a891bcb821acd19592b2178John McCallclass InjectedClassNameType : public Type { 255255851d6d117e79db3a891bcb821acd19592b2178John McCall CXXRecordDecl *Decl; 255355851d6d117e79db3a891bcb821acd19592b2178John McCall 25544578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// The template specialization which this type represents. 25554578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// For example, in 25564578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// template <class T> class A { ... }; 25574578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// this is A<T>, whereas in 25584578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// template <class X, class Y> class A<B<X,Y> > { ... }; 25594578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// this is A<B<X,Y> >. 25604578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// 25614578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// It is always unqualified, always a template specialization type, 25624578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall /// and always dependent. 25634578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall QualType InjectedType; 256455851d6d117e79db3a891bcb821acd19592b2178John McCall 256555851d6d117e79db3a891bcb821acd19592b2178John McCall friend class ASTContext; // ASTContext creates these. 2566a8d7ca6e37fb2aba356c16ca9c31cafa7ae68584Douglas Gregor friend class TagDecl; // TagDecl mutilates the Decl 2567f2606db18b5d64f241d74dc4e967347ad3da4792Argiris Kirtzidis friend class PCHReader; // FIXME: ASTContext::getInjectedClassNameType is not 2568f2606db18b5d64f241d74dc4e967347ad3da4792Argiris Kirtzidis // currently suitable for PCH reading, too much 2569f2606db18b5d64f241d74dc4e967347ad3da4792Argiris Kirtzidis // interdependencies. 25704578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall InjectedClassNameType(CXXRecordDecl *D, QualType TST) 25714578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall : Type(InjectedClassName, QualType(), true), 25724578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall Decl(D), InjectedType(TST) { 257355851d6d117e79db3a891bcb821acd19592b2178John McCall assert(isa<TemplateSpecializationType>(TST)); 257455851d6d117e79db3a891bcb821acd19592b2178John McCall assert(!TST.hasQualifiers()); 25754578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall assert(TST->isDependentType()); 257655851d6d117e79db3a891bcb821acd19592b2178John McCall } 257755851d6d117e79db3a891bcb821acd19592b2178John McCall 257855851d6d117e79db3a891bcb821acd19592b2178John McCallpublic: 25794578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall QualType getInjectedSpecializationType() const { return InjectedType; } 25804578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall const TemplateSpecializationType *getInjectedTST() const { 25814578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall return cast<TemplateSpecializationType>(InjectedType.getTypePtr()); 258255851d6d117e79db3a891bcb821acd19592b2178John McCall } 258355851d6d117e79db3a891bcb821acd19592b2178John McCall 258455851d6d117e79db3a891bcb821acd19592b2178John McCall CXXRecordDecl *getDecl() const { return Decl; } 258555851d6d117e79db3a891bcb821acd19592b2178John McCall 25864578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall bool isSugared() const { return false; } 25874578a3a1441eb22b68d909fa35d82e6ee7204e38John McCall QualType desugar() const { return QualType(this, 0); } 258855851d6d117e79db3a891bcb821acd19592b2178John McCall 258955851d6d117e79db3a891bcb821acd19592b2178John McCall static bool classof(const Type *T) { 259055851d6d117e79db3a891bcb821acd19592b2178John McCall return T->getTypeClass() == InjectedClassName; 259155851d6d117e79db3a891bcb821acd19592b2178John McCall } 259255851d6d117e79db3a891bcb821acd19592b2178John McCall static bool classof(const InjectedClassNameType *T) { return true; } 259355851d6d117e79db3a891bcb821acd19592b2178John McCall}; 259455851d6d117e79db3a891bcb821acd19592b2178John McCall 2595ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// \brief The kind of a tag type. 2596ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraenum TagTypeKind { 2597ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "struct" keyword. 2598ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TTK_Struct, 2599ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "union" keyword. 2600ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TTK_Union, 2601ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "class" keyword. 2602ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TTK_Class, 2603ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "enum" keyword. 2604ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TTK_Enum 2605ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara}; 2606ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2607ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or 2608ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// introduces an elaborated-type-specifier. 2609ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregorenum ElaboratedTypeKeyword { 2610ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor /// \brief The "struct" keyword introduces the elaborated-type-specifier. 2611ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor ETK_Struct, 2612ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor /// \brief The "union" keyword introduces the elaborated-type-specifier. 2613ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor ETK_Union, 2614ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "class" keyword introduces the elaborated-type-specifier. 2615ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ETK_Class, 2616ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor /// \brief The "enum" keyword introduces the elaborated-type-specifier. 2617ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ETK_Enum, 2618ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "typename" keyword precedes the qualified type name, e.g., 2619ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \c typename T::type. 2620ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ETK_Typename, 2621ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief No keyword precedes the qualified type name. 2622ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ETK_None 2623ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor}; 2624ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2625ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword. 2626ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// The keyword in stored in the free bits of the base class. 2627ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// Also provides a few static helpers for converting and printing 2628ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// elaborated type keyword and tag type kind enumerations. 2629ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraclass TypeWithKeyword : public Type { 2630ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// Keyword - Encodes an ElaboratedTypeKeyword enumeration constant. 2631ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara unsigned Keyword : 3; 2632ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2633ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraprotected: 2634ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, 2635ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara QualType Canonical, bool dependent) 2636ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara : Type(tc, Canonical, dependent), Keyword(Keyword) {} 2637ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2638ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnarapublic: 2639ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara virtual ~TypeWithKeyword(); // pin vtable to Type.cpp 2640ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2641ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ElaboratedTypeKeyword getKeyword() const { 2642ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara return static_cast<ElaboratedTypeKeyword>(Keyword); 2643ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara } 2644ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2645ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST) 2646ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// into an elaborated type keyword. 2647ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec); 2648ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2649ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST) 2650ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// into a tag type kind. It is an error to provide a type specifier 2651ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// which *isn't* a tag kind here. 2652ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec); 2653ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2654ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// getKeywordForTagDeclKind - Converts a TagTypeKind into an 2655ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// elaborated type keyword. 2656ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag); 2657ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2658ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// getTagTypeKindForKeyword - Converts an elaborated type keyword into 2659ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara // a TagTypeKind. It is an error to provide an elaborated type keyword 2660ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// which *isn't* a tag kind here. 2661ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword); 2662ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2663ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword); 2664ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2665ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static const char *getKeywordName(ElaboratedTypeKeyword Keyword); 2666ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2667ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static const char *getTagTypeKindName(TagTypeKind Kind) { 2668ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara return getKeywordName(getKeywordForTagTypeKind(Kind)); 2669ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara } 2670ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2671ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara class CannotCastToThisType {}; 2672ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static CannotCastToThisType classof(const Type *); 2673ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara}; 2674ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2675ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// \brief Represents a type that was referred to using an elaborated type 2676ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type, 2677ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// or both. 2678734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// 2679734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// This type is used to keep track of a type name as written in the 2680ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// source code, including tag keywords and any nested-name-specifiers. 2681ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// The type itself is always "sugar", used to express what was written 2682ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// in the source code but containing no additional semantic information. 2683ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode { 2684ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 26851e589cc31d339860b9df61870930961601d68120Douglas Gregor /// \brief The nested name specifier containing the qualifier. 26861e589cc31d339860b9df61870930961601d68120Douglas Gregor NestedNameSpecifier *NNS; 2687734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2688734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor /// \brief The type that this qualified name refers to. 2689734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor QualType NamedType; 2690734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2691ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 2692ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara QualType NamedType, QualType CanonType) 2693ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara : TypeWithKeyword(Keyword, Elaborated, CanonType, 2694ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara NamedType->isDependentType()), 2695ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara NNS(NNS), NamedType(NamedType) { 2696ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara assert(!(Keyword == ETK_None && NNS == 0) && 2697ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara "ElaboratedType cannot have elaborated type keyword " 2698ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara "and name qualifier both null."); 2699ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara } 2700734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2701734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor friend class ASTContext; // ASTContext creates these 2702734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2703734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorpublic: 270452b136ace347ee82e11145927e37980157bacb35John McCall ~ElaboratedType(); 2705ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 27061e589cc31d339860b9df61870930961601d68120Douglas Gregor /// \brief Retrieve the qualification on this type. 27071e589cc31d339860b9df61870930961601d68120Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2708734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2709734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 2710734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor QualType getNamedType() const { return NamedType; } 2711734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 27120afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Remove a single level of sugar. 27130afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return getNamedType(); } 27140afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 27150afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall /// \brief Returns whether this type directly provides sugar. 27160afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return true; } 27170afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2718734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2719ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara Profile(ID, getKeyword(), NNS, NamedType); 2720734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor } 2721734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2722ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 2723ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara NestedNameSpecifier *NNS, QualType NamedType) { 2724ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ID.AddInteger(Keyword); 27251e589cc31d339860b9df61870930961601d68120Douglas Gregor ID.AddPointer(NNS); 27261e589cc31d339860b9df61870930961601d68120Douglas Gregor NamedType.Profile(ID); 27271e589cc31d339860b9df61870930961601d68120Douglas Gregor } 2728734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 272925cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 2730ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara return T->getTypeClass() == Elaborated; 2731734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor } 2732ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static bool classof(const ElaboratedType *T) { return true; } 2733734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor}; 2734734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 2735ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// \brief Represents a qualified type name for which the type name is 2736ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// dependent. 2737d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor/// 2738ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// DependentNameType represents a class of dependent types that involve a 2739ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent) 2740ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a 2741ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// typename-specifier), "class", "struct", "union", or "enum" (for a 2742ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we 2743ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier). 2744ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { 2745ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2746d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor /// \brief The nested name specifier containing the qualifier. 2747d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor NestedNameSpecifier *NNS; 2748d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2749d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor /// \brief The type that this typename specifier refers to. 275052b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *Name; 2751d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2752ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 2753ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor const IdentifierInfo *Name, QualType CanonType) 2754ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara : TypeWithKeyword(Keyword, DependentName, CanonType, true), 2755ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara NNS(NNS), Name(Name) { 275625cf760b54d3b88633827501013bc51a29b28abaMike Stump assert(NNS->isDependent() && 2757725b41e4eefc6d19b6215f24489acbc2e1641765Douglas Gregor "DependentNameType requires a dependent nested-name-specifier"); 2758d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2759d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2760d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor friend class ASTContext; // ASTContext creates these 2761d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2762d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregorpublic: 276352b136ace347ee82e11145927e37980157bacb35John McCall virtual ~DependentNameType(); 2764ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 2765d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor /// \brief Retrieve the qualification on this type. 2766d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2767d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 276877da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 276977da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// identifier. 277077da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// 277177da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 277277da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// form of the original typename was terminated by an identifier, 277377da58034d00866f3261d2c657a5823578f73028Douglas Gregor /// e.g., "typename T::type". 277425cf760b54d3b88633827501013bc51a29b28abaMike Stump const IdentifierInfo *getIdentifier() const { 277552b136ace347ee82e11145927e37980157bacb35John McCall return Name; 277677da58034d00866f3261d2c657a5823578f73028Douglas Gregor } 2777d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 27780afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 27790afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 27800afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2781d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2782ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara Profile(ID, getKeyword(), NNS, Name); 2783d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2784d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 2785ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 278652b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name) { 2787ca7a15360ebda535be0f3281baf6bd4310b9b6d4Douglas Gregor ID.AddInteger(Keyword); 2788d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor ID.AddPointer(NNS); 278952b136ace347ee82e11145927e37980157bacb35John McCall ID.AddPointer(Name); 2790d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2791d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 279225cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 2793725b41e4eefc6d19b6215f24489acbc2e1641765Douglas Gregor return T->getTypeClass() == DependentName; 2794d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor } 2795725b41e4eefc6d19b6215f24489acbc2e1641765Douglas Gregor static bool classof(const DependentNameType *T) { return true; } 2796d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor}; 2797d30226003ea60119b19901b7813821c7ec3d7e55Douglas Gregor 279852b136ace347ee82e11145927e37980157bacb35John McCall/// DependentTemplateSpecializationType - Represents a template 279952b136ace347ee82e11145927e37980157bacb35John McCall/// specialization type whose template cannot be resolved, e.g. 280052b136ace347ee82e11145927e37980157bacb35John McCall/// A<T>::template B<T> 280152b136ace347ee82e11145927e37980157bacb35John McCallclass DependentTemplateSpecializationType : 280252b136ace347ee82e11145927e37980157bacb35John McCall public TypeWithKeyword, public llvm::FoldingSetNode { 280352b136ace347ee82e11145927e37980157bacb35John McCall 280452b136ace347ee82e11145927e37980157bacb35John McCall /// \brief The nested name specifier containing the qualifier. 280552b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *NNS; 280652b136ace347ee82e11145927e37980157bacb35John McCall 280752b136ace347ee82e11145927e37980157bacb35John McCall /// \brief The identifier of the template. 280852b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *Name; 280952b136ace347ee82e11145927e37980157bacb35John McCall 281052b136ace347ee82e11145927e37980157bacb35John McCall /// \brief - The number of template arguments named in this class 281152b136ace347ee82e11145927e37980157bacb35John McCall /// template specialization. 281252b136ace347ee82e11145927e37980157bacb35John McCall unsigned NumArgs; 281352b136ace347ee82e11145927e37980157bacb35John McCall 281452b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument *getArgBuffer() const { 281552b136ace347ee82e11145927e37980157bacb35John McCall return reinterpret_cast<const TemplateArgument*>(this+1); 281652b136ace347ee82e11145927e37980157bacb35John McCall } 281752b136ace347ee82e11145927e37980157bacb35John McCall TemplateArgument *getArgBuffer() { 281852b136ace347ee82e11145927e37980157bacb35John McCall return reinterpret_cast<TemplateArgument*>(this+1); 281952b136ace347ee82e11145927e37980157bacb35John McCall } 282052b136ace347ee82e11145927e37980157bacb35John McCall 282102cd8e64ab4b62f88c62f63320ddd17466764022John McCall DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 282252b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *NNS, 282352b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *Name, 282452b136ace347ee82e11145927e37980157bacb35John McCall unsigned NumArgs, 282552b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument *Args, 282652b136ace347ee82e11145927e37980157bacb35John McCall QualType Canon); 282752b136ace347ee82e11145927e37980157bacb35John McCall 282852b136ace347ee82e11145927e37980157bacb35John McCall virtual void Destroy(ASTContext& C); 282952b136ace347ee82e11145927e37980157bacb35John McCall 283052b136ace347ee82e11145927e37980157bacb35John McCall friend class ASTContext; // ASTContext creates these 283152b136ace347ee82e11145927e37980157bacb35John McCall 283252b136ace347ee82e11145927e37980157bacb35John McCallpublic: 283352b136ace347ee82e11145927e37980157bacb35John McCall virtual ~DependentTemplateSpecializationType(); 283452b136ace347ee82e11145927e37980157bacb35John McCall 283552b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *getQualifier() const { return NNS; } 283652b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *getIdentifier() const { return Name; } 283752b136ace347ee82e11145927e37980157bacb35John McCall 283852b136ace347ee82e11145927e37980157bacb35John McCall /// \brief Retrieve the template arguments. 283952b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument *getArgs() const { 284052b136ace347ee82e11145927e37980157bacb35John McCall return getArgBuffer(); 284152b136ace347ee82e11145927e37980157bacb35John McCall } 284252b136ace347ee82e11145927e37980157bacb35John McCall 284352b136ace347ee82e11145927e37980157bacb35John McCall /// \brief Retrieve the number of template arguments. 284452b136ace347ee82e11145927e37980157bacb35John McCall unsigned getNumArgs() const { return NumArgs; } 284552b136ace347ee82e11145927e37980157bacb35John McCall 284652b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 284752b136ace347ee82e11145927e37980157bacb35John McCall 284852b136ace347ee82e11145927e37980157bacb35John McCall typedef const TemplateArgument * iterator; 284952b136ace347ee82e11145927e37980157bacb35John McCall iterator begin() const { return getArgs(); } 285052b136ace347ee82e11145927e37980157bacb35John McCall iterator end() const; // inline in TemplateBase.h 285152b136ace347ee82e11145927e37980157bacb35John McCall 285252b136ace347ee82e11145927e37980157bacb35John McCall bool isSugared() const { return false; } 285352b136ace347ee82e11145927e37980157bacb35John McCall QualType desugar() const { return QualType(this, 0); } 285452b136ace347ee82e11145927e37980157bacb35John McCall 285502cd8e64ab4b62f88c62f63320ddd17466764022John McCall void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context) { 285652b136ace347ee82e11145927e37980157bacb35John McCall Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs()); 285752b136ace347ee82e11145927e37980157bacb35John McCall } 285852b136ace347ee82e11145927e37980157bacb35John McCall 285952b136ace347ee82e11145927e37980157bacb35John McCall static void Profile(llvm::FoldingSetNodeID &ID, 286052b136ace347ee82e11145927e37980157bacb35John McCall ASTContext &Context, 286152b136ace347ee82e11145927e37980157bacb35John McCall ElaboratedTypeKeyword Keyword, 286252b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *Qualifier, 286352b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *Name, 286452b136ace347ee82e11145927e37980157bacb35John McCall unsigned NumArgs, 286552b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument *Args); 286652b136ace347ee82e11145927e37980157bacb35John McCall 286752b136ace347ee82e11145927e37980157bacb35John McCall static bool classof(const Type *T) { 286852b136ace347ee82e11145927e37980157bacb35John McCall return T->getTypeClass() == DependentTemplateSpecialization; 286952b136ace347ee82e11145927e37980157bacb35John McCall } 287052b136ace347ee82e11145927e37980157bacb35John McCall static bool classof(const DependentTemplateSpecializationType *T) { 287152b136ace347ee82e11145927e37980157bacb35John McCall return true; 287252b136ace347ee82e11145927e37980157bacb35John McCall } 287352b136ace347ee82e11145927e37980157bacb35John McCall}; 287452b136ace347ee82e11145927e37980157bacb35John McCall 2875f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// ObjCObjectType - Represents a class type in Objective C. 2876f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// Every Objective C type is a combination of a base type and a 2877f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// list of protocols. 2878f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 2879f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// Given the following declarations: 2880f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// @class C; 2881f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// @protocol P; 2882f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 2883f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType 2884f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// with base C and no protocols. 2885f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 2886f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P]. 2887f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 2888cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose 2889cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType 2890cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// and no protocols. 2891f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 2892cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType 2893cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually 2894cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// this should get its own sugar class to better represent the source. 2895f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallclass ObjCObjectType : public Type { 2896f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // Pad the bit count up so that NumProtocols is 2-byte aligned 2897f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall unsigned : BitsRemainingInType - 16; 2898f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2899f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// \brief The number of protocols stored after the 2900f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// ObjCObjectPointerType node. 2901f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// 2902cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// These protocols are those written directly on the type. If 2903cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// protocol qualifiers ever become additive, the iterators will 2904cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// get kindof complicated. 2905cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// 2906f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// In the canonical object type, these are sorted alphabetically 2907f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// and uniqued. 2908f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall unsigned NumProtocols : 16; 290977763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff 2910f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// Either a BuiltinType or an InterfaceType or sugar for either. 2911f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall QualType BaseType; 2912f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2913f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCProtocolDecl * const *getProtocolStorage() const { 2914f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return const_cast<ObjCObjectType*>(this)->getProtocolStorage(); 2915f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 2916f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2917f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCProtocolDecl **getProtocolStorage(); 2918f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2919f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallprotected: 2920f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCObjectType(QualType Canonical, QualType Base, 2921f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCProtocolDecl * const *Protocols, unsigned NumProtocols); 2922f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2923f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall enum Nonce_ObjCInterface { Nonce_ObjCInterface }; 2924f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCObjectType(enum Nonce_ObjCInterface) 2925f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall : Type(ObjCInterface, QualType(), false), 2926f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall NumProtocols(0), 2927f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall BaseType(QualType(this_(), 0)) {} 292877763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff 2929949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 2930949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor Linkage getLinkageImpl() const; // key function 2931949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 293281f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroffpublic: 2933cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getBaseType - Gets the base type of this object type. This is 2934cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// always (possibly sugar for) one of: 2935cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// - the 'id' builtin type (as opposed to the 'id' type visible to the 2936cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// user, which is a typedef for an ObjCPointerType) 2937cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// - the 'Class' builtin type (same caveat) 2938cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// - an ObjCObjectType (currently always an ObjCInterfaceType) 2939f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall QualType getBaseType() const { return BaseType; } 294039abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek 2941f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCId() const { 2942f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId); 2943f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 2944f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCClass() const { 2945f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass); 2946f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 2947f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); } 2948f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); } 2949f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCUnqualifiedIdOrClass() const { 2950f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall if (!qual_empty()) return false; 2951f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>()) 2952f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return T->getKind() == BuiltinType::ObjCId || 2953f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall T->getKind() == BuiltinType::ObjCClass; 2954f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return false; 2955f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 2956f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); } 2957f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); } 2958f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2959f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// Gets the interface declaration for this object type, if the base type 2960f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// really is an interface. 2961f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCInterfaceDecl *getInterface() const; 2962f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2963f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall typedef ObjCProtocolDecl * const *qual_iterator; 2964f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2965f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_iterator qual_begin() const { return getProtocolStorage(); } 2966f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); } 2967f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2968f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool qual_empty() const { return getNumProtocols() == 0; } 296925cf760b54d3b88633827501013bc51a29b28abaMike Stump 297077763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 297177763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff /// interface type, or 0 if there are none. 297239abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek unsigned getNumProtocols() const { return NumProtocols; } 2973329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 2974f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// \brief Fetch a protocol by index. 2975f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor ObjCProtocolDecl *getProtocol(unsigned I) const { 2976f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor assert(I < getNumProtocols() && "Out-of-range protocol access"); 2977f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor return qual_begin()[I]; 2978f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor } 2979f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor 29800afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 29810afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 29820afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 2983f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall static bool classof(const Type *T) { 2984f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return T->getTypeClass() == ObjCObject || 2985f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall T->getTypeClass() == ObjCInterface; 2986f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 2987f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall static bool classof(const ObjCObjectType *) { return true; } 2988f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall}; 2989f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2990f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation 2991f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// of ObjCObjectType, so as to not increase the footprint of 2992f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// ObjCInterfaceType. Code outside of ASTContext and the core type 2993f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// system should not reference this type. 2994f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode { 2995f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall friend class ASTContext; 2996f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 2997f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // If anyone adds fields here, ObjCObjectType::getProtocolStorage() 2998f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // will need to be modified. 2999f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3000f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCObjectTypeImpl(QualType Canonical, QualType Base, 3001f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCProtocolDecl * const *Protocols, 3002f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall unsigned NumProtocols) 3003f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {} 3004f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3005f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallpublic: 3006f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall void Destroy(ASTContext& C); // key function 3007f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 300877763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 300925cf760b54d3b88633827501013bc51a29b28abaMike Stump static void Profile(llvm::FoldingSetNodeID &ID, 3010f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall QualType Base, 3011f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCProtocolDecl *const *protocols, 3012f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall unsigned NumProtocols); 3013f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall}; 301425cf760b54d3b88633827501013bc51a29b28abaMike Stump 3015f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() { 3016f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return reinterpret_cast<ObjCProtocolDecl**>( 3017f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall static_cast<ObjCObjectTypeImpl*>(this) + 1); 3018f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall} 3019f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3020f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 3021f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// object oriented design. They basically correspond to C++ classes. There 3022f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// are two kinds of interface types, normal interfaces like "NSString" and 3023f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// qualified interfaces, which are qualified with a protocol list like 3024f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// "NSString<NSCopyable, NSAmazing>". 3025cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// 3026cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// ObjCInterfaceType guarantees the following properties when considered 3027cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// as a subtype of its superclass, ObjCObjectType: 3028cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// - There are no protocol qualifiers. To reinforce this, code which 3029cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// tries to invoke the protocol methods via an ObjCInterfaceType will 3030cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// fail to compile. 3031cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// - It is its own base type. That is, if T is an ObjCInterfaceType*, 3032cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// T->getBaseType() == QualType(T, 0). 3033f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallclass ObjCInterfaceType : public ObjCObjectType { 3034f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCInterfaceDecl *Decl; 3035f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3036f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCInterfaceType(const ObjCInterfaceDecl *D) 3037f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall : ObjCObjectType(Nonce_ObjCInterface), 3038f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall Decl(const_cast<ObjCInterfaceDecl*>(D)) {} 3039f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall friend class ASTContext; // ASTContext creates these. 3040f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallpublic: 3041f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall void Destroy(ASTContext& C); // key function 3042f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3043cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getDecl - Get the declaration of this interface. 3044f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCInterfaceDecl *getDecl() const { return Decl; } 3045f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3046f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isSugared() const { return false; } 3047f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall QualType desugar() const { return QualType(this, 0); } 3048b93a009003f19418ef0ef0d8a42a3895562c7391Douglas Gregor 304925cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 305025cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == ObjCInterface; 305181f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff } 305242730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 3053f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3054f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // Nonsense to "hide" certain members of ObjCObjectType within this 3055f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // class. People asking for protocols on an ObjCInterfaceType are 3056f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // not going to get what they want: ObjCInterfaceTypes are 3057f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // guaranteed to have no protocols. 3058f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall enum { 3059f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_iterator, 3060f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_begin, 3061f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_end, 3062f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall getNumProtocols, 3063f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall getProtocol 3064f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall }; 306581f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff}; 306681f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff 3067f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const { 3068f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall if (const ObjCInterfaceType *T = 3069f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall getBaseType()->getAs<ObjCInterfaceType>()) 3070f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return T->getDecl(); 3071f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return 0; 3072f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall} 3073f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3074cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// ObjCObjectPointerType - Used to represent a pointer to an 3075cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// Objective C object. These are constructed from pointer 3076cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar 3077cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// for one). In addition, the 'id' and 'Class' types are typedefs 3078cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>' 3079cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// are translated into these. 3080329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff/// 3081cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// Pointers to pointers to Objective C objects are still PointerTypes; 3082cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// only the first level of pointer gets it own type implementation. 3083329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 3084cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall QualType PointeeType; 308525cf760b54d3b88633827501013bc51a29b28abaMike Stump 3086f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCObjectPointerType(QualType Canonical, QualType Pointee) 3087f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall : Type(ObjCObjectPointer, Canonical, false), 3088f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall PointeeType(Pointee) {} 3089329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff friend class ASTContext; // ASTContext creates these. 309025cf760b54d3b88633827501013bc51a29b28abaMike Stump 3091949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregorprotected: 3092949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor virtual Linkage getLinkageImpl() const; 3093949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 3094329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffpublic: 309539abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek void Destroy(ASTContext& C); 309639abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek 3097cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getPointeeType - Gets the type pointed to by this ObjC pointer. 3098cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// The result will always be an ObjCObjectType or sugar thereof. 3099329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff QualType getPointeeType() const { return PointeeType; } 3100329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 3101cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getObjCObjectType - Gets the type pointed to by this ObjC 3102cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// pointer. This method always returns non-null. 3103cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// 3104cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// This method is equivalent to getPointeeType() except that 3105cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// it discards any typedefs (or other sugar) between this 3106cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// type and the "outermost" object type. So for: 3107cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// @class A; @protocol P; @protocol Q; 3108cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// typedef A<P> AP; 3109cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// typedef A A1; 3110cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// typedef A1<P> A1P; 3111cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// typedef A1P<Q> A1PQ; 3112cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A*', getObjectType() will return 'A'. 3113cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A<P>*', getObjectType() will return 'A<P>'. 3114cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'AP*', getObjectType() will return 'A<P>'. 3115cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A1*', getObjectType() will return 'A'. 3116cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A1<P>*', getObjectType() will return 'A1<P>'. 3117cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A1P*', getObjectType() will return 'A1<P>'. 3118cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because 3119cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// adding protocols to a protocol-qualified base discards the 3120cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// old qualifiers (for now). But if it didn't, getObjectType() 3121cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// would return 'A1P<Q>' (and we'd have to make iterating over 3122cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// qualifiers more complicated). 3123f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall const ObjCObjectType *getObjectType() const { 3124f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return PointeeType->getAs<ObjCObjectType>(); 3125f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 3126f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 3127cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getInterfaceType - If this pointer points to an Objective C 3128cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// @interface type, gets the type for that interface. Any protocol 3129cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// qualifiers on the interface are ignored. 3130cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// 3131cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// \return null if the base type for this pointer is 'id' or 'Class' 313225cf760b54d3b88633827501013bc51a29b28abaMike Stump const ObjCInterfaceType *getInterfaceType() const { 3133f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>(); 3134329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 3135cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 3136cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getInterfaceDecl - If this pointer points to an Objective @interface 3137cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// type, gets the declaration for that interface. 3138cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// 3139cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// \return null if the base type for this pointer is 'id' or 'Class' 3140329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff ObjCInterfaceDecl *getInterfaceDecl() const { 3141cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall return getObjectType()->getInterface(); 3142329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 3143cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 3144cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if 3145cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// its object type is the primitive 'id' type with no protocols. 3146329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCIdType() const { 3147f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->isObjCUnqualifiedId(); 3148329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 3149cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 3150cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// isObjCClassType - True if this is equivalent to the 'Class' type, 3151cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// i.e. if its object tive is the primitive 'Class' type with no protocols. 3152329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff bool isObjCClassType() const { 3153f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->isObjCUnqualifiedClass(); 31547bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff } 31552818bd26562e1a2b7d7e9fb31d72f698a5748289Fariborz Jahanian 3156cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some 3157cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// non-empty set of protocols. 315825cf760b54d3b88633827501013bc51a29b28abaMike Stump bool isObjCQualifiedIdType() const { 3159f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->isObjCQualifiedId(); 31607bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff } 3161cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 3162cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for 3163cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// some non-empty set of protocols. 316427bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff bool isObjCQualifiedClassType() const { 3165f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->isObjCQualifiedClass(); 3166329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 3167cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 3168cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// An iterator over the qualifiers on the object type. Provided 3169cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// for convenience. This will always iterate over the full set of 3170cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// protocols on a type, not just those provided directly. 3171f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall typedef ObjCObjectType::qual_iterator qual_iterator; 3172329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 317339abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek qual_iterator qual_begin() const { 3174f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->qual_begin(); 317539abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek } 3176f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_iterator qual_end() const { 3177f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->qual_end(); 317839abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek } 3179f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool qual_empty() const { return getObjectType()->qual_empty(); } 3180329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 3181cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getNumProtocols - Return the number of qualifying protocols on 3182cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// the object type. 3183f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall unsigned getNumProtocols() const { 3184f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->getNumProtocols(); 3185f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 3186329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff 3187cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// \brief Retrieve a qualifying protocol by index on the object 3188cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// type. 3189f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor ObjCProtocolDecl *getProtocol(unsigned I) const { 3190f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->getProtocol(I); 3191f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor } 3192f584f2392641e1ef754c17a46f2e52334ebbf545Douglas Gregor 31930afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall bool isSugared() const { return false; } 31940afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall QualType desugar() const { return QualType(this, 0); } 31950afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall 3196cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall void Profile(llvm::FoldingSetNodeID &ID) { 3197cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall Profile(ID, getPointeeType()); 3198cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall } 3199f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { 3200f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ID.AddPointer(T.getAsOpaquePtr()); 3201f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 320225cf760b54d3b88633827501013bc51a29b28abaMike Stump static bool classof(const Type *T) { 320325cf760b54d3b88633827501013bc51a29b28abaMike Stump return T->getTypeClass() == ObjCObjectPointer; 3204329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff } 3205329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 3206329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff}; 3207fd3d5fdac0d25464e1b9c36bc646965494d44f66Argiris Kirtzidis 32083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall/// A qualifier set is used to build a set of qualifiers. 32093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallclass QualifierCollector : public Qualifiers { 32103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall ASTContext *Context; 32113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallpublic: 32133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector(Qualifiers Qs = Qualifiers()) 32143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Qualifiers(Qs), Context(0) {} 32153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector(ASTContext &Context, Qualifiers Qs = Qualifiers()) 32163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall : Qualifiers(Qs), Context(&Context) {} 32173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall void setContext(ASTContext &C) { Context = &C; } 32193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Collect any qualifiers on the given type and return an 32213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// unqualified type. 32223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *strip(QualType QT) { 3223c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor addFastQualifiers(QT.getLocalFastQualifiers()); 3224c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (QT.hasLocalNonFastQualifiers()) { 32253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = QT.getExtQualsUnsafe(); 32263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Context = &EQ->getContext(); 32273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall addQualifiers(EQ->getQualifiers()); 32283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getBaseType(); 32293ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 32303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return QT.getTypePtrUnsafe(); 32313ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 32323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Apply the collected qualifiers to the given type. 32343ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType apply(QualType QT) const; 32353ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32363ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall /// Apply the collected qualifiers to the given type. 32373ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualType apply(const Type* T) const; 32383ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32393ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall}; 32403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 32413ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3242b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner// Inline function definitions. 32434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 32447480534aa1979f5c8a6c1d59ede223ba21f280e5John McCallinline bool QualType::isCanonical() const { 32457480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall const Type *T = getTypePtr(); 3246c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalQualifiers()) 32477480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall return T->isCanonicalUnqualified() && !isa<ArrayType>(T); 32487480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall return T->isCanonicalUnqualified(); 32497480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall} 32507480534aa1979f5c8a6c1d59ede223ba21f280e5John McCall 32514ea8425c9601895fa137f877bc784f75f20adac6John McCallinline bool QualType::isCanonicalAsParam() const { 3252c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalQualifiers()) return false; 32534ea8425c9601895fa137f877bc784f75f20adac6John McCall const Type *T = getTypePtr(); 32544ea8425c9601895fa137f877bc784f75f20adac6John McCall return T->isCanonicalUnqualified() && 32554ea8425c9601895fa137f877bc784f75f20adac6John McCall !isa<FunctionType>(T) && !isa<ArrayType>(T); 32564ea8425c9601895fa137f877bc784f75f20adac6John McCall} 32574ea8425c9601895fa137f877bc784f75f20adac6John McCall 32584f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::isConstQualified() const { 32594f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return isLocalConstQualified() || 32604f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalConstQualified(); 32614f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 32624f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 32634f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::isRestrictQualified() const { 32644f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return isLocalRestrictQualified() || 32654f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalRestrictQualified(); 32664f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 32674f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 32684f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 32694f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::isVolatileQualified() const { 32704f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return isLocalVolatileQualified() || 32714f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().isLocalVolatileQualified(); 32724f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 32734f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 32744f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline bool QualType::hasQualifiers() const { 32754f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return hasLocalQualifiers() || 32764f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers(); 32774f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 32784f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 32794f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline Qualifiers QualType::getQualifiers() const { 32804f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor Qualifiers Quals = getLocalQualifiers(); 32814f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor Quals.addQualifiers( 32824f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().getLocalQualifiers()); 32834f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return Quals; 32844f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 32854f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor 32864f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregorinline unsigned QualType::getCVRQualifiers() const { 32874f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor return getLocalCVRQualifiers() | 32884f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor getTypePtr()->getCanonicalTypeInternal().getLocalCVRQualifiers(); 32894f4b5bcdce90be1ebc9373c500cc07cfb458400cDouglas Gregor} 32906d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth 32916d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// getCVRQualifiersThroughArrayTypes - If there are CVR qualifiers for this 32926d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// type, returns them. Otherwise, if this is an array type, recurses 32936d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// on the element type until some qualifiers have been found or a non-array 32946d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth/// type reached. 32956d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruthinline unsigned QualType::getCVRQualifiersThroughArrayTypes() const { 32966d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth if (unsigned Quals = getCVRQualifiers()) 32976d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth return Quals; 32986d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth QualType CT = getTypePtr()->getCanonicalTypeInternal(); 32996d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 33006d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth return AT->getElementType().getCVRQualifiersThroughArrayTypes(); 33016d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth return 0; 33026d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth} 33036d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth 33043ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeConst() { 33053ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeFastQualifiers(Qualifiers::Const); 33063ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall} 33073ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 33083ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeRestrict() { 33093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeFastQualifiers(Qualifiers::Restrict); 33103ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall} 33113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 33123ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeVolatile() { 33133ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector Qc; 33143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *Ty = Qc.strip(*this); 33153ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (Qc.hasVolatile()) { 33163ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qc.removeVolatile(); 33173ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall *this = Qc.apply(Ty); 33183ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 33193ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall} 33203ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 33213ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline void QualType::removeCVRQualifiers(unsigned Mask) { 3322451b7b9a60208869cf5d6d958134cb104343949fJohn McCall assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits"); 33233ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 33243ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // Fast path: we don't need to touch the slow qualifiers. 33253ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (!(Mask & ~Qualifiers::FastMask)) { 33263ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall removeFastQualifiers(Mask); 33273ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return; 33283ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 33293ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 33303ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall QualifierCollector Qc; 33313ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const Type *Ty = Qc.strip(*this); 33323ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall Qc.removeCVRQualifiers(Mask); 33333ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall *this = Qc.apply(Ty); 33342a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb} 33352a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 33362a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// getAddressSpace - Return the address space of this type. 33372a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambinline unsigned QualType::getAddressSpace() const { 3338c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalNonFastQualifiers()) { 33393ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = getExtQualsUnsafe(); 33403ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasAddressSpace()) 33413ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getAddressSpace(); 33423ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 33433ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 334401ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 3345c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (CT.hasLocalNonFastQualifiers()) { 33463ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = CT.getExtQualsUnsafe(); 33473ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasAddressSpace()) 33483ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getAddressSpace(); 33493ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 33503ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 335101ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 3352a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return AT->getElementType().getAddressSpace(); 335301ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 3354efc11216a5755f69b5540289aa2dd374d4bc82abNate Begeman return RT->getAddressSpace(); 33552a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return 0; 33562a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb} 3357b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner 3358af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 33593ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const { 3360c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (hasLocalNonFastQualifiers()) { 33613ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = getExtQualsUnsafe(); 33623ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasObjCGCAttr()) 33633ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getObjCGCAttr(); 33643ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 33653ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3366af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 3367c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor if (CT.hasLocalNonFastQualifiers()) { 33683ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall const ExtQuals *EQ = CT.getExtQualsUnsafe(); 33693ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (EQ->hasObjCGCAttr()) 33703ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return EQ->getObjCGCAttr(); 33713ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall } 33723ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall 3373af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 3374af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian return AT->getElementType().getObjCGCAttr(); 3375cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *PT = CT->getAs<ObjCObjectPointerType>()) 337625cf760b54d3b88633827501013bc51a29b28abaMike Stump return PT->getPointeeType().getObjCGCAttr(); 33774bb774e2352b6c5f459b345a5e0f41bd244e70a7Fariborz Jahanian // We most look at all pointer types, not just pointer to interface types. 33784bb774e2352b6c5f459b345a5e0f41bd244e70a7Fariborz Jahanian if (const PointerType *PT = CT->getAs<PointerType>()) 337925cf760b54d3b88633827501013bc51a29b28abaMike Stump return PT->getPointeeType().getObjCGCAttr(); 33803ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall return Qualifiers::GCNone; 3381af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian} 33821bb806498909a43a7829edb21c42606335d69694Mike Stump 3383433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { 3384433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola if (const PointerType *PT = t.getAs<PointerType>()) { 3385cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>()) 3386433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola return FT->getExtInfo(); 3387433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola } else if (const FunctionType *FT = t.getAs<FunctionType>()) 3388433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola return FT->getExtInfo(); 33891bb806498909a43a7829edb21c42606335d69694Mike Stump 3390433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola return FunctionType::ExtInfo(); 33911bb806498909a43a7829edb21c42606335d69694Mike Stump} 339225cf760b54d3b88633827501013bc51a29b28abaMike Stump 3393433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { 3394433d7d2c70b9be3f9edd40579f512ecab8755049Rafael Espindola return getFunctionExtInfo(*t); 339531cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor} 339631cc550280fe5c50d7f6ff57978ec083d284b53bDouglas Gregor 339745c5e7c236f638b5a783dd5843c7a52b3d279a89Douglas Gregor/// \brief Determine whether this set of qualifiers is a superset of the given 339845c5e7c236f638b5a783dd5843c7a52b3d279a89Douglas Gregor/// set of qualifiers. 339945c5e7c236f638b5a783dd5843c7a52b3d279a89Douglas Gregorinline bool Qualifiers::isSupersetOf(Qualifiers Other) const { 340045c5e7c236f638b5a783dd5843c7a52b3d279a89Douglas Gregor return Mask != Other.Mask && (Mask | Other.Mask) == Mask; 340145c5e7c236f638b5a783dd5843c7a52b3d279a89Douglas Gregor} 340245c5e7c236f638b5a783dd5843c7a52b3d279a89Douglas Gregor 34033fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 34043fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 34053fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// is more qualified than "const int", "volatile int", and 34063fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int". However, it is not more qualified than "const volatile 34073fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int". 34083fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 34093ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // FIXME: work on arbitrary qualifiers 34106d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes(); 34116d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes(); 34128fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner if (getAddressSpace() != Other.getAddressSpace()) 34138fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner return false; 34143fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 34153fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 34163fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 34173fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 34183fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// as qualified as the Other type. For example, "const volatile 34193fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 34203fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int", and "const volatile int". 34213fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 34223ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // FIXME: work on arbitrary qualifiers 34236d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes(); 34246d18ae945b0b85054942aaac9ee32011d5b8b34dChandler Carruth unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes(); 34258fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner if (getAddressSpace() != Other.getAddressSpace()) 34268fc38c21132d37ff76f624ab1dcfe03ba63e2518Chris Lattner return false; 34273fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 34283fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 34293fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 34303fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 34313fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int&), returns the type that the reference refers to ("const 34323fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 34333fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// throughout Sema to implement C++ 5p6: 34343fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// 34353fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 34363fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 34373fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// analysis, the expression designates the object or function 34383fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 34393fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline QualType QualType::getNonReferenceType() const { 3440d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 34413fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return RefType->getPointeeType(); 34423fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor else 34433fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return *this; 34443fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 34453fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 3446b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isFunctionType() const { 3447c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<FunctionType>(CanonicalType); 3448b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 3449b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isPointerType() const { 3450c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<PointerType>(CanonicalType); 3451b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 345279ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroffinline bool Type::isAnyPointerType() const { 345379ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroff return isPointerType() || isObjCObjectPointerType(); 345479ae19a7c9421e17ba26ea9cbf5a7f4dcc015cdeSteve Naroff} 34557aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffinline bool Type::isBlockPointerType() const { 3456c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<BlockPointerType>(CanonicalType); 34577aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff} 3458cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattnerinline bool Type::isReferenceType() const { 3459c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ReferenceType>(CanonicalType); 3460cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner} 3461ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlinline bool Type::isLValueReferenceType() const { 3462c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<LValueReferenceType>(CanonicalType); 3463ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl} 3464ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlinline bool Type::isRValueReferenceType() const { 3465c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<RValueReferenceType>(CanonicalType); 3466ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl} 346783b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenekinline bool Type::isFunctionPointerType() const { 3468d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const PointerType* T = getAs<PointerType>()) 346983b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek return T->getPointeeType()->isFunctionType(); 347083b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek else 347183b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek return false; 347283b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek} 34737555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlinline bool Type::isMemberPointerType() const { 3474c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<MemberPointerType>(CanonicalType); 34757555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl} 34767555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 3477d00cd9ec368acf3e615d55f659eca4639044ba7dTed Kremenek if (const MemberPointerType* T = getAs<MemberPointerType>()) 34787555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return T->getPointeeType()->isFunctionType(); 34797555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl else 34807555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return false; 34817555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl} 3482b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isArrayType() const { 3483c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ArrayType>(CanonicalType); 3484b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 3485a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isConstantArrayType() const { 3486c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ConstantArrayType>(CanonicalType); 3487a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 3488a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isIncompleteArrayType() const { 3489c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<IncompleteArrayType>(CanonicalType); 3490a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 3491a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isVariableArrayType() const { 3492c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<VariableArrayType>(CanonicalType); 3493a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 34941b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorinline bool Type::isDependentSizedArrayType() const { 3495c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType); 34961b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor} 3497b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isRecordType() const { 3498c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<RecordType>(CanonicalType); 3499b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 35003277df47de6b65b55721726dc3f7b294e70ef6feChris Lattnerinline bool Type::isAnyComplexType() const { 3501c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ComplexType>(CanonicalType); 35023277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner} 3503b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isVectorType() const { 3504c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<VectorType>(CanonicalType); 3505b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 3506af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemaninline bool Type::isExtVectorType() const { 3507c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ExtVectorType>(CanonicalType); 3508b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 3509c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroffinline bool Type::isObjCObjectPointerType() const { 3510c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<ObjCObjectPointerType>(CanonicalType); 3511c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff} 3512f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallinline bool Type::isObjCObjectType() const { 3513f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return isa<ObjCObjectType>(CanonicalType); 3514b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner} 351542730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 3516cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3517c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff return OPT->isObjCQualifiedIdType(); 3518c75c1a882cad91f2edc6a926eb8cd725abad2262Steve Naroff return false; 3519dcb2b1e489948a570ee07ca65e12d42edffa20efFariborz Jahanian} 352027bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroffinline bool Type::isObjCQualifiedClassType() const { 3521cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 352227bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff return OPT->isObjCQualifiedClassType(); 352327bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff return false; 352427bc49f518604f310aca9ed21be0bee12bdc6237Steve Naroff} 3525329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffinline bool Type::isObjCIdType() const { 3526cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3527329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return OPT->isObjCIdType(); 3528329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return false; 3529329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff} 3530329ec22704eee011640ebf37c29343e82fb984c6Steve Naroffinline bool Type::isObjCClassType() const { 3531cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3532329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return OPT->isObjCClassType(); 3533329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff return false; 3534329ec22704eee011640ebf37c29343e82fb984c6Steve Naroff} 3535a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanianinline bool Type::isObjCSelType() const { 35362818bd26562e1a2b7d7e9fb31d72f698a5748289Fariborz Jahanian if (const PointerType *OPT = getAs<PointerType>()) 35372818bd26562e1a2b7d7e9fb31d72f698a5748289Fariborz Jahanian return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); 3538a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian return false; 3539a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian} 35407bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroffinline bool Type::isObjCBuiltinType() const { 3541a238d6daa15f845738a8b15a3bc9f5b84617744bFariborz Jahanian return isObjCIdType() || isObjCClassType() || isObjCSelType(); 35427bffd37bd2642e9d1bf0d093e9c1a7b3467f3014Steve Naroff} 3543dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorinline bool Type::isTemplateTypeParmType() const { 3544c79209789205c9de5fcc7aedfd6308057d40b618Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType); 3545dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor} 3546dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 3547522fb671290dd5462bfd819401768686fa53e925Tom Careinline bool Type::isBuiltinType() const { 3548522fb671290dd5462bfd819401768686fa53e925Tom Care return getAs<BuiltinType>(); 3549522fb671290dd5462bfd819401768686fa53e925Tom Care} 3550522fb671290dd5462bfd819401768686fa53e925Tom Care 3551c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 3552cac0eaf6caa1035b6a971b32adeea895ba14715cJohn McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 3553c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 3554c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar return true; 3555c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar return false; 3556c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar} 3557c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar 355800fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor/// \brief Determines whether this is a type for which one can define 355900fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor/// an overloaded operator. 356000fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregorinline bool Type::isOverloadableType() const { 356100fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 356245014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor} 356345014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor 3564fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 3565fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 3566f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall isObjCObjectPointerType() || isNullPtrType()); 3567fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar} 3568fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar 35697c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 3570f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return isObjCObjectPointerType(); 35717c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian} 35727c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian 3573da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 3574da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// diagnostic with <<. 3575da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 3576da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner QualType T) { 3577da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 3578da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner Diagnostic::ak_qualtype); 3579da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner return DB; 3580da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner} 358125cf760b54d3b88633827501013bc51a29b28abaMike Stump 35828edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth/// Insertion operator for partial diagnostics. This allows sending QualType's 35838edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth/// into a diagnostic with <<. 35848edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruthinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, 35858edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth QualType T) { 35868edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 35878edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth Diagnostic::ak_qualtype); 35888edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth return PD; 35898edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth} 35908edbcc8c7084a7311da0ba56df59c758bed0db87Chandler Carruth 3591406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does 3592406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor// not try to look through a qualified type to get to an array type. 3593406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregortemplate<typename T, 3594406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor bool isArrayType = (llvm::is_same<T, ArrayType>::value || 3595406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor llvm::is_base_of<ArrayType, T>::value)> 3596406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { }; 3597406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor 3598406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregortemplate<typename T> 3599406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>; 3600406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor 3601f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek/// Member-template getAs<specific type>'. 3602f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenektemplate <typename T> const T *Type::getAs() const { 3603406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor ArrayType_cannot_be_used_with_getAs<T> at; 3604406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor (void)at; 3605406b56a9a0ed38e9fbcea1f51ea28ee3719517d3Douglas Gregor 3606f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // If this is directly a T type, return it. 3607f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek if (const T *Ty = dyn_cast<T>(this)) 3608f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek return Ty; 360925cf760b54d3b88633827501013bc51a29b28abaMike Stump 3610f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // If the canonical form of this type isn't the right kind, reject it. 36113ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall if (!isa<T>(CanonicalType)) 3612f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek return 0; 361325cf760b54d3b88633827501013bc51a29b28abaMike Stump 36143ddc81456e4ee7e1017f17860053f3eec505a50eJohn McCall // If this is a typedef for the type, strip the typedef off without 3615f5de0a3cbaa216daf2ea7e42611bbd1ebad42fa7Ted Kremenek // losing all typedef information. 36160afd9f4ac27a7cef40c7a879f4b3fac0c612a218John McCall return cast<T>(getUnqualifiedDesugaredType()); 361725cf760b54d3b88633827501013bc51a29b28abaMike Stump} 3618da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner 36194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner} // end namespace clang 36204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 36214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#endif 3622