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