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