Type.h revision 74942cde3da623741b60c2524fc44ef0cb35724b
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, bool hasExs, 1156 bool hasAnyExs, const QualType *ExArray, 1157 unsigned numExs, QualType Canonical) 1158 : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 1159 (Result->isDependentType() || 1160 hasAnyDependentType(ArgArray, numArgs))), 1161 NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 1162 AnyExceptionSpec(hasAnyExs) { 1163 // Fill in the trailing argument array. 1164 QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 1165 for (unsigned i = 0; i != numArgs; ++i) 1166 ArgInfo[i] = ArgArray[i]; 1167 // Fill in the exception array. 1168 QualType *Ex = ArgInfo + numArgs; 1169 for (unsigned i = 0; i != numExs; ++i) 1170 Ex[i] = ExArray[i]; 1171 } 1172 1173 /// NumArgs - The number of arguments this function has, not counting '...'. 1174 unsigned NumArgs : 20; 1175 1176 /// NumExceptions - The number of types in the exception spec, if any. 1177 unsigned NumExceptions : 10; 1178 1179 /// HasExceptionSpec - Whether this function has an exception spec at all. 1180 bool HasExceptionSpec : 1; 1181 1182 /// AnyExceptionSpec - Whether this function has a throw(...) spec. 1183 bool AnyExceptionSpec : 1; 1184 1185 /// ArgInfo - There is an variable size array after the class in memory that 1186 /// holds the argument types. 1187 1188 /// Exceptions - There is another variable size array after ArgInfo that 1189 /// holds the exception types. 1190 1191 friend class ASTContext; // ASTContext creates these. 1192 1193public: 1194 unsigned getNumArgs() const { return NumArgs; } 1195 QualType getArgType(unsigned i) const { 1196 assert(i < NumArgs && "Invalid argument number!"); 1197 return arg_type_begin()[i]; 1198 } 1199 1200 bool hasExceptionSpec() const { return HasExceptionSpec; } 1201 bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 1202 unsigned getNumExceptions() const { return NumExceptions; } 1203 QualType getExceptionType(unsigned i) const { 1204 assert(i < NumExceptions && "Invalid exception number!"); 1205 return exception_begin()[i]; 1206 } 1207 1208 bool isVariadic() const { return getSubClassData(); } 1209 unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 1210 1211 typedef const QualType *arg_type_iterator; 1212 arg_type_iterator arg_type_begin() const { 1213 return reinterpret_cast<const QualType *>(this+1); 1214 } 1215 arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1216 1217 typedef const QualType *exception_iterator; 1218 exception_iterator exception_begin() const { 1219 // exceptions begin where arguments end 1220 return arg_type_end(); 1221 } 1222 exception_iterator exception_end() const { 1223 return exception_begin() + NumExceptions; 1224 } 1225 1226 virtual void getAsStringInternal(std::string &InnerString) const; 1227 1228 static bool classof(const Type *T) { 1229 return T->getTypeClass() == FunctionProto; 1230 } 1231 static bool classof(const FunctionProtoType *) { return true; } 1232 1233 void Profile(llvm::FoldingSetNodeID &ID); 1234 static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1235 arg_type_iterator ArgTys, unsigned NumArgs, 1236 bool isVariadic, unsigned TypeQuals, 1237 bool hasExceptionSpec, bool anyExceptionSpec, 1238 unsigned NumExceptions, exception_iterator Exs); 1239}; 1240 1241 1242class TypedefType : public Type { 1243 TypedefDecl *Decl; 1244protected: 1245 TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 1246 : Type(tc, can, can->isDependentType()), Decl(D) { 1247 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1248 } 1249 friend class ASTContext; // ASTContext creates these. 1250public: 1251 1252 TypedefDecl *getDecl() const { return Decl; } 1253 1254 /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1255 /// potentially looking through *all* consecutive typedefs. This returns the 1256 /// sum of the type qualifiers, so if you have: 1257 /// typedef const int A; 1258 /// typedef volatile A B; 1259 /// looking through the typedefs for B will give you "const volatile A". 1260 QualType LookThroughTypedefs() const; 1261 1262 virtual void getAsStringInternal(std::string &InnerString) const; 1263 1264 static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 1265 static bool classof(const TypedefType *) { return true; } 1266}; 1267 1268/// TypeOfExprType (GCC extension). 1269class TypeOfExprType : public Type { 1270 Expr *TOExpr; 1271 TypeOfExprType(Expr *E, QualType can); 1272 friend class ASTContext; // ASTContext creates these. 1273public: 1274 Expr *getUnderlyingExpr() const { return TOExpr; } 1275 1276 virtual void getAsStringInternal(std::string &InnerString) const; 1277 1278 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 1279 static bool classof(const TypeOfExprType *) { return true; } 1280}; 1281 1282/// TypeOfType (GCC extension). 1283class TypeOfType : public Type { 1284 QualType TOType; 1285 TypeOfType(QualType T, QualType can) 1286 : Type(TypeOf, can, T->isDependentType()), TOType(T) { 1287 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1288 } 1289 friend class ASTContext; // ASTContext creates these. 1290public: 1291 QualType getUnderlyingType() const { return TOType; } 1292 1293 virtual void getAsStringInternal(std::string &InnerString) const; 1294 1295 static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 1296 static bool classof(const TypeOfType *) { return true; } 1297}; 1298 1299class TagType : public Type { 1300 /// Stores the TagDecl associated with this type. The decl will 1301 /// point to the TagDecl that actually defines the entity (or is a 1302 /// definition in progress), if there is such a definition. The 1303 /// single-bit value will be non-zero when this tag is in the 1304 /// process of being defined. 1305 mutable llvm::PointerIntPair<TagDecl *, 1> decl; 1306 friend class ASTContext; 1307 friend class TagDecl; 1308 1309protected: 1310 // FIXME: We'll need the user to pass in information about whether 1311 // this type is dependent or not, because we don't have enough 1312 // information to compute it here. 1313 TagType(TypeClass TC, TagDecl *D, QualType can) 1314 : Type(TC, can, /*Dependent=*/false), decl(D, 0) {} 1315 1316public: 1317 TagDecl *getDecl() const { return decl.getPointer(); } 1318 1319 /// @brief Determines whether this type is in the process of being 1320 /// defined. 1321 bool isBeingDefined() const { return decl.getInt(); } 1322 void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); } 1323 1324 virtual void getAsStringInternal(std::string &InnerString) const; 1325 void getAsStringInternal(std::string &InnerString, 1326 bool SuppressTagKind) const; 1327 1328 static bool classof(const Type *T) { 1329 return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 1330 } 1331 static bool classof(const TagType *) { return true; } 1332 static bool classof(const RecordType *) { return true; } 1333 static bool classof(const EnumType *) { return true; } 1334}; 1335 1336/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 1337/// to detect TagType objects of structs/unions/classes. 1338class RecordType : public TagType { 1339protected: 1340 explicit RecordType(RecordDecl *D) 1341 : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 1342 explicit RecordType(TypeClass TC, RecordDecl *D) 1343 : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 1344 friend class ASTContext; // ASTContext creates these. 1345public: 1346 1347 RecordDecl *getDecl() const { 1348 return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 1349 } 1350 1351 // FIXME: This predicate is a helper to QualType/Type. It needs to 1352 // recursively check all fields for const-ness. If any field is declared 1353 // const, it needs to return false. 1354 bool hasConstFields() const { return false; } 1355 1356 // FIXME: RecordType needs to check when it is created that all fields are in 1357 // the same address space, and return that. 1358 unsigned getAddressSpace() const { return 0; } 1359 1360 static bool classof(const TagType *T); 1361 static bool classof(const Type *T) { 1362 return isa<TagType>(T) && classof(cast<TagType>(T)); 1363 } 1364 static bool classof(const RecordType *) { return true; } 1365}; 1366 1367/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 1368/// to detect TagType objects of enums. 1369class EnumType : public TagType { 1370 explicit EnumType(EnumDecl *D) 1371 : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 1372 friend class ASTContext; // ASTContext creates these. 1373public: 1374 1375 EnumDecl *getDecl() const { 1376 return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 1377 } 1378 1379 static bool classof(const TagType *T); 1380 static bool classof(const Type *T) { 1381 return isa<TagType>(T) && classof(cast<TagType>(T)); 1382 } 1383 static bool classof(const EnumType *) { return true; } 1384}; 1385 1386class TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 1387 unsigned Depth : 16; 1388 unsigned Index : 16; 1389 IdentifierInfo *Name; 1390 1391 TemplateTypeParmType(unsigned D, unsigned I, IdentifierInfo *N, 1392 QualType Canon) 1393 : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 1394 Depth(D), Index(I), Name(N) { } 1395 1396 TemplateTypeParmType(unsigned D, unsigned I) 1397 : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 1398 Depth(D), Index(I), Name(0) { } 1399 1400 friend class ASTContext; // ASTContext creates these 1401 1402public: 1403 unsigned getDepth() const { return Depth; } 1404 unsigned getIndex() const { return Index; } 1405 IdentifierInfo *getName() const { return Name; } 1406 1407 virtual void getAsStringInternal(std::string &InnerString) const; 1408 1409 void Profile(llvm::FoldingSetNodeID &ID) { 1410 Profile(ID, Depth, Index, Name); 1411 } 1412 1413 static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 1414 unsigned Index, IdentifierInfo *Name) { 1415 ID.AddInteger(Depth); 1416 ID.AddInteger(Index); 1417 ID.AddPointer(Name); 1418 } 1419 1420 static bool classof(const Type *T) { 1421 return T->getTypeClass() == TemplateTypeParm; 1422 } 1423 static bool classof(const TemplateTypeParmType *T) { return true; } 1424}; 1425 1426/// \brief Represents the type of a template specialization as written 1427/// in the source code. 1428/// 1429/// Template specialization types represent the syntactic form of a 1430/// template-id that refers to a type, e.g., @c vector<int>. Some 1431/// template specialization types are syntactic sugar, whose canonical 1432/// type will point to some other type node that represents the 1433/// instantiation or class template specialization. For example, a 1434/// class template specialization type of @c vector<int> will refer to 1435/// a tag type for the instantiation 1436/// @c std::vector<int, std::allocator<int>>. 1437/// 1438/// Other template specialization types, for which the template name 1439/// is dependent, may be canonical types. These types are always 1440/// dependent. 1441class TemplateSpecializationType 1442 : public Type, public llvm::FoldingSetNode { 1443 1444 /// \brief The name of the template being specialized. 1445 TemplateName Template; 1446 1447 /// \brief - The number of template arguments named in this class 1448 /// template specialization. 1449 unsigned NumArgs; 1450 1451 TemplateSpecializationType(TemplateName T, 1452 const TemplateArgument *Args, 1453 unsigned NumArgs, QualType Canon); 1454 1455 virtual void Destroy(ASTContext& C); 1456 1457 friend class ASTContext; // ASTContext creates these 1458 1459public: 1460 /// \brief Determine whether any of the given template arguments are 1461 /// dependent. 1462 static bool anyDependentTemplateArguments(const TemplateArgument *Args, 1463 unsigned NumArgs); 1464 1465 /// \brief Print a template argument list, including the '<' and '>' 1466 /// enclosing the template arguments. 1467 static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 1468 unsigned NumArgs); 1469 1470 typedef const TemplateArgument * iterator; 1471 1472 iterator begin() const { return getArgs(); } 1473 iterator end() const; 1474 1475 /// \brief Retrieve the name of the template that we are specializing. 1476 TemplateName getTemplateName() const { return Template; } 1477 1478 /// \brief Retrieve the template arguments. 1479 const TemplateArgument *getArgs() const { 1480 return reinterpret_cast<const TemplateArgument *>(this + 1); 1481 } 1482 1483 /// \brief Retrieve the number of template arguments. 1484 unsigned getNumArgs() const { return NumArgs; } 1485 1486 /// \brief Retrieve a specific template argument as a type. 1487 /// \precondition @c isArgType(Arg) 1488 const TemplateArgument &getArg(unsigned Idx) const; 1489 1490 virtual void getAsStringInternal(std::string &InnerString) const; 1491 1492 void Profile(llvm::FoldingSetNodeID &ID) { 1493 Profile(ID, Template, getArgs(), NumArgs); 1494 } 1495 1496 static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 1497 const TemplateArgument *Args, unsigned NumArgs); 1498 1499 static bool classof(const Type *T) { 1500 return T->getTypeClass() == TemplateSpecialization; 1501 } 1502 static bool classof(const TemplateSpecializationType *T) { return true; } 1503}; 1504 1505/// \brief Represents a type that was referred to via a qualified 1506/// name, e.g., N::M::type. 1507/// 1508/// This type is used to keep track of a type name as written in the 1509/// source code, including any nested-name-specifiers. The type itself 1510/// is always "sugar", used to express what was written in the source 1511/// code but containing no additional semantic information. 1512class QualifiedNameType : public Type, public llvm::FoldingSetNode { 1513 /// \brief The nested name specifier containing the qualifier. 1514 NestedNameSpecifier *NNS; 1515 1516 /// \brief The type that this qualified name refers to. 1517 QualType NamedType; 1518 1519 QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 1520 QualType CanonType) 1521 : Type(QualifiedName, CanonType, NamedType->isDependentType()), 1522 NNS(NNS), NamedType(NamedType) { } 1523 1524 friend class ASTContext; // ASTContext creates these 1525 1526public: 1527 /// \brief Retrieve the qualification on this type. 1528 NestedNameSpecifier *getQualifier() const { return NNS; } 1529 1530 /// \brief Retrieve the type named by the qualified-id. 1531 QualType getNamedType() const { return NamedType; } 1532 1533 virtual void getAsStringInternal(std::string &InnerString) const; 1534 1535 void Profile(llvm::FoldingSetNodeID &ID) { 1536 Profile(ID, NNS, NamedType); 1537 } 1538 1539 static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1540 QualType NamedType) { 1541 ID.AddPointer(NNS); 1542 NamedType.Profile(ID); 1543 } 1544 1545 static bool classof(const Type *T) { 1546 return T->getTypeClass() == QualifiedName; 1547 } 1548 static bool classof(const QualifiedNameType *T) { return true; } 1549}; 1550 1551/// \brief Represents a 'typename' specifier that names a type within 1552/// a dependent type, e.g., "typename T::type". 1553/// 1554/// TypenameType has a very similar structure to QualifiedNameType, 1555/// which also involves a nested-name-specifier following by a type, 1556/// and (FIXME!) both can even be prefixed by the 'typename' 1557/// keyword. However, the two types serve very different roles: 1558/// QualifiedNameType is a non-semantic type that serves only as sugar 1559/// to show how a particular type was written in the source 1560/// code. TypenameType, on the other hand, only occurs when the 1561/// nested-name-specifier is dependent, such that we cannot resolve 1562/// the actual type until after instantiation. 1563class TypenameType : public Type, public llvm::FoldingSetNode { 1564 /// \brief The nested name specifier containing the qualifier. 1565 NestedNameSpecifier *NNS; 1566 1567 typedef llvm::PointerUnion<const IdentifierInfo *, 1568 const TemplateSpecializationType *> NameType; 1569 1570 /// \brief The type that this typename specifier refers to. 1571 NameType Name; 1572 1573 TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 1574 QualType CanonType) 1575 : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 1576 assert(NNS->isDependent() && 1577 "TypenameType requires a dependent nested-name-specifier"); 1578 } 1579 1580 TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 1581 QualType CanonType) 1582 : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 1583 assert(NNS->isDependent() && 1584 "TypenameType requires a dependent nested-name-specifier"); 1585 } 1586 1587 friend class ASTContext; // ASTContext creates these 1588 1589public: 1590 /// \brief Retrieve the qualification on this type. 1591 NestedNameSpecifier *getQualifier() const { return NNS; } 1592 1593 /// \brief Retrieve the type named by the typename specifier as an 1594 /// identifier. 1595 /// 1596 /// This routine will return a non-NULL identifier pointer when the 1597 /// form of the original typename was terminated by an identifier, 1598 /// e.g., "typename T::type". 1599 const IdentifierInfo *getIdentifier() const { 1600 return Name.dyn_cast<const IdentifierInfo *>(); 1601 } 1602 1603 /// \brief Retrieve the type named by the typename specifier as a 1604 /// type specialization. 1605 const TemplateSpecializationType *getTemplateId() const { 1606 return Name.dyn_cast<const TemplateSpecializationType *>(); 1607 } 1608 1609 virtual void getAsStringInternal(std::string &InnerString) const; 1610 1611 void Profile(llvm::FoldingSetNodeID &ID) { 1612 Profile(ID, NNS, Name); 1613 } 1614 1615 static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1616 NameType Name) { 1617 ID.AddPointer(NNS); 1618 ID.AddPointer(Name.getOpaqueValue()); 1619 } 1620 1621 static bool classof(const Type *T) { 1622 return T->getTypeClass() == Typename; 1623 } 1624 static bool classof(const TypenameType *T) { return true; } 1625}; 1626 1627/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1628/// object oriented design. They basically correspond to C++ classes. There 1629/// are two kinds of interface types, normal interfaces like "NSString" and 1630/// qualified interfaces, which are qualified with a protocol list like 1631/// "NSString<NSCopyable, NSAmazing>". Qualified interface types are instances 1632/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType. 1633class ObjCInterfaceType : public Type { 1634 ObjCInterfaceDecl *Decl; 1635protected: 1636 ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 1637 Type(tc, QualType(), /*Dependent=*/false), Decl(D) { } 1638 friend class ASTContext; // ASTContext creates these. 1639public: 1640 1641 ObjCInterfaceDecl *getDecl() const { return Decl; } 1642 1643 /// qual_iterator and friends: this provides access to the (potentially empty) 1644 /// list of protocols qualifying this interface. If this is an instance of 1645 /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an 1646 /// empty list if there are no qualifying protocols. 1647 typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1648 inline qual_iterator qual_begin() const; 1649 inline qual_iterator qual_end() const; 1650 bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; } 1651 1652 /// getNumProtocols - Return the number of qualifying protocols in this 1653 /// interface type, or 0 if there are none. 1654 inline unsigned getNumProtocols() const; 1655 1656 /// getProtocol - Return the specified qualifying protocol. 1657 inline ObjCProtocolDecl *getProtocol(unsigned i) const; 1658 1659 1660 virtual void getAsStringInternal(std::string &InnerString) const; 1661 static bool classof(const Type *T) { 1662 return T->getTypeClass() == ObjCInterface || 1663 T->getTypeClass() == ObjCQualifiedInterface; 1664 } 1665 static bool classof(const ObjCInterfaceType *) { return true; } 1666}; 1667 1668/// ObjCQualifiedInterfaceType - This class represents interface types 1669/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>. 1670/// 1671/// Duplicate protocols are removed and protocol list is canonicalized to be in 1672/// alphabetical order. 1673class ObjCQualifiedInterfaceType : public ObjCInterfaceType, 1674 public llvm::FoldingSetNode { 1675 1676 // List of protocols for this protocol conforming object type 1677 // List is sorted on protocol name. No protocol is enterred more than once. 1678 llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 1679 1680 ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1681 ObjCProtocolDecl **Protos, unsigned NumP) : 1682 ObjCInterfaceType(ObjCQualifiedInterface, D), 1683 Protocols(Protos, Protos+NumP) { } 1684 friend class ASTContext; // ASTContext creates these. 1685public: 1686 1687 ObjCProtocolDecl *getProtocol(unsigned i) const { 1688 return Protocols[i]; 1689 } 1690 unsigned getNumProtocols() const { 1691 return Protocols.size(); 1692 } 1693 1694 qual_iterator qual_begin() const { return Protocols.begin(); } 1695 qual_iterator qual_end() const { return Protocols.end(); } 1696 1697 virtual void getAsStringInternal(std::string &InnerString) const; 1698 1699 void Profile(llvm::FoldingSetNodeID &ID); 1700 static void Profile(llvm::FoldingSetNodeID &ID, 1701 const ObjCInterfaceDecl *Decl, 1702 ObjCProtocolDecl **protocols, unsigned NumProtocols); 1703 1704 static bool classof(const Type *T) { 1705 return T->getTypeClass() == ObjCQualifiedInterface; 1706 } 1707 static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1708}; 1709 1710inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const { 1711 if (const ObjCQualifiedInterfaceType *QIT = 1712 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1713 return QIT->qual_begin(); 1714 return 0; 1715} 1716inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const { 1717 if (const ObjCQualifiedInterfaceType *QIT = 1718 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1719 return QIT->qual_end(); 1720 return 0; 1721} 1722 1723/// getNumProtocols - Return the number of qualifying protocols in this 1724/// interface type, or 0 if there are none. 1725inline unsigned ObjCInterfaceType::getNumProtocols() const { 1726 if (const ObjCQualifiedInterfaceType *QIT = 1727 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1728 return QIT->getNumProtocols(); 1729 return 0; 1730} 1731 1732/// getProtocol - Return the specified qualifying protocol. 1733inline ObjCProtocolDecl *ObjCInterfaceType::getProtocol(unsigned i) const { 1734 return cast<ObjCQualifiedInterfaceType>(this)->getProtocol(i); 1735} 1736 1737 1738 1739/// ObjCQualifiedIdType - to represent id<protocol-list>. 1740/// 1741/// Duplicate protocols are removed and protocol list is canonicalized to be in 1742/// alphabetical order. 1743class ObjCQualifiedIdType : public Type, 1744 public llvm::FoldingSetNode { 1745 // List of protocols for this protocol conforming 'id' type 1746 // List is sorted on protocol name. No protocol is enterred more than once. 1747 llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1748 1749 ObjCQualifiedIdType(ObjCProtocolDecl **Protos, unsigned NumP) 1750 : Type(ObjCQualifiedId, QualType()/*these are always canonical*/, 1751 /*Dependent=*/false), 1752 Protocols(Protos, Protos+NumP) { } 1753 friend class ASTContext; // ASTContext creates these. 1754public: 1755 1756 ObjCProtocolDecl *getProtocols(unsigned i) const { 1757 return Protocols[i]; 1758 } 1759 unsigned getNumProtocols() const { 1760 return Protocols.size(); 1761 } 1762 ObjCProtocolDecl **getReferencedProtocols() { 1763 return &Protocols[0]; 1764 } 1765 1766 typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1767 qual_iterator qual_begin() const { return Protocols.begin(); } 1768 qual_iterator qual_end() const { return Protocols.end(); } 1769 1770 virtual void getAsStringInternal(std::string &InnerString) const; 1771 1772 void Profile(llvm::FoldingSetNodeID &ID); 1773 static void Profile(llvm::FoldingSetNodeID &ID, 1774 ObjCProtocolDecl **protocols, unsigned NumProtocols); 1775 1776 static bool classof(const Type *T) { 1777 return T->getTypeClass() == ObjCQualifiedId; 1778 } 1779 static bool classof(const ObjCQualifiedIdType *) { return true; } 1780 1781}; 1782 1783// Inline function definitions. 1784 1785/// getUnqualifiedType - Return the type without any qualifiers. 1786inline QualType QualType::getUnqualifiedType() const { 1787 Type *TP = getTypePtr(); 1788 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP)) 1789 TP = EXTQT->getBaseType(); 1790 return QualType(TP, 0); 1791} 1792 1793/// getAddressSpace - Return the address space of this type. 1794inline unsigned QualType::getAddressSpace() const { 1795 QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1796 if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1797 return AT->getElementType().getAddressSpace(); 1798 if (const RecordType *RT = dyn_cast<RecordType>(CT)) 1799 return RT->getAddressSpace(); 1800 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1801 return EXTQT->getAddressSpace(); 1802 return 0; 1803} 1804 1805/// getObjCGCAttr - Return the gc attribute of this type. 1806inline QualType::GCAttrTypes QualType::getObjCGCAttr() const { 1807 QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1808 if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1809 return AT->getElementType().getObjCGCAttr(); 1810 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1811 return EXTQT->getObjCGCAttr(); 1812 if (const PointerType *PT = CT->getAsPointerType()) 1813 return PT->getPointeeType().getObjCGCAttr(); 1814 return GCNone; 1815} 1816 1817/// isMoreQualifiedThan - Determine whether this type is more 1818/// qualified than the Other type. For example, "const volatile int" 1819/// is more qualified than "const int", "volatile int", and 1820/// "int". However, it is not more qualified than "const volatile 1821/// int". 1822inline bool QualType::isMoreQualifiedThan(QualType Other) const { 1823 unsigned MyQuals = this->getCVRQualifiers(); 1824 unsigned OtherQuals = Other.getCVRQualifiers(); 1825 if (getAddressSpace() != Other.getAddressSpace()) 1826 return false; 1827 return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 1828} 1829 1830/// isAtLeastAsQualifiedAs - Determine whether this type is at last 1831/// as qualified as the Other type. For example, "const volatile 1832/// int" is at least as qualified as "const int", "volatile int", 1833/// "int", and "const volatile int". 1834inline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 1835 unsigned MyQuals = this->getCVRQualifiers(); 1836 unsigned OtherQuals = Other.getCVRQualifiers(); 1837 if (getAddressSpace() != Other.getAddressSpace()) 1838 return false; 1839 return (MyQuals | OtherQuals) == MyQuals; 1840} 1841 1842/// getNonReferenceType - If Type is a reference type (e.g., const 1843/// int&), returns the type that the reference refers to ("const 1844/// int"). Otherwise, returns the type itself. This routine is used 1845/// throughout Sema to implement C++ 5p6: 1846/// 1847/// If an expression initially has the type "reference to T" (8.3.2, 1848/// 8.5.3), the type is adjusted to "T" prior to any further 1849/// analysis, the expression designates the object or function 1850/// denoted by the reference, and the expression is an lvalue. 1851inline QualType QualType::getNonReferenceType() const { 1852 if (const ReferenceType *RefType = (*this)->getAsReferenceType()) 1853 return RefType->getPointeeType(); 1854 else 1855 return *this; 1856} 1857 1858inline const TypedefType* Type::getAsTypedefType() const { 1859 return dyn_cast<TypedefType>(this); 1860} 1861inline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 1862 if (const PointerType *PT = getAsPointerType()) 1863 return PT->getPointeeType()->getAsObjCInterfaceType(); 1864 return 0; 1865} 1866 1867// NOTE: All of these methods use "getUnqualifiedType" to strip off address 1868// space qualifiers if present. 1869inline bool Type::isFunctionType() const { 1870 return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 1871} 1872inline bool Type::isPointerType() const { 1873 return isa<PointerType>(CanonicalType.getUnqualifiedType()); 1874} 1875inline bool Type::isBlockPointerType() const { 1876 return isa<BlockPointerType>(CanonicalType.getUnqualifiedType()); 1877} 1878inline bool Type::isReferenceType() const { 1879 return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 1880} 1881inline bool Type::isLValueReferenceType() const { 1882 return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()); 1883} 1884inline bool Type::isRValueReferenceType() const { 1885 return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()); 1886} 1887inline bool Type::isFunctionPointerType() const { 1888 if (const PointerType* T = getAsPointerType()) 1889 return T->getPointeeType()->isFunctionType(); 1890 else 1891 return false; 1892} 1893inline bool Type::isMemberPointerType() const { 1894 return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 1895} 1896inline bool Type::isMemberFunctionPointerType() const { 1897 if (const MemberPointerType* T = getAsMemberPointerType()) 1898 return T->getPointeeType()->isFunctionType(); 1899 else 1900 return false; 1901} 1902inline bool Type::isArrayType() const { 1903 return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 1904} 1905inline bool Type::isConstantArrayType() const { 1906 return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 1907} 1908inline bool Type::isIncompleteArrayType() const { 1909 return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 1910} 1911inline bool Type::isVariableArrayType() const { 1912 return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 1913} 1914inline bool Type::isDependentSizedArrayType() const { 1915 return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 1916} 1917inline bool Type::isRecordType() const { 1918 return isa<RecordType>(CanonicalType.getUnqualifiedType()); 1919} 1920inline bool Type::isAnyComplexType() const { 1921 return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 1922} 1923inline bool Type::isVectorType() const { 1924 return isa<VectorType>(CanonicalType.getUnqualifiedType()); 1925} 1926inline bool Type::isExtVectorType() const { 1927 return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 1928} 1929inline bool Type::isObjCInterfaceType() const { 1930 return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 1931} 1932inline bool Type::isObjCQualifiedInterfaceType() const { 1933 return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); 1934} 1935inline bool Type::isObjCQualifiedIdType() const { 1936 return isa<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType()); 1937} 1938inline bool Type::isTemplateTypeParmType() const { 1939 return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 1940} 1941 1942inline bool Type::isSpecificBuiltinType(unsigned K) const { 1943 if (const BuiltinType *BT = getAsBuiltinType()) 1944 if (BT->getKind() == (BuiltinType::Kind) K) 1945 return true; 1946 return false; 1947} 1948 1949/// \brief Determines whether this is a type for which one can define 1950/// an overloaded operator. 1951inline bool Type::isOverloadableType() const { 1952 return isDependentType() || isRecordType() || isEnumeralType(); 1953} 1954 1955inline bool Type::hasPointerRepresentation() const { 1956 return (isPointerType() || isReferenceType() || isBlockPointerType() || 1957 isObjCInterfaceType() || isObjCQualifiedIdType() || 1958 isObjCQualifiedInterfaceType()); 1959} 1960 1961inline bool Type::hasObjCPointerRepresentation() const { 1962 return (isObjCInterfaceType() || isObjCQualifiedIdType() || 1963 isObjCQualifiedInterfaceType()); 1964} 1965 1966/// Insertion operator for diagnostics. This allows sending QualType's into a 1967/// diagnostic with <<. 1968inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 1969 QualType T) { 1970 DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 1971 Diagnostic::ak_qualtype); 1972 return DB; 1973} 1974 1975} // end namespace clang 1976 1977#endif 1978