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