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