clang  5.0.0
Type.h
Go to the documentation of this file.
1 //===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 /// \brief C Language Family Type Representation
11 ///
12 /// This file defines the clang::Type interface and subclasses, used to
13 /// represent types for languages in the C family.
14 ///
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_CLANG_AST_TYPE_H
18 #define LLVM_CLANG_AST_TYPE_H
19 
21 #include "clang/AST/TemplateName.h"
23 #include "clang/Basic/Diagnostic.h"
25 #include "clang/Basic/LLVM.h"
26 #include "clang/Basic/Linkage.h"
28 #include "clang/Basic/Specifiers.h"
29 #include "clang/Basic/Visibility.h"
30 #include "llvm/ADT/APInt.h"
31 #include "llvm/ADT/FoldingSet.h"
32 #include "llvm/ADT/Optional.h"
33 #include "llvm/ADT/PointerIntPair.h"
34 #include "llvm/ADT/PointerUnion.h"
35 #include "llvm/ADT/Twine.h"
36 #include "llvm/ADT/iterator_range.h"
37 #include "llvm/Support/ErrorHandling.h"
38 
39 namespace clang {
40  enum {
43  };
44  class Type;
45  class ExtQuals;
46  class QualType;
47 }
48 
49 namespace llvm {
50  template <typename T>
51  class PointerLikeTypeTraits;
52  template<>
54  public:
55  static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
56  static inline ::clang::Type *getFromVoidPointer(void *P) {
57  return static_cast< ::clang::Type*>(P);
58  }
59  enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
60  };
61  template<>
63  public:
64  static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
65  static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
66  return static_cast< ::clang::ExtQuals*>(P);
67  }
68  enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
69  };
70 
71  template <>
72  struct isPodLike<clang::QualType> { static const bool value = true; };
73 }
74 
75 namespace clang {
76  class ASTContext;
77  class TypedefNameDecl;
78  class TemplateDecl;
79  class TemplateTypeParmDecl;
80  class NonTypeTemplateParmDecl;
81  class TemplateTemplateParmDecl;
82  class TagDecl;
83  class RecordDecl;
84  class CXXRecordDecl;
85  class EnumDecl;
86  class FieldDecl;
87  class FunctionDecl;
88  class ObjCInterfaceDecl;
89  class ObjCProtocolDecl;
90  class ObjCMethodDecl;
91  class ObjCTypeParamDecl;
92  class UnresolvedUsingTypenameDecl;
93  class Expr;
94  class Stmt;
95  class SourceLocation;
96  class StmtIteratorBase;
97  class TemplateArgument;
98  class TemplateArgumentLoc;
99  class TemplateArgumentListInfo;
100  class ElaboratedType;
101  class ExtQuals;
102  class ExtQualsTypeCommonBase;
103  struct PrintingPolicy;
104 
105  template <typename> class CanQual;
106  typedef CanQual<Type> CanQualType;
107 
108  // Provide forward declarations for all of the *Type classes
109 #define TYPE(Class, Base) class Class##Type;
110 #include "clang/AST/TypeNodes.def"
111 
112 /// The collection of all-type qualifiers we support.
113 /// Clang supports five independent qualifiers:
114 /// * C99: const, volatile, and restrict
115 /// * MS: __unaligned
116 /// * Embedded C (TR18037): address spaces
117 /// * Objective C: the GC attributes (none, weak, or strong)
118 class Qualifiers {
119 public:
120  enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
121  Const = 0x1,
122  Restrict = 0x2,
123  Volatile = 0x4,
125  };
126 
127  enum GC {
128  GCNone = 0,
131  };
132 
134  /// There is no lifetime qualification on this type.
136 
137  /// This object can be modified without requiring retains or
138  /// releases.
140 
141  /// Assigning into this object requires the old value to be
142  /// released and the new value to be retained. The timing of the
143  /// release of the old value is inexact: it may be moved to
144  /// immediately after the last known point where the value is
145  /// live.
147 
148  /// Reading or writing from this object requires a barrier call.
150 
151  /// Assigning into this object requires a lifetime extension.
153  };
154 
155  enum {
156  /// The maximum supported address space number.
157  /// 23 bits should be enough for anyone.
158  MaxAddressSpace = 0x7fffffu,
159 
160  /// The width of the "fast" qualifier mask.
162 
163  /// The fast qualifier mask.
164  FastMask = (1 << FastWidth) - 1
165  };
166 
167  Qualifiers() : Mask(0) {}
168 
169  /// Returns the common set of qualifiers while removing them from
170  /// the given sets.
172  // If both are only CVR-qualified, bit operations are sufficient.
173  if (!(L.Mask & ~CVRMask) && !(R.Mask & ~CVRMask)) {
174  Qualifiers Q;
175  Q.Mask = L.Mask & R.Mask;
176  L.Mask &= ~Q.Mask;
177  R.Mask &= ~Q.Mask;
178  return Q;
179  }
180 
181  Qualifiers Q;
182  unsigned CommonCRV = L.getCVRQualifiers() & R.getCVRQualifiers();
183  Q.addCVRQualifiers(CommonCRV);
184  L.removeCVRQualifiers(CommonCRV);
185  R.removeCVRQualifiers(CommonCRV);
186 
187  if (L.getObjCGCAttr() == R.getObjCGCAttr()) {
189  L.removeObjCGCAttr();
190  R.removeObjCGCAttr();
191  }
192 
193  if (L.getObjCLifetime() == R.getObjCLifetime()) {
195  L.removeObjCLifetime();
196  R.removeObjCLifetime();
197  }
198 
199  if (L.getAddressSpace() == R.getAddressSpace()) {
201  L.removeAddressSpace();
202  R.removeAddressSpace();
203  }
204  return Q;
205  }
206 
207  static Qualifiers fromFastMask(unsigned Mask) {
208  Qualifiers Qs;
209  Qs.addFastQualifiers(Mask);
210  return Qs;
211  }
212 
213  static Qualifiers fromCVRMask(unsigned CVR) {
214  Qualifiers Qs;
215  Qs.addCVRQualifiers(CVR);
216  return Qs;
217  }
218 
219  static Qualifiers fromCVRUMask(unsigned CVRU) {
220  Qualifiers Qs;
221  Qs.addCVRUQualifiers(CVRU);
222  return Qs;
223  }
224 
225  // Deserialize qualifiers from an opaque representation.
226  static Qualifiers fromOpaqueValue(unsigned opaque) {
227  Qualifiers Qs;
228  Qs.Mask = opaque;
229  return Qs;
230  }
231 
232  // Serialize these qualifiers into an opaque representation.
233  unsigned getAsOpaqueValue() const {
234  return Mask;
235  }
236 
237  bool hasConst() const { return Mask & Const; }
238  void setConst(bool flag) {
239  Mask = (Mask & ~Const) | (flag ? Const : 0);
240  }
241  void removeConst() { Mask &= ~Const; }
242  void addConst() { Mask |= Const; }
243 
244  bool hasVolatile() const { return Mask & Volatile; }
245  void setVolatile(bool flag) {
246  Mask = (Mask & ~Volatile) | (flag ? Volatile : 0);
247  }
248  void removeVolatile() { Mask &= ~Volatile; }
249  void addVolatile() { Mask |= Volatile; }
250 
251  bool hasRestrict() const { return Mask & Restrict; }
252  void setRestrict(bool flag) {
253  Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
254  }
255  void removeRestrict() { Mask &= ~Restrict; }
256  void addRestrict() { Mask |= Restrict; }
257 
258  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
259  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
260  void setCVRQualifiers(unsigned mask) {
261  assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
262  Mask = (Mask & ~CVRMask) | mask;
263  }
264  void removeCVRQualifiers(unsigned mask) {
265  assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
266  Mask &= ~mask;
267  }
270  }
271  void addCVRQualifiers(unsigned mask) {
272  assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
273  Mask |= mask;
274  }
275  void addCVRUQualifiers(unsigned mask) {
276  assert(!(mask & ~CVRMask & ~UMask) && "bitmask contains non-CVRU bits");
277  Mask |= mask;
278  }
279 
280  bool hasUnaligned() const { return Mask & UMask; }
281  void setUnaligned(bool flag) {
282  Mask = (Mask & ~UMask) | (flag ? UMask : 0);
283  }
284  void removeUnaligned() { Mask &= ~UMask; }
285  void addUnaligned() { Mask |= UMask; }
286 
287  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
288  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
290  Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
291  }
294  assert(type);
295  setObjCGCAttr(type);
296  }
298  Qualifiers qs = *this;
299  qs.removeObjCGCAttr();
300  return qs;
301  }
303  Qualifiers qs = *this;
304  qs.removeObjCLifetime();
305  return qs;
306  }
307 
308  bool hasObjCLifetime() const { return Mask & LifetimeMask; }
310  return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
311  }
313  Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
314  }
317  assert(type);
318  assert(!hasObjCLifetime());
319  Mask |= (type << LifetimeShift);
320  }
321 
322  /// True if the lifetime is neither None or ExplicitNone.
324  ObjCLifetime lifetime = getObjCLifetime();
325  return (lifetime > OCL_ExplicitNone);
326  }
327 
328  /// True if the lifetime is either strong or weak.
330  ObjCLifetime lifetime = getObjCLifetime();
331  return (lifetime == OCL_Strong || lifetime == OCL_Weak);
332  }
333 
334  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
335  unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }
338  }
339  /// Get the address space attribute value to be printed by diagnostics.
341  auto Addr = getAddressSpace();
342  // This function is not supposed to be used with language specific
343  // address spaces. If that happens, the diagnostic message should consider
344  // printing the QualType instead of the address space value.
345  assert(Addr == 0 || hasTargetSpecificAddressSpace());
346  if (Addr)
347  return Addr - LangAS::FirstTargetAddressSpace;
348  // TODO: The diagnostic messages where Addr may be 0 should be fixed
349  // since it cannot differentiate the situation where 0 denotes the default
350  // address space or user specified __attribute__((address_space(0))).
351  return 0;
352  }
353  void setAddressSpace(unsigned space) {
354  assert(space <= MaxAddressSpace);
355  Mask = (Mask & ~AddressSpaceMask)
356  | (((uint32_t) space) << AddressSpaceShift);
357  }
359  void addAddressSpace(unsigned space) {
360  assert(space);
361  setAddressSpace(space);
362  }
363 
364  // Fast qualifiers are those that can be allocated directly
365  // on a QualType object.
366  bool hasFastQualifiers() const { return getFastQualifiers(); }
367  unsigned getFastQualifiers() const { return Mask & FastMask; }
368  void setFastQualifiers(unsigned mask) {
369  assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
370  Mask = (Mask & ~FastMask) | mask;
371  }
372  void removeFastQualifiers(unsigned mask) {
373  assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
374  Mask &= ~mask;
375  }
378  }
379  void addFastQualifiers(unsigned mask) {
380  assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
381  Mask |= mask;
382  }
383 
384  /// Return true if the set contains any qualifiers which require an ExtQuals
385  /// node to be allocated.
386  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
388  Qualifiers Quals = *this;
389  Quals.setFastQualifiers(0);
390  return Quals;
391  }
392 
393  /// Return true if the set contains any qualifiers.
394  bool hasQualifiers() const { return Mask; }
395  bool empty() const { return !Mask; }
396 
397  /// Add the qualifiers from the given set to this set.
399  // If the other set doesn't have any non-boolean qualifiers, just
400  // bit-or it in.
401  if (!(Q.Mask & ~CVRMask))
402  Mask |= Q.Mask;
403  else {
404  Mask |= (Q.Mask & CVRMask);
405  if (Q.hasAddressSpace())
407  if (Q.hasObjCGCAttr())
409  if (Q.hasObjCLifetime())
411  }
412  }
413 
414  /// \brief Remove the qualifiers from the given set from this set.
416  // If the other set doesn't have any non-boolean qualifiers, just
417  // bit-and the inverse in.
418  if (!(Q.Mask & ~CVRMask))
419  Mask &= ~Q.Mask;
420  else {
421  Mask &= ~(Q.Mask & CVRMask);
422  if (getObjCGCAttr() == Q.getObjCGCAttr())
424  if (getObjCLifetime() == Q.getObjCLifetime())
426  if (getAddressSpace() == Q.getAddressSpace())
428  }
429  }
430 
431  /// Add the qualifiers from the given set to this set, given that
432  /// they don't conflict.
434  assert(getAddressSpace() == qs.getAddressSpace() ||
435  !hasAddressSpace() || !qs.hasAddressSpace());
436  assert(getObjCGCAttr() == qs.getObjCGCAttr() ||
437  !hasObjCGCAttr() || !qs.hasObjCGCAttr());
438  assert(getObjCLifetime() == qs.getObjCLifetime() ||
439  !hasObjCLifetime() || !qs.hasObjCLifetime());
440  Mask |= qs.Mask;
441  }
442 
443  /// Returns true if this address space is a superset of the other one.
444  /// OpenCL v2.0 defines conversion rules (OpenCLC v2.0 s6.5.5) and notion of
445  /// overlapping address spaces.
446  /// CL1.1 or CL1.2:
447  /// every address space is a superset of itself.
448  /// CL2.0 adds:
449  /// __generic is a superset of any address space except for __constant.
451  return
452  // Address spaces must match exactly.
453  getAddressSpace() == other.getAddressSpace() ||
454  // Otherwise in OpenCLC v2.0 s6.5.5: every address space except
455  // for __constant can be used as __generic.
458  }
459 
460  /// Determines if these qualifiers compatibly include another set.
461  /// Generally this answers the question of whether an object with the other
462  /// qualifiers can be safely used as an object with these qualifiers.
463  bool compatiblyIncludes(Qualifiers other) const {
464  return isAddressSpaceSupersetOf(other) &&
465  // ObjC GC qualifiers can match, be added, or be removed, but can't
466  // be changed.
467  (getObjCGCAttr() == other.getObjCGCAttr() || !hasObjCGCAttr() ||
468  !other.hasObjCGCAttr()) &&
469  // ObjC lifetime qualifiers must match exactly.
470  getObjCLifetime() == other.getObjCLifetime() &&
471  // CVR qualifiers may subset.
472  (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) &&
473  // U qualifier may superset.
474  (!other.hasUnaligned() || hasUnaligned());
475  }
476 
477  /// \brief Determines if these qualifiers compatibly include another set of
478  /// qualifiers from the narrow perspective of Objective-C ARC lifetime.
479  ///
480  /// One set of Objective-C lifetime qualifiers compatibly includes the other
481  /// if the lifetime qualifiers match, or if both are non-__weak and the
482  /// including set also contains the 'const' qualifier, or both are non-__weak
483  /// and one is None (which can only happen in non-ARC modes).
485  if (getObjCLifetime() == other.getObjCLifetime())
486  return true;
487 
488  if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak)
489  return false;
490 
491  if (getObjCLifetime() == OCL_None || other.getObjCLifetime() == OCL_None)
492  return true;
493 
494  return hasConst();
495  }
496 
497  /// \brief Determine whether this set of qualifiers is a strict superset of
498  /// another set of qualifiers, not considering qualifier compatibility.
499  bool isStrictSupersetOf(Qualifiers Other) const;
500 
501  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
502  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
503 
504  explicit operator bool() const { return hasQualifiers(); }
505 
507  addQualifiers(R);
508  return *this;
509  }
510 
511  // Union two qualifier sets. If an enumerated qualifier appears
512  // in both sets, use the one from the right.
514  L += R;
515  return L;
516  }
517 
519  removeQualifiers(R);
520  return *this;
521  }
522 
523  /// \brief Compute the difference between two qualifier sets.
525  L -= R;
526  return L;
527  }
528 
529  std::string getAsString() const;
530  std::string getAsString(const PrintingPolicy &Policy) const;
531 
532  bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const;
533  void print(raw_ostream &OS, const PrintingPolicy &Policy,
534  bool appendSpaceIfNonEmpty = false) const;
535 
536  void Profile(llvm::FoldingSetNodeID &ID) const {
537  ID.AddInteger(Mask);
538  }
539 
540 private:
541 
542  // bits: |0 1 2|3|4 .. 5|6 .. 8|9 ... 31|
543  // |C R V|U|GCAttr|Lifetime|AddressSpace|
544  uint32_t Mask;
545 
546  static const uint32_t UMask = 0x8;
547  static const uint32_t UShift = 3;
548  static const uint32_t GCAttrMask = 0x30;
549  static const uint32_t GCAttrShift = 4;
550  static const uint32_t LifetimeMask = 0x1C0;
551  static const uint32_t LifetimeShift = 6;
552  static const uint32_t AddressSpaceMask =
553  ~(CVRMask | UMask | GCAttrMask | LifetimeMask);
554  static const uint32_t AddressSpaceShift = 9;
555 };
556 
557 /// A std::pair-like structure for storing a qualified type split
558 /// into its local qualifiers and its locally-unqualified type.
560  /// The locally-unqualified type.
561  const Type *Ty;
562 
563  /// The local qualifiers.
565 
566  SplitQualType() : Ty(nullptr), Quals() {}
567  SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {}
568 
569  SplitQualType getSingleStepDesugaredType() const; // end of this file
570 
571  // Make std::tie work.
572  std::pair<const Type *,Qualifiers> asPair() const {
573  return std::pair<const Type *, Qualifiers>(Ty, Quals);
574  }
575 
577  return a.Ty == b.Ty && a.Quals == b.Quals;
578  }
580  return a.Ty != b.Ty || a.Quals != b.Quals;
581  }
582 };
583 
584 /// The kind of type we are substituting Objective-C type arguments into.
585 ///
586 /// The kind of substitution affects the replacement of type parameters when
587 /// no concrete type information is provided, e.g., when dealing with an
588 /// unspecialized type.
590  /// An ordinary type.
591  Ordinary,
592  /// The result type of a method or function.
593  Result,
594  /// The parameter type of a method or function.
595  Parameter,
596  /// The type of a property.
597  Property,
598  /// The superclass of a type.
599  Superclass,
600 };
601 
602 /// A (possibly-)qualified type.
603 ///
604 /// For efficiency, we don't store CV-qualified types as nodes on their
605 /// own: instead each reference to a type stores the qualifiers. This
606 /// greatly reduces the number of nodes we need to allocate for types (for
607 /// example we only need one for 'int', 'const int', 'volatile int',
608 /// 'const volatile int', etc).
609 ///
610 /// As an added efficiency bonus, instead of making this a pair, we
611 /// just store the two bits we care about in the low bits of the
612 /// pointer. To handle the packing/unpacking, we make QualType be a
613 /// simple wrapper class that acts like a smart pointer. A third bit
614 /// indicates whether there are extended qualifiers present, in which
615 /// case the pointer points to a special structure.
616 class QualType {
617  // Thankfully, these are efficiently composable.
618  llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>,
620 
621  const ExtQuals *getExtQualsUnsafe() const {
622  return Value.getPointer().get<const ExtQuals*>();
623  }
624 
625  const Type *getTypePtrUnsafe() const {
626  return Value.getPointer().get<const Type*>();
627  }
628 
629  const ExtQualsTypeCommonBase *getCommonPtr() const {
630  assert(!isNull() && "Cannot retrieve a NULL type pointer");
631  uintptr_t CommonPtrVal
632  = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
633  CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
634  return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
635  }
636 
637  friend class QualifierCollector;
638 public:
639  QualType() {}
640 
641  QualType(const Type *Ptr, unsigned Quals)
642  : Value(Ptr, Quals) {}
643  QualType(const ExtQuals *Ptr, unsigned Quals)
644  : Value(Ptr, Quals) {}
645 
646  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
647  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
648 
649  /// Retrieves a pointer to the underlying (unqualified) type.
650  ///
651  /// This function requires that the type not be NULL. If the type might be
652  /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
653  const Type *getTypePtr() const;
654 
655  const Type *getTypePtrOrNull() const;
656 
657  /// Retrieves a pointer to the name of the base type.
658  const IdentifierInfo *getBaseTypeIdentifier() const;
659 
660  /// Divides a QualType into its unqualified type and a set of local
661  /// qualifiers.
662  SplitQualType split() const;
663 
664  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
665  static QualType getFromOpaquePtr(const void *Ptr) {
666  QualType T;
667  T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
668  return T;
669  }
670 
671  const Type &operator*() const {
672  return *getTypePtr();
673  }
674 
675  const Type *operator->() const {
676  return getTypePtr();
677  }
678 
679  bool isCanonical() const;
680  bool isCanonicalAsParam() const;
681 
682  /// Return true if this QualType doesn't point to a type yet.
683  bool isNull() const {
684  return Value.getPointer().isNull();
685  }
686 
687  /// \brief Determine whether this particular QualType instance has the
688  /// "const" qualifier set, without looking through typedefs that may have
689  /// added "const" at a different level.
690  bool isLocalConstQualified() const {
691  return (getLocalFastQualifiers() & Qualifiers::Const);
692  }
693 
694  /// \brief Determine whether this type is const-qualified.
695  bool isConstQualified() const;
696 
697  /// \brief Determine whether this particular QualType instance has the
698  /// "restrict" qualifier set, without looking through typedefs that may have
699  /// added "restrict" at a different level.
701  return (getLocalFastQualifiers() & Qualifiers::Restrict);
702  }
703 
704  /// \brief Determine whether this type is restrict-qualified.
705  bool isRestrictQualified() const;
706 
707  /// \brief Determine whether this particular QualType instance has the
708  /// "volatile" qualifier set, without looking through typedefs that may have
709  /// added "volatile" at a different level.
711  return (getLocalFastQualifiers() & Qualifiers::Volatile);
712  }
713 
714  /// \brief Determine whether this type is volatile-qualified.
715  bool isVolatileQualified() const;
716 
717  /// \brief Determine whether this particular QualType instance has any
718  /// qualifiers, without looking through any typedefs that might add
719  /// qualifiers at a different level.
720  bool hasLocalQualifiers() const {
721  return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
722  }
723 
724  /// \brief Determine whether this type has any qualifiers.
725  bool hasQualifiers() const;
726 
727  /// \brief Determine whether this particular QualType instance has any
728  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
729  /// instance.
731  return Value.getPointer().is<const ExtQuals*>();
732  }
733 
734  /// \brief Retrieve the set of qualifiers local to this particular QualType
735  /// instance, not including any qualifiers acquired through typedefs or
736  /// other sugar.
737  Qualifiers getLocalQualifiers() const;
738 
739  /// \brief Retrieve the set of qualifiers applied to this type.
740  Qualifiers getQualifiers() const;
741 
742  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
743  /// local to this particular QualType instance, not including any qualifiers
744  /// acquired through typedefs or other sugar.
745  unsigned getLocalCVRQualifiers() const {
746  return getLocalFastQualifiers();
747  }
748 
749  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
750  /// applied to this type.
751  unsigned getCVRQualifiers() const;
752 
753  bool isConstant(const ASTContext& Ctx) const {
754  return QualType::isConstant(*this, Ctx);
755  }
756 
757  /// \brief Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
758  bool isPODType(const ASTContext &Context) const;
759 
760  /// Return true if this is a POD type according to the rules of the C++98
761  /// standard, regardless of the current compilation's language.
762  bool isCXX98PODType(const ASTContext &Context) const;
763 
764  /// Return true if this is a POD type according to the more relaxed rules
765  /// of the C++11 standard, regardless of the current compilation's language.
766  /// (C++0x [basic.types]p9)
767  bool isCXX11PODType(const ASTContext &Context) const;
768 
769  /// Return true if this is a trivial type per (C++0x [basic.types]p9)
770  bool isTrivialType(const ASTContext &Context) const;
771 
772  /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
773  bool isTriviallyCopyableType(const ASTContext &Context) const;
774 
775  // Don't promise in the API that anything besides 'const' can be
776  // easily added.
777 
778  /// Add the `const` type qualifier to this QualType.
779  void addConst() {
781  }
782  QualType withConst() const {
783  return withFastQualifiers(Qualifiers::Const);
784  }
785 
786  /// Add the `volatile` type qualifier to this QualType.
787  void addVolatile() {
789  }
791  return withFastQualifiers(Qualifiers::Volatile);
792  }
793 
794  /// Add the `restrict` qualifier to this QualType.
795  void addRestrict() {
797  }
799  return withFastQualifiers(Qualifiers::Restrict);
800  }
801 
802  QualType withCVRQualifiers(unsigned CVR) const {
803  return withFastQualifiers(CVR);
804  }
805 
806  void addFastQualifiers(unsigned TQs) {
807  assert(!(TQs & ~Qualifiers::FastMask)
808  && "non-fast qualifier bits set in mask!");
809  Value.setInt(Value.getInt() | TQs);
810  }
811 
812  void removeLocalConst();
813  void removeLocalVolatile();
814  void removeLocalRestrict();
815  void removeLocalCVRQualifiers(unsigned Mask);
816 
817  void removeLocalFastQualifiers() { Value.setInt(0); }
818  void removeLocalFastQualifiers(unsigned Mask) {
819  assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
820  Value.setInt(Value.getInt() & ~Mask);
821  }
822 
823  // Creates a type with the given qualifiers in addition to any
824  // qualifiers already on this type.
825  QualType withFastQualifiers(unsigned TQs) const {
826  QualType T = *this;
827  T.addFastQualifiers(TQs);
828  return T;
829  }
830 
831  // Creates a type with exactly the given fast qualifiers, removing
832  // any existing fast qualifiers.
834  return withoutLocalFastQualifiers().withFastQualifiers(TQs);
835  }
836 
837  // Removes fast qualifiers, but leaves any extended qualifiers in place.
839  QualType T = *this;
841  return T;
842  }
843 
844  QualType getCanonicalType() const;
845 
846  /// \brief Return this type with all of the instance-specific qualifiers
847  /// removed, but without removing any qualifiers that may have been applied
848  /// through typedefs.
849  QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
850 
851  /// \brief Retrieve the unqualified variant of the given type,
852  /// removing as little sugar as possible.
853  ///
854  /// This routine looks through various kinds of sugar to find the
855  /// least-desugared type that is unqualified. For example, given:
856  ///
857  /// \code
858  /// typedef int Integer;
859  /// typedef const Integer CInteger;
860  /// typedef CInteger DifferenceType;
861  /// \endcode
862  ///
863  /// Executing \c getUnqualifiedType() on the type \c DifferenceType will
864  /// desugar until we hit the type \c Integer, which has no qualifiers on it.
865  ///
866  /// The resulting type might still be qualified if it's sugar for an array
867  /// type. To strip qualifiers even from within a sugared array type, use
868  /// ASTContext::getUnqualifiedArrayType.
869  inline QualType getUnqualifiedType() const;
870 
871  /// Retrieve the unqualified variant of the given type, removing as little
872  /// sugar as possible.
873  ///
874  /// Like getUnqualifiedType(), but also returns the set of
875  /// qualifiers that were built up.
876  ///
877  /// The resulting type might still be qualified if it's sugar for an array
878  /// type. To strip qualifiers even from within a sugared array type, use
879  /// ASTContext::getUnqualifiedArrayType.
880  inline SplitQualType getSplitUnqualifiedType() const;
881 
882  /// \brief Determine whether this type is more qualified than the other
883  /// given type, requiring exact equality for non-CVR qualifiers.
884  bool isMoreQualifiedThan(QualType Other) const;
885 
886  /// \brief Determine whether this type is at least as qualified as the other
887  /// given type, requiring exact equality for non-CVR qualifiers.
888  bool isAtLeastAsQualifiedAs(QualType Other) const;
889 
890  QualType getNonReferenceType() const;
891 
892  /// \brief Determine the type of a (typically non-lvalue) expression with the
893  /// specified result type.
894  ///
895  /// This routine should be used for expressions for which the return type is
896  /// explicitly specified (e.g., in a cast or call) and isn't necessarily
897  /// an lvalue. It removes a top-level reference (since there are no
898  /// expressions of reference type) and deletes top-level cvr-qualifiers
899  /// from non-class types (in C++) or all types (in C).
900  QualType getNonLValueExprType(const ASTContext &Context) const;
901 
902  /// Return the specified type with any "sugar" removed from
903  /// the type. This takes off typedefs, typeof's etc. If the outer level of
904  /// the type is already concrete, it returns it unmodified. This is similar
905  /// to getting the canonical type, but it doesn't remove *all* typedefs. For
906  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
907  /// concrete.
908  ///
909  /// Qualifiers are left in place.
911  return getDesugaredType(*this, Context);
912  }
913 
915  return getSplitDesugaredType(*this);
916  }
917 
918  /// \brief Return the specified type with one level of "sugar" removed from
919  /// the type.
920  ///
921  /// This routine takes off the first typedef, typeof, etc. If the outer level
922  /// of the type is already concrete, it returns it unmodified.
924  return getSingleStepDesugaredTypeImpl(*this, Context);
925  }
926 
927  /// Returns the specified type after dropping any
928  /// outer-level parentheses.
930  if (isa<ParenType>(*this))
931  return QualType::IgnoreParens(*this);
932  return *this;
933  }
934 
935  /// Indicate whether the specified types and qualifiers are identical.
936  friend bool operator==(const QualType &LHS, const QualType &RHS) {
937  return LHS.Value == RHS.Value;
938  }
939  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
940  return LHS.Value != RHS.Value;
941  }
942  std::string getAsString() const {
943  return getAsString(split());
944  }
945  static std::string getAsString(SplitQualType split) {
946  return getAsString(split.Ty, split.Quals);
947  }
948  static std::string getAsString(const Type *ty, Qualifiers qs);
949 
950  std::string getAsString(const PrintingPolicy &Policy) const;
951 
952  void print(raw_ostream &OS, const PrintingPolicy &Policy,
953  const Twine &PlaceHolder = Twine(),
954  unsigned Indentation = 0) const {
955  print(split(), OS, Policy, PlaceHolder, Indentation);
956  }
957  static void print(SplitQualType split, raw_ostream &OS,
958  const PrintingPolicy &policy, const Twine &PlaceHolder,
959  unsigned Indentation = 0) {
960  return print(split.Ty, split.Quals, OS, policy, PlaceHolder, Indentation);
961  }
962  static void print(const Type *ty, Qualifiers qs,
963  raw_ostream &OS, const PrintingPolicy &policy,
964  const Twine &PlaceHolder,
965  unsigned Indentation = 0);
966 
967  void getAsStringInternal(std::string &Str,
968  const PrintingPolicy &Policy) const {
969  return getAsStringInternal(split(), Str, Policy);
970  }
971  static void getAsStringInternal(SplitQualType split, std::string &out,
972  const PrintingPolicy &policy) {
973  return getAsStringInternal(split.Ty, split.Quals, out, policy);
974  }
975  static void getAsStringInternal(const Type *ty, Qualifiers qs,
976  std::string &out,
977  const PrintingPolicy &policy);
978 
980  const QualType &T;
981  const PrintingPolicy &Policy;
982  const Twine &PlaceHolder;
983  unsigned Indentation;
984  public:
986  const Twine &PlaceHolder, unsigned Indentation)
987  : T(T), Policy(Policy), PlaceHolder(PlaceHolder),
988  Indentation(Indentation) { }
989 
990  friend raw_ostream &operator<<(raw_ostream &OS,
991  const StreamedQualTypeHelper &SQT) {
992  SQT.T.print(OS, SQT.Policy, SQT.PlaceHolder, SQT.Indentation);
993  return OS;
994  }
995  };
996 
998  const Twine &PlaceHolder = Twine(),
999  unsigned Indentation = 0) const {
1000  return StreamedQualTypeHelper(*this, Policy, PlaceHolder, Indentation);
1001  }
1002 
1003  void dump(const char *s) const;
1004  void dump() const;
1005  void dump(llvm::raw_ostream &OS) const;
1006 
1007  void Profile(llvm::FoldingSetNodeID &ID) const {
1008  ID.AddPointer(getAsOpaquePtr());
1009  }
1010 
1011  /// Return the address space of this type.
1012  inline unsigned getAddressSpace() const;
1013 
1014  /// Returns gc attribute of this type.
1015  inline Qualifiers::GC getObjCGCAttr() const;
1016 
1017  /// true when Type is objc's weak.
1018  bool isObjCGCWeak() const {
1019  return getObjCGCAttr() == Qualifiers::Weak;
1020  }
1021 
1022  /// true when Type is objc's strong.
1023  bool isObjCGCStrong() const {
1024  return getObjCGCAttr() == Qualifiers::Strong;
1025  }
1026 
1027  /// Returns lifetime attribute of this type.
1029  return getQualifiers().getObjCLifetime();
1030  }
1031 
1033  return getQualifiers().hasNonTrivialObjCLifetime();
1034  }
1035 
1037  return getQualifiers().hasStrongOrWeakObjCLifetime();
1038  }
1039 
1040  // true when Type is objc's weak and weak is enabled but ARC isn't.
1041  bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const;
1042 
1047  DK_objc_weak_lifetime
1048  };
1049 
1050  /// Returns a nonzero value if objects of this type require
1051  /// non-trivial work to clean up after. Non-zero because it's
1052  /// conceivable that qualifiers (objc_gc(weak)?) could make
1053  /// something require destruction.
1055  return isDestructedTypeImpl(*this);
1056  }
1057 
1058  /// Determine whether expressions of the given type are forbidden
1059  /// from being lvalues in C.
1060  ///
1061  /// The expression types that are forbidden to be lvalues are:
1062  /// - 'void', but not qualified void
1063  /// - function types
1064  ///
1065  /// The exact rule here is C99 6.3.2.1:
1066  /// An lvalue is an expression with an object type or an incomplete
1067  /// type other than void.
1068  bool isCForbiddenLValueType() const;
1069 
1070  /// Substitute type arguments for the Objective-C type parameters used in the
1071  /// subject type.
1072  ///
1073  /// \param ctx ASTContext in which the type exists.
1074  ///
1075  /// \param typeArgs The type arguments that will be substituted for the
1076  /// Objective-C type parameters in the subject type, which are generally
1077  /// computed via \c Type::getObjCSubstitutions. If empty, the type
1078  /// parameters will be replaced with their bounds or id/Class, as appropriate
1079  /// for the context.
1080  ///
1081  /// \param context The context in which the subject type was written.
1082  ///
1083  /// \returns the resulting type.
1084  QualType substObjCTypeArgs(ASTContext &ctx,
1085  ArrayRef<QualType> typeArgs,
1086  ObjCSubstitutionContext context) const;
1087 
1088  /// Substitute type arguments from an object type for the Objective-C type
1089  /// parameters used in the subject type.
1090  ///
1091  /// This operation combines the computation of type arguments for
1092  /// substitution (\c Type::getObjCSubstitutions) with the actual process of
1093  /// substitution (\c QualType::substObjCTypeArgs) for the convenience of
1094  /// callers that need to perform a single substitution in isolation.
1095  ///
1096  /// \param objectType The type of the object whose member type we're
1097  /// substituting into. For example, this might be the receiver of a message
1098  /// or the base of a property access.
1099  ///
1100  /// \param dc The declaration context from which the subject type was
1101  /// retrieved, which indicates (for example) which type parameters should
1102  /// be substituted.
1103  ///
1104  /// \param context The context in which the subject type was written.
1105  ///
1106  /// \returns the subject type after replacing all of the Objective-C type
1107  /// parameters with their corresponding arguments.
1108  QualType substObjCMemberType(QualType objectType,
1109  const DeclContext *dc,
1110  ObjCSubstitutionContext context) const;
1111 
1112  /// Strip Objective-C "__kindof" types from the given type.
1113  QualType stripObjCKindOfType(const ASTContext &ctx) const;
1114 
1115  /// Remove all qualifiers including _Atomic.
1116  QualType getAtomicUnqualifiedType() const;
1117 
1118 private:
1119  // These methods are implemented in a separate translation unit;
1120  // "static"-ize them to avoid creating temporary QualTypes in the
1121  // caller.
1122  static bool isConstant(QualType T, const ASTContext& Ctx);
1123  static QualType getDesugaredType(QualType T, const ASTContext &Context);
1124  static SplitQualType getSplitDesugaredType(QualType T);
1125  static SplitQualType getSplitUnqualifiedTypeImpl(QualType type);
1126  static QualType getSingleStepDesugaredTypeImpl(QualType type,
1127  const ASTContext &C);
1128  static QualType IgnoreParens(QualType T);
1129  static DestructionKind isDestructedTypeImpl(QualType type);
1130 };
1131 
1132 } // end clang.
1133 
1134 namespace llvm {
1135 /// Implement simplify_type for QualType, so that we can dyn_cast from QualType
1136 /// to a specific Type class.
1137 template<> struct simplify_type< ::clang::QualType> {
1138  typedef const ::clang::Type *SimpleType;
1139  static SimpleType getSimplifiedValue(::clang::QualType Val) {
1140  return Val.getTypePtr();
1141  }
1142 };
1143 
1144 // Teach SmallPtrSet that QualType is "basically a pointer".
1145 template<>
1146 class PointerLikeTypeTraits<clang::QualType> {
1147 public:
1148  static inline void *getAsVoidPointer(clang::QualType P) {
1149  return P.getAsOpaquePtr();
1150  }
1151  static inline clang::QualType getFromVoidPointer(void *P) {
1153  }
1154  // Various qualifiers go in low bits.
1155  enum { NumLowBitsAvailable = 0 };
1156 };
1157 
1158 } // end namespace llvm
1159 
1160 namespace clang {
1161 
1162 /// \brief Base class that is common to both the \c ExtQuals and \c Type
1163 /// classes, which allows \c QualType to access the common fields between the
1164 /// two.
1165 ///
1167  ExtQualsTypeCommonBase(const Type *baseType, QualType canon)
1168  : BaseType(baseType), CanonicalType(canon) {}
1169 
1170  /// \brief The "base" type of an extended qualifiers type (\c ExtQuals) or
1171  /// a self-referential pointer (for \c Type).
1172  ///
1173  /// This pointer allows an efficient mapping from a QualType to its
1174  /// underlying type pointer.
1175  const Type *const BaseType;
1176 
1177  /// \brief The canonical type of this type. A QualType.
1178  QualType CanonicalType;
1179 
1180  friend class QualType;
1181  friend class Type;
1182  friend class ExtQuals;
1183 };
1184 
1185 /// We can encode up to four bits in the low bits of a
1186 /// type pointer, but there are many more type qualifiers that we want
1187 /// to be able to apply to an arbitrary type. Therefore we have this
1188 /// struct, intended to be heap-allocated and used by QualType to
1189 /// store qualifiers.
1190 ///
1191 /// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
1192 /// in three low bits on the QualType pointer; a fourth bit records whether
1193 /// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
1194 /// Objective-C GC attributes) are much more rare.
1195 class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode {
1196  // NOTE: changing the fast qualifiers should be straightforward as
1197  // long as you don't make 'const' non-fast.
1198  // 1. Qualifiers:
1199  // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
1200  // Fast qualifiers must occupy the low-order bits.
1201  // b) Update Qualifiers::FastWidth and FastMask.
1202  // 2. QualType:
1203  // a) Update is{Volatile,Restrict}Qualified(), defined inline.
1204  // b) Update remove{Volatile,Restrict}, defined near the end of
1205  // this header.
1206  // 3. ASTContext:
1207  // a) Update get{Volatile,Restrict}Type.
1208 
1209  /// The immutable set of qualifiers applied by this node. Always contains
1210  /// extended qualifiers.
1211  Qualifiers Quals;
1212 
1213  ExtQuals *this_() { return this; }
1214 
1215 public:
1216  ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
1217  : ExtQualsTypeCommonBase(baseType,
1218  canon.isNull() ? QualType(this_(), 0) : canon),
1219  Quals(quals)
1220  {
1221  assert(Quals.hasNonFastQualifiers()
1222  && "ExtQuals created with no fast qualifiers");
1223  assert(!Quals.hasFastQualifiers()
1224  && "ExtQuals created with fast qualifiers");
1225  }
1226 
1227  Qualifiers getQualifiers() const { return Quals; }
1228 
1229  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
1230  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
1231 
1232  bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); }
1234  return Quals.getObjCLifetime();
1235  }
1236 
1237  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
1238  unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
1239 
1240  const Type *getBaseType() const { return BaseType; }
1241 
1242 public:
1243  void Profile(llvm::FoldingSetNodeID &ID) const {
1244  Profile(ID, getBaseType(), Quals);
1245  }
1246  static void Profile(llvm::FoldingSetNodeID &ID,
1247  const Type *BaseType,
1248  Qualifiers Quals) {
1249  assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
1250  ID.AddPointer(BaseType);
1251  Quals.Profile(ID);
1252  }
1253 };
1254 
1255 /// The kind of C++11 ref-qualifier associated with a function type.
1256 /// This determines whether a member function's "this" object can be an
1257 /// lvalue, rvalue, or neither.
1259  /// \brief No ref-qualifier was provided.
1260  RQ_None = 0,
1261  /// \brief An lvalue ref-qualifier was provided (\c &).
1263  /// \brief An rvalue ref-qualifier was provided (\c &&).
1265 };
1266 
1267 /// Which keyword(s) were used to create an AutoType.
1268 enum class AutoTypeKeyword {
1269  /// \brief auto
1270  Auto,
1271  /// \brief decltype(auto)
1272  DecltypeAuto,
1273  /// \brief __auto_type (GNU extension)
1274  GNUAutoType
1275 };
1276 
1277 /// The base class of the type hierarchy.
1278 ///
1279 /// A central concept with types is that each type always has a canonical
1280 /// type. A canonical type is the type with any typedef names stripped out
1281 /// of it or the types it references. For example, consider:
1282 ///
1283 /// typedef int foo;
1284 /// typedef foo* bar;
1285 /// 'int *' 'foo *' 'bar'
1286 ///
1287 /// There will be a Type object created for 'int'. Since int is canonical, its
1288 /// CanonicalType pointer points to itself. There is also a Type for 'foo' (a
1289 /// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next
1290 /// there is a PointerType that represents 'int*', which, like 'int', is
1291 /// canonical. Finally, there is a PointerType type for 'foo*' whose canonical
1292 /// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
1293 /// is also 'int*'.
1294 ///
1295 /// Non-canonical types are useful for emitting diagnostics, without losing
1296 /// information about typedefs being used. Canonical types are useful for type
1297 /// comparisons (they allow by-pointer equality tests) and useful for reasoning
1298 /// about whether something has a particular form (e.g. is a function type),
1299 /// because they implicitly, recursively, strip all typedefs out of a type.
1300 ///
1301 /// Types, once created, are immutable.
1302 ///
1304 public:
1305  enum TypeClass {
1306 #define TYPE(Class, Base) Class,
1307 #define LAST_TYPE(Class) TypeLast = Class,
1308 #define ABSTRACT_TYPE(Class, Base)
1309 #include "clang/AST/TypeNodes.def"
1310  TagFirst = Record, TagLast = Enum
1311  };
1312 
1313 private:
1314  Type(const Type &) = delete;
1315  void operator=(const Type &) = delete;
1316 
1317  /// Bitfields required by the Type class.
1318  class TypeBitfields {
1319  friend class Type;
1320  template <class T> friend class TypePropertyCache;
1321 
1322  /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
1323  unsigned TC : 8;
1324 
1325  /// Whether this type is a dependent type (C++ [temp.dep.type]).
1326  unsigned Dependent : 1;
1327 
1328  /// Whether this type somehow involves a template parameter, even
1329  /// if the resolution of the type does not depend on a template parameter.
1330  unsigned InstantiationDependent : 1;
1331 
1332  /// Whether this type is a variably-modified type (C99 6.7.5).
1333  unsigned VariablyModified : 1;
1334 
1335  /// \brief Whether this type contains an unexpanded parameter pack
1336  /// (for C++11 variadic templates).
1337  unsigned ContainsUnexpandedParameterPack : 1;
1338 
1339  /// \brief True if the cache (i.e. the bitfields here starting with
1340  /// 'Cache') is valid.
1341  mutable unsigned CacheValid : 1;
1342 
1343  /// \brief Linkage of this type.
1344  mutable unsigned CachedLinkage : 3;
1345 
1346  /// \brief Whether this type involves and local or unnamed types.
1347  mutable unsigned CachedLocalOrUnnamed : 1;
1348 
1349  /// \brief Whether this type comes from an AST file.
1350  mutable unsigned FromAST : 1;
1351 
1352  bool isCacheValid() const {
1353  return CacheValid;
1354  }
1355  Linkage getLinkage() const {
1356  assert(isCacheValid() && "getting linkage from invalid cache");
1357  return static_cast<Linkage>(CachedLinkage);
1358  }
1359  bool hasLocalOrUnnamedType() const {
1360  assert(isCacheValid() && "getting linkage from invalid cache");
1361  return CachedLocalOrUnnamed;
1362  }
1363  };
1364  enum { NumTypeBits = 18 };
1365 
1366 protected:
1367  // These classes allow subclasses to somewhat cleanly pack bitfields
1368  // into Type.
1369 
1371  friend class ArrayType;
1372 
1373  unsigned : NumTypeBits;
1374 
1375  /// CVR qualifiers from declarations like
1376  /// 'int X[static restrict 4]'. For function parameters only.
1377  unsigned IndexTypeQuals : 3;
1378 
1379  /// Storage class qualifiers from declarations like
1380  /// 'int X[static restrict 4]'. For function parameters only.
1381  /// Actually an ArrayType::ArraySizeModifier.
1382  unsigned SizeModifier : 3;
1383  };
1384 
1386  friend class BuiltinType;
1387 
1388  unsigned : NumTypeBits;
1389 
1390  /// The kind (BuiltinType::Kind) of builtin type this is.
1391  unsigned Kind : 8;
1392  };
1393 
1395  friend class FunctionType;
1396  friend class FunctionProtoType;
1397 
1398  unsigned : NumTypeBits;
1399 
1400  /// Extra information which affects how the function is called, like
1401  /// regparm and the calling convention.
1402  unsigned ExtInfo : 11;
1403 
1404  /// Used only by FunctionProtoType, put here to pack with the
1405  /// other bitfields.
1406  /// The qualifiers are part of FunctionProtoType because...
1407  ///
1408  /// C++ 8.3.5p4: The return type, the parameter type list and the
1409  /// cv-qualifier-seq, [...], are part of the function type.
1410  unsigned TypeQuals : 4;
1411 
1412  /// \brief The ref-qualifier associated with a \c FunctionProtoType.
1413  ///
1414  /// This is a value of type \c RefQualifierKind.
1415  unsigned RefQualifier : 2;
1416  };
1417 
1419  friend class ObjCObjectType;
1420 
1421  unsigned : NumTypeBits;
1422 
1423  /// The number of type arguments stored directly on this object type.
1424  unsigned NumTypeArgs : 7;
1425 
1426  /// The number of protocols stored directly on this object type.
1427  unsigned NumProtocols : 6;
1428 
1429  /// Whether this is a "kindof" type.
1430  unsigned IsKindOf : 1;
1431  };
1432  static_assert(NumTypeBits + 7 + 6 + 1 <= 32, "Does not fit in an unsigned");
1433 
1435  friend class ReferenceType;
1436 
1437  unsigned : NumTypeBits;
1438 
1439  /// True if the type was originally spelled with an lvalue sigil.
1440  /// This is never true of rvalue references but can also be false
1441  /// on lvalue references because of C++0x [dcl.typedef]p9,
1442  /// as follows:
1443  ///
1444  /// typedef int &ref; // lvalue, spelled lvalue
1445  /// typedef int &&rvref; // rvalue
1446  /// ref &a; // lvalue, inner ref, spelled lvalue
1447  /// ref &&a; // lvalue, inner ref
1448  /// rvref &a; // lvalue, inner ref, spelled lvalue
1449  /// rvref &&a; // rvalue, inner ref
1450  unsigned SpelledAsLValue : 1;
1451 
1452  /// True if the inner type is a reference type. This only happens
1453  /// in non-canonical forms.
1454  unsigned InnerRef : 1;
1455  };
1456 
1458  friend class TypeWithKeyword;
1459 
1460  unsigned : NumTypeBits;
1461 
1462  /// An ElaboratedTypeKeyword. 8 bits for efficient access.
1463  unsigned Keyword : 8;
1464  };
1465 
1467  friend class VectorType;
1468 
1469  unsigned : NumTypeBits;
1470 
1471  /// The kind of vector, either a generic vector type or some
1472  /// target-specific vector type such as for AltiVec or Neon.
1473  unsigned VecKind : 3;
1474 
1475  /// The number of elements in the vector.
1476  unsigned NumElements : 29 - NumTypeBits;
1477 
1478  enum { MaxNumElements = (1 << (29 - NumTypeBits)) - 1 };
1479  };
1480 
1482  friend class AttributedType;
1483 
1484  unsigned : NumTypeBits;
1485 
1486  /// An AttributedType::Kind
1487  unsigned AttrKind : 32 - NumTypeBits;
1488  };
1489 
1491  friend class AutoType;
1492 
1493  unsigned : NumTypeBits;
1494 
1495  /// Was this placeholder type spelled as 'auto', 'decltype(auto)',
1496  /// or '__auto_type'? AutoTypeKeyword value.
1497  unsigned Keyword : 2;
1498  };
1499 
1500  union {
1501  TypeBitfields TypeBits;
1511  };
1512 
1513 private:
1514  /// \brief Set whether this type comes from an AST file.
1515  void setFromAST(bool V = true) const {
1516  TypeBits.FromAST = V;
1517  }
1518 
1519  template <class T> friend class TypePropertyCache;
1520 
1521 protected:
1522  // silence VC++ warning C4355: 'this' : used in base member initializer list
1523  Type *this_() { return this; }
1524  Type(TypeClass tc, QualType canon, bool Dependent,
1525  bool InstantiationDependent, bool VariablyModified,
1526  bool ContainsUnexpandedParameterPack)
1527  : ExtQualsTypeCommonBase(this,
1528  canon.isNull() ? QualType(this_(), 0) : canon) {
1529  TypeBits.TC = tc;
1530  TypeBits.Dependent = Dependent;
1531  TypeBits.InstantiationDependent = Dependent || InstantiationDependent;
1532  TypeBits.VariablyModified = VariablyModified;
1533  TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
1534  TypeBits.CacheValid = false;
1535  TypeBits.CachedLocalOrUnnamed = false;
1536  TypeBits.CachedLinkage = NoLinkage;
1537  TypeBits.FromAST = false;
1538  }
1539  friend class ASTContext;
1540 
1541  void setDependent(bool D = true) {
1542  TypeBits.Dependent = D;
1543  if (D)
1544  TypeBits.InstantiationDependent = true;
1545  }
1546  void setInstantiationDependent(bool D = true) {
1547  TypeBits.InstantiationDependent = D; }
1548  void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM;
1549  }
1550  void setContainsUnexpandedParameterPack(bool PP = true) {
1551  TypeBits.ContainsUnexpandedParameterPack = PP;
1552  }
1553 
1554 public:
1555  TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
1556 
1557  /// \brief Whether this type comes from an AST file.
1558  bool isFromAST() const { return TypeBits.FromAST; }
1559 
1560  /// \brief Whether this type is or contains an unexpanded parameter
1561  /// pack, used to support C++0x variadic templates.
1562  ///
1563  /// A type that contains a parameter pack shall be expanded by the
1564  /// ellipsis operator at some point. For example, the typedef in the
1565  /// following example contains an unexpanded parameter pack 'T':
1566  ///
1567  /// \code
1568  /// template<typename ...T>
1569  /// struct X {
1570  /// typedef T* pointer_types; // ill-formed; T is a parameter pack.
1571  /// };
1572  /// \endcode
1573  ///
1574  /// Note that this routine does not specify which
1576  return TypeBits.ContainsUnexpandedParameterPack;
1577  }
1578 
1579  /// Determines if this type would be canonical if it had no further
1580  /// qualification.
1581  bool isCanonicalUnqualified() const {
1582  return CanonicalType == QualType(this, 0);
1583  }
1584 
1585  /// Pull a single level of sugar off of this locally-unqualified type.
1586  /// Users should generally prefer SplitQualType::getSingleStepDesugaredType()
1587  /// or QualType::getSingleStepDesugaredType(const ASTContext&).
1589 
1590  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
1591  /// object types, function types, and incomplete types.
1592 
1593  /// Return true if this is an incomplete type.
1594  /// A type that can describe objects, but which lacks information needed to
1595  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
1596  /// routine will need to determine if the size is actually required.
1597  ///
1598  /// \brief Def If non-null, and the type refers to some kind of declaration
1599  /// that can be completed (such as a C struct, C++ class, or Objective-C
1600  /// class), will be set to the declaration.
1601  bool isIncompleteType(NamedDecl **Def = nullptr) const;
1602 
1603  /// Return true if this is an incomplete or object
1604  /// type, in other words, not a function type.
1606  return !isFunctionType();
1607  }
1608 
1609  /// \brief Determine whether this type is an object type.
1610  bool isObjectType() const {
1611  // C++ [basic.types]p8:
1612  // An object type is a (possibly cv-qualified) type that is not a
1613  // function type, not a reference type, and not a void type.
1614  return !isReferenceType() && !isFunctionType() && !isVoidType();
1615  }
1616 
1617  /// Return true if this is a literal type
1618  /// (C++11 [basic.types]p10)
1619  bool isLiteralType(const ASTContext &Ctx) const;
1620 
1621  /// Test if this type is a standard-layout type.
1622  /// (C++0x [basic.type]p9)
1623  bool isStandardLayoutType() const;
1624 
1625  /// Helper methods to distinguish type categories. All type predicates
1626  /// operate on the canonical type, ignoring typedefs and qualifiers.
1627 
1628  /// Returns true if the type is a builtin type.
1629  bool isBuiltinType() const;
1630 
1631  /// Test for a particular builtin type.
1632  bool isSpecificBuiltinType(unsigned K) const;
1633 
1634  /// Test for a type which does not represent an actual type-system type but
1635  /// is instead used as a placeholder for various convenient purposes within
1636  /// Clang. All such types are BuiltinTypes.
1637  bool isPlaceholderType() const;
1638  const BuiltinType *getAsPlaceholderType() const;
1639 
1640  /// Test for a specific placeholder type.
1641  bool isSpecificPlaceholderType(unsigned K) const;
1642 
1643  /// Test for a placeholder type other than Overload; see
1644  /// BuiltinType::isNonOverloadPlaceholderType.
1645  bool isNonOverloadPlaceholderType() const;
1646 
1647  /// isIntegerType() does *not* include complex integers (a GCC extension).
1648  /// isComplexIntegerType() can be used to test for complex integers.
1649  bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum)
1650  bool isEnumeralType() const;
1651  bool isBooleanType() const;
1652  bool isCharType() const;
1653  bool isWideCharType() const;
1654  bool isChar16Type() const;
1655  bool isChar32Type() const;
1656  bool isAnyCharacterType() const;
1657  bool isIntegralType(const ASTContext &Ctx) const;
1658 
1659  /// Determine whether this type is an integral or enumeration type.
1660  bool isIntegralOrEnumerationType() const;
1661  /// Determine whether this type is an integral or unscoped enumeration type.
1663 
1664  /// Floating point categories.
1665  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
1666  /// isComplexType() does *not* include complex integers (a GCC extension).
1667  /// isComplexIntegerType() can be used to test for complex integers.
1668  bool isComplexType() const; // C99 6.2.5p11 (complex)
1669  bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int.
1670  bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex)
1671  bool isHalfType() const; // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half)
1672  bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
1673  bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating)
1674  bool isVoidType() const; // C99 6.2.5p19
1675  bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers)
1676  bool isAggregateType() const;
1677  bool isFundamentalType() const;
1678  bool isCompoundType() const;
1679 
1680  // Type Predicates: Check to see if this type is structurally the specified
1681  // type, ignoring typedefs and qualifiers.
1682  bool isFunctionType() const;
1683  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
1684  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
1685  bool isPointerType() const;
1686  bool isAnyPointerType() const; // Any C pointer or ObjC object pointer
1687  bool isBlockPointerType() const;
1688  bool isVoidPointerType() const;
1689  bool isReferenceType() const;
1690  bool isLValueReferenceType() const;
1691  bool isRValueReferenceType() const;
1692  bool isFunctionPointerType() const;
1693  bool isMemberPointerType() const;
1694  bool isMemberFunctionPointerType() const;
1695  bool isMemberDataPointerType() const;
1696  bool isArrayType() const;
1697  bool isConstantArrayType() const;
1698  bool isIncompleteArrayType() const;
1699  bool isVariableArrayType() const;
1700  bool isDependentSizedArrayType() const;
1701  bool isRecordType() const;
1702  bool isClassType() const;
1703  bool isStructureType() const;
1704  bool isObjCBoxableRecordType() const;
1705  bool isInterfaceType() const;
1706  bool isStructureOrClassType() const;
1707  bool isUnionType() const;
1708  bool isComplexIntegerType() const; // GCC _Complex integer type.
1709  bool isVectorType() const; // GCC vector type.
1710  bool isExtVectorType() const; // Extended vector type.
1711  bool isObjCObjectPointerType() const; // pointer to ObjC object
1712  bool isObjCRetainableType() const; // ObjC object or block pointer
1713  bool isObjCLifetimeType() const; // (array of)* retainable type
1714  bool isObjCIndirectLifetimeType() const; // (pointer to)* lifetime type
1715  bool isObjCNSObjectType() const; // __attribute__((NSObject))
1716  bool isObjCIndependentClassType() const; // __attribute__((objc_independent_class))
1717  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
1718  // for the common case.
1719  bool isObjCObjectType() const; // NSString or typeof(*(id)0)
1720  bool isObjCQualifiedInterfaceType() const; // NSString<foo>
1721  bool isObjCQualifiedIdType() const; // id<foo>
1722  bool isObjCQualifiedClassType() const; // Class<foo>
1723  bool isObjCObjectOrInterfaceType() const;
1724  bool isObjCIdType() const; // id
1725  bool isObjCInertUnsafeUnretainedType() const;
1726 
1727  /// Whether the type is Objective-C 'id' or a __kindof type of an
1728  /// object type, e.g., __kindof NSView * or __kindof id
1729  /// <NSCopying>.
1730  ///
1731  /// \param bound Will be set to the bound on non-id subtype types,
1732  /// which will be (possibly specialized) Objective-C class type, or
1733  /// null for 'id.
1734  bool isObjCIdOrObjectKindOfType(const ASTContext &ctx,
1735  const ObjCObjectType *&bound) const;
1736 
1737  bool isObjCClassType() const; // Class
1738 
1739  /// Whether the type is Objective-C 'Class' or a __kindof type of an
1740  /// Class type, e.g., __kindof Class <NSCopying>.
1741  ///
1742  /// Unlike \c isObjCIdOrObjectKindOfType, there is no relevant bound
1743  /// here because Objective-C's type system cannot express "a class
1744  /// object for a subclass of NSFoo".
1745  bool isObjCClassOrClassKindOfType() const;
1746 
1748  bool isObjCSelType() const; // Class
1749  bool isObjCBuiltinType() const; // 'id' or 'Class'
1750  bool isObjCARCBridgableType() const;
1751  bool isCARCBridgableType() const;
1752  bool isTemplateTypeParmType() const; // C++ template type parameter
1753  bool isNullPtrType() const; // C++11 std::nullptr_t
1754  bool isAlignValT() const; // C++17 std::align_val_t
1755  bool isStdByteType() const; // C++17 std::byte
1756  bool isAtomicType() const; // C11 _Atomic()
1757 
1758 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1759  bool is##Id##Type() const;
1760 #include "clang/Basic/OpenCLImageTypes.def"
1761 
1762  bool isImageType() const; // Any OpenCL image type
1763 
1764  bool isSamplerT() const; // OpenCL sampler_t
1765  bool isEventT() const; // OpenCL event_t
1766  bool isClkEventT() const; // OpenCL clk_event_t
1767  bool isQueueT() const; // OpenCL queue_t
1768  bool isReserveIDT() const; // OpenCL reserve_id_t
1769 
1770  bool isPipeType() const; // OpenCL pipe type
1771  bool isOpenCLSpecificType() const; // Any OpenCL specific type
1772 
1773  /// Determines if this type, which must satisfy
1774  /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
1775  /// than implicitly __strong.
1776  bool isObjCARCImplicitlyUnretainedType() const;
1777 
1778  /// Return the implicit lifetime for this type, which must not be dependent.
1780 
1791  };
1792  /// Given that this is a scalar type, classify it.
1794 
1795  /// Whether this type is a dependent type, meaning that its definition
1796  /// somehow depends on a template parameter (C++ [temp.dep.type]).
1797  bool isDependentType() const { return TypeBits.Dependent; }
1798 
1799  /// \brief Determine whether this type is an instantiation-dependent type,
1800  /// meaning that the type involves a template parameter (even if the
1801  /// definition does not actually depend on the type substituted for that
1802  /// template parameter).
1804  return TypeBits.InstantiationDependent;
1805  }
1806 
1807  /// \brief Determine whether this type is an undeduced type, meaning that
1808  /// it somehow involves a C++11 'auto' type or similar which has not yet been
1809  /// deduced.
1810  bool isUndeducedType() const;
1811 
1812  /// \brief Whether this type is a variably-modified type (C99 6.7.5).
1813  bool isVariablyModifiedType() const { return TypeBits.VariablyModified; }
1814 
1815  /// \brief Whether this type involves a variable-length array type
1816  /// with a definite size.
1817  bool hasSizedVLAType() const;
1818 
1819  /// \brief Whether this type is or contains a local or unnamed type.
1820  bool hasUnnamedOrLocalType() const;
1821 
1822  bool isOverloadableType() const;
1823 
1824  /// \brief Determine wither this type is a C++ elaborated-type-specifier.
1825  bool isElaboratedTypeSpecifier() const;
1826 
1827  bool canDecayToPointerType() const;
1828 
1829  /// Whether this type is represented natively as a pointer. This includes
1830  /// pointers, references, block pointers, and Objective-C interface,
1831  /// qualified id, and qualified interface types, as well as nullptr_t.
1832  bool hasPointerRepresentation() const;
1833 
1834  /// Whether this type can represent an objective pointer type for the
1835  /// purpose of GC'ability
1836  bool hasObjCPointerRepresentation() const;
1837 
1838  /// \brief Determine whether this type has an integer representation
1839  /// of some sort, e.g., it is an integer type or a vector.
1840  bool hasIntegerRepresentation() const;
1841 
1842  /// \brief Determine whether this type has an signed integer representation
1843  /// of some sort, e.g., it is an signed integer type or a vector.
1844  bool hasSignedIntegerRepresentation() const;
1845 
1846  /// \brief Determine whether this type has an unsigned integer representation
1847  /// of some sort, e.g., it is an unsigned integer type or a vector.
1848  bool hasUnsignedIntegerRepresentation() const;
1849 
1850  /// \brief Determine whether this type has a floating-point representation
1851  /// of some sort, e.g., it is a floating-point type or a vector thereof.
1852  bool hasFloatingRepresentation() const;
1853 
1854  // Type Checking Functions: Check to see if this type is structurally the
1855  // specified type, ignoring typedefs and qualifiers, and return a pointer to
1856  // the best type we can.
1857  const RecordType *getAsStructureType() const;
1858  /// NOTE: getAs*ArrayType are methods on ASTContext.
1859  const RecordType *getAsUnionType() const;
1860  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
1861  const ObjCObjectType *getAsObjCInterfaceType() const;
1862  // The following is a convenience method that returns an ObjCObjectPointerType
1863  // for object declared using an interface.
1868 
1869  /// \brief Retrieves the CXXRecordDecl that this type refers to, either
1870  /// because the type is a RecordType or because it is the injected-class-name
1871  /// type of a class template or class template partial specialization.
1873 
1874  /// \brief Retrieves the TagDecl that this type refers to, either
1875  /// because the type is a TagType or because it is the injected-class-name
1876  /// type of a class template or class template partial specialization.
1877  TagDecl *getAsTagDecl() const;
1878 
1879  /// If this is a pointer or reference to a RecordType, return the
1880  /// CXXRecordDecl that that type refers to.
1881  ///
1882  /// If this is not a pointer or reference, or the type being pointed to does
1883  /// not refer to a CXXRecordDecl, returns NULL.
1884  const CXXRecordDecl *getPointeeCXXRecordDecl() const;
1885 
1886  /// Get the DeducedType whose type will be deduced for a variable with
1887  /// an initializer of this type. This looks through declarators like pointer
1888  /// types, but not through decltype or typedefs.
1890 
1891  /// Get the AutoType whose type will be deduced for a variable with
1892  /// an initializer of this type. This looks through declarators like pointer
1893  /// types, but not through decltype or typedefs.
1895  return dyn_cast_or_null<AutoType>(getContainedDeducedType());
1896  }
1897 
1898  /// Determine whether this type was written with a leading 'auto'
1899  /// corresponding to a trailing return type (possibly for a nested
1900  /// function type within a pointer to function type or similar).
1901  bool hasAutoForTrailingReturnType() const;
1902 
1903  /// Member-template getAs<specific type>'. Look through sugar for
1904  /// an instance of <specific type>. This scheme will eventually
1905  /// replace the specific getAsXXXX methods above.
1906  ///
1907  /// There are some specializations of this member template listed
1908  /// immediately following this class.
1909  template <typename T> const T *getAs() const;
1910 
1911  /// Member-template getAsAdjusted<specific type>. Look through specific kinds
1912  /// of sugar (parens, attributes, etc) for an instance of <specific type>.
1913  /// This is used when you need to walk over sugar nodes that represent some
1914  /// kind of type adjustment from a type that was written as a <specific type>
1915  /// to another type that is still canonically a <specific type>.
1916  template <typename T> const T *getAsAdjusted() const;
1917 
1918  /// A variant of getAs<> for array types which silently discards
1919  /// qualifiers from the outermost type.
1920  const ArrayType *getAsArrayTypeUnsafe() const;
1921 
1922  /// Member-template castAs<specific type>. Look through sugar for
1923  /// the underlying instance of <specific type>.
1924  ///
1925  /// This method has the same relationship to getAs<T> as cast<T> has
1926  /// to dyn_cast<T>; which is to say, the underlying type *must*
1927  /// have the intended type, and this method will never return null.
1928  template <typename T> const T *castAs() const;
1929 
1930  /// A variant of castAs<> for array type which silently discards
1931  /// qualifiers from the outermost type.
1932  const ArrayType *castAsArrayTypeUnsafe() const;
1933 
1934  /// Get the base element type of this type, potentially discarding type
1935  /// qualifiers. This should never be used when type qualifiers
1936  /// are meaningful.
1937  const Type *getBaseElementTypeUnsafe() const;
1938 
1939  /// If this is an array type, return the element type of the array,
1940  /// potentially with type qualifiers missing.
1941  /// This should never be used when type qualifiers are meaningful.
1942  const Type *getArrayElementTypeNoTypeQual() const;
1943 
1944  /// If this is a pointer type, return the pointee type.
1945  /// If this is an array type, return the array element type.
1946  /// This should never be used when type qualifiers are meaningful.
1947  const Type *getPointeeOrArrayElementType() const;
1948 
1949  /// If this is a pointer, ObjC object pointer, or block
1950  /// pointer, this returns the respective pointee.
1951  QualType getPointeeType() const;
1952 
1953  /// Return the specified type with any "sugar" removed from the type,
1954  /// removing any typedefs, typeofs, etc., as well as any qualifiers.
1955  const Type *getUnqualifiedDesugaredType() const;
1956 
1957  /// More type predicates useful for type checking/promotion
1958  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
1959 
1960  /// Return true if this is an integer type that is
1961  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
1962  /// or an enum decl which has a signed representation.
1963  bool isSignedIntegerType() const;
1964 
1965  /// Return true if this is an integer type that is
1966  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool],
1967  /// or an enum decl which has an unsigned representation.
1968  bool isUnsignedIntegerType() const;
1969 
1970  /// Determines whether this is an integer type that is signed or an
1971  /// enumeration types whose underlying type is a signed integer type.
1972  bool isSignedIntegerOrEnumerationType() const;
1973 
1974  /// Determines whether this is an integer type that is unsigned or an
1975  /// enumeration types whose underlying type is a unsigned integer type.
1977 
1978  /// Return true if this is not a variable sized type,
1979  /// according to the rules of C99 6.7.5p3. It is not legal to call this on
1980  /// incomplete types.
1981  bool isConstantSizeType() const;
1982 
1983  /// Returns true if this type can be represented by some
1984  /// set of type specifiers.
1985  bool isSpecifierType() const;
1986 
1987  /// Determine the linkage of this type.
1988  Linkage getLinkage() const;
1989 
1990  /// Determine the visibility of this type.
1993  }
1994 
1995  /// Return true if the visibility was explicitly set is the code.
1996  bool isVisibilityExplicit() const {
1998  }
1999 
2000  /// Determine the linkage and visibility of this type.
2002 
2003  /// True if the computed linkage is valid. Used for consistency
2004  /// checking. Should always return true.
2005  bool isLinkageValid() const;
2006 
2007  /// Determine the nullability of the given type.
2008  ///
2009  /// Note that nullability is only captured as sugar within the type
2010  /// system, not as part of the canonical type, so nullability will
2011  /// be lost by canonicalization and desugaring.
2012  Optional<NullabilityKind> getNullability(const ASTContext &context) const;
2013 
2014  /// Determine whether the given type can have a nullability
2015  /// specifier applied to it, i.e., if it is any kind of pointer type.
2016  ///
2017  /// \param ResultIfUnknown The value to return if we don't yet know whether
2018  /// this type can have nullability because it is dependent.
2019  bool canHaveNullability(bool ResultIfUnknown = true) const;
2020 
2021  /// Retrieve the set of substitutions required when accessing a member
2022  /// of the Objective-C receiver type that is declared in the given context.
2023  ///
2024  /// \c *this is the type of the object we're operating on, e.g., the
2025  /// receiver for a message send or the base of a property access, and is
2026  /// expected to be of some object or object pointer type.
2027  ///
2028  /// \param dc The declaration context for which we are building up a
2029  /// substitution mapping, which should be an Objective-C class, extension,
2030  /// category, or method within.
2031  ///
2032  /// \returns an array of type arguments that can be substituted for
2033  /// the type parameters of the given declaration context in any type described
2034  /// within that context, or an empty optional to indicate that no
2035  /// substitution is required.
2037  getObjCSubstitutions(const DeclContext *dc) const;
2038 
2039  /// Determines if this is an ObjC interface type that may accept type
2040  /// parameters.
2041  bool acceptsObjCTypeParams() const;
2042 
2043  const char *getTypeClassName() const;
2044 
2046  return CanonicalType;
2047  }
2048  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
2049  void dump() const;
2050  void dump(llvm::raw_ostream &OS) const;
2051 
2052  friend class ASTReader;
2053  friend class ASTWriter;
2054 };
2055 
2056 /// \brief This will check for a TypedefType by removing any existing sugar
2057 /// until it reaches a TypedefType or a non-sugared type.
2058 template <> const TypedefType *Type::getAs() const;
2059 
2060 /// \brief This will check for a TemplateSpecializationType by removing any
2061 /// existing sugar until it reaches a TemplateSpecializationType or a
2062 /// non-sugared type.
2063 template <> const TemplateSpecializationType *Type::getAs() const;
2064 
2065 /// \brief This will check for an AttributedType by removing any existing sugar
2066 /// until it reaches an AttributedType or a non-sugared type.
2067 template <> const AttributedType *Type::getAs() const;
2068 
2069 // We can do canonical leaf types faster, because we don't have to
2070 // worry about preserving child type decoration.
2071 #define TYPE(Class, Base)
2072 #define LEAF_TYPE(Class) \
2073 template <> inline const Class##Type *Type::getAs() const { \
2074  return dyn_cast<Class##Type>(CanonicalType); \
2075 } \
2076 template <> inline const Class##Type *Type::castAs() const { \
2077  return cast<Class##Type>(CanonicalType); \
2078 }
2079 #include "clang/AST/TypeNodes.def"
2080 
2081 
2082 /// This class is used for builtin types like 'int'. Builtin
2083 /// types are always canonical and have a literal name field.
2084 class BuiltinType : public Type {
2085 public:
2086  enum Kind {
2087 // OpenCL image types
2088 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id,
2089 #include "clang/Basic/OpenCLImageTypes.def"
2090 // All other builtin types
2091 #define BUILTIN_TYPE(Id, SingletonId) Id,
2092 #define LAST_BUILTIN_TYPE(Id) LastKind = Id
2093 #include "clang/AST/BuiltinTypes.def"
2094  };
2095 
2096 public:
2098  : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent),
2099  /*InstantiationDependent=*/(K == Dependent),
2100  /*VariablyModified=*/false,
2101  /*Unexpanded parameter pack=*/false) {
2102  BuiltinTypeBits.Kind = K;
2103  }
2104 
2105  Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
2106  StringRef getName(const PrintingPolicy &Policy) const;
2107  const char *getNameAsCString(const PrintingPolicy &Policy) const {
2108  // The StringRef is null-terminated.
2109  StringRef str = getName(Policy);
2110  assert(!str.empty() && str.data()[str.size()] == '\0');
2111  return str.data();
2112  }
2113 
2114  bool isSugared() const { return false; }
2115  QualType desugar() const { return QualType(this, 0); }
2116 
2117  bool isInteger() const {
2118  return getKind() >= Bool && getKind() <= Int128;
2119  }
2120 
2121  bool isSignedInteger() const {
2122  return getKind() >= Char_S && getKind() <= Int128;
2123  }
2124 
2125  bool isUnsignedInteger() const {
2126  return getKind() >= Bool && getKind() <= UInt128;
2127  }
2128 
2129  bool isFloatingPoint() const {
2130  return getKind() >= Half && getKind() <= Float128;
2131  }
2132 
2133  /// Determines whether the given kind corresponds to a placeholder type.
2134  static bool isPlaceholderTypeKind(Kind K) {
2135  return K >= Overload;
2136  }
2137 
2138  /// Determines whether this type is a placeholder type, i.e. a type
2139  /// which cannot appear in arbitrary positions in a fully-formed
2140  /// expression.
2141  bool isPlaceholderType() const {
2142  return isPlaceholderTypeKind(getKind());
2143  }
2144 
2145  /// Determines whether this type is a placeholder type other than
2146  /// Overload. Most placeholder types require only syntactic
2147  /// information about their context in order to be resolved (e.g.
2148  /// whether it is a call expression), which means they can (and
2149  /// should) be resolved in an earlier "phase" of analysis.
2150  /// Overload expressions sometimes pick up further information
2151  /// from their context, like whether the context expects a
2152  /// specific function-pointer type, and so frequently need
2153  /// special treatment.
2155  return getKind() > Overload;
2156  }
2157 
2158  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
2159 };
2160 
2161 /// Complex values, per C99 6.2.5p11. This supports the C99 complex
2162 /// types (_Complex float etc) as well as the GCC integer complex extensions.
2163 ///
2164 class ComplexType : public Type, public llvm::FoldingSetNode {
2165  QualType ElementType;
2166  ComplexType(QualType Element, QualType CanonicalPtr) :
2167  Type(Complex, CanonicalPtr, Element->isDependentType(),
2168  Element->isInstantiationDependentType(),
2169  Element->isVariablyModifiedType(),
2170  Element->containsUnexpandedParameterPack()),
2171  ElementType(Element) {
2172  }
2173  friend class ASTContext; // ASTContext creates these.
2174 
2175 public:
2176  QualType getElementType() const { return ElementType; }
2177 
2178  bool isSugared() const { return false; }
2179  QualType desugar() const { return QualType(this, 0); }
2180 
2181  void Profile(llvm::FoldingSetNodeID &ID) {
2182  Profile(ID, getElementType());
2183  }
2184  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
2185  ID.AddPointer(Element.getAsOpaquePtr());
2186  }
2187 
2188  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
2189 };
2190 
2191 /// Sugar for parentheses used when specifying types.
2192 ///
2193 class ParenType : public Type, public llvm::FoldingSetNode {
2194  QualType Inner;
2195 
2196  ParenType(QualType InnerType, QualType CanonType) :
2197  Type(Paren, CanonType, InnerType->isDependentType(),
2198  InnerType->isInstantiationDependentType(),
2199  InnerType->isVariablyModifiedType(),
2200  InnerType->containsUnexpandedParameterPack()),
2201  Inner(InnerType) {
2202  }
2203  friend class ASTContext; // ASTContext creates these.
2204 
2205 public:
2206 
2207  QualType getInnerType() const { return Inner; }
2208 
2209  bool isSugared() const { return true; }
2210  QualType desugar() const { return getInnerType(); }
2211 
2212  void Profile(llvm::FoldingSetNodeID &ID) {
2213  Profile(ID, getInnerType());
2214  }
2215  static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
2216  Inner.Profile(ID);
2217  }
2218 
2219  static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
2220 };
2221 
2222 /// PointerType - C99 6.7.5.1 - Pointer Declarators.
2223 ///
2224 class PointerType : public Type, public llvm::FoldingSetNode {
2225  QualType PointeeType;
2226 
2227  PointerType(QualType Pointee, QualType CanonicalPtr) :
2228  Type(Pointer, CanonicalPtr, Pointee->isDependentType(),
2229  Pointee->isInstantiationDependentType(),
2230  Pointee->isVariablyModifiedType(),
2231  Pointee->containsUnexpandedParameterPack()),
2232  PointeeType(Pointee) {
2233  }
2234  friend class ASTContext; // ASTContext creates these.
2235 
2236 public:
2237 
2238  QualType getPointeeType() const { return PointeeType; }
2239 
2240  /// Returns true if address spaces of pointers overlap.
2241  /// OpenCL v2.0 defines conversion rules for pointers to different
2242  /// address spaces (OpenCLC v2.0 s6.5.5) and notion of overlapping
2243  /// address spaces.
2244  /// CL1.1 or CL1.2:
2245  /// address spaces overlap iff they are they same.
2246  /// CL2.0 adds:
2247  /// __generic overlaps with any address space except for __constant.
2248  bool isAddressSpaceOverlapping(const PointerType &other) const {
2249  Qualifiers thisQuals = PointeeType.getQualifiers();
2250  Qualifiers otherQuals = other.getPointeeType().getQualifiers();
2251  // Address spaces overlap if at least one of them is a superset of another
2252  return thisQuals.isAddressSpaceSupersetOf(otherQuals) ||
2253  otherQuals.isAddressSpaceSupersetOf(thisQuals);
2254  }
2255 
2256  bool isSugared() const { return false; }
2257  QualType desugar() const { return QualType(this, 0); }
2258 
2259  void Profile(llvm::FoldingSetNodeID &ID) {
2260  Profile(ID, getPointeeType());
2261  }
2262  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
2263  ID.AddPointer(Pointee.getAsOpaquePtr());
2264  }
2265 
2266  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
2267 };
2268 
2269 /// Represents a type which was implicitly adjusted by the semantic
2270 /// engine for arbitrary reasons. For example, array and function types can
2271 /// decay, and function types can have their calling conventions adjusted.
2272 class AdjustedType : public Type, public llvm::FoldingSetNode {
2273  QualType OriginalTy;
2274  QualType AdjustedTy;
2275 
2276 protected:
2277  AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy,
2278  QualType CanonicalPtr)
2279  : Type(TC, CanonicalPtr, OriginalTy->isDependentType(),
2280  OriginalTy->isInstantiationDependentType(),
2281  OriginalTy->isVariablyModifiedType(),
2282  OriginalTy->containsUnexpandedParameterPack()),
2283  OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}
2284 
2285  friend class ASTContext; // ASTContext creates these.
2286 
2287 public:
2288  QualType getOriginalType() const { return OriginalTy; }
2289  QualType getAdjustedType() const { return AdjustedTy; }
2290 
2291  bool isSugared() const { return true; }
2292  QualType desugar() const { return AdjustedTy; }
2293 
2294  void Profile(llvm::FoldingSetNodeID &ID) {
2295  Profile(ID, OriginalTy, AdjustedTy);
2296  }
2297  static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New) {
2298  ID.AddPointer(Orig.getAsOpaquePtr());
2299  ID.AddPointer(New.getAsOpaquePtr());
2300  }
2301 
2302  static bool classof(const Type *T) {
2303  return T->getTypeClass() == Adjusted || T->getTypeClass() == Decayed;
2304  }
2305 };
2306 
2307 /// Represents a pointer type decayed from an array or function type.
2308 class DecayedType : public AdjustedType {
2309 
2310  inline
2311  DecayedType(QualType OriginalType, QualType Decayed, QualType Canonical);
2312 
2313  friend class ASTContext; // ASTContext creates these.
2314 
2315 public:
2317 
2318  inline QualType getPointeeType() const;
2319 
2320  static bool classof(const Type *T) { return T->getTypeClass() == Decayed; }
2321 };
2322 
2323 /// Pointer to a block type.
2324 /// This type is to represent types syntactically represented as
2325 /// "void (^)(int)", etc. Pointee is required to always be a function type.
2326 ///
2327 class BlockPointerType : public Type, public llvm::FoldingSetNode {
2328  QualType PointeeType; // Block is some kind of pointer type
2329  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
2330  Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
2331  Pointee->isInstantiationDependentType(),
2332  Pointee->isVariablyModifiedType(),
2333  Pointee->containsUnexpandedParameterPack()),
2334  PointeeType(Pointee) {
2335  }
2336  friend class ASTContext; // ASTContext creates these.
2337 
2338 public:
2339 
2340  // Get the pointee type. Pointee is required to always be a function type.
2341  QualType getPointeeType() const { return PointeeType; }
2342 
2343  bool isSugared() const { return false; }
2344  QualType desugar() const { return QualType(this, 0); }
2345 
2346  void Profile(llvm::FoldingSetNodeID &ID) {
2347  Profile(ID, getPointeeType());
2348  }
2349  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
2350  ID.AddPointer(Pointee.getAsOpaquePtr());
2351  }
2352 
2353  static bool classof(const Type *T) {
2354  return T->getTypeClass() == BlockPointer;
2355  }
2356 };
2357 
2358 /// Base for LValueReferenceType and RValueReferenceType
2359 ///
2360 class ReferenceType : public Type, public llvm::FoldingSetNode {
2361  QualType PointeeType;
2362 
2363 protected:
2364  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
2365  bool SpelledAsLValue) :
2366  Type(tc, CanonicalRef, Referencee->isDependentType(),
2367  Referencee->isInstantiationDependentType(),
2368  Referencee->isVariablyModifiedType(),
2369  Referencee->containsUnexpandedParameterPack()),
2370  PointeeType(Referencee)
2371  {
2372  ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
2373  ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
2374  }
2375 
2376 public:
2377  bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
2378  bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
2379 
2380  QualType getPointeeTypeAsWritten() const { return PointeeType; }
2382  // FIXME: this might strip inner qualifiers; okay?
2383  const ReferenceType *T = this;
2384  while (T->isInnerRef())
2385  T = T->PointeeType->castAs<ReferenceType>();
2386  return T->PointeeType;
2387  }
2388 
2389  void Profile(llvm::FoldingSetNodeID &ID) {
2390  Profile(ID, PointeeType, isSpelledAsLValue());
2391  }
2392  static void Profile(llvm::FoldingSetNodeID &ID,
2393  QualType Referencee,
2394  bool SpelledAsLValue) {
2395  ID.AddPointer(Referencee.getAsOpaquePtr());
2396  ID.AddBoolean(SpelledAsLValue);
2397  }
2398 
2399  static bool classof(const Type *T) {
2400  return T->getTypeClass() == LValueReference ||
2401  T->getTypeClass() == RValueReference;
2402  }
2403 };
2404 
2405 /// An lvalue reference type, per C++11 [dcl.ref].
2406 ///
2408  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
2409  bool SpelledAsLValue) :
2410  ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue)
2411  {}
2412  friend class ASTContext; // ASTContext creates these
2413 public:
2414  bool isSugared() const { return false; }
2415  QualType desugar() const { return QualType(this, 0); }
2416 
2417  static bool classof(const Type *T) {
2418  return T->getTypeClass() == LValueReference;
2419  }
2420 };
2421 
2422 /// An rvalue reference type, per C++11 [dcl.ref].
2423 ///
2425  RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
2426  ReferenceType(RValueReference, Referencee, CanonicalRef, false) {
2427  }
2428  friend class ASTContext; // ASTContext creates these
2429 public:
2430  bool isSugared() const { return false; }
2431  QualType desugar() const { return QualType(this, 0); }
2432 
2433  static bool classof(const Type *T) {
2434  return T->getTypeClass() == RValueReference;
2435  }
2436 };
2437 
2438 /// A pointer to member type per C++ 8.3.3 - Pointers to members.
2439 ///
2440 /// This includes both pointers to data members and pointer to member functions.
2441 ///
2442 class MemberPointerType : public Type, public llvm::FoldingSetNode {
2443  QualType PointeeType;
2444  /// The class of which the pointee is a member. Must ultimately be a
2445  /// RecordType, but could be a typedef or a template parameter too.
2446  const Type *Class;
2447 
2448  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
2449  Type(MemberPointer, CanonicalPtr,
2450  Cls->isDependentType() || Pointee->isDependentType(),
2451  (Cls->isInstantiationDependentType() ||
2452  Pointee->isInstantiationDependentType()),
2453  Pointee->isVariablyModifiedType(),
2455  Pointee->containsUnexpandedParameterPack())),
2456  PointeeType(Pointee), Class(Cls) {
2457  }
2458  friend class ASTContext; // ASTContext creates these.
2459 
2460 public:
2461  QualType getPointeeType() const { return PointeeType; }
2462 
2463  /// Returns true if the member type (i.e. the pointee type) is a
2464  /// function type rather than a data-member type.
2466  return PointeeType->isFunctionProtoType();
2467  }
2468 
2469  /// Returns true if the member type (i.e. the pointee type) is a
2470  /// data type rather than a function type.
2471  bool isMemberDataPointer() const {
2472  return !PointeeType->isFunctionProtoType();
2473  }
2474 
2475  const Type *getClass() const { return Class; }
2477 
2478  bool isSugared() const { return false; }
2479  QualType desugar() const { return QualType(this, 0); }
2480 
2481  void Profile(llvm::FoldingSetNodeID &ID) {
2482  Profile(ID, getPointeeType(), getClass());
2483  }
2484  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
2485  const Type *Class) {
2486  ID.AddPointer(Pointee.getAsOpaquePtr());
2487  ID.AddPointer(Class);
2488  }
2489 
2490  static bool classof(const Type *T) {
2491  return T->getTypeClass() == MemberPointer;
2492  }
2493 };
2494 
2495 /// Represents an array type, per C99 6.7.5.2 - Array Declarators.
2496 ///
2497 class ArrayType : public Type, public llvm::FoldingSetNode {
2498 public:
2499  /// Capture whether this is a normal array (e.g. int X[4])
2500  /// an array with a static size (e.g. int X[static 4]), or an array
2501  /// with a star size (e.g. int X[*]).
2502  /// 'static' is only allowed on function parameters.
2505  };
2506 private:
2507  /// The element type of the array.
2508  QualType ElementType;
2509 
2510 protected:
2511  // C++ [temp.dep.type]p1:
2512  // A type is dependent if it is...
2513  // - an array type constructed from any dependent type or whose
2514  // size is specified by a constant expression that is
2515  // value-dependent,
2517  ArraySizeModifier sm, unsigned tq,
2518  bool ContainsUnexpandedParameterPack)
2519  : Type(tc, can, et->isDependentType() || tc == DependentSizedArray,
2520  et->isInstantiationDependentType() || tc == DependentSizedArray,
2521  (tc == VariableArray || et->isVariablyModifiedType()),
2522  ContainsUnexpandedParameterPack),
2523  ElementType(et) {
2524  ArrayTypeBits.IndexTypeQuals = tq;
2525  ArrayTypeBits.SizeModifier = sm;
2526  }
2527 
2528  friend class ASTContext; // ASTContext creates these.
2529 
2530 public:
2531  QualType getElementType() const { return ElementType; }
2533  return ArraySizeModifier(ArrayTypeBits.SizeModifier);
2534  }
2537  }
2538  unsigned getIndexTypeCVRQualifiers() const {
2539  return ArrayTypeBits.IndexTypeQuals;
2540  }
2541 
2542  static bool classof(const Type *T) {
2543  return T->getTypeClass() == ConstantArray ||
2544  T->getTypeClass() == VariableArray ||
2545  T->getTypeClass() == IncompleteArray ||
2546  T->getTypeClass() == DependentSizedArray;
2547  }
2548 };
2549 
2550 /// Represents the canonical version of C arrays with a specified constant size.
2551 /// For example, the canonical type for 'int A[4 + 4*100]' is a
2552 /// ConstantArrayType where the element type is 'int' and the size is 404.
2554  llvm::APInt Size; // Allows us to unique the type.
2555 
2556  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
2557  ArraySizeModifier sm, unsigned tq)
2558  : ArrayType(ConstantArray, et, can, sm, tq,
2560  Size(size) {}
2561 protected:
2563  const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
2564  : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()),
2565  Size(size) {}
2566  friend class ASTContext; // ASTContext creates these.
2567 public:
2568  const llvm::APInt &getSize() const { return Size; }
2569  bool isSugared() const { return false; }
2570  QualType desugar() const { return QualType(this, 0); }
2571 
2572 
2573  /// \brief Determine the number of bits required to address a member of
2574  // an array with the given element type and number of elements.
2575  static unsigned getNumAddressingBits(const ASTContext &Context,
2576  QualType ElementType,
2577  const llvm::APInt &NumElements);
2578 
2579  /// \brief Determine the maximum number of active bits that an array's size
2580  /// can require, which limits the maximum size of the array.
2581  static unsigned getMaxSizeBits(const ASTContext &Context);
2582 
2583  void Profile(llvm::FoldingSetNodeID &ID) {
2584  Profile(ID, getElementType(), getSize(),
2586  }
2587  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
2588  const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
2589  unsigned TypeQuals) {
2590  ID.AddPointer(ET.getAsOpaquePtr());
2591  ID.AddInteger(ArraySize.getZExtValue());
2592  ID.AddInteger(SizeMod);
2593  ID.AddInteger(TypeQuals);
2594  }
2595  static bool classof(const Type *T) {
2596  return T->getTypeClass() == ConstantArray;
2597  }
2598 };
2599 
2600 /// Represents a C array with an unspecified size. For example 'int A[]' has
2601 /// an IncompleteArrayType where the element type is 'int' and the size is
2602 /// unspecified.
2604 
2606  ArraySizeModifier sm, unsigned tq)
2607  : ArrayType(IncompleteArray, et, can, sm, tq,
2609  friend class ASTContext; // ASTContext creates these.
2610 public:
2611  bool isSugared() const { return false; }
2612  QualType desugar() const { return QualType(this, 0); }
2613 
2614  static bool classof(const Type *T) {
2615  return T->getTypeClass() == IncompleteArray;
2616  }
2617 
2618  friend class StmtIteratorBase;
2619 
2620  void Profile(llvm::FoldingSetNodeID &ID) {
2623  }
2624 
2625  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
2626  ArraySizeModifier SizeMod, unsigned TypeQuals) {
2627  ID.AddPointer(ET.getAsOpaquePtr());
2628  ID.AddInteger(SizeMod);
2629  ID.AddInteger(TypeQuals);
2630  }
2631 };
2632 
2633 /// Represents a C array with a specified size that is not an
2634 /// integer-constant-expression. For example, 'int s[x+foo()]'.
2635 /// Since the size expression is an arbitrary expression, we store it as such.
2636 ///
2637 /// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
2638 /// should not be: two lexically equivalent variable array types could mean
2639 /// different things, for example, these variables do not have the same type
2640 /// dynamically:
2641 ///
2642 /// void foo(int x) {
2643 /// int Y[x];
2644 /// ++x;
2645 /// int Z[x];
2646 /// }
2647 ///
2649  /// An assignment-expression. VLA's are only permitted within
2650  /// a function block.
2651  Stmt *SizeExpr;
2652  /// The range spanned by the left and right array brackets.
2653  SourceRange Brackets;
2654 
2656  ArraySizeModifier sm, unsigned tq,
2657  SourceRange brackets)
2658  : ArrayType(VariableArray, et, can, sm, tq,
2660  SizeExpr((Stmt*) e), Brackets(brackets) {}
2661  friend class ASTContext; // ASTContext creates these.
2662 
2663 public:
2664  Expr *getSizeExpr() const {
2665  // We use C-style casts instead of cast<> here because we do not wish
2666  // to have a dependency of Type.h on Stmt.h/Expr.h.
2667  return (Expr*) SizeExpr;
2668  }
2669  SourceRange getBracketsRange() const { return Brackets; }
2670  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
2671  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
2672 
2673  bool isSugared() const { return false; }
2674  QualType desugar() const { return QualType(this, 0); }
2675 
2676  static bool classof(const Type *T) {
2677  return T->getTypeClass() == VariableArray;
2678  }
2679 
2680  friend class StmtIteratorBase;
2681 
2682  void Profile(llvm::FoldingSetNodeID &ID) {
2683  llvm_unreachable("Cannot unique VariableArrayTypes.");
2684  }
2685 };
2686 
2687 /// Represents an array type in C++ whose size is a value-dependent expression.
2688 ///
2689 /// For example:
2690 /// \code
2691 /// template<typename T, int Size>
2692 /// class array {
2693 /// T data[Size];
2694 /// };
2695 /// \endcode
2696 ///
2697 /// For these types, we won't actually know what the array bound is
2698 /// until template instantiation occurs, at which point this will
2699 /// become either a ConstantArrayType or a VariableArrayType.
2701  const ASTContext &Context;
2702 
2703  /// \brief An assignment expression that will instantiate to the
2704  /// size of the array.
2705  ///
2706  /// The expression itself might be null, in which case the array
2707  /// type will have its size deduced from an initializer.
2708  Stmt *SizeExpr;
2709 
2710  /// The range spanned by the left and right array brackets.
2711  SourceRange Brackets;
2712 
2713  DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can,
2714  Expr *e, ArraySizeModifier sm, unsigned tq,
2715  SourceRange brackets);
2716 
2717  friend class ASTContext; // ASTContext creates these.
2718 
2719 public:
2720  Expr *getSizeExpr() const {
2721  // We use C-style casts instead of cast<> here because we do not wish
2722  // to have a dependency of Type.h on Stmt.h/Expr.h.
2723  return (Expr*) SizeExpr;
2724  }
2725  SourceRange getBracketsRange() const { return Brackets; }
2726  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
2727  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
2728 
2729  bool isSugared() const { return false; }
2730  QualType desugar() const { return QualType(this, 0); }
2731 
2732  static bool classof(const Type *T) {
2733  return T->getTypeClass() == DependentSizedArray;
2734  }
2735 
2736  friend class StmtIteratorBase;
2737 
2738 
2739  void Profile(llvm::FoldingSetNodeID &ID) {
2740  Profile(ID, Context, getElementType(),
2742  }
2743 
2744  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
2745  QualType ET, ArraySizeModifier SizeMod,
2746  unsigned TypeQuals, Expr *E);
2747 };
2748 
2749 /// Represents an extended vector type where either the type or size is
2750 /// dependent.
2751 ///
2752 /// For example:
2753 /// \code
2754 /// template<typename T, int Size>
2755 /// class vector {
2756 /// typedef T __attribute__((ext_vector_type(Size))) type;
2757 /// }
2758 /// \endcode
2759 class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
2760  const ASTContext &Context;
2761  Expr *SizeExpr;
2762  /// The element type of the array.
2763  QualType ElementType;
2764  SourceLocation loc;
2765 
2766  DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType,
2767  QualType can, Expr *SizeExpr, SourceLocation loc);
2768 
2769  friend class ASTContext;
2770 
2771 public:
2772  Expr *getSizeExpr() const { return SizeExpr; }
2773  QualType getElementType() const { return ElementType; }
2774  SourceLocation getAttributeLoc() const { return loc; }
2775 
2776  bool isSugared() const { return false; }
2777  QualType desugar() const { return QualType(this, 0); }
2778 
2779  static bool classof(const Type *T) {
2780  return T->getTypeClass() == DependentSizedExtVector;
2781  }
2782 
2783  void Profile(llvm::FoldingSetNodeID &ID) {
2784  Profile(ID, Context, getElementType(), getSizeExpr());
2785  }
2786 
2787  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
2788  QualType ElementType, Expr *SizeExpr);
2789 };
2790 
2791 
2792 /// Represents a GCC generic vector type. This type is created using
2793 /// __attribute__((vector_size(n)), where "n" specifies the vector size in
2794 /// bytes; or from an Altivec __vector or vector declaration.
2795 /// Since the constructor takes the number of vector elements, the
2796 /// client is responsible for converting the size into the number of elements.
2797 class VectorType : public Type, public llvm::FoldingSetNode {
2798 public:
2799  enum VectorKind {
2800  GenericVector, ///< not a target-specific vector type
2801  AltiVecVector, ///< is AltiVec vector
2802  AltiVecPixel, ///< is AltiVec 'vector Pixel'
2803  AltiVecBool, ///< is AltiVec 'vector bool ...'
2804  NeonVector, ///< is ARM Neon vector
2805  NeonPolyVector ///< is ARM Neon polynomial vector
2806  };
2807 protected:
2808  /// The element type of the vector.
2810 
2811  VectorType(QualType vecType, unsigned nElements, QualType canonType,
2812  VectorKind vecKind);
2813 
2814  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
2815  QualType canonType, VectorKind vecKind);
2816 
2817  friend class ASTContext; // ASTContext creates these.
2818 
2819 public:
2820 
2822  unsigned getNumElements() const { return VectorTypeBits.NumElements; }
2823  static bool isVectorSizeTooLarge(unsigned NumElements) {
2824  return NumElements > VectorTypeBitfields::MaxNumElements;
2825  }
2826 
2827  bool isSugared() const { return false; }
2828  QualType desugar() const { return QualType(this, 0); }
2829 
2831  return VectorKind(VectorTypeBits.VecKind);
2832  }
2833 
2834  void Profile(llvm::FoldingSetNodeID &ID) {
2837  }
2838  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
2839  unsigned NumElements, TypeClass TypeClass,
2840  VectorKind VecKind) {
2841  ID.AddPointer(ElementType.getAsOpaquePtr());
2842  ID.AddInteger(NumElements);
2843  ID.AddInteger(TypeClass);
2844  ID.AddInteger(VecKind);
2845  }
2846 
2847  static bool classof(const Type *T) {
2848  return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
2849  }
2850 };
2851 
2852 /// ExtVectorType - Extended vector type. This type is created using
2853 /// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
2854 /// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
2855 /// class enables syntactic extensions, like Vector Components for accessing
2856 /// points (as .xyzw), colors (as .rgba), and textures (modeled after OpenGL
2857 /// Shading Language).
2858 class ExtVectorType : public VectorType {
2859  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
2860  VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
2861  friend class ASTContext; // ASTContext creates these.
2862 public:
2863  static int getPointAccessorIdx(char c) {
2864  switch (c) {
2865  default: return -1;
2866  case 'x': case 'r': return 0;
2867  case 'y': case 'g': return 1;
2868  case 'z': case 'b': return 2;
2869  case 'w': case 'a': return 3;
2870  }
2871  }
2872  static int getNumericAccessorIdx(char c) {
2873  switch (c) {
2874  default: return -1;
2875  case '0': return 0;
2876  case '1': return 1;
2877  case '2': return 2;
2878  case '3': return 3;
2879  case '4': return 4;
2880  case '5': return 5;
2881  case '6': return 6;
2882  case '7': return 7;
2883  case '8': return 8;
2884  case '9': return 9;
2885  case 'A':
2886  case 'a': return 10;
2887  case 'B':
2888  case 'b': return 11;
2889  case 'C':
2890  case 'c': return 12;
2891  case 'D':
2892  case 'd': return 13;
2893  case 'E':
2894  case 'e': return 14;
2895  case 'F':
2896  case 'f': return 15;
2897  }
2898  }
2899 
2900  static int getAccessorIdx(char c, bool isNumericAccessor) {
2901  if (isNumericAccessor)
2902  return getNumericAccessorIdx(c);
2903  else
2904  return getPointAccessorIdx(c);
2905  }
2906 
2907  bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const {
2908  if (int idx = getAccessorIdx(c, isNumericAccessor)+1)
2909  return unsigned(idx-1) < getNumElements();
2910  return false;
2911  }
2912  bool isSugared() const { return false; }
2913  QualType desugar() const { return QualType(this, 0); }
2914 
2915  static bool classof(const Type *T) {
2916  return T->getTypeClass() == ExtVector;
2917  }
2918 };
2919 
2920 /// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base
2921 /// class of FunctionNoProtoType and FunctionProtoType.
2922 ///
2923 class FunctionType : public Type {
2924  // The type returned by the function.
2925  QualType ResultType;
2926 
2927  public:
2928  /// A class which abstracts out some details necessary for
2929  /// making a call.
2930  ///
2931  /// It is not actually used directly for storing this information in
2932  /// a FunctionType, although FunctionType does currently use the
2933  /// same bit-pattern.
2934  ///
2935  // If you add a field (say Foo), other than the obvious places (both,
2936  // constructors, compile failures), what you need to update is
2937  // * Operator==
2938  // * getFoo
2939  // * withFoo
2940  // * functionType. Add Foo, getFoo.
2941  // * ASTContext::getFooType
2942  // * ASTContext::mergeFunctionTypes
2943  // * FunctionNoProtoType::Profile
2944  // * FunctionProtoType::Profile
2945  // * TypePrinter::PrintFunctionProto
2946  // * AST read and write
2947  // * Codegen
2948  class ExtInfo {
2949  // Feel free to rearrange or add bits, but if you go over 11,
2950  // you'll need to adjust both the Bits field below and
2951  // Type::FunctionTypeBitfields.
2952 
2953  // | CC |noreturn|produces|nocallersavedregs|regparm|
2954  // |0 .. 4| 5 | 6 | 7 |8 .. 10|
2955  //
2956  // regparm is either 0 (no regparm attribute) or the regparm value+1.
2957  enum { CallConvMask = 0x1F };
2958  enum { NoReturnMask = 0x20 };
2959  enum { ProducesResultMask = 0x40 };
2960  enum { NoCallerSavedRegsMask = 0x80 };
2961  enum {
2962  RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask |
2963  NoCallerSavedRegsMask),
2964  RegParmOffset = 8
2965  }; // Assumed to be the last field
2966 
2967  uint16_t Bits;
2968 
2969  ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
2970 
2971  friend class FunctionType;
2972 
2973  public:
2974  // Constructor with no defaults. Use this when you know that you
2975  // have all the elements (when reading an AST file for example).
2976  ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
2977  bool producesResult, bool noCallerSavedRegs) {
2978  assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
2979  Bits = ((unsigned)cc) | (noReturn ? NoReturnMask : 0) |
2980  (producesResult ? ProducesResultMask : 0) |
2981  (noCallerSavedRegs ? NoCallerSavedRegsMask : 0) |
2982  (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0);
2983  }
2984 
2985  // Constructor with all defaults. Use when for example creating a
2986  // function known to use defaults.
2987  ExtInfo() : Bits(CC_C) { }
2988 
2989  // Constructor with just the calling convention, which is an important part
2990  // of the canonical type.
2991  ExtInfo(CallingConv CC) : Bits(CC) { }
2992 
2993  bool getNoReturn() const { return Bits & NoReturnMask; }
2994  bool getProducesResult() const { return Bits & ProducesResultMask; }
2995  bool getNoCallerSavedRegs() const { return Bits & NoCallerSavedRegsMask; }
2996  bool getHasRegParm() const { return (Bits >> RegParmOffset) != 0; }
2997  unsigned getRegParm() const {
2998  unsigned RegParm = Bits >> RegParmOffset;
2999  if (RegParm > 0)
3000  --RegParm;
3001  return RegParm;
3002  }
3003  CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
3004 
3005  bool operator==(ExtInfo Other) const {
3006  return Bits == Other.Bits;
3007  }
3008  bool operator!=(ExtInfo Other) const {
3009  return Bits != Other.Bits;
3010  }
3011 
3012  // Note that we don't have setters. That is by design, use
3013  // the following with methods instead of mutating these objects.
3014 
3015  ExtInfo withNoReturn(bool noReturn) const {
3016  if (noReturn)
3017  return ExtInfo(Bits | NoReturnMask);
3018  else
3019  return ExtInfo(Bits & ~NoReturnMask);
3020  }
3021 
3022  ExtInfo withProducesResult(bool producesResult) const {
3023  if (producesResult)
3024  return ExtInfo(Bits | ProducesResultMask);
3025  else
3026  return ExtInfo(Bits & ~ProducesResultMask);
3027  }
3028 
3029  ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const {
3030  if (noCallerSavedRegs)
3031  return ExtInfo(Bits | NoCallerSavedRegsMask);
3032  else
3033  return ExtInfo(Bits & ~NoCallerSavedRegsMask);
3034  }
3035 
3036  ExtInfo withRegParm(unsigned RegParm) const {
3037  assert(RegParm < 7 && "Invalid regparm value");
3038  return ExtInfo((Bits & ~RegParmMask) |
3039  ((RegParm + 1) << RegParmOffset));
3040  }
3041 
3043  return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
3044  }
3045 
3046  void Profile(llvm::FoldingSetNodeID &ID) const {
3047  ID.AddInteger(Bits);
3048  }
3049  };
3050 
3051 protected:
3053  QualType Canonical, bool Dependent,
3054  bool InstantiationDependent,
3055  bool VariablyModified, bool ContainsUnexpandedParameterPack,
3056  ExtInfo Info)
3057  : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
3058  ContainsUnexpandedParameterPack),
3059  ResultType(res) {
3060  FunctionTypeBits.ExtInfo = Info.Bits;
3061  }
3062  unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; }
3063 
3064 public:
3065  QualType getReturnType() const { return ResultType; }
3066 
3067  bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
3068  unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
3069  /// Determine whether this function type includes the GNU noreturn
3070  /// attribute. The C++11 [[noreturn]] attribute does not affect the function
3071  /// type.
3072  bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
3073  CallingConv getCallConv() const { return getExtInfo().getCC(); }
3074  ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
3075  bool isConst() const { return getTypeQuals() & Qualifiers::Const; }
3076  bool isVolatile() const { return getTypeQuals() & Qualifiers::Volatile; }
3077  bool isRestrict() const { return getTypeQuals() & Qualifiers::Restrict; }
3078 
3079  /// \brief Determine the type of an expression that calls a function of
3080  /// this type.
3082  return getReturnType().getNonLValueExprType(Context);
3083  }
3084 
3085  static StringRef getNameForCallConv(CallingConv CC);
3086 
3087  static bool classof(const Type *T) {
3088  return T->getTypeClass() == FunctionNoProto ||
3089  T->getTypeClass() == FunctionProto;
3090  }
3091 };
3092 
3093 /// Represents a K&R-style 'int foo()' function, which has
3094 /// no information available about its arguments.
3095 class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
3097  : FunctionType(FunctionNoProto, Result, Canonical,
3098  /*Dependent=*/false, /*InstantiationDependent=*/false,
3099  Result->isVariablyModifiedType(),
3100  /*ContainsUnexpandedParameterPack=*/false, Info) {}
3101 
3102  friend class ASTContext; // ASTContext creates these.
3103 
3104 public:
3105  // No additional state past what FunctionType provides.
3106 
3107  bool isSugared() const { return false; }
3108  QualType desugar() const { return QualType(this, 0); }
3109 
3110  void Profile(llvm::FoldingSetNodeID &ID) {
3111  Profile(ID, getReturnType(), getExtInfo());
3112  }
3113  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
3114  ExtInfo Info) {
3115  Info.Profile(ID);
3116  ID.AddPointer(ResultType.getAsOpaquePtr());
3117  }
3118 
3119  static bool classof(const Type *T) {
3120  return T->getTypeClass() == FunctionNoProto;
3121  }
3122 };
3123 
3124 /// Represents a prototype with parameter type info, e.g.
3125 /// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no
3126 /// parameters, not as having a single void parameter. Such a type can have an
3127 /// exception specification, but this specification is not part of the canonical
3128 /// type.
3129 class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
3130 public:
3131  /// Interesting information about a specific parameter that can't simply
3132  /// be reflected in parameter's type.
3133  ///
3134  /// It makes sense to model language features this way when there's some
3135  /// sort of parameter-specific override (such as an attribute) that
3136  /// affects how the function is called. For example, the ARC ns_consumed
3137  /// attribute changes whether a parameter is passed at +0 (the default)
3138  /// or +1 (ns_consumed). This must be reflected in the function type,
3139  /// but isn't really a change to the parameter type.
3140  ///
3141  /// One serious disadvantage of modelling language features this way is
3142  /// that they generally do not work with language features that attempt
3143  /// to destructure types. For example, template argument deduction will
3144  /// not be able to match a parameter declared as
3145  /// T (*)(U)
3146  /// against an argument of type
3147  /// void (*)(__attribute__((ns_consumed)) id)
3148  /// because the substitution of T=void, U=id into the former will
3149  /// not produce the latter.
3151  enum {
3152  ABIMask = 0x0F,
3153  IsConsumed = 0x10,
3154  HasPassObjSize = 0x20,
3155  };
3156  unsigned char Data;
3157 
3158  public:
3159  ExtParameterInfo() : Data(0) {}
3160 
3161  /// Return the ABI treatment of this parameter.
3163  return ParameterABI(Data & ABIMask);
3164  }
3166  ExtParameterInfo copy = *this;
3167  copy.Data = (copy.Data & ~ABIMask) | unsigned(kind);
3168  return copy;
3169  }
3170 
3171  /// Is this parameter considered "consumed" by Objective-C ARC?
3172  /// Consumed parameters must have retainable object type.
3173  bool isConsumed() const {
3174  return (Data & IsConsumed);
3175  }
3176  ExtParameterInfo withIsConsumed(bool consumed) const {
3177  ExtParameterInfo copy = *this;
3178  if (consumed) {
3179  copy.Data |= IsConsumed;
3180  } else {
3181  copy.Data &= ~IsConsumed;
3182  }
3183  return copy;
3184  }
3185 
3186  bool hasPassObjectSize() const {
3187  return Data & HasPassObjSize;
3188  }
3190  ExtParameterInfo Copy = *this;
3191  Copy.Data |= HasPassObjSize;
3192  return Copy;
3193  }
3194 
3195  unsigned char getOpaqueValue() const { return Data; }
3196  static ExtParameterInfo getFromOpaqueValue(unsigned char data) {
3197  ExtParameterInfo result;
3198  result.Data = data;
3199  return result;
3200  }
3201 
3203  return lhs.Data == rhs.Data;
3204  }
3206  return lhs.Data != rhs.Data;
3207  }
3208  };
3209 
3212  : Type(EST_None), NoexceptExpr(nullptr),
3213  SourceDecl(nullptr), SourceTemplate(nullptr) {}
3214 
3216  : Type(EST), NoexceptExpr(nullptr), SourceDecl(nullptr),
3217  SourceTemplate(nullptr) {}
3218 
3219  /// The kind of exception specification this is.
3221  /// Explicitly-specified list of exception types.
3223  /// Noexcept expression, if this is EST_ComputedNoexcept.
3225  /// The function whose exception specification this is, for
3226  /// EST_Unevaluated and EST_Uninstantiated.
3228  /// The function template whose exception specification this is instantiated
3229  /// from, for EST_Uninstantiated.
3231  };
3232 
3233  /// Extra information about a function prototype.
3234  struct ExtProtoInfo {
3236  : Variadic(false), HasTrailingReturn(false), TypeQuals(0),
3237  RefQualifier(RQ_None), ExtParameterInfos(nullptr) {}
3238 
3240  : ExtInfo(CC), Variadic(false), HasTrailingReturn(false), TypeQuals(0),
3241  RefQualifier(RQ_None), ExtParameterInfos(nullptr) {}
3242 
3244  ExtProtoInfo Result(*this);
3245  Result.ExceptionSpec = O;
3246  return Result;
3247  }
3248 
3250  bool Variadic : 1;
3251  bool HasTrailingReturn : 1;
3252  unsigned char TypeQuals;
3256  };
3257 
3258 private:
3259  /// \brief Determine whether there are any argument types that
3260  /// contain an unexpanded parameter pack.
3261  static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
3262  unsigned numArgs) {
3263  for (unsigned Idx = 0; Idx < numArgs; ++Idx)
3264  if (ArgArray[Idx]->containsUnexpandedParameterPack())
3265  return true;
3266 
3267  return false;
3268  }
3269 
3271  QualType canonical, const ExtProtoInfo &epi);
3272 
3273  /// The number of parameters this function has, not counting '...'.
3274  unsigned NumParams : 15;
3275 
3276  /// The number of types in the exception spec, if any.
3277  unsigned NumExceptions : 9;
3278 
3279  /// The type of exception specification this function has.
3280  unsigned ExceptionSpecType : 4;
3281 
3282  /// Whether this function has extended parameter information.
3283  unsigned HasExtParameterInfos : 1;
3284 
3285  /// Whether the function is variadic.
3286  unsigned Variadic : 1;
3287 
3288  /// Whether this function has a trailing return type.
3289  unsigned HasTrailingReturn : 1;
3290 
3291  // ParamInfo - There is an variable size array after the class in memory that
3292  // holds the parameter types.
3293 
3294  // Exceptions - There is another variable size array after ArgInfo that
3295  // holds the exception types.
3296 
3297  // NoexceptExpr - Instead of Exceptions, there may be a single Expr* pointing
3298  // to the expression in the noexcept() specifier.
3299 
3300  // ExceptionSpecDecl, ExceptionSpecTemplate - Instead of Exceptions, there may
3301  // be a pair of FunctionDecl* pointing to the function which should be used to
3302  // instantiate this function type's exception specification, and the function
3303  // from which it should be instantiated.
3304 
3305  // ExtParameterInfos - A variable size array, following the exception
3306  // specification and of length NumParams, holding an ExtParameterInfo
3307  // for each of the parameters. This only appears if HasExtParameterInfos
3308  // is true.
3309 
3310  friend class ASTContext; // ASTContext creates these.
3311 
3312  const ExtParameterInfo *getExtParameterInfosBuffer() const {
3313  assert(hasExtParameterInfos());
3314 
3315  // Find the end of the exception specification.
3316  const char *ptr = reinterpret_cast<const char *>(exception_begin());
3317  ptr += getExceptionSpecSize();
3318 
3319  return reinterpret_cast<const ExtParameterInfo *>(ptr);
3320  }
3321 
3322  size_t getExceptionSpecSize() const {
3323  switch (getExceptionSpecType()) {
3324  case EST_None: return 0;
3325  case EST_DynamicNone: return 0;
3326  case EST_MSAny: return 0;
3327  case EST_BasicNoexcept: return 0;
3328  case EST_Unparsed: return 0;
3329  case EST_Dynamic: return getNumExceptions() * sizeof(QualType);
3330  case EST_ComputedNoexcept: return sizeof(Expr*);
3331  case EST_Uninstantiated: return 2 * sizeof(FunctionDecl*);
3332  case EST_Unevaluated: return sizeof(FunctionDecl*);
3333  }
3334  llvm_unreachable("bad exception specification kind");
3335  }
3336 
3337 public:
3338  unsigned getNumParams() const { return NumParams; }
3339  QualType getParamType(unsigned i) const {
3340  assert(i < NumParams && "invalid parameter index");
3341  return param_type_begin()[i];
3342  }
3344  return llvm::makeArrayRef(param_type_begin(), param_type_end());
3345  }
3346 
3348  ExtProtoInfo EPI;
3349  EPI.ExtInfo = getExtInfo();
3350  EPI.Variadic = isVariadic();
3351  EPI.HasTrailingReturn = hasTrailingReturn();
3352  EPI.ExceptionSpec.Type = getExceptionSpecType();
3353  EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals());
3354  EPI.RefQualifier = getRefQualifier();
3355  if (EPI.ExceptionSpec.Type == EST_Dynamic) {
3356  EPI.ExceptionSpec.Exceptions = exceptions();
3357  } else if (EPI.ExceptionSpec.Type == EST_ComputedNoexcept) {
3358  EPI.ExceptionSpec.NoexceptExpr = getNoexceptExpr();
3359  } else if (EPI.ExceptionSpec.Type == EST_Uninstantiated) {
3360  EPI.ExceptionSpec.SourceDecl = getExceptionSpecDecl();
3361  EPI.ExceptionSpec.SourceTemplate = getExceptionSpecTemplate();
3362  } else if (EPI.ExceptionSpec.Type == EST_Unevaluated) {
3363  EPI.ExceptionSpec.SourceDecl = getExceptionSpecDecl();
3364  }
3365  if (hasExtParameterInfos())
3366  EPI.ExtParameterInfos = getExtParameterInfosBuffer();
3367  return EPI;
3368  }
3369 
3370  /// Get the kind of exception specification on this function.
3372  return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
3373  }
3374  /// Return whether this function has any kind of exception spec.
3375  bool hasExceptionSpec() const {
3376  return getExceptionSpecType() != EST_None;
3377  }
3378  /// Return whether this function has a dynamic (throw) exception spec.
3380  return isDynamicExceptionSpec(getExceptionSpecType());
3381  }
3382  /// Return whether this function has a noexcept exception spec.
3384  return isNoexceptExceptionSpec(getExceptionSpecType());
3385  }
3386  /// Return whether this function has a dependent exception spec.
3387  bool hasDependentExceptionSpec() const;
3388  /// Return whether this function has an instantiation-dependent exception
3389  /// spec.
3390  bool hasInstantiationDependentExceptionSpec() const;
3391  /// Result type of getNoexceptSpec().
3393  NR_NoNoexcept, ///< There is no noexcept specifier.
3394  NR_BadNoexcept, ///< The noexcept specifier has a bad expression.
3395  NR_Dependent, ///< The noexcept specifier is dependent.
3396  NR_Throw, ///< The noexcept specifier evaluates to false.
3397  NR_Nothrow ///< The noexcept specifier evaluates to true.
3398  };
3399  /// Get the meaning of the noexcept spec on this function, if any.
3400  NoexceptResult getNoexceptSpec(const ASTContext &Ctx) const;
3401  unsigned getNumExceptions() const { return NumExceptions; }
3402  QualType getExceptionType(unsigned i) const {
3403  assert(i < NumExceptions && "Invalid exception number!");
3404  return exception_begin()[i];
3405  }
3407  if (getExceptionSpecType() != EST_ComputedNoexcept)
3408  return nullptr;
3409  // NoexceptExpr sits where the arguments end.
3410  return *reinterpret_cast<Expr *const *>(param_type_end());
3411  }
3412  /// \brief If this function type has an exception specification which hasn't
3413  /// been determined yet (either because it has not been evaluated or because
3414  /// it has not been instantiated), this is the function whose exception
3415  /// specification is represented by this type.
3417  if (getExceptionSpecType() != EST_Uninstantiated &&
3418  getExceptionSpecType() != EST_Unevaluated)
3419  return nullptr;
3420  return reinterpret_cast<FunctionDecl *const *>(param_type_end())[0];
3421  }
3422  /// \brief If this function type has an uninstantiated exception
3423  /// specification, this is the function whose exception specification
3424  /// should be instantiated to find the exception specification for
3425  /// this type.
3427  if (getExceptionSpecType() != EST_Uninstantiated)
3428  return nullptr;
3429  return reinterpret_cast<FunctionDecl *const *>(param_type_end())[1];
3430  }
3431  /// Determine whether this function type has a non-throwing exception
3432  /// specification.
3433  CanThrowResult canThrow(const ASTContext &Ctx) const;
3434  /// Determine whether this function type has a non-throwing exception
3435  /// specification. If this depends on template arguments, returns
3436  /// \c ResultIfDependent.
3437  bool isNothrow(const ASTContext &Ctx, bool ResultIfDependent = false) const {
3438  return ResultIfDependent ? canThrow(Ctx) != CT_Can
3439  : canThrow(Ctx) == CT_Cannot;
3440  }
3441 
3442  bool isVariadic() const { return Variadic; }
3443 
3444  /// Determines whether this function prototype contains a
3445  /// parameter pack at the end.
3446  ///
3447  /// A function template whose last parameter is a parameter pack can be
3448  /// called with an arbitrary number of arguments, much like a variadic
3449  /// function.
3450  bool isTemplateVariadic() const;
3451 
3452  bool hasTrailingReturn() const { return HasTrailingReturn; }
3453 
3454  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
3455 
3456 
3457  /// Retrieve the ref-qualifier associated with this function type.
3459  return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
3460  }
3461 
3463  typedef llvm::iterator_range<param_type_iterator> param_type_range;
3464 
3466  return param_type_range(param_type_begin(), param_type_end());
3467  }
3469  return reinterpret_cast<const QualType *>(this+1);
3470  }
3472  return param_type_begin() + NumParams;
3473  }
3474 
3476 
3478  return llvm::makeArrayRef(exception_begin(), exception_end());
3479  }
3481  // exceptions begin where arguments end
3482  return param_type_end();
3483  }
3485  if (getExceptionSpecType() != EST_Dynamic)
3486  return exception_begin();
3487  return exception_begin() + NumExceptions;
3488  }
3489 
3490  /// Is there any interesting extra information for any of the parameters
3491  /// of this function type?
3492  bool hasExtParameterInfos() const { return HasExtParameterInfos; }
3494  assert(hasExtParameterInfos());
3495  return ArrayRef<ExtParameterInfo>(getExtParameterInfosBuffer(),
3496  getNumParams());
3497  }
3498  /// Return a pointer to the beginning of the array of extra parameter
3499  /// information, if present, or else null if none of the parameters
3500  /// carry it. This is equivalent to getExtProtoInfo().ExtParameterInfos.
3502  if (!hasExtParameterInfos())
3503  return nullptr;
3504  return getExtParameterInfosBuffer();
3505  }
3506 
3508  assert(I < getNumParams() && "parameter index out of range");
3509  if (hasExtParameterInfos())
3510  return getExtParameterInfosBuffer()[I];
3511  return ExtParameterInfo();
3512  }
3513 
3514  ParameterABI getParameterABI(unsigned I) const {
3515  assert(I < getNumParams() && "parameter index out of range");
3516  if (hasExtParameterInfos())
3517  return getExtParameterInfosBuffer()[I].getABI();
3518  return ParameterABI::Ordinary;
3519  }
3520 
3521  bool isParamConsumed(unsigned I) const {
3522  assert(I < getNumParams() && "parameter index out of range");
3523  if (hasExtParameterInfos())
3524  return getExtParameterInfosBuffer()[I].isConsumed();
3525  return false;
3526  }
3527 
3528  bool isSugared() const { return false; }
3529  QualType desugar() const { return QualType(this, 0); }
3530 
3531  void printExceptionSpecification(raw_ostream &OS,
3532  const PrintingPolicy &Policy) const;
3533 
3534  static bool classof(const Type *T) {
3535  return T->getTypeClass() == FunctionProto;
3536  }
3537 
3538  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
3539  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
3540  param_type_iterator ArgTys, unsigned NumArgs,
3541  const ExtProtoInfo &EPI, const ASTContext &Context,
3542  bool Canonical);
3543 };
3544 
3545 /// \brief Represents the dependent type named by a dependently-scoped
3546 /// typename using declaration, e.g.
3547 /// using typename Base<T>::foo;
3548 ///
3549 /// Template instantiation turns these into the underlying type.
3550 class UnresolvedUsingType : public Type {
3552 
3554  : Type(UnresolvedUsing, QualType(), true, true, false,
3555  /*ContainsUnexpandedParameterPack=*/false),
3556  Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {}
3557  friend class ASTContext; // ASTContext creates these.
3558 public:
3559 
3561 
3562  bool isSugared() const { return false; }
3563  QualType desugar() const { return QualType(this, 0); }
3564 
3565  static bool classof(const Type *T) {
3566  return T->getTypeClass() == UnresolvedUsing;
3567  }
3568 
3569  void Profile(llvm::FoldingSetNodeID &ID) {
3570  return Profile(ID, Decl);
3571  }
3572  static void Profile(llvm::FoldingSetNodeID &ID,
3574  ID.AddPointer(D);
3575  }
3576 };
3577 
3578 
3579 class TypedefType : public Type {
3581 protected:
3583  : Type(tc, can, can->isDependentType(),
3585  can->isVariablyModifiedType(),
3586  /*ContainsUnexpandedParameterPack=*/false),
3587  Decl(const_cast<TypedefNameDecl*>(D)) {
3588  assert(!isa<TypedefType>(can) && "Invalid canonical type");
3589  }
3590  friend class ASTContext; // ASTContext creates these.
3591 public:
3592 
3593  TypedefNameDecl *getDecl() const { return Decl; }
3594 
3595  bool isSugared() const { return true; }
3596  QualType desugar() const;
3597 
3598  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
3599 };
3600 
3601 /// Represents a `typeof` (or __typeof__) expression (a GCC extension).
3602 class TypeOfExprType : public Type {
3603  Expr *TOExpr;
3604 
3605 protected:
3606  TypeOfExprType(Expr *E, QualType can = QualType());
3607  friend class ASTContext; // ASTContext creates these.
3608 public:
3609  Expr *getUnderlyingExpr() const { return TOExpr; }
3610 
3611  /// \brief Remove a single level of sugar.
3612  QualType desugar() const;
3613 
3614  /// \brief Returns whether this type directly provides sugar.
3615  bool isSugared() const;
3616 
3617  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
3618 };
3619 
3620 /// \brief Internal representation of canonical, dependent
3621 /// `typeof(expr)` types.
3622 ///
3623 /// This class is used internally by the ASTContext to manage
3624 /// canonical, dependent types, only. Clients will only see instances
3625 /// of this class via TypeOfExprType nodes.
3627  : public TypeOfExprType, public llvm::FoldingSetNode {
3628  const ASTContext &Context;
3629 
3630 public:
3632  : TypeOfExprType(E), Context(Context) { }
3633 
3634  void Profile(llvm::FoldingSetNodeID &ID) {
3635  Profile(ID, Context, getUnderlyingExpr());
3636  }
3637 
3638  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3639  Expr *E);
3640 };
3641 
3642 /// Represents `typeof(type)`, a GCC extension.
3643 class TypeOfType : public Type {
3644  QualType TOType;
3645  TypeOfType(QualType T, QualType can)
3646  : Type(TypeOf, can, T->isDependentType(),
3650  TOType(T) {
3651  assert(!isa<TypedefType>(can) && "Invalid canonical type");
3652  }
3653  friend class ASTContext; // ASTContext creates these.
3654 public:
3655  QualType getUnderlyingType() const { return TOType; }
3656 
3657  /// \brief Remove a single level of sugar.
3658  QualType desugar() const { return getUnderlyingType(); }
3659 
3660  /// \brief Returns whether this type directly provides sugar.
3661  bool isSugared() const { return true; }
3662 
3663  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
3664 };
3665 
3666 /// Represents the type `decltype(expr)` (C++11).
3667 class DecltypeType : public Type {
3668  Expr *E;
3669  QualType UnderlyingType;
3670 
3671 protected:
3672  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
3673  friend class ASTContext; // ASTContext creates these.
3674 public:
3675  Expr *getUnderlyingExpr() const { return E; }
3676  QualType getUnderlyingType() const { return UnderlyingType; }
3677 
3678  /// \brief Remove a single level of sugar.
3679  QualType desugar() const;
3680 
3681  /// \brief Returns whether this type directly provides sugar.
3682  bool isSugared() const;
3683 
3684  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
3685 };
3686 
3687 /// \brief Internal representation of canonical, dependent
3688 /// decltype(expr) types.
3689 ///
3690 /// This class is used internally by the ASTContext to manage
3691 /// canonical, dependent types, only. Clients will only see instances
3692 /// of this class via DecltypeType nodes.
3693 class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
3694  const ASTContext &Context;
3695 
3696 public:
3698 
3699  void Profile(llvm::FoldingSetNodeID &ID) {
3700  Profile(ID, Context, getUnderlyingExpr());
3701  }
3702 
3703  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3704  Expr *E);
3705 };
3706 
3707 /// A unary type transform, which is a type constructed from another.
3708 class UnaryTransformType : public Type {
3709 public:
3710  enum UTTKind {
3711  EnumUnderlyingType
3712  };
3713 
3714 private:
3715  /// The untransformed type.
3716  QualType BaseType;
3717  /// The transformed type if not dependent, otherwise the same as BaseType.
3718  QualType UnderlyingType;
3719 
3720  UTTKind UKind;
3721 protected:
3722  UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind,
3723  QualType CanonicalTy);
3724  friend class ASTContext;
3725 public:
3726  bool isSugared() const { return !isDependentType(); }
3727  QualType desugar() const { return UnderlyingType; }
3728 
3729  QualType getUnderlyingType() const { return UnderlyingType; }
3730  QualType getBaseType() const { return BaseType; }
3731 
3732  UTTKind getUTTKind() const { return UKind; }
3733 
3734  static bool classof(const Type *T) {
3735  return T->getTypeClass() == UnaryTransform;
3736  }
3737 };
3738 
3739 /// \brief Internal representation of canonical, dependent
3740 /// __underlying_type(type) types.
3741 ///
3742 /// This class is used internally by the ASTContext to manage
3743 /// canonical, dependent types, only. Clients will only see instances
3744 /// of this class via UnaryTransformType nodes.
3746  public llvm::FoldingSetNode {
3747 public:
3748  DependentUnaryTransformType(const ASTContext &C, QualType BaseType,
3749  UTTKind UKind);
3750  void Profile(llvm::FoldingSetNodeID &ID) {
3751  Profile(ID, getBaseType(), getUTTKind());
3752  }
3753 
3754  static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType,
3755  UTTKind UKind) {
3756  ID.AddPointer(BaseType.getAsOpaquePtr());
3757  ID.AddInteger((unsigned)UKind);
3758  }
3759 };
3760 
3761 class TagType : public Type {
3762  /// Stores the TagDecl associated with this type. The decl may point to any
3763  /// TagDecl that declares the entity.
3764  TagDecl * decl;
3765 
3766  friend class ASTReader;
3767 
3768 protected:
3769  TagType(TypeClass TC, const TagDecl *D, QualType can);
3770 
3771 public:
3772  TagDecl *getDecl() const;
3773 
3774  /// Determines whether this type is in the process of being defined.
3775  bool isBeingDefined() const;
3776 
3777  static bool classof(const Type *T) {
3778  return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
3779  }
3780 };
3781 
3782 /// A helper class that allows the use of isa/cast/dyncast
3783 /// to detect TagType objects of structs/unions/classes.
3784 class RecordType : public TagType {
3785 protected:
3786  explicit RecordType(const RecordDecl *D)
3787  : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { }
3789  : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { }
3790  friend class ASTContext; // ASTContext creates these.
3791 public:
3792 
3793  RecordDecl *getDecl() const {
3794  return reinterpret_cast<RecordDecl*>(TagType::getDecl());
3795  }
3796 
3797  // FIXME: This predicate is a helper to QualType/Type. It needs to
3798  // recursively check all fields for const-ness. If any field is declared
3799  // const, it needs to return false.
3800  bool hasConstFields() const { return false; }
3801 
3802  bool isSugared() const { return false; }
3803  QualType desugar() const { return QualType(this, 0); }
3804 
3805  static bool classof(const Type *T) { return T->getTypeClass() == Record; }
3806 };
3807 
3808 /// A helper class that allows the use of isa/cast/dyncast
3809 /// to detect TagType objects of enums.
3810 class EnumType : public TagType {
3811  explicit EnumType(const EnumDecl *D)
3812  : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { }
3813  friend class ASTContext; // ASTContext creates these.
3814 public:
3815 
3816  EnumDecl *getDecl() const {
3817  return reinterpret_cast<EnumDecl*>(TagType::getDecl());
3818  }
3819 
3820  bool isSugared() const { return false; }
3821  QualType desugar() const { return QualType(this, 0); }
3822 
3823  static bool classof(const Type *T) { return T->getTypeClass() == Enum; }
3824 };
3825 
3826 /// An attributed type is a type to which a type attribute has been applied.
3827 ///
3828 /// The "modified type" is the fully-sugared type to which the attributed
3829 /// type was applied; generally it is not canonically equivalent to the
3830 /// attributed type. The "equivalent type" is the minimally-desugared type
3831 /// which the type is canonically equivalent to.
3832 ///
3833 /// For example, in the following attributed type:
3834 /// int32_t __attribute__((vector_size(16)))
3835 /// - the modified type is the TypedefType for int32_t
3836 /// - the equivalent type is VectorType(16, int32_t)
3837 /// - the canonical type is VectorType(16, int)
3838 class AttributedType : public Type, public llvm::FoldingSetNode {
3839 public:
3840  // It is really silly to have yet another attribute-kind enum, but
3841  // clang::attr::Kind doesn't currently cover the pure type attrs.
3842  enum Kind {
3843  // Expression operand.
3849 
3850  FirstExprOperandKind = attr_address_space,
3851  LastExprOperandKind = attr_neon_polyvector_type,
3852 
3853  // Enumerated operand (string or keyword).
3858 
3859  FirstEnumOperandKind = attr_objc_gc,
3860  LastEnumOperandKind = attr_pcs_vfp,
3861 
3862  // No operand.
3887  };
3888 
3889 private:
3890  QualType ModifiedType;
3891  QualType EquivalentType;
3892 
3893  friend class ASTContext; // creates these
3894 
3895  AttributedType(QualType canon, Kind attrKind, QualType modified,
3896  QualType equivalent)
3897  : Type(Attributed, canon, equivalent->isDependentType(),
3898  equivalent->isInstantiationDependentType(),
3899  equivalent->isVariablyModifiedType(),
3900  equivalent->containsUnexpandedParameterPack()),
3901  ModifiedType(modified), EquivalentType(equivalent) {
3902  AttributedTypeBits.AttrKind = attrKind;
3903  }
3904 
3905 public:
3906  Kind getAttrKind() const {
3907  return static_cast<Kind>(AttributedTypeBits.AttrKind);
3908  }
3909 
3910  QualType getModifiedType() const { return ModifiedType; }
3911  QualType getEquivalentType() const { return EquivalentType; }
3912 
3913  bool isSugared() const { return true; }
3914  QualType desugar() const { return getEquivalentType(); }
3915 
3916  /// Does this attribute behave like a type qualifier?
3917  ///
3918  /// A type qualifier adjusts a type to provide specialized rules for
3919  /// a specific object, like the standard const and volatile qualifiers.
3920  /// This includes attributes controlling things like nullability,
3921  /// address spaces, and ARC ownership. The value of the object is still
3922  /// largely described by the modified type.
3923  ///
3924  /// In contrast, many type attributes "rewrite" their modified type to
3925  /// produce a fundamentally different type, not necessarily related in any
3926  /// formalizable way to the original type. For example, calling convention
3927  /// and vector attributes are not simple type qualifiers.
3928  ///
3929  /// Type qualifiers are often, but not always, reflected in the canonical
3930  /// type.
3931  bool isQualifier() const;
3932 
3933  bool isMSTypeSpec() const;
3934 
3935  bool isCallingConv() const;
3936 
3937  llvm::Optional<NullabilityKind> getImmediateNullability() const;
3938 
3939  /// Retrieve the attribute kind corresponding to the given
3940  /// nullability kind.
3942  switch (kind) {
3944  return attr_nonnull;
3945 
3947  return attr_nullable;
3948 
3950  return attr_null_unspecified;
3951  }
3952  llvm_unreachable("Unknown nullability kind.");
3953  }
3954 
3955  /// Strip off the top-level nullability annotation on the given
3956  /// type, if it's there.
3957  ///
3958  /// \param T The type to strip. If the type is exactly an
3959  /// AttributedType specifying nullability (without looking through
3960  /// type sugar), the nullability is returned and this type changed
3961  /// to the underlying modified type.
3962  ///
3963  /// \returns the top-level nullability, if present.
3964  static Optional<NullabilityKind> stripOuterNullability(QualType &T);
3965 
3966  void Profile(llvm::FoldingSetNodeID &ID) {
3967  Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
3968  }
3969 
3970  static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind,
3971  QualType modified, QualType equivalent) {
3972  ID.AddInteger(attrKind);
3973  ID.AddPointer(modified.getAsOpaquePtr());
3974  ID.AddPointer(equivalent.getAsOpaquePtr());
3975  }
3976 
3977  static bool classof(const Type *T) {
3978  return T->getTypeClass() == Attributed;
3979  }
3980 };
3981 
3982 class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
3983  // Helper data collector for canonical types.
3984  struct CanonicalTTPTInfo {
3985  unsigned Depth : 15;
3986  unsigned ParameterPack : 1;
3987  unsigned Index : 16;
3988  };
3989 
3990  union {
3991  // Info for the canonical type.
3992  CanonicalTTPTInfo CanTTPTInfo;
3993  // Info for the non-canonical type.
3995  };
3996 
3997  /// Build a non-canonical type.
3999  : Type(TemplateTypeParm, Canon, /*Dependent=*/true,
4000  /*InstantiationDependent=*/true,
4001  /*VariablyModified=*/false,
4003  TTPDecl(TTPDecl) { }
4004 
4005  /// Build the canonical type.
4006  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
4007  : Type(TemplateTypeParm, QualType(this, 0),
4008  /*Dependent=*/true,
4009  /*InstantiationDependent=*/true,
4010  /*VariablyModified=*/false, PP) {
4011  CanTTPTInfo.Depth = D;
4012  CanTTPTInfo.Index = I;
4013  CanTTPTInfo.ParameterPack = PP;
4014  }
4015 
4016  friend class ASTContext; // ASTContext creates these
4017 
4018  const CanonicalTTPTInfo& getCanTTPTInfo() const {
4020  return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo;
4021  }
4022 
4023 public:
4024  unsigned getDepth() const { return getCanTTPTInfo().Depth; }
4025  unsigned getIndex() const { return getCanTTPTInfo().Index; }
4026  bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; }
4027 
4029  return isCanonicalUnqualified() ? nullptr : TTPDecl;
4030  }
4031 
4032  IdentifierInfo *getIdentifier() const;
4033 
4034  bool isSugared() const { return false; }
4035  QualType desugar() const { return QualType(this, 0); }
4036 
4037  void Profile(llvm::FoldingSetNodeID &ID) {
4038  Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
4039  }
4040 
4041  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
4042  unsigned Index, bool ParameterPack,
4043  TemplateTypeParmDecl *TTPDecl) {
4044  ID.AddInteger(Depth);
4045  ID.AddInteger(Index);
4046  ID.AddBoolean(ParameterPack);
4047  ID.AddPointer(TTPDecl);
4048  }
4049 
4050  static bool classof(const Type *T) {
4051  return T->getTypeClass() == TemplateTypeParm;
4052  }
4053 };
4054 
4055 /// \brief Represents the result of substituting a type for a template
4056 /// type parameter.
4057 ///
4058 /// Within an instantiated template, all template type parameters have
4059 /// been replaced with these. They are used solely to record that a
4060 /// type was originally written as a template type parameter;
4061 /// therefore they are never canonical.
4062 class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
4063  // The original type parameter.
4064  const TemplateTypeParmType *Replaced;
4065 
4067  : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
4069  Canon->isVariablyModifiedType(),
4071  Replaced(Param) { }
4072 
4073  friend class ASTContext;
4074 
4075 public:
4076  /// Gets the template parameter that was substituted for.
4078  return Replaced;
4079  }
4080 
4081  /// Gets the type that was substituted for the template
4082  /// parameter.
4084  return getCanonicalTypeInternal();
4085  }
4086 
4087  bool isSugared() const { return true; }
4088  QualType desugar() const { return getReplacementType(); }
4089 
4090  void Profile(llvm::FoldingSetNodeID &ID) {
4091  Profile(ID, getReplacedParameter(), getReplacementType());
4092  }
4093  static void Profile(llvm::FoldingSetNodeID &ID,
4094  const TemplateTypeParmType *Replaced,
4096  ID.AddPointer(Replaced);
4097  ID.AddPointer(Replacement.getAsOpaquePtr());
4098  }
4099 
4100  static bool classof(const Type *T) {
4101  return T->getTypeClass() == SubstTemplateTypeParm;
4102  }
4103 };
4104 
4105 /// \brief Represents the result of substituting a set of types for a template
4106 /// type parameter pack.
4107 ///
4108 /// When a pack expansion in the source code contains multiple parameter packs
4109 /// and those parameter packs correspond to different levels of template
4110 /// parameter lists, this type node is used to represent a template type
4111 /// parameter pack from an outer level, which has already had its argument pack
4112 /// substituted but that still lives within a pack expansion that itself
4113 /// could not be instantiated. When actually performing a substitution into
4114 /// that pack expansion (e.g., when all template parameters have corresponding
4115 /// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
4116 /// at the current pack substitution index.
4117 class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
4118  /// \brief The original type parameter.
4119  const TemplateTypeParmType *Replaced;
4120 
4121  /// \brief A pointer to the set of template arguments that this
4122  /// parameter pack is instantiated with.
4123  const TemplateArgument *Arguments;
4124 
4125  /// \brief The number of template arguments in \c Arguments.
4126  unsigned NumArguments;
4127 
4129  QualType Canon,
4130  const TemplateArgument &ArgPack);
4131 
4132  friend class ASTContext;
4133 
4134 public:
4135  IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); }
4136 
4137  /// Gets the template parameter that was substituted for.
4139  return Replaced;
4140  }
4141 
4142  bool isSugared() const { return false; }
4143  QualType desugar() const { return QualType(this, 0); }
4144 
4145  TemplateArgument getArgumentPack() const;
4146 
4147  void Profile(llvm::FoldingSetNodeID &ID);
4148  static void Profile(llvm::FoldingSetNodeID &ID,
4149  const TemplateTypeParmType *Replaced,
4150  const TemplateArgument &ArgPack);
4151 
4152  static bool classof(const Type *T) {
4153  return T->getTypeClass() == SubstTemplateTypeParmPack;
4154  }
4155 };
4156 
4157 /// \brief Common base class for placeholders for types that get replaced by
4158 /// placeholder type deduction: C++11 auto, C++14 decltype(auto), C++17 deduced
4159 /// class template types, and (eventually) constrained type names from the C++
4160 /// Concepts TS.
4161 ///
4162 /// These types are usually a placeholder for a deduced type. However, before
4163 /// the initializer is attached, or (usually) if the initializer is
4164 /// type-dependent, there is no deduced type and the type is canonical. In
4165 /// the latter case, it is also a dependent type.
4166 class DeducedType : public Type {
4167 protected:
4168  DeducedType(TypeClass TC, QualType DeducedAsType, bool IsDependent,
4169  bool IsInstantiationDependent, bool ContainsParameterPack)
4170  : Type(TC,
4171  // FIXME: Retain the sugared deduced type?
4172  DeducedAsType.isNull() ? QualType(this, 0)
4173  : DeducedAsType.getCanonicalType(),
4174  IsDependent, IsInstantiationDependent,
4175  /*VariablyModified=*/false, ContainsParameterPack) {
4176  if (!DeducedAsType.isNull()) {
4177  if (DeducedAsType->isDependentType())
4178  setDependent();
4179  if (DeducedAsType->isInstantiationDependentType())
4181  if (DeducedAsType->containsUnexpandedParameterPack())
4183  }
4184  }
4185 
4186 public:
4187  bool isSugared() const { return !isCanonicalUnqualified(); }
4189 
4190  /// \brief Get the type deduced for this placeholder type, or null if it's
4191  /// either not been deduced or was deduced to a dependent type.
4194  }
4195  bool isDeduced() const {
4196  return !isCanonicalUnqualified() || isDependentType();
4197  }
4198 
4199  static bool classof(const Type *T) {
4200  return T->getTypeClass() == Auto ||
4201  T->getTypeClass() == DeducedTemplateSpecialization;
4202  }
4203 };
4204 
4205 /// \brief Represents a C++11 auto or C++14 decltype(auto) type.
4206 class AutoType : public DeducedType, public llvm::FoldingSetNode {
4207  AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword,
4208  bool IsDeducedAsDependent)
4209  : DeducedType(Auto, DeducedAsType, IsDeducedAsDependent,
4210  IsDeducedAsDependent, /*ContainsPack=*/false) {
4211  AutoTypeBits.Keyword = (unsigned)Keyword;
4212  }
4213 
4214  friend class ASTContext; // ASTContext creates these
4215 
4216 public:
4217  bool isDecltypeAuto() const {
4218  return getKeyword() == AutoTypeKeyword::DecltypeAuto;
4219  }
4221  return (AutoTypeKeyword)AutoTypeBits.Keyword;
4222  }
4223 
4224  void Profile(llvm::FoldingSetNodeID &ID) {
4225  Profile(ID, getDeducedType(), getKeyword(), isDependentType());
4226  }
4227 
4228  static void Profile(llvm::FoldingSetNodeID &ID, QualType Deduced,
4229  AutoTypeKeyword Keyword, bool IsDependent) {
4230  ID.AddPointer(Deduced.getAsOpaquePtr());
4231  ID.AddInteger((unsigned)Keyword);
4232  ID.AddBoolean(IsDependent);
4233  }
4234 
4235  static bool classof(const Type *T) {
4236  return T->getTypeClass() == Auto;
4237  }
4238 };
4239 
4240 /// \brief Represents a C++17 deduced template specialization type.
4242  public llvm::FoldingSetNode {
4243  /// The name of the template whose arguments will be deduced.
4244  TemplateName Template;
4245 
4247  QualType DeducedAsType,
4248  bool IsDeducedAsDependent)
4249  : DeducedType(DeducedTemplateSpecialization, DeducedAsType,
4250  IsDeducedAsDependent || Template.isDependent(),
4251  IsDeducedAsDependent || Template.isInstantiationDependent(),
4252  Template.containsUnexpandedParameterPack()),
4253  Template(Template) {}
4254 
4255  friend class ASTContext; // ASTContext creates these
4256 
4257 public:
4258  /// Retrieve the name of the template that we are deducing.
4259  TemplateName getTemplateName() const { return Template;}
4260 
4261  void Profile(llvm::FoldingSetNodeID &ID) {
4262  Profile(ID, getTemplateName(), getDeducedType(), isDependentType());
4263  }
4264 
4265  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template,
4266  QualType Deduced, bool IsDependent) {
4267  Template.Profile(ID);
4268  ID.AddPointer(Deduced.getAsOpaquePtr());
4269  ID.AddBoolean(IsDependent);
4270  }
4271 
4272  static bool classof(const Type *T) {
4273  return T->getTypeClass() == DeducedTemplateSpecialization;
4274  }
4275 };
4276 
4277 /// \brief Represents a type template specialization; the template
4278 /// must be a class template, a type alias template, or a template
4279 /// template parameter. A template which cannot be resolved to one of
4280 /// these, e.g. because it is written with a dependent scope
4281 /// specifier, is instead represented as a
4282 /// @c DependentTemplateSpecializationType.
4283 ///
4284 /// A non-dependent template specialization type is always "sugar",
4285 /// typically for a \c RecordType. For example, a class template
4286 /// specialization type of \c vector<int> will refer to a tag type for
4287 /// the instantiation \c std::vector<int, std::allocator<int>>
4288 ///
4289 /// Template specializations are dependent if either the template or
4290 /// any of the template arguments are dependent, in which case the
4291 /// type may also be canonical.
4292 ///
4293 /// Instances of this type are allocated with a trailing array of
4294 /// TemplateArguments, followed by a QualType representing the
4295 /// non-canonical aliased type when the template is a type alias
4296 /// template.
4297 class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) TemplateSpecializationType
4298  : public Type,
4299  public llvm::FoldingSetNode {
4300  /// The name of the template being specialized. This is
4301  /// either a TemplateName::Template (in which case it is a
4302  /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a
4303  /// TypeAliasTemplateDecl*), a
4304  /// TemplateName::SubstTemplateTemplateParmPack, or a
4305  /// TemplateName::SubstTemplateTemplateParm (in which case the
4306  /// replacement must, recursively, be one of these).
4307  TemplateName Template;
4308 
4309  /// The number of template arguments named in this class template
4310  /// specialization.
4311  unsigned NumArgs : 31;
4312 
4313  /// Whether this template specialization type is a substituted type alias.
4314  unsigned TypeAlias : 1;
4315 
4318  QualType Canon,
4319  QualType Aliased);
4320 
4321  friend class ASTContext; // ASTContext creates these
4322 
4323 public:
4324  /// Determine whether any of the given template arguments are dependent.
4325  static bool anyDependentTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
4326  bool &InstantiationDependent);
4327 
4328  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &,
4329  bool &InstantiationDependent);
4330 
4331  /// \brief Print a template argument list, including the '<' and '>'
4332  /// enclosing the template arguments.
4333  static void PrintTemplateArgumentList(raw_ostream &OS,
4335  const PrintingPolicy &Policy,
4336  bool SkipBrackets = false);
4337 
4338  static void PrintTemplateArgumentList(raw_ostream &OS,
4340  const PrintingPolicy &Policy);
4341 
4342  static void PrintTemplateArgumentList(raw_ostream &OS,
4343  const TemplateArgumentListInfo &,
4344  const PrintingPolicy &Policy);
4345 
4346  /// True if this template specialization type matches a current
4347  /// instantiation in the context in which it is found.
4348  bool isCurrentInstantiation() const {
4349  return isa<InjectedClassNameType>(getCanonicalTypeInternal());
4350  }
4351 
4352  /// \brief Determine if this template specialization type is for a type alias
4353  /// template that has been substituted.
4354  ///
4355  /// Nearly every template specialization type whose template is an alias
4356  /// template will be substituted. However, this is not the case when
4357  /// the specialization contains a pack expansion but the template alias
4358  /// does not have a corresponding parameter pack, e.g.,
4359  ///
4360  /// \code
4361  /// template<typename T, typename U, typename V> struct S;
4362  /// template<typename T, typename U> using A = S<T, int, U>;
4363  /// template<typename... Ts> struct X {
4364  /// typedef A<Ts...> type; // not a type alias
4365  /// };
4366  /// \endcode
4367  bool isTypeAlias() const { return TypeAlias; }
4368 
4369  /// Get the aliased type, if this is a specialization of a type alias
4370  /// template.
4372  assert(isTypeAlias() && "not a type alias template specialization");
4373  return *reinterpret_cast<const QualType*>(end());
4374  }
4375 
4376  typedef const TemplateArgument * iterator;
4377 
4378  iterator begin() const { return getArgs(); }
4379  iterator end() const; // defined inline in TemplateBase.h
4380 
4381  /// Retrieve the name of the template that we are specializing.
4382  TemplateName getTemplateName() const { return Template; }
4383 
4384  /// Retrieve the template arguments.
4385  const TemplateArgument *getArgs() const {
4386  return reinterpret_cast<const TemplateArgument *>(this + 1);
4387  }
4388 
4389  /// Retrieve the number of template arguments.
4390  unsigned getNumArgs() const { return NumArgs; }
4391 
4392  /// Retrieve a specific template argument as a type.
4393  /// \pre \c isArgType(Arg)
4394  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
4395 
4397  return {getArgs(), NumArgs};
4398  }
4399 
4400  bool isSugared() const {
4401  return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
4402  }
4404 
4405  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
4406  Profile(ID, Template, template_arguments(), Ctx);
4407  if (isTypeAlias())
4408  getAliasedType().Profile(ID);
4409  }
4410 
4411  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
4413  const ASTContext &Context);
4414 
4415  static bool classof(const Type *T) {
4416  return T->getTypeClass() == TemplateSpecialization;
4417  }
4418 };
4419 
4420 /// The injected class name of a C++ class template or class
4421 /// template partial specialization. Used to record that a type was
4422 /// spelled with a bare identifier rather than as a template-id; the
4423 /// equivalent for non-templated classes is just RecordType.
4424 ///
4425 /// Injected class name types are always dependent. Template
4426 /// instantiation turns these into RecordTypes.
4427 ///
4428 /// Injected class name types are always canonical. This works
4429 /// because it is impossible to compare an injected class name type
4430 /// with the corresponding non-injected template type, for the same
4431 /// reason that it is impossible to directly compare template
4432 /// parameters from different dependent contexts: injected class name
4433 /// types can only occur within the scope of a particular templated
4434 /// declaration, and within that scope every template specialization
4435 /// will canonicalize to the injected class name (when appropriate
4436 /// according to the rules of the language).
4437 class InjectedClassNameType : public Type {
4439 
4440  /// The template specialization which this type represents.
4441  /// For example, in
4442  /// template <class T> class A { ... };
4443  /// this is A<T>, whereas in
4444  /// template <class X, class Y> class A<B<X,Y> > { ... };
4445  /// this is A<B<X,Y> >.
4446  ///
4447  /// It is always unqualified, always a template specialization type,
4448  /// and always dependent.
4449  QualType InjectedType;
4450 
4451  friend class ASTContext; // ASTContext creates these.
4452  friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
4453  // currently suitable for AST reading, too much
4454  // interdependencies.
4455  friend class ASTNodeImporter;
4456 
4458  : Type(InjectedClassName, QualType(), /*Dependent=*/true,
4459  /*InstantiationDependent=*/true,
4460  /*VariablyModified=*/false,
4461  /*ContainsUnexpandedParameterPack=*/false),
4462  Decl(D), InjectedType(TST) {
4463  assert(isa<TemplateSpecializationType>(TST));
4464  assert(!TST.hasQualifiers());
4465  assert(TST->isDependentType());
4466  }
4467 
4468 public:
4469  QualType getInjectedSpecializationType() const { return InjectedType; }
4471  return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
4472  }
4474  return getInjectedTST()->getTemplateName();
4475  }
4476 
4477  CXXRecordDecl *getDecl() const;
4478 
4479  bool isSugared() const { return false; }
4480  QualType desugar() const { return QualType(this, 0); }
4481 
4482  static bool classof(const Type *T) {
4483  return T->getTypeClass() == InjectedClassName;
4484  }
4485 };
4486 
4487 /// \brief The kind of a tag type.
4489  /// \brief The "struct" keyword.
4491  /// \brief The "__interface" keyword.
4493  /// \brief The "union" keyword.
4495  /// \brief The "class" keyword.
4497  /// \brief The "enum" keyword.
4499 };
4500 
4501 /// \brief The elaboration keyword that precedes a qualified type name or
4502 /// introduces an elaborated-type-specifier.
4504  /// \brief The "struct" keyword introduces the elaborated-type-specifier.
4506  /// \brief The "__interface" keyword introduces the elaborated-type-specifier.
4508  /// \brief The "union" keyword introduces the elaborated-type-specifier.
4510  /// \brief The "class" keyword introduces the elaborated-type-specifier.
4512  /// \brief The "enum" keyword introduces the elaborated-type-specifier.
4514  /// \brief The "typename" keyword precedes the qualified type name, e.g.,
4515  /// \c typename T::type.
4517  /// \brief No keyword precedes the qualified type name.
4519 };
4520 
4521 /// A helper class for Type nodes having an ElaboratedTypeKeyword.
4522 /// The keyword in stored in the free bits of the base class.
4523 /// Also provides a few static helpers for converting and printing
4524 /// elaborated type keyword and tag type kind enumerations.
4525 class TypeWithKeyword : public Type {
4526 protected:
4528  QualType Canonical, bool Dependent,
4529  bool InstantiationDependent, bool VariablyModified,
4530  bool ContainsUnexpandedParameterPack)
4531  : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
4532  ContainsUnexpandedParameterPack) {
4533  TypeWithKeywordBits.Keyword = Keyword;
4534  }
4535 
4536 public:
4538  return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
4539  }
4540 
4541  /// Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
4542  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
4543 
4544  /// Converts a type specifier (DeclSpec::TST) into a tag type kind.
4545  /// It is an error to provide a type specifier which *isn't* a tag kind here.
4546  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
4547 
4548  /// Converts a TagTypeKind into an elaborated type keyword.
4549  static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
4550 
4551  /// Converts an elaborated type keyword into a TagTypeKind.
4552  /// It is an error to provide an elaborated type keyword
4553  /// which *isn't* a tag kind here.
4554  static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
4555 
4556  static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
4557 
4558  static StringRef getKeywordName(ElaboratedTypeKeyword Keyword);
4559 
4561  return getKeywordName(getKeywordForTagTypeKind(Kind));
4562  }
4563 
4565  static CannotCastToThisType classof(const Type *);
4566 };
4567 
4568 /// \brief Represents a type that was referred to using an elaborated type
4569 /// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
4570 /// or both.
4571 ///
4572 /// This type is used to keep track of a type name as written in the
4573 /// source code, including tag keywords and any nested-name-specifiers.
4574 /// The type itself is always "sugar", used to express what was written
4575 /// in the source code but containing no additional semantic information.
4576 class ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode {
4577 
4578  /// The nested name specifier containing the qualifier.
4579  NestedNameSpecifier *NNS;
4580 
4581  /// The type that this qualified name refers to.
4582  QualType NamedType;
4583 
4585  QualType NamedType, QualType CanonType)
4586  : TypeWithKeyword(Keyword, Elaborated, CanonType,
4587  NamedType->isDependentType(),
4588  NamedType->isInstantiationDependentType(),
4589  NamedType->isVariablyModifiedType(),
4590  NamedType->containsUnexpandedParameterPack()),
4591  NNS(NNS), NamedType(NamedType) {
4592  assert(!(Keyword == ETK_None && NNS == nullptr) &&
4593  "ElaboratedType cannot have elaborated type keyword "
4594  "and name qualifier both null.");
4595  }
4596 
4597  friend class ASTContext; // ASTContext creates these
4598 
4599 public:
4600  ~ElaboratedType();
4601 
4602  /// Retrieve the qualification on this type.
4603  NestedNameSpecifier *getQualifier() const { return NNS; }
4604 
4605  /// Retrieve the type named by the qualified-id.
4606  QualType getNamedType() const { return NamedType; }
4607 
4608  /// Remove a single level of sugar.
4609  QualType desugar() const { return getNamedType(); }
4610 
4611  /// Returns whether this type directly provides sugar.
4612  bool isSugared() const { return true; }
4613 
4614  void Profile(llvm::FoldingSetNodeID &ID) {
4615  Profile(ID, getKeyword(), NNS, NamedType);
4616  }
4617 
4618  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
4619  NestedNameSpecifier *NNS, QualType NamedType) {
4620  ID.AddInteger(Keyword);
4621  ID.AddPointer(NNS);
4622  NamedType.Profile(ID);
4623  }
4624 
4625  static bool classof(const Type *T) {
4626  return T->getTypeClass() == Elaborated;
4627  }
4628 };
4629 
4630 /// \brief Represents a qualified type name for which the type name is
4631 /// dependent.
4632 ///
4633 /// DependentNameType represents a class of dependent types that involve a
4634 /// possibly dependent nested-name-specifier (e.g., "T::") followed by a
4635 /// name of a type. The DependentNameType may start with a "typename" (for a
4636 /// typename-specifier), "class", "struct", "union", or "enum" (for a
4637 /// dependent elaborated-type-specifier), or nothing (in contexts where we
4638 /// know that we must be referring to a type, e.g., in a base class specifier).
4639 /// Typically the nested-name-specifier is dependent, but in MSVC compatibility
4640 /// mode, this type is used with non-dependent names to delay name lookup until
4641 /// instantiation.
4642 class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
4643 
4644  /// \brief The nested name specifier containing the qualifier.
4645  NestedNameSpecifier *NNS;
4646 
4647  /// \brief The type that this typename specifier refers to.
4648  const IdentifierInfo *Name;
4649 
4651  const IdentifierInfo *Name, QualType CanonType)
4652  : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true,
4653  /*InstantiationDependent=*/true,
4654  /*VariablyModified=*/false,
4656  NNS(NNS), Name(Name) {}
4657 
4658  friend class ASTContext; // ASTContext creates these
4659 
4660 public:
4661  /// Retrieve the qualification on this type.
4662  NestedNameSpecifier *getQualifier() const { return NNS; }
4663 
4664  /// Retrieve the type named by the typename specifier as an identifier.
4665  ///
4666  /// This routine will return a non-NULL identifier pointer when the
4667  /// form of the original typename was terminated by an identifier,
4668  /// e.g., "typename T::type".
4670  return Name;
4671  }
4672 
4673  bool isSugared() const { return false; }
4674  QualType desugar() const { return QualType(this, 0); }
4675 
4676  void Profile(llvm::FoldingSetNodeID &ID) {
4677  Profile(ID, getKeyword(), NNS, Name);
4678  }
4679 
4680  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
4681  NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
4682  ID.AddInteger(Keyword);
4683  ID.AddPointer(NNS);
4684  ID.AddPointer(Name);
4685  }
4686 
4687  static bool classof(const Type *T) {
4688  return T->getTypeClass() == DependentName;
4689  }
4690 };
4691 
4692 /// Represents a template specialization type whose template cannot be
4693 /// resolved, e.g.
4694 /// A<T>::template B<T>
4695 class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) DependentTemplateSpecializationType
4696  : public TypeWithKeyword,
4697  public llvm::FoldingSetNode {
4698 
4699  /// The nested name specifier containing the qualifier.
4700  NestedNameSpecifier *NNS;
4701 
4702  /// The identifier of the template.
4703  const IdentifierInfo *Name;
4704 
4705  /// \brief The number of template arguments named in this class template
4706  /// specialization.
4707  unsigned NumArgs;
4708 
4709  const TemplateArgument *getArgBuffer() const {
4710  return reinterpret_cast<const TemplateArgument*>(this+1);
4711  }
4712  TemplateArgument *getArgBuffer() {
4713  return reinterpret_cast<TemplateArgument*>(this+1);
4714  }
4715 
4717  NestedNameSpecifier *NNS,
4718  const IdentifierInfo *Name,
4720  QualType Canon);
4721 
4722  friend class ASTContext; // ASTContext creates these
4723 
4724 public:
4725  NestedNameSpecifier *getQualifier() const { return NNS; }
4726  const IdentifierInfo *getIdentifier() const { return Name; }
4727 
4728  /// \brief Retrieve the template arguments.
4729  const TemplateArgument *getArgs() const {
4730  return getArgBuffer();
4731  }
4732 
4733  /// \brief Retrieve the number of template arguments.
4734  unsigned getNumArgs() const { return NumArgs; }
4735 
4736  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
4737 
4739  return {getArgs(), NumArgs};
4740  }
4741 
4742  typedef const TemplateArgument * iterator;
4743  iterator begin() const { return getArgs(); }
4744  iterator end() const; // inline in TemplateBase.h
4745 
4746  bool isSugared() const { return false; }
4747  QualType desugar() const { return QualType(this, 0); }
4748 
4749  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
4750  Profile(ID, Context, getKeyword(), NNS, Name, {getArgs(), NumArgs});
4751  }
4752 
4753  static void Profile(llvm::FoldingSetNodeID &ID,
4754  const ASTContext &Context,
4755  ElaboratedTypeKeyword Keyword,
4756  NestedNameSpecifier *Qualifier,
4757  const IdentifierInfo *Name,
4759 
4760  static bool classof(const Type *T) {
4761  return T->getTypeClass() == DependentTemplateSpecialization;
4762  }
4763 };
4764 
4765 /// \brief Represents a pack expansion of types.
4766 ///
4767 /// Pack expansions are part of C++11 variadic templates. A pack
4768 /// expansion contains a pattern, which itself contains one or more
4769 /// "unexpanded" parameter packs. When instantiated, a pack expansion
4770 /// produces a series of types, each instantiated from the pattern of
4771 /// the expansion, where the Ith instantiation of the pattern uses the
4772 /// Ith arguments bound to each of the unexpanded parameter packs. The
4773 /// pack expansion is considered to "expand" these unexpanded
4774 /// parameter packs.
4775 ///
4776 /// \code
4777 /// template<typename ...Types> struct tuple;
4778 ///
4779 /// template<typename ...Types>
4780 /// struct tuple_of_references {
4781 /// typedef tuple<Types&...> type;
4782 /// };
4783 /// \endcode
4784 ///
4785 /// Here, the pack expansion \c Types&... is represented via a
4786 /// PackExpansionType whose pattern is Types&.
4787 class PackExpansionType : public Type, public llvm::FoldingSetNode {
4788  /// \brief The pattern of the pack expansion.
4789  QualType Pattern;
4790 
4791  /// \brief The number of expansions that this pack expansion will
4792  /// generate when substituted (+1), or indicates that
4793  ///
4794  /// This field will only have a non-zero value when some of the parameter
4795  /// packs that occur within the pattern have been substituted but others have
4796  /// not.
4797  unsigned NumExpansions;
4798 
4799  PackExpansionType(QualType Pattern, QualType Canon,
4800  Optional<unsigned> NumExpansions)
4801  : Type(PackExpansion, Canon, /*Dependent=*/Pattern->isDependentType(),
4802  /*InstantiationDependent=*/true,
4803  /*VariablyModified=*/Pattern->isVariablyModifiedType(),
4804  /*ContainsUnexpandedParameterPack=*/false),
4805  Pattern(Pattern),
4806  NumExpansions(NumExpansions? *NumExpansions + 1: 0) { }
4807 
4808  friend class ASTContext; // ASTContext creates these
4809 
4810 public:
4811  /// \brief Retrieve the pattern of this pack expansion, which is the
4812  /// type that will be repeatedly instantiated when instantiating the
4813  /// pack expansion itself.
4814  QualType getPattern() const { return Pattern; }
4815 
4816  /// \brief Retrieve the number of expansions that this pack expansion will
4817  /// generate, if known.
4819  if (NumExpansions)
4820  return NumExpansions - 1;
4821 
4822  return None;
4823  }
4824 
4825  bool isSugared() const { return !Pattern->isDependentType(); }
4826  QualType desugar() const { return isSugared() ? Pattern : QualType(this, 0); }
4827 
4828  void Profile(llvm::FoldingSetNodeID &ID) {
4829  Profile(ID, getPattern(), getNumExpansions());
4830  }
4831 
4832  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern,
4833  Optional<unsigned> NumExpansions) {
4834  ID.AddPointer(Pattern.getAsOpaquePtr());
4835  ID.AddBoolean(NumExpansions.hasValue());
4836  if (NumExpansions)
4837  ID.AddInteger(*NumExpansions);
4838  }
4839 
4840  static bool classof(const Type *T) {
4841  return T->getTypeClass() == PackExpansion;
4842  }
4843 };
4844 
4845 /// This class wraps the list of protocol qualifiers. For types that can
4846 /// take ObjC protocol qualifers, they can subclass this class.
4847 template <class T>
4849 protected:
4852  return const_cast<ObjCProtocolQualifiers*>(this)->getProtocolStorage();
4853  }
4854 
4856  return static_cast<T*>(this)->getProtocolStorageImpl();
4857  }
4858  void setNumProtocols(unsigned N) {
4859  static_cast<T*>(this)->setNumProtocolsImpl(N);
4860  }
4862  setNumProtocols(protocols.size());
4863  assert(getNumProtocols() == protocols.size() &&
4864  "bitfield overflow in protocol count");
4865  if (!protocols.empty())
4866  memcpy(getProtocolStorage(), protocols.data(),
4867  protocols.size() * sizeof(ObjCProtocolDecl*));
4868  }
4869 
4870 public:
4872  typedef llvm::iterator_range<qual_iterator> qual_range;
4873 
4874  qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
4875  qual_iterator qual_begin() const { return getProtocolStorage(); }
4876  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
4877 
4878  bool qual_empty() const { return getNumProtocols() == 0; }
4879 
4880  /// Return the number of qualifying protocols in this type, or 0 if
4881  /// there are none.
4882  unsigned getNumProtocols() const {
4883  return static_cast<const T*>(this)->getNumProtocolsImpl();
4884  }
4885 
4886  /// Fetch a protocol by index.
4887  ObjCProtocolDecl *getProtocol(unsigned I) const {
4888  assert(I < getNumProtocols() && "Out-of-range protocol access");
4889  return qual_begin()[I];
4890  }
4891 
4892  /// Retrieve all of the protocol qualifiers.
4894  return ArrayRef<ObjCProtocolDecl *>(qual_begin(), getNumProtocols());
4895  }
4896 };
4897 
4898 /// Represents a type parameter type in Objective C. It can take
4899 /// a list of protocols.
4900 class ObjCTypeParamType : public Type,
4901  public ObjCProtocolQualifiers<ObjCTypeParamType>,
4902  public llvm::FoldingSetNode {
4903  friend class ASTContext;
4905 
4906  /// The number of protocols stored on this type.
4907  unsigned NumProtocols : 6;
4908 
4909  ObjCTypeParamDecl *OTPDecl;
4910  /// The protocols are stored after the ObjCTypeParamType node. In the
4911  /// canonical type, the list of protocols are sorted alphabetically
4912  /// and uniqued.
4913  ObjCProtocolDecl **getProtocolStorageImpl();
4914  /// Return the number of qualifying protocols in this interface type,
4915  /// or 0 if there are none.
4916  unsigned getNumProtocolsImpl() const {
4917  return NumProtocols;
4918  }
4919  void setNumProtocolsImpl(unsigned N) {
4920  NumProtocols = N;
4921  }
4922  ObjCTypeParamType(const ObjCTypeParamDecl *D,
4923  QualType can,
4924  ArrayRef<ObjCProtocolDecl *> protocols);
4925 public:
4926  bool isSugared() const { return true; }
4928 
4929  static bool classof(const Type *T) {
4930  return T->getTypeClass() == ObjCTypeParam;
4931  }
4932 
4933  void Profile(llvm::FoldingSetNodeID &ID);
4934  static void Profile(llvm::FoldingSetNodeID &ID,
4935  const ObjCTypeParamDecl *OTPDecl,
4936  ArrayRef<ObjCProtocolDecl *> protocols);
4937 
4938  ObjCTypeParamDecl *getDecl() const { return OTPDecl; }
4939 };
4940 
4941 /// Represents a class type in Objective C.
4942 ///
4943 /// Every Objective C type is a combination of a base type, a set of
4944 /// type arguments (optional, for parameterized classes) and a list of
4945 /// protocols.
4946 ///
4947 /// Given the following declarations:
4948 /// \code
4949 /// \@class C<T>;
4950 /// \@protocol P;
4951 /// \endcode
4952 ///
4953 /// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType
4954 /// with base C and no protocols.
4955 ///
4956 /// 'C<P>' is an unspecialized ObjCObjectType with base C and protocol list [P].
4957 /// 'C<C*>' is a specialized ObjCObjectType with type arguments 'C*' and no
4958 /// protocol list.
4959 /// 'C<C*><P>' is a specialized ObjCObjectType with base C, type arguments 'C*',
4960 /// and protocol list [P].
4961 ///
4962 /// 'id' is a TypedefType which is sugar for an ObjCObjectPointerType whose
4963 /// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
4964 /// and no protocols.
4965 ///
4966 /// 'id<P>' is an ObjCObjectPointerType whose pointee is an ObjCObjectType
4967 /// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually
4968 /// this should get its own sugar class to better represent the source.
4969 class ObjCObjectType : public Type,
4970  public ObjCProtocolQualifiers<ObjCObjectType> {
4972  // ObjCObjectType.NumTypeArgs - the number of type arguments stored
4973  // after the ObjCObjectPointerType node.
4974  // ObjCObjectType.NumProtocols - the number of protocols stored
4975  // after the type arguments of ObjCObjectPointerType node.
4976  //
4977  // These protocols are those written directly on the type. If
4978  // protocol qualifiers ever become additive, the iterators will need
4979  // to get kindof complicated.
4980  //
4981  // In the canonical object type, these are sorted alphabetically
4982  // and uniqued.
4983 
4984  /// Either a BuiltinType or an InterfaceType or sugar for either.
4985  QualType BaseType;
4986 
4987  /// Cached superclass type.
4988  mutable llvm::PointerIntPair<const ObjCObjectType *, 1, bool>
4989  CachedSuperClassType;
4990 
4991  QualType *getTypeArgStorage();
4992  const QualType *getTypeArgStorage() const {
4993  return const_cast<ObjCObjectType *>(this)->getTypeArgStorage();
4994  }
4995 
4996  ObjCProtocolDecl **getProtocolStorageImpl();
4997  /// Return the number of qualifying protocols in this interface type,
4998  /// or 0 if there are none.
4999  unsigned getNumProtocolsImpl() const {
5000  return ObjCObjectTypeBits.NumProtocols;
5001  }
5002  void setNumProtocolsImpl(unsigned N) {
5003  ObjCObjectTypeBits.NumProtocols = N;
5004  }
5005 
5006 protected:
5007  ObjCObjectType(QualType Canonical, QualType Base,
5008  ArrayRef<QualType> typeArgs,
5009  ArrayRef<ObjCProtocolDecl *> protocols,
5010  bool isKindOf);
5011 
5014  : Type(ObjCInterface, QualType(), false, false, false, false),
5015  BaseType(QualType(this_(), 0)) {
5016  ObjCObjectTypeBits.NumProtocols = 0;
5017  ObjCObjectTypeBits.NumTypeArgs = 0;
5018  ObjCObjectTypeBits.IsKindOf = 0;
5019  }
5020 
5021  void computeSuperClassTypeSlow() const;
5022 
5023 public:
5024  /// Gets the base type of this object type. This is always (possibly
5025  /// sugar for) one of:
5026  /// - the 'id' builtin type (as opposed to the 'id' type visible to the
5027  /// user, which is a typedef for an ObjCObjectPointerType)
5028  /// - the 'Class' builtin type (same caveat)
5029  /// - an ObjCObjectType (currently always an ObjCInterfaceType)
5030  QualType getBaseType() const { return BaseType; }
5031 
5032  bool isObjCId() const {
5033  return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
5034  }
5035  bool isObjCClass() const {
5036  return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
5037  }
5038  bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
5039  bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
5041  if (!qual_empty()) return false;
5042  if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
5043  return T->getKind() == BuiltinType::ObjCId ||
5044  T->getKind() == BuiltinType::ObjCClass;
5045  return false;
5046  }
5047  bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
5048  bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
5049 
5050  /// Gets the interface declaration for this object type, if the base type
5051  /// really is an interface.
5052  ObjCInterfaceDecl *getInterface() const;
5053 
5054  /// Determine whether this object type is "specialized", meaning
5055  /// that it has type arguments.
5056  bool isSpecialized() const;
5057 
5058  /// Determine whether this object type was written with type arguments.
5059  bool isSpecializedAsWritten() const {
5060  return ObjCObjectTypeBits.NumTypeArgs > 0;
5061  }
5062 
5063  /// Determine whether this object type is "unspecialized", meaning
5064  /// that it has no type arguments.
5065  bool isUnspecialized() const { return !isSpecialized(); }
5066 
5067  /// Determine whether this object type is "unspecialized" as
5068  /// written, meaning that it has no type arguments.
5069  bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); }
5070 
5071  /// Retrieve the type arguments of this object type (semantically).
5072  ArrayRef<QualType> getTypeArgs() const;
5073 
5074  /// Retrieve the type arguments of this object type as they were
5075  /// written.
5077  return llvm::makeArrayRef(getTypeArgStorage(),
5078  ObjCObjectTypeBits.NumTypeArgs);
5079  }
5080 
5081  /// Whether this is a "__kindof" type as written.
5082  bool isKindOfTypeAsWritten() const { return ObjCObjectTypeBits.IsKindOf; }
5083 
5084  /// Whether this ia a "__kindof" type (semantically).
5085  bool isKindOfType() const;
5086 
5087  /// Retrieve the type of the superclass of this object type.
5088  ///
5089  /// This operation substitutes any type arguments into the
5090  /// superclass of the current class type, potentially producing a
5091  /// specialization of the superclass type. Produces a null type if
5092  /// there is no superclass.
5094  if (!CachedSuperClassType.getInt())
5095  computeSuperClassTypeSlow();
5096 
5097  assert(CachedSuperClassType.getInt() && "Superclass not set?");
5098  return QualType(CachedSuperClassType.getPointer(), 0);
5099  }
5100 
5101  /// Strip off the Objective-C "kindof" type and (with it) any
5102  /// protocol qualifiers.
5103  QualType stripObjCKindOfTypeAndQuals(const ASTContext &ctx) const;
5104 
5105  bool isSugared() const { return false; }
5106  QualType desugar() const { return QualType(this, 0); }
5107 
5108  static bool classof(const Type *T) {
5109  return T->getTypeClass() == ObjCObject ||
5110  T->getTypeClass() == ObjCInterface;
5111  }
5112 };
5113 
5114 /// A class providing a concrete implementation
5115 /// of ObjCObjectType, so as to not increase the footprint of
5116 /// ObjCInterfaceType. Code outside of ASTContext and the core type
5117 /// system should not reference this type.
5118 class ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
5119  friend class ASTContext;
5120 
5121  // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
5122  // will need to be modified.
5123 
5125  ArrayRef<QualType> typeArgs,
5126  ArrayRef<ObjCProtocolDecl *> protocols,
5127  bool isKindOf)
5128  : ObjCObjectType(Canonical, Base, typeArgs, protocols, isKindOf) {}
5129 
5130 public:
5131  void Profile(llvm::FoldingSetNodeID &ID);
5132  static void Profile(llvm::FoldingSetNodeID &ID,
5133  QualType Base,
5134  ArrayRef<QualType> typeArgs,
5135  ArrayRef<ObjCProtocolDecl *> protocols,
5136  bool isKindOf);
5137 };
5138 
5139 inline QualType *ObjCObjectType::getTypeArgStorage() {
5140  return reinterpret_cast<QualType *>(static_cast<ObjCObjectTypeImpl*>(this)+1);
5141 }
5142 
5143 inline ObjCProtocolDecl **ObjCObjectType::getProtocolStorageImpl() {
5144  return reinterpret_cast<ObjCProtocolDecl**>(
5145  getTypeArgStorage() + ObjCObjectTypeBits.NumTypeArgs);
5146 }
5147 
5148 inline ObjCProtocolDecl **ObjCTypeParamType::getProtocolStorageImpl() {
5149  return reinterpret_cast<ObjCProtocolDecl**>(
5150  static_cast<ObjCTypeParamType*>(this)+1);
5151 }
5152 
5153 /// Interfaces are the core concept in Objective-C for object oriented design.
5154 /// They basically correspond to C++ classes. There are two kinds of interface
5155 /// types: normal interfaces like `NSString`, and qualified interfaces, which
5156 /// are qualified with a protocol list like `NSString<NSCopyable, NSAmazing>`.
5157 ///
5158 /// ObjCInterfaceType guarantees the following properties when considered
5159 /// as a subtype of its superclass, ObjCObjectType:
5160 /// - There are no protocol qualifiers. To reinforce this, code which
5161 /// tries to invoke the protocol methods via an ObjCInterfaceType will
5162 /// fail to compile.
5163 /// - It is its own base type. That is, if T is an ObjCInterfaceType*,
5164 /// T->getBaseType() == QualType(T, 0).
5166  mutable ObjCInterfaceDecl *Decl;
5167 
5170  Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
5171  friend class ASTContext; // ASTContext creates these.
5172  friend class ASTReader;
5173  friend class ObjCInterfaceDecl;
5174 
5175 public:
5176  /// Get the declaration of this interface.
5177  ObjCInterfaceDecl *getDecl() const { return Decl; }
5178 
5179  bool isSugared() const { return false; }
5180  QualType desugar() const { return QualType(this, 0); }
5181 
5182  static bool classof(const Type *T) {
5183  return T->getTypeClass() == ObjCInterface;
5184  }
5185 
5186  // Nonsense to "hide" certain members of ObjCObjectType within this
5187  // class. People asking for protocols on an ObjCInterfaceType are
5188  // not going to get what they want: ObjCInterfaceTypes are
5189  // guaranteed to have no protocols.
5190  enum {
5195  getProtocol
5196  };
5197 };
5198 
5200  QualType baseType = getBaseType();
5201  while (const ObjCObjectType *ObjT = baseType->getAs<ObjCObjectType>()) {
5202  if (const ObjCInterfaceType *T = dyn_cast<ObjCInterfaceType>(ObjT))
5203  return T->getDecl();
5204 
5205  baseType = ObjT->getBaseType();
5206  }
5207 
5208  return nullptr;
5209 }
5210 
5211 /// Represents a pointer to an Objective C object.
5212 ///
5213 /// These are constructed from pointer declarators when the pointee type is
5214 /// an ObjCObjectType (or sugar for one). In addition, the 'id' and 'Class'
5215 /// types are typedefs for these, and the protocol-qualified types 'id<P>'
5216 /// and 'Class<P>' are translated into these.
5217 ///
5218 /// Pointers to pointers to Objective C objects are still PointerTypes;
5219 /// only the first level of pointer gets it own type implementation.
5220 class ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
5221  QualType PointeeType;
5222 
5223  ObjCObjectPointerType(QualType Canonical, QualType Pointee)
5224  : Type(ObjCObjectPointer, Canonical,
5225  Pointee->isDependentType(),
5226  Pointee->isInstantiationDependentType(),
5227  Pointee->isVariablyModifiedType(),
5228  Pointee->containsUnexpandedParameterPack()),
5229  PointeeType(Pointee) {}
5230  friend class ASTContext; // ASTContext creates these.
5231 
5232 public:
5233  /// Gets the type pointed to by this ObjC pointer.
5234  /// The result will always be an ObjCObjectType or sugar thereof.
5235  QualType getPointeeType() const { return PointeeType; }
5236 
5237  /// Gets the type pointed to by this ObjC pointer. Always returns non-null.
5238  ///
5239  /// This method is equivalent to getPointeeType() except that
5240  /// it discards any typedefs (or other sugar) between this
5241  /// type and the "outermost" object type. So for:
5242  /// \code
5243  /// \@class A; \@protocol P; \@protocol Q;
5244  /// typedef A<P> AP;
5245  /// typedef A A1;
5246  /// typedef A1<P> A1P;
5247  /// typedef A1P<Q> A1PQ;
5248  /// \endcode
5249  /// For 'A*', getObjectType() will return 'A'.
5250  /// For 'A<P>*', getObjectType() will return 'A<P>'.
5251  /// For 'AP*', getObjectType() will return 'A<P>'.
5252  /// For 'A1*', getObjectType() will return 'A'.
5253  /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
5254  /// For 'A1P*', getObjectType() will return 'A1<P>'.
5255  /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
5256  /// adding protocols to a protocol-qualified base discards the
5257  /// old qualifiers (for now). But if it didn't, getObjectType()
5258  /// would return 'A1P<Q>' (and we'd have to make iterating over
5259  /// qualifiers more complicated).
5261  return PointeeType->castAs<ObjCObjectType>();
5262  }
5263 
5264  /// If this pointer points to an Objective C
5265  /// \@interface type, gets the type for that interface. Any protocol
5266  /// qualifiers on the interface are ignored.
5267  ///
5268  /// \return null if the base type for this pointer is 'id' or 'Class'
5269  const ObjCInterfaceType *getInterfaceType() const;
5270 
5271  /// If this pointer points to an Objective \@interface
5272  /// type, gets the declaration for that interface.
5273  ///
5274  /// \return null if the base type for this pointer is 'id' or 'Class'
5276  return getObjectType()->getInterface();
5277  }
5278 
5279  /// True if this is equivalent to the 'id' type, i.e. if
5280  /// its object type is the primitive 'id' type with no protocols.
5281  bool isObjCIdType() const {
5282  return getObjectType()->isObjCUnqualifiedId();
5283  }
5284 
5285  /// True if this is equivalent to the 'Class' type,
5286  /// i.e. if its object tive is the primitive 'Class' type with no protocols.
5287  bool isObjCClassType() const {
5288  return getObjectType()->isObjCUnqualifiedClass();
5289  }
5290 
5291  /// True if this is equivalent to the 'id' or 'Class' type,
5292  bool isObjCIdOrClassType() const {
5293  return getObjectType()->isObjCUnqualifiedIdOrClass();
5294  }
5295 
5296  /// True if this is equivalent to 'id<P>' for some non-empty set of
5297  /// protocols.
5298  bool isObjCQualifiedIdType() const {
5299  return getObjectType()->isObjCQualifiedId();
5300  }
5301 
5302  /// True if this is equivalent to 'Class<P>' for some non-empty set of
5303  /// protocols.
5305  return getObjectType()->isObjCQualifiedClass();
5306  }
5307 
5308  /// Whether this is a "__kindof" type.
5309  bool isKindOfType() const { return getObjectType()->isKindOfType(); }
5310 
5311  /// Whether this type is specialized, meaning that it has type arguments.
5312  bool isSpecialized() const { return getObjectType()->isSpecialized(); }
5313 
5314  /// Whether this type is specialized, meaning that it has type arguments.
5315  bool isSpecializedAsWritten() const {
5316  return getObjectType()->isSpecializedAsWritten();
5317  }
5318 
5319  /// Whether this type is unspecialized, meaning that is has no type arguments.
5320  bool isUnspecialized() const { return getObjectType()->isUnspecialized(); }
5321 
5322  /// Determine whether this object type is "unspecialized" as
5323  /// written, meaning that it has no type arguments.
5324  bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); }
5325 
5326  /// Retrieve the type arguments for this type.
5328  return getObjectType()->getTypeArgs();
5329  }
5330 
5331  /// Retrieve the type arguments for this type.
5333  return getObjectType()->getTypeArgsAsWritten();
5334  }
5335 
5336  /// An iterator over the qualifiers on the object type. Provided
5337  /// for convenience. This will always iterate over the full set of
5338  /// protocols on a type, not just those provided directly.
5340  typedef llvm::iterator_range<qual_iterator> qual_range;
5341 
5342  qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
5344  return getObjectType()->qual_begin();
5345  }
5347  return getObjectType()->qual_end();
5348  }
5349  bool qual_empty() const { return getObjectType()->qual_empty(); }
5350 
5351  /// Return the number of qualifying protocols on the object type.
5352  unsigned getNumProtocols() const {
5353  return getObjectType()->getNumProtocols();
5354  }
5355 
5356  /// Retrieve a qualifying protocol by index on the object type.
5357  ObjCProtocolDecl *getProtocol(unsigned I) const {
5358  return getObjectType()->getProtocol(I);
5359  }
5360 
5361  bool isSugared() const { return false; }
5362  QualType desugar() const { return QualType(this, 0); }
5363 
5364  /// Retrieve the type of the superclass of this object pointer type.
5365  ///
5366  /// This operation substitutes any type arguments into the
5367  /// superclass of the current class type, potentially producing a
5368  /// pointer to a specialization of the superclass type. Produces a
5369  /// null type if there is no superclass.
5370  QualType getSuperClassType() const;
5371 
5372  /// Strip off the Objective-C "kindof" type and (with it) any
5373  /// protocol qualifiers.
5374  const ObjCObjectPointerType *stripObjCKindOfTypeAndQuals(
5375  const ASTContext &ctx) const;
5376 
5377  void Profile(llvm::FoldingSetNodeID &ID) {
5378  Profile(ID, getPointeeType());
5379  }
5380  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
5381  ID.AddPointer(T.getAsOpaquePtr());
5382  }
5383  static bool classof(const Type *T) {
5384  return T->getTypeClass() == ObjCObjectPointer;
5385  }
5386 };
5387 
5388 class AtomicType : public Type, public llvm::FoldingSetNode {
5389  QualType ValueType;
5390 
5391  AtomicType(QualType ValTy, QualType Canonical)
5392  : Type(Atomic, Canonical, ValTy->isDependentType(),
5394  ValTy->isVariablyModifiedType(),
5396  ValueType(ValTy) {}
5397  friend class ASTContext; // ASTContext creates these.
5398 
5399  public:
5400  /// Gets the type contained by this atomic type, i.e.
5401  /// the type returned by performing an atomic load of this atomic type.
5402  QualType getValueType() const { return ValueType; }
5403 
5404  bool isSugared() const { return false; }
5405  QualType desugar() const { return QualType(this, 0); }
5406 
5407  void Profile(llvm::FoldingSetNodeID &ID) {
5408  Profile(ID, getValueType());
5409  }
5410  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
5411  ID.AddPointer(T.getAsOpaquePtr());
5412  }
5413  static bool classof(const Type *T) {
5414  return T->getTypeClass() == Atomic;
5415  }
5416 };
5417 
5418 /// PipeType - OpenCL20.
5419 class PipeType : public Type, public llvm::FoldingSetNode {
5420  QualType ElementType;
5421  bool isRead;
5422 
5423  PipeType(QualType elemType, QualType CanonicalPtr, bool isRead) :
5424  Type(Pipe, CanonicalPtr, elemType->isDependentType(),
5425  elemType->isInstantiationDependentType(),
5426  elemType->isVariablyModifiedType(),
5427  elemType->containsUnexpandedParameterPack()),
5428  ElementType(elemType), isRead(isRead) {}
5429  friend class ASTContext; // ASTContext creates these.
5430 
5431 public:
5432  QualType getElementType() const { return ElementType; }
5433 
5434  bool isSugared() const { return false; }
5435 
5436  QualType desugar() const { return QualType(this, 0); }
5437 
5438  void Profile(llvm::FoldingSetNodeID &ID) {
5439  Profile(ID, getElementType(), isReadOnly());
5440  }
5441 
5442  static void Profile(llvm::FoldingSetNodeID &ID, QualType T, bool isRead) {
5443  ID.AddPointer(T.getAsOpaquePtr());
5444  ID.AddBoolean(isRead);
5445  }
5446 
5447  static bool classof(const Type *T) {
5448  return T->getTypeClass() == Pipe;
5449  }
5450 
5451  bool isReadOnly() const { return isRead; }
5452 };
5453 
5454 /// A qualifier set is used to build a set of qualifiers.
5456 public:
5458 
5459  /// Collect any qualifiers on the given type and return an
5460  /// unqualified type. The qualifiers are assumed to be consistent
5461  /// with those already in the type.
5463  addFastQualifiers(type.getLocalFastQualifiers());
5464  if (!type.hasLocalNonFastQualifiers())
5465  return type.getTypePtrUnsafe();
5466 
5467  const ExtQuals *extQuals = type.getExtQualsUnsafe();
5468  addConsistentQualifiers(extQuals->getQualifiers());
5469  return extQuals->getBaseType();
5470  }
5471 
5472  /// Apply the collected qualifiers to the given type.
5473  QualType apply(const ASTContext &Context, QualType QT) const;
5474 
5475  /// Apply the collected qualifiers to the given type.
5476  QualType apply(const ASTContext &Context, const Type* T) const;
5477 };
5478 
5479 
5480 // Inline function definitions.
5481 
5483  SplitQualType desugar =
5484  Ty->getLocallyUnqualifiedSingleStepDesugaredType().split();
5485  desugar.Quals.addConsistentQualifiers(Quals);
5486  return desugar;
5487 }
5488 
5489 inline const Type *QualType::getTypePtr() const {
5490  return getCommonPtr()->BaseType;
5491 }
5492 
5493 inline const Type *QualType::getTypePtrOrNull() const {
5494  return (isNull() ? nullptr : getCommonPtr()->BaseType);
5495 }
5496 
5498  if (!hasLocalNonFastQualifiers())
5499  return SplitQualType(getTypePtrUnsafe(),
5500  Qualifiers::fromFastMask(getLocalFastQualifiers()));
5501 
5502  const ExtQuals *eq = getExtQualsUnsafe();
5503  Qualifiers qs = eq->getQualifiers();
5504  qs.addFastQualifiers(getLocalFastQualifiers());
5505  return SplitQualType(eq->getBaseType(), qs);
5506 }
5507 
5509  Qualifiers Quals;
5510  if (hasLocalNonFastQualifiers())
5511  Quals = getExtQualsUnsafe()->getQualifiers();
5512  Quals.addFastQualifiers(getLocalFastQualifiers());
5513  return Quals;
5514 }
5515 
5517  Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers();
5518  quals.addFastQualifiers(getLocalFastQualifiers());
5519  return quals;
5520 }
5521 
5522 inline unsigned QualType::getCVRQualifiers() const {
5523  unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers();
5524  cvr |= getLocalCVRQualifiers();
5525  return cvr;
5526 }
5527 
5529  QualType canon = getCommonPtr()->CanonicalType;
5530  return canon.withFastQualifiers(getLocalFastQualifiers());
5531 }
5532 
5533 inline bool QualType::isCanonical() const {
5534  return getTypePtr()->isCanonicalUnqualified();
5535 }
5536 
5537 inline bool QualType::isCanonicalAsParam() const {
5538  if (!isCanonical()) return false;
5539  if (hasLocalQualifiers()) return false;
5540 
5541  const Type *T = getTypePtr();
5542  if (T->isVariablyModifiedType() && T->hasSizedVLAType())
5543  return false;
5544 
5545  return !isa<FunctionType>(T) && !isa<ArrayType>(T);
5546 }
5547 
5548 inline bool QualType::isConstQualified() const {
5549  return isLocalConstQualified() ||
5550  getCommonPtr()->CanonicalType.isLocalConstQualified();
5551 }
5552 
5553 inline bool QualType::isRestrictQualified() const {
5554  return isLocalRestrictQualified() ||
5555  getCommonPtr()->CanonicalType.isLocalRestrictQualified();
5556 }
5557 
5558 
5559 inline bool QualType::isVolatileQualified() const {
5560  return isLocalVolatileQualified() ||
5561  getCommonPtr()->CanonicalType.isLocalVolatileQualified();
5562 }
5563 
5564 inline bool QualType::hasQualifiers() const {
5565  return hasLocalQualifiers() ||
5566  getCommonPtr()->CanonicalType.hasLocalQualifiers();
5567 }
5568 
5570  if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
5571  return QualType(getTypePtr(), 0);
5572 
5573  return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0);
5574 }
5575 
5577  if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
5578  return split();
5579 
5580  return getSplitUnqualifiedTypeImpl(*this);
5581 }
5582 
5584  removeLocalFastQualifiers(Qualifiers::Const);
5585 }
5586 
5588  removeLocalFastQualifiers(Qualifiers::Restrict);
5589 }
5590 
5592  removeLocalFastQualifiers(Qualifiers::Volatile);
5593 }
5594 
5595 inline void QualType::removeLocalCVRQualifiers(unsigned Mask) {
5596  assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
5597  static_assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask,
5598  "Fast bits differ from CVR bits!");
5599 
5600  // Fast path: we don't need to touch the slow qualifiers.
5601  removeLocalFastQualifiers(Mask);
5602 }
5603 
5604 /// Return the address space of this type.
5605 inline unsigned QualType::getAddressSpace() const {
5606  return getQualifiers().getAddressSpace();
5607 }
5608 
5609 /// Return the gc attribute of this type.
5611  return getQualifiers().getObjCGCAttr();
5612 }
5613 
5615  if (const PointerType *PT = t.getAs<PointerType>()) {
5616  if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>())
5617  return FT->getExtInfo();
5618  } else if (const FunctionType *FT = t.getAs<FunctionType>())
5619  return FT->getExtInfo();
5620 
5621  return FunctionType::ExtInfo();
5622 }
5623 
5625  return getFunctionExtInfo(*t);
5626 }
5627 
5628 /// Determine whether this type is more
5629 /// qualified than the Other type. For example, "const volatile int"
5630 /// is more qualified than "const int", "volatile int", and
5631 /// "int". However, it is not more qualified than "const volatile
5632 /// int".
5633 inline bool QualType::isMoreQualifiedThan(QualType other) const {
5634  Qualifiers MyQuals = getQualifiers();
5635  Qualifiers OtherQuals = other.getQualifiers();
5636  return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes(OtherQuals));
5637 }
5638 
5639 /// Determine whether this type is at last
5640 /// as qualified as the Other type. For example, "const volatile
5641 /// int" is at least as qualified as "const int", "volatile int",
5642 /// "int", and "const volatile int".
5643 inline bool QualType::isAtLeastAsQualifiedAs(QualType other) const {
5644  Qualifiers OtherQuals = other.getQualifiers();
5645 
5646  // Ignore __unaligned qualifier if this type is a void.
5647  if (getUnqualifiedType()->isVoidType())
5648  OtherQuals.removeUnaligned();
5649 
5650  return getQualifiers().compatiblyIncludes(OtherQuals);
5651 }
5652 
5653 /// If Type is a reference type (e.g., const
5654 /// int&), returns the type that the reference refers to ("const
5655 /// int"). Otherwise, returns the type itself. This routine is used
5656 /// throughout Sema to implement C++ 5p6:
5657 ///
5658 /// If an expression initially has the type "reference to T" (8.3.2,
5659 /// 8.5.3), the type is adjusted to "T" prior to any further
5660 /// analysis, the expression designates the object or function
5661 /// denoted by the reference, and the expression is an lvalue.
5663  if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>())
5664  return RefType->getPointeeType();
5665  else
5666  return *this;
5667 }
5668 
5670  return ((getTypePtr()->isVoidType() && !hasQualifiers()) ||
5671  getTypePtr()->isFunctionType());
5672 }
5673 
5674 /// Tests whether the type is categorized as a fundamental type.
5675 ///
5676 /// \returns True for types specified in C++0x [basic.fundamental].
5677 inline bool Type::isFundamentalType() const {
5678  return isVoidType() ||
5679  // FIXME: It's really annoying that we don't have an
5680  // 'isArithmeticType()' which agrees with the standard definition.
5681  (isArithmeticType() && !isEnumeralType());
5682 }
5683 
5684 /// Tests whether the type is categorized as a compound type.
5685 ///
5686 /// \returns True for types specified in C++0x [basic.compound].
5687 inline bool Type::isCompoundType() const {
5688  // C++0x [basic.compound]p1:
5689  // Compound types can be constructed in the following ways:
5690  // -- arrays of objects of a given type [...];
5691  return isArrayType() ||
5692  // -- functions, which have parameters of given types [...];
5693  isFunctionType() ||
5694  // -- pointers to void or objects or functions [...];
5695  isPointerType() ||
5696  // -- references to objects or functions of a given type. [...]
5697  isReferenceType() ||
5698  // -- classes containing a sequence of objects of various types, [...];
5699  isRecordType() ||
5700  // -- unions, which are classes capable of containing objects of different
5701  // types at different times;
5702  isUnionType() ||
5703  // -- enumerations, which comprise a set of named constant values. [...];
5704  isEnumeralType() ||
5705  // -- pointers to non-static class members, [...].
5707 }
5708 
5709 inline bool Type::isFunctionType() const {
5710  return isa<FunctionType>(CanonicalType);
5711 }
5712 inline bool Type::isPointerType() const {
5713  return isa<PointerType>(CanonicalType);
5714 }
5715 inline bool Type::isAnyPointerType() const {
5716  return isPointerType() || isObjCObjectPointerType();
5717 }
5718 inline bool Type::isBlockPointerType() const {
5719  return isa<BlockPointerType>(CanonicalType);
5720 }
5721 inline bool Type::isReferenceType() const {
5722  return isa<ReferenceType>(CanonicalType);
5723 }
5724 inline bool Type::isLValueReferenceType() const {
5725  return isa<LValueReferenceType>(CanonicalType);
5726 }
5727 inline bool Type::isRValueReferenceType() const {
5728  return isa<RValueReferenceType>(CanonicalType);
5729 }
5730 inline bool Type::isFunctionPointerType() const {
5731  if (const PointerType *T = getAs<PointerType>())
5732  return T->getPointeeType()->isFunctionType();
5733  else
5734  return false;
5735 }
5736 inline bool Type::isMemberPointerType() const {
5737  return isa<MemberPointerType>(CanonicalType);
5738 }
5740  if (const MemberPointerType* T = getAs<MemberPointerType>())
5741  return T->isMemberFunctionPointer();
5742  else
5743  return false;
5744 }
5745 inline bool Type::isMemberDataPointerType() const {
5746  if (const MemberPointerType* T = getAs<MemberPointerType>())
5747  return T->isMemberDataPointer();
5748  else
5749  return false;
5750 }
5751 inline bool Type::isArrayType() const {
5752  return isa<ArrayType>(CanonicalType);
5753 }
5754 inline bool Type::isConstantArrayType() const {
5755  return isa<ConstantArrayType>(CanonicalType);
5756 }
5757 inline bool Type::isIncompleteArrayType() const {
5758  return isa<IncompleteArrayType>(CanonicalType);
5759 }
5760 inline bool Type::isVariableArrayType() const {
5761  return isa<VariableArrayType>(CanonicalType);
5762 }
5763 inline bool Type::isDependentSizedArrayType() const {
5764  return isa<DependentSizedArrayType>(CanonicalType);
5765 }
5766 inline bool Type::isBuiltinType() const {
5767  return isa<BuiltinType>(CanonicalType);
5768 }
5769 inline bool Type::isRecordType() const {
5770  return isa<RecordType>(CanonicalType);
5771 }
5772 inline bool Type::isEnumeralType() const {
5773  return isa<EnumType>(CanonicalType);
5774 }
5775 inline bool Type::isAnyComplexType() const {
5776  return isa<ComplexType>(CanonicalType);
5777 }
5778 inline bool Type::isVectorType() const {
5779  return isa<VectorType>(CanonicalType);
5780 }
5781 inline bool Type::isExtVectorType() const {
5782  return isa<ExtVectorType>(CanonicalType);
5783 }
5784 inline bool Type::isObjCObjectPointerType() const {
5785  return isa<ObjCObjectPointerType>(CanonicalType);
5786 }
5787 inline bool Type::isObjCObjectType() const {
5788  return isa<ObjCObjectType>(CanonicalType);
5789 }
5791  return isa<ObjCInterfaceType>(CanonicalType) ||
5792  isa<ObjCObjectType>(CanonicalType);
5793 }
5794 inline bool Type::isAtomicType() const {
5795  return isa<AtomicType>(CanonicalType);
5796 }
5797 
5798 inline bool Type::isObjCQualifiedIdType() const {
5799  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
5800  return OPT->isObjCQualifiedIdType();
5801  return false;
5802 }
5803 inline bool Type::isObjCQualifiedClassType() const {
5804  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
5805  return OPT->isObjCQualifiedClassType();
5806  return false;
5807 }
5808 inline bool Type::isObjCIdType() const {
5809  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
5810  return OPT->isObjCIdType();
5811  return false;
5812 }
5813 inline bool Type::isObjCClassType() const {
5814  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
5815  return OPT->isObjCClassType();
5816  return false;
5817 }
5818 inline bool Type::isObjCSelType() const {
5819  if (const PointerType *OPT = getAs<PointerType>())
5820  return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
5821  return false;
5822 }
5823 inline bool Type::isObjCBuiltinType() const {
5824  return isObjCIdType() || isObjCClassType() || isObjCSelType();
5825 }
5826 
5827 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
5828  inline bool Type::is##Id##Type() const { \
5829  return isSpecificBuiltinType(BuiltinType::Id); \
5830  }
5831 #include "clang/Basic/OpenCLImageTypes.def"
5832 
5833 inline bool Type::isSamplerT() const {
5834  return isSpecificBuiltinType(BuiltinType::OCLSampler);
5835 }
5836 
5837 inline bool Type::isEventT() const {
5838  return isSpecificBuiltinType(BuiltinType::OCLEvent);
5839 }
5840 
5841 inline bool Type::isClkEventT() const {
5842  return isSpecificBuiltinType(BuiltinType::OCLClkEvent);
5843 }
5844 
5845 inline bool Type::isQueueT() const {
5846  return isSpecificBuiltinType(BuiltinType::OCLQueue);
5847 }
5848 
5849 inline bool Type::isReserveIDT() const {
5850  return isSpecificBuiltinType(BuiltinType::OCLReserveID);
5851 }
5852 
5853 inline bool Type::isImageType() const {
5854 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) is##Id##Type() ||
5855  return
5856 #include "clang/Basic/OpenCLImageTypes.def"
5857  0; // end boolean or operation
5858 }
5859 
5860 inline bool Type::isPipeType() const {
5861  return isa<PipeType>(CanonicalType);
5862 }
5863 
5864 inline bool Type::isOpenCLSpecificType() const {
5865  return isSamplerT() || isEventT() || isImageType() || isClkEventT() ||
5866  isQueueT() || isReserveIDT() || isPipeType();
5867 }
5868 
5869 inline bool Type::isTemplateTypeParmType() const {
5870  return isa<TemplateTypeParmType>(CanonicalType);
5871 }
5872 
5873 inline bool Type::isSpecificBuiltinType(unsigned K) const {
5874  if (const BuiltinType *BT = getAs<BuiltinType>())
5875  if (BT->getKind() == (BuiltinType::Kind) K)
5876  return true;
5877  return false;
5878 }
5879 
5880 inline bool Type::isPlaceholderType() const {
5881  if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
5882  return BT->isPlaceholderType();
5883  return false;
5884 }
5885 
5887  if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
5888  if (BT->isPlaceholderType())
5889  return BT;
5890  return nullptr;
5891 }
5892 
5893 inline bool Type::isSpecificPlaceholderType(unsigned K) const {
5895  if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
5896  return (BT->getKind() == (BuiltinType::Kind) K);
5897  return false;
5898 }
5899 
5901  if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
5902  return BT->isNonOverloadPlaceholderType();
5903  return false;
5904 }
5905 
5906 inline bool Type::isVoidType() const {
5907  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
5908  return BT->getKind() == BuiltinType::Void;
5909  return false;
5910 }
5911 
5912 inline bool Type::isHalfType() const {
5913  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
5914  return BT->getKind() == BuiltinType::Half;
5915  // FIXME: Should we allow complex __fp16? Probably not.
5916  return false;
5917 }
5918 
5919 inline bool Type::isNullPtrType() const {
5920  if (const BuiltinType *BT = getAs<BuiltinType>())
5921  return BT->getKind() == BuiltinType::NullPtr;
5922  return false;
5923 }
5924 
5926 bool IsEnumDeclScoped(EnumDecl *);
5927 
5928 inline bool Type::isIntegerType() const {
5929  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
5930  return BT->getKind() >= BuiltinType::Bool &&
5931  BT->getKind() <= BuiltinType::Int128;
5932  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
5933  // Incomplete enum types are not treated as integer types.
5934  // FIXME: In C++, enum types are never integer types.
5935  return IsEnumDeclComplete(ET->getDecl()) &&
5936  !IsEnumDeclScoped(ET->getDecl());
5937  }
5938  return false;
5939 }
5940 
5941 inline bool Type::isScalarType() const {
5942  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
5943  return BT->getKind() > BuiltinType::Void &&
5944  BT->getKind() <= BuiltinType::NullPtr;
5945  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
5946  // Enums are scalar types, but only if they are defined. Incomplete enums
5947  // are not treated as scalar types.
5948  return IsEnumDeclComplete(ET->getDecl());
5949  return isa<PointerType>(CanonicalType) ||
5950  isa<BlockPointerType>(CanonicalType) ||
5951  isa<MemberPointerType>(CanonicalType) ||
5952  isa<ComplexType>(CanonicalType) ||
5953  isa<ObjCObjectPointerType>(CanonicalType);
5954 }
5955 
5957  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
5958  return BT->getKind() >= BuiltinType::Bool &&
5959  BT->getKind() <= BuiltinType::Int128;
5960 
5961  // Check for a complete enum type; incomplete enum types are not properly an
5962  // enumeration type in the sense required here.
5963  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
5964  return IsEnumDeclComplete(ET->getDecl());
5965 
5966  return false;
5967 }
5968 
5969 inline bool Type::isBooleanType() const {
5970  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
5971  return BT->getKind() == BuiltinType::Bool;
5972  return false;
5973 }
5974 
5975 inline bool Type::isUndeducedType() const {
5976  auto *DT = getContainedDeducedType();
5977  return DT && !DT->isDeduced();
5978 }
5979 
5980 /// \brief Determines whether this is a type for which one can define
5981 /// an overloaded operator.
5982 inline bool Type::isOverloadableType() const {
5983  return isDependentType() || isRecordType() || isEnumeralType();
5984 }
5985 
5986 /// \brief Determines whether this type can decay to a pointer type.
5987 inline bool Type::canDecayToPointerType() const {
5988  return isFunctionType() || isArrayType();
5989 }
5990 
5991 inline bool Type::hasPointerRepresentation() const {
5992  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
5994 }
5995 
5997  return isObjCObjectPointerType();
5998 }
5999 
6000 inline const Type *Type::getBaseElementTypeUnsafe() const {
6001  const Type *type = this;
6002  while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe())
6003  type = arrayType->getElementType().getTypePtr();
6004  return type;
6005 }
6006 
6008  const Type *type = this;
6009  if (type->isAnyPointerType())
6010  return type->getPointeeType().getTypePtr();
6011  else if (type->isArrayType())
6012  return type->getBaseElementTypeUnsafe();
6013  return type;
6014 }
6015 
6016 /// Insertion operator for diagnostics. This allows sending QualType's into a
6017 /// diagnostic with <<.
6019  QualType T) {
6020  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
6022  return DB;
6023 }
6024 
6025 /// Insertion operator for partial diagnostics. This allows sending QualType's
6026 /// into a diagnostic with <<.
6028  QualType T) {
6029  PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
6031  return PD;
6032 }
6033 
6034 // Helper class template that is used by Type::getAs to ensure that one does
6035 // not try to look through a qualified type to get to an array type.
6036 template <typename T>
6037 using TypeIsArrayType =
6038  std::integral_constant<bool, std::is_same<T, ArrayType>::value ||
6039  std::is_base_of<ArrayType, T>::value>;
6040 
6041 // Member-template getAs<specific type>'.
6042 template <typename T> const T *Type::getAs() const {
6043  static_assert(!TypeIsArrayType<T>::value,
6044  "ArrayType cannot be used with getAs!");
6045 
6046  // If this is directly a T type, return it.
6047  if (const T *Ty = dyn_cast<T>(this))
6048  return Ty;
6049 
6050  // If the canonical form of this type isn't the right kind, reject it.
6051  if (!isa<T>(CanonicalType))
6052  return nullptr;
6053 
6054  // If this is a typedef for the type, strip the typedef off without
6055  // losing all typedef information.
6056  return cast<T>(getUnqualifiedDesugaredType());
6057 }
6058 
6059 template <typename T> const T *Type::getAsAdjusted() const {
6060  static_assert(!TypeIsArrayType<T>::value, "ArrayType cannot be used with getAsAdjusted!");
6061 
6062  // If this is directly a T type, return it.
6063  if (const T *Ty = dyn_cast<T>(this))
6064  return Ty;
6065 
6066  // If the canonical form of this type isn't the right kind, reject it.
6067  if (!isa<T>(CanonicalType))
6068  return nullptr;
6069 
6070  // Strip off type adjustments that do not modify the underlying nature of the
6071  // type.
6072  const Type *Ty = this;
6073  while (Ty) {
6074  if (const auto *A = dyn_cast<AttributedType>(Ty))
6075  Ty = A->getModifiedType().getTypePtr();
6076  else if (const auto *E = dyn_cast<ElaboratedType>(Ty))
6077  Ty = E->desugar().getTypePtr();
6078  else if (const auto *P = dyn_cast<ParenType>(Ty))
6079  Ty = P->desugar().getTypePtr();
6080  else if (const auto *A = dyn_cast<AdjustedType>(Ty))
6081  Ty = A->desugar().getTypePtr();
6082  else
6083  break;
6084  }
6085 
6086  // Just because the canonical type is correct does not mean we can use cast<>,
6087  // since we may not have stripped off all the sugar down to the base type.
6088  return dyn_cast<T>(Ty);
6089 }
6090 
6091 inline const ArrayType *Type::getAsArrayTypeUnsafe() const {
6092  // If this is directly an array type, return it.
6093  if (const ArrayType *arr = dyn_cast<ArrayType>(this))
6094  return arr;
6095 
6096  // If the canonical form of this type isn't the right kind, reject it.
6097  if (!isa<ArrayType>(CanonicalType))
6098  return nullptr;
6099 
6100  // If this is a typedef for the type, strip the typedef off without
6101  // losing all typedef information.
6102  return cast<ArrayType>(getUnqualifiedDesugaredType());
6103 }
6104 
6105 template <typename T> const T *Type::castAs() const {
6106  static_assert(!TypeIsArrayType<T>::value,
6107  "ArrayType cannot be used with castAs!");
6108 
6109  if (const T *ty = dyn_cast<T>(this)) return ty;
6110  assert(isa<T>(CanonicalType));
6111  return cast<T>(getUnqualifiedDesugaredType());
6112 }
6113 
6115  assert(isa<ArrayType>(CanonicalType));
6116  if (const ArrayType *arr = dyn_cast<ArrayType>(this)) return arr;
6117  return cast<ArrayType>(getUnqualifiedDesugaredType());
6118 }
6119 
6120 DecayedType::DecayedType(QualType OriginalType, QualType DecayedPtr,
6121  QualType CanonicalPtr)
6122  : AdjustedType(Decayed, OriginalType, DecayedPtr, CanonicalPtr) {
6123 #ifndef NDEBUG
6124  QualType Adjusted = getAdjustedType();
6125  (void)AttributedType::stripOuterNullability(Adjusted);
6126  assert(isa<PointerType>(Adjusted));
6127 #endif
6128 }
6129 
6131  QualType Decayed = getDecayedType();
6133  return cast<PointerType>(Decayed)->getPointeeType();
6134 }
6135 
6136 
6137 } // end namespace clang
6138 
6139 #endif
bool isDynamicExceptionSpec(ExceptionSpecificationType ESpecType)
bool isObjCSelType() const
Definition: Type.h:5818
bool isPlaceholderType() const
Determines whether this type is a placeholder type, i.e.
Definition: Type.h:2141
Internal representation of canonical, dependent typeof(expr) types.
Definition: Type.h:3626
Kind getKind() const
Definition: Type.h:2105
unsigned getNumElements() const
Definition: Type.h:2822
bool hasObjCGCAttr() const
Definition: Type.h:287
unsigned getAddressSpace() const
Return the address space of this type.
Definition: Type.h:5605
const ComplexType * getAsComplexIntegerType() const
Definition: Type.cpp:407
bool isUnspecialized() const
Determine whether this object type is "unspecialized", meaning that it has no type arguments...
Definition: Type.h:5065
bool compatiblyIncludesObjCLifetime(Qualifiers other) const
Determines if these qualifiers compatibly include another set of qualifiers from the narrow perspecti...
Definition: Type.h:484
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:1243
bool isObjCObjectOrInterfaceType() const
Definition: Type.h:5790
QualType getExceptionType(unsigned i) const
Definition: Type.h:3402
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
Definition: Type.h:4576
SourceLocation getEnd() const
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present...
Definition: Type.h:3501
typedefconst::clang::Type * SimpleType
Definition: Type.h:1138
Expr * getSizeExpr() const
Definition: Type.h:2772
QualType getUnderlyingType() const
Definition: Type.h:3676
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:5508
const Type * Ty
The locally-unqualified type.
Definition: Type.h:561
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
Definition: Type.h:5177
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition: Type.h:4405
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1618
Qualifiers getNonFastQualifiers() const
Definition: Type.h:387
bool isVariadic() const
Definition: Type.h:3442
static bool classof(const Type *T)
Definition: Type.h:3777
static void print(SplitQualType split, raw_ostream &OS, const PrintingPolicy &policy, const Twine &PlaceHolder, unsigned Indentation=0)
Definition: Type.h:957
static Qualifiers fromCVRUMask(unsigned CVRU)
Definition: Type.h:219
TemplateName getTemplateName() const
Definition: Type.h:4473
bool isNullPtrType() const
Definition: Type.h:5919
ExtParameterInfo getExtParameterInfo(unsigned I) const
Definition: Type.h:3507
The "enum" keyword introduces the elaborated-type-specifier.
Definition: Type.h:4513
bool containsUnexpandedParameterPack() const
Whether this nested-name-specifier contains an unexpanded parameter pack (for C++11 variadic template...
void removeUnaligned()
Definition: Type.h:284
unsigned getDepth() const
Definition: Type.h:4024
void setDependent(bool D=true)
Definition: Type.h:1541
no exception specification
QualType desugar() const
Definition: Type.h:2777
bool canDecayToPointerType() const
Determines whether this type can decay to a pointer type.
Definition: Type.h:5987
bool isNonOverloadPlaceholderType() const
Test for a placeholder type other than Overload; see BuiltinType::isNonOverloadPlaceholderType.
Definition: Type.h:5900
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2224
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2682
Represents the dependent type named by a dependently-scoped typename using declaration, e.g.
Definition: Type.h:3550
bool isAtLeastAsQualifiedAs(QualType Other) const
Determine whether this type is at least as qualified as the other given type, requiring exact equalit...
Definition: Type.h:5643
A (possibly-)qualified type.
Definition: Type.h:616
bool isConstantArrayType() const
Definition: Type.h:5754
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
Definition: Type.h:6007
const TemplateArgument * iterator
Definition: Type.h:4742
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee)
Definition: Type.h:2262
const T * getAsAdjusted() const
Member-template getAsAdjusted<specific type>.
Definition: Type.h:6059
SourceRange getBracketsRange() const
Definition: Type.h:2669
QualType getCallResultType(const ASTContext &Context) const
Determine the type of an expression that calls a function of this type.
Definition: Type.h:3081
bool isCharType() const
Definition: Type.cpp:1694
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: Type.h:1581
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
Definition: Type.h:5873
bool operator==(Qualifiers Other) const
Definition: Type.h:501
bool hasFloatingRepresentation() const
Determine whether this type has a floating-point representation of some sort, e.g., it is a floating-point type or a vector thereof.
Definition: Type.cpp:1830
ExtInfo withCallingConv(CallingConv cc) const
Definition: Type.h:3042
bool isConsumed() const
Is this parameter considered "consumed" by Objective-C ARC? Consumed parameters must have retainable ...
Definition: Type.h:3173
ArrayRef< QualType > getTypeArgs() const
Retrieve the type arguments for this type.
Definition: Type.h:5327
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after...
Definition: Type.h:1054
static QualType getObjectType(APValue::LValueBase B)
Retrieves the "underlying object type" of the given expression, as used by __builtin_object_size.
bool isMemberPointerType() const
Definition: Type.h:5736
QualType desugar() const
Definition: Type.h:3108
FunctionDecl * getExceptionSpecDecl() const
If this function type has an exception specification which hasn't been determined yet (either because...
Definition: Type.h:3416
__auto_type (GNU extension)
QualType getBaseType() const
Definition: Type.h:3730
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
Definition: Type.h:5082
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:1803
unsigned getFastQualifiers() const
Definition: Type.h:367
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type...
Definition: Type.cpp:2618
ParameterABI getParameterABI(unsigned I) const
Definition: Type.h:3514
Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const
Return the implicit lifetime for this type, which must not be dependent.
Definition: Type.cpp:3707
QualType desugar() const
Definition: Type.h:4480
bool isSugared() const
Definition: Type.h:5434
bool IsEnumDeclScoped(EnumDecl *ED)
Check if the given decl is scoped.
Definition: Decl.h:4014
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: Type.h:1268
void setInstantiationDependent(bool D=true)
Definition: Type.h:1546
Stmt - This represents one statement.
Definition: Stmt.h:60
NullabilityKind
Describes the nullability of a particular type.
Definition: Specifiers.h:281
QualType desugar() const
Definition: Type.h:2344
ExtInfo(CallingConv CC)
Definition: Type.h:2991
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:1724
Internal representation of canonical, dependent __underlying_type(type) types.
Definition: Type.h:3745
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:2923
bool isLocalRestrictQualified() const
Determine whether this particular QualType instance has the "restrict" qualifier set, without looking through typedefs that may have added "restrict" at a different level.
Definition: Type.h:700
unsigned getNumArgs() const
Retrieve the number of template arguments.
Definition: Type.h:4734
static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind, QualType modified, QualType equivalent)
Definition: Type.h:3970
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4828
bool hasAutoForTrailingReturnType() const
Determine whether this type was written with a leading 'auto' corresponding to a trailing return type...
Definition: Type.cpp:1632
static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner)
Definition: Type.h:2215
No linkage, which means that the entity is unique and can only be referred to from within its scope...
Definition: Linkage.h:28
QualType desugar() const
Definition: Type.h:4674
ObjCProtocolDecl *const * getProtocolStorage() const
Definition: Type.h:4851
bool isSugared() const
Definition: Type.h:2178
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2834
QualType desugar() const
Definition: Type.h:2415
void addConst()
Add the const type qualifier to this QualType.
Definition: Type.h:779
Qualifiers::GC getObjCGCAttr() const
Returns gc attribute of this type.
Definition: Type.h:5610
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:4642
CanonicalTTPTInfo CanTTPTInfo
Definition: Type.h:3992
void setObjCLifetime(ObjCLifetime type)
Definition: Type.h:312
friend Qualifiers operator-(Qualifiers L, Qualifiers R)
Compute the difference between two qualifier sets.
Definition: Type.h:524
ConstantArrayType(TypeClass tc, QualType et, QualType can, const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
Definition: Type.h:2562
static bool classof(const Type *T)
Definition: Type.h:2353
static bool classof(const Type *T)
Definition: Type.h:4482
static std::string getAsString(SplitQualType split)
Definition: Type.h:945
bool isRecordType() const
Definition: Type.h:5769
static void Profile(llvm::FoldingSetNodeID &ID, QualType T)
Definition: Type.h:5410
bool isInteger() const
Definition: Type.h:2117
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:81
bool isChar16Type() const
Definition: Type.cpp:1710
ObjCObjectTypeBitfields ObjCObjectTypeBits
Definition: Type.h:1507
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
Definition: Type.cpp:2154
StringRef P
bool isVoidPointerType() const
Definition: Type.cpp:384
Represents a C++11 auto or C++14 decltype(auto) type.
Definition: Type.h:4206
bool isObjCQualifiedId() const
Definition: Type.h:5047
QualType desugar() const
Definition: Type.h:5180
bool isEnumeralType() const
Definition: Type.h:5772
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:3046
A class providing a concrete implementation of ObjCObjectType, so as to not increase the footprint of...
Definition: Type.h:5118
void removeQualifiers(Qualifiers Q)
Remove the qualifiers from the given set from this set.
Definition: Type.h:415
static bool classof(const Type *T)
Definition: Type.h:2847
std::string getAsString() const
Definition: Type.h:942
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
Definition: Attr.h:195
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type...
Definition: Type.h:3492
QualType getPointeeType() const
Definition: Type.h:2461
bool isSugared() const
Definition: Type.h:4187
The base class of the type hierarchy.
Definition: Type.h:1303
ObjCObjectType(enum Nonce_ObjCInterface)
Definition: Type.h:5013
ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const
Definition: Type.h:3029
bool isObjCQualifiedClassType() const
Definition: Type.h:5803
bool isElaboratedTypeSpecifier() const
Determine wither this type is a C++ elaborated-type-specifier.
Definition: Type.cpp:2499
unsigned getCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers applied to this type.
Definition: Type.h:5522
void setObjCGCAttr(GC type)
Definition: Type.h:289
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2497
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2181
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:5260
AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy, QualType CanonicalPtr)
Definition: Type.h:2277
static bool classof(const Type *T)
Definition: Type.h:2542
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2346
bool isDecltypeAuto() const
Definition: Type.h:4217
bool isBooleanType() const
Definition: Type.h:5969
static clang::QualType getFromVoidPointer(void *P)
Definition: Type.h:1151
bool compatiblyIncludes(Qualifiers other) const
Determines if these qualifiers compatibly include another set.
Definition: Type.h:463
QualType ElementType
The element type of the vector.
Definition: Type.h:2809
const QualType * param_type_iterator
Definition: Type.h:3462
unsigned getIndex() const
Definition: Type.h:4025
bool getHasRegParm() const
Definition: Type.h:3067
bool isBlockPointerType() const
Definition: Type.h:5718
const ObjCObjectPointerType * getAsObjCQualifiedClassType() const
Definition: Type.cpp:1508
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition: Type.h:997
bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const
Definition: Type.h:2907
bool isCForbiddenLValueType() const
Determine whether expressions of the given type are forbidden from being lvalues in C...
Definition: Type.h:5669
bool isUnspecialized() const
Whether this type is unspecialized, meaning that is has no type arguments.
Definition: Type.h:5320
Qualifiers & operator+=(Qualifiers R)
Definition: Type.h:506
bool isSpelledAsLValue() const
Definition: Type.h:2377
static inline::clang::ExtQuals * getFromVoidPointer(void *P)
Definition: Type.h:65
static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, unsigned TypeQuals)
Definition: Type.h:2587
bool hasUnsignedIntegerRepresentation() const
Determine whether this type has an unsigned integer representation of some sort, e.g., it is an unsigned integer type or a vector.
Definition: Type.cpp:1814
bool hasStrongOrWeakObjCLifetime() const
True if the lifetime is either strong or weak.
Definition: Type.h:329
const llvm::APInt & getSize() const
Definition: Type.h:2568
void * getAsOpaquePtr() const
Definition: Type.h:664
static Qualifiers fromOpaqueValue(unsigned opaque)
Definition: Type.h:226
The noexcept specifier has a bad expression.
Definition: Type.h:3394
void removeObjCLifetime()
Definition: Type.h:315
ObjCProtocolDecl *const * qual_iterator
Definition: Type.h:4871
ObjCLifetime getObjCLifetime() const
Definition: Type.h:309
The "union" keyword.
Definition: Type.h:4494
Extra information about a function prototype.
Definition: Type.h:3234
CallingConv getCallConv() const
Definition: Type.h:3073
bool isCanonical() const
Definition: Type.h:5533
std::string getAsString() const
AutoTypeKeyword getKeyword() const
Definition: Type.h:4220
Qualifiers::ObjCLifetime getObjCLifetime() const
Definition: Type.h:1233
ArrayTypeBitfields ArrayTypeBits
Definition: Type.h:1502
Represents a C++17 deduced template specialization type.
Definition: Type.h:4241
bool isSpecialized() const
Whether this type is specialized, meaning that it has type arguments.
Definition: Type.h:5312
The "__interface" keyword.
Definition: Type.h:4492
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:4028
void addAddressSpace(unsigned space)
Definition: Type.h:359
QualType getOriginalType() const
Definition: Type.h:2288
bool isRealType() const
Definition: Type.cpp:1843
bool isMemberDataPointerType() const
Definition: Type.h:5745
static Qualifiers fromFastMask(unsigned Mask)
Definition: Type.h:207
static StringRef getTagTypeKindName(TagTypeKind Kind)
Definition: Type.h:4560
QualType(const Type *Ptr, unsigned Quals)
Definition: Type.h:641
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
void getAsStringInternal(std::string &Str, const PrintingPolicy &Policy) const
Definition: Type.h:967
bool isImageType() const
Definition: Type.h:5853
const BuiltinType * getAsPlaceholderType() const
Definition: Type.h:5886
Qualifiers getIndexTypeQualifiers() const
Definition: Type.h:2535
bool canHaveNullability(bool ResultIfUnknown=true) const
Determine whether the given type can have a nullability specifier applied to it, i.e., if it is any kind of pointer type.
Definition: Type.cpp:3545
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1575
bool isObjCRetainableType() const
Definition: Type.cpp:3751
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:4062
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2259
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
Definition: Linkage.h:25
unsigned getNumArgs() const
Retrieve the number of template arguments.
Definition: Type.h:4390
bool isUnionType() const
Definition: Type.cpp:390
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs, typeofs, etc., as well as any qualifiers.
Definition: Type.cpp:340
QualType getUnderlyingType() const
Definition: Type.h:3729
bool isVoidType() const
Definition: Type.h:5906
The collection of all-type qualifiers we support.
Definition: Type.h:118
bool isSugared() const
Definition: Type.h:4034
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
QualType desugar() const
Definition: Type.h:3529
PipeType - OpenCL20.
Definition: Type.h:5419
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const
Definition: Diagnostic.h:1067
The width of the "fast" qualifier mask.
Definition: Type.h:161
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2739
bool operator==(ExtInfo Other) const
Definition: Type.h:3005
QualType getPointeeType() const
Definition: Type.h:6130
unsigned getNumParams() const
Definition: Type.h:3338
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3354
Visibility getVisibility() const
Definition: Visibility.h:83
bool isOpenCLSpecificType() const
Definition: Type.h:5864
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type...
Definition: Type.h:1894
DependentTypeOfExprType(const ASTContext &Context, Expr *E)
Definition: Type.h:3631
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
Definition: Type.h:4669
QualType getElementType() const
Definition: Type.h:2773
FunctionType::ExtInfo ExtInfo
Definition: Type.h:3249
One of these records is kept for each identifier that is lexed.
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:2538
ExtInfo withProducesResult(bool producesResult) const
Definition: Type.h:3022
bool isScalarType() const
Definition: Type.h:5941
Defines the Linkage enumeration and various utility functions.
const TemplateArgument * iterator
Definition: Type.h:4376
ParameterABI getABI() const
Return the ABI treatment of this parameter.
Definition: Type.h:3162
bool hasObjCPointerRepresentation() const
Whether this type can represent an objective pointer type for the purpose of GC'ability.
Definition: Type.h:5996
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
Definition: Type.cpp:1552
Represents a class type in Objective C.
Definition: Type.h:4969
void removeRestrict()
Definition: Type.h:255
qual_iterator qual_begin() const
Definition: Type.h:4875
QualType desugar() const
Definition: Type.h:2115
Expr * getSizeExpr() const
Definition: Type.h:2664
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Definition: Type.h:1813
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:128
is ARM Neon vector
Definition: Type.h:2804
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:3343
bool isObjCARCImplicitlyUnretainedType() const
Determines if this type, which must satisfy isObjCLifetimeType(), is implicitly __unsafe_unretained r...
Definition: Type.cpp:3713
bool isSugared() const
Definition: Type.h:3820
static bool classof(const Type *T)
Definition: Type.h:4760
bool isReferenceType() const
Definition: Type.h:5721
QualType desugar() const
Definition: Type.h:3727
bool isStructureOrClassType() const
Definition: Type.cpp:377
bool isAnyPointerType() const
Definition: Type.h:5715
Defines the ExceptionSpecificationType enumeration and various utility functions. ...
void removeConst()
Definition: Type.h:241
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.h:4612
NoexceptResult
Result type of getNoexceptSpec().
Definition: Type.h:3392
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2481
static bool classof(const Type *T)
Definition: Type.h:2417
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
Definition: ASTMatchers.h:281
void setLocalFastQualifiers(unsigned Quals)
Definition: Type.h:647
bool isChar32Type() const
Definition: Type.cpp:1716
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that that type refers to...
Definition: Type.cpp:1533
ObjCObjectType::qual_iterator qual_iterator
An iterator over the qualifiers on the object type.
Definition: Type.h:5339
Base class that is common to both the ExtQuals and Type classes, which allows QualType to access the ...
Definition: Type.h:1166
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:4662
unsigned getCVRQualifiers() const
Definition: Type.h:259
static bool classof(const Type *T)
Definition: Type.h:2158
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition: Type.h:3150
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
Definition: Type.h:3493
The fast qualifier mask.
Definition: Type.h:164
static bool classof(const Type *T)
Definition: Type.h:5182
Represents the result of substituting a set of types for a template type parameter pack...
Definition: Type.h:4117
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments for this type.
Definition: Type.h:5332
bool hasTargetSpecificAddressSpace() const
Definition: Type.h:336
const RecordType * getAsUnionType() const
NOTE: getAs*ArrayType are methods on ASTContext.
Definition: Type.cpp:449
bool isLocalVolatileQualified() const
Determine whether this particular QualType instance has the "volatile" qualifier set, without looking through typedefs that may have added "volatile" at a different level.
Definition: Type.h:710
static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, unsigned NumElements, TypeClass TypeClass, VectorKind VecKind)
Definition: Type.h:2838
static int getPointAccessorIdx(char c)
Definition: Type.h:2863
unsigned getAsOpaqueValue() const
Definition: Type.h:233
ObjCProtocolDecl * getProtocol(unsigned I) const
Retrieve a qualifying protocol by index on the object type.
Definition: Type.h:5357
unsigned getRegParm() const
Definition: Type.h:2997
bool hasStrongOrWeakObjCLifetime() const
Definition: Type.h:1036
static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee, bool SpelledAsLValue)
Definition: Type.h:2392
bool isParamConsumed(unsigned I) const
Definition: Type.h:3521
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5438
static bool classof(const Type *T)
Definition: Type.h:4199
QualType getUnderlyingType() const
Definition: Type.h:3655
ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, bool SpelledAsLValue)
Definition: Type.h:2364
Expr * getUnderlyingExpr() const
Definition: Type.h:3675
FunctionType(TypeClass tc, QualType res, QualType Canonical, bool Dependent, bool InstantiationDependent, bool VariablyModified, bool ContainsUnexpandedParameterPack, ExtInfo Info)
Definition: Type.h:3052
Values of this type can be null.
void addRestrict()
Add the restrict qualifier to this QualType.
Definition: Type.h:795
const Type & operator*() const
Definition: Type.h:671
static bool classof(const Type *T)
Definition: Type.h:5413
bool isSugared() const
Definition: Type.h:2912
unsigned getRegParmType() const
Definition: Type.h:3068
Type(TypeClass tc, QualType canon, bool Dependent, bool InstantiationDependent, bool VariablyModified, bool ContainsUnexpandedParameterPack)
Definition: Type.h:1524
bool isIntegralOrUnscopedEnumerationType() const
Determine whether this type is an integral or unscoped enumeration type.
Definition: Type.cpp:1677
bool hasNonFastQualifiers() const
Return true if the set contains any qualifiers which require an ExtQuals node to be allocated...
Definition: Type.h:386
bool isSugared() const
Definition: Type.h:2114
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2424
static bool classof(const Type *T)
Definition: Type.h:2614
param_type_range param_types() const
Definition: Type.h:3465
static bool classof(const Type *T)
Definition: Type.h:2320
An lvalue ref-qualifier was provided (&).
Definition: Type.h:1262
bool isSpecificPlaceholderType(unsigned K) const
Test for a specific placeholder type.
Definition: Type.h:5893
void addObjCGCAttr(GC type)
Definition: Type.h:293
ArrayRef< ObjCProtocolDecl * > getProtocols() const
Retrieve all of the protocol qualifiers.
Definition: Type.h:4893
bool isFundamentalType() const
Tests whether the type is categorized as a fundamental type.
Definition: Type.h:5677
Microsoft throw(...) extension.
A convenient class for passing around template argument information.
Definition: TemplateBase.h:524
Qualifiers withoutObjCGCAttr() const
Definition: Type.h:297
void setRestrict(bool flag)
Definition: Type.h:252
static bool classof(const Type *T)
Definition: Type.h:5383
LinkageInfo getLinkageAndVisibility() const
Determine the linkage and visibility of this type.
Definition: Type.cpp:3517
QualType getBaseType() const
Gets the base type of this object type.
Definition: Type.h:5030
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:4382
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
QualType getReturnType() const
Definition: Type.h:3065
The "struct" keyword introduces the elaborated-type-specifier.
Definition: Type.h:4505
bool isSugared() const
Definition: Type.h:2256
UnresolvedUsingTypenameDecl * getDecl() const
Definition: Type.h:3560
ExtParameterInfo withHasPassObjectSize() const
Definition: Type.h:3189
TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, QualType Canonical, bool Dependent, bool InstantiationDependent, bool VariablyModified, bool ContainsUnexpandedParameterPack)
Definition: Type.h:4527
Whether values of this type can be null is (explicitly) unspecified.
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:32
SplitQualType getSplitUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:5576
BuiltinType(Kind K)
Definition: Type.h:2097
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition: Type.cpp:3770
Represents a typeof (or typeof) expression (a GCC extension).
Definition: Type.h:3602
void addCVRQualifiers(unsigned mask)
Definition: Type.h:271
Expr * getNoexceptExpr() const
Definition: Type.h:3406
unsigned getNumProtocols() const
Return the number of qualifying protocols on the object type.
Definition: Type.h:5352
RecordDecl * getDecl() const
Definition: Type.h:3793
QualType withoutLocalFastQualifiers() const
Definition: Type.h:838
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface...
Definition: Type.h:5199
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
Definition: Type.cpp:1784
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4614
Defines the Diagnostic-related interfaces.
const ObjCObjectType * getAsObjCInterfaceType() const
Definition: Type.cpp:1518
Values of this type can never be null.
QualType desugar() const
Definition: Type.h:4403
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition: Type.h:952
static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R)
Returns the common set of qualifiers while removing them from the given sets.
Definition: Type.h:171
static bool classof(const Type *T)
Definition: Type.h:2676
TemplateTypeParmDecl * TTPDecl
Definition: Type.h:3994
QualType desugar() const
Definition: Type.h:4188
void addQualifiers(Qualifiers Q)
Add the qualifiers from the given set to this set.
Definition: Type.h:398
Type * this_()
Definition: Type.h:1523
static unsigned getNumAddressingBits(const ASTContext &Context, QualType ElementType, const llvm::APInt &NumElements)
Determine the number of bits required to address a member of.
Definition: Type.cpp:76
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:4603
static bool classof(const Type *T)
Definition: Type.h:3734
TypeClass getTypeClass() const
Definition: Type.h:1555
bool isStructureType() const
Definition: Type.cpp:362
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:1985
bool isObjCIndependentClassType() const
Definition: Type.cpp:3746
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
Definition: Type.cpp:1930
bool hasConst() const
Definition: Type.h:237
QualType withVolatile() const
Definition: Type.h:790
void setUnaligned(bool flag)
Definition: Type.h:281
static bool classof(const Type *T)
Definition: Type.h:2266
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool appendSpaceIfNonEmpty=false) const
const TemplateSpecializationType * getInjectedTST() const
Definition: Type.h:4470
friend Qualifiers operator+(Qualifiers L, Qualifiers R)
Definition: Type.h:513
void addCVRUQualifiers(unsigned mask)
Definition: Type.h:275
void addUnaligned()
Definition: Type.h:285
Represents an ObjC class declaration.
Definition: DeclObjC.h:1108
bool isExtVectorType() const
Definition: Type.h:5781
static void * getAsVoidPointer(clang::QualType P)
Definition: Type.h:1148
QualType desugar() const
Definition: Type.h:2828
bool empty() const
Definition: Type.h:395
friend bool operator==(const QualType &LHS, const QualType &RHS)
Indicate whether the specified types and qualifiers are identical.
Definition: Type.h:936
detail::InMemoryDirectory::const_iterator I
QualType getAliasedType() const
Get the aliased type, if this is a specialization of a type alias template.
Definition: Type.h:4371
is ARM Neon polynomial vector
Definition: Type.h:2805
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:3227
bool operator!=(ExtInfo Other) const
Definition: Type.h:3008
void removeVolatile()
Definition: Type.h:248
bool isFromAST() const
Whether this type comes from an AST file.
Definition: Type.h:1558
QualType getCanonicalTypeInternal() const
Definition: Type.h:2045
void setFastQualifiers(unsigned mask)
Definition: Type.h:368
bool isSugared() const
Definition: Type.h:2343
static void Profile(llvm::FoldingSetNodeID &ID, const TemplateTypeParmType *Replaced, QualType Replacement)
Definition: Type.h:4093
bool isMemberFunctionPointer() const
Returns true if the member type (i.e.
Definition: Type.h:2465
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:2759
This object can be modified without requiring retains or releases.
Definition: Type.h:139
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Definition: Type.h:4138
bool isLinkageValid() const
True if the computed linkage is valid.
Definition: Type.cpp:3509
Defines the clang::Visibility enumeration and various utility functions.
static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name)
Definition: Type.h:4680
static bool classof(const Type *T)
Definition: Type.h:4235
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type...
Definition: Type.h:6091
EnumDecl * getDecl() const
Definition: Type.h:3816
Represents a K&R-style 'int foo()' function, which has no information available about its arguments...
Definition: Type.h:3095
Provides definitions for the various language-specific address spaces.
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4676
llvm::iterator_range< qual_iterator > qual_range
Definition: Type.h:5340
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition: Type.h:5402
QualType getInjectedSpecializationType() const
Definition: Type.h:4469
bool isObjCUnqualifiedId() const
Definition: Type.h:5038
const Type * getBaseType() const
Definition: Type.h:1240
ExtInfo getExtInfo() const
Definition: Type.h:3074
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type...
Definition: Type.h:6114
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2212
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:953
CanQualType getCanonicalTypeUnqualified() const
ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
Definition: Type.h:1216
Optional< ArrayRef< QualType > > getObjCSubstitutions(const DeclContext *dc) const
Retrieve the set of substitutions required when accessing a member of the Objective-C receiver type t...
Definition: Type.cpp:1303
QualType getParamType(unsigned i) const
Definition: Type.h:3339
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3129
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:3371
bool containsUnexpandedParameterPack() const
Determines whether this template name contains an unexpanded parameter pack (for C++0x variadic templ...
QualType desugar() const
Definition: Type.h:2257
bool isFloatingPoint() const
Definition: Type.h:2129
const Type * operator->() const
Definition: Type.h:675
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1028
param_type_iterator param_type_begin() const
Definition: Type.h:3468
This class wraps the list of protocol qualifiers.
Definition: Type.h:4848
bool isUnspecializedAsWritten() const
Determine whether this object type is "unspecialized" as written, meaning that it has no type argumen...
Definition: Type.h:5324
QualType desugar() const
Definition: Type.h:2612
QualType desugar() const
Definition: Type.h:3821
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: Type.h:2503
ASTContext * Context
void addObjCLifetime(ObjCLifetime type)
Definition: Type.h:316
QualType desugar() const
Definition: Type.h:2730
ObjCProtocolDecl ** getProtocolStorage()
Definition: Type.h:4855
bool getNoCallerSavedRegs() const
Definition: Type.h:2995
bool isMoreQualifiedThan(QualType Other) const
Determine whether this type is more qualified than the other given type, requiring exact equality for...
Definition: Type.h:5633
bool hasFastQualifiers() const
Definition: Type.h:366
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:414
bool isFunctionPointerType() const
Definition: Type.h:5730
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3110
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
Definition: Type.h:720
bool hasUnaligned() const
Definition: Type.h:280
bool hasSizedVLAType() const
Whether this type involves a variable-length array type with a definite size.
Definition: Type.cpp:3793
bool isRealFloatingType() const
Floating point categories.
Definition: Type.cpp:1837
bool isObjCInertUnsafeUnretainedType() const
Was this type written with the special inert-in-MRC __unsafe_unretained qualifier?
Definition: Type.cpp:518
bool hasVolatile() const
Definition: Type.h:244
static void * getAsVoidPointer(::clang::ExtQuals *P)
Definition: Type.h:64
bool isSignedInteger() const
Definition: Type.h:2121
bool isKindOfType() const
Whether this is a "__kindof" type.
Definition: Type.h:5309
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:2700
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
Definition: Type.cpp:1760
int * Depth
static bool classof(const Type *T)
Definition: Type.h:2219
RecordType(TypeClass TC, RecordDecl *D)
Definition: Type.h:3788
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:5497
QualType desugar() const
Definition: Type.h:4927
static bool classof(const Type *T)
Definition: Type.h:4625
const Type * getTypePtrOrNull() const
Definition: Type.h:5493
Qualifiers::GC getObjCGCAttr() const
Definition: Type.h:1230
QualType getSuperClassType() const
Retrieve the type of the superclass of this object type.
Definition: Type.h:5093
QualType getPointeeType() const
Definition: Type.h:2341
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
Definition: Type.h:5975
void addVolatile()
Definition: Type.h:249
Expr - This represents one expression.
Definition: Expr.h:105
bool isQueueT() const
Definition: Type.h:5845
static void getAsStringInternal(SplitQualType split, std::string &out, const PrintingPolicy &policy)
Definition: Type.h:971
static bool classof(const Type *T)
Definition: Type.h:3087
bool isSugared() const
Definition: Type.h:4825
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition: Type.h:4516
bool isSugared() const
Definition: Type.h:2569
QualType desugar() const
Remove a single level of sugar.
Definition: Type.h:4609
bool isAnyComplexType() const
Definition: Type.h:5775
static Kind getNullabilityAttrKind(NullabilityKind kind)
Retrieve the attribute kind corresponding to the given nullability kind.
Definition: Type.h:3941
bool isObjCClassType() const
Definition: Type.h:5813
Declaration of a template type parameter.
Internal representation of canonical, dependent decltype(expr) types.
Definition: Type.h:3693
bool hasObjCGCAttr() const
Definition: Type.h:1229
bool hasCVRQualifiers() const
Definition: Type.h:258
friend bool operator!=(const QualType &LHS, const QualType &RHS)
Definition: Type.h:939
QualType getLocallyUnqualifiedSingleStepDesugaredType() const
Pull a single level of sugar off of this locally-unqualified type.
Definition: Type.cpp:223
static bool classof(const Type *T)
Definition: Type.h:4929
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:4503
bool isLocalConstQualified() const
Determine whether this particular QualType instance has the "const" qualifier set, without looking through typedefs that may have added "const" at a different level.
Definition: Type.h:690
static bool classof(const Type *T)
Definition: Type.h:4272
bool isAtomicType() const
Definition: Type.h:5794
bool isUnsignedInteger() const
Definition: Type.h:2125
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3966
void setAddressSpace(unsigned space)
Definition: Type.h:353
bool isTypeAlias() const
Determine if this template specialization type is for a type alias template that has been substituted...
Definition: Type.h:4367
ObjCSubstitutionContext
The kind of type we are substituting Objective-C type arguments into.
Definition: Type.h:589
bool isObjCGCWeak() const
true when Type is objc's weak.
Definition: Type.h:1018
llvm::iterator_range< param_type_iterator > param_type_range
Definition: Type.h:3463
bool isSugared() const
Definition: Type.h:3726
bool isInstantiationDependent() const
Determines whether this is a template name that somehow depends on a template parameter.
Expr * getUnderlyingExpr() const
Definition: Type.h:3609
bool isVariableArrayType() const
Definition: Type.h:5760
bool hasObjCLifetime() const
Definition: Type.h:1232
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:4606
bool getNoReturn() const
Definition: Type.h:2993
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:3347
bool isSugared() const
Definition: Type.h:5404
ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &O)
Definition: Type.h:3243
static bool classof(const Type *T)
Definition: Type.h:3565
#define bool
Definition: stdbool.h:31
void removeFastQualifiers(unsigned mask)
Definition: Type.h:372
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2294
bool isFloatingType() const
Definition: Type.cpp:1821
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3699
ArrayType(TypeClass tc, QualType et, QualType can, ArraySizeModifier sm, unsigned tq, bool ContainsUnexpandedParameterPack)
Definition: Type.h:2516
Represents a C++ template name within the type system.
Definition: TemplateName.h:176
Represents the type decltype(expr) (C++11).
Definition: Type.h:3667
void removeLocalConst()
Definition: Type.h:5583
void removeLocalVolatile()
Definition: Type.h:5591
bool isFunctionNoProtoType() const
Definition: Type.h:1683
unsigned getTypeQuals() const
Definition: Type.h:3062
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
Definition: Type.h:910
There is no noexcept specifier.
Definition: Type.h:3393
bool isObjCIdType() const
Definition: Type.h:5808
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:559
Kind getAttrKind() const
Definition: Type.h:3906
static inline::clang::Type * getFromVoidPointer(void *P)
Definition: Type.h:56
SourceLocation getAttributeLoc() const
Definition: Type.h:2774
static Optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
Definition: Type.cpp:3663
A unary type transform, which is a type constructed from another.
Definition: Type.h:3708
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:1797
static bool classof(const Type *T)
Definition: Type.h:2399
bool hasTrailingReturn() const
Definition: Type.h:3452
Qualifiers Quals
The local qualifiers.
Definition: Type.h:564
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Definition: Type.h:5298
static bool classof(const Type *T)
Definition: Type.h:2595
ScalarTypeKind
Definition: Type.h:1781
SourceLocation getRBracketLoc() const
Definition: Type.h:2727
bool isSugared() const
Definition: Type.h:4673
A helper class for Type nodes having an ElaboratedTypeKeyword.
Definition: Type.h:4525
QualType withFastQualifiers(unsigned TQs) const
Definition: Type.h:825
QualType desugar() const
Definition: Type.h:2179
Represents a GCC generic vector type.
Definition: Type.h:2797
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2407
ExtParameterInfo withABI(ParameterABI kind) const
Definition: Type.h:3165
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Definition: Type.h:4166
QualType getElementType() const
Definition: Type.h:2821
bool isStrictSupersetOf(Qualifiers Other) const
Determine whether this set of qualifiers is a strict superset of another set of qualifiers, not considering qualifier compatibility.
Definition: Type.cpp:31
bool isComplexIntegerType() const
Definition: Type.cpp:402
The result type of a method or function.
static bool classof(const Type *T)
Definition: Type.h:4840
void removeLocalCVRQualifiers(unsigned Mask)
Definition: Type.h:5595
unsigned getLocalCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers local to this particular QualType instan...
Definition: Type.h:745
bool IsEnumDeclComplete(EnumDecl *ED)
Check if the given decl is complete.
Definition: Decl.h:4006
bool isUnsignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is unsigned or an enumeration types whose underlying ...
Definition: Type.cpp:1800
static ExtParameterInfo getFromOpaqueValue(unsigned char data)
Definition: Type.h:3196
void removeCVRQualifiers(unsigned mask)
Definition: Type.h:264
static StringRef getIdentifier(const Token &Tok)
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Definition: opencl-c.h:82
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:4083
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:232
bool isTemplateTypeParmType() const
Definition: Type.h:5869
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3750
QualType desugar() const
Definition: Type.h:2570
bool isObjectType() const
Determine whether this type is an object type.
Definition: Type.h:1610
QualType desugar() const
Definition: Type.h:3914
bool hasObjCLifetime() const
Definition: Type.h:308
bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const
SourceRange getBracketsRange() const
Definition: Type.h:2725
bool hasUnnamedOrLocalType() const
Whether this type is or contains a local or unnamed type.
Definition: Type.cpp:3426
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee)
Definition: Type.h:2349
unsigned getLocalFastQualifiers() const
Definition: Type.h:646
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
Definition: Type.h:3072
static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType)
Definition: Type.h:4618
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Definition: Type.h:4077
bool isDependentSizedArrayType() const
Definition: Type.h:5763
const IdentifierInfo * getIdentifier() const
Definition: Type.h:4726
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Definition: Type.cpp:3834
CanThrowResult
Possible results from evaluation of a noexcept expression.
There is no lifetime qualification on this type.
Definition: Type.h:135
exception_iterator exception_begin() const
Definition: Type.h:3480
ExtInfo withRegParm(unsigned RegParm) const
Definition: Type.h:3036
bool hasNoexceptExceptionSpec() const
Return whether this function has a noexcept exception spec.
Definition: Type.h:3383
static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, ExtInfo Info)
Definition: Type.h:3113
void setNumProtocols(unsigned N)
Definition: Type.h:4858
is AltiVec 'vector Pixel'
Definition: Type.h:2802
#define false
Definition: stdbool.h:33
The "struct" keyword.
Definition: Type.h:4490
Assigning into this object requires the old value to be released and the new value to be retained...
Definition: Type.h:146
Kind
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition: Type.h:5956
not a target-specific vector type
Definition: Type.h:2800
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3220
static bool classof(const Type *T)
Definition: Type.h:3684
iterator begin() const
Definition: Type.h:4378
QualType desugar() const
Definition: Type.h:2674
static bool classof(const Type *T)
Definition: Type.h:3598
QualType desugar() const
Definition: Type.h:4826
void setVolatile(bool flag)
Definition: Type.h:245
bool isAlignValT() const
Definition: Type.cpp:2307
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:3255
const char * getNameAsCString(const PrintingPolicy &Policy) const
Definition: Type.h:2107
Encodes a location in the source.
QualType desugar() const
Definition: Type.h:5436
bool hasIntegerRepresentation() const
Determine whether this type has an integer representation of some sort, e.g., it is an integer type o...
Definition: Type.cpp:1637
void addVolatile()
Add the volatile type qualifier to this QualType.
Definition: Type.h:787
bool isObjCIdOrClassType() const
True if this is equivalent to the 'id' or 'Class' type,.
Definition: Type.h:5292
Sugar for parentheses used when specifying types.
Definition: Type.h:2193
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:3810
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5489
Visibility getVisibility() const
Determine the visibility of this type.
Definition: Type.h:1991
QualType getElementType() const
Definition: Type.h:2176
QualType withCVRQualifiers(unsigned CVR) const
Definition: Type.h:802
bool isConstant(const ASTContext &Ctx) const
Definition: Type.h:753
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition: Type.h:3458
SourceLocation getLBracketLoc() const
Definition: Type.h:2726
Represents typeof(type), a GCC extension.
Definition: Type.h:3643
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:5165
static bool classof(const Type *T)
Definition: Type.h:2302
bool isComplexType() const
isComplexType() does not include complex integers (a GCC extension).
Definition: Type.cpp:396
bool isBuiltinType() const
Helper methods to distinguish type categories.
Definition: Type.h:5766
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
Definition: Type.h:4259
static bool classof(const Type *T)
Definition: Type.h:2490
const std::string ID
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2816
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6.7.5p3.
Definition: Type.cpp:1920
static bool isPlaceholderTypeKind(Kind K)
Determines whether the given kind corresponds to a placeholder type.
Definition: Type.h:2134
static bool classof(const Type *T)
Definition: Type.h:2732
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2583
static QualType getUnderlyingType(const SubRegion *R)
bool isObjCUnqualifiedIdOrClass() const
Definition: Type.h:5040
static void Profile(llvm::FoldingSetNodeID &ID, QualType T)
Definition: Type.h:5380
VectorKind getVectorKind() const
Definition: Type.h:2830
unsigned getAddressSpace() const
Definition: Type.h:1238
QualType withConst() const
Definition: Type.h:782
bool qual_empty() const
Definition: Type.h:5349
bool isRestrict() const
Definition: Type.h:3077
bool isObjCBuiltinType() const
Definition: Type.h:5823
bool isObjCClassOrClassKindOfType() const
Whether the type is Objective-C 'Class' or a __kindof type of an Class type, e.g., __kindof Class <NSCopying>.
Definition: Type.cpp:495
bool isSugared() const
Definition: Type.h:3107
bool isSugared() const
Definition: Type.h:2430
bool isVisibilityExplicit() const
Return true if the visibility was explicitly set is the code.
Definition: Type.h:1996
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4090
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
static void Profile(llvm::FoldingSetNodeID &ID, const Type *BaseType, Qualifiers Quals)
Definition: Type.h:1246
No ref-qualifier was provided.
Definition: Type.h:1260
ExtInfo withNoReturn(bool noReturn) const
Definition: Type.h:3015
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
Definition: Type.cpp:1663
bool isNothrow(const ASTContext &Ctx, bool ResultIfDependent=false) const
Determine whether this function type has a non-throwing exception specification.
Definition: Type.h:3437
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
Definition: Type.cpp:190
bool isObjCBoxableRecordType() const
Definition: Type.cpp:367
bool isSugared() const
Definition: Type.h:3595
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
FunctionDecl * getExceptionSpecTemplate() const
If this function type has an uninstantiated exception specification, this is the function whose excep...
Definition: Type.h:3426
void Profile(llvm::FoldingSetNodeID &ID)
Definition: TemplateName.h:294
bool hasConstFields() const
Definition: Type.h:3800
AttributedTypeBitfields AttributedTypeBits
Definition: Type.h:1503
SplitQualType getSplitDesugaredType() const
Definition: Type.h:914
static void Profile(llvm::FoldingSetNodeID &ID, QualType Deduced, AutoTypeKeyword Keyword, bool IsDependent)
Definition: Type.h:4228
ExceptionSpecInfo(ExceptionSpecificationType EST)
Definition: Type.h:3215
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: Type.h:6000
is AltiVec 'vector bool ...'
Definition: Type.h:2803
bool acceptsObjCTypeParams() const
Determines if this is an ObjC interface type that may accept type parameters.
Definition: Type.cpp:1385
bool isSpecializedAsWritten() const
Determine whether this object type was written with type arguments.
Definition: Type.h:5059
qual_iterator qual_begin() const
Definition: Type.h:5343
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
Definition: Type.h:1258
bool isReserveIDT() const
Definition: Type.h:5849
bool isMemberDataPointer() const
Returns true if the member type (i.e.
Definition: Type.h:2471
TypedefNameDecl * getDecl() const
Definition: Type.h:3593
QualType desugar() const
Definition: Type.h:5405
bool isObjCQualifiedClassType() const
True if this is equivalent to 'Class.
Definition: Type.h:5304
is AltiVec vector
Definition: Type.h:2801
SourceLocation getBegin() const
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:6105
static bool classof(const Type *T)
Definition: Type.h:3805
Qualifiers & operator-=(Qualifiers R)
Definition: Type.h:518
bool isVectorType() const
Definition: Type.h:5778
qual_range quals() const
Definition: Type.h:4874
ObjCProtocolDecl * getProtocol(unsigned I) const
Fetch a protocol by index.
Definition: Type.h:4887
friend bool operator!=(ExtParameterInfo lhs, ExtParameterInfo rhs)
Definition: Type.h:3205
static bool isVectorSizeTooLarge(unsigned NumElements)
Definition: Type.h:2823
bool isPromotableIntegerType() const
More type predicates useful for type checking/promotion.
Definition: Type.cpp:2325
bool isMemberFunctionPointerType() const
Definition: Type.h:5739
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:4396
An rvalue ref-qualifier was provided (&&).
Definition: Type.h:1264
Assigning into this object requires a lifetime extension.
Definition: Type.h:152
void removeObjCGCAttr()
Definition: Type.h:292
void addFastQualifiers(unsigned TQs)
Definition: Type.h:806
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:5559
UTTKind getUTTKind() const
Definition: Type.h:3732
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:665
void setVariablyModified(bool VM=true)
Definition: Type.h:1548
ParameterABI
Kinds of parameter ABI.
Definition: Specifiers.h:298
QualType desugar() const
Definition: Type.h:4035
bool isSugared() const
Definition: Type.h:3913
ObjCTypeParamDecl * getDecl() const
Definition: Type.h:4938
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type...
Definition: Type.cpp:1627
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5377
bool isObjCQualifiedClass() const
Definition: Type.h:5048
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2308
bool isFunctionProtoType() const
Definition: Type.h:1684
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:4437
QualType getPointeeType() const
Definition: Type.h:2238
Represents a pack expansion of types.
Definition: Type.h:4787
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Definition: Type.h:5076
Defines various enumerations that describe declaration and type specifiers.
Expr * getSizeExpr() const
Definition: Type.h:2720
const char * getTypeClassName() const
Definition: Type.cpp:2514
static unsigned getMaxSizeBits(const ASTContext &Context)
Determine the maximum number of active bits that an array's size can require, which limits the maximu...
Definition: Type.cpp:111
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2682
bool isStdByteType() const
Definition: Type.cpp:2316
friend bool operator!=(SplitQualType a, SplitQualType b)
Definition: Type.h:579
Represents a template argument.
Definition: TemplateBase.h:40
static bool classof(const Type *T)
Definition: Type.h:3823
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons...
Definition: Type.h:2272
TagTypeKind
The kind of a tag type.
Definition: Type.h:4488
QualType desugar() const
Definition: Type.h:3563
not evaluated yet, for special member function
A qualifier set is used to build a set of qualifiers.
Definition: Type.h:5455
Qualifiers withoutObjCLifetime() const
Definition: Type.h:302
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1215
bool isAggregateType() const
Determines whether the type is a C++ aggregate type or C aggregate or union type. ...
Definition: Type.cpp:1906
void setContainsUnexpandedParameterPack(bool PP=true)
Definition: Type.h:1550
StringRef Name
Definition: USRFinder.cpp:123
static bool classof(const Type *T)
Definition: Type.h:3119
TypeWithKeywordBitfields TypeWithKeywordBits
Definition: Type.h:1509
bool isDependent() const
Determines whether this is a dependent template name.
bool isSugared() const
Definition: Type.h:2827
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchers.h:2126
void removeLocalFastQualifiers()
Definition: Type.h:817
bool hasLocalNonFastQualifiers() const
Determine whether this particular QualType instance has any "non-fast" qualifiers, e.g., those that are stored in an ExtQualType instance.
Definition: Type.h:730
static bool classof(const Type *T)
Definition: Type.h:4152
static bool classof(const Type *T)
Definition: Type.h:3617
QualType IgnoreParens() const
Returns the specified type after dropping any outer-level parentheses.
Definition: Type.h:929
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:328
bool getProducesResult() const
Definition: Type.h:2994
bool hasNonTrivialObjCLifetime() const
True if the lifetime is neither None or ExplicitNone.
Definition: Type.h:323
TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can)
Definition: Type.h:3582
QualType getEquivalentType() const
Definition: Type.h:3911
StreamedQualTypeHelper(const QualType &T, const PrintingPolicy &Policy, const Twine &PlaceHolder, unsigned Indentation)
Definition: Type.h:985
void dump() const
Definition: ASTDumper.cpp:2525
bool isParameterPack() const
Definition: Type.h:4026
bool isStandardLayoutType() const
Test if this type is a standard-layout type.
Definition: Type.cpp:2220
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3497
void setConst(bool flag)
Definition: Type.h:238
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:537
The "union" keyword introduces the elaborated-type-specifier.
Definition: Type.h:4509
CallingConv getCC() const
Definition: Type.h:3003
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
Definition: Type.h:5462
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2783
param_type_iterator param_type_end() const
Definition: Type.h:3471
The "class" keyword introduces the elaborated-type-specifier.
Definition: Type.h:4511
friend raw_ostream & operator<<(raw_ostream &OS, const StreamedQualTypeHelper &SQT)
Definition: Type.h:990
ReferenceTypeBitfields ReferenceTypeBits
Definition: Type.h:1508
EnumDecl - Represents an enum.
Definition: Decl.h:3102
bool isSugared() const
Definition: Type.h:2209
FunctionType::ExtInfo getFunctionExtInfo(const Type &t)
Definition: Type.h:5614
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2389
QualType(const ExtQuals *Ptr, unsigned Quals)
Definition: Type.h:643
detail::InMemoryDirectory::const_iterator E
The maximum supported address space number.
Definition: Type.h:158
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2442
unsigned getNumProtocols() const
Return the number of qualifying protocols in this type, or 0 if there are none.
Definition: Type.h:4882
QualType getModifiedType() const
Definition: Type.h:3910
bool isHalfType() const
Definition: Type.h:5912
bool isSugared() const
Definition: Type.h:4479
void setCVRQualifiers(unsigned mask)
Definition: Type.h:260
bool isSamplerT() const
Definition: Type.h:5833
static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New)
Definition: Type.h:2297
bool isLValueReferenceType() const
Definition: Type.h:5724
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern, Optional< unsigned > NumExpansions)
Definition: Type.h:4832
QualType desugar() const
Definition: Type.h:4088
unsigned char getOpaqueValue() const
Definition: Type.h:3195
bool isCanonicalAsParam() const
Definition: Type.h:5537
bool isCurrentInstantiation() const
True if this template specialization type matches a current instantiation in the context in which it ...
Definition: Type.h:4348
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4037
static bool classof(const Type *T)
Definition: Type.h:2779
void addConsistentQualifiers(Qualifiers qs)
Add the qualifiers from the given set to this set, given that they don't conflict.
Definition: Type.h:433
const RecordType * getAsStructureType() const
Definition: Type.cpp:430
bool isWideCharType() const
Definition: Type.cpp:1703
bool isRValueReferenceType() const
Definition: Type.h:5727
void addConst()
Definition: Type.h:242
bool isVisibilityExplicit() const
Definition: Visibility.h:84
void removeCVRQualifiers()
Definition: Type.h:268
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:5235
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Definition: Type.h:5662
static void Profile(llvm::FoldingSetNodeID &ID, QualType T, bool isRead)
Definition: Type.h:5442
Represents a pointer to an Objective C object.
Definition: Type.h:5220
Pointer to a block type.
Definition: Type.h:2327
static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType, UTTKind UKind)
Definition: Type.h:3754
static bool classof(const Type *T)
Definition: Type.h:4050
QualType desugar() const
Definition: Type.h:2210
bool isObjCObjectType() const
Definition: Type.h:5787
bool operator!=(Qualifiers Other) const
Definition: Type.h:502
FunctionTypeBitfields FunctionTypeBits
Definition: Type.h:1506
QualType getLocalUnqualifiedType() const
Return this type with all of the instance-specific qualifiers removed, but without removing any quali...
Definition: Type.h:849
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:3230
const QualType * exception_iterator
Definition: Type.h:3475
const TemplateArgument * getArgs() const
Retrieve the template arguments.
Definition: Type.h:4385
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:3784
qual_iterator qual_end() const
Definition: Type.h:5346
Complex values, per C99 6.2.5p11.
Definition: Type.h:2164
static bool classof(const Type *T)
Definition: Type.h:3534
static bool classof(const Type *T)
Definition: Type.h:2188
qual_iterator qual_end() const
Definition: Type.h:4876
bool isObjCNSObjectType() const
Definition: Type.cpp:3733
llvm::iterator_range< qual_iterator > qual_range
Definition: Type.h:4872
QualType withExactLocalFastQualifiers(unsigned TQs) const
Definition: Type.h:833
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:6042
AutoTypeBitfields AutoTypeBits
Definition: Type.h:1504
unsigned getTypeQuals() const
Definition: Type.h:3454
bool isAddressSpaceOverlapping(const PointerType &other) const
Returns true if address spaces of pointers overlap.
Definition: Type.h:2248
QualType getCanonicalType() const
Definition: Type.h:5528
static bool classof(const Type *T)
Definition: Type.h:3977
bool isSpecifierType() const
Returns true if this type can be represented by some set of type specifiers.
Definition: Type.cpp:2357
ObjCInterfaceDecl * getInterfaceDecl() const
If this pointer points to an Objective @interface type, gets the declaration for that interface...
Definition: Type.h:5275
const ObjCObjectType * getAsObjCQualifiedInterfaceType() const
Definition: Type.cpp:1484
void addRestrict()
Definition: Type.h:256
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2620
static bool classof(const Type *T)
Definition: Type.h:2433
bool isObjCQualifiedIdType() const
Definition: Type.h:5798
VectorTypeBitfields VectorTypeBits
Definition: Type.h:1510
std::integral_constant< bool, std::is_same< T, ArrayType >::value||std::is_base_of< ArrayType, T >::value > TypeIsArrayType
Definition: Type.h:6039
static bool classof(const Type *T)
Definition: Type.h:4687
bool isFunctionType() const
Definition: Type.h:5709
ExtVectorType - Extended vector type.
Definition: Type.h:2858
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:4738
QualType getInnerType() const
Definition: Type.h:2207
const TemplateArgument * getArgs() const
Retrieve the template arguments.
Definition: Type.h:4729
The noexcept specifier evaluates to false.
Definition: Type.h:3396
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2360
friend bool operator==(ExtParameterInfo lhs, ExtParameterInfo rhs)
Definition: Type.h:3202
bool isSugared() const
Definition: Type.h:5105
bool isSugared() const
Definition: Type.h:3802
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1548
QualType desugar() const
Remove a single level of sugar.
Definition: Type.h:3658
unsigned getAddressSpace() const
Definition: Type.h:335
QualType withRestrict() const
Definition: Type.h:798
QualType desugar() const
Definition: Type.h:2479
bool isRestrictQualified() const
Determine whether this type is restrict-qualified.
Definition: Type.h:5553
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
static bool classof(const Type *T)
Definition: Type.h:5447
static bool classof(const Type *T)
Definition: Type.h:4415
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
NestedNameSpecifier * getQualifier() const
Definition: Type.h:4725
The "class" keyword.
Definition: Type.h:4496
GC getObjCGCAttr() const
Definition: Type.h:288
const Expr * Replacement
Definition: AttributeList.h:59
QualType getPointeeType() const
Definition: Type.h:2381
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:3222
Linkage getLinkage() const
Determine the linkage of this type.
Definition: Type.cpp:3421
The type-property cache.
Definition: Type.cpp:3286
bool isDeduced() const
Definition: Type.h:4195
bool isSugared() const
Definition: Type.h:2673
bool hasNonTrivialObjCLifetime() const
Definition: Type.h:1032
bool isReadOnly() const
Definition: Type.h:5451
bool isObjCGCStrong() const
true when Type is objc's strong.
Definition: Type.h:1023
const Type * getClass() const
Definition: Type.h:2475
bool isSugared() const
Definition: Type.h:3562
TypeBitfields TypeBits
Definition: Type.h:1501
Reading or writing from this object requires a barrier call.
Definition: Type.h:149
Expr * NoexceptExpr
Noexcept expression, if this is EST_ComputedNoexcept.
Definition: Type.h:3224
bool isSugared() const
Definition: Type.h:4926
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, const Type *Class)
Definition: Type.h:2484
bool isSugared() const
Definition: Type.h:2478
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:3838
bool hasAddressSpace() const
Definition: Type.h:334
Represents a type parameter type in Objective C.
Definition: Type.h:4900
bool isBlockCompatibleObjCPointerType(ASTContext &ctx) const
Definition: Type.cpp:3674
bool isObjCClassType() const
True if this is equivalent to the 'Class' type, i.e.
Definition: Type.h:5287
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4261
bool isCARCBridgableType() const
Determine whether the given type T is a "bridgeable" C type.
Definition: Type.cpp:3784
QualType desugar() const
Definition: Type.h:5106
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:5569
bool isSugared() const
Definition: Type.h:2414
bool isClkEventT() const
Definition: Type.h:5841
std::pair< const Type *, Qualifiers > asPair() const
Definition: Type.h:572
Represents a C++ struct/union/class.
Definition: DeclCXX.h:267
void removeLocalRestrict()
Definition: Type.h:5587
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4695
bool hasQualifiers() const
Return true if the set contains any qualifiers.
Definition: Type.h:394
bool isObjCObjectPointerType() const
Definition: Type.h:5784
bool isPlaceholderType() const
Test for a type which does not represent an actual type-system type but is instead used as a placehol...
Definition: Type.h:5880
static bool classof(const Type *T)
Definition: Type.h:4100
Represents a C array with an unspecified size.
Definition: Type.h:2603
bool isObjCUnqualifiedClass() const
Definition: Type.h:5039
SplitQualType(const Type *ty, Qualifiers qs)
Definition: Type.h:567
void removeFastQualifiers()
Definition: Type.h:376
bool isCompoundType() const
Tests whether the type is categorized as a compound type.
Definition: Type.h:5687
The parameter type of a method or function.
QualType desugar() const
Definition: Type.h:2292
ArraySizeModifier getSizeModifier() const
Definition: Type.h:2532
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:4537
bool qual_empty() const
Definition: Type.h:4878
DeducedType(TypeClass TC, QualType DeducedAsType, bool IsDependent, bool IsInstantiationDependent, bool ContainsParameterPack)
Definition: Type.h:4168
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
Definition: Type.h:3379
bool isPipeType() const
Definition: Type.h:5860
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition: Type.h:5982
The "enum" keyword.
Definition: Type.h:4498
bool isEventT() const
Definition: Type.h:5837
qual_range quals() const
Definition: Type.h:5342
QualType desugar() const
Definition: Type.h:2431
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3634
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:44
This class is used for builtin types like 'int'.
Definition: Type.h:2084
exception_iterator exception_end() const
Definition: Type.h:3484
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:82
SourceLocation getLBracketLoc() const
Definition: Type.h:2670
QualType getAdjustedType() const
Definition: Type.h:2289
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3569
bool isArrayType() const
Definition: Type.h:5751
static bool classof(const Type *T)
Definition: Type.h:3663
void removeLocalFastQualifiers(unsigned Mask)
Definition: Type.h:818
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Definition: Type.h:4814
bool isSpecializedAsWritten() const
Whether this type is specialized, meaning that it has type arguments.
Definition: Type.h:5315
QualType getDecayedType() const
Definition: Type.h:2316
static Qualifiers fromCVRMask(unsigned CVR)
Definition: Type.h:213
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it's either not been deduced or was deduce...
Definition: Type.h:4192
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2380
bool getHasRegParm() const
Definition: Type.h:2996
TagDecl * getDecl() const
Definition: Type.cpp:2986
bool isObjCIndirectLifetimeType() const
Definition: Type.cpp:3756
bool isIncompleteArrayType() const
Definition: Type.h:5757
unsigned getAddressSpaceAttributePrintValue() const
Get the address space attribute value to be printed by diagnostics.
Definition: Type.h:340
SourceLocation getRBracketLoc() const
Definition: Type.h:2671
Qualifiers getQualifiers() const
Definition: Type.h:1227
void initialize(ArrayRef< ObjCProtocolDecl * > protocols)
Definition: Type.h:4861
bool isObjCId() const
Definition: Type.h:5032
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:1007
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4297
bool hasRestrict() const
Definition: Type.h:251
QualType desugar() const
Definition: Type.h:5362
QualType getElementType() const
Definition: Type.h:5432
QualType getElementType() const
Definition: Type.h:2531
static void Profile(llvm::FoldingSetNodeID &ID, QualType Element)
Definition: Type.h:2184
bool hasQualifiers() const
Determine whether this type has any qualifiers.
Definition: Type.h:5564
ExtParameterInfo withIsConsumed(bool consumed) const
Definition: Type.h:3176
ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc, bool producesResult, bool noCallerSavedRegs)
Definition: Type.h:2976
SplitQualType getSingleStepDesugaredType() const
Definition: Type.h:5482
bool isObjCClass() const
Definition: Type.h:5035
RecordType(const RecordDecl *D)
Definition: Type.h:3786
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
Definition: Type.h:3375
static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, ArraySizeModifier SizeMod, unsigned TypeQuals)
Definition: Type.h:2625
static SimpleType getSimplifiedValue(::clang::QualType Val)
Definition: Type.h:1139
QualType desugar() const
Definition: Type.h:2913
We can encode up to four bits in the low bits of a type pointer, but there are many more type qualifi...
Definition: Type.h:1195
IdentifierInfo * getIdentifier() const
Definition: Type.h:4135
static StringRef getNameForCallConv(CallingConv CC)
Definition: Type.cpp:2634
#define true
Definition: stdbool.h:32
bool isObjCARCBridgableType() const
Determine whether the given type T is a "bridgable" Objective-C type, which is either an Objective-C ...
Definition: Type.cpp:3779
BuiltinTypeBitfields BuiltinTypeBits
Definition: Type.h:1505
static int getNumericAccessorIdx(char c)
Definition: Type.h:2872
bool isInterfaceType() const
Definition: Type.cpp:372
A trivial tuple used to represent a source range.
VectorType(QualType vecType, unsigned nElements, QualType canonType, VectorKind vecKind)
Definition: Type.cpp:171
static void * getAsVoidPointer(::clang::Type *P)
Definition: Type.h:55
bool isSugared() const
Definition: Type.h:2729
bool isVolatile() const
Definition: Type.h:3076
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
bool isNonOverloadPlaceholderType() const
Determines whether this type is a placeholder type other than Overload.
Definition: Type.h:2154
void addFastQualifiers(unsigned mask)
Definition: Type.h:379
StringRef getName(const PrintingPolicy &Policy) const
Definition: Type.cpp:2524
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:2648
bool isObjCIdOrObjectKindOfType(const ASTContext &ctx, const ObjCObjectType *&bound) const
Whether the type is Objective-C 'id' or a __kindof type of an object type, e.g., __kindof NSView * or...
Definition: Type.cpp:469
bool isClassType() const
Definition: Type.cpp:357
bool isArithmeticType() const
Definition: Type.cpp:1852
No keyword precedes the qualified type name.
Definition: Type.h:4518
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], or an enum decl which has a signed representation.
Definition: Type.cpp:1744
bool isSugared() const
Definition: Type.h:5361
static int getAccessorIdx(char c, bool isNumericAccessor)
Definition: Type.h:2900
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5407
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition: Type.h:5548
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g., it is an signed integer type or a vector.
Definition: Type.cpp:1774
bool isUnspecializedAsWritten() const
Determine whether this object type is "unspecialized" as written, meaning that it has no type argumen...
Definition: Type.h:5069
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:683
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:4749
bool isSugared() const
Definition: Type.h:2291
bool isSugared() const
Definition: Type.h:5179
const ObjCObjectPointerType * getAsObjCInterfacePointerType() const
Definition: Type.cpp:1525
friend bool operator==(SplitQualType a, SplitQualType b)
Definition: Type.h:576
bool isObjCIdType() const
True if this is equivalent to the 'id' type, i.e.
Definition: Type.h:5281
The noexcept specifier is dependent.
Definition: Type.h:3395
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.h:3661
static void Profile(llvm::FoldingSetNodeID &ID, UnresolvedUsingTypenameDecl *D)
Definition: Type.h:3572
void removeAddressSpace()
Definition: Type.h:358
Optional< NullabilityKind > getNullability(const ASTContext &context) const
Determine the nullability of the given type.
Definition: Type.cpp:3526
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
Definition: Type.h:923
QualifierCollector(Qualifiers Qs=Qualifiers())
Definition: Type.h:5457
The "__interface" keyword introduces the elaborated-type-specifier.
Definition: Type.h:4507
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:4818
ArrayRef< QualType > exceptions() const
Definition: Type.h:3477
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:2553
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3254
static bool classof(const Type *T)
Definition: Type.h:5108
A class which abstracts out some details necessary for making a call.
Definition: Type.h:2948
bool isObjCQualifiedInterfaceType() const
Definition: Type.cpp:1494
static bool classof(const Type *T)
Definition: Type.h:2915
ScalarTypeKind getScalarTypeKind() const
Given that this is a scalar type, classify it.
Definition: Type.cpp:1867
bool isSugared() const
Definition: Type.h:3528
bool hasPointerRepresentation() const
Whether this type is represented natively as a pointer.
Definition: Type.h:5991
static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *TTPDecl)
Definition: Type.h:4041
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4224
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:5928
QualType desugar() const
Definition: Type.h:3803
const ObjCObjectPointerType * getAsObjCQualifiedIdType() const
Definition: Type.cpp:1498
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:536
bool hasAddressSpace() const
Definition: Type.h:1237
bool isAddressSpaceSupersetOf(Qualifiers other) const
Returns true if this address space is a superset of the other one.
Definition: Type.h:450
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:5516
bool isInnerRef() const
Definition: Type.h:2378
bool isPointerType() const
Definition: Type.h:5712
bool isConst() const
Definition: Type.h:3075
unsigned getNumExceptions() const
Definition: Type.h:3401
static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template, QualType Deduced, bool IsDependent)
Definition: Type.h:4265
bool isIncompleteOrObjectType() const
Return true if this is an incomplete or object type, in other words, not a function type...
Definition: Type.h:1605
bool isSugared() const
Definition: Type.h:2611