Type.h revision 195099
1193326Sed//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed// 10193326Sed// This file defines the Type interface and subclasses. 11193326Sed// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed 14193326Sed#ifndef LLVM_CLANG_AST_TYPE_H 15193326Sed#define LLVM_CLANG_AST_TYPE_H 16193326Sed 17193326Sed#include "clang/Basic/Diagnostic.h" 18193326Sed#include "clang/Basic/IdentifierTable.h" 19193326Sed#include "clang/AST/NestedNameSpecifier.h" 20193326Sed#include "clang/AST/TemplateName.h" 21193326Sed#include "llvm/Support/Casting.h" 22193326Sed#include "llvm/ADT/APSInt.h" 23193326Sed#include "llvm/ADT/FoldingSet.h" 24193326Sed#include "llvm/ADT/PointerIntPair.h" 25193326Sed#include "llvm/ADT/PointerUnion.h" 26193326Sed 27193326Sedusing llvm::isa; 28193326Sedusing llvm::cast; 29193326Sedusing llvm::cast_or_null; 30193326Sedusing llvm::dyn_cast; 31193326Sedusing llvm::dyn_cast_or_null; 32193326Sednamespace clang { class Type; } 33193326Sed 34193326Sednamespace llvm { 35193326Sed template <typename T> 36193326Sed class PointerLikeTypeTraits; 37193326Sed template<> 38193326Sed class PointerLikeTypeTraits< ::clang::Type*> { 39193326Sed public: 40193326Sed static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 41193326Sed static inline ::clang::Type *getFromVoidPointer(void *P) { 42193326Sed return static_cast< ::clang::Type*>(P); 43193326Sed } 44193326Sed enum { NumLowBitsAvailable = 3 }; 45193326Sed }; 46193326Sed} 47193326Sed 48193326Sednamespace clang { 49193326Sed class ASTContext; 50193326Sed class TypedefDecl; 51193326Sed class TemplateDecl; 52193326Sed class TemplateTypeParmDecl; 53193326Sed class NonTypeTemplateParmDecl; 54193326Sed class TemplateTemplateParmDecl; 55193326Sed class TagDecl; 56193326Sed class RecordDecl; 57193326Sed class CXXRecordDecl; 58193326Sed class EnumDecl; 59193326Sed class FieldDecl; 60193326Sed class ObjCInterfaceDecl; 61193326Sed class ObjCProtocolDecl; 62193326Sed class ObjCMethodDecl; 63193326Sed class Expr; 64193326Sed class Stmt; 65193326Sed class SourceLocation; 66193326Sed class StmtIteratorBase; 67193326Sed class TemplateArgument; 68193326Sed class QualifiedNameType; 69193326Sed class PrintingPolicy; 70193326Sed 71193326Sed // Provide forward declarations for all of the *Type classes 72193326Sed#define TYPE(Class, Base) class Class##Type; 73193326Sed#include "clang/AST/TypeNodes.def" 74193326Sed 75193326Sed/// QualType - For efficiency, we don't store CVR-qualified types as nodes on 76193326Sed/// their own: instead each reference to a type stores the qualifiers. This 77193326Sed/// greatly reduces the number of nodes we need to allocate for types (for 78193326Sed/// example we only need one for 'int', 'const int', 'volatile int', 79193326Sed/// 'const volatile int', etc). 80193326Sed/// 81193326Sed/// As an added efficiency bonus, instead of making this a pair, we just store 82193326Sed/// the three bits we care about in the low bits of the pointer. To handle the 83193326Sed/// packing/unpacking, we make QualType be a simple wrapper class that acts like 84193326Sed/// a smart pointer. 85193326Sedclass QualType { 86193326Sed llvm::PointerIntPair<Type*, 3> Value; 87193326Sedpublic: 88193326Sed enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 89193326Sed Const = 0x1, 90193326Sed Restrict = 0x2, 91193326Sed Volatile = 0x4, 92193326Sed CVRFlags = Const|Restrict|Volatile 93193326Sed }; 94193326Sed 95193326Sed enum GCAttrTypes { 96193326Sed GCNone = 0, 97193326Sed Weak, 98193326Sed Strong 99193326Sed }; 100193326Sed 101193326Sed QualType() {} 102193326Sed 103193326Sed QualType(const Type *Ptr, unsigned Quals) 104193326Sed : Value(const_cast<Type*>(Ptr), Quals) {} 105193326Sed 106193326Sed unsigned getCVRQualifiers() const { return Value.getInt(); } 107193326Sed void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); } 108193326Sed Type *getTypePtr() const { return Value.getPointer(); } 109193326Sed 110193326Sed void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 111193326Sed static QualType getFromOpaquePtr(void *Ptr) { 112193326Sed QualType T; 113193326Sed T.Value.setFromOpaqueValue(Ptr); 114193326Sed return T; 115193326Sed } 116193326Sed 117193326Sed Type &operator*() const { 118193326Sed return *getTypePtr(); 119193326Sed } 120193326Sed 121193326Sed Type *operator->() const { 122193326Sed return getTypePtr(); 123193326Sed } 124193326Sed 125193326Sed /// isNull - Return true if this QualType doesn't point to a type yet. 126193326Sed bool isNull() const { 127193326Sed return getTypePtr() == 0; 128193326Sed } 129193326Sed 130193326Sed bool isConstQualified() const { 131193326Sed return (getCVRQualifiers() & Const) ? true : false; 132193326Sed } 133193326Sed bool isVolatileQualified() const { 134193326Sed return (getCVRQualifiers() & Volatile) ? true : false; 135193326Sed } 136193326Sed bool isRestrictQualified() const { 137193326Sed return (getCVRQualifiers() & Restrict) ? true : false; 138193326Sed } 139193326Sed 140193326Sed bool isConstant(ASTContext& Ctx) const; 141193326Sed 142193326Sed /// addConst/addVolatile/addRestrict - add the specified type qual to this 143193326Sed /// QualType. 144193326Sed void addConst() { Value.setInt(Value.getInt() | Const); } 145193326Sed void addVolatile() { Value.setInt(Value.getInt() | Volatile); } 146193326Sed void addRestrict() { Value.setInt(Value.getInt() | Restrict); } 147193326Sed 148193326Sed void removeConst() { Value.setInt(Value.getInt() & ~Const); } 149193326Sed void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); } 150193326Sed void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); } 151193326Sed 152193326Sed QualType getQualifiedType(unsigned TQs) const { 153193326Sed return QualType(getTypePtr(), TQs); 154193326Sed } 155193326Sed QualType getWithAdditionalQualifiers(unsigned TQs) const { 156193326Sed return QualType(getTypePtr(), TQs|getCVRQualifiers()); 157193326Sed } 158193326Sed 159193326Sed QualType withConst() const { return getWithAdditionalQualifiers(Const); } 160193326Sed QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);} 161193326Sed QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);} 162193326Sed 163193326Sed QualType getUnqualifiedType() const; 164193326Sed bool isMoreQualifiedThan(QualType Other) const; 165193326Sed bool isAtLeastAsQualifiedAs(QualType Other) const; 166193326Sed QualType getNonReferenceType() const; 167193326Sed 168193326Sed /// getDesugaredType - Return the specified type with any "sugar" removed from 169193326Sed /// the type. This takes off typedefs, typeof's etc. If the outer level of 170193326Sed /// the type is already concrete, it returns it unmodified. This is similar 171193326Sed /// to getting the canonical type, but it doesn't remove *all* typedefs. For 172193326Sed /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 173193326Sed /// concrete. 174193326Sed QualType getDesugaredType(bool ForDisplay = false) const; 175193326Sed 176193326Sed /// operator==/!= - Indicate whether the specified types and qualifiers are 177193326Sed /// identical. 178193326Sed bool operator==(const QualType &RHS) const { 179193326Sed return Value == RHS.Value; 180193326Sed } 181193326Sed bool operator!=(const QualType &RHS) const { 182193326Sed return Value != RHS.Value; 183193326Sed } 184193326Sed std::string getAsString() const; 185193326Sed 186193326Sed std::string getAsString(const PrintingPolicy &Policy) const { 187193326Sed std::string S; 188193326Sed getAsStringInternal(S, Policy); 189193326Sed return S; 190193326Sed } 191193326Sed void getAsStringInternal(std::string &Str, const PrintingPolicy &Policy) const; 192193326Sed 193193326Sed void dump(const char *s) const; 194193326Sed void dump() const; 195193326Sed 196193326Sed void Profile(llvm::FoldingSetNodeID &ID) const { 197193326Sed ID.AddPointer(getAsOpaquePtr()); 198193326Sed } 199193326Sed 200193326Sedpublic: 201193326Sed 202193326Sed /// getAddressSpace - Return the address space of this type. 203193326Sed inline unsigned getAddressSpace() const; 204193326Sed 205193326Sed /// GCAttrTypesAttr - Returns gc attribute of this type. 206193326Sed inline QualType::GCAttrTypes getObjCGCAttr() const; 207193326Sed 208193326Sed /// isObjCGCWeak true when Type is objc's weak. 209193326Sed bool isObjCGCWeak() const { 210193326Sed return getObjCGCAttr() == Weak; 211193326Sed } 212193326Sed 213193326Sed /// isObjCGCStrong true when Type is objc's strong. 214193326Sed bool isObjCGCStrong() const { 215193326Sed return getObjCGCAttr() == Strong; 216193326Sed } 217193326Sed}; 218193326Sed 219193326Sed} // end clang. 220193326Sed 221193326Sednamespace llvm { 222193326Sed/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 223193326Sed/// to a specific Type class. 224193326Sedtemplate<> struct simplify_type<const ::clang::QualType> { 225193326Sed typedef ::clang::Type* SimpleType; 226193326Sed static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 227193326Sed return Val.getTypePtr(); 228193326Sed } 229193326Sed}; 230193326Sedtemplate<> struct simplify_type< ::clang::QualType> 231193326Sed : public simplify_type<const ::clang::QualType> {}; 232193326Sed 233193326Sed// Teach SmallPtrSet that QualType is "basically a pointer". 234193326Sedtemplate<> 235193326Sedclass PointerLikeTypeTraits<clang::QualType> { 236193326Sedpublic: 237193326Sed static inline void *getAsVoidPointer(clang::QualType P) { 238193326Sed return P.getAsOpaquePtr(); 239193326Sed } 240193326Sed static inline clang::QualType getFromVoidPointer(void *P) { 241193326Sed return clang::QualType::getFromOpaquePtr(P); 242193326Sed } 243193326Sed // CVR qualifiers go in low bits. 244193326Sed enum { NumLowBitsAvailable = 0 }; 245193326Sed}; 246193326Sed} // end namespace llvm 247193326Sed 248193326Sednamespace clang { 249193326Sed 250193326Sed/// Type - This is the base class of the type hierarchy. A central concept 251193326Sed/// with types is that each type always has a canonical type. A canonical type 252193326Sed/// is the type with any typedef names stripped out of it or the types it 253193326Sed/// references. For example, consider: 254193326Sed/// 255193326Sed/// typedef int foo; 256193326Sed/// typedef foo* bar; 257193326Sed/// 'int *' 'foo *' 'bar' 258193326Sed/// 259193326Sed/// There will be a Type object created for 'int'. Since int is canonical, its 260193326Sed/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 261193326Sed/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 262193326Sed/// there is a PointerType that represents 'int*', which, like 'int', is 263193326Sed/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 264193326Sed/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 265193326Sed/// is also 'int*'. 266193326Sed/// 267193326Sed/// Non-canonical types are useful for emitting diagnostics, without losing 268193326Sed/// information about typedefs being used. Canonical types are useful for type 269193326Sed/// comparisons (they allow by-pointer equality tests) and useful for reasoning 270193326Sed/// about whether something has a particular form (e.g. is a function type), 271193326Sed/// because they implicitly, recursively, strip all typedefs out of a type. 272193326Sed/// 273193326Sed/// Types, once created, are immutable. 274193326Sed/// 275193326Sedclass Type { 276193326Sedpublic: 277193326Sed enum TypeClass { 278193326Sed#define TYPE(Class, Base) Class, 279193326Sed#define ABSTRACT_TYPE(Class, Base) 280193326Sed#include "clang/AST/TypeNodes.def" 281193326Sed TagFirst = Record, TagLast = Enum 282193326Sed }; 283193326Sed 284193326Sedprivate: 285193326Sed QualType CanonicalType; 286193326Sed 287193326Sed /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 288193326Sed bool Dependent : 1; 289193326Sed 290193326Sed /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 291193326Sed /// Note that this should stay at the end of the ivars for Type so that 292193326Sed /// subclasses can pack their bitfields into the same word. 293193326Sed unsigned TC : 5; 294193326Sed 295193326Sed Type(const Type&); // DO NOT IMPLEMENT. 296193326Sed void operator=(const Type&); // DO NOT IMPLEMENT. 297193326Sedprotected: 298193326Sed // silence VC++ warning C4355: 'this' : used in base member initializer list 299193326Sed Type *this_() { return this; } 300193326Sed Type(TypeClass tc, QualType Canonical, bool dependent) 301193326Sed : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 302193326Sed Dependent(dependent), TC(tc) {} 303193326Sed virtual ~Type() {} 304193326Sed virtual void Destroy(ASTContext& C); 305193326Sed friend class ASTContext; 306193326Sed 307193326Sedpublic: 308193326Sed TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 309193326Sed 310193326Sed bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 311193326Sed 312193326Sed /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 313193326Sed /// object types, function types, and incomplete types. 314193326Sed 315193326Sed /// \brief Determines whether the type describes an object in memory. 316193326Sed /// 317193326Sed /// Note that this definition of object type corresponds to the C++ 318193326Sed /// definition of object type, which includes incomplete types, as 319193326Sed /// opposed to the C definition (which does not include incomplete 320193326Sed /// types). 321193326Sed bool isObjectType() const; 322193326Sed 323193326Sed /// isIncompleteType - Return true if this is an incomplete type. 324193326Sed /// A type that can describe objects, but which lacks information needed to 325193326Sed /// determine its size (e.g. void, or a fwd declared struct). Clients of this 326193326Sed /// routine will need to determine if the size is actually required. 327193326Sed bool isIncompleteType() const; 328193326Sed 329193326Sed /// isIncompleteOrObjectType - Return true if this is an incomplete or object 330193326Sed /// type, in other words, not a function type. 331193326Sed bool isIncompleteOrObjectType() const { 332193326Sed return !isFunctionType(); 333193326Sed } 334193326Sed 335193326Sed /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 336193326Sed bool isPODType() const; 337193326Sed 338193326Sed /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 339193326Sed /// types that have a non-constant expression. This does not include "[]". 340193326Sed bool isVariablyModifiedType() const; 341193326Sed 342193326Sed /// Helper methods to distinguish type categories. All type predicates 343193326Sed /// operate on the canonical type, ignoring typedefs and qualifiers. 344193326Sed 345193326Sed /// isSpecificBuiltinType - Test for a particular builtin type. 346193326Sed bool isSpecificBuiltinType(unsigned K) const; 347193326Sed 348193326Sed /// isIntegerType() does *not* include complex integers (a GCC extension). 349193326Sed /// isComplexIntegerType() can be used to test for complex integers. 350193326Sed bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 351193326Sed bool isEnumeralType() const; 352193326Sed bool isBooleanType() const; 353193326Sed bool isCharType() const; 354193326Sed bool isWideCharType() const; 355193326Sed bool isIntegralType() const; 356193326Sed 357193326Sed /// Floating point categories. 358193326Sed bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 359193326Sed /// isComplexType() does *not* include complex integers (a GCC extension). 360193326Sed /// isComplexIntegerType() can be used to test for complex integers. 361193326Sed bool isComplexType() const; // C99 6.2.5p11 (complex) 362193326Sed bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 363193326Sed bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 364193326Sed bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 365193326Sed bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 366193326Sed bool isVoidType() const; // C99 6.2.5p19 367193326Sed bool isDerivedType() const; // C99 6.2.5p20 368193326Sed bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 369193326Sed bool isAggregateType() const; 370193326Sed 371193326Sed // Type Predicates: Check to see if this type is structurally the specified 372193326Sed // type, ignoring typedefs and qualifiers. 373193326Sed bool isFunctionType() const; 374193326Sed bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; } 375193326Sed bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; } 376193326Sed bool isPointerType() const; 377193326Sed bool isBlockPointerType() const; 378193326Sed bool isReferenceType() const; 379193326Sed bool isLValueReferenceType() const; 380193326Sed bool isRValueReferenceType() const; 381193326Sed bool isFunctionPointerType() const; 382193326Sed bool isMemberPointerType() const; 383193326Sed bool isMemberFunctionPointerType() const; 384193326Sed bool isArrayType() const; 385193326Sed bool isConstantArrayType() const; 386193326Sed bool isIncompleteArrayType() const; 387193326Sed bool isVariableArrayType() const; 388193326Sed bool isDependentSizedArrayType() const; 389193326Sed bool isRecordType() const; 390193326Sed bool isClassType() const; 391193326Sed bool isStructureType() const; 392193326Sed bool isUnionType() const; 393193326Sed bool isComplexIntegerType() const; // GCC _Complex integer type. 394193326Sed bool isVectorType() const; // GCC vector type. 395193326Sed bool isExtVectorType() const; // Extended vector type. 396194613Sed bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 397193326Sed bool isObjCInterfaceType() const; // NSString or NSString<foo> 398193326Sed bool isObjCQualifiedInterfaceType() const; // NSString<foo> 399193326Sed bool isObjCQualifiedIdType() const; // id<foo> 400193326Sed bool isTemplateTypeParmType() const; // C++ template type parameter 401193326Sed bool isNullPtrType() const; // C++0x nullptr_t 402193326Sed 403193326Sed /// isDependentType - Whether this type is a dependent type, meaning 404193326Sed /// that its definition somehow depends on a template parameter 405193326Sed /// (C++ [temp.dep.type]). 406193326Sed bool isDependentType() const { return Dependent; } 407193326Sed bool isOverloadableType() const; 408193326Sed 409193326Sed /// hasPointerRepresentation - Whether this type is represented 410193326Sed /// natively as a pointer; this includes pointers, references, block 411193326Sed /// pointers, and Objective-C interface, qualified id, and qualified 412193326Sed /// interface types, as well as nullptr_t. 413193326Sed bool hasPointerRepresentation() const; 414193326Sed 415193326Sed /// hasObjCPointerRepresentation - Whether this type can represent 416193326Sed /// an objective pointer type for the purpose of GC'ability 417193326Sed bool hasObjCPointerRepresentation() const; 418193326Sed 419193326Sed // Type Checking Functions: Check to see if this type is structurally the 420193326Sed // specified type, ignoring typedefs and qualifiers, and return a pointer to 421193326Sed // the best type we can. 422193326Sed const BuiltinType *getAsBuiltinType() const; 423193326Sed const FunctionType *getAsFunctionType() const; 424193326Sed const FunctionNoProtoType *getAsFunctionNoProtoType() const; 425193326Sed const FunctionProtoType *getAsFunctionProtoType() const; 426193326Sed const PointerType *getAsPointerType() const; 427193326Sed const BlockPointerType *getAsBlockPointerType() const; 428193326Sed const ReferenceType *getAsReferenceType() const; 429193326Sed const LValueReferenceType *getAsLValueReferenceType() const; 430193326Sed const RValueReferenceType *getAsRValueReferenceType() const; 431193326Sed const MemberPointerType *getAsMemberPointerType() const; 432193326Sed const TagType *getAsTagType() const; 433193326Sed const RecordType *getAsRecordType() const; 434193326Sed const RecordType *getAsStructureType() const; 435193326Sed /// NOTE: getAs*ArrayType are methods on ASTContext. 436193326Sed const TypedefType *getAsTypedefType() const; 437193326Sed const RecordType *getAsUnionType() const; 438193326Sed const EnumType *getAsEnumType() const; 439193326Sed const VectorType *getAsVectorType() const; // GCC vector type. 440193326Sed const ComplexType *getAsComplexType() const; 441193326Sed const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 442193326Sed const ExtVectorType *getAsExtVectorType() const; // Extended vector type. 443194613Sed const ObjCObjectPointerType *getAsObjCObjectPointerType() const; 444193326Sed const ObjCInterfaceType *getAsObjCInterfaceType() const; 445193326Sed const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const; 446194613Sed const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 447193326Sed const TemplateTypeParmType *getAsTemplateTypeParmType() const; 448193326Sed 449193326Sed const TemplateSpecializationType * 450193326Sed getAsTemplateSpecializationType() const; 451193326Sed 452193326Sed /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 453193326Sed /// interface, return the interface type, otherwise return null. 454193326Sed const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 455193326Sed 456193326Sed /// getArrayElementTypeNoTypeQual - If this is an array type, return the 457193326Sed /// element type of the array, potentially with type qualifiers missing. 458193326Sed /// This method should never be used when type qualifiers are meaningful. 459193326Sed const Type *getArrayElementTypeNoTypeQual() const; 460193326Sed 461193326Sed /// getDesugaredType - Return the specified type with any "sugar" removed from 462193326Sed /// the type. This takes off typedefs, typeof's etc. If the outer level of 463193326Sed /// the type is already concrete, it returns it unmodified. This is similar 464193326Sed /// to getting the canonical type, but it doesn't remove *all* typedefs. For 465193326Sed /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 466193326Sed /// concrete. 467193326Sed QualType getDesugaredType(bool ForDisplay = false) const; 468193326Sed 469193326Sed /// More type predicates useful for type checking/promotion 470193326Sed bool isPromotableIntegerType() const; // C99 6.3.1.1p2 471193326Sed 472193326Sed /// isSignedIntegerType - Return true if this is an integer type that is 473193326Sed /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 474193326Sed /// an enum decl which has a signed representation, or a vector of signed 475193326Sed /// integer element type. 476193326Sed bool isSignedIntegerType() const; 477193326Sed 478193326Sed /// isUnsignedIntegerType - Return true if this is an integer type that is 479193326Sed /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 480193326Sed /// decl which has an unsigned representation, or a vector of unsigned integer 481193326Sed /// element type. 482193326Sed bool isUnsignedIntegerType() const; 483193326Sed 484193326Sed /// isConstantSizeType - Return true if this is not a variable sized type, 485193326Sed /// according to the rules of C99 6.7.5p3. It is not legal to call this on 486193326Sed /// incomplete types. 487193326Sed bool isConstantSizeType() const; 488193326Sed 489193326Sed /// isSpecifierType - Returns true if this type can be represented by some 490193326Sed /// set of type specifiers. 491193326Sed bool isSpecifierType() const; 492193326Sed 493193326Sed QualType getCanonicalTypeInternal() const { return CanonicalType; } 494193326Sed void dump() const; 495193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const = 0; 496193326Sed static bool classof(const Type *) { return true; } 497193326Sed}; 498193326Sed 499193326Sed/// ExtQualType - TR18037 (C embedded extensions) 6.2.5p26 500193326Sed/// This supports all kinds of type attributes; including, 501193326Sed/// address space qualified types, objective-c's __weak and 502193326Sed/// __strong attributes. 503193326Sed/// 504193326Sedclass ExtQualType : public Type, public llvm::FoldingSetNode { 505193326Sed /// BaseType - This is the underlying type that this qualifies. All CVR 506193326Sed /// qualifiers are stored on the QualType that references this type, so we 507193326Sed /// can't have any here. 508193326Sed Type *BaseType; 509193326Sed 510193326Sed /// Address Space ID - The address space ID this type is qualified with. 511193326Sed unsigned AddressSpace; 512193326Sed /// GC __weak/__strong attributes 513193326Sed QualType::GCAttrTypes GCAttrType; 514193326Sed 515193326Sed ExtQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace, 516193326Sed QualType::GCAttrTypes gcAttr) : 517193326Sed Type(ExtQual, CanonicalPtr, Base->isDependentType()), BaseType(Base), 518193326Sed AddressSpace(AddrSpace), GCAttrType(gcAttr) { 519193326Sed assert(!isa<ExtQualType>(BaseType) && 520193326Sed "Cannot have ExtQualType of ExtQualType"); 521193326Sed } 522193326Sed friend class ASTContext; // ASTContext creates these. 523193326Sedpublic: 524193326Sed Type *getBaseType() const { return BaseType; } 525193326Sed QualType::GCAttrTypes getObjCGCAttr() const { return GCAttrType; } 526193326Sed unsigned getAddressSpace() const { return AddressSpace; } 527193326Sed 528193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 529193326Sed 530193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 531193326Sed Profile(ID, getBaseType(), AddressSpace, GCAttrType); 532193326Sed } 533193326Sed static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 534193326Sed unsigned AddrSpace, QualType::GCAttrTypes gcAttr) { 535193326Sed ID.AddPointer(Base); 536193326Sed ID.AddInteger(AddrSpace); 537193326Sed ID.AddInteger(gcAttr); 538193326Sed } 539193326Sed 540193326Sed static bool classof(const Type *T) { return T->getTypeClass() == ExtQual; } 541193326Sed static bool classof(const ExtQualType *) { return true; } 542193326Sed}; 543193326Sed 544193326Sed 545193326Sed/// BuiltinType - This class is used for builtin types like 'int'. Builtin 546193326Sed/// types are always canonical and have a literal name field. 547193326Sedclass BuiltinType : public Type { 548193326Sedpublic: 549193326Sed enum Kind { 550193326Sed Void, 551193326Sed 552193326Sed Bool, // This is bool and/or _Bool. 553193326Sed Char_U, // This is 'char' for targets where char is unsigned. 554193326Sed UChar, // This is explicitly qualified unsigned char. 555193326Sed UShort, 556193326Sed UInt, 557193326Sed ULong, 558193326Sed ULongLong, 559193326Sed UInt128, // __uint128_t 560193326Sed 561193326Sed Char_S, // This is 'char' for targets where char is signed. 562193326Sed SChar, // This is explicitly qualified signed char. 563193326Sed WChar, // This is 'wchar_t' for C++. 564193326Sed Short, 565193326Sed Int, 566193326Sed Long, 567193326Sed LongLong, 568193326Sed Int128, // __int128_t 569193326Sed 570193326Sed Float, Double, LongDouble, 571193326Sed 572193326Sed NullPtr, // This is the type of C++0x 'nullptr'. 573193326Sed 574193326Sed Overload, // This represents the type of an overloaded function declaration. 575195099Sed Dependent, // This represents the type of a type-dependent expression. 576195099Sed 577195099Sed UndeducedAuto // In C++0x, this represents the type of an auto variable 578195099Sed // that has not been deduced yet. 579193326Sed }; 580193326Sedprivate: 581193326Sed Kind TypeKind; 582193326Sedpublic: 583193326Sed BuiltinType(Kind K) 584193326Sed : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 585193326Sed TypeKind(K) {} 586193326Sed 587193326Sed Kind getKind() const { return TypeKind; } 588193326Sed const char *getName(bool CPlusPlus) const; 589193326Sed 590193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 591193326Sed 592193326Sed static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 593193326Sed static bool classof(const BuiltinType *) { return true; } 594193326Sed}; 595193326Sed 596193326Sed/// FixedWidthIntType - Used for arbitrary width types that we either don't 597193326Sed/// want to or can't map to named integer types. These always have a lower 598193326Sed/// integer rank than builtin types of the same width. 599193326Sedclass FixedWidthIntType : public Type { 600193326Sedprivate: 601193326Sed unsigned Width; 602193326Sed bool Signed; 603193326Sedpublic: 604193326Sed FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false), 605193326Sed Width(W), Signed(S) {} 606193326Sed 607193326Sed unsigned getWidth() const { return Width; } 608193326Sed bool isSigned() const { return Signed; } 609193326Sed const char *getName() const; 610193326Sed 611193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 612193326Sed 613193326Sed static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; } 614193326Sed static bool classof(const FixedWidthIntType *) { return true; } 615193326Sed}; 616193326Sed 617193326Sed/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 618193326Sed/// types (_Complex float etc) as well as the GCC integer complex extensions. 619193326Sed/// 620193326Sedclass ComplexType : public Type, public llvm::FoldingSetNode { 621193326Sed QualType ElementType; 622193326Sed ComplexType(QualType Element, QualType CanonicalPtr) : 623193326Sed Type(Complex, CanonicalPtr, Element->isDependentType()), 624193326Sed ElementType(Element) { 625193326Sed } 626193326Sed friend class ASTContext; // ASTContext creates these. 627193326Sedpublic: 628193326Sed QualType getElementType() const { return ElementType; } 629193326Sed 630193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 631193326Sed 632193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 633193326Sed Profile(ID, getElementType()); 634193326Sed } 635193326Sed static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 636193326Sed ID.AddPointer(Element.getAsOpaquePtr()); 637193326Sed } 638193326Sed 639193326Sed static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 640193326Sed static bool classof(const ComplexType *) { return true; } 641193326Sed}; 642193326Sed 643193326Sed/// PointerType - C99 6.7.5.1 - Pointer Declarators. 644193326Sed/// 645193326Sedclass PointerType : public Type, public llvm::FoldingSetNode { 646193326Sed QualType PointeeType; 647193326Sed 648193326Sed PointerType(QualType Pointee, QualType CanonicalPtr) : 649193326Sed Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 650193326Sed } 651193326Sed friend class ASTContext; // ASTContext creates these. 652193326Sedpublic: 653193326Sed 654193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 655193326Sed 656193326Sed QualType getPointeeType() const { return PointeeType; } 657193326Sed 658193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 659193326Sed Profile(ID, getPointeeType()); 660193326Sed } 661193326Sed static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 662193326Sed ID.AddPointer(Pointee.getAsOpaquePtr()); 663193326Sed } 664193326Sed 665193326Sed static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 666193326Sed static bool classof(const PointerType *) { return true; } 667193326Sed}; 668193326Sed 669193326Sed/// BlockPointerType - pointer to a block type. 670193326Sed/// This type is to represent types syntactically represented as 671193326Sed/// "void (^)(int)", etc. Pointee is required to always be a function type. 672193326Sed/// 673193326Sedclass BlockPointerType : public Type, public llvm::FoldingSetNode { 674193326Sed QualType PointeeType; // Block is some kind of pointer type 675193326Sed BlockPointerType(QualType Pointee, QualType CanonicalCls) : 676193326Sed Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 677193326Sed PointeeType(Pointee) { 678193326Sed } 679193326Sed friend class ASTContext; // ASTContext creates these. 680193326Sedpublic: 681193326Sed 682193326Sed // Get the pointee type. Pointee is required to always be a function type. 683193326Sed QualType getPointeeType() const { return PointeeType; } 684193326Sed 685193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 686193326Sed 687193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 688193326Sed Profile(ID, getPointeeType()); 689193326Sed } 690193326Sed static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 691193326Sed ID.AddPointer(Pointee.getAsOpaquePtr()); 692193326Sed } 693193326Sed 694193326Sed static bool classof(const Type *T) { 695193326Sed return T->getTypeClass() == BlockPointer; 696193326Sed } 697193326Sed static bool classof(const BlockPointerType *) { return true; } 698193326Sed}; 699193326Sed 700193326Sed/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 701193326Sed/// 702193326Sedclass ReferenceType : public Type, public llvm::FoldingSetNode { 703193326Sed QualType PointeeType; 704193326Sed 705193326Sedprotected: 706193326Sed ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) : 707193326Sed Type(tc, CanonicalRef, Referencee->isDependentType()), 708193326Sed PointeeType(Referencee) { 709193326Sed } 710193326Sedpublic: 711193326Sed QualType getPointeeType() const { return PointeeType; } 712193326Sed 713193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 714193326Sed Profile(ID, getPointeeType()); 715193326Sed } 716193326Sed static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 717193326Sed ID.AddPointer(Referencee.getAsOpaquePtr()); 718193326Sed } 719193326Sed 720193326Sed static bool classof(const Type *T) { 721193326Sed return T->getTypeClass() == LValueReference || 722193326Sed T->getTypeClass() == RValueReference; 723193326Sed } 724193326Sed static bool classof(const ReferenceType *) { return true; } 725193326Sed}; 726193326Sed 727193326Sed/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 728193326Sed/// 729193326Sedclass LValueReferenceType : public ReferenceType { 730193326Sed LValueReferenceType(QualType Referencee, QualType CanonicalRef) : 731193326Sed ReferenceType(LValueReference, Referencee, CanonicalRef) { 732193326Sed } 733193326Sed friend class ASTContext; // ASTContext creates these 734193326Sedpublic: 735193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 736193326Sed 737193326Sed static bool classof(const Type *T) { 738193326Sed return T->getTypeClass() == LValueReference; 739193326Sed } 740193326Sed static bool classof(const LValueReferenceType *) { return true; } 741193326Sed}; 742193326Sed 743193326Sed/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 744193326Sed/// 745193326Sedclass RValueReferenceType : public ReferenceType { 746193326Sed RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 747193326Sed ReferenceType(RValueReference, Referencee, CanonicalRef) { 748193326Sed } 749193326Sed friend class ASTContext; // ASTContext creates these 750193326Sedpublic: 751193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 752193326Sed 753193326Sed static bool classof(const Type *T) { 754193326Sed return T->getTypeClass() == RValueReference; 755193326Sed } 756193326Sed static bool classof(const RValueReferenceType *) { return true; } 757193326Sed}; 758193326Sed 759193326Sed/// MemberPointerType - C++ 8.3.3 - Pointers to members 760193326Sed/// 761193326Sedclass MemberPointerType : public Type, public llvm::FoldingSetNode { 762193326Sed QualType PointeeType; 763193326Sed /// The class of which the pointee is a member. Must ultimately be a 764193326Sed /// RecordType, but could be a typedef or a template parameter too. 765193326Sed const Type *Class; 766193326Sed 767193326Sed MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 768193326Sed Type(MemberPointer, CanonicalPtr, 769193326Sed Cls->isDependentType() || Pointee->isDependentType()), 770193326Sed PointeeType(Pointee), Class(Cls) { 771193326Sed } 772193326Sed friend class ASTContext; // ASTContext creates these. 773193326Sedpublic: 774193326Sed 775193326Sed QualType getPointeeType() const { return PointeeType; } 776193326Sed 777193326Sed const Type *getClass() const { return Class; } 778193326Sed 779193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 780193326Sed 781193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 782193326Sed Profile(ID, getPointeeType(), getClass()); 783193326Sed } 784193326Sed static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 785193326Sed const Type *Class) { 786193326Sed ID.AddPointer(Pointee.getAsOpaquePtr()); 787193326Sed ID.AddPointer(Class); 788193326Sed } 789193326Sed 790193326Sed static bool classof(const Type *T) { 791193326Sed return T->getTypeClass() == MemberPointer; 792193326Sed } 793193326Sed static bool classof(const MemberPointerType *) { return true; } 794193326Sed}; 795193326Sed 796193326Sed/// ArrayType - C99 6.7.5.2 - Array Declarators. 797193326Sed/// 798193326Sedclass ArrayType : public Type, public llvm::FoldingSetNode { 799193326Sedpublic: 800193326Sed /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 801193326Sed /// an array with a static size (e.g. int X[static 4]), or an array 802193326Sed /// with a star size (e.g. int X[*]). 803193326Sed /// 'static' is only allowed on function parameters. 804193326Sed enum ArraySizeModifier { 805193326Sed Normal, Static, Star 806193326Sed }; 807193326Sedprivate: 808193326Sed /// ElementType - The element type of the array. 809193326Sed QualType ElementType; 810193326Sed 811193326Sed // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 812193326Sed /// NOTE: These fields are packed into the bitfields space in the Type class. 813193326Sed unsigned SizeModifier : 2; 814193326Sed 815193326Sed /// IndexTypeQuals - Capture qualifiers in declarations like: 816193326Sed /// 'int X[static restrict 4]'. For function parameters only. 817193326Sed unsigned IndexTypeQuals : 3; 818193326Sed 819193326Sedprotected: 820193326Sed // C++ [temp.dep.type]p1: 821193326Sed // A type is dependent if it is... 822193326Sed // - an array type constructed from any dependent type or whose 823193326Sed // size is specified by a constant expression that is 824193326Sed // value-dependent, 825193326Sed ArrayType(TypeClass tc, QualType et, QualType can, 826193326Sed ArraySizeModifier sm, unsigned tq) 827193326Sed : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 828193326Sed ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 829193326Sed 830193326Sed friend class ASTContext; // ASTContext creates these. 831193326Sedpublic: 832193326Sed QualType getElementType() const { return ElementType; } 833193326Sed ArraySizeModifier getSizeModifier() const { 834193326Sed return ArraySizeModifier(SizeModifier); 835193326Sed } 836193326Sed unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 837193326Sed 838193326Sed static bool classof(const Type *T) { 839193326Sed return T->getTypeClass() == ConstantArray || 840193326Sed T->getTypeClass() == VariableArray || 841193326Sed T->getTypeClass() == IncompleteArray || 842193326Sed T->getTypeClass() == DependentSizedArray; 843193326Sed } 844193326Sed static bool classof(const ArrayType *) { return true; } 845193326Sed}; 846193326Sed 847193326Sed/// ConstantArrayType - This class represents C arrays with a specified constant 848193326Sed/// size. For example 'int A[100]' has ConstantArrayType where the element type 849193326Sed/// is 'int' and the size is 100. 850193326Sedclass ConstantArrayType : public ArrayType { 851193326Sed llvm::APInt Size; // Allows us to unique the type. 852193326Sed 853193326Sed ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 854193326Sed ArraySizeModifier sm, unsigned tq) 855193326Sed : ArrayType(ConstantArray, et, can, sm, tq), Size(size) {} 856193326Sed friend class ASTContext; // ASTContext creates these. 857193326Sedpublic: 858193326Sed const llvm::APInt &getSize() const { return Size; } 859193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 860193326Sed 861193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 862193326Sed Profile(ID, getElementType(), getSize(), 863193326Sed getSizeModifier(), getIndexTypeQualifier()); 864193326Sed } 865193326Sed static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 866193326Sed const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 867193326Sed unsigned TypeQuals) { 868193326Sed ID.AddPointer(ET.getAsOpaquePtr()); 869193326Sed ID.AddInteger(ArraySize.getZExtValue()); 870193326Sed ID.AddInteger(SizeMod); 871193326Sed ID.AddInteger(TypeQuals); 872193326Sed } 873193326Sed static bool classof(const Type *T) { 874193326Sed return T->getTypeClass() == ConstantArray; 875193326Sed } 876193326Sed static bool classof(const ConstantArrayType *) { return true; } 877193326Sed}; 878193326Sed 879193326Sed/// IncompleteArrayType - This class represents C arrays with an unspecified 880193326Sed/// size. For example 'int A[]' has an IncompleteArrayType where the element 881193326Sed/// type is 'int' and the size is unspecified. 882193326Sedclass IncompleteArrayType : public ArrayType { 883193326Sed IncompleteArrayType(QualType et, QualType can, 884193326Sed ArraySizeModifier sm, unsigned tq) 885193326Sed : ArrayType(IncompleteArray, et, can, sm, tq) {} 886193326Sed friend class ASTContext; // ASTContext creates these. 887193326Sedpublic: 888193326Sed 889193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 890193326Sed 891193326Sed static bool classof(const Type *T) { 892193326Sed return T->getTypeClass() == IncompleteArray; 893193326Sed } 894193326Sed static bool classof(const IncompleteArrayType *) { return true; } 895193326Sed 896193326Sed friend class StmtIteratorBase; 897193326Sed 898193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 899193326Sed Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier()); 900193326Sed } 901193326Sed 902193326Sed static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 903193326Sed ArraySizeModifier SizeMod, unsigned TypeQuals) { 904193326Sed ID.AddPointer(ET.getAsOpaquePtr()); 905193326Sed ID.AddInteger(SizeMod); 906193326Sed ID.AddInteger(TypeQuals); 907193326Sed } 908193326Sed}; 909193326Sed 910193326Sed/// VariableArrayType - This class represents C arrays with a specified size 911193326Sed/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 912193326Sed/// Since the size expression is an arbitrary expression, we store it as such. 913193326Sed/// 914193326Sed/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 915193326Sed/// should not be: two lexically equivalent variable array types could mean 916193326Sed/// different things, for example, these variables do not have the same type 917193326Sed/// dynamically: 918193326Sed/// 919193326Sed/// void foo(int x) { 920193326Sed/// int Y[x]; 921193326Sed/// ++x; 922193326Sed/// int Z[x]; 923193326Sed/// } 924193326Sed/// 925193326Sedclass VariableArrayType : public ArrayType { 926193326Sed /// SizeExpr - An assignment expression. VLA's are only permitted within 927193326Sed /// a function block. 928193326Sed Stmt *SizeExpr; 929193326Sed 930193326Sed VariableArrayType(QualType et, QualType can, Expr *e, 931193326Sed ArraySizeModifier sm, unsigned tq) 932193326Sed : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 933193326Sed friend class ASTContext; // ASTContext creates these. 934193326Sed virtual void Destroy(ASTContext& C); 935193326Sed 936193326Sedpublic: 937193326Sed Expr *getSizeExpr() const { 938193326Sed // We use C-style casts instead of cast<> here because we do not wish 939193326Sed // to have a dependency of Type.h on Stmt.h/Expr.h. 940193326Sed return (Expr*) SizeExpr; 941193326Sed } 942193326Sed 943193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 944193326Sed 945193326Sed static bool classof(const Type *T) { 946193326Sed return T->getTypeClass() == VariableArray; 947193326Sed } 948193326Sed static bool classof(const VariableArrayType *) { return true; } 949193326Sed 950193326Sed friend class StmtIteratorBase; 951193326Sed 952193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 953193326Sed assert(0 && "Cannnot unique VariableArrayTypes."); 954193326Sed } 955193326Sed}; 956193326Sed 957193326Sed/// DependentSizedArrayType - This type represents an array type in 958193326Sed/// C++ whose size is a value-dependent expression. For example: 959193326Sed/// @code 960193326Sed/// template<typename T, int Size> 961193326Sed/// class array { 962193326Sed/// T data[Size]; 963193326Sed/// }; 964193326Sed/// @endcode 965193326Sed/// For these types, we won't actually know what the array bound is 966193326Sed/// until template instantiation occurs, at which point this will 967193326Sed/// become either a ConstantArrayType or a VariableArrayType. 968193326Sedclass DependentSizedArrayType : public ArrayType { 969193326Sed /// SizeExpr - An assignment expression that will instantiate to the 970193326Sed /// size of the array. 971193326Sed Stmt *SizeExpr; 972193326Sed 973193326Sed DependentSizedArrayType(QualType et, QualType can, Expr *e, 974193326Sed ArraySizeModifier sm, unsigned tq) 975193326Sed : ArrayType(DependentSizedArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 976193326Sed friend class ASTContext; // ASTContext creates these. 977193326Sed virtual void Destroy(ASTContext& C); 978193326Sed 979193326Sedpublic: 980193326Sed Expr *getSizeExpr() const { 981193326Sed // We use C-style casts instead of cast<> here because we do not wish 982193326Sed // to have a dependency of Type.h on Stmt.h/Expr.h. 983193326Sed return (Expr*) SizeExpr; 984193326Sed } 985193326Sed 986193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 987193326Sed 988193326Sed static bool classof(const Type *T) { 989193326Sed return T->getTypeClass() == DependentSizedArray; 990193326Sed } 991193326Sed static bool classof(const DependentSizedArrayType *) { return true; } 992193326Sed 993193326Sed friend class StmtIteratorBase; 994193326Sed 995193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 996193326Sed assert(0 && "Cannnot unique DependentSizedArrayTypes."); 997193326Sed } 998193326Sed}; 999193326Sed 1000194613Sed/// DependentSizedExtVectorType - This type represent an extended vector type 1001194613Sed/// where either the type or size is dependent. For example: 1002194613Sed/// @code 1003194613Sed/// template<typename T, int Size> 1004194613Sed/// class vector { 1005194613Sed/// typedef T __attribute__((ext_vector_type(Size))) type; 1006194613Sed/// } 1007194613Sed/// @endcode 1008194613Sedclass DependentSizedExtVectorType : public Type { 1009194613Sed Expr *SizeExpr; 1010194613Sed /// ElementType - The element type of the array. 1011194613Sed QualType ElementType; 1012194613Sed SourceLocation loc; 1013194613Sed 1014194613Sed DependentSizedExtVectorType(QualType ElementType, QualType can, 1015194613Sed Expr *SizeExpr, SourceLocation loc) 1016194613Sed : Type (DependentSizedExtVector, can, true), 1017194613Sed SizeExpr(SizeExpr), ElementType(ElementType), loc(loc) {} 1018194613Sed friend class ASTContext; 1019194613Sed virtual void Destroy(ASTContext& C); 1020194613Sed 1021194613Sedpublic: 1022194613Sed const Expr *getSizeExpr() const { return SizeExpr; } 1023194613Sed QualType getElementType() const { return ElementType; } 1024194613Sed SourceLocation getAttributeLoc() const { return loc; } 1025194613Sed 1026194613Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1027194613Sed 1028194613Sed static bool classof(const Type *T) { 1029194613Sed return T->getTypeClass() == DependentSizedExtVector; 1030194613Sed } 1031194613Sed static bool classof(const DependentSizedExtVectorType *) { return true; } 1032194613Sed}; 1033194613Sed 1034194613Sed 1035193326Sed/// VectorType - GCC generic vector type. This type is created using 1036193326Sed/// __attribute__((vector_size(n)), where "n" specifies the vector size in 1037193326Sed/// bytes. Since the constructor takes the number of vector elements, the 1038193326Sed/// client is responsible for converting the size into the number of elements. 1039193326Sedclass VectorType : public Type, public llvm::FoldingSetNode { 1040193326Sedprotected: 1041193326Sed /// ElementType - The element type of the vector. 1042193326Sed QualType ElementType; 1043193326Sed 1044193326Sed /// NumElements - The number of elements in the vector. 1045193326Sed unsigned NumElements; 1046193326Sed 1047193326Sed VectorType(QualType vecType, unsigned nElements, QualType canonType) : 1048193326Sed Type(Vector, canonType, vecType->isDependentType()), 1049193326Sed ElementType(vecType), NumElements(nElements) {} 1050193326Sed VectorType(TypeClass tc, QualType vecType, unsigned nElements, 1051193326Sed QualType canonType) 1052193326Sed : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 1053193326Sed NumElements(nElements) {} 1054193326Sed friend class ASTContext; // ASTContext creates these. 1055193326Sedpublic: 1056193326Sed 1057193326Sed QualType getElementType() const { return ElementType; } 1058193326Sed unsigned getNumElements() const { return NumElements; } 1059193326Sed 1060193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1061193326Sed 1062193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 1063193326Sed Profile(ID, getElementType(), getNumElements(), getTypeClass()); 1064193326Sed } 1065193326Sed static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 1066193326Sed unsigned NumElements, TypeClass TypeClass) { 1067193326Sed ID.AddPointer(ElementType.getAsOpaquePtr()); 1068193326Sed ID.AddInteger(NumElements); 1069193326Sed ID.AddInteger(TypeClass); 1070193326Sed } 1071193326Sed static bool classof(const Type *T) { 1072193326Sed return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 1073193326Sed } 1074193326Sed static bool classof(const VectorType *) { return true; } 1075193326Sed}; 1076193326Sed 1077193326Sed/// ExtVectorType - Extended vector type. This type is created using 1078193326Sed/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1079193326Sed/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1080193326Sed/// class enables syntactic extensions, like Vector Components for accessing 1081193326Sed/// points, colors, and textures (modeled after OpenGL Shading Language). 1082193326Sedclass ExtVectorType : public VectorType { 1083193326Sed ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1084193326Sed VectorType(ExtVector, vecType, nElements, canonType) {} 1085193326Sed friend class ASTContext; // ASTContext creates these. 1086193326Sedpublic: 1087193326Sed static int getPointAccessorIdx(char c) { 1088193326Sed switch (c) { 1089193326Sed default: return -1; 1090193326Sed case 'x': return 0; 1091193326Sed case 'y': return 1; 1092193326Sed case 'z': return 2; 1093193326Sed case 'w': return 3; 1094193326Sed } 1095193326Sed } 1096193326Sed static int getNumericAccessorIdx(char c) { 1097193326Sed switch (c) { 1098193326Sed default: return -1; 1099193326Sed case '0': return 0; 1100193326Sed case '1': return 1; 1101193326Sed case '2': return 2; 1102193326Sed case '3': return 3; 1103193326Sed case '4': return 4; 1104193326Sed case '5': return 5; 1105193326Sed case '6': return 6; 1106193326Sed case '7': return 7; 1107193326Sed case '8': return 8; 1108193326Sed case '9': return 9; 1109195099Sed case 'A': 1110193326Sed case 'a': return 10; 1111195099Sed case 'B': 1112193326Sed case 'b': return 11; 1113195099Sed case 'C': 1114193326Sed case 'c': return 12; 1115195099Sed case 'D': 1116193326Sed case 'd': return 13; 1117195099Sed case 'E': 1118193326Sed case 'e': return 14; 1119195099Sed case 'F': 1120193326Sed case 'f': return 15; 1121193326Sed } 1122193326Sed } 1123193326Sed 1124193326Sed static int getAccessorIdx(char c) { 1125193326Sed if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1126193326Sed return getNumericAccessorIdx(c); 1127193326Sed } 1128193326Sed 1129193326Sed bool isAccessorWithinNumElements(char c) const { 1130193326Sed if (int idx = getAccessorIdx(c)+1) 1131193326Sed return unsigned(idx-1) < NumElements; 1132193326Sed return false; 1133193326Sed } 1134193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1135193326Sed 1136193326Sed static bool classof(const Type *T) { 1137193326Sed return T->getTypeClass() == ExtVector; 1138193326Sed } 1139193326Sed static bool classof(const ExtVectorType *) { return true; } 1140193326Sed}; 1141193326Sed 1142193326Sed/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 1143193326Sed/// class of FunctionNoProtoType and FunctionProtoType. 1144193326Sed/// 1145193326Sedclass FunctionType : public Type { 1146193326Sed /// SubClassData - This field is owned by the subclass, put here to pack 1147193326Sed /// tightly with the ivars in Type. 1148193326Sed bool SubClassData : 1; 1149193326Sed 1150193326Sed /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1151193326Sed /// other bitfields. 1152193326Sed /// The qualifiers are part of FunctionProtoType because... 1153193326Sed /// 1154193326Sed /// C++ 8.3.5p4: The return type, the parameter type list and the 1155193326Sed /// cv-qualifier-seq, [...], are part of the function type. 1156193326Sed /// 1157193326Sed unsigned TypeQuals : 3; 1158193326Sed 1159193326Sed // The type returned by the function. 1160193326Sed QualType ResultType; 1161193326Sedprotected: 1162193326Sed FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 1163193326Sed unsigned typeQuals, QualType Canonical, bool Dependent) 1164193326Sed : Type(tc, Canonical, Dependent), 1165193326Sed SubClassData(SubclassInfo), TypeQuals(typeQuals), ResultType(res) {} 1166193326Sed bool getSubClassData() const { return SubClassData; } 1167193326Sed unsigned getTypeQuals() const { return TypeQuals; } 1168193326Sedpublic: 1169193326Sed 1170193326Sed QualType getResultType() const { return ResultType; } 1171193326Sed 1172193326Sed 1173193326Sed static bool classof(const Type *T) { 1174193326Sed return T->getTypeClass() == FunctionNoProto || 1175193326Sed T->getTypeClass() == FunctionProto; 1176193326Sed } 1177193326Sed static bool classof(const FunctionType *) { return true; } 1178193326Sed}; 1179193326Sed 1180193326Sed/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 1181193326Sed/// no information available about its arguments. 1182193326Sedclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 1183193326Sed FunctionNoProtoType(QualType Result, QualType Canonical) 1184193326Sed : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 1185193326Sed /*Dependent=*/false) {} 1186193326Sed friend class ASTContext; // ASTContext creates these. 1187193326Sedpublic: 1188193326Sed // No additional state past what FunctionType provides. 1189193326Sed 1190193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1191193326Sed 1192193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 1193193326Sed Profile(ID, getResultType()); 1194193326Sed } 1195193326Sed static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) { 1196193326Sed ID.AddPointer(ResultType.getAsOpaquePtr()); 1197193326Sed } 1198193326Sed 1199193326Sed static bool classof(const Type *T) { 1200193326Sed return T->getTypeClass() == FunctionNoProto; 1201193326Sed } 1202193326Sed static bool classof(const FunctionNoProtoType *) { return true; } 1203193326Sed}; 1204193326Sed 1205193326Sed/// FunctionProtoType - Represents a prototype with argument type info, e.g. 1206193326Sed/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 1207193326Sed/// arguments, not as having a single void argument. Such a type can have an 1208193326Sed/// exception specification, but this specification is not part of the canonical 1209193326Sed/// type. 1210193326Sedclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 1211193326Sed /// hasAnyDependentType - Determine whether there are any dependent 1212193326Sed /// types within the arguments passed in. 1213193326Sed static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 1214193326Sed for (unsigned Idx = 0; Idx < numArgs; ++Idx) 1215193326Sed if (ArgArray[Idx]->isDependentType()) 1216193326Sed return true; 1217193326Sed 1218193326Sed return false; 1219193326Sed } 1220193326Sed 1221193326Sed FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 1222193326Sed bool isVariadic, unsigned typeQuals, bool hasExs, 1223193326Sed bool hasAnyExs, const QualType *ExArray, 1224193326Sed unsigned numExs, QualType Canonical) 1225193326Sed : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 1226193326Sed (Result->isDependentType() || 1227193326Sed hasAnyDependentType(ArgArray, numArgs))), 1228193326Sed NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 1229193326Sed AnyExceptionSpec(hasAnyExs) { 1230193326Sed // Fill in the trailing argument array. 1231193326Sed QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 1232193326Sed for (unsigned i = 0; i != numArgs; ++i) 1233193326Sed ArgInfo[i] = ArgArray[i]; 1234193326Sed // Fill in the exception array. 1235193326Sed QualType *Ex = ArgInfo + numArgs; 1236193326Sed for (unsigned i = 0; i != numExs; ++i) 1237193326Sed Ex[i] = ExArray[i]; 1238193326Sed } 1239193326Sed 1240193326Sed /// NumArgs - The number of arguments this function has, not counting '...'. 1241193326Sed unsigned NumArgs : 20; 1242193326Sed 1243193326Sed /// NumExceptions - The number of types in the exception spec, if any. 1244193326Sed unsigned NumExceptions : 10; 1245193326Sed 1246193326Sed /// HasExceptionSpec - Whether this function has an exception spec at all. 1247193326Sed bool HasExceptionSpec : 1; 1248193326Sed 1249193326Sed /// AnyExceptionSpec - Whether this function has a throw(...) spec. 1250193326Sed bool AnyExceptionSpec : 1; 1251193326Sed 1252193326Sed /// ArgInfo - There is an variable size array after the class in memory that 1253193326Sed /// holds the argument types. 1254193326Sed 1255193326Sed /// Exceptions - There is another variable size array after ArgInfo that 1256193326Sed /// holds the exception types. 1257193326Sed 1258193326Sed friend class ASTContext; // ASTContext creates these. 1259193326Sed 1260193326Sedpublic: 1261193326Sed unsigned getNumArgs() const { return NumArgs; } 1262193326Sed QualType getArgType(unsigned i) const { 1263193326Sed assert(i < NumArgs && "Invalid argument number!"); 1264193326Sed return arg_type_begin()[i]; 1265193326Sed } 1266193326Sed 1267193326Sed bool hasExceptionSpec() const { return HasExceptionSpec; } 1268193326Sed bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 1269193326Sed unsigned getNumExceptions() const { return NumExceptions; } 1270193326Sed QualType getExceptionType(unsigned i) const { 1271193326Sed assert(i < NumExceptions && "Invalid exception number!"); 1272193326Sed return exception_begin()[i]; 1273193326Sed } 1274193326Sed bool hasEmptyExceptionSpec() const { 1275193326Sed return hasExceptionSpec() && !hasAnyExceptionSpec() && 1276193326Sed getNumExceptions() == 0; 1277193326Sed } 1278193326Sed 1279193326Sed bool isVariadic() const { return getSubClassData(); } 1280193326Sed unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 1281193326Sed 1282193326Sed typedef const QualType *arg_type_iterator; 1283193326Sed arg_type_iterator arg_type_begin() const { 1284193326Sed return reinterpret_cast<const QualType *>(this+1); 1285193326Sed } 1286193326Sed arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1287193326Sed 1288193326Sed typedef const QualType *exception_iterator; 1289193326Sed exception_iterator exception_begin() const { 1290193326Sed // exceptions begin where arguments end 1291193326Sed return arg_type_end(); 1292193326Sed } 1293193326Sed exception_iterator exception_end() const { 1294193326Sed return exception_begin() + NumExceptions; 1295193326Sed } 1296193326Sed 1297193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1298193326Sed 1299193326Sed static bool classof(const Type *T) { 1300193326Sed return T->getTypeClass() == FunctionProto; 1301193326Sed } 1302193326Sed static bool classof(const FunctionProtoType *) { return true; } 1303193326Sed 1304193326Sed void Profile(llvm::FoldingSetNodeID &ID); 1305193326Sed static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1306193326Sed arg_type_iterator ArgTys, unsigned NumArgs, 1307193326Sed bool isVariadic, unsigned TypeQuals, 1308193326Sed bool hasExceptionSpec, bool anyExceptionSpec, 1309193326Sed unsigned NumExceptions, exception_iterator Exs); 1310193326Sed}; 1311193326Sed 1312193326Sed 1313193326Sedclass TypedefType : public Type { 1314193326Sed TypedefDecl *Decl; 1315193326Sedprotected: 1316193326Sed TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 1317193326Sed : Type(tc, can, can->isDependentType()), Decl(D) { 1318193326Sed assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1319193326Sed } 1320193326Sed friend class ASTContext; // ASTContext creates these. 1321193326Sedpublic: 1322193326Sed 1323193326Sed TypedefDecl *getDecl() const { return Decl; } 1324193326Sed 1325193326Sed /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1326193326Sed /// potentially looking through *all* consecutive typedefs. This returns the 1327193326Sed /// sum of the type qualifiers, so if you have: 1328193326Sed /// typedef const int A; 1329193326Sed /// typedef volatile A B; 1330193326Sed /// looking through the typedefs for B will give you "const volatile A". 1331193326Sed QualType LookThroughTypedefs() const; 1332193326Sed 1333193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1334193326Sed 1335193326Sed static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 1336193326Sed static bool classof(const TypedefType *) { return true; } 1337193326Sed}; 1338193326Sed 1339193326Sed/// TypeOfExprType (GCC extension). 1340193326Sedclass TypeOfExprType : public Type { 1341193326Sed Expr *TOExpr; 1342193326Sed TypeOfExprType(Expr *E, QualType can); 1343193326Sed friend class ASTContext; // ASTContext creates these. 1344193326Sedpublic: 1345193326Sed Expr *getUnderlyingExpr() const { return TOExpr; } 1346193326Sed 1347193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1348193326Sed 1349193326Sed static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 1350193326Sed static bool classof(const TypeOfExprType *) { return true; } 1351193326Sed}; 1352193326Sed 1353193326Sed/// TypeOfType (GCC extension). 1354193326Sedclass TypeOfType : public Type { 1355193326Sed QualType TOType; 1356193326Sed TypeOfType(QualType T, QualType can) 1357193326Sed : Type(TypeOf, can, T->isDependentType()), TOType(T) { 1358193326Sed assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1359193326Sed } 1360193326Sed friend class ASTContext; // ASTContext creates these. 1361193326Sedpublic: 1362193326Sed QualType getUnderlyingType() const { return TOType; } 1363193326Sed 1364193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1365193326Sed 1366193326Sed static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 1367193326Sed static bool classof(const TypeOfType *) { return true; } 1368193326Sed}; 1369193326Sed 1370195099Sed/// DecltypeType (C++0x) 1371195099Sedclass DecltypeType : public Type { 1372195099Sed Expr *E; 1373195099Sed DecltypeType(Expr *E, QualType can); 1374195099Sed friend class ASTContext; // ASTContext creates these. 1375195099Sedpublic: 1376195099Sed Expr *getUnderlyingExpr() const { return E; } 1377195099Sed 1378195099Sed virtual void getAsStringInternal(std::string &InnerString, 1379195099Sed const PrintingPolicy &Policy) const; 1380195099Sed 1381195099Sed static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 1382195099Sed static bool classof(const DecltypeType *) { return true; } 1383195099Sed}; 1384195099Sed 1385193326Sedclass TagType : public Type { 1386193326Sed /// Stores the TagDecl associated with this type. The decl will 1387193326Sed /// point to the TagDecl that actually defines the entity (or is a 1388193326Sed /// definition in progress), if there is such a definition. The 1389193326Sed /// single-bit value will be non-zero when this tag is in the 1390193326Sed /// process of being defined. 1391193326Sed mutable llvm::PointerIntPair<TagDecl *, 1> decl; 1392193326Sed friend class ASTContext; 1393193326Sed friend class TagDecl; 1394193326Sed 1395193326Sedprotected: 1396193326Sed TagType(TypeClass TC, TagDecl *D, QualType can); 1397193326Sed 1398193326Sedpublic: 1399193326Sed TagDecl *getDecl() const { return decl.getPointer(); } 1400193326Sed 1401193326Sed /// @brief Determines whether this type is in the process of being 1402193326Sed /// defined. 1403193326Sed bool isBeingDefined() const { return decl.getInt(); } 1404193326Sed void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); } 1405193326Sed 1406193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1407193326Sed 1408193326Sed static bool classof(const Type *T) { 1409193326Sed return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 1410193326Sed } 1411193326Sed static bool classof(const TagType *) { return true; } 1412193326Sed static bool classof(const RecordType *) { return true; } 1413193326Sed static bool classof(const EnumType *) { return true; } 1414193326Sed}; 1415193326Sed 1416193326Sed/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 1417193326Sed/// to detect TagType objects of structs/unions/classes. 1418193326Sedclass RecordType : public TagType { 1419193326Sedprotected: 1420193326Sed explicit RecordType(RecordDecl *D) 1421193326Sed : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 1422193326Sed explicit RecordType(TypeClass TC, RecordDecl *D) 1423193326Sed : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 1424193326Sed friend class ASTContext; // ASTContext creates these. 1425193326Sedpublic: 1426193326Sed 1427193326Sed RecordDecl *getDecl() const { 1428193326Sed return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 1429193326Sed } 1430193326Sed 1431193326Sed // FIXME: This predicate is a helper to QualType/Type. It needs to 1432193326Sed // recursively check all fields for const-ness. If any field is declared 1433193326Sed // const, it needs to return false. 1434193326Sed bool hasConstFields() const { return false; } 1435193326Sed 1436193326Sed // FIXME: RecordType needs to check when it is created that all fields are in 1437193326Sed // the same address space, and return that. 1438193326Sed unsigned getAddressSpace() const { return 0; } 1439193326Sed 1440193326Sed static bool classof(const TagType *T); 1441193326Sed static bool classof(const Type *T) { 1442193326Sed return isa<TagType>(T) && classof(cast<TagType>(T)); 1443193326Sed } 1444193326Sed static bool classof(const RecordType *) { return true; } 1445193326Sed}; 1446193326Sed 1447193326Sed/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 1448193326Sed/// to detect TagType objects of enums. 1449193326Sedclass EnumType : public TagType { 1450193326Sed explicit EnumType(EnumDecl *D) 1451193326Sed : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 1452193326Sed friend class ASTContext; // ASTContext creates these. 1453193326Sedpublic: 1454193326Sed 1455193326Sed EnumDecl *getDecl() const { 1456193326Sed return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 1457193326Sed } 1458193326Sed 1459193326Sed static bool classof(const TagType *T); 1460193326Sed static bool classof(const Type *T) { 1461193326Sed return isa<TagType>(T) && classof(cast<TagType>(T)); 1462193326Sed } 1463193326Sed static bool classof(const EnumType *) { return true; } 1464193326Sed}; 1465193326Sed 1466193326Sedclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 1467194613Sed unsigned Depth : 15; 1468193326Sed unsigned Index : 16; 1469194613Sed unsigned ParameterPack : 1; 1470193326Sed IdentifierInfo *Name; 1471193326Sed 1472194613Sed TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 1473193326Sed QualType Canon) 1474193326Sed : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 1475194613Sed Depth(D), Index(I), ParameterPack(PP), Name(N) { } 1476193326Sed 1477194613Sed TemplateTypeParmType(unsigned D, unsigned I, bool PP) 1478193326Sed : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 1479194613Sed Depth(D), Index(I), ParameterPack(PP), Name(0) { } 1480193326Sed 1481193326Sed friend class ASTContext; // ASTContext creates these 1482193326Sed 1483193326Sedpublic: 1484193326Sed unsigned getDepth() const { return Depth; } 1485193326Sed unsigned getIndex() const { return Index; } 1486194613Sed bool isParameterPack() const { return ParameterPack; } 1487193326Sed IdentifierInfo *getName() const { return Name; } 1488193326Sed 1489193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1490193326Sed 1491193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 1492194613Sed Profile(ID, Depth, Index, ParameterPack, Name); 1493193326Sed } 1494193326Sed 1495193326Sed static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 1496194613Sed unsigned Index, bool ParameterPack, 1497194613Sed IdentifierInfo *Name) { 1498193326Sed ID.AddInteger(Depth); 1499193326Sed ID.AddInteger(Index); 1500194613Sed ID.AddBoolean(ParameterPack); 1501193326Sed ID.AddPointer(Name); 1502193326Sed } 1503193326Sed 1504193326Sed static bool classof(const Type *T) { 1505193326Sed return T->getTypeClass() == TemplateTypeParm; 1506193326Sed } 1507193326Sed static bool classof(const TemplateTypeParmType *T) { return true; } 1508193326Sed}; 1509193326Sed 1510193326Sed/// \brief Represents the type of a template specialization as written 1511193326Sed/// in the source code. 1512193326Sed/// 1513193326Sed/// Template specialization types represent the syntactic form of a 1514193326Sed/// template-id that refers to a type, e.g., @c vector<int>. Some 1515193326Sed/// template specialization types are syntactic sugar, whose canonical 1516193326Sed/// type will point to some other type node that represents the 1517193326Sed/// instantiation or class template specialization. For example, a 1518193326Sed/// class template specialization type of @c vector<int> will refer to 1519193326Sed/// a tag type for the instantiation 1520193326Sed/// @c std::vector<int, std::allocator<int>>. 1521193326Sed/// 1522193326Sed/// Other template specialization types, for which the template name 1523193326Sed/// is dependent, may be canonical types. These types are always 1524193326Sed/// dependent. 1525193326Sedclass TemplateSpecializationType 1526193326Sed : public Type, public llvm::FoldingSetNode { 1527193326Sed 1528193326Sed /// \brief The name of the template being specialized. 1529193326Sed TemplateName Template; 1530193326Sed 1531193326Sed /// \brief - The number of template arguments named in this class 1532193326Sed /// template specialization. 1533193326Sed unsigned NumArgs; 1534193326Sed 1535193326Sed TemplateSpecializationType(TemplateName T, 1536193326Sed const TemplateArgument *Args, 1537193326Sed unsigned NumArgs, QualType Canon); 1538193326Sed 1539193326Sed virtual void Destroy(ASTContext& C); 1540193326Sed 1541193326Sed friend class ASTContext; // ASTContext creates these 1542193326Sed 1543193326Sedpublic: 1544193326Sed /// \brief Determine whether any of the given template arguments are 1545193326Sed /// dependent. 1546193326Sed static bool anyDependentTemplateArguments(const TemplateArgument *Args, 1547193326Sed unsigned NumArgs); 1548193326Sed 1549193326Sed /// \brief Print a template argument list, including the '<' and '>' 1550193326Sed /// enclosing the template arguments. 1551193326Sed static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 1552193326Sed unsigned NumArgs, 1553193326Sed const PrintingPolicy &Policy); 1554193326Sed 1555193326Sed typedef const TemplateArgument * iterator; 1556193326Sed 1557193326Sed iterator begin() const { return getArgs(); } 1558193326Sed iterator end() const; 1559193326Sed 1560193326Sed /// \brief Retrieve the name of the template that we are specializing. 1561193326Sed TemplateName getTemplateName() const { return Template; } 1562193326Sed 1563193326Sed /// \brief Retrieve the template arguments. 1564193326Sed const TemplateArgument *getArgs() const { 1565193326Sed return reinterpret_cast<const TemplateArgument *>(this + 1); 1566193326Sed } 1567193326Sed 1568193326Sed /// \brief Retrieve the number of template arguments. 1569193326Sed unsigned getNumArgs() const { return NumArgs; } 1570193326Sed 1571193326Sed /// \brief Retrieve a specific template argument as a type. 1572193326Sed /// \precondition @c isArgType(Arg) 1573193326Sed const TemplateArgument &getArg(unsigned Idx) const; 1574193326Sed 1575193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1576193326Sed 1577193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 1578193326Sed Profile(ID, Template, getArgs(), NumArgs); 1579193326Sed } 1580193326Sed 1581193326Sed static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 1582193326Sed const TemplateArgument *Args, unsigned NumArgs); 1583193326Sed 1584193326Sed static bool classof(const Type *T) { 1585193326Sed return T->getTypeClass() == TemplateSpecialization; 1586193326Sed } 1587193326Sed static bool classof(const TemplateSpecializationType *T) { return true; } 1588193326Sed}; 1589193326Sed 1590193326Sed/// \brief Represents a type that was referred to via a qualified 1591193326Sed/// name, e.g., N::M::type. 1592193326Sed/// 1593193326Sed/// This type is used to keep track of a type name as written in the 1594193326Sed/// source code, including any nested-name-specifiers. The type itself 1595193326Sed/// is always "sugar", used to express what was written in the source 1596193326Sed/// code but containing no additional semantic information. 1597193326Sedclass QualifiedNameType : public Type, public llvm::FoldingSetNode { 1598193326Sed /// \brief The nested name specifier containing the qualifier. 1599193326Sed NestedNameSpecifier *NNS; 1600193326Sed 1601193326Sed /// \brief The type that this qualified name refers to. 1602193326Sed QualType NamedType; 1603193326Sed 1604193326Sed QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 1605193326Sed QualType CanonType) 1606193326Sed : Type(QualifiedName, CanonType, NamedType->isDependentType()), 1607193326Sed NNS(NNS), NamedType(NamedType) { } 1608193326Sed 1609193326Sed friend class ASTContext; // ASTContext creates these 1610193326Sed 1611193326Sedpublic: 1612193326Sed /// \brief Retrieve the qualification on this type. 1613193326Sed NestedNameSpecifier *getQualifier() const { return NNS; } 1614193326Sed 1615193326Sed /// \brief Retrieve the type named by the qualified-id. 1616193326Sed QualType getNamedType() const { return NamedType; } 1617193326Sed 1618193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1619193326Sed 1620193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 1621193326Sed Profile(ID, NNS, NamedType); 1622193326Sed } 1623193326Sed 1624193326Sed static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1625193326Sed QualType NamedType) { 1626193326Sed ID.AddPointer(NNS); 1627193326Sed NamedType.Profile(ID); 1628193326Sed } 1629193326Sed 1630193326Sed static bool classof(const Type *T) { 1631193326Sed return T->getTypeClass() == QualifiedName; 1632193326Sed } 1633193326Sed static bool classof(const QualifiedNameType *T) { return true; } 1634193326Sed}; 1635193326Sed 1636193326Sed/// \brief Represents a 'typename' specifier that names a type within 1637193326Sed/// a dependent type, e.g., "typename T::type". 1638193326Sed/// 1639193326Sed/// TypenameType has a very similar structure to QualifiedNameType, 1640193326Sed/// which also involves a nested-name-specifier following by a type, 1641193326Sed/// and (FIXME!) both can even be prefixed by the 'typename' 1642193326Sed/// keyword. However, the two types serve very different roles: 1643193326Sed/// QualifiedNameType is a non-semantic type that serves only as sugar 1644193326Sed/// to show how a particular type was written in the source 1645193326Sed/// code. TypenameType, on the other hand, only occurs when the 1646193326Sed/// nested-name-specifier is dependent, such that we cannot resolve 1647193326Sed/// the actual type until after instantiation. 1648193326Sedclass TypenameType : public Type, public llvm::FoldingSetNode { 1649193326Sed /// \brief The nested name specifier containing the qualifier. 1650193326Sed NestedNameSpecifier *NNS; 1651193326Sed 1652193326Sed typedef llvm::PointerUnion<const IdentifierInfo *, 1653193326Sed const TemplateSpecializationType *> NameType; 1654193326Sed 1655193326Sed /// \brief The type that this typename specifier refers to. 1656193326Sed NameType Name; 1657193326Sed 1658193326Sed TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 1659193326Sed QualType CanonType) 1660193326Sed : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 1661193326Sed assert(NNS->isDependent() && 1662193326Sed "TypenameType requires a dependent nested-name-specifier"); 1663193326Sed } 1664193326Sed 1665193326Sed TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 1666193326Sed QualType CanonType) 1667193326Sed : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 1668193326Sed assert(NNS->isDependent() && 1669193326Sed "TypenameType requires a dependent nested-name-specifier"); 1670193326Sed } 1671193326Sed 1672193326Sed friend class ASTContext; // ASTContext creates these 1673193326Sed 1674193326Sedpublic: 1675193326Sed /// \brief Retrieve the qualification on this type. 1676193326Sed NestedNameSpecifier *getQualifier() const { return NNS; } 1677193326Sed 1678193326Sed /// \brief Retrieve the type named by the typename specifier as an 1679193326Sed /// identifier. 1680193326Sed /// 1681193326Sed /// This routine will return a non-NULL identifier pointer when the 1682193326Sed /// form of the original typename was terminated by an identifier, 1683193326Sed /// e.g., "typename T::type". 1684193326Sed const IdentifierInfo *getIdentifier() const { 1685193326Sed return Name.dyn_cast<const IdentifierInfo *>(); 1686193326Sed } 1687193326Sed 1688193326Sed /// \brief Retrieve the type named by the typename specifier as a 1689193326Sed /// type specialization. 1690193326Sed const TemplateSpecializationType *getTemplateId() const { 1691193326Sed return Name.dyn_cast<const TemplateSpecializationType *>(); 1692193326Sed } 1693193326Sed 1694193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1695193326Sed 1696193326Sed void Profile(llvm::FoldingSetNodeID &ID) { 1697193326Sed Profile(ID, NNS, Name); 1698193326Sed } 1699193326Sed 1700193326Sed static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1701193326Sed NameType Name) { 1702193326Sed ID.AddPointer(NNS); 1703193326Sed ID.AddPointer(Name.getOpaqueValue()); 1704193326Sed } 1705193326Sed 1706193326Sed static bool classof(const Type *T) { 1707193326Sed return T->getTypeClass() == Typename; 1708193326Sed } 1709193326Sed static bool classof(const TypenameType *T) { return true; } 1710193326Sed}; 1711193326Sed 1712194613Sed/// ObjCObjectPointerType - Used to represent 'id', 'Interface *', 'id <p>', 1713194613Sed/// and 'Interface <p> *'. 1714194613Sed/// 1715194613Sed/// Duplicate protocols are removed and protocol list is canonicalized to be in 1716194613Sed/// alphabetical order. 1717194613Sedclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 1718194613Sed ObjCInterfaceDecl *Decl; 1719194613Sed // List of protocols for this protocol conforming object type 1720194613Sed // List is sorted on protocol name. No protocol is entered more than once. 1721194613Sed llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1722194613Sed 1723194613Sed ObjCObjectPointerType(ObjCInterfaceDecl *D, 1724194613Sed ObjCProtocolDecl **Protos, unsigned NumP) : 1725194613Sed Type(ObjCObjectPointer, QualType(), /*Dependent=*/false), 1726194613Sed Decl(D), Protocols(Protos, Protos+NumP) { } 1727194613Sed friend class ASTContext; // ASTContext creates these. 1728194613Sed 1729194613Sedpublic: 1730194613Sed ObjCInterfaceDecl *getDecl() const { return Decl; } 1731194613Sed 1732194613Sed /// isObjCQualifiedIdType - true for "id <p>". 1733194613Sed bool isObjCQualifiedIdType() const { return Decl == 0 && Protocols.size(); } 1734194613Sed 1735194613Sed /// qual_iterator and friends: this provides access to the (potentially empty) 1736194613Sed /// list of protocols qualifying this interface. 1737194613Sed typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1738194613Sed 1739194613Sed qual_iterator qual_begin() const { return Protocols.begin(); } 1740194613Sed qual_iterator qual_end() const { return Protocols.end(); } 1741194613Sed bool qual_empty() const { return Protocols.size() == 0; } 1742194613Sed 1743194613Sed /// getNumProtocols - Return the number of qualifying protocols in this 1744194613Sed /// interface type, or 0 if there are none. 1745194613Sed unsigned getNumProtocols() const { return Protocols.size(); } 1746194613Sed 1747194613Sed void Profile(llvm::FoldingSetNodeID &ID); 1748194613Sed static void Profile(llvm::FoldingSetNodeID &ID, 1749194613Sed const ObjCInterfaceDecl *Decl, 1750194613Sed ObjCProtocolDecl **protocols, unsigned NumProtocols); 1751194613Sed virtual void getAsStringInternal(std::string &InnerString, 1752194613Sed const PrintingPolicy &Policy) const; 1753194613Sed static bool classof(const Type *T) { 1754194613Sed return T->getTypeClass() == ObjCObjectPointer; 1755194613Sed } 1756194613Sed static bool classof(const ObjCObjectPointerType *) { return true; } 1757194613Sed}; 1758194613Sed 1759193326Sed/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1760193326Sed/// object oriented design. They basically correspond to C++ classes. There 1761193326Sed/// are two kinds of interface types, normal interfaces like "NSString" and 1762193326Sed/// qualified interfaces, which are qualified with a protocol list like 1763193326Sed/// "NSString<NSCopyable, NSAmazing>". Qualified interface types are instances 1764193326Sed/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType. 1765193326Sedclass ObjCInterfaceType : public Type { 1766193326Sed ObjCInterfaceDecl *Decl; 1767193326Sedprotected: 1768193326Sed ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 1769193326Sed Type(tc, QualType(), /*Dependent=*/false), Decl(D) { } 1770193326Sed friend class ASTContext; // ASTContext creates these. 1771193326Sedpublic: 1772193326Sed 1773193326Sed ObjCInterfaceDecl *getDecl() const { return Decl; } 1774193326Sed 1775193326Sed /// qual_iterator and friends: this provides access to the (potentially empty) 1776193326Sed /// list of protocols qualifying this interface. If this is an instance of 1777193326Sed /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an 1778193326Sed /// empty list if there are no qualifying protocols. 1779193326Sed typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1780193326Sed inline qual_iterator qual_begin() const; 1781193326Sed inline qual_iterator qual_end() const; 1782193326Sed bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; } 1783193326Sed 1784193326Sed /// getNumProtocols - Return the number of qualifying protocols in this 1785193326Sed /// interface type, or 0 if there are none. 1786193326Sed inline unsigned getNumProtocols() const; 1787193326Sed 1788193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1789193326Sed static bool classof(const Type *T) { 1790193326Sed return T->getTypeClass() == ObjCInterface || 1791193326Sed T->getTypeClass() == ObjCQualifiedInterface; 1792193326Sed } 1793193326Sed static bool classof(const ObjCInterfaceType *) { return true; } 1794193326Sed}; 1795193326Sed 1796193326Sed/// ObjCQualifiedInterfaceType - This class represents interface types 1797193326Sed/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>. 1798193326Sed/// 1799193326Sed/// Duplicate protocols are removed and protocol list is canonicalized to be in 1800193326Sed/// alphabetical order. 1801193326Sedclass ObjCQualifiedInterfaceType : public ObjCInterfaceType, 1802193326Sed public llvm::FoldingSetNode { 1803193326Sed 1804193326Sed // List of protocols for this protocol conforming object type 1805193326Sed // List is sorted on protocol name. No protocol is enterred more than once. 1806193326Sed llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 1807193326Sed 1808193326Sed ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1809193326Sed ObjCProtocolDecl **Protos, unsigned NumP) : 1810193326Sed ObjCInterfaceType(ObjCQualifiedInterface, D), 1811193326Sed Protocols(Protos, Protos+NumP) { } 1812193326Sed friend class ASTContext; // ASTContext creates these. 1813193326Sedpublic: 1814193326Sed 1815193326Sed unsigned getNumProtocols() const { 1816193326Sed return Protocols.size(); 1817193326Sed } 1818193326Sed 1819193326Sed qual_iterator qual_begin() const { return Protocols.begin(); } 1820193326Sed qual_iterator qual_end() const { return Protocols.end(); } 1821193326Sed 1822193326Sed virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1823193326Sed 1824193326Sed void Profile(llvm::FoldingSetNodeID &ID); 1825193326Sed static void Profile(llvm::FoldingSetNodeID &ID, 1826193326Sed const ObjCInterfaceDecl *Decl, 1827193326Sed ObjCProtocolDecl **protocols, unsigned NumProtocols); 1828193326Sed 1829193326Sed static bool classof(const Type *T) { 1830193326Sed return T->getTypeClass() == ObjCQualifiedInterface; 1831193326Sed } 1832193326Sed static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1833193326Sed}; 1834193326Sed 1835193326Sedinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const { 1836193326Sed if (const ObjCQualifiedInterfaceType *QIT = 1837193326Sed dyn_cast<ObjCQualifiedInterfaceType>(this)) 1838193326Sed return QIT->qual_begin(); 1839193326Sed return 0; 1840193326Sed} 1841193326Sedinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const { 1842193326Sed if (const ObjCQualifiedInterfaceType *QIT = 1843193326Sed dyn_cast<ObjCQualifiedInterfaceType>(this)) 1844193326Sed return QIT->qual_end(); 1845193326Sed return 0; 1846193326Sed} 1847193326Sed 1848193326Sed/// getNumProtocols - Return the number of qualifying protocols in this 1849193326Sed/// interface type, or 0 if there are none. 1850193326Sedinline unsigned ObjCInterfaceType::getNumProtocols() const { 1851193326Sed if (const ObjCQualifiedInterfaceType *QIT = 1852193326Sed dyn_cast<ObjCQualifiedInterfaceType>(this)) 1853193326Sed return QIT->getNumProtocols(); 1854193326Sed return 0; 1855193326Sed} 1856193326Sed 1857193326Sed// Inline function definitions. 1858193326Sed 1859193326Sed/// getUnqualifiedType - Return the type without any qualifiers. 1860193326Sedinline QualType QualType::getUnqualifiedType() const { 1861193326Sed Type *TP = getTypePtr(); 1862193326Sed if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP)) 1863193326Sed TP = EXTQT->getBaseType(); 1864193326Sed return QualType(TP, 0); 1865193326Sed} 1866193326Sed 1867193326Sed/// getAddressSpace - Return the address space of this type. 1868193326Sedinline unsigned QualType::getAddressSpace() const { 1869193326Sed QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1870193326Sed if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1871193326Sed return AT->getElementType().getAddressSpace(); 1872193326Sed if (const RecordType *RT = dyn_cast<RecordType>(CT)) 1873193326Sed return RT->getAddressSpace(); 1874193326Sed if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1875193326Sed return EXTQT->getAddressSpace(); 1876193326Sed return 0; 1877193326Sed} 1878193326Sed 1879193326Sed/// getObjCGCAttr - Return the gc attribute of this type. 1880193326Sedinline QualType::GCAttrTypes QualType::getObjCGCAttr() const { 1881193326Sed QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1882193326Sed if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1883193326Sed return AT->getElementType().getObjCGCAttr(); 1884193326Sed if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1885193326Sed return EXTQT->getObjCGCAttr(); 1886193326Sed if (const PointerType *PT = CT->getAsPointerType()) 1887193326Sed return PT->getPointeeType().getObjCGCAttr(); 1888193326Sed return GCNone; 1889193326Sed} 1890193326Sed 1891193326Sed/// isMoreQualifiedThan - Determine whether this type is more 1892193326Sed/// qualified than the Other type. For example, "const volatile int" 1893193326Sed/// is more qualified than "const int", "volatile int", and 1894193326Sed/// "int". However, it is not more qualified than "const volatile 1895193326Sed/// int". 1896193326Sedinline bool QualType::isMoreQualifiedThan(QualType Other) const { 1897193326Sed unsigned MyQuals = this->getCVRQualifiers(); 1898193326Sed unsigned OtherQuals = Other.getCVRQualifiers(); 1899193326Sed if (getAddressSpace() != Other.getAddressSpace()) 1900193326Sed return false; 1901193326Sed return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 1902193326Sed} 1903193326Sed 1904193326Sed/// isAtLeastAsQualifiedAs - Determine whether this type is at last 1905193326Sed/// as qualified as the Other type. For example, "const volatile 1906193326Sed/// int" is at least as qualified as "const int", "volatile int", 1907193326Sed/// "int", and "const volatile int". 1908193326Sedinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 1909193326Sed unsigned MyQuals = this->getCVRQualifiers(); 1910193326Sed unsigned OtherQuals = Other.getCVRQualifiers(); 1911193326Sed if (getAddressSpace() != Other.getAddressSpace()) 1912193326Sed return false; 1913193326Sed return (MyQuals | OtherQuals) == MyQuals; 1914193326Sed} 1915193326Sed 1916193326Sed/// getNonReferenceType - If Type is a reference type (e.g., const 1917193326Sed/// int&), returns the type that the reference refers to ("const 1918193326Sed/// int"). Otherwise, returns the type itself. This routine is used 1919193326Sed/// throughout Sema to implement C++ 5p6: 1920193326Sed/// 1921193326Sed/// If an expression initially has the type "reference to T" (8.3.2, 1922193326Sed/// 8.5.3), the type is adjusted to "T" prior to any further 1923193326Sed/// analysis, the expression designates the object or function 1924193326Sed/// denoted by the reference, and the expression is an lvalue. 1925193326Sedinline QualType QualType::getNonReferenceType() const { 1926193326Sed if (const ReferenceType *RefType = (*this)->getAsReferenceType()) 1927193326Sed return RefType->getPointeeType(); 1928193326Sed else 1929193326Sed return *this; 1930193326Sed} 1931193326Sed 1932193326Sedinline const TypedefType* Type::getAsTypedefType() const { 1933193326Sed return dyn_cast<TypedefType>(this); 1934193326Sed} 1935193326Sedinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 1936193326Sed if (const PointerType *PT = getAsPointerType()) 1937193326Sed return PT->getPointeeType()->getAsObjCInterfaceType(); 1938193326Sed return 0; 1939193326Sed} 1940193326Sed 1941193326Sed// NOTE: All of these methods use "getUnqualifiedType" to strip off address 1942193326Sed// space qualifiers if present. 1943193326Sedinline bool Type::isFunctionType() const { 1944193326Sed return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 1945193326Sed} 1946193326Sedinline bool Type::isPointerType() const { 1947193326Sed return isa<PointerType>(CanonicalType.getUnqualifiedType()); 1948193326Sed} 1949193326Sedinline bool Type::isBlockPointerType() const { 1950193326Sed return isa<BlockPointerType>(CanonicalType.getUnqualifiedType()); 1951193326Sed} 1952193326Sedinline bool Type::isReferenceType() const { 1953193326Sed return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 1954193326Sed} 1955193326Sedinline bool Type::isLValueReferenceType() const { 1956193326Sed return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()); 1957193326Sed} 1958193326Sedinline bool Type::isRValueReferenceType() const { 1959193326Sed return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()); 1960193326Sed} 1961193326Sedinline bool Type::isFunctionPointerType() const { 1962193326Sed if (const PointerType* T = getAsPointerType()) 1963193326Sed return T->getPointeeType()->isFunctionType(); 1964193326Sed else 1965193326Sed return false; 1966193326Sed} 1967193326Sedinline bool Type::isMemberPointerType() const { 1968193326Sed return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 1969193326Sed} 1970193326Sedinline bool Type::isMemberFunctionPointerType() const { 1971193326Sed if (const MemberPointerType* T = getAsMemberPointerType()) 1972193326Sed return T->getPointeeType()->isFunctionType(); 1973193326Sed else 1974193326Sed return false; 1975193326Sed} 1976193326Sedinline bool Type::isArrayType() const { 1977193326Sed return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 1978193326Sed} 1979193326Sedinline bool Type::isConstantArrayType() const { 1980193326Sed return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 1981193326Sed} 1982193326Sedinline bool Type::isIncompleteArrayType() const { 1983193326Sed return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 1984193326Sed} 1985193326Sedinline bool Type::isVariableArrayType() const { 1986193326Sed return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 1987193326Sed} 1988193326Sedinline bool Type::isDependentSizedArrayType() const { 1989193326Sed return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 1990193326Sed} 1991193326Sedinline bool Type::isRecordType() const { 1992193326Sed return isa<RecordType>(CanonicalType.getUnqualifiedType()); 1993193326Sed} 1994193326Sedinline bool Type::isAnyComplexType() const { 1995193326Sed return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 1996193326Sed} 1997193326Sedinline bool Type::isVectorType() const { 1998193326Sed return isa<VectorType>(CanonicalType.getUnqualifiedType()); 1999193326Sed} 2000193326Sedinline bool Type::isExtVectorType() const { 2001193326Sed return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 2002193326Sed} 2003194613Sedinline bool Type::isObjCObjectPointerType() const { 2004194613Sed return isa<ObjCObjectPointerType>(CanonicalType.getUnqualifiedType()); 2005194613Sed} 2006193326Sedinline bool Type::isObjCInterfaceType() const { 2007193326Sed return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 2008193326Sed} 2009193326Sedinline bool Type::isObjCQualifiedInterfaceType() const { 2010193326Sed return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); 2011193326Sed} 2012193326Sedinline bool Type::isObjCQualifiedIdType() const { 2013194613Sed if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) { 2014194613Sed return OPT->isObjCQualifiedIdType(); 2015194613Sed } 2016194613Sed return false; 2017193326Sed} 2018193326Sedinline bool Type::isTemplateTypeParmType() const { 2019193326Sed return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 2020193326Sed} 2021193326Sed 2022193326Sedinline bool Type::isSpecificBuiltinType(unsigned K) const { 2023193326Sed if (const BuiltinType *BT = getAsBuiltinType()) 2024193326Sed if (BT->getKind() == (BuiltinType::Kind) K) 2025193326Sed return true; 2026193326Sed return false; 2027193326Sed} 2028193326Sed 2029193326Sed/// \brief Determines whether this is a type for which one can define 2030193326Sed/// an overloaded operator. 2031193326Sedinline bool Type::isOverloadableType() const { 2032193326Sed return isDependentType() || isRecordType() || isEnumeralType(); 2033193326Sed} 2034193326Sed 2035193326Sedinline bool Type::hasPointerRepresentation() const { 2036193326Sed return (isPointerType() || isReferenceType() || isBlockPointerType() || 2037193326Sed isObjCInterfaceType() || isObjCQualifiedIdType() || 2038193326Sed isObjCQualifiedInterfaceType() || isNullPtrType()); 2039193326Sed} 2040193326Sed 2041193326Sedinline bool Type::hasObjCPointerRepresentation() const { 2042193326Sed return (isObjCInterfaceType() || isObjCQualifiedIdType() || 2043193326Sed isObjCQualifiedInterfaceType()); 2044193326Sed} 2045193326Sed 2046193326Sed/// Insertion operator for diagnostics. This allows sending QualType's into a 2047193326Sed/// diagnostic with <<. 2048193326Sedinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 2049193326Sed QualType T) { 2050193326Sed DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 2051193326Sed Diagnostic::ak_qualtype); 2052193326Sed return DB; 2053193326Sed} 2054193326Sed 2055193326Sed} // end namespace clang 2056193326Sed 2057193326Sed#endif 2058