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