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