Type.h revision 3049ec9961d1a1f0570a24dc601e6a362129b35d
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 "clang/Basic/IdentifierTable.h" 19#include "clang/Basic/Linkage.h" 20#include "clang/Basic/PartialDiagnostic.h" 21#include "clang/AST/NestedNameSpecifier.h" 22#include "clang/AST/TemplateName.h" 23#include "llvm/Support/Casting.h" 24#include "llvm/Support/type_traits.h" 25#include "llvm/ADT/APSInt.h" 26#include "llvm/ADT/FoldingSet.h" 27#include "llvm/ADT/PointerIntPair.h" 28#include "llvm/ADT/PointerUnion.h" 29 30using llvm::isa; 31using llvm::cast; 32using llvm::cast_or_null; 33using llvm::dyn_cast; 34using llvm::dyn_cast_or_null; 35namespace clang { 36 enum { 37 TypeAlignmentInBits = 3, 38 TypeAlignment = 1 << TypeAlignmentInBits 39 }; 40 class Type; 41 class ExtQuals; 42 class QualType; 43} 44 45namespace llvm { 46 template <typename T> 47 class PointerLikeTypeTraits; 48 template<> 49 class PointerLikeTypeTraits< ::clang::Type*> { 50 public: 51 static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 52 static inline ::clang::Type *getFromVoidPointer(void *P) { 53 return static_cast< ::clang::Type*>(P); 54 } 55 enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 56 }; 57 template<> 58 class PointerLikeTypeTraits< ::clang::ExtQuals*> { 59 public: 60 static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; } 61 static inline ::clang::ExtQuals *getFromVoidPointer(void *P) { 62 return static_cast< ::clang::ExtQuals*>(P); 63 } 64 enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; 65 }; 66 67 template <> 68 struct isPodLike<clang::QualType> { static const bool value = true; }; 69} 70 71namespace clang { 72 class ASTContext; 73 class TypedefDecl; 74 class TemplateDecl; 75 class TemplateTypeParmDecl; 76 class NonTypeTemplateParmDecl; 77 class TemplateTemplateParmDecl; 78 class TagDecl; 79 class RecordDecl; 80 class CXXRecordDecl; 81 class EnumDecl; 82 class FieldDecl; 83 class ObjCInterfaceDecl; 84 class ObjCProtocolDecl; 85 class ObjCMethodDecl; 86 class UnresolvedUsingTypenameDecl; 87 class Expr; 88 class Stmt; 89 class SourceLocation; 90 class StmtIteratorBase; 91 class TemplateArgument; 92 class TemplateArgumentLoc; 93 class TemplateArgumentListInfo; 94 class Type; 95 class ElaboratedType; 96 struct PrintingPolicy; 97 98 template <typename> class CanQual; 99 typedef CanQual<Type> CanQualType; 100 101 // Provide forward declarations for all of the *Type classes 102#define TYPE(Class, Base) class Class##Type; 103#include "clang/AST/TypeNodes.def" 104 105/// Qualifiers - The collection of all-type qualifiers we support. 106/// Clang supports five independent qualifiers: 107/// * C99: const, volatile, and restrict 108/// * Embedded C (TR18037): address spaces 109/// * Objective C: the GC attributes (none, weak, or strong) 110class Qualifiers { 111public: 112 enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 113 Const = 0x1, 114 Restrict = 0x2, 115 Volatile = 0x4, 116 CVRMask = Const | Volatile | Restrict 117 }; 118 119 enum GC { 120 GCNone = 0, 121 Weak, 122 Strong 123 }; 124 125 enum { 126 /// The maximum supported address space number. 127 /// 24 bits should be enough for anyone. 128 MaxAddressSpace = 0xffffffu, 129 130 /// The width of the "fast" qualifier mask. 131 FastWidth = 2, 132 133 /// The fast qualifier mask. 134 FastMask = (1 << FastWidth) - 1 135 }; 136 137 Qualifiers() : Mask(0) {} 138 139 static Qualifiers fromFastMask(unsigned Mask) { 140 Qualifiers Qs; 141 Qs.addFastQualifiers(Mask); 142 return Qs; 143 } 144 145 static Qualifiers fromCVRMask(unsigned CVR) { 146 Qualifiers Qs; 147 Qs.addCVRQualifiers(CVR); 148 return Qs; 149 } 150 151 // Deserialize qualifiers from an opaque representation. 152 static Qualifiers fromOpaqueValue(unsigned opaque) { 153 Qualifiers Qs; 154 Qs.Mask = opaque; 155 return Qs; 156 } 157 158 // Serialize these qualifiers into an opaque representation. 159 unsigned getAsOpaqueValue() const { 160 return Mask; 161 } 162 163 bool hasConst() const { return Mask & Const; } 164 void setConst(bool flag) { 165 Mask = (Mask & ~Const) | (flag ? Const : 0); 166 } 167 void removeConst() { Mask &= ~Const; } 168 void addConst() { Mask |= Const; } 169 170 bool hasVolatile() const { return Mask & Volatile; } 171 void setVolatile(bool flag) { 172 Mask = (Mask & ~Volatile) | (flag ? Volatile : 0); 173 } 174 void removeVolatile() { Mask &= ~Volatile; } 175 void addVolatile() { Mask |= Volatile; } 176 177 bool hasRestrict() const { return Mask & Restrict; } 178 void setRestrict(bool flag) { 179 Mask = (Mask & ~Restrict) | (flag ? Restrict : 0); 180 } 181 void removeRestrict() { Mask &= ~Restrict; } 182 void addRestrict() { Mask |= Restrict; } 183 184 bool hasCVRQualifiers() const { return getCVRQualifiers(); } 185 unsigned getCVRQualifiers() const { return Mask & CVRMask; } 186 void setCVRQualifiers(unsigned mask) { 187 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 188 Mask = (Mask & ~CVRMask) | mask; 189 } 190 void removeCVRQualifiers(unsigned mask) { 191 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 192 Mask &= ~mask; 193 } 194 void removeCVRQualifiers() { 195 removeCVRQualifiers(CVRMask); 196 } 197 void addCVRQualifiers(unsigned mask) { 198 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); 199 Mask |= mask; 200 } 201 202 bool hasObjCGCAttr() const { return Mask & GCAttrMask; } 203 GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); } 204 void setObjCGCAttr(GC type) { 205 Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift); 206 } 207 void removeObjCGCAttr() { setObjCGCAttr(GCNone); } 208 void addObjCGCAttr(GC type) { 209 assert(type); 210 setObjCGCAttr(type); 211 } 212 213 bool hasAddressSpace() const { return Mask & AddressSpaceMask; } 214 unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; } 215 void setAddressSpace(unsigned space) { 216 assert(space <= MaxAddressSpace); 217 Mask = (Mask & ~AddressSpaceMask) 218 | (((uint32_t) space) << AddressSpaceShift); 219 } 220 void removeAddressSpace() { setAddressSpace(0); } 221 void addAddressSpace(unsigned space) { 222 assert(space); 223 setAddressSpace(space); 224 } 225 226 // Fast qualifiers are those that can be allocated directly 227 // on a QualType object. 228 bool hasFastQualifiers() const { return getFastQualifiers(); } 229 unsigned getFastQualifiers() const { return Mask & FastMask; } 230 void setFastQualifiers(unsigned mask) { 231 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 232 Mask = (Mask & ~FastMask) | mask; 233 } 234 void removeFastQualifiers(unsigned mask) { 235 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 236 Mask &= ~mask; 237 } 238 void removeFastQualifiers() { 239 removeFastQualifiers(FastMask); 240 } 241 void addFastQualifiers(unsigned mask) { 242 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); 243 Mask |= mask; 244 } 245 246 /// hasNonFastQualifiers - Return true if the set contains any 247 /// qualifiers which require an ExtQuals node to be allocated. 248 bool hasNonFastQualifiers() const { return Mask & ~FastMask; } 249 Qualifiers getNonFastQualifiers() const { 250 Qualifiers Quals = *this; 251 Quals.setFastQualifiers(0); 252 return Quals; 253 } 254 255 /// hasQualifiers - Return true if the set contains any qualifiers. 256 bool hasQualifiers() const { return Mask; } 257 bool empty() const { return !Mask; } 258 259 /// \brief Add the qualifiers from the given set to this set. 260 void addQualifiers(Qualifiers Q) { 261 // If the other set doesn't have any non-boolean qualifiers, just 262 // bit-or it in. 263 if (!(Q.Mask & ~CVRMask)) 264 Mask |= Q.Mask; 265 else { 266 Mask |= (Q.Mask & CVRMask); 267 if (Q.hasAddressSpace()) 268 addAddressSpace(Q.getAddressSpace()); 269 if (Q.hasObjCGCAttr()) 270 addObjCGCAttr(Q.getObjCGCAttr()); 271 } 272 } 273 274 bool isSupersetOf(Qualifiers Other) const; 275 276 bool operator==(Qualifiers Other) const { return Mask == Other.Mask; } 277 bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; } 278 279 operator bool() const { return hasQualifiers(); } 280 281 Qualifiers &operator+=(Qualifiers R) { 282 addQualifiers(R); 283 return *this; 284 } 285 286 // Union two qualifier sets. If an enumerated qualifier appears 287 // in both sets, use the one from the right. 288 friend Qualifiers operator+(Qualifiers L, Qualifiers R) { 289 L += R; 290 return L; 291 } 292 293 Qualifiers &operator-=(Qualifiers R) { 294 Mask = Mask & ~(R.Mask); 295 return *this; 296 } 297 298 /// \brief Compute the difference between two qualifier sets. 299 friend Qualifiers operator-(Qualifiers L, Qualifiers R) { 300 L -= R; 301 return L; 302 } 303 304 std::string getAsString() const; 305 std::string getAsString(const PrintingPolicy &Policy) const { 306 std::string Buffer; 307 getAsStringInternal(Buffer, Policy); 308 return Buffer; 309 } 310 void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const; 311 312 void Profile(llvm::FoldingSetNodeID &ID) const { 313 ID.AddInteger(Mask); 314 } 315 316private: 317 318 // bits: |0 1 2|3 .. 4|5 .. 31| 319 // |C R V|GCAttr|AddrSpace| 320 uint32_t Mask; 321 322 static const uint32_t GCAttrMask = 0x18; 323 static const uint32_t GCAttrShift = 3; 324 static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask); 325 static const uint32_t AddressSpaceShift = 5; 326}; 327 328 329/// ExtQuals - We can encode up to three bits in the low bits of a 330/// type pointer, but there are many more type qualifiers that we want 331/// to be able to apply to an arbitrary type. Therefore we have this 332/// struct, intended to be heap-allocated and used by QualType to 333/// store qualifiers. 334/// 335/// The current design tags the 'const' and 'restrict' qualifiers in 336/// two low bits on the QualType pointer; a third bit records whether 337/// the pointer is an ExtQuals node. 'const' was chosen because it is 338/// orders of magnitude more common than the other two qualifiers, in 339/// both library and user code. It's relatively rare to see 340/// 'restrict' in user code, but many standard C headers are saturated 341/// with 'restrict' declarations, so that representing them efficiently 342/// is a critical goal of this representation. 343class ExtQuals : public llvm::FoldingSetNode { 344 // NOTE: changing the fast qualifiers should be straightforward as 345 // long as you don't make 'const' non-fast. 346 // 1. Qualifiers: 347 // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ). 348 // Fast qualifiers must occupy the low-order bits. 349 // b) Update Qualifiers::FastWidth and FastMask. 350 // 2. QualType: 351 // a) Update is{Volatile,Restrict}Qualified(), defined inline. 352 // b) Update remove{Volatile,Restrict}, defined near the end of 353 // this header. 354 // 3. ASTContext: 355 // a) Update get{Volatile,Restrict}Type. 356 357 /// Context - the context to which this set belongs. We save this 358 /// here so that QualifierCollector can use it to reapply extended 359 /// qualifiers to an arbitrary type without requiring a context to 360 /// be pushed through every single API dealing with qualifiers. 361 ASTContext& Context; 362 363 /// BaseType - the underlying type that this qualifies 364 const Type *BaseType; 365 366 /// Quals - the immutable set of qualifiers applied by this 367 /// node; always contains extended qualifiers. 368 Qualifiers Quals; 369 370public: 371 ExtQuals(ASTContext& Context, const Type *Base, Qualifiers Quals) 372 : Context(Context), BaseType(Base), Quals(Quals) 373 { 374 assert(Quals.hasNonFastQualifiers() 375 && "ExtQuals created with no fast qualifiers"); 376 assert(!Quals.hasFastQualifiers() 377 && "ExtQuals created with fast qualifiers"); 378 } 379 380 Qualifiers getQualifiers() const { return Quals; } 381 382 bool hasVolatile() const { return Quals.hasVolatile(); } 383 384 bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); } 385 Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); } 386 387 bool hasAddressSpace() const { return Quals.hasAddressSpace(); } 388 unsigned getAddressSpace() const { return Quals.getAddressSpace(); } 389 390 const Type *getBaseType() const { return BaseType; } 391 392 ASTContext &getContext() const { return Context; } 393 394public: 395 void Profile(llvm::FoldingSetNodeID &ID) const { 396 Profile(ID, getBaseType(), Quals); 397 } 398 static void Profile(llvm::FoldingSetNodeID &ID, 399 const Type *BaseType, 400 Qualifiers Quals) { 401 assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!"); 402 ID.AddPointer(BaseType); 403 Quals.Profile(ID); 404 } 405}; 406 407/// CallingConv - Specifies the calling convention that a function uses. 408enum CallingConv { 409 CC_Default, 410 CC_C, // __attribute__((cdecl)) 411 CC_X86StdCall, // __attribute__((stdcall)) 412 CC_X86FastCall, // __attribute__((fastcall)) 413 CC_X86ThisCall // __attribute__((thiscall)) 414}; 415 416 417/// QualType - For efficiency, we don't store CV-qualified types as nodes on 418/// their own: instead each reference to a type stores the qualifiers. This 419/// greatly reduces the number of nodes we need to allocate for types (for 420/// example we only need one for 'int', 'const int', 'volatile int', 421/// 'const volatile int', etc). 422/// 423/// As an added efficiency bonus, instead of making this a pair, we 424/// just store the two bits we care about in the low bits of the 425/// pointer. To handle the packing/unpacking, we make QualType be a 426/// simple wrapper class that acts like a smart pointer. A third bit 427/// indicates whether there are extended qualifiers present, in which 428/// case the pointer points to a special structure. 429class QualType { 430 // Thankfully, these are efficiently composable. 431 llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>, 432 Qualifiers::FastWidth> Value; 433 434 const ExtQuals *getExtQualsUnsafe() const { 435 return Value.getPointer().get<const ExtQuals*>(); 436 } 437 438 const Type *getTypePtrUnsafe() const { 439 return Value.getPointer().get<const Type*>(); 440 } 441 442 QualType getUnqualifiedTypeSlow() const; 443 444 friend class QualifierCollector; 445public: 446 QualType() {} 447 448 QualType(const Type *Ptr, unsigned Quals) 449 : Value(Ptr, Quals) {} 450 QualType(const ExtQuals *Ptr, unsigned Quals) 451 : Value(Ptr, Quals) {} 452 453 unsigned getLocalFastQualifiers() const { return Value.getInt(); } 454 void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); } 455 456 /// Retrieves a pointer to the underlying (unqualified) type. 457 /// This should really return a const Type, but it's not worth 458 /// changing all the users right now. 459 Type *getTypePtr() const { 460 if (hasLocalNonFastQualifiers()) 461 return const_cast<Type*>(getExtQualsUnsafe()->getBaseType()); 462 return const_cast<Type*>(getTypePtrUnsafe()); 463 } 464 465 void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 466 static QualType getFromOpaquePtr(void *Ptr) { 467 QualType T; 468 T.Value.setFromOpaqueValue(Ptr); 469 return T; 470 } 471 472 Type &operator*() const { 473 return *getTypePtr(); 474 } 475 476 Type *operator->() const { 477 return getTypePtr(); 478 } 479 480 bool isCanonical() const; 481 bool isCanonicalAsParam() const; 482 483 /// isNull - Return true if this QualType doesn't point to a type yet. 484 bool isNull() const { 485 return Value.getPointer().isNull(); 486 } 487 488 /// \brief Determine whether this particular QualType instance has the 489 /// "const" qualifier set, without looking through typedefs that may have 490 /// added "const" at a different level. 491 bool isLocalConstQualified() const { 492 return (getLocalFastQualifiers() & Qualifiers::Const); 493 } 494 495 /// \brief Determine whether this type is const-qualified. 496 bool isConstQualified() const; 497 498 /// \brief Determine whether this particular QualType instance has the 499 /// "restrict" qualifier set, without looking through typedefs that may have 500 /// added "restrict" at a different level. 501 bool isLocalRestrictQualified() const { 502 return (getLocalFastQualifiers() & Qualifiers::Restrict); 503 } 504 505 /// \brief Determine whether this type is restrict-qualified. 506 bool isRestrictQualified() const; 507 508 /// \brief Determine whether this particular QualType instance has the 509 /// "volatile" qualifier set, without looking through typedefs that may have 510 /// added "volatile" at a different level. 511 bool isLocalVolatileQualified() const { 512 return (hasLocalNonFastQualifiers() && getExtQualsUnsafe()->hasVolatile()); 513 } 514 515 /// \brief Determine whether this type is volatile-qualified. 516 bool isVolatileQualified() const; 517 518 /// \brief Determine whether this particular QualType instance has any 519 /// qualifiers, without looking through any typedefs that might add 520 /// qualifiers at a different level. 521 bool hasLocalQualifiers() const { 522 return getLocalFastQualifiers() || hasLocalNonFastQualifiers(); 523 } 524 525 /// \brief Determine whether this type has any qualifiers. 526 bool hasQualifiers() const; 527 528 /// \brief Determine whether this particular QualType instance has any 529 /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType 530 /// instance. 531 bool hasLocalNonFastQualifiers() const { 532 return Value.getPointer().is<const ExtQuals*>(); 533 } 534 535 /// \brief Retrieve the set of qualifiers local to this particular QualType 536 /// instance, not including any qualifiers acquired through typedefs or 537 /// other sugar. 538 Qualifiers getLocalQualifiers() const { 539 Qualifiers Quals; 540 if (hasLocalNonFastQualifiers()) 541 Quals = getExtQualsUnsafe()->getQualifiers(); 542 Quals.addFastQualifiers(getLocalFastQualifiers()); 543 return Quals; 544 } 545 546 /// \brief Retrieve the set of qualifiers applied to this type. 547 Qualifiers getQualifiers() const; 548 549 /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 550 /// local to this particular QualType instance, not including any qualifiers 551 /// acquired through typedefs or other sugar. 552 unsigned getLocalCVRQualifiers() const { 553 unsigned CVR = getLocalFastQualifiers(); 554 if (isLocalVolatileQualified()) 555 CVR |= Qualifiers::Volatile; 556 return CVR; 557 } 558 559 /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 560 /// applied to this type. 561 unsigned getCVRQualifiers() const; 562 563 /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers 564 /// applied to this type, looking through any number of unqualified array 565 /// types to their element types' qualifiers. 566 unsigned getCVRQualifiersThroughArrayTypes() const; 567 568 bool isConstant(ASTContext& Ctx) const { 569 return QualType::isConstant(*this, Ctx); 570 } 571 572 // Don't promise in the API that anything besides 'const' can be 573 // easily added. 574 575 /// addConst - add the specified type qualifier to this QualType. 576 void addConst() { 577 addFastQualifiers(Qualifiers::Const); 578 } 579 QualType withConst() const { 580 return withFastQualifiers(Qualifiers::Const); 581 } 582 583 void addFastQualifiers(unsigned TQs) { 584 assert(!(TQs & ~Qualifiers::FastMask) 585 && "non-fast qualifier bits set in mask!"); 586 Value.setInt(Value.getInt() | TQs); 587 } 588 589 // FIXME: The remove* functions are semantically broken, because they might 590 // not remove a qualifier stored on a typedef. Most of the with* functions 591 // have the same problem. 592 void removeConst(); 593 void removeVolatile(); 594 void removeRestrict(); 595 void removeCVRQualifiers(unsigned Mask); 596 597 void removeFastQualifiers() { Value.setInt(0); } 598 void removeFastQualifiers(unsigned Mask) { 599 assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers"); 600 Value.setInt(Value.getInt() & ~Mask); 601 } 602 603 // Creates a type with the given qualifiers in addition to any 604 // qualifiers already on this type. 605 QualType withFastQualifiers(unsigned TQs) const { 606 QualType T = *this; 607 T.addFastQualifiers(TQs); 608 return T; 609 } 610 611 // Creates a type with exactly the given fast qualifiers, removing 612 // any existing fast qualifiers. 613 QualType withExactFastQualifiers(unsigned TQs) const { 614 return withoutFastQualifiers().withFastQualifiers(TQs); 615 } 616 617 // Removes fast qualifiers, but leaves any extended qualifiers in place. 618 QualType withoutFastQualifiers() const { 619 QualType T = *this; 620 T.removeFastQualifiers(); 621 return T; 622 } 623 624 /// \brief Return this type with all of the instance-specific qualifiers 625 /// removed, but without removing any qualifiers that may have been applied 626 /// through typedefs. 627 QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); } 628 629 /// \brief Return the unqualified form of the given type, which might be 630 /// desugared to eliminate qualifiers introduced via typedefs. 631 QualType getUnqualifiedType() const { 632 QualType T = getLocalUnqualifiedType(); 633 if (!T.hasQualifiers()) 634 return T; 635 636 return getUnqualifiedTypeSlow(); 637 } 638 639 bool isMoreQualifiedThan(QualType Other) const; 640 bool isAtLeastAsQualifiedAs(QualType Other) const; 641 QualType getNonReferenceType() const; 642 643 /// \brief Determine the type of a (typically non-lvalue) expression with the 644 /// specified result type. 645 /// 646 /// This routine should be used for expressions for which the return type is 647 /// explicitly specified (e.g., in a cast or call) and isn't necessarily 648 /// an lvalue. It removes a top-level reference (since there are no 649 /// expressions of reference type) and deletes top-level cvr-qualifiers 650 /// from non-class types (in C++) or all types (in C). 651 QualType getNonLValueExprType(ASTContext &Context) const; 652 653 /// getDesugaredType - Return the specified type with any "sugar" removed from 654 /// the type. This takes off typedefs, typeof's etc. If the outer level of 655 /// the type is already concrete, it returns it unmodified. This is similar 656 /// to getting the canonical type, but it doesn't remove *all* typedefs. For 657 /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 658 /// concrete. 659 /// 660 /// Qualifiers are left in place. 661 QualType getDesugaredType() const { 662 return QualType::getDesugaredType(*this); 663 } 664 665 /// operator==/!= - Indicate whether the specified types and qualifiers are 666 /// identical. 667 friend bool operator==(const QualType &LHS, const QualType &RHS) { 668 return LHS.Value == RHS.Value; 669 } 670 friend bool operator!=(const QualType &LHS, const QualType &RHS) { 671 return LHS.Value != RHS.Value; 672 } 673 std::string getAsString() const; 674 675 std::string getAsString(const PrintingPolicy &Policy) const { 676 std::string S; 677 getAsStringInternal(S, Policy); 678 return S; 679 } 680 void getAsStringInternal(std::string &Str, 681 const PrintingPolicy &Policy) const; 682 683 void dump(const char *s) const; 684 void dump() const; 685 686 void Profile(llvm::FoldingSetNodeID &ID) const { 687 ID.AddPointer(getAsOpaquePtr()); 688 } 689 690 /// getAddressSpace - Return the address space of this type. 691 inline unsigned getAddressSpace() const; 692 693 /// GCAttrTypesAttr - Returns gc attribute of this type. 694 inline Qualifiers::GC getObjCGCAttr() const; 695 696 /// isObjCGCWeak true when Type is objc's weak. 697 bool isObjCGCWeak() const { 698 return getObjCGCAttr() == Qualifiers::Weak; 699 } 700 701 /// isObjCGCStrong true when Type is objc's strong. 702 bool isObjCGCStrong() const { 703 return getObjCGCAttr() == Qualifiers::Strong; 704 } 705 706private: 707 // These methods are implemented in a separate translation unit; 708 // "static"-ize them to avoid creating temporary QualTypes in the 709 // caller. 710 static bool isConstant(QualType T, ASTContext& Ctx); 711 static QualType getDesugaredType(QualType T); 712}; 713 714} // end clang. 715 716namespace llvm { 717/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 718/// to a specific Type class. 719template<> struct simplify_type<const ::clang::QualType> { 720 typedef ::clang::Type* SimpleType; 721 static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 722 return Val.getTypePtr(); 723 } 724}; 725template<> struct simplify_type< ::clang::QualType> 726 : public simplify_type<const ::clang::QualType> {}; 727 728// Teach SmallPtrSet that QualType is "basically a pointer". 729template<> 730class PointerLikeTypeTraits<clang::QualType> { 731public: 732 static inline void *getAsVoidPointer(clang::QualType P) { 733 return P.getAsOpaquePtr(); 734 } 735 static inline clang::QualType getFromVoidPointer(void *P) { 736 return clang::QualType::getFromOpaquePtr(P); 737 } 738 // Various qualifiers go in low bits. 739 enum { NumLowBitsAvailable = 0 }; 740}; 741 742} // end namespace llvm 743 744namespace clang { 745 746/// Type - This is the base class of the type hierarchy. A central concept 747/// with types is that each type always has a canonical type. A canonical type 748/// is the type with any typedef names stripped out of it or the types it 749/// references. For example, consider: 750/// 751/// typedef int foo; 752/// typedef foo* bar; 753/// 'int *' 'foo *' 'bar' 754/// 755/// There will be a Type object created for 'int'. Since int is canonical, its 756/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 757/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 758/// there is a PointerType that represents 'int*', which, like 'int', is 759/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 760/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 761/// is also 'int*'. 762/// 763/// Non-canonical types are useful for emitting diagnostics, without losing 764/// information about typedefs being used. Canonical types are useful for type 765/// comparisons (they allow by-pointer equality tests) and useful for reasoning 766/// about whether something has a particular form (e.g. is a function type), 767/// because they implicitly, recursively, strip all typedefs out of a type. 768/// 769/// Types, once created, are immutable. 770/// 771class Type { 772public: 773 enum TypeClass { 774#define TYPE(Class, Base) Class, 775#define LAST_TYPE(Class) TypeLast = Class, 776#define ABSTRACT_TYPE(Class, Base) 777#include "clang/AST/TypeNodes.def" 778 TagFirst = Record, TagLast = Enum 779 }; 780 781private: 782 Type(const Type&); // DO NOT IMPLEMENT. 783 void operator=(const Type&); // DO NOT IMPLEMENT. 784 785 QualType CanonicalType; 786 787 /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 788 unsigned TC : 8; 789 790 /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 791 /// Note that this should stay at the end of the ivars for Type so that 792 /// subclasses can pack their bitfields into the same word. 793 bool Dependent : 1; 794 795 /// \brief Whether the linkage of this type is already known. 796 mutable bool LinkageKnown : 1; 797 798 /// \brief Linkage of this type. 799 mutable unsigned CachedLinkage : 2; 800 801 /// \brief FromAST - Whether this type comes from an AST file. 802 mutable bool FromAST : 1; 803 804 /// \brief Set whether this type comes from an AST file. 805 void setFromAST(bool V = true) const { 806 FromAST = V; 807 } 808 809protected: 810 /// \brief Compute the linkage of this type. 811 virtual Linkage getLinkageImpl() const; 812 813 enum { BitsRemainingInType = 19 }; 814 815 // silence VC++ warning C4355: 'this' : used in base member initializer list 816 Type *this_() { return this; } 817 Type(TypeClass tc, QualType Canonical, bool dependent) 818 : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 819 TC(tc), Dependent(dependent), LinkageKnown(false), 820 CachedLinkage(NoLinkage), FromAST(false) {} 821 virtual ~Type(); 822 friend class ASTContext; 823 824public: 825 TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 826 827 /// \brief Whether this type comes from an AST file. 828 bool isFromAST() const { return FromAST; } 829 830 bool isCanonicalUnqualified() const { 831 return CanonicalType.getTypePtr() == this; 832 } 833 834 /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 835 /// object types, function types, and incomplete types. 836 837 /// isIncompleteType - Return true if this is an incomplete type. 838 /// A type that can describe objects, but which lacks information needed to 839 /// determine its size (e.g. void, or a fwd declared struct). Clients of this 840 /// routine will need to determine if the size is actually required. 841 bool isIncompleteType() const; 842 843 /// isIncompleteOrObjectType - Return true if this is an incomplete or object 844 /// type, in other words, not a function type. 845 bool isIncompleteOrObjectType() const { 846 return !isFunctionType(); 847 } 848 849 /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 850 bool isPODType() const; 851 852 /// isLiteralType - Return true if this is a literal type 853 /// (C++0x [basic.types]p10) 854 bool isLiteralType() const; 855 856 /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 857 /// types that have a non-constant expression. This does not include "[]". 858 bool isVariablyModifiedType() const; 859 860 /// Helper methods to distinguish type categories. All type predicates 861 /// operate on the canonical type, ignoring typedefs and qualifiers. 862 863 /// isBuiltinType - returns true if the type is a builtin type. 864 bool isBuiltinType() const; 865 866 /// isSpecificBuiltinType - Test for a particular builtin type. 867 bool isSpecificBuiltinType(unsigned K) const; 868 869 /// isIntegerType() does *not* include complex integers (a GCC extension). 870 /// isComplexIntegerType() can be used to test for complex integers. 871 bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 872 bool isEnumeralType() const; 873 bool isBooleanType() const; 874 bool isCharType() const; 875 bool isWideCharType() const; 876 bool isAnyCharacterType() const; 877 bool isIntegralType(ASTContext &Ctx) const; 878 879 /// \brief Determine whether this type is an integral or enumeration type. 880 bool isIntegralOrEnumerationType() const; 881 882 /// Floating point categories. 883 bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 884 /// isComplexType() does *not* include complex integers (a GCC extension). 885 /// isComplexIntegerType() can be used to test for complex integers. 886 bool isComplexType() const; // C99 6.2.5p11 (complex) 887 bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 888 bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 889 bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 890 bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 891 bool isVoidType() const; // C99 6.2.5p19 892 bool isDerivedType() const; // C99 6.2.5p20 893 bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 894 bool isAggregateType() const; 895 896 // Type Predicates: Check to see if this type is structurally the specified 897 // type, ignoring typedefs and qualifiers. 898 bool isFunctionType() const; 899 bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } 900 bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } 901 bool isPointerType() const; 902 bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 903 bool isBlockPointerType() const; 904 bool isVoidPointerType() const; 905 bool isReferenceType() const; 906 bool isLValueReferenceType() const; 907 bool isRValueReferenceType() const; 908 bool isFunctionPointerType() const; 909 bool isMemberPointerType() const; 910 bool isMemberFunctionPointerType() const; 911 bool isMemberDataPointerType() const; 912 bool isArrayType() const; 913 bool isConstantArrayType() const; 914 bool isIncompleteArrayType() const; 915 bool isVariableArrayType() const; 916 bool isDependentSizedArrayType() const; 917 bool isRecordType() const; 918 bool isClassType() const; 919 bool isStructureType() const; 920 bool isStructureOrClassType() const; 921 bool isUnionType() const; 922 bool isComplexIntegerType() const; // GCC _Complex integer type. 923 bool isVectorType() const; // GCC vector type. 924 bool isExtVectorType() const; // Extended vector type. 925 bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 926 // FIXME: change this to 'raw' interface type, so we can used 'interface' type 927 // for the common case. 928 bool isObjCObjectType() const; // NSString or typeof(*(id)0) 929 bool isObjCQualifiedInterfaceType() const; // NSString<foo> 930 bool isObjCQualifiedIdType() const; // id<foo> 931 bool isObjCQualifiedClassType() const; // Class<foo> 932 bool isObjCObjectOrInterfaceType() const; 933 bool isObjCIdType() const; // id 934 bool isObjCClassType() const; // Class 935 bool isObjCSelType() const; // Class 936 bool isObjCBuiltinType() const; // 'id' or 'Class' 937 bool isTemplateTypeParmType() const; // C++ template type parameter 938 bool isNullPtrType() const; // C++0x nullptr_t 939 940 /// isDependentType - Whether this type is a dependent type, meaning 941 /// that its definition somehow depends on a template parameter 942 /// (C++ [temp.dep.type]). 943 bool isDependentType() const { return Dependent; } 944 bool isOverloadableType() const; 945 946 /// \brief Determine wither this type is a C++ elaborated-type-specifier. 947 bool isElaboratedTypeSpecifier() const; 948 949 /// hasPointerRepresentation - Whether this type is represented 950 /// natively as a pointer; this includes pointers, references, block 951 /// pointers, and Objective-C interface, qualified id, and qualified 952 /// interface types, as well as nullptr_t. 953 bool hasPointerRepresentation() const; 954 955 /// hasObjCPointerRepresentation - Whether this type can represent 956 /// an objective pointer type for the purpose of GC'ability 957 bool hasObjCPointerRepresentation() const; 958 959 /// \brief Determine whether this type has an integer representation 960 /// of some sort, e.g., it is an integer type or a vector. 961 bool hasIntegerRepresentation() const; 962 963 /// \brief Determine whether this type has an signed integer representation 964 /// of some sort, e.g., it is an signed integer type or a vector. 965 bool hasSignedIntegerRepresentation() const; 966 967 /// \brief Determine whether this type has an unsigned integer representation 968 /// of some sort, e.g., it is an unsigned integer type or a vector. 969 bool hasUnsignedIntegerRepresentation() const; 970 971 /// \brief Determine whether this type has a floating-point representation 972 /// of some sort, e.g., it is a floating-point type or a vector thereof. 973 bool hasFloatingRepresentation() const; 974 975 // Type Checking Functions: Check to see if this type is structurally the 976 // specified type, ignoring typedefs and qualifiers, and return a pointer to 977 // the best type we can. 978 const RecordType *getAsStructureType() const; 979 /// NOTE: getAs*ArrayType are methods on ASTContext. 980 const RecordType *getAsUnionType() const; 981 const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 982 // The following is a convenience method that returns an ObjCObjectPointerType 983 // for object declared using an interface. 984 const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 985 const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 986 const ObjCObjectType *getAsObjCQualifiedInterfaceType() const; 987 const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 988 989 /// \brief Retrieves the CXXRecordDecl that this type refers to, either 990 /// because the type is a RecordType or because it is the injected-class-name 991 /// type of a class template or class template partial specialization. 992 CXXRecordDecl *getAsCXXRecordDecl() const; 993 994 // Member-template getAs<specific type>'. Look through sugar for 995 // an instance of <specific type>. This scheme will eventually 996 // replace the specific getAsXXXX methods above. 997 // 998 // There are some specializations of this member template listed 999 // immediately following this class. 1000 template <typename T> const T *getAs() const; 1001 1002 /// getArrayElementTypeNoTypeQual - If this is an array type, return the 1003 /// element type of the array, potentially with type qualifiers missing. 1004 /// This method should never be used when type qualifiers are meaningful. 1005 const Type *getArrayElementTypeNoTypeQual() const; 1006 1007 /// getPointeeType - If this is a pointer, ObjC object pointer, or block 1008 /// pointer, this returns the respective pointee. 1009 QualType getPointeeType() const; 1010 1011 /// getUnqualifiedDesugaredType() - Return the specified type with 1012 /// any "sugar" removed from the type, removing any typedefs, 1013 /// typeofs, etc., as well as any qualifiers. 1014 const Type *getUnqualifiedDesugaredType() const; 1015 1016 /// More type predicates useful for type checking/promotion 1017 bool isPromotableIntegerType() const; // C99 6.3.1.1p2 1018 1019 /// isSignedIntegerType - Return true if this is an integer type that is 1020 /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 1021 /// an enum decl which has a signed representation, or a vector of signed 1022 /// integer element type. 1023 bool isSignedIntegerType() const; 1024 1025 /// isUnsignedIntegerType - Return true if this is an integer type that is 1026 /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 1027 /// decl which has an unsigned representation, or a vector of unsigned integer 1028 /// element type. 1029 bool isUnsignedIntegerType() const; 1030 1031 /// isConstantSizeType - Return true if this is not a variable sized type, 1032 /// according to the rules of C99 6.7.5p3. It is not legal to call this on 1033 /// incomplete types. 1034 bool isConstantSizeType() const; 1035 1036 /// isSpecifierType - Returns true if this type can be represented by some 1037 /// set of type specifiers. 1038 bool isSpecifierType() const; 1039 1040 /// \brief Determine the linkage of this type. 1041 Linkage getLinkage() const; 1042 1043 /// \brief Note that the linkage is no longer known. 1044 void ClearLinkageCache(); 1045 1046 const char *getTypeClassName() const; 1047 1048 QualType getCanonicalTypeInternal() const { 1049 return CanonicalType; 1050 } 1051 CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h 1052 void dump() const; 1053 static bool classof(const Type *) { return true; } 1054 1055 friend class ASTReader; 1056 friend class ASTWriter; 1057}; 1058 1059template <> inline const TypedefType *Type::getAs() const { 1060 return dyn_cast<TypedefType>(this); 1061} 1062 1063// We can do canonical leaf types faster, because we don't have to 1064// worry about preserving child type decoration. 1065#define TYPE(Class, Base) 1066#define LEAF_TYPE(Class) \ 1067template <> inline const Class##Type *Type::getAs() const { \ 1068 return dyn_cast<Class##Type>(CanonicalType); \ 1069} 1070#include "clang/AST/TypeNodes.def" 1071 1072 1073/// BuiltinType - This class is used for builtin types like 'int'. Builtin 1074/// types are always canonical and have a literal name field. 1075class BuiltinType : public Type { 1076public: 1077 enum Kind { 1078 Void, 1079 1080 Bool, // This is bool and/or _Bool. 1081 Char_U, // This is 'char' for targets where char is unsigned. 1082 UChar, // This is explicitly qualified unsigned char. 1083 Char16, // This is 'char16_t' for C++. 1084 Char32, // This is 'char32_t' for C++. 1085 UShort, 1086 UInt, 1087 ULong, 1088 ULongLong, 1089 UInt128, // __uint128_t 1090 1091 Char_S, // This is 'char' for targets where char is signed. 1092 SChar, // This is explicitly qualified signed char. 1093 WChar, // This is 'wchar_t' for C++. 1094 Short, 1095 Int, 1096 Long, 1097 LongLong, 1098 Int128, // __int128_t 1099 1100 Float, Double, LongDouble, 1101 1102 NullPtr, // This is the type of C++0x 'nullptr'. 1103 1104 Overload, // This represents the type of an overloaded function declaration. 1105 Dependent, // This represents the type of a type-dependent expression. 1106 1107 UndeducedAuto, // In C++0x, this represents the type of an auto variable 1108 // that has not been deduced yet. 1109 1110 /// The primitive Objective C 'id' type. The type pointed to by the 1111 /// user-visible 'id' type. Only ever shows up in an AST as the base 1112 /// type of an ObjCObjectType. 1113 ObjCId, 1114 1115 /// The primitive Objective C 'Class' type. The type pointed to by the 1116 /// user-visible 'Class' type. Only ever shows up in an AST as the 1117 /// base type of an ObjCObjectType. 1118 ObjCClass, 1119 1120 ObjCSel // This represents the ObjC 'SEL' type. 1121 }; 1122private: 1123 Kind TypeKind; 1124 1125protected: 1126 virtual Linkage getLinkageImpl() const; 1127 1128public: 1129 BuiltinType(Kind K) 1130 : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 1131 TypeKind(K) {} 1132 1133 Kind getKind() const { return TypeKind; } 1134 const char *getName(const LangOptions &LO) const; 1135 1136 bool isSugared() const { return false; } 1137 QualType desugar() const { return QualType(this, 0); } 1138 1139 bool isInteger() const { 1140 return TypeKind >= Bool && TypeKind <= Int128; 1141 } 1142 1143 bool isSignedInteger() const { 1144 return TypeKind >= Char_S && TypeKind <= Int128; 1145 } 1146 1147 bool isUnsignedInteger() const { 1148 return TypeKind >= Bool && TypeKind <= UInt128; 1149 } 1150 1151 bool isFloatingPoint() const { 1152 return TypeKind >= Float && TypeKind <= LongDouble; 1153 } 1154 1155 static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 1156 static bool classof(const BuiltinType *) { return true; } 1157}; 1158 1159/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 1160/// types (_Complex float etc) as well as the GCC integer complex extensions. 1161/// 1162class ComplexType : public Type, public llvm::FoldingSetNode { 1163 QualType ElementType; 1164 ComplexType(QualType Element, QualType CanonicalPtr) : 1165 Type(Complex, CanonicalPtr, Element->isDependentType()), 1166 ElementType(Element) { 1167 } 1168 friend class ASTContext; // ASTContext creates these. 1169 1170protected: 1171 virtual Linkage getLinkageImpl() const; 1172 1173public: 1174 QualType getElementType() const { return ElementType; } 1175 1176 bool isSugared() const { return false; } 1177 QualType desugar() const { return QualType(this, 0); } 1178 1179 void Profile(llvm::FoldingSetNodeID &ID) { 1180 Profile(ID, getElementType()); 1181 } 1182 static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 1183 ID.AddPointer(Element.getAsOpaquePtr()); 1184 } 1185 1186 static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 1187 static bool classof(const ComplexType *) { return true; } 1188}; 1189 1190/// PointerType - C99 6.7.5.1 - Pointer Declarators. 1191/// 1192class PointerType : public Type, public llvm::FoldingSetNode { 1193 QualType PointeeType; 1194 1195 PointerType(QualType Pointee, QualType CanonicalPtr) : 1196 Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 1197 } 1198 friend class ASTContext; // ASTContext creates these. 1199 1200protected: 1201 virtual Linkage getLinkageImpl() const; 1202 1203public: 1204 1205 QualType getPointeeType() const { return PointeeType; } 1206 1207 bool isSugared() const { return false; } 1208 QualType desugar() const { return QualType(this, 0); } 1209 1210 void Profile(llvm::FoldingSetNodeID &ID) { 1211 Profile(ID, getPointeeType()); 1212 } 1213 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 1214 ID.AddPointer(Pointee.getAsOpaquePtr()); 1215 } 1216 1217 static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 1218 static bool classof(const PointerType *) { return true; } 1219}; 1220 1221/// BlockPointerType - pointer to a block type. 1222/// This type is to represent types syntactically represented as 1223/// "void (^)(int)", etc. Pointee is required to always be a function type. 1224/// 1225class BlockPointerType : public Type, public llvm::FoldingSetNode { 1226 QualType PointeeType; // Block is some kind of pointer type 1227 BlockPointerType(QualType Pointee, QualType CanonicalCls) : 1228 Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 1229 PointeeType(Pointee) { 1230 } 1231 friend class ASTContext; // ASTContext creates these. 1232 1233protected: 1234 virtual Linkage getLinkageImpl() const; 1235 1236public: 1237 1238 // Get the pointee type. Pointee is required to always be a function type. 1239 QualType getPointeeType() const { return PointeeType; } 1240 1241 bool isSugared() const { return false; } 1242 QualType desugar() const { return QualType(this, 0); } 1243 1244 void Profile(llvm::FoldingSetNodeID &ID) { 1245 Profile(ID, getPointeeType()); 1246 } 1247 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 1248 ID.AddPointer(Pointee.getAsOpaquePtr()); 1249 } 1250 1251 static bool classof(const Type *T) { 1252 return T->getTypeClass() == BlockPointer; 1253 } 1254 static bool classof(const BlockPointerType *) { return true; } 1255}; 1256 1257/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 1258/// 1259class ReferenceType : public Type, public llvm::FoldingSetNode { 1260 QualType PointeeType; 1261 1262 /// True if the type was originally spelled with an lvalue sigil. 1263 /// This is never true of rvalue references but can also be false 1264 /// on lvalue references because of C++0x [dcl.typedef]p9, 1265 /// as follows: 1266 /// 1267 /// typedef int &ref; // lvalue, spelled lvalue 1268 /// typedef int &&rvref; // rvalue 1269 /// ref &a; // lvalue, inner ref, spelled lvalue 1270 /// ref &&a; // lvalue, inner ref 1271 /// rvref &a; // lvalue, inner ref, spelled lvalue 1272 /// rvref &&a; // rvalue, inner ref 1273 bool SpelledAsLValue; 1274 1275 /// True if the inner type is a reference type. This only happens 1276 /// in non-canonical forms. 1277 bool InnerRef; 1278 1279protected: 1280 ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, 1281 bool SpelledAsLValue) : 1282 Type(tc, CanonicalRef, Referencee->isDependentType()), 1283 PointeeType(Referencee), SpelledAsLValue(SpelledAsLValue), 1284 InnerRef(Referencee->isReferenceType()) { 1285 } 1286 1287 virtual Linkage getLinkageImpl() const; 1288 1289public: 1290 bool isSpelledAsLValue() const { return SpelledAsLValue; } 1291 bool isInnerRef() const { return InnerRef; } 1292 1293 QualType getPointeeTypeAsWritten() const { return PointeeType; } 1294 QualType getPointeeType() const { 1295 // FIXME: this might strip inner qualifiers; okay? 1296 const ReferenceType *T = this; 1297 while (T->InnerRef) 1298 T = T->PointeeType->getAs<ReferenceType>(); 1299 return T->PointeeType; 1300 } 1301 1302 void Profile(llvm::FoldingSetNodeID &ID) { 1303 Profile(ID, PointeeType, SpelledAsLValue); 1304 } 1305 static void Profile(llvm::FoldingSetNodeID &ID, 1306 QualType Referencee, 1307 bool SpelledAsLValue) { 1308 ID.AddPointer(Referencee.getAsOpaquePtr()); 1309 ID.AddBoolean(SpelledAsLValue); 1310 } 1311 1312 static bool classof(const Type *T) { 1313 return T->getTypeClass() == LValueReference || 1314 T->getTypeClass() == RValueReference; 1315 } 1316 static bool classof(const ReferenceType *) { return true; } 1317}; 1318 1319/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 1320/// 1321class LValueReferenceType : public ReferenceType { 1322 LValueReferenceType(QualType Referencee, QualType CanonicalRef, 1323 bool SpelledAsLValue) : 1324 ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue) 1325 {} 1326 friend class ASTContext; // ASTContext creates these 1327public: 1328 bool isSugared() const { return false; } 1329 QualType desugar() const { return QualType(this, 0); } 1330 1331 static bool classof(const Type *T) { 1332 return T->getTypeClass() == LValueReference; 1333 } 1334 static bool classof(const LValueReferenceType *) { return true; } 1335}; 1336 1337/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 1338/// 1339class RValueReferenceType : public ReferenceType { 1340 RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 1341 ReferenceType(RValueReference, Referencee, CanonicalRef, false) { 1342 } 1343 friend class ASTContext; // ASTContext creates these 1344public: 1345 bool isSugared() const { return false; } 1346 QualType desugar() const { return QualType(this, 0); } 1347 1348 static bool classof(const Type *T) { 1349 return T->getTypeClass() == RValueReference; 1350 } 1351 static bool classof(const RValueReferenceType *) { return true; } 1352}; 1353 1354/// MemberPointerType - C++ 8.3.3 - Pointers to members 1355/// 1356class MemberPointerType : public Type, public llvm::FoldingSetNode { 1357 QualType PointeeType; 1358 /// The class of which the pointee is a member. Must ultimately be a 1359 /// RecordType, but could be a typedef or a template parameter too. 1360 const Type *Class; 1361 1362 MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 1363 Type(MemberPointer, CanonicalPtr, 1364 Cls->isDependentType() || Pointee->isDependentType()), 1365 PointeeType(Pointee), Class(Cls) { 1366 } 1367 friend class ASTContext; // ASTContext creates these. 1368 1369protected: 1370 virtual Linkage getLinkageImpl() const; 1371 1372public: 1373 QualType getPointeeType() const { return PointeeType; } 1374 1375 /// Returns true if the member type (i.e. the pointee type) is a 1376 /// function type rather than a data-member type. 1377 bool isMemberFunctionPointer() const { 1378 return PointeeType->isFunctionProtoType(); 1379 } 1380 1381 /// Returns true if the member type (i.e. the pointee type) is a 1382 /// data type rather than a function type. 1383 bool isMemberDataPointer() const { 1384 return !PointeeType->isFunctionProtoType(); 1385 } 1386 1387 const Type *getClass() const { return Class; } 1388 1389 bool isSugared() const { return false; } 1390 QualType desugar() const { return QualType(this, 0); } 1391 1392 void Profile(llvm::FoldingSetNodeID &ID) { 1393 Profile(ID, getPointeeType(), getClass()); 1394 } 1395 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 1396 const Type *Class) { 1397 ID.AddPointer(Pointee.getAsOpaquePtr()); 1398 ID.AddPointer(Class); 1399 } 1400 1401 static bool classof(const Type *T) { 1402 return T->getTypeClass() == MemberPointer; 1403 } 1404 static bool classof(const MemberPointerType *) { return true; } 1405}; 1406 1407/// ArrayType - C99 6.7.5.2 - Array Declarators. 1408/// 1409class ArrayType : public Type, public llvm::FoldingSetNode { 1410public: 1411 /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 1412 /// an array with a static size (e.g. int X[static 4]), or an array 1413 /// with a star size (e.g. int X[*]). 1414 /// 'static' is only allowed on function parameters. 1415 enum ArraySizeModifier { 1416 Normal, Static, Star 1417 }; 1418private: 1419 /// ElementType - The element type of the array. 1420 QualType ElementType; 1421 1422 // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 1423 /// NOTE: These fields are packed into the bitfields space in the Type class. 1424 unsigned SizeModifier : 2; 1425 1426 /// IndexTypeQuals - Capture qualifiers in declarations like: 1427 /// 'int X[static restrict 4]'. For function parameters only. 1428 unsigned IndexTypeQuals : 3; 1429 1430protected: 1431 // C++ [temp.dep.type]p1: 1432 // A type is dependent if it is... 1433 // - an array type constructed from any dependent type or whose 1434 // size is specified by a constant expression that is 1435 // value-dependent, 1436 ArrayType(TypeClass tc, QualType et, QualType can, 1437 ArraySizeModifier sm, unsigned tq) 1438 : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 1439 ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 1440 1441 friend class ASTContext; // ASTContext creates these. 1442 1443 virtual Linkage getLinkageImpl() const; 1444 1445public: 1446 QualType getElementType() const { return ElementType; } 1447 ArraySizeModifier getSizeModifier() const { 1448 return ArraySizeModifier(SizeModifier); 1449 } 1450 Qualifiers getIndexTypeQualifiers() const { 1451 return Qualifiers::fromCVRMask(IndexTypeQuals); 1452 } 1453 unsigned getIndexTypeCVRQualifiers() const { return IndexTypeQuals; } 1454 1455 static bool classof(const Type *T) { 1456 return T->getTypeClass() == ConstantArray || 1457 T->getTypeClass() == VariableArray || 1458 T->getTypeClass() == IncompleteArray || 1459 T->getTypeClass() == DependentSizedArray; 1460 } 1461 static bool classof(const ArrayType *) { return true; } 1462}; 1463 1464/// ConstantArrayType - This class represents the canonical version of 1465/// C arrays with a specified constant size. For example, the canonical 1466/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 1467/// type is 'int' and the size is 404. 1468class ConstantArrayType : public ArrayType { 1469 llvm::APInt Size; // Allows us to unique the type. 1470 1471 ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 1472 ArraySizeModifier sm, unsigned tq) 1473 : ArrayType(ConstantArray, et, can, sm, tq), 1474 Size(size) {} 1475protected: 1476 ConstantArrayType(TypeClass tc, QualType et, QualType can, 1477 const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 1478 : ArrayType(tc, et, can, sm, tq), Size(size) {} 1479 friend class ASTContext; // ASTContext creates these. 1480public: 1481 const llvm::APInt &getSize() const { return Size; } 1482 bool isSugared() const { return false; } 1483 QualType desugar() const { return QualType(this, 0); } 1484 1485 1486 /// \brief Determine the number of bits required to address a member of 1487 // an array with the given element type and number of elements. 1488 static unsigned getNumAddressingBits(ASTContext &Context, 1489 QualType ElementType, 1490 const llvm::APInt &NumElements); 1491 1492 /// \brief Determine the maximum number of active bits that an array's size 1493 /// can require, which limits the maximum size of the array. 1494 static unsigned getMaxSizeBits(ASTContext &Context); 1495 1496 void Profile(llvm::FoldingSetNodeID &ID) { 1497 Profile(ID, getElementType(), getSize(), 1498 getSizeModifier(), getIndexTypeCVRQualifiers()); 1499 } 1500 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 1501 const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 1502 unsigned TypeQuals) { 1503 ID.AddPointer(ET.getAsOpaquePtr()); 1504 ID.AddInteger(ArraySize.getZExtValue()); 1505 ID.AddInteger(SizeMod); 1506 ID.AddInteger(TypeQuals); 1507 } 1508 static bool classof(const Type *T) { 1509 return T->getTypeClass() == ConstantArray; 1510 } 1511 static bool classof(const ConstantArrayType *) { return true; } 1512}; 1513 1514/// IncompleteArrayType - This class represents C arrays with an unspecified 1515/// size. For example 'int A[]' has an IncompleteArrayType where the element 1516/// type is 'int' and the size is unspecified. 1517class IncompleteArrayType : public ArrayType { 1518 1519 IncompleteArrayType(QualType et, QualType can, 1520 ArraySizeModifier sm, unsigned tq) 1521 : ArrayType(IncompleteArray, et, can, sm, tq) {} 1522 friend class ASTContext; // ASTContext creates these. 1523public: 1524 bool isSugared() const { return false; } 1525 QualType desugar() const { return QualType(this, 0); } 1526 1527 static bool classof(const Type *T) { 1528 return T->getTypeClass() == IncompleteArray; 1529 } 1530 static bool classof(const IncompleteArrayType *) { return true; } 1531 1532 friend class StmtIteratorBase; 1533 1534 void Profile(llvm::FoldingSetNodeID &ID) { 1535 Profile(ID, getElementType(), getSizeModifier(), 1536 getIndexTypeCVRQualifiers()); 1537 } 1538 1539 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 1540 ArraySizeModifier SizeMod, unsigned TypeQuals) { 1541 ID.AddPointer(ET.getAsOpaquePtr()); 1542 ID.AddInteger(SizeMod); 1543 ID.AddInteger(TypeQuals); 1544 } 1545}; 1546 1547/// VariableArrayType - This class represents C arrays with a specified size 1548/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 1549/// Since the size expression is an arbitrary expression, we store it as such. 1550/// 1551/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 1552/// should not be: two lexically equivalent variable array types could mean 1553/// different things, for example, these variables do not have the same type 1554/// dynamically: 1555/// 1556/// void foo(int x) { 1557/// int Y[x]; 1558/// ++x; 1559/// int Z[x]; 1560/// } 1561/// 1562class VariableArrayType : public ArrayType { 1563 /// SizeExpr - An assignment expression. VLA's are only permitted within 1564 /// a function block. 1565 Stmt *SizeExpr; 1566 /// Brackets - The left and right array brackets. 1567 SourceRange Brackets; 1568 1569 VariableArrayType(QualType et, QualType can, Expr *e, 1570 ArraySizeModifier sm, unsigned tq, 1571 SourceRange brackets) 1572 : ArrayType(VariableArray, et, can, sm, tq), 1573 SizeExpr((Stmt*) e), Brackets(brackets) {} 1574 friend class ASTContext; // ASTContext creates these. 1575 1576public: 1577 Expr *getSizeExpr() const { 1578 // We use C-style casts instead of cast<> here because we do not wish 1579 // to have a dependency of Type.h on Stmt.h/Expr.h. 1580 return (Expr*) SizeExpr; 1581 } 1582 SourceRange getBracketsRange() const { return Brackets; } 1583 SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 1584 SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 1585 1586 bool isSugared() const { return false; } 1587 QualType desugar() const { return QualType(this, 0); } 1588 1589 static bool classof(const Type *T) { 1590 return T->getTypeClass() == VariableArray; 1591 } 1592 static bool classof(const VariableArrayType *) { return true; } 1593 1594 friend class StmtIteratorBase; 1595 1596 void Profile(llvm::FoldingSetNodeID &ID) { 1597 assert(0 && "Cannnot unique VariableArrayTypes."); 1598 } 1599}; 1600 1601/// DependentSizedArrayType - This type represents an array type in 1602/// C++ whose size is a value-dependent expression. For example: 1603/// 1604/// \code 1605/// template<typename T, int Size> 1606/// class array { 1607/// T data[Size]; 1608/// }; 1609/// \endcode 1610/// 1611/// For these types, we won't actually know what the array bound is 1612/// until template instantiation occurs, at which point this will 1613/// become either a ConstantArrayType or a VariableArrayType. 1614class DependentSizedArrayType : public ArrayType { 1615 ASTContext &Context; 1616 1617 /// \brief An assignment expression that will instantiate to the 1618 /// size of the array. 1619 /// 1620 /// The expression itself might be NULL, in which case the array 1621 /// type will have its size deduced from an initializer. 1622 Stmt *SizeExpr; 1623 1624 /// Brackets - The left and right array brackets. 1625 SourceRange Brackets; 1626 1627 DependentSizedArrayType(ASTContext &Context, QualType et, QualType can, 1628 Expr *e, ArraySizeModifier sm, unsigned tq, 1629 SourceRange brackets) 1630 : ArrayType(DependentSizedArray, et, can, sm, tq), 1631 Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {} 1632 friend class ASTContext; // ASTContext creates these. 1633 1634public: 1635 Expr *getSizeExpr() const { 1636 // We use C-style casts instead of cast<> here because we do not wish 1637 // to have a dependency of Type.h on Stmt.h/Expr.h. 1638 return (Expr*) SizeExpr; 1639 } 1640 SourceRange getBracketsRange() const { return Brackets; } 1641 SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 1642 SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 1643 1644 bool isSugared() const { return false; } 1645 QualType desugar() const { return QualType(this, 0); } 1646 1647 static bool classof(const Type *T) { 1648 return T->getTypeClass() == DependentSizedArray; 1649 } 1650 static bool classof(const DependentSizedArrayType *) { return true; } 1651 1652 friend class StmtIteratorBase; 1653 1654 1655 void Profile(llvm::FoldingSetNodeID &ID) { 1656 Profile(ID, Context, getElementType(), 1657 getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); 1658 } 1659 1660 static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 1661 QualType ET, ArraySizeModifier SizeMod, 1662 unsigned TypeQuals, Expr *E); 1663}; 1664 1665/// DependentSizedExtVectorType - This type represent an extended vector type 1666/// where either the type or size is dependent. For example: 1667/// @code 1668/// template<typename T, int Size> 1669/// class vector { 1670/// typedef T __attribute__((ext_vector_type(Size))) type; 1671/// } 1672/// @endcode 1673class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { 1674 ASTContext &Context; 1675 Expr *SizeExpr; 1676 /// ElementType - The element type of the array. 1677 QualType ElementType; 1678 SourceLocation loc; 1679 1680 DependentSizedExtVectorType(ASTContext &Context, QualType ElementType, 1681 QualType can, Expr *SizeExpr, SourceLocation loc) 1682 : Type (DependentSizedExtVector, can, true), 1683 Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 1684 loc(loc) {} 1685 friend class ASTContext; 1686 1687public: 1688 Expr *getSizeExpr() const { return SizeExpr; } 1689 QualType getElementType() const { return ElementType; } 1690 SourceLocation getAttributeLoc() const { return loc; } 1691 1692 bool isSugared() const { return false; } 1693 QualType desugar() const { return QualType(this, 0); } 1694 1695 static bool classof(const Type *T) { 1696 return T->getTypeClass() == DependentSizedExtVector; 1697 } 1698 static bool classof(const DependentSizedExtVectorType *) { return true; } 1699 1700 void Profile(llvm::FoldingSetNodeID &ID) { 1701 Profile(ID, Context, getElementType(), getSizeExpr()); 1702 } 1703 1704 static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 1705 QualType ElementType, Expr *SizeExpr); 1706}; 1707 1708 1709/// VectorType - GCC generic vector type. This type is created using 1710/// __attribute__((vector_size(n)), where "n" specifies the vector size in 1711/// bytes; or from an Altivec __vector or vector declaration. 1712/// Since the constructor takes the number of vector elements, the 1713/// client is responsible for converting the size into the number of elements. 1714class VectorType : public Type, public llvm::FoldingSetNode { 1715public: 1716 enum AltiVecSpecific { 1717 NotAltiVec, // is not AltiVec vector 1718 AltiVec, // is AltiVec vector 1719 Pixel, // is AltiVec 'vector Pixel' 1720 Bool // is AltiVec 'vector bool ...' 1721 }; 1722protected: 1723 /// ElementType - The element type of the vector. 1724 QualType ElementType; 1725 1726 /// NumElements - The number of elements in the vector. 1727 unsigned NumElements; 1728 1729 AltiVecSpecific AltiVecSpec; 1730 1731 VectorType(QualType vecType, unsigned nElements, QualType canonType, 1732 AltiVecSpecific altiVecSpec) : 1733 Type(Vector, canonType, vecType->isDependentType()), 1734 ElementType(vecType), NumElements(nElements), AltiVecSpec(altiVecSpec) {} 1735 VectorType(TypeClass tc, QualType vecType, unsigned nElements, 1736 QualType canonType, AltiVecSpecific altiVecSpec) 1737 : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 1738 NumElements(nElements), AltiVecSpec(altiVecSpec) {} 1739 friend class ASTContext; // ASTContext creates these. 1740 1741 virtual Linkage getLinkageImpl() const; 1742 1743public: 1744 1745 QualType getElementType() const { return ElementType; } 1746 unsigned getNumElements() const { return NumElements; } 1747 1748 bool isSugared() const { return false; } 1749 QualType desugar() const { return QualType(this, 0); } 1750 1751 AltiVecSpecific getAltiVecSpecific() const { return AltiVecSpec; } 1752 1753 void Profile(llvm::FoldingSetNodeID &ID) { 1754 Profile(ID, getElementType(), getNumElements(), getTypeClass(), AltiVecSpec); 1755 } 1756 static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 1757 unsigned NumElements, TypeClass TypeClass, 1758 unsigned AltiVecSpec) { 1759 ID.AddPointer(ElementType.getAsOpaquePtr()); 1760 ID.AddInteger(NumElements); 1761 ID.AddInteger(TypeClass); 1762 ID.AddInteger(AltiVecSpec); 1763 } 1764 1765 static bool classof(const Type *T) { 1766 return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 1767 } 1768 static bool classof(const VectorType *) { return true; } 1769}; 1770 1771/// ExtVectorType - Extended vector type. This type is created using 1772/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1773/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1774/// class enables syntactic extensions, like Vector Components for accessing 1775/// points, colors, and textures (modeled after OpenGL Shading Language). 1776class ExtVectorType : public VectorType { 1777 ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1778 VectorType(ExtVector, vecType, nElements, canonType, NotAltiVec) {} 1779 friend class ASTContext; // ASTContext creates these. 1780public: 1781 static int getPointAccessorIdx(char c) { 1782 switch (c) { 1783 default: return -1; 1784 case 'x': case 'r': return 0; 1785 case 'y': case 'g': return 1; 1786 case 'z': case 'b': return 2; 1787 case 'w': case 'a': return 3; 1788 } 1789 } 1790 static int getNumericAccessorIdx(char c) { 1791 switch (c) { 1792 default: return -1; 1793 case '0': return 0; 1794 case '1': return 1; 1795 case '2': return 2; 1796 case '3': return 3; 1797 case '4': return 4; 1798 case '5': return 5; 1799 case '6': return 6; 1800 case '7': return 7; 1801 case '8': return 8; 1802 case '9': return 9; 1803 case 'A': 1804 case 'a': return 10; 1805 case 'B': 1806 case 'b': return 11; 1807 case 'C': 1808 case 'c': return 12; 1809 case 'D': 1810 case 'd': return 13; 1811 case 'E': 1812 case 'e': return 14; 1813 case 'F': 1814 case 'f': return 15; 1815 } 1816 } 1817 1818 static int getAccessorIdx(char c) { 1819 if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1820 return getNumericAccessorIdx(c); 1821 } 1822 1823 bool isAccessorWithinNumElements(char c) const { 1824 if (int idx = getAccessorIdx(c)+1) 1825 return unsigned(idx-1) < NumElements; 1826 return false; 1827 } 1828 bool isSugared() const { return false; } 1829 QualType desugar() const { return QualType(this, 0); } 1830 1831 static bool classof(const Type *T) { 1832 return T->getTypeClass() == ExtVector; 1833 } 1834 static bool classof(const ExtVectorType *) { return true; } 1835}; 1836 1837/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 1838/// class of FunctionNoProtoType and FunctionProtoType. 1839/// 1840class FunctionType : public Type { 1841 virtual void ANCHOR(); // Key function for FunctionType. 1842 1843 /// SubClassData - This field is owned by the subclass, put here to pack 1844 /// tightly with the ivars in Type. 1845 bool SubClassData : 1; 1846 1847 /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1848 /// other bitfields. 1849 /// The qualifiers are part of FunctionProtoType because... 1850 /// 1851 /// C++ 8.3.5p4: The return type, the parameter type list and the 1852 /// cv-qualifier-seq, [...], are part of the function type. 1853 /// 1854 unsigned TypeQuals : 3; 1855 1856 /// NoReturn - Indicates if the function type is attribute noreturn. 1857 unsigned NoReturn : 1; 1858 1859 /// RegParm - How many arguments to pass inreg. 1860 unsigned RegParm : 3; 1861 1862 /// CallConv - The calling convention used by the function. 1863 unsigned CallConv : 3; 1864 1865 // The type returned by the function. 1866 QualType ResultType; 1867 1868 public: 1869 // This class is used for passing arround the information needed to 1870 // construct a call. It is not actually used for storage, just for 1871 // factoring together common arguments. 1872 // If you add a field (say Foo), other than the obvious places (both, constructors, 1873 // compile failures), what you need to update is 1874 // * Operetor== 1875 // * getFoo 1876 // * withFoo 1877 // * functionType. Add Foo, getFoo. 1878 // * ASTContext::getFooType 1879 // * ASTContext::mergeFunctionTypes 1880 // * FunctionNoProtoType::Profile 1881 // * FunctionProtoType::Profile 1882 // * TypePrinter::PrintFunctionProto 1883 // * AST read and write 1884 // * Codegen 1885 1886 class ExtInfo { 1887 public: 1888 // Constructor with no defaults. Use this when you know that you 1889 // have all the elements (when reading an AST file for example). 1890 ExtInfo(bool noReturn, unsigned regParm, CallingConv cc) : 1891 NoReturn(noReturn), RegParm(regParm), CC(cc) {} 1892 1893 // Constructor with all defaults. Use when for example creating a 1894 // function know to use defaults. 1895 ExtInfo() : NoReturn(false), RegParm(0), CC(CC_Default) {} 1896 1897 bool getNoReturn() const { return NoReturn; } 1898 unsigned getRegParm() const { return RegParm; } 1899 CallingConv getCC() const { return CC; } 1900 1901 bool operator==(const ExtInfo &Other) const { 1902 return getNoReturn() == Other.getNoReturn() && 1903 getRegParm() == Other.getRegParm() && 1904 getCC() == Other.getCC(); 1905 } 1906 bool operator!=(const ExtInfo &Other) const { 1907 return !(*this == Other); 1908 } 1909 1910 // Note that we don't have setters. That is by design, use 1911 // the following with methods instead of mutating these objects. 1912 1913 ExtInfo withNoReturn(bool noReturn) const { 1914 return ExtInfo(noReturn, getRegParm(), getCC()); 1915 } 1916 1917 ExtInfo withRegParm(unsigned RegParm) const { 1918 return ExtInfo(getNoReturn(), RegParm, getCC()); 1919 } 1920 1921 ExtInfo withCallingConv(CallingConv cc) const { 1922 return ExtInfo(getNoReturn(), getRegParm(), cc); 1923 } 1924 1925 private: 1926 // True if we have __attribute__((noreturn)) 1927 bool NoReturn; 1928 // The value passed to __attribute__((regparm(x))) 1929 unsigned RegParm; 1930 // The calling convention as specified via 1931 // __attribute__((cdecl|stdcall|fastcall|thiscall)) 1932 CallingConv CC; 1933 }; 1934 1935protected: 1936 FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 1937 unsigned typeQuals, QualType Canonical, bool Dependent, 1938 const ExtInfo &Info) 1939 : Type(tc, Canonical, Dependent), 1940 SubClassData(SubclassInfo), TypeQuals(typeQuals), 1941 NoReturn(Info.getNoReturn()), 1942 RegParm(Info.getRegParm()), CallConv(Info.getCC()), ResultType(res) {} 1943 bool getSubClassData() const { return SubClassData; } 1944 unsigned getTypeQuals() const { return TypeQuals; } 1945public: 1946 1947 QualType getResultType() const { return ResultType; } 1948 1949 unsigned getRegParmType() const { return RegParm; } 1950 bool getNoReturnAttr() const { return NoReturn; } 1951 CallingConv getCallConv() const { return (CallingConv)CallConv; } 1952 ExtInfo getExtInfo() const { 1953 return ExtInfo(NoReturn, RegParm, (CallingConv)CallConv); 1954 } 1955 1956 /// \brief Determine the type of an expression that calls a function of 1957 /// this type. 1958 QualType getCallResultType(ASTContext &Context) const { 1959 return getResultType().getNonLValueExprType(Context); 1960 } 1961 1962 static llvm::StringRef getNameForCallConv(CallingConv CC); 1963 1964 static bool classof(const Type *T) { 1965 return T->getTypeClass() == FunctionNoProto || 1966 T->getTypeClass() == FunctionProto; 1967 } 1968 static bool classof(const FunctionType *) { return true; } 1969}; 1970 1971/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 1972/// no information available about its arguments. 1973class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 1974 FunctionNoProtoType(QualType Result, QualType Canonical, 1975 const ExtInfo &Info) 1976 : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 1977 /*Dependent=*/false, Info) {} 1978 friend class ASTContext; // ASTContext creates these. 1979 1980protected: 1981 virtual Linkage getLinkageImpl() const; 1982 1983public: 1984 // No additional state past what FunctionType provides. 1985 1986 bool isSugared() const { return false; } 1987 QualType desugar() const { return QualType(this, 0); } 1988 1989 void Profile(llvm::FoldingSetNodeID &ID) { 1990 Profile(ID, getResultType(), getExtInfo()); 1991 } 1992 static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 1993 const ExtInfo &Info) { 1994 ID.AddInteger(Info.getCC()); 1995 ID.AddInteger(Info.getRegParm()); 1996 ID.AddInteger(Info.getNoReturn()); 1997 ID.AddPointer(ResultType.getAsOpaquePtr()); 1998 } 1999 2000 static bool classof(const Type *T) { 2001 return T->getTypeClass() == FunctionNoProto; 2002 } 2003 static bool classof(const FunctionNoProtoType *) { return true; } 2004}; 2005 2006/// FunctionProtoType - Represents a prototype with argument type info, e.g. 2007/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 2008/// arguments, not as having a single void argument. Such a type can have an 2009/// exception specification, but this specification is not part of the canonical 2010/// type. 2011class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 2012 /// hasAnyDependentType - Determine whether there are any dependent 2013 /// types within the arguments passed in. 2014 static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 2015 for (unsigned Idx = 0; Idx < numArgs; ++Idx) 2016 if (ArgArray[Idx]->isDependentType()) 2017 return true; 2018 2019 return false; 2020 } 2021 2022 FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 2023 bool isVariadic, unsigned typeQuals, bool hasExs, 2024 bool hasAnyExs, const QualType *ExArray, 2025 unsigned numExs, QualType Canonical, 2026 const ExtInfo &Info) 2027 : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 2028 (Result->isDependentType() || 2029 hasAnyDependentType(ArgArray, numArgs)), 2030 Info), 2031 NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 2032 AnyExceptionSpec(hasAnyExs) { 2033 // Fill in the trailing argument array. 2034 QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 2035 for (unsigned i = 0; i != numArgs; ++i) 2036 ArgInfo[i] = ArgArray[i]; 2037 // Fill in the exception array. 2038 QualType *Ex = ArgInfo + numArgs; 2039 for (unsigned i = 0; i != numExs; ++i) 2040 Ex[i] = ExArray[i]; 2041 } 2042 2043 /// NumArgs - The number of arguments this function has, not counting '...'. 2044 unsigned NumArgs : 20; 2045 2046 /// NumExceptions - The number of types in the exception spec, if any. 2047 unsigned NumExceptions : 10; 2048 2049 /// HasExceptionSpec - Whether this function has an exception spec at all. 2050 bool HasExceptionSpec : 1; 2051 2052 /// AnyExceptionSpec - Whether this function has a throw(...) spec. 2053 bool AnyExceptionSpec : 1; 2054 2055 /// ArgInfo - There is an variable size array after the class in memory that 2056 /// holds the argument types. 2057 2058 /// Exceptions - There is another variable size array after ArgInfo that 2059 /// holds the exception types. 2060 2061 friend class ASTContext; // ASTContext creates these. 2062 2063protected: 2064 virtual Linkage getLinkageImpl() const; 2065 2066public: 2067 unsigned getNumArgs() const { return NumArgs; } 2068 QualType getArgType(unsigned i) const { 2069 assert(i < NumArgs && "Invalid argument number!"); 2070 return arg_type_begin()[i]; 2071 } 2072 2073 bool hasExceptionSpec() const { return HasExceptionSpec; } 2074 bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 2075 unsigned getNumExceptions() const { return NumExceptions; } 2076 QualType getExceptionType(unsigned i) const { 2077 assert(i < NumExceptions && "Invalid exception number!"); 2078 return exception_begin()[i]; 2079 } 2080 bool hasEmptyExceptionSpec() const { 2081 return hasExceptionSpec() && !hasAnyExceptionSpec() && 2082 getNumExceptions() == 0; 2083 } 2084 2085 bool isVariadic() const { return getSubClassData(); } 2086 unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 2087 2088 typedef const QualType *arg_type_iterator; 2089 arg_type_iterator arg_type_begin() const { 2090 return reinterpret_cast<const QualType *>(this+1); 2091 } 2092 arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 2093 2094 typedef const QualType *exception_iterator; 2095 exception_iterator exception_begin() const { 2096 // exceptions begin where arguments end 2097 return arg_type_end(); 2098 } 2099 exception_iterator exception_end() const { 2100 return exception_begin() + NumExceptions; 2101 } 2102 2103 bool isSugared() const { return false; } 2104 QualType desugar() const { return QualType(this, 0); } 2105 2106 static bool classof(const Type *T) { 2107 return T->getTypeClass() == FunctionProto; 2108 } 2109 static bool classof(const FunctionProtoType *) { return true; } 2110 2111 void Profile(llvm::FoldingSetNodeID &ID); 2112 static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 2113 arg_type_iterator ArgTys, unsigned NumArgs, 2114 bool isVariadic, unsigned TypeQuals, 2115 bool hasExceptionSpec, bool anyExceptionSpec, 2116 unsigned NumExceptions, exception_iterator Exs, 2117 const ExtInfo &ExtInfo); 2118}; 2119 2120 2121/// \brief Represents the dependent type named by a dependently-scoped 2122/// typename using declaration, e.g. 2123/// using typename Base<T>::foo; 2124/// Template instantiation turns these into the underlying type. 2125class UnresolvedUsingType : public Type { 2126 UnresolvedUsingTypenameDecl *Decl; 2127 2128 UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) 2129 : Type(UnresolvedUsing, QualType(), true), 2130 Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {} 2131 friend class ASTContext; // ASTContext creates these. 2132public: 2133 2134 UnresolvedUsingTypenameDecl *getDecl() const { return Decl; } 2135 2136 bool isSugared() const { return false; } 2137 QualType desugar() const { return QualType(this, 0); } 2138 2139 static bool classof(const Type *T) { 2140 return T->getTypeClass() == UnresolvedUsing; 2141 } 2142 static bool classof(const UnresolvedUsingType *) { return true; } 2143 2144 void Profile(llvm::FoldingSetNodeID &ID) { 2145 return Profile(ID, Decl); 2146 } 2147 static void Profile(llvm::FoldingSetNodeID &ID, 2148 UnresolvedUsingTypenameDecl *D) { 2149 ID.AddPointer(D); 2150 } 2151}; 2152 2153 2154class TypedefType : public Type { 2155 TypedefDecl *Decl; 2156protected: 2157 TypedefType(TypeClass tc, const TypedefDecl *D, QualType can) 2158 : Type(tc, can, can->isDependentType()), 2159 Decl(const_cast<TypedefDecl*>(D)) { 2160 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 2161 } 2162 friend class ASTContext; // ASTContext creates these. 2163public: 2164 2165 TypedefDecl *getDecl() const { return Decl; } 2166 2167 /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 2168 /// potentially looking through *all* consecutive typedefs. This returns the 2169 /// sum of the type qualifiers, so if you have: 2170 /// typedef const int A; 2171 /// typedef volatile A B; 2172 /// looking through the typedefs for B will give you "const volatile A". 2173 QualType LookThroughTypedefs() const; 2174 2175 bool isSugared() const { return true; } 2176 QualType desugar() const; 2177 2178 static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 2179 static bool classof(const TypedefType *) { return true; } 2180}; 2181 2182/// TypeOfExprType (GCC extension). 2183class TypeOfExprType : public Type { 2184 Expr *TOExpr; 2185 2186protected: 2187 TypeOfExprType(Expr *E, QualType can = QualType()); 2188 friend class ASTContext; // ASTContext creates these. 2189public: 2190 Expr *getUnderlyingExpr() const { return TOExpr; } 2191 2192 /// \brief Remove a single level of sugar. 2193 QualType desugar() const; 2194 2195 /// \brief Returns whether this type directly provides sugar. 2196 bool isSugared() const { return true; } 2197 2198 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 2199 static bool classof(const TypeOfExprType *) { return true; } 2200}; 2201 2202/// \brief Internal representation of canonical, dependent 2203/// typeof(expr) types. 2204/// 2205/// This class is used internally by the ASTContext to manage 2206/// canonical, dependent types, only. Clients will only see instances 2207/// of this class via TypeOfExprType nodes. 2208class DependentTypeOfExprType 2209 : public TypeOfExprType, public llvm::FoldingSetNode { 2210 ASTContext &Context; 2211 2212public: 2213 DependentTypeOfExprType(ASTContext &Context, Expr *E) 2214 : TypeOfExprType(E), Context(Context) { } 2215 2216 bool isSugared() const { return false; } 2217 QualType desugar() const { return QualType(this, 0); } 2218 2219 void Profile(llvm::FoldingSetNodeID &ID) { 2220 Profile(ID, Context, getUnderlyingExpr()); 2221 } 2222 2223 static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 2224 Expr *E); 2225}; 2226 2227/// TypeOfType (GCC extension). 2228class TypeOfType : public Type { 2229 QualType TOType; 2230 TypeOfType(QualType T, QualType can) 2231 : Type(TypeOf, can, T->isDependentType()), TOType(T) { 2232 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 2233 } 2234 friend class ASTContext; // ASTContext creates these. 2235public: 2236 QualType getUnderlyingType() const { return TOType; } 2237 2238 /// \brief Remove a single level of sugar. 2239 QualType desugar() const { return getUnderlyingType(); } 2240 2241 /// \brief Returns whether this type directly provides sugar. 2242 bool isSugared() const { return true; } 2243 2244 static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 2245 static bool classof(const TypeOfType *) { return true; } 2246}; 2247 2248/// DecltypeType (C++0x) 2249class DecltypeType : public Type { 2250 Expr *E; 2251 2252 // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 2253 // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 2254 // from it. 2255 QualType UnderlyingType; 2256 2257protected: 2258 DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 2259 friend class ASTContext; // ASTContext creates these. 2260public: 2261 Expr *getUnderlyingExpr() const { return E; } 2262 QualType getUnderlyingType() const { return UnderlyingType; } 2263 2264 /// \brief Remove a single level of sugar. 2265 QualType desugar() const { return getUnderlyingType(); } 2266 2267 /// \brief Returns whether this type directly provides sugar. 2268 bool isSugared() const { return !isDependentType(); } 2269 2270 static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 2271 static bool classof(const DecltypeType *) { return true; } 2272}; 2273 2274/// \brief Internal representation of canonical, dependent 2275/// decltype(expr) types. 2276/// 2277/// This class is used internally by the ASTContext to manage 2278/// canonical, dependent types, only. Clients will only see instances 2279/// of this class via DecltypeType nodes. 2280class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { 2281 ASTContext &Context; 2282 2283public: 2284 DependentDecltypeType(ASTContext &Context, Expr *E); 2285 2286 bool isSugared() const { return false; } 2287 QualType desugar() const { return QualType(this, 0); } 2288 2289 void Profile(llvm::FoldingSetNodeID &ID) { 2290 Profile(ID, Context, getUnderlyingExpr()); 2291 } 2292 2293 static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 2294 Expr *E); 2295}; 2296 2297class TagType : public Type { 2298 /// Stores the TagDecl associated with this type. The decl may point to any 2299 /// TagDecl that declares the entity. 2300 TagDecl * decl; 2301 2302protected: 2303 TagType(TypeClass TC, const TagDecl *D, QualType can); 2304 2305 virtual Linkage getLinkageImpl() const; 2306 2307public: 2308 TagDecl *getDecl() const; 2309 2310 /// @brief Determines whether this type is in the process of being 2311 /// defined. 2312 bool isBeingDefined() const; 2313 2314 static bool classof(const Type *T) { 2315 return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 2316 } 2317 static bool classof(const TagType *) { return true; } 2318 static bool classof(const RecordType *) { return true; } 2319 static bool classof(const EnumType *) { return true; } 2320}; 2321 2322/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 2323/// to detect TagType objects of structs/unions/classes. 2324class RecordType : public TagType { 2325protected: 2326 explicit RecordType(const RecordDecl *D) 2327 : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { } 2328 explicit RecordType(TypeClass TC, RecordDecl *D) 2329 : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { } 2330 friend class ASTContext; // ASTContext creates these. 2331public: 2332 2333 RecordDecl *getDecl() const { 2334 return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 2335 } 2336 2337 // FIXME: This predicate is a helper to QualType/Type. It needs to 2338 // recursively check all fields for const-ness. If any field is declared 2339 // const, it needs to return false. 2340 bool hasConstFields() const { return false; } 2341 2342 // FIXME: RecordType needs to check when it is created that all fields are in 2343 // the same address space, and return that. 2344 unsigned getAddressSpace() const { return 0; } 2345 2346 bool isSugared() const { return false; } 2347 QualType desugar() const { return QualType(this, 0); } 2348 2349 static bool classof(const TagType *T); 2350 static bool classof(const Type *T) { 2351 return isa<TagType>(T) && classof(cast<TagType>(T)); 2352 } 2353 static bool classof(const RecordType *) { return true; } 2354}; 2355 2356/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 2357/// to detect TagType objects of enums. 2358class EnumType : public TagType { 2359 explicit EnumType(const EnumDecl *D) 2360 : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { } 2361 friend class ASTContext; // ASTContext creates these. 2362public: 2363 2364 EnumDecl *getDecl() const { 2365 return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 2366 } 2367 2368 bool isSugared() const { return false; } 2369 QualType desugar() const { return QualType(this, 0); } 2370 2371 static bool classof(const TagType *T); 2372 static bool classof(const Type *T) { 2373 return isa<TagType>(T) && classof(cast<TagType>(T)); 2374 } 2375 static bool classof(const EnumType *) { return true; } 2376}; 2377 2378class TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 2379 unsigned Depth : 15; 2380 unsigned Index : 16; 2381 unsigned ParameterPack : 1; 2382 IdentifierInfo *Name; 2383 2384 TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 2385 QualType Canon) 2386 : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 2387 Depth(D), Index(I), ParameterPack(PP), Name(N) { } 2388 2389 TemplateTypeParmType(unsigned D, unsigned I, bool PP) 2390 : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 2391 Depth(D), Index(I), ParameterPack(PP), Name(0) { } 2392 2393 friend class ASTContext; // ASTContext creates these 2394 2395public: 2396 unsigned getDepth() const { return Depth; } 2397 unsigned getIndex() const { return Index; } 2398 bool isParameterPack() const { return ParameterPack; } 2399 IdentifierInfo *getName() const { return Name; } 2400 2401 bool isSugared() const { return false; } 2402 QualType desugar() const { return QualType(this, 0); } 2403 2404 void Profile(llvm::FoldingSetNodeID &ID) { 2405 Profile(ID, Depth, Index, ParameterPack, Name); 2406 } 2407 2408 static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 2409 unsigned Index, bool ParameterPack, 2410 IdentifierInfo *Name) { 2411 ID.AddInteger(Depth); 2412 ID.AddInteger(Index); 2413 ID.AddBoolean(ParameterPack); 2414 ID.AddPointer(Name); 2415 } 2416 2417 static bool classof(const Type *T) { 2418 return T->getTypeClass() == TemplateTypeParm; 2419 } 2420 static bool classof(const TemplateTypeParmType *T) { return true; } 2421}; 2422 2423/// \brief Represents the result of substituting a type for a template 2424/// type parameter. 2425/// 2426/// Within an instantiated template, all template type parameters have 2427/// been replaced with these. They are used solely to record that a 2428/// type was originally written as a template type parameter; 2429/// therefore they are never canonical. 2430class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode { 2431 // The original type parameter. 2432 const TemplateTypeParmType *Replaced; 2433 2434 SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) 2435 : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType()), 2436 Replaced(Param) { } 2437 2438 friend class ASTContext; 2439 2440public: 2441 IdentifierInfo *getName() const { return Replaced->getName(); } 2442 2443 /// Gets the template parameter that was substituted for. 2444 const TemplateTypeParmType *getReplacedParameter() const { 2445 return Replaced; 2446 } 2447 2448 /// Gets the type that was substituted for the template 2449 /// parameter. 2450 QualType getReplacementType() const { 2451 return getCanonicalTypeInternal(); 2452 } 2453 2454 bool isSugared() const { return true; } 2455 QualType desugar() const { return getReplacementType(); } 2456 2457 void Profile(llvm::FoldingSetNodeID &ID) { 2458 Profile(ID, getReplacedParameter(), getReplacementType()); 2459 } 2460 static void Profile(llvm::FoldingSetNodeID &ID, 2461 const TemplateTypeParmType *Replaced, 2462 QualType Replacement) { 2463 ID.AddPointer(Replaced); 2464 ID.AddPointer(Replacement.getAsOpaquePtr()); 2465 } 2466 2467 static bool classof(const Type *T) { 2468 return T->getTypeClass() == SubstTemplateTypeParm; 2469 } 2470 static bool classof(const SubstTemplateTypeParmType *T) { return true; } 2471}; 2472 2473/// \brief Represents the type of a template specialization as written 2474/// in the source code. 2475/// 2476/// Template specialization types represent the syntactic form of a 2477/// template-id that refers to a type, e.g., @c vector<int>. Some 2478/// template specialization types are syntactic sugar, whose canonical 2479/// type will point to some other type node that represents the 2480/// instantiation or class template specialization. For example, a 2481/// class template specialization type of @c vector<int> will refer to 2482/// a tag type for the instantiation 2483/// @c std::vector<int, std::allocator<int>>. 2484/// 2485/// Other template specialization types, for which the template name 2486/// is dependent, may be canonical types. These types are always 2487/// dependent. 2488class TemplateSpecializationType 2489 : public Type, public llvm::FoldingSetNode { 2490 /// \brief The name of the template being specialized. 2491 TemplateName Template; 2492 2493 /// \brief - The number of template arguments named in this class 2494 /// template specialization. 2495 unsigned NumArgs; 2496 2497 TemplateSpecializationType(TemplateName T, 2498 const TemplateArgument *Args, 2499 unsigned NumArgs, QualType Canon); 2500 2501 friend class ASTContext; // ASTContext creates these 2502 2503public: 2504 /// \brief Determine whether any of the given template arguments are 2505 /// dependent. 2506 static bool anyDependentTemplateArguments(const TemplateArgument *Args, 2507 unsigned NumArgs); 2508 2509 static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args, 2510 unsigned NumArgs); 2511 2512 static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &); 2513 2514 /// \brief Print a template argument list, including the '<' and '>' 2515 /// enclosing the template arguments. 2516 static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 2517 unsigned NumArgs, 2518 const PrintingPolicy &Policy); 2519 2520 static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args, 2521 unsigned NumArgs, 2522 const PrintingPolicy &Policy); 2523 2524 static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &, 2525 const PrintingPolicy &Policy); 2526 2527 /// True if this template specialization type matches a current 2528 /// instantiation in the context in which it is found. 2529 bool isCurrentInstantiation() const { 2530 return isa<InjectedClassNameType>(getCanonicalTypeInternal()); 2531 } 2532 2533 typedef const TemplateArgument * iterator; 2534 2535 iterator begin() const { return getArgs(); } 2536 iterator end() const; // defined inline in TemplateBase.h 2537 2538 /// \brief Retrieve the name of the template that we are specializing. 2539 TemplateName getTemplateName() const { return Template; } 2540 2541 /// \brief Retrieve the template arguments. 2542 const TemplateArgument *getArgs() const { 2543 return reinterpret_cast<const TemplateArgument *>(this + 1); 2544 } 2545 2546 /// \brief Retrieve the number of template arguments. 2547 unsigned getNumArgs() const { return NumArgs; } 2548 2549 /// \brief Retrieve a specific template argument as a type. 2550 /// \precondition @c isArgType(Arg) 2551 const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 2552 2553 bool isSugared() const { 2554 return !isDependentType() || isCurrentInstantiation(); 2555 } 2556 QualType desugar() const { return getCanonicalTypeInternal(); } 2557 2558 void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Ctx) { 2559 Profile(ID, Template, getArgs(), NumArgs, Ctx); 2560 } 2561 2562 static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 2563 const TemplateArgument *Args, 2564 unsigned NumArgs, 2565 ASTContext &Context); 2566 2567 static bool classof(const Type *T) { 2568 return T->getTypeClass() == TemplateSpecialization; 2569 } 2570 static bool classof(const TemplateSpecializationType *T) { return true; } 2571}; 2572 2573/// \brief The injected class name of a C++ class template or class 2574/// template partial specialization. Used to record that a type was 2575/// spelled with a bare identifier rather than as a template-id; the 2576/// equivalent for non-templated classes is just RecordType. 2577/// 2578/// Injected class name types are always dependent. Template 2579/// instantiation turns these into RecordTypes. 2580/// 2581/// Injected class name types are always canonical. This works 2582/// because it is impossible to compare an injected class name type 2583/// with the corresponding non-injected template type, for the same 2584/// reason that it is impossible to directly compare template 2585/// parameters from different dependent contexts: injected class name 2586/// types can only occur within the scope of a particular templated 2587/// declaration, and within that scope every template specialization 2588/// will canonicalize to the injected class name (when appropriate 2589/// according to the rules of the language). 2590class InjectedClassNameType : public Type { 2591 CXXRecordDecl *Decl; 2592 2593 /// The template specialization which this type represents. 2594 /// For example, in 2595 /// template <class T> class A { ... }; 2596 /// this is A<T>, whereas in 2597 /// template <class X, class Y> class A<B<X,Y> > { ... }; 2598 /// this is A<B<X,Y> >. 2599 /// 2600 /// It is always unqualified, always a template specialization type, 2601 /// and always dependent. 2602 QualType InjectedType; 2603 2604 friend class ASTContext; // ASTContext creates these. 2605 friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not 2606 // currently suitable for AST reading, too much 2607 // interdependencies. 2608 InjectedClassNameType(CXXRecordDecl *D, QualType TST) 2609 : Type(InjectedClassName, QualType(), true), 2610 Decl(D), InjectedType(TST) { 2611 assert(isa<TemplateSpecializationType>(TST)); 2612 assert(!TST.hasQualifiers()); 2613 assert(TST->isDependentType()); 2614 } 2615 2616public: 2617 QualType getInjectedSpecializationType() const { return InjectedType; } 2618 const TemplateSpecializationType *getInjectedTST() const { 2619 return cast<TemplateSpecializationType>(InjectedType.getTypePtr()); 2620 } 2621 2622 CXXRecordDecl *getDecl() const; 2623 2624 bool isSugared() const { return false; } 2625 QualType desugar() const { return QualType(this, 0); } 2626 2627 static bool classof(const Type *T) { 2628 return T->getTypeClass() == InjectedClassName; 2629 } 2630 static bool classof(const InjectedClassNameType *T) { return true; } 2631}; 2632 2633/// \brief The kind of a tag type. 2634enum TagTypeKind { 2635 /// \brief The "struct" keyword. 2636 TTK_Struct, 2637 /// \brief The "union" keyword. 2638 TTK_Union, 2639 /// \brief The "class" keyword. 2640 TTK_Class, 2641 /// \brief The "enum" keyword. 2642 TTK_Enum 2643}; 2644 2645/// \brief The elaboration keyword that precedes a qualified type name or 2646/// introduces an elaborated-type-specifier. 2647enum ElaboratedTypeKeyword { 2648 /// \brief The "struct" keyword introduces the elaborated-type-specifier. 2649 ETK_Struct, 2650 /// \brief The "union" keyword introduces the elaborated-type-specifier. 2651 ETK_Union, 2652 /// \brief The "class" keyword introduces the elaborated-type-specifier. 2653 ETK_Class, 2654 /// \brief The "enum" keyword introduces the elaborated-type-specifier. 2655 ETK_Enum, 2656 /// \brief The "typename" keyword precedes the qualified type name, e.g., 2657 /// \c typename T::type. 2658 ETK_Typename, 2659 /// \brief No keyword precedes the qualified type name. 2660 ETK_None 2661}; 2662 2663/// A helper class for Type nodes having an ElaboratedTypeKeyword. 2664/// The keyword in stored in the free bits of the base class. 2665/// Also provides a few static helpers for converting and printing 2666/// elaborated type keyword and tag type kind enumerations. 2667class TypeWithKeyword : public Type { 2668 /// Keyword - Encodes an ElaboratedTypeKeyword enumeration constant. 2669 unsigned Keyword : 3; 2670 2671protected: 2672 TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, 2673 QualType Canonical, bool dependent) 2674 : Type(tc, Canonical, dependent), Keyword(Keyword) {} 2675 2676public: 2677 virtual ~TypeWithKeyword(); // pin vtable to Type.cpp 2678 2679 ElaboratedTypeKeyword getKeyword() const { 2680 return static_cast<ElaboratedTypeKeyword>(Keyword); 2681 } 2682 2683 /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST) 2684 /// into an elaborated type keyword. 2685 static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec); 2686 2687 /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST) 2688 /// into a tag type kind. It is an error to provide a type specifier 2689 /// which *isn't* a tag kind here. 2690 static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec); 2691 2692 /// getKeywordForTagDeclKind - Converts a TagTypeKind into an 2693 /// elaborated type keyword. 2694 static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag); 2695 2696 /// getTagTypeKindForKeyword - Converts an elaborated type keyword into 2697 // a TagTypeKind. It is an error to provide an elaborated type keyword 2698 /// which *isn't* a tag kind here. 2699 static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword); 2700 2701 static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword); 2702 2703 static const char *getKeywordName(ElaboratedTypeKeyword Keyword); 2704 2705 static const char *getTagTypeKindName(TagTypeKind Kind) { 2706 return getKeywordName(getKeywordForTagTypeKind(Kind)); 2707 } 2708 2709 class CannotCastToThisType {}; 2710 static CannotCastToThisType classof(const Type *); 2711}; 2712 2713/// \brief Represents a type that was referred to using an elaborated type 2714/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type, 2715/// or both. 2716/// 2717/// This type is used to keep track of a type name as written in the 2718/// source code, including tag keywords and any nested-name-specifiers. 2719/// The type itself is always "sugar", used to express what was written 2720/// in the source code but containing no additional semantic information. 2721class ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode { 2722 2723 /// \brief The nested name specifier containing the qualifier. 2724 NestedNameSpecifier *NNS; 2725 2726 /// \brief The type that this qualified name refers to. 2727 QualType NamedType; 2728 2729 ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 2730 QualType NamedType, QualType CanonType) 2731 : TypeWithKeyword(Keyword, Elaborated, CanonType, 2732 NamedType->isDependentType()), 2733 NNS(NNS), NamedType(NamedType) { 2734 assert(!(Keyword == ETK_None && NNS == 0) && 2735 "ElaboratedType cannot have elaborated type keyword " 2736 "and name qualifier both null."); 2737 } 2738 2739 friend class ASTContext; // ASTContext creates these 2740 2741public: 2742 ~ElaboratedType(); 2743 2744 /// \brief Retrieve the qualification on this type. 2745 NestedNameSpecifier *getQualifier() const { return NNS; } 2746 2747 /// \brief Retrieve the type named by the qualified-id. 2748 QualType getNamedType() const { return NamedType; } 2749 2750 /// \brief Remove a single level of sugar. 2751 QualType desugar() const { return getNamedType(); } 2752 2753 /// \brief Returns whether this type directly provides sugar. 2754 bool isSugared() const { return true; } 2755 2756 void Profile(llvm::FoldingSetNodeID &ID) { 2757 Profile(ID, getKeyword(), NNS, NamedType); 2758 } 2759 2760 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 2761 NestedNameSpecifier *NNS, QualType NamedType) { 2762 ID.AddInteger(Keyword); 2763 ID.AddPointer(NNS); 2764 NamedType.Profile(ID); 2765 } 2766 2767 static bool classof(const Type *T) { 2768 return T->getTypeClass() == Elaborated; 2769 } 2770 static bool classof(const ElaboratedType *T) { return true; } 2771}; 2772 2773/// \brief Represents a qualified type name for which the type name is 2774/// dependent. 2775/// 2776/// DependentNameType represents a class of dependent types that involve a 2777/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent) 2778/// name of a type. The DependentNameType may start with a "typename" (for a 2779/// typename-specifier), "class", "struct", "union", or "enum" (for a 2780/// dependent elaborated-type-specifier), or nothing (in contexts where we 2781/// know that we must be referring to a type, e.g., in a base class specifier). 2782class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { 2783 2784 /// \brief The nested name specifier containing the qualifier. 2785 NestedNameSpecifier *NNS; 2786 2787 /// \brief The type that this typename specifier refers to. 2788 const IdentifierInfo *Name; 2789 2790 DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 2791 const IdentifierInfo *Name, QualType CanonType) 2792 : TypeWithKeyword(Keyword, DependentName, CanonType, true), 2793 NNS(NNS), Name(Name) { 2794 assert(NNS->isDependent() && 2795 "DependentNameType requires a dependent nested-name-specifier"); 2796 } 2797 2798 friend class ASTContext; // ASTContext creates these 2799 2800public: 2801 virtual ~DependentNameType(); 2802 2803 /// \brief Retrieve the qualification on this type. 2804 NestedNameSpecifier *getQualifier() const { return NNS; } 2805 2806 /// \brief Retrieve the type named by the typename specifier as an 2807 /// identifier. 2808 /// 2809 /// This routine will return a non-NULL identifier pointer when the 2810 /// form of the original typename was terminated by an identifier, 2811 /// e.g., "typename T::type". 2812 const IdentifierInfo *getIdentifier() const { 2813 return Name; 2814 } 2815 2816 bool isSugared() const { return false; } 2817 QualType desugar() const { return QualType(this, 0); } 2818 2819 void Profile(llvm::FoldingSetNodeID &ID) { 2820 Profile(ID, getKeyword(), NNS, Name); 2821 } 2822 2823 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, 2824 NestedNameSpecifier *NNS, const IdentifierInfo *Name) { 2825 ID.AddInteger(Keyword); 2826 ID.AddPointer(NNS); 2827 ID.AddPointer(Name); 2828 } 2829 2830 static bool classof(const Type *T) { 2831 return T->getTypeClass() == DependentName; 2832 } 2833 static bool classof(const DependentNameType *T) { return true; } 2834}; 2835 2836/// DependentTemplateSpecializationType - Represents a template 2837/// specialization type whose template cannot be resolved, e.g. 2838/// A<T>::template B<T> 2839class DependentTemplateSpecializationType : 2840 public TypeWithKeyword, public llvm::FoldingSetNode { 2841 2842 /// \brief The nested name specifier containing the qualifier. 2843 NestedNameSpecifier *NNS; 2844 2845 /// \brief The identifier of the template. 2846 const IdentifierInfo *Name; 2847 2848 /// \brief - The number of template arguments named in this class 2849 /// template specialization. 2850 unsigned NumArgs; 2851 2852 const TemplateArgument *getArgBuffer() const { 2853 return reinterpret_cast<const TemplateArgument*>(this+1); 2854 } 2855 TemplateArgument *getArgBuffer() { 2856 return reinterpret_cast<TemplateArgument*>(this+1); 2857 } 2858 2859 DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 2860 NestedNameSpecifier *NNS, 2861 const IdentifierInfo *Name, 2862 unsigned NumArgs, 2863 const TemplateArgument *Args, 2864 QualType Canon); 2865 2866 friend class ASTContext; // ASTContext creates these 2867 2868public: 2869 virtual ~DependentTemplateSpecializationType(); 2870 2871 NestedNameSpecifier *getQualifier() const { return NNS; } 2872 const IdentifierInfo *getIdentifier() const { return Name; } 2873 2874 /// \brief Retrieve the template arguments. 2875 const TemplateArgument *getArgs() const { 2876 return getArgBuffer(); 2877 } 2878 2879 /// \brief Retrieve the number of template arguments. 2880 unsigned getNumArgs() const { return NumArgs; } 2881 2882 const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h 2883 2884 typedef const TemplateArgument * iterator; 2885 iterator begin() const { return getArgs(); } 2886 iterator end() const; // inline in TemplateBase.h 2887 2888 bool isSugared() const { return false; } 2889 QualType desugar() const { return QualType(this, 0); } 2890 2891 void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context) { 2892 Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs()); 2893 } 2894 2895 static void Profile(llvm::FoldingSetNodeID &ID, 2896 ASTContext &Context, 2897 ElaboratedTypeKeyword Keyword, 2898 NestedNameSpecifier *Qualifier, 2899 const IdentifierInfo *Name, 2900 unsigned NumArgs, 2901 const TemplateArgument *Args); 2902 2903 static bool classof(const Type *T) { 2904 return T->getTypeClass() == DependentTemplateSpecialization; 2905 } 2906 static bool classof(const DependentTemplateSpecializationType *T) { 2907 return true; 2908 } 2909}; 2910 2911/// ObjCObjectType - Represents a class type in Objective C. 2912/// Every Objective C type is a combination of a base type and a 2913/// list of protocols. 2914/// 2915/// Given the following declarations: 2916/// @class C; 2917/// @protocol P; 2918/// 2919/// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType 2920/// with base C and no protocols. 2921/// 2922/// 'C<P>' is an ObjCObjectType with base C and protocol list [P]. 2923/// 2924/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose 2925/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType 2926/// and no protocols. 2927/// 2928/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType 2929/// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually 2930/// this should get its own sugar class to better represent the source. 2931class ObjCObjectType : public Type { 2932 // Pad the bit count up so that NumProtocols is 2-byte aligned 2933 unsigned : BitsRemainingInType - 16; 2934 2935 /// \brief The number of protocols stored after the 2936 /// ObjCObjectPointerType node. 2937 /// 2938 /// These protocols are those written directly on the type. If 2939 /// protocol qualifiers ever become additive, the iterators will 2940 /// get kindof complicated. 2941 /// 2942 /// In the canonical object type, these are sorted alphabetically 2943 /// and uniqued. 2944 unsigned NumProtocols : 16; 2945 2946 /// Either a BuiltinType or an InterfaceType or sugar for either. 2947 QualType BaseType; 2948 2949 ObjCProtocolDecl * const *getProtocolStorage() const { 2950 return const_cast<ObjCObjectType*>(this)->getProtocolStorage(); 2951 } 2952 2953 ObjCProtocolDecl **getProtocolStorage(); 2954 2955protected: 2956 ObjCObjectType(QualType Canonical, QualType Base, 2957 ObjCProtocolDecl * const *Protocols, unsigned NumProtocols); 2958 2959 enum Nonce_ObjCInterface { Nonce_ObjCInterface }; 2960 ObjCObjectType(enum Nonce_ObjCInterface) 2961 : Type(ObjCInterface, QualType(), false), 2962 NumProtocols(0), 2963 BaseType(QualType(this_(), 0)) {} 2964 2965protected: 2966 Linkage getLinkageImpl() const; // key function 2967 2968public: 2969 /// getBaseType - Gets the base type of this object type. This is 2970 /// always (possibly sugar for) one of: 2971 /// - the 'id' builtin type (as opposed to the 'id' type visible to the 2972 /// user, which is a typedef for an ObjCPointerType) 2973 /// - the 'Class' builtin type (same caveat) 2974 /// - an ObjCObjectType (currently always an ObjCInterfaceType) 2975 QualType getBaseType() const { return BaseType; } 2976 2977 bool isObjCId() const { 2978 return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId); 2979 } 2980 bool isObjCClass() const { 2981 return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass); 2982 } 2983 bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); } 2984 bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); } 2985 bool isObjCUnqualifiedIdOrClass() const { 2986 if (!qual_empty()) return false; 2987 if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>()) 2988 return T->getKind() == BuiltinType::ObjCId || 2989 T->getKind() == BuiltinType::ObjCClass; 2990 return false; 2991 } 2992 bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); } 2993 bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); } 2994 2995 /// Gets the interface declaration for this object type, if the base type 2996 /// really is an interface. 2997 ObjCInterfaceDecl *getInterface() const; 2998 2999 typedef ObjCProtocolDecl * const *qual_iterator; 3000 3001 qual_iterator qual_begin() const { return getProtocolStorage(); } 3002 qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); } 3003 3004 bool qual_empty() const { return getNumProtocols() == 0; } 3005 3006 /// getNumProtocols - Return the number of qualifying protocols in this 3007 /// interface type, or 0 if there are none. 3008 unsigned getNumProtocols() const { return NumProtocols; } 3009 3010 /// \brief Fetch a protocol by index. 3011 ObjCProtocolDecl *getProtocol(unsigned I) const { 3012 assert(I < getNumProtocols() && "Out-of-range protocol access"); 3013 return qual_begin()[I]; 3014 } 3015 3016 bool isSugared() const { return false; } 3017 QualType desugar() const { return QualType(this, 0); } 3018 3019 static bool classof(const Type *T) { 3020 return T->getTypeClass() == ObjCObject || 3021 T->getTypeClass() == ObjCInterface; 3022 } 3023 static bool classof(const ObjCObjectType *) { return true; } 3024}; 3025 3026/// ObjCObjectTypeImpl - A class providing a concrete implementation 3027/// of ObjCObjectType, so as to not increase the footprint of 3028/// ObjCInterfaceType. Code outside of ASTContext and the core type 3029/// system should not reference this type. 3030class ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode { 3031 friend class ASTContext; 3032 3033 // If anyone adds fields here, ObjCObjectType::getProtocolStorage() 3034 // will need to be modified. 3035 3036 ObjCObjectTypeImpl(QualType Canonical, QualType Base, 3037 ObjCProtocolDecl * const *Protocols, 3038 unsigned NumProtocols) 3039 : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {} 3040 3041public: 3042 void Profile(llvm::FoldingSetNodeID &ID); 3043 static void Profile(llvm::FoldingSetNodeID &ID, 3044 QualType Base, 3045 ObjCProtocolDecl *const *protocols, 3046 unsigned NumProtocols); 3047}; 3048 3049inline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() { 3050 return reinterpret_cast<ObjCProtocolDecl**>( 3051 static_cast<ObjCObjectTypeImpl*>(this) + 1); 3052} 3053 3054/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 3055/// object oriented design. They basically correspond to C++ classes. There 3056/// are two kinds of interface types, normal interfaces like "NSString" and 3057/// qualified interfaces, which are qualified with a protocol list like 3058/// "NSString<NSCopyable, NSAmazing>". 3059/// 3060/// ObjCInterfaceType guarantees the following properties when considered 3061/// as a subtype of its superclass, ObjCObjectType: 3062/// - There are no protocol qualifiers. To reinforce this, code which 3063/// tries to invoke the protocol methods via an ObjCInterfaceType will 3064/// fail to compile. 3065/// - It is its own base type. That is, if T is an ObjCInterfaceType*, 3066/// T->getBaseType() == QualType(T, 0). 3067class ObjCInterfaceType : public ObjCObjectType { 3068 ObjCInterfaceDecl *Decl; 3069 3070 ObjCInterfaceType(const ObjCInterfaceDecl *D) 3071 : ObjCObjectType(Nonce_ObjCInterface), 3072 Decl(const_cast<ObjCInterfaceDecl*>(D)) {} 3073 friend class ASTContext; // ASTContext creates these. 3074public: 3075 /// getDecl - Get the declaration of this interface. 3076 ObjCInterfaceDecl *getDecl() const { return Decl; } 3077 3078 bool isSugared() const { return false; } 3079 QualType desugar() const { return QualType(this, 0); } 3080 3081 static bool classof(const Type *T) { 3082 return T->getTypeClass() == ObjCInterface; 3083 } 3084 static bool classof(const ObjCInterfaceType *) { return true; } 3085 3086 // Nonsense to "hide" certain members of ObjCObjectType within this 3087 // class. People asking for protocols on an ObjCInterfaceType are 3088 // not going to get what they want: ObjCInterfaceTypes are 3089 // guaranteed to have no protocols. 3090 enum { 3091 qual_iterator, 3092 qual_begin, 3093 qual_end, 3094 getNumProtocols, 3095 getProtocol 3096 }; 3097}; 3098 3099inline ObjCInterfaceDecl *ObjCObjectType::getInterface() const { 3100 if (const ObjCInterfaceType *T = 3101 getBaseType()->getAs<ObjCInterfaceType>()) 3102 return T->getDecl(); 3103 return 0; 3104} 3105 3106/// ObjCObjectPointerType - Used to represent a pointer to an 3107/// Objective C object. These are constructed from pointer 3108/// declarators when the pointee type is an ObjCObjectType (or sugar 3109/// for one). In addition, the 'id' and 'Class' types are typedefs 3110/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>' 3111/// are translated into these. 3112/// 3113/// Pointers to pointers to Objective C objects are still PointerTypes; 3114/// only the first level of pointer gets it own type implementation. 3115class ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 3116 QualType PointeeType; 3117 3118 ObjCObjectPointerType(QualType Canonical, QualType Pointee) 3119 : Type(ObjCObjectPointer, Canonical, false), 3120 PointeeType(Pointee) {} 3121 friend class ASTContext; // ASTContext creates these. 3122 3123protected: 3124 virtual Linkage getLinkageImpl() const; 3125 3126public: 3127 /// getPointeeType - Gets the type pointed to by this ObjC pointer. 3128 /// The result will always be an ObjCObjectType or sugar thereof. 3129 QualType getPointeeType() const { return PointeeType; } 3130 3131 /// getObjCObjectType - Gets the type pointed to by this ObjC 3132 /// pointer. This method always returns non-null. 3133 /// 3134 /// This method is equivalent to getPointeeType() except that 3135 /// it discards any typedefs (or other sugar) between this 3136 /// type and the "outermost" object type. So for: 3137 /// @class A; @protocol P; @protocol Q; 3138 /// typedef A<P> AP; 3139 /// typedef A A1; 3140 /// typedef A1<P> A1P; 3141 /// typedef A1P<Q> A1PQ; 3142 /// For 'A*', getObjectType() will return 'A'. 3143 /// For 'A<P>*', getObjectType() will return 'A<P>'. 3144 /// For 'AP*', getObjectType() will return 'A<P>'. 3145 /// For 'A1*', getObjectType() will return 'A'. 3146 /// For 'A1<P>*', getObjectType() will return 'A1<P>'. 3147 /// For 'A1P*', getObjectType() will return 'A1<P>'. 3148 /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because 3149 /// adding protocols to a protocol-qualified base discards the 3150 /// old qualifiers (for now). But if it didn't, getObjectType() 3151 /// would return 'A1P<Q>' (and we'd have to make iterating over 3152 /// qualifiers more complicated). 3153 const ObjCObjectType *getObjectType() const { 3154 return PointeeType->getAs<ObjCObjectType>(); 3155 } 3156 3157 /// getInterfaceType - If this pointer points to an Objective C 3158 /// @interface type, gets the type for that interface. Any protocol 3159 /// qualifiers on the interface are ignored. 3160 /// 3161 /// \return null if the base type for this pointer is 'id' or 'Class' 3162 const ObjCInterfaceType *getInterfaceType() const { 3163 return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>(); 3164 } 3165 3166 /// getInterfaceDecl - If this pointer points to an Objective @interface 3167 /// type, gets the declaration for that interface. 3168 /// 3169 /// \return null if the base type for this pointer is 'id' or 'Class' 3170 ObjCInterfaceDecl *getInterfaceDecl() const { 3171 return getObjectType()->getInterface(); 3172 } 3173 3174 /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if 3175 /// its object type is the primitive 'id' type with no protocols. 3176 bool isObjCIdType() const { 3177 return getObjectType()->isObjCUnqualifiedId(); 3178 } 3179 3180 /// isObjCClassType - True if this is equivalent to the 'Class' type, 3181 /// i.e. if its object tive is the primitive 'Class' type with no protocols. 3182 bool isObjCClassType() const { 3183 return getObjectType()->isObjCUnqualifiedClass(); 3184 } 3185 3186 /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some 3187 /// non-empty set of protocols. 3188 bool isObjCQualifiedIdType() const { 3189 return getObjectType()->isObjCQualifiedId(); 3190 } 3191 3192 /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for 3193 /// some non-empty set of protocols. 3194 bool isObjCQualifiedClassType() const { 3195 return getObjectType()->isObjCQualifiedClass(); 3196 } 3197 3198 /// An iterator over the qualifiers on the object type. Provided 3199 /// for convenience. This will always iterate over the full set of 3200 /// protocols on a type, not just those provided directly. 3201 typedef ObjCObjectType::qual_iterator qual_iterator; 3202 3203 qual_iterator qual_begin() const { 3204 return getObjectType()->qual_begin(); 3205 } 3206 qual_iterator qual_end() const { 3207 return getObjectType()->qual_end(); 3208 } 3209 bool qual_empty() const { return getObjectType()->qual_empty(); } 3210 3211 /// getNumProtocols - Return the number of qualifying protocols on 3212 /// the object type. 3213 unsigned getNumProtocols() const { 3214 return getObjectType()->getNumProtocols(); 3215 } 3216 3217 /// \brief Retrieve a qualifying protocol by index on the object 3218 /// type. 3219 ObjCProtocolDecl *getProtocol(unsigned I) const { 3220 return getObjectType()->getProtocol(I); 3221 } 3222 3223 bool isSugared() const { return false; } 3224 QualType desugar() const { return QualType(this, 0); } 3225 3226 void Profile(llvm::FoldingSetNodeID &ID) { 3227 Profile(ID, getPointeeType()); 3228 } 3229 static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { 3230 ID.AddPointer(T.getAsOpaquePtr()); 3231 } 3232 static bool classof(const Type *T) { 3233 return T->getTypeClass() == ObjCObjectPointer; 3234 } 3235 static bool classof(const ObjCObjectPointerType *) { return true; } 3236}; 3237 3238/// A qualifier set is used to build a set of qualifiers. 3239class QualifierCollector : public Qualifiers { 3240 ASTContext *Context; 3241 3242public: 3243 QualifierCollector(Qualifiers Qs = Qualifiers()) 3244 : Qualifiers(Qs), Context(0) {} 3245 QualifierCollector(ASTContext &Context, Qualifiers Qs = Qualifiers()) 3246 : Qualifiers(Qs), Context(&Context) {} 3247 3248 void setContext(ASTContext &C) { Context = &C; } 3249 3250 /// Collect any qualifiers on the given type and return an 3251 /// unqualified type. 3252 const Type *strip(QualType QT) { 3253 addFastQualifiers(QT.getLocalFastQualifiers()); 3254 if (QT.hasLocalNonFastQualifiers()) { 3255 const ExtQuals *EQ = QT.getExtQualsUnsafe(); 3256 Context = &EQ->getContext(); 3257 addQualifiers(EQ->getQualifiers()); 3258 return EQ->getBaseType(); 3259 } 3260 return QT.getTypePtrUnsafe(); 3261 } 3262 3263 /// Apply the collected qualifiers to the given type. 3264 QualType apply(QualType QT) const; 3265 3266 /// Apply the collected qualifiers to the given type. 3267 QualType apply(const Type* T) const; 3268 3269}; 3270 3271 3272// Inline function definitions. 3273 3274inline bool QualType::isCanonical() const { 3275 const Type *T = getTypePtr(); 3276 if (hasLocalQualifiers()) 3277 return T->isCanonicalUnqualified() && !isa<ArrayType>(T); 3278 return T->isCanonicalUnqualified(); 3279} 3280 3281inline bool QualType::isCanonicalAsParam() const { 3282 if (hasLocalQualifiers()) return false; 3283 const Type *T = getTypePtr(); 3284 return T->isCanonicalUnqualified() && 3285 !isa<FunctionType>(T) && !isa<ArrayType>(T); 3286} 3287 3288inline bool QualType::isConstQualified() const { 3289 return isLocalConstQualified() || 3290 getTypePtr()->getCanonicalTypeInternal().isLocalConstQualified(); 3291} 3292 3293inline bool QualType::isRestrictQualified() const { 3294 return isLocalRestrictQualified() || 3295 getTypePtr()->getCanonicalTypeInternal().isLocalRestrictQualified(); 3296} 3297 3298 3299inline bool QualType::isVolatileQualified() const { 3300 return isLocalVolatileQualified() || 3301 getTypePtr()->getCanonicalTypeInternal().isLocalVolatileQualified(); 3302} 3303 3304inline bool QualType::hasQualifiers() const { 3305 return hasLocalQualifiers() || 3306 getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers(); 3307} 3308 3309inline Qualifiers QualType::getQualifiers() const { 3310 Qualifiers Quals = getLocalQualifiers(); 3311 Quals.addQualifiers( 3312 getTypePtr()->getCanonicalTypeInternal().getLocalQualifiers()); 3313 return Quals; 3314} 3315 3316inline unsigned QualType::getCVRQualifiers() const { 3317 return getLocalCVRQualifiers() | 3318 getTypePtr()->getCanonicalTypeInternal().getLocalCVRQualifiers(); 3319} 3320 3321/// getCVRQualifiersThroughArrayTypes - If there are CVR qualifiers for this 3322/// type, returns them. Otherwise, if this is an array type, recurses 3323/// on the element type until some qualifiers have been found or a non-array 3324/// type reached. 3325inline unsigned QualType::getCVRQualifiersThroughArrayTypes() const { 3326 if (unsigned Quals = getCVRQualifiers()) 3327 return Quals; 3328 QualType CT = getTypePtr()->getCanonicalTypeInternal(); 3329 if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 3330 return AT->getElementType().getCVRQualifiersThroughArrayTypes(); 3331 return 0; 3332} 3333 3334inline void QualType::removeConst() { 3335 removeFastQualifiers(Qualifiers::Const); 3336} 3337 3338inline void QualType::removeRestrict() { 3339 removeFastQualifiers(Qualifiers::Restrict); 3340} 3341 3342inline void QualType::removeVolatile() { 3343 QualifierCollector Qc; 3344 const Type *Ty = Qc.strip(*this); 3345 if (Qc.hasVolatile()) { 3346 Qc.removeVolatile(); 3347 *this = Qc.apply(Ty); 3348 } 3349} 3350 3351inline void QualType::removeCVRQualifiers(unsigned Mask) { 3352 assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits"); 3353 3354 // Fast path: we don't need to touch the slow qualifiers. 3355 if (!(Mask & ~Qualifiers::FastMask)) { 3356 removeFastQualifiers(Mask); 3357 return; 3358 } 3359 3360 QualifierCollector Qc; 3361 const Type *Ty = Qc.strip(*this); 3362 Qc.removeCVRQualifiers(Mask); 3363 *this = Qc.apply(Ty); 3364} 3365 3366/// getAddressSpace - Return the address space of this type. 3367inline unsigned QualType::getAddressSpace() const { 3368 if (hasLocalNonFastQualifiers()) { 3369 const ExtQuals *EQ = getExtQualsUnsafe(); 3370 if (EQ->hasAddressSpace()) 3371 return EQ->getAddressSpace(); 3372 } 3373 3374 QualType CT = getTypePtr()->getCanonicalTypeInternal(); 3375 if (CT.hasLocalNonFastQualifiers()) { 3376 const ExtQuals *EQ = CT.getExtQualsUnsafe(); 3377 if (EQ->hasAddressSpace()) 3378 return EQ->getAddressSpace(); 3379 } 3380 3381 if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 3382 return AT->getElementType().getAddressSpace(); 3383 if (const RecordType *RT = dyn_cast<RecordType>(CT)) 3384 return RT->getAddressSpace(); 3385 return 0; 3386} 3387 3388/// getObjCGCAttr - Return the gc attribute of this type. 3389inline Qualifiers::GC QualType::getObjCGCAttr() const { 3390 if (hasLocalNonFastQualifiers()) { 3391 const ExtQuals *EQ = getExtQualsUnsafe(); 3392 if (EQ->hasObjCGCAttr()) 3393 return EQ->getObjCGCAttr(); 3394 } 3395 3396 QualType CT = getTypePtr()->getCanonicalTypeInternal(); 3397 if (CT.hasLocalNonFastQualifiers()) { 3398 const ExtQuals *EQ = CT.getExtQualsUnsafe(); 3399 if (EQ->hasObjCGCAttr()) 3400 return EQ->getObjCGCAttr(); 3401 } 3402 3403 if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 3404 return AT->getElementType().getObjCGCAttr(); 3405 if (const ObjCObjectPointerType *PT = CT->getAs<ObjCObjectPointerType>()) 3406 return PT->getPointeeType().getObjCGCAttr(); 3407 // We most look at all pointer types, not just pointer to interface types. 3408 if (const PointerType *PT = CT->getAs<PointerType>()) 3409 return PT->getPointeeType().getObjCGCAttr(); 3410 return Qualifiers::GCNone; 3411} 3412 3413inline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { 3414 if (const PointerType *PT = t.getAs<PointerType>()) { 3415 if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>()) 3416 return FT->getExtInfo(); 3417 } else if (const FunctionType *FT = t.getAs<FunctionType>()) 3418 return FT->getExtInfo(); 3419 3420 return FunctionType::ExtInfo(); 3421} 3422 3423inline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { 3424 return getFunctionExtInfo(*t); 3425} 3426 3427/// \brief Determine whether this set of qualifiers is a superset of the given 3428/// set of qualifiers. 3429inline bool Qualifiers::isSupersetOf(Qualifiers Other) const { 3430 return Mask != Other.Mask && (Mask | Other.Mask) == Mask; 3431} 3432 3433/// isMoreQualifiedThan - Determine whether this type is more 3434/// qualified than the Other type. For example, "const volatile int" 3435/// is more qualified than "const int", "volatile int", and 3436/// "int". However, it is not more qualified than "const volatile 3437/// int". 3438inline bool QualType::isMoreQualifiedThan(QualType Other) const { 3439 // FIXME: work on arbitrary qualifiers 3440 unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes(); 3441 unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes(); 3442 if (getAddressSpace() != Other.getAddressSpace()) 3443 return false; 3444 return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 3445} 3446 3447/// isAtLeastAsQualifiedAs - Determine whether this type is at last 3448/// as qualified as the Other type. For example, "const volatile 3449/// int" is at least as qualified as "const int", "volatile int", 3450/// "int", and "const volatile int". 3451inline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 3452 // FIXME: work on arbitrary qualifiers 3453 unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes(); 3454 unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes(); 3455 if (getAddressSpace() != Other.getAddressSpace()) 3456 return false; 3457 return (MyQuals | OtherQuals) == MyQuals; 3458} 3459 3460/// getNonReferenceType - If Type is a reference type (e.g., const 3461/// int&), returns the type that the reference refers to ("const 3462/// int"). Otherwise, returns the type itself. This routine is used 3463/// throughout Sema to implement C++ 5p6: 3464/// 3465/// If an expression initially has the type "reference to T" (8.3.2, 3466/// 8.5.3), the type is adjusted to "T" prior to any further 3467/// analysis, the expression designates the object or function 3468/// denoted by the reference, and the expression is an lvalue. 3469inline QualType QualType::getNonReferenceType() const { 3470 if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 3471 return RefType->getPointeeType(); 3472 else 3473 return *this; 3474} 3475 3476inline bool Type::isFunctionType() const { 3477 return isa<FunctionType>(CanonicalType); 3478} 3479inline bool Type::isPointerType() const { 3480 return isa<PointerType>(CanonicalType); 3481} 3482inline bool Type::isAnyPointerType() const { 3483 return isPointerType() || isObjCObjectPointerType(); 3484} 3485inline bool Type::isBlockPointerType() const { 3486 return isa<BlockPointerType>(CanonicalType); 3487} 3488inline bool Type::isReferenceType() const { 3489 return isa<ReferenceType>(CanonicalType); 3490} 3491inline bool Type::isLValueReferenceType() const { 3492 return isa<LValueReferenceType>(CanonicalType); 3493} 3494inline bool Type::isRValueReferenceType() const { 3495 return isa<RValueReferenceType>(CanonicalType); 3496} 3497inline bool Type::isFunctionPointerType() const { 3498 if (const PointerType* T = getAs<PointerType>()) 3499 return T->getPointeeType()->isFunctionType(); 3500 else 3501 return false; 3502} 3503inline bool Type::isMemberPointerType() const { 3504 return isa<MemberPointerType>(CanonicalType); 3505} 3506inline bool Type::isMemberFunctionPointerType() const { 3507 if (const MemberPointerType* T = getAs<MemberPointerType>()) 3508 return T->isMemberFunctionPointer(); 3509 else 3510 return false; 3511} 3512inline bool Type::isMemberDataPointerType() const { 3513 if (const MemberPointerType* T = getAs<MemberPointerType>()) 3514 return T->isMemberDataPointer(); 3515 else 3516 return false; 3517} 3518inline bool Type::isArrayType() const { 3519 return isa<ArrayType>(CanonicalType); 3520} 3521inline bool Type::isConstantArrayType() const { 3522 return isa<ConstantArrayType>(CanonicalType); 3523} 3524inline bool Type::isIncompleteArrayType() const { 3525 return isa<IncompleteArrayType>(CanonicalType); 3526} 3527inline bool Type::isVariableArrayType() const { 3528 return isa<VariableArrayType>(CanonicalType); 3529} 3530inline bool Type::isDependentSizedArrayType() const { 3531 return isa<DependentSizedArrayType>(CanonicalType); 3532} 3533inline bool Type::isRecordType() const { 3534 return isa<RecordType>(CanonicalType); 3535} 3536inline bool Type::isAnyComplexType() const { 3537 return isa<ComplexType>(CanonicalType); 3538} 3539inline bool Type::isVectorType() const { 3540 return isa<VectorType>(CanonicalType); 3541} 3542inline bool Type::isExtVectorType() const { 3543 return isa<ExtVectorType>(CanonicalType); 3544} 3545inline bool Type::isObjCObjectPointerType() const { 3546 return isa<ObjCObjectPointerType>(CanonicalType); 3547} 3548inline bool Type::isObjCObjectType() const { 3549 return isa<ObjCObjectType>(CanonicalType); 3550} 3551inline bool Type::isObjCObjectOrInterfaceType() const { 3552 return isa<ObjCInterfaceType>(CanonicalType) || 3553 isa<ObjCObjectType>(CanonicalType); 3554} 3555 3556inline bool Type::isObjCQualifiedIdType() const { 3557 if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3558 return OPT->isObjCQualifiedIdType(); 3559 return false; 3560} 3561inline bool Type::isObjCQualifiedClassType() const { 3562 if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3563 return OPT->isObjCQualifiedClassType(); 3564 return false; 3565} 3566inline bool Type::isObjCIdType() const { 3567 if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3568 return OPT->isObjCIdType(); 3569 return false; 3570} 3571inline bool Type::isObjCClassType() const { 3572 if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 3573 return OPT->isObjCClassType(); 3574 return false; 3575} 3576inline bool Type::isObjCSelType() const { 3577 if (const PointerType *OPT = getAs<PointerType>()) 3578 return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); 3579 return false; 3580} 3581inline bool Type::isObjCBuiltinType() const { 3582 return isObjCIdType() || isObjCClassType() || isObjCSelType(); 3583} 3584inline bool Type::isTemplateTypeParmType() const { 3585 return isa<TemplateTypeParmType>(CanonicalType); 3586} 3587 3588inline bool Type::isBuiltinType() const { 3589 return getAs<BuiltinType>(); 3590} 3591 3592inline bool Type::isSpecificBuiltinType(unsigned K) const { 3593 if (const BuiltinType *BT = getAs<BuiltinType>()) 3594 if (BT->getKind() == (BuiltinType::Kind) K) 3595 return true; 3596 return false; 3597} 3598 3599/// \brief Determines whether this is a type for which one can define 3600/// an overloaded operator. 3601inline bool Type::isOverloadableType() const { 3602 return isDependentType() || isRecordType() || isEnumeralType(); 3603} 3604 3605inline bool Type::hasPointerRepresentation() const { 3606 return (isPointerType() || isReferenceType() || isBlockPointerType() || 3607 isObjCObjectPointerType() || isNullPtrType()); 3608} 3609 3610inline bool Type::hasObjCPointerRepresentation() const { 3611 return isObjCObjectPointerType(); 3612} 3613 3614/// Insertion operator for diagnostics. This allows sending QualType's into a 3615/// diagnostic with <<. 3616inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 3617 QualType T) { 3618 DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 3619 Diagnostic::ak_qualtype); 3620 return DB; 3621} 3622 3623/// Insertion operator for partial diagnostics. This allows sending QualType's 3624/// into a diagnostic with <<. 3625inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, 3626 QualType T) { 3627 PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 3628 Diagnostic::ak_qualtype); 3629 return PD; 3630} 3631 3632// Helper class template that is used by Type::getAs to ensure that one does 3633// not try to look through a qualified type to get to an array type. 3634template<typename T, 3635 bool isArrayType = (llvm::is_same<T, ArrayType>::value || 3636 llvm::is_base_of<ArrayType, T>::value)> 3637struct ArrayType_cannot_be_used_with_getAs { }; 3638 3639template<typename T> 3640struct ArrayType_cannot_be_used_with_getAs<T, true>; 3641 3642/// Member-template getAs<specific type>'. 3643template <typename T> const T *Type::getAs() const { 3644 ArrayType_cannot_be_used_with_getAs<T> at; 3645 (void)at; 3646 3647 // If this is directly a T type, return it. 3648 if (const T *Ty = dyn_cast<T>(this)) 3649 return Ty; 3650 3651 // If the canonical form of this type isn't the right kind, reject it. 3652 if (!isa<T>(CanonicalType)) 3653 return 0; 3654 3655 // If this is a typedef for the type, strip the typedef off without 3656 // losing all typedef information. 3657 return cast<T>(getUnqualifiedDesugaredType()); 3658} 3659 3660} // end namespace clang 3661 3662#endif 3663