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