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