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