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