Type.h revision b5adc4636f653b37891792d2a279e889dab0935f
1ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===// 2ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// 3ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// The LLVM Compiler Infrastructure 4ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// 5ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// This file is distributed under the University of Illinois Open Source 6ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// License. See LICENSE.TXT for details. 7ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// 8ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao//===----------------------------------------------------------------------===// 9ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// 10ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// This file defines the Type interface and subclasses. 11ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// 12ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao//===----------------------------------------------------------------------===// 13ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 14ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#ifndef LLVM_CLANG_AST_TYPE_H 15ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#define LLVM_CLANG_AST_TYPE_H 16ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 17ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "clang/Basic/Diagnostic.h" 188b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl#include "clang/Basic/ExceptionSpecificationType.h" 19ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "clang/Basic/IdentifierTable.h" 20ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "clang/Basic/Linkage.h" 21ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "clang/Basic/PartialDiagnostic.h" 2282254439b368de855d1e66440071017a1f2d4f0aJohn McCall#include "clang/Basic/Visibility.h" 23ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "clang/AST/NestedNameSpecifier.h" 24ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "clang/AST/TemplateName.h" 25ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "llvm/Support/type_traits.h" 269fe8c74a93ac8e92512615c5f83e7a328b3b0544David Blaikie#include "llvm/Support/ErrorHandling.h" 27ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "llvm/ADT/APSInt.h" 28ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "llvm/ADT/FoldingSet.h" 29cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor#include "llvm/ADT/Optional.h" 30ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "llvm/ADT/PointerIntPair.h" 31ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "llvm/ADT/PointerUnion.h" 329594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "clang/Basic/LLVM.h" 33ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 34ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaonamespace clang { 35ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao enum { 36f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor TypeAlignmentInBits = 4, 37ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao TypeAlignment = 1 << TypeAlignmentInBits 38ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao }; 39ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class Type; 40ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class ExtQuals; 41ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class QualType; 42ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 43ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 44ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaonamespace llvm { 45ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao template <typename T> 46ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class PointerLikeTypeTraits; 47ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao template<> 48ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class PointerLikeTypeTraits< ::clang::Type*> { 49ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao public: 50ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 51ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static inline ::clang::Type *getFromVoidPointer(void *P) { 52ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return static_cast< ::clang::Type*>(P); 53ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 54ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 55ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao }; 56ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao template<> 57ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class PointerLikeTypeTraits< ::clang::ExtQuals*> { 58ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao public: 59ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; } 60ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static inline ::clang::ExtQuals *getFromVoidPointer(void *P) { 61ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return static_cast< ::clang::ExtQuals*>(P); 62ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 63ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 64ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao }; 65ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 66ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao template <> 67ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao struct isPodLike<clang::QualType> { static const bool value = true; }; 68ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 69ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 70ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaonamespace clang { 71ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class ASTContext; 72162e1c1b487352434552147967c3dd296ebee2f7Richard Smith class TypedefNameDecl; 73ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class TemplateDecl; 74ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class TemplateTypeParmDecl; 75ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class NonTypeTemplateParmDecl; 76ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class TemplateTemplateParmDecl; 77ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class TagDecl; 78ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class RecordDecl; 79ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class CXXRecordDecl; 80ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class EnumDecl; 81ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class FieldDecl; 82ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class ObjCInterfaceDecl; 83ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class ObjCProtocolDecl; 84ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class ObjCMethodDecl; 85ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class UnresolvedUsingTypenameDecl; 86ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class Expr; 87ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class Stmt; 88ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class SourceLocation; 89ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class StmtIteratorBase; 90ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class TemplateArgument; 91ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class TemplateArgumentLoc; 92ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class TemplateArgumentListInfo; 93ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara class ElaboratedType; 943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall class ExtQuals; 953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall class ExtQualsTypeCommonBase; 96ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao struct PrintingPolicy; 97ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 98b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie template <typename> class CanQual; 99ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao typedef CanQual<Type> CanQualType; 100ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 101ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Provide forward declarations for all of the *Type classes 102ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#define TYPE(Class, Base) class Class##Type; 103ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "clang/AST/TypeNodes.def" 104ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 105ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Qualifiers - The collection of all-type qualifiers we support. 106ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Clang supports five independent qualifiers: 107ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// * C99: const, volatile, and restrict 108ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// * Embedded C (TR18037): address spaces 109ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// * Objective C: the GC attributes (none, weak, or strong) 110ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass Qualifiers { 111ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 112ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 113ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Const = 0x1, 114ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Restrict = 0x2, 115ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Volatile = 0x4, 116ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao CVRMask = Const | Volatile | Restrict 117ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao }; 118ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 119ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao enum GC { 120ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao GCNone = 0, 121ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Weak, 122ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Strong 123ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao }; 124ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 125f85e193739c953358c865005855253af4f68a497John McCall enum ObjCLifetime { 126f85e193739c953358c865005855253af4f68a497John McCall /// There is no lifetime qualification on this type. 127f85e193739c953358c865005855253af4f68a497John McCall OCL_None, 128f85e193739c953358c865005855253af4f68a497John McCall 129f85e193739c953358c865005855253af4f68a497John McCall /// This object can be modified without requiring retains or 130f85e193739c953358c865005855253af4f68a497John McCall /// releases. 131f85e193739c953358c865005855253af4f68a497John McCall OCL_ExplicitNone, 132f85e193739c953358c865005855253af4f68a497John McCall 133f85e193739c953358c865005855253af4f68a497John McCall /// Assigning into this object requires the old value to be 134f85e193739c953358c865005855253af4f68a497John McCall /// released and the new value to be retained. The timing of the 135f85e193739c953358c865005855253af4f68a497John McCall /// release of the old value is inexact: it may be moved to 136f85e193739c953358c865005855253af4f68a497John McCall /// immediately after the last known point where the value is 137f85e193739c953358c865005855253af4f68a497John McCall /// live. 138f85e193739c953358c865005855253af4f68a497John McCall OCL_Strong, 139f85e193739c953358c865005855253af4f68a497John McCall 140f85e193739c953358c865005855253af4f68a497John McCall /// Reading or writing from this object requires a barrier call. 141f85e193739c953358c865005855253af4f68a497John McCall OCL_Weak, 142f85e193739c953358c865005855253af4f68a497John McCall 143f85e193739c953358c865005855253af4f68a497John McCall /// Assigning into this object requires a lifetime extension. 144f85e193739c953358c865005855253af4f68a497John McCall OCL_Autoreleasing 145f85e193739c953358c865005855253af4f68a497John McCall }; 146f85e193739c953358c865005855253af4f68a497John McCall 147ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao enum { 148ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// The maximum supported address space number. 149ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// 24 bits should be enough for anyone. 150ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao MaxAddressSpace = 0xffffffu, 151ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 152ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// The width of the "fast" qualifier mask. 153f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor FastWidth = 3, 154ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 155ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// The fast qualifier mask. 156ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao FastMask = (1 << FastWidth) - 1 157ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao }; 158ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 159ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Qualifiers() : Mask(0) {} 160ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 161ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static Qualifiers fromFastMask(unsigned Mask) { 162ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Qualifiers Qs; 163ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Qs.addFastQualifiers(Mask); 164ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return Qs; 165ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 166ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 167ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static Qualifiers fromCVRMask(unsigned CVR) { 168ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Qualifiers Qs; 169ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Qs.addCVRQualifiers(CVR); 170ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return Qs; 171ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 172ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 173ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Deserialize qualifiers from an opaque representation. 174ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static Qualifiers fromOpaqueValue(unsigned opaque) { 175ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Qualifiers Qs; 176ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Qs.Mask = opaque; 177ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return Qs; 178ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 179ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 180ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Serialize these qualifiers into an opaque representation. 181ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned getAsOpaqueValue() const { 182ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return Mask; 183ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 184ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 185ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasConst() const { return Mask & Const; } 186ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void setConst(bool flag) { 187ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Mask = (Mask & ~Const) | (flag ? Const : 0); 188ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 189ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void removeConst() { Mask &= ~Const; } 190ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void addConst() { Mask |= Const; } 191ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 192ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasVolatile() const { return Mask & Volatile; } 193ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void setVolatile(bool flag) { 194ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Mask = (Mask & ~Volatile) | (flag ? Volatile : 0); 195ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 196ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void removeVolatile() { Mask &= ~Volatile; } 197ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void addVolatile() { Mask |= Volatile; } 198ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 199ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasRestrict() const { return Mask & Restrict; } 200ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void setRestrict(bool flag) { 201ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Mask = (Mask & ~Restrict) | (flag ? Restrict : 0); 202ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 203ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void removeRestrict() { Mask &= ~Restrict; } 204ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void addRestrict() { Mask |= Restrict; } 205ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 206ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasCVRQualifiers() const { return getCVRQualifiers(); } 207ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned getCVRQualifiers() const { return Mask & CVRMask; } 208ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void setCVRQualifiers(unsigned mask) { 209ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 210ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Mask = (Mask & ~CVRMask) | mask; 211ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 212ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void removeCVRQualifiers(unsigned mask) { 213ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 214ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Mask &= ~mask; 215ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 216ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void removeCVRQualifiers() { 217ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao removeCVRQualifiers(CVRMask); 218ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 219ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void addCVRQualifiers(unsigned mask) { 220ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 221ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Mask |= mask; 222ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 223ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 224ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasObjCGCAttr() const { return Mask & GCAttrMask; } 225ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); } 226ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void setObjCGCAttr(GC type) { 227ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift); 228ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 229ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void removeObjCGCAttr() { setObjCGCAttr(GCNone); } 230ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void addObjCGCAttr(GC type) { 231ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(type); 232ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao setObjCGCAttr(type); 233ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2342234873111009eb8655d63362cedc422eb9fc517John McCall Qualifiers withoutObjCGCAttr() const { 2352234873111009eb8655d63362cedc422eb9fc517John McCall Qualifiers qs = *this; 2362234873111009eb8655d63362cedc422eb9fc517John McCall qs.removeObjCGCAttr(); 2372234873111009eb8655d63362cedc422eb9fc517John McCall return qs; 2382234873111009eb8655d63362cedc422eb9fc517John McCall } 239f85e193739c953358c865005855253af4f68a497John McCall Qualifiers withoutObjCGLifetime() const { 240f85e193739c953358c865005855253af4f68a497John McCall Qualifiers qs = *this; 241f85e193739c953358c865005855253af4f68a497John McCall qs.removeObjCLifetime(); 242f85e193739c953358c865005855253af4f68a497John McCall return qs; 243f85e193739c953358c865005855253af4f68a497John McCall } 2440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 245f85e193739c953358c865005855253af4f68a497John McCall bool hasObjCLifetime() const { return Mask & LifetimeMask; } 246f85e193739c953358c865005855253af4f68a497John McCall ObjCLifetime getObjCLifetime() const { 247f85e193739c953358c865005855253af4f68a497John McCall return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift); 248f85e193739c953358c865005855253af4f68a497John McCall } 249f85e193739c953358c865005855253af4f68a497John McCall void setObjCLifetime(ObjCLifetime type) { 250f85e193739c953358c865005855253af4f68a497John McCall Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift); 251f85e193739c953358c865005855253af4f68a497John McCall } 252f85e193739c953358c865005855253af4f68a497John McCall void removeObjCLifetime() { setObjCLifetime(OCL_None); } 253f85e193739c953358c865005855253af4f68a497John McCall void addObjCLifetime(ObjCLifetime type) { 254f85e193739c953358c865005855253af4f68a497John McCall assert(type); 255f85e193739c953358c865005855253af4f68a497John McCall setObjCLifetime(type); 256f85e193739c953358c865005855253af4f68a497John McCall } 257f85e193739c953358c865005855253af4f68a497John McCall 258f85e193739c953358c865005855253af4f68a497John McCall /// True if the lifetime is neither None or ExplicitNone. 259f85e193739c953358c865005855253af4f68a497John McCall bool hasNonTrivialObjCLifetime() const { 260f85e193739c953358c865005855253af4f68a497John McCall ObjCLifetime lifetime = getObjCLifetime(); 261f85e193739c953358c865005855253af4f68a497John McCall return (lifetime > OCL_ExplicitNone); 262f85e193739c953358c865005855253af4f68a497John McCall } 263ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 264f85e193739c953358c865005855253af4f68a497John McCall /// True if the lifetime is either strong or weak. 265f85e193739c953358c865005855253af4f68a497John McCall bool hasStrongOrWeakObjCLifetime() const { 266f85e193739c953358c865005855253af4f68a497John McCall ObjCLifetime lifetime = getObjCLifetime(); 267f85e193739c953358c865005855253af4f68a497John McCall return (lifetime == OCL_Strong || lifetime == OCL_Weak); 268f85e193739c953358c865005855253af4f68a497John McCall } 269b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 270ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasAddressSpace() const { return Mask & AddressSpaceMask; } 271ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; } 272ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void setAddressSpace(unsigned space) { 273ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(space <= MaxAddressSpace); 274ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Mask = (Mask & ~AddressSpaceMask) 275ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao | (((uint32_t) space) << AddressSpaceShift); 276ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 277ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void removeAddressSpace() { setAddressSpace(0); } 278ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void addAddressSpace(unsigned space) { 279ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(space); 280ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao setAddressSpace(space); 281ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 282ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 283ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Fast qualifiers are those that can be allocated directly 284ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // on a QualType object. 285ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasFastQualifiers() const { return getFastQualifiers(); } 286ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned getFastQualifiers() const { return Mask & FastMask; } 287ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void setFastQualifiers(unsigned mask) { 288ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 289ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Mask = (Mask & ~FastMask) | mask; 290ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 291ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void removeFastQualifiers(unsigned mask) { 292ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 293ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Mask &= ~mask; 294ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 295ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void removeFastQualifiers() { 296ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao removeFastQualifiers(FastMask); 297ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 298ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void addFastQualifiers(unsigned mask) { 299ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 300ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Mask |= mask; 301ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 302ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 303ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// hasNonFastQualifiers - Return true if the set contains any 304ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// qualifiers which require an ExtQuals node to be allocated. 305ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasNonFastQualifiers() const { return Mask & ~FastMask; } 306ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Qualifiers getNonFastQualifiers() const { 307ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Qualifiers Quals = *this; 308ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Quals.setFastQualifiers(0); 309ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return Quals; 310ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 311ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 312ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// hasQualifiers - Return true if the set contains any qualifiers. 313ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasQualifiers() const { return Mask; } 314ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool empty() const { return !Mask; } 315ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 316ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Add the qualifiers from the given set to this set. 317ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void addQualifiers(Qualifiers Q) { 318ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // If the other set doesn't have any non-boolean qualifiers, just 319ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // bit-or it in. 320ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (!(Q.Mask & ~CVRMask)) 321ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Mask |= Q.Mask; 322ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao else { 323ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Mask |= (Q.Mask & CVRMask); 324ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (Q.hasAddressSpace()) 325ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao addAddressSpace(Q.getAddressSpace()); 326ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (Q.hasObjCGCAttr()) 327ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao addObjCGCAttr(Q.getObjCGCAttr()); 328f85e193739c953358c865005855253af4f68a497John McCall if (Q.hasObjCLifetime()) 329f85e193739c953358c865005855253af4f68a497John McCall addObjCLifetime(Q.getObjCLifetime()); 330ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 331ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 332ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 33362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \brief Add the qualifiers from the given set to this set, given that 33462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// they don't conflict. 33562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall void addConsistentQualifiers(Qualifiers qs) { 33662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall assert(getAddressSpace() == qs.getAddressSpace() || 33762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall !hasAddressSpace() || !qs.hasAddressSpace()); 33862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall assert(getObjCGCAttr() == qs.getObjCGCAttr() || 33962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall !hasObjCGCAttr() || !qs.hasObjCGCAttr()); 340f85e193739c953358c865005855253af4f68a497John McCall assert(getObjCLifetime() == qs.getObjCLifetime() || 341f85e193739c953358c865005855253af4f68a497John McCall !hasObjCLifetime() || !qs.hasObjCLifetime()); 34262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Mask |= qs.Mask; 34362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 34462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 34562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \brief Determines if these qualifiers compatibly include another set. 34662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// Generally this answers the question of whether an object with the other 34762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// qualifiers can be safely used as an object with these qualifiers. 34862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall bool compatiblyIncludes(Qualifiers other) const { 349b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie return 350377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor // Address spaces must match exactly. 351377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor getAddressSpace() == other.getAddressSpace() && 352377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor // ObjC GC qualifiers can match, be added, or be removed, but can't be 353377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor // changed. 354377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor (getObjCGCAttr() == other.getObjCGCAttr() || 355377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor !hasObjCGCAttr() || !other.hasObjCGCAttr()) && 356f85e193739c953358c865005855253af4f68a497John McCall // ObjC lifetime qualifiers must match exactly. 357f85e193739c953358c865005855253af4f68a497John McCall getObjCLifetime() == other.getObjCLifetime() && 358377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor // CVR qualifiers may subset. 359377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)); 36062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 36162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 362f85e193739c953358c865005855253af4f68a497John McCall /// \brief Determines if these qualifiers compatibly include another set of 363f85e193739c953358c865005855253af4f68a497John McCall /// qualifiers from the narrow perspective of Objective-C ARC lifetime. 364f85e193739c953358c865005855253af4f68a497John McCall /// 365f85e193739c953358c865005855253af4f68a497John McCall /// One set of Objective-C lifetime qualifiers compatibly includes the other 366b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// if the lifetime qualifiers match, or if both are non-__weak and the 367f85e193739c953358c865005855253af4f68a497John McCall /// including set also contains the 'const' qualifier. 368f85e193739c953358c865005855253af4f68a497John McCall bool compatiblyIncludesObjCLifetime(Qualifiers other) const { 369f85e193739c953358c865005855253af4f68a497John McCall if (getObjCLifetime() == other.getObjCLifetime()) 370f85e193739c953358c865005855253af4f68a497John McCall return true; 371b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 372f85e193739c953358c865005855253af4f68a497John McCall if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak) 373f85e193739c953358c865005855253af4f68a497John McCall return false; 374b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 375f85e193739c953358c865005855253af4f68a497John McCall return hasConst(); 376f85e193739c953358c865005855253af4f68a497John McCall } 377b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 378f85e193739c953358c865005855253af4f68a497John McCall bool isSupersetOf(Qualifiers Other) const; 379f85e193739c953358c865005855253af4f68a497John McCall 380769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor /// \brief Determine whether this set of qualifiers is a strict superset of 381769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor /// another set of qualifiers, not considering qualifier compatibility. 382769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor bool isStrictSupersetOf(Qualifiers Other) const; 383b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 384ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool operator==(Qualifiers Other) const { return Mask == Other.Mask; } 385ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; } 386ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 387ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao operator bool() const { return hasQualifiers(); } 388ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 389ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Qualifiers &operator+=(Qualifiers R) { 390ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao addQualifiers(R); 391ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return *this; 392ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 393ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 394ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Union two qualifier sets. If an enumerated qualifier appears 395ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // in both sets, use the one from the right. 396ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend Qualifiers operator+(Qualifiers L, Qualifiers R) { 397ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao L += R; 398ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return L; 399ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 400b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 4016b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor Qualifiers &operator-=(Qualifiers R) { 4026b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor Mask = Mask & ~(R.Mask); 4036b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor return *this; 4046b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor } 405ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4066b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor /// \brief Compute the difference between two qualifier sets. 4076b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor friend Qualifiers operator-(Qualifiers L, Qualifiers R) { 4086b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor L -= R; 4096b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor return L; 4106b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor } 411b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 412ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao std::string getAsString() const; 413ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao std::string getAsString(const PrintingPolicy &Policy) const { 414ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao std::string Buffer; 415ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao getAsStringInternal(Buffer, Policy); 416ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return Buffer; 417ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 418ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const; 419ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 420ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) const { 421ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddInteger(Mask); 422ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 423ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 424ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprivate: 425ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 426f85e193739c953358c865005855253af4f68a497John McCall // bits: |0 1 2|3 .. 4|5 .. 7|8 ... 31| 427f85e193739c953358c865005855253af4f68a497John McCall // |C R V|GCAttr|Lifetime|AddressSpace| 428ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao uint32_t Mask; 429ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 430ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static const uint32_t GCAttrMask = 0x18; 431ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static const uint32_t GCAttrShift = 3; 432f85e193739c953358c865005855253af4f68a497John McCall static const uint32_t LifetimeMask = 0xE0; 433f85e193739c953358c865005855253af4f68a497John McCall static const uint32_t LifetimeShift = 5; 434f85e193739c953358c865005855253af4f68a497John McCall static const uint32_t AddressSpaceMask = ~(CVRMask|GCAttrMask|LifetimeMask); 435f85e193739c953358c865005855253af4f68a497John McCall static const uint32_t AddressSpaceShift = 8; 436ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 437ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 438ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// CallingConv - Specifies the calling convention that a function uses. 439ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoenum CallingConv { 440ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao CC_Default, 441ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao CC_C, // __attribute__((cdecl)) 442ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao CC_X86StdCall, // __attribute__((stdcall)) 44301890a8487ae3330abc501b455e2092545d54775Douglas Gregor CC_X86FastCall, // __attribute__((fastcall)) 44423cf1f9d0f258b16fb5c07a14ceb7aba4562903eDawn Perchik CC_X86ThisCall, // __attribute__((thiscall)) 445414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov CC_X86Pascal, // __attribute__((pascal)) 446414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov CC_AAPCS, // __attribute__((pcs("aapcs"))) 447414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov CC_AAPCS_VFP // __attribute__((pcs("aapcs-vfp"))) 448ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 449ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 45049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCalltypedef std::pair<const Type*, Qualifiers> SplitQualType; 451ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 452ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// QualType - For efficiency, we don't store CV-qualified types as nodes on 453ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// their own: instead each reference to a type stores the qualifiers. This 454ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// greatly reduces the number of nodes we need to allocate for types (for 455ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// example we only need one for 'int', 'const int', 'volatile int', 456ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 'const volatile int', etc). 457ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 458ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// As an added efficiency bonus, instead of making this a pair, we 459ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// just store the two bits we care about in the low bits of the 460ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// pointer. To handle the packing/unpacking, we make QualType be a 461ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// simple wrapper class that acts like a smart pointer. A third bit 462ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// indicates whether there are extended qualifiers present, in which 463ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// case the pointer points to a special structure. 464ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass QualType { 465ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Thankfully, these are efficiently composable. 466ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>, 467ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Qualifiers::FastWidth> Value; 468ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 469ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const ExtQuals *getExtQualsUnsafe() const { 470ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return Value.getPointer().get<const ExtQuals*>(); 471ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 472ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 473ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const Type *getTypePtrUnsafe() const { 474ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return Value.getPointer().get<const Type*>(); 475ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 476ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ExtQualsTypeCommonBase *getCommonPtr() const { 4783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!isNull() && "Cannot retrieve a NULL type pointer"); 4793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall uintptr_t CommonPtrVal 4803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = reinterpret_cast<uintptr_t>(Value.getOpaqueValue()); 4813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1); 4823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal); 4833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 4843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 485ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class QualifierCollector; 486ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 487ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType() {} 488ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 489ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType(const Type *Ptr, unsigned Quals) 490ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao : Value(Ptr, Quals) {} 491ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType(const ExtQuals *Ptr, unsigned Quals) 492ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao : Value(Ptr, Quals) {} 493ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 494ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned getLocalFastQualifiers() const { return Value.getInt(); } 495ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); } 496ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 497ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// Retrieves a pointer to the underlying (unqualified) type. 498ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// This should really return a const Type, but it's not worth 499ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// changing all the users right now. 5001ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor /// 5011ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor /// This function requires that the type not be NULL. If the type might be 5021ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor /// NULL, use the (slightly less efficient) \c getTypePtrOrNull(). 5033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *getTypePtr() const; 504b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 5053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *getTypePtrOrNull() const; 5061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5074d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain /// Retrieves a pointer to the name of the base type. 5084d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain const IdentifierInfo *getBaseTypeIdentifier() const; 5094d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain 51049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall /// Divides a QualType into its unqualified type and a set of local 51149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall /// qualifiers. 5123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType split() const; 513ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 514ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 515f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall static QualType getFromOpaquePtr(const void *Ptr) { 516ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType T; 517f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall T.Value.setFromOpaqueValue(const_cast<void*>(Ptr)); 518ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T; 519ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 520ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 521f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type &operator*() const { 522ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return *getTypePtr(); 523ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 524ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 525f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type *operator->() const { 526ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return getTypePtr(); 527ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 528ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 529ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isCanonical() const; 530ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isCanonicalAsParam() const; 531ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 532ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isNull - Return true if this QualType doesn't point to a type yet. 533ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isNull() const { 534ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return Value.getPointer().isNull(); 535ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 536ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 537b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// \brief Determine whether this particular QualType instance has the 538ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// "const" qualifier set, without looking through typedefs that may have 539ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// added "const" at a different level. 540ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isLocalConstQualified() const { 541ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return (getLocalFastQualifiers() & Qualifiers::Const); 542ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 543b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 544ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Determine whether this type is const-qualified. 545ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isConstQualified() const; 546b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 547b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// \brief Determine whether this particular QualType instance has the 548ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// "restrict" qualifier set, without looking through typedefs that may have 549ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// added "restrict" at a different level. 550ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isLocalRestrictQualified() const { 551ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return (getLocalFastQualifiers() & Qualifiers::Restrict); 552ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 553b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 554ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Determine whether this type is restrict-qualified. 555ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isRestrictQualified() const; 556b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 557b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// \brief Determine whether this particular QualType instance has the 558ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// "volatile" qualifier set, without looking through typedefs that may have 559ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// added "volatile" at a different level. 560ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isLocalVolatileQualified() const { 561f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor return (getLocalFastQualifiers() & Qualifiers::Volatile); 562ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 563ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 564ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Determine whether this type is volatile-qualified. 565ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isVolatileQualified() const; 566b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 567ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Determine whether this particular QualType instance has any 568b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// qualifiers, without looking through any typedefs that might add 569ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// qualifiers at a different level. 570ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasLocalQualifiers() const { 571ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return getLocalFastQualifiers() || hasLocalNonFastQualifiers(); 572ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 573ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 574ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Determine whether this type has any qualifiers. 575ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasQualifiers() const; 576b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 577ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Determine whether this particular QualType instance has any 578ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType 579ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// instance. 580ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasLocalNonFastQualifiers() const { 581ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return Value.getPointer().is<const ExtQuals*>(); 582ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 583ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 584ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Retrieve the set of qualifiers local to this particular QualType 585ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// instance, not including any qualifiers acquired through typedefs or 586ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// other sugar. 5873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers getLocalQualifiers() const; 588ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 589ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Retrieve the set of qualifiers applied to this type. 590ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Qualifiers getQualifiers() const; 591b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 592b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 593ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// local to this particular QualType instance, not including any qualifiers 594ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// acquired through typedefs or other sugar. 595ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned getLocalCVRQualifiers() const { 596f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor return getLocalFastQualifiers(); 597ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 598ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 599b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 600ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// applied to this type. 601ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned getCVRQualifiers() const; 602ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 603ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isConstant(ASTContext& Ctx) const { 604ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return QualType::isConstant(*this, Ctx); 605ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 606ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 607f85e193739c953358c865005855253af4f68a497John McCall /// \brief Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10). 608f85e193739c953358c865005855253af4f68a497John McCall bool isPODType(ASTContext &Context) const; 609f85e193739c953358c865005855253af4f68a497John McCall 610f85e193739c953358c865005855253af4f68a497John McCall /// isCXX11PODType() - Return true if this is a POD type according to the 611f85e193739c953358c865005855253af4f68a497John McCall /// more relaxed rules of the C++11 standard, regardless of the current 612f85e193739c953358c865005855253af4f68a497John McCall /// compilation's language. 613f85e193739c953358c865005855253af4f68a497John McCall /// (C++0x [basic.types]p9) 614f85e193739c953358c865005855253af4f68a497John McCall bool isCXX11PODType(ASTContext &Context) const; 615b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 616f85e193739c953358c865005855253af4f68a497John McCall /// isTrivialType - Return true if this is a trivial type 617f85e193739c953358c865005855253af4f68a497John McCall /// (C++0x [basic.types]p9) 618b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie bool isTrivialType(ASTContext &Context) const; 619f85e193739c953358c865005855253af4f68a497John McCall 620f85e193739c953358c865005855253af4f68a497John McCall /// isTriviallyCopyableType - Return true if this is a trivially 621f85e193739c953358c865005855253af4f68a497John McCall /// copyable type (C++0x [basic.types]p9) 622f85e193739c953358c865005855253af4f68a497John McCall bool isTriviallyCopyableType(ASTContext &Context) const; 623f85e193739c953358c865005855253af4f68a497John McCall 624ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Don't promise in the API that anything besides 'const' can be 625ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // easily added. 626ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 627b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// addConst - add the specified type qualifier to this QualType. 628ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void addConst() { 629ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao addFastQualifiers(Qualifiers::Const); 630ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 631ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType withConst() const { 632ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return withFastQualifiers(Qualifiers::Const); 633ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 634ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 635b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// addVolatile - add the specified type qualifier to this QualType. 636308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt void addVolatile() { 637308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt addFastQualifiers(Qualifiers::Volatile); 638308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt } 639308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt QualType withVolatile() const { 640308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt return withFastQualifiers(Qualifiers::Volatile); 641308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt } 642308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt 643a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall QualType withCVRQualifiers(unsigned CVR) const { 644a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall return withFastQualifiers(CVR); 645a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall } 646a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall 647ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void addFastQualifiers(unsigned TQs) { 648ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(!(TQs & ~Qualifiers::FastMask) 649ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao && "non-fast qualifier bits set in mask!"); 650ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Value.setInt(Value.getInt() | TQs); 651ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 652ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 65349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalConst(); 65449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalVolatile(); 65549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalRestrict(); 65649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalCVRQualifiers(unsigned Mask); 657ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 65849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalFastQualifiers() { Value.setInt(0); } 65949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall void removeLocalFastQualifiers(unsigned Mask) { 660ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers"); 661ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Value.setInt(Value.getInt() & ~Mask); 662ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 663ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 664ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Creates a type with the given qualifiers in addition to any 665ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // qualifiers already on this type. 666ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType withFastQualifiers(unsigned TQs) const { 667ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType T = *this; 668ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao T.addFastQualifiers(TQs); 669ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T; 670ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 671ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 672ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Creates a type with exactly the given fast qualifiers, removing 673ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // any existing fast qualifiers. 67449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall QualType withExactLocalFastQualifiers(unsigned TQs) const { 67549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return withoutLocalFastQualifiers().withFastQualifiers(TQs); 676ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 677ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 678ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Removes fast qualifiers, but leaves any extended qualifiers in place. 67949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall QualType withoutLocalFastQualifiers() const { 680ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType T = *this; 68149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall T.removeLocalFastQualifiers(); 682ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T; 683ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 684ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 6853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType getCanonicalType() const; 6863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 687ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Return this type with all of the instance-specific qualifiers 688ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// removed, but without removing any qualifiers that may have been applied 689ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// through typedefs. 690ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); } 691ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 69262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \brief Retrieve the unqualified variant of the given type, 69362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// removing as little sugar as possible. 69462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 69562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// This routine looks through various kinds of sugar to find the 69662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// least-desugared type that is unqualified. For example, given: 69762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 69862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \code 69962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// typedef int Integer; 70062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// typedef const Integer CInteger; 70162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// typedef CInteger DifferenceType; 70262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// \endcode 70362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 70462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// Executing \c getUnqualifiedType() on the type \c DifferenceType will 70562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// desugar until we hit the type \c Integer, which has no qualifiers on it. 70662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 70762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// The resulting type might still be qualified if it's an array 70862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// type. To strip qualifiers even from within an array type, use 70962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// ASTContext::getUnqualifiedArrayType. 71062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall inline QualType getUnqualifiedType() const; 71162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 71262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// getSplitUnqualifiedType - Retrieve the unqualified variant of the 71362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// given type, removing as little sugar as possible. 71462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 71562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// Like getUnqualifiedType(), but also returns the set of 71662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// qualifiers that were built up. 71762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// 71862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// The resulting type might still be qualified if it's an array 71962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// type. To strip qualifiers even from within an array type, use 72062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall /// ASTContext::getUnqualifiedArrayType. 72162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall inline SplitQualType getSplitUnqualifiedType() const; 722b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 72361d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// \brief Determine whether this type is more qualified than the other 72461d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// given type, requiring exact equality for non-CVR qualifiers. 725ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isMoreQualifiedThan(QualType Other) const; 72661d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor 72761d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// \brief Determine whether this type is at least as qualified as the other 72861d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor /// given type, requiring exact equality for non-CVR qualifiers. 729ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isAtLeastAsQualifiedAs(QualType Other) const; 730b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 731ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getNonReferenceType() const; 732ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 7332350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor /// \brief Determine the type of a (typically non-lvalue) expression with the 7342350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor /// specified result type. 735b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// 7362350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor /// This routine should be used for expressions for which the return type is 7372350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor /// explicitly specified (e.g., in a cast or call) and isn't necessarily 738b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// an lvalue. It removes a top-level reference (since there are no 7398079eee9128444d02bebf24410126f9d55399f84Douglas Gregor /// expressions of reference type) and deletes top-level cvr-qualifiers 7408079eee9128444d02bebf24410126f9d55399f84Douglas Gregor /// from non-class types (in C++) or all types (in C). 7412350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor QualType getNonLValueExprType(ASTContext &Context) const; 742b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 743ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// getDesugaredType - Return the specified type with any "sugar" removed from 744ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// the type. This takes off typedefs, typeof's etc. If the outer level of 745ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// the type is already concrete, it returns it unmodified. This is similar 746ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// to getting the canonical type, but it doesn't remove *all* typedefs. For 747ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 748ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// concrete. 749ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// 750ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// Qualifiers are left in place. 7514ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType getDesugaredType(const ASTContext &Context) const { 75249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getDesugaredType(*this, Context); 75349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 75449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall 75549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall SplitQualType getSplitDesugaredType() const { 75649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getSplitDesugaredType(*this); 757bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 75898cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor 759f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor /// \brief Return the specified type with one level of "sugar" removed from 760b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// the type. 761f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor /// 762f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor /// This routine takes off the first typedef, typeof, etc. If the outer level 763f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor /// of the type is already concrete, it returns it unmodified. 764f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor QualType getSingleStepDesugaredType(const ASTContext &Context) const; 765b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 766075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// IgnoreParens - Returns the specified type after dropping any 767075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// outer-level parentheses. 768075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType IgnoreParens() const { 769723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara if (isa<ParenType>(*this)) 770723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara return QualType::IgnoreParens(*this); 771723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara return *this; 772ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 773ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 774ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// operator==/!= - Indicate whether the specified types and qualifiers are 775ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// identical. 776ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend bool operator==(const QualType &LHS, const QualType &RHS) { 777ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return LHS.Value == RHS.Value; 778ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 779ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend bool operator!=(const QualType &LHS, const QualType &RHS) { 780ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return LHS.Value != RHS.Value; 781ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 78249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall std::string getAsString() const { 78349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getAsString(split()); 78449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 78549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static std::string getAsString(SplitQualType split) { 78649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getAsString(split.first, split.second); 78749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 78849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static std::string getAsString(const Type *ty, Qualifiers qs); 789ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 790ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao std::string getAsString(const PrintingPolicy &Policy) const { 791ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao std::string S; 792ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao getAsStringInternal(S, Policy); 793ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return S; 794ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 795ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void getAsStringInternal(std::string &Str, 79649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall const PrintingPolicy &Policy) const { 79749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getAsStringInternal(split(), Str, Policy); 79849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 79949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static void getAsStringInternal(SplitQualType split, std::string &out, 80049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall const PrintingPolicy &policy) { 80149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return getAsStringInternal(split.first, split.second, out, policy); 80249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall } 80349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static void getAsStringInternal(const Type *ty, Qualifiers qs, 80449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall std::string &out, 80549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall const PrintingPolicy &policy); 806ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 807ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void dump(const char *s) const; 808ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void dump() const; 809ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 810ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) const { 811ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(getAsOpaquePtr()); 812ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 813ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 814ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// getAddressSpace - Return the address space of this type. 815ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao inline unsigned getAddressSpace() const; 816ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 817f85e193739c953358c865005855253af4f68a497John McCall /// getObjCGCAttr - Returns gc attribute of this type. 818ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao inline Qualifiers::GC getObjCGCAttr() const; 819ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 820ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isObjCGCWeak true when Type is objc's weak. 821ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isObjCGCWeak() const { 822ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return getObjCGCAttr() == Qualifiers::Weak; 823ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 824ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 825ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isObjCGCStrong true when Type is objc's strong. 826ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isObjCGCStrong() const { 827ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return getObjCGCAttr() == Qualifiers::Strong; 828ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 829ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 830f85e193739c953358c865005855253af4f68a497John McCall /// getObjCLifetime - Returns lifetime attribute of this type. 831f85e193739c953358c865005855253af4f68a497John McCall Qualifiers::ObjCLifetime getObjCLifetime() const { 832f85e193739c953358c865005855253af4f68a497John McCall return getQualifiers().getObjCLifetime(); 833f85e193739c953358c865005855253af4f68a497John McCall } 834f85e193739c953358c865005855253af4f68a497John McCall 835f85e193739c953358c865005855253af4f68a497John McCall bool hasNonTrivialObjCLifetime() const { 836f85e193739c953358c865005855253af4f68a497John McCall return getQualifiers().hasNonTrivialObjCLifetime(); 837f85e193739c953358c865005855253af4f68a497John McCall } 838f85e193739c953358c865005855253af4f68a497John McCall 839f85e193739c953358c865005855253af4f68a497John McCall bool hasStrongOrWeakObjCLifetime() const { 840f85e193739c953358c865005855253af4f68a497John McCall return getQualifiers().hasStrongOrWeakObjCLifetime(); 841f85e193739c953358c865005855253af4f68a497John McCall } 842f85e193739c953358c865005855253af4f68a497John McCall 8430d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall enum DestructionKind { 8440d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall DK_none, 845f85e193739c953358c865005855253af4f68a497John McCall DK_cxx_destructor, 846f85e193739c953358c865005855253af4f68a497John McCall DK_objc_strong_lifetime, 847f85e193739c953358c865005855253af4f68a497John McCall DK_objc_weak_lifetime 8480d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall }; 8490d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 8500d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// isDestructedType - nonzero if objects of this type require 8510d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// non-trivial work to clean up after. Non-zero because it's 8520d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// conceivable that qualifiers (objc_gc(weak)?) could make 8530d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// something require destruction. 8540d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall DestructionKind isDestructedType() const { 8550d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall return isDestructedTypeImpl(*this); 8560d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall } 8570d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 858b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// \brief Determine whether expressions of the given type are forbidden 8592b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// from being lvalues in C. 8602b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// 8612b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// The expression types that are forbidden to be lvalues are: 8622b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// - 'void', but not qualified void 8632b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// - function types 8642b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// 8652b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// The exact rule here is C99 6.3.2.1: 8662b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// An lvalue is an expression with an object type or an incomplete 8672b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor /// type other than void. 8682b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor bool isCForbiddenLValueType() const; 8692b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor 87085ea7aa961deac1d754f610af8062ae3f8b4e2a5Sebastian Redl /// \brief Determine whether this type has trivial copy/move-assignment 87185ea7aa961deac1d754f610af8062ae3f8b4e2a5Sebastian Redl /// semantics. 87285ea7aa961deac1d754f610af8062ae3f8b4e2a5Sebastian Redl bool hasTrivialAssignment(ASTContext &Context, bool Copying) const; 873b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 874ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprivate: 875ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // These methods are implemented in a separate translation unit; 876ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // "static"-ize them to avoid creating temporary QualTypes in the 877ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // caller. 878ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool isConstant(QualType T, ASTContext& Ctx); 8794ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static QualType getDesugaredType(QualType T, const ASTContext &Context); 88049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall static SplitQualType getSplitDesugaredType(QualType T); 88162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall static SplitQualType getSplitUnqualifiedTypeImpl(QualType type); 882075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static QualType IgnoreParens(QualType T); 8830d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall static DestructionKind isDestructedTypeImpl(QualType type); 884ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 885ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 886ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} // end clang. 887ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 888ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaonamespace llvm { 889ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 890ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// to a specific Type class. 891ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaotemplate<> struct simplify_type<const ::clang::QualType> { 892f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall typedef const ::clang::Type *SimpleType; 893ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 894ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return Val.getTypePtr(); 895ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 896ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 897ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaotemplate<> struct simplify_type< ::clang::QualType> 898ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao : public simplify_type<const ::clang::QualType> {}; 899ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 900ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// Teach SmallPtrSet that QualType is "basically a pointer". 901ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaotemplate<> 902ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass PointerLikeTypeTraits<clang::QualType> { 903ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 904ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static inline void *getAsVoidPointer(clang::QualType P) { 905ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return P.getAsOpaquePtr(); 906ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 907ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static inline clang::QualType getFromVoidPointer(void *P) { 908ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return clang::QualType::getFromOpaquePtr(P); 909ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 910ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Various qualifiers go in low bits. 911ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao enum { NumLowBitsAvailable = 0 }; 912ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 913ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 914ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} // end namespace llvm 915ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 916ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaonamespace clang { 917ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 918b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie/// \brief Base class that is common to both the \c ExtQuals and \c Type 9193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// classes, which allows \c QualType to access the common fields between the 9203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// two. 9213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// 9223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQualsTypeCommonBase { 9233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQualsTypeCommonBase(const Type *baseType, QualType canon) 9243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall : BaseType(baseType), CanonicalType(canon) {} 9253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 9263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// \brief The "base" type of an extended qualifiers type (\c ExtQuals) or 9273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// a self-referential pointer (for \c Type). 9283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// 929b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// This pointer allows an efficient mapping from a QualType to its 9303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// underlying type pointer. 9313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *const BaseType; 9323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 9333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// \brief The canonical type of this type. A QualType. 9343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType CanonicalType; 9353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 9363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall friend class QualType; 9373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall friend class Type; 9383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall friend class ExtQuals; 9393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}; 940b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 9413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// ExtQuals - We can encode up to four bits in the low bits of a 9423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// type pointer, but there are many more type qualifiers that we want 9433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// to be able to apply to an arbitrary type. Therefore we have this 9443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// struct, intended to be heap-allocated and used by QualType to 9453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// store qualifiers. 9463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// 947b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers 9483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// in three low bits on the QualType pointer; a fourth bit records whether 9493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// the pointer is an ExtQuals node. The extended qualifiers (address spaces, 9503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// Objective-C GC attributes) are much more rare. 9513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { 9523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // NOTE: changing the fast qualifiers should be straightforward as 9533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // long as you don't make 'const' non-fast. 9543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // 1. Qualifiers: 9553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ). 9563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Fast qualifiers must occupy the low-order bits. 9573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // b) Update Qualifiers::FastWidth and FastMask. 9583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // 2. QualType: 9593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // a) Update is{Volatile,Restrict}Qualified(), defined inline. 9603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // b) Update remove{Volatile,Restrict}, defined near the end of 9613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // this header. 9623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // 3. ASTContext: 9633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // a) Update get{Volatile,Restrict}Type. 9643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 9653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// Quals - the immutable set of qualifiers applied by this 9663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// node; always contains extended qualifiers. 9673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers Quals; 9683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 9693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQuals *this_() { return this; } 9703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 9713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic: 972b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie ExtQuals(const Type *baseType, QualType canon, Qualifiers quals) 9733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall : ExtQualsTypeCommonBase(baseType, 9743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall canon.isNull() ? QualType(this_(), 0) : canon), 9753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals(quals) 9763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall { 9773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(Quals.hasNonFastQualifiers() 9783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall && "ExtQuals created with no fast qualifiers"); 9793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!Quals.hasFastQualifiers() 9803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall && "ExtQuals created with fast qualifiers"); 9813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 9823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 9833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers getQualifiers() const { return Quals; } 9843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 9853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); } 9863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); } 9873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 988f85e193739c953358c865005855253af4f68a497John McCall bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); } 989f85e193739c953358c865005855253af4f68a497John McCall Qualifiers::ObjCLifetime getObjCLifetime() const { 990f85e193739c953358c865005855253af4f68a497John McCall return Quals.getObjCLifetime(); 991f85e193739c953358c865005855253af4f68a497John McCall } 992f85e193739c953358c865005855253af4f68a497John McCall 9933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall bool hasAddressSpace() const { return Quals.hasAddressSpace(); } 9943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned getAddressSpace() const { return Quals.getAddressSpace(); } 9953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 9963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *getBaseType() const { return BaseType; } 9973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 9983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic: 9993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall void Profile(llvm::FoldingSetNodeID &ID) const { 10003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Profile(ID, getBaseType(), Quals); 10013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 10023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall static void Profile(llvm::FoldingSetNodeID &ID, 10033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *BaseType, 10043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers Quals) { 10053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!"); 10063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ID.AddPointer(BaseType); 10073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals.Profile(ID); 10083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 10093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}; 10103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 1011b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie/// \brief The kind of C++0x ref-qualifier associated with a function type, 1012b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie/// which determines whether a member function's "this" object can be an 1013c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// lvalue, rvalue, or neither. 1014c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregorenum RefQualifierKind { 1015c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief No ref-qualifier was provided. 1016c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RQ_None = 0, 1017c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief An lvalue ref-qualifier was provided (\c &). 1018c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RQ_LValue, 1019c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief An rvalue ref-qualifier was provided (\c &&). 1020c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RQ_RValue 1021c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor}; 1022b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1023ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Type - This is the base class of the type hierarchy. A central concept 1024ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// with types is that each type always has a canonical type. A canonical type 1025ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// is the type with any typedef names stripped out of it or the types it 1026ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// references. For example, consider: 1027ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 1028ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// typedef int foo; 1029ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// typedef foo* bar; 1030ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 'int *' 'foo *' 'bar' 1031ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 1032ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// There will be a Type object created for 'int'. Since int is canonical, its 1033ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 1034ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 1035ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// there is a PointerType that represents 'int*', which, like 'int', is 1036ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 1037ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 1038ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// is also 'int*'. 1039ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 1040ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Non-canonical types are useful for emitting diagnostics, without losing 1041ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// information about typedefs being used. Canonical types are useful for type 1042ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// comparisons (they allow by-pointer equality tests) and useful for reasoning 1043ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// about whether something has a particular form (e.g. is a function type), 1044ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// because they implicitly, recursively, strip all typedefs out of a type. 1045ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 1046ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Types, once created, are immutable. 1047ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 10481ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass Type : public ExtQualsTypeCommonBase { 1049ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 1050ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao enum TypeClass { 1051ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#define TYPE(Class, Base) Class, 1052ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#define LAST_TYPE(Class) TypeLast = Class, 1053ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#define ABSTRACT_TYPE(Class, Base) 1054ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "clang/AST/TypeNodes.def" 1055ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao TagFirst = Record, TagLast = Enum 1056ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao }; 1057ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1058ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprivate: 1059f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall Type(const Type&); // DO NOT IMPLEMENT. 1060f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall void operator=(const Type&); // DO NOT IMPLEMENT. 1061f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 1062084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// Bitfields required by the Type class. 1063084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall class TypeBitfields { 1064084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall friend class Type; 1065b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall template <class T> friend class TypePropertyCache; 1066ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1067084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 1068084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned TC : 8; 1069084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1070084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 1071084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// Note that this should stay at the end of the ivars for Type so that 1072084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// subclasses can pack their bitfields into the same word. 1073b366986ba90b62e13a9562822179f488c1febcc5Francois Pichet unsigned Dependent : 1; 1074b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1075b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// \brief Whether this type somehow involves a template parameter, even 1076561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// if the resolution of the type does not depend on a template parameter. 1077561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor unsigned InstantiationDependent : 1; 1078b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1079084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// \brief Whether this type is a variably-modified type (C99 6.7.5). 1080b366986ba90b62e13a9562822179f488c1febcc5Francois Pichet unsigned VariablyModified : 1; 1081d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1082d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this type contains an unexpanded parameter pack 1083d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// (for C++0x variadic templates). 1084d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned ContainsUnexpandedParameterPack : 1; 1085b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 108682254439b368de855d1e66440071017a1f2d4f0aJohn McCall /// \brief Nonzero if the cache (i.e. the bitfields here starting 108782254439b368de855d1e66440071017a1f2d4f0aJohn McCall /// with 'Cache') is valid. If so, then this is a 108882254439b368de855d1e66440071017a1f2d4f0aJohn McCall /// LangOptions::VisibilityMode+1. 108982254439b368de855d1e66440071017a1f2d4f0aJohn McCall mutable unsigned CacheValidAndVisibility : 2; 1090b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1091084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// \brief Linkage of this type. 1092084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall mutable unsigned CachedLinkage : 2; 109311594551693b1db92840bf1640d087ce1062609fSebastian Redl 1094b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// \brief Whether this type involves and local or unnamed types. 1095b366986ba90b62e13a9562822179f488c1febcc5Francois Pichet mutable unsigned CachedLocalOrUnnamed : 1; 1096b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1097084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// \brief FromAST - Whether this type comes from an AST file. 1098b366986ba90b62e13a9562822179f488c1febcc5Francois Pichet mutable unsigned FromAST : 1; 1099084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 110082254439b368de855d1e66440071017a1f2d4f0aJohn McCall bool isCacheValid() const { 110182254439b368de855d1e66440071017a1f2d4f0aJohn McCall return (CacheValidAndVisibility != 0); 110282254439b368de855d1e66440071017a1f2d4f0aJohn McCall } 110382254439b368de855d1e66440071017a1f2d4f0aJohn McCall Visibility getVisibility() const { 110482254439b368de855d1e66440071017a1f2d4f0aJohn McCall assert(isCacheValid() && "getting linkage from invalid cache"); 110582254439b368de855d1e66440071017a1f2d4f0aJohn McCall return static_cast<Visibility>(CacheValidAndVisibility-1); 110682254439b368de855d1e66440071017a1f2d4f0aJohn McCall } 110782254439b368de855d1e66440071017a1f2d4f0aJohn McCall Linkage getLinkage() const { 110882254439b368de855d1e66440071017a1f2d4f0aJohn McCall assert(isCacheValid() && "getting linkage from invalid cache"); 110982254439b368de855d1e66440071017a1f2d4f0aJohn McCall return static_cast<Linkage>(CachedLinkage); 111082254439b368de855d1e66440071017a1f2d4f0aJohn McCall } 111182254439b368de855d1e66440071017a1f2d4f0aJohn McCall bool hasLocalOrUnnamedType() const { 111282254439b368de855d1e66440071017a1f2d4f0aJohn McCall assert(isCacheValid() && "getting linkage from invalid cache"); 111382254439b368de855d1e66440071017a1f2d4f0aJohn McCall return CachedLocalOrUnnamed; 111482254439b368de855d1e66440071017a1f2d4f0aJohn McCall } 1115084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall }; 1116561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor enum { NumTypeBits = 18 }; 1117084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1118084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCallprotected: 1119084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall // These classes allow subclasses to somewhat cleanly pack bitfields 1120084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall // into Type. 1121084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1122084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall class ArrayTypeBitfields { 1123084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall friend class ArrayType; 1124084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1125084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned : NumTypeBits; 1126084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1127084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// IndexTypeQuals - CVR qualifiers from declarations like 1128084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// 'int X[static restrict 4]'. For function parameters only. 1129084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned IndexTypeQuals : 3; 1130084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1131084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// SizeModifier - storage class qualifiers from declarations like 1132084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// 'int X[static restrict 4]'. For function parameters only. 1133084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// Actually an ArrayType::ArraySizeModifier. 1134084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned SizeModifier : 3; 1135084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall }; 1136084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1137084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall class BuiltinTypeBitfields { 1138084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall friend class BuiltinType; 1139084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1140084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned : NumTypeBits; 1141084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1142084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// The kind (BuiltinType::Kind) of builtin type this is. 1143084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned Kind : 8; 1144084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall }; 1145084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1146084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall class FunctionTypeBitfields { 1147084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall friend class FunctionType; 1148084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1149084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned : NumTypeBits; 1150084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1151084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// Extra information which affects how the function is called, like 1152084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// regparm and the calling convention. 11537e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor unsigned ExtInfo : 8; 1154084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1155e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall /// Whether the function is variadic. Only used by FunctionProtoType. 1156e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned Variadic : 1; 1157084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1158084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1159084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// other bitfields. 1160084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// The qualifiers are part of FunctionProtoType because... 1161084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// 1162084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// C++ 8.3.5p4: The return type, the parameter type list and the 1163084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// cv-qualifier-seq, [...], are part of the function type. 1164084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned TypeQuals : 3; 1165b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1166c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief The ref-qualifier associated with a \c FunctionProtoType. 1167c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// 1168c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// This is a value of type \c RefQualifierKind. 1169c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor unsigned RefQualifier : 2; 1170084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall }; 1171084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1172084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall class ObjCObjectTypeBitfields { 1173084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall friend class ObjCObjectType; 1174084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1175084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned : NumTypeBits; 1176084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1177084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// NumProtocols - The number of protocols stored directly on this 1178084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// object type. 1179084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned NumProtocols : 32 - NumTypeBits; 1180084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall }; 1181084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1182084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall class ReferenceTypeBitfields { 1183084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall friend class ReferenceType; 1184084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1185084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned : NumTypeBits; 1186084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1187084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// True if the type was originally spelled with an lvalue sigil. 1188084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// This is never true of rvalue references but can also be false 1189084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// on lvalue references because of C++0x [dcl.typedef]p9, 1190084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// as follows: 1191084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// 1192084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// typedef int &ref; // lvalue, spelled lvalue 1193084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// typedef int &&rvref; // rvalue 1194084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// ref &a; // lvalue, inner ref, spelled lvalue 1195084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// ref &&a; // lvalue, inner ref 1196084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// rvref &a; // lvalue, inner ref, spelled lvalue 1197084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// rvref &&a; // rvalue, inner ref 1198b366986ba90b62e13a9562822179f488c1febcc5Francois Pichet unsigned SpelledAsLValue : 1; 1199084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1200084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// True if the inner type is a reference type. This only happens 1201084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// in non-canonical forms. 1202b366986ba90b62e13a9562822179f488c1febcc5Francois Pichet unsigned InnerRef : 1; 1203084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall }; 120411594551693b1db92840bf1640d087ce1062609fSebastian Redl 12051e75edda2f03c9416845f86c8f69dfaff6eb262bJohn McCall class TypeWithKeywordBitfields { 12061e75edda2f03c9416845f86c8f69dfaff6eb262bJohn McCall friend class TypeWithKeyword; 120711594551693b1db92840bf1640d087ce1062609fSebastian Redl 12081e75edda2f03c9416845f86c8f69dfaff6eb262bJohn McCall unsigned : NumTypeBits; 12091e75edda2f03c9416845f86c8f69dfaff6eb262bJohn McCall 12101e75edda2f03c9416845f86c8f69dfaff6eb262bJohn McCall /// An ElaboratedTypeKeyword. 8 bits for efficient access. 12111e75edda2f03c9416845f86c8f69dfaff6eb262bJohn McCall unsigned Keyword : 8; 12121e75edda2f03c9416845f86c8f69dfaff6eb262bJohn McCall }; 12131e75edda2f03c9416845f86c8f69dfaff6eb262bJohn McCall 1214084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall class VectorTypeBitfields { 1215084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall friend class VectorType; 121611594551693b1db92840bf1640d087ce1062609fSebastian Redl 1217084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned : NumTypeBits; 1218f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall 1219b3e547db227afec80fd921b4dbff66bd91da992fBob Wilson /// VecKind - The kind of vector, either a generic vector type or some 1220b3e547db227afec80fd921b4dbff66bd91da992fBob Wilson /// target-specific vector type such as for AltiVec or Neon. 122187fa7564c1e8b7894c1a9f646cb1294c8c2a7f9dBob Wilson unsigned VecKind : 3; 1222084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1223084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall /// NumElements - The number of elements in the vector. 122487fa7564c1e8b7894c1a9f646cb1294c8c2a7f9dBob Wilson unsigned NumElements : 29 - NumTypeBits; 1225084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall }; 1226084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 12279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall class AttributedTypeBitfields { 12289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall friend class AttributedType; 12299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 12309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall unsigned : NumTypeBits; 12319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 12329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// AttrKind - an AttributedType::Kind 12339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall unsigned AttrKind : 32 - NumTypeBits; 12349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall }; 12359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 1236084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall union { 1237084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall TypeBitfields TypeBits; 1238084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall ArrayTypeBitfields ArrayTypeBits; 12399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeBitfields AttributedTypeBits; 1240084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall BuiltinTypeBitfields BuiltinTypeBits; 1241084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall FunctionTypeBitfields FunctionTypeBits; 1242084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall ObjCObjectTypeBitfields ObjCObjectTypeBits; 1243084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall ReferenceTypeBitfields ReferenceTypeBits; 12441e75edda2f03c9416845f86c8f69dfaff6eb262bJohn McCall TypeWithKeywordBitfields TypeWithKeywordBits; 1245084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall VectorTypeBitfields VectorTypeBits; 1246084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall }; 1247084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 1248084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCallprivate: 1249461310d47dfb77ed4b176cfa19358bddeb732a35Sebastian Redl /// \brief Set whether this type comes from an AST file. 1250b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie void setFromAST(bool V = true) const { 1251084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall TypeBits.FromAST = V; 125211594551693b1db92840bf1640d087ce1062609fSebastian Redl } 1253ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1254b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall template <class T> friend class TypePropertyCache; 125582254439b368de855d1e66440071017a1f2d4f0aJohn McCall 1256ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprotected: 1257ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // silence VC++ warning C4355: 'this' : used in base member initializer list 1258ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Type *this_() { return this; } 1259b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie Type(TypeClass tc, QualType canon, bool Dependent, 1260561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent, bool VariablyModified, 1261d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool ContainsUnexpandedParameterPack) 12623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall : ExtQualsTypeCommonBase(this, 12633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall canon.isNull() ? QualType(this_(), 0) : canon) { 1264084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall TypeBits.TC = tc; 1265084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall TypeBits.Dependent = Dependent; 1266561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TypeBits.InstantiationDependent = Dependent || InstantiationDependent; 1267084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall TypeBits.VariablyModified = VariablyModified; 1268d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 126982254439b368de855d1e66440071017a1f2d4f0aJohn McCall TypeBits.CacheValidAndVisibility = 0; 1270084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall TypeBits.CachedLocalOrUnnamed = false; 1271084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall TypeBits.CachedLinkage = NoLinkage; 1272084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall TypeBits.FromAST = false; 1273084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall } 1274ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; 1275ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1276b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie void setDependent(bool D = true) { 1277b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie TypeBits.Dependent = D; 1278561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (D) 1279561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TypeBits.InstantiationDependent = true; 1280561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1281b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie void setInstantiationDependent(bool D = true) { 1282561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TypeBits.InstantiationDependent = D; } 1283b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; 1284561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1285d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor void setContainsUnexpandedParameterPack(bool PP = true) { 1286d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor TypeBits.ContainsUnexpandedParameterPack = PP; 1287d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 1288d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1289ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 1290084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); } 1291ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1292461310d47dfb77ed4b176cfa19358bddeb732a35Sebastian Redl /// \brief Whether this type comes from an AST file. 1293084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall bool isFromAST() const { return TypeBits.FromAST; } 129411594551693b1db92840bf1640d087ce1062609fSebastian Redl 1295d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this type is or contains an unexpanded parameter 1296d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// pack, used to support C++0x variadic templates. 1297d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 1298d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// A type that contains a parameter pack shall be expanded by the 1299d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// ellipsis operator at some point. For example, the typedef in the 1300d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// following example contains an unexpanded parameter pack 'T': 1301d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 1302d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \code 1303d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// template<typename ...T> 1304d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// struct X { 1305d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// typedef T* pointer_types; // ill-formed; T is a parameter pack. 1306d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// }; 1307d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \endcode 1308d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 1309b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// Note that this routine does not specify which 1310b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie bool containsUnexpandedParameterPack() const { 1311d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return TypeBits.ContainsUnexpandedParameterPack; 1312d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 1313d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 13143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// Determines if this type would be canonical if it had no further 13153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// qualification. 1316ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isCanonicalUnqualified() const { 13173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return CanonicalType == QualType(this, 0); 1318ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1319ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1320ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 1321ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// object types, function types, and incomplete types. 1322ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1323ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isIncompleteType - Return true if this is an incomplete type. 1324ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// A type that can describe objects, but which lacks information needed to 1325ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// determine its size (e.g. void, or a fwd declared struct). Clients of this 1326ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// routine will need to determine if the size is actually required. 1327ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isIncompleteType() const; 1328ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1329ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isIncompleteOrObjectType - Return true if this is an incomplete or object 1330ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// type, in other words, not a function type. 1331ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isIncompleteOrObjectType() const { 1332ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return !isFunctionType(); 1333ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1334b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 13352fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor /// \brief Determine whether this type is an object type. 13362fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor bool isObjectType() const { 13372fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor // C++ [basic.types]p8: 1338b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie // An object type is a (possibly cv-qualified) type that is not a 13392fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor // function type, not a reference type, and not a void type. 13402fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor return !isReferenceType() && !isFunctionType() && !isVoidType(); 13412fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor } 1342ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1343ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isLiteralType - Return true if this is a literal type 1344ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// (C++0x [basic.types]p10) 1345ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isLiteralType() const; 1346ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1347636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth /// \brief Test if this type is a standard-layout type. 1348636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth /// (C++0x [basic.type]p9) 1349636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth bool isStandardLayoutType() const; 1350636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1351ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// Helper methods to distinguish type categories. All type predicates 1352ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// operate on the canonical type, ignoring typedefs and qualifiers. 1353ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1354522fb671290dd5462bfd819401768686fa53e925Tom Care /// isBuiltinType - returns true if the type is a builtin type. 1355522fb671290dd5462bfd819401768686fa53e925Tom Care bool isBuiltinType() const; 1356522fb671290dd5462bfd819401768686fa53e925Tom Care 1357ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isSpecificBuiltinType - Test for a particular builtin type. 1358ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSpecificBuiltinType(unsigned K) const; 1359ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 136013e47eecb1470d59e399952280e68c16e302c75dJohn McCall /// isPlaceholderType - Test for a type which does not represent an 136113e47eecb1470d59e399952280e68c16e302c75dJohn McCall /// actual type-system type but is instead used as a placeholder for 136213e47eecb1470d59e399952280e68c16e302c75dJohn McCall /// various convenient purposes within Clang. All such types are 136313e47eecb1470d59e399952280e68c16e302c75dJohn McCall /// BuiltinTypes. 136413e47eecb1470d59e399952280e68c16e302c75dJohn McCall bool isPlaceholderType() const; 1365a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall const BuiltinType *getAsPlaceholderType() const; 136613e47eecb1470d59e399952280e68c16e302c75dJohn McCall 1367864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// isSpecificPlaceholderType - Test for a specific placeholder type. 1368864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall bool isSpecificPlaceholderType(unsigned K) const; 1369864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 1370ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isIntegerType() does *not* include complex integers (a GCC extension). 1371ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isComplexIntegerType() can be used to test for complex integers. 1372ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 1373ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isEnumeralType() const; 1374ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isBooleanType() const; 1375ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isCharType() const; 1376ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isWideCharType() const; 13775cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isChar16Type() const; 13785cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isChar32Type() const; 1379ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isAnyCharacterType() const; 13807fcbab0d9ed96afbdcc3dd4ad876bcbf452fd25fDouglas Gregor bool isIntegralType(ASTContext &Ctx) const; 1381b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 138259327f06fa557d652e0560e6895c93db70ea5ec7Douglas Gregor /// \brief Determine whether this type is an integral or enumeration type. 138359327f06fa557d652e0560e6895c93db70ea5ec7Douglas Gregor bool isIntegralOrEnumerationType() const; 1384df8e391abb083ea901108528cbd505980dccf695Douglas Gregor /// \brief Determine whether this type is an integral or unscoped enumeration 1385df8e391abb083ea901108528cbd505980dccf695Douglas Gregor /// type. 1386df8e391abb083ea901108528cbd505980dccf695Douglas Gregor bool isIntegralOrUnscopedEnumerationType() const; 1387b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1388ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// Floating point categories. 1389ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 1390ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isComplexType() does *not* include complex integers (a GCC extension). 1391ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isComplexIntegerType() can be used to test for complex integers. 1392ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isComplexType() const; // C99 6.2.5p11 (complex) 1393ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 1394ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 1395aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov bool isHalfType() const; // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half) 1396ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 1397ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 1398ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isVoidType() const; // C99 6.2.5p19 1399ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isDerivedType() const; // C99 6.2.5p20 1400ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 1401ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isAggregateType() const; 1402aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth bool isFundamentalType() const; 1403aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth bool isCompoundType() const; 1404ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1405ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Type Predicates: Check to see if this type is structurally the specified 1406ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // type, ignoring typedefs and qualifiers. 1407ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isFunctionType() const; 1408ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } 1409ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } 1410ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isPointerType() const; 1411ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 1412ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isBlockPointerType() const; 1413ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isVoidPointerType() const; 1414ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isReferenceType() const; 1415ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isLValueReferenceType() const; 1416ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isRValueReferenceType() const; 1417ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isFunctionPointerType() const; 1418ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isMemberPointerType() const; 1419ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isMemberFunctionPointerType() const; 1420d401c08eaebd14b9fa6440513c764a7342d0adeaDouglas Gregor bool isMemberDataPointerType() const; 1421ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isArrayType() const; 1422ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isConstantArrayType() const; 1423ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isIncompleteArrayType() const; 1424ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isVariableArrayType() const; 1425ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isDependentSizedArrayType() const; 1426ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isRecordType() const; 1427ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isClassType() const; 1428ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isStructureType() const; 1429ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isStructureOrClassType() const; 1430ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isUnionType() const; 1431ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isComplexIntegerType() const; // GCC _Complex integer type. 1432ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isVectorType() const; // GCC vector type. 1433ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isExtVectorType() const; // Extended vector type. 1434f85e193739c953358c865005855253af4f68a497John McCall bool isObjCObjectPointerType() const; // pointer to ObjC object 1435f85e193739c953358c865005855253af4f68a497John McCall bool isObjCRetainableType() const; // ObjC object or block pointer 1436f85e193739c953358c865005855253af4f68a497John McCall bool isObjCLifetimeType() const; // (array of)* retainable type 1437f85e193739c953358c865005855253af4f68a497John McCall bool isObjCIndirectLifetimeType() const; // (pointer to)* lifetime type 1438f85e193739c953358c865005855253af4f68a497John McCall bool isObjCNSObjectType() const; // __attribute__((NSObject)) 1439ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // FIXME: change this to 'raw' interface type, so we can used 'interface' type 1440ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // for the common case. 1441f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCObjectType() const; // NSString or typeof(*(id)0) 1442ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isObjCQualifiedInterfaceType() const; // NSString<foo> 1443ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isObjCQualifiedIdType() const; // id<foo> 1444ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isObjCQualifiedClassType() const; // Class<foo> 1445e004547e55aa2e69d1a7ee3d037605c5b1e9f6c3Douglas Gregor bool isObjCObjectOrInterfaceType() const; 1446ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isObjCIdType() const; // id 1447ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isObjCClassType() const; // Class 1448ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isObjCSelType() const; // Class 1449ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isObjCBuiltinType() const; // 'id' or 'Class' 1450f85e193739c953358c865005855253af4f68a497John McCall bool isObjCARCBridgableType() const; 1451f85e193739c953358c865005855253af4f68a497John McCall bool isCARCBridgableType() const; 1452ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isTemplateTypeParmType() const; // C++ template type parameter 1453ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isNullPtrType() const; // C++0x nullptr_t 1454b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman bool isAtomicType() const; // C1X _Atomic() 1455ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1456f85e193739c953358c865005855253af4f68a497John McCall /// Determines if this type, which must satisfy 1457f85e193739c953358c865005855253af4f68a497John McCall /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather 1458f85e193739c953358c865005855253af4f68a497John McCall /// than implicitly __strong. 1459f85e193739c953358c865005855253af4f68a497John McCall bool isObjCARCImplicitlyUnretainedType() const; 1460f85e193739c953358c865005855253af4f68a497John McCall 1461f85e193739c953358c865005855253af4f68a497John McCall /// Return the implicit lifetime for this type, which must not be dependent. 1462f85e193739c953358c865005855253af4f68a497John McCall Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const; 1463f85e193739c953358c865005855253af4f68a497John McCall 14646b4052d120c3ef414a822b3cff063432a1df3186John McCall enum ScalarTypeKind { 14651d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall STK_CPointer, 14661d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall STK_BlockPointer, 14671d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall STK_ObjCObjectPointer, 14686b4052d120c3ef414a822b3cff063432a1df3186John McCall STK_MemberPointer, 14696b4052d120c3ef414a822b3cff063432a1df3186John McCall STK_Bool, 14706b4052d120c3ef414a822b3cff063432a1df3186John McCall STK_Integral, 14716b4052d120c3ef414a822b3cff063432a1df3186John McCall STK_Floating, 14726b4052d120c3ef414a822b3cff063432a1df3186John McCall STK_IntegralComplex, 14736b4052d120c3ef414a822b3cff063432a1df3186John McCall STK_FloatingComplex 14746b4052d120c3ef414a822b3cff063432a1df3186John McCall }; 14756b4052d120c3ef414a822b3cff063432a1df3186John McCall /// getScalarTypeKind - Given that this is a scalar type, classify it. 14766b4052d120c3ef414a822b3cff063432a1df3186John McCall ScalarTypeKind getScalarTypeKind() const; 14776b4052d120c3ef414a822b3cff063432a1df3186John McCall 1478ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isDependentType - Whether this type is a dependent type, meaning 1479ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// that its definition somehow depends on a template parameter 1480ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// (C++ [temp.dep.type]). 1481084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall bool isDependentType() const { return TypeBits.Dependent; } 1482b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1483561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Determine whether this type is an instantiation-dependent type, 1484561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// meaning that the type involves a template parameter (even if the 1485561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// definition does not actually depend on the type substituted for that 1486561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// template parameter). 1487b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie bool isInstantiationDependentType() const { 1488b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie return TypeBits.InstantiationDependent; 1489561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1490b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1491e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor /// \brief Whether this type is a variably-modified type (C99 6.7.5). 1492084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall bool isVariablyModifiedType() const { return TypeBits.VariablyModified; } 14933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 14943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// \brief Whether this type involves a variable-length array type 14953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// with a definite size. 14963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall bool hasSizedVLAType() const; 1497b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1498b0efb27f8928c8cdfd4b94b547ec9d87e31066cdDouglas Gregor /// \brief Whether this type is or contains a local or unnamed type. 1499b0efb27f8928c8cdfd4b94b547ec9d87e31066cdDouglas Gregor bool hasUnnamedOrLocalType() const; 1500b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1501ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isOverloadableType() const; 1502ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1503ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Determine wither this type is a C++ elaborated-type-specifier. 1504ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isElaboratedTypeSpecifier() const; 1505bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth 1506bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth bool canDecayToPointerType() const; 1507b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1508ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// hasPointerRepresentation - Whether this type is represented 1509ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// natively as a pointer; this includes pointers, references, block 1510ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// pointers, and Objective-C interface, qualified id, and qualified 1511ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// interface types, as well as nullptr_t. 1512ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasPointerRepresentation() const; 1513ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1514ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// hasObjCPointerRepresentation - Whether this type can represent 1515ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// an objective pointer type for the purpose of GC'ability 1516ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasObjCPointerRepresentation() const; 1517ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 151857cff32124cd5b95f3e1a5da12d3fff7e8892943Douglas Gregor /// \brief Determine whether this type has an integer representation 151957cff32124cd5b95f3e1a5da12d3fff7e8892943Douglas Gregor /// of some sort, e.g., it is an integer type or a vector. 152057cff32124cd5b95f3e1a5da12d3fff7e8892943Douglas Gregor bool hasIntegerRepresentation() const; 152157cff32124cd5b95f3e1a5da12d3fff7e8892943Douglas Gregor 152257cff32124cd5b95f3e1a5da12d3fff7e8892943Douglas Gregor /// \brief Determine whether this type has an signed integer representation 152357cff32124cd5b95f3e1a5da12d3fff7e8892943Douglas Gregor /// of some sort, e.g., it is an signed integer type or a vector. 152457cff32124cd5b95f3e1a5da12d3fff7e8892943Douglas Gregor bool hasSignedIntegerRepresentation() const; 152557cff32124cd5b95f3e1a5da12d3fff7e8892943Douglas Gregor 152657cff32124cd5b95f3e1a5da12d3fff7e8892943Douglas Gregor /// \brief Determine whether this type has an unsigned integer representation 152757cff32124cd5b95f3e1a5da12d3fff7e8892943Douglas Gregor /// of some sort, e.g., it is an unsigned integer type or a vector. 152857cff32124cd5b95f3e1a5da12d3fff7e8892943Douglas Gregor bool hasUnsignedIntegerRepresentation() const; 152957cff32124cd5b95f3e1a5da12d3fff7e8892943Douglas Gregor 15301a7c1b12a61ed17f914c9d557dd6666e0253c133Douglas Gregor /// \brief Determine whether this type has a floating-point representation 15311a7c1b12a61ed17f914c9d557dd6666e0253c133Douglas Gregor /// of some sort, e.g., it is a floating-point type or a vector thereof. 15321a7c1b12a61ed17f914c9d557dd6666e0253c133Douglas Gregor bool hasFloatingRepresentation() const; 153357cff32124cd5b95f3e1a5da12d3fff7e8892943Douglas Gregor 1534ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Type Checking Functions: Check to see if this type is structurally the 1535ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // specified type, ignoring typedefs and qualifiers, and return a pointer to 1536ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // the best type we can. 1537ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const RecordType *getAsStructureType() const; 1538ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// NOTE: getAs*ArrayType are methods on ASTContext. 1539ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const RecordType *getAsUnionType() const; 1540ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 1541ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // The following is a convenience method that returns an ObjCObjectPointerType 1542ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // for object declared using an interface. 1543ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 1544ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 1545759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian const ObjCObjectPointerType *getAsObjCQualifiedClassType() const; 1546f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall const ObjCObjectType *getAsObjCQualifiedInterfaceType() const; 1547ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 1548ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 154995c54dfa43c5159d2854910c21cc03374238e94eDouglas Gregor /// \brief Retrieves the CXXRecordDecl that this type refers to, either 1550b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// because the type is a RecordType or because it is the injected-class-name 155195c54dfa43c5159d2854910c21cc03374238e94eDouglas Gregor /// type of a class template or class template partial specialization. 155295c54dfa43c5159d2854910c21cc03374238e94eDouglas Gregor CXXRecordDecl *getAsCXXRecordDecl() const; 155334b41d939a1328f484511c6002ba2456db879a29Richard Smith 155434b41d939a1328f484511c6002ba2456db879a29Richard Smith /// \brief Get the AutoType whose type will be deduced for a variable with 155534b41d939a1328f484511c6002ba2456db879a29Richard Smith /// an initializer of this type. This looks through declarators like pointer 155634b41d939a1328f484511c6002ba2456db879a29Richard Smith /// types, but not through decltype or typedefs. 155734b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *getContainedAutoType() const; 1558b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1559d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// Member-template getAs<specific type>'. Look through sugar for 1560d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// an instance of <specific type>. This scheme will eventually 1561d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// replace the specific getAsXXXX methods above. 1562d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// 1563d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// There are some specializations of this member template listed 1564d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// immediately following this class. 1565ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao template <typename T> const T *getAs() const; 1566ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 15673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// A variant of getAs<> for array types which silently discards 15683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// qualifiers from the outermost type. 15693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ArrayType *getAsArrayTypeUnsafe() const; 15703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 1571d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// Member-template castAs<specific type>. Look through sugar for 1572d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// the underlying instance of <specific type>. 1573d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// 1574d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// This method has the same relationship to getAs<T> as cast<T> has 1575d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// to dyn_cast<T>; which is to say, the underlying type *must* 1576d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// have the intended type, and this method will never return null. 1577d0370f59e79702ac908c81bf556519f91e9ca297John McCall template <typename T> const T *castAs() const; 1578d0370f59e79702ac908c81bf556519f91e9ca297John McCall 1579d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// A variant of castAs<> for array type which silently discards 1580d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// qualifiers from the outermost type. 1581d0370f59e79702ac908c81bf556519f91e9ca297John McCall const ArrayType *castAsArrayTypeUnsafe() const; 1582d0370f59e79702ac908c81bf556519f91e9ca297John McCall 1583d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// getBaseElementTypeUnsafe - Get the base element type of this 1584d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// type, potentially discarding type qualifiers. This method 1585d0370f59e79702ac908c81bf556519f91e9ca297John McCall /// should never be used when type qualifiers are meaningful. 1586d0370f59e79702ac908c81bf556519f91e9ca297John McCall const Type *getBaseElementTypeUnsafe() const; 1587d0370f59e79702ac908c81bf556519f91e9ca297John McCall 1588ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// getArrayElementTypeNoTypeQual - If this is an array type, return the 1589ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// element type of the array, potentially with type qualifiers missing. 1590ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// This method should never be used when type qualifiers are meaningful. 1591ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const Type *getArrayElementTypeNoTypeQual() const; 1592ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1593ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// getPointeeType - If this is a pointer, ObjC object pointer, or block 1594ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// pointer, this returns the respective pointee. 1595ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getPointeeType() const; 1596ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1597ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// getUnqualifiedDesugaredType() - Return the specified type with 1598ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// any "sugar" removed from the type, removing any typedefs, 1599ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// typeofs, etc., as well as any qualifiers. 1600ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const Type *getUnqualifiedDesugaredType() const; 1601ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1602ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// More type predicates useful for type checking/promotion 1603ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isPromotableIntegerType() const; // C99 6.3.1.1p2 1604ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1605ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isSignedIntegerType - Return true if this is an integer type that is 1606ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 16075f3827cabd526d0dd5f291d46c310103cebe7a44Eli Friedman /// or an enum decl which has a signed representation. 1608ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSignedIntegerType() const; 1609ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1610ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isUnsignedIntegerType - Return true if this is an integer type that is 1611b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], 16125f3827cabd526d0dd5f291d46c310103cebe7a44Eli Friedman /// or an enum decl which has an unsigned representation. 1613ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isUnsignedIntegerType() const; 1614ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1615b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// Determines whether this is an integer type that is signed or an 1616575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor /// enumeration types whose underlying type is a signed integer type. 1617575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor bool isSignedIntegerOrEnumerationType() const; 1618b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1619b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// Determines whether this is an integer type that is unsigned or an 1620575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor /// enumeration types whose underlying type is a unsigned integer type. 1621575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor bool isUnsignedIntegerOrEnumerationType() const; 1622575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 1623ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isConstantSizeType - Return true if this is not a variable sized type, 1624ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// according to the rules of C99 6.7.5p3. It is not legal to call this on 1625ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// incomplete types. 1626ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isConstantSizeType() const; 1627ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1628ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// isSpecifierType - Returns true if this type can be represented by some 1629ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// set of type specifiers. 1630ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSpecifierType() const; 1631ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1632ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Determine the linkage of this type. 1633949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor Linkage getLinkage() const; 163482254439b368de855d1e66440071017a1f2d4f0aJohn McCall 163582254439b368de855d1e66440071017a1f2d4f0aJohn McCall /// \brief Determine the visibility of this type. 163682254439b368de855d1e66440071017a1f2d4f0aJohn McCall Visibility getVisibility() const; 163782254439b368de855d1e66440071017a1f2d4f0aJohn McCall 163882254439b368de855d1e66440071017a1f2d4f0aJohn McCall /// \brief Determine the linkage and visibility of this type. 163982254439b368de855d1e66440071017a1f2d4f0aJohn McCall std::pair<Linkage,Visibility> getLinkageAndVisibility() const; 1640b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1641949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor /// \brief Note that the linkage is no longer known. 1642949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor void ClearLinkageCache(); 1643b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1644949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor const char *getTypeClassName() const; 1645ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1646ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getCanonicalTypeInternal() const { 1647ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return CanonicalType; 1648ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1649ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h 1650ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void dump() const; 1651f85e193739c953358c865005855253af4f68a497John McCall 1652ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *) { return true; } 1653b69c35fbf8635a267215a83b4e9fd980019f003aArgiris Kirtzidis 16547b39a2cadf9d62647f3aa572c52b77ea4114a599Sebastian Redl friend class ASTReader; 1655c9b42df920d69f0a2e4779bfbea6234cf355539dSebastian Redl friend class ASTWriter; 1656ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 1657ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1658ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaotemplate <> inline const TypedefType *Type::getAs() const { 1659ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return dyn_cast<TypedefType>(this); 1660ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 1661ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1662ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// We can do canonical leaf types faster, because we don't have to 1663ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// worry about preserving child type decoration. 1664ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#define TYPE(Class, Base) 1665ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#define LEAF_TYPE(Class) \ 1666ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaotemplate <> inline const Class##Type *Type::getAs() const { \ 1667ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return dyn_cast<Class##Type>(CanonicalType); \ 1668d0370f59e79702ac908c81bf556519f91e9ca297John McCall} \ 1669d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <> inline const Class##Type *Type::castAs() const { \ 1670d0370f59e79702ac908c81bf556519f91e9ca297John McCall return cast<Class##Type>(CanonicalType); \ 1671ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 1672ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "clang/AST/TypeNodes.def" 1673ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1674ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1675ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// BuiltinType - This class is used for builtin types like 'int'. Builtin 1676ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// types are always canonical and have a literal name field. 1677ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass BuiltinType : public Type { 1678ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 1679ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao enum Kind { 1680e0a22d06888c13989b3f72db319f1d498bf69153John McCall#define BUILTIN_TYPE(Id, SingletonId) Id, 1681e0a22d06888c13989b3f72db319f1d498bf69153John McCall#define LAST_BUILTIN_TYPE(Id) LastKind = Id 1682e0a22d06888c13989b3f72db319f1d498bf69153John McCall#include "clang/AST/BuiltinTypes.def" 1683ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao }; 1684f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall 1685ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 1686ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao BuiltinType(Kind K) 1687e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent), 1688561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/(K == Dependent), 1689d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 1690d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*Unexpanded paramter pack=*/false) { 1691084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall BuiltinTypeBits.Kind = K; 1692f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall } 1693ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1694084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); } 169530c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor const char *getName(const PrintingPolicy &Policy) const; 1696ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1697ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 1698ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 1699ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1700ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isInteger() const { 1701f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall return getKind() >= Bool && getKind() <= Int128; 1702ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1703ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1704ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSignedInteger() const { 1705f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall return getKind() >= Char_S && getKind() <= Int128; 1706ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1707ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1708ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isUnsignedInteger() const { 1709f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall return getKind() >= Bool && getKind() <= UInt128; 1710ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1711ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1712ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isFloatingPoint() const { 1713aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov return getKind() >= Half && getKind() <= LongDouble; 1714680523a91dd3351389667c8de17121ba7ae82673John McCall } 1715680523a91dd3351389667c8de17121ba7ae82673John McCall 171685def357129b6cdfd69a66ad0e6994506418a2a9John McCall /// Determines whether the given kind corresponds to a placeholder type. 171785def357129b6cdfd69a66ad0e6994506418a2a9John McCall static bool isPlaceholderTypeKind(Kind K) { 171885def357129b6cdfd69a66ad0e6994506418a2a9John McCall return K >= Overload; 1719afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall } 1720afcfd753e6c5d50edb13dd0b7f46fc40f6aa8fa0John McCall 1721864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// Determines whether this type is a placeholder type, i.e. a type 1722864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// which cannot appear in arbitrary positions in a fully-formed 1723864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// expression. 172413e47eecb1470d59e399952280e68c16e302c75dJohn McCall bool isPlaceholderType() const { 172585def357129b6cdfd69a66ad0e6994506418a2a9John McCall return isPlaceholderTypeKind(getKind()); 1726ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1727ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1728ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 1729ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const BuiltinType *) { return true; } 1730ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 1731ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1732ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 1733ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// types (_Complex float etc) as well as the GCC integer complex extensions. 1734ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 1735ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass ComplexType : public Type, public llvm::FoldingSetNode { 1736ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType ElementType; 1737ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ComplexType(QualType Element, QualType CanonicalPtr) : 1738e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor Type(Complex, CanonicalPtr, Element->isDependentType(), 1739561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Element->isInstantiationDependentType(), 1740d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Element->isVariablyModifiedType(), 1741d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Element->containsUnexpandedParameterPack()), 1742ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ElementType(Element) { 1743ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1744ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 1745949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1746ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 1747ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getElementType() const { return ElementType; } 1748ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1749ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 1750ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 1751ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1752ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 1753ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Profile(ID, getElementType()); 1754ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1755ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 1756ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(Element.getAsOpaquePtr()); 1757ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1758ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1759ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 1760ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const ComplexType *) { return true; } 1761ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 1762ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1763075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// ParenType - Sugar for parentheses used when specifying types. 1764075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// 1765075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenType : public Type, public llvm::FoldingSetNode { 1766075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Inner; 1767075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1768075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenType(QualType InnerType, QualType CanonType) : 1769075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Type(Paren, CanonType, InnerType->isDependentType(), 1770561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InnerType->isInstantiationDependentType(), 1771d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor InnerType->isVariablyModifiedType(), 1772d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor InnerType->containsUnexpandedParameterPack()), 1773075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner(InnerType) { 1774075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1775075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara friend class ASTContext; // ASTContext creates these. 1776075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1777075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic: 1778075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1779075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType getInnerType() const { return Inner; } 1780075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1781075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara bool isSugared() const { return true; } 1782075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType desugar() const { return getInnerType(); } 1783075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1784075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara void Profile(llvm::FoldingSetNodeID &ID) { 1785075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Profile(ID, getInnerType()); 1786075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1787075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) { 1788075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner.Profile(ID); 1789075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1790075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1791075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static bool classof(const Type *T) { return T->getTypeClass() == Paren; } 1792075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static bool classof(const ParenType *) { return true; } 1793075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}; 1794075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1795ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// PointerType - C99 6.7.5.1 - Pointer Declarators. 1796ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 1797ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass PointerType : public Type, public llvm::FoldingSetNode { 1798ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType PointeeType; 1799ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1800ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao PointerType(QualType Pointee, QualType CanonicalPtr) : 1801e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor Type(Pointer, CanonicalPtr, Pointee->isDependentType(), 1802561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Pointee->isInstantiationDependentType(), 1803d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->isVariablyModifiedType(), 1804b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie Pointee->containsUnexpandedParameterPack()), 1805e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor PointeeType(Pointee) { 1806ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1807ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 1808949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 1809ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 1810ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1811ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getPointeeType() const { return PointeeType; } 1812ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1813ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 1814ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 1815ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1816ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 1817ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Profile(ID, getPointeeType()); 1818ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1819ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 1820ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(Pointee.getAsOpaquePtr()); 1821ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1822ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1823ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 1824ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const PointerType *) { return true; } 1825ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 1826ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1827ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// BlockPointerType - pointer to a block type. 1828ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// This type is to represent types syntactically represented as 1829ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// "void (^)(int)", etc. Pointee is required to always be a function type. 1830ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 1831ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass BlockPointerType : public Type, public llvm::FoldingSetNode { 1832ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType PointeeType; // Block is some kind of pointer type 1833ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao BlockPointerType(QualType Pointee, QualType CanonicalCls) : 1834e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor Type(BlockPointer, CanonicalCls, Pointee->isDependentType(), 1835561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Pointee->isInstantiationDependentType(), 1836d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->isVariablyModifiedType(), 1837d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->containsUnexpandedParameterPack()), 1838ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao PointeeType(Pointee) { 1839ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1840ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 1841b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1842ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 1843ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1844ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Get the pointee type. Pointee is required to always be a function type. 1845ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getPointeeType() const { return PointeeType; } 1846ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1847ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 1848ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 1849ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1850ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 1851ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Profile(ID, getPointeeType()); 1852ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1853ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 1854ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(Pointee.getAsOpaquePtr()); 1855ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1856ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1857ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 1858ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == BlockPointer; 1859ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1860ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const BlockPointerType *) { return true; } 1861ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 1862ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1863ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 1864ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 1865ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass ReferenceType : public Type, public llvm::FoldingSetNode { 1866ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType PointeeType; 1867ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1868ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprotected: 1869ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, 1870ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool SpelledAsLValue) : 1871e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor Type(tc, CanonicalRef, Referencee->isDependentType(), 1872561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Referencee->isInstantiationDependentType(), 1873d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Referencee->isVariablyModifiedType(), 1874b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie Referencee->containsUnexpandedParameterPack()), 1875b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie PointeeType(Referencee) 1876d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor { 1877084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue; 1878084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall ReferenceTypeBits.InnerRef = Referencee->isReferenceType(); 1879ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1880b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1881ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 1882084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; } 1883084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall bool isInnerRef() const { return ReferenceTypeBits.InnerRef; } 1884b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1885ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getPointeeTypeAsWritten() const { return PointeeType; } 1886ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getPointeeType() const { 1887ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // FIXME: this might strip inner qualifiers; okay? 1888ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const ReferenceType *T = this; 1889f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall while (T->isInnerRef()) 1890d0370f59e79702ac908c81bf556519f91e9ca297John McCall T = T->PointeeType->castAs<ReferenceType>(); 1891ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->PointeeType; 1892ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1893ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1894ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 1895f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall Profile(ID, PointeeType, isSpelledAsLValue()); 1896ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1897ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, 1898ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType Referencee, 1899ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool SpelledAsLValue) { 1900ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(Referencee.getAsOpaquePtr()); 1901ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddBoolean(SpelledAsLValue); 1902ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1903ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1904ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 1905ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == LValueReference || 1906ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao T->getTypeClass() == RValueReference; 1907ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1908ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const ReferenceType *) { return true; } 1909ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 1910ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1911ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 1912ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 1913ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass LValueReferenceType : public ReferenceType { 1914ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao LValueReferenceType(QualType Referencee, QualType CanonicalRef, 1915ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool SpelledAsLValue) : 1916ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue) 1917ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao {} 1918ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these 1919ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 1920ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 1921ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 1922ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1923ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 1924ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == LValueReference; 1925ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1926ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const LValueReferenceType *) { return true; } 1927ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 1928ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1929ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 1930ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 1931ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass RValueReferenceType : public ReferenceType { 1932ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 1933ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ReferenceType(RValueReference, Referencee, CanonicalRef, false) { 1934ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1935ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these 1936ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 1937ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 1938ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 1939ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1940ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 1941ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == RValueReference; 1942ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1943ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const RValueReferenceType *) { return true; } 1944ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 1945ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1946ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// MemberPointerType - C++ 8.3.3 - Pointers to members 1947ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 1948ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass MemberPointerType : public Type, public llvm::FoldingSetNode { 1949ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType PointeeType; 1950ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// The class of which the pointee is a member. Must ultimately be a 1951ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// RecordType, but could be a typedef or a template parameter too. 1952ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const Type *Class; 1953ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1954ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 1955ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Type(MemberPointer, CanonicalPtr, 1956e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor Cls->isDependentType() || Pointee->isDependentType(), 1957b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie (Cls->isInstantiationDependentType() || 1958561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Pointee->isInstantiationDependentType()), 1959d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->isVariablyModifiedType(), 1960b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie (Cls->containsUnexpandedParameterPack() || 1961d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Pointee->containsUnexpandedParameterPack())), 1962ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao PointeeType(Pointee), Class(Cls) { 1963ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1964ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 1965b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 1966ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 1967ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getPointeeType() const { return PointeeType; } 1968ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 19696ae2325ec3b27aae178267de58fe35acf2027b91John McCall /// Returns true if the member type (i.e. the pointee type) is a 19706ae2325ec3b27aae178267de58fe35acf2027b91John McCall /// function type rather than a data-member type. 19716ae2325ec3b27aae178267de58fe35acf2027b91John McCall bool isMemberFunctionPointer() const { 19726ae2325ec3b27aae178267de58fe35acf2027b91John McCall return PointeeType->isFunctionProtoType(); 19736ae2325ec3b27aae178267de58fe35acf2027b91John McCall } 19746ae2325ec3b27aae178267de58fe35acf2027b91John McCall 19756ae2325ec3b27aae178267de58fe35acf2027b91John McCall /// Returns true if the member type (i.e. the pointee type) is a 19766ae2325ec3b27aae178267de58fe35acf2027b91John McCall /// data type rather than a function type. 19776ae2325ec3b27aae178267de58fe35acf2027b91John McCall bool isMemberDataPointer() const { 19786ae2325ec3b27aae178267de58fe35acf2027b91John McCall return !PointeeType->isFunctionProtoType(); 19796ae2325ec3b27aae178267de58fe35acf2027b91John McCall } 19806ae2325ec3b27aae178267de58fe35acf2027b91John McCall 1981ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const Type *getClass() const { return Class; } 1982ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1983ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 1984ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 1985ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1986ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 1987ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Profile(ID, getPointeeType(), getClass()); 1988ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1989ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 1990ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const Type *Class) { 1991ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(Pointee.getAsOpaquePtr()); 1992ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(Class); 1993ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1994ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 1995ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 1996ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == MemberPointer; 1997ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 1998ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const MemberPointerType *) { return true; } 1999ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2000ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2001ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// ArrayType - C99 6.7.5.2 - Array Declarators. 2002ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 2003ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass ArrayType : public Type, public llvm::FoldingSetNode { 2004ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2005ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 2006ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// an array with a static size (e.g. int X[static 4]), or an array 2007ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// with a star size (e.g. int X[*]). 2008ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// 'static' is only allowed on function parameters. 2009ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao enum ArraySizeModifier { 2010ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Normal, Static, Star 2011ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao }; 2012ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprivate: 2013ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// ElementType - The element type of the array. 2014ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType ElementType; 2015ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2016ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprotected: 2017ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // C++ [temp.dep.type]p1: 2018ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // A type is dependent if it is... 2019ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // - an array type constructed from any dependent type or whose 2020ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // size is specified by a constant expression that is 2021ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // value-dependent, 2022ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ArrayType(TypeClass tc, QualType et, QualType can, 2023d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ArraySizeModifier sm, unsigned tq, 2024d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool ContainsUnexpandedParameterPack) 2025e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray, 2026561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor et->isInstantiationDependentType() || tc == DependentSizedArray, 2027d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (tc == VariableArray || et->isVariablyModifiedType()), 2028d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ContainsUnexpandedParameterPack), 2029f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall ElementType(et) { 2030084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall ArrayTypeBits.IndexTypeQuals = tq; 2031084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall ArrayTypeBits.SizeModifier = sm; 2032f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall } 2033ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2034ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 2035949d2c031f173ec539d1aa667bba503fda7fb763Douglas Gregor 2036ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2037ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getElementType() const { return ElementType; } 2038ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ArraySizeModifier getSizeModifier() const { 2039084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall return ArraySizeModifier(ArrayTypeBits.SizeModifier); 2040ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2041ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Qualifiers getIndexTypeQualifiers() const { 2042f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers()); 2043f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall } 2044f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall unsigned getIndexTypeCVRQualifiers() const { 2045084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall return ArrayTypeBits.IndexTypeQuals; 2046ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2047ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2048ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 2049ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == ConstantArray || 2050ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao T->getTypeClass() == VariableArray || 2051ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao T->getTypeClass() == IncompleteArray || 2052ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao T->getTypeClass() == DependentSizedArray; 2053ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2054ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const ArrayType *) { return true; } 2055ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2056ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2057ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// ConstantArrayType - This class represents the canonical version of 2058ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// C arrays with a specified constant size. For example, the canonical 2059ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 2060ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// type is 'int' and the size is 404. 2061ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass ConstantArrayType : public ArrayType { 2062ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao llvm::APInt Size; // Allows us to unique the type. 2063ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2064ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 2065ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ArraySizeModifier sm, unsigned tq) 2066d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(ConstantArray, et, can, sm, tq, 2067d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor et->containsUnexpandedParameterPack()), 2068ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Size(size) {} 2069ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprotected: 2070ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ConstantArrayType(TypeClass tc, QualType et, QualType can, 2071ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 2072b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()), 2073d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Size(size) {} 2074ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 2075ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2076ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const llvm::APInt &getSize() const { return Size; } 2077ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 2078ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 2079ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2080b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 208164a5f6f7034808988c3596cf340a879c0c501869Douglas Gregor /// \brief Determine the number of bits required to address a member of 208264a5f6f7034808988c3596cf340a879c0c501869Douglas Gregor // an array with the given element type and number of elements. 208364a5f6f7034808988c3596cf340a879c0c501869Douglas Gregor static unsigned getNumAddressingBits(ASTContext &Context, 208464a5f6f7034808988c3596cf340a879c0c501869Douglas Gregor QualType ElementType, 208564a5f6f7034808988c3596cf340a879c0c501869Douglas Gregor const llvm::APInt &NumElements); 2086b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 208764a5f6f7034808988c3596cf340a879c0c501869Douglas Gregor /// \brief Determine the maximum number of active bits that an array's size 208864a5f6f7034808988c3596cf340a879c0c501869Douglas Gregor /// can require, which limits the maximum size of the array. 208964a5f6f7034808988c3596cf340a879c0c501869Douglas Gregor static unsigned getMaxSizeBits(ASTContext &Context); 2090b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 2091ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 2092ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Profile(ID, getElementType(), getSize(), 2093ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao getSizeModifier(), getIndexTypeCVRQualifiers()); 2094ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2095ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 2096ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 2097ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned TypeQuals) { 2098ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(ET.getAsOpaquePtr()); 2099ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddInteger(ArraySize.getZExtValue()); 2100ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddInteger(SizeMod); 2101ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddInteger(TypeQuals); 2102ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2103ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 2104ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == ConstantArray; 2105ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2106ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const ConstantArrayType *) { return true; } 2107ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2108ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2109ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// IncompleteArrayType - This class represents C arrays with an unspecified 2110ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// size. For example 'int A[]' has an IncompleteArrayType where the element 2111ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// type is 'int' and the size is unspecified. 2112ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass IncompleteArrayType : public ArrayType { 2113ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2114ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao IncompleteArrayType(QualType et, QualType can, 2115ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ArraySizeModifier sm, unsigned tq) 2116b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie : ArrayType(IncompleteArray, et, can, sm, tq, 2117d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor et->containsUnexpandedParameterPack()) {} 2118ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 2119ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2120ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 2121ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 2122ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2123ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 2124ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == IncompleteArray; 2125ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2126ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const IncompleteArrayType *) { return true; } 2127ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2128ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class StmtIteratorBase; 2129ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2130ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 2131ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Profile(ID, getElementType(), getSizeModifier(), 2132ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao getIndexTypeCVRQualifiers()); 2133ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2134ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2135ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 2136ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ArraySizeModifier SizeMod, unsigned TypeQuals) { 2137ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(ET.getAsOpaquePtr()); 2138ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddInteger(SizeMod); 2139ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddInteger(TypeQuals); 2140ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2141ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2142ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2143ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// VariableArrayType - This class represents C arrays with a specified size 2144ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 2145ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Since the size expression is an arbitrary expression, we store it as such. 2146ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 2147ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 2148ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// should not be: two lexically equivalent variable array types could mean 2149ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// different things, for example, these variables do not have the same type 2150ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// dynamically: 2151ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 2152ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// void foo(int x) { 2153ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// int Y[x]; 2154ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// ++x; 2155ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// int Z[x]; 2156ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// } 2157ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 2158ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass VariableArrayType : public ArrayType { 2159ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// SizeExpr - An assignment expression. VLA's are only permitted within 2160ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// a function block. 2161ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Stmt *SizeExpr; 2162ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// Brackets - The left and right array brackets. 2163ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao SourceRange Brackets; 2164ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2165ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao VariableArrayType(QualType et, QualType can, Expr *e, 2166ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ArraySizeModifier sm, unsigned tq, 2167ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao SourceRange brackets) 2168b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie : ArrayType(VariableArray, et, can, sm, tq, 2169d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor et->containsUnexpandedParameterPack()), 2170ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao SizeExpr((Stmt*) e), Brackets(brackets) {} 2171ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 2172ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2173ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2174ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Expr *getSizeExpr() const { 2175ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // We use C-style casts instead of cast<> here because we do not wish 2176ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // to have a dependency of Type.h on Stmt.h/Expr.h. 2177ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return (Expr*) SizeExpr; 2178ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2179ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao SourceRange getBracketsRange() const { return Brackets; } 2180ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 2181ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 2182ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2183ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 2184ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 2185ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2186ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 2187ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == VariableArray; 2188ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2189ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const VariableArrayType *) { return true; } 2190ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2191ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class StmtIteratorBase; 2192ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2193ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 2194b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Cannot unique VariableArrayTypes."); 2195ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2196ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2197ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2198ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// DependentSizedArrayType - This type represents an array type in 2199ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// C++ whose size is a value-dependent expression. For example: 2200ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 2201ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// \code 2202ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// template<typename T, int Size> 2203ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// class array { 2204ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// T data[Size]; 2205ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// }; 2206ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// \endcode 2207ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 2208ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// For these types, we won't actually know what the array bound is 2209ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// until template instantiation occurs, at which point this will 2210ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// become either a ConstantArrayType or a VariableArrayType. 2211ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass DependentSizedArrayType : public ArrayType { 22124ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 2213ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2214ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief An assignment expression that will instantiate to the 2215ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// size of the array. 2216ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// 2217ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// The expression itself might be NULL, in which case the array 2218ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// type will have its size deduced from an initializer. 2219ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Stmt *SizeExpr; 2220ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2221ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// Brackets - The left and right array brackets. 2222ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao SourceRange Brackets; 2223ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 22244ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can, 2225ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Expr *e, ArraySizeModifier sm, unsigned tq, 2226d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceRange brackets); 2227d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2228ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 2229ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2230ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2231ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Expr *getSizeExpr() const { 2232ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // We use C-style casts instead of cast<> here because we do not wish 2233ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // to have a dependency of Type.h on Stmt.h/Expr.h. 2234ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return (Expr*) SizeExpr; 2235ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2236ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao SourceRange getBracketsRange() const { return Brackets; } 2237ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 2238ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 2239ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2240ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 2241ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 2242ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2243ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 2244ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == DependentSizedArray; 2245ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2246ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const DependentSizedArrayType *) { return true; } 2247ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2248ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class StmtIteratorBase; 2249ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2250ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2251ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 2252ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Profile(ID, Context, getElementType(), 2253ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); 2254ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2255ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 22564ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 2257ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType ET, ArraySizeModifier SizeMod, 2258ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned TypeQuals, Expr *E); 2259ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2260ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2261ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// DependentSizedExtVectorType - This type represent an extended vector type 2262ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// where either the type or size is dependent. For example: 2263ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// @code 2264ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// template<typename T, int Size> 2265ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// class vector { 2266ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// typedef T __attribute__((ext_vector_type(Size))) type; 2267ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// } 2268ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// @endcode 2269ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { 22704ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 2271ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Expr *SizeExpr; 2272ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// ElementType - The element type of the array. 2273ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType ElementType; 2274ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao SourceLocation loc; 2275ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 22764ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType, 2277d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType can, Expr *SizeExpr, SourceLocation loc); 2278d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2279ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; 2280ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2281ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2282ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Expr *getSizeExpr() const { return SizeExpr; } 2283ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getElementType() const { return ElementType; } 2284ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao SourceLocation getAttributeLoc() const { return loc; } 2285ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2286ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 2287ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 2288ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2289ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 2290ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == DependentSizedExtVector; 2291ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2292ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const DependentSizedExtVectorType *) { return true; } 2293ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2294ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 2295ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Profile(ID, Context, getElementType(), getSizeExpr()); 2296ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2297ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 22984ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 2299ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType ElementType, Expr *SizeExpr); 2300ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2301ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2302ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2303ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// VectorType - GCC generic vector type. This type is created using 2304ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// __attribute__((vector_size(n)), where "n" specifies the vector size in 2305ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// bytes; or from an Altivec __vector or vector declaration. 2306ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Since the constructor takes the number of vector elements, the 2307ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// client is responsible for converting the size into the number of elements. 2308ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass VectorType : public Type, public llvm::FoldingSetNode { 23099484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattnerpublic: 2310b3e547db227afec80fd921b4dbff66bd91da992fBob Wilson enum VectorKind { 2311b3e547db227afec80fd921b4dbff66bd91da992fBob Wilson GenericVector, // not a target-specific vector type 2312b3e547db227afec80fd921b4dbff66bd91da992fBob Wilson AltiVecVector, // is AltiVec vector 2313b3e547db227afec80fd921b4dbff66bd91da992fBob Wilson AltiVecPixel, // is AltiVec 'vector Pixel' 2314b3e547db227afec80fd921b4dbff66bd91da992fBob Wilson AltiVecBool, // is AltiVec 'vector bool ...' 23151ab6481f698c0995cb294ac1a29d21bfb970c41cBob Wilson NeonVector, // is ARM Neon vector 23161ab6481f698c0995cb294ac1a29d21bfb970c41cBob Wilson NeonPolyVector // is ARM Neon polynomial vector 23179484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner }; 2318ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprotected: 2319ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// ElementType - The element type of the vector. 2320ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType ElementType; 2321ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2322ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao VectorType(QualType vecType, unsigned nElements, QualType canonType, 2323d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorKind vecKind); 2324b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 2325ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao VectorType(TypeClass tc, QualType vecType, unsigned nElements, 2326d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType canonType, VectorKind vecKind); 2327d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2328ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 2329b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 2330ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2331ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2332ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getElementType() const { return ElementType; } 2333084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned getNumElements() const { return VectorTypeBits.NumElements; } 2334ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2335ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 2336ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 2337ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2338b3e547db227afec80fd921b4dbff66bd91da992fBob Wilson VectorKind getVectorKind() const { 2339b3e547db227afec80fd921b4dbff66bd91da992fBob Wilson return VectorKind(VectorTypeBits.VecKind); 2340f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall } 23419484f8eade39f9d22deb26abdd6c1c804b820eacChris Lattner 2342ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 2343f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall Profile(ID, getElementType(), getNumElements(), 2344b3e547db227afec80fd921b4dbff66bd91da992fBob Wilson getTypeClass(), getVectorKind()); 2345ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2346ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 2347ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned NumElements, TypeClass TypeClass, 2348b3e547db227afec80fd921b4dbff66bd91da992fBob Wilson VectorKind VecKind) { 2349ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(ElementType.getAsOpaquePtr()); 2350ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddInteger(NumElements); 2351ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddInteger(TypeClass); 2352b3e547db227afec80fd921b4dbff66bd91da992fBob Wilson ID.AddInteger(VecKind); 2353ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2354ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2355ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 2356ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 2357ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2358ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const VectorType *) { return true; } 2359ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2360ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2361ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// ExtVectorType - Extended vector type. This type is created using 2362ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 2363ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 2364ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// class enables syntactic extensions, like Vector Components for accessing 2365ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// points, colors, and textures (modeled after OpenGL Shading Language). 2366ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass ExtVectorType : public VectorType { 2367ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 2368b3e547db227afec80fd921b4dbff66bd91da992fBob Wilson VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {} 2369ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 2370ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2371ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static int getPointAccessorIdx(char c) { 2372ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao switch (c) { 2373ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao default: return -1; 2374ec29bc0265b0a67e7e47947fd5e0707f46c15d4aVictor Hsieh case 'x': case 'r': return 0; 2375ec29bc0265b0a67e7e47947fd5e0707f46c15d4aVictor Hsieh case 'y': case 'g': return 1; 2376ec29bc0265b0a67e7e47947fd5e0707f46c15d4aVictor Hsieh case 'z': case 'b': return 2; 2377ec29bc0265b0a67e7e47947fd5e0707f46c15d4aVictor Hsieh case 'w': case 'a': return 3; 2378ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2379ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2380ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static int getNumericAccessorIdx(char c) { 2381ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao switch (c) { 2382ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao default: return -1; 2383ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case '0': return 0; 2384ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case '1': return 1; 2385ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case '2': return 2; 2386ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case '3': return 3; 2387ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case '4': return 4; 2388ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case '5': return 5; 2389ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case '6': return 6; 2390ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case '7': return 7; 2391ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case '8': return 8; 2392ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case '9': return 9; 2393ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case 'A': 2394ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case 'a': return 10; 2395ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case 'B': 2396ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case 'b': return 11; 2397ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case 'C': 2398ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case 'c': return 12; 2399ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case 'D': 2400ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case 'd': return 13; 2401ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case 'E': 2402ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case 'e': return 14; 2403ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case 'F': 2404ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao case 'f': return 15; 2405ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2406ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2407ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2408ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static int getAccessorIdx(char c) { 2409ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (int idx = getPointAccessorIdx(c)+1) return idx-1; 2410ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return getNumericAccessorIdx(c); 2411ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2412ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2413ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isAccessorWithinNumElements(char c) const { 2414ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (int idx = getAccessorIdx(c)+1) 2415f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall return unsigned(idx-1) < getNumElements(); 2416ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return false; 2417ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2418ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 2419ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 2420ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2421ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 2422ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == ExtVector; 2423ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2424ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const ExtVectorType *) { return true; } 2425ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2426ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2427ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 2428ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// class of FunctionNoProtoType and FunctionProtoType. 2429ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 2430ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass FunctionType : public Type { 2431ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // The type returned by the function. 2432ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType ResultType; 2433ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2434ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao public: 2435373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// ExtInfo - A class which abstracts out some details necessary for 2436373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// making a call. 2437373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// 2438373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// It is not actually used directly for storing this information in 2439373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// a FunctionType, although FunctionType does currently use the 2440373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// same bit-pattern. 2441373920bd733b1d28fe7bf209945a62eb9248d948John McCall /// 2442075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara // If you add a field (say Foo), other than the obvious places (both, 2443075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara // constructors, compile failures), what you need to update is 2444075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara // * Operator== 2445ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // * getFoo 2446ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // * withFoo 2447ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // * functionType. Add Foo, getFoo. 2448ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // * ASTContext::getFooType 2449ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // * ASTContext::mergeFunctionTypes 2450ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // * FunctionNoProtoType::Profile 2451ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // * FunctionProtoType::Profile 2452ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // * TypePrinter::PrintFunctionProto 2453461310d47dfb77ed4b176cfa19358bddeb732a35Sebastian Redl // * AST read and write 2454ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // * Codegen 2455ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao class ExtInfo { 24567e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor // Feel free to rearrange or add bits, but if you go over 8, 2457373920bd733b1d28fe7bf209945a62eb9248d948John McCall // you'll need to adjust both the Bits field below and 2458373920bd733b1d28fe7bf209945a62eb9248d948John McCall // Type::FunctionTypeBitfields. 2459373920bd733b1d28fe7bf209945a62eb9248d948John McCall 24607e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor // | CC |noreturn|produces|regparm| 24617e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor // |0 .. 2| 3 | 4 | 5 .. 7| 24627e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor // 24637e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor // regparm is either 0 (no regparm attribute) or the regparm value+1. 2464084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall enum { CallConvMask = 0x7 }; 2465084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall enum { NoReturnMask = 0x8 }; 2466f85e193739c953358c865005855253af4f68a497John McCall enum { ProducesResultMask = 0x10 }; 2467f85e193739c953358c865005855253af4f68a497John McCall enum { RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask), 24687e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor RegParmOffset = 5 }; // Assumed to be the last field 2469084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall 2470f85e193739c953358c865005855253af4f68a497John McCall uint16_t Bits; 2471f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall 2472f85e193739c953358c865005855253af4f68a497John McCall ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {} 2473f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall 2474f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall friend class FunctionType; 2475f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall 2476ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao public: 2477ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Constructor with no defaults. Use this when you know that you 2478461310d47dfb77ed4b176cfa19358bddeb732a35Sebastian Redl // have all the elements (when reading an AST file for example). 2479f85e193739c953358c865005855253af4f68a497John McCall ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc, 2480f85e193739c953358c865005855253af4f68a497John McCall bool producesResult) { 24817e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor assert((!hasRegParm || regParm < 7) && "Invalid regparm value"); 2482084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall Bits = ((unsigned) cc) | 2483084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall (noReturn ? NoReturnMask : 0) | 2484f85e193739c953358c865005855253af4f68a497John McCall (producesResult ? ProducesResultMask : 0) | 24857e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0); 2486f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall } 2487ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2488ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Constructor with all defaults. Use when for example creating a 2489ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // function know to use defaults. 2490f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall ExtInfo() : Bits(0) {} 2491ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2492084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall bool getNoReturn() const { return Bits & NoReturnMask; } 2493f85e193739c953358c865005855253af4f68a497John McCall bool getProducesResult() const { return Bits & ProducesResultMask; } 24947e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor bool getHasRegParm() const { return (Bits >> RegParmOffset) != 0; } 2495b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie unsigned getRegParm() const { 24967e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor unsigned RegParm = Bits >> RegParmOffset; 24977e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor if (RegParm > 0) 24987e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor --RegParm; 24997e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor return RegParm; 25007e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor } 2501084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall CallingConv getCC() const { return CallingConv(Bits & CallConvMask); } 2502ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2503f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall bool operator==(ExtInfo Other) const { 2504f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall return Bits == Other.Bits; 2505ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2506f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall bool operator!=(ExtInfo Other) const { 2507f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall return Bits != Other.Bits; 2508ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2509ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2510ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Note that we don't have setters. That is by design, use 2511ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // the following with methods instead of mutating these objects. 2512ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2513ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ExtInfo withNoReturn(bool noReturn) const { 2514f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall if (noReturn) 2515f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall return ExtInfo(Bits | NoReturnMask); 2516f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall else 2517f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall return ExtInfo(Bits & ~NoReturnMask); 2518ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2519ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2520f85e193739c953358c865005855253af4f68a497John McCall ExtInfo withProducesResult(bool producesResult) const { 2521f85e193739c953358c865005855253af4f68a497John McCall if (producesResult) 2522f85e193739c953358c865005855253af4f68a497John McCall return ExtInfo(Bits | ProducesResultMask); 2523f85e193739c953358c865005855253af4f68a497John McCall else 2524f85e193739c953358c865005855253af4f68a497John McCall return ExtInfo(Bits & ~ProducesResultMask); 2525f85e193739c953358c865005855253af4f68a497John McCall } 2526f85e193739c953358c865005855253af4f68a497John McCall 2527ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ExtInfo withRegParm(unsigned RegParm) const { 25287e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor assert(RegParm < 7 && "Invalid regparm value"); 2529f85e193739c953358c865005855253af4f68a497John McCall return ExtInfo((Bits & ~RegParmMask) | 25307e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor ((RegParm + 1) << RegParmOffset)); 2531ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2532ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2533ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ExtInfo withCallingConv(CallingConv cc) const { 2534084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc); 2535ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2536ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2537e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall void Profile(llvm::FoldingSetNodeID &ID) const { 2538f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall ID.AddInteger(Bits); 2539f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall } 2540ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao }; 2541ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2542ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprotected: 2543e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionType(TypeClass tc, QualType res, bool variadic, 2544c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor unsigned typeQuals, RefQualifierKind RefQualifier, 2545c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor QualType Canonical, bool Dependent, 2546561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent, 2547b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie bool VariablyModified, bool ContainsUnexpandedParameterPack, 2548d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ExtInfo Info) 2549b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified, 2550b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie ContainsUnexpandedParameterPack), 2551d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ResultType(res) { 2552084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall FunctionTypeBits.ExtInfo = Info.Bits; 2553e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionTypeBits.Variadic = variadic; 2554084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall FunctionTypeBits.TypeQuals = typeQuals; 2555c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor FunctionTypeBits.RefQualifier = static_cast<unsigned>(RefQualifier); 2556f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall } 2557e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall bool isVariadic() const { return FunctionTypeBits.Variadic; } 2558084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; } 2559b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 2560c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind getRefQualifier() const { 2561c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier); 2562c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor } 2563c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 2564ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2565ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2566ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getResultType() const { return ResultType; } 2567a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman 2568a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman bool getHasRegParm() const { return getExtInfo().getHasRegParm(); } 2569084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned getRegParmType() const { return getExtInfo().getRegParm(); } 2570084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); } 2571084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall CallingConv getCallConv() const { return getExtInfo().getCC(); } 2572084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); } 2573ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 25748079eee9128444d02bebf24410126f9d55399f84Douglas Gregor /// \brief Determine the type of an expression that calls a function of 25758079eee9128444d02bebf24410126f9d55399f84Douglas Gregor /// this type. 2576b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie QualType getCallResultType(ASTContext &Context) const { 25772350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor return getResultType().getNonLValueExprType(Context); 25788079eee9128444d02bebf24410126f9d55399f84Douglas Gregor } 25798079eee9128444d02bebf24410126f9d55399f84Douglas Gregor 2580686775deca8b8685eb90801495880e3abdd844c2Chris Lattner static StringRef getNameForCallConv(CallingConv CC); 2581ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2582ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 2583ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == FunctionNoProto || 2584ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao T->getTypeClass() == FunctionProto; 2585ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2586ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const FunctionType *) { return true; } 2587ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2588ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2589ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 2590ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// no information available about its arguments. 2591ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 2592f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info) 2593c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor : FunctionType(FunctionNoProto, Result, false, 0, RQ_None, Canonical, 2594561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*Dependent=*/false, /*InstantiationDependent=*/false, 2595b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie Result->isVariablyModifiedType(), 2596d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false, Info) {} 2597d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2598ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 2599b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 2600ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2601ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // No additional state past what FunctionType provides. 2602ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2603ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 2604ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 2605ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2606ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 2607ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Profile(ID, getResultType(), getExtInfo()); 2608ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2609ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 2610f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall ExtInfo Info) { 2611f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall Info.Profile(ID); 2612ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(ResultType.getAsOpaquePtr()); 2613ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2614ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2615ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 2616ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == FunctionNoProto; 2617ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2618ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const FunctionNoProtoType *) { return true; } 2619ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2620ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2621ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// FunctionProtoType - Represents a prototype with argument type info, e.g. 2622ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 2623ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// arguments, not as having a single void argument. Such a type can have an 2624ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// exception specification, but this specification is not part of the canonical 2625ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// type. 2626ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 2627e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallpublic: 2628e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall /// ExtProtoInfo - Extra information about a function prototype. 2629e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall struct ExtProtoInfo { 2630e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ExtProtoInfo() : 26318b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl Variadic(false), ExceptionSpecType(EST_None), TypeQuals(0), 2632f85e193739c953358c865005855253af4f68a497John McCall RefQualifier(RQ_None), NumExceptions(0), Exceptions(0), NoexceptExpr(0), 2633f85e193739c953358c865005855253af4f68a497John McCall ConsumedArguments(0) {} 2634e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 2635e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionType::ExtInfo ExtInfo; 2636e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall bool Variadic; 26378b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl ExceptionSpecificationType ExceptionSpecType; 2638e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned char TypeQuals; 2639c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier; 2640e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned NumExceptions; 2641e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall const QualType *Exceptions; 26428b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl Expr *NoexceptExpr; 2643f85e193739c953358c865005855253af4f68a497John McCall const bool *ConsumedArguments; 2644e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall }; 2645e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 2646e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallprivate: 2647d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Determine whether there are any argument types that 2648d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// contain an unexpanded parameter pack. 2649b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray, 2650d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned numArgs) { 2651d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 2652d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor if (ArgArray[Idx]->containsUnexpandedParameterPack()) 2653d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return true; 2654d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2655d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return false; 2656d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 2657d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 2658e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType(QualType result, const QualType *args, unsigned numArgs, 2659e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall QualType canonical, const ExtProtoInfo &epi); 2660ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2661ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// NumArgs - The number of arguments this function has, not counting '...'. 2662f85e193739c953358c865005855253af4f68a497John McCall unsigned NumArgs : 19; 2663ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2664ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// NumExceptions - The number of types in the exception spec, if any. 266560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl unsigned NumExceptions : 9; 2666ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 266760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// ExceptionSpecType - The type of exception specification this function has. 266860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl unsigned ExceptionSpecType : 3; 2669ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2670f85e193739c953358c865005855253af4f68a497John McCall /// HasAnyConsumedArgs - Whether this function has any consumed arguments. 2671f85e193739c953358c865005855253af4f68a497John McCall unsigned HasAnyConsumedArgs : 1; 2672f85e193739c953358c865005855253af4f68a497John McCall 26736a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // ArgInfo - There is an variable size array after the class in memory that 26746a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // holds the argument types. 2675ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 26766a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // Exceptions - There is another variable size array after ArgInfo that 26776a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // holds the exception types. 2678ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 26796a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // NoexceptExpr - Instead of Exceptions, there may be a single Expr* pointing 26806a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // to the expression in the noexcept() specifier. 268160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 26826a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // ConsumedArgs - A variable size array, following Exceptions 26836a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // and of length NumArgs, holding flags indicating which arguments 26846a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek // are consumed. This only appears if HasAnyConsumedArgs is true. 2685f85e193739c953358c865005855253af4f68a497John McCall 2686ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 2687ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2688f85e193739c953358c865005855253af4f68a497John McCall const bool *getConsumedArgsBuffer() const { 2689f85e193739c953358c865005855253af4f68a497John McCall assert(hasAnyConsumedArgs()); 2690f85e193739c953358c865005855253af4f68a497John McCall 2691f85e193739c953358c865005855253af4f68a497John McCall // Find the end of the exceptions. 2692f85e193739c953358c865005855253af4f68a497John McCall Expr * const *eh_end = reinterpret_cast<Expr * const *>(arg_type_end()); 2693f85e193739c953358c865005855253af4f68a497John McCall if (getExceptionSpecType() != EST_ComputedNoexcept) 2694f85e193739c953358c865005855253af4f68a497John McCall eh_end += NumExceptions; 2695f85e193739c953358c865005855253af4f68a497John McCall else 2696f85e193739c953358c865005855253af4f68a497John McCall eh_end += 1; // NoexceptExpr 2697f85e193739c953358c865005855253af4f68a497John McCall 2698f85e193739c953358c865005855253af4f68a497John McCall return reinterpret_cast<const bool*>(eh_end); 2699f85e193739c953358c865005855253af4f68a497John McCall } 2700f85e193739c953358c865005855253af4f68a497John McCall 2701ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2702ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned getNumArgs() const { return NumArgs; } 2703ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getArgType(unsigned i) const { 2704ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(i < NumArgs && "Invalid argument number!"); 2705ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return arg_type_begin()[i]; 2706ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2707ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2708e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ExtProtoInfo getExtProtoInfo() const { 2709e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ExtProtoInfo EPI; 2710e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.ExtInfo = getExtInfo(); 2711e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.Variadic = isVariadic(); 271260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.ExceptionSpecType = getExceptionSpecType(); 2713e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals()); 2714c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor EPI.RefQualifier = getRefQualifier(); 271560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (EPI.ExceptionSpecType == EST_Dynamic) { 271660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.NumExceptions = NumExceptions; 271760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.Exceptions = exception_begin(); 271860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) { 271960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl EPI.NoexceptExpr = getNoexceptExpr(); 272060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 2721f85e193739c953358c865005855253af4f68a497John McCall if (hasAnyConsumedArgs()) 2722f85e193739c953358c865005855253af4f68a497John McCall EPI.ConsumedArguments = getConsumedArgsBuffer(); 2723e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall return EPI; 2724e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall } 2725e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 272660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Get the kind of exception specification on this function. 272760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecificationType getExceptionSpecType() const { 272860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return static_cast<ExceptionSpecificationType>(ExceptionSpecType); 272960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 273060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Return whether this function has any kind of exception spec. 273160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool hasExceptionSpec() const { 273260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return getExceptionSpecType() != EST_None; 273360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 273460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Return whether this function has a dynamic (throw) exception spec. 273560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool hasDynamicExceptionSpec() const { 273660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return isDynamicExceptionSpec(getExceptionSpecType()); 273760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 2738fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// \brief Return whether this function has a noexcept exception spec. 273960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool hasNoexceptExceptionSpec() const { 274060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return isNoexceptExceptionSpec(getExceptionSpecType()); 274160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 274260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Result type of getNoexceptSpec(). 274360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl enum NoexceptResult { 274460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_NoNoexcept, ///< There is no noexcept specifier. 274560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_BadNoexcept, ///< The noexcept specifier has a bad expression. 274660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_Dependent, ///< The noexcept specifier is dependent. 274760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_Throw, ///< The noexcept specifier evaluates to false. 274860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NR_Nothrow ///< The noexcept specifier evaluates to true. 274960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl }; 275060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /// \brief Get the meaning of the noexcept spec on this function, if any. 27518026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl NoexceptResult getNoexceptSpec(ASTContext &Ctx) const; 2752ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned getNumExceptions() const { return NumExceptions; } 2753ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getExceptionType(unsigned i) const { 2754ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(i < NumExceptions && "Invalid exception number!"); 2755ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return exception_begin()[i]; 2756ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 275760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Expr *getNoexceptExpr() const { 275860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (getExceptionSpecType() != EST_ComputedNoexcept) 275960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return 0; 276060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // NoexceptExpr sits where the arguments end. 276160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return *reinterpret_cast<Expr *const *>(arg_type_end()); 2762d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson } 27638026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl bool isNothrow(ASTContext &Ctx) const { 276460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecificationType EST = getExceptionSpecType(); 27657a614d8380297fcd2bc23986241905d97222948cRichard Smith assert(EST != EST_Delayed); 276660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (EST == EST_DynamicNone || EST == EST_BasicNoexcept) 276760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return true; 276860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (EST != EST_ComputedNoexcept) 276960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return false; 27708026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl return getNoexceptSpec(Ctx) == NR_Nothrow; 2771ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2772ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2773e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall using FunctionType::isVariadic; 277460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 2775f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// \brief Determines whether this function prototype contains a 2776f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// parameter pack at the end. 2777f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// 2778f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// A function template whose last parameter is a parameter pack can be 2779f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor /// called with an arbitrary number of arguments, much like a variadic 2780b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// function. However, 2781f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor bool isTemplateVariadic() const; 2782b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 2783ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 2784ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2785b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 2786c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor /// \brief Retrieve the ref-qualifier associated with this function type. 2787c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind getRefQualifier() const { 2788c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor return FunctionType::getRefQualifier(); 2789c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor } 2790b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 2791ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao typedef const QualType *arg_type_iterator; 2792ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao arg_type_iterator arg_type_begin() const { 2793ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return reinterpret_cast<const QualType *>(this+1); 2794ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2795ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 2796ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2797ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao typedef const QualType *exception_iterator; 2798ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao exception_iterator exception_begin() const { 2799ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // exceptions begin where arguments end 2800ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return arg_type_end(); 2801ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2802ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao exception_iterator exception_end() const { 280360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (getExceptionSpecType() != EST_Dynamic) 280460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return exception_begin(); 2805ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return exception_begin() + NumExceptions; 2806ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2807ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2808f85e193739c953358c865005855253af4f68a497John McCall bool hasAnyConsumedArgs() const { 2809f85e193739c953358c865005855253af4f68a497John McCall return HasAnyConsumedArgs; 2810f85e193739c953358c865005855253af4f68a497John McCall } 2811f85e193739c953358c865005855253af4f68a497John McCall bool isArgConsumed(unsigned I) const { 2812f85e193739c953358c865005855253af4f68a497John McCall assert(I < getNumArgs() && "argument index out of range!"); 2813f85e193739c953358c865005855253af4f68a497John McCall if (hasAnyConsumedArgs()) 2814f85e193739c953358c865005855253af4f68a497John McCall return getConsumedArgsBuffer()[I]; 2815f85e193739c953358c865005855253af4f68a497John McCall return false; 2816f85e193739c953358c865005855253af4f68a497John McCall } 2817f85e193739c953358c865005855253af4f68a497John McCall 2818ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 2819ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 2820ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2821ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 2822ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == FunctionProto; 2823ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2824ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const FunctionProtoType *) { return true; } 2825ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 28268026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx); 2827ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 2828ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao arg_type_iterator ArgTys, unsigned NumArgs, 28298026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ExtProtoInfo &EPI, const ASTContext &Context); 2830ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2831ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2832ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2833ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// \brief Represents the dependent type named by a dependently-scoped 2834ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// typename using declaration, e.g. 2835ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// using typename Base<T>::foo; 2836ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Template instantiation turns these into the underlying type. 2837ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass UnresolvedUsingType : public Type { 2838ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao UnresolvedUsingTypenameDecl *Decl; 2839ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2840ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) 2841b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie : Type(UnresolvedUsing, QualType(), true, true, false, 2842d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 2843ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {} 2844ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 2845ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2846ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2847ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao UnresolvedUsingTypenameDecl *getDecl() const { return Decl; } 2848ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2849ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 2850ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 2851ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2852ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 2853ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == UnresolvedUsing; 2854ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2855ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const UnresolvedUsingType *) { return true; } 2856ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2857ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 2858ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return Profile(ID, Decl); 2859ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2860ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, 2861ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao UnresolvedUsingTypenameDecl *D) { 2862ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(D); 2863ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2864ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2865ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2866ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2867ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass TypedefType : public Type { 2868162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *Decl; 2869ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprotected: 2870162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can) 2871b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie : Type(tc, can, can->isDependentType(), 2872561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor can->isInstantiationDependentType(), 2873b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie can->isVariablyModifiedType(), 2874d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 2875162e1c1b487352434552147967c3dd296ebee2f7Richard Smith Decl(const_cast<TypedefNameDecl*>(D)) { 2876ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(!isa<TypedefType>(can) && "Invalid canonical type"); 2877ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2878ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 2879ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2880ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2881162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *getDecl() const { return Decl; } 2882ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2883ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return true; } 2884ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const; 2885ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2886ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 2887ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const TypedefType *) { return true; } 2888ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2889ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2890ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// TypeOfExprType (GCC extension). 2891ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass TypeOfExprType : public Type { 2892ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Expr *TOExpr; 2893ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2894ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprotected: 2895ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao TypeOfExprType(Expr *E, QualType can = QualType()); 2896ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 2897ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2898ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Expr *getUnderlyingExpr() const { return TOExpr; } 2899ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2900ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Remove a single level of sugar. 2901ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const; 2902ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2903ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Returns whether this type directly provides sugar. 29046af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor bool isSugared() const; 2905ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2906ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 2907ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const TypeOfExprType *) { return true; } 2908ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2909ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2910ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// \brief Internal representation of canonical, dependent 2911ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// typeof(expr) types. 2912ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 2913ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// This class is used internally by the ASTContext to manage 2914ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// canonical, dependent types, only. Clients will only see instances 2915ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// of this class via TypeOfExprType nodes. 2916ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass DependentTypeOfExprType 2917ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao : public TypeOfExprType, public llvm::FoldingSetNode { 29184ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 2919ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2920ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 29214ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentTypeOfExprType(const ASTContext &Context, Expr *E) 2922ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao : TypeOfExprType(E), Context(Context) { } 2923ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2924ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 2925ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Profile(ID, Context, getUnderlyingExpr()); 2926ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2927ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 29284ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 2929ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Expr *E); 2930ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2931ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2932ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// TypeOfType (GCC extension). 2933ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass TypeOfType : public Type { 2934ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType TOType; 2935ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao TypeOfType(QualType T, QualType can) 2936b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie : Type(TypeOf, can, T->isDependentType(), 2937561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isInstantiationDependentType(), 2938b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie T->isVariablyModifiedType(), 2939b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie T->containsUnexpandedParameterPack()), 2940e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor TOType(T) { 2941ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(!isa<TypedefType>(can) && "Invalid canonical type"); 2942ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2943ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 2944ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2945ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getUnderlyingType() const { return TOType; } 2946ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2947ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Remove a single level of sugar. 2948ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return getUnderlyingType(); } 2949ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2950ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Returns whether this type directly provides sugar. 2951ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return true; } 2952ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2953ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 2954ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const TypeOfType *) { return true; } 2955ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2956ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2957ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// DecltypeType (C++0x) 2958ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass DecltypeType : public Type { 2959ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Expr *E; 2960ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2961ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 2962ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 2963ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // from it. 2964ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType UnderlyingType; 2965ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2966ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprotected: 2967ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 2968ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 2969ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 2970ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Expr *getUnderlyingExpr() const { return E; } 2971ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getUnderlyingType() const { return UnderlyingType; } 2972ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2973ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Remove a single level of sugar. 29746af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor QualType desugar() const; 2975ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2976ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Returns whether this type directly provides sugar. 29776af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor bool isSugared() const; 2978ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2979ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 2980ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const DecltypeType *) { return true; } 2981ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 2982ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2983ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// \brief Internal representation of canonical, dependent 2984ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// decltype(expr) types. 2985ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 2986ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// This class is used internally by the ASTContext to manage 2987ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// canonical, dependent types, only. Clients will only see instances 2988ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// of this class via DecltypeType nodes. 2989ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { 29904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context; 2991ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2992ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 29934ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DependentDecltypeType(const ASTContext &Context, Expr *E); 2994ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 2995ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 2996ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Profile(ID, Context, getUnderlyingExpr()); 2997ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 2998ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 29994ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 3000ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Expr *E); 3001ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 3002ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3003ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt/// \brief A unary type transform, which is a type constructed from another 3004ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntclass UnaryTransformType : public Type { 3005ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntpublic: 3006ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt enum UTTKind { 3007ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt EnumUnderlyingType 3008ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt }; 3009ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 3010ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntprivate: 3011ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt /// The untransformed type. 3012ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType BaseType; 3013ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt /// The transformed type if not dependent, otherwise the same as BaseType. 3014ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType UnderlyingType; 3015ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 3016ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UTTKind UKind; 3017ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntprotected: 3018ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind, 3019ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType CanonicalTy); 3020ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt friend class ASTContext; 3021ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntpublic: 3022ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt bool isSugared() const { return !isDependentType(); } 3023ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType desugar() const { return UnderlyingType; } 3024ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 3025ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType getUnderlyingType() const { return UnderlyingType; } 3026ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType getBaseType() const { return BaseType; } 3027ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 3028ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UTTKind getUTTKind() const { return UKind; } 3029b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 3030ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt static bool classof(const Type *T) { 3031ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return T->getTypeClass() == UnaryTransform; 3032ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 3033ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt static bool classof(const UnaryTransformType *) { return true; } 3034ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}; 3035ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 3036ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass TagType : public Type { 3037295dcb357afc5f6215405709cba1498f14bd673dSebastian Redl /// Stores the TagDecl associated with this type. The decl may point to any 3038295dcb357afc5f6215405709cba1498f14bd673dSebastian Redl /// TagDecl that declares the entity. 3039295dcb357afc5f6215405709cba1498f14bd673dSebastian Redl TagDecl * decl; 3040ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3041ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprotected: 3042ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao TagType(TypeClass TC, const TagDecl *D, QualType can); 3043ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3044ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 3045295dcb357afc5f6215405709cba1498f14bd673dSebastian Redl TagDecl *getDecl() const; 3046ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3047ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// @brief Determines whether this type is in the process of being 3048ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// defined. 3049295dcb357afc5f6215405709cba1498f14bd673dSebastian Redl bool isBeingDefined() const; 3050ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3051ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 3052ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 3053ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3054ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const TagType *) { return true; } 3055ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const RecordType *) { return true; } 3056ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const EnumType *) { return true; } 3057ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 3058ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3059ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 3060ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// to detect TagType objects of structs/unions/classes. 3061ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass RecordType : public TagType { 3062ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprotected: 3063ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao explicit RecordType(const RecordDecl *D) 3064ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { } 3065ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao explicit RecordType(TypeClass TC, RecordDecl *D) 3066ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { } 3067ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 3068ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 3069ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3070ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao RecordDecl *getDecl() const { 3071ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 3072ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3073ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3074ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // FIXME: This predicate is a helper to QualType/Type. It needs to 3075ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // recursively check all fields for const-ness. If any field is declared 3076ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // const, it needs to return false. 3077ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool hasConstFields() const { return false; } 3078ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3079ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 3080ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 3081ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3082ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const TagType *T); 3083ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 3084ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<TagType>(T) && classof(cast<TagType>(T)); 3085ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3086ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const RecordType *) { return true; } 3087ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 3088ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3089ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 3090ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// to detect TagType objects of enums. 3091ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass EnumType : public TagType { 3092ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao explicit EnumType(const EnumDecl *D) 3093ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { } 3094ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 3095ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 3096ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3097ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao EnumDecl *getDecl() const { 3098ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 3099ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3100ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3101ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 3102ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 3103ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3104ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const TagType *T); 3105ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 3106ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<TagType>(T) && classof(cast<TagType>(T)); 3107ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3108ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const EnumType *) { return true; } 3109ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 3110ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 31119d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// AttributedType - An attributed type is a type to which a type 31129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// attribute has been applied. The "modified type" is the 31139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// fully-sugared type to which the attributed type was applied; 31149d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// generally it is not canonically equivalent to the attributed type. 31159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// The "equivalent type" is the minimally-desugared type which the 31169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// type is canonically equivalent to. 31179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// 31189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// For example, in the following attributed type: 31199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// int32_t __attribute__((vector_size(16))) 31209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// - the modified type is the TypedefType for int32_t 31219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// - the equivalent type is VectorType(16, int32_t) 31229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// - the canonical type is VectorType(16, int) 31239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallclass AttributedType : public Type, public llvm::FoldingSetNode { 31249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic: 31259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // It is really silly to have yet another attribute-kind enum, but 31269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // clang::attr::Kind doesn't currently cover the pure type attrs. 31279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall enum Kind { 31289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // Expression operand. 3129170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_address_space, 3130170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_regparm, 3131170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_vector_size, 3132170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_neon_vector_type, 3133170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_neon_polyvector_type, 31349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 3135170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet FirstExprOperandKind = attr_address_space, 3136170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet LastExprOperandKind = attr_neon_polyvector_type, 31379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 31389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // Enumerated operand (string or keyword). 3139170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet attr_objc_gc, 3140b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis attr_objc_ownership, 3141414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov attr_pcs, 31429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 3143170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet FirstEnumOperandKind = attr_objc_gc, 3144414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov LastEnumOperandKind = attr_pcs, 31459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 31469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // No operand. 31473cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_noreturn, 31483cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_cdecl, 31493cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_fastcall, 31503cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_stdcall, 31513cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_thiscall, 31523cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet attr_pascal 31539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall }; 31549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 31559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallprivate: 31569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType ModifiedType; 31579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType EquivalentType; 31589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 31599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall friend class ASTContext; // creates these 31609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 31619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType(QualType canon, Kind attrKind, 31629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modified, QualType equivalent) 31639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall : Type(Attributed, canon, canon->isDependentType(), 3164561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor canon->isInstantiationDependentType(), 31659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall canon->isVariablyModifiedType(), 31669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall canon->containsUnexpandedParameterPack()), 31679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ModifiedType(modified), EquivalentType(equivalent) { 31689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeBits.AttrKind = attrKind; 31699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 31709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 31719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic: 31729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Kind getAttrKind() const { 31739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return static_cast<Kind>(AttributedTypeBits.AttrKind); 31749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 31759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 31769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType getModifiedType() const { return ModifiedType; } 31779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType getEquivalentType() const { return EquivalentType; } 31789d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 31799d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall bool isSugared() const { return true; } 31809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType desugar() const { return getEquivalentType(); } 31819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 31829d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall void Profile(llvm::FoldingSetNodeID &ID) { 31839d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Profile(ID, getAttrKind(), ModifiedType, EquivalentType); 31849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 31859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 31869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind, 31879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modified, QualType equivalent) { 31889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ID.AddInteger(attrKind); 31899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ID.AddPointer(modified.getAsOpaquePtr()); 31909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall ID.AddPointer(equivalent.getAsOpaquePtr()); 31919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 31929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 31939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall static bool classof(const Type *T) { 31949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return T->getTypeClass() == Attributed; 31959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 31969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall static bool classof(const AttributedType *T) { return true; } 31979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}; 31989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 3199ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 32004fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth // Helper data collector for canonical types. 32014fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth struct CanonicalTTPTInfo { 32024fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned Depth : 15; 32034fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned ParameterPack : 1; 32044fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned Index : 16; 32054fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth }; 3206ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 32074fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth union { 32084fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth // Info for the canonical type. 32094fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth CanonicalTTPTInfo CanTTPTInfo; 32104fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth // Info for the non-canonical type. 32114fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmDecl *TTPDecl; 32124fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth }; 321372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 32144fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth /// Build a non-canonical type. 32154fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon) 3216e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true, 3217561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 32184fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth /*VariablyModified=*/false, 32195d65e34b08b3e57a4da834195757d0d15baaffd0Chandler Carruth Canon->containsUnexpandedParameterPack()), 32204fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TTPDecl(TTPDecl) { } 3221ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 32224fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth /// Build the canonical type. 3223ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao TemplateTypeParmType(unsigned D, unsigned I, bool PP) 3224b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie : Type(TemplateTypeParm, QualType(this, 0), 3225561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*Dependent=*/true, 3226561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 32274fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth /*VariablyModified=*/false, PP) { 32284fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth CanTTPTInfo.Depth = D; 32294fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth CanTTPTInfo.Index = I; 32304fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth CanTTPTInfo.ParameterPack = PP; 32314fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth } 3232ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3233ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these 3234ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 32354fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth const CanonicalTTPTInfo& getCanTTPTInfo() const { 32364fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth QualType Can = getCanonicalTypeInternal(); 32375d65e34b08b3e57a4da834195757d0d15baaffd0Chandler Carruth return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo; 32384fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth } 32394fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 3240ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 32414fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned getDepth() const { return getCanTTPTInfo().Depth; } 32424fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth unsigned getIndex() const { return getCanTTPTInfo().Index; } 32434fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; } 32444fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 32454fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmDecl *getDecl() const { 32464fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth return isCanonicalUnqualified() ? 0 : TTPDecl; 32474fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth } 32484fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 3249b7efff4bae117604f442bb6859c844f90b15f3ffChandler Carruth IdentifierInfo *getIdentifier() const; 3250ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3251ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 3252ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 3253ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3254ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 32554fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl()); 3256ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3257ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3258ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 3259ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned Index, bool ParameterPack, 32604fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmDecl *TTPDecl) { 3261ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddInteger(Depth); 3262ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddInteger(Index); 3263ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddBoolean(ParameterPack); 32644fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth ID.AddPointer(TTPDecl); 3265ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3266ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3267ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 3268ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == TemplateTypeParm; 3269ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3270ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const TemplateTypeParmType *T) { return true; } 3271ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 3272ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3273ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// \brief Represents the result of substituting a type for a template 3274ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// type parameter. 3275ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 3276ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Within an instantiated template, all template type parameters have 3277ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// been replaced with these. They are used solely to record that a 3278ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// type was originally written as a template type parameter; 3279ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// therefore they are never canonical. 3280ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode { 3281ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // The original type parameter. 3282ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const TemplateTypeParmType *Replaced; 3283ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3284ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) 3285e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(), 3286561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Canon->isInstantiationDependentType(), 3287d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Canon->isVariablyModifiedType(), 3288d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Canon->containsUnexpandedParameterPack()), 3289ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Replaced(Param) { } 3290ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3291ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; 3292ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3293ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 3294ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// Gets the template parameter that was substituted for. 3295ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const TemplateTypeParmType *getReplacedParameter() const { 3296ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return Replaced; 3297ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3298ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3299ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// Gets the type that was substituted for the template 3300ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// parameter. 3301ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getReplacementType() const { 3302ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return getCanonicalTypeInternal(); 3303ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3304ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3305ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return true; } 3306ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return getReplacementType(); } 3307ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3308ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 3309ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Profile(ID, getReplacedParameter(), getReplacementType()); 3310ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3311ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, 3312ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const TemplateTypeParmType *Replaced, 3313ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType Replacement) { 3314ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(Replaced); 3315ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(Replacement.getAsOpaquePtr()); 3316ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3317ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3318ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 3319ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == SubstTemplateTypeParm; 3320ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3321ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const SubstTemplateTypeParmType *T) { return true; } 3322ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 3323ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3324c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// \brief Represents the result of substituting a set of types for a template 3325c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// type parameter pack. 3326c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// 3327c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs 3328c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// and those parameter packs correspond to different levels of template 3329b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie/// parameter lists, this type node is used to represent a template type 3330c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack 3331c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// substituted but that still lives within a pack expansion that itself 3332c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// could not be instantiated. When actually performing a substitution into 3333c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding 3334c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType 3335c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// at the current pack substitution index. 3336c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorclass SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode { 3337c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// \brief The original type parameter. 3338c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Replaced; 3339b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 3340c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// \brief A pointer to the set of template arguments that this 3341c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// parameter pack is instantiated with. 3342c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument *Arguments; 3343b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 3344c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// \brief The number of template arguments in \c Arguments. 3345c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor unsigned NumArguments; 3346b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 3347b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param, 3348c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType Canon, 3349c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack); 3350b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 3351c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor friend class ASTContext; 3352b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 3353c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorpublic: 3354b7efff4bae117604f442bb6859c844f90b15f3ffChandler Carruth IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); } 3355b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 3356c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// Gets the template parameter that was substituted for. 3357c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *getReplacedParameter() const { 3358c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return Replaced; 3359c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor } 3360b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 3361c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor bool isSugared() const { return false; } 3362c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType desugar() const { return QualType(this, 0); } 3363b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 3364c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor TemplateArgument getArgumentPack() const; 3365b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 3366c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID); 3367c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, 3368c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Replaced, 3369c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack); 3370b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 3371c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor static bool classof(const Type *T) { 3372c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return T->getTypeClass() == SubstTemplateTypeParmPack; 3373c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor } 3374c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor static bool classof(const SubstTemplateTypeParmPackType *T) { return true; } 3375c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor}; 3376c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 337734b41d939a1328f484511c6002ba2456db879a29Richard Smith/// \brief Represents a C++0x auto type. 337834b41d939a1328f484511c6002ba2456db879a29Richard Smith/// 337934b41d939a1328f484511c6002ba2456db879a29Richard Smith/// These types are usually a placeholder for a deduced type. However, within 338034b41d939a1328f484511c6002ba2456db879a29Richard Smith/// templates and before the initializer is attached, there is no deduced type 338134b41d939a1328f484511c6002ba2456db879a29Richard Smith/// and an auto type is type-dependent and canonical. 338234b41d939a1328f484511c6002ba2456db879a29Richard Smithclass AutoType : public Type, public llvm::FoldingSetNode { 338334b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType(QualType DeducedType) 338434b41d939a1328f484511c6002ba2456db879a29Richard Smith : Type(Auto, DeducedType.isNull() ? QualType(this, 0) : DeducedType, 338534b41d939a1328f484511c6002ba2456db879a29Richard Smith /*Dependent=*/DeducedType.isNull(), 3386561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/DeducedType.isNull(), 338734b41d939a1328f484511c6002ba2456db879a29Richard Smith /*VariablyModified=*/false, /*ContainsParameterPack=*/false) { 338834b41d939a1328f484511c6002ba2456db879a29Richard Smith assert((DeducedType.isNull() || !DeducedType->isDependentType()) && 338934b41d939a1328f484511c6002ba2456db879a29Richard Smith "deduced a dependent type for auto"); 339034b41d939a1328f484511c6002ba2456db879a29Richard Smith } 339134b41d939a1328f484511c6002ba2456db879a29Richard Smith 339234b41d939a1328f484511c6002ba2456db879a29Richard Smith friend class ASTContext; // ASTContext creates these 339334b41d939a1328f484511c6002ba2456db879a29Richard Smith 339434b41d939a1328f484511c6002ba2456db879a29Richard Smithpublic: 339534b41d939a1328f484511c6002ba2456db879a29Richard Smith bool isSugared() const { return isDeduced(); } 339634b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType desugar() const { return getCanonicalTypeInternal(); } 339734b41d939a1328f484511c6002ba2456db879a29Richard Smith 339834b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType getDeducedType() const { 339934b41d939a1328f484511c6002ba2456db879a29Richard Smith return isDeduced() ? getCanonicalTypeInternal() : QualType(); 340034b41d939a1328f484511c6002ba2456db879a29Richard Smith } 340134b41d939a1328f484511c6002ba2456db879a29Richard Smith bool isDeduced() const { 340234b41d939a1328f484511c6002ba2456db879a29Richard Smith return !isDependentType(); 340334b41d939a1328f484511c6002ba2456db879a29Richard Smith } 340434b41d939a1328f484511c6002ba2456db879a29Richard Smith 340534b41d939a1328f484511c6002ba2456db879a29Richard Smith void Profile(llvm::FoldingSetNodeID &ID) { 340634b41d939a1328f484511c6002ba2456db879a29Richard Smith Profile(ID, getDeducedType()); 340734b41d939a1328f484511c6002ba2456db879a29Richard Smith } 340834b41d939a1328f484511c6002ba2456db879a29Richard Smith 340934b41d939a1328f484511c6002ba2456db879a29Richard Smith static void Profile(llvm::FoldingSetNodeID &ID, 341034b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType Deduced) { 341134b41d939a1328f484511c6002ba2456db879a29Richard Smith ID.AddPointer(Deduced.getAsOpaquePtr()); 341234b41d939a1328f484511c6002ba2456db879a29Richard Smith } 341334b41d939a1328f484511c6002ba2456db879a29Richard Smith 341434b41d939a1328f484511c6002ba2456db879a29Richard Smith static bool classof(const Type *T) { 341534b41d939a1328f484511c6002ba2456db879a29Richard Smith return T->getTypeClass() == Auto; 341634b41d939a1328f484511c6002ba2456db879a29Richard Smith } 341734b41d939a1328f484511c6002ba2456db879a29Richard Smith static bool classof(const AutoType *T) { return true; } 341834b41d939a1328f484511c6002ba2456db879a29Richard Smith}; 341934b41d939a1328f484511c6002ba2456db879a29Richard Smith 34201901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// \brief Represents a type template specialization; the template 34211901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// must be a class template, a type alias template, or a template 34221901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// template parameter. A template which cannot be resolved to one of 34231901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// these, e.g. because it is written with a dependent scope 34241901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// specifier, is instead represented as a 34251901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// @c DependentTemplateSpecializationType. 3426ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 34271901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// A non-dependent template specialization type is always "sugar", 34281901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// typically for a @c RecordType. For example, a class template 34291901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// specialization type of @c vector<int> will refer to a tag type for 34301901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// the instantiation @c std::vector<int, std::allocator<int>> 3431ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 34321901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// Template specializations are dependent if either the template or 34331901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// any of the template arguments are dependent, in which case the 34341901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// type may also be canonical. 34353e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith/// 34361901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// Instances of this type are allocated with a trailing array of 34371901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// TemplateArguments, followed by a QualType representing the 34381901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// non-canonical aliased type when the template is a type alias 34391901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// template. 3440ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass TemplateSpecializationType 3441ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao : public Type, public llvm::FoldingSetNode { 34421901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall /// \brief The name of the template being specialized. This is 34431901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall /// either a TemplateName::Template (in which case it is a 34441901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a 3445146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall /// TypeAliasTemplateDecl*), a 3446146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall /// TemplateName::SubstTemplateTemplateParmPack, or a 3447146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall /// TemplateName::SubstTemplateTemplateParm (in which case the 3448146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall /// replacement must, recursively, be one of these). 3449ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao TemplateName Template; 3450ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3451ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief - The number of template arguments named in this class 3452ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// template specialization. 3453ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned NumArgs; 3454ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 345502cd8e64ab4b62f88c62f63320ddd17466764022John McCall TemplateSpecializationType(TemplateName T, 3456ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const TemplateArgument *Args, 34573e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith unsigned NumArgs, QualType Canon, 34583e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Aliased); 3459ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3460ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these 3461ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3462ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 3463ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Determine whether any of the given template arguments are 3464ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// dependent. 3465ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool anyDependentTemplateArguments(const TemplateArgument *Args, 3466561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor unsigned NumArgs, 3467561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent); 3468ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3469ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args, 3470561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor unsigned NumArgs, 3471561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent); 3472ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3473561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &, 3474561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent); 3475ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3476ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Print a template argument list, including the '<' and '>' 3477ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// enclosing the template arguments. 3478ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 3479ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned NumArgs, 3480dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor const PrintingPolicy &Policy, 3481dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor bool SkipBrackets = false); 3482ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3483ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args, 3484ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned NumArgs, 3485ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const PrintingPolicy &Policy); 3486ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3487ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &, 3488ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const PrintingPolicy &Policy); 3489ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3490ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// True if this template specialization type matches a current 3491ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// instantiation in the context in which it is found. 3492ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isCurrentInstantiation() const { 3493486c883ca29f6b50bb8ded372ad5bb2970fd4101John McCall return isa<InjectedClassNameType>(getCanonicalTypeInternal()); 3494ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3495ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 34963e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith /// True if this template specialization type is for a type alias 34973e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith /// template. 34983e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith bool isTypeAlias() const; 34993e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith /// Get the aliased type, if this is a specialization of a type alias 35003e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith /// template. 35013e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType getAliasedType() const { 35023e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith assert(isTypeAlias() && "not a type alias template specialization"); 35033e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return *reinterpret_cast<const QualType*>(end()); 35043e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 35053e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 3506ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao typedef const TemplateArgument * iterator; 3507ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3508ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao iterator begin() const { return getArgs(); } 350952b136ace347ee82e11145927e37980157bacb35John McCall iterator end() const; // defined inline in TemplateBase.h 3510ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3511ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Retrieve the name of the template that we are specializing. 3512ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao TemplateName getTemplateName() const { return Template; } 3513ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3514ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Retrieve the template arguments. 3515ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const TemplateArgument *getArgs() const { 3516ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return reinterpret_cast<const TemplateArgument *>(this + 1); 3517ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3518ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3519ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Retrieve the number of template arguments. 3520ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned getNumArgs() const { return NumArgs; } 3521ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3522ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Retrieve a specific template argument as a type. 3523ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \precondition @c isArgType(Arg) 352452b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 3525ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3526ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { 35273e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return !isDependentType() || isCurrentInstantiation() || isTypeAlias(); 3528ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3529ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return getCanonicalTypeInternal(); } 3530ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 35314ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) { 3532486c883ca29f6b50bb8ded372ad5bb2970fd4101John McCall Profile(ID, Template, getArgs(), NumArgs, Ctx); 35333e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (isTypeAlias()) 35343e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith getAliasedType().Profile(ID); 3535ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3536ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3537ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 3538ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const TemplateArgument *Args, 3539ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao unsigned NumArgs, 35404ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context); 3541ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3542ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 3543ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == TemplateSpecialization; 3544ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3545ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const TemplateSpecializationType *T) { return true; } 3546ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 3547ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3548ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// \brief The injected class name of a C++ class template or class 3549ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// template partial specialization. Used to record that a type was 3550ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// spelled with a bare identifier rather than as a template-id; the 3551ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// equivalent for non-templated classes is just RecordType. 3552ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 3553ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Injected class name types are always dependent. Template 3554ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// instantiation turns these into RecordTypes. 3555ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 3556ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Injected class name types are always canonical. This works 3557ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// because it is impossible to compare an injected class name type 3558ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// with the corresponding non-injected template type, for the same 3559ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// reason that it is impossible to directly compare template 3560ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// parameters from different dependent contexts: injected class name 3561ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// types can only occur within the scope of a particular templated 3562ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// declaration, and within that scope every template specialization 3563ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// will canonicalize to the injected class name (when appropriate 3564ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// according to the rules of the language). 3565ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass InjectedClassNameType : public Type { 3566ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao CXXRecordDecl *Decl; 3567ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3568ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// The template specialization which this type represents. 3569ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// For example, in 3570ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// template <class T> class A { ... }; 3571ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// this is A<T>, whereas in 3572ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// template <class X, class Y> class A<B<X,Y> > { ... }; 3573ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// this is A<B<X,Y> >. 3574ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// 3575ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// It is always unqualified, always a template specialization type, 3576ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// and always dependent. 3577ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType InjectedType; 3578ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3579ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 35807b39a2cadf9d62647f3aa572c52b77ea4114a599Sebastian Redl friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not 35817b39a2cadf9d62647f3aa572c52b77ea4114a599Sebastian Redl // currently suitable for AST reading, too much 3582f2606db18b5d64f241d74dc4e967347ad3da4792Argiris Kirtzidis // interdependencies. 3583ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao InjectedClassNameType(CXXRecordDecl *D, QualType TST) 3584e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor : Type(InjectedClassName, QualType(), /*Dependent=*/true, 3585561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 3586b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /*VariablyModified=*/false, 3587d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3588ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao Decl(D), InjectedType(TST) { 3589ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(isa<TemplateSpecializationType>(TST)); 3590ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(!TST.hasQualifiers()); 3591ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(TST->isDependentType()); 3592ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3593ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3594ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 3595ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getInjectedSpecializationType() const { return InjectedType; } 3596ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const TemplateSpecializationType *getInjectedTST() const { 3597ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return cast<TemplateSpecializationType>(InjectedType.getTypePtr()); 3598ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3599ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3600295dcb357afc5f6215405709cba1498f14bd673dSebastian Redl CXXRecordDecl *getDecl() const; 3601ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3602ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 3603ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 3604ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3605ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 3606ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == InjectedClassName; 3607ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3608ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const InjectedClassNameType *T) { return true; } 3609ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 3610ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3611ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// \brief The kind of a tag type. 3612ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraenum TagTypeKind { 3613ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "struct" keyword. 3614ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TTK_Struct, 3615ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "union" keyword. 3616ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TTK_Union, 3617ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "class" keyword. 3618ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TTK_Class, 3619ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "enum" keyword. 3620ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TTK_Enum 3621ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara}; 3622ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3623ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// \brief The elaboration keyword that precedes a qualified type name or 3624ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// introduces an elaborated-type-specifier. 3625ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoenum ElaboratedTypeKeyword { 3626ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief The "struct" keyword introduces the elaborated-type-specifier. 3627ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ETK_Struct, 3628ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief The "union" keyword introduces the elaborated-type-specifier. 3629ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ETK_Union, 3630ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "class" keyword introduces the elaborated-type-specifier. 3631ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ETK_Class, 3632ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief The "enum" keyword introduces the elaborated-type-specifier. 3633ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ETK_Enum, 3634ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief The "typename" keyword precedes the qualified type name, e.g., 3635ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \c typename T::type. 3636ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ETK_Typename, 3637ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// \brief No keyword precedes the qualified type name. 3638ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ETK_None 3639ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 3640ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3641ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword. 3642ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// The keyword in stored in the free bits of the base class. 3643ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// Also provides a few static helpers for converting and printing 3644ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// elaborated type keyword and tag type kind enumerations. 3645ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraclass TypeWithKeyword : public Type { 3646ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraprotected: 3647ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, 3648b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie QualType Canonical, bool Dependent, 3649b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie bool InstantiationDependent, bool VariablyModified, 3650d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool ContainsUnexpandedParameterPack) 3651b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified, 3652d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ContainsUnexpandedParameterPack) { 36531e75edda2f03c9416845f86c8f69dfaff6eb262bJohn McCall TypeWithKeywordBits.Keyword = Keyword; 36541e75edda2f03c9416845f86c8f69dfaff6eb262bJohn McCall } 3655ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3656ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnarapublic: 3657ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ElaboratedTypeKeyword getKeyword() const { 36581e75edda2f03c9416845f86c8f69dfaff6eb262bJohn McCall return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword); 3659ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara } 3660ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3661ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST) 3662ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// into an elaborated type keyword. 3663ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec); 3664ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3665ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST) 3666ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// into a tag type kind. It is an error to provide a type specifier 3667ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// which *isn't* a tag kind here. 3668ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec); 3669ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3670ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// getKeywordForTagDeclKind - Converts a TagTypeKind into an 3671ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// elaborated type keyword. 3672ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag); 3673ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3674ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// getTagTypeKindForKeyword - Converts an elaborated type keyword into 3675ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara // a TagTypeKind. It is an error to provide an elaborated type keyword 3676ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara /// which *isn't* a tag kind here. 3677ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword); 3678ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3679ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword); 3680ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3681ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static const char *getKeywordName(ElaboratedTypeKeyword Keyword); 3682ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3683ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static const char *getTagTypeKindName(TagTypeKind Kind) { 3684ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara return getKeywordName(getKeywordForTagTypeKind(Kind)); 3685ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara } 3686ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3687ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara class CannotCastToThisType {}; 3688ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static CannotCastToThisType classof(const Type *); 3689ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara}; 3690ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3691ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// \brief Represents a type that was referred to using an elaborated type 3692ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type, 3693ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// or both. 3694ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 3695ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// This type is used to keep track of a type name as written in the 3696ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// source code, including tag keywords and any nested-name-specifiers. 3697ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// The type itself is always "sugar", used to express what was written 3698ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara/// in the source code but containing no additional semantic information. 3699ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode { 3700ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3701ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief The nested name specifier containing the qualifier. 3702ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao NestedNameSpecifier *NNS; 3703ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3704ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief The type that this qualified name refers to. 3705ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType NamedType; 3706ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3707ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 3708ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara QualType NamedType, QualType CanonType) 3709ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara : TypeWithKeyword(Keyword, Elaborated, CanonType, 3710e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor NamedType->isDependentType(), 3711561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor NamedType->isInstantiationDependentType(), 3712d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor NamedType->isVariablyModifiedType(), 3713d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor NamedType->containsUnexpandedParameterPack()), 3714ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara NNS(NNS), NamedType(NamedType) { 3715ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara assert(!(Keyword == ETK_None && NNS == 0) && 3716ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara "ElaboratedType cannot have elaborated type keyword " 3717ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara "and name qualifier both null."); 3718ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara } 3719ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3720ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these 3721ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3722ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 372352b136ace347ee82e11145927e37980157bacb35John McCall ~ElaboratedType(); 3724ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3725ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Retrieve the qualification on this type. 3726ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao NestedNameSpecifier *getQualifier() const { return NNS; } 3727ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3728ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Retrieve the type named by the qualified-id. 3729ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getNamedType() const { return NamedType; } 3730ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3731ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Remove a single level of sugar. 3732ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return getNamedType(); } 3733ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3734ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Returns whether this type directly provides sugar. 3735ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return true; } 3736ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3737ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 3738ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara Profile(ID, getKeyword(), NNS, NamedType); 3739ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3740ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3741ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 3742ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara NestedNameSpecifier *NNS, QualType NamedType) { 3743ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara ID.AddInteger(Keyword); 3744ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(NNS); 3745ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao NamedType.Profile(ID); 3746ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3747ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3748ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 3749ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara return T->getTypeClass() == Elaborated; 3750ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3751ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara static bool classof(const ElaboratedType *T) { return true; } 3752ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 3753ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3754ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// \brief Represents a qualified type name for which the type name is 3755b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie/// dependent. 3756ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 3757b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie/// DependentNameType represents a class of dependent types that involve a 3758b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent) 3759ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// name of a type. The DependentNameType may start with a "typename" (for a 3760b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie/// typename-specifier), "class", "struct", "union", or "enum" (for a 3761ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// dependent elaborated-type-specifier), or nothing (in contexts where we 3762ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// know that we must be referring to a type, e.g., in a base class specifier). 3763ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { 3764ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara 3765ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief The nested name specifier containing the qualifier. 3766ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao NestedNameSpecifier *NNS; 3767ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3768ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief The type that this typename specifier refers to. 376952b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *Name; 3770ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3771b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 3772ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const IdentifierInfo *Name, QualType CanonType) 3773e5ab6f7366103282ac9d851bd66b4a0d5e8e6819Douglas Gregor : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true, 3774561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 3775d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 3776d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor NNS->containsUnexpandedParameterPack()), 3777ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara NNS(NNS), Name(Name) { 3778ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(NNS->isDependent() && 3779ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao "DependentNameType requires a dependent nested-name-specifier"); 3780ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3781ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3782ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these 3783ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3784ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 3785ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Retrieve the qualification on this type. 3786ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao NestedNameSpecifier *getQualifier() const { return NNS; } 3787ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3788ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// \brief Retrieve the type named by the typename specifier as an 3789ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// identifier. 3790ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// 3791ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// This routine will return a non-NULL identifier pointer when the 3792ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// form of the original typename was terminated by an identifier, 3793ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// e.g., "typename T::type". 3794ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const IdentifierInfo *getIdentifier() const { 379552b136ace347ee82e11145927e37980157bacb35John McCall return Name; 3796ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3797ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3798ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 3799ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 3800ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3801ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID) { 3802ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara Profile(ID, getKeyword(), NNS, Name); 3803ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3804ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3805ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 380652b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name) { 3807ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddInteger(Keyword); 3808ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ID.AddPointer(NNS); 380952b136ace347ee82e11145927e37980157bacb35John McCall ID.AddPointer(Name); 3810ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3811ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3812ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 3813ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == DependentName; 3814ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 3815ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const DependentNameType *T) { return true; } 3816ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 3817ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 381852b136ace347ee82e11145927e37980157bacb35John McCall/// DependentTemplateSpecializationType - Represents a template 381952b136ace347ee82e11145927e37980157bacb35John McCall/// specialization type whose template cannot be resolved, e.g. 382052b136ace347ee82e11145927e37980157bacb35John McCall/// A<T>::template B<T> 382152b136ace347ee82e11145927e37980157bacb35John McCallclass DependentTemplateSpecializationType : 382252b136ace347ee82e11145927e37980157bacb35John McCall public TypeWithKeyword, public llvm::FoldingSetNode { 3823ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 382452b136ace347ee82e11145927e37980157bacb35John McCall /// \brief The nested name specifier containing the qualifier. 382552b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *NNS; 382652b136ace347ee82e11145927e37980157bacb35John McCall 382752b136ace347ee82e11145927e37980157bacb35John McCall /// \brief The identifier of the template. 382852b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *Name; 382952b136ace347ee82e11145927e37980157bacb35John McCall 383052b136ace347ee82e11145927e37980157bacb35John McCall /// \brief - The number of template arguments named in this class 383152b136ace347ee82e11145927e37980157bacb35John McCall /// template specialization. 383252b136ace347ee82e11145927e37980157bacb35John McCall unsigned NumArgs; 383352b136ace347ee82e11145927e37980157bacb35John McCall 383452b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument *getArgBuffer() const { 383552b136ace347ee82e11145927e37980157bacb35John McCall return reinterpret_cast<const TemplateArgument*>(this+1); 383652b136ace347ee82e11145927e37980157bacb35John McCall } 383752b136ace347ee82e11145927e37980157bacb35John McCall TemplateArgument *getArgBuffer() { 383852b136ace347ee82e11145927e37980157bacb35John McCall return reinterpret_cast<TemplateArgument*>(this+1); 383952b136ace347ee82e11145927e37980157bacb35John McCall } 384052b136ace347ee82e11145927e37980157bacb35John McCall 384102cd8e64ab4b62f88c62f63320ddd17466764022John McCall DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 384252b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *NNS, 384352b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *Name, 384452b136ace347ee82e11145927e37980157bacb35John McCall unsigned NumArgs, 384552b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument *Args, 384652b136ace347ee82e11145927e37980157bacb35John McCall QualType Canon); 384752b136ace347ee82e11145927e37980157bacb35John McCall 384852b136ace347ee82e11145927e37980157bacb35John McCall friend class ASTContext; // ASTContext creates these 3849ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 3850ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 385152b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *getQualifier() const { return NNS; } 385252b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *getIdentifier() const { return Name; } 385352b136ace347ee82e11145927e37980157bacb35John McCall 385452b136ace347ee82e11145927e37980157bacb35John McCall /// \brief Retrieve the template arguments. 385552b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument *getArgs() const { 385652b136ace347ee82e11145927e37980157bacb35John McCall return getArgBuffer(); 385752b136ace347ee82e11145927e37980157bacb35John McCall } 385852b136ace347ee82e11145927e37980157bacb35John McCall 385952b136ace347ee82e11145927e37980157bacb35John McCall /// \brief Retrieve the number of template arguments. 386052b136ace347ee82e11145927e37980157bacb35John McCall unsigned getNumArgs() const { return NumArgs; } 386152b136ace347ee82e11145927e37980157bacb35John McCall 386252b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 386352b136ace347ee82e11145927e37980157bacb35John McCall 386452b136ace347ee82e11145927e37980157bacb35John McCall typedef const TemplateArgument * iterator; 386552b136ace347ee82e11145927e37980157bacb35John McCall iterator begin() const { return getArgs(); } 386652b136ace347ee82e11145927e37980157bacb35John McCall iterator end() const; // inline in TemplateBase.h 386752b136ace347ee82e11145927e37980157bacb35John McCall 386852b136ace347ee82e11145927e37980157bacb35John McCall bool isSugared() const { return false; } 386952b136ace347ee82e11145927e37980157bacb35John McCall QualType desugar() const { return QualType(this, 0); } 387052b136ace347ee82e11145927e37980157bacb35John McCall 38714ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) { 387252b136ace347ee82e11145927e37980157bacb35John McCall Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs()); 387352b136ace347ee82e11145927e37980157bacb35John McCall } 387452b136ace347ee82e11145927e37980157bacb35John McCall 387552b136ace347ee82e11145927e37980157bacb35John McCall static void Profile(llvm::FoldingSetNodeID &ID, 38764ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 387752b136ace347ee82e11145927e37980157bacb35John McCall ElaboratedTypeKeyword Keyword, 387852b136ace347ee82e11145927e37980157bacb35John McCall NestedNameSpecifier *Qualifier, 387952b136ace347ee82e11145927e37980157bacb35John McCall const IdentifierInfo *Name, 388052b136ace347ee82e11145927e37980157bacb35John McCall unsigned NumArgs, 388152b136ace347ee82e11145927e37980157bacb35John McCall const TemplateArgument *Args); 388252b136ace347ee82e11145927e37980157bacb35John McCall 388352b136ace347ee82e11145927e37980157bacb35John McCall static bool classof(const Type *T) { 388452b136ace347ee82e11145927e37980157bacb35John McCall return T->getTypeClass() == DependentTemplateSpecialization; 388552b136ace347ee82e11145927e37980157bacb35John McCall } 388652b136ace347ee82e11145927e37980157bacb35John McCall static bool classof(const DependentTemplateSpecializationType *T) { 388752b136ace347ee82e11145927e37980157bacb35John McCall return true; 3888b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie } 388952b136ace347ee82e11145927e37980157bacb35John McCall}; 389052b136ace347ee82e11145927e37980157bacb35John McCall 38917536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \brief Represents a pack expansion of types. 38927536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 38937536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Pack expansions are part of C++0x variadic templates. A pack 38947536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// expansion contains a pattern, which itself contains one or more 38957536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// "unexpanded" parameter packs. When instantiated, a pack expansion 38967536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// produces a series of types, each instantiated from the pattern of 38977536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// the expansion, where the Ith instantiation of the pattern uses the 38987536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Ith arguments bound to each of the unexpanded parameter packs. The 38997536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// pack expansion is considered to "expand" these unexpanded 39007536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// parameter packs. 39017536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 39027536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \code 39037536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types> struct tuple; 39047536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 3905b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie/// template<typename ...Types> 39067536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// struct tuple_of_references { 39077536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// typedef tuple<Types&...> type; 39087536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// }; 39097536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \endcode 39107536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// 39117536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Here, the pack expansion \c Types&... is represented via a 39127536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// PackExpansionType whose pattern is Types&. 39137536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorclass PackExpansionType : public Type, public llvm::FoldingSetNode { 39147536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// \brief The pattern of the pack expansion. 39157536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType Pattern; 39167536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 3917cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// \brief The number of expansions that this pack expansion will 3918b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// generate when substituted (+1), or indicates that 3919cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// 3920b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// This field will only have a non-zero value when some of the parameter 3921b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie /// packs that occur within the pattern have been substituted but others have 3922cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// not. 3923cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor unsigned NumExpansions; 3924b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 3925cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor PackExpansionType(QualType Pattern, QualType Canon, 3926cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) 39277536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor : Type(PackExpansion, Canon, /*Dependent=*/true, 3928561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 39297536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /*VariableModified=*/Pattern->isVariablyModifiedType(), 39307536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3931b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie Pattern(Pattern), 3932cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions(NumExpansions? *NumExpansions + 1: 0) { } 39337536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 39347536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor friend class ASTContext; // ASTContext creates these 3935b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 39367536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorpublic: 39377536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// \brief Retrieve the pattern of this pack expansion, which is the 39387536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// type that will be repeatedly instantiated when instantiating the 39397536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor /// pack expansion itself. 39407536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType getPattern() const { return Pattern; } 39417536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 3942cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// \brief Retrieve the number of expansions that this pack expansion will 3943cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// generate, if known. 3944cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> getNumExpansions() const { 3945cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor if (NumExpansions) 3946cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor return NumExpansions - 1; 3947b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 3948cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor return llvm::Optional<unsigned>(); 3949cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor } 3950b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 39517536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor bool isSugared() const { return false; } 39527536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType desugar() const { return QualType(this, 0); } 39537536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 39547536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 3955cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Profile(ID, getPattern(), getNumExpansions()); 39567536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 39577536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 3958cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern, 3959cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 39607536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor ID.AddPointer(Pattern.getAsOpaquePtr()); 3961cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor ID.AddBoolean(NumExpansions); 3962cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor if (NumExpansions) 3963cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor ID.AddInteger(*NumExpansions); 39647536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 39657536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 39667536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor static bool classof(const Type *T) { 39677536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return T->getTypeClass() == PackExpansion; 39687536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 39697536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor static bool classof(const PackExpansionType *T) { 39707536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return true; 3971b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie } 39727536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor}; 39737536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 3974f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// ObjCObjectType - Represents a class type in Objective C. 3975f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// Every Objective C type is a combination of a base type and a 3976f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// list of protocols. 3977f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 3978f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// Given the following declarations: 3979f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// @class C; 3980f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// @protocol P; 3981f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 3982f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType 3983f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// with base C and no protocols. 3984f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 3985f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P]. 3986f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 3987cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose 3988cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType 3989cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// and no protocols. 3990f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// 3991cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType 3992cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually 3993cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// this should get its own sugar class to better represent the source. 3994f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallclass ObjCObjectType : public Type { 3995084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall // ObjCObjectType.NumProtocols - the number of protocols stored 3996084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall // after the ObjCObjectPointerType node. 3997f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall // 3998f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall // These protocols are those written directly on the type. If 3999f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall // protocol qualifiers ever become additive, the iterators will need 4000f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall // to get kindof complicated. 4001f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall // 4002f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall // In the canonical object type, these are sorted alphabetically 4003f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall // and uniqued. 400477763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff 4005f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// Either a BuiltinType or an InterfaceType or sugar for either. 4006f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall QualType BaseType; 4007f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4008f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCProtocolDecl * const *getProtocolStorage() const { 4009f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return const_cast<ObjCObjectType*>(this)->getProtocolStorage(); 4010f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 4011f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4012f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCProtocolDecl **getProtocolStorage(); 4013f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4014f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallprotected: 4015b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie ObjCObjectType(QualType Canonical, QualType Base, 4016f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCProtocolDecl * const *Protocols, unsigned NumProtocols); 4017f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4018f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall enum Nonce_ObjCInterface { Nonce_ObjCInterface }; 4019f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCObjectType(enum Nonce_ObjCInterface) 4020561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Type(ObjCInterface, QualType(), false, false, false, false), 4021f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall BaseType(QualType(this_(), 0)) { 4022084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall ObjCObjectTypeBits.NumProtocols = 0; 4023f11e7f7a1d04438e9bacdcfb04a110ea01dcadeeJohn McCall } 402477763c58e3b7783c8e54671c2b696ecd81ed524fSteve Naroff 402581f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroffpublic: 4026cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getBaseType - Gets the base type of this object type. This is 4027cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// always (possibly sugar for) one of: 4028cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// - the 'id' builtin type (as opposed to the 'id' type visible to the 4029cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// user, which is a typedef for an ObjCPointerType) 4030cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// - the 'Class' builtin type (same caveat) 4031cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// - an ObjCObjectType (currently always an ObjCInterfaceType) 4032f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall QualType getBaseType() const { return BaseType; } 403339abeeb809b1c9cdd18d0d338aa8cbf71748d8d2Ted Kremenek 4034f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCId() const { 4035f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId); 4036f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 4037f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCClass() const { 4038f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass); 4039f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 4040f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); } 4041f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); } 4042f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCUnqualifiedIdOrClass() const { 4043f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall if (!qual_empty()) return false; 4044f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>()) 4045f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return T->getKind() == BuiltinType::ObjCId || 4046f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall T->getKind() == BuiltinType::ObjCClass; 4047f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return false; 4048f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 4049f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); } 4050f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); } 4051f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4052f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// Gets the interface declaration for this object type, if the base type 4053f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// really is an interface. 4054f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCInterfaceDecl *getInterface() const; 4055f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4056f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall typedef ObjCProtocolDecl * const *qual_iterator; 4057f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4058f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_iterator qual_begin() const { return getProtocolStorage(); } 4059f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); } 4060f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4061f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool qual_empty() const { return getNumProtocols() == 0; } 4062ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4063ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// getNumProtocols - Return the number of qualifying protocols in this 4064ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// interface type, or 0 if there are none. 4065084ff0118a8a97513e725202a9ee4b35ed78a36cJohn McCall unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; } 4066ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4067f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall /// \brief Fetch a protocol by index. 4068ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ObjCProtocolDecl *getProtocol(unsigned I) const { 4069ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(I < getNumProtocols() && "Out-of-range protocol access"); 4070ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return qual_begin()[I]; 4071ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 4072b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 4073ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 4074ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 4075ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4076f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall static bool classof(const Type *T) { 4077f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return T->getTypeClass() == ObjCObject || 4078f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall T->getTypeClass() == ObjCInterface; 4079f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 4080f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall static bool classof(const ObjCObjectType *) { return true; } 4081f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall}; 4082f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4083f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation 4084f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// of ObjCObjectType, so as to not increase the footprint of 4085f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// ObjCInterfaceType. Code outside of ASTContext and the core type 4086f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// system should not reference this type. 4087f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode { 4088f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall friend class ASTContext; 4089f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4090f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // If anyone adds fields here, ObjCObjectType::getProtocolStorage() 4091f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // will need to be modified. 4092f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4093b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie ObjCObjectTypeImpl(QualType Canonical, QualType Base, 4094f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCProtocolDecl * const *Protocols, 4095f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall unsigned NumProtocols) 4096f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {} 4097f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4098f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallpublic: 4099ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao void Profile(llvm::FoldingSetNodeID &ID); 4100ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static void Profile(llvm::FoldingSetNodeID &ID, 4101f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall QualType Base, 4102b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie ObjCProtocolDecl *const *protocols, 4103b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie unsigned NumProtocols); 4104f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall}; 4105ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4106f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() { 4107f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return reinterpret_cast<ObjCProtocolDecl**>( 4108f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall static_cast<ObjCObjectTypeImpl*>(this) + 1); 4109f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall} 4110f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4111f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 4112f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// object oriented design. They basically correspond to C++ classes. There 4113f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// are two kinds of interface types, normal interfaces like "NSString" and 4114f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// qualified interfaces, which are qualified with a protocol list like 4115f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall/// "NSString<NSCopyable, NSAmazing>". 4116cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// 4117cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// ObjCInterfaceType guarantees the following properties when considered 4118cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// as a subtype of its superclass, ObjCObjectType: 4119cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// - There are no protocol qualifiers. To reinforce this, code which 4120cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// tries to invoke the protocol methods via an ObjCInterfaceType will 4121cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// fail to compile. 4122cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// - It is its own base type. That is, if T is an ObjCInterfaceType*, 4123cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// T->getBaseType() == QualType(T, 0). 4124f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallclass ObjCInterfaceType : public ObjCObjectType { 4125f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCInterfaceDecl *Decl; 4126f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4127f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCInterfaceType(const ObjCInterfaceDecl *D) 4128f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall : ObjCObjectType(Nonce_ObjCInterface), 4129f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall Decl(const_cast<ObjCInterfaceDecl*>(D)) {} 4130f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall friend class ASTContext; // ASTContext creates these. 413182254439b368de855d1e66440071017a1f2d4f0aJohn McCall 4132f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallpublic: 4133cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getDecl - Get the declaration of this interface. 41345a24acfed51d1233e325f43af5b2147ad9c31e04Douglas Gregor ObjCInterfaceDecl *getDecl() const { return Decl; } 4135f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4136f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool isSugared() const { return false; } 4137f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall QualType desugar() const { return QualType(this, 0); } 4138ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4139ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 4140ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == ObjCInterface; 4141ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 4142ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const ObjCInterfaceType *) { return true; } 4143f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4144f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // Nonsense to "hide" certain members of ObjCObjectType within this 4145f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // class. People asking for protocols on an ObjCInterfaceType are 4146f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // not going to get what they want: ObjCInterfaceTypes are 4147f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall // guaranteed to have no protocols. 4148f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall enum { 4149f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_iterator, 4150f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_begin, 4151f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_end, 4152f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall getNumProtocols, 4153f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall getProtocol 4154f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall }; 4155ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 4156ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4157f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const { 4158f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall if (const ObjCInterfaceType *T = 4159f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall getBaseType()->getAs<ObjCInterfaceType>()) 4160f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return T->getDecl(); 4161f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return 0; 4162f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall} 4163f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4164cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// ObjCObjectPointerType - Used to represent a pointer to an 4165cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// Objective C object. These are constructed from pointer 4166cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar 4167cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// for one). In addition, the 'id' and 'Class' types are typedefs 4168cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>' 4169cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// are translated into these. 4170ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 4171cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// Pointers to pointers to Objective C objects are still PointerTypes; 4172cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall/// only the first level of pointer gets it own type implementation. 4173ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 4174cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall QualType PointeeType; 4175ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4176f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ObjCObjectPointerType(QualType Canonical, QualType Pointee) 4177561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Type(ObjCObjectPointer, Canonical, false, false, false, false), 4178f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall PointeeType(Pointee) {} 4179ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao friend class ASTContext; // ASTContext creates these. 4180ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4181ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 4182cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getPointeeType - Gets the type pointed to by this ObjC pointer. 4183cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// The result will always be an ObjCObjectType or sugar thereof. 4184ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType getPointeeType() const { return PointeeType; } 4185ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4186cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getObjCObjectType - Gets the type pointed to by this ObjC 4187cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// pointer. This method always returns non-null. 4188cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// 4189cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// This method is equivalent to getPointeeType() except that 4190cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// it discards any typedefs (or other sugar) between this 4191cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// type and the "outermost" object type. So for: 4192cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// @class A; @protocol P; @protocol Q; 4193cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// typedef A<P> AP; 4194cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// typedef A A1; 4195cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// typedef A1<P> A1P; 4196cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// typedef A1P<Q> A1PQ; 4197cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A*', getObjectType() will return 'A'. 4198cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A<P>*', getObjectType() will return 'A<P>'. 4199cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'AP*', getObjectType() will return 'A<P>'. 4200cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A1*', getObjectType() will return 'A'. 4201cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A1<P>*', getObjectType() will return 'A1<P>'. 4202cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A1P*', getObjectType() will return 'A1<P>'. 4203cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because 4204cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// adding protocols to a protocol-qualified base discards the 4205cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// old qualifiers (for now). But if it didn't, getObjectType() 4206cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// would return 'A1P<Q>' (and we'd have to make iterating over 4207cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// qualifiers more complicated). 4208f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall const ObjCObjectType *getObjectType() const { 4209d0370f59e79702ac908c81bf556519f91e9ca297John McCall return PointeeType->castAs<ObjCObjectType>(); 4210f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 4211f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall 4212cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getInterfaceType - If this pointer points to an Objective C 4213cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// @interface type, gets the type for that interface. Any protocol 4214cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// qualifiers on the interface are ignored. 4215cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// 4216cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// \return null if the base type for this pointer is 'id' or 'Class' 4217ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const ObjCInterfaceType *getInterfaceType() const { 4218f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>(); 4219ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 4220cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 4221cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getInterfaceDecl - If this pointer points to an Objective @interface 4222cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// type, gets the declaration for that interface. 4223cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// 4224cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// \return null if the base type for this pointer is 'id' or 'Class' 4225ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ObjCInterfaceDecl *getInterfaceDecl() const { 4226cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall return getObjectType()->getInterface(); 4227ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 4228cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 4229cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if 4230cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// its object type is the primitive 'id' type with no protocols. 4231ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isObjCIdType() const { 4232f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->isObjCUnqualifiedId(); 4233ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 4234cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 4235cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// isObjCClassType - True if this is equivalent to the 'Class' type, 4236cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// i.e. if its object tive is the primitive 'Class' type with no protocols. 4237ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isObjCClassType() const { 4238f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->isObjCUnqualifiedClass(); 4239ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 4240b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 4241cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some 4242cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// non-empty set of protocols. 4243ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isObjCQualifiedIdType() const { 4244f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->isObjCQualifiedId(); 4245ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 4246cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 4247cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for 4248cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// some non-empty set of protocols. 4249ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isObjCQualifiedClassType() const { 4250f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->isObjCQualifiedClass(); 4251ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 4252cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall 4253cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// An iterator over the qualifiers on the object type. Provided 4254cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// for convenience. This will always iterate over the full set of 4255cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// protocols on a type, not just those provided directly. 4256f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall typedef ObjCObjectType::qual_iterator qual_iterator; 4257ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4258ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao qual_iterator qual_begin() const { 4259f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->qual_begin(); 4260ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 4261f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall qual_iterator qual_end() const { 4262f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->qual_end(); 4263ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 4264f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall bool qual_empty() const { return getObjectType()->qual_empty(); } 4265ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4266cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// getNumProtocols - Return the number of qualifying protocols on 4267cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// the object type. 4268f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall unsigned getNumProtocols() const { 4269f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->getNumProtocols(); 4270f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 4271ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4272cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// \brief Retrieve a qualifying protocol by index on the object 4273cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall /// type. 4274ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ObjCProtocolDecl *getProtocol(unsigned I) const { 4275f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return getObjectType()->getProtocol(I); 4276ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 4277b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 4278ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isSugared() const { return false; } 4279ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType desugar() const { return QualType(this, 0); } 4280ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4281cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall void Profile(llvm::FoldingSetNodeID &ID) { 4282cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall Profile(ID, getPointeeType()); 4283cca3b567dafc1d3125f476ae19bf82d84b16e4c1John McCall } 4284f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { 4285f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall ID.AddPointer(T.getAsOpaquePtr()); 4286f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall } 4287ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const Type *T) { 4288ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getTypeClass() == ObjCObjectPointer; 4289ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 4290ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao static bool classof(const ObjCObjectPointerType *) { return true; } 4291ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 4292ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4293b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmanclass AtomicType : public Type, public llvm::FoldingSetNode { 4294b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType ValueType; 4295b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4296b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicType(QualType ValTy, QualType Canonical) 4297b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman : Type(Atomic, Canonical, ValTy->isDependentType(), 4298b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ValTy->isInstantiationDependentType(), 4299b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ValTy->isVariablyModifiedType(), 4300b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ValTy->containsUnexpandedParameterPack()), 4301b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ValueType(ValTy) {} 4302b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman friend class ASTContext; // ASTContext creates these. 4303b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4304b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman public: 4305b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// getValueType - Gets the type contained by this atomic type, i.e. 4306b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// the type returned by performing an atomic load of this atomic type. 4307b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType getValueType() const { return ValueType; } 4308b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4309b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman bool isSugared() const { return false; } 4310b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType desugar() const { return QualType(this, 0); } 4311b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4312b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 4313b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Profile(ID, getValueType()); 4314b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 4315b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { 4316b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ID.AddPointer(T.getAsOpaquePtr()); 4317b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 4318b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman static bool classof(const Type *T) { 4319b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return T->getTypeClass() == Atomic; 4320b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 4321b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman static bool classof(const AtomicType *) { return true; } 4322b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman}; 4323b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4324ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// A qualifier set is used to build a set of qualifiers. 4325ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass QualifierCollector : public Qualifiers { 4326ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic: 432749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {} 4328ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4329ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// Collect any qualifiers on the given type and return an 43303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// unqualified type. The qualifiers are assumed to be consistent 43313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall /// with those already in the type. 43323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *strip(QualType type) { 43333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall addFastQualifiers(type.getLocalFastQualifiers()); 43343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!type.hasLocalNonFastQualifiers()) 43353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return type.getTypePtrUnsafe(); 4336b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 43373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ExtQuals *extQuals = type.getExtQualsUnsafe(); 43383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall addConsistentQualifiers(extQuals->getQualifiers()); 43393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return extQuals->getBaseType(); 4340ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } 4341ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4342ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// Apply the collected qualifiers to the given type. 43434ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType apply(const ASTContext &Context, QualType QT) const; 4344ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4345ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao /// Apply the collected qualifiers to the given type. 43464ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType apply(const ASTContext &Context, const Type* T) const; 4347ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}; 4348ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4349ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4350ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// Inline function definitions. 4351ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 43523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtr() const { 43533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getCommonPtr()->BaseType; 43543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 43553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 43563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtrOrNull() const { 43573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return (isNull() ? 0 : getCommonPtr()->BaseType); 43583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 43593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 43603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline SplitQualType QualType::split() const { 43613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!hasLocalNonFastQualifiers()) 43623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return SplitQualType(getTypePtrUnsafe(), 43633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers::fromFastMask(getLocalFastQualifiers())); 43643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 43653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ExtQuals *eq = getExtQualsUnsafe(); 43663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers qs = eq->getQualifiers(); 43673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall qs.addFastQualifiers(getLocalFastQualifiers()); 43683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return SplitQualType(eq->getBaseType(), qs); 43693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 43703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 43713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getLocalQualifiers() const { 43723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers Quals; 43733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (hasLocalNonFastQualifiers()) 43743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals = getExtQualsUnsafe()->getQualifiers(); 43753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Quals.addFastQualifiers(getLocalFastQualifiers()); 43763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return Quals; 43773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 43783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 43793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getQualifiers() const { 43803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers(); 43813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall quals.addFastQualifiers(getLocalFastQualifiers()); 43823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return quals; 43833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 43843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 43853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline unsigned QualType::getCVRQualifiers() const { 43863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers(); 43873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall cvr |= getLocalCVRQualifiers(); 43883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return cvr; 43893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 43903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 43913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline QualType QualType::getCanonicalType() const { 43923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType canon = getCommonPtr()->CanonicalType; 43933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return canon.withFastQualifiers(getLocalFastQualifiers()); 43943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 43953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 4396ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool QualType::isCanonical() const { 43973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getTypePtr()->isCanonicalUnqualified(); 4398ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4399ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4400ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool QualType::isCanonicalAsParam() const { 44013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isCanonical()) return false; 4402ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (hasLocalQualifiers()) return false; 4403b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 4404ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao const Type *T = getTypePtr(); 44053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (T->isVariablyModifiedType() && T->hasSizedVLAType()) 44063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return false; 44073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 44083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return !isa<FunctionType>(T) && !isa<ArrayType>(T); 4409ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4410ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4411ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool QualType::isConstQualified() const { 4412b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie return isLocalConstQualified() || 44133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.isLocalConstQualified(); 4414ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4415ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4416ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool QualType::isRestrictQualified() const { 4417b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie return isLocalRestrictQualified() || 44183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.isLocalRestrictQualified(); 4419ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4420ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4421ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4422ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool QualType::isVolatileQualified() const { 4423b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie return isLocalVolatileQualified() || 44243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.isLocalVolatileQualified(); 4425ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4426b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 4427ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool QualType::hasQualifiers() const { 4428ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return hasLocalQualifiers() || 44293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall getCommonPtr()->CanonicalType.hasLocalQualifiers(); 4430ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4431ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 443262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline QualType QualType::getUnqualifiedType() const { 443362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) 443462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return QualType(getTypePtr(), 0); 443562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 443662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return QualType(getSplitUnqualifiedTypeImpl(*this).first, 0); 4437ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4438ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 443962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline SplitQualType QualType::getSplitUnqualifiedType() const { 444062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) 444162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return split(); 444262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 444362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getSplitUnqualifiedTypeImpl(*this); 4444fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 4445b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 444649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalConst() { 444749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Qualifiers::Const); 4448ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4449ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 445049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalRestrict() { 445149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Qualifiers::Restrict); 4452ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4453ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 445449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalVolatile() { 445549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Qualifiers::Volatile); 4456ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4457ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 445849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalCVRQualifiers(unsigned Mask) { 4459ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits"); 4460c3c0af36bac3d71f61dd758585ab307892545de4Douglas Gregor assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask); 4461ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4462ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // Fast path: we don't need to touch the slow qualifiers. 446349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall removeLocalFastQualifiers(Mask); 4464ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4465ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4466ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// getAddressSpace - Return the address space of this type. 4467ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline unsigned QualType::getAddressSpace() const { 44683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getQualifiers().getAddressSpace(); 4469ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4470ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4471ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// getObjCGCAttr - Return the gc attribute of this type. 4472ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline Qualifiers::GC QualType::getObjCGCAttr() const { 44733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getQualifiers().getObjCGCAttr(); 4474ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4475ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4476ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { 4477ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (const PointerType *PT = t.getAs<PointerType>()) { 4478ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>()) 4479ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return FT->getExtInfo(); 4480ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao } else if (const FunctionType *FT = t.getAs<FunctionType>()) 4481ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return FT->getExtInfo(); 4482ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4483ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return FunctionType::ExtInfo(); 4484ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4485ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4486ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { 4487ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return getFunctionExtInfo(*t); 4488ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4489ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4490ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// isMoreQualifiedThan - Determine whether this type is more 4491ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// qualified than the Other type. For example, "const volatile int" 4492ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// is more qualified than "const int", "volatile int", and 4493ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// "int". However, it is not more qualified than "const volatile 4494ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// int". 449562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isMoreQualifiedThan(QualType other) const { 449662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Qualifiers myQuals = getQualifiers(); 449762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Qualifiers otherQuals = other.getQualifiers(); 449862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return (myQuals != otherQuals && myQuals.compatiblyIncludes(otherQuals)); 4499ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4500ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4501ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// isAtLeastAsQualifiedAs - Determine whether this type is at last 4502ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// as qualified as the Other type. For example, "const volatile 4503ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// int" is at least as qualified as "const int", "volatile int", 4504ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// "int", and "const volatile int". 450562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isAtLeastAsQualifiedAs(QualType other) const { 450662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getQualifiers().compatiblyIncludes(other.getQualifiers()); 4507ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4508ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4509ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// getNonReferenceType - If Type is a reference type (e.g., const 4510ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// int&), returns the type that the reference refers to ("const 4511ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// int"). Otherwise, returns the type itself. This routine is used 4512ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// throughout Sema to implement C++ 5p6: 4513ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 4514ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// If an expression initially has the type "reference to T" (8.3.2, 4515ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 8.5.3), the type is adjusted to "T" prior to any further 4516ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// analysis, the expression designates the object or function 4517ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// denoted by the reference, and the expression is an lvalue. 4518ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline QualType QualType::getNonReferenceType() const { 4519ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 4520ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return RefType->getPointeeType(); 4521ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao else 4522ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return *this; 4523ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4524ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 45252b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregorinline bool QualType::isCForbiddenLValueType() const { 45262b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor return ((getTypePtr()->isVoidType() && !hasQualifiers()) || 45272b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor getTypePtr()->isFunctionType()); 45282b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor} 45292b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor 4530aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \brief Tests whether the type is categorized as a fundamental type. 4531aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// 4532aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \returns True for types specified in C++0x [basic.fundamental]. 4533aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruthinline bool Type::isFundamentalType() const { 4534aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth return isVoidType() || 4535aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // FIXME: It's really annoying that we don't have an 4536aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // 'isArithmeticType()' which agrees with the standard definition. 4537aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth (isArithmeticType() && !isEnumeralType()); 4538aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth} 4539aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth 4540aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \brief Tests whether the type is categorized as a compound type. 4541aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// 4542aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \returns True for types specified in C++0x [basic.compound]. 4543aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruthinline bool Type::isCompoundType() const { 4544aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // C++0x [basic.compound]p1: 4545aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // Compound types can be constructed in the following ways: 4546aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- arrays of objects of a given type [...]; 4547aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth return isArrayType() || 4548aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- functions, which have parameters of given types [...]; 4549aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isFunctionType() || 4550aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- pointers to void or objects or functions [...]; 4551aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isPointerType() || 4552aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- references to objects or functions of a given type. [...] 4553aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isReferenceType() || 4554aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- classes containing a sequence of objects of various types, [...]; 4555aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isRecordType() || 4556b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie // -- unions, which are classes capable of containing objects of different 4557b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie // types at different times; 4558aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isUnionType() || 4559aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- enumerations, which comprise a set of named constant values. [...]; 4560aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isEnumeralType() || 4561aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth // -- pointers to non-static class members, [...]. 4562aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth isMemberPointerType(); 4563aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth} 4564aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth 4565ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isFunctionType() const { 4566ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<FunctionType>(CanonicalType); 4567ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4568ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isPointerType() const { 4569ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<PointerType>(CanonicalType); 4570ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4571ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isAnyPointerType() const { 4572ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isPointerType() || isObjCObjectPointerType(); 4573ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4574ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isBlockPointerType() const { 4575ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<BlockPointerType>(CanonicalType); 4576ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4577ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isReferenceType() const { 4578ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<ReferenceType>(CanonicalType); 4579ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4580ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isLValueReferenceType() const { 4581ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<LValueReferenceType>(CanonicalType); 4582ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4583ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isRValueReferenceType() const { 4584ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<RValueReferenceType>(CanonicalType); 4585ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4586ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isFunctionPointerType() const { 4587d0370f59e79702ac908c81bf556519f91e9ca297John McCall if (const PointerType *T = getAs<PointerType>()) 4588ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return T->getPointeeType()->isFunctionType(); 4589ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao else 4590ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return false; 4591ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4592ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isMemberPointerType() const { 4593ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<MemberPointerType>(CanonicalType); 4594ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4595ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isMemberFunctionPointerType() const { 4596ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (const MemberPointerType* T = getAs<MemberPointerType>()) 45976ae2325ec3b27aae178267de58fe35acf2027b91John McCall return T->isMemberFunctionPointer(); 45987555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl else 45997555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return false; 46007555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl} 4601d401c08eaebd14b9fa6440513c764a7342d0adeaDouglas Gregorinline bool Type::isMemberDataPointerType() const { 4602d401c08eaebd14b9fa6440513c764a7342d0adeaDouglas Gregor if (const MemberPointerType* T = getAs<MemberPointerType>()) 46036ae2325ec3b27aae178267de58fe35acf2027b91John McCall return T->isMemberDataPointer(); 4604ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao else 4605ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return false; 4606ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4607ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isArrayType() const { 4608ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<ArrayType>(CanonicalType); 4609ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4610ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isConstantArrayType() const { 4611ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<ConstantArrayType>(CanonicalType); 4612ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4613ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isIncompleteArrayType() const { 4614ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<IncompleteArrayType>(CanonicalType); 4615ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4616ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isVariableArrayType() const { 4617ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<VariableArrayType>(CanonicalType); 4618ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4619ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isDependentSizedArrayType() const { 4620ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<DependentSizedArrayType>(CanonicalType); 4621ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 462214b135ed28e79e44f1e3237209d24cac3af9e91bJohn McCallinline bool Type::isBuiltinType() const { 462314b135ed28e79e44f1e3237209d24cac3af9e91bJohn McCall return isa<BuiltinType>(CanonicalType); 462414b135ed28e79e44f1e3237209d24cac3af9e91bJohn McCall} 4625ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isRecordType() const { 4626ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<RecordType>(CanonicalType); 4627ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 462814b135ed28e79e44f1e3237209d24cac3af9e91bJohn McCallinline bool Type::isEnumeralType() const { 462914b135ed28e79e44f1e3237209d24cac3af9e91bJohn McCall return isa<EnumType>(CanonicalType); 463014b135ed28e79e44f1e3237209d24cac3af9e91bJohn McCall} 4631ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isAnyComplexType() const { 4632ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<ComplexType>(CanonicalType); 4633ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4634ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isVectorType() const { 4635ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<VectorType>(CanonicalType); 4636ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4637ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isExtVectorType() const { 4638ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<ExtVectorType>(CanonicalType); 4639ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4640ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isObjCObjectPointerType() const { 4641ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<ObjCObjectPointerType>(CanonicalType); 4642ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4643f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCallinline bool Type::isObjCObjectType() const { 4644f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return isa<ObjCObjectType>(CanonicalType); 4645b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner} 4646e004547e55aa2e69d1a7ee3d037605c5b1e9f6c3Douglas Gregorinline bool Type::isObjCObjectOrInterfaceType() const { 4647b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie return isa<ObjCInterfaceType>(CanonicalType) || 4648e004547e55aa2e69d1a7ee3d037605c5b1e9f6c3Douglas Gregor isa<ObjCObjectType>(CanonicalType); 4649ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4650b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmaninline bool Type::isAtomicType() const { 4651b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return isa<AtomicType>(CanonicalType); 4652b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 4653e004547e55aa2e69d1a7ee3d037605c5b1e9f6c3Douglas Gregor 4654ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isObjCQualifiedIdType() const { 4655ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 4656ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return OPT->isObjCQualifiedIdType(); 4657ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return false; 4658ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4659ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isObjCQualifiedClassType() const { 4660ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 4661ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return OPT->isObjCQualifiedClassType(); 4662ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return false; 4663ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4664ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isObjCIdType() const { 4665ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 4666ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return OPT->isObjCIdType(); 4667ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return false; 4668ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4669ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isObjCClassType() const { 4670ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 4671ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return OPT->isObjCClassType(); 4672ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return false; 4673ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4674ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isObjCSelType() const { 4675ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (const PointerType *OPT = getAs<PointerType>()) 4676ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); 4677ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return false; 4678ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4679ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isObjCBuiltinType() const { 4680ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isObjCIdType() || isObjCClassType() || isObjCSelType(); 4681ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4682ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isTemplateTypeParmType() const { 4683ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isa<TemplateTypeParmType>(CanonicalType); 4684ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4685ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4686ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isSpecificBuiltinType(unsigned K) const { 4687ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (const BuiltinType *BT = getAs<BuiltinType>()) 4688ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (BT->getKind() == (BuiltinType::Kind) K) 4689ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return true; 4690ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return false; 4691ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4692ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 469313e47eecb1470d59e399952280e68c16e302c75dJohn McCallinline bool Type::isPlaceholderType() const { 4694a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(this)) 469513e47eecb1470d59e399952280e68c16e302c75dJohn McCall return BT->isPlaceholderType(); 469613e47eecb1470d59e399952280e68c16e302c75dJohn McCall return false; 469713e47eecb1470d59e399952280e68c16e302c75dJohn McCall} 469813e47eecb1470d59e399952280e68c16e302c75dJohn McCall 4699a180f04c091bf3ede4fe292ba6a29d61da09e936John McCallinline const BuiltinType *Type::getAsPlaceholderType() const { 4700a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(this)) 4701a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall if (BT->isPlaceholderType()) 4702a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall return BT; 4703a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall return 0; 4704a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall} 4705a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall 4706864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCallinline bool Type::isSpecificPlaceholderType(unsigned K) const { 470785def357129b6cdfd69a66ad0e6994506418a2a9John McCall assert(BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K)); 4708864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(this)) 4709864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return (BT->getKind() == (BuiltinType::Kind) K); 4710864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return false; 4711864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall} 4712864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 4713ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// \brief Determines whether this is a type for which one can define 4714ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// an overloaded operator. 4715ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::isOverloadableType() const { 4716ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return isDependentType() || isRecordType() || isEnumeralType(); 4717ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4718ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4719bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth/// \brief Determines whether this type can decay to a pointer type. 4720bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruthinline bool Type::canDecayToPointerType() const { 4721bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth return isFunctionType() || isArrayType(); 4722bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth} 4723bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth 4724ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::hasPointerRepresentation() const { 4725ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return (isPointerType() || isReferenceType() || isBlockPointerType() || 4726f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall isObjCObjectPointerType() || isNullPtrType()); 4727ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4728ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4729ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline bool Type::hasObjCPointerRepresentation() const { 4730f4f254c60f644f08dea9cfbe0865016a5ef748a6John McCall return isObjCObjectPointerType(); 4731ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4732ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4733d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const Type *Type::getBaseElementTypeUnsafe() const { 4734d0370f59e79702ac908c81bf556519f91e9ca297John McCall const Type *type = this; 4735d0370f59e79702ac908c81bf556519f91e9ca297John McCall while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe()) 4736d0370f59e79702ac908c81bf556519f91e9ca297John McCall type = arrayType->getElementType().getTypePtr(); 4737d0370f59e79702ac908c81bf556519f91e9ca297John McCall return type; 4738d0370f59e79702ac908c81bf556519f91e9ca297John McCall} 4739d0370f59e79702ac908c81bf556519f91e9ca297John McCall 4740ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Insertion operator for diagnostics. This allows sending QualType's into a 4741ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// diagnostic with <<. 4742ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 4743ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType T) { 4744ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 4745d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine::ak_qualtype); 4746ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return DB; 4747ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4748ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4749ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Insertion operator for partial diagnostics. This allows sending QualType's 4750ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// into a diagnostic with <<. 4751ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, 4752ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao QualType T) { 4753ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 4754d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine::ak_qualtype); 4755ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return PD; 4756ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4757ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4758ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// Helper class template that is used by Type::getAs to ensure that one does 4759ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// not try to look through a qualified type to get to an array type. 4760ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaotemplate<typename T, 4761ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao bool isArrayType = (llvm::is_same<T, ArrayType>::value || 4762ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao llvm::is_base_of<ArrayType, T>::value)> 4763ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaostruct ArrayType_cannot_be_used_with_getAs { }; 4764b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 4765ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaotemplate<typename T> 4766ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaostruct ArrayType_cannot_be_used_with_getAs<T, true>; 4767b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 4768ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Member-template getAs<specific type>'. 4769ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaotemplate <typename T> const T *Type::getAs() const { 4770ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao ArrayType_cannot_be_used_with_getAs<T> at; 4771ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao (void)at; 4772b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie 4773ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // If this is directly a T type, return it. 4774ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (const T *Ty = dyn_cast<T>(this)) 4775ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return Ty; 4776ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4777ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // If the canonical form of this type isn't the right kind, reject it. 4778ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao if (!isa<T>(CanonicalType)) 4779ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return 0; 4780ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4781ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // If this is a typedef for the type, strip the typedef off without 4782ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao // losing all typedef information. 4783ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao return cast<T>(getUnqualifiedDesugaredType()); 4784ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} 4785ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 47863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const ArrayType *Type::getAsArrayTypeUnsafe() const { 47873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If this is directly an array type, return it. 47883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const ArrayType *arr = dyn_cast<ArrayType>(this)) 47893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return arr; 47903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 47913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If the canonical form of this type isn't the right kind, reject it. 47923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isa<ArrayType>(CanonicalType)) 47933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return 0; 47943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 47953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If this is a typedef for the type, strip the typedef off without 47963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // losing all typedef information. 47973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()); 47983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 47993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 4800d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <typename T> const T *Type::castAs() const { 4801d0370f59e79702ac908c81bf556519f91e9ca297John McCall ArrayType_cannot_be_used_with_getAs<T> at; 4802d0370f59e79702ac908c81bf556519f91e9ca297John McCall (void) at; 4803d0370f59e79702ac908c81bf556519f91e9ca297John McCall 4804d0370f59e79702ac908c81bf556519f91e9ca297John McCall assert(isa<T>(CanonicalType)); 4805d0370f59e79702ac908c81bf556519f91e9ca297John McCall if (const T *ty = dyn_cast<T>(this)) return ty; 4806d0370f59e79702ac908c81bf556519f91e9ca297John McCall return cast<T>(getUnqualifiedDesugaredType()); 4807d0370f59e79702ac908c81bf556519f91e9ca297John McCall} 4808d0370f59e79702ac908c81bf556519f91e9ca297John McCall 4809d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const ArrayType *Type::castAsArrayTypeUnsafe() const { 4810d0370f59e79702ac908c81bf556519f91e9ca297John McCall assert(isa<ArrayType>(CanonicalType)); 4811d0370f59e79702ac908c81bf556519f91e9ca297John McCall if (const ArrayType *arr = dyn_cast<ArrayType>(this)) return arr; 4812d0370f59e79702ac908c81bf556519f91e9ca297John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()); 4813d0370f59e79702ac908c81bf556519f91e9ca297John McCall} 4814d0370f59e79702ac908c81bf556519f91e9ca297John McCall 4815ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao} // end namespace clang 4816ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao 4817ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#endif 4818