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