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