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