Type.h revision 2df9ced9fd1e8c7d7b38443db07e0e811de22571
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 UInt128, // __uint128_t 541 542 Char_S, // This is 'char' for targets where char is signed. 543 SChar, // This is explicitly qualified signed char. 544 WChar, // This is 'wchar_t' for C++. 545 Short, 546 Int, 547 Long, 548 LongLong, 549 Int128, // __int128_t 550 551 Float, Double, LongDouble, 552 553 Overload, // This represents the type of an overloaded function declaration. 554 Dependent // This represents the type of a type-dependent expression. 555 }; 556private: 557 Kind TypeKind; 558public: 559 BuiltinType(Kind K) 560 : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 561 TypeKind(K) {} 562 563 Kind getKind() const { return TypeKind; } 564 const char *getName() const; 565 566 virtual void getAsStringInternal(std::string &InnerString) const; 567 568 static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 569 static bool classof(const BuiltinType *) { return true; } 570}; 571 572/// FixedWidthIntType - Used for arbitrary width types that we either don't 573/// want to or can't map to named integer types. These always have a lower 574/// integer rank than builtin types of the same width. 575class FixedWidthIntType : public Type { 576private: 577 unsigned Width; 578 bool Signed; 579public: 580 FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false), 581 Width(W), Signed(S) {} 582 583 unsigned getWidth() const { return Width; } 584 bool isSigned() const { return Signed; } 585 const char *getName() const; 586 587 virtual void getAsStringInternal(std::string &InnerString) const; 588 589 static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; } 590 static bool classof(const FixedWidthIntType *) { return true; } 591}; 592 593/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 594/// types (_Complex float etc) as well as the GCC integer complex extensions. 595/// 596class ComplexType : public Type, public llvm::FoldingSetNode { 597 QualType ElementType; 598 ComplexType(QualType Element, QualType CanonicalPtr) : 599 Type(Complex, CanonicalPtr, Element->isDependentType()), 600 ElementType(Element) { 601 } 602 friend class ASTContext; // ASTContext creates these. 603public: 604 QualType getElementType() const { return ElementType; } 605 606 virtual void getAsStringInternal(std::string &InnerString) const; 607 608 void Profile(llvm::FoldingSetNodeID &ID) { 609 Profile(ID, getElementType()); 610 } 611 static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 612 ID.AddPointer(Element.getAsOpaquePtr()); 613 } 614 615 static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 616 static bool classof(const ComplexType *) { return true; } 617}; 618 619/// PointerType - C99 6.7.5.1 - Pointer Declarators. 620/// 621class PointerType : public Type, public llvm::FoldingSetNode { 622 QualType PointeeType; 623 624 PointerType(QualType Pointee, QualType CanonicalPtr) : 625 Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 626 } 627 friend class ASTContext; // ASTContext creates these. 628public: 629 630 virtual void getAsStringInternal(std::string &InnerString) const; 631 632 QualType getPointeeType() const { return PointeeType; } 633 634 void Profile(llvm::FoldingSetNodeID &ID) { 635 Profile(ID, getPointeeType()); 636 } 637 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 638 ID.AddPointer(Pointee.getAsOpaquePtr()); 639 } 640 641 static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 642 static bool classof(const PointerType *) { return true; } 643}; 644 645/// BlockPointerType - pointer to a block type. 646/// This type is to represent types syntactically represented as 647/// "void (^)(int)", etc. Pointee is required to always be a function type. 648/// 649class BlockPointerType : public Type, public llvm::FoldingSetNode { 650 QualType PointeeType; // Block is some kind of pointer type 651 BlockPointerType(QualType Pointee, QualType CanonicalCls) : 652 Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 653 PointeeType(Pointee) { 654 } 655 friend class ASTContext; // ASTContext creates these. 656public: 657 658 // Get the pointee type. Pointee is required to always be a function type. 659 QualType getPointeeType() const { return PointeeType; } 660 661 virtual void getAsStringInternal(std::string &InnerString) const; 662 663 void Profile(llvm::FoldingSetNodeID &ID) { 664 Profile(ID, getPointeeType()); 665 } 666 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 667 ID.AddPointer(Pointee.getAsOpaquePtr()); 668 } 669 670 static bool classof(const Type *T) { 671 return T->getTypeClass() == BlockPointer; 672 } 673 static bool classof(const BlockPointerType *) { return true; } 674}; 675 676/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 677/// 678class ReferenceType : public Type, public llvm::FoldingSetNode { 679 QualType PointeeType; 680 681protected: 682 ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) : 683 Type(tc, CanonicalRef, Referencee->isDependentType()), 684 PointeeType(Referencee) { 685 } 686public: 687 QualType getPointeeType() const { return PointeeType; } 688 689 void Profile(llvm::FoldingSetNodeID &ID) { 690 Profile(ID, getPointeeType()); 691 } 692 static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 693 ID.AddPointer(Referencee.getAsOpaquePtr()); 694 } 695 696 static bool classof(const Type *T) { 697 return T->getTypeClass() == LValueReference || 698 T->getTypeClass() == RValueReference; 699 } 700 static bool classof(const ReferenceType *) { return true; } 701}; 702 703/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 704/// 705class LValueReferenceType : public ReferenceType { 706 LValueReferenceType(QualType Referencee, QualType CanonicalRef) : 707 ReferenceType(LValueReference, Referencee, CanonicalRef) { 708 } 709 friend class ASTContext; // ASTContext creates these 710public: 711 virtual void getAsStringInternal(std::string &InnerString) const; 712 713 static bool classof(const Type *T) { 714 return T->getTypeClass() == LValueReference; 715 } 716 static bool classof(const LValueReferenceType *) { return true; } 717}; 718 719/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 720/// 721class RValueReferenceType : public ReferenceType { 722 RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 723 ReferenceType(RValueReference, Referencee, CanonicalRef) { 724 } 725 friend class ASTContext; // ASTContext creates these 726public: 727 virtual void getAsStringInternal(std::string &InnerString) const; 728 729 static bool classof(const Type *T) { 730 return T->getTypeClass() == RValueReference; 731 } 732 static bool classof(const RValueReferenceType *) { return true; } 733}; 734 735/// MemberPointerType - C++ 8.3.3 - Pointers to members 736/// 737class MemberPointerType : public Type, public llvm::FoldingSetNode { 738 QualType PointeeType; 739 /// The class of which the pointee is a member. Must ultimately be a 740 /// RecordType, but could be a typedef or a template parameter too. 741 const Type *Class; 742 743 MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 744 Type(MemberPointer, CanonicalPtr, 745 Cls->isDependentType() || Pointee->isDependentType()), 746 PointeeType(Pointee), Class(Cls) { 747 } 748 friend class ASTContext; // ASTContext creates these. 749public: 750 751 QualType getPointeeType() const { return PointeeType; } 752 753 const Type *getClass() const { return Class; } 754 755 virtual void getAsStringInternal(std::string &InnerString) const; 756 757 void Profile(llvm::FoldingSetNodeID &ID) { 758 Profile(ID, getPointeeType(), getClass()); 759 } 760 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 761 const Type *Class) { 762 ID.AddPointer(Pointee.getAsOpaquePtr()); 763 ID.AddPointer(Class); 764 } 765 766 static bool classof(const Type *T) { 767 return T->getTypeClass() == MemberPointer; 768 } 769 static bool classof(const MemberPointerType *) { return true; } 770}; 771 772/// ArrayType - C99 6.7.5.2 - Array Declarators. 773/// 774class ArrayType : public Type, public llvm::FoldingSetNode { 775public: 776 /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 777 /// an array with a static size (e.g. int X[static 4]), or an array 778 /// with a star size (e.g. int X[*]). 779 /// 'static' is only allowed on function parameters. 780 enum ArraySizeModifier { 781 Normal, Static, Star 782 }; 783private: 784 /// ElementType - The element type of the array. 785 QualType ElementType; 786 787 // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 788 /// NOTE: These fields are packed into the bitfields space in the Type class. 789 unsigned SizeModifier : 2; 790 791 /// IndexTypeQuals - Capture qualifiers in declarations like: 792 /// 'int X[static restrict 4]'. For function parameters only. 793 unsigned IndexTypeQuals : 3; 794 795protected: 796 // C++ [temp.dep.type]p1: 797 // A type is dependent if it is... 798 // - an array type constructed from any dependent type or whose 799 // size is specified by a constant expression that is 800 // value-dependent, 801 ArrayType(TypeClass tc, QualType et, QualType can, 802 ArraySizeModifier sm, unsigned tq) 803 : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 804 ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 805 806 friend class ASTContext; // ASTContext creates these. 807public: 808 QualType getElementType() const { return ElementType; } 809 ArraySizeModifier getSizeModifier() const { 810 return ArraySizeModifier(SizeModifier); 811 } 812 unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 813 814 static bool classof(const Type *T) { 815 return T->getTypeClass() == ConstantArray || 816 T->getTypeClass() == VariableArray || 817 T->getTypeClass() == IncompleteArray || 818 T->getTypeClass() == DependentSizedArray; 819 } 820 static bool classof(const ArrayType *) { return true; } 821}; 822 823/// ConstantArrayType - This class represents C arrays with a specified constant 824/// size. For example 'int A[100]' has ConstantArrayType where the element type 825/// is 'int' and the size is 100. 826class ConstantArrayType : public ArrayType { 827 llvm::APInt Size; // Allows us to unique the type. 828 829 ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 830 ArraySizeModifier sm, unsigned tq) 831 : ArrayType(ConstantArray, et, can, sm, tq), Size(size) {} 832 friend class ASTContext; // ASTContext creates these. 833public: 834 const llvm::APInt &getSize() const { return Size; } 835 virtual void getAsStringInternal(std::string &InnerString) const; 836 837 void Profile(llvm::FoldingSetNodeID &ID) { 838 Profile(ID, getElementType(), getSize(), 839 getSizeModifier(), getIndexTypeQualifier()); 840 } 841 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 842 const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 843 unsigned TypeQuals) { 844 ID.AddPointer(ET.getAsOpaquePtr()); 845 ID.AddInteger(ArraySize.getZExtValue()); 846 ID.AddInteger(SizeMod); 847 ID.AddInteger(TypeQuals); 848 } 849 static bool classof(const Type *T) { 850 return T->getTypeClass() == ConstantArray; 851 } 852 static bool classof(const ConstantArrayType *) { return true; } 853}; 854 855/// IncompleteArrayType - This class represents C arrays with an unspecified 856/// size. For example 'int A[]' has an IncompleteArrayType where the element 857/// type is 'int' and the size is unspecified. 858class IncompleteArrayType : public ArrayType { 859 IncompleteArrayType(QualType et, QualType can, 860 ArraySizeModifier sm, unsigned tq) 861 : ArrayType(IncompleteArray, et, can, sm, tq) {} 862 friend class ASTContext; // ASTContext creates these. 863public: 864 865 virtual void getAsStringInternal(std::string &InnerString) const; 866 867 static bool classof(const Type *T) { 868 return T->getTypeClass() == IncompleteArray; 869 } 870 static bool classof(const IncompleteArrayType *) { return true; } 871 872 friend class StmtIteratorBase; 873 874 void Profile(llvm::FoldingSetNodeID &ID) { 875 Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier()); 876 } 877 878 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 879 ArraySizeModifier SizeMod, unsigned TypeQuals) { 880 ID.AddPointer(ET.getAsOpaquePtr()); 881 ID.AddInteger(SizeMod); 882 ID.AddInteger(TypeQuals); 883 } 884}; 885 886/// VariableArrayType - This class represents C arrays with a specified size 887/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 888/// Since the size expression is an arbitrary expression, we store it as such. 889/// 890/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 891/// should not be: two lexically equivalent variable array types could mean 892/// different things, for example, these variables do not have the same type 893/// dynamically: 894/// 895/// void foo(int x) { 896/// int Y[x]; 897/// ++x; 898/// int Z[x]; 899/// } 900/// 901class VariableArrayType : public ArrayType { 902 /// SizeExpr - An assignment expression. VLA's are only permitted within 903 /// a function block. 904 Stmt *SizeExpr; 905 906 VariableArrayType(QualType et, QualType can, Expr *e, 907 ArraySizeModifier sm, unsigned tq) 908 : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 909 friend class ASTContext; // ASTContext creates these. 910 virtual void Destroy(ASTContext& C); 911 912public: 913 Expr *getSizeExpr() const { 914 // We use C-style casts instead of cast<> here because we do not wish 915 // to have a dependency of Type.h on Stmt.h/Expr.h. 916 return (Expr*) SizeExpr; 917 } 918 919 virtual void getAsStringInternal(std::string &InnerString) const; 920 921 static bool classof(const Type *T) { 922 return T->getTypeClass() == VariableArray; 923 } 924 static bool classof(const VariableArrayType *) { return true; } 925 926 friend class StmtIteratorBase; 927 928 void Profile(llvm::FoldingSetNodeID &ID) { 929 assert(0 && "Cannnot unique VariableArrayTypes."); 930 } 931}; 932 933/// DependentSizedArrayType - This type represents an array type in 934/// C++ whose size is a value-dependent expression. For example: 935/// @code 936/// template<typename T, int Size> 937/// class array { 938/// T data[Size]; 939/// }; 940/// @endcode 941/// For these types, we won't actually know what the array bound is 942/// until template instantiation occurs, at which point this will 943/// become either a ConstantArrayType or a VariableArrayType. 944class DependentSizedArrayType : public ArrayType { 945 /// SizeExpr - An assignment expression that will instantiate to the 946 /// size of the array. 947 Stmt *SizeExpr; 948 949 DependentSizedArrayType(QualType et, QualType can, Expr *e, 950 ArraySizeModifier sm, unsigned tq) 951 : ArrayType(DependentSizedArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 952 friend class ASTContext; // ASTContext creates these. 953 virtual void Destroy(ASTContext& C); 954 955public: 956 Expr *getSizeExpr() const { 957 // We use C-style casts instead of cast<> here because we do not wish 958 // to have a dependency of Type.h on Stmt.h/Expr.h. 959 return (Expr*) SizeExpr; 960 } 961 962 virtual void getAsStringInternal(std::string &InnerString) const; 963 964 static bool classof(const Type *T) { 965 return T->getTypeClass() == DependentSizedArray; 966 } 967 static bool classof(const DependentSizedArrayType *) { return true; } 968 969 friend class StmtIteratorBase; 970 971 void Profile(llvm::FoldingSetNodeID &ID) { 972 assert(0 && "Cannnot unique DependentSizedArrayTypes."); 973 } 974}; 975 976/// VectorType - GCC generic vector type. This type is created using 977/// __attribute__((vector_size(n)), where "n" specifies the vector size in 978/// bytes. Since the constructor takes the number of vector elements, the 979/// client is responsible for converting the size into the number of elements. 980class VectorType : public Type, public llvm::FoldingSetNode { 981protected: 982 /// ElementType - The element type of the vector. 983 QualType ElementType; 984 985 /// NumElements - The number of elements in the vector. 986 unsigned NumElements; 987 988 VectorType(QualType vecType, unsigned nElements, QualType canonType) : 989 Type(Vector, canonType, vecType->isDependentType()), 990 ElementType(vecType), NumElements(nElements) {} 991 VectorType(TypeClass tc, QualType vecType, unsigned nElements, 992 QualType canonType) 993 : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 994 NumElements(nElements) {} 995 friend class ASTContext; // ASTContext creates these. 996public: 997 998 QualType getElementType() const { return ElementType; } 999 unsigned getNumElements() const { return NumElements; } 1000 1001 virtual void getAsStringInternal(std::string &InnerString) const; 1002 1003 void Profile(llvm::FoldingSetNodeID &ID) { 1004 Profile(ID, getElementType(), getNumElements(), getTypeClass()); 1005 } 1006 static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 1007 unsigned NumElements, TypeClass TypeClass) { 1008 ID.AddPointer(ElementType.getAsOpaquePtr()); 1009 ID.AddInteger(NumElements); 1010 ID.AddInteger(TypeClass); 1011 } 1012 static bool classof(const Type *T) { 1013 return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 1014 } 1015 static bool classof(const VectorType *) { return true; } 1016}; 1017 1018/// ExtVectorType - Extended vector type. This type is created using 1019/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1020/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1021/// class enables syntactic extensions, like Vector Components for accessing 1022/// points, colors, and textures (modeled after OpenGL Shading Language). 1023class ExtVectorType : public VectorType { 1024 ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1025 VectorType(ExtVector, vecType, nElements, canonType) {} 1026 friend class ASTContext; // ASTContext creates these. 1027public: 1028 static int getPointAccessorIdx(char c) { 1029 switch (c) { 1030 default: return -1; 1031 case 'x': return 0; 1032 case 'y': return 1; 1033 case 'z': return 2; 1034 case 'w': return 3; 1035 } 1036 } 1037 static int getNumericAccessorIdx(char c) { 1038 switch (c) { 1039 default: return -1; 1040 case '0': return 0; 1041 case '1': return 1; 1042 case '2': return 2; 1043 case '3': return 3; 1044 case '4': return 4; 1045 case '5': return 5; 1046 case '6': return 6; 1047 case '7': return 7; 1048 case '8': return 8; 1049 case '9': return 9; 1050 case 'a': return 10; 1051 case 'b': return 11; 1052 case 'c': return 12; 1053 case 'd': return 13; 1054 case 'e': return 14; 1055 case 'f': return 15; 1056 } 1057 } 1058 1059 static int getAccessorIdx(char c) { 1060 if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1061 return getNumericAccessorIdx(c); 1062 } 1063 1064 bool isAccessorWithinNumElements(char c) const { 1065 if (int idx = getAccessorIdx(c)+1) 1066 return unsigned(idx-1) < NumElements; 1067 return false; 1068 } 1069 virtual void getAsStringInternal(std::string &InnerString) const; 1070 1071 static bool classof(const Type *T) { 1072 return T->getTypeClass() == ExtVector; 1073 } 1074 static bool classof(const ExtVectorType *) { return true; } 1075}; 1076 1077/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 1078/// class of FunctionNoProtoType and FunctionProtoType. 1079/// 1080class FunctionType : public Type { 1081 /// SubClassData - This field is owned by the subclass, put here to pack 1082 /// tightly with the ivars in Type. 1083 bool SubClassData : 1; 1084 1085 /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1086 /// other bitfields. 1087 /// The qualifiers are part of FunctionProtoType because... 1088 /// 1089 /// C++ 8.3.5p4: The return type, the parameter type list and the 1090 /// cv-qualifier-seq, [...], are part of the function type. 1091 /// 1092 unsigned TypeQuals : 3; 1093 1094 // The type returned by the function. 1095 QualType ResultType; 1096protected: 1097 FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 1098 unsigned typeQuals, QualType Canonical, bool Dependent) 1099 : Type(tc, Canonical, Dependent), 1100 SubClassData(SubclassInfo), TypeQuals(typeQuals), ResultType(res) {} 1101 bool getSubClassData() const { return SubClassData; } 1102 unsigned getTypeQuals() const { return TypeQuals; } 1103public: 1104 1105 QualType getResultType() const { return ResultType; } 1106 1107 1108 static bool classof(const Type *T) { 1109 return T->getTypeClass() == FunctionNoProto || 1110 T->getTypeClass() == FunctionProto; 1111 } 1112 static bool classof(const FunctionType *) { return true; } 1113}; 1114 1115/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 1116/// no information available about its arguments. 1117class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 1118 FunctionNoProtoType(QualType Result, QualType Canonical) 1119 : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 1120 /*Dependent=*/false) {} 1121 friend class ASTContext; // ASTContext creates these. 1122public: 1123 // No additional state past what FunctionType provides. 1124 1125 virtual void getAsStringInternal(std::string &InnerString) const; 1126 1127 void Profile(llvm::FoldingSetNodeID &ID) { 1128 Profile(ID, getResultType()); 1129 } 1130 static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) { 1131 ID.AddPointer(ResultType.getAsOpaquePtr()); 1132 } 1133 1134 static bool classof(const Type *T) { 1135 return T->getTypeClass() == FunctionNoProto; 1136 } 1137 static bool classof(const FunctionNoProtoType *) { return true; } 1138}; 1139 1140/// FunctionProtoType - Represents a prototype with argument type info, e.g. 1141/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 1142/// arguments, not as having a single void argument. 1143class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 1144 /// hasAnyDependentType - Determine whether there are any dependent 1145 /// types within the arguments passed in. 1146 static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 1147 for (unsigned Idx = 0; Idx < numArgs; ++Idx) 1148 if (ArgArray[Idx]->isDependentType()) 1149 return true; 1150 1151 return false; 1152 } 1153 1154 FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 1155 bool isVariadic, unsigned typeQuals, QualType Canonical) 1156 : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 1157 (Result->isDependentType() || 1158 hasAnyDependentType(ArgArray, numArgs))), 1159 NumArgs(numArgs) { 1160 // Fill in the trailing argument array. 1161 QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);; 1162 for (unsigned i = 0; i != numArgs; ++i) 1163 ArgInfo[i] = ArgArray[i]; 1164 } 1165 1166 /// NumArgs - The number of arguments this function has, not counting '...'. 1167 unsigned NumArgs; 1168 1169 /// ArgInfo - There is an variable size array after the class in memory that 1170 /// holds the argument types. 1171 1172 friend class ASTContext; // ASTContext creates these. 1173 1174public: 1175 unsigned getNumArgs() const { return NumArgs; } 1176 QualType getArgType(unsigned i) const { 1177 assert(i < NumArgs && "Invalid argument number!"); 1178 return arg_type_begin()[i]; 1179 } 1180 1181 bool isVariadic() const { return getSubClassData(); } 1182 unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 1183 1184 typedef const QualType *arg_type_iterator; 1185 arg_type_iterator arg_type_begin() const { 1186 return reinterpret_cast<const QualType *>(this+1); 1187 } 1188 arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1189 1190 virtual void getAsStringInternal(std::string &InnerString) const; 1191 1192 static bool classof(const Type *T) { 1193 return T->getTypeClass() == FunctionProto; 1194 } 1195 static bool classof(const FunctionProtoType *) { return true; } 1196 1197 void Profile(llvm::FoldingSetNodeID &ID); 1198 static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1199 arg_type_iterator ArgTys, unsigned NumArgs, 1200 bool isVariadic, unsigned TypeQuals); 1201}; 1202 1203 1204class TypedefType : public Type { 1205 TypedefDecl *Decl; 1206protected: 1207 TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 1208 : Type(tc, can, can->isDependentType()), Decl(D) { 1209 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1210 } 1211 friend class ASTContext; // ASTContext creates these. 1212public: 1213 1214 TypedefDecl *getDecl() const { return Decl; } 1215 1216 /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1217 /// potentially looking through *all* consecutive typedefs. This returns the 1218 /// sum of the type qualifiers, so if you have: 1219 /// typedef const int A; 1220 /// typedef volatile A B; 1221 /// looking through the typedefs for B will give you "const volatile A". 1222 QualType LookThroughTypedefs() const; 1223 1224 virtual void getAsStringInternal(std::string &InnerString) const; 1225 1226 static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 1227 static bool classof(const TypedefType *) { return true; } 1228}; 1229 1230/// TypeOfExprType (GCC extension). 1231class TypeOfExprType : public Type { 1232 Expr *TOExpr; 1233 TypeOfExprType(Expr *E, QualType can); 1234 friend class ASTContext; // ASTContext creates these. 1235public: 1236 Expr *getUnderlyingExpr() const { return TOExpr; } 1237 1238 virtual void getAsStringInternal(std::string &InnerString) const; 1239 1240 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 1241 static bool classof(const TypeOfExprType *) { return true; } 1242}; 1243 1244/// TypeOfType (GCC extension). 1245class TypeOfType : public Type { 1246 QualType TOType; 1247 TypeOfType(QualType T, QualType can) 1248 : Type(TypeOf, can, T->isDependentType()), TOType(T) { 1249 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1250 } 1251 friend class ASTContext; // ASTContext creates these. 1252public: 1253 QualType getUnderlyingType() const { return TOType; } 1254 1255 virtual void getAsStringInternal(std::string &InnerString) const; 1256 1257 static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 1258 static bool classof(const TypeOfType *) { return true; } 1259}; 1260 1261class TagType : public Type { 1262 /// Stores the TagDecl associated with this type. The decl will 1263 /// point to the TagDecl that actually defines the entity (or is a 1264 /// definition in progress), if there is such a definition. The 1265 /// single-bit value will be non-zero when this tag is in the 1266 /// process of being defined. 1267 mutable llvm::PointerIntPair<TagDecl *, 1> decl; 1268 friend class ASTContext; 1269 friend class TagDecl; 1270 1271protected: 1272 // FIXME: We'll need the user to pass in information about whether 1273 // this type is dependent or not, because we don't have enough 1274 // information to compute it here. 1275 TagType(TypeClass TC, TagDecl *D, QualType can) 1276 : Type(TC, can, /*Dependent=*/false), decl(D, 0) {} 1277 1278public: 1279 TagDecl *getDecl() const { return decl.getPointer(); } 1280 1281 /// @brief Determines whether this type is in the process of being 1282 /// defined. 1283 bool isBeingDefined() const { return decl.getInt(); } 1284 void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); } 1285 1286 virtual void getAsStringInternal(std::string &InnerString) const; 1287 void getAsStringInternal(std::string &InnerString, 1288 bool SuppressTagKind) const; 1289 1290 static bool classof(const Type *T) { 1291 return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 1292 } 1293 static bool classof(const TagType *) { return true; } 1294 static bool classof(const RecordType *) { return true; } 1295 static bool classof(const EnumType *) { return true; } 1296}; 1297 1298/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 1299/// to detect TagType objects of structs/unions/classes. 1300class RecordType : public TagType { 1301protected: 1302 explicit RecordType(RecordDecl *D) 1303 : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 1304 explicit RecordType(TypeClass TC, RecordDecl *D) 1305 : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 1306 friend class ASTContext; // ASTContext creates these. 1307public: 1308 1309 RecordDecl *getDecl() const { 1310 return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 1311 } 1312 1313 // FIXME: This predicate is a helper to QualType/Type. It needs to 1314 // recursively check all fields for const-ness. If any field is declared 1315 // const, it needs to return false. 1316 bool hasConstFields() const { return false; } 1317 1318 // FIXME: RecordType needs to check when it is created that all fields are in 1319 // the same address space, and return that. 1320 unsigned getAddressSpace() const { return 0; } 1321 1322 static bool classof(const TagType *T); 1323 static bool classof(const Type *T) { 1324 return isa<TagType>(T) && classof(cast<TagType>(T)); 1325 } 1326 static bool classof(const RecordType *) { return true; } 1327}; 1328 1329/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 1330/// to detect TagType objects of enums. 1331class EnumType : public TagType { 1332 explicit EnumType(EnumDecl *D) 1333 : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 1334 friend class ASTContext; // ASTContext creates these. 1335public: 1336 1337 EnumDecl *getDecl() const { 1338 return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 1339 } 1340 1341 static bool classof(const TagType *T); 1342 static bool classof(const Type *T) { 1343 return isa<TagType>(T) && classof(cast<TagType>(T)); 1344 } 1345 static bool classof(const EnumType *) { return true; } 1346}; 1347 1348class TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 1349 unsigned Depth : 16; 1350 unsigned Index : 16; 1351 IdentifierInfo *Name; 1352 1353 TemplateTypeParmType(unsigned D, unsigned I, IdentifierInfo *N, 1354 QualType Canon) 1355 : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 1356 Depth(D), Index(I), Name(N) { } 1357 1358 TemplateTypeParmType(unsigned D, unsigned I) 1359 : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 1360 Depth(D), Index(I), Name(0) { } 1361 1362 friend class ASTContext; // ASTContext creates these 1363 1364public: 1365 unsigned getDepth() const { return Depth; } 1366 unsigned getIndex() const { return Index; } 1367 IdentifierInfo *getName() const { return Name; } 1368 1369 virtual void getAsStringInternal(std::string &InnerString) const; 1370 1371 void Profile(llvm::FoldingSetNodeID &ID) { 1372 Profile(ID, Depth, Index, Name); 1373 } 1374 1375 static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 1376 unsigned Index, IdentifierInfo *Name) { 1377 ID.AddInteger(Depth); 1378 ID.AddInteger(Index); 1379 ID.AddPointer(Name); 1380 } 1381 1382 static bool classof(const Type *T) { 1383 return T->getTypeClass() == TemplateTypeParm; 1384 } 1385 static bool classof(const TemplateTypeParmType *T) { return true; } 1386}; 1387 1388/// \brief Represents the type of a template specialization as written 1389/// in the source code. 1390/// 1391/// Template specialization types represent the syntactic form of a 1392/// template-id that refers to a type, e.g., @c vector<int>. Some 1393/// template specialization types are syntactic sugar, whose canonical 1394/// type will point to some other type node that represents the 1395/// instantiation or class template specialization. For example, a 1396/// class template specialization type of @c vector<int> will refer to 1397/// a tag type for the instantiation 1398/// @c std::vector<int, std::allocator<int>>. 1399/// 1400/// Other template specialization types, for which the template name 1401/// is dependent, may be canonical types. These types are always 1402/// dependent. 1403class TemplateSpecializationType 1404 : public Type, public llvm::FoldingSetNode { 1405 1406 /// \brief The name of the template being specialized. 1407 TemplateName Template; 1408 1409 /// \brief - The number of template arguments named in this class 1410 /// template specialization. 1411 unsigned NumArgs; 1412 1413 TemplateSpecializationType(TemplateName T, 1414 const TemplateArgument *Args, 1415 unsigned NumArgs, QualType Canon); 1416 1417 virtual void Destroy(ASTContext& C); 1418 1419 friend class ASTContext; // ASTContext creates these 1420 1421public: 1422 /// \brief Determine whether any of the given template arguments are 1423 /// dependent. 1424 static bool anyDependentTemplateArguments(const TemplateArgument *Args, 1425 unsigned NumArgs); 1426 1427 /// \brief Print a template argument list, including the '<' and '>' 1428 /// enclosing the template arguments. 1429 static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 1430 unsigned NumArgs); 1431 1432 typedef const TemplateArgument * iterator; 1433 1434 iterator begin() const { return getArgs(); } 1435 iterator end() const; 1436 1437 /// \brief Retrieve the name of the template that we are specializing. 1438 TemplateName getTemplateName() const { return Template; } 1439 1440 /// \brief Retrieve the template arguments. 1441 const TemplateArgument *getArgs() const { 1442 return reinterpret_cast<const TemplateArgument *>(this + 1); 1443 } 1444 1445 /// \brief Retrieve the number of template arguments. 1446 unsigned getNumArgs() const { return NumArgs; } 1447 1448 /// \brief Retrieve a specific template argument as a type. 1449 /// \precondition @c isArgType(Arg) 1450 const TemplateArgument &getArg(unsigned Idx) const; 1451 1452 virtual void getAsStringInternal(std::string &InnerString) const; 1453 1454 void Profile(llvm::FoldingSetNodeID &ID) { 1455 Profile(ID, Template, getArgs(), NumArgs); 1456 } 1457 1458 static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 1459 const TemplateArgument *Args, unsigned NumArgs); 1460 1461 static bool classof(const Type *T) { 1462 return T->getTypeClass() == TemplateSpecialization; 1463 } 1464 static bool classof(const TemplateSpecializationType *T) { return true; } 1465}; 1466 1467/// \brief Represents a type that was referred to via a qualified 1468/// name, e.g., N::M::type. 1469/// 1470/// This type is used to keep track of a type name as written in the 1471/// source code, including any nested-name-specifiers. The type itself 1472/// is always "sugar", used to express what was written in the source 1473/// code but containing no additional semantic information. 1474class QualifiedNameType : public Type, public llvm::FoldingSetNode { 1475 /// \brief The nested name specifier containing the qualifier. 1476 NestedNameSpecifier *NNS; 1477 1478 /// \brief The type that this qualified name refers to. 1479 QualType NamedType; 1480 1481 QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 1482 QualType CanonType) 1483 : Type(QualifiedName, CanonType, NamedType->isDependentType()), 1484 NNS(NNS), NamedType(NamedType) { } 1485 1486 friend class ASTContext; // ASTContext creates these 1487 1488public: 1489 /// \brief Retrieve the qualification on this type. 1490 NestedNameSpecifier *getQualifier() const { return NNS; } 1491 1492 /// \brief Retrieve the type named by the qualified-id. 1493 QualType getNamedType() const { return NamedType; } 1494 1495 virtual void getAsStringInternal(std::string &InnerString) const; 1496 1497 void Profile(llvm::FoldingSetNodeID &ID) { 1498 Profile(ID, NNS, NamedType); 1499 } 1500 1501 static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1502 QualType NamedType) { 1503 ID.AddPointer(NNS); 1504 NamedType.Profile(ID); 1505 } 1506 1507 static bool classof(const Type *T) { 1508 return T->getTypeClass() == QualifiedName; 1509 } 1510 static bool classof(const QualifiedNameType *T) { return true; } 1511}; 1512 1513/// \brief Represents a 'typename' specifier that names a type within 1514/// a dependent type, e.g., "typename T::type". 1515/// 1516/// TypenameType has a very similar structure to QualifiedNameType, 1517/// which also involves a nested-name-specifier following by a type, 1518/// and (FIXME!) both can even be prefixed by the 'typename' 1519/// keyword. However, the two types serve very different roles: 1520/// QualifiedNameType is a non-semantic type that serves only as sugar 1521/// to show how a particular type was written in the source 1522/// code. TypenameType, on the other hand, only occurs when the 1523/// nested-name-specifier is dependent, such that we cannot resolve 1524/// the actual type until after instantiation. 1525class TypenameType : public Type, public llvm::FoldingSetNode { 1526 /// \brief The nested name specifier containing the qualifier. 1527 NestedNameSpecifier *NNS; 1528 1529 typedef llvm::PointerUnion<const IdentifierInfo *, 1530 const TemplateSpecializationType *> NameType; 1531 1532 /// \brief The type that this typename specifier refers to. 1533 NameType Name; 1534 1535 TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 1536 QualType CanonType) 1537 : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 1538 assert(NNS->isDependent() && 1539 "TypenameType requires a dependent nested-name-specifier"); 1540 } 1541 1542 TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 1543 QualType CanonType) 1544 : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 1545 assert(NNS->isDependent() && 1546 "TypenameType requires a dependent nested-name-specifier"); 1547 } 1548 1549 friend class ASTContext; // ASTContext creates these 1550 1551public: 1552 /// \brief Retrieve the qualification on this type. 1553 NestedNameSpecifier *getQualifier() const { return NNS; } 1554 1555 /// \brief Retrieve the type named by the typename specifier as an 1556 /// identifier. 1557 /// 1558 /// This routine will return a non-NULL identifier pointer when the 1559 /// form of the original typename was terminated by an identifier, 1560 /// e.g., "typename T::type". 1561 const IdentifierInfo *getIdentifier() const { 1562 return Name.dyn_cast<const IdentifierInfo *>(); 1563 } 1564 1565 /// \brief Retrieve the type named by the typename specifier as a 1566 /// type specialization. 1567 const TemplateSpecializationType *getTemplateId() const { 1568 return Name.dyn_cast<const TemplateSpecializationType *>(); 1569 } 1570 1571 virtual void getAsStringInternal(std::string &InnerString) const; 1572 1573 void Profile(llvm::FoldingSetNodeID &ID) { 1574 Profile(ID, NNS, Name); 1575 } 1576 1577 static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1578 NameType Name) { 1579 ID.AddPointer(NNS); 1580 ID.AddPointer(Name.getOpaqueValue()); 1581 } 1582 1583 static bool classof(const Type *T) { 1584 return T->getTypeClass() == Typename; 1585 } 1586 static bool classof(const TypenameType *T) { return true; } 1587}; 1588 1589/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1590/// object oriented design. They basically correspond to C++ classes. There 1591/// are two kinds of interface types, normal interfaces like "NSString" and 1592/// qualified interfaces, which are qualified with a protocol list like 1593/// "NSString<NSCopyable, NSAmazing>". Qualified interface types are instances 1594/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType. 1595class ObjCInterfaceType : public Type { 1596 ObjCInterfaceDecl *Decl; 1597protected: 1598 ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 1599 Type(tc, QualType(), /*Dependent=*/false), Decl(D) { } 1600 friend class ASTContext; // ASTContext creates these. 1601public: 1602 1603 ObjCInterfaceDecl *getDecl() const { return Decl; } 1604 1605 /// qual_iterator and friends: this provides access to the (potentially empty) 1606 /// list of protocols qualifying this interface. If this is an instance of 1607 /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an 1608 /// empty list if there are no qualifying protocols. 1609 typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1610 inline qual_iterator qual_begin() const; 1611 inline qual_iterator qual_end() const; 1612 bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; } 1613 1614 /// getNumProtocols - Return the number of qualifying protocols in this 1615 /// interface type, or 0 if there are none. 1616 inline unsigned getNumProtocols() const; 1617 1618 /// getProtocol - Return the specified qualifying protocol. 1619 inline ObjCProtocolDecl *getProtocol(unsigned i) const; 1620 1621 1622 virtual void getAsStringInternal(std::string &InnerString) const; 1623 static bool classof(const Type *T) { 1624 return T->getTypeClass() == ObjCInterface || 1625 T->getTypeClass() == ObjCQualifiedInterface; 1626 } 1627 static bool classof(const ObjCInterfaceType *) { return true; } 1628}; 1629 1630/// ObjCQualifiedInterfaceType - This class represents interface types 1631/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>. 1632/// 1633/// Duplicate protocols are removed and protocol list is canonicalized to be in 1634/// alphabetical order. 1635class ObjCQualifiedInterfaceType : public ObjCInterfaceType, 1636 public llvm::FoldingSetNode { 1637 1638 // List of protocols for this protocol conforming object type 1639 // List is sorted on protocol name. No protocol is enterred more than once. 1640 llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 1641 1642 ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1643 ObjCProtocolDecl **Protos, unsigned NumP) : 1644 ObjCInterfaceType(ObjCQualifiedInterface, D), 1645 Protocols(Protos, Protos+NumP) { } 1646 friend class ASTContext; // ASTContext creates these. 1647public: 1648 1649 ObjCProtocolDecl *getProtocol(unsigned i) const { 1650 return Protocols[i]; 1651 } 1652 unsigned getNumProtocols() const { 1653 return Protocols.size(); 1654 } 1655 1656 qual_iterator qual_begin() const { return Protocols.begin(); } 1657 qual_iterator qual_end() const { return Protocols.end(); } 1658 1659 virtual void getAsStringInternal(std::string &InnerString) const; 1660 1661 void Profile(llvm::FoldingSetNodeID &ID); 1662 static void Profile(llvm::FoldingSetNodeID &ID, 1663 const ObjCInterfaceDecl *Decl, 1664 ObjCProtocolDecl **protocols, unsigned NumProtocols); 1665 1666 static bool classof(const Type *T) { 1667 return T->getTypeClass() == ObjCQualifiedInterface; 1668 } 1669 static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1670}; 1671 1672inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const { 1673 if (const ObjCQualifiedInterfaceType *QIT = 1674 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1675 return QIT->qual_begin(); 1676 return 0; 1677} 1678inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const { 1679 if (const ObjCQualifiedInterfaceType *QIT = 1680 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1681 return QIT->qual_end(); 1682 return 0; 1683} 1684 1685/// getNumProtocols - Return the number of qualifying protocols in this 1686/// interface type, or 0 if there are none. 1687inline unsigned ObjCInterfaceType::getNumProtocols() const { 1688 if (const ObjCQualifiedInterfaceType *QIT = 1689 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1690 return QIT->getNumProtocols(); 1691 return 0; 1692} 1693 1694/// getProtocol - Return the specified qualifying protocol. 1695inline ObjCProtocolDecl *ObjCInterfaceType::getProtocol(unsigned i) const { 1696 return cast<ObjCQualifiedInterfaceType>(this)->getProtocol(i); 1697} 1698 1699 1700 1701/// ObjCQualifiedIdType - to represent id<protocol-list>. 1702/// 1703/// Duplicate protocols are removed and protocol list is canonicalized to be in 1704/// alphabetical order. 1705class ObjCQualifiedIdType : public Type, 1706 public llvm::FoldingSetNode { 1707 // List of protocols for this protocol conforming 'id' type 1708 // List is sorted on protocol name. No protocol is enterred more than once. 1709 llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1710 1711 ObjCQualifiedIdType(ObjCProtocolDecl **Protos, unsigned NumP) 1712 : Type(ObjCQualifiedId, QualType()/*these are always canonical*/, 1713 /*Dependent=*/false), 1714 Protocols(Protos, Protos+NumP) { } 1715 friend class ASTContext; // ASTContext creates these. 1716public: 1717 1718 ObjCProtocolDecl *getProtocols(unsigned i) const { 1719 return Protocols[i]; 1720 } 1721 unsigned getNumProtocols() const { 1722 return Protocols.size(); 1723 } 1724 ObjCProtocolDecl **getReferencedProtocols() { 1725 return &Protocols[0]; 1726 } 1727 1728 typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1729 qual_iterator qual_begin() const { return Protocols.begin(); } 1730 qual_iterator qual_end() const { return Protocols.end(); } 1731 1732 virtual void getAsStringInternal(std::string &InnerString) const; 1733 1734 void Profile(llvm::FoldingSetNodeID &ID); 1735 static void Profile(llvm::FoldingSetNodeID &ID, 1736 ObjCProtocolDecl **protocols, unsigned NumProtocols); 1737 1738 static bool classof(const Type *T) { 1739 return T->getTypeClass() == ObjCQualifiedId; 1740 } 1741 static bool classof(const ObjCQualifiedIdType *) { return true; } 1742 1743}; 1744 1745// Inline function definitions. 1746 1747/// getUnqualifiedType - Return the type without any qualifiers. 1748inline QualType QualType::getUnqualifiedType() const { 1749 Type *TP = getTypePtr(); 1750 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP)) 1751 TP = EXTQT->getBaseType(); 1752 return QualType(TP, 0); 1753} 1754 1755/// getAddressSpace - Return the address space of this type. 1756inline unsigned QualType::getAddressSpace() const { 1757 QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1758 if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1759 return AT->getElementType().getAddressSpace(); 1760 if (const RecordType *RT = dyn_cast<RecordType>(CT)) 1761 return RT->getAddressSpace(); 1762 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1763 return EXTQT->getAddressSpace(); 1764 return 0; 1765} 1766 1767/// getObjCGCAttr - Return the gc attribute of this type. 1768inline QualType::GCAttrTypes QualType::getObjCGCAttr() const { 1769 QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1770 if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1771 return AT->getElementType().getObjCGCAttr(); 1772 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1773 return EXTQT->getObjCGCAttr(); 1774 if (const PointerType *PT = CT->getAsPointerType()) 1775 return PT->getPointeeType().getObjCGCAttr(); 1776 return GCNone; 1777} 1778 1779/// isMoreQualifiedThan - Determine whether this type is more 1780/// qualified than the Other type. For example, "const volatile int" 1781/// is more qualified than "const int", "volatile int", and 1782/// "int". However, it is not more qualified than "const volatile 1783/// int". 1784inline bool QualType::isMoreQualifiedThan(QualType Other) const { 1785 unsigned MyQuals = this->getCVRQualifiers(); 1786 unsigned OtherQuals = Other.getCVRQualifiers(); 1787 if (getAddressSpace() != Other.getAddressSpace()) 1788 return false; 1789 return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 1790} 1791 1792/// isAtLeastAsQualifiedAs - Determine whether this type is at last 1793/// as qualified as the Other type. For example, "const volatile 1794/// int" is at least as qualified as "const int", "volatile int", 1795/// "int", and "const volatile int". 1796inline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 1797 unsigned MyQuals = this->getCVRQualifiers(); 1798 unsigned OtherQuals = Other.getCVRQualifiers(); 1799 if (getAddressSpace() != Other.getAddressSpace()) 1800 return false; 1801 return (MyQuals | OtherQuals) == MyQuals; 1802} 1803 1804/// getNonReferenceType - If Type is a reference type (e.g., const 1805/// int&), returns the type that the reference refers to ("const 1806/// int"). Otherwise, returns the type itself. This routine is used 1807/// throughout Sema to implement C++ 5p6: 1808/// 1809/// If an expression initially has the type "reference to T" (8.3.2, 1810/// 8.5.3), the type is adjusted to "T" prior to any further 1811/// analysis, the expression designates the object or function 1812/// denoted by the reference, and the expression is an lvalue. 1813inline QualType QualType::getNonReferenceType() const { 1814 if (const ReferenceType *RefType = (*this)->getAsReferenceType()) 1815 return RefType->getPointeeType(); 1816 else 1817 return *this; 1818} 1819 1820inline const TypedefType* Type::getAsTypedefType() const { 1821 return dyn_cast<TypedefType>(this); 1822} 1823inline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 1824 if (const PointerType *PT = getAsPointerType()) 1825 return PT->getPointeeType()->getAsObjCInterfaceType(); 1826 return 0; 1827} 1828 1829// NOTE: All of these methods use "getUnqualifiedType" to strip off address 1830// space qualifiers if present. 1831inline bool Type::isFunctionType() const { 1832 return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 1833} 1834inline bool Type::isPointerType() const { 1835 return isa<PointerType>(CanonicalType.getUnqualifiedType()); 1836} 1837inline bool Type::isBlockPointerType() const { 1838 return isa<BlockPointerType>(CanonicalType.getUnqualifiedType()); 1839} 1840inline bool Type::isReferenceType() const { 1841 return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 1842} 1843inline bool Type::isLValueReferenceType() const { 1844 return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()); 1845} 1846inline bool Type::isRValueReferenceType() const { 1847 return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()); 1848} 1849inline bool Type::isFunctionPointerType() const { 1850 if (const PointerType* T = getAsPointerType()) 1851 return T->getPointeeType()->isFunctionType(); 1852 else 1853 return false; 1854} 1855inline bool Type::isMemberPointerType() const { 1856 return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 1857} 1858inline bool Type::isMemberFunctionPointerType() const { 1859 if (const MemberPointerType* T = getAsMemberPointerType()) 1860 return T->getPointeeType()->isFunctionType(); 1861 else 1862 return false; 1863} 1864inline bool Type::isArrayType() const { 1865 return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 1866} 1867inline bool Type::isConstantArrayType() const { 1868 return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 1869} 1870inline bool Type::isIncompleteArrayType() const { 1871 return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 1872} 1873inline bool Type::isVariableArrayType() const { 1874 return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 1875} 1876inline bool Type::isDependentSizedArrayType() const { 1877 return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 1878} 1879inline bool Type::isRecordType() const { 1880 return isa<RecordType>(CanonicalType.getUnqualifiedType()); 1881} 1882inline bool Type::isAnyComplexType() const { 1883 return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 1884} 1885inline bool Type::isVectorType() const { 1886 return isa<VectorType>(CanonicalType.getUnqualifiedType()); 1887} 1888inline bool Type::isExtVectorType() const { 1889 return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 1890} 1891inline bool Type::isObjCInterfaceType() const { 1892 return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 1893} 1894inline bool Type::isObjCQualifiedInterfaceType() const { 1895 return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); 1896} 1897inline bool Type::isObjCQualifiedIdType() const { 1898 return isa<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType()); 1899} 1900inline bool Type::isTemplateTypeParmType() const { 1901 return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 1902} 1903 1904inline bool Type::isSpecificBuiltinType(unsigned K) const { 1905 if (const BuiltinType *BT = getAsBuiltinType()) 1906 if (BT->getKind() == (BuiltinType::Kind) K) 1907 return true; 1908 return false; 1909} 1910 1911/// \brief Determines whether this is a type for which one can define 1912/// an overloaded operator. 1913inline bool Type::isOverloadableType() const { 1914 return isDependentType() || isRecordType() || isEnumeralType(); 1915} 1916 1917inline bool Type::hasPointerRepresentation() const { 1918 return (isPointerType() || isReferenceType() || isBlockPointerType() || 1919 isObjCInterfaceType() || isObjCQualifiedIdType() || 1920 isObjCQualifiedInterfaceType()); 1921} 1922 1923inline bool Type::hasObjCPointerRepresentation() const { 1924 return (isObjCInterfaceType() || isObjCQualifiedIdType() || 1925 isObjCQualifiedInterfaceType()); 1926} 1927 1928/// Insertion operator for diagnostics. This allows sending QualType's into a 1929/// diagnostic with <<. 1930inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 1931 QualType T) { 1932 DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 1933 Diagnostic::ak_qualtype); 1934 return DB; 1935} 1936 1937} // end namespace clang 1938 1939#endif 1940