Type.h revision ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79
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 "llvm/Support/Casting.h" 18#include "llvm/ADT/FoldingSet.h" 19#include "llvm/ADT/APSInt.h" 20#include "llvm/Bitcode/SerializationFwd.h" 21 22using llvm::isa; 23using llvm::cast; 24using llvm::cast_or_null; 25using llvm::dyn_cast; 26using llvm::dyn_cast_or_null; 27 28namespace clang { 29 class ASTContext; 30 class Type; 31 class TypedefDecl; 32 class TagDecl; 33 class RecordDecl; 34 class CXXRecordDecl; 35 class EnumDecl; 36 class FieldDecl; 37 class ObjCInterfaceDecl; 38 class ObjCProtocolDecl; 39 class ObjCMethodDecl; 40 class Expr; 41 class Stmt; 42 class SourceLocation; 43 class PointerLikeType; 44 class PointerType; 45 class ReferenceType; 46 class VectorType; 47 class ArrayType; 48 class ConstantArrayType; 49 class VariableArrayType; 50 class IncompleteArrayType; 51 class RecordType; 52 class EnumType; 53 class ComplexType; 54 class TagType; 55 class TypedefType; 56 class FunctionType; 57 class FunctionTypeProto; 58 class ExtVectorType; 59 class BuiltinType; 60 class ObjCInterfaceType; 61 class ObjCQualifiedIdType; 62 class ObjCQualifiedInterfaceType; 63 class StmtIteratorBase; 64 65/// QualType - For efficiency, we don't store CVR-qualified types as nodes on 66/// their own: instead each reference to a type stores the qualifiers. This 67/// greatly reduces the number of nodes we need to allocate for types (for 68/// example we only need one for 'int', 'const int', 'volatile int', 69/// 'const volatile int', etc). 70/// 71/// As an added efficiency bonus, instead of making this a pair, we just store 72/// the three bits we care about in the low bits of the pointer. To handle the 73/// packing/unpacking, we make QualType be a simple wrapper class that acts like 74/// a smart pointer. 75class QualType { 76 uintptr_t ThePtr; 77public: 78 enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 79 Const = 0x1, 80 Restrict = 0x2, 81 Volatile = 0x4, 82 CVRFlags = Const|Restrict|Volatile 83 }; 84 85 QualType() : ThePtr(0) {} 86 87 QualType(Type *Ptr, unsigned Quals) { 88 assert((Quals & ~CVRFlags) == 0 && "Invalid type qualifiers!"); 89 ThePtr = reinterpret_cast<uintptr_t>(Ptr); 90 assert((ThePtr & CVRFlags) == 0 && "Type pointer not 8-byte aligned?"); 91 ThePtr |= Quals; 92 } 93 94 static QualType getFromOpaquePtr(void *Ptr) { 95 QualType T; 96 T.ThePtr = reinterpret_cast<uintptr_t>(Ptr); 97 return T; 98 } 99 100 unsigned getCVRQualifiers() const { 101 return ThePtr & CVRFlags; 102 } 103 Type *getTypePtr() const { 104 return reinterpret_cast<Type*>(ThePtr & ~CVRFlags); 105 } 106 107 void *getAsOpaquePtr() const { 108 return reinterpret_cast<void*>(ThePtr); 109 } 110 111 Type &operator*() const { 112 return *getTypePtr(); 113 } 114 115 Type *operator->() const { 116 return getTypePtr(); 117 } 118 119 /// isNull - Return true if this QualType doesn't point to a type yet. 120 bool isNull() const { 121 return ThePtr == 0; 122 } 123 124 bool isConstQualified() const { 125 return (ThePtr & Const) ? true : false; 126 } 127 bool isVolatileQualified() const { 128 return (ThePtr & Volatile) ? true : false; 129 } 130 bool isRestrictQualified() const { 131 return (ThePtr & Restrict) ? true : false; 132 } 133 134 /// addConst/addVolatile/addRestrict - add the specified type qual to this 135 /// QualType. 136 void addConst() { ThePtr |= Const; } 137 void addVolatile() { ThePtr |= Volatile; } 138 void addRestrict() { ThePtr |= Restrict; } 139 140 void removeConst() { ThePtr &= ~Const; } 141 void removeVolatile() { ThePtr &= ~Volatile; } 142 void removeRestrict() { ThePtr &= ~Restrict; } 143 144 QualType getQualifiedType(unsigned TQs) const { 145 return QualType(getTypePtr(), TQs); 146 } 147 QualType getWithAdditionalQualifiers(unsigned TQs) const { 148 return QualType(getTypePtr(), TQs|getCVRQualifiers()); 149 } 150 151 inline QualType getUnqualifiedType() const; 152 153 /// operator==/!= - Indicate whether the specified types and qualifiers are 154 /// identical. 155 bool operator==(const QualType &RHS) const { 156 return ThePtr == RHS.ThePtr; 157 } 158 bool operator!=(const QualType &RHS) const { 159 return ThePtr != RHS.ThePtr; 160 } 161 std::string getAsString() const { 162 std::string S; 163 getAsStringInternal(S); 164 return S; 165 } 166 void getAsStringInternal(std::string &Str) const; 167 168 void dump(const char *s) const; 169 void dump() const; 170 171 void Profile(llvm::FoldingSetNodeID &ID) const { 172 ID.AddPointer(getAsOpaquePtr()); 173 } 174 175public: 176 177 /// getAddressSpace - Return the address space of this type. 178 inline unsigned getAddressSpace() const; 179 180 /// Emit - Serialize a QualType to Bitcode. 181 void Emit(llvm::Serializer& S) const; 182 183 /// Read - Deserialize a QualType from Bitcode. 184 static QualType ReadVal(llvm::Deserializer& D); 185 186 void ReadBackpatch(llvm::Deserializer& D); 187}; 188 189} // end clang. 190 191namespace llvm { 192/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 193/// to a specific Type class. 194template<> struct simplify_type<const ::clang::QualType> { 195 typedef ::clang::Type* SimpleType; 196 static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 197 return Val.getTypePtr(); 198 } 199}; 200template<> struct simplify_type< ::clang::QualType> 201 : public simplify_type<const ::clang::QualType> {}; 202 203} // end namespace llvm 204 205namespace clang { 206 207/// Type - This is the base class of the type hierarchy. A central concept 208/// with types is that each type always has a canonical type. A canonical type 209/// is the type with any typedef names stripped out of it or the types it 210/// references. For example, consider: 211/// 212/// typedef int foo; 213/// typedef foo* bar; 214/// 'int *' 'foo *' 'bar' 215/// 216/// There will be a Type object created for 'int'. Since int is canonical, its 217/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 218/// TypeNameType). Its CanonicalType pointer points to the 'int' Type. Next 219/// there is a PointerType that represents 'int*', which, like 'int', is 220/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 221/// type is 'int*', and there is a TypeNameType for 'bar', whose canonical type 222/// is also 'int*'. 223/// 224/// Non-canonical types are useful for emitting diagnostics, without losing 225/// information about typedefs being used. Canonical types are useful for type 226/// comparisons (they allow by-pointer equality tests) and useful for reasoning 227/// about whether something has a particular form (e.g. is a function type), 228/// because they implicitly, recursively, strip all typedefs out of a type. 229/// 230/// Types, once created, are immutable. 231/// 232class Type { 233public: 234 enum TypeClass { 235 Builtin, Complex, Pointer, Reference, 236 ConstantArray, VariableArray, IncompleteArray, 237 Vector, ExtVector, 238 FunctionNoProto, FunctionProto, 239 TypeName, Tagged, ASQual, 240 ObjCInterface, ObjCQualifiedInterface, 241 ObjCQualifiedId, 242 TypeOfExp, TypeOfTyp // GNU typeof extension. 243 }; 244private: 245 QualType CanonicalType; 246 247 /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 248 /// Note that this should stay at the end of the ivars for Type so that 249 /// subclasses can pack their bitfields into the same word. 250 unsigned TC : 5; 251protected: 252 // silence VC++ warning C4355: 'this' : used in base member initializer list 253 Type *this_() { return this; } 254 Type(TypeClass tc, QualType Canonical) 255 : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 256 TC(tc) {} 257 virtual ~Type() {}; 258 virtual void Destroy(ASTContext& C); 259 friend class ASTContext; 260 261 void EmitTypeInternal(llvm::Serializer& S) const; 262 void ReadTypeInternal(llvm::Deserializer& D); 263 264public: 265 TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 266 267 bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 268 269 /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 270 /// object types, function types, and incomplete types. 271 272 /// isObjectType - types that fully describe objects. An object is a region 273 /// of memory that can be examined and stored into (H&S). 274 bool isObjectType() const; 275 276 /// isIncompleteType - Return true if this is an incomplete type. 277 /// A type that can describe objects, but which lacks information needed to 278 /// determine its size (e.g. void, or a fwd declared struct). Clients of this 279 /// routine will need to determine if the size is actually required. 280 bool isIncompleteType() const; 281 282 /// isIncompleteOrObjectType - Return true if this is an incomplete or object 283 /// type, in other words, not a function type. 284 bool isIncompleteOrObjectType() const { 285 return !isFunctionType(); 286 } 287 288 /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 289 /// types that have a non-constant expression. This does not include "[]". 290 bool isVariablyModifiedType() const; 291 292 /// Helper methods to distinguish type categories. All type predicates 293 /// operate on the canonical type, ignoring typedefs and qualifiers. 294 295 /// isIntegerType() does *not* include complex integers (a GCC extension). 296 /// isComplexIntegerType() can be used to test for complex integers. 297 bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 298 bool isEnumeralType() const; 299 bool isBooleanType() const; 300 bool isCharType() const; 301 bool isIntegralType() const; 302 303 /// Floating point categories. 304 bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 305 /// isComplexType() does *not* include complex integers (a GCC extension). 306 /// isComplexIntegerType() can be used to test for complex integers. 307 bool isComplexType() const; // C99 6.2.5p11 (complex) 308 bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 309 bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 310 bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 311 bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 312 bool isVoidType() const; // C99 6.2.5p19 313 bool isDerivedType() const; // C99 6.2.5p20 314 bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 315 bool isAggregateType() const; // C99 6.2.5p21 (arrays, structures) 316 317 // Type Predicates: Check to see if this type is structurally the specified 318 // type, ignoring typedefs and qualifiers. 319 bool isFunctionType() const; 320 bool isPointerLikeType() const; // Pointer or Reference. 321 bool isPointerType() const; 322 bool isReferenceType() const; 323 bool isFunctionPointerType() const; 324 bool isArrayType() const; 325 bool isConstantArrayType() const; 326 bool isIncompleteArrayType() const; 327 bool isVariableArrayType() const; 328 bool isRecordType() const; 329 bool isClassType() const; 330 bool isStructureType() const; 331 bool isUnionType() const; 332 bool isComplexIntegerType() const; // GCC _Complex integer type. 333 bool isVectorType() const; // GCC vector type. 334 bool isExtVectorType() const; // Extended vector type. 335 bool isObjCInterfaceType() const; // NSString or NSString<foo> 336 bool isObjCQualifiedInterfaceType() const; // NSString<foo> 337 bool isObjCQualifiedIdType() const; // id<foo> 338 339 // Type Checking Functions: Check to see if this type is structurally the 340 // specified type, ignoring typedefs and qualifiers, and return a pointer to 341 // the best type we can. 342 const BuiltinType *getAsBuiltinType() const; 343 const FunctionType *getAsFunctionType() const; 344 const FunctionTypeProto *getAsFunctionTypeProto() const; 345 const PointerLikeType *getAsPointerLikeType() const; // Pointer or Reference. 346 const PointerType *getAsPointerType() const; 347 const ReferenceType *getAsReferenceType() const; 348 const RecordType *getAsRecordType() const; 349 const RecordType *getAsStructureType() const; 350 /// NOTE: getAsArrayType* are methods on ASTContext. 351 const TypedefType *getAsTypedefType() const; 352 const RecordType *getAsUnionType() const; 353 const EnumType *getAsEnumType() const; 354 const VectorType *getAsVectorType() const; // GCC vector type. 355 const ComplexType *getAsComplexType() const; 356 const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 357 const ExtVectorType *getAsExtVectorType() const; // Extended vector type. 358 const ObjCInterfaceType *getAsObjCInterfaceType() const; 359 const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const; 360 const ObjCQualifiedIdType *getAsObjCQualifiedIdType() const; 361 362 /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 363 /// interface, return the interface type, otherwise return null. 364 const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 365 366 /// getArrayElementTypeNoTypeQual - If this is an array type, return the 367 /// element type of the array, potentially with type qualifiers missing. 368 /// This method should never be used when type qualifiers are meaningful. 369 const Type *getArrayElementTypeNoTypeQual() const; 370 371 372 373 /// getDesugaredType - Return the specified type with any "sugar" removed from 374 /// the type. This takes off typedefs, typeof's etc. If the outer level of 375 /// the type is already concrete, it returns it unmodified. This is similar 376 /// to getting the canonical type, but it doesn't remove *all* typedefs. For 377 /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 378 /// concrete. 379 QualType getDesugaredType() const; 380 381 /// More type predicates useful for type checking/promotion 382 bool isPromotableIntegerType() const; // C99 6.3.1.1p2 383 384 /// isSignedIntegerType - Return true if this is an integer type that is 385 /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 386 /// an enum decl which has a signed representation, or a vector of signed 387 /// integer element type. 388 bool isSignedIntegerType() const; 389 390 /// isUnsignedIntegerType - Return true if this is an integer type that is 391 /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 392 /// decl which has an unsigned representation, or a vector of unsigned integer 393 /// element type. 394 bool isUnsignedIntegerType() const; 395 396 /// isConstantSizeType - Return true if this is not a variable sized type, 397 /// according to the rules of C99 6.7.5p3. It is not legal to call this on 398 /// incomplete types. 399 bool isConstantSizeType() const; 400 401 QualType getCanonicalTypeInternal() const { return CanonicalType; } 402 void dump() const; 403 virtual void getAsStringInternal(std::string &InnerString) const = 0; 404 static bool classof(const Type *) { return true; } 405 406protected: 407 /// Emit - Emit a Type to bitcode. Used by ASTContext. 408 void Emit(llvm::Serializer& S) const; 409 410 /// Create - Construct a Type from bitcode. Used by ASTContext. 411 static void Create(ASTContext& Context, unsigned i, llvm::Deserializer& S); 412 413 /// EmitImpl - Subclasses must implement this method in order to 414 /// be serialized. 415 virtual void EmitImpl(llvm::Serializer& S) const; 416}; 417 418/// ASQualType - TR18037 (C embedded extensions) 6.2.5p26 419/// This supports address space qualified types. 420/// 421class ASQualType : public Type, public llvm::FoldingSetNode { 422 /// BaseType - This is the underlying type that this qualifies. All CVR 423 /// qualifiers are stored on the QualType that references this type, so we 424 /// can't have any here. 425 Type *BaseType; 426 /// Address Space ID - The address space ID this type is qualified with. 427 unsigned AddressSpace; 428 ASQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace) : 429 Type(ASQual, CanonicalPtr), BaseType(Base), AddressSpace(AddrSpace) { 430 } 431 friend class ASTContext; // ASTContext creates these. 432public: 433 Type *getBaseType() const { return BaseType; } 434 unsigned getAddressSpace() const { return AddressSpace; } 435 436 virtual void getAsStringInternal(std::string &InnerString) const; 437 438 void Profile(llvm::FoldingSetNodeID &ID) { 439 Profile(ID, getBaseType(), AddressSpace); 440 } 441 static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 442 unsigned AddrSpace) { 443 ID.AddPointer(Base); 444 ID.AddInteger(AddrSpace); 445 } 446 447 static bool classof(const Type *T) { return T->getTypeClass() == ASQual; } 448 static bool classof(const ASQualType *) { return true; } 449 450protected: 451 virtual void EmitImpl(llvm::Serializer& S) const; 452 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 453 friend class Type; 454}; 455 456 457/// BuiltinType - This class is used for builtin types like 'int'. Builtin 458/// types are always canonical and have a literal name field. 459class BuiltinType : public Type { 460public: 461 enum Kind { 462 Void, 463 464 Bool, // This is bool and/or _Bool. 465 Char_U, // This is 'char' for targets where char is unsigned. 466 UChar, // This is explicitly qualified unsigned char. 467 UShort, 468 UInt, 469 ULong, 470 ULongLong, 471 472 Char_S, // This is 'char' for targets where char is signed. 473 SChar, // This is explicitly qualified signed char. 474 Short, 475 Int, 476 Long, 477 LongLong, 478 479 Float, Double, LongDouble 480 }; 481private: 482 Kind TypeKind; 483public: 484 BuiltinType(Kind K) : Type(Builtin, QualType()), TypeKind(K) {} 485 486 Kind getKind() const { return TypeKind; } 487 const char *getName() const; 488 489 virtual void getAsStringInternal(std::string &InnerString) const; 490 491 static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 492 static bool classof(const BuiltinType *) { return true; } 493}; 494 495/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 496/// types (_Complex float etc) as well as the GCC integer complex extensions. 497/// 498class ComplexType : public Type, public llvm::FoldingSetNode { 499 QualType ElementType; 500 ComplexType(QualType Element, QualType CanonicalPtr) : 501 Type(Complex, CanonicalPtr), ElementType(Element) { 502 } 503 friend class ASTContext; // ASTContext creates these. 504public: 505 QualType getElementType() const { return ElementType; } 506 507 virtual void getAsStringInternal(std::string &InnerString) const; 508 509 void Profile(llvm::FoldingSetNodeID &ID) { 510 Profile(ID, getElementType()); 511 } 512 static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 513 ID.AddPointer(Element.getAsOpaquePtr()); 514 } 515 516 static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 517 static bool classof(const ComplexType *) { return true; } 518 519protected: 520 virtual void EmitImpl(llvm::Serializer& S) const; 521 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 522 friend class Type; 523}; 524 525/// PointerLikeType - Common base class for pointers and references. 526/// 527class PointerLikeType : public Type { 528 QualType PointeeType; 529protected: 530 PointerLikeType(TypeClass K, QualType Pointee, QualType CanonicalPtr) : 531 Type(K, CanonicalPtr), PointeeType(Pointee) { 532 } 533public: 534 535 QualType getPointeeType() const { return PointeeType; } 536 537 static bool classof(const Type *T) { 538 return T->getTypeClass() == Pointer || T->getTypeClass() == Reference; 539 } 540 static bool classof(const PointerLikeType *) { return true; } 541}; 542 543/// PointerType - C99 6.7.5.1 - Pointer Declarators. 544/// 545class PointerType : public PointerLikeType, public llvm::FoldingSetNode { 546 PointerType(QualType Pointee, QualType CanonicalPtr) : 547 PointerLikeType(Pointer, Pointee, CanonicalPtr) { 548 } 549 friend class ASTContext; // ASTContext creates these. 550public: 551 552 virtual void getAsStringInternal(std::string &InnerString) const; 553 554 void Profile(llvm::FoldingSetNodeID &ID) { 555 Profile(ID, getPointeeType()); 556 } 557 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 558 ID.AddPointer(Pointee.getAsOpaquePtr()); 559 } 560 561 static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 562 static bool classof(const PointerType *) { return true; } 563 564protected: 565 virtual void EmitImpl(llvm::Serializer& S) const; 566 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 567 friend class Type; 568}; 569 570/// ReferenceType - C++ 8.3.2 - Reference Declarators. 571/// 572class ReferenceType : public PointerLikeType, public llvm::FoldingSetNode { 573 ReferenceType(QualType Referencee, QualType CanonicalRef) : 574 PointerLikeType(Reference, Referencee, CanonicalRef) { 575 } 576 friend class ASTContext; // ASTContext creates these. 577public: 578 virtual void getAsStringInternal(std::string &InnerString) const; 579 580 void Profile(llvm::FoldingSetNodeID &ID) { 581 Profile(ID, getPointeeType()); 582 } 583 static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 584 ID.AddPointer(Referencee.getAsOpaquePtr()); 585 } 586 587 static bool classof(const Type *T) { return T->getTypeClass() == Reference; } 588 static bool classof(const ReferenceType *) { return true; } 589}; 590 591/// ArrayType - C99 6.7.5.2 - Array Declarators. 592/// 593class ArrayType : public Type, public llvm::FoldingSetNode { 594public: 595 /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 596 /// an array with a static size (e.g. int X[static 4]), or with a star size 597 /// (e.g. int X[*]). 'static' is only allowed on function parameters. 598 enum ArraySizeModifier { 599 Normal, Static, Star 600 }; 601private: 602 /// ElementType - The element type of the array. 603 QualType ElementType; 604 605 // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 606 /// NOTE: These fields are packed into the bitfields space in the Type class. 607 unsigned SizeModifier : 2; 608 609 /// IndexTypeQuals - Capture qualifiers in declarations like: 610 /// 'int X[static restrict 4]'. For function parameters only. 611 unsigned IndexTypeQuals : 3; 612 613protected: 614 ArrayType(TypeClass tc, QualType et, QualType can, 615 ArraySizeModifier sm, unsigned tq) 616 : Type(tc, can), ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 617 friend class ASTContext; // ASTContext creates these. 618public: 619 QualType getElementType() const { return ElementType; } 620 ArraySizeModifier getSizeModifier() const { 621 return ArraySizeModifier(SizeModifier); 622 } 623 unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 624 625 static bool classof(const Type *T) { 626 return T->getTypeClass() == ConstantArray || 627 T->getTypeClass() == VariableArray || 628 T->getTypeClass() == IncompleteArray; 629 } 630 static bool classof(const ArrayType *) { return true; } 631}; 632 633/// ConstantArrayType - This class represents C arrays with a specified constant 634/// size. For example 'int A[100]' has ConstantArrayType where the element type 635/// is 'int' and the size is 100. 636class ConstantArrayType : public ArrayType { 637 llvm::APInt Size; // Allows us to unique the type. 638 639 ConstantArrayType(QualType et, QualType can, llvm::APInt sz, 640 ArraySizeModifier sm, unsigned tq) 641 : ArrayType(ConstantArray, et, can, sm, tq), Size(sz) {} 642 friend class ASTContext; // ASTContext creates these. 643public: 644 const llvm::APInt &getSize() const { return Size; } 645 virtual void getAsStringInternal(std::string &InnerString) const; 646 647 void Profile(llvm::FoldingSetNodeID &ID) { 648 Profile(ID, getElementType(), getSize()); 649 } 650 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 651 llvm::APInt ArraySize) { 652 ID.AddPointer(ET.getAsOpaquePtr()); 653 ID.AddInteger(ArraySize.getZExtValue()); 654 } 655 static bool classof(const Type *T) { 656 return T->getTypeClass() == ConstantArray; 657 } 658 static bool classof(const ConstantArrayType *) { return true; } 659 660protected: 661 virtual void EmitImpl(llvm::Serializer& S) const; 662 static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 663 friend class Type; 664}; 665 666/// IncompleteArrayType - This class represents C arrays with an unspecified 667/// size. For example 'int A[]' has an IncompleteArrayType where the element 668/// type is 'int' and the size is unspecified. 669class IncompleteArrayType : public ArrayType { 670 IncompleteArrayType(QualType et, QualType can, 671 ArraySizeModifier sm, unsigned tq) 672 : ArrayType(IncompleteArray, et, can, sm, tq) {} 673 friend class ASTContext; // ASTContext creates these. 674public: 675 676 virtual void getAsStringInternal(std::string &InnerString) const; 677 678 static bool classof(const Type *T) { 679 return T->getTypeClass() == IncompleteArray; 680 } 681 static bool classof(const IncompleteArrayType *) { return true; } 682 683 friend class StmtIteratorBase; 684 685 void Profile(llvm::FoldingSetNodeID &ID) { 686 Profile(ID, getElementType()); 687 } 688 689 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET) { 690 ID.AddPointer(ET.getAsOpaquePtr()); 691 } 692 693protected: 694 virtual void EmitImpl(llvm::Serializer& S) const; 695 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 696 friend class Type; 697}; 698 699/// VariableArrayType - This class represents C arrays with a specified size 700/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 701/// Since the size expression is an arbitrary expression, we store it as such. 702/// 703/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 704/// should not be: two lexically equivalent variable array types could mean 705/// different things, for example, these variables do not have the same type 706/// dynamically: 707/// 708/// void foo(int x) { 709/// int Y[x]; 710/// ++x; 711/// int Z[x]; 712/// } 713/// 714class VariableArrayType : public ArrayType { 715 /// SizeExpr - An assignment expression. VLA's are only permitted within 716 /// a function block. 717 Stmt *SizeExpr; 718 719 VariableArrayType(QualType et, QualType can, Expr *e, 720 ArraySizeModifier sm, unsigned tq) 721 : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 722 friend class ASTContext; // ASTContext creates these. 723 virtual void Destroy(ASTContext& C); 724 725public: 726 Expr *getSizeExpr() const { 727 // We use C-style casts instead of cast<> here because we do not wish 728 // to have a dependency of Type.h on Stmt.h/Expr.h. 729 return (Expr*) SizeExpr; 730 } 731 732 virtual void getAsStringInternal(std::string &InnerString) const; 733 734 static bool classof(const Type *T) { 735 return T->getTypeClass() == VariableArray; 736 } 737 static bool classof(const VariableArrayType *) { return true; } 738 739 friend class StmtIteratorBase; 740 741 void Profile(llvm::FoldingSetNodeID &ID) { 742 assert (0 && "Cannnot unique VariableArrayTypes."); 743 } 744 745protected: 746 virtual void EmitImpl(llvm::Serializer& S) const; 747 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 748 friend class Type; 749}; 750 751/// VectorType - GCC generic vector type. This type is created using 752/// __attribute__((vector_size(n)), where "n" specifies the vector size in 753/// bytes. Since the constructor takes the number of vector elements, the 754/// client is responsible for converting the size into the number of elements. 755class VectorType : public Type, public llvm::FoldingSetNode { 756protected: 757 /// ElementType - The element type of the vector. 758 QualType ElementType; 759 760 /// NumElements - The number of elements in the vector. 761 unsigned NumElements; 762 763 VectorType(QualType vecType, unsigned nElements, QualType canonType) : 764 Type(Vector, canonType), ElementType(vecType), NumElements(nElements) {} 765 VectorType(TypeClass tc, QualType vecType, unsigned nElements, 766 QualType canonType) : Type(tc, canonType), ElementType(vecType), 767 NumElements(nElements) {} 768 friend class ASTContext; // ASTContext creates these. 769public: 770 771 QualType getElementType() const { return ElementType; } 772 unsigned getNumElements() const { return NumElements; } 773 774 virtual void getAsStringInternal(std::string &InnerString) const; 775 776 void Profile(llvm::FoldingSetNodeID &ID) { 777 Profile(ID, getElementType(), getNumElements(), getTypeClass()); 778 } 779 static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 780 unsigned NumElements, TypeClass TypeClass) { 781 ID.AddPointer(ElementType.getAsOpaquePtr()); 782 ID.AddInteger(NumElements); 783 ID.AddInteger(TypeClass); 784 } 785 static bool classof(const Type *T) { 786 return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 787 } 788 static bool classof(const VectorType *) { return true; } 789}; 790 791/// ExtVectorType - Extended vector type. This type is created using 792/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 793/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 794/// class enables syntactic extensions, like Vector Components for accessing 795/// points, colors, and textures (modeled after OpenGL Shading Language). 796class ExtVectorType : public VectorType { 797 ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 798 VectorType(ExtVector, vecType, nElements, canonType) {} 799 friend class ASTContext; // ASTContext creates these. 800public: 801 static int getPointAccessorIdx(char c) { 802 switch (c) { 803 default: return -1; 804 case 'x': return 0; 805 case 'y': return 1; 806 case 'z': return 2; 807 case 'w': return 3; 808 } 809 } 810 static int getColorAccessorIdx(char c) { 811 switch (c) { 812 default: return -1; 813 case 'r': return 0; 814 case 'g': return 1; 815 case 'b': return 2; 816 case 'a': return 3; 817 } 818 } 819 static int getTextureAccessorIdx(char c) { 820 switch (c) { 821 default: return -1; 822 case 's': return 0; 823 case 't': return 1; 824 case 'p': return 2; 825 case 'q': return 3; 826 } 827 }; 828 829 static int getAccessorIdx(char c) { 830 if (int idx = getPointAccessorIdx(c)+1) return idx-1; 831 if (int idx = getColorAccessorIdx(c)+1) return idx-1; 832 return getTextureAccessorIdx(c); 833 } 834 835 bool isAccessorWithinNumElements(char c) const { 836 if (int idx = getAccessorIdx(c)+1) 837 return unsigned(idx-1) < NumElements; 838 return false; 839 } 840 virtual void getAsStringInternal(std::string &InnerString) const; 841 842 static bool classof(const Type *T) { 843 return T->getTypeClass() == ExtVector; 844 } 845 static bool classof(const ExtVectorType *) { return true; } 846}; 847 848/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 849/// class of FunctionTypeNoProto and FunctionTypeProto. 850/// 851class FunctionType : public Type { 852 /// SubClassData - This field is owned by the subclass, put here to pack 853 /// tightly with the ivars in Type. 854 bool SubClassData : 1; 855 856 // The type returned by the function. 857 QualType ResultType; 858protected: 859 FunctionType(TypeClass tc, QualType res, bool SubclassInfo,QualType Canonical) 860 : Type(tc, Canonical), SubClassData(SubclassInfo), ResultType(res) {} 861 bool getSubClassData() const { return SubClassData; } 862public: 863 864 QualType getResultType() const { return ResultType; } 865 866 867 static bool classof(const Type *T) { 868 return T->getTypeClass() == FunctionNoProto || 869 T->getTypeClass() == FunctionProto; 870 } 871 static bool classof(const FunctionType *) { return true; } 872}; 873 874/// FunctionTypeNoProto - Represents a K&R-style 'int foo()' function, which has 875/// no information available about its arguments. 876class FunctionTypeNoProto : public FunctionType, public llvm::FoldingSetNode { 877 FunctionTypeNoProto(QualType Result, QualType Canonical) 878 : FunctionType(FunctionNoProto, Result, false, Canonical) {} 879 friend class ASTContext; // ASTContext creates these. 880public: 881 // No additional state past what FunctionType provides. 882 883 virtual void getAsStringInternal(std::string &InnerString) const; 884 885 void Profile(llvm::FoldingSetNodeID &ID) { 886 Profile(ID, getResultType()); 887 } 888 static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) { 889 ID.AddPointer(ResultType.getAsOpaquePtr()); 890 } 891 892 static bool classof(const Type *T) { 893 return T->getTypeClass() == FunctionNoProto; 894 } 895 static bool classof(const FunctionTypeNoProto *) { return true; } 896 897protected: 898 virtual void EmitImpl(llvm::Serializer& S) const; 899 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 900 friend class Type; 901}; 902 903/// FunctionTypeProto - Represents a prototype with argument type info, e.g. 904/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 905/// arguments, not as having a single void argument. 906class FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode { 907 FunctionTypeProto(QualType Result, QualType *ArgArray, unsigned numArgs, 908 bool isVariadic, QualType Canonical) 909 : FunctionType(FunctionProto, Result, isVariadic, Canonical), 910 NumArgs(numArgs) { 911 // Fill in the trailing argument array. 912 QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);; 913 for (unsigned i = 0; i != numArgs; ++i) 914 ArgInfo[i] = ArgArray[i]; 915 } 916 917 /// NumArgs - The number of arguments this function has, not counting '...'. 918 unsigned NumArgs; 919 920 /// ArgInfo - There is an variable size array after the class in memory that 921 /// holds the argument types. 922 923 friend class ASTContext; // ASTContext creates these. 924 virtual void Destroy(ASTContext& C); 925 926public: 927 unsigned getNumArgs() const { return NumArgs; } 928 QualType getArgType(unsigned i) const { 929 assert(i < NumArgs && "Invalid argument number!"); 930 return arg_type_begin()[i]; 931 } 932 933 bool isVariadic() const { return getSubClassData(); } 934 935 typedef const QualType *arg_type_iterator; 936 arg_type_iterator arg_type_begin() const { 937 return reinterpret_cast<const QualType *>(this+1); 938 } 939 arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 940 941 virtual void getAsStringInternal(std::string &InnerString) const; 942 943 static bool classof(const Type *T) { 944 return T->getTypeClass() == FunctionProto; 945 } 946 static bool classof(const FunctionTypeProto *) { return true; } 947 948 void Profile(llvm::FoldingSetNodeID &ID); 949 static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 950 arg_type_iterator ArgTys, unsigned NumArgs, 951 bool isVariadic); 952 953protected: 954 virtual void EmitImpl(llvm::Serializer& S) const; 955 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 956 friend class Type; 957}; 958 959 960class TypedefType : public Type { 961 TypedefDecl *Decl; 962protected: 963 TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 964 : Type(tc, can), Decl(D) { 965 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 966 } 967 friend class ASTContext; // ASTContext creates these. 968public: 969 970 TypedefDecl *getDecl() const { return Decl; } 971 972 /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 973 /// potentially looking through *all* consequtive typedefs. This returns the 974 /// sum of the type qualifiers, so if you have: 975 /// typedef const int A; 976 /// typedef volatile A B; 977 /// looking through the typedefs for B will give you "const volatile A". 978 QualType LookThroughTypedefs() const; 979 980 virtual void getAsStringInternal(std::string &InnerString) const; 981 982 static bool classof(const Type *T) { return T->getTypeClass() == TypeName; } 983 static bool classof(const TypedefType *) { return true; } 984 985protected: 986 virtual void EmitImpl(llvm::Serializer& S) const; 987 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 988 friend class Type; 989}; 990 991/// TypeOfExpr (GCC extension). 992class TypeOfExpr : public Type { 993 Expr *TOExpr; 994 TypeOfExpr(Expr *E, QualType can) : Type(TypeOfExp, can), TOExpr(E) { 995 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 996 } 997 friend class ASTContext; // ASTContext creates these. 998public: 999 Expr *getUnderlyingExpr() const { return TOExpr; } 1000 1001 virtual void getAsStringInternal(std::string &InnerString) const; 1002 1003 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExp; } 1004 static bool classof(const TypeOfExpr *) { return true; } 1005}; 1006 1007/// TypeOfType (GCC extension). 1008class TypeOfType : public Type { 1009 QualType TOType; 1010 TypeOfType(QualType T, QualType can) : Type(TypeOfTyp, can), TOType(T) { 1011 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1012 } 1013 friend class ASTContext; // ASTContext creates these. 1014public: 1015 QualType getUnderlyingType() const { return TOType; } 1016 1017 virtual void getAsStringInternal(std::string &InnerString) const; 1018 1019 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfTyp; } 1020 static bool classof(const TypeOfType *) { return true; } 1021}; 1022 1023class TagType : public Type { 1024 TagDecl *decl; 1025 1026protected: 1027 TagType(TagDecl *D, QualType can) : Type(Tagged, can), decl(D) {} 1028 1029public: 1030 TagDecl *getDecl() const { return decl; } 1031 1032 virtual void getAsStringInternal(std::string &InnerString) const; 1033 1034 static bool classof(const Type *T) { return T->getTypeClass() == Tagged; } 1035 static bool classof(const TagType *) { return true; } 1036 1037protected: 1038 virtual void EmitImpl(llvm::Serializer& S) const; 1039 static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 1040 friend class Type; 1041}; 1042 1043/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 1044/// to detect TagType objects of structs/unions/classes. 1045class RecordType : public TagType { 1046protected: 1047 explicit RecordType(RecordDecl *D) : TagType(cast<TagDecl>(D), QualType()) { } 1048 friend class ASTContext; // ASTContext creates these. 1049public: 1050 1051 RecordDecl *getDecl() const { 1052 return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 1053 } 1054 1055 // FIXME: This predicate is a helper to QualType/Type. It needs to 1056 // recursively check all fields for const-ness. If any field is declared 1057 // const, it needs to return false. 1058 bool hasConstFields() const { return false; } 1059 1060 // FIXME: RecordType needs to check when it is created that all fields are in 1061 // the same address space, and return that. 1062 unsigned getAddressSpace() const { return 0; } 1063 1064 static bool classof(const TagType *T); 1065 static bool classof(const Type *T) { 1066 return isa<TagType>(T) && classof(cast<TagType>(T)); 1067 } 1068 static bool classof(const RecordType *) { return true; } 1069}; 1070 1071/// CXXRecordType - This is a helper class that allows the use of 1072/// isa/cast/dyncast to detect TagType objects of C++ structs/unions/classes. 1073class CXXRecordType : public RecordType { 1074 explicit CXXRecordType(CXXRecordDecl *D) 1075 : RecordType(reinterpret_cast<RecordDecl*>(D)) { } 1076 friend class ASTContext; // ASTContext creates these. 1077public: 1078 1079 CXXRecordDecl *getDecl() const { 1080 return reinterpret_cast<CXXRecordDecl*>(RecordType::getDecl()); 1081 } 1082 1083 static bool classof(const TagType *T); 1084 static bool classof(const Type *T) { 1085 return isa<TagType>(T) && classof(cast<TagType>(T)); 1086 } 1087 static bool classof(const CXXRecordType *) { return true; } 1088}; 1089 1090/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 1091/// to detect TagType objects of enums. 1092class EnumType : public TagType { 1093 explicit EnumType(EnumDecl *D) : TagType(cast<TagDecl>(D), QualType()) { } 1094 friend class ASTContext; // ASTContext creates these. 1095public: 1096 1097 EnumDecl *getDecl() const { 1098 return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 1099 } 1100 1101 static bool classof(const TagType *T); 1102 static bool classof(const Type *T) { 1103 return isa<TagType>(T) && classof(cast<TagType>(T)); 1104 } 1105 static bool classof(const EnumType *) { return true; } 1106}; 1107 1108 1109 1110/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1111/// object oriented design. They basically correspond to C++ classes. There 1112/// are two kinds of interface types, normal interfaces like "NSString" and 1113/// qualified interfaces, which are qualified with a protocol list like 1114/// "NSString<NSCopyable, NSAmazing>". Qualified interface types are instances 1115/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType. 1116class ObjCInterfaceType : public Type { 1117 ObjCInterfaceDecl *Decl; 1118protected: 1119 ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 1120 Type(tc, QualType()), Decl(D) { } 1121 friend class ASTContext; // ASTContext creates these. 1122public: 1123 1124 ObjCInterfaceDecl *getDecl() const { return Decl; } 1125 1126 /// qual_iterator and friends: this provides access to the (potentially empty) 1127 /// list of protocols qualifying this interface. If this is an instance of 1128 /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an 1129 /// empty list if there are no qualifying protocols. 1130 typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1131 inline qual_iterator qual_begin() const; 1132 inline qual_iterator qual_end() const; 1133 bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; } 1134 1135 /// getNumProtocols - Return the number of qualifying protocols in this 1136 /// interface type, or 0 if there are none. 1137 inline unsigned getNumProtocols() const; 1138 1139 /// getProtocol - Return the specified qualifying protocol. 1140 inline ObjCProtocolDecl *getProtocol(unsigned i) const; 1141 1142 1143 virtual void getAsStringInternal(std::string &InnerString) const; 1144 static bool classof(const Type *T) { 1145 return T->getTypeClass() == ObjCInterface || 1146 T->getTypeClass() == ObjCQualifiedInterface; 1147 } 1148 static bool classof(const ObjCInterfaceType *) { return true; } 1149}; 1150 1151/// ObjCQualifiedInterfaceType - This class represents interface types 1152/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>. 1153/// 1154/// Duplicate protocols are removed and protocol list is canonicalized to be in 1155/// alphabetical order. 1156class ObjCQualifiedInterfaceType : public ObjCInterfaceType, 1157 public llvm::FoldingSetNode { 1158 1159 // List of protocols for this protocol conforming object type 1160 // List is sorted on protocol name. No protocol is enterred more than once. 1161 llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 1162 1163 ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1164 ObjCProtocolDecl **Protos, unsigned NumP) : 1165 ObjCInterfaceType(ObjCQualifiedInterface, D), 1166 Protocols(Protos, Protos+NumP) { } 1167 friend class ASTContext; // ASTContext creates these. 1168public: 1169 1170 ObjCProtocolDecl *getProtocol(unsigned i) const { 1171 return Protocols[i]; 1172 } 1173 unsigned getNumProtocols() const { 1174 return Protocols.size(); 1175 } 1176 1177 qual_iterator qual_begin() const { return Protocols.begin(); } 1178 qual_iterator qual_end() const { return Protocols.end(); } 1179 1180 virtual void getAsStringInternal(std::string &InnerString) const; 1181 1182 void Profile(llvm::FoldingSetNodeID &ID); 1183 static void Profile(llvm::FoldingSetNodeID &ID, 1184 const ObjCInterfaceDecl *Decl, 1185 ObjCProtocolDecl **protocols, unsigned NumProtocols); 1186 1187 static bool classof(const Type *T) { 1188 return T->getTypeClass() == ObjCQualifiedInterface; 1189 } 1190 static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1191}; 1192 1193inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const { 1194 if (const ObjCQualifiedInterfaceType *QIT = 1195 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1196 return QIT->qual_begin(); 1197 return 0; 1198} 1199inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const { 1200 if (const ObjCQualifiedInterfaceType *QIT = 1201 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1202 return QIT->qual_end(); 1203 return 0; 1204} 1205 1206/// getNumProtocols - Return the number of qualifying protocols in this 1207/// interface type, or 0 if there are none. 1208inline unsigned ObjCInterfaceType::getNumProtocols() const { 1209 if (const ObjCQualifiedInterfaceType *QIT = 1210 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1211 return QIT->getNumProtocols(); 1212 return 0; 1213} 1214 1215/// getProtocol - Return the specified qualifying protocol. 1216inline ObjCProtocolDecl *ObjCInterfaceType::getProtocol(unsigned i) const { 1217 return cast<ObjCQualifiedInterfaceType>(this)->getProtocol(i); 1218} 1219 1220 1221 1222/// ObjCQualifiedIdType - to represent id<protocol-list>. 1223/// 1224/// Duplicate protocols are removed and protocol list is canonicalized to be in 1225/// alphabetical order. 1226class ObjCQualifiedIdType : public Type, 1227 public llvm::FoldingSetNode { 1228 // List of protocols for this protocol conforming 'id' type 1229 // List is sorted on protocol name. No protocol is enterred more than once. 1230 llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1231 1232 ObjCQualifiedIdType(ObjCProtocolDecl **Protos, unsigned NumP) 1233 : Type(ObjCQualifiedId, QualType()/*these are always canonical*/), 1234 Protocols(Protos, Protos+NumP) { } 1235 friend class ASTContext; // ASTContext creates these. 1236public: 1237 1238 ObjCProtocolDecl *getProtocols(unsigned i) const { 1239 return Protocols[i]; 1240 } 1241 unsigned getNumProtocols() const { 1242 return Protocols.size(); 1243 } 1244 ObjCProtocolDecl **getReferencedProtocols() { 1245 return &Protocols[0]; 1246 } 1247 1248 typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1249 qual_iterator qual_begin() const { return Protocols.begin(); } 1250 qual_iterator qual_end() const { return Protocols.end(); } 1251 1252 virtual void getAsStringInternal(std::string &InnerString) const; 1253 1254 void Profile(llvm::FoldingSetNodeID &ID); 1255 static void Profile(llvm::FoldingSetNodeID &ID, 1256 ObjCProtocolDecl **protocols, unsigned NumProtocols); 1257 1258 static bool classof(const Type *T) { 1259 return T->getTypeClass() == ObjCQualifiedId; 1260 } 1261 static bool classof(const ObjCQualifiedIdType *) { return true; } 1262 1263}; 1264 1265 1266// Inline function definitions. 1267 1268/// getUnqualifiedType - Return the type without any qualifiers. 1269inline QualType QualType::getUnqualifiedType() const { 1270 Type *TP = getTypePtr(); 1271 if (const ASQualType *ASQT = dyn_cast<ASQualType>(TP)) 1272 TP = ASQT->getBaseType(); 1273 return QualType(TP, 0); 1274} 1275 1276/// getAddressSpace - Return the address space of this type. 1277inline unsigned QualType::getAddressSpace() const { 1278 QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1279 if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1280 return AT->getElementType().getAddressSpace(); 1281 if (const RecordType *RT = dyn_cast<RecordType>(CT)) 1282 return RT->getAddressSpace(); 1283 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CT)) 1284 return ASQT->getAddressSpace(); 1285 return 0; 1286} 1287 1288inline const TypedefType* Type::getAsTypedefType() const { 1289 return dyn_cast<TypedefType>(this); 1290} 1291inline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 1292 if (const PointerType *PT = getAsPointerType()) 1293 return PT->getPointeeType()->getAsObjCInterfaceType(); 1294 return 0; 1295} 1296 1297// NOTE: All of these methods use "getUnqualifiedType" to strip off address 1298// space qualifiers if present. 1299inline bool Type::isFunctionType() const { 1300 return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 1301} 1302inline bool Type::isPointerType() const { 1303 return isa<PointerType>(CanonicalType.getUnqualifiedType()); 1304} 1305inline bool Type::isReferenceType() const { 1306 return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 1307} 1308inline bool Type::isPointerLikeType() const { 1309 return isa<PointerLikeType>(CanonicalType.getUnqualifiedType()); 1310} 1311inline bool Type::isFunctionPointerType() const { 1312 if (const PointerType* T = getAsPointerType()) 1313 return T->getPointeeType()->isFunctionType(); 1314 else 1315 return false; 1316} 1317inline bool Type::isArrayType() const { 1318 return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 1319} 1320inline bool Type::isConstantArrayType() const { 1321 return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 1322} 1323inline bool Type::isIncompleteArrayType() const { 1324 return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 1325} 1326inline bool Type::isVariableArrayType() const { 1327 return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 1328} 1329inline bool Type::isRecordType() const { 1330 return isa<RecordType>(CanonicalType.getUnqualifiedType()); 1331} 1332inline bool Type::isAnyComplexType() const { 1333 return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 1334} 1335inline bool Type::isVectorType() const { 1336 return isa<VectorType>(CanonicalType.getUnqualifiedType()); 1337} 1338inline bool Type::isExtVectorType() const { 1339 return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 1340} 1341inline bool Type::isObjCInterfaceType() const { 1342 return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 1343} 1344inline bool Type::isObjCQualifiedInterfaceType() const { 1345 return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); 1346} 1347inline bool Type::isObjCQualifiedIdType() const { 1348 return isa<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType()); 1349} 1350} // end namespace clang 1351 1352#endif 1353