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