Type.h revision 63d22fa6071690209b339451e4939de120a45e70
1//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the Type interface and subclasses. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_TYPE_H 15#define LLVM_CLANG_AST_TYPE_H 16 17#include "clang/Basic/Diagnostic.h" 18#include "clang/Basic/IdentifierTable.h" 19#include "clang/AST/NestedNameSpecifier.h" 20#include "clang/AST/TemplateName.h" 21#include "llvm/Support/Casting.h" 22#include "llvm/ADT/APSInt.h" 23#include "llvm/ADT/FoldingSet.h" 24#include "llvm/ADT/PointerIntPair.h" 25#include "llvm/ADT/PointerUnion.h" 26 27using llvm::isa; 28using llvm::cast; 29using llvm::cast_or_null; 30using llvm::dyn_cast; 31using llvm::dyn_cast_or_null; 32namespace clang { class Type; } 33 34namespace llvm { 35 template <typename T> 36 class PointerLikeTypeTraits; 37 template<> 38 class PointerLikeTypeTraits< ::clang::Type*> { 39 public: 40 static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 41 static inline ::clang::Type *getFromVoidPointer(void *P) { 42 return static_cast< ::clang::Type*>(P); 43 } 44 enum { NumLowBitsAvailable = 3 }; 45 }; 46} 47 48namespace clang { 49 class ASTContext; 50 class TypedefDecl; 51 class TemplateDecl; 52 class TemplateTypeParmDecl; 53 class NonTypeTemplateParmDecl; 54 class TemplateTemplateParmDecl; 55 class TagDecl; 56 class RecordDecl; 57 class CXXRecordDecl; 58 class EnumDecl; 59 class FieldDecl; 60 class ObjCInterfaceDecl; 61 class ObjCProtocolDecl; 62 class ObjCMethodDecl; 63 class Expr; 64 class Stmt; 65 class SourceLocation; 66 class StmtIteratorBase; 67 class TemplateArgument; 68 class QualifiedNameType; 69 struct PrintingPolicy; 70 71 // Provide forward declarations for all of the *Type classes 72#define TYPE(Class, Base) class Class##Type; 73#include "clang/AST/TypeNodes.def" 74 75/// QualType - For efficiency, we don't store CVR-qualified types as nodes on 76/// their own: instead each reference to a type stores the qualifiers. This 77/// greatly reduces the number of nodes we need to allocate for types (for 78/// example we only need one for 'int', 'const int', 'volatile int', 79/// 'const volatile int', etc). 80/// 81/// As an added efficiency bonus, instead of making this a pair, we just store 82/// the three bits we care about in the low bits of the pointer. To handle the 83/// packing/unpacking, we make QualType be a simple wrapper class that acts like 84/// a smart pointer. 85class QualType { 86 llvm::PointerIntPair<Type*, 3> Value; 87public: 88 enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 89 Const = 0x1, 90 Restrict = 0x2, 91 Volatile = 0x4, 92 CVRFlags = Const|Restrict|Volatile 93 }; 94 95 enum GCAttrTypes { 96 GCNone = 0, 97 Weak, 98 Strong 99 }; 100 101 // 24 bits should be enough for anyone. 102 static const unsigned MaxAddressSpace = 0xffffffu; 103 104 QualType() {} 105 106 QualType(const Type *Ptr, unsigned Quals) 107 : Value(const_cast<Type*>(Ptr), Quals) {} 108 109 unsigned getCVRQualifiers() const { return Value.getInt(); } 110 void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); } 111 Type *getTypePtr() const { return Value.getPointer(); } 112 113 void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 114 static QualType getFromOpaquePtr(void *Ptr) { 115 QualType T; 116 T.Value.setFromOpaqueValue(Ptr); 117 return T; 118 } 119 120 Type &operator*() const { 121 return *getTypePtr(); 122 } 123 124 Type *operator->() const { 125 return getTypePtr(); 126 } 127 128 /// isNull - Return true if this QualType doesn't point to a type yet. 129 bool isNull() const { 130 return getTypePtr() == 0; 131 } 132 133 bool isConstQualified() const { 134 return (getCVRQualifiers() & Const) ? true : false; 135 } 136 bool isVolatileQualified() const { 137 return (getCVRQualifiers() & Volatile) ? true : false; 138 } 139 bool isRestrictQualified() const { 140 return (getCVRQualifiers() & Restrict) ? true : false; 141 } 142 143 bool isConstant(ASTContext& Ctx) const; 144 145 /// addConst/addVolatile/addRestrict - add the specified type qual to this 146 /// QualType. 147 void addConst() { Value.setInt(Value.getInt() | Const); } 148 void addVolatile() { Value.setInt(Value.getInt() | Volatile); } 149 void addRestrict() { Value.setInt(Value.getInt() | Restrict); } 150 151 void removeConst() { Value.setInt(Value.getInt() & ~Const); } 152 void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); } 153 void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); } 154 155 QualType getQualifiedType(unsigned TQs) const { 156 return QualType(getTypePtr(), TQs); 157 } 158 QualType getWithAdditionalQualifiers(unsigned TQs) const { 159 return QualType(getTypePtr(), TQs|getCVRQualifiers()); 160 } 161 162 QualType withConst() const { return getWithAdditionalQualifiers(Const); } 163 QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);} 164 QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);} 165 166 QualType getUnqualifiedType() const; 167 bool isMoreQualifiedThan(QualType Other) const; 168 bool isAtLeastAsQualifiedAs(QualType Other) const; 169 QualType getNonReferenceType() const; 170 171 /// getDesugaredType - Return the specified type with any "sugar" removed from 172 /// the type. This takes off typedefs, typeof's etc. If the outer level of 173 /// the type is already concrete, it returns it unmodified. This is similar 174 /// to getting the canonical type, but it doesn't remove *all* typedefs. For 175 /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 176 /// concrete. 177 QualType getDesugaredType(bool ForDisplay = false) const; 178 179 /// operator==/!= - Indicate whether the specified types and qualifiers are 180 /// identical. 181 bool operator==(const QualType &RHS) const { 182 return Value == RHS.Value; 183 } 184 bool operator!=(const QualType &RHS) const { 185 return Value != RHS.Value; 186 } 187 std::string getAsString() const; 188 189 std::string getAsString(const PrintingPolicy &Policy) const { 190 std::string S; 191 getAsStringInternal(S, Policy); 192 return S; 193 } 194 void getAsStringInternal(std::string &Str, 195 const PrintingPolicy &Policy) const; 196 197 void dump(const char *s) const; 198 void dump() const; 199 200 void Profile(llvm::FoldingSetNodeID &ID) const { 201 ID.AddPointer(getAsOpaquePtr()); 202 } 203 204public: 205 206 /// getAddressSpace - Return the address space of this type. 207 inline unsigned getAddressSpace() const; 208 209 /// GCAttrTypesAttr - Returns gc attribute of this type. 210 inline QualType::GCAttrTypes getObjCGCAttr() const; 211 212 /// isObjCGCWeak true when Type is objc's weak. 213 bool isObjCGCWeak() const { 214 return getObjCGCAttr() == Weak; 215 } 216 217 /// isObjCGCStrong true when Type is objc's strong. 218 bool isObjCGCStrong() const { 219 return getObjCGCAttr() == Strong; 220 } 221 222 /// getNoReturnAttr - Returns true if the type has the noreturn attribute, 223 /// false otherwise. 224 bool getNoReturnAttr() const; 225}; 226 227} // end clang. 228 229namespace llvm { 230/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 231/// to a specific Type class. 232template<> struct simplify_type<const ::clang::QualType> { 233 typedef ::clang::Type* SimpleType; 234 static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 235 return Val.getTypePtr(); 236 } 237}; 238template<> struct simplify_type< ::clang::QualType> 239 : public simplify_type<const ::clang::QualType> {}; 240 241// Teach SmallPtrSet that QualType is "basically a pointer". 242template<> 243class PointerLikeTypeTraits<clang::QualType> { 244public: 245 static inline void *getAsVoidPointer(clang::QualType P) { 246 return P.getAsOpaquePtr(); 247 } 248 static inline clang::QualType getFromVoidPointer(void *P) { 249 return clang::QualType::getFromOpaquePtr(P); 250 } 251 // CVR qualifiers go in low bits. 252 enum { NumLowBitsAvailable = 0 }; 253}; 254} // end namespace llvm 255 256namespace clang { 257 258/// Type - This is the base class of the type hierarchy. A central concept 259/// with types is that each type always has a canonical type. A canonical type 260/// is the type with any typedef names stripped out of it or the types it 261/// references. For example, consider: 262/// 263/// typedef int foo; 264/// typedef foo* bar; 265/// 'int *' 'foo *' 'bar' 266/// 267/// There will be a Type object created for 'int'. Since int is canonical, its 268/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 269/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 270/// there is a PointerType that represents 'int*', which, like 'int', is 271/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 272/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 273/// is also 'int*'. 274/// 275/// Non-canonical types are useful for emitting diagnostics, without losing 276/// information about typedefs being used. Canonical types are useful for type 277/// comparisons (they allow by-pointer equality tests) and useful for reasoning 278/// about whether something has a particular form (e.g. is a function type), 279/// because they implicitly, recursively, strip all typedefs out of a type. 280/// 281/// Types, once created, are immutable. 282/// 283class Type { 284public: 285 enum TypeClass { 286#define TYPE(Class, Base) Class, 287#define ABSTRACT_TYPE(Class, Base) 288#include "clang/AST/TypeNodes.def" 289 TagFirst = Record, TagLast = Enum 290 }; 291 292private: 293 QualType CanonicalType; 294 295 /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 296 bool Dependent : 1; 297 298 /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 299 /// Note that this should stay at the end of the ivars for Type so that 300 /// subclasses can pack their bitfields into the same word. 301 unsigned TC : 6; 302 303 Type(const Type&); // DO NOT IMPLEMENT. 304 void operator=(const Type&); // DO NOT IMPLEMENT. 305protected: 306 // silence VC++ warning C4355: 'this' : used in base member initializer list 307 Type *this_() { return this; } 308 Type(TypeClass tc, QualType Canonical, bool dependent) 309 : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 310 Dependent(dependent), TC(tc) {} 311 virtual ~Type() {} 312 virtual void Destroy(ASTContext& C); 313 friend class ASTContext; 314 315public: 316 TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 317 318 bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 319 320 /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 321 /// object types, function types, and incomplete types. 322 323 /// \brief Determines whether the type describes an object in memory. 324 /// 325 /// Note that this definition of object type corresponds to the C++ 326 /// definition of object type, which includes incomplete types, as 327 /// opposed to the C definition (which does not include incomplete 328 /// types). 329 bool isObjectType() const; 330 331 /// isIncompleteType - Return true if this is an incomplete type. 332 /// A type that can describe objects, but which lacks information needed to 333 /// determine its size (e.g. void, or a fwd declared struct). Clients of this 334 /// routine will need to determine if the size is actually required. 335 bool isIncompleteType() const; 336 337 /// isIncompleteOrObjectType - Return true if this is an incomplete or object 338 /// type, in other words, not a function type. 339 bool isIncompleteOrObjectType() const { 340 return !isFunctionType(); 341 } 342 343 /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 344 bool isPODType() const; 345 346 /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 347 /// types that have a non-constant expression. This does not include "[]". 348 bool isVariablyModifiedType() const; 349 350 /// Helper methods to distinguish type categories. All type predicates 351 /// operate on the canonical type, ignoring typedefs and qualifiers. 352 353 /// isSpecificBuiltinType - Test for a particular builtin type. 354 bool isSpecificBuiltinType(unsigned K) const; 355 356 /// isIntegerType() does *not* include complex integers (a GCC extension). 357 /// isComplexIntegerType() can be used to test for complex integers. 358 bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 359 bool isEnumeralType() const; 360 bool isBooleanType() const; 361 bool isCharType() const; 362 bool isWideCharType() const; 363 bool isIntegralType() const; 364 365 /// Floating point categories. 366 bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 367 /// isComplexType() does *not* include complex integers (a GCC extension). 368 /// isComplexIntegerType() can be used to test for complex integers. 369 bool isComplexType() const; // C99 6.2.5p11 (complex) 370 bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 371 bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 372 bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 373 bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 374 bool isVoidType() const; // C99 6.2.5p19 375 bool isDerivedType() const; // C99 6.2.5p20 376 bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 377 bool isAggregateType() const; 378 379 // Type Predicates: Check to see if this type is structurally the specified 380 // type, ignoring typedefs and qualifiers. 381 bool isFunctionType() const; 382 bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; } 383 bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; } 384 bool isPointerType() const; 385 bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 386 bool isBlockPointerType() const; 387 bool isVoidPointerType() const; 388 bool isReferenceType() const; 389 bool isLValueReferenceType() const; 390 bool isRValueReferenceType() const; 391 bool isFunctionPointerType() const; 392 bool isMemberPointerType() const; 393 bool isMemberFunctionPointerType() const; 394 bool isArrayType() const; 395 bool isConstantArrayType() const; 396 bool isIncompleteArrayType() const; 397 bool isVariableArrayType() const; 398 bool isDependentSizedArrayType() const; 399 bool isRecordType() const; 400 bool isClassType() const; 401 bool isStructureType() const; 402 bool isUnionType() const; 403 bool isComplexIntegerType() const; // GCC _Complex integer type. 404 bool isVectorType() const; // GCC vector type. 405 bool isExtVectorType() const; // Extended vector type. 406 bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 407 // FIXME: change this to 'raw' interface type, so we can used 'interface' type 408 // for the common case. 409 bool isObjCInterfaceType() const; // NSString or NSString<foo> 410 bool isObjCQualifiedInterfaceType() const; // NSString<foo> 411 bool isObjCQualifiedIdType() const; // id<foo> 412 bool isObjCQualifiedClassType() const; // Class<foo> 413 bool isObjCIdType() const; // id 414 bool isObjCClassType() const; // Class 415 bool isObjCBuiltinType() const; // 'id' or 'Class' 416 bool isTemplateTypeParmType() const; // C++ template type parameter 417 bool isNullPtrType() const; // C++0x nullptr_t 418 419 /// isDependentType - Whether this type is a dependent type, meaning 420 /// that its definition somehow depends on a template parameter 421 /// (C++ [temp.dep.type]). 422 bool isDependentType() const { return Dependent; } 423 bool isOverloadableType() const; 424 425 /// hasPointerRepresentation - Whether this type is represented 426 /// natively as a pointer; this includes pointers, references, block 427 /// pointers, and Objective-C interface, qualified id, and qualified 428 /// interface types, as well as nullptr_t. 429 bool hasPointerRepresentation() const; 430 431 /// hasObjCPointerRepresentation - Whether this type can represent 432 /// an objective pointer type for the purpose of GC'ability 433 bool hasObjCPointerRepresentation() const; 434 435 // Type Checking Functions: Check to see if this type is structurally the 436 // specified type, ignoring typedefs and qualifiers, and return a pointer to 437 // the best type we can. 438 const BuiltinType *getAsBuiltinType() const; 439 const FunctionType *getAsFunctionType() const; 440 const FunctionNoProtoType *getAsFunctionNoProtoType() const; 441 const FunctionProtoType *getAsFunctionProtoType() const; 442 const RecordType *getAsStructureType() const; 443 /// NOTE: getAs*ArrayType are methods on ASTContext. 444 const TypedefType *getAsTypedefType() const; 445 const RecordType *getAsUnionType() const; 446 const EnumType *getAsEnumType() const; 447 const VectorType *getAsVectorType() const; // GCC vector type. 448 const ComplexType *getAsComplexType() const; 449 const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 450 const ExtVectorType *getAsExtVectorType() const; // Extended vector type. 451 const ObjCObjectPointerType *getAsObjCObjectPointerType() const; 452 // The following is a convenience method that returns an ObjCObjectPointerType 453 // for object declared using an interface. 454 const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 455 const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 456 const ObjCInterfaceType *getAsObjCInterfaceType() const; 457 const ObjCInterfaceType *getAsObjCQualifiedInterfaceType() const; 458 const TemplateTypeParmType *getAsTemplateTypeParmType() const; 459 const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 460 461 // Member-template getAs<specific type>'. This scheme will eventually 462 // replace the specific getAsXXXX methods above. 463 template <typename T> const T *getAs() const; 464 465 const TemplateSpecializationType * 466 getAsTemplateSpecializationType() const; 467 468 /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 469 /// interface, return the interface type, otherwise return null. 470 const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 471 472 /// getArrayElementTypeNoTypeQual - If this is an array type, return the 473 /// element type of the array, potentially with type qualifiers missing. 474 /// This method should never be used when type qualifiers are meaningful. 475 const Type *getArrayElementTypeNoTypeQual() const; 476 477 /// getPointeeType - If this is a pointer, ObjC object pointer, or block 478 /// pointer, this returns the respective pointee. 479 QualType getPointeeType() const; 480 481 /// getDesugaredType - Return the specified type with any "sugar" removed from 482 /// the type. This takes off typedefs, typeof's etc. If the outer level of 483 /// the type is already concrete, it returns it unmodified. This is similar 484 /// to getting the canonical type, but it doesn't remove *all* typedefs. For 485 /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 486 /// concrete. 487 QualType getDesugaredType(bool ForDisplay = false) const; 488 489 /// More type predicates useful for type checking/promotion 490 bool isPromotableIntegerType() const; // C99 6.3.1.1p2 491 492 /// isSignedIntegerType - Return true if this is an integer type that is 493 /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 494 /// an enum decl which has a signed representation, or a vector of signed 495 /// integer element type. 496 bool isSignedIntegerType() const; 497 498 /// isUnsignedIntegerType - Return true if this is an integer type that is 499 /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 500 /// decl which has an unsigned representation, or a vector of unsigned integer 501 /// element type. 502 bool isUnsignedIntegerType() const; 503 504 /// isConstantSizeType - Return true if this is not a variable sized type, 505 /// according to the rules of C99 6.7.5p3. It is not legal to call this on 506 /// incomplete types. 507 bool isConstantSizeType() const; 508 509 /// isSpecifierType - Returns true if this type can be represented by some 510 /// set of type specifiers. 511 bool isSpecifierType() const; 512 513 QualType getCanonicalTypeInternal() const { return CanonicalType; } 514 void dump() const; 515 virtual void getAsStringInternal(std::string &InnerString, 516 const PrintingPolicy &Policy) const = 0; 517 static bool classof(const Type *) { return true; } 518}; 519 520/// ExtQualType - TR18037 (C embedded extensions) 6.2.5p26 521/// This supports all kinds of type attributes; including, 522/// address space qualified types, objective-c's __weak and 523/// __strong attributes. 524/// 525class ExtQualType : public Type, public llvm::FoldingSetNode { 526 /// BaseType - This is the underlying type that this qualifies. All CVR 527 /// qualifiers are stored on the QualType that references this type, so we 528 /// can't have any here. 529 Type *BaseType; 530 531 /// Address Space ID - The address space ID this type is qualified with. 532 unsigned AddressSpace; 533 /// GC __weak/__strong attributes 534 QualType::GCAttrTypes GCAttrType; 535 536 ExtQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace, 537 QualType::GCAttrTypes gcAttr) : 538 Type(ExtQual, CanonicalPtr, Base->isDependentType()), BaseType(Base), 539 AddressSpace(AddrSpace), GCAttrType(gcAttr) { 540 assert(!isa<ExtQualType>(BaseType) && 541 "Cannot have ExtQualType of ExtQualType"); 542 } 543 friend class ASTContext; // ASTContext creates these. 544public: 545 Type *getBaseType() const { return BaseType; } 546 QualType::GCAttrTypes getObjCGCAttr() const { return GCAttrType; } 547 unsigned getAddressSpace() const { return AddressSpace; } 548 549 virtual void getAsStringInternal(std::string &InnerString, 550 const PrintingPolicy &Policy) const; 551 552 void Profile(llvm::FoldingSetNodeID &ID) { 553 Profile(ID, getBaseType(), AddressSpace, GCAttrType); 554 } 555 static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 556 unsigned AddrSpace, QualType::GCAttrTypes gcAttr) { 557 ID.AddPointer(Base); 558 ID.AddInteger(AddrSpace); 559 ID.AddInteger(gcAttr); 560 } 561 562 static bool classof(const Type *T) { return T->getTypeClass() == ExtQual; } 563 static bool classof(const ExtQualType *) { return true; } 564}; 565 566 567/// QualifierSet - This class is used to collect qualifiers. 568/// Clang supports five independent qualifiers: 569/// * C99: const, volatile, and restrict 570/// * Embedded C (TR18037): address spaces 571/// * Objective C: the GC attributes (none, weak, or strong) 572class QualifierSet { 573public: 574 QualifierSet() : Mask(0) {} 575 576 void removeConst() { removeCVR(QualType::Const); } 577 void removeVolatile() { removeCVR(QualType::Volatile); } 578 void removeRestrict() { removeCVR(QualType::Restrict); } 579 void removeCVR(unsigned mask) { Mask &= ~mask; } 580 void removeAddressSpace() { setAddressSpace(0); } 581 void removeObjCGCAttrType() { setGCAttrType(QualType::GCNone); } 582 583 void addConst() { addCVR(QualType::Const); } 584 void addVolatile() { addCVR(QualType::Volatile); } 585 void addRestrict() { addCVR(QualType::Restrict); } 586 void addCVR(unsigned mask) { Mask |= mask; } 587 void addAddressSpace(unsigned space) { 588 assert(space); 589 setAddressSpace(space); 590 } 591 void addObjCGCAttrType(QualType::GCAttrTypes type) { 592 assert(type); 593 setGCAttrType(type); 594 } 595 596 bool hasConst() const { return Mask & QualType::Const; } 597 bool hasVolatile() const { return Mask & QualType::Volatile; } 598 bool hasRestrict() const { return Mask & QualType::Restrict; } 599 unsigned getCVRMask() const { return Mask & CVRMask; } 600 601 bool hasObjCGCAttrType() const { return Mask & GCAttrMask; } 602 QualType::GCAttrTypes getObjCGCAttrType() const { 603 return QualType::GCAttrTypes((Mask & GCAttrMask) >> GCAttrShift); 604 } 605 606 bool hasAddressSpace() const { return Mask & AddressSpaceMask; } 607 unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; } 608 609 /// empty() - Return true if there are no qualifiers collected 610 /// in this set. 611 bool empty() { 612 return (Mask == 0); 613 } 614 615 /// Collect any qualifiers on the given type and return an 616 /// unqualified type. 617 const Type *strip(QualType QT) { 618 Mask |= QT.getCVRQualifiers(); 619 return strip(QT.getTypePtr()); 620 } 621 622 /// Collect any qualifiers on the given type and return an 623 /// unqualified type. 624 const Type *strip(const Type* T); 625 626 /// Apply the collected qualifiers to the given type. 627 QualType apply(QualType QT, ASTContext& C); 628 629 /// Apply the collected qualifiers to the given type. 630 QualType apply(const Type* T, ASTContext& C) { 631 return apply(QualType(T, 0), C); 632 } 633 634 bool operator==(QualifierSet& Other) { return Mask == Other.Mask; } 635 636private: 637 void setAddressSpace(unsigned space) { 638 assert(space <= MaxAddressSpace); 639 Mask = (Mask & ~AddressSpaceMask) 640 | (((uint32_t) space) << AddressSpaceShift); 641 } 642 643 void setGCAttrType(QualType::GCAttrTypes type) { 644 Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift); 645 } 646 647 // bits: |0 1 2|3 .. 4|5 .. 31| 648 // |C R V|GCAttr|AddrSpace| 649 uint32_t Mask; 650 651 static const uint32_t CVRMask = 0x07; 652 static const uint32_t GCAttrMask = 0x18; 653 static const uint32_t GCAttrShift = 3; 654 static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask); 655 static const uint32_t AddressSpaceShift = 5; 656 static const unsigned MaxAddressSpace = QualType::MaxAddressSpace; 657}; 658 659 660/// BuiltinType - This class is used for builtin types like 'int'. Builtin 661/// types are always canonical and have a literal name field. 662class BuiltinType : public Type { 663public: 664 enum Kind { 665 Void, 666 667 Bool, // This is bool and/or _Bool. 668 Char_U, // This is 'char' for targets where char is unsigned. 669 UChar, // This is explicitly qualified unsigned char. 670 Char16, // This is 'char16_t' for C++. 671 Char32, // This is 'char32_t' for C++. 672 UShort, 673 UInt, 674 ULong, 675 ULongLong, 676 UInt128, // __uint128_t 677 678 Char_S, // This is 'char' for targets where char is signed. 679 SChar, // This is explicitly qualified signed char. 680 WChar, // This is 'wchar_t' for C++. 681 Short, 682 Int, 683 Long, 684 LongLong, 685 Int128, // __int128_t 686 687 Float, Double, LongDouble, 688 689 NullPtr, // This is the type of C++0x 'nullptr'. 690 691 Overload, // This represents the type of an overloaded function declaration. 692 Dependent, // This represents the type of a type-dependent expression. 693 694 UndeducedAuto, // In C++0x, this represents the type of an auto variable 695 // that has not been deduced yet. 696 ObjCId, // This represents the ObjC 'id' type. 697 ObjCClass // This represents the ObjC 'Class' type. 698 }; 699private: 700 Kind TypeKind; 701public: 702 BuiltinType(Kind K) 703 : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 704 TypeKind(K) {} 705 706 Kind getKind() const { return TypeKind; } 707 const char *getName(const LangOptions &LO) const; 708 709 virtual void getAsStringInternal(std::string &InnerString, 710 const PrintingPolicy &Policy) const; 711 712 static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 713 static bool classof(const BuiltinType *) { return true; } 714}; 715 716/// FixedWidthIntType - Used for arbitrary width types that we either don't 717/// want to or can't map to named integer types. These always have a lower 718/// integer rank than builtin types of the same width. 719class FixedWidthIntType : public Type { 720private: 721 unsigned Width; 722 bool Signed; 723public: 724 FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false), 725 Width(W), Signed(S) {} 726 727 unsigned getWidth() const { return Width; } 728 bool isSigned() const { return Signed; } 729 const char *getName() const; 730 731 virtual void getAsStringInternal(std::string &InnerString, 732 const PrintingPolicy &Policy) const; 733 734 static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; } 735 static bool classof(const FixedWidthIntType *) { return true; } 736}; 737 738/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 739/// types (_Complex float etc) as well as the GCC integer complex extensions. 740/// 741class ComplexType : public Type, public llvm::FoldingSetNode { 742 QualType ElementType; 743 ComplexType(QualType Element, QualType CanonicalPtr) : 744 Type(Complex, CanonicalPtr, Element->isDependentType()), 745 ElementType(Element) { 746 } 747 friend class ASTContext; // ASTContext creates these. 748public: 749 QualType getElementType() const { return ElementType; } 750 751 virtual void getAsStringInternal(std::string &InnerString, 752 const PrintingPolicy &Policy) const; 753 754 void Profile(llvm::FoldingSetNodeID &ID) { 755 Profile(ID, getElementType()); 756 } 757 static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 758 ID.AddPointer(Element.getAsOpaquePtr()); 759 } 760 761 static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 762 static bool classof(const ComplexType *) { return true; } 763}; 764 765/// PointerType - C99 6.7.5.1 - Pointer Declarators. 766/// 767class PointerType : public Type, public llvm::FoldingSetNode { 768 QualType PointeeType; 769 770 PointerType(QualType Pointee, QualType CanonicalPtr) : 771 Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 772 } 773 friend class ASTContext; // ASTContext creates these. 774public: 775 776 virtual void getAsStringInternal(std::string &InnerString, 777 const PrintingPolicy &Policy) const; 778 779 QualType getPointeeType() const { return PointeeType; } 780 781 void Profile(llvm::FoldingSetNodeID &ID) { 782 Profile(ID, getPointeeType()); 783 } 784 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 785 ID.AddPointer(Pointee.getAsOpaquePtr()); 786 } 787 788 static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 789 static bool classof(const PointerType *) { return true; } 790}; 791 792/// BlockPointerType - pointer to a block type. 793/// This type is to represent types syntactically represented as 794/// "void (^)(int)", etc. Pointee is required to always be a function type. 795/// 796class BlockPointerType : public Type, public llvm::FoldingSetNode { 797 QualType PointeeType; // Block is some kind of pointer type 798 BlockPointerType(QualType Pointee, QualType CanonicalCls) : 799 Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 800 PointeeType(Pointee) { 801 } 802 friend class ASTContext; // ASTContext creates these. 803public: 804 805 // Get the pointee type. Pointee is required to always be a function type. 806 QualType getPointeeType() const { return PointeeType; } 807 808 virtual void getAsStringInternal(std::string &InnerString, 809 const PrintingPolicy &Policy) const; 810 811 void Profile(llvm::FoldingSetNodeID &ID) { 812 Profile(ID, getPointeeType()); 813 } 814 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 815 ID.AddPointer(Pointee.getAsOpaquePtr()); 816 } 817 818 static bool classof(const Type *T) { 819 return T->getTypeClass() == BlockPointer; 820 } 821 static bool classof(const BlockPointerType *) { return true; } 822}; 823 824/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 825/// 826class ReferenceType : public Type, public llvm::FoldingSetNode { 827 QualType PointeeType; 828 829protected: 830 ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) : 831 Type(tc, CanonicalRef, Referencee->isDependentType()), 832 PointeeType(Referencee) { 833 } 834public: 835 QualType getPointeeType() const { return PointeeType; } 836 837 void Profile(llvm::FoldingSetNodeID &ID) { 838 Profile(ID, getPointeeType()); 839 } 840 static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 841 ID.AddPointer(Referencee.getAsOpaquePtr()); 842 } 843 844 static bool classof(const Type *T) { 845 return T->getTypeClass() == LValueReference || 846 T->getTypeClass() == RValueReference; 847 } 848 static bool classof(const ReferenceType *) { return true; } 849}; 850 851/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 852/// 853class LValueReferenceType : public ReferenceType { 854 LValueReferenceType(QualType Referencee, QualType CanonicalRef) : 855 ReferenceType(LValueReference, Referencee, CanonicalRef) { 856 } 857 friend class ASTContext; // ASTContext creates these 858public: 859 virtual void getAsStringInternal(std::string &InnerString, 860 const PrintingPolicy &Policy) const; 861 862 static bool classof(const Type *T) { 863 return T->getTypeClass() == LValueReference; 864 } 865 static bool classof(const LValueReferenceType *) { return true; } 866}; 867 868/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 869/// 870class RValueReferenceType : public ReferenceType { 871 RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 872 ReferenceType(RValueReference, Referencee, CanonicalRef) { 873 } 874 friend class ASTContext; // ASTContext creates these 875public: 876 virtual void getAsStringInternal(std::string &InnerString, 877 const PrintingPolicy &Policy) const; 878 879 static bool classof(const Type *T) { 880 return T->getTypeClass() == RValueReference; 881 } 882 static bool classof(const RValueReferenceType *) { return true; } 883}; 884 885/// MemberPointerType - C++ 8.3.3 - Pointers to members 886/// 887class MemberPointerType : public Type, public llvm::FoldingSetNode { 888 QualType PointeeType; 889 /// The class of which the pointee is a member. Must ultimately be a 890 /// RecordType, but could be a typedef or a template parameter too. 891 const Type *Class; 892 893 MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 894 Type(MemberPointer, CanonicalPtr, 895 Cls->isDependentType() || Pointee->isDependentType()), 896 PointeeType(Pointee), Class(Cls) { 897 } 898 friend class ASTContext; // ASTContext creates these. 899public: 900 901 QualType getPointeeType() const { return PointeeType; } 902 903 const Type *getClass() const { return Class; } 904 905 virtual void getAsStringInternal(std::string &InnerString, 906 const PrintingPolicy &Policy) const; 907 908 void Profile(llvm::FoldingSetNodeID &ID) { 909 Profile(ID, getPointeeType(), getClass()); 910 } 911 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 912 const Type *Class) { 913 ID.AddPointer(Pointee.getAsOpaquePtr()); 914 ID.AddPointer(Class); 915 } 916 917 static bool classof(const Type *T) { 918 return T->getTypeClass() == MemberPointer; 919 } 920 static bool classof(const MemberPointerType *) { return true; } 921}; 922 923/// ArrayType - C99 6.7.5.2 - Array Declarators. 924/// 925class ArrayType : public Type, public llvm::FoldingSetNode { 926public: 927 /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 928 /// an array with a static size (e.g. int X[static 4]), or an array 929 /// with a star size (e.g. int X[*]). 930 /// 'static' is only allowed on function parameters. 931 enum ArraySizeModifier { 932 Normal, Static, Star 933 }; 934private: 935 /// ElementType - The element type of the array. 936 QualType ElementType; 937 938 // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 939 /// NOTE: These fields are packed into the bitfields space in the Type class. 940 unsigned SizeModifier : 2; 941 942 /// IndexTypeQuals - Capture qualifiers in declarations like: 943 /// 'int X[static restrict 4]'. For function parameters only. 944 unsigned IndexTypeQuals : 3; 945 946protected: 947 // C++ [temp.dep.type]p1: 948 // A type is dependent if it is... 949 // - an array type constructed from any dependent type or whose 950 // size is specified by a constant expression that is 951 // value-dependent, 952 ArrayType(TypeClass tc, QualType et, QualType can, 953 ArraySizeModifier sm, unsigned tq) 954 : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 955 ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 956 957 friend class ASTContext; // ASTContext creates these. 958public: 959 QualType getElementType() const { return ElementType; } 960 ArraySizeModifier getSizeModifier() const { 961 return ArraySizeModifier(SizeModifier); 962 } 963 unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 964 965 static bool classof(const Type *T) { 966 return T->getTypeClass() == ConstantArray || 967 T->getTypeClass() == ConstantArrayWithExpr || 968 T->getTypeClass() == ConstantArrayWithoutExpr || 969 T->getTypeClass() == VariableArray || 970 T->getTypeClass() == IncompleteArray || 971 T->getTypeClass() == DependentSizedArray; 972 } 973 static bool classof(const ArrayType *) { return true; } 974}; 975 976/// ConstantArrayType - This class represents the canonical version of 977/// C arrays with a specified constant size. For example, the canonical 978/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 979/// type is 'int' and the size is 404. 980class ConstantArrayType : public ArrayType { 981 llvm::APInt Size; // Allows us to unique the type. 982 983 ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 984 ArraySizeModifier sm, unsigned tq) 985 : ArrayType(ConstantArray, et, can, sm, tq), 986 Size(size) {} 987protected: 988 ConstantArrayType(TypeClass tc, QualType et, QualType can, 989 const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 990 : ArrayType(tc, et, can, sm, tq), Size(size) {} 991 friend class ASTContext; // ASTContext creates these. 992public: 993 const llvm::APInt &getSize() const { return Size; } 994 virtual void getAsStringInternal(std::string &InnerString, 995 const PrintingPolicy &Policy) const; 996 997 void Profile(llvm::FoldingSetNodeID &ID) { 998 Profile(ID, getElementType(), getSize(), 999 getSizeModifier(), getIndexTypeQualifier()); 1000 } 1001 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 1002 const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 1003 unsigned TypeQuals) { 1004 ID.AddPointer(ET.getAsOpaquePtr()); 1005 ID.AddInteger(ArraySize.getZExtValue()); 1006 ID.AddInteger(SizeMod); 1007 ID.AddInteger(TypeQuals); 1008 } 1009 static bool classof(const Type *T) { 1010 return T->getTypeClass() == ConstantArray || 1011 T->getTypeClass() == ConstantArrayWithExpr || 1012 T->getTypeClass() == ConstantArrayWithoutExpr; 1013 } 1014 static bool classof(const ConstantArrayType *) { return true; } 1015}; 1016 1017/// ConstantArrayWithExprType - This class represents C arrays with a 1018/// constant size specified by means of an integer constant expression. 1019/// For example 'int A[sizeof(int)]' has ConstantArrayWithExprType where 1020/// the element type is 'int' and the size expression is 'sizeof(int)'. 1021/// These types are non-canonical. 1022class ConstantArrayWithExprType : public ConstantArrayType { 1023 /// SizeExpr - The ICE occurring in the concrete syntax. 1024 Expr *SizeExpr; 1025 /// Brackets - The left and right array brackets. 1026 SourceRange Brackets; 1027 1028 ConstantArrayWithExprType(QualType et, QualType can, 1029 const llvm::APInt &size, Expr *e, 1030 ArraySizeModifier sm, unsigned tq, 1031 SourceRange brackets) 1032 : ConstantArrayType(ConstantArrayWithExpr, et, can, size, sm, tq), 1033 SizeExpr(e), Brackets(brackets) {} 1034 friend class ASTContext; // ASTContext creates these. 1035 virtual void Destroy(ASTContext& C); 1036 1037public: 1038 Expr *getSizeExpr() const { return SizeExpr; } 1039 SourceRange getBracketsRange() const { return Brackets; } 1040 SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 1041 SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 1042 1043 virtual void getAsStringInternal(std::string &InnerString, 1044 const PrintingPolicy &Policy) const; 1045 1046 static bool classof(const Type *T) { 1047 return T->getTypeClass() == ConstantArrayWithExpr; 1048 } 1049 static bool classof(const ConstantArrayWithExprType *) { return true; } 1050 1051 void Profile(llvm::FoldingSetNodeID &ID) { 1052 assert(0 && "Cannot unique ConstantArrayWithExprTypes."); 1053 } 1054}; 1055 1056/// ConstantArrayWithoutExprType - This class represents C arrays with a 1057/// constant size that was not specified by an integer constant expression, 1058/// but inferred by static semantics. 1059/// For example 'int A[] = { 0, 1, 2 }' has ConstantArrayWithoutExprType. 1060/// These types are non-canonical: the corresponding canonical type, 1061/// having the size specified in an APInt object, is a ConstantArrayType. 1062class ConstantArrayWithoutExprType : public ConstantArrayType { 1063 1064 ConstantArrayWithoutExprType(QualType et, QualType can, 1065 const llvm::APInt &size, 1066 ArraySizeModifier sm, unsigned tq) 1067 : ConstantArrayType(ConstantArrayWithoutExpr, et, can, size, sm, tq) {} 1068 friend class ASTContext; // ASTContext creates these. 1069 1070public: 1071 virtual void getAsStringInternal(std::string &InnerString, 1072 const PrintingPolicy &Policy) const; 1073 1074 static bool classof(const Type *T) { 1075 return T->getTypeClass() == ConstantArrayWithoutExpr; 1076 } 1077 static bool classof(const ConstantArrayWithoutExprType *) { return true; } 1078 1079 void Profile(llvm::FoldingSetNodeID &ID) { 1080 assert(0 && "Cannot unique ConstantArrayWithoutExprTypes."); 1081 } 1082}; 1083 1084/// IncompleteArrayType - This class represents C arrays with an unspecified 1085/// size. For example 'int A[]' has an IncompleteArrayType where the element 1086/// type is 'int' and the size is unspecified. 1087class IncompleteArrayType : public ArrayType { 1088 1089 IncompleteArrayType(QualType et, QualType can, 1090 ArraySizeModifier sm, unsigned tq) 1091 : ArrayType(IncompleteArray, et, can, sm, tq) {} 1092 friend class ASTContext; // ASTContext creates these. 1093public: 1094 virtual void getAsStringInternal(std::string &InnerString, 1095 const PrintingPolicy &Policy) const; 1096 1097 static bool classof(const Type *T) { 1098 return T->getTypeClass() == IncompleteArray; 1099 } 1100 static bool classof(const IncompleteArrayType *) { return true; } 1101 1102 friend class StmtIteratorBase; 1103 1104 void Profile(llvm::FoldingSetNodeID &ID) { 1105 Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier()); 1106 } 1107 1108 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 1109 ArraySizeModifier SizeMod, unsigned TypeQuals) { 1110 ID.AddPointer(ET.getAsOpaquePtr()); 1111 ID.AddInteger(SizeMod); 1112 ID.AddInteger(TypeQuals); 1113 } 1114}; 1115 1116/// VariableArrayType - This class represents C arrays with a specified size 1117/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 1118/// Since the size expression is an arbitrary expression, we store it as such. 1119/// 1120/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 1121/// should not be: two lexically equivalent variable array types could mean 1122/// different things, for example, these variables do not have the same type 1123/// dynamically: 1124/// 1125/// void foo(int x) { 1126/// int Y[x]; 1127/// ++x; 1128/// int Z[x]; 1129/// } 1130/// 1131class VariableArrayType : public ArrayType { 1132 /// SizeExpr - An assignment expression. VLA's are only permitted within 1133 /// a function block. 1134 Stmt *SizeExpr; 1135 /// Brackets - The left and right array brackets. 1136 SourceRange Brackets; 1137 1138 VariableArrayType(QualType et, QualType can, Expr *e, 1139 ArraySizeModifier sm, unsigned tq, 1140 SourceRange brackets) 1141 : ArrayType(VariableArray, et, can, sm, tq), 1142 SizeExpr((Stmt*) e), Brackets(brackets) {} 1143 friend class ASTContext; // ASTContext creates these. 1144 virtual void Destroy(ASTContext& C); 1145 1146public: 1147 Expr *getSizeExpr() const { 1148 // We use C-style casts instead of cast<> here because we do not wish 1149 // to have a dependency of Type.h on Stmt.h/Expr.h. 1150 return (Expr*) SizeExpr; 1151 } 1152 SourceRange getBracketsRange() const { return Brackets; } 1153 SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 1154 SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 1155 1156 virtual void getAsStringInternal(std::string &InnerString, 1157 const PrintingPolicy &Policy) const; 1158 1159 static bool classof(const Type *T) { 1160 return T->getTypeClass() == VariableArray; 1161 } 1162 static bool classof(const VariableArrayType *) { return true; } 1163 1164 friend class StmtIteratorBase; 1165 1166 void Profile(llvm::FoldingSetNodeID &ID) { 1167 assert(0 && "Cannnot unique VariableArrayTypes."); 1168 } 1169}; 1170 1171/// DependentSizedArrayType - This type represents an array type in 1172/// C++ whose size is a value-dependent expression. For example: 1173/// @code 1174/// template<typename T, int Size> 1175/// class array { 1176/// T data[Size]; 1177/// }; 1178/// @endcode 1179/// For these types, we won't actually know what the array bound is 1180/// until template instantiation occurs, at which point this will 1181/// become either a ConstantArrayType or a VariableArrayType. 1182class DependentSizedArrayType : public ArrayType { 1183 /// SizeExpr - An assignment expression that will instantiate to the 1184 /// size of the array. 1185 Stmt *SizeExpr; 1186 /// Brackets - The left and right array brackets. 1187 SourceRange Brackets; 1188 1189 DependentSizedArrayType(QualType et, QualType can, Expr *e, 1190 ArraySizeModifier sm, unsigned tq, 1191 SourceRange brackets) 1192 : ArrayType(DependentSizedArray, et, can, sm, tq), 1193 SizeExpr((Stmt*) e), Brackets(brackets) {} 1194 friend class ASTContext; // ASTContext creates these. 1195 virtual void Destroy(ASTContext& C); 1196 1197public: 1198 Expr *getSizeExpr() const { 1199 // We use C-style casts instead of cast<> here because we do not wish 1200 // to have a dependency of Type.h on Stmt.h/Expr.h. 1201 return (Expr*) SizeExpr; 1202 } 1203 SourceRange getBracketsRange() const { return Brackets; } 1204 SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 1205 SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 1206 1207 virtual void getAsStringInternal(std::string &InnerString, 1208 const PrintingPolicy &Policy) const; 1209 1210 static bool classof(const Type *T) { 1211 return T->getTypeClass() == DependentSizedArray; 1212 } 1213 static bool classof(const DependentSizedArrayType *) { return true; } 1214 1215 friend class StmtIteratorBase; 1216 1217 void Profile(llvm::FoldingSetNodeID &ID) { 1218 assert(0 && "Cannnot unique DependentSizedArrayTypes."); 1219 } 1220}; 1221 1222/// DependentSizedExtVectorType - This type represent an extended vector type 1223/// where either the type or size is dependent. For example: 1224/// @code 1225/// template<typename T, int Size> 1226/// class vector { 1227/// typedef T __attribute__((ext_vector_type(Size))) type; 1228/// } 1229/// @endcode 1230class DependentSizedExtVectorType : public Type { 1231 Expr *SizeExpr; 1232 /// ElementType - The element type of the array. 1233 QualType ElementType; 1234 SourceLocation loc; 1235 1236 DependentSizedExtVectorType(QualType ElementType, QualType can, 1237 Expr *SizeExpr, SourceLocation loc) 1238 : Type (DependentSizedExtVector, can, true), 1239 SizeExpr(SizeExpr), ElementType(ElementType), loc(loc) {} 1240 friend class ASTContext; 1241 virtual void Destroy(ASTContext& C); 1242 1243public: 1244 const Expr *getSizeExpr() const { return SizeExpr; } 1245 QualType getElementType() const { return ElementType; } 1246 SourceLocation getAttributeLoc() const { return loc; } 1247 1248 virtual void getAsStringInternal(std::string &InnerString, 1249 const PrintingPolicy &Policy) const; 1250 1251 static bool classof(const Type *T) { 1252 return T->getTypeClass() == DependentSizedExtVector; 1253 } 1254 static bool classof(const DependentSizedExtVectorType *) { return true; } 1255}; 1256 1257 1258/// VectorType - GCC generic vector type. This type is created using 1259/// __attribute__((vector_size(n)), where "n" specifies the vector size in 1260/// bytes. Since the constructor takes the number of vector elements, the 1261/// client is responsible for converting the size into the number of elements. 1262class VectorType : public Type, public llvm::FoldingSetNode { 1263protected: 1264 /// ElementType - The element type of the vector. 1265 QualType ElementType; 1266 1267 /// NumElements - The number of elements in the vector. 1268 unsigned NumElements; 1269 1270 VectorType(QualType vecType, unsigned nElements, QualType canonType) : 1271 Type(Vector, canonType, vecType->isDependentType()), 1272 ElementType(vecType), NumElements(nElements) {} 1273 VectorType(TypeClass tc, QualType vecType, unsigned nElements, 1274 QualType canonType) 1275 : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 1276 NumElements(nElements) {} 1277 friend class ASTContext; // ASTContext creates these. 1278public: 1279 1280 QualType getElementType() const { return ElementType; } 1281 unsigned getNumElements() const { return NumElements; } 1282 1283 virtual void getAsStringInternal(std::string &InnerString, 1284 const PrintingPolicy &Policy) const; 1285 1286 void Profile(llvm::FoldingSetNodeID &ID) { 1287 Profile(ID, getElementType(), getNumElements(), getTypeClass()); 1288 } 1289 static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 1290 unsigned NumElements, TypeClass TypeClass) { 1291 ID.AddPointer(ElementType.getAsOpaquePtr()); 1292 ID.AddInteger(NumElements); 1293 ID.AddInteger(TypeClass); 1294 } 1295 static bool classof(const Type *T) { 1296 return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 1297 } 1298 static bool classof(const VectorType *) { return true; } 1299}; 1300 1301/// ExtVectorType - Extended vector type. This type is created using 1302/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1303/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1304/// class enables syntactic extensions, like Vector Components for accessing 1305/// points, colors, and textures (modeled after OpenGL Shading Language). 1306class ExtVectorType : public VectorType { 1307 ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1308 VectorType(ExtVector, vecType, nElements, canonType) {} 1309 friend class ASTContext; // ASTContext creates these. 1310public: 1311 static int getPointAccessorIdx(char c) { 1312 switch (c) { 1313 default: return -1; 1314 case 'x': return 0; 1315 case 'y': return 1; 1316 case 'z': return 2; 1317 case 'w': return 3; 1318 } 1319 } 1320 static int getNumericAccessorIdx(char c) { 1321 switch (c) { 1322 default: return -1; 1323 case '0': return 0; 1324 case '1': return 1; 1325 case '2': return 2; 1326 case '3': return 3; 1327 case '4': return 4; 1328 case '5': return 5; 1329 case '6': return 6; 1330 case '7': return 7; 1331 case '8': return 8; 1332 case '9': return 9; 1333 case 'A': 1334 case 'a': return 10; 1335 case 'B': 1336 case 'b': return 11; 1337 case 'C': 1338 case 'c': return 12; 1339 case 'D': 1340 case 'd': return 13; 1341 case 'E': 1342 case 'e': return 14; 1343 case 'F': 1344 case 'f': return 15; 1345 } 1346 } 1347 1348 static int getAccessorIdx(char c) { 1349 if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1350 return getNumericAccessorIdx(c); 1351 } 1352 1353 bool isAccessorWithinNumElements(char c) const { 1354 if (int idx = getAccessorIdx(c)+1) 1355 return unsigned(idx-1) < NumElements; 1356 return false; 1357 } 1358 virtual void getAsStringInternal(std::string &InnerString, 1359 const PrintingPolicy &Policy) const; 1360 1361 static bool classof(const Type *T) { 1362 return T->getTypeClass() == ExtVector; 1363 } 1364 static bool classof(const ExtVectorType *) { return true; } 1365}; 1366 1367/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 1368/// class of FunctionNoProtoType and FunctionProtoType. 1369/// 1370class FunctionType : public Type { 1371 /// SubClassData - This field is owned by the subclass, put here to pack 1372 /// tightly with the ivars in Type. 1373 bool SubClassData : 1; 1374 1375 /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1376 /// other bitfields. 1377 /// The qualifiers are part of FunctionProtoType because... 1378 /// 1379 /// C++ 8.3.5p4: The return type, the parameter type list and the 1380 /// cv-qualifier-seq, [...], are part of the function type. 1381 /// 1382 unsigned TypeQuals : 3; 1383 1384 /// NoReturn - Indicates if the function type is attribute noreturn. 1385 unsigned NoReturn : 1; 1386 1387 // The type returned by the function. 1388 QualType ResultType; 1389protected: 1390 FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 1391 unsigned typeQuals, QualType Canonical, bool Dependent, 1392 bool noReturn = false) 1393 : Type(tc, Canonical, Dependent), 1394 SubClassData(SubclassInfo), TypeQuals(typeQuals), NoReturn(noReturn), 1395 ResultType(res) {} 1396 bool getSubClassData() const { return SubClassData; } 1397 unsigned getTypeQuals() const { return TypeQuals; } 1398public: 1399 1400 QualType getResultType() const { return ResultType; } 1401 bool getNoReturnAttr() const { return NoReturn; } 1402 1403 1404 static bool classof(const Type *T) { 1405 return T->getTypeClass() == FunctionNoProto || 1406 T->getTypeClass() == FunctionProto; 1407 } 1408 static bool classof(const FunctionType *) { return true; } 1409}; 1410 1411/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 1412/// no information available about its arguments. 1413class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 1414 FunctionNoProtoType(QualType Result, QualType Canonical, 1415 bool NoReturn = false) 1416 : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 1417 /*Dependent=*/false, NoReturn) {} 1418 friend class ASTContext; // ASTContext creates these. 1419public: 1420 // No additional state past what FunctionType provides. 1421 1422 virtual void getAsStringInternal(std::string &InnerString, 1423 const PrintingPolicy &Policy) const; 1424 1425 void Profile(llvm::FoldingSetNodeID &ID) { 1426 Profile(ID, getResultType(), getNoReturnAttr()); 1427 } 1428 static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 1429 bool NoReturn) { 1430 ID.AddInteger(NoReturn); 1431 ID.AddPointer(ResultType.getAsOpaquePtr()); 1432 } 1433 1434 static bool classof(const Type *T) { 1435 return T->getTypeClass() == FunctionNoProto; 1436 } 1437 static bool classof(const FunctionNoProtoType *) { return true; } 1438}; 1439 1440/// FunctionProtoType - Represents a prototype with argument type info, e.g. 1441/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 1442/// arguments, not as having a single void argument. Such a type can have an 1443/// exception specification, but this specification is not part of the canonical 1444/// type. 1445class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 1446 /// hasAnyDependentType - Determine whether there are any dependent 1447 /// types within the arguments passed in. 1448 static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 1449 for (unsigned Idx = 0; Idx < numArgs; ++Idx) 1450 if (ArgArray[Idx]->isDependentType()) 1451 return true; 1452 1453 return false; 1454 } 1455 1456 FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 1457 bool isVariadic, unsigned typeQuals, bool hasExs, 1458 bool hasAnyExs, const QualType *ExArray, 1459 unsigned numExs, QualType Canonical, bool NoReturn) 1460 : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 1461 (Result->isDependentType() || 1462 hasAnyDependentType(ArgArray, numArgs)), NoReturn), 1463 NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 1464 AnyExceptionSpec(hasAnyExs) { 1465 // Fill in the trailing argument array. 1466 QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 1467 for (unsigned i = 0; i != numArgs; ++i) 1468 ArgInfo[i] = ArgArray[i]; 1469 // Fill in the exception array. 1470 QualType *Ex = ArgInfo + numArgs; 1471 for (unsigned i = 0; i != numExs; ++i) 1472 Ex[i] = ExArray[i]; 1473 } 1474 1475 /// NumArgs - The number of arguments this function has, not counting '...'. 1476 unsigned NumArgs : 20; 1477 1478 /// NumExceptions - The number of types in the exception spec, if any. 1479 unsigned NumExceptions : 10; 1480 1481 /// HasExceptionSpec - Whether this function has an exception spec at all. 1482 bool HasExceptionSpec : 1; 1483 1484 /// AnyExceptionSpec - Whether this function has a throw(...) spec. 1485 bool AnyExceptionSpec : 1; 1486 1487 /// ArgInfo - There is an variable size array after the class in memory that 1488 /// holds the argument types. 1489 1490 /// Exceptions - There is another variable size array after ArgInfo that 1491 /// holds the exception types. 1492 1493 friend class ASTContext; // ASTContext creates these. 1494 1495public: 1496 unsigned getNumArgs() const { return NumArgs; } 1497 QualType getArgType(unsigned i) const { 1498 assert(i < NumArgs && "Invalid argument number!"); 1499 return arg_type_begin()[i]; 1500 } 1501 1502 bool hasExceptionSpec() const { return HasExceptionSpec; } 1503 bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 1504 unsigned getNumExceptions() const { return NumExceptions; } 1505 QualType getExceptionType(unsigned i) const { 1506 assert(i < NumExceptions && "Invalid exception number!"); 1507 return exception_begin()[i]; 1508 } 1509 bool hasEmptyExceptionSpec() const { 1510 return hasExceptionSpec() && !hasAnyExceptionSpec() && 1511 getNumExceptions() == 0; 1512 } 1513 1514 bool isVariadic() const { return getSubClassData(); } 1515 unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 1516 1517 typedef const QualType *arg_type_iterator; 1518 arg_type_iterator arg_type_begin() const { 1519 return reinterpret_cast<const QualType *>(this+1); 1520 } 1521 arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1522 1523 typedef const QualType *exception_iterator; 1524 exception_iterator exception_begin() const { 1525 // exceptions begin where arguments end 1526 return arg_type_end(); 1527 } 1528 exception_iterator exception_end() const { 1529 return exception_begin() + NumExceptions; 1530 } 1531 1532 virtual void getAsStringInternal(std::string &InnerString, 1533 const PrintingPolicy &Policy) const; 1534 1535 static bool classof(const Type *T) { 1536 return T->getTypeClass() == FunctionProto; 1537 } 1538 static bool classof(const FunctionProtoType *) { return true; } 1539 1540 void Profile(llvm::FoldingSetNodeID &ID); 1541 static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1542 arg_type_iterator ArgTys, unsigned NumArgs, 1543 bool isVariadic, unsigned TypeQuals, 1544 bool hasExceptionSpec, bool anyExceptionSpec, 1545 unsigned NumExceptions, exception_iterator Exs, 1546 bool NoReturn); 1547}; 1548 1549 1550class TypedefType : public Type { 1551 TypedefDecl *Decl; 1552protected: 1553 TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 1554 : Type(tc, can, can->isDependentType()), Decl(D) { 1555 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1556 } 1557 friend class ASTContext; // ASTContext creates these. 1558public: 1559 1560 TypedefDecl *getDecl() const { return Decl; } 1561 1562 /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1563 /// potentially looking through *all* consecutive typedefs. This returns the 1564 /// sum of the type qualifiers, so if you have: 1565 /// typedef const int A; 1566 /// typedef volatile A B; 1567 /// looking through the typedefs for B will give you "const volatile A". 1568 QualType LookThroughTypedefs() const; 1569 1570 virtual void getAsStringInternal(std::string &InnerString, 1571 const PrintingPolicy &Policy) const; 1572 1573 static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 1574 static bool classof(const TypedefType *) { return true; } 1575}; 1576 1577/// TypeOfExprType (GCC extension). 1578class TypeOfExprType : public Type { 1579 Expr *TOExpr; 1580 1581protected: 1582 TypeOfExprType(Expr *E, QualType can = QualType()); 1583 friend class ASTContext; // ASTContext creates these. 1584public: 1585 Expr *getUnderlyingExpr() const { return TOExpr; } 1586 1587 virtual void getAsStringInternal(std::string &InnerString, 1588 const PrintingPolicy &Policy) const; 1589 1590 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 1591 static bool classof(const TypeOfExprType *) { return true; } 1592}; 1593 1594/// Subclass of TypeOfExprType that is used for canonical, dependent 1595/// typeof(expr) types. 1596class DependentTypeOfExprType 1597 : public TypeOfExprType, public llvm::FoldingSetNode { 1598 ASTContext &Context; 1599 1600public: 1601 DependentTypeOfExprType(ASTContext &Context, Expr *E) 1602 : TypeOfExprType(E), Context(Context) { } 1603 1604 void Profile(llvm::FoldingSetNodeID &ID) { 1605 Profile(ID, Context, getUnderlyingExpr()); 1606 } 1607 1608 static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 1609 Expr *E); 1610}; 1611 1612/// TypeOfType (GCC extension). 1613class TypeOfType : public Type { 1614 QualType TOType; 1615 TypeOfType(QualType T, QualType can) 1616 : Type(TypeOf, can, T->isDependentType()), TOType(T) { 1617 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1618 } 1619 friend class ASTContext; // ASTContext creates these. 1620public: 1621 QualType getUnderlyingType() const { return TOType; } 1622 1623 virtual void getAsStringInternal(std::string &InnerString, 1624 const PrintingPolicy &Policy) const; 1625 1626 static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 1627 static bool classof(const TypeOfType *) { return true; } 1628}; 1629 1630/// DecltypeType (C++0x) 1631class DecltypeType : public Type { 1632 Expr *E; 1633 1634 // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 1635 // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 1636 // from it. 1637 QualType UnderlyingType; 1638 1639 DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 1640 friend class ASTContext; // ASTContext creates these. 1641public: 1642 Expr *getUnderlyingExpr() const { return E; } 1643 QualType getUnderlyingType() const { return UnderlyingType; } 1644 1645 virtual void getAsStringInternal(std::string &InnerString, 1646 const PrintingPolicy &Policy) const; 1647 1648 static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 1649 static bool classof(const DecltypeType *) { return true; } 1650}; 1651 1652class TagType : public Type { 1653 /// Stores the TagDecl associated with this type. The decl will 1654 /// point to the TagDecl that actually defines the entity (or is a 1655 /// definition in progress), if there is such a definition. The 1656 /// single-bit value will be non-zero when this tag is in the 1657 /// process of being defined. 1658 mutable llvm::PointerIntPair<TagDecl *, 1> decl; 1659 friend class ASTContext; 1660 friend class TagDecl; 1661 1662protected: 1663 TagType(TypeClass TC, TagDecl *D, QualType can); 1664 1665public: 1666 TagDecl *getDecl() const { return decl.getPointer(); } 1667 1668 /// @brief Determines whether this type is in the process of being 1669 /// defined. 1670 bool isBeingDefined() const { return decl.getInt(); } 1671 void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); } 1672 1673 virtual void getAsStringInternal(std::string &InnerString, 1674 const PrintingPolicy &Policy) const; 1675 1676 static bool classof(const Type *T) { 1677 return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 1678 } 1679 static bool classof(const TagType *) { return true; } 1680 static bool classof(const RecordType *) { return true; } 1681 static bool classof(const EnumType *) { return true; } 1682}; 1683 1684/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 1685/// to detect TagType objects of structs/unions/classes. 1686class RecordType : public TagType { 1687protected: 1688 explicit RecordType(RecordDecl *D) 1689 : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 1690 explicit RecordType(TypeClass TC, RecordDecl *D) 1691 : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 1692 friend class ASTContext; // ASTContext creates these. 1693public: 1694 1695 RecordDecl *getDecl() const { 1696 return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 1697 } 1698 1699 // FIXME: This predicate is a helper to QualType/Type. It needs to 1700 // recursively check all fields for const-ness. If any field is declared 1701 // const, it needs to return false. 1702 bool hasConstFields() const { return false; } 1703 1704 // FIXME: RecordType needs to check when it is created that all fields are in 1705 // the same address space, and return that. 1706 unsigned getAddressSpace() const { return 0; } 1707 1708 static bool classof(const TagType *T); 1709 static bool classof(const Type *T) { 1710 return isa<TagType>(T) && classof(cast<TagType>(T)); 1711 } 1712 static bool classof(const RecordType *) { return true; } 1713}; 1714 1715/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 1716/// to detect TagType objects of enums. 1717class EnumType : public TagType { 1718 explicit EnumType(EnumDecl *D) 1719 : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 1720 friend class ASTContext; // ASTContext creates these. 1721public: 1722 1723 EnumDecl *getDecl() const { 1724 return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 1725 } 1726 1727 static bool classof(const TagType *T); 1728 static bool classof(const Type *T) { 1729 return isa<TagType>(T) && classof(cast<TagType>(T)); 1730 } 1731 static bool classof(const EnumType *) { return true; } 1732}; 1733 1734class TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 1735 unsigned Depth : 15; 1736 unsigned Index : 16; 1737 unsigned ParameterPack : 1; 1738 IdentifierInfo *Name; 1739 1740 TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 1741 QualType Canon) 1742 : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 1743 Depth(D), Index(I), ParameterPack(PP), Name(N) { } 1744 1745 TemplateTypeParmType(unsigned D, unsigned I, bool PP) 1746 : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 1747 Depth(D), Index(I), ParameterPack(PP), Name(0) { } 1748 1749 friend class ASTContext; // ASTContext creates these 1750 1751public: 1752 unsigned getDepth() const { return Depth; } 1753 unsigned getIndex() const { return Index; } 1754 bool isParameterPack() const { return ParameterPack; } 1755 IdentifierInfo *getName() const { return Name; } 1756 1757 virtual void getAsStringInternal(std::string &InnerString, 1758 const PrintingPolicy &Policy) const; 1759 1760 void Profile(llvm::FoldingSetNodeID &ID) { 1761 Profile(ID, Depth, Index, ParameterPack, Name); 1762 } 1763 1764 static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 1765 unsigned Index, bool ParameterPack, 1766 IdentifierInfo *Name) { 1767 ID.AddInteger(Depth); 1768 ID.AddInteger(Index); 1769 ID.AddBoolean(ParameterPack); 1770 ID.AddPointer(Name); 1771 } 1772 1773 static bool classof(const Type *T) { 1774 return T->getTypeClass() == TemplateTypeParm; 1775 } 1776 static bool classof(const TemplateTypeParmType *T) { return true; } 1777}; 1778 1779/// \brief Represents the type of a template specialization as written 1780/// in the source code. 1781/// 1782/// Template specialization types represent the syntactic form of a 1783/// template-id that refers to a type, e.g., @c vector<int>. Some 1784/// template specialization types are syntactic sugar, whose canonical 1785/// type will point to some other type node that represents the 1786/// instantiation or class template specialization. For example, a 1787/// class template specialization type of @c vector<int> will refer to 1788/// a tag type for the instantiation 1789/// @c std::vector<int, std::allocator<int>>. 1790/// 1791/// Other template specialization types, for which the template name 1792/// is dependent, may be canonical types. These types are always 1793/// dependent. 1794class TemplateSpecializationType 1795 : public Type, public llvm::FoldingSetNode { 1796 1797 // FIXME: Currently needed for profiling expressions; can we avoid this? 1798 ASTContext &Context; 1799 1800 /// \brief The name of the template being specialized. 1801 TemplateName Template; 1802 1803 /// \brief - The number of template arguments named in this class 1804 /// template specialization. 1805 unsigned NumArgs; 1806 1807 TemplateSpecializationType(ASTContext &Context, 1808 TemplateName T, 1809 const TemplateArgument *Args, 1810 unsigned NumArgs, QualType Canon); 1811 1812 virtual void Destroy(ASTContext& C); 1813 1814 friend class ASTContext; // ASTContext creates these 1815 1816public: 1817 /// \brief Determine whether any of the given template arguments are 1818 /// dependent. 1819 static bool anyDependentTemplateArguments(const TemplateArgument *Args, 1820 unsigned NumArgs); 1821 1822 /// \brief Print a template argument list, including the '<' and '>' 1823 /// enclosing the template arguments. 1824 static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 1825 unsigned NumArgs, 1826 const PrintingPolicy &Policy); 1827 1828 typedef const TemplateArgument * iterator; 1829 1830 iterator begin() const { return getArgs(); } 1831 iterator end() const; 1832 1833 /// \brief Retrieve the name of the template that we are specializing. 1834 TemplateName getTemplateName() const { return Template; } 1835 1836 /// \brief Retrieve the template arguments. 1837 const TemplateArgument *getArgs() const { 1838 return reinterpret_cast<const TemplateArgument *>(this + 1); 1839 } 1840 1841 /// \brief Retrieve the number of template arguments. 1842 unsigned getNumArgs() const { return NumArgs; } 1843 1844 /// \brief Retrieve a specific template argument as a type. 1845 /// \precondition @c isArgType(Arg) 1846 const TemplateArgument &getArg(unsigned Idx) const; 1847 1848 virtual void getAsStringInternal(std::string &InnerString, 1849 const PrintingPolicy &Policy) const; 1850 1851 void Profile(llvm::FoldingSetNodeID &ID) { 1852 Profile(ID, Template, getArgs(), NumArgs, Context); 1853 } 1854 1855 static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 1856 const TemplateArgument *Args, unsigned NumArgs, 1857 ASTContext &Context); 1858 1859 static bool classof(const Type *T) { 1860 return T->getTypeClass() == TemplateSpecialization; 1861 } 1862 static bool classof(const TemplateSpecializationType *T) { return true; } 1863}; 1864 1865/// \brief Represents a type that was referred to via a qualified 1866/// name, e.g., N::M::type. 1867/// 1868/// This type is used to keep track of a type name as written in the 1869/// source code, including any nested-name-specifiers. The type itself 1870/// is always "sugar", used to express what was written in the source 1871/// code but containing no additional semantic information. 1872class QualifiedNameType : public Type, public llvm::FoldingSetNode { 1873 /// \brief The nested name specifier containing the qualifier. 1874 NestedNameSpecifier *NNS; 1875 1876 /// \brief The type that this qualified name refers to. 1877 QualType NamedType; 1878 1879 QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 1880 QualType CanonType) 1881 : Type(QualifiedName, CanonType, NamedType->isDependentType()), 1882 NNS(NNS), NamedType(NamedType) { } 1883 1884 friend class ASTContext; // ASTContext creates these 1885 1886public: 1887 /// \brief Retrieve the qualification on this type. 1888 NestedNameSpecifier *getQualifier() const { return NNS; } 1889 1890 /// \brief Retrieve the type named by the qualified-id. 1891 QualType getNamedType() const { return NamedType; } 1892 1893 virtual void getAsStringInternal(std::string &InnerString, 1894 const PrintingPolicy &Policy) const; 1895 1896 void Profile(llvm::FoldingSetNodeID &ID) { 1897 Profile(ID, NNS, NamedType); 1898 } 1899 1900 static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1901 QualType NamedType) { 1902 ID.AddPointer(NNS); 1903 NamedType.Profile(ID); 1904 } 1905 1906 static bool classof(const Type *T) { 1907 return T->getTypeClass() == QualifiedName; 1908 } 1909 static bool classof(const QualifiedNameType *T) { return true; } 1910}; 1911 1912/// \brief Represents a 'typename' specifier that names a type within 1913/// a dependent type, e.g., "typename T::type". 1914/// 1915/// TypenameType has a very similar structure to QualifiedNameType, 1916/// which also involves a nested-name-specifier following by a type, 1917/// and (FIXME!) both can even be prefixed by the 'typename' 1918/// keyword. However, the two types serve very different roles: 1919/// QualifiedNameType is a non-semantic type that serves only as sugar 1920/// to show how a particular type was written in the source 1921/// code. TypenameType, on the other hand, only occurs when the 1922/// nested-name-specifier is dependent, such that we cannot resolve 1923/// the actual type until after instantiation. 1924class TypenameType : public Type, public llvm::FoldingSetNode { 1925 /// \brief The nested name specifier containing the qualifier. 1926 NestedNameSpecifier *NNS; 1927 1928 typedef llvm::PointerUnion<const IdentifierInfo *, 1929 const TemplateSpecializationType *> NameType; 1930 1931 /// \brief The type that this typename specifier refers to. 1932 NameType Name; 1933 1934 TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 1935 QualType CanonType) 1936 : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 1937 assert(NNS->isDependent() && 1938 "TypenameType requires a dependent nested-name-specifier"); 1939 } 1940 1941 TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 1942 QualType CanonType) 1943 : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 1944 assert(NNS->isDependent() && 1945 "TypenameType requires a dependent nested-name-specifier"); 1946 } 1947 1948 friend class ASTContext; // ASTContext creates these 1949 1950public: 1951 /// \brief Retrieve the qualification on this type. 1952 NestedNameSpecifier *getQualifier() const { return NNS; } 1953 1954 /// \brief Retrieve the type named by the typename specifier as an 1955 /// identifier. 1956 /// 1957 /// This routine will return a non-NULL identifier pointer when the 1958 /// form of the original typename was terminated by an identifier, 1959 /// e.g., "typename T::type". 1960 const IdentifierInfo *getIdentifier() const { 1961 return Name.dyn_cast<const IdentifierInfo *>(); 1962 } 1963 1964 /// \brief Retrieve the type named by the typename specifier as a 1965 /// type specialization. 1966 const TemplateSpecializationType *getTemplateId() const { 1967 return Name.dyn_cast<const TemplateSpecializationType *>(); 1968 } 1969 1970 virtual void getAsStringInternal(std::string &InnerString, 1971 const PrintingPolicy &Policy) const; 1972 1973 void Profile(llvm::FoldingSetNodeID &ID) { 1974 Profile(ID, NNS, Name); 1975 } 1976 1977 static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1978 NameType Name) { 1979 ID.AddPointer(NNS); 1980 ID.AddPointer(Name.getOpaqueValue()); 1981 } 1982 1983 static bool classof(const Type *T) { 1984 return T->getTypeClass() == Typename; 1985 } 1986 static bool classof(const TypenameType *T) { return true; } 1987}; 1988 1989/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1990/// object oriented design. They basically correspond to C++ classes. There 1991/// are two kinds of interface types, normal interfaces like "NSString" and 1992/// qualified interfaces, which are qualified with a protocol list like 1993/// "NSString<NSCopyable, NSAmazing>". 1994class ObjCInterfaceType : public Type, public llvm::FoldingSetNode { 1995 ObjCInterfaceDecl *Decl; 1996 1997 // List of protocols for this protocol conforming object type 1998 // List is sorted on protocol name. No protocol is enterred more than once. 1999 llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 2000 2001 ObjCInterfaceType(ObjCInterfaceDecl *D, 2002 ObjCProtocolDecl **Protos, unsigned NumP) : 2003 Type(ObjCInterface, QualType(), /*Dependent=*/false), 2004 Decl(D), Protocols(Protos, Protos+NumP) { } 2005 friend class ASTContext; // ASTContext creates these. 2006public: 2007 ObjCInterfaceDecl *getDecl() const { return Decl; } 2008 2009 /// getNumProtocols - Return the number of qualifying protocols in this 2010 /// interface type, or 0 if there are none. 2011 unsigned getNumProtocols() const { return Protocols.size(); } 2012 2013 /// qual_iterator and friends: this provides access to the (potentially empty) 2014 /// list of protocols qualifying this interface. 2015 typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 2016 qual_iterator qual_begin() const { return Protocols.begin(); } 2017 qual_iterator qual_end() const { return Protocols.end(); } 2018 bool qual_empty() const { return Protocols.size() == 0; } 2019 2020 virtual void getAsStringInternal(std::string &InnerString, 2021 const PrintingPolicy &Policy) const; 2022 2023 void Profile(llvm::FoldingSetNodeID &ID); 2024 static void Profile(llvm::FoldingSetNodeID &ID, 2025 const ObjCInterfaceDecl *Decl, 2026 ObjCProtocolDecl **protocols, unsigned NumProtocols); 2027 2028 static bool classof(const Type *T) { 2029 return T->getTypeClass() == ObjCInterface; 2030 } 2031 static bool classof(const ObjCInterfaceType *) { return true; } 2032}; 2033 2034/// ObjCObjectPointerType - Used to represent 'id', 'Interface *', 'id <p>', 2035/// and 'Interface <p> *'. 2036/// 2037/// Duplicate protocols are removed and protocol list is canonicalized to be in 2038/// alphabetical order. 2039class ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 2040 QualType PointeeType; // A builtin or interface type. 2041 2042 // List of protocols for this protocol conforming object type 2043 // List is sorted on protocol name. No protocol is entered more than once. 2044 llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 2045 2046 ObjCObjectPointerType(QualType T, ObjCProtocolDecl **Protos, unsigned NumP) : 2047 Type(ObjCObjectPointer, QualType(), /*Dependent=*/false), 2048 PointeeType(T), Protocols(Protos, Protos+NumP) { } 2049 friend class ASTContext; // ASTContext creates these. 2050 2051public: 2052 // Get the pointee type. Pointee will either be: 2053 // - a built-in type (for 'id' and 'Class'). 2054 // - an interface type (for user-defined types). 2055 // - a TypedefType whose canonical type is an interface (as in 'T' below). 2056 // For example: typedef NSObject T; T *var; 2057 QualType getPointeeType() const { return PointeeType; } 2058 2059 const ObjCInterfaceType *getInterfaceType() const { 2060 return PointeeType->getAsObjCInterfaceType(); 2061 } 2062 /// getInterfaceDecl - returns an interface decl for user-defined types. 2063 ObjCInterfaceDecl *getInterfaceDecl() const { 2064 return getInterfaceType() ? getInterfaceType()->getDecl() : 0; 2065 } 2066 /// isObjCIdType - true for "id". 2067 bool isObjCIdType() const { 2068 return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && 2069 !Protocols.size(); 2070 } 2071 /// isObjCClassType - true for "Class". 2072 bool isObjCClassType() const { 2073 return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) && 2074 !Protocols.size(); 2075 } 2076 /// isObjCQualifiedIdType - true for "id <p>". 2077 bool isObjCQualifiedIdType() const { 2078 return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && 2079 Protocols.size(); 2080 } 2081 /// isObjCQualifiedClassType - true for "Class <p>". 2082 bool isObjCQualifiedClassType() const { 2083 return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) && 2084 Protocols.size(); 2085 } 2086 /// qual_iterator and friends: this provides access to the (potentially empty) 2087 /// list of protocols qualifying this interface. 2088 typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 2089 2090 qual_iterator qual_begin() const { return Protocols.begin(); } 2091 qual_iterator qual_end() const { return Protocols.end(); } 2092 bool qual_empty() const { return Protocols.size() == 0; } 2093 2094 /// getNumProtocols - Return the number of qualifying protocols in this 2095 /// interface type, or 0 if there are none. 2096 unsigned getNumProtocols() const { return Protocols.size(); } 2097 2098 void Profile(llvm::FoldingSetNodeID &ID); 2099 static void Profile(llvm::FoldingSetNodeID &ID, QualType T, 2100 ObjCProtocolDecl **protocols, unsigned NumProtocols); 2101 virtual void getAsStringInternal(std::string &InnerString, 2102 const PrintingPolicy &Policy) const; 2103 static bool classof(const Type *T) { 2104 return T->getTypeClass() == ObjCObjectPointer; 2105 } 2106 static bool classof(const ObjCObjectPointerType *) { return true; } 2107}; 2108 2109// Inline function definitions. 2110 2111/// getUnqualifiedType - Return the type without any qualifiers. 2112inline QualType QualType::getUnqualifiedType() const { 2113 Type *TP = getTypePtr(); 2114 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP)) 2115 TP = EXTQT->getBaseType(); 2116 return QualType(TP, 0); 2117} 2118 2119/// getAddressSpace - Return the address space of this type. 2120inline unsigned QualType::getAddressSpace() const { 2121 QualType CT = getTypePtr()->getCanonicalTypeInternal(); 2122 if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2123 return AT->getElementType().getAddressSpace(); 2124 if (const RecordType *RT = dyn_cast<RecordType>(CT)) 2125 return RT->getAddressSpace(); 2126 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 2127 return EXTQT->getAddressSpace(); 2128 return 0; 2129} 2130 2131/// getObjCGCAttr - Return the gc attribute of this type. 2132inline QualType::GCAttrTypes QualType::getObjCGCAttr() const { 2133 QualType CT = getTypePtr()->getCanonicalTypeInternal(); 2134 if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2135 return AT->getElementType().getObjCGCAttr(); 2136 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 2137 return EXTQT->getObjCGCAttr(); 2138 if (const ObjCObjectPointerType *PT = CT->getAsObjCObjectPointerType()) 2139 return PT->getPointeeType().getObjCGCAttr(); 2140 return GCNone; 2141} 2142 2143 /// getNoReturnAttr - Returns true if the type has the noreturn attribute, 2144 /// false otherwise. 2145inline bool QualType::getNoReturnAttr() const { 2146 QualType CT = getTypePtr()->getCanonicalTypeInternal(); 2147 if (const PointerType *PT = getTypePtr()->getAs<PointerType>()) { 2148 if (const FunctionType *FT = PT->getPointeeType()->getAsFunctionType()) 2149 return FT->getNoReturnAttr(); 2150 } else if (const FunctionType *FT = getTypePtr()->getAsFunctionType()) 2151 return FT->getNoReturnAttr(); 2152 2153 return false; 2154} 2155 2156/// isMoreQualifiedThan - Determine whether this type is more 2157/// qualified than the Other type. For example, "const volatile int" 2158/// is more qualified than "const int", "volatile int", and 2159/// "int". However, it is not more qualified than "const volatile 2160/// int". 2161inline bool QualType::isMoreQualifiedThan(QualType Other) const { 2162 unsigned MyQuals = this->getCVRQualifiers(); 2163 unsigned OtherQuals = Other.getCVRQualifiers(); 2164 if (getAddressSpace() != Other.getAddressSpace()) 2165 return false; 2166 return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 2167} 2168 2169/// isAtLeastAsQualifiedAs - Determine whether this type is at last 2170/// as qualified as the Other type. For example, "const volatile 2171/// int" is at least as qualified as "const int", "volatile int", 2172/// "int", and "const volatile int". 2173inline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 2174 unsigned MyQuals = this->getCVRQualifiers(); 2175 unsigned OtherQuals = Other.getCVRQualifiers(); 2176 if (getAddressSpace() != Other.getAddressSpace()) 2177 return false; 2178 return (MyQuals | OtherQuals) == MyQuals; 2179} 2180 2181/// getNonReferenceType - If Type is a reference type (e.g., const 2182/// int&), returns the type that the reference refers to ("const 2183/// int"). Otherwise, returns the type itself. This routine is used 2184/// throughout Sema to implement C++ 5p6: 2185/// 2186/// If an expression initially has the type "reference to T" (8.3.2, 2187/// 8.5.3), the type is adjusted to "T" prior to any further 2188/// analysis, the expression designates the object or function 2189/// denoted by the reference, and the expression is an lvalue. 2190inline QualType QualType::getNonReferenceType() const { 2191 if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 2192 return RefType->getPointeeType(); 2193 else 2194 return *this; 2195} 2196 2197inline const TypedefType* Type::getAsTypedefType() const { 2198 return dyn_cast<TypedefType>(this); 2199} 2200inline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 2201 if (const PointerType *PT = getAs<PointerType>()) 2202 return PT->getPointeeType()->getAsObjCInterfaceType(); 2203 return 0; 2204} 2205 2206// NOTE: All of these methods use "getUnqualifiedType" to strip off address 2207// space qualifiers if present. 2208inline bool Type::isFunctionType() const { 2209 return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 2210} 2211inline bool Type::isPointerType() const { 2212 return isa<PointerType>(CanonicalType.getUnqualifiedType()); 2213} 2214inline bool Type::isAnyPointerType() const { 2215 return isPointerType() || isObjCObjectPointerType(); 2216} 2217inline bool Type::isBlockPointerType() const { 2218 return isa<BlockPointerType>(CanonicalType.getUnqualifiedType()); 2219} 2220inline bool Type::isReferenceType() const { 2221 return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 2222} 2223inline bool Type::isLValueReferenceType() const { 2224 return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()); 2225} 2226inline bool Type::isRValueReferenceType() const { 2227 return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()); 2228} 2229inline bool Type::isFunctionPointerType() const { 2230 if (const PointerType* T = getAs<PointerType>()) 2231 return T->getPointeeType()->isFunctionType(); 2232 else 2233 return false; 2234} 2235inline bool Type::isMemberPointerType() const { 2236 return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 2237} 2238inline bool Type::isMemberFunctionPointerType() const { 2239 if (const MemberPointerType* T = getAs<MemberPointerType>()) 2240 return T->getPointeeType()->isFunctionType(); 2241 else 2242 return false; 2243} 2244inline bool Type::isArrayType() const { 2245 return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 2246} 2247inline bool Type::isConstantArrayType() const { 2248 return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 2249} 2250inline bool Type::isIncompleteArrayType() const { 2251 return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 2252} 2253inline bool Type::isVariableArrayType() const { 2254 return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 2255} 2256inline bool Type::isDependentSizedArrayType() const { 2257 return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 2258} 2259inline bool Type::isRecordType() const { 2260 return isa<RecordType>(CanonicalType.getUnqualifiedType()); 2261} 2262inline bool Type::isAnyComplexType() const { 2263 return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 2264} 2265inline bool Type::isVectorType() const { 2266 return isa<VectorType>(CanonicalType.getUnqualifiedType()); 2267} 2268inline bool Type::isExtVectorType() const { 2269 return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 2270} 2271inline bool Type::isObjCObjectPointerType() const { 2272 return isa<ObjCObjectPointerType>(CanonicalType.getUnqualifiedType()); 2273} 2274inline bool Type::isObjCInterfaceType() const { 2275 return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 2276} 2277inline bool Type::isObjCQualifiedIdType() const { 2278 if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) 2279 return OPT->isObjCQualifiedIdType(); 2280 return false; 2281} 2282inline bool Type::isObjCQualifiedClassType() const { 2283 if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) 2284 return OPT->isObjCQualifiedClassType(); 2285 return false; 2286} 2287inline bool Type::isObjCIdType() const { 2288 if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) 2289 return OPT->isObjCIdType(); 2290 return false; 2291} 2292inline bool Type::isObjCClassType() const { 2293 if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) 2294 return OPT->isObjCClassType(); 2295 return false; 2296} 2297inline bool Type::isObjCBuiltinType() const { 2298 return isObjCIdType() || isObjCClassType(); 2299} 2300inline bool Type::isTemplateTypeParmType() const { 2301 return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 2302} 2303 2304inline bool Type::isSpecificBuiltinType(unsigned K) const { 2305 if (const BuiltinType *BT = getAsBuiltinType()) 2306 if (BT->getKind() == (BuiltinType::Kind) K) 2307 return true; 2308 return false; 2309} 2310 2311/// \brief Determines whether this is a type for which one can define 2312/// an overloaded operator. 2313inline bool Type::isOverloadableType() const { 2314 return isDependentType() || isRecordType() || isEnumeralType(); 2315} 2316 2317inline bool Type::hasPointerRepresentation() const { 2318 return (isPointerType() || isReferenceType() || isBlockPointerType() || 2319 isObjCInterfaceType() || isObjCObjectPointerType() || 2320 isObjCQualifiedInterfaceType() || isNullPtrType()); 2321} 2322 2323inline bool Type::hasObjCPointerRepresentation() const { 2324 return (isObjCInterfaceType() || isObjCObjectPointerType() || 2325 isObjCQualifiedInterfaceType()); 2326} 2327 2328/// Insertion operator for diagnostics. This allows sending QualType's into a 2329/// diagnostic with <<. 2330inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 2331 QualType T) { 2332 DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 2333 Diagnostic::ak_qualtype); 2334 return DB; 2335} 2336 2337/// Member-template getAs<specific type>'. 2338template <typename T> const T *Type::getAs() const { 2339 // If this is directly a T type, return it. 2340 if (const T *Ty = dyn_cast<T>(this)) 2341 return Ty; 2342 2343 // If the canonical form of this type isn't the right kind, reject it. 2344 if (!isa<T>(CanonicalType)) { 2345 // Look through type qualifiers 2346 if (isa<T>(CanonicalType.getUnqualifiedType())) 2347 return CanonicalType.getUnqualifiedType()->getAs<T>(); 2348 return 0; 2349 } 2350 2351 // If this is a typedef for a pointer type, strip the typedef off without 2352 // losing all typedef information. 2353 return cast<T>(getDesugaredType()); 2354} 2355 2356} // end namespace clang 2357 2358#endif 2359