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