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