clang  8.0.0svn
Type.h
Go to the documentation of this file.
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 /// \file
11 /// C Language Family Type Representation
12 ///
13 /// This file defines the clang::Type interface and subclasses, used to
14 /// represent types for languages in the C family.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_CLANG_AST_TYPE_H
19 #define LLVM_CLANG_AST_TYPE_H
20 
22 #include "clang/AST/TemplateName.h"
24 #include "clang/Basic/AttrKinds.h"
25 #include "clang/Basic/Diagnostic.h"
27 #include "clang/Basic/LLVM.h"
28 #include "clang/Basic/Linkage.h"
31 #include "clang/Basic/Specifiers.h"
32 #include "clang/Basic/Visibility.h"
33 #include "llvm/ADT/APInt.h"
34 #include "llvm/ADT/APSInt.h"
35 #include "llvm/ADT/ArrayRef.h"
36 #include "llvm/ADT/FoldingSet.h"
37 #include "llvm/ADT/None.h"
38 #include "llvm/ADT/Optional.h"
39 #include "llvm/ADT/PointerIntPair.h"
40 #include "llvm/ADT/PointerUnion.h"
41 #include "llvm/ADT/StringRef.h"
42 #include "llvm/ADT/Twine.h"
43 #include "llvm/ADT/iterator_range.h"
44 #include "llvm/Support/Casting.h"
45 #include "llvm/Support/Compiler.h"
46 #include "llvm/Support/ErrorHandling.h"
47 #include "llvm/Support/PointerLikeTypeTraits.h"
48 #include "llvm/Support/type_traits.h"
49 #include "llvm/Support/TrailingObjects.h"
50 #include <cassert>
51 #include <cstddef>
52 #include <cstdint>
53 #include <cstring>
54 #include <string>
55 #include <type_traits>
56 #include <utility>
57 
58 namespace clang {
59 
60 class ExtQuals;
61 class QualType;
62 class TagDecl;
63 class Type;
64 
65 enum {
68 };
69 
70 } // namespace clang
71 
72 namespace llvm {
73 
74  template <typename T>
75  struct PointerLikeTypeTraits;
76  template<>
78  static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
79 
81  return static_cast< ::clang::Type*>(P);
82  }
83 
84  enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
85  };
86 
87  template<>
89  static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
90 
91  static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
92  return static_cast< ::clang::ExtQuals*>(P);
93  }
94 
95  enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
96  };
97 
98  template <>
99  struct isPodLike<clang::QualType> { static const bool value = true; };
100 
101 } // namespace llvm
102 
103 namespace clang {
104 
105 class ASTContext;
106 template <typename> class CanQual;
107 class CXXRecordDecl;
108 class DeclContext;
109 class EnumDecl;
110 class Expr;
111 class ExtQualsTypeCommonBase;
112 class FunctionDecl;
113 class IdentifierInfo;
114 class NamedDecl;
115 class ObjCInterfaceDecl;
116 class ObjCProtocolDecl;
117 class ObjCTypeParamDecl;
118 struct PrintingPolicy;
119 class RecordDecl;
120 class Stmt;
121 class TagDecl;
122 class TemplateArgument;
123 class TemplateArgumentListInfo;
124 class TemplateArgumentLoc;
125 class TemplateTypeParmDecl;
126 class TypedefNameDecl;
127 class UnresolvedUsingTypenameDecl;
128 
129 using CanQualType = CanQual<Type>;
130 
131 // Provide forward declarations for all of the *Type classes.
132 #define TYPE(Class, Base) class Class##Type;
133 #include "clang/AST/TypeNodes.def"
134 
135 /// The collection of all-type qualifiers we support.
136 /// Clang supports five independent qualifiers:
137 /// * C99: const, volatile, and restrict
138 /// * MS: __unaligned
139 /// * Embedded C (TR18037): address spaces
140 /// * Objective C: the GC attributes (none, weak, or strong)
141 class Qualifiers {
142 public:
143  enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
144  Const = 0x1,
145  Restrict = 0x2,
146  Volatile = 0x4,
147  CVRMask = Const | Volatile | Restrict
148  };
149 
150  enum GC {
151  GCNone = 0,
153  Strong
154  };
155 
157  /// There is no lifetime qualification on this type.
159 
160  /// This object can be modified without requiring retains or
161  /// releases.
163 
164  /// Assigning into this object requires the old value to be
165  /// released and the new value to be retained. The timing of the
166  /// release of the old value is inexact: it may be moved to
167  /// immediately after the last known point where the value is
168  /// live.
170 
171  /// Reading or writing from this object requires a barrier call.
173 
174  /// Assigning into this object requires a lifetime extension.
175  OCL_Autoreleasing
176  };
177 
178  enum {
179  /// The maximum supported address space number.
180  /// 23 bits should be enough for anyone.
181  MaxAddressSpace = 0x7fffffu,
182 
183  /// The width of the "fast" qualifier mask.
184  FastWidth = 3,
185 
186  /// The fast qualifier mask.
187  FastMask = (1 << FastWidth) - 1
188  };
189 
190  /// Returns the common set of qualifiers while removing them from
191  /// the given sets.
193  // If both are only CVR-qualified, bit operations are sufficient.
194  if (!(L.Mask & ~CVRMask) && !(R.Mask & ~CVRMask)) {
195  Qualifiers Q;
196  Q.Mask = L.Mask & R.Mask;
197  L.Mask &= ~Q.Mask;
198  R.Mask &= ~Q.Mask;
199  return Q;
200  }
201 
202  Qualifiers Q;
203  unsigned CommonCRV = L.getCVRQualifiers() & R.getCVRQualifiers();
204  Q.addCVRQualifiers(CommonCRV);
205  L.removeCVRQualifiers(CommonCRV);
206  R.removeCVRQualifiers(CommonCRV);
207 
208  if (L.getObjCGCAttr() == R.getObjCGCAttr()) {
210  L.removeObjCGCAttr();
211  R.removeObjCGCAttr();
212  }
213 
214  if (L.getObjCLifetime() == R.getObjCLifetime()) {
216  L.removeObjCLifetime();
217  R.removeObjCLifetime();
218  }
219 
220  if (L.getAddressSpace() == R.getAddressSpace()) {
222  L.removeAddressSpace();
223  R.removeAddressSpace();
224  }
225  return Q;
226  }
227 
228  static Qualifiers fromFastMask(unsigned Mask) {
229  Qualifiers Qs;
230  Qs.addFastQualifiers(Mask);
231  return Qs;
232  }
233 
234  static Qualifiers fromCVRMask(unsigned CVR) {
235  Qualifiers Qs;
236  Qs.addCVRQualifiers(CVR);
237  return Qs;
238  }
239 
240  static Qualifiers fromCVRUMask(unsigned CVRU) {
241  Qualifiers Qs;
242  Qs.addCVRUQualifiers(CVRU);
243  return Qs;
244  }
245 
246  // Deserialize qualifiers from an opaque representation.
247  static Qualifiers fromOpaqueValue(unsigned opaque) {
248  Qualifiers Qs;
249  Qs.Mask = opaque;
250  return Qs;
251  }
252 
253  // Serialize these qualifiers into an opaque representation.
254  unsigned getAsOpaqueValue() const {
255  return Mask;
256  }
257 
258  bool hasConst() const { return Mask & Const; }
259  void setConst(bool flag) {
260  Mask = (Mask & ~Const) | (flag ? Const : 0);
261  }
262  void removeConst() { Mask &= ~Const; }
263  void addConst() { Mask |= Const; }
264 
265  bool hasVolatile() const { return Mask & Volatile; }
266  void setVolatile(bool flag) {
267  Mask = (Mask & ~Volatile) | (flag ? Volatile : 0);
268  }
269  void removeVolatile() { Mask &= ~Volatile; }
270  void addVolatile() { Mask |= Volatile; }
271 
272  bool hasRestrict() const { return Mask & Restrict; }
273  void setRestrict(bool flag) {
274  Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
275  }
276  void removeRestrict() { Mask &= ~Restrict; }
277  void addRestrict() { Mask |= Restrict; }
278 
279  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
280  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
281  void setCVRQualifiers(unsigned mask) {
282  assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
283  Mask = (Mask & ~CVRMask) | mask;
284  }
285  void removeCVRQualifiers(unsigned mask) {
286  assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
287  Mask &= ~mask;
288  }
290  removeCVRQualifiers(CVRMask);
291  }
292  void addCVRQualifiers(unsigned mask) {
293  assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
294  Mask |= mask;
295  }
296  void addCVRUQualifiers(unsigned mask) {
297  assert(!(mask & ~CVRMask & ~UMask) && "bitmask contains non-CVRU bits");
298  Mask |= mask;
299  }
300 
301  bool hasUnaligned() const { return Mask & UMask; }
302  void setUnaligned(bool flag) {
303  Mask = (Mask & ~UMask) | (flag ? UMask : 0);
304  }
305  void removeUnaligned() { Mask &= ~UMask; }
306  void addUnaligned() { Mask |= UMask; }
307 
308  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
309  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
311  Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
312  }
313  void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
315  assert(type);
316  setObjCGCAttr(type);
317  }
319  Qualifiers qs = *this;
320  qs.removeObjCGCAttr();
321  return qs;
322  }
324  Qualifiers qs = *this;
325  qs.removeObjCLifetime();
326  return qs;
327  }
328 
329  bool hasObjCLifetime() const { return Mask & LifetimeMask; }
331  return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
332  }
334  Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
335  }
336  void removeObjCLifetime() { setObjCLifetime(OCL_None); }
338  assert(type);
339  assert(!hasObjCLifetime());
340  Mask |= (type << LifetimeShift);
341  }
342 
343  /// True if the lifetime is neither None or ExplicitNone.
345  ObjCLifetime lifetime = getObjCLifetime();
346  return (lifetime > OCL_ExplicitNone);
347  }
348 
349  /// True if the lifetime is either strong or weak.
351  ObjCLifetime lifetime = getObjCLifetime();
352  return (lifetime == OCL_Strong || lifetime == OCL_Weak);
353  }
354 
355  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
357  return static_cast<LangAS>(Mask >> AddressSpaceShift);
358  }
360  return isTargetAddressSpace(getAddressSpace());
361  }
362  /// Get the address space attribute value to be printed by diagnostics.
364  auto Addr = getAddressSpace();
365  // This function is not supposed to be used with language specific
366  // address spaces. If that happens, the diagnostic message should consider
367  // printing the QualType instead of the address space value.
368  assert(Addr == LangAS::Default || hasTargetSpecificAddressSpace());
369  if (Addr != LangAS::Default)
370  return toTargetAddressSpace(Addr);
371  // TODO: The diagnostic messages where Addr may be 0 should be fixed
372  // since it cannot differentiate the situation where 0 denotes the default
373  // address space or user specified __attribute__((address_space(0))).
374  return 0;
375  }
376  void setAddressSpace(LangAS space) {
377  assert((unsigned)space <= MaxAddressSpace);
378  Mask = (Mask & ~AddressSpaceMask)
379  | (((uint32_t) space) << AddressSpaceShift);
380  }
381  void removeAddressSpace() { setAddressSpace(LangAS::Default); }
382  void addAddressSpace(LangAS space) {
383  assert(space != LangAS::Default);
384  setAddressSpace(space);
385  }
386 
387  // Fast qualifiers are those that can be allocated directly
388  // on a QualType object.
389  bool hasFastQualifiers() const { return getFastQualifiers(); }
390  unsigned getFastQualifiers() const { return Mask & FastMask; }
391  void setFastQualifiers(unsigned mask) {
392  assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
393  Mask = (Mask & ~FastMask) | mask;
394  }
395  void removeFastQualifiers(unsigned mask) {
396  assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
397  Mask &= ~mask;
398  }
400  removeFastQualifiers(FastMask);
401  }
402  void addFastQualifiers(unsigned mask) {
403  assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
404  Mask |= mask;
405  }
406 
407  /// Return true if the set contains any qualifiers which require an ExtQuals
408  /// node to be allocated.
409  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
411  Qualifiers Quals = *this;
412  Quals.setFastQualifiers(0);
413  return Quals;
414  }
415 
416  /// Return true if the set contains any qualifiers.
417  bool hasQualifiers() const { return Mask; }
418  bool empty() const { return !Mask; }
419 
420  /// Add the qualifiers from the given set to this set.
422  // If the other set doesn't have any non-boolean qualifiers, just
423  // bit-or it in.
424  if (!(Q.Mask & ~CVRMask))
425  Mask |= Q.Mask;
426  else {
427  Mask |= (Q.Mask & CVRMask);
428  if (Q.hasAddressSpace())
429  addAddressSpace(Q.getAddressSpace());
430  if (Q.hasObjCGCAttr())
431  addObjCGCAttr(Q.getObjCGCAttr());
432  if (Q.hasObjCLifetime())
433  addObjCLifetime(Q.getObjCLifetime());
434  }
435  }
436 
437  /// Remove the qualifiers from the given set from this set.
439  // If the other set doesn't have any non-boolean qualifiers, just
440  // bit-and the inverse in.
441  if (!(Q.Mask & ~CVRMask))
442  Mask &= ~Q.Mask;
443  else {
444  Mask &= ~(Q.Mask & CVRMask);
445  if (getObjCGCAttr() == Q.getObjCGCAttr())
446  removeObjCGCAttr();
447  if (getObjCLifetime() == Q.getObjCLifetime())
448  removeObjCLifetime();
449  if (getAddressSpace() == Q.getAddressSpace())
450  removeAddressSpace();
451  }
452  }
453 
454  /// Add the qualifiers from the given set to this set, given that
455  /// they don't conflict.
457  assert(getAddressSpace() == qs.getAddressSpace() ||
458  !hasAddressSpace() || !qs.hasAddressSpace());
459  assert(getObjCGCAttr() == qs.getObjCGCAttr() ||
460  !hasObjCGCAttr() || !qs.hasObjCGCAttr());
461  assert(getObjCLifetime() == qs.getObjCLifetime() ||
462  !hasObjCLifetime() || !qs.hasObjCLifetime());
463  Mask |= qs.Mask;
464  }
465 
466  /// Returns true if this address space is a superset of the other one.
467  /// OpenCL v2.0 defines conversion rules (OpenCLC v2.0 s6.5.5) and notion of
468  /// overlapping address spaces.
469  /// CL1.1 or CL1.2:
470  /// every address space is a superset of itself.
471  /// CL2.0 adds:
472  /// __generic is a superset of any address space except for __constant.
474  return
475  // Address spaces must match exactly.
476  getAddressSpace() == other.getAddressSpace() ||
477  // Otherwise in OpenCLC v2.0 s6.5.5: every address space except
478  // for __constant can be used as __generic.
479  (getAddressSpace() == LangAS::opencl_generic &&
481  }
482 
483  /// Determines if these qualifiers compatibly include another set.
484  /// Generally this answers the question of whether an object with the other
485  /// qualifiers can be safely used as an object with these qualifiers.
486  bool compatiblyIncludes(Qualifiers other) const {
487  return isAddressSpaceSupersetOf(other) &&
488  // ObjC GC qualifiers can match, be added, or be removed, but can't
489  // be changed.
490  (getObjCGCAttr() == other.getObjCGCAttr() || !hasObjCGCAttr() ||
491  !other.hasObjCGCAttr()) &&
492  // ObjC lifetime qualifiers must match exactly.
493  getObjCLifetime() == other.getObjCLifetime() &&
494  // CVR qualifiers may subset.
495  (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) &&
496  // U qualifier may superset.
497  (!other.hasUnaligned() || hasUnaligned());
498  }
499 
500  /// Determines if these qualifiers compatibly include another set of
501  /// qualifiers from the narrow perspective of Objective-C ARC lifetime.
502  ///
503  /// One set of Objective-C lifetime qualifiers compatibly includes the other
504  /// if the lifetime qualifiers match, or if both are non-__weak and the
505  /// including set also contains the 'const' qualifier, or both are non-__weak
506  /// and one is None (which can only happen in non-ARC modes).
508  if (getObjCLifetime() == other.getObjCLifetime())
509  return true;
510 
511  if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak)
512  return false;
513 
514  if (getObjCLifetime() == OCL_None || other.getObjCLifetime() == OCL_None)
515  return true;
516 
517  return hasConst();
518  }
519 
520  /// Determine whether this set of qualifiers is a strict superset of
521  /// another set of qualifiers, not considering qualifier compatibility.
522  bool isStrictSupersetOf(Qualifiers Other) const;
523 
524  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
525  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
526 
527  explicit operator bool() const { return hasQualifiers(); }
528 
530  addQualifiers(R);
531  return *this;
532  }
533 
534  // Union two qualifier sets. If an enumerated qualifier appears
535  // in both sets, use the one from the right.
537  L += R;
538  return L;
539  }
540 
542  removeQualifiers(R);
543  return *this;
544  }
545 
546  /// Compute the difference between two qualifier sets.
548  L -= R;
549  return L;
550  }
551 
552  std::string getAsString() const;
553  std::string getAsString(const PrintingPolicy &Policy) const;
554 
555  bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const;
556  void print(raw_ostream &OS, const PrintingPolicy &Policy,
557  bool appendSpaceIfNonEmpty = false) const;
558 
559  void Profile(llvm::FoldingSetNodeID &ID) const {
560  ID.AddInteger(Mask);
561  }
562 
563 private:
564  // bits: |0 1 2|3|4 .. 5|6 .. 8|9 ... 31|
565  // |C R V|U|GCAttr|Lifetime|AddressSpace|
566  uint32_t Mask = 0;
567 
568  static const uint32_t UMask = 0x8;
569  static const uint32_t UShift = 3;
570  static const uint32_t GCAttrMask = 0x30;
571  static const uint32_t GCAttrShift = 4;
572  static const uint32_t LifetimeMask = 0x1C0;
573  static const uint32_t LifetimeShift = 6;
574  static const uint32_t AddressSpaceMask =
575  ~(CVRMask | UMask | GCAttrMask | LifetimeMask);
576  static const uint32_t AddressSpaceShift = 9;
577 };
578 
579 /// A std::pair-like structure for storing a qualified type split
580 /// into its local qualifiers and its locally-unqualified type.
582  /// The locally-unqualified type.
583  const Type *Ty = nullptr;
584 
585  /// The local qualifiers.
587 
588  SplitQualType() = default;
589  SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {}
590 
591  SplitQualType getSingleStepDesugaredType() const; // end of this file
592 
593  // Make std::tie work.
594  std::pair<const Type *,Qualifiers> asPair() const {
595  return std::pair<const Type *, Qualifiers>(Ty, Quals);
596  }
597 
599  return a.Ty == b.Ty && a.Quals == b.Quals;
600  }
602  return a.Ty != b.Ty || a.Quals != b.Quals;
603  }
604 };
605 
606 /// The kind of type we are substituting Objective-C type arguments into.
607 ///
608 /// The kind of substitution affects the replacement of type parameters when
609 /// no concrete type information is provided, e.g., when dealing with an
610 /// unspecialized type.
612  /// An ordinary type.
613  Ordinary,
614 
615  /// The result type of a method or function.
616  Result,
617 
618  /// The parameter type of a method or function.
619  Parameter,
620 
621  /// The type of a property.
622  Property,
623 
624  /// The superclass of a type.
625  Superclass,
626 };
627 
628 /// A (possibly-)qualified type.
629 ///
630 /// For efficiency, we don't store CV-qualified types as nodes on their
631 /// own: instead each reference to a type stores the qualifiers. This
632 /// greatly reduces the number of nodes we need to allocate for types (for
633 /// example we only need one for 'int', 'const int', 'volatile int',
634 /// 'const volatile int', etc).
635 ///
636 /// As an added efficiency bonus, instead of making this a pair, we
637 /// just store the two bits we care about in the low bits of the
638 /// pointer. To handle the packing/unpacking, we make QualType be a
639 /// simple wrapper class that acts like a smart pointer. A third bit
640 /// indicates whether there are extended qualifiers present, in which
641 /// case the pointer points to a special structure.
642 class QualType {
643  friend class QualifierCollector;
644 
645  // Thankfully, these are efficiently composable.
646  llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>,
648 
649  const ExtQuals *getExtQualsUnsafe() const {
650  return Value.getPointer().get<const ExtQuals*>();
651  }
652 
653  const Type *getTypePtrUnsafe() const {
654  return Value.getPointer().get<const Type*>();
655  }
656 
657  const ExtQualsTypeCommonBase *getCommonPtr() const {
658  assert(!isNull() && "Cannot retrieve a NULL type pointer");
659  auto CommonPtrVal = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
660  CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
661  return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
662  }
663 
664 public:
665  QualType() = default;
666  QualType(const Type *Ptr, unsigned Quals) : Value(Ptr, Quals) {}
667  QualType(const ExtQuals *Ptr, unsigned Quals) : Value(Ptr, Quals) {}
668 
669  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
670  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
671 
672  /// Retrieves a pointer to the underlying (unqualified) type.
673  ///
674  /// This function requires that the type not be NULL. If the type might be
675  /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
676  const Type *getTypePtr() const;
677 
678  const Type *getTypePtrOrNull() const;
679 
680  /// Retrieves a pointer to the name of the base type.
681  const IdentifierInfo *getBaseTypeIdentifier() const;
682 
683  /// Divides a QualType into its unqualified type and a set of local
684  /// qualifiers.
685  SplitQualType split() const;
686 
687  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
688 
689  static QualType getFromOpaquePtr(const void *Ptr) {
690  QualType T;
691  T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
692  return T;
693  }
694 
695  const Type &operator*() const {
696  return *getTypePtr();
697  }
698 
699  const Type *operator->() const {
700  return getTypePtr();
701  }
702 
703  bool isCanonical() const;
704  bool isCanonicalAsParam() const;
705 
706  /// Return true if this QualType doesn't point to a type yet.
707  bool isNull() const {
708  return Value.getPointer().isNull();
709  }
710 
711  /// Determine whether this particular QualType instance has the
712  /// "const" qualifier set, without looking through typedefs that may have
713  /// added "const" at a different level.
714  bool isLocalConstQualified() const {
715  return (getLocalFastQualifiers() & Qualifiers::Const);
716  }
717 
718  /// Determine whether this type is const-qualified.
719  bool isConstQualified() const;
720 
721  /// Determine whether this particular QualType instance has the
722  /// "restrict" qualifier set, without looking through typedefs that may have
723  /// added "restrict" at a different level.
725  return (getLocalFastQualifiers() & Qualifiers::Restrict);
726  }
727 
728  /// Determine whether this type is restrict-qualified.
729  bool isRestrictQualified() const;
730 
731  /// Determine whether this particular QualType instance has the
732  /// "volatile" qualifier set, without looking through typedefs that may have
733  /// added "volatile" at a different level.
735  return (getLocalFastQualifiers() & Qualifiers::Volatile);
736  }
737 
738  /// Determine whether this type is volatile-qualified.
739  bool isVolatileQualified() const;
740 
741  /// Determine whether this particular QualType instance has any
742  /// qualifiers, without looking through any typedefs that might add
743  /// qualifiers at a different level.
744  bool hasLocalQualifiers() const {
745  return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
746  }
747 
748  /// Determine whether this type has any qualifiers.
749  bool hasQualifiers() const;
750 
751  /// Determine whether this particular QualType instance has any
752  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
753  /// instance.
755  return Value.getPointer().is<const ExtQuals*>();
756  }
757 
758  /// Retrieve the set of qualifiers local to this particular QualType
759  /// instance, not including any qualifiers acquired through typedefs or
760  /// other sugar.
761  Qualifiers getLocalQualifiers() const;
762 
763  /// Retrieve the set of qualifiers applied to this type.
764  Qualifiers getQualifiers() const;
765 
766  /// Retrieve the set of CVR (const-volatile-restrict) qualifiers
767  /// local to this particular QualType instance, not including any qualifiers
768  /// acquired through typedefs or other sugar.
769  unsigned getLocalCVRQualifiers() const {
770  return getLocalFastQualifiers();
771  }
772 
773  /// Retrieve the set of CVR (const-volatile-restrict) qualifiers
774  /// applied to this type.
775  unsigned getCVRQualifiers() const;
776 
777  bool isConstant(const ASTContext& Ctx) const {
778  return QualType::isConstant(*this, Ctx);
779  }
780 
781  /// Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
782  bool isPODType(const ASTContext &Context) const;
783 
784  /// Return true if this is a POD type according to the rules of the C++98
785  /// standard, regardless of the current compilation's language.
786  bool isCXX98PODType(const ASTContext &Context) const;
787 
788  /// Return true if this is a POD type according to the more relaxed rules
789  /// of the C++11 standard, regardless of the current compilation's language.
790  /// (C++0x [basic.types]p9). Note that, unlike
791  /// CXXRecordDecl::isCXX11StandardLayout, this takes DRs into account.
792  bool isCXX11PODType(const ASTContext &Context) const;
793 
794  /// Return true if this is a trivial type per (C++0x [basic.types]p9)
795  bool isTrivialType(const ASTContext &Context) const;
796 
797  /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
798  bool isTriviallyCopyableType(const ASTContext &Context) const;
799 
800 
801  /// Returns true if it is a class and it might be dynamic.
802  bool mayBeDynamicClass() const;
803 
804  /// Returns true if it is not a class or if the class might not be dynamic.
805  bool mayBeNotDynamicClass() const;
806 
807  // Don't promise in the API that anything besides 'const' can be
808  // easily added.
809 
810  /// Add the `const` type qualifier to this QualType.
811  void addConst() {
812  addFastQualifiers(Qualifiers::Const);
813  }
814  QualType withConst() const {
815  return withFastQualifiers(Qualifiers::Const);
816  }
817 
818  /// Add the `volatile` type qualifier to this QualType.
819  void addVolatile() {
820  addFastQualifiers(Qualifiers::Volatile);
821  }
823  return withFastQualifiers(Qualifiers::Volatile);
824  }
825 
826  /// Add the `restrict` qualifier to this QualType.
827  void addRestrict() {
828  addFastQualifiers(Qualifiers::Restrict);
829  }
831  return withFastQualifiers(Qualifiers::Restrict);
832  }
833 
834  QualType withCVRQualifiers(unsigned CVR) const {
835  return withFastQualifiers(CVR);
836  }
837 
838  void addFastQualifiers(unsigned TQs) {
839  assert(!(TQs & ~Qualifiers::FastMask)
840  && "non-fast qualifier bits set in mask!");
841  Value.setInt(Value.getInt() | TQs);
842  }
843 
844  void removeLocalConst();
845  void removeLocalVolatile();
846  void removeLocalRestrict();
847  void removeLocalCVRQualifiers(unsigned Mask);
848 
849  void removeLocalFastQualifiers() { Value.setInt(0); }
850  void removeLocalFastQualifiers(unsigned Mask) {
851  assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
852  Value.setInt(Value.getInt() & ~Mask);
853  }
854 
855  // Creates a type with the given qualifiers in addition to any
856  // qualifiers already on this type.
857  QualType withFastQualifiers(unsigned TQs) const {
858  QualType T = *this;
859  T.addFastQualifiers(TQs);
860  return T;
861  }
862 
863  // Creates a type with exactly the given fast qualifiers, removing
864  // any existing fast qualifiers.
866  return withoutLocalFastQualifiers().withFastQualifiers(TQs);
867  }
868 
869  // Removes fast qualifiers, but leaves any extended qualifiers in place.
871  QualType T = *this;
873  return T;
874  }
875 
876  QualType getCanonicalType() const;
877 
878  /// Return this type with all of the instance-specific qualifiers
879  /// removed, but without removing any qualifiers that may have been applied
880  /// through typedefs.
881  QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
882 
883  /// Retrieve the unqualified variant of the given type,
884  /// removing as little sugar as possible.
885  ///
886  /// This routine looks through various kinds of sugar to find the
887  /// least-desugared type that is unqualified. For example, given:
888  ///
889  /// \code
890  /// typedef int Integer;
891  /// typedef const Integer CInteger;
892  /// typedef CInteger DifferenceType;
893  /// \endcode
894  ///
895  /// Executing \c getUnqualifiedType() on the type \c DifferenceType will
896  /// desugar until we hit the type \c Integer, which has no qualifiers on it.
897  ///
898  /// The resulting type might still be qualified if it's sugar for an array
899  /// type. To strip qualifiers even from within a sugared array type, use
900  /// ASTContext::getUnqualifiedArrayType.
901  inline QualType getUnqualifiedType() const;
902 
903  /// Retrieve the unqualified variant of the given type, removing as little
904  /// sugar as possible.
905  ///
906  /// Like getUnqualifiedType(), but also returns the set of
907  /// qualifiers that were built up.
908  ///
909  /// The resulting type might still be qualified if it's sugar for an array
910  /// type. To strip qualifiers even from within a sugared array type, use
911  /// ASTContext::getUnqualifiedArrayType.
912  inline SplitQualType getSplitUnqualifiedType() const;
913 
914  /// Determine whether this type is more qualified than the other
915  /// given type, requiring exact equality for non-CVR qualifiers.
916  bool isMoreQualifiedThan(QualType Other) const;
917 
918  /// Determine whether this type is at least as qualified as the other
919  /// given type, requiring exact equality for non-CVR qualifiers.
920  bool isAtLeastAsQualifiedAs(QualType Other) const;
921 
922  QualType getNonReferenceType() const;
923 
924  /// Determine the type of a (typically non-lvalue) expression with the
925  /// specified result type.
926  ///
927  /// This routine should be used for expressions for which the return type is
928  /// explicitly specified (e.g., in a cast or call) and isn't necessarily
929  /// an lvalue. It removes a top-level reference (since there are no
930  /// expressions of reference type) and deletes top-level cvr-qualifiers
931  /// from non-class types (in C++) or all types (in C).
932  QualType getNonLValueExprType(const ASTContext &Context) const;
933 
934  /// Return the specified type with any "sugar" removed from
935  /// the type. This takes off typedefs, typeof's etc. If the outer level of
936  /// the type is already concrete, it returns it unmodified. This is similar
937  /// to getting the canonical type, but it doesn't remove *all* typedefs. For
938  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
939  /// concrete.
940  ///
941  /// Qualifiers are left in place.
942  QualType getDesugaredType(const ASTContext &Context) const {
943  return getDesugaredType(*this, Context);
944  }
945 
947  return getSplitDesugaredType(*this);
948  }
949 
950  /// Return the specified type with one level of "sugar" removed from
951  /// the type.
952  ///
953  /// This routine takes off the first typedef, typeof, etc. If the outer level
954  /// of the type is already concrete, it returns it unmodified.
956  return getSingleStepDesugaredTypeImpl(*this, Context);
957  }
958 
959  /// Returns the specified type after dropping any
960  /// outer-level parentheses.
962  if (isa<ParenType>(*this))
963  return QualType::IgnoreParens(*this);
964  return *this;
965  }
966 
967  /// Indicate whether the specified types and qualifiers are identical.
968  friend bool operator==(const QualType &LHS, const QualType &RHS) {
969  return LHS.Value == RHS.Value;
970  }
971  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
972  return LHS.Value != RHS.Value;
973  }
974 
975  static std::string getAsString(SplitQualType split,
976  const PrintingPolicy &Policy) {
977  return getAsString(split.Ty, split.Quals, Policy);
978  }
979  static std::string getAsString(const Type *ty, Qualifiers qs,
980  const PrintingPolicy &Policy);
981 
982  std::string getAsString() const;
983  std::string getAsString(const PrintingPolicy &Policy) const;
984 
985  void print(raw_ostream &OS, const PrintingPolicy &Policy,
986  const Twine &PlaceHolder = Twine(),
987  unsigned Indentation = 0) const {
988  print(split(), OS, Policy, PlaceHolder, Indentation);
989  }
990 
991  static void print(SplitQualType split, raw_ostream &OS,
992  const PrintingPolicy &policy, const Twine &PlaceHolder,
993  unsigned Indentation = 0) {
994  return print(split.Ty, split.Quals, OS, policy, PlaceHolder, Indentation);
995  }
996 
997  static void print(const Type *ty, Qualifiers qs,
998  raw_ostream &OS, const PrintingPolicy &policy,
999  const Twine &PlaceHolder,
1000  unsigned Indentation = 0);
1001 
1002  void getAsStringInternal(std::string &Str,
1003  const PrintingPolicy &Policy) const {
1004  return getAsStringInternal(split(), Str, Policy);
1005  }
1006 
1007  static void getAsStringInternal(SplitQualType split, std::string &out,
1008  const PrintingPolicy &policy) {
1009  return getAsStringInternal(split.Ty, split.Quals, out, policy);
1010  }
1011 
1012  static void getAsStringInternal(const Type *ty, Qualifiers qs,
1013  std::string &out,
1014  const PrintingPolicy &policy);
1015 
1017  const QualType &T;
1018  const PrintingPolicy &Policy;
1019  const Twine &PlaceHolder;
1020  unsigned Indentation;
1021 
1022  public:
1024  const Twine &PlaceHolder, unsigned Indentation)
1025  : T(T), Policy(Policy), PlaceHolder(PlaceHolder),
1026  Indentation(Indentation) {}
1027 
1028  friend raw_ostream &operator<<(raw_ostream &OS,
1029  const StreamedQualTypeHelper &SQT) {
1030  SQT.T.print(OS, SQT.Policy, SQT.PlaceHolder, SQT.Indentation);
1031  return OS;
1032  }
1033  };
1034 
1036  const Twine &PlaceHolder = Twine(),
1037  unsigned Indentation = 0) const {
1038  return StreamedQualTypeHelper(*this, Policy, PlaceHolder, Indentation);
1039  }
1040 
1041  void dump(const char *s) const;
1042  void dump() const;
1043  void dump(llvm::raw_ostream &OS) const;
1044 
1045  void Profile(llvm::FoldingSetNodeID &ID) const {
1046  ID.AddPointer(getAsOpaquePtr());
1047  }
1048 
1049  /// Return the address space of this type.
1050  inline LangAS getAddressSpace() const;
1051 
1052  /// Returns gc attribute of this type.
1053  inline Qualifiers::GC getObjCGCAttr() const;
1054 
1055  /// true when Type is objc's weak.
1056  bool isObjCGCWeak() const {
1057  return getObjCGCAttr() == Qualifiers::Weak;
1058  }
1059 
1060  /// true when Type is objc's strong.
1061  bool isObjCGCStrong() const {
1062  return getObjCGCAttr() == Qualifiers::Strong;
1063  }
1064 
1065  /// Returns lifetime attribute of this type.
1067  return getQualifiers().getObjCLifetime();
1068  }
1069 
1071  return getQualifiers().hasNonTrivialObjCLifetime();
1072  }
1073 
1075  return getQualifiers().hasStrongOrWeakObjCLifetime();
1076  }
1077 
1078  // true when Type is objc's weak and weak is enabled but ARC isn't.
1079  bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const;
1080 
1082  /// The type does not fall into any of the following categories. Note that
1083  /// this case is zero-valued so that values of this enum can be used as a
1084  /// boolean condition for non-triviality.
1086 
1087  /// The type is an Objective-C retainable pointer type that is qualified
1088  /// with the ARC __strong qualifier.
1090 
1091  /// The type is an Objective-C retainable pointer type that is qualified
1092  /// with the ARC __weak qualifier.
1094 
1095  /// The type is a struct containing a field whose type is not PCK_Trivial.
1096  PDIK_Struct
1097  };
1098 
1099  /// Functions to query basic properties of non-trivial C struct types.
1100 
1101  /// Check if this is a non-trivial type that would cause a C struct
1102  /// transitively containing this type to be non-trivial to default initialize
1103  /// and return the kind.
1105  isNonTrivialToPrimitiveDefaultInitialize() const;
1106 
1108  /// The type does not fall into any of the following categories. Note that
1109  /// this case is zero-valued so that values of this enum can be used as a
1110  /// boolean condition for non-triviality.
1112 
1113  /// The type would be trivial except that it is volatile-qualified. Types
1114  /// that fall into one of the other non-trivial cases may additionally be
1115  /// volatile-qualified.
1117 
1118  /// The type is an Objective-C retainable pointer type that is qualified
1119  /// with the ARC __strong qualifier.
1121 
1122  /// The type is an Objective-C retainable pointer type that is qualified
1123  /// with the ARC __weak qualifier.
1125 
1126  /// The type is a struct containing a field whose type is neither
1127  /// PCK_Trivial nor PCK_VolatileTrivial.
1128  /// Note that a C++ struct type does not necessarily match this; C++ copying
1129  /// semantics are too complex to express here, in part because they depend
1130  /// on the exact constructor or assignment operator that is chosen by
1131  /// overload resolution to do the copy.
1132  PCK_Struct
1133  };
1134 
1135  /// Check if this is a non-trivial type that would cause a C struct
1136  /// transitively containing this type to be non-trivial to copy and return the
1137  /// kind.
1138  PrimitiveCopyKind isNonTrivialToPrimitiveCopy() const;
1139 
1140  /// Check if this is a non-trivial type that would cause a C struct
1141  /// transitively containing this type to be non-trivial to destructively
1142  /// move and return the kind. Destructive move in this context is a C++-style
1143  /// move in which the source object is placed in a valid but unspecified state
1144  /// after it is moved, as opposed to a truly destructive move in which the
1145  /// source object is placed in an uninitialized state.
1146  PrimitiveCopyKind isNonTrivialToPrimitiveDestructiveMove() const;
1147 
1153  DK_nontrivial_c_struct
1154  };
1155 
1156  /// Returns a nonzero value if objects of this type require
1157  /// non-trivial work to clean up after. Non-zero because it's
1158  /// conceivable that qualifiers (objc_gc(weak)?) could make
1159  /// something require destruction.
1161  return isDestructedTypeImpl(*this);
1162  }
1163 
1164  /// Determine whether expressions of the given type are forbidden
1165  /// from being lvalues in C.
1166  ///
1167  /// The expression types that are forbidden to be lvalues are:
1168  /// - 'void', but not qualified void
1169  /// - function types
1170  ///
1171  /// The exact rule here is C99 6.3.2.1:
1172  /// An lvalue is an expression with an object type or an incomplete
1173  /// type other than void.
1174  bool isCForbiddenLValueType() const;
1175 
1176  /// Substitute type arguments for the Objective-C type parameters used in the
1177  /// subject type.
1178  ///
1179  /// \param ctx ASTContext in which the type exists.
1180  ///
1181  /// \param typeArgs The type arguments that will be substituted for the
1182  /// Objective-C type parameters in the subject type, which are generally
1183  /// computed via \c Type::getObjCSubstitutions. If empty, the type
1184  /// parameters will be replaced with their bounds or id/Class, as appropriate
1185  /// for the context.
1186  ///
1187  /// \param context The context in which the subject type was written.
1188  ///
1189  /// \returns the resulting type.
1190  QualType substObjCTypeArgs(ASTContext &ctx,
1191  ArrayRef<QualType> typeArgs,
1192  ObjCSubstitutionContext context) const;
1193 
1194  /// Substitute type arguments from an object type for the Objective-C type
1195  /// parameters used in the subject type.
1196  ///
1197  /// This operation combines the computation of type arguments for
1198  /// substitution (\c Type::getObjCSubstitutions) with the actual process of
1199  /// substitution (\c QualType::substObjCTypeArgs) for the convenience of
1200  /// callers that need to perform a single substitution in isolation.
1201  ///
1202  /// \param objectType The type of the object whose member type we're
1203  /// substituting into. For example, this might be the receiver of a message
1204  /// or the base of a property access.
1205  ///
1206  /// \param dc The declaration context from which the subject type was
1207  /// retrieved, which indicates (for example) which type parameters should
1208  /// be substituted.
1209  ///
1210  /// \param context The context in which the subject type was written.
1211  ///
1212  /// \returns the subject type after replacing all of the Objective-C type
1213  /// parameters with their corresponding arguments.
1214  QualType substObjCMemberType(QualType objectType,
1215  const DeclContext *dc,
1216  ObjCSubstitutionContext context) const;
1217 
1218  /// Strip Objective-C "__kindof" types from the given type.
1219  QualType stripObjCKindOfType(const ASTContext &ctx) const;
1220 
1221  /// Remove all qualifiers including _Atomic.
1222  QualType getAtomicUnqualifiedType() const;
1223 
1224 private:
1225  // These methods are implemented in a separate translation unit;
1226  // "static"-ize them to avoid creating temporary QualTypes in the
1227  // caller.
1228  static bool isConstant(QualType T, const ASTContext& Ctx);
1229  static QualType getDesugaredType(QualType T, const ASTContext &Context);
1230  static SplitQualType getSplitDesugaredType(QualType T);
1231  static SplitQualType getSplitUnqualifiedTypeImpl(QualType type);
1232  static QualType getSingleStepDesugaredTypeImpl(QualType type,
1233  const ASTContext &C);
1234  static QualType IgnoreParens(QualType T);
1235  static DestructionKind isDestructedTypeImpl(QualType type);
1236 };
1237 
1238 } // namespace clang
1239 
1240 namespace llvm {
1241 
1242 /// Implement simplify_type for QualType, so that we can dyn_cast from QualType
1243 /// to a specific Type class.
1244 template<> struct simplify_type< ::clang::QualType> {
1246 
1248  return Val.getTypePtr();
1249  }
1250 };
1251 
1252 // Teach SmallPtrSet that QualType is "basically a pointer".
1253 template<>
1254 struct PointerLikeTypeTraits<clang::QualType> {
1255  static inline void *getAsVoidPointer(clang::QualType P) {
1256  return P.getAsOpaquePtr();
1257  }
1258 
1259  static inline clang::QualType getFromVoidPointer(void *P) {
1261  }
1262 
1263  // Various qualifiers go in low bits.
1264  enum { NumLowBitsAvailable = 0 };
1265 };
1266 
1267 } // namespace llvm
1268 
1269 namespace clang {
1270 
1271 /// Base class that is common to both the \c ExtQuals and \c Type
1272 /// classes, which allows \c QualType to access the common fields between the
1273 /// two.
1275  friend class ExtQuals;
1276  friend class QualType;
1277  friend class Type;
1278 
1279  /// The "base" type of an extended qualifiers type (\c ExtQuals) or
1280  /// a self-referential pointer (for \c Type).
1281  ///
1282  /// This pointer allows an efficient mapping from a QualType to its
1283  /// underlying type pointer.
1284  const Type *const BaseType;
1285 
1286  /// The canonical type of this type. A QualType.
1287  QualType CanonicalType;
1288 
1289  ExtQualsTypeCommonBase(const Type *baseType, QualType canon)
1290  : BaseType(baseType), CanonicalType(canon) {}
1291 };
1292 
1293 /// We can encode up to four bits in the low bits of a
1294 /// type pointer, but there are many more type qualifiers that we want
1295 /// to be able to apply to an arbitrary type. Therefore we have this
1296 /// struct, intended to be heap-allocated and used by QualType to
1297 /// store qualifiers.
1298 ///
1299 /// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
1300 /// in three low bits on the QualType pointer; a fourth bit records whether
1301 /// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
1302 /// Objective-C GC attributes) are much more rare.
1303 class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode {
1304  // NOTE: changing the fast qualifiers should be straightforward as
1305  // long as you don't make 'const' non-fast.
1306  // 1. Qualifiers:
1307  // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
1308  // Fast qualifiers must occupy the low-order bits.
1309  // b) Update Qualifiers::FastWidth and FastMask.
1310  // 2. QualType:
1311  // a) Update is{Volatile,Restrict}Qualified(), defined inline.
1312  // b) Update remove{Volatile,Restrict}, defined near the end of
1313  // this header.
1314  // 3. ASTContext:
1315  // a) Update get{Volatile,Restrict}Type.
1316 
1317  /// The immutable set of qualifiers applied by this node. Always contains
1318  /// extended qualifiers.
1319  Qualifiers Quals;
1320 
1321  ExtQuals *this_() { return this; }
1322 
1323 public:
1324  ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
1325  : ExtQualsTypeCommonBase(baseType,
1326  canon.isNull() ? QualType(this_(), 0) : canon),
1327  Quals(quals) {
1328  assert(Quals.hasNonFastQualifiers()
1329  && "ExtQuals created with no fast qualifiers");
1330  assert(!Quals.hasFastQualifiers()
1331  && "ExtQuals created with fast qualifiers");
1332  }
1333 
1334  Qualifiers getQualifiers() const { return Quals; }
1335 
1336  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
1337  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
1338 
1339  bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); }
1341  return Quals.getObjCLifetime();
1342  }
1343 
1344  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
1345  LangAS getAddressSpace() const { return Quals.getAddressSpace(); }
1346 
1347  const Type *getBaseType() const { return BaseType; }
1348 
1349 public:
1350  void Profile(llvm::FoldingSetNodeID &ID) const {
1351  Profile(ID, getBaseType(), Quals);
1352  }
1353 
1354  static void Profile(llvm::FoldingSetNodeID &ID,
1355  const Type *BaseType,
1356  Qualifiers Quals) {
1357  assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
1358  ID.AddPointer(BaseType);
1359  Quals.Profile(ID);
1360  }
1361 };
1362 
1363 /// The kind of C++11 ref-qualifier associated with a function type.
1364 /// This determines whether a member function's "this" object can be an
1365 /// lvalue, rvalue, or neither.
1367  /// No ref-qualifier was provided.
1368  RQ_None = 0,
1369 
1370  /// An lvalue ref-qualifier was provided (\c &).
1372 
1373  /// An rvalue ref-qualifier was provided (\c &&).
1375 };
1376 
1377 /// Which keyword(s) were used to create an AutoType.
1378 enum class AutoTypeKeyword {
1379  /// auto
1380  Auto,
1381 
1382  /// decltype(auto)
1383  DecltypeAuto,
1384 
1385  /// __auto_type (GNU extension)
1386  GNUAutoType
1387 };
1388 
1389 /// The base class of the type hierarchy.
1390 ///
1391 /// A central concept with types is that each type always has a canonical
1392 /// type. A canonical type is the type with any typedef names stripped out
1393 /// of it or the types it references. For example, consider:
1394 ///
1395 /// typedef int foo;
1396 /// typedef foo* bar;
1397 /// 'int *' 'foo *' 'bar'
1398 ///
1399 /// There will be a Type object created for 'int'. Since int is canonical, its
1400 /// CanonicalType pointer points to itself. There is also a Type for 'foo' (a
1401 /// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next
1402 /// there is a PointerType that represents 'int*', which, like 'int', is
1403 /// canonical. Finally, there is a PointerType type for 'foo*' whose canonical
1404 /// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
1405 /// is also 'int*'.
1406 ///
1407 /// Non-canonical types are useful for emitting diagnostics, without losing
1408 /// information about typedefs being used. Canonical types are useful for type
1409 /// comparisons (they allow by-pointer equality tests) and useful for reasoning
1410 /// about whether something has a particular form (e.g. is a function type),
1411 /// because they implicitly, recursively, strip all typedefs out of a type.
1412 ///
1413 /// Types, once created, are immutable.
1414 ///
1416 public:
1417  enum TypeClass {
1418 #define TYPE(Class, Base) Class,
1419 #define LAST_TYPE(Class) TypeLast = Class,
1420 #define ABSTRACT_TYPE(Class, Base)
1421 #include "clang/AST/TypeNodes.def"
1422  TagFirst = Record, TagLast = Enum
1423  };
1424 
1425 private:
1426  /// Bitfields required by the Type class.
1427  class TypeBitfields {
1428  friend class Type;
1429  template <class T> friend class TypePropertyCache;
1430 
1431  /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
1432  unsigned TC : 8;
1433 
1434  /// Whether this type is a dependent type (C++ [temp.dep.type]).
1435  unsigned Dependent : 1;
1436 
1437  /// Whether this type somehow involves a template parameter, even
1438  /// if the resolution of the type does not depend on a template parameter.
1439  unsigned InstantiationDependent : 1;
1440 
1441  /// Whether this type is a variably-modified type (C99 6.7.5).
1442  unsigned VariablyModified : 1;
1443 
1444  /// Whether this type contains an unexpanded parameter pack
1445  /// (for C++11 variadic templates).
1446  unsigned ContainsUnexpandedParameterPack : 1;
1447 
1448  /// True if the cache (i.e. the bitfields here starting with
1449  /// 'Cache') is valid.
1450  mutable unsigned CacheValid : 1;
1451 
1452  /// Linkage of this type.
1453  mutable unsigned CachedLinkage : 3;
1454 
1455  /// Whether this type involves and local or unnamed types.
1456  mutable unsigned CachedLocalOrUnnamed : 1;
1457 
1458  /// Whether this type comes from an AST file.
1459  mutable unsigned FromAST : 1;
1460 
1461  bool isCacheValid() const {
1462  return CacheValid;
1463  }
1464 
1465  Linkage getLinkage() const {
1466  assert(isCacheValid() && "getting linkage from invalid cache");
1467  return static_cast<Linkage>(CachedLinkage);
1468  }
1469 
1470  bool hasLocalOrUnnamedType() const {
1471  assert(isCacheValid() && "getting linkage from invalid cache");
1472  return CachedLocalOrUnnamed;
1473  }
1474  };
1475  enum { NumTypeBits = 18 };
1476 
1477 protected:
1478  // These classes allow subclasses to somewhat cleanly pack bitfields
1479  // into Type.
1480 
1482  friend class ArrayType;
1483 
1484  unsigned : NumTypeBits;
1485 
1486  /// CVR qualifiers from declarations like
1487  /// 'int X[static restrict 4]'. For function parameters only.
1488  unsigned IndexTypeQuals : 3;
1489 
1490  /// Storage class qualifiers from declarations like
1491  /// 'int X[static restrict 4]'. For function parameters only.
1492  /// Actually an ArrayType::ArraySizeModifier.
1493  unsigned SizeModifier : 3;
1494  };
1495 
1497  friend class BuiltinType;
1498 
1499  unsigned : NumTypeBits;
1500 
1501  /// The kind (BuiltinType::Kind) of builtin type this is.
1502  unsigned Kind : 8;
1503  };
1504 
1505  /// FunctionTypeBitfields store various bits belonging to FunctionProtoType.
1506  /// Only common bits are stored here. Additional uncommon bits are stored
1507  /// in a trailing object after FunctionProtoType.
1509  friend class FunctionProtoType;
1510  friend class FunctionType;
1511 
1512  unsigned : NumTypeBits;
1513 
1514  /// Extra information which affects how the function is called, like
1515  /// regparm and the calling convention.
1516  unsigned ExtInfo : 12;
1517 
1518  /// The ref-qualifier associated with a \c FunctionProtoType.
1519  ///
1520  /// This is a value of type \c RefQualifierKind.
1521  unsigned RefQualifier : 2;
1522 
1523  /// Used only by FunctionProtoType, put here to pack with the
1524  /// other bitfields.
1525  /// The qualifiers are part of FunctionProtoType because...
1526  ///
1527  /// C++ 8.3.5p4: The return type, the parameter type list and the
1528  /// cv-qualifier-seq, [...], are part of the function type.
1529  unsigned TypeQuals : 4;
1530 
1531  /// The number of parameters this function has, not counting '...'.
1532  /// According to [implimits] 8 bits should be enough here but this is
1533  /// somewhat easy to exceed with metaprogramming and so we would like to
1534  /// keep NumParams as wide as reasonably possible.
1535  unsigned NumParams : 16;
1536 
1537  /// The type of exception specification this function has.
1538  unsigned ExceptionSpecType : 4;
1539 
1540  /// Whether this function has extended parameter information.
1541  unsigned HasExtParameterInfos : 1;
1542 
1543  /// Whether the function is variadic.
1544  unsigned Variadic : 1;
1545 
1546  /// Whether this function has a trailing return type.
1547  unsigned HasTrailingReturn : 1;
1548  };
1549 
1551  friend class ObjCObjectType;
1552 
1553  unsigned : NumTypeBits;
1554 
1555  /// The number of type arguments stored directly on this object type.
1556  unsigned NumTypeArgs : 7;
1557 
1558  /// The number of protocols stored directly on this object type.
1559  unsigned NumProtocols : 6;
1560 
1561  /// Whether this is a "kindof" type.
1562  unsigned IsKindOf : 1;
1563  };
1564 
1566  friend class ReferenceType;
1567 
1568  unsigned : NumTypeBits;
1569 
1570  /// True if the type was originally spelled with an lvalue sigil.
1571  /// This is never true of rvalue references but can also be false
1572  /// on lvalue references because of C++0x [dcl.typedef]p9,
1573  /// as follows:
1574  ///
1575  /// typedef int &ref; // lvalue, spelled lvalue
1576  /// typedef int &&rvref; // rvalue
1577  /// ref &a; // lvalue, inner ref, spelled lvalue
1578  /// ref &&a; // lvalue, inner ref
1579  /// rvref &a; // lvalue, inner ref, spelled lvalue
1580  /// rvref &&a; // rvalue, inner ref
1581  unsigned SpelledAsLValue : 1;
1582 
1583  /// True if the inner type is a reference type. This only happens
1584  /// in non-canonical forms.
1585  unsigned InnerRef : 1;
1586  };
1587 
1589  friend class TypeWithKeyword;
1590 
1591  unsigned : NumTypeBits;
1592 
1593  /// An ElaboratedTypeKeyword. 8 bits for efficient access.
1594  unsigned Keyword : 8;
1595  };
1596 
1597  enum { NumTypeWithKeywordBits = 8 };
1598 
1600  friend class ElaboratedType;
1601 
1602  unsigned : NumTypeBits;
1603  unsigned : NumTypeWithKeywordBits;
1604 
1605  /// Whether the ElaboratedType has a trailing OwnedTagDecl.
1606  unsigned HasOwnedTagDecl : 1;
1607  };
1608 
1610  friend class VectorType;
1611  friend class DependentVectorType;
1612 
1613  unsigned : NumTypeBits;
1614 
1615  /// The kind of vector, either a generic vector type or some
1616  /// target-specific vector type such as for AltiVec or Neon.
1617  unsigned VecKind : 3;
1618 
1619  /// The number of elements in the vector.
1620  unsigned NumElements : 29 - NumTypeBits;
1621 
1622  enum { MaxNumElements = (1 << (29 - NumTypeBits)) - 1 };
1623  };
1624 
1626  friend class AttributedType;
1627 
1628  unsigned : NumTypeBits;
1629 
1630  /// An AttributedType::Kind
1631  unsigned AttrKind : 32 - NumTypeBits;
1632  };
1633 
1635  friend class AutoType;
1636 
1637  unsigned : NumTypeBits;
1638 
1639  /// Was this placeholder type spelled as 'auto', 'decltype(auto)',
1640  /// or '__auto_type'? AutoTypeKeyword value.
1641  unsigned Keyword : 2;
1642  };
1643 
1646 
1647  unsigned : NumTypeBits;
1648 
1649  /// The number of template arguments in \c Arguments, which is
1650  /// expected to be able to hold at least 1024 according to [implimits].
1651  /// However as this limit is somewhat easy to hit with template
1652  /// metaprogramming we'd prefer to keep it as large as possible.
1653  /// At the moment it has been left as a non-bitfield since this type
1654  /// safely fits in 64 bits as an unsigned, so there is no reason to
1655  /// introduce the performance impact of a bitfield.
1656  unsigned NumArgs;
1657  };
1658 
1661 
1662  unsigned : NumTypeBits;
1663 
1664  /// Whether this template specialization type is a substituted type alias.
1665  unsigned TypeAlias : 1;
1666 
1667  /// The number of template arguments named in this class template
1668  /// specialization, which is expected to be able to hold at least 1024
1669  /// according to [implimits]. However, as this limit is somewhat easy to
1670  /// hit with template metaprogramming we'd prefer to keep it as large
1671  /// as possible. At the moment it has been left as a non-bitfield since
1672  /// this type safely fits in 64 bits as an unsigned, so there is no reason
1673  /// to introduce the performance impact of a bitfield.
1674  unsigned NumArgs;
1675  };
1676 
1679 
1680  unsigned : NumTypeBits;
1681  unsigned : NumTypeWithKeywordBits;
1682 
1683  /// The number of template arguments named in this class template
1684  /// specialization, which is expected to be able to hold at least 1024
1685  /// according to [implimits]. However, as this limit is somewhat easy to
1686  /// hit with template metaprogramming we'd prefer to keep it as large
1687  /// as possible. At the moment it has been left as a non-bitfield since
1688  /// this type safely fits in 64 bits as an unsigned, so there is no reason
1689  /// to introduce the performance impact of a bitfield.
1690  unsigned NumArgs;
1691  };
1692 
1694  friend class PackExpansionType;
1695 
1696  unsigned : NumTypeBits;
1697 
1698  /// The number of expansions that this pack expansion will
1699  /// generate when substituted (+1), which is expected to be able to
1700  /// hold at least 1024 according to [implimits]. However, as this limit
1701  /// is somewhat easy to hit with template metaprogramming we'd prefer to
1702  /// keep it as large as possible. At the moment it has been left as a
1703  /// non-bitfield since this type safely fits in 64 bits as an unsigned, so
1704  /// there is no reason to introduce the performance impact of a bitfield.
1705  ///
1706  /// This field will only have a non-zero value when some of the parameter
1707  /// packs that occur within the pattern have been substituted but others
1708  /// have not.
1709  unsigned NumExpansions;
1710  };
1711 
1712  union {
1713  TypeBitfields TypeBits;
1729 
1730  static_assert(sizeof(TypeBitfields) <= 8,
1731  "TypeBitfields is larger than 8 bytes!");
1732  static_assert(sizeof(ArrayTypeBitfields) <= 8,
1733  "ArrayTypeBitfields is larger than 8 bytes!");
1734  static_assert(sizeof(AttributedTypeBitfields) <= 8,
1735  "AttributedTypeBitfields is larger than 8 bytes!");
1736  static_assert(sizeof(AutoTypeBitfields) <= 8,
1737  "AutoTypeBitfields is larger than 8 bytes!");
1738  static_assert(sizeof(BuiltinTypeBitfields) <= 8,
1739  "BuiltinTypeBitfields is larger than 8 bytes!");
1740  static_assert(sizeof(FunctionTypeBitfields) <= 8,
1741  "FunctionTypeBitfields is larger than 8 bytes!");
1742  static_assert(sizeof(ObjCObjectTypeBitfields) <= 8,
1743  "ObjCObjectTypeBitfields is larger than 8 bytes!");
1744  static_assert(sizeof(ReferenceTypeBitfields) <= 8,
1745  "ReferenceTypeBitfields is larger than 8 bytes!");
1746  static_assert(sizeof(TypeWithKeywordBitfields) <= 8,
1747  "TypeWithKeywordBitfields is larger than 8 bytes!");
1748  static_assert(sizeof(ElaboratedTypeBitfields) <= 8,
1749  "ElaboratedTypeBitfields is larger than 8 bytes!");
1750  static_assert(sizeof(VectorTypeBitfields) <= 8,
1751  "VectorTypeBitfields is larger than 8 bytes!");
1752  static_assert(sizeof(SubstTemplateTypeParmPackTypeBitfields) <= 8,
1753  "SubstTemplateTypeParmPackTypeBitfields is larger"
1754  " than 8 bytes!");
1755  static_assert(sizeof(TemplateSpecializationTypeBitfields) <= 8,
1756  "TemplateSpecializationTypeBitfields is larger"
1757  " than 8 bytes!");
1758  static_assert(sizeof(DependentTemplateSpecializationTypeBitfields) <= 8,
1759  "DependentTemplateSpecializationTypeBitfields is larger"
1760  " than 8 bytes!");
1761  static_assert(sizeof(PackExpansionTypeBitfields) <= 8,
1762  "PackExpansionTypeBitfields is larger than 8 bytes");
1763  };
1764 
1765 private:
1766  template <class T> friend class TypePropertyCache;
1767 
1768  /// Set whether this type comes from an AST file.
1769  void setFromAST(bool V = true) const {
1770  TypeBits.FromAST = V;
1771  }
1772 
1773 protected:
1774  friend class ASTContext;
1775 
1776  Type(TypeClass tc, QualType canon, bool Dependent,
1777  bool InstantiationDependent, bool VariablyModified,
1778  bool ContainsUnexpandedParameterPack)
1779  : ExtQualsTypeCommonBase(this,
1780  canon.isNull() ? QualType(this_(), 0) : canon) {
1781  TypeBits.TC = tc;
1782  TypeBits.Dependent = Dependent;
1783  TypeBits.InstantiationDependent = Dependent || InstantiationDependent;
1784  TypeBits.VariablyModified = VariablyModified;
1785  TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
1786  TypeBits.CacheValid = false;
1787  TypeBits.CachedLocalOrUnnamed = false;
1788  TypeBits.CachedLinkage = NoLinkage;
1789  TypeBits.FromAST = false;
1790  }
1791 
1792  // silence VC++ warning C4355: 'this' : used in base member initializer list
1793  Type *this_() { return this; }
1794 
1795  void setDependent(bool D = true) {
1796  TypeBits.Dependent = D;
1797  if (D)
1798  TypeBits.InstantiationDependent = true;
1799  }
1800 
1801  void setInstantiationDependent(bool D = true) {
1802  TypeBits.InstantiationDependent = D; }
1803 
1804  void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; }
1805 
1806  void setContainsUnexpandedParameterPack(bool PP = true) {
1807  TypeBits.ContainsUnexpandedParameterPack = PP;
1808  }
1809 
1810 public:
1811  friend class ASTReader;
1812  friend class ASTWriter;
1813 
1814  Type(const Type &) = delete;
1815  Type &operator=(const Type &) = delete;
1816 
1817  TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
1818 
1819  /// Whether this type comes from an AST file.
1820  bool isFromAST() const { return TypeBits.FromAST; }
1821 
1822  /// Whether this type is or contains an unexpanded parameter
1823  /// pack, used to support C++0x variadic templates.
1824  ///
1825  /// A type that contains a parameter pack shall be expanded by the
1826  /// ellipsis operator at some point. For example, the typedef in the
1827  /// following example contains an unexpanded parameter pack 'T':
1828  ///
1829  /// \code
1830  /// template<typename ...T>
1831  /// struct X {
1832  /// typedef T* pointer_types; // ill-formed; T is a parameter pack.
1833  /// };
1834  /// \endcode
1835  ///
1836  /// Note that this routine does not specify which
1838  return TypeBits.ContainsUnexpandedParameterPack;
1839  }
1840 
1841  /// Determines if this type would be canonical if it had no further
1842  /// qualification.
1843  bool isCanonicalUnqualified() const {
1844  return CanonicalType == QualType(this, 0);
1845  }
1846 
1847  /// Pull a single level of sugar off of this locally-unqualified type.
1848  /// Users should generally prefer SplitQualType::getSingleStepDesugaredType()
1849  /// or QualType::getSingleStepDesugaredType(const ASTContext&).
1850  QualType getLocallyUnqualifiedSingleStepDesugaredType() const;
1851 
1852  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
1853  /// object types, function types, and incomplete types.
1854 
1855  /// Return true if this is an incomplete type.
1856  /// A type that can describe objects, but which lacks information needed to
1857  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
1858  /// routine will need to determine if the size is actually required.
1859  ///
1860  /// Def If non-null, and the type refers to some kind of declaration
1861  /// that can be completed (such as a C struct, C++ class, or Objective-C
1862  /// class), will be set to the declaration.
1863  bool isIncompleteType(NamedDecl **Def = nullptr) const;
1864 
1865  /// Return true if this is an incomplete or object
1866  /// type, in other words, not a function type.
1868  return !isFunctionType();
1869  }
1870 
1871  /// Determine whether this type is an object type.
1872  bool isObjectType() const {
1873  // C++ [basic.types]p8:
1874  // An object type is a (possibly cv-qualified) type that is not a
1875  // function type, not a reference type, and not a void type.
1876  return !isReferenceType() && !isFunctionType() && !isVoidType();
1877  }
1878 
1879  /// Return true if this is a literal type
1880  /// (C++11 [basic.types]p10)
1881  bool isLiteralType(const ASTContext &Ctx) const;
1882 
1883  /// Test if this type is a standard-layout type.
1884  /// (C++0x [basic.type]p9)
1885  bool isStandardLayoutType() const;
1886 
1887  /// Helper methods to distinguish type categories. All type predicates
1888  /// operate on the canonical type, ignoring typedefs and qualifiers.
1889 
1890  /// Returns true if the type is a builtin type.
1891  bool isBuiltinType() const;
1892 
1893  /// Test for a particular builtin type.
1894  bool isSpecificBuiltinType(unsigned K) const;
1895 
1896  /// Test for a type which does not represent an actual type-system type but
1897  /// is instead used as a placeholder for various convenient purposes within
1898  /// Clang. All such types are BuiltinTypes.
1899  bool isPlaceholderType() const;
1900  const BuiltinType *getAsPlaceholderType() const;
1901 
1902  /// Test for a specific placeholder type.
1903  bool isSpecificPlaceholderType(unsigned K) const;
1904 
1905  /// Test for a placeholder type other than Overload; see
1906  /// BuiltinType::isNonOverloadPlaceholderType.
1907  bool isNonOverloadPlaceholderType() const;
1908 
1909  /// isIntegerType() does *not* include complex integers (a GCC extension).
1910  /// isComplexIntegerType() can be used to test for complex integers.
1911  bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum)
1912  bool isEnumeralType() const;
1913 
1914  /// Determine whether this type is a scoped enumeration type.
1915  bool isScopedEnumeralType() const;
1916  bool isBooleanType() const;
1917  bool isCharType() const;
1918  bool isWideCharType() const;
1919  bool isChar8Type() const;
1920  bool isChar16Type() const;
1921  bool isChar32Type() const;
1922  bool isAnyCharacterType() const;
1923  bool isIntegralType(const ASTContext &Ctx) const;
1924 
1925  /// Determine whether this type is an integral or enumeration type.
1926  bool isIntegralOrEnumerationType() const;
1927 
1928  /// Determine whether this type is an integral or unscoped enumeration type.
1929  bool isIntegralOrUnscopedEnumerationType() const;
1930 
1931  /// Floating point categories.
1932  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
1933  /// isComplexType() does *not* include complex integers (a GCC extension).
1934  /// isComplexIntegerType() can be used to test for complex integers.
1935  bool isComplexType() const; // C99 6.2.5p11 (complex)
1936  bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int.
1937  bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex)
1938  bool isHalfType() const; // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half)
1939  bool isFloat16Type() const; // C11 extension ISO/IEC TS 18661
1940  bool isFloat128Type() const;
1941  bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
1942  bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating)
1943  bool isVoidType() const; // C99 6.2.5p19
1944  bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers)
1945  bool isAggregateType() const;
1946  bool isFundamentalType() const;
1947  bool isCompoundType() const;
1948 
1949  // Type Predicates: Check to see if this type is structurally the specified
1950  // type, ignoring typedefs and qualifiers.
1951  bool isFunctionType() const;
1952  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
1953  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
1954  bool isPointerType() const;
1955  bool isAnyPointerType() const; // Any C pointer or ObjC object pointer
1956  bool isBlockPointerType() const;
1957  bool isVoidPointerType() const;
1958  bool isReferenceType() const;
1959  bool isLValueReferenceType() const;
1960  bool isRValueReferenceType() const;
1961  bool isFunctionPointerType() const;
1962  bool isMemberPointerType() const;
1963  bool isMemberFunctionPointerType() const;
1964  bool isMemberDataPointerType() const;
1965  bool isArrayType() const;
1966  bool isConstantArrayType() const;
1967  bool isIncompleteArrayType() const;
1968  bool isVariableArrayType() const;
1969  bool isDependentSizedArrayType() const;
1970  bool isRecordType() const;
1971  bool isClassType() const;
1972  bool isStructureType() const;
1973  bool isObjCBoxableRecordType() const;
1974  bool isInterfaceType() const;
1975  bool isStructureOrClassType() const;
1976  bool isUnionType() const;
1977  bool isComplexIntegerType() const; // GCC _Complex integer type.
1978  bool isVectorType() const; // GCC vector type.
1979  bool isExtVectorType() const; // Extended vector type.
1980  bool isDependentAddressSpaceType() const; // value-dependent address space qualifier
1981  bool isObjCObjectPointerType() const; // pointer to ObjC object
1982  bool isObjCRetainableType() const; // ObjC object or block pointer
1983  bool isObjCLifetimeType() const; // (array of)* retainable type
1984  bool isObjCIndirectLifetimeType() const; // (pointer to)* lifetime type
1985  bool isObjCNSObjectType() const; // __attribute__((NSObject))
1986  bool isObjCIndependentClassType() const; // __attribute__((objc_independent_class))
1987  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
1988  // for the common case.
1989  bool isObjCObjectType() const; // NSString or typeof(*(id)0)
1990  bool isObjCQualifiedInterfaceType() const; // NSString<foo>
1991  bool isObjCQualifiedIdType() const; // id<foo>
1992  bool isObjCQualifiedClassType() const; // Class<foo>
1993  bool isObjCObjectOrInterfaceType() const;
1994  bool isObjCIdType() const; // id
1995 
1996  /// Was this type written with the special inert-in-ARC __unsafe_unretained
1997  /// qualifier?
1998  ///
1999  /// This approximates the answer to the following question: if this
2000  /// translation unit were compiled in ARC, would this type be qualified
2001  /// with __unsafe_unretained?
2003  return hasAttr(attr::ObjCInertUnsafeUnretained);
2004  }
2005 
2006  /// Whether the type is Objective-C 'id' or a __kindof type of an
2007  /// object type, e.g., __kindof NSView * or __kindof id
2008  /// <NSCopying>.
2009  ///
2010  /// \param bound Will be set to the bound on non-id subtype types,
2011  /// which will be (possibly specialized) Objective-C class type, or
2012  /// null for 'id.
2013  bool isObjCIdOrObjectKindOfType(const ASTContext &ctx,
2014  const ObjCObjectType *&bound) const;
2015 
2016  bool isObjCClassType() const; // Class
2017 
2018  /// Whether the type is Objective-C 'Class' or a __kindof type of an
2019  /// Class type, e.g., __kindof Class <NSCopying>.
2020  ///
2021  /// Unlike \c isObjCIdOrObjectKindOfType, there is no relevant bound
2022  /// here because Objective-C's type system cannot express "a class
2023  /// object for a subclass of NSFoo".
2024  bool isObjCClassOrClassKindOfType() const;
2025 
2026  bool isBlockCompatibleObjCPointerType(ASTContext &ctx) const;
2027  bool isObjCSelType() const; // Class
2028  bool isObjCBuiltinType() const; // 'id' or 'Class'
2029  bool isObjCARCBridgableType() const;
2030  bool isCARCBridgableType() const;
2031  bool isTemplateTypeParmType() const; // C++ template type parameter
2032  bool isNullPtrType() const; // C++11 std::nullptr_t
2033  bool isAlignValT() const; // C++17 std::align_val_t
2034  bool isStdByteType() const; // C++17 std::byte
2035  bool isAtomicType() const; // C11 _Atomic()
2036 
2037 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2038  bool is##Id##Type() const;
2039 #include "clang/Basic/OpenCLImageTypes.def"
2040 
2041  bool isImageType() const; // Any OpenCL image type
2042 
2043  bool isSamplerT() const; // OpenCL sampler_t
2044  bool isEventT() const; // OpenCL event_t
2045  bool isClkEventT() const; // OpenCL clk_event_t
2046  bool isQueueT() const; // OpenCL queue_t
2047  bool isReserveIDT() const; // OpenCL reserve_id_t
2048 
2049  bool isPipeType() const; // OpenCL pipe type
2050  bool isOpenCLSpecificType() const; // Any OpenCL specific type
2051 
2052  /// Determines if this type, which must satisfy
2053  /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
2054  /// than implicitly __strong.
2055  bool isObjCARCImplicitlyUnretainedType() const;
2056 
2057  /// Return the implicit lifetime for this type, which must not be dependent.
2058  Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
2059 
2070  STK_FixedPoint
2071  };
2072 
2073  /// Given that this is a scalar type, classify it.
2074  ScalarTypeKind getScalarTypeKind() const;
2075 
2076  /// Whether this type is a dependent type, meaning that its definition
2077  /// somehow depends on a template parameter (C++ [temp.dep.type]).
2078  bool isDependentType() const { return TypeBits.Dependent; }
2079 
2080  /// Determine whether this type is an instantiation-dependent type,
2081  /// meaning that the type involves a template parameter (even if the
2082  /// definition does not actually depend on the type substituted for that
2083  /// template parameter).
2085  return TypeBits.InstantiationDependent;
2086  }
2087 
2088  /// Determine whether this type is an undeduced type, meaning that
2089  /// it somehow involves a C++11 'auto' type or similar which has not yet been
2090  /// deduced.
2091  bool isUndeducedType() const;
2092 
2093  /// Whether this type is a variably-modified type (C99 6.7.5).
2094  bool isVariablyModifiedType() const { return TypeBits.VariablyModified; }
2095 
2096  /// Whether this type involves a variable-length array type
2097  /// with a definite size.
2098  bool hasSizedVLAType() const;
2099 
2100  /// Whether this type is or contains a local or unnamed type.
2101  bool hasUnnamedOrLocalType() const;
2102 
2103  bool isOverloadableType() const;
2104 
2105  /// Determine wither this type is a C++ elaborated-type-specifier.
2106  bool isElaboratedTypeSpecifier() const;
2107 
2108  bool canDecayToPointerType() const;
2109 
2110  /// Whether this type is represented natively as a pointer. This includes
2111  /// pointers, references, block pointers, and Objective-C interface,
2112  /// qualified id, and qualified interface types, as well as nullptr_t.
2113  bool hasPointerRepresentation() const;
2114 
2115  /// Whether this type can represent an objective pointer type for the
2116  /// purpose of GC'ability
2117  bool hasObjCPointerRepresentation() const;
2118 
2119  /// Determine whether this type has an integer representation
2120  /// of some sort, e.g., it is an integer type or a vector.
2121  bool hasIntegerRepresentation() const;
2122 
2123  /// Determine whether this type has an signed integer representation
2124  /// of some sort, e.g., it is an signed integer type or a vector.
2125  bool hasSignedIntegerRepresentation() const;
2126 
2127  /// Determine whether this type has an unsigned integer representation
2128  /// of some sort, e.g., it is an unsigned integer type or a vector.
2129  bool hasUnsignedIntegerRepresentation() const;
2130 
2131  /// Determine whether this type has a floating-point representation
2132  /// of some sort, e.g., it is a floating-point type or a vector thereof.
2133  bool hasFloatingRepresentation() const;
2134 
2135  // Type Checking Functions: Check to see if this type is structurally the
2136  // specified type, ignoring typedefs and qualifiers, and return a pointer to
2137  // the best type we can.
2138  const RecordType *getAsStructureType() const;
2139  /// NOTE: getAs*ArrayType are methods on ASTContext.
2140  const RecordType *getAsUnionType() const;
2141  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
2142  const ObjCObjectType *getAsObjCInterfaceType() const;
2143 
2144  // The following is a convenience method that returns an ObjCObjectPointerType
2145  // for object declared using an interface.
2146  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
2147  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
2148  const ObjCObjectPointerType *getAsObjCQualifiedClassType() const;
2149  const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
2150 
2151  /// Retrieves the CXXRecordDecl that this type refers to, either
2152  /// because the type is a RecordType or because it is the injected-class-name
2153  /// type of a class template or class template partial specialization.
2154  CXXRecordDecl *getAsCXXRecordDecl() const;
2155 
2156  /// Retrieves the RecordDecl this type refers to.
2157  RecordDecl *getAsRecordDecl() const;
2158 
2159  /// Retrieves the TagDecl that this type refers to, either
2160  /// because the type is a TagType or because it is the injected-class-name
2161  /// type of a class template or class template partial specialization.
2162  TagDecl *getAsTagDecl() const;
2163 
2164  /// If this is a pointer or reference to a RecordType, return the
2165  /// CXXRecordDecl that the type refers to.
2166  ///
2167  /// If this is not a pointer or reference, or the type being pointed to does
2168  /// not refer to a CXXRecordDecl, returns NULL.
2169  const CXXRecordDecl *getPointeeCXXRecordDecl() const;
2170 
2171  /// Get the DeducedType whose type will be deduced for a variable with
2172  /// an initializer of this type. This looks through declarators like pointer
2173  /// types, but not through decltype or typedefs.
2174  DeducedType *getContainedDeducedType() const;
2175 
2176  /// Get the AutoType whose type will be deduced for a variable with
2177  /// an initializer of this type. This looks through declarators like pointer
2178  /// types, but not through decltype or typedefs.
2180  return dyn_cast_or_null<AutoType>(getContainedDeducedType());
2181  }
2182 
2183  /// Determine whether this type was written with a leading 'auto'
2184  /// corresponding to a trailing return type (possibly for a nested
2185  /// function type within a pointer to function type or similar).
2186  bool hasAutoForTrailingReturnType() const;
2187 
2188  /// Member-template getAs<specific type>'. Look through sugar for
2189  /// an instance of <specific type>. This scheme will eventually
2190  /// replace the specific getAsXXXX methods above.
2191  ///
2192  /// There are some specializations of this member template listed
2193  /// immediately following this class.
2194  template <typename T> const T *getAs() const;
2195 
2196  /// Member-template getAsAdjusted<specific type>. Look through specific kinds
2197  /// of sugar (parens, attributes, etc) for an instance of <specific type>.
2198  /// This is used when you need to walk over sugar nodes that represent some
2199  /// kind of type adjustment from a type that was written as a <specific type>
2200  /// to another type that is still canonically a <specific type>.
2201  template <typename T> const T *getAsAdjusted() const;
2202 
2203  /// A variant of getAs<> for array types which silently discards
2204  /// qualifiers from the outermost type.
2205  const ArrayType *getAsArrayTypeUnsafe() const;
2206 
2207  /// Member-template castAs<specific type>. Look through sugar for
2208  /// the underlying instance of <specific type>.
2209  ///
2210  /// This method has the same relationship to getAs<T> as cast<T> has
2211  /// to dyn_cast<T>; which is to say, the underlying type *must*
2212  /// have the intended type, and this method will never return null.
2213  template <typename T> const T *castAs() const;
2214 
2215  /// A variant of castAs<> for array type which silently discards
2216  /// qualifiers from the outermost type.
2217  const ArrayType *castAsArrayTypeUnsafe() const;
2218 
2219  /// Determine whether this type had the specified attribute applied to it
2220  /// (looking through top-level type sugar).
2221  bool hasAttr(attr::Kind AK) const;
2222 
2223  /// Get the base element type of this type, potentially discarding type
2224  /// qualifiers. This should never be used when type qualifiers
2225  /// are meaningful.
2226  const Type *getBaseElementTypeUnsafe() const;
2227 
2228  /// If this is an array type, return the element type of the array,
2229  /// potentially with type qualifiers missing.
2230  /// This should never be used when type qualifiers are meaningful.
2231  const Type *getArrayElementTypeNoTypeQual() const;
2232 
2233  /// If this is a pointer type, return the pointee type.
2234  /// If this is an array type, return the array element type.
2235  /// This should never be used when type qualifiers are meaningful.
2236  const Type *getPointeeOrArrayElementType() const;
2237 
2238  /// If this is a pointer, ObjC object pointer, or block
2239  /// pointer, this returns the respective pointee.
2240  QualType getPointeeType() const;
2241 
2242  /// Return the specified type with any "sugar" removed from the type,
2243  /// removing any typedefs, typeofs, etc., as well as any qualifiers.
2244  const Type *getUnqualifiedDesugaredType() const;
2245 
2246  /// More type predicates useful for type checking/promotion
2247  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
2248 
2249  /// Return true if this is an integer type that is
2250  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
2251  /// or an enum decl which has a signed representation.
2252  bool isSignedIntegerType() const;
2253 
2254  /// Return true if this is an integer type that is
2255  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool],
2256  /// or an enum decl which has an unsigned representation.
2257  bool isUnsignedIntegerType() const;
2258 
2259  /// Determines whether this is an integer type that is signed or an
2260  /// enumeration types whose underlying type is a signed integer type.
2261  bool isSignedIntegerOrEnumerationType() const;
2262 
2263  /// Determines whether this is an integer type that is unsigned or an
2264  /// enumeration types whose underlying type is a unsigned integer type.
2265  bool isUnsignedIntegerOrEnumerationType() const;
2266 
2267  /// Return true if this is a fixed point type according to
2268  /// ISO/IEC JTC1 SC22 WG14 N1169.
2269  bool isFixedPointType() const;
2270 
2271  /// Return true if this is a saturated fixed point type according to
2272  /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned.
2273  bool isSaturatedFixedPointType() const;
2274 
2275  /// Return true if this is a saturated fixed point type according to
2276  /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned.
2277  bool isUnsaturatedFixedPointType() const;
2278 
2279  /// Return true if this is a fixed point type that is signed according
2280  /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated.
2281  bool isSignedFixedPointType() const;
2282 
2283  /// Return true if this is a fixed point type that is unsigned according
2284  /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated.
2285  bool isUnsignedFixedPointType() const;
2286 
2287  /// Return true if this is not a variable sized type,
2288  /// according to the rules of C99 6.7.5p3. It is not legal to call this on
2289  /// incomplete types.
2290  bool isConstantSizeType() const;
2291 
2292  /// Returns true if this type can be represented by some
2293  /// set of type specifiers.
2294  bool isSpecifierType() const;
2295 
2296  /// Determine the linkage of this type.
2297  Linkage getLinkage() const;
2298 
2299  /// Determine the visibility of this type.
2301  return getLinkageAndVisibility().getVisibility();
2302  }
2303 
2304  /// Return true if the visibility was explicitly set is the code.
2305  bool isVisibilityExplicit() const {
2306  return getLinkageAndVisibility().isVisibilityExplicit();
2307  }
2308 
2309  /// Determine the linkage and visibility of this type.
2310  LinkageInfo getLinkageAndVisibility() const;
2311 
2312  /// True if the computed linkage is valid. Used for consistency
2313  /// checking. Should always return true.
2314  bool isLinkageValid() const;
2315 
2316  /// Determine the nullability of the given type.
2317  ///
2318  /// Note that nullability is only captured as sugar within the type
2319  /// system, not as part of the canonical type, so nullability will
2320  /// be lost by canonicalization and desugaring.
2321  Optional<NullabilityKind> getNullability(const ASTContext &context) const;
2322 
2323  /// Determine whether the given type can have a nullability
2324  /// specifier applied to it, i.e., if it is any kind of pointer type.
2325  ///
2326  /// \param ResultIfUnknown The value to return if we don't yet know whether
2327  /// this type can have nullability because it is dependent.
2328  bool canHaveNullability(bool ResultIfUnknown = true) const;
2329 
2330  /// Retrieve the set of substitutions required when accessing a member
2331  /// of the Objective-C receiver type that is declared in the given context.
2332  ///
2333  /// \c *this is the type of the object we're operating on, e.g., the
2334  /// receiver for a message send or the base of a property access, and is
2335  /// expected to be of some object or object pointer type.
2336  ///
2337  /// \param dc The declaration context for which we are building up a
2338  /// substitution mapping, which should be an Objective-C class, extension,
2339  /// category, or method within.
2340  ///
2341  /// \returns an array of type arguments that can be substituted for
2342  /// the type parameters of the given declaration context in any type described
2343  /// within that context, or an empty optional to indicate that no
2344  /// substitution is required.
2346  getObjCSubstitutions(const DeclContext *dc) const;
2347 
2348  /// Determines if this is an ObjC interface type that may accept type
2349  /// parameters.
2350  bool acceptsObjCTypeParams() const;
2351 
2352  const char *getTypeClassName() const;
2353 
2355  return CanonicalType;
2356  }
2357 
2358  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
2359  void dump() const;
2360  void dump(llvm::raw_ostream &OS) const;
2361 };
2362 
2363 /// This will check for a TypedefType by removing any existing sugar
2364 /// until it reaches a TypedefType or a non-sugared type.
2365 template <> const TypedefType *Type::getAs() const;
2366 
2367 /// This will check for a TemplateSpecializationType by removing any
2368 /// existing sugar until it reaches a TemplateSpecializationType or a
2369 /// non-sugared type.
2370 template <> const TemplateSpecializationType *Type::getAs() const;
2371 
2372 /// This will check for an AttributedType by removing any existing sugar
2373 /// until it reaches an AttributedType or a non-sugared type.
2374 template <> const AttributedType *Type::getAs() const;
2375 
2376 // We can do canonical leaf types faster, because we don't have to
2377 // worry about preserving child type decoration.
2378 #define TYPE(Class, Base)
2379 #define LEAF_TYPE(Class) \
2380 template <> inline const Class##Type *Type::getAs() const { \
2381  return dyn_cast<Class##Type>(CanonicalType); \
2382 } \
2383 template <> inline const Class##Type *Type::castAs() const { \
2384  return cast<Class##Type>(CanonicalType); \
2385 }
2386 #include "clang/AST/TypeNodes.def"
2387 
2388 /// This class is used for builtin types like 'int'. Builtin
2389 /// types are always canonical and have a literal name field.
2390 class BuiltinType : public Type {
2391 public:
2392  enum Kind {
2393 // OpenCL image types
2394 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id,
2395 #include "clang/Basic/OpenCLImageTypes.def"
2396 // All other builtin types
2397 #define BUILTIN_TYPE(Id, SingletonId) Id,
2398 #define LAST_BUILTIN_TYPE(Id) LastKind = Id
2399 #include "clang/AST/BuiltinTypes.def"
2400  };
2401 
2402 private:
2403  friend class ASTContext; // ASTContext creates these.
2404 
2405  BuiltinType(Kind K)
2406  : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent),
2407  /*InstantiationDependent=*/(K == Dependent),
2408  /*VariablyModified=*/false,
2409  /*Unexpanded parameter pack=*/false) {
2410  BuiltinTypeBits.Kind = K;
2411  }
2412 
2413 public:
2414  Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
2415  StringRef getName(const PrintingPolicy &Policy) const;
2416 
2417  const char *getNameAsCString(const PrintingPolicy &Policy) const {
2418  // The StringRef is null-terminated.
2419  StringRef str = getName(Policy);
2420  assert(!str.empty() && str.data()[str.size()] == '\0');
2421  return str.data();
2422  }
2423 
2424  bool isSugared() const { return false; }
2425  QualType desugar() const { return QualType(this, 0); }
2426 
2427  bool isInteger() const {
2428  return getKind() >= Bool && getKind() <= Int128;
2429  }
2430 
2431  bool isSignedInteger() const {
2432  return getKind() >= Char_S && getKind() <= Int128;
2433  }
2434 
2435  bool isUnsignedInteger() const {
2436  return getKind() >= Bool && getKind() <= UInt128;
2437  }
2438 
2439  bool isFloatingPoint() const {
2440  return getKind() >= Half && getKind() <= Float128;
2441  }
2442 
2443  /// Determines whether the given kind corresponds to a placeholder type.
2444  static bool isPlaceholderTypeKind(Kind K) {
2445  return K >= Overload;
2446  }
2447 
2448  /// Determines whether this type is a placeholder type, i.e. a type
2449  /// which cannot appear in arbitrary positions in a fully-formed
2450  /// expression.
2451  bool isPlaceholderType() const {
2452  return isPlaceholderTypeKind(getKind());
2453  }
2454 
2455  /// Determines whether this type is a placeholder type other than
2456  /// Overload. Most placeholder types require only syntactic
2457  /// information about their context in order to be resolved (e.g.
2458  /// whether it is a call expression), which means they can (and
2459  /// should) be resolved in an earlier "phase" of analysis.
2460  /// Overload expressions sometimes pick up further information
2461  /// from their context, like whether the context expects a
2462  /// specific function-pointer type, and so frequently need
2463  /// special treatment.
2465  return getKind() > Overload;
2466  }
2467 
2468  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
2469 };
2470 
2471 /// Complex values, per C99 6.2.5p11. This supports the C99 complex
2472 /// types (_Complex float etc) as well as the GCC integer complex extensions.
2473 class ComplexType : public Type, public llvm::FoldingSetNode {
2474  friend class ASTContext; // ASTContext creates these.
2475 
2476  QualType ElementType;
2477 
2478  ComplexType(QualType Element, QualType CanonicalPtr)
2479  : Type(Complex, CanonicalPtr, Element->isDependentType(),
2480  Element->isInstantiationDependentType(),
2481  Element->isVariablyModifiedType(),
2482  Element->containsUnexpandedParameterPack()),
2483  ElementType(Element) {}
2484 
2485 public:
2486  QualType getElementType() const { return ElementType; }
2487 
2488  bool isSugared() const { return false; }
2489  QualType desugar() const { return QualType(this, 0); }
2490 
2491  void Profile(llvm::FoldingSetNodeID &ID) {
2492  Profile(ID, getElementType());
2493  }
2494 
2495  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
2496  ID.AddPointer(Element.getAsOpaquePtr());
2497  }
2498 
2499  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
2500 };
2501 
2502 /// Sugar for parentheses used when specifying types.
2503 class ParenType : public Type, public llvm::FoldingSetNode {
2504  friend class ASTContext; // ASTContext creates these.
2505 
2506  QualType Inner;
2507 
2508  ParenType(QualType InnerType, QualType CanonType)
2509  : Type(Paren, CanonType, InnerType->isDependentType(),
2510  InnerType->isInstantiationDependentType(),
2511  InnerType->isVariablyModifiedType(),
2512  InnerType->containsUnexpandedParameterPack()),
2513  Inner(InnerType) {}
2514 
2515 public:
2516  QualType getInnerType() const { return Inner; }
2517 
2518  bool isSugared() const { return true; }
2519  QualType desugar() const { return getInnerType(); }
2520 
2521  void Profile(llvm::FoldingSetNodeID &ID) {
2522  Profile(ID, getInnerType());
2523  }
2524 
2525  static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
2526  Inner.Profile(ID);
2527  }
2528 
2529  static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
2530 };
2531 
2532 /// PointerType - C99 6.7.5.1 - Pointer Declarators.
2533 class PointerType : public Type, public llvm::FoldingSetNode {
2534  friend class ASTContext; // ASTContext creates these.
2535 
2536  QualType PointeeType;
2537 
2538  PointerType(QualType Pointee, QualType CanonicalPtr)
2539  : Type(Pointer, CanonicalPtr, Pointee->isDependentType(),
2540  Pointee->isInstantiationDependentType(),
2541  Pointee->isVariablyModifiedType(),
2542  Pointee->containsUnexpandedParameterPack()),
2543  PointeeType(Pointee) {}
2544 
2545 public:
2546  QualType getPointeeType() const { return PointeeType; }
2547 
2548  /// Returns true if address spaces of pointers overlap.
2549  /// OpenCL v2.0 defines conversion rules for pointers to different
2550  /// address spaces (OpenCLC v2.0 s6.5.5) and notion of overlapping
2551  /// address spaces.
2552  /// CL1.1 or CL1.2:
2553  /// address spaces overlap iff they are they same.
2554  /// CL2.0 adds:
2555  /// __generic overlaps with any address space except for __constant.
2556  bool isAddressSpaceOverlapping(const PointerType &other) const {
2557  Qualifiers thisQuals = PointeeType.getQualifiers();
2558  Qualifiers otherQuals = other.getPointeeType().getQualifiers();
2559  // Address spaces overlap if at least one of them is a superset of another
2560  return thisQuals.isAddressSpaceSupersetOf(otherQuals) ||
2561  otherQuals.isAddressSpaceSupersetOf(thisQuals);
2562  }
2563 
2564  bool isSugared() const { return false; }
2565  QualType desugar() const { return QualType(this, 0); }
2566 
2567  void Profile(llvm::FoldingSetNodeID &ID) {
2568  Profile(ID, getPointeeType());
2569  }
2570 
2571  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
2572  ID.AddPointer(Pointee.getAsOpaquePtr());
2573  }
2574 
2575  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
2576 };
2577 
2578 /// Represents a type which was implicitly adjusted by the semantic
2579 /// engine for arbitrary reasons. For example, array and function types can
2580 /// decay, and function types can have their calling conventions adjusted.
2581 class AdjustedType : public Type, public llvm::FoldingSetNode {
2582  QualType OriginalTy;
2583  QualType AdjustedTy;
2584 
2585 protected:
2586  friend class ASTContext; // ASTContext creates these.
2587 
2588  AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy,
2589  QualType CanonicalPtr)
2590  : Type(TC, CanonicalPtr, OriginalTy->isDependentType(),
2591  OriginalTy->isInstantiationDependentType(),
2592  OriginalTy->isVariablyModifiedType(),
2593  OriginalTy->containsUnexpandedParameterPack()),
2594  OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}
2595 
2596 public:
2597  QualType getOriginalType() const { return OriginalTy; }
2598  QualType getAdjustedType() const { return AdjustedTy; }
2599 
2600  bool isSugared() const { return true; }
2601  QualType desugar() const { return AdjustedTy; }
2602 
2603  void Profile(llvm::FoldingSetNodeID &ID) {
2604  Profile(ID, OriginalTy, AdjustedTy);
2605  }
2606 
2607  static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New) {
2608  ID.AddPointer(Orig.getAsOpaquePtr());
2609  ID.AddPointer(New.getAsOpaquePtr());
2610  }
2611 
2612  static bool classof(const Type *T) {
2613  return T->getTypeClass() == Adjusted || T->getTypeClass() == Decayed;
2614  }
2615 };
2616 
2617 /// Represents a pointer type decayed from an array or function type.
2618 class DecayedType : public AdjustedType {
2619  friend class ASTContext; // ASTContext creates these.
2620 
2621  inline
2622  DecayedType(QualType OriginalType, QualType Decayed, QualType Canonical);
2623 
2624 public:
2625  QualType getDecayedType() const { return getAdjustedType(); }
2626 
2627  inline QualType getPointeeType() const;
2628 
2629  static bool classof(const Type *T) { return T->getTypeClass() == Decayed; }
2630 };
2631 
2632 /// Pointer to a block type.
2633 /// This type is to represent types syntactically represented as
2634 /// "void (^)(int)", etc. Pointee is required to always be a function type.
2635 class BlockPointerType : public Type, public llvm::FoldingSetNode {
2636  friend class ASTContext; // ASTContext creates these.
2637 
2638  // Block is some kind of pointer type
2639  QualType PointeeType;
2640 
2641  BlockPointerType(QualType Pointee, QualType CanonicalCls)
2642  : Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
2643  Pointee->isInstantiationDependentType(),
2644  Pointee->isVariablyModifiedType(),
2645  Pointee->containsUnexpandedParameterPack()),
2646  PointeeType(Pointee) {}
2647 
2648 public:
2649  // Get the pointee type. Pointee is required to always be a function type.
2650  QualType getPointeeType() const { return PointeeType; }
2651 
2652  bool isSugared() const { return false; }
2653  QualType desugar() const { return QualType(this, 0); }
2654 
2655  void Profile(llvm::FoldingSetNodeID &ID) {
2656  Profile(ID, getPointeeType());
2657  }
2658 
2659  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
2660  ID.AddPointer(Pointee.getAsOpaquePtr());
2661  }
2662 
2663  static bool classof(const Type *T) {
2664  return T->getTypeClass() == BlockPointer;
2665  }
2666 };
2667 
2668 /// Base for LValueReferenceType and RValueReferenceType
2669 class ReferenceType : public Type, public llvm::FoldingSetNode {
2670  QualType PointeeType;
2671 
2672 protected:
2673  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
2674  bool SpelledAsLValue)
2675  : Type(tc, CanonicalRef, Referencee->isDependentType(),
2676  Referencee->isInstantiationDependentType(),
2677  Referencee->isVariablyModifiedType(),
2678  Referencee->containsUnexpandedParameterPack()),
2679  PointeeType(Referencee) {
2680  ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
2681  ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
2682  }
2683 
2684 public:
2685  bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
2686  bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
2687 
2688  QualType getPointeeTypeAsWritten() const { return PointeeType; }
2689 
2691  // FIXME: this might strip inner qualifiers; okay?
2692  const ReferenceType *T = this;
2693  while (T->isInnerRef())
2694  T = T->PointeeType->castAs<ReferenceType>();
2695  return T->PointeeType;
2696  }
2697 
2698  void Profile(llvm::FoldingSetNodeID &ID) {
2699  Profile(ID, PointeeType, isSpelledAsLValue());
2700  }
2701 
2702  static void Profile(llvm::FoldingSetNodeID &ID,
2703  QualType Referencee,
2704  bool SpelledAsLValue) {
2705  ID.AddPointer(Referencee.getAsOpaquePtr());
2706  ID.AddBoolean(SpelledAsLValue);
2707  }
2708 
2709  static bool classof(const Type *T) {
2710  return T->getTypeClass() == LValueReference ||
2711  T->getTypeClass() == RValueReference;
2712  }
2713 };
2714 
2715 /// An lvalue reference type, per C++11 [dcl.ref].
2717  friend class ASTContext; // ASTContext creates these
2718 
2719  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
2720  bool SpelledAsLValue)
2721  : ReferenceType(LValueReference, Referencee, CanonicalRef,
2722  SpelledAsLValue) {}
2723 
2724 public:
2725  bool isSugared() const { return false; }
2726  QualType desugar() const { return QualType(this, 0); }
2727 
2728  static bool classof(const Type *T) {
2729  return T->getTypeClass() == LValueReference;
2730  }
2731 };
2732 
2733 /// An rvalue reference type, per C++11 [dcl.ref].
2735  friend class ASTContext; // ASTContext creates these
2736 
2737  RValueReferenceType(QualType Referencee, QualType CanonicalRef)
2738  : ReferenceType(RValueReference, Referencee, CanonicalRef, false) {}
2739 
2740 public:
2741  bool isSugared() const { return false; }
2742  QualType desugar() const { return QualType(this, 0); }
2743 
2744  static bool classof(const Type *T) {
2745  return T->getTypeClass() == RValueReference;
2746  }
2747 };
2748 
2749 /// A pointer to member type per C++ 8.3.3 - Pointers to members.
2750 ///
2751 /// This includes both pointers to data members and pointer to member functions.
2752 class MemberPointerType : public Type, public llvm::FoldingSetNode {
2753  friend class ASTContext; // ASTContext creates these.
2754 
2755  QualType PointeeType;
2756 
2757  /// The class of which the pointee is a member. Must ultimately be a
2758  /// RecordType, but could be a typedef or a template parameter too.
2759  const Type *Class;
2760 
2761  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr)
2762  : Type(MemberPointer, CanonicalPtr,
2763  Cls->isDependentType() || Pointee->isDependentType(),
2764  (Cls->isInstantiationDependentType() ||
2765  Pointee->isInstantiationDependentType()),
2766  Pointee->isVariablyModifiedType(),
2767  (Cls->containsUnexpandedParameterPack() ||
2768  Pointee->containsUnexpandedParameterPack())),
2769  PointeeType(Pointee), Class(Cls) {}
2770 
2771 public:
2772  QualType getPointeeType() const { return PointeeType; }
2773 
2774  /// Returns true if the member type (i.e. the pointee type) is a
2775  /// function type rather than a data-member type.
2777  return PointeeType->isFunctionProtoType();
2778  }
2779 
2780  /// Returns true if the member type (i.e. the pointee type) is a
2781  /// data type rather than a function type.
2782  bool isMemberDataPointer() const {
2783  return !PointeeType->isFunctionProtoType();
2784  }
2785 
2786  const Type *getClass() const { return Class; }
2787  CXXRecordDecl *getMostRecentCXXRecordDecl() const;
2788 
2789  bool isSugared() const { return false; }
2790  QualType desugar() const { return QualType(this, 0); }
2791 
2792  void Profile(llvm::FoldingSetNodeID &ID) {
2793  Profile(ID, getPointeeType(), getClass());
2794  }
2795 
2796  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
2797  const Type *Class) {
2798  ID.AddPointer(Pointee.getAsOpaquePtr());
2799  ID.AddPointer(Class);
2800  }
2801 
2802  static bool classof(const Type *T) {
2803  return T->getTypeClass() == MemberPointer;
2804  }
2805 };
2806 
2807 /// Represents an array type, per C99 6.7.5.2 - Array Declarators.
2808 class ArrayType : public Type, public llvm::FoldingSetNode {
2809 public:
2810  /// Capture whether this is a normal array (e.g. int X[4])
2811  /// an array with a static size (e.g. int X[static 4]), or an array
2812  /// with a star size (e.g. int X[*]).
2813  /// 'static' is only allowed on function parameters.
2815  Normal, Static, Star
2816  };
2817 
2818 private:
2819  /// The element type of the array.
2820  QualType ElementType;
2821 
2822 protected:
2823  friend class ASTContext; // ASTContext creates these.
2824 
2825  // C++ [temp.dep.type]p1:
2826  // A type is dependent if it is...
2827  // - an array type constructed from any dependent type or whose
2828  // size is specified by a constant expression that is
2829  // value-dependent,
2831  ArraySizeModifier sm, unsigned tq,
2832  bool ContainsUnexpandedParameterPack)
2833  : Type(tc, can, et->isDependentType() || tc == DependentSizedArray,
2834  et->isInstantiationDependentType() || tc == DependentSizedArray,
2835  (tc == VariableArray || et->isVariablyModifiedType()),
2836  ContainsUnexpandedParameterPack),
2837  ElementType(et) {
2838  ArrayTypeBits.IndexTypeQuals = tq;
2839  ArrayTypeBits.SizeModifier = sm;
2840  }
2841 
2842 public:
2843  QualType getElementType() const { return ElementType; }
2844 
2846  return ArraySizeModifier(ArrayTypeBits.SizeModifier);
2847  }
2848 
2850  return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
2851  }
2852 
2853  unsigned getIndexTypeCVRQualifiers() const {
2854  return ArrayTypeBits.IndexTypeQuals;
2855  }
2856 
2857  static bool classof(const Type *T) {
2858  return T->getTypeClass() == ConstantArray ||
2859  T->getTypeClass() == VariableArray ||
2860  T->getTypeClass() == IncompleteArray ||
2861  T->getTypeClass() == DependentSizedArray;
2862  }
2863 };
2864 
2865 /// Represents the canonical version of C arrays with a specified constant size.
2866 /// For example, the canonical type for 'int A[4 + 4*100]' is a
2867 /// ConstantArrayType where the element type is 'int' and the size is 404.
2869  llvm::APInt Size; // Allows us to unique the type.
2870 
2871  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
2872  ArraySizeModifier sm, unsigned tq)
2873  : ArrayType(ConstantArray, et, can, sm, tq,
2875  Size(size) {}
2876 
2877 protected:
2878  friend class ASTContext; // ASTContext creates these.
2879 
2881  const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
2882  : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()),
2883  Size(size) {}
2884 
2885 public:
2886  const llvm::APInt &getSize() const { return Size; }
2887  bool isSugared() const { return false; }
2888  QualType desugar() const { return QualType(this, 0); }
2889 
2890  /// Determine the number of bits required to address a member of
2891  // an array with the given element type and number of elements.
2892  static unsigned getNumAddressingBits(const ASTContext &Context,
2893  QualType ElementType,
2894  const llvm::APInt &NumElements);
2895 
2896  /// Determine the maximum number of active bits that an array's size
2897  /// can require, which limits the maximum size of the array.
2898  static unsigned getMaxSizeBits(const ASTContext &Context);
2899 
2900  void Profile(llvm::FoldingSetNodeID &ID) {
2901  Profile(ID, getElementType(), getSize(),
2902  getSizeModifier(), getIndexTypeCVRQualifiers());
2903  }
2904 
2905  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
2906  const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
2907  unsigned TypeQuals) {
2908  ID.AddPointer(ET.getAsOpaquePtr());
2909  ID.AddInteger(ArraySize.getZExtValue());
2910  ID.AddInteger(SizeMod);
2911  ID.AddInteger(TypeQuals);
2912  }
2913 
2914  static bool classof(const Type *T) {
2915  return T->getTypeClass() == ConstantArray;
2916  }
2917 };
2918 
2919 /// Represents a C array with an unspecified size. For example 'int A[]' has
2920 /// an IncompleteArrayType where the element type is 'int' and the size is
2921 /// unspecified.
2923  friend class ASTContext; // ASTContext creates these.
2924 
2926  ArraySizeModifier sm, unsigned tq)
2927  : ArrayType(IncompleteArray, et, can, sm, tq,
2928  et->containsUnexpandedParameterPack()) {}
2929 
2930 public:
2931  friend class StmtIteratorBase;
2932 
2933  bool isSugared() const { return false; }
2934  QualType desugar() const { return QualType(this, 0); }
2935 
2936  static bool classof(const Type *T) {
2937  return T->getTypeClass() == IncompleteArray;
2938  }
2939 
2940  void Profile(llvm::FoldingSetNodeID &ID) {
2941  Profile(ID, getElementType(), getSizeModifier(),
2942  getIndexTypeCVRQualifiers());
2943  }
2944 
2945  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
2946  ArraySizeModifier SizeMod, unsigned TypeQuals) {
2947  ID.AddPointer(ET.getAsOpaquePtr());
2948  ID.AddInteger(SizeMod);
2949  ID.AddInteger(TypeQuals);
2950  }
2951 };
2952 
2953 /// Represents a C array with a specified size that is not an
2954 /// integer-constant-expression. For example, 'int s[x+foo()]'.
2955 /// Since the size expression is an arbitrary expression, we store it as such.
2956 ///
2957 /// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
2958 /// should not be: two lexically equivalent variable array types could mean
2959 /// different things, for example, these variables do not have the same type
2960 /// dynamically:
2961 ///
2962 /// void foo(int x) {
2963 /// int Y[x];
2964 /// ++x;
2965 /// int Z[x];
2966 /// }
2968  friend class ASTContext; // ASTContext creates these.
2969 
2970  /// An assignment-expression. VLA's are only permitted within
2971  /// a function block.
2972  Stmt *SizeExpr;
2973 
2974  /// The range spanned by the left and right array brackets.
2975  SourceRange Brackets;
2976 
2978  ArraySizeModifier sm, unsigned tq,
2979  SourceRange brackets)
2980  : ArrayType(VariableArray, et, can, sm, tq,
2981  et->containsUnexpandedParameterPack()),
2982  SizeExpr((Stmt*) e), Brackets(brackets) {}
2983 
2984 public:
2985  friend class StmtIteratorBase;
2986 
2987  Expr *getSizeExpr() const {
2988  // We use C-style casts instead of cast<> here because we do not wish
2989  // to have a dependency of Type.h on Stmt.h/Expr.h.
2990  return (Expr*) SizeExpr;
2991  }
2992 
2993  SourceRange getBracketsRange() const { return Brackets; }
2994  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
2995  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
2996 
2997  bool isSugared() const { return false; }
2998  QualType desugar() const { return QualType(this, 0); }
2999 
3000  static bool classof(const Type *T) {
3001  return T->getTypeClass() == VariableArray;
3002  }
3003 
3004  void Profile(llvm::FoldingSetNodeID &ID) {
3005  llvm_unreachable("Cannot unique VariableArrayTypes.");
3006  }
3007 };
3008 
3009 /// Represents an array type in C++ whose size is a value-dependent expression.
3010 ///
3011 /// For example:
3012 /// \code
3013 /// template<typename T, int Size>
3014 /// class array {
3015 /// T data[Size];
3016 /// };
3017 /// \endcode
3018 ///
3019 /// For these types, we won't actually know what the array bound is
3020 /// until template instantiation occurs, at which point this will
3021 /// become either a ConstantArrayType or a VariableArrayType.
3023  friend class ASTContext; // ASTContext creates these.
3024 
3025  const ASTContext &Context;
3026 
3027  /// An assignment expression that will instantiate to the
3028  /// size of the array.
3029  ///
3030  /// The expression itself might be null, in which case the array
3031  /// type will have its size deduced from an initializer.
3032  Stmt *SizeExpr;
3033 
3034  /// The range spanned by the left and right array brackets.
3035  SourceRange Brackets;
3036 
3037  DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can,
3038  Expr *e, ArraySizeModifier sm, unsigned tq,
3039  SourceRange brackets);
3040 
3041 public:
3042  friend class StmtIteratorBase;
3043 
3044  Expr *getSizeExpr() const {
3045  // We use C-style casts instead of cast<> here because we do not wish
3046  // to have a dependency of Type.h on Stmt.h/Expr.h.
3047  return (Expr*) SizeExpr;
3048  }
3049 
3050  SourceRange getBracketsRange() const { return Brackets; }
3051  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
3052  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
3053 
3054  bool isSugared() const { return false; }
3055  QualType desugar() const { return QualType(this, 0); }
3056 
3057  static bool classof(const Type *T) {
3058  return T->getTypeClass() == DependentSizedArray;
3059  }
3060 
3061  void Profile(llvm::FoldingSetNodeID &ID) {
3062  Profile(ID, Context, getElementType(),
3063  getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
3064  }
3065 
3066  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3067  QualType ET, ArraySizeModifier SizeMod,
3068  unsigned TypeQuals, Expr *E);
3069 };
3070 
3071 /// Represents an extended address space qualifier where the input address space
3072 /// value is dependent. Non-dependent address spaces are not represented with a
3073 /// special Type subclass; they are stored on an ExtQuals node as part of a QualType.
3074 ///
3075 /// For example:
3076 /// \code
3077 /// template<typename T, int AddrSpace>
3078 /// class AddressSpace {
3079 /// typedef T __attribute__((address_space(AddrSpace))) type;
3080 /// }
3081 /// \endcode
3082 class DependentAddressSpaceType : public Type, public llvm::FoldingSetNode {
3083  friend class ASTContext;
3084 
3085  const ASTContext &Context;
3086  Expr *AddrSpaceExpr;
3087  QualType PointeeType;
3088  SourceLocation loc;
3089 
3090  DependentAddressSpaceType(const ASTContext &Context, QualType PointeeType,
3091  QualType can, Expr *AddrSpaceExpr,
3092  SourceLocation loc);
3093 
3094 public:
3095  Expr *getAddrSpaceExpr() const { return AddrSpaceExpr; }
3096  QualType getPointeeType() const { return PointeeType; }
3097  SourceLocation getAttributeLoc() const { return loc; }
3098 
3099  bool isSugared() const { return false; }
3100  QualType desugar() const { return QualType(this, 0); }
3101 
3102  static bool classof(const Type *T) {
3103  return T->getTypeClass() == DependentAddressSpace;
3104  }
3105 
3106  void Profile(llvm::FoldingSetNodeID &ID) {
3107  Profile(ID, Context, getPointeeType(), getAddrSpaceExpr());
3108  }
3109 
3110  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3111  QualType PointeeType, Expr *AddrSpaceExpr);
3112 };
3113 
3114 /// Represents an extended vector type where either the type or size is
3115 /// dependent.
3116 ///
3117 /// For example:
3118 /// \code
3119 /// template<typename T, int Size>
3120 /// class vector {
3121 /// typedef T __attribute__((ext_vector_type(Size))) type;
3122 /// }
3123 /// \endcode
3124 class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
3125  friend class ASTContext;
3126 
3127  const ASTContext &Context;
3128  Expr *SizeExpr;
3129 
3130  /// The element type of the array.
3131  QualType ElementType;
3132 
3133  SourceLocation loc;
3134 
3135  DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType,
3136  QualType can, Expr *SizeExpr, SourceLocation loc);
3137 
3138 public:
3139  Expr *getSizeExpr() const { return SizeExpr; }
3140  QualType getElementType() const { return ElementType; }
3141  SourceLocation getAttributeLoc() const { return loc; }
3142 
3143  bool isSugared() const { return false; }
3144  QualType desugar() const { return QualType(this, 0); }
3145 
3146  static bool classof(const Type *T) {
3147  return T->getTypeClass() == DependentSizedExtVector;
3148  }
3149 
3150  void Profile(llvm::FoldingSetNodeID &ID) {
3151  Profile(ID, Context, getElementType(), getSizeExpr());
3152  }
3153 
3154  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3155  QualType ElementType, Expr *SizeExpr);
3156 };
3157 
3158 
3159 /// Represents a GCC generic vector type. This type is created using
3160 /// __attribute__((vector_size(n)), where "n" specifies the vector size in
3161 /// bytes; or from an Altivec __vector or vector declaration.
3162 /// Since the constructor takes the number of vector elements, the
3163 /// client is responsible for converting the size into the number of elements.
3164 class VectorType : public Type, public llvm::FoldingSetNode {
3165 public:
3166  enum VectorKind {
3167  /// not a target-specific vector type
3169 
3170  /// is AltiVec vector
3172 
3173  /// is AltiVec 'vector Pixel'
3175 
3176  /// is AltiVec 'vector bool ...'
3178 
3179  /// is ARM Neon vector
3181 
3182  /// is ARM Neon polynomial vector
3183  NeonPolyVector
3184  };
3185 
3186 protected:
3187  friend class ASTContext; // ASTContext creates these.
3188 
3189  /// The element type of the vector.
3191 
3192  VectorType(QualType vecType, unsigned nElements, QualType canonType,
3193  VectorKind vecKind);
3194 
3195  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
3196  QualType canonType, VectorKind vecKind);
3197 
3198 public:
3199  QualType getElementType() const { return ElementType; }
3200  unsigned getNumElements() const { return VectorTypeBits.NumElements; }
3201 
3202  static bool isVectorSizeTooLarge(unsigned NumElements) {
3203  return NumElements > VectorTypeBitfields::MaxNumElements;
3204  }
3205 
3206  bool isSugared() const { return false; }
3207  QualType desugar() const { return QualType(this, 0); }
3208 
3210  return VectorKind(VectorTypeBits.VecKind);
3211  }
3212 
3213  void Profile(llvm::FoldingSetNodeID &ID) {
3214  Profile(ID, getElementType(), getNumElements(),
3215  getTypeClass(), getVectorKind());
3216  }
3217 
3218  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
3219  unsigned NumElements, TypeClass TypeClass,
3220  VectorKind VecKind) {
3221  ID.AddPointer(ElementType.getAsOpaquePtr());
3222  ID.AddInteger(NumElements);
3223  ID.AddInteger(TypeClass);
3224  ID.AddInteger(VecKind);
3225  }
3226 
3227  static bool classof(const Type *T) {
3228  return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
3229  }
3230 };
3231 
3232 /// Represents a vector type where either the type or size is dependent.
3233 ////
3234 /// For example:
3235 /// \code
3236 /// template<typename T, int Size>
3237 /// class vector {
3238 /// typedef T __attribute__((vector_size(Size))) type;
3239 /// }
3240 /// \endcode
3241 class DependentVectorType : public Type, public llvm::FoldingSetNode {
3242  friend class ASTContext;
3243 
3244  const ASTContext &Context;
3245  QualType ElementType;
3246  Expr *SizeExpr;
3247  SourceLocation Loc;
3248 
3249  DependentVectorType(const ASTContext &Context, QualType ElementType,
3250  QualType CanonType, Expr *SizeExpr,
3251  SourceLocation Loc, VectorType::VectorKind vecKind);
3252 
3253 public:
3254  Expr *getSizeExpr() const { return SizeExpr; }
3255  QualType getElementType() const { return ElementType; }
3256  SourceLocation getAttributeLoc() const { return Loc; }
3258  return VectorType::VectorKind(VectorTypeBits.VecKind);
3259  }
3260 
3261  bool isSugared() const { return false; }
3262  QualType desugar() const { return QualType(this, 0); }
3263 
3264  static bool classof(const Type *T) {
3265  return T->getTypeClass() == DependentVector;
3266  }
3267 
3268  void Profile(llvm::FoldingSetNodeID &ID) {
3269  Profile(ID, Context, getElementType(), getSizeExpr(), getVectorKind());
3270  }
3271 
3272  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3273  QualType ElementType, const Expr *SizeExpr,
3274  VectorType::VectorKind VecKind);
3275 };
3276 
3277 /// ExtVectorType - Extended vector type. This type is created using
3278 /// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
3279 /// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
3280 /// class enables syntactic extensions, like Vector Components for accessing
3281 /// points (as .xyzw), colors (as .rgba), and textures (modeled after OpenGL
3282 /// Shading Language).
3283 class ExtVectorType : public VectorType {
3284  friend class ASTContext; // ASTContext creates these.
3285 
3286  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType)
3287  : VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
3288 
3289 public:
3290  static int getPointAccessorIdx(char c) {
3291  switch (c) {
3292  default: return -1;
3293  case 'x': case 'r': return 0;
3294  case 'y': case 'g': return 1;
3295  case 'z': case 'b': return 2;
3296  case 'w': case 'a': return 3;
3297  }
3298  }
3299 
3300  static int getNumericAccessorIdx(char c) {
3301  switch (c) {
3302  default: return -1;
3303  case '0': return 0;
3304  case '1': return 1;
3305  case '2': return 2;
3306  case '3': return 3;
3307  case '4': return 4;
3308  case '5': return 5;
3309  case '6': return 6;
3310  case '7': return 7;
3311  case '8': return 8;
3312  case '9': return 9;
3313  case 'A':
3314  case 'a': return 10;
3315  case 'B':
3316  case 'b': return 11;
3317  case 'C':
3318  case 'c': return 12;
3319  case 'D':
3320  case 'd': return 13;
3321  case 'E':
3322  case 'e': return 14;
3323  case 'F':
3324  case 'f': return 15;
3325  }
3326  }
3327 
3328  static int getAccessorIdx(char c, bool isNumericAccessor) {
3329  if (isNumericAccessor)
3330  return getNumericAccessorIdx(c);
3331  else
3332  return getPointAccessorIdx(c);
3333  }
3334 
3335  bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const {
3336  if (int idx = getAccessorIdx(c, isNumericAccessor)+1)
3337  return unsigned(idx-1) < getNumElements();
3338  return false;
3339  }
3340 
3341  bool isSugared() const { return false; }
3342  QualType desugar() const { return QualType(this, 0); }
3343 
3344  static bool classof(const Type *T) {
3345  return T->getTypeClass() == ExtVector;
3346  }
3347 };
3348 
3349 /// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base
3350 /// class of FunctionNoProtoType and FunctionProtoType.
3351 class FunctionType : public Type {
3352  // The type returned by the function.
3353  QualType ResultType;
3354 
3355 public:
3356  /// Interesting information about a specific parameter that can't simply
3357  /// be reflected in parameter's type. This is only used by FunctionProtoType
3358  /// but is in FunctionType to make this class available during the
3359  /// specification of the bases of FunctionProtoType.
3360  ///
3361  /// It makes sense to model language features this way when there's some
3362  /// sort of parameter-specific override (such as an attribute) that
3363  /// affects how the function is called. For example, the ARC ns_consumed
3364  /// attribute changes whether a parameter is passed at +0 (the default)
3365  /// or +1 (ns_consumed). This must be reflected in the function type,
3366  /// but isn't really a change to the parameter type.
3367  ///
3368  /// One serious disadvantage of modelling language features this way is
3369  /// that they generally do not work with language features that attempt
3370  /// to destructure types. For example, template argument deduction will
3371  /// not be able to match a parameter declared as
3372  /// T (*)(U)
3373  /// against an argument of type
3374  /// void (*)(__attribute__((ns_consumed)) id)
3375  /// because the substitution of T=void, U=id into the former will
3376  /// not produce the latter.
3378  enum {
3379  ABIMask = 0x0F,
3380  IsConsumed = 0x10,
3381  HasPassObjSize = 0x20,
3382  IsNoEscape = 0x40,
3383  };
3384  unsigned char Data = 0;
3385 
3386  public:
3387  ExtParameterInfo() = default;
3388 
3389  /// Return the ABI treatment of this parameter.
3390  ParameterABI getABI() const { return ParameterABI(Data & ABIMask); }
3392  ExtParameterInfo copy = *this;
3393  copy.Data = (copy.Data & ~ABIMask) | unsigned(kind);
3394  return copy;
3395  }
3396 
3397  /// Is this parameter considered "consumed" by Objective-C ARC?
3398  /// Consumed parameters must have retainable object type.
3399  bool isConsumed() const { return (Data & IsConsumed); }
3400  ExtParameterInfo withIsConsumed(bool consumed) const {
3401  ExtParameterInfo copy = *this;
3402  if (consumed)
3403  copy.Data |= IsConsumed;
3404  else
3405  copy.Data &= ~IsConsumed;
3406  return copy;
3407  }
3408 
3409  bool hasPassObjectSize() const { return Data & HasPassObjSize; }
3411  ExtParameterInfo Copy = *this;
3412  Copy.Data |= HasPassObjSize;
3413  return Copy;
3414  }
3415 
3416  bool isNoEscape() const { return Data & IsNoEscape; }
3417  ExtParameterInfo withIsNoEscape(bool NoEscape) const {
3418  ExtParameterInfo Copy = *this;
3419  if (NoEscape)
3420  Copy.Data |= IsNoEscape;
3421  else
3422  Copy.Data &= ~IsNoEscape;
3423  return Copy;
3424  }
3425 
3426  unsigned char getOpaqueValue() const { return Data; }
3427  static ExtParameterInfo getFromOpaqueValue(unsigned char data) {
3428  ExtParameterInfo result;
3429  result.Data = data;
3430  return result;
3431  }
3432 
3434  return lhs.Data == rhs.Data;
3435  }
3436 
3438  return lhs.Data != rhs.Data;
3439  }
3440  };
3441 
3442  /// A class which abstracts out some details necessary for
3443  /// making a call.
3444  ///
3445  /// It is not actually used directly for storing this information in
3446  /// a FunctionType, although FunctionType does currently use the
3447  /// same bit-pattern.
3448  ///
3449  // If you add a field (say Foo), other than the obvious places (both,
3450  // constructors, compile failures), what you need to update is
3451  // * Operator==
3452  // * getFoo
3453  // * withFoo
3454  // * functionType. Add Foo, getFoo.
3455  // * ASTContext::getFooType
3456  // * ASTContext::mergeFunctionTypes
3457  // * FunctionNoProtoType::Profile
3458  // * FunctionProtoType::Profile
3459  // * TypePrinter::PrintFunctionProto
3460  // * AST read and write
3461  // * Codegen
3462  class ExtInfo {
3463  friend class FunctionType;
3464 
3465  // Feel free to rearrange or add bits, but if you go over 12,
3466  // you'll need to adjust both the Bits field below and
3467  // Type::FunctionTypeBitfields.
3468 
3469  // | CC |noreturn|produces|nocallersavedregs|regparm|nocfcheck|
3470  // |0 .. 4| 5 | 6 | 7 |8 .. 10| 11 |
3471  //
3472  // regparm is either 0 (no regparm attribute) or the regparm value+1.
3473  enum { CallConvMask = 0x1F };
3474  enum { NoReturnMask = 0x20 };
3475  enum { ProducesResultMask = 0x40 };
3476  enum { NoCallerSavedRegsMask = 0x80 };
3477  enum { NoCfCheckMask = 0x800 };
3478  enum {
3479  RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask |
3480  NoCallerSavedRegsMask | NoCfCheckMask),
3481  RegParmOffset = 8
3482  }; // Assumed to be the last field
3483  uint16_t Bits = CC_C;
3484 
3485  ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
3486 
3487  public:
3488  // Constructor with no defaults. Use this when you know that you
3489  // have all the elements (when reading an AST file for example).
3490  ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
3491  bool producesResult, bool noCallerSavedRegs, bool NoCfCheck) {
3492  assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
3493  Bits = ((unsigned)cc) | (noReturn ? NoReturnMask : 0) |
3494  (producesResult ? ProducesResultMask : 0) |
3495  (noCallerSavedRegs ? NoCallerSavedRegsMask : 0) |
3496  (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0) |
3497  (NoCfCheck ? NoCfCheckMask : 0);
3498  }
3499 
3500  // Constructor with all defaults. Use when for example creating a
3501  // function known to use defaults.
3502  ExtInfo() = default;
3503 
3504  // Constructor with just the calling convention, which is an important part
3505  // of the canonical type.
3506  ExtInfo(CallingConv CC) : Bits(CC) {}
3507 
3508  bool getNoReturn() const { return Bits & NoReturnMask; }
3509  bool getProducesResult() const { return Bits & ProducesResultMask; }
3510  bool getNoCallerSavedRegs() const { return Bits & NoCallerSavedRegsMask; }
3511  bool getNoCfCheck() const { return Bits & NoCfCheckMask; }
3512  bool getHasRegParm() const { return (Bits >> RegParmOffset) != 0; }
3513 
3514  unsigned getRegParm() const {
3515  unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset;
3516  if (RegParm > 0)
3517  --RegParm;
3518  return RegParm;
3519  }
3520 
3521  CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
3522 
3523  bool operator==(ExtInfo Other) const {
3524  return Bits == Other.Bits;
3525  }
3526  bool operator!=(ExtInfo Other) const {
3527  return Bits != Other.Bits;
3528  }
3529 
3530  // Note that we don't have setters. That is by design, use
3531  // the following with methods instead of mutating these objects.
3532 
3533  ExtInfo withNoReturn(bool noReturn) const {
3534  if (noReturn)
3535  return ExtInfo(Bits | NoReturnMask);
3536  else
3537  return ExtInfo(Bits & ~NoReturnMask);
3538  }
3539 
3540  ExtInfo withProducesResult(bool producesResult) const {
3541  if (producesResult)
3542  return ExtInfo(Bits | ProducesResultMask);
3543  else
3544  return ExtInfo(Bits & ~ProducesResultMask);
3545  }
3546 
3547  ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const {
3548  if (noCallerSavedRegs)
3549  return ExtInfo(Bits | NoCallerSavedRegsMask);
3550  else
3551  return ExtInfo(Bits & ~NoCallerSavedRegsMask);
3552  }
3553 
3554  ExtInfo withNoCfCheck(bool noCfCheck) const {
3555  if (noCfCheck)
3556  return ExtInfo(Bits | NoCfCheckMask);
3557  else
3558  return ExtInfo(Bits & ~NoCfCheckMask);
3559  }
3560 
3561  ExtInfo withRegParm(unsigned RegParm) const {
3562  assert(RegParm < 7 && "Invalid regparm value");
3563  return ExtInfo((Bits & ~RegParmMask) |
3564  ((RegParm + 1) << RegParmOffset));
3565  }
3566 
3568  return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
3569  }
3570 
3571  void Profile(llvm::FoldingSetNodeID &ID) const {
3572  ID.AddInteger(Bits);
3573  }
3574  };
3575 
3576  /// A simple holder for a QualType representing a type in an
3577  /// exception specification. Unfortunately needed by FunctionProtoType
3578  /// because TrailingObjects cannot handle repeated types.
3580 
3581  /// A simple holder for various uncommon bits which do not fit in
3582  /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
3583  /// alignment of subsequent objects in TrailingObjects. You must update
3584  /// hasExtraBitfields in FunctionProtoType after adding extra data here.
3585  struct alignas(void *) FunctionTypeExtraBitfields {
3586  /// The number of types in the exception specification.
3587  /// A whole unsigned is not needed here and according to
3588  /// [implimits] 8 bits would be enough here.
3590  };
3591 
3592 protected:
3594  QualType Canonical, bool Dependent,
3595  bool InstantiationDependent,
3596  bool VariablyModified, bool ContainsUnexpandedParameterPack,
3597  ExtInfo Info)
3598  : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
3599  ContainsUnexpandedParameterPack),
3600  ResultType(res) {
3601  FunctionTypeBits.ExtInfo = Info.Bits;
3602  }
3603 
3604  unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; }
3605 
3606 public:
3607  QualType getReturnType() const { return ResultType; }
3608 
3609  bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
3610  unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
3611 
3612  /// Determine whether this function type includes the GNU noreturn
3613  /// attribute. The C++11 [[noreturn]] attribute does not affect the function
3614  /// type.
3615  bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
3616 
3617  CallingConv getCallConv() const { return getExtInfo().getCC(); }
3618  ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
3619  bool isConst() const { return getTypeQuals() & Qualifiers::Const; }
3620  bool isVolatile() const { return getTypeQuals() & Qualifiers::Volatile; }
3621  bool isRestrict() const { return getTypeQuals() & Qualifiers::Restrict; }
3622 
3623  /// Determine the type of an expression that calls a function of
3624  /// this type.
3625  QualType getCallResultType(const ASTContext &Context) const {
3626  return getReturnType().getNonLValueExprType(Context);
3627  }
3628 
3629  static StringRef getNameForCallConv(CallingConv CC);
3630 
3631  static bool classof(const Type *T) {
3632  return T->getTypeClass() == FunctionNoProto ||
3633  T->getTypeClass() == FunctionProto;
3634  }
3635 };
3636 
3637 /// Represents a K&R-style 'int foo()' function, which has
3638 /// no information available about its arguments.
3639 class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
3640  friend class ASTContext; // ASTContext creates these.
3641 
3643  : FunctionType(FunctionNoProto, Result, Canonical,
3644  /*Dependent=*/false, /*InstantiationDependent=*/false,
3645  Result->isVariablyModifiedType(),
3646  /*ContainsUnexpandedParameterPack=*/false, Info) {}
3647 
3648 public:
3649  // No additional state past what FunctionType provides.
3650 
3651  bool isSugared() const { return false; }
3652  QualType desugar() const { return QualType(this, 0); }
3653 
3654  void Profile(llvm::FoldingSetNodeID &ID) {
3655  Profile(ID, getReturnType(), getExtInfo());
3656  }
3657 
3658  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
3659  ExtInfo Info) {
3660  Info.Profile(ID);
3661  ID.AddPointer(ResultType.getAsOpaquePtr());
3662  }
3663 
3664  static bool classof(const Type *T) {
3665  return T->getTypeClass() == FunctionNoProto;
3666  }
3667 };
3668 
3669 /// Represents a prototype with parameter type info, e.g.
3670 /// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no
3671 /// parameters, not as having a single void parameter. Such a type can have
3672 /// an exception specification, but this specification is not part of the
3673 /// canonical type. FunctionProtoType has several trailing objects, some of
3674 /// which optional. For more information about the trailing objects see
3675 /// the first comment inside FunctionProtoType.
3677  : public FunctionType,
3678  public llvm::FoldingSetNode,
3679  private llvm::TrailingObjects<
3680  FunctionProtoType, QualType, FunctionType::FunctionTypeExtraBitfields,
3681  FunctionType::ExceptionType, Expr *, FunctionDecl *,
3682  FunctionType::ExtParameterInfo> {
3683  friend class ASTContext; // ASTContext creates these.
3684  friend TrailingObjects;
3685 
3686  // FunctionProtoType is followed by several trailing objects, some of
3687  // which optional. They are in order:
3688  //
3689  // * An array of getNumParams() QualType holding the parameter types.
3690  // Always present. Note that for the vast majority of FunctionProtoType,
3691  // these will be the only trailing objects.
3692  //
3693  // * Optionally if some extra data is stored in FunctionTypeExtraBitfields
3694  // (see FunctionTypeExtraBitfields and FunctionTypeBitfields):
3695  // a single FunctionTypeExtraBitfields. Present if and only if
3696  // hasExtraBitfields() is true.
3697  //
3698  // * Optionally exactly one of:
3699  // * an array of getNumExceptions() ExceptionType,
3700  // * a single Expr *,
3701  // * a pair of FunctionDecl *,
3702  // * a single FunctionDecl *
3703  // used to store information about the various types of exception
3704  // specification. See getExceptionSpecSize for the details.
3705  //
3706  // * Optionally an array of getNumParams() ExtParameterInfo holding
3707  // an ExtParameterInfo for each of the parameters. Present if and
3708  // only if hasExtParameterInfos() is true.
3709  //
3710  // The optional FunctionTypeExtraBitfields has to be before the data
3711  // related to the exception specification since it contains the number
3712  // of exception types.
3713  //
3714  // We put the ExtParameterInfos last. If all were equal, it would make
3715  // more sense to put these before the exception specification, because
3716  // it's much easier to skip past them compared to the elaborate switch
3717  // required to skip the exception specification. However, all is not
3718  // equal; ExtParameterInfos are used to model very uncommon features,
3719  // and it's better not to burden the more common paths.
3720 
3721 public:
3722  /// Holds information about the various types of exception specification.
3723  /// ExceptionSpecInfo is not stored as such in FunctionProtoType but is
3724  /// used to group together the various bits of information about the
3725  /// exception specification.
3727  /// The kind of exception specification this is.
3729 
3730  /// Explicitly-specified list of exception types.
3732 
3733  /// Noexcept expression, if this is a computed noexcept specification.
3734  Expr *NoexceptExpr = nullptr;
3735 
3736  /// The function whose exception specification this is, for
3737  /// EST_Unevaluated and EST_Uninstantiated.
3738  FunctionDecl *SourceDecl = nullptr;
3739 
3740  /// The function template whose exception specification this is instantiated
3741  /// from, for EST_Uninstantiated.
3742  FunctionDecl *SourceTemplate = nullptr;
3743 
3744  ExceptionSpecInfo() = default;
3745 
3747  };
3748 
3749  /// Extra information about a function prototype. ExtProtoInfo is not
3750  /// stored as such in FunctionProtoType but is used to group together
3751  /// the various bits of extra information about a function prototype.
3752  struct ExtProtoInfo {
3754  bool Variadic : 1;
3756  unsigned char TypeQuals = 0;
3757  RefQualifierKind RefQualifier = RQ_None;
3759  const ExtParameterInfo *ExtParameterInfos = nullptr;
3760 
3761  ExtProtoInfo() : Variadic(false), HasTrailingReturn(false) {}
3762 
3764  : ExtInfo(CC), Variadic(false), HasTrailingReturn(false) {}
3765 
3767  ExtProtoInfo Result(*this);
3768  Result.ExceptionSpec = ESI;
3769  return Result;
3770  }
3771  };
3772 
3773 private:
3774  unsigned numTrailingObjects(OverloadToken<QualType>) const {
3775  return getNumParams();
3776  }
3777 
3778  unsigned numTrailingObjects(OverloadToken<FunctionTypeExtraBitfields>) const {
3779  return hasExtraBitfields();
3780  }
3781 
3782  unsigned numTrailingObjects(OverloadToken<ExceptionType>) const {
3783  return getExceptionSpecSize().NumExceptionType;
3784  }
3785 
3786  unsigned numTrailingObjects(OverloadToken<Expr *>) const {
3787  return getExceptionSpecSize().NumExprPtr;
3788  }
3789 
3790  unsigned numTrailingObjects(OverloadToken<FunctionDecl *>) const {
3791  return getExceptionSpecSize().NumFunctionDeclPtr;
3792  }
3793 
3794  unsigned numTrailingObjects(OverloadToken<ExtParameterInfo>) const {
3795  return hasExtParameterInfos() ? getNumParams() : 0;
3796  }
3797 
3798  /// Determine whether there are any argument types that
3799  /// contain an unexpanded parameter pack.
3800  static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
3801  unsigned numArgs) {
3802  for (unsigned Idx = 0; Idx < numArgs; ++Idx)
3803  if (ArgArray[Idx]->containsUnexpandedParameterPack())
3804  return true;
3805 
3806  return false;
3807  }
3808 
3810  QualType canonical, const ExtProtoInfo &epi);
3811 
3812  /// This struct is returned by getExceptionSpecSize and is used to
3813  /// translate an ExceptionSpecificationType to the number and kind
3814  /// of trailing objects related to the exception specification.
3815  struct ExceptionSpecSizeHolder {
3816  unsigned NumExceptionType;
3817  unsigned NumExprPtr;
3818  unsigned NumFunctionDeclPtr;
3819  };
3820 
3821  /// Return the number and kind of trailing objects
3822  /// related to the exception specification.
3823  static ExceptionSpecSizeHolder
3824  getExceptionSpecSize(ExceptionSpecificationType EST, unsigned NumExceptions) {
3825  switch (EST) {
3826  case EST_None:
3827  case EST_DynamicNone:
3828  case EST_MSAny:
3829  case EST_BasicNoexcept:
3830  case EST_Unparsed:
3831  return {0, 0, 0};
3832 
3833  case EST_Dynamic:
3834  return {NumExceptions, 0, 0};
3835 
3836  case EST_DependentNoexcept:
3837  case EST_NoexceptFalse:
3838  case EST_NoexceptTrue:
3839  return {0, 1, 0};
3840 
3841  case EST_Uninstantiated:
3842  return {0, 0, 2};
3843 
3844  case EST_Unevaluated:
3845  return {0, 0, 1};
3846  }
3847  llvm_unreachable("bad exception specification kind");
3848  }
3849 
3850  /// Return the number and kind of trailing objects
3851  /// related to the exception specification.
3852  ExceptionSpecSizeHolder getExceptionSpecSize() const {
3853  return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions());
3854  }
3855 
3856  /// Whether the trailing FunctionTypeExtraBitfields is present.
3857  static bool hasExtraBitfields(ExceptionSpecificationType EST) {
3858  // If the exception spec type is EST_Dynamic then we have > 0 exception
3859  // types and the exact number is stored in FunctionTypeExtraBitfields.
3860  return EST == EST_Dynamic;
3861  }
3862 
3863  /// Whether the trailing FunctionTypeExtraBitfields is present.
3864  bool hasExtraBitfields() const {
3865  return hasExtraBitfields(getExceptionSpecType());
3866  }
3867 
3868 public:
3869  unsigned getNumParams() const { return FunctionTypeBits.NumParams; }
3870 
3871  QualType getParamType(unsigned i) const {
3872  assert(i < getNumParams() && "invalid parameter index");
3873  return param_type_begin()[i];
3874  }
3875 
3877  return llvm::makeArrayRef(param_type_begin(), param_type_end());
3878  }
3879 
3881  ExtProtoInfo EPI;
3882  EPI.ExtInfo = getExtInfo();
3883  EPI.Variadic = isVariadic();
3884  EPI.HasTrailingReturn = hasTrailingReturn();
3885  EPI.ExceptionSpec.Type = getExceptionSpecType();
3886  EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals());
3887  EPI.RefQualifier = getRefQualifier();
3888  if (EPI.ExceptionSpec.Type == EST_Dynamic) {
3889  EPI.ExceptionSpec.Exceptions = exceptions();
3890  } else if (isComputedNoexcept(EPI.ExceptionSpec.Type)) {
3891  EPI.ExceptionSpec.NoexceptExpr = getNoexceptExpr();
3892  } else if (EPI.ExceptionSpec.Type == EST_Uninstantiated) {
3893  EPI.ExceptionSpec.SourceDecl = getExceptionSpecDecl();
3894  EPI.ExceptionSpec.SourceTemplate = getExceptionSpecTemplate();
3895  } else if (EPI.ExceptionSpec.Type == EST_Unevaluated) {
3896  EPI.ExceptionSpec.SourceDecl = getExceptionSpecDecl();
3897  }
3898  EPI.ExtParameterInfos = getExtParameterInfosOrNull();
3899  return EPI;
3900  }
3901 
3902  /// Get the kind of exception specification on this function.
3904  return static_cast<ExceptionSpecificationType>(
3905  FunctionTypeBits.ExceptionSpecType);
3906  }
3907 
3908  /// Return whether this function has any kind of exception spec.
3909  bool hasExceptionSpec() const { return getExceptionSpecType() != EST_None; }
3910 
3911  /// Return whether this function has a dynamic (throw) exception spec.
3913  return isDynamicExceptionSpec(getExceptionSpecType());
3914  }
3915 
3916  /// Return whether this function has a noexcept exception spec.
3918  return isNoexceptExceptionSpec(getExceptionSpecType());
3919  }
3920 
3921  /// Return whether this function has a dependent exception spec.
3922  bool hasDependentExceptionSpec() const;
3923 
3924  /// Return whether this function has an instantiation-dependent exception
3925  /// spec.
3926  bool hasInstantiationDependentExceptionSpec() const;
3927 
3928  /// Return the number of types in the exception specification.
3929  unsigned getNumExceptions() const {
3930  return getExceptionSpecType() == EST_Dynamic
3931  ? getTrailingObjects<FunctionTypeExtraBitfields>()
3932  ->NumExceptionType
3933  : 0;
3934  }
3935 
3936  /// Return the ith exception type, where 0 <= i < getNumExceptions().
3937  QualType getExceptionType(unsigned i) const {
3938  assert(i < getNumExceptions() && "Invalid exception number!");
3939  return exception_begin()[i];
3940  }
3941 
3942  /// Return the expression inside noexcept(expression), or a null pointer
3943  /// if there is none (because the exception spec is not of this form).
3945  if (!isComputedNoexcept(getExceptionSpecType()))
3946  return nullptr;
3947  return *getTrailingObjects<Expr *>();
3948  }
3949 
3950  /// If this function type has an exception specification which hasn't
3951  /// been determined yet (either because it has not been evaluated or because
3952  /// it has not been instantiated), this is the function whose exception
3953  /// specification is represented by this type.
3955  if (getExceptionSpecType() != EST_Uninstantiated &&
3956  getExceptionSpecType() != EST_Unevaluated)
3957  return nullptr;
3958  return getTrailingObjects<FunctionDecl *>()[0];
3959  }
3960 
3961  /// If this function type has an uninstantiated exception
3962  /// specification, this is the function whose exception specification
3963  /// should be instantiated to find the exception specification for
3964  /// this type.
3966  if (getExceptionSpecType() != EST_Uninstantiated)
3967  return nullptr;
3968  return getTrailingObjects<FunctionDecl *>()[1];
3969  }
3970 
3971  /// Determine whether this function type has a non-throwing exception
3972  /// specification.
3973  CanThrowResult canThrow() const;
3974 
3975  /// Determine whether this function type has a non-throwing exception
3976  /// specification. If this depends on template arguments, returns
3977  /// \c ResultIfDependent.
3978  bool isNothrow(bool ResultIfDependent = false) const {
3979  return ResultIfDependent ? canThrow() != CT_Can : canThrow() == CT_Cannot;
3980  }
3981 
3982  /// Whether this function prototype is variadic.
3983  bool isVariadic() const { return FunctionTypeBits.Variadic; }
3984 
3985  /// Determines whether this function prototype contains a
3986  /// parameter pack at the end.
3987  ///
3988  /// A function template whose last parameter is a parameter pack can be
3989  /// called with an arbitrary number of arguments, much like a variadic
3990  /// function.
3991  bool isTemplateVariadic() const;
3992 
3993  /// Whether this function prototype has a trailing return type.
3994  bool hasTrailingReturn() const { return FunctionTypeBits.HasTrailingReturn; }
3995 
3996  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
3997 
3998  /// Retrieve the ref-qualifier associated with this function type.
4000  return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
4001  }
4002 
4004  using param_type_range = llvm::iterator_range<param_type_iterator>;
4005 
4007  return param_type_range(param_type_begin(), param_type_end());
4008  }
4009 
4011  return getTrailingObjects<QualType>();
4012  }
4013 
4015  return param_type_begin() + getNumParams();
4016  }
4017 
4018  using exception_iterator = const QualType *;
4019 
4021  return llvm::makeArrayRef(exception_begin(), exception_end());
4022  }
4023 
4025  return reinterpret_cast<exception_iterator>(
4026  getTrailingObjects<ExceptionType>());
4027  }
4028 
4030  return exception_begin() + getNumExceptions();
4031  }
4032 
4033  /// Is there any interesting extra information for any of the parameters
4034  /// of this function type?
4035  bool hasExtParameterInfos() const {
4036  return FunctionTypeBits.HasExtParameterInfos;
4037  }
4038 
4040  assert(hasExtParameterInfos());
4041  return ArrayRef<ExtParameterInfo>(getTrailingObjects<ExtParameterInfo>(),
4042  getNumParams());
4043  }
4044 
4045  /// Return a pointer to the beginning of the array of extra parameter
4046  /// information, if present, or else null if none of the parameters
4047  /// carry it. This is equivalent to getExtProtoInfo().ExtParameterInfos.
4049  if (!hasExtParameterInfos())
4050  return nullptr;
4051  return getTrailingObjects<ExtParameterInfo>();
4052  }
4053 
4055  assert(I < getNumParams() && "parameter index out of range");
4056  if (hasExtParameterInfos())
4057  return getTrailingObjects<ExtParameterInfo>()[I];
4058  return ExtParameterInfo();
4059  }
4060 
4061  ParameterABI getParameterABI(unsigned I) const {
4062  assert(I < getNumParams() && "parameter index out of range");
4063  if (hasExtParameterInfos())
4064  return getTrailingObjects<ExtParameterInfo>()[I].getABI();
4065  return ParameterABI::Ordinary;
4066  }
4067 
4068  bool isParamConsumed(unsigned I) const {
4069  assert(I < getNumParams() && "parameter index out of range");
4070  if (hasExtParameterInfos())
4071  return getTrailingObjects<ExtParameterInfo>()[I].isConsumed();
4072  return false;
4073  }
4074 
4075  bool isSugared() const { return false; }
4076  QualType desugar() const { return QualType(this, 0); }
4077 
4078  void printExceptionSpecification(raw_ostream &OS,
4079  const PrintingPolicy &Policy) const;
4080 
4081  static bool classof(const Type *T) {
4082  return T->getTypeClass() == FunctionProto;
4083  }
4084 
4085  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
4086  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
4087  param_type_iterator ArgTys, unsigned NumArgs,
4088  const ExtProtoInfo &EPI, const ASTContext &Context,
4089  bool Canonical);
4090 };
4091 
4092 /// Represents the dependent type named by a dependently-scoped
4093 /// typename using declaration, e.g.
4094 /// using typename Base<T>::foo;
4095 ///
4096 /// Template instantiation turns these into the underlying type.
4097 class UnresolvedUsingType : public Type {
4098  friend class ASTContext; // ASTContext creates these.
4099 
4101 
4103  : Type(UnresolvedUsing, QualType(), true, true, false,
4104  /*ContainsUnexpandedParameterPack=*/false),
4105  Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {}
4106 
4107 public:
4108  UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
4109 
4110  bool isSugared() const { return false; }
4111  QualType desugar() const { return QualType(this, 0); }
4112 
4113  static bool classof(const Type *T) {
4114  return T->getTypeClass() == UnresolvedUsing;
4115  }
4116 
4117  void Profile(llvm::FoldingSetNodeID &ID) {
4118  return Profile(ID, Decl);
4119  }
4120 
4121  static void Profile(llvm::FoldingSetNodeID &ID,
4123  ID.AddPointer(D);
4124  }
4125 };
4126 
4127 class TypedefType : public Type {
4129 
4130 protected:
4131  friend class ASTContext; // ASTContext creates these.
4132 
4134  : Type(tc, can, can->isDependentType(),
4135  can->isInstantiationDependentType(),
4136  can->isVariablyModifiedType(),
4137  /*ContainsUnexpandedParameterPack=*/false),
4138  Decl(const_cast<TypedefNameDecl*>(D)) {
4139  assert(!isa<TypedefType>(can) && "Invalid canonical type");
4140  }
4141 
4142 public:
4143  TypedefNameDecl *getDecl() const { return Decl; }
4144 
4145  bool isSugared() const { return true; }
4146  QualType desugar() const;
4147 
4148  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
4149 };
4150 
4151 /// Represents a `typeof` (or __typeof__) expression (a GCC extension).
4152 class TypeOfExprType : public Type {
4153  Expr *TOExpr;
4154 
4155 protected:
4156  friend class ASTContext; // ASTContext creates these.
4157 
4158  TypeOfExprType(Expr *E, QualType can = QualType());
4159 
4160 public:
4161  Expr *getUnderlyingExpr() const { return TOExpr; }
4162 
4163  /// Remove a single level of sugar.
4164  QualType desugar() const;
4165 
4166  /// Returns whether this type directly provides sugar.
4167  bool isSugared() const;
4168 
4169  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
4170 };
4171 
4172 /// Internal representation of canonical, dependent
4173 /// `typeof(expr)` types.
4174 ///
4175 /// This class is used internally by the ASTContext to manage
4176 /// canonical, dependent types, only. Clients will only see instances
4177 /// of this class via TypeOfExprType nodes.
4179  : public TypeOfExprType, public llvm::FoldingSetNode {
4180  const ASTContext &Context;
4181 
4182 public:
4184  : TypeOfExprType(E), Context(Context) {}
4185 
4186  void Profile(llvm::FoldingSetNodeID &ID) {
4187  Profile(ID, Context, getUnderlyingExpr());
4188  }
4189 
4190  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4191  Expr *E);
4192 };
4193 
4194 /// Represents `typeof(type)`, a GCC extension.
4195 class TypeOfType : public Type {
4196  friend class ASTContext; // ASTContext creates these.
4197 
4198  QualType TOType;
4199 
4200  TypeOfType(QualType T, QualType can)
4201  : Type(TypeOf, can, T->isDependentType(),
4202  T->isInstantiationDependentType(),
4203  T->isVariablyModifiedType(),
4204  T->containsUnexpandedParameterPack()),
4205  TOType(T) {
4206  assert(!isa<TypedefType>(can) && "Invalid canonical type");
4207  }
4208 
4209 public:
4210  QualType getUnderlyingType() const { return TOType; }
4211 
4212  /// Remove a single level of sugar.
4213  QualType desugar() const { return getUnderlyingType(); }
4214 
4215  /// Returns whether this type directly provides sugar.
4216  bool isSugared() const { return true; }
4217 
4218  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
4219 };
4220 
4221 /// Represents the type `decltype(expr)` (C++11).
4222 class DecltypeType : public Type {
4223  Expr *E;
4224  QualType UnderlyingType;
4225 
4226 protected:
4227  friend class ASTContext; // ASTContext creates these.
4228 
4229  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
4230 
4231 public:
4232  Expr *getUnderlyingExpr() const { return E; }
4233  QualType getUnderlyingType() const { return UnderlyingType; }
4234 
4235  /// Remove a single level of sugar.
4236  QualType desugar() const;
4237 
4238  /// Returns whether this type directly provides sugar.
4239  bool isSugared() const;
4240 
4241  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
4242 };
4243 
4244 /// Internal representation of canonical, dependent
4245 /// decltype(expr) types.
4246 ///
4247 /// This class is used internally by the ASTContext to manage
4248 /// canonical, dependent types, only. Clients will only see instances
4249 /// of this class via DecltypeType nodes.
4250 class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
4251  const ASTContext &Context;
4252 
4253 public:
4254  DependentDecltypeType(const ASTContext &Context, Expr *E);
4255 
4256  void Profile(llvm::FoldingSetNodeID &ID) {
4257  Profile(ID, Context, getUnderlyingExpr());
4258  }
4259 
4260  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4261  Expr *E);
4262 };
4263 
4264 /// A unary type transform, which is a type constructed from another.
4265 class UnaryTransformType : public Type {
4266 public:
4267  enum UTTKind {
4268  EnumUnderlyingType
4269  };
4270 
4271 private:
4272  /// The untransformed type.
4273  QualType BaseType;
4274 
4275  /// The transformed type if not dependent, otherwise the same as BaseType.
4276  QualType UnderlyingType;
4277 
4278  UTTKind UKind;
4279 
4280 protected:
4281  friend class ASTContext;
4282 
4283  UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind,
4284  QualType CanonicalTy);
4285 
4286 public:
4287  bool isSugared() const { return !isDependentType(); }
4288  QualType desugar() const { return UnderlyingType; }
4289 
4290  QualType getUnderlyingType() const { return UnderlyingType; }
4291  QualType getBaseType() const { return BaseType; }
4292 
4293  UTTKind getUTTKind() const { return UKind; }
4294 
4295  static bool classof(const Type *T) {
4296  return T->getTypeClass() == UnaryTransform;
4297  }
4298 };
4299 
4300 /// Internal representation of canonical, dependent
4301 /// __underlying_type(type) types.
4302 ///
4303 /// This class is used internally by the ASTContext to manage
4304 /// canonical, dependent types, only. Clients will only see instances
4305 /// of this class via UnaryTransformType nodes.
4307  public llvm::FoldingSetNode {
4308 public:
4310  UTTKind UKind);
4311 
4312  void Profile(llvm::FoldingSetNodeID &ID) {
4313  Profile(ID, getBaseType(), getUTTKind());
4314  }
4315 
4316  static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType,
4317  UTTKind UKind) {
4318  ID.AddPointer(BaseType.getAsOpaquePtr());
4319  ID.AddInteger((unsigned)UKind);
4320  }
4321 };
4322 
4323 class TagType : public Type {
4324  friend class ASTReader;
4325 
4326  /// Stores the TagDecl associated with this type. The decl may point to any
4327  /// TagDecl that declares the entity.
4328  TagDecl *decl;
4329 
4330 protected:
4331  TagType(TypeClass TC, const TagDecl *D, QualType can);
4332 
4333 public:
4334  TagDecl *getDecl() const;
4335 
4336  /// Determines whether this type is in the process of being defined.
4337  bool isBeingDefined() const;
4338 
4339  static bool classof(const Type *T) {
4340  return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
4341  }
4342 };
4343 
4344 /// A helper class that allows the use of isa/cast/dyncast
4345 /// to detect TagType objects of structs/unions/classes.
4346 class RecordType : public TagType {
4347 protected:
4348  friend class ASTContext; // ASTContext creates these.
4349 
4350  explicit RecordType(const RecordDecl *D)
4351  : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) {}
4353  : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) {}
4354 
4355 public:
4356  RecordDecl *getDecl() const {
4357  return reinterpret_cast<RecordDecl*>(TagType::getDecl());
4358  }
4359 
4360  /// Recursively check all fields in the record for const-ness. If any field
4361  /// is declared const, return true. Otherwise, return false.
4362  bool hasConstFields() const;
4363 
4364  bool isSugared() const { return false; }
4365  QualType desugar() const { return QualType(this, 0); }
4366 
4367  static bool classof(const Type *T) { return T->getTypeClass() == Record; }
4368 };
4369 
4370 /// A helper class that allows the use of isa/cast/dyncast
4371 /// to detect TagType objects of enums.
4372 class EnumType : public TagType {
4373  friend class ASTContext; // ASTContext creates these.
4374 
4375  explicit EnumType(const EnumDecl *D)
4376  : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) {}
4377 
4378 public:
4379  EnumDecl *getDecl() const {
4380  return reinterpret_cast<EnumDecl*>(TagType::getDecl());
4381  }
4382 
4383  bool isSugared() const { return false; }
4384  QualType desugar() const { return QualType(this, 0); }
4385 
4386  static bool classof(const Type *T) { return T->getTypeClass() == Enum; }
4387 };
4388 
4389 /// An attributed type is a type to which a type attribute has been applied.
4390 ///
4391 /// The "modified type" is the fully-sugared type to which the attributed
4392 /// type was applied; generally it is not canonically equivalent to the
4393 /// attributed type. The "equivalent type" is the minimally-desugared type
4394 /// which the type is canonically equivalent to.
4395 ///
4396 /// For example, in the following attributed type:
4397 /// int32_t __attribute__((vector_size(16)))
4398 /// - the modified type is the TypedefType for int32_t
4399 /// - the equivalent type is VectorType(16, int32_t)
4400 /// - the canonical type is VectorType(16, int)
4401 class AttributedType : public Type, public llvm::FoldingSetNode {
4402 public:
4403  using Kind = attr::Kind;
4404 
4405 private:
4406  friend class ASTContext; // ASTContext creates these
4407 
4408  QualType ModifiedType;
4409  QualType EquivalentType;
4410 
4411  AttributedType(QualType canon, attr::Kind attrKind, QualType modified,
4412  QualType equivalent)
4413  : Type(Attributed, canon, equivalent->isDependentType(),
4414  equivalent->isInstantiationDependentType(),
4415  equivalent->isVariablyModifiedType(),
4416  equivalent->containsUnexpandedParameterPack()),
4417  ModifiedType(modified), EquivalentType(equivalent) {
4418  AttributedTypeBits.AttrKind = attrKind;
4419  }
4420 
4421 public:
4422  Kind getAttrKind() const {
4423  return static_cast<Kind>(AttributedTypeBits.AttrKind);
4424  }
4425 
4426  QualType getModifiedType() const { return ModifiedType; }
4427  QualType getEquivalentType() const { return EquivalentType; }
4428 
4429  bool isSugared() const { return true; }
4430  QualType desugar() const { return getEquivalentType(); }
4431 
4432  /// Does this attribute behave like a type qualifier?
4433  ///
4434  /// A type qualifier adjusts a type to provide specialized rules for
4435  /// a specific object, like the standard const and volatile qualifiers.
4436  /// This includes attributes controlling things like nullability,
4437  /// address spaces, and ARC ownership. The value of the object is still
4438  /// largely described by the modified type.
4439  ///
4440  /// In contrast, many type attributes "rewrite" their modified type to
4441  /// produce a fundamentally different type, not necessarily related in any
4442  /// formalizable way to the original type. For example, calling convention
4443  /// and vector attributes are not simple type qualifiers.
4444  ///
4445  /// Type qualifiers are often, but not always, reflected in the canonical
4446  /// type.
4447  bool isQualifier() const;
4448 
4449  bool isMSTypeSpec() const;
4450 
4451  bool isCallingConv() const;
4452 
4453  llvm::Optional<NullabilityKind> getImmediateNullability() const;
4454 
4455  /// Retrieve the attribute kind corresponding to the given
4456  /// nullability kind.
4458  switch (kind) {
4460  return attr::TypeNonNull;
4461 
4463  return attr::TypeNullable;
4464 
4466  return attr::TypeNullUnspecified;
4467  }
4468  llvm_unreachable("Unknown nullability kind.");
4469  }
4470 
4471  /// Strip off the top-level nullability annotation on the given
4472  /// type, if it's there.
4473  ///
4474  /// \param T The type to strip. If the type is exactly an
4475  /// AttributedType specifying nullability (without looking through
4476  /// type sugar), the nullability is returned and this type changed
4477  /// to the underlying modified type.
4478  ///
4479  /// \returns the top-level nullability, if present.
4480  static Optional<NullabilityKind> stripOuterNullability(QualType &T);
4481 
4482  void Profile(llvm::FoldingSetNodeID &ID) {
4483  Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
4484  }
4485 
4486  static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind,
4487  QualType modified, QualType equivalent) {
4488  ID.AddInteger(attrKind);
4489  ID.AddPointer(modified.getAsOpaquePtr());
4490  ID.AddPointer(equivalent.getAsOpaquePtr());
4491  }
4492 
4493  static bool classof(const Type *T) {
4494  return T->getTypeClass() == Attributed;
4495  }
4496 };
4497 
4498 class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
4499  friend class ASTContext; // ASTContext creates these
4500 
4501  // Helper data collector for canonical types.
4502  struct CanonicalTTPTInfo {
4503  unsigned Depth : 15;
4504  unsigned ParameterPack : 1;
4505  unsigned Index : 16;
4506  };
4507 
4508  union {
4509  // Info for the canonical type.
4510  CanonicalTTPTInfo CanTTPTInfo;
4511 
4512  // Info for the non-canonical type.
4514  };
4515 
4516  /// Build a non-canonical type.
4518  : Type(TemplateTypeParm, Canon, /*Dependent=*/true,
4519  /*InstantiationDependent=*/true,
4520  /*VariablyModified=*/false,
4521  Canon->containsUnexpandedParameterPack()),
4522  TTPDecl(TTPDecl) {}
4523 
4524  /// Build the canonical type.
4525  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
4526  : Type(TemplateTypeParm, QualType(this, 0),
4527  /*Dependent=*/true,
4528  /*InstantiationDependent=*/true,
4529  /*VariablyModified=*/false, PP) {
4530  CanTTPTInfo.Depth = D;
4531  CanTTPTInfo.Index = I;
4532  CanTTPTInfo.ParameterPack = PP;
4533  }
4534 
4535  const CanonicalTTPTInfo& getCanTTPTInfo() const {
4536  QualType Can = getCanonicalTypeInternal();
4537  return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo;
4538  }
4539 
4540 public:
4541  unsigned getDepth() const { return getCanTTPTInfo().Depth; }
4542  unsigned getIndex() const { return getCanTTPTInfo().Index; }
4543  bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; }
4544 
4546  return isCanonicalUnqualified() ? nullptr : TTPDecl;
4547  }
4548 
4549  IdentifierInfo *getIdentifier() const;
4550 
4551  bool isSugared() const { return false; }
4552  QualType desugar() const { return QualType(this, 0); }
4553 
4554  void Profile(llvm::FoldingSetNodeID &ID) {
4555  Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
4556  }
4557 
4558  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
4559  unsigned Index, bool ParameterPack,
4560  TemplateTypeParmDecl *TTPDecl) {
4561  ID.AddInteger(Depth);
4562  ID.AddInteger(Index);
4563  ID.AddBoolean(ParameterPack);
4564  ID.AddPointer(TTPDecl);
4565  }
4566 
4567  static bool classof(const Type *T) {
4568  return T->getTypeClass() == TemplateTypeParm;
4569  }
4570 };
4571 
4572 /// Represents the result of substituting a type for a template
4573 /// type parameter.
4574 ///
4575 /// Within an instantiated template, all template type parameters have
4576 /// been replaced with these. They are used solely to record that a
4577 /// type was originally written as a template type parameter;
4578 /// therefore they are never canonical.
4579 class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
4580  friend class ASTContext;
4581 
4582  // The original type parameter.
4583  const TemplateTypeParmType *Replaced;
4584 
4586  : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
4587  Canon->isInstantiationDependentType(),
4588  Canon->isVariablyModifiedType(),
4589  Canon->containsUnexpandedParameterPack()),
4590  Replaced(Param) {}
4591 
4592 public:
4593  /// Gets the template parameter that was substituted for.
4595  return Replaced;
4596  }
4597 
4598  /// Gets the type that was substituted for the template
4599  /// parameter.
4601  return getCanonicalTypeInternal();
4602  }
4603 
4604  bool isSugared() const { return true; }
4605  QualType desugar() const { return getReplacementType(); }
4606 
4607  void Profile(llvm::FoldingSetNodeID &ID) {
4608  Profile(ID, getReplacedParameter(), getReplacementType());
4609  }
4610 
4611  static void Profile(llvm::FoldingSetNodeID &ID,
4612  const TemplateTypeParmType *Replaced,
4613  QualType Replacement) {
4614  ID.AddPointer(Replaced);
4615  ID.AddPointer(Replacement.getAsOpaquePtr());
4616  }
4617 
4618  static bool classof(const Type *T) {
4619  return T->getTypeClass() == SubstTemplateTypeParm;
4620  }
4621 };
4622 
4623 /// Represents the result of substituting a set of types for a template
4624 /// type parameter pack.
4625 ///
4626 /// When a pack expansion in the source code contains multiple parameter packs
4627 /// and those parameter packs correspond to different levels of template
4628 /// parameter lists, this type node is used to represent a template type
4629 /// parameter pack from an outer level, which has already had its argument pack
4630 /// substituted but that still lives within a pack expansion that itself
4631 /// could not be instantiated. When actually performing a substitution into
4632 /// that pack expansion (e.g., when all template parameters have corresponding
4633 /// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
4634 /// at the current pack substitution index.
4635 class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
4636  friend class ASTContext;
4637 
4638  /// The original type parameter.
4639  const TemplateTypeParmType *Replaced;
4640 
4641  /// A pointer to the set of template arguments that this
4642  /// parameter pack is instantiated with.
4643  const TemplateArgument *Arguments;
4644 
4646  QualType Canon,
4647  const TemplateArgument &ArgPack);
4648 
4649 public:
4650  IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); }
4651 
4652  /// Gets the template parameter that was substituted for.
4654  return Replaced;
4655  }
4656 
4657  unsigned getNumArgs() const {
4658  return SubstTemplateTypeParmPackTypeBits.NumArgs;
4659  }
4660 
4661  bool isSugared() const { return false; }
4662  QualType desugar() const { return QualType(this, 0); }
4663 
4664  TemplateArgument getArgumentPack() const;
4665 
4666  void Profile(llvm::FoldingSetNodeID &ID);
4667  static void Profile(llvm::FoldingSetNodeID &ID,
4668  const TemplateTypeParmType *Replaced,
4669  const TemplateArgument &ArgPack);
4670 
4671  static bool classof(const Type *T) {
4672  return T->getTypeClass() == SubstTemplateTypeParmPack;
4673  }
4674 };
4675 
4676 /// Common base class for placeholders for types that get replaced by
4677 /// placeholder type deduction: C++11 auto, C++14 decltype(auto), C++17 deduced
4678 /// class template types, and (eventually) constrained type names from the C++
4679 /// Concepts TS.
4680 ///
4681 /// These types are usually a placeholder for a deduced type. However, before
4682 /// the initializer is attached, or (usually) if the initializer is
4683 /// type-dependent, there is no deduced type and the type is canonical. In
4684 /// the latter case, it is also a dependent type.
4685 class DeducedType : public Type {
4686 protected:
4687  DeducedType(TypeClass TC, QualType DeducedAsType, bool IsDependent,
4688  bool IsInstantiationDependent, bool ContainsParameterPack)
4689  : Type(TC,
4690  // FIXME: Retain the sugared deduced type?
4691  DeducedAsType.isNull() ? QualType(this, 0)
4692  : DeducedAsType.getCanonicalType(),
4693  IsDependent, IsInstantiationDependent,
4694  /*VariablyModified=*/false, ContainsParameterPack) {
4695  if (!DeducedAsType.isNull()) {
4696  if (DeducedAsType->isDependentType())
4697  setDependent();
4698  if (DeducedAsType->isInstantiationDependentType())
4699  setInstantiationDependent();
4700  if (DeducedAsType->containsUnexpandedParameterPack())
4701  setContainsUnexpandedParameterPack();
4702  }
4703  }
4704 
4705 public:
4706  bool isSugared() const { return !isCanonicalUnqualified(); }
4707  QualType desugar() const { return getCanonicalTypeInternal(); }
4708 
4709  /// Get the type deduced for this placeholder type, or null if it's
4710  /// either not been deduced or was deduced to a dependent type.
4712  return !isCanonicalUnqualified() ? getCanonicalTypeInternal() : QualType();
4713  }
4714  bool isDeduced() const {
4715  return !isCanonicalUnqualified() || isDependentType();
4716  }
4717 
4718  static bool classof(const Type *T) {
4719  return T->getTypeClass() == Auto ||
4720  T->getTypeClass() == DeducedTemplateSpecialization;
4721  }
4722 };
4723 
4724 /// Represents a C++11 auto or C++14 decltype(auto) type.
4725 class AutoType : public DeducedType, public llvm::FoldingSetNode {
4726  friend class ASTContext; // ASTContext creates these
4727 
4728  AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword,
4729  bool IsDeducedAsDependent)
4730  : DeducedType(Auto, DeducedAsType, IsDeducedAsDependent,
4731  IsDeducedAsDependent, /*ContainsPack=*/false) {
4732  AutoTypeBits.Keyword = (unsigned)Keyword;
4733  }
4734 
4735 public:
4736  bool isDecltypeAuto() const {
4737  return getKeyword() == AutoTypeKeyword::DecltypeAuto;
4738  }
4739 
4741  return (AutoTypeKeyword)AutoTypeBits.Keyword;
4742  }
4743 
4744  void Profile(llvm::FoldingSetNodeID &ID) {
4745  Profile(ID, getDeducedType(), getKeyword(), isDependentType());
4746  }
4747 
4748  static void Profile(llvm::FoldingSetNodeID &ID, QualType Deduced,
4749  AutoTypeKeyword Keyword, bool IsDependent) {
4750  ID.AddPointer(Deduced.getAsOpaquePtr());
4751  ID.AddInteger((unsigned)Keyword);
4752  ID.AddBoolean(IsDependent);
4753  }
4754 
4755  static bool classof(const Type *T) {
4756  return T->getTypeClass() == Auto;
4757  }
4758 };
4759 
4760 /// Represents a C++17 deduced template specialization type.
4762  public llvm::FoldingSetNode {
4763  friend class ASTContext; // ASTContext creates these
4764 
4765  /// The name of the template whose arguments will be deduced.
4766  TemplateName Template;
4767 
4769  QualType DeducedAsType,
4770  bool IsDeducedAsDependent)
4771  : DeducedType(DeducedTemplateSpecialization, DeducedAsType,
4772  IsDeducedAsDependent || Template.isDependent(),
4773  IsDeducedAsDependent || Template.isInstantiationDependent(),
4774  Template.containsUnexpandedParameterPack()),
4775  Template(Template) {}
4776 
4777 public:
4778  /// Retrieve the name of the template that we are deducing.
4779  TemplateName getTemplateName() const { return Template;}
4780 
4781  void Profile(llvm::FoldingSetNodeID &ID) {
4782  Profile(ID, getTemplateName(), getDeducedType(), isDependentType());
4783  }
4784 
4785  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template,
4786  QualType Deduced, bool IsDependent) {
4787  Template.Profile(ID);
4788  ID.AddPointer(Deduced.getAsOpaquePtr());
4789  ID.AddBoolean(IsDependent);
4790  }
4791 
4792  static bool classof(const Type *T) {
4793  return T->getTypeClass() == DeducedTemplateSpecialization;
4794  }
4795 };
4796 
4797 /// Represents a type template specialization; the template
4798 /// must be a class template, a type alias template, or a template
4799 /// template parameter. A template which cannot be resolved to one of
4800 /// these, e.g. because it is written with a dependent scope
4801 /// specifier, is instead represented as a
4802 /// @c DependentTemplateSpecializationType.
4803 ///
4804 /// A non-dependent template specialization type is always "sugar",
4805 /// typically for a \c RecordType. For example, a class template
4806 /// specialization type of \c vector<int> will refer to a tag type for
4807 /// the instantiation \c std::vector<int, std::allocator<int>>
4808 ///
4809 /// Template specializations are dependent if either the template or
4810 /// any of the template arguments are dependent, in which case the
4811 /// type may also be canonical.
4812 ///
4813 /// Instances of this type are allocated with a trailing array of
4814 /// TemplateArguments, followed by a QualType representing the
4815 /// non-canonical aliased type when the template is a type alias
4816 /// template.
4818  : public Type,
4819  public llvm::FoldingSetNode {
4820  friend class ASTContext; // ASTContext creates these
4821 
4822  /// The name of the template being specialized. This is
4823  /// either a TemplateName::Template (in which case it is a
4824  /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a
4825  /// TypeAliasTemplateDecl*), a
4826  /// TemplateName::SubstTemplateTemplateParmPack, or a
4827  /// TemplateName::SubstTemplateTemplateParm (in which case the
4828  /// replacement must, recursively, be one of these).
4829  TemplateName Template;
4830 
4833  QualType Canon,
4834  QualType Aliased);
4835 
4836 public:
4837  /// Determine whether any of the given template arguments are dependent.
4838  static bool anyDependentTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
4839  bool &InstantiationDependent);
4840 
4841  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &,
4842  bool &InstantiationDependent);
4843 
4844  /// True if this template specialization type matches a current
4845  /// instantiation in the context in which it is found.
4846  bool isCurrentInstantiation() const {
4847  return isa<InjectedClassNameType>(getCanonicalTypeInternal());
4848  }
4849 
4850  /// Determine if this template specialization type is for a type alias
4851  /// template that has been substituted.
4852  ///
4853  /// Nearly every template specialization type whose template is an alias
4854  /// template will be substituted. However, this is not the case when
4855  /// the specialization contains a pack expansion but the template alias
4856  /// does not have a corresponding parameter pack, e.g.,
4857  ///
4858  /// \code
4859  /// template<typename T, typename U, typename V> struct S;
4860  /// template<typename T, typename U> using A = S<T, int, U>;
4861  /// template<typename... Ts> struct X {
4862  /// typedef A<Ts...> type; // not a type alias
4863  /// };
4864  /// \endcode
4865  bool isTypeAlias() const { return TemplateSpecializationTypeBits.TypeAlias; }
4866 
4867  /// Get the aliased type, if this is a specialization of a type alias
4868  /// template.
4870  assert(isTypeAlias() && "not a type alias template specialization");
4871  return *reinterpret_cast<const QualType*>(end());
4872  }
4873 
4874  using iterator = const TemplateArgument *;
4875 
4876  iterator begin() const { return getArgs(); }
4877  iterator end() const; // defined inline in TemplateBase.h
4878 
4879  /// Retrieve the name of the template that we are specializing.
4880  TemplateName getTemplateName() const { return Template; }
4881 
4882  /// Retrieve the template arguments.
4883  const TemplateArgument *getArgs() const {
4884  return reinterpret_cast<const TemplateArgument *>(this + 1);
4885  }
4886 
4887  /// Retrieve the number of template arguments.
4888  unsigned getNumArgs() const {
4889  return TemplateSpecializationTypeBits.NumArgs;
4890  }
4891 
4892  /// Retrieve a specific template argument as a type.
4893  /// \pre \c isArgType(Arg)
4894  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
4895 
4897  return {getArgs(), getNumArgs()};
4898  }
4899 
4900  bool isSugared() const {
4901  return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
4902  }
4903 
4904  QualType desugar() const { return getCanonicalTypeInternal(); }
4905 
4906  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
4907  Profile(ID, Template, template_arguments(), Ctx);
4908  if (isTypeAlias())
4909  getAliasedType().Profile(ID);
4910  }
4911 
4912  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
4914  const ASTContext &Context);
4915 
4916  static bool classof(const Type *T) {
4917  return T->getTypeClass() == TemplateSpecialization;
4918  }
4919 };
4920 
4921 /// Print a template argument list, including the '<' and '>'
4922 /// enclosing the template arguments.
4923 void printTemplateArgumentList(raw_ostream &OS,
4925  const PrintingPolicy &Policy);
4926 
4927 void printTemplateArgumentList(raw_ostream &OS,
4929  const PrintingPolicy &Policy);
4930 
4931 void printTemplateArgumentList(raw_ostream &OS,
4932  const TemplateArgumentListInfo &Args,
4933  const PrintingPolicy &Policy);
4934 
4935 /// The injected class name of a C++ class template or class
4936 /// template partial specialization. Used to record that a type was
4937 /// spelled with a bare identifier rather than as a template-id; the
4938 /// equivalent for non-templated classes is just RecordType.
4939 ///
4940 /// Injected class name types are always dependent. Template
4941 /// instantiation turns these into RecordTypes.
4942 ///
4943 /// Injected class name types are always canonical. This works
4944 /// because it is impossible to compare an injected class name type
4945 /// with the corresponding non-injected template type, for the same
4946 /// reason that it is impossible to directly compare template
4947 /// parameters from different dependent contexts: injected class name
4948 /// types can only occur within the scope of a particular templated
4949 /// declaration, and within that scope every template specialization
4950 /// will canonicalize to the injected class name (when appropriate
4951 /// according to the rules of the language).
4952 class InjectedClassNameType : public Type {
4953  friend class ASTContext; // ASTContext creates these.
4954  friend class ASTNodeImporter;
4955  friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
4956  // currently suitable for AST reading, too much
4957  // interdependencies.
4958 
4960 
4961  /// The template specialization which this type represents.
4962  /// For example, in
4963  /// template <class T> class A { ... };
4964  /// this is A<T>, whereas in
4965  /// template <class X, class Y> class A<B<X,Y> > { ... };
4966  /// this is A<B<X,Y> >.
4967  ///
4968  /// It is always unqualified, always a template specialization type,
4969  /// and always dependent.
4970  QualType InjectedType;
4971 
4973  : Type(InjectedClassName, QualType(), /*Dependent=*/true,
4974  /*InstantiationDependent=*/true,
4975  /*VariablyModified=*/false,
4976  /*ContainsUnexpandedParameterPack=*/false),
4977  Decl(D), InjectedType(TST) {
4978  assert(isa<TemplateSpecializationType>(TST));
4979  assert(!TST.hasQualifiers());
4980  assert(TST->isDependentType());
4981  }
4982 
4983 public:
4984  QualType getInjectedSpecializationType() const { return InjectedType; }
4985 
4987  return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
4988  }
4989 
4991  return getInjectedTST()->getTemplateName();
4992  }
4993 
4994  CXXRecordDecl *getDecl() const;
4995 
4996  bool isSugared() const { return false; }
4997  QualType desugar() const { return QualType(this, 0); }
4998 
4999  static bool classof(const Type *T) {
5000  return T->getTypeClass() == InjectedClassName;
5001  }
5002 };
5003 
5004 /// The kind of a tag type.
5006  /// The "struct" keyword.
5008 
5009  /// The "__interface" keyword.
5011 
5012  /// The "union" keyword.
5014 
5015  /// The "class" keyword.
5017 
5018  /// The "enum" keyword.
5020 };
5021 
5022 /// The elaboration keyword that precedes a qualified type name or
5023 /// introduces an elaborated-type-specifier.
5025  /// The "struct" keyword introduces the elaborated-type-specifier.
5027 
5028  /// The "__interface" keyword introduces the elaborated-type-specifier.
5030 
5031  /// The "union" keyword introduces the elaborated-type-specifier.
5033 
5034  /// The "class" keyword introduces the elaborated-type-specifier.
5036 
5037  /// The "enum" keyword introduces the elaborated-type-specifier.
5039 
5040  /// The "typename" keyword precedes the qualified type name, e.g.,
5041  /// \c typename T::type.
5043 
5044  /// No keyword precedes the qualified type name.
5046 };
5047 
5048 /// A helper class for Type nodes having an ElaboratedTypeKeyword.
5049 /// The keyword in stored in the free bits of the base class.
5050 /// Also provides a few static helpers for converting and printing
5051 /// elaborated type keyword and tag type kind enumerations.
5052 class TypeWithKeyword : public Type {
5053 protected:
5055  QualType Canonical, bool Dependent,
5056  bool InstantiationDependent, bool VariablyModified,
5057  bool ContainsUnexpandedParameterPack)
5058  : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
5059  ContainsUnexpandedParameterPack) {
5060  TypeWithKeywordBits.Keyword = Keyword;
5061  }
5062 
5063 public:
5065  return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
5066  }
5067 
5068  /// Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
5069  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
5070 
5071  /// Converts a type specifier (DeclSpec::TST) into a tag type kind.
5072  /// It is an error to provide a type specifier which *isn't* a tag kind here.
5073  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
5074 
5075  /// Converts a TagTypeKind into an elaborated type keyword.
5076  static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
5077 
5078  /// Converts an elaborated type keyword into a TagTypeKind.
5079  /// It is an error to provide an elaborated type keyword
5080  /// which *isn't* a tag kind here.
5081  static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
5082 
5083  static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
5084 
5085  static StringRef getKeywordName(ElaboratedTypeKeyword Keyword);
5086 
5088  return getKeywordName(getKeywordForTagTypeKind(Kind));
5089  }
5090 
5092  static CannotCastToThisType classof(const Type *);
5093 };
5094 
5095 /// Represents a type that was referred to using an elaborated type
5096 /// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
5097 /// or both.
5098 ///
5099 /// This type is used to keep track of a type name as written in the
5100 /// source code, including tag keywords and any nested-name-specifiers.
5101 /// The type itself is always "sugar", used to express what was written
5102 /// in the source code but containing no additional semantic information.
5103 class ElaboratedType final
5104  : public TypeWithKeyword,
5105  public llvm::FoldingSetNode,
5106  private llvm::TrailingObjects<ElaboratedType, TagDecl *> {
5107  friend class ASTContext; // ASTContext creates these
5108  friend TrailingObjects;
5109 
5110  /// The nested name specifier containing the qualifier.
5111  NestedNameSpecifier *NNS;
5112 
5113  /// The type that this qualified name refers to.
5114  QualType NamedType;
5115 
5116  /// The (re)declaration of this tag type owned by this occurrence is stored
5117  /// as a trailing object if there is one. Use getOwnedTagDecl to obtain
5118  /// it, or obtain a null pointer if there is none.
5119 
5121  QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl)
5122  : TypeWithKeyword(Keyword, Elaborated, CanonType,
5123  NamedType->isDependentType(),
5124  NamedType->isInstantiationDependentType(),
5125  NamedType->isVariablyModifiedType(),
5126  NamedType->containsUnexpandedParameterPack()),
5127  NNS(NNS), NamedType(NamedType) {
5128  ElaboratedTypeBits.HasOwnedTagDecl = false;
5129  if (OwnedTagDecl) {
5130  ElaboratedTypeBits.HasOwnedTagDecl = true;
5131  *getTrailingObjects<TagDecl *>() = OwnedTagDecl;
5132  }
5133  assert(!(Keyword == ETK_None && NNS == nullptr) &&
5134  "ElaboratedType cannot have elaborated type keyword "
5135  "and name qualifier both null.");
5136  }
5137 
5138 public:
5139  /// Retrieve the qualification on this type.
5140  NestedNameSpecifier *getQualifier() const { return NNS; }
5141 
5142  /// Retrieve the type named by the qualified-id.
5143  QualType getNamedType() const { return NamedType; }
5144 
5145  /// Remove a single level of sugar.
5146  QualType desugar() const { return getNamedType(); }
5147 
5148  /// Returns whether this type directly provides sugar.
5149  bool isSugared() const { return true; }
5150 
5151  /// Return the (re)declaration of this type owned by this occurrence of this
5152  /// type, or nullptr if there is none.
5154  return ElaboratedTypeBits.HasOwnedTagDecl ? *getTrailingObjects<TagDecl *>()
5155  : nullptr;
5156  }
5157 
5158  void Profile(llvm::FoldingSetNodeID &ID) {
5159  Profile(ID, getKeyword(), NNS, NamedType, getOwnedTagDecl());
5160  }
5161 
5162  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
5163  NestedNameSpecifier *NNS, QualType NamedType,
5164  TagDecl *OwnedTagDecl) {
5165  ID.AddInteger(Keyword);
5166  ID.AddPointer(NNS);
5167  NamedType.Profile(ID);
5168  ID.AddPointer(OwnedTagDecl);
5169  }
5170 
5171  static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; }
5172 };
5173 
5174 /// Represents a qualified type name for which the type name is
5175 /// dependent.
5176 ///
5177 /// DependentNameType represents a class of dependent types that involve a
5178 /// possibly dependent nested-name-specifier (e.g., "T::") followed by a
5179 /// name of a type. The DependentNameType may start with a "typename" (for a
5180 /// typename-specifier), "class", "struct", "union", or "enum" (for a
5181 /// dependent elaborated-type-specifier), or nothing (in contexts where we
5182 /// know that we must be referring to a type, e.g., in a base class specifier).
5183 /// Typically the nested-name-specifier is dependent, but in MSVC compatibility
5184 /// mode, this type is used with non-dependent names to delay name lookup until
5185 /// instantiation.
5186 class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
5187  friend class ASTContext; // ASTContext creates these
5188 
5189  /// The nested name specifier containing the qualifier.
5190  NestedNameSpecifier *NNS;
5191 
5192  /// The type that this typename specifier refers to.
5193  const IdentifierInfo *Name;
5194 
5196  const IdentifierInfo *Name, QualType CanonType)
5197  : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true,
5198  /*InstantiationDependent=*/true,
5199  /*VariablyModified=*/false,
5200  NNS->containsUnexpandedParameterPack()),
5201  NNS(NNS), Name(Name) {}
5202 
5203 public:
5204  /// Retrieve the qualification on this type.
5205  NestedNameSpecifier *getQualifier() const { return NNS; }
5206 
5207  /// Retrieve the type named by the typename specifier as an identifier.
5208  ///
5209  /// This routine will return a non-NULL identifier pointer when the
5210  /// form of the original typename was terminated by an identifier,
5211  /// e.g., "typename T::type".
5213  return Name;
5214  }
5215 
5216  bool isSugared() const { return false; }
5217  QualType desugar() const { return QualType(this, 0); }
5218 
5219  void Profile(llvm::FoldingSetNodeID &ID) {
5220  Profile(ID, getKeyword(), NNS, Name);
5221  }
5222 
5223  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
5224  NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
5225  ID.AddInteger(Keyword);
5226  ID.AddPointer(NNS);
5227  ID.AddPointer(Name);
5228  }
5229 
5230  static bool classof(const Type *T) {
5231  return T->getTypeClass() == DependentName;
5232  }
5233 };
5234 
5235 /// Represents a template specialization type whose template cannot be
5236 /// resolved, e.g.
5237 /// A<T>::template B<T>
5239  : public TypeWithKeyword,