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