clang 19.0.0git
Type.h
Go to the documentation of this file.
1//===- Type.h - C Language Family Type Representation -----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// C Language Family Type Representation
11///
12/// This file defines the clang::Type interface and subclasses, used to
13/// represent types for languages in the C family.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_CLANG_AST_TYPE_H
18#define LLVM_CLANG_AST_TYPE_H
19
27#include "clang/Basic/LLVM.h"
28#include "clang/Basic/Linkage.h"
33#include "llvm/ADT/APInt.h"
34#include "llvm/ADT/APSInt.h"
35#include "llvm/ADT/ArrayRef.h"
36#include "llvm/ADT/FoldingSet.h"
37#include "llvm/ADT/PointerIntPair.h"
38#include "llvm/ADT/PointerUnion.h"
39#include "llvm/ADT/STLForwardCompat.h"
40#include "llvm/ADT/StringRef.h"
41#include "llvm/ADT/Twine.h"
42#include "llvm/ADT/iterator_range.h"
43#include "llvm/Support/Casting.h"
44#include "llvm/Support/Compiler.h"
45#include "llvm/Support/ErrorHandling.h"
46#include "llvm/Support/PointerLikeTypeTraits.h"
47#include "llvm/Support/TrailingObjects.h"
48#include "llvm/Support/type_traits.h"
49#include <cassert>
50#include <cstddef>
51#include <cstdint>
52#include <cstring>
53#include <optional>
54#include <string>
55#include <type_traits>
56#include <utility>
57
58namespace clang {
59
60class BTFTypeTagAttr;
61class ExtQuals;
62class QualType;
63class ConceptDecl;
64class TagDecl;
65class TemplateParameterList;
66class Type;
67
68enum {
71};
72
73namespace serialization {
74 template <class T> class AbstractTypeReader;
75 template <class T> class AbstractTypeWriter;
76}
77
78} // namespace clang
79
80namespace llvm {
81
82 template <typename T>
84 template<>
86 static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
87
88 static inline ::clang::Type *getFromVoidPointer(void *P) {
89 return static_cast< ::clang::Type*>(P);
90 }
91
92 static constexpr int NumLowBitsAvailable = clang::TypeAlignmentInBits;
93 };
94
95 template<>
97 static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
98
99 static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
100 return static_cast< ::clang::ExtQuals*>(P);
101 }
102
103 static constexpr int NumLowBitsAvailable = clang::TypeAlignmentInBits;
104 };
105
106} // namespace llvm
107
108namespace clang {
109
110class ASTContext;
111template <typename> class CanQual;
112class CXXRecordDecl;
113class DeclContext;
114class EnumDecl;
115class Expr;
116class ExtQualsTypeCommonBase;
117class FunctionDecl;
118class IdentifierInfo;
119class NamedDecl;
120class ObjCInterfaceDecl;
121class ObjCProtocolDecl;
122class ObjCTypeParamDecl;
123struct PrintingPolicy;
124class RecordDecl;
125class Stmt;
126class TagDecl;
127class TemplateArgument;
128class TemplateArgumentListInfo;
129class TemplateArgumentLoc;
130class TemplateTypeParmDecl;
131class TypedefNameDecl;
132class UnresolvedUsingTypenameDecl;
133class UsingShadowDecl;
134
135using CanQualType = CanQual<Type>;
136
137// Provide forward declarations for all of the *Type classes.
138#define TYPE(Class, Base) class Class##Type;
139#include "clang/AST/TypeNodes.inc"
140
141/// The collection of all-type qualifiers we support.
142/// Clang supports five independent qualifiers:
143/// * C99: const, volatile, and restrict
144/// * MS: __unaligned
145/// * Embedded C (TR18037): address spaces
146/// * Objective C: the GC attributes (none, weak, or strong)
148public:
149 enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
150 Const = 0x1,
151 Restrict = 0x2,
152 Volatile = 0x4,
154 };
155
156 enum GC {
159 Strong
160 };
161
163 /// There is no lifetime qualification on this type.
165
166 /// This object can be modified without requiring retains or
167 /// releases.
169
170 /// Assigning into this object requires the old value to be
171 /// released and the new value to be retained. The timing of the
172 /// release of the old value is inexact: it may be moved to
173 /// immediately after the last known point where the value is
174 /// live.
176
177 /// Reading or writing from this object requires a barrier call.
179
180 /// Assigning into this object requires a lifetime extension.
182 };
183
184 enum {
185 /// The maximum supported address space number.
186 /// 23 bits should be enough for anyone.
187 MaxAddressSpace = 0x7fffffu,
188
189 /// The width of the "fast" qualifier mask.
191
192 /// The fast qualifier mask.
193 FastMask = (1 << FastWidth) - 1
194 };
195
196 /// Returns the common set of qualifiers while removing them from
197 /// the given sets.
199 // If both are only CVR-qualified, bit operations are sufficient.
200 if (!(L.Mask & ~CVRMask) && !(R.Mask & ~CVRMask)) {
201 Qualifiers Q;
202 Q.Mask = L.Mask & R.Mask;
203 L.Mask &= ~Q.Mask;
204 R.Mask &= ~Q.Mask;
205 return Q;
206 }
207
208 Qualifiers Q;
209 unsigned CommonCRV = L.getCVRQualifiers() & R.getCVRQualifiers();
210 Q.addCVRQualifiers(CommonCRV);
211 L.removeCVRQualifiers(CommonCRV);
212 R.removeCVRQualifiers(CommonCRV);
213
214 if (L.getObjCGCAttr() == R.getObjCGCAttr()) {
218 }
219
220 if (L.getObjCLifetime() == R.getObjCLifetime()) {
224 }
225
226 if (L.getAddressSpace() == R.getAddressSpace()) {
230 }
231 return Q;
232 }
233
234 static Qualifiers fromFastMask(unsigned Mask) {
235 Qualifiers Qs;
236 Qs.addFastQualifiers(Mask);
237 return Qs;
238 }
239
240 static Qualifiers fromCVRMask(unsigned CVR) {
241 Qualifiers Qs;
242 Qs.addCVRQualifiers(CVR);
243 return Qs;
244 }
245
246 static Qualifiers fromCVRUMask(unsigned CVRU) {
247 Qualifiers Qs;
248 Qs.addCVRUQualifiers(CVRU);
249 return Qs;
250 }
251
252 // Deserialize qualifiers from an opaque representation.
253 static Qualifiers fromOpaqueValue(unsigned opaque) {
254 Qualifiers Qs;
255 Qs.Mask = opaque;
256 return Qs;
257 }
258
259 // Serialize these qualifiers into an opaque representation.
260 unsigned getAsOpaqueValue() const {
261 return Mask;
262 }
263
264 bool hasConst() const { return Mask & Const; }
265 bool hasOnlyConst() const { return Mask == Const; }
266 void removeConst() { Mask &= ~Const; }
267 void addConst() { Mask |= Const; }
269 Qualifiers Qs = *this;
270 Qs.addConst();
271 return Qs;
272 }
273
274 bool hasVolatile() const { return Mask & Volatile; }
275 bool hasOnlyVolatile() const { return Mask == Volatile; }
276 void removeVolatile() { Mask &= ~Volatile; }
277 void addVolatile() { Mask |= Volatile; }
279 Qualifiers Qs = *this;
280 Qs.addVolatile();
281 return Qs;
282 }
283
284 bool hasRestrict() const { return Mask & Restrict; }
285 bool hasOnlyRestrict() const { return Mask == Restrict; }
286 void removeRestrict() { Mask &= ~Restrict; }
287 void addRestrict() { Mask |= Restrict; }
289 Qualifiers Qs = *this;
290 Qs.addRestrict();
291 return Qs;
292 }
293
294 bool hasCVRQualifiers() const { return getCVRQualifiers(); }
295 unsigned getCVRQualifiers() const { return Mask & CVRMask; }
296 unsigned getCVRUQualifiers() const { return Mask & (CVRMask | UMask); }
297
298 void setCVRQualifiers(unsigned mask) {
299 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
300 Mask = (Mask & ~CVRMask) | mask;
301 }
302 void removeCVRQualifiers(unsigned mask) {
303 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
304 Mask &= ~mask;
305 }
308 }
309 void addCVRQualifiers(unsigned mask) {
310 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
311 Mask |= mask;
312 }
313 void addCVRUQualifiers(unsigned mask) {
314 assert(!(mask & ~CVRMask & ~UMask) && "bitmask contains non-CVRU bits");
315 Mask |= mask;
316 }
317
318 bool hasUnaligned() const { return Mask & UMask; }
319 void setUnaligned(bool flag) {
320 Mask = (Mask & ~UMask) | (flag ? UMask : 0);
321 }
322 void removeUnaligned() { Mask &= ~UMask; }
323 void addUnaligned() { Mask |= UMask; }
324
325 bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
326 GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
328 Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
329 }
332 assert(type);
334 }
336 Qualifiers qs = *this;
337 qs.removeObjCGCAttr();
338 return qs;
339 }
341 Qualifiers qs = *this;
343 return qs;
344 }
346 Qualifiers qs = *this;
348 return qs;
349 }
350
351 bool hasObjCLifetime() const { return Mask & LifetimeMask; }
353 return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
354 }
356 Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
357 }
360 assert(type);
361 assert(!hasObjCLifetime());
362 Mask |= (type << LifetimeShift);
363 }
364
365 /// True if the lifetime is neither None or ExplicitNone.
367 ObjCLifetime lifetime = getObjCLifetime();
368 return (lifetime > OCL_ExplicitNone);
369 }
370
371 /// True if the lifetime is either strong or weak.
373 ObjCLifetime lifetime = getObjCLifetime();
374 return (lifetime == OCL_Strong || lifetime == OCL_Weak);
375 }
376
377 bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
379 return static_cast<LangAS>(Mask >> AddressSpaceShift);
380 }
383 }
384 /// Get the address space attribute value to be printed by diagnostics.
386 auto Addr = getAddressSpace();
387 // This function is not supposed to be used with language specific
388 // address spaces. If that happens, the diagnostic message should consider
389 // printing the QualType instead of the address space value.
391 if (Addr != LangAS::Default)
392 return toTargetAddressSpace(Addr);
393 // TODO: The diagnostic messages where Addr may be 0 should be fixed
394 // since it cannot differentiate the situation where 0 denotes the default
395 // address space or user specified __attribute__((address_space(0))).
396 return 0;
397 }
399 assert((unsigned)space <= MaxAddressSpace);
400 Mask = (Mask & ~AddressSpaceMask)
401 | (((uint32_t) space) << AddressSpaceShift);
402 }
405 assert(space != LangAS::Default);
406 setAddressSpace(space);
407 }
408
409 // Fast qualifiers are those that can be allocated directly
410 // on a QualType object.
411 bool hasFastQualifiers() const { return getFastQualifiers(); }
412 unsigned getFastQualifiers() const { return Mask & FastMask; }
413 void setFastQualifiers(unsigned mask) {
414 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
415 Mask = (Mask & ~FastMask) | mask;
416 }
417 void removeFastQualifiers(unsigned mask) {
418 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
419 Mask &= ~mask;
420 }
423 }
424 void addFastQualifiers(unsigned mask) {
425 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
426 Mask |= mask;
427 }
428
429 /// Return true if the set contains any qualifiers which require an ExtQuals
430 /// node to be allocated.
431 bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
433 Qualifiers Quals = *this;
434 Quals.setFastQualifiers(0);
435 return Quals;
436 }
437
438 /// Return true if the set contains any qualifiers.
439 bool hasQualifiers() const { return Mask; }
440 bool empty() const { return !Mask; }
441
442 /// Add the qualifiers from the given set to this set.
444 // If the other set doesn't have any non-boolean qualifiers, just
445 // bit-or it in.
446 if (!(Q.Mask & ~CVRMask))
447 Mask |= Q.Mask;
448 else {
449 Mask |= (Q.Mask & CVRMask);
450 if (Q.hasAddressSpace())
452 if (Q.hasObjCGCAttr())
454 if (Q.hasObjCLifetime())
456 }
457 }
458
459 /// Remove the qualifiers from the given set from this set.
461 // If the other set doesn't have any non-boolean qualifiers, just
462 // bit-and the inverse in.
463 if (!(Q.Mask & ~CVRMask))
464 Mask &= ~Q.Mask;
465 else {
466 Mask &= ~(Q.Mask & CVRMask);
467 if (getObjCGCAttr() == Q.getObjCGCAttr())
469 if (getObjCLifetime() == Q.getObjCLifetime())
471 if (getAddressSpace() == Q.getAddressSpace())
473 }
474 }
475
476 /// Add the qualifiers from the given set to this set, given that
477 /// they don't conflict.
479 assert(getAddressSpace() == qs.getAddressSpace() ||
480 !hasAddressSpace() || !qs.hasAddressSpace());
481 assert(getObjCGCAttr() == qs.getObjCGCAttr() ||
482 !hasObjCGCAttr() || !qs.hasObjCGCAttr());
483 assert(getObjCLifetime() == qs.getObjCLifetime() ||
484 !hasObjCLifetime() || !qs.hasObjCLifetime());
485 Mask |= qs.Mask;
486 }
487
488 /// Returns true if address space A is equal to or a superset of B.
489 /// OpenCL v2.0 defines conversion rules (OpenCLC v2.0 s6.5.5) and notion of
490 /// overlapping address spaces.
491 /// CL1.1 or CL1.2:
492 /// every address space is a superset of itself.
493 /// CL2.0 adds:
494 /// __generic is a superset of any address space except for __constant.
496 // Address spaces must match exactly.
497 return A == B ||
498 // Otherwise in OpenCLC v2.0 s6.5.5: every address space except
499 // for __constant can be used as __generic.
501 // We also define global_device and global_host address spaces,
502 // to distinguish global pointers allocated on host from pointers
503 // allocated on device, which are a subset of __global.
508 // Consider pointer size address spaces to be equivalent to default.
511 // Default is a superset of SYCL address spaces.
512 (A == LangAS::Default &&
516 // In HIP device compilation, any cuda address space is allowed
517 // to implicitly cast into the default address space.
518 (A == LangAS::Default &&
520 B == LangAS::cuda_shared));
521 }
522
523 /// Returns true if the address space in these qualifiers is equal to or
524 /// a superset of the address space in the argument qualifiers.
527 }
528
529 /// Determines if these qualifiers compatibly include another set.
530 /// Generally this answers the question of whether an object with the other
531 /// qualifiers can be safely used as an object with these qualifiers.
532 bool compatiblyIncludes(Qualifiers other) const {
533 return isAddressSpaceSupersetOf(other) &&
534 // ObjC GC qualifiers can match, be added, or be removed, but can't
535 // be changed.
536 (getObjCGCAttr() == other.getObjCGCAttr() || !hasObjCGCAttr() ||
537 !other.hasObjCGCAttr()) &&
538 // ObjC lifetime qualifiers must match exactly.
539 getObjCLifetime() == other.getObjCLifetime() &&
540 // CVR qualifiers may subset.
541 (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) &&
542 // U qualifier may superset.
543 (!other.hasUnaligned() || hasUnaligned());
544 }
545
546 /// Determines if these qualifiers compatibly include another set of
547 /// qualifiers from the narrow perspective of Objective-C ARC lifetime.
548 ///
549 /// One set of Objective-C lifetime qualifiers compatibly includes the other
550 /// if the lifetime qualifiers match, or if both are non-__weak and the
551 /// including set also contains the 'const' qualifier, or both are non-__weak
552 /// and one is None (which can only happen in non-ARC modes).
554 if (getObjCLifetime() == other.getObjCLifetime())
555 return true;
556
557 if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak)
558 return false;
559
560 if (getObjCLifetime() == OCL_None || other.getObjCLifetime() == OCL_None)
561 return true;
562
563 return hasConst();
564 }
565
566 /// Determine whether this set of qualifiers is a strict superset of
567 /// another set of qualifiers, not considering qualifier compatibility.
569
570 bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
571 bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
572
573 explicit operator bool() const { return hasQualifiers(); }
574
576 addQualifiers(R);
577 return *this;
578 }
579
580 // Union two qualifier sets. If an enumerated qualifier appears
581 // in both sets, use the one from the right.
583 L += R;
584 return L;
585 }
586
589 return *this;
590 }
591
592 /// Compute the difference between two qualifier sets.
594 L -= R;
595 return L;
596 }
597
598 std::string getAsString() const;
599 std::string getAsString(const PrintingPolicy &Policy) const;
600
601 static std::string getAddrSpaceAsString(LangAS AS);
602
603 bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const;
604 void print(raw_ostream &OS, const PrintingPolicy &Policy,
605 bool appendSpaceIfNonEmpty = false) const;
606
607 void Profile(llvm::FoldingSetNodeID &ID) const {
608 ID.AddInteger(Mask);
609 }
610
611private:
612 // bits: |0 1 2|3|4 .. 5|6 .. 8|9 ... 31|
613 // |C R V|U|GCAttr|Lifetime|AddressSpace|
614 uint32_t Mask = 0;
615
616 static const uint32_t UMask = 0x8;
617 static const uint32_t UShift = 3;
618 static const uint32_t GCAttrMask = 0x30;
619 static const uint32_t GCAttrShift = 4;
620 static const uint32_t LifetimeMask = 0x1C0;
621 static const uint32_t LifetimeShift = 6;
622 static const uint32_t AddressSpaceMask =
623 ~(CVRMask | UMask | GCAttrMask | LifetimeMask);
624 static const uint32_t AddressSpaceShift = 9;
625};
626
628 Qualifiers Quals;
629 bool HasAtomic;
630
631public:
632 QualifiersAndAtomic() : HasAtomic(false) {}
633 QualifiersAndAtomic(Qualifiers Quals, bool HasAtomic)
634 : Quals(Quals), HasAtomic(HasAtomic) {}
635
636 operator Qualifiers() const { return Quals; }
637
638 bool hasVolatile() const { return Quals.hasVolatile(); }
639 bool hasConst() const { return Quals.hasConst(); }
640 bool hasRestrict() const { return Quals.hasRestrict(); }
641 bool hasAtomic() const { return HasAtomic; }
642
643 void addVolatile() { Quals.addVolatile(); }
644 void addConst() { Quals.addConst(); }
645 void addRestrict() { Quals.addRestrict(); }
646 void addAtomic() { HasAtomic = true; }
647
648 void removeVolatile() { Quals.removeVolatile(); }
649 void removeConst() { Quals.removeConst(); }
650 void removeRestrict() { Quals.removeRestrict(); }
651 void removeAtomic() { HasAtomic = false; }
652
654 return {Quals.withVolatile(), HasAtomic};
655 }
656 QualifiersAndAtomic withConst() { return {Quals.withConst(), HasAtomic}; }
658 return {Quals.withRestrict(), HasAtomic};
659 }
660 QualifiersAndAtomic withAtomic() { return {Quals, true}; }
661
663 Quals += RHS;
664 return *this;
665 }
666};
667
668/// A std::pair-like structure for storing a qualified type split
669/// into its local qualifiers and its locally-unqualified type.
671 /// The locally-unqualified type.
672 const Type *Ty = nullptr;
673
674 /// The local qualifiers.
676
677 SplitQualType() = default;
678 SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {}
679
680 SplitQualType getSingleStepDesugaredType() const; // end of this file
681
682 // Make std::tie work.
683 std::pair<const Type *,Qualifiers> asPair() const {
684 return std::pair<const Type *, Qualifiers>(Ty, Quals);
685 }
686
688 return a.Ty == b.Ty && a.Quals == b.Quals;
689 }
691 return a.Ty != b.Ty || a.Quals != b.Quals;
692 }
693};
694
695/// The kind of type we are substituting Objective-C type arguments into.
696///
697/// The kind of substitution affects the replacement of type parameters when
698/// no concrete type information is provided, e.g., when dealing with an
699/// unspecialized type.
701 /// An ordinary type.
702 Ordinary,
703
704 /// The result type of a method or function.
705 Result,
706
707 /// The parameter type of a method or function.
708 Parameter,
709
710 /// The type of a property.
711 Property,
712
713 /// The superclass of a type.
715};
716
717/// The kind of 'typeof' expression we're after.
718enum class TypeOfKind : uint8_t {
719 Qualified,
721};
722
723/// A (possibly-)qualified type.
724///
725/// For efficiency, we don't store CV-qualified types as nodes on their
726/// own: instead each reference to a type stores the qualifiers. This
727/// greatly reduces the number of nodes we need to allocate for types (for
728/// example we only need one for 'int', 'const int', 'volatile int',
729/// 'const volatile int', etc).
730///
731/// As an added efficiency bonus, instead of making this a pair, we
732/// just store the two bits we care about in the low bits of the
733/// pointer. To handle the packing/unpacking, we make QualType be a
734/// simple wrapper class that acts like a smart pointer. A third bit
735/// indicates whether there are extended qualifiers present, in which
736/// case the pointer points to a special structure.
737class QualType {
738 friend class QualifierCollector;
739
740 // Thankfully, these are efficiently composable.
741 llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>,
743
744 const ExtQuals *getExtQualsUnsafe() const {
745 return Value.getPointer().get<const ExtQuals*>();
746 }
747
748 const Type *getTypePtrUnsafe() const {
749 return Value.getPointer().get<const Type*>();
750 }
751
752 const ExtQualsTypeCommonBase *getCommonPtr() const {
753 assert(!isNull() && "Cannot retrieve a NULL type pointer");
754 auto CommonPtrVal = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
755 CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
756 return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
757 }
758
759public:
760 QualType() = default;
761 QualType(const Type *Ptr, unsigned Quals) : Value(Ptr, Quals) {}
762 QualType(const ExtQuals *Ptr, unsigned Quals) : Value(Ptr, Quals) {}
763
764 unsigned getLocalFastQualifiers() const { return Value.getInt(); }
765 void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
766
767 bool UseExcessPrecision(const ASTContext &Ctx);
768
769 /// Retrieves a pointer to the underlying (unqualified) type.
770 ///
771 /// This function requires that the type not be NULL. If the type might be
772 /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
773 const Type *getTypePtr() const;
774
775 const Type *getTypePtrOrNull() const;
776
777 /// Retrieves a pointer to the name of the base type.
779
780 /// Divides a QualType into its unqualified type and a set of local
781 /// qualifiers.
782 SplitQualType split() const;
783
784 void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
785
786 static QualType getFromOpaquePtr(const void *Ptr) {
787 QualType T;
788 T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
789 return T;
790 }
791
792 const Type &operator*() const {
793 return *getTypePtr();
794 }
795
796 const Type *operator->() const {
797 return getTypePtr();
798 }
799
800 bool isCanonical() const;
801 bool isCanonicalAsParam() const;
802
803 /// Return true if this QualType doesn't point to a type yet.
804 bool isNull() const {
805 return Value.getPointer().isNull();
806 }
807
808 // Determines if a type can form `T&`.
809 bool isReferenceable() const;
810
811 /// Determine whether this particular QualType instance has the
812 /// "const" qualifier set, without looking through typedefs that may have
813 /// added "const" at a different level.
816 }
817
818 /// Determine whether this type is const-qualified.
819 bool isConstQualified() const;
820
826 };
827 /// Determine whether instances of this type can be placed in immutable
828 /// storage.
829 /// If ExcludeCtor is true, the duration when the object's constructor runs
830 /// will not be considered. The caller will need to verify that the object is
831 /// not written to during its construction. ExcludeDtor works similarly.
832 std::optional<NonConstantStorageReason>
833 isNonConstantStorage(const ASTContext &Ctx, bool ExcludeCtor,
834 bool ExcludeDtor);
835
836 bool isConstantStorage(const ASTContext &Ctx, bool ExcludeCtor,
837 bool ExcludeDtor) {
838 return !isNonConstantStorage(Ctx, ExcludeCtor, ExcludeDtor);
839 }
840
841 /// Determine whether this particular QualType instance has the
842 /// "restrict" qualifier set, without looking through typedefs that may have
843 /// added "restrict" at a different level.
846 }
847
848 /// Determine whether this type is restrict-qualified.
849 bool isRestrictQualified() const;
850
851 /// Determine whether this particular QualType instance has the
852 /// "volatile" qualifier set, without looking through typedefs that may have
853 /// added "volatile" at a different level.
856 }
857
858 /// Determine whether this type is volatile-qualified.
859 bool isVolatileQualified() const;
860
861 /// Determine whether this particular QualType instance has any
862 /// qualifiers, without looking through any typedefs that might add
863 /// qualifiers at a different level.
864 bool hasLocalQualifiers() const {
866 }
867
868 /// Determine whether this type has any qualifiers.
869 bool hasQualifiers() const;
870
871 /// Determine whether this particular QualType instance has any
872 /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
873 /// instance.
875 return Value.getPointer().is<const ExtQuals*>();
876 }
877
878 /// Retrieve the set of qualifiers local to this particular QualType
879 /// instance, not including any qualifiers acquired through typedefs or
880 /// other sugar.
882
883 /// Retrieve the set of qualifiers applied to this type.
885
886 /// Retrieve the set of CVR (const-volatile-restrict) qualifiers
887 /// local to this particular QualType instance, not including any qualifiers
888 /// acquired through typedefs or other sugar.
889 unsigned getLocalCVRQualifiers() const {
890 return getLocalFastQualifiers();
891 }
892
893 /// Retrieve the set of CVR (const-volatile-restrict) qualifiers
894 /// applied to this type.
895 unsigned getCVRQualifiers() const;
896
897 bool isConstant(const ASTContext& Ctx) const {
898 return QualType::isConstant(*this, Ctx);
899 }
900
901 /// Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
902 bool isPODType(const ASTContext &Context) const;
903
904 /// Return true if this is a POD type according to the rules of the C++98
905 /// standard, regardless of the current compilation's language.
906 bool isCXX98PODType(const ASTContext &Context) const;
907
908 /// Return true if this is a POD type according to the more relaxed rules
909 /// of the C++11 standard, regardless of the current compilation's language.
910 /// (C++0x [basic.types]p9). Note that, unlike
911 /// CXXRecordDecl::isCXX11StandardLayout, this takes DRs into account.
912 bool isCXX11PODType(const ASTContext &Context) const;
913
914 /// Return true if this is a trivial type per (C++0x [basic.types]p9)
915 bool isTrivialType(const ASTContext &Context) const;
916
917 /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
918 bool isTriviallyCopyableType(const ASTContext &Context) const;
919
920 /// Return true if this is a trivially copyable type
921 bool isTriviallyCopyConstructibleType(const ASTContext &Context) const;
922
923 /// Return true if this is a trivially relocatable type.
924 bool isTriviallyRelocatableType(const ASTContext &Context) const;
925
926 /// Return true if this is a trivially equality comparable type.
927 bool isTriviallyEqualityComparableType(const ASTContext &Context) const;
928
929 /// Returns true if it is a class and it might be dynamic.
930 bool mayBeDynamicClass() const;
931
932 /// Returns true if it is not a class or if the class might not be dynamic.
933 bool mayBeNotDynamicClass() const;
934
935 /// Returns true if it is a WebAssembly Reference Type.
936 bool isWebAssemblyReferenceType() const;
937
938 /// Returns true if it is a WebAssembly Externref Type.
939 bool isWebAssemblyExternrefType() const;
940
941 /// Returns true if it is a WebAssembly Funcref Type.
942 bool isWebAssemblyFuncrefType() const;
943
944 // Don't promise in the API that anything besides 'const' can be
945 // easily added.
946
947 /// Add the `const` type qualifier to this QualType.
948 void addConst() {
950 }
953 }
954
955 /// Add the `volatile` type qualifier to this QualType.
956 void addVolatile() {
958 }
961 }
962
963 /// Add the `restrict` qualifier to this QualType.
964 void addRestrict() {
966 }
969 }
970
971 QualType withCVRQualifiers(unsigned CVR) const {
972 return withFastQualifiers(CVR);
973 }
974
975 void addFastQualifiers(unsigned TQs) {
976 assert(!(TQs & ~Qualifiers::FastMask)
977 && "non-fast qualifier bits set in mask!");
978 Value.setInt(Value.getInt() | TQs);
979 }
980
981 void removeLocalConst();
982 void removeLocalVolatile();
983 void removeLocalRestrict();
984
985 void removeLocalFastQualifiers() { Value.setInt(0); }
986 void removeLocalFastQualifiers(unsigned Mask) {
987 assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
988 Value.setInt(Value.getInt() & ~Mask);
989 }
990
991 // Creates a type with the given qualifiers in addition to any
992 // qualifiers already on this type.
993 QualType withFastQualifiers(unsigned TQs) const {
994 QualType T = *this;
995 T.addFastQualifiers(TQs);
996 return T;
997 }
998
999 // Creates a type with exactly the given fast qualifiers, removing
1000 // any existing fast qualifiers.
1003 }
1004
1005 // Removes fast qualifiers, but leaves any extended qualifiers in place.
1007 QualType T = *this;
1009 return T;
1010 }
1011
1012 QualType getCanonicalType() const;
1013
1014 /// Return this type with all of the instance-specific qualifiers
1015 /// removed, but without removing any qualifiers that may have been applied
1016 /// through typedefs.
1018
1019 /// Retrieve the unqualified variant of the given type,
1020 /// removing as little sugar as possible.
1021 ///
1022 /// This routine looks through various kinds of sugar to find the
1023 /// least-desugared type that is unqualified. For example, given:
1024 ///
1025 /// \code
1026 /// typedef int Integer;
1027 /// typedef const Integer CInteger;
1028 /// typedef CInteger DifferenceType;
1029 /// \endcode
1030 ///
1031 /// Executing \c getUnqualifiedType() on the type \c DifferenceType will
1032 /// desugar until we hit the type \c Integer, which has no qualifiers on it.
1033 ///
1034 /// The resulting type might still be qualified if it's sugar for an array
1035 /// type. To strip qualifiers even from within a sugared array type, use
1036 /// ASTContext::getUnqualifiedArrayType.
1037 ///
1038 /// Note: In C, the _Atomic qualifier is special (see C23 6.2.5p32 for
1039 /// details), and it is not stripped by this function. Use
1040 /// getAtomicUnqualifiedType() to strip qualifiers including _Atomic.
1041 inline QualType getUnqualifiedType() const;
1042
1043 /// Retrieve the unqualified variant of the given type, removing as little
1044 /// sugar as possible.
1045 ///
1046 /// Like getUnqualifiedType(), but also returns the set of
1047 /// qualifiers that were built up.
1048 ///
1049 /// The resulting type might still be qualified if it's sugar for an array
1050 /// type. To strip qualifiers even from within a sugared array type, use
1051 /// ASTContext::getUnqualifiedArrayType.
1053
1054 /// Determine whether this type is more qualified than the other
1055 /// given type, requiring exact equality for non-CVR qualifiers.
1057
1058 /// Determine whether this type is at least as qualified as the other
1059 /// given type, requiring exact equality for non-CVR qualifiers.
1061
1063
1064 /// Determine the type of a (typically non-lvalue) expression with the
1065 /// specified result type.
1066 ///
1067 /// This routine should be used for expressions for which the return type is
1068 /// explicitly specified (e.g., in a cast or call) and isn't necessarily
1069 /// an lvalue. It removes a top-level reference (since there are no
1070 /// expressions of reference type) and deletes top-level cvr-qualifiers
1071 /// from non-class types (in C++) or all types (in C).
1072 QualType getNonLValueExprType(const ASTContext &Context) const;
1073
1074 /// Remove an outer pack expansion type (if any) from this type. Used as part
1075 /// of converting the type of a declaration to the type of an expression that
1076 /// references that expression. It's meaningless for an expression to have a
1077 /// pack expansion type.
1079
1080 /// Return the specified type with any "sugar" removed from
1081 /// the type. This takes off typedefs, typeof's etc. If the outer level of
1082 /// the type is already concrete, it returns it unmodified. This is similar
1083 /// to getting the canonical type, but it doesn't remove *all* typedefs. For
1084 /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
1085 /// concrete.
1086 ///
1087 /// Qualifiers are left in place.
1088 QualType getDesugaredType(const ASTContext &Context) const {
1089 return getDesugaredType(*this, Context);
1090 }
1091
1093 return getSplitDesugaredType(*this);
1094 }
1095
1096 /// Return the specified type with one level of "sugar" removed from
1097 /// the type.
1098 ///
1099 /// This routine takes off the first typedef, typeof, etc. If the outer level
1100 /// of the type is already concrete, it returns it unmodified.
1102 return getSingleStepDesugaredTypeImpl(*this, Context);
1103 }
1104
1105 /// Returns the specified type after dropping any
1106 /// outer-level parentheses.
1108 if (isa<ParenType>(*this))
1109 return QualType::IgnoreParens(*this);
1110 return *this;
1111 }
1112
1113 /// Indicate whether the specified types and qualifiers are identical.
1114 friend bool operator==(const QualType &LHS, const QualType &RHS) {
1115 return LHS.Value == RHS.Value;
1116 }
1117 friend bool operator!=(const QualType &LHS, const QualType &RHS) {
1118 return LHS.Value != RHS.Value;
1119 }
1120 friend bool operator<(const QualType &LHS, const QualType &RHS) {
1121 return LHS.Value < RHS.Value;
1122 }
1123
1124 static std::string getAsString(SplitQualType split,
1125 const PrintingPolicy &Policy) {
1126 return getAsString(split.Ty, split.Quals, Policy);
1127 }
1128 static std::string getAsString(const Type *ty, Qualifiers qs,
1129 const PrintingPolicy &Policy);
1130
1131 std::string getAsString() const;
1132 std::string getAsString(const PrintingPolicy &Policy) const;
1133
1134 void print(raw_ostream &OS, const PrintingPolicy &Policy,
1135 const Twine &PlaceHolder = Twine(),
1136 unsigned Indentation = 0) const;
1137
1138 static void print(SplitQualType split, raw_ostream &OS,
1139 const PrintingPolicy &policy, const Twine &PlaceHolder,
1140 unsigned Indentation = 0) {
1141 return print(split.Ty, split.Quals, OS, policy, PlaceHolder, Indentation);
1142 }
1143
1144 static void print(const Type *ty, Qualifiers qs,
1145 raw_ostream &OS, const PrintingPolicy &policy,
1146 const Twine &PlaceHolder,
1147 unsigned Indentation = 0);
1148
1149 void getAsStringInternal(std::string &Str,
1150 const PrintingPolicy &Policy) const;
1151
1152 static void getAsStringInternal(SplitQualType split, std::string &out,
1153 const PrintingPolicy &policy) {
1154 return getAsStringInternal(split.Ty, split.Quals, out, policy);
1155 }
1156
1157 static void getAsStringInternal(const Type *ty, Qualifiers qs,
1158 std::string &out,
1159 const PrintingPolicy &policy);
1160
1162 const QualType &T;
1163 const PrintingPolicy &Policy;
1164 const Twine &PlaceHolder;
1165 unsigned Indentation;
1166
1167 public:
1169 const Twine &PlaceHolder, unsigned Indentation)
1170 : T(T), Policy(Policy), PlaceHolder(PlaceHolder),
1171 Indentation(Indentation) {}
1172
1173 friend raw_ostream &operator<<(raw_ostream &OS,
1174 const StreamedQualTypeHelper &SQT) {
1175 SQT.T.print(OS, SQT.Policy, SQT.PlaceHolder, SQT.Indentation);
1176 return OS;
1177 }
1178 };
1179
1181 const Twine &PlaceHolder = Twine(),
1182 unsigned Indentation = 0) const {
1183 return StreamedQualTypeHelper(*this, Policy, PlaceHolder, Indentation);
1184 }
1185
1186 void dump(const char *s) const;
1187 void dump() const;
1188 void dump(llvm::raw_ostream &OS, const ASTContext &Context) const;
1189
1190 void Profile(llvm::FoldingSetNodeID &ID) const {
1191 ID.AddPointer(getAsOpaquePtr());
1192 }
1193
1194 /// Check if this type has any address space qualifier.
1195 inline bool hasAddressSpace() const;
1196
1197 /// Return the address space of this type.
1198 inline LangAS getAddressSpace() const;
1199
1200 /// Returns true if address space qualifiers overlap with T address space
1201 /// qualifiers.
1202 /// OpenCL C defines conversion rules for pointers to different address spaces
1203 /// and notion of overlapping address spaces.
1204 /// CL1.1 or CL1.2:
1205 /// address spaces overlap iff they are they same.
1206 /// OpenCL C v2.0 s6.5.5 adds:
1207 /// __generic overlaps with any address space except for __constant.
1210 Qualifiers TQ = T.getQualifiers();
1211 // Address spaces overlap if at least one of them is a superset of another
1213 }
1214
1215 /// Returns gc attribute of this type.
1216 inline Qualifiers::GC getObjCGCAttr() const;
1217
1218 /// true when Type is objc's weak.
1219 bool isObjCGCWeak() const {
1220 return getObjCGCAttr() == Qualifiers::Weak;
1221 }
1222
1223 /// true when Type is objc's strong.
1224 bool isObjCGCStrong() const {
1226 }
1227
1228 /// Returns lifetime attribute of this type.
1230 return getQualifiers().getObjCLifetime();
1231 }
1232
1235 }
1236
1239 }
1240
1241 // true when Type is objc's weak and weak is enabled but ARC isn't.
1242 bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const;
1243
1245 /// The type does not fall into any of the following categories. Note that
1246 /// this case is zero-valued so that values of this enum can be used as a
1247 /// boolean condition for non-triviality.
1249
1250 /// The type is an Objective-C retainable pointer type that is qualified
1251 /// with the ARC __strong qualifier.
1253
1254 /// The type is an Objective-C retainable pointer type that is qualified
1255 /// with the ARC __weak qualifier.
1257
1258 /// The type is a struct containing a field whose type is not PCK_Trivial.
1261
1262 /// Functions to query basic properties of non-trivial C struct types.
1263
1264 /// Check if this is a non-trivial type that would cause a C struct
1265 /// transitively containing this type to be non-trivial to default initialize
1266 /// and return the kind.
1269
1271 /// The type does not fall into any of the following categories. Note that
1272 /// this case is zero-valued so that values of this enum can be used as a
1273 /// boolean condition for non-triviality.
1275
1276 /// The type would be trivial except that it is volatile-qualified. Types
1277 /// that fall into one of the other non-trivial cases may additionally be
1278 /// volatile-qualified.
1280
1281 /// The type is an Objective-C retainable pointer type that is qualified
1282 /// with the ARC __strong qualifier.
1284
1285 /// The type is an Objective-C retainable pointer type that is qualified
1286 /// with the ARC __weak qualifier.
1288
1289 /// The type is a struct containing a field whose type is neither
1290 /// PCK_Trivial nor PCK_VolatileTrivial.
1291 /// Note that a C++ struct type does not necessarily match this; C++ copying
1292 /// semantics are too complex to express here, in part because they depend
1293 /// on the exact constructor or assignment operator that is chosen by
1294 /// overload resolution to do the copy.
1297
1298 /// Check if this is a non-trivial type that would cause a C struct
1299 /// transitively containing this type to be non-trivial to copy and return the
1300 /// kind.
1302
1303 /// Check if this is a non-trivial type that would cause a C struct
1304 /// transitively containing this type to be non-trivial to destructively
1305 /// move and return the kind. Destructive move in this context is a C++-style
1306 /// move in which the source object is placed in a valid but unspecified state
1307 /// after it is moved, as opposed to a truly destructive move in which the
1308 /// source object is placed in an uninitialized state.
1310
1318
1319 /// Returns a nonzero value if objects of this type require
1320 /// non-trivial work to clean up after. Non-zero because it's
1321 /// conceivable that qualifiers (objc_gc(weak)?) could make
1322 /// something require destruction.
1324 return isDestructedTypeImpl(*this);
1325 }
1326
1327 /// Check if this is or contains a C union that is non-trivial to
1328 /// default-initialize, which is a union that has a member that is non-trivial
1329 /// to default-initialize. If this returns true,
1330 /// isNonTrivialToPrimitiveDefaultInitialize returns PDIK_Struct.
1332
1333 /// Check if this is or contains a C union that is non-trivial to destruct,
1334 /// which is a union that has a member that is non-trivial to destruct. If
1335 /// this returns true, isDestructedType returns DK_nontrivial_c_struct.
1337
1338 /// Check if this is or contains a C union that is non-trivial to copy, which
1339 /// is a union that has a member that is non-trivial to copy. If this returns
1340 /// true, isNonTrivialToPrimitiveCopy returns PCK_Struct.
1342
1343 /// Determine whether expressions of the given type are forbidden
1344 /// from being lvalues in C.
1345 ///
1346 /// The expression types that are forbidden to be lvalues are:
1347 /// - 'void', but not qualified void
1348 /// - function types
1349 ///
1350 /// The exact rule here is C99 6.3.2.1:
1351 /// An lvalue is an expression with an object type or an incomplete
1352 /// type other than void.
1353 bool isCForbiddenLValueType() const;
1354
1355 /// Substitute type arguments for the Objective-C type parameters used in the
1356 /// subject type.
1357 ///
1358 /// \param ctx ASTContext in which the type exists.
1359 ///
1360 /// \param typeArgs The type arguments that will be substituted for the
1361 /// Objective-C type parameters in the subject type, which are generally
1362 /// computed via \c Type::getObjCSubstitutions. If empty, the type
1363 /// parameters will be replaced with their bounds or id/Class, as appropriate
1364 /// for the context.
1365 ///
1366 /// \param context The context in which the subject type was written.
1367 ///
1368 /// \returns the resulting type.
1370 ArrayRef<QualType> typeArgs,
1371 ObjCSubstitutionContext context) const;
1372
1373 /// Substitute type arguments from an object type for the Objective-C type
1374 /// parameters used in the subject type.
1375 ///
1376 /// This operation combines the computation of type arguments for
1377 /// substitution (\c Type::getObjCSubstitutions) with the actual process of
1378 /// substitution (\c QualType::substObjCTypeArgs) for the convenience of
1379 /// callers that need to perform a single substitution in isolation.
1380 ///
1381 /// \param objectType The type of the object whose member type we're
1382 /// substituting into. For example, this might be the receiver of a message
1383 /// or the base of a property access.
1384 ///
1385 /// \param dc The declaration context from which the subject type was
1386 /// retrieved, which indicates (for example) which type parameters should
1387 /// be substituted.
1388 ///
1389 /// \param context The context in which the subject type was written.
1390 ///
1391 /// \returns the subject type after replacing all of the Objective-C type
1392 /// parameters with their corresponding arguments.
1394 const DeclContext *dc,
1395 ObjCSubstitutionContext context) const;
1396
1397 /// Strip Objective-C "__kindof" types from the given type.
1398 QualType stripObjCKindOfType(const ASTContext &ctx) const;
1399
1400 /// Remove all qualifiers including _Atomic.
1402
1403private:
1404 // These methods are implemented in a separate translation unit;
1405 // "static"-ize them to avoid creating temporary QualTypes in the
1406 // caller.
1407 static bool isConstant(QualType T, const ASTContext& Ctx);
1408 static QualType getDesugaredType(QualType T, const ASTContext &Context);
1410 static SplitQualType getSplitUnqualifiedTypeImpl(QualType type);
1411 static QualType getSingleStepDesugaredTypeImpl(QualType type,
1412 const ASTContext &C);
1413 static QualType IgnoreParens(QualType T);
1414 static DestructionKind isDestructedTypeImpl(QualType type);
1415
1416 /// Check if \param RD is or contains a non-trivial C union.
1419 static bool hasNonTrivialToPrimitiveCopyCUnion(const RecordDecl *RD);
1420};
1421
1422raw_ostream &operator<<(raw_ostream &OS, QualType QT);
1423
1424} // namespace clang
1425
1426namespace llvm {
1427
1428/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
1429/// to a specific Type class.
1430template<> struct simplify_type< ::clang::QualType> {
1431 using SimpleType = const ::clang::Type *;
1432
1434 return Val.getTypePtr();
1435 }
1436};
1437
1438// Teach SmallPtrSet that QualType is "basically a pointer".
1439template<>
1440struct PointerLikeTypeTraits<clang::QualType> {
1441 static inline void *getAsVoidPointer(clang::QualType P) {
1442 return P.getAsOpaquePtr();
1443 }
1444
1445 static inline clang::QualType getFromVoidPointer(void *P) {
1447 }
1448
1449 // Various qualifiers go in low bits.
1450 static constexpr int NumLowBitsAvailable = 0;
1451};
1452
1453} // namespace llvm
1454
1455namespace clang {
1456
1457/// Base class that is common to both the \c ExtQuals and \c Type
1458/// classes, which allows \c QualType to access the common fields between the
1459/// two.
1461 friend class ExtQuals;
1462 friend class QualType;
1463 friend class Type;
1464
1465 /// The "base" type of an extended qualifiers type (\c ExtQuals) or
1466 /// a self-referential pointer (for \c Type).
1467 ///
1468 /// This pointer allows an efficient mapping from a QualType to its
1469 /// underlying type pointer.
1470 const Type *const BaseType;
1471
1472 /// The canonical type of this type. A QualType.
1473 QualType CanonicalType;
1474
1475 ExtQualsTypeCommonBase(const Type *baseType, QualType canon)
1476 : BaseType(baseType), CanonicalType(canon) {}
1477};
1478
1479/// We can encode up to four bits in the low bits of a
1480/// type pointer, but there are many more type qualifiers that we want
1481/// to be able to apply to an arbitrary type. Therefore we have this
1482/// struct, intended to be heap-allocated and used by QualType to
1483/// store qualifiers.
1484///
1485/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
1486/// in three low bits on the QualType pointer; a fourth bit records whether
1487/// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
1488/// Objective-C GC attributes) are much more rare.
1489class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase,
1490 public llvm::FoldingSetNode {
1491 // NOTE: changing the fast qualifiers should be straightforward as
1492 // long as you don't make 'const' non-fast.
1493 // 1. Qualifiers:
1494 // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
1495 // Fast qualifiers must occupy the low-order bits.
1496 // b) Update Qualifiers::FastWidth and FastMask.
1497 // 2. QualType:
1498 // a) Update is{Volatile,Restrict}Qualified(), defined inline.
1499 // b) Update remove{Volatile,Restrict}, defined near the end of
1500 // this header.
1501 // 3. ASTContext:
1502 // a) Update get{Volatile,Restrict}Type.
1503
1504 /// The immutable set of qualifiers applied by this node. Always contains
1505 /// extended qualifiers.
1506 Qualifiers Quals;
1507
1508 ExtQuals *this_() { return this; }
1509
1510public:
1511 ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
1512 : ExtQualsTypeCommonBase(baseType,
1513 canon.isNull() ? QualType(this_(), 0) : canon),
1514 Quals(quals) {
1515 assert(Quals.hasNonFastQualifiers()
1516 && "ExtQuals created with no fast qualifiers");
1517 assert(!Quals.hasFastQualifiers()
1518 && "ExtQuals created with fast qualifiers");
1519 }
1520
1521 Qualifiers getQualifiers() const { return Quals; }
1522
1523 bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
1524 Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
1525
1526 bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); }
1528 return Quals.getObjCLifetime();
1529 }
1530
1531 bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
1532 LangAS getAddressSpace() const { return Quals.getAddressSpace(); }
1533
1534 const Type *getBaseType() const { return BaseType; }
1535
1536public:
1537 void Profile(llvm::FoldingSetNodeID &ID) const {
1538 Profile(ID, getBaseType(), Quals);
1539 }
1540
1541 static void Profile(llvm::FoldingSetNodeID &ID,
1542 const Type *BaseType,
1543 Qualifiers Quals) {
1544 assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
1545 ID.AddPointer(BaseType);
1546 Quals.Profile(ID);
1547 }
1548};
1549
1550/// The kind of C++11 ref-qualifier associated with a function type.
1551/// This determines whether a member function's "this" object can be an
1552/// lvalue, rvalue, or neither.
1554 /// No ref-qualifier was provided.
1556
1557 /// An lvalue ref-qualifier was provided (\c &).
1559
1560 /// An rvalue ref-qualifier was provided (\c &&).
1561 RQ_RValue
1563
1564/// Which keyword(s) were used to create an AutoType.
1566 /// auto
1567 Auto,
1568
1569 /// decltype(auto)
1571
1572 /// __auto_type (GNU extension)
1574};
1575
1576enum class ArraySizeModifier;
1577enum class ElaboratedTypeKeyword;
1578enum class VectorKind;
1579
1580/// The base class of the type hierarchy.
1581///
1582/// A central concept with types is that each type always has a canonical
1583/// type. A canonical type is the type with any typedef names stripped out
1584/// of it or the types it references. For example, consider:
1585///
1586/// typedef int foo;
1587/// typedef foo* bar;
1588/// 'int *' 'foo *' 'bar'
1589///
1590/// There will be a Type object created for 'int'. Since int is canonical, its
1591/// CanonicalType pointer points to itself. There is also a Type for 'foo' (a
1592/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next
1593/// there is a PointerType that represents 'int*', which, like 'int', is
1594/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical
1595/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
1596/// is also 'int*'.
1597///
1598/// Non-canonical types are useful for emitting diagnostics, without losing
1599/// information about typedefs being used. Canonical types are useful for type
1600/// comparisons (they allow by-pointer equality tests) and useful for reasoning
1601/// about whether something has a particular form (e.g. is a function type),
1602/// because they implicitly, recursively, strip all typedefs out of a type.
1603///
1604/// Types, once created, are immutable.
1605///
1606class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
1607public:
1609#define TYPE(Class, Base) Class,
1610#define LAST_TYPE(Class) TypeLast = Class
1611#define ABSTRACT_TYPE(Class, Base)
1612#include "clang/AST/TypeNodes.inc"
1613 };
1614
1615private:
1616 /// Bitfields required by the Type class.
1617 class TypeBitfields {
1618 friend class Type;
1619 template <class T> friend class TypePropertyCache;
1620
1621 /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
1622 LLVM_PREFERRED_TYPE(TypeClass)
1623 unsigned TC : 8;
1624
1625 /// Store information on the type dependency.
1626 LLVM_PREFERRED_TYPE(TypeDependence)
1627 unsigned Dependence : llvm::BitWidth<TypeDependence>;
1628
1629 /// True if the cache (i.e. the bitfields here starting with
1630 /// 'Cache') is valid.
1631 LLVM_PREFERRED_TYPE(bool)
1632 mutable unsigned CacheValid : 1;
1633
1634 /// Linkage of this type.
1635 LLVM_PREFERRED_TYPE(Linkage)
1636 mutable unsigned CachedLinkage : 3;
1637
1638 /// Whether this type involves and local or unnamed types.
1639 LLVM_PREFERRED_TYPE(bool)
1640 mutable unsigned CachedLocalOrUnnamed : 1;
1641
1642 /// Whether this type comes from an AST file.
1643 LLVM_PREFERRED_TYPE(bool)
1644 mutable unsigned FromAST : 1;
1645
1646 bool isCacheValid() const {
1647 return CacheValid;
1648 }
1649
1650 Linkage getLinkage() const {
1651 assert(isCacheValid() && "getting linkage from invalid cache");
1652 return static_cast<Linkage>(CachedLinkage);
1653 }
1654
1655 bool hasLocalOrUnnamedType() const {
1656 assert(isCacheValid() && "getting linkage from invalid cache");
1657 return CachedLocalOrUnnamed;
1658 }
1659 };
1660 enum { NumTypeBits = 8 + llvm::BitWidth<TypeDependence> + 6 };
1661
1662protected:
1663 // These classes allow subclasses to somewhat cleanly pack bitfields
1664 // into Type.
1665
1667 friend class ArrayType;
1668
1669 LLVM_PREFERRED_TYPE(TypeBitfields)
1670 unsigned : NumTypeBits;
1671
1672 /// CVR qualifiers from declarations like
1673 /// 'int X[static restrict 4]'. For function parameters only.
1674 LLVM_PREFERRED_TYPE(Qualifiers)
1675 unsigned IndexTypeQuals : 3;
1676
1677 /// Storage class qualifiers from declarations like
1678 /// 'int X[static restrict 4]'. For function parameters only.
1679 LLVM_PREFERRED_TYPE(ArraySizeModifier)
1680 unsigned SizeModifier : 3;
1681 };
1682 enum { NumArrayTypeBits = NumTypeBits + 6 };
1683
1685 friend class ConstantArrayType;
1686
1687 LLVM_PREFERRED_TYPE(ArrayTypeBitfields)
1688 unsigned : NumArrayTypeBits;
1689
1690 /// Whether we have a stored size expression.
1691 LLVM_PREFERRED_TYPE(bool)
1692 unsigned HasStoredSizeExpr : 1;
1693 };
1694
1696 friend class BuiltinType;
1697
1698 LLVM_PREFERRED_TYPE(TypeBitfields)
1699 unsigned : NumTypeBits;
1700
1701 /// The kind (BuiltinType::Kind) of builtin type this is.
1702 static constexpr unsigned NumOfBuiltinTypeBits = 9;
1703 unsigned Kind : NumOfBuiltinTypeBits;
1704 };
1705
1706 /// FunctionTypeBitfields store various bits belonging to FunctionProtoType.
1707 /// Only common bits are stored here. Additional uncommon bits are stored
1708 /// in a trailing object after FunctionProtoType.
1710 friend class FunctionProtoType;
1711 friend class FunctionType;
1712
1713 LLVM_PREFERRED_TYPE(TypeBitfields)
1714 unsigned : NumTypeBits;
1715
1716 /// Extra information which affects how the function is called, like
1717 /// regparm and the calling convention.
1718 LLVM_PREFERRED_TYPE(CallingConv)
1719 unsigned ExtInfo : 13;
1720
1721 /// The ref-qualifier associated with a \c FunctionProtoType.
1722 ///
1723 /// This is a value of type \c RefQualifierKind.
1724 LLVM_PREFERRED_TYPE(RefQualifierKind)
1725 unsigned RefQualifier : 2;
1726
1727 /// Used only by FunctionProtoType, put here to pack with the
1728 /// other bitfields.
1729 /// The qualifiers are part of FunctionProtoType because...
1730 ///
1731 /// C++ 8.3.5p4: The return type, the parameter type list and the
1732 /// cv-qualifier-seq, [...], are part of the function type.
1733 LLVM_PREFERRED_TYPE(Qualifiers)
1734 unsigned FastTypeQuals : Qualifiers::FastWidth;
1735 /// Whether this function has extended Qualifiers.
1736 LLVM_PREFERRED_TYPE(bool)
1737 unsigned HasExtQuals : 1;
1738
1739 /// The number of parameters this function has, not counting '...'.
1740 /// According to [implimits] 8 bits should be enough here but this is
1741 /// somewhat easy to exceed with metaprogramming and so we would like to
1742 /// keep NumParams as wide as reasonably possible.
1743 unsigned NumParams : 16;
1744
1745 /// The type of exception specification this function has.
1746 LLVM_PREFERRED_TYPE(ExceptionSpecificationType)
1747 unsigned ExceptionSpecType : 4;
1748
1749 /// Whether this function has extended parameter information.
1750 LLVM_PREFERRED_TYPE(bool)
1751 unsigned HasExtParameterInfos : 1;
1752
1753 /// Whether this function has extra bitfields for the prototype.
1754 LLVM_PREFERRED_TYPE(bool)
1755 unsigned HasExtraBitfields : 1;
1756
1757 /// Whether the function is variadic.
1758 LLVM_PREFERRED_TYPE(bool)
1759 unsigned Variadic : 1;
1760
1761 /// Whether this function has a trailing return type.
1762 LLVM_PREFERRED_TYPE(bool)
1763 unsigned HasTrailingReturn : 1;
1764 };
1765
1767 friend class ObjCObjectType;
1768
1769 LLVM_PREFERRED_TYPE(TypeBitfields)
1770 unsigned : NumTypeBits;
1771
1772 /// The number of type arguments stored directly on this object type.
1773 unsigned NumTypeArgs : 7;
1774
1775 /// The number of protocols stored directly on this object type.
1776 unsigned NumProtocols : 6;
1777
1778 /// Whether this is a "kindof" type.
1779 LLVM_PREFERRED_TYPE(bool)
1780 unsigned IsKindOf : 1;
1781 };
1782
1784 friend class ReferenceType;
1785
1786 LLVM_PREFERRED_TYPE(TypeBitfields)
1787 unsigned : NumTypeBits;
1788
1789 /// True if the type was originally spelled with an lvalue sigil.
1790 /// This is never true of rvalue references but can also be false
1791 /// on lvalue references because of C++0x [dcl.typedef]p9,
1792 /// as follows:
1793 ///
1794 /// typedef int &ref; // lvalue, spelled lvalue
1795 /// typedef int &&rvref; // rvalue
1796 /// ref &a; // lvalue, inner ref, spelled lvalue
1797 /// ref &&a; // lvalue, inner ref
1798 /// rvref &a; // lvalue, inner ref, spelled lvalue
1799 /// rvref &&a; // rvalue, inner ref
1800 LLVM_PREFERRED_TYPE(bool)
1801 unsigned SpelledAsLValue : 1;
1802
1803 /// True if the inner type is a reference type. This only happens
1804 /// in non-canonical forms.
1805 LLVM_PREFERRED_TYPE(bool)
1806 unsigned InnerRef : 1;
1807 };
1808
1810 friend class TypeWithKeyword;
1811
1812 LLVM_PREFERRED_TYPE(TypeBitfields)
1813 unsigned : NumTypeBits;
1814
1815 /// An ElaboratedTypeKeyword. 8 bits for efficient access.
1816 LLVM_PREFERRED_TYPE(ElaboratedTypeKeyword)
1817 unsigned Keyword : 8;
1818 };
1819
1820 enum { NumTypeWithKeywordBits = NumTypeBits + 8 };
1821
1823 friend class ElaboratedType;
1824
1825 LLVM_PREFERRED_TYPE(TypeWithKeywordBitfields)
1826 unsigned : NumTypeWithKeywordBits;
1827
1828 /// Whether the ElaboratedType has a trailing OwnedTagDecl.
1829 LLVM_PREFERRED_TYPE(bool)
1830 unsigned HasOwnedTagDecl : 1;
1831 };
1832
1834 friend class VectorType;
1836
1837 LLVM_PREFERRED_TYPE(TypeBitfields)
1838 unsigned : NumTypeBits;
1839
1840 /// The kind of vector, either a generic vector type or some
1841 /// target-specific vector type such as for AltiVec or Neon.
1842 LLVM_PREFERRED_TYPE(VectorKind)
1843 unsigned VecKind : 4;
1844 /// The number of elements in the vector.
1845 uint32_t NumElements;
1846 };
1847
1849 friend class AttributedType;
1850
1851 LLVM_PREFERRED_TYPE(TypeBitfields)
1852 unsigned : NumTypeBits;
1853
1854 LLVM_PREFERRED_TYPE(attr::Kind)
1855 unsigned AttrKind : 32 - NumTypeBits;
1856 };
1857
1859 friend class AutoType;
1860
1861 LLVM_PREFERRED_TYPE(TypeBitfields)
1862 unsigned : NumTypeBits;
1863
1864 /// Was this placeholder type spelled as 'auto', 'decltype(auto)',
1865 /// or '__auto_type'? AutoTypeKeyword value.
1866 LLVM_PREFERRED_TYPE(AutoTypeKeyword)
1867 unsigned Keyword : 2;
1868
1869 /// The number of template arguments in the type-constraints, which is
1870 /// expected to be able to hold at least 1024 according to [implimits].
1871 /// However as this limit is somewhat easy to hit with template
1872 /// metaprogramming we'd prefer to keep it as large as possible.
1873 /// At the moment it has been left as a non-bitfield since this type
1874 /// safely fits in 64 bits as an unsigned, so there is no reason to
1875 /// introduce the performance impact of a bitfield.
1876 unsigned NumArgs;
1877 };
1878
1880 friend class TypeOfType;
1881 friend class TypeOfExprType;
1882
1883 LLVM_PREFERRED_TYPE(TypeBitfields)
1884 unsigned : NumTypeBits;
1885 LLVM_PREFERRED_TYPE(bool)
1886 unsigned IsUnqual : 1; // If true: typeof_unqual, else: typeof
1887 };
1888
1890 friend class UsingType;
1891
1892 LLVM_PREFERRED_TYPE(TypeBitfields)
1893 unsigned : NumTypeBits;
1894
1895 /// True if the underlying type is different from the declared one.
1896 LLVM_PREFERRED_TYPE(bool)
1897 unsigned hasTypeDifferentFromDecl : 1;
1898 };
1899
1901 friend class TypedefType;
1902
1903 LLVM_PREFERRED_TYPE(TypeBitfields)
1904 unsigned : NumTypeBits;
1905
1906 /// True if the underlying type is different from the declared one.
1907 LLVM_PREFERRED_TYPE(bool)
1908 unsigned hasTypeDifferentFromDecl : 1;
1909 };
1910
1913
1914 LLVM_PREFERRED_TYPE(TypeBitfields)
1915 unsigned : NumTypeBits;
1916
1917 LLVM_PREFERRED_TYPE(bool)
1918 unsigned HasNonCanonicalUnderlyingType : 1;
1919
1920 // The index of the template parameter this substitution represents.
1921 unsigned Index : 15;
1922
1923 /// Represents the index within a pack if this represents a substitution
1924 /// from a pack expansion. This index starts at the end of the pack and
1925 /// increments towards the beginning.
1926 /// Positive non-zero number represents the index + 1.
1927 /// Zero means this is not substituted from an expansion.
1928 unsigned PackIndex : 16;
1929 };
1930
1933
1934 LLVM_PREFERRED_TYPE(TypeBitfields)
1935 unsigned : NumTypeBits;
1936
1937 // The index of the template parameter this substitution represents.
1938 unsigned Index : 16;
1939
1940 /// The number of template arguments in \c Arguments, which is
1941 /// expected to be able to hold at least 1024 according to [implimits].
1942 /// However as this limit is somewhat easy to hit with template
1943 /// metaprogramming we'd prefer to keep it as large as possible.
1944 unsigned NumArgs : 16;
1945 };
1946
1949
1950 LLVM_PREFERRED_TYPE(TypeBitfields)
1951 unsigned : NumTypeBits;
1952
1953 /// Whether this template specialization type is a substituted type alias.
1954 LLVM_PREFERRED_TYPE(bool)
1955 unsigned TypeAlias : 1;
1956
1957 /// The number of template arguments named in this class template
1958 /// specialization, which is expected to be able to hold at least 1024
1959 /// according to [implimits]. However, as this limit is somewhat easy to
1960 /// hit with template metaprogramming we'd prefer to keep it as large
1961 /// as possible. At the moment it has been left as a non-bitfield since
1962 /// this type safely fits in 64 bits as an unsigned, so there is no reason
1963 /// to introduce the performance impact of a bitfield.
1964 unsigned NumArgs;
1965 };
1966
1969
1970 LLVM_PREFERRED_TYPE(TypeWithKeywordBitfields)
1971 unsigned : NumTypeWithKeywordBits;
1972
1973 /// The number of template arguments named in this class template
1974 /// specialization, which is expected to be able to hold at least 1024
1975 /// according to [implimits]. However, as this limit is somewhat easy to
1976 /// hit with template metaprogramming we'd prefer to keep it as large
1977 /// as possible. At the moment it has been left as a non-bitfield since
1978 /// this type safely fits in 64 bits as an unsigned, so there is no reason
1979 /// to introduce the performance impact of a bitfield.
1980 unsigned NumArgs;
1981 };
1982
1984 friend class PackExpansionType;
1985
1986 LLVM_PREFERRED_TYPE(TypeBitfields)
1987 unsigned : NumTypeBits;
1988
1989 /// The number of expansions that this pack expansion will
1990 /// generate when substituted (+1), which is expected to be able to
1991 /// hold at least 1024 according to [implimits]. However, as this limit
1992 /// is somewhat easy to hit with template metaprogramming we'd prefer to
1993 /// keep it as large as possible. At the moment it has been left as a
1994 /// non-bitfield since this type safely fits in 64 bits as an unsigned, so
1995 /// there is no reason to introduce the performance impact of a bitfield.
1996 ///
1997 /// This field will only have a non-zero value when some of the parameter
1998 /// packs that occur within the pattern have been substituted but others
1999 /// have not.
2000 unsigned NumExpansions;
2001 };
2002
2003 union {
2004 TypeBitfields TypeBits;
2025 };
2026
2027private:
2028 template <class T> friend class TypePropertyCache;
2029
2030 /// Set whether this type comes from an AST file.
2031 void setFromAST(bool V = true) const {
2032 TypeBits.FromAST = V;
2033 }
2034
2035protected:
2036 friend class ASTContext;
2037
2040 canon.isNull() ? QualType(this_(), 0) : canon) {
2041 static_assert(sizeof(*this) <=
2042 alignof(decltype(*this)) + sizeof(ExtQualsTypeCommonBase),
2043 "changing bitfields changed sizeof(Type)!");
2044 static_assert(alignof(decltype(*this)) % TypeAlignment == 0,
2045 "Insufficient alignment!");
2046 TypeBits.TC = tc;
2047 TypeBits.Dependence = static_cast<unsigned>(Dependence);
2048 TypeBits.CacheValid = false;
2049 TypeBits.CachedLocalOrUnnamed = false;
2050 TypeBits.CachedLinkage = llvm::to_underlying(Linkage::Invalid);
2051 TypeBits.FromAST = false;
2052 }
2053
2054 // silence VC++ warning C4355: 'this' : used in base member initializer list
2055 Type *this_() { return this; }
2056
2058 TypeBits.Dependence = static_cast<unsigned>(D);
2059 }
2060
2061 void addDependence(TypeDependence D) { setDependence(getDependence() | D); }
2062
2063public:
2064 friend class ASTReader;
2065 friend class ASTWriter;
2066 template <class T> friend class serialization::AbstractTypeReader;
2067 template <class T> friend class serialization::AbstractTypeWriter;
2068
2069 Type(const Type &) = delete;
2070 Type(Type &&) = delete;
2071 Type &operator=(const Type &) = delete;
2072 Type &operator=(Type &&) = delete;
2073
2074 TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
2075
2076 /// Whether this type comes from an AST file.
2077 bool isFromAST() const { return TypeBits.FromAST; }
2078
2079 /// Whether this type is or contains an unexpanded parameter
2080 /// pack, used to support C++0x variadic templates.
2081 ///
2082 /// A type that contains a parameter pack shall be expanded by the
2083 /// ellipsis operator at some point. For example, the typedef in the
2084 /// following example contains an unexpanded parameter pack 'T':
2085 ///
2086 /// \code
2087 /// template<typename ...T>
2088 /// struct X {
2089 /// typedef T* pointer_types; // ill-formed; T is a parameter pack.
2090 /// };
2091 /// \endcode
2092 ///
2093 /// Note that this routine does not specify which
2095 return getDependence() & TypeDependence::UnexpandedPack;
2096 }
2097
2098 /// Determines if this type would be canonical if it had no further
2099 /// qualification.
2101 return CanonicalType == QualType(this, 0);
2102 }
2103
2104 /// Pull a single level of sugar off of this locally-unqualified type.
2105 /// Users should generally prefer SplitQualType::getSingleStepDesugaredType()
2106 /// or QualType::getSingleStepDesugaredType(const ASTContext&).
2107 QualType getLocallyUnqualifiedSingleStepDesugaredType() const;
2108
2109 /// As an extension, we classify types as one of "sized" or "sizeless";
2110 /// every type is one or the other. Standard types are all sized;
2111 /// sizeless types are purely an extension.
2112 ///
2113 /// Sizeless types contain data with no specified size, alignment,
2114 /// or layout.
2115 bool isSizelessType() const;
2116 bool isSizelessBuiltinType() const;
2117
2118 /// Returns true for all scalable vector types.
2119 bool isSizelessVectorType() const;
2120
2121 /// Returns true for SVE scalable vector types.
2122 bool isSVESizelessBuiltinType() const;
2123
2124 /// Returns true for RVV scalable vector types.
2125 bool isRVVSizelessBuiltinType() const;
2126
2127 /// Check if this is a WebAssembly Externref Type.
2128 bool isWebAssemblyExternrefType() const;
2129
2130 /// Returns true if this is a WebAssembly table type: either an array of
2131 /// reference types, or a pointer to a reference type (which can only be
2132 /// created by array to pointer decay).
2133 bool isWebAssemblyTableType() const;
2134
2135 /// Determines if this is a sizeless type supported by the
2136 /// 'arm_sve_vector_bits' type attribute, which can be applied to a single
2137 /// SVE vector or predicate, excluding tuple types such as svint32x4_t.
2138 bool isSveVLSBuiltinType() const;
2139
2140 /// Returns the representative type for the element of an SVE builtin type.
2141 /// This is used to represent fixed-length SVE vectors created with the
2142 /// 'arm_sve_vector_bits' type attribute as VectorType.
2143 QualType getSveEltType(const ASTContext &Ctx) const;
2144
2145 /// Determines if this is a sizeless type supported by the
2146 /// 'riscv_rvv_vector_bits' type attribute, which can be applied to a single
2147 /// RVV vector or mask.
2148 bool isRVVVLSBuiltinType() const;
2149
2150 /// Returns the representative type for the element of an RVV builtin type.
2151 /// This is used to represent fixed-length RVV vectors created with the
2152 /// 'riscv_rvv_vector_bits' type attribute as VectorType.
2153 QualType getRVVEltType(const ASTContext &Ctx) const;
2154
2155 /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
2156 /// object types, function types, and incomplete types.
2157
2158 /// Return true if this is an incomplete type.
2159 /// A type that can describe objects, but which lacks information needed to
2160 /// determine its size (e.g. void, or a fwd declared struct). Clients of this
2161 /// routine will need to determine if the size is actually required.
2162 ///
2163 /// Def If non-null, and the type refers to some kind of declaration
2164 /// that can be completed (such as a C struct, C++ class, or Objective-C
2165 /// class), will be set to the declaration.
2166 bool isIncompleteType(NamedDecl **Def = nullptr) const;
2167
2168 /// Return true if this is an incomplete or object
2169 /// type, in other words, not a function type.
2171 return !isFunctionType();
2172 }
2173
2174 /// Determine whether this type is an object type.
2175 bool isObjectType() const {
2176 // C++ [basic.types]p8:
2177 // An object type is a (possibly cv-qualified) type that is not a
2178 // function type, not a reference type, and not a void type.
2179 return !isReferenceType() && !isFunctionType() && !isVoidType();
2180 }
2181
2182 /// Return true if this is a literal type
2183 /// (C++11 [basic.types]p10)
2184 bool isLiteralType(const ASTContext &Ctx) const;
2185
2186 /// Determine if this type is a structural type, per C++20 [temp.param]p7.
2187 bool isStructuralType() const;
2188
2189 /// Test if this type is a standard-layout type.
2190 /// (C++0x [basic.type]p9)
2191 bool isStandardLayoutType() const;
2192
2193 /// Helper methods to distinguish type categories. All type predicates
2194 /// operate on the canonical type, ignoring typedefs and qualifiers.
2195
2196 /// Returns true if the type is a builtin type.
2197 bool isBuiltinType() const;
2198
2199 /// Test for a particular builtin type.
2200 bool isSpecificBuiltinType(unsigned K) const;
2201
2202 /// Test for a type which does not represent an actual type-system type but
2203 /// is instead used as a placeholder for various convenient purposes within
2204 /// Clang. All such types are BuiltinTypes.
2205 bool isPlaceholderType() const;
2206 const BuiltinType *getAsPlaceholderType() const;
2207
2208 /// Test for a specific placeholder type.
2209 bool isSpecificPlaceholderType(unsigned K) const;
2210
2211 /// Test for a placeholder type other than Overload; see
2212 /// BuiltinType::isNonOverloadPlaceholderType.
2213 bool isNonOverloadPlaceholderType() const;
2214
2215 /// isIntegerType() does *not* include complex integers (a GCC extension).
2216 /// isComplexIntegerType() can be used to test for complex integers.
2217 bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum)
2218 bool isEnumeralType() const;
2219
2220 /// Determine whether this type is a scoped enumeration type.
2221 bool isScopedEnumeralType() const;
2222 bool isBooleanType() const;
2223 bool isCharType() const;
2224 bool isWideCharType() const;
2225 bool isChar8Type() const;
2226 bool isChar16Type() const;
2227 bool isChar32Type() const;
2228 bool isAnyCharacterType() const;
2229 bool isIntegralType(const ASTContext &Ctx) const;
2230
2231 /// Determine whether this type is an integral or enumeration type.
2232 bool isIntegralOrEnumerationType() const;
2233
2234 /// Determine whether this type is an integral or unscoped enumeration type.
2235 bool isIntegralOrUnscopedEnumerationType() const;
2236 bool isUnscopedEnumerationType() const;
2237
2238 /// Floating point categories.
2239 bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
2240 /// isComplexType() does *not* include complex integers (a GCC extension).
2241 /// isComplexIntegerType() can be used to test for complex integers.
2242 bool isComplexType() const; // C99 6.2.5p11 (complex)
2243 bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int.
2244 bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex)
2245 bool isHalfType() const; // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half)
2246 bool isFloat16Type() const; // C11 extension ISO/IEC TS 18661
2247 bool isFloat32Type() const;
2248 bool isBFloat16Type() const;
2249 bool isFloat128Type() const;
2250 bool isIbm128Type() const;
2251 bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
2252 bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating)
2253 bool isVoidType() const; // C99 6.2.5p19
2254 bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers)
2255 bool isAggregateType() const;
2256 bool isFundamentalType() const;
2257 bool isCompoundType() const;
2258
2259 // Type Predicates: Check to see if this type is structurally the specified
2260 // type, ignoring typedefs and qualifiers.
2261 bool isFunctionType() const;
2262 bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
2263 bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
2264 bool isPointerType() const;
2265 bool isAnyPointerType() const; // Any C pointer or ObjC object pointer
2266 bool isBlockPointerType() const;
2267 bool isVoidPointerType() const;
2268 bool isReferenceType() const;
2269 bool isLValueReferenceType() const;
2270 bool isRValueReferenceType() const;
2271 bool isObjectPointerType() const;
2272 bool isFunctionPointerType() const;
2273 bool isFunctionReferenceType() const;
2274 bool isMemberPointerType() const;
2275 bool isMemberFunctionPointerType() const;
2276 bool isMemberDataPointerType() const;
2277 bool isArrayType() const;
2278 bool isConstantArrayType() const;
2279 bool isIncompleteArrayType() const;
2280 bool isVariableArrayType() const;
2281 bool isDependentSizedArrayType() const;
2282 bool isRecordType() const;
2283 bool isClassType() const;
2284 bool isStructureType() const;
2285 bool isObjCBoxableRecordType() const;
2286 bool isInterfaceType() const;
2287 bool isStructureOrClassType() const;
2288 bool isUnionType() const;
2289 bool isComplexIntegerType() const; // GCC _Complex integer type.
2290 bool isVectorType() const; // GCC vector type.
2291 bool isExtVectorType() const; // Extended vector type.
2292 bool isExtVectorBoolType() const; // Extended vector type with bool element.
2293 bool isMatrixType() const; // Matrix type.
2294 bool isConstantMatrixType() const; // Constant matrix type.
2295 bool isDependentAddressSpaceType() const; // value-dependent address space qualifier
2296 bool isObjCObjectPointerType() const; // pointer to ObjC object
2297 bool isObjCRetainableType() const; // ObjC object or block pointer
2298 bool isObjCLifetimeType() const; // (array of)* retainable type
2299 bool isObjCIndirectLifetimeType() const; // (pointer to)* lifetime type
2300 bool isObjCNSObjectType() const; // __attribute__((NSObject))
2301 bool isObjCIndependentClassType() const; // __attribute__((objc_independent_class))
2302 // FIXME: change this to 'raw' interface type, so we can used 'interface' type
2303 // for the common case.
2304 bool isObjCObjectType() const; // NSString or typeof(*(id)0)
2305 bool isObjCQualifiedInterfaceType() const; // NSString<foo>
2306 bool isObjCQualifiedIdType() const; // id<foo>
2307 bool isObjCQualifiedClassType() const; // Class<foo>
2308 bool isObjCObjectOrInterfaceType() const;
2309 bool isObjCIdType() const; // id
2310 bool isDecltypeType() const;
2311 /// Was this type written with the special inert-in-ARC __unsafe_unretained
2312 /// qualifier?
2313 ///
2314 /// This approximates the answer to the following question: if this
2315 /// translation unit were compiled in ARC, would this type be qualified
2316 /// with __unsafe_unretained?
2318 return hasAttr(attr::ObjCInertUnsafeUnretained);
2319 }
2320
2321 /// Whether the type is Objective-C 'id' or a __kindof type of an
2322 /// object type, e.g., __kindof NSView * or __kindof id
2323 /// <NSCopying>.
2324 ///
2325 /// \param bound Will be set to the bound on non-id subtype types,
2326 /// which will be (possibly specialized) Objective-C class type, or
2327 /// null for 'id.
2328 bool isObjCIdOrObjectKindOfType(const ASTContext &ctx,
2329 const ObjCObjectType *&bound) const;
2330
2331 bool isObjCClassType() const; // Class
2332
2333 /// Whether the type is Objective-C 'Class' or a __kindof type of an
2334 /// Class type, e.g., __kindof Class <NSCopying>.
2335 ///
2336 /// Unlike \c isObjCIdOrObjectKindOfType, there is no relevant bound
2337 /// here because Objective-C's type system cannot express "a class
2338 /// object for a subclass of NSFoo".
2339 bool isObjCClassOrClassKindOfType() const;
2340
2341 bool isBlockCompatibleObjCPointerType(ASTContext &ctx) const;
2342 bool isObjCSelType() const; // Class
2343 bool isObjCBuiltinType() const; // 'id' or 'Class'
2344 bool isObjCARCBridgableType() const;
2345 bool isCARCBridgableType() const;
2346 bool isTemplateTypeParmType() const; // C++ template type parameter
2347 bool isNullPtrType() const; // C++11 std::nullptr_t or
2348 // C23 nullptr_t
2349 bool isNothrowT() const; // C++ std::nothrow_t
2350 bool isAlignValT() const; // C++17 std::align_val_t
2351 bool isStdByteType() const; // C++17 std::byte
2352 bool isAtomicType() const; // C11 _Atomic()
2353 bool isUndeducedAutoType() const; // C++11 auto or
2354 // C++14 decltype(auto)
2355 bool isTypedefNameType() const; // typedef or alias template
2356
2357#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2358 bool is##Id##Type() const;
2359#include "clang/Basic/OpenCLImageTypes.def"
2360
2361 bool isImageType() const; // Any OpenCL image type
2362
2363 bool isSamplerT() const; // OpenCL sampler_t
2364 bool isEventT() const; // OpenCL event_t
2365 bool isClkEventT() const; // OpenCL clk_event_t
2366 bool isQueueT() const; // OpenCL queue_t
2367 bool isReserveIDT() const; // OpenCL reserve_id_t
2368
2369#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
2370 bool is##Id##Type() const;
2371#include "clang/Basic/OpenCLExtensionTypes.def"
2372 // Type defined in cl_intel_device_side_avc_motion_estimation OpenCL extension
2373 bool isOCLIntelSubgroupAVCType() const;
2374 bool isOCLExtOpaqueType() const; // Any OpenCL extension type
2375
2376 bool isPipeType() const; // OpenCL pipe type
2377 bool isBitIntType() const; // Bit-precise integer type
2378 bool isOpenCLSpecificType() const; // Any OpenCL specific type
2379
2380 /// Determines if this type, which must satisfy
2381 /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
2382 /// than implicitly __strong.
2383 bool isObjCARCImplicitlyUnretainedType() const;
2384
2385 /// Check if the type is the CUDA device builtin surface type.
2386 bool isCUDADeviceBuiltinSurfaceType() const;
2387 /// Check if the type is the CUDA device builtin texture type.
2388 bool isCUDADeviceBuiltinTextureType() const;
2389
2390 /// Return the implicit lifetime for this type, which must not be dependent.
2391 Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
2392
2403 STK_FixedPoint
2405
2406 /// Given that this is a scalar type, classify it.
2407 ScalarTypeKind getScalarTypeKind() const;
2408
2410 return static_cast<TypeDependence>(TypeBits.Dependence);
2411 }
2412
2413 /// Whether this type is an error type.
2414 bool containsErrors() const {
2415 return getDependence() & TypeDependence::Error;
2416 }
2417
2418 /// Whether this type is a dependent type, meaning that its definition
2419 /// somehow depends on a template parameter (C++ [temp.dep.type]).
2420 bool isDependentType() const {
2421 return getDependence() & TypeDependence::Dependent;
2422 }
2423
2424 /// Determine whether this type is an instantiation-dependent type,
2425 /// meaning that the type involves a template parameter (even if the
2426 /// definition does not actually depend on the type substituted for that
2427 /// template parameter).
2429 return getDependence() & TypeDependence::Instantiation;
2430 }
2431
2432 /// Determine whether this type is an undeduced type, meaning that
2433 /// it somehow involves a C++11 'auto' type or similar which has not yet been
2434 /// deduced.
2435 bool isUndeducedType() const;
2436
2437 /// Whether this type is a variably-modified type (C99 6.7.5).
2439 return getDependence() & TypeDependence::VariablyModified;
2440 }
2441
2442 /// Whether this type involves a variable-length array type
2443 /// with a definite size.
2444 bool hasSizedVLAType() const;
2445
2446 /// Whether this type is or contains a local or unnamed type.
2447 bool hasUnnamedOrLocalType() const;
2448
2449 bool isOverloadableType() const;
2450
2451 /// Determine wither this type is a C++ elaborated-type-specifier.
2452 bool isElaboratedTypeSpecifier() const;
2453
2454 bool canDecayToPointerType() const;
2455
2456 /// Whether this type is represented natively as a pointer. This includes
2457 /// pointers, references, block pointers, and Objective-C interface,
2458 /// qualified id, and qualified interface types, as well as nullptr_t.
2459 bool hasPointerRepresentation() const;
2460
2461 /// Whether this type can represent an objective pointer type for the
2462 /// purpose of GC'ability
2463 bool hasObjCPointerRepresentation() const;
2464
2465 /// Determine whether this type has an integer representation
2466 /// of some sort, e.g., it is an integer type or a vector.
2467 bool hasIntegerRepresentation() const;
2468
2469 /// Determine whether this type has an signed integer representation
2470 /// of some sort, e.g., it is an signed integer type or a vector.
2471 bool hasSignedIntegerRepresentation() const;
2472
2473 /// Determine whether this type has an unsigned integer representation
2474 /// of some sort, e.g., it is an unsigned integer type or a vector.
2475 bool hasUnsignedIntegerRepresentation() const;
2476
2477 /// Determine whether this type has a floating-point representation
2478 /// of some sort, e.g., it is a floating-point type or a vector thereof.
2479 bool hasFloatingRepresentation() const;
2480
2481 // Type Checking Functions: Check to see if this type is structurally the
2482 // specified type, ignoring typedefs and qualifiers, and return a pointer to
2483 // the best type we can.
2484 const RecordType *getAsStructureType() const;
2485 /// NOTE: getAs*ArrayType are methods on ASTContext.
2486 const RecordType *getAsUnionType() const;
2487 const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
2488 const ObjCObjectType *getAsObjCInterfaceType() const;
2489
2490 // The following is a convenience method that returns an ObjCObjectPointerType
2491 // for object declared using an interface.
2492 const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
2493 const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
2494 const ObjCObjectPointerType *getAsObjCQualifiedClassType() const;
2495 const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
2496
2497 /// Retrieves the CXXRecordDecl that this type refers to, either
2498 /// because the type is a RecordType or because it is the injected-class-name
2499 /// type of a class template or class template partial specialization.
2500 CXXRecordDecl *getAsCXXRecordDecl() const;
2501
2502 /// Retrieves the RecordDecl this type refers to.
2503 RecordDecl *getAsRecordDecl() const;
2504
2505 /// Retrieves the TagDecl that this type refers to, either
2506 /// because the type is a TagType or because it is the injected-class-name
2507 /// type of a class template or class template partial specialization.
2508 TagDecl *getAsTagDecl() const;
2509
2510 /// If this is a pointer or reference to a RecordType, return the
2511 /// CXXRecordDecl that the type refers to.
2512 ///
2513 /// If this is not a pointer or reference, or the type being pointed to does
2514 /// not refer to a CXXRecordDecl, returns NULL.
2515 const CXXRecordDecl *getPointeeCXXRecordDecl() const;
2516
2517 /// Get the DeducedType whose type will be deduced for a variable with
2518 /// an initializer of this type. This looks through declarators like pointer
2519 /// types, but not through decltype or typedefs.
2520 DeducedType *getContainedDeducedType() const;
2521
2522 /// Get the AutoType whose type will be deduced for a variable with
2523 /// an initializer of this type. This looks through declarators like pointer
2524 /// types, but not through decltype or typedefs.
2526 return dyn_cast_or_null<AutoType>(getContainedDeducedType());
2527 }
2528
2529 /// Determine whether this type was written with a leading 'auto'
2530 /// corresponding to a trailing return type (possibly for a nested
2531 /// function type within a pointer to function type or similar).
2532 bool hasAutoForTrailingReturnType() const;
2533
2534 /// Member-template getAs<specific type>'. Look through sugar for
2535 /// an instance of <specific type>. This scheme will eventually
2536 /// replace the specific getAsXXXX methods above.
2537 ///
2538 /// There are some specializations of this member template listed
2539 /// immediately following this class.
2540 template <typename T> const T *getAs() const;
2541
2542 /// Member-template getAsAdjusted<specific type>. Look through specific kinds
2543 /// of sugar (parens, attributes, etc) for an instance of <specific type>.
2544 /// This is used when you need to walk over sugar nodes that represent some
2545 /// kind of type adjustment from a type that was written as a <specific type>
2546 /// to another type that is still canonically a <specific type>.
2547 template <typename T> const T *getAsAdjusted() const;
2548
2549 /// A variant of getAs<> for array types which silently discards
2550 /// qualifiers from the outermost type.
2551 const ArrayType *getAsArrayTypeUnsafe() const;
2552
2553 /// Member-template castAs<specific type>. Look through sugar for
2554 /// the underlying instance of <specific type>.
2555 ///
2556 /// This method has the same relationship to getAs<T> as cast<T> has
2557 /// to dyn_cast<T>; which is to say, the underlying type *must*
2558 /// have the intended type, and this method will never return null.
2559 template <typename T> const T *castAs() const;
2560
2561 /// A variant of castAs<> for array type which silently discards
2562 /// qualifiers from the outermost type.
2563 const ArrayType *castAsArrayTypeUnsafe() const;
2564
2565 /// Determine whether this type had the specified attribute applied to it
2566 /// (looking through top-level type sugar).
2567 bool hasAttr(attr::Kind AK) const;
2568
2569 /// Get the base element type of this type, potentially discarding type
2570 /// qualifiers. This should never be used when type qualifiers
2571 /// are meaningful.
2572 const Type *getBaseElementTypeUnsafe() const;
2573
2574 /// If this is an array type, return the element type of the array,
2575 /// potentially with type qualifiers missing.
2576 /// This should never be used when type qualifiers are meaningful.
2577 const Type *getArrayElementTypeNoTypeQual() const;
2578
2579 /// If this is a pointer type, return the pointee type.
2580 /// If this is an array type, return the array element type.
2581 /// This should never be used when type qualifiers are meaningful.
2582 const Type *getPointeeOrArrayElementType() const;
2583
2584 /// If this is a pointer, ObjC object pointer, or block
2585 /// pointer, this returns the respective pointee.
2586 QualType getPointeeType() const;
2587
2588 /// Return the specified type with any "sugar" removed from the type,
2589 /// removing any typedefs, typeofs, etc., as well as any qualifiers.
2590 const Type *getUnqualifiedDesugaredType() const;
2591
2592 /// Return true if this is an integer type that is
2593 /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
2594 /// or an enum decl which has a signed representation.
2595 bool isSignedIntegerType() const;
2596
2597 /// Return true if this is an integer type that is
2598 /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool],
2599 /// or an enum decl which has an unsigned representation.
2600 bool isUnsignedIntegerType() const;
2601
2602 /// Determines whether this is an integer type that is signed or an
2603 /// enumeration types whose underlying type is a signed integer type.
2604 bool isSignedIntegerOrEnumerationType() const;
2605
2606 /// Determines whether this is an integer type that is unsigned or an
2607 /// enumeration types whose underlying type is a unsigned integer type.
2608 bool isUnsignedIntegerOrEnumerationType() const;
2609
2610 /// Return true if this is a fixed point type according to
2611 /// ISO/IEC JTC1 SC22 WG14 N1169.
2612 bool isFixedPointType() const;
2613
2614 /// Return true if this is a fixed point or integer type.
2615 bool isFixedPointOrIntegerType() const;
2616
2617 /// Return true if this can be converted to (or from) a fixed point type.
2618 bool isConvertibleToFixedPointType() const;
2619
2620 /// Return true if this is a saturated fixed point type according to
2621 /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned.
2622 bool isSaturatedFixedPointType() const;
2623
2624 /// Return true if this is a saturated fixed point type according to
2625 /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned.
2626 bool isUnsaturatedFixedPointType() const;
2627
2628 /// Return true if this is a fixed point type that is signed according
2629 /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated.
2630 bool isSignedFixedPointType() const;
2631
2632 /// Return true if this is a fixed point type that is unsigned according
2633 /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated.
2634 bool isUnsignedFixedPointType() const;
2635
2636 /// Return true if this is not a variable sized type,
2637 /// according to the rules of C99 6.7.5p3. It is not legal to call this on
2638 /// incomplete types.
2639 bool isConstantSizeType() const;
2640
2641 /// Returns true if this type can be represented by some
2642 /// set of type specifiers.
2643 bool isSpecifierType() const;
2644
2645 /// Determine the linkage of this type.
2646 Linkage getLinkage() const;
2647
2648 /// Determine the visibility of this type.
2650 return getLinkageAndVisibility().getVisibility();
2651 }
2652
2653 /// Return true if the visibility was explicitly set is the code.
2655 return getLinkageAndVisibility().isVisibilityExplicit();
2656 }
2657
2658 /// Determine the linkage and visibility of this type.
2659 LinkageInfo getLinkageAndVisibility() const;
2660
2661 /// True if the computed linkage is valid. Used for consistency
2662 /// checking. Should always return true.
2663 bool isLinkageValid() const;
2664
2665 /// Determine the nullability of the given type.
2666 ///
2667 /// Note that nullability is only captured as sugar within the type
2668 /// system, not as part of the canonical type, so nullability will
2669 /// be lost by canonicalization and desugaring.
2670 std::optional<NullabilityKind> getNullability() const;
2671
2672 /// Determine whether the given type can have a nullability
2673 /// specifier applied to it, i.e., if it is any kind of pointer type.
2674 ///
2675 /// \param ResultIfUnknown The value to return if we don't yet know whether
2676 /// this type can have nullability because it is dependent.
2677 bool canHaveNullability(bool ResultIfUnknown = true) const;
2678
2679 /// Retrieve the set of substitutions required when accessing a member
2680 /// of the Objective-C receiver type that is declared in the given context.
2681 ///
2682 /// \c *this is the type of the object we're operating on, e.g., the
2683 /// receiver for a message send or the base of a property access, and is
2684 /// expected to be of some object or object pointer type.
2685 ///
2686 /// \param dc The declaration context for which we are building up a
2687 /// substitution mapping, which should be an Objective-C class, extension,
2688 /// category, or method within.
2689 ///
2690 /// \returns an array of type arguments that can be substituted for
2691 /// the type parameters of the given declaration context in any type described
2692 /// within that context, or an empty optional to indicate that no
2693 /// substitution is required.
2694 std::optional<ArrayRef<QualType>>
2695 getObjCSubstitutions(const DeclContext *dc) const;
2696
2697 /// Determines if this is an ObjC interface type that may accept type
2698 /// parameters.
2699 bool acceptsObjCTypeParams() const;
2700
2701 const char *getTypeClassName() const;
2702
2704 return CanonicalType;
2705 }
2706
2707 CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
2708 void dump() const;
2709 void dump(llvm::raw_ostream &OS, const ASTContext &Context) const;
2710};
2711
2712/// This will check for a TypedefType by removing any existing sugar
2713/// until it reaches a TypedefType or a non-sugared type.
2714template <> const TypedefType *Type::getAs() const;
2715template <> const UsingType *Type::getAs() const;
2716
2717/// This will check for a TemplateSpecializationType by removing any
2718/// existing sugar until it reaches a TemplateSpecializationType or a
2719/// non-sugared type.
2720template <> const TemplateSpecializationType *Type::getAs() const;
2721
2722/// This will check for an AttributedType by removing any existing sugar
2723/// until it reaches an AttributedType or a non-sugared type.
2724template <> const AttributedType *Type::getAs() const;
2725
2726// We can do canonical leaf types faster, because we don't have to
2727// worry about preserving child type decoration.
2728#define TYPE(Class, Base)
2729#define LEAF_TYPE(Class) \
2730template <> inline const Class##Type *Type::getAs() const { \
2731 return dyn_cast<Class##Type>(CanonicalType); \
2732} \
2733template <> inline const Class##Type *Type::castAs() const { \
2734 return cast<Class##Type>(CanonicalType); \
2735}
2736#include "clang/AST/TypeNodes.inc"
2737
2738/// This class is used for builtin types like 'int'. Builtin
2739/// types are always canonical and have a literal name field.
2740class BuiltinType : public Type {
2741public:
2742 enum Kind {
2743// OpenCL image types
2744#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id,
2745#include "clang/Basic/OpenCLImageTypes.def"
2746// OpenCL extension types
2747#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) Id,
2748#include "clang/Basic/OpenCLExtensionTypes.def"
2749// SVE Types
2750#define SVE_TYPE(Name, Id, SingletonId) Id,
2751#include "clang/Basic/AArch64SVEACLETypes.def"
2752// PPC MMA Types
2753#define PPC_VECTOR_TYPE(Name, Id, Size) Id,
2754#include "clang/Basic/PPCTypes.def"
2755// RVV Types
2756#define RVV_TYPE(Name, Id, SingletonId) Id,
2757#include "clang/Basic/RISCVVTypes.def"
2758// WebAssembly reference types
2759#define WASM_TYPE(Name, Id, SingletonId) Id,
2760#include "clang/Basic/WebAssemblyReferenceTypes.def"
2761// All other builtin types
2762#define BUILTIN_TYPE(Id, SingletonId) Id,
2763#define LAST_BUILTIN_TYPE(Id) LastKind = Id
2764#include "clang/AST/BuiltinTypes.def"
2765 };
2766
2767private:
2768 friend class ASTContext; // ASTContext creates these.
2769
2770 BuiltinType(Kind K)
2771 : Type(Builtin, QualType(),
2772 K == Dependent ? TypeDependence::DependentInstantiation
2773 : TypeDependence::None) {
2774 static_assert(Kind::LastKind <
2775 (1 << BuiltinTypeBitfields::NumOfBuiltinTypeBits) &&
2776 "Defined builtin type exceeds the allocated space for serial "
2777 "numbering");
2778 BuiltinTypeBits.Kind = K;
2779 }
2780
2781public:
2782 Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
2783 StringRef getName(const PrintingPolicy &Policy) const;
2784
2785 const char *getNameAsCString(const PrintingPolicy &Policy) const {
2786 // The StringRef is null-terminated.
2787 StringRef str = getName(Policy);
2788 assert(!str.empty() && str.data()[str.size()] == '\0');
2789 return str.data();
2790 }
2791
2792 bool isSugared() const { return false; }
2793 QualType desugar() const { return QualType(this, 0); }
2794
2795 bool isInteger() const {
2796 return getKind() >= Bool && getKind() <= Int128;
2797 }
2798
2799 bool isSignedInteger() const {
2800 return getKind() >= Char_S && getKind() <= Int128;
2801 }
2802
2803 bool isUnsignedInteger() const {
2804 return getKind() >= Bool && getKind() <= UInt128;
2805 }
2806
2807 bool isFloatingPoint() const {
2808 return getKind() >= Half && getKind() <= Ibm128;
2809 }
2810
2811 bool isSVEBool() const { return getKind() == Kind::SveBool; }
2812
2813 bool isSVECount() const { return getKind() == Kind::SveCount; }
2814
2815 /// Determines whether the given kind corresponds to a placeholder type.
2817 return K >= Overload;
2818 }
2819
2820 /// Determines whether this type is a placeholder type, i.e. a type
2821 /// which cannot appear in arbitrary positions in a fully-formed
2822 /// expression.
2823 bool isPlaceholderType() const {
2824 return isPlaceholderTypeKind(getKind());
2825 }
2826
2827 /// Determines whether this type is a placeholder type other than
2828 /// Overload. Most placeholder types require only syntactic
2829 /// information about their context in order to be resolved (e.g.
2830 /// whether it is a call expression), which means they can (and
2831 /// should) be resolved in an earlier "phase" of analysis.
2832 /// Overload expressions sometimes pick up further information
2833 /// from their context, like whether the context expects a
2834 /// specific function-pointer type, and so frequently need
2835 /// special treatment.
2837 return getKind() > Overload;
2838 }
2839
2840 static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
2841};
2842
2843/// Complex values, per C99 6.2.5p11. This supports the C99 complex
2844/// types (_Complex float etc) as well as the GCC integer complex extensions.
2845class ComplexType : public Type, public llvm::FoldingSetNode {
2846 friend class ASTContext; // ASTContext creates these.
2847
2848 QualType ElementType;
2849
2850 ComplexType(QualType Element, QualType CanonicalPtr)
2851 : Type(Complex, CanonicalPtr, Element->getDependence()),
2852 ElementType(Element) {}
2853
2854public:
2855 QualType getElementType() const { return ElementType; }
2856
2857 bool isSugared() const { return false; }
2858 QualType desugar() const { return QualType(this, 0); }
2859
2860 void Profile(llvm::FoldingSetNodeID &ID) {
2861 Profile(ID, getElementType());
2862 }
2863
2864 static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
2865 ID.AddPointer(Element.getAsOpaquePtr());
2866 }
2867
2868 static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
2869};
2870
2871/// Sugar for parentheses used when specifying types.
2872class ParenType : public Type, public llvm::FoldingSetNode {
2873 friend class ASTContext; // ASTContext creates these.
2874
2875 QualType Inner;
2876
2877 ParenType(QualType InnerType, QualType CanonType)
2878 : Type(Paren, CanonType, InnerType->getDependence()), Inner(InnerType) {}
2879
2880public:
2881 QualType getInnerType() const { return Inner; }
2882
2883 bool isSugared() const { return true; }
2884 QualType desugar() const { return getInnerType(); }
2885
2886 void Profile(llvm::FoldingSetNodeID &ID) {
2887 Profile(ID, getInnerType());
2888 }
2889
2890 static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
2891 Inner.Profile(ID);
2892 }
2893
2894 static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
2895};
2896
2897/// PointerType - C99 6.7.5.1 - Pointer Declarators.
2898class PointerType : public Type, public llvm::FoldingSetNode {
2899 friend class ASTContext; // ASTContext creates these.
2900
2901 QualType PointeeType;
2902
2903 PointerType(QualType Pointee, QualType CanonicalPtr)
2904 : Type(Pointer, CanonicalPtr, Pointee->getDependence()),
2905 PointeeType(Pointee) {}
2906
2907public:
2908 QualType getPointeeType() const { return PointeeType; }
2909
2910 bool isSugared() const { return false; }
2911 QualType desugar() const { return QualType(this, 0); }
2912
2913 void Profile(llvm::FoldingSetNodeID &ID) {
2914 Profile(ID, getPointeeType());
2915 }
2916
2917 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
2918 ID.AddPointer(Pointee.getAsOpaquePtr());
2919 }
2920
2921 static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
2922};
2923
2924/// Represents a type which was implicitly adjusted by the semantic
2925/// engine for arbitrary reasons. For example, array and function types can
2926/// decay, and function types can have their calling conventions adjusted.
2927class AdjustedType : public Type, public llvm::FoldingSetNode {
2928 QualType OriginalTy;
2929 QualType AdjustedTy;
2930
2931protected:
2932 friend class ASTContext; // ASTContext creates these.
2933
2934 AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy,
2935 QualType CanonicalPtr)
2936 : Type(TC, CanonicalPtr, OriginalTy->getDependence()),
2937 OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}
2938
2939public:
2940 QualType getOriginalType() const { return OriginalTy; }
2941 QualType getAdjustedType() const { return AdjustedTy; }
2942
2943 bool isSugared() const { return true; }
2944 QualType desugar() const { return AdjustedTy; }
2945
2946 void Profile(llvm::FoldingSetNodeID &ID) {
2947 Profile(ID, OriginalTy, AdjustedTy);
2948 }
2949
2950 static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New) {
2951 ID.AddPointer(Orig.getAsOpaquePtr());
2952 ID.AddPointer(New.getAsOpaquePtr());
2953 }
2954
2955 static bool classof(const Type *T) {
2956 return T->getTypeClass() == Adjusted || T->getTypeClass() == Decayed;
2957 }
2958};
2959
2960/// Represents a pointer type decayed from an array or function type.
2962 friend class ASTContext; // ASTContext creates these.
2963
2964 inline
2965 DecayedType(QualType OriginalType, QualType Decayed, QualType Canonical);
2966
2967public:
2968 QualType getDecayedType() const { return getAdjustedType(); }
2969
2970 inline QualType getPointeeType() const;
2971
2972 static bool classof(const Type *T) { return T->getTypeClass() == Decayed; }
2973};
2974
2975/// Pointer to a block type.
2976/// This type is to represent types syntactically represented as
2977/// "void (^)(int)", etc. Pointee is required to always be a function type.
2978class BlockPointerType : public Type, public llvm::FoldingSetNode {
2979 friend class ASTContext; // ASTContext creates these.
2980
2981 // Block is some kind of pointer type
2982 QualType PointeeType;
2983
2984 BlockPointerType(QualType Pointee, QualType CanonicalCls)
2985 : Type(BlockPointer, CanonicalCls, Pointee->getDependence()),
2986 PointeeType(Pointee) {}
2987
2988public:
2989 // Get the pointee type. Pointee is required to always be a function type.
2990 QualType getPointeeType() const { return PointeeType; }
2991
2992 bool isSugared() const { return false; }
2993 QualType desugar() const { return QualType(this, 0); }
2994
2995 void Profile(llvm::FoldingSetNodeID &ID) {
2996 Profile(ID, getPointeeType());
2997 }
2998
2999 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
3000 ID.AddPointer(Pointee.getAsOpaquePtr());
3001 }
3002
3003 static bool classof(const Type *T) {
3004 return T->getTypeClass() == BlockPointer;
3005 }
3006};
3007
3008/// Base for LValueReferenceType and RValueReferenceType
3009class ReferenceType : public Type, public llvm::FoldingSetNode {
3010 QualType PointeeType;
3011
3012protected:
3013 ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
3014 bool SpelledAsLValue)
3015 : Type(tc, CanonicalRef, Referencee->getDependence()),
3016 PointeeType(Referencee) {
3017 ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
3018 ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
3019 }
3020
3021public:
3022 bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
3023 bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
3024
3025 QualType getPointeeTypeAsWritten() const { return PointeeType; }
3026
3028 // FIXME: this might strip inner qualifiers; okay?
3029 const ReferenceType *T = this;
3030 while (T->isInnerRef())
3031 T = T->PointeeType->castAs<ReferenceType>();
3032 return T->PointeeType;
3033 }
3034
3035 void Profile(llvm::FoldingSetNodeID &ID) {
3036 Profile(ID, PointeeType, isSpelledAsLValue());
3037 }
3038
3039 static void Profile(llvm::FoldingSetNodeID &ID,
3040 QualType Referencee,
3041 bool SpelledAsLValue) {
3042 ID.AddPointer(Referencee.getAsOpaquePtr());
3043 ID.AddBoolean(SpelledAsLValue);
3044 }
3045
3046 static bool classof(const Type *T) {
3047 return T->getTypeClass() == LValueReference ||
3048 T->getTypeClass() == RValueReference;
3049 }
3050};
3051
3052/// An lvalue reference type, per C++11 [dcl.ref].
3054 friend class ASTContext; // ASTContext creates these
3055
3056 LValueReferenceType(QualType Referencee, QualType CanonicalRef,
3057 bool SpelledAsLValue)
3058 : ReferenceType(LValueReference, Referencee, CanonicalRef,
3059 SpelledAsLValue) {}
3060
3061public:
3062 bool isSugared() const { return false; }
3063 QualType desugar() const { return QualType(this, 0); }
3064
3065 static bool classof(const Type *T) {
3066 return T->getTypeClass() == LValueReference;
3067 }
3068};
3069
3070/// An rvalue reference type, per C++11 [dcl.ref].
3072 friend class ASTContext; // ASTContext creates these
3073
3074 RValueReferenceType(QualType Referencee, QualType CanonicalRef)
3075 : ReferenceType(RValueReference, Referencee, CanonicalRef, false) {}
3076
3077public:
3078 bool isSugared() const { return false; }
3079 QualType desugar() const { return QualType(this, 0); }
3080
3081 static bool classof(const Type *T) {
3082 return T->getTypeClass() == RValueReference;
3083 }
3084};
3085
3086/// A pointer to member type per C++ 8.3.3 - Pointers to members.
3087///
3088/// This includes both pointers to data members and pointer to member functions.
3089class MemberPointerType : public Type, public llvm::FoldingSetNode {
3090 friend class ASTContext; // ASTContext creates these.
3091
3092 QualType PointeeType;
3093
3094 /// The class of which the pointee is a member. Must ultimately be a
3095 /// RecordType, but could be a typedef or a template parameter too.
3096 const Type *Class;
3097
3098 MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr)
3099 : Type(MemberPointer, CanonicalPtr,
3100 (Cls->getDependence() & ~TypeDependence::VariablyModified) |
3101 Pointee->getDependence()),
3102 PointeeType(Pointee), Class(Cls) {}
3103
3104public:
3105 QualType getPointeeType() const { return PointeeType; }
3106
3107 /// Returns true if the member type (i.e. the pointee type) is a
3108 /// function type rather than a data-member type.
3110 return PointeeType->isFunctionProtoType();
3111 }
3112
3113 /// Returns true if the member type (i.e. the pointee type) is a
3114 /// data type rather than a function type.
3115 bool isMemberDataPointer() const {
3116 return !PointeeType->isFunctionProtoType();
3117 }
3118
3119 const Type *getClass() const { return Class; }
3120 CXXRecordDecl *getMostRecentCXXRecordDecl() const;
3121
3122 bool isSugared() const { return false; }
3123 QualType desugar() const { return QualType(this, 0); }
3124
3125 void Profile(llvm::FoldingSetNodeID &ID) {
3126 Profile(ID, getPointeeType(), getClass());
3127 }
3128
3129 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
3130 const Type *Class) {
3131 ID.AddPointer(Pointee.getAsOpaquePtr());
3132 ID.AddPointer(Class);
3133 }
3134
3135 static bool classof(const Type *T) {
3136 return T->getTypeClass() == MemberPointer;
3137 }
3138};
3139
3140/// Capture whether this is a normal array (e.g. int X[4])
3141/// an array with a static size (e.g. int X[static 4]), or an array
3142/// with a star size (e.g. int X[*]).
3143/// 'static' is only allowed on function parameters.
3144enum class ArraySizeModifier { Normal, Static, Star };
3145
3146/// Represents an array type, per C99 6.7.5.2 - Array Declarators.
3147class ArrayType : public Type, public llvm::FoldingSetNode {
3148private:
3149 /// The element type of the array.
3150 QualType ElementType;
3151
3152protected:
3153 friend class ASTContext; // ASTContext creates these.
3154
3156 unsigned tq, const Expr *sz = nullptr);
3157
3158public:
3159 QualType getElementType() const { return ElementType; }
3160
3162 return ArraySizeModifier(ArrayTypeBits.SizeModifier);
3163 }
3164
3166 return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
3167 }
3168
3169 unsigned getIndexTypeCVRQualifiers() const {
3170 return ArrayTypeBits.IndexTypeQuals;
3171 }
3172
3173 static bool classof(const Type *T) {
3174 return T->getTypeClass() == ConstantArray ||
3175 T->getTypeClass() == VariableArray ||
3176 T->getTypeClass() == IncompleteArray ||
3177 T->getTypeClass() == DependentSizedArray;
3178 }
3179};
3180
3181/// Represents the canonical version of C arrays with a specified constant size.
3182/// For example, the canonical type for 'int A[4 + 4*100]' is a
3183/// ConstantArrayType where the element type is 'int' and the size is 404.
3185 : public ArrayType,
3186 private llvm::TrailingObjects<ConstantArrayType, const Expr *> {
3187 friend class ASTContext; // ASTContext creates these.
3188 friend TrailingObjects;
3189
3190 llvm::APInt Size; // Allows us to unique the type.
3191
3192 ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
3193 const Expr *sz, ArraySizeModifier sm, unsigned tq)
3194 : ArrayType(ConstantArray, et, can, sm, tq, sz), Size(size) {
3195 ConstantArrayTypeBits.HasStoredSizeExpr = sz != nullptr;
3196 if (ConstantArrayTypeBits.HasStoredSizeExpr) {
3197 assert(!can.isNull() && "canonical constant array should not have size");
3198 *getTrailingObjects<const Expr*>() = sz;
3199 }
3200 }
3201
3202 unsigned numTrailingObjects(OverloadToken<const Expr*>) const {
3203 return ConstantArrayTypeBits.HasStoredSizeExpr;
3204 }
3205
3206public:
3207 const llvm::APInt &getSize() const { return Size; }
3208 const Expr *getSizeExpr() const {
3209 return ConstantArrayTypeBits.HasStoredSizeExpr
3210 ? *getTrailingObjects<const Expr *>()
3211 : nullptr;
3212 }
3213 bool isSugared() const { return false; }
3214 QualType desugar() const { return QualType(this, 0); }
3215
3216 /// Determine the number of bits required to address a member of
3217 // an array with the given element type and number of elements.
3218 static unsigned getNumAddressingBits(const ASTContext &Context,
3219 QualType ElementType,
3220 const llvm::APInt &NumElements);
3221
3222 unsigned getNumAddressingBits(const ASTContext &Context) const;
3223
3224 /// Determine the maximum number of active bits that an array's size
3225 /// can require, which limits the maximum size of the array.
3226 static unsigned getMaxSizeBits(const ASTContext &Context);
3227
3228 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
3229 Profile(ID, Ctx, getElementType(), getSize(), getSizeExpr(),
3230 getSizeModifier(), getIndexTypeCVRQualifiers());
3231 }
3232
3233 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx,
3234 QualType ET, const llvm::APInt &ArraySize,
3235 const Expr *SizeExpr, ArraySizeModifier SizeMod,
3236 unsigned TypeQuals);
3237
3238 static bool classof(const Type *T) {
3239 return T->getTypeClass() == ConstantArray;
3240 }
3241};
3242
3243/// Represents a C array with an unspecified size. For example 'int A[]' has
3244/// an IncompleteArrayType where the element type is 'int' and the size is
3245/// unspecified.
3247 friend class ASTContext; // ASTContext creates these.
3248
3250 ArraySizeModifier sm, unsigned tq)
3251 : ArrayType(IncompleteArray, et, can, sm, tq) {}
3252
3253public:
3254 friend class StmtIteratorBase;
3255
3256 bool isSugared() const { return false; }
3257 QualType desugar() const { return QualType(this, 0); }
3258
3259 static bool classof(const Type *T) {
3260 return T->getTypeClass() == IncompleteArray;
3261 }
3262
3263 void Profile(llvm::FoldingSetNodeID &ID) {
3264 Profile(ID, getElementType(), getSizeModifier(),
3265 getIndexTypeCVRQualifiers());
3266 }
3267
3268 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
3269 ArraySizeModifier SizeMod, unsigned TypeQuals) {
3270 ID.AddPointer(ET.getAsOpaquePtr());
3271 ID.AddInteger(llvm::to_underlying(SizeMod));
3272 ID.AddInteger(TypeQuals);
3273 }
3274};
3275
3276/// Represents a C array with a specified size that is not an
3277/// integer-constant-expression. For example, 'int s[x+foo()]'.
3278/// Since the size expression is an arbitrary expression, we store it as such.
3279///
3280/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
3281/// should not be: two lexically equivalent variable array types could mean
3282/// different things, for example, these variables do not have the same type
3283/// dynamically:
3284///
3285/// void foo(int x) {
3286/// int Y[x];
3287/// ++x;
3288/// int Z[x];
3289/// }
3291 friend class ASTContext; // ASTContext creates these.
3292
3293 /// An assignment-expression. VLA's are only permitted within
3294 /// a function block.
3295 Stmt *SizeExpr;
3296
3297 /// The range spanned by the left and right array brackets.
3298 SourceRange Brackets;
3299
3301 ArraySizeModifier sm, unsigned tq,
3302 SourceRange brackets)
3303 : ArrayType(VariableArray, et, can, sm, tq, e),
3304 SizeExpr((Stmt*) e), Brackets(brackets) {}
3305
3306public:
3307 friend class StmtIteratorBase;
3308
3310 // We use C-style casts instead of cast<> here because we do not wish
3311 // to have a dependency of Type.h on Stmt.h/Expr.h.
3312 return (Expr*) SizeExpr;
3313 }
3314
3315 SourceRange getBracketsRange() const { return Brackets; }
3316 SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
3317 SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
3318
3319 bool isSugared() const { return false; }
3320 QualType desugar() const { return QualType(this, 0); }
3321
3322 static bool classof(const Type *T) {
3323 return T->getTypeClass() == VariableArray;
3324 }
3325
3326 void Profile(llvm::FoldingSetNodeID &ID) {
3327 llvm_unreachable("Cannot unique VariableArrayTypes.");
3328 }
3329};
3330
3331/// Represents an array type in C++ whose size is a value-dependent expression.
3332///
3333/// For example:
3334/// \code
3335/// template<typename T, int Size>
3336/// class array {
3337/// T data[Size];
3338/// };
3339/// \endcode
3340///
3341/// For these types, we won't actually know what the array bound is
3342/// until template instantiation occurs, at which point this will
3343/// become either a ConstantArrayType or a VariableArrayType.
3345 friend class ASTContext; // ASTContext creates these.
3346
3347 /// An assignment expression that will instantiate to the
3348 /// size of the array.
3349 ///
3350 /// The expression itself might be null, in which case the array
3351 /// type will have its size deduced from an initializer.
3352 Stmt *SizeExpr;
3353
3354 /// The range spanned by the left and right array brackets.
3355 SourceRange Brackets;
3356
3358 ArraySizeModifier sm, unsigned tq,
3359 SourceRange brackets);
3360
3361public:
3362 friend class StmtIteratorBase;
3363
3365 // We use C-style casts instead of cast<> here because we do not wish
3366 // to have a dependency of Type.h on Stmt.h/Expr.h.
3367 return (Expr*) SizeExpr;
3368 }
3369
3370 SourceRange getBracketsRange() const { return Brackets; }
3371 SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
3372 SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
3373
3374 bool isSugared() const { return false; }
3375 QualType desugar() const { return QualType(this, 0); }
3376
3377 static bool classof(const Type *T) {
3378 return T->getTypeClass() == DependentSizedArray;
3379 }
3380
3381 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
3382 Profile(ID, Context, getElementType(),
3383 getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
3384 }
3385
3386 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3387 QualType ET, ArraySizeModifier SizeMod,
3388 unsigned TypeQuals, Expr *E);
3389};
3390
3391/// Represents an extended address space qualifier where the input address space
3392/// value is dependent. Non-dependent address spaces are not represented with a
3393/// special Type subclass; they are stored on an ExtQuals node as part of a QualType.
3394///
3395/// For example:
3396/// \code
3397/// template<typename T, int AddrSpace>
3398/// class AddressSpace {
3399/// typedef T __attribute__((address_space(AddrSpace))) type;
3400/// }
3401/// \endcode
3402class DependentAddressSpaceType : public Type, public llvm::FoldingSetNode {
3403 friend class ASTContext;
3404
3405 Expr *AddrSpaceExpr;
3406 QualType PointeeType;
3407 SourceLocation loc;
3408
3410 Expr *AddrSpaceExpr, SourceLocation loc);
3411
3412public:
3413 Expr *getAddrSpaceExpr() const { return AddrSpaceExpr; }
3414 QualType getPointeeType() const { return PointeeType; }
3415 SourceLocation getAttributeLoc() const { return loc; }
3416
3417 bool isSugared() const { return false; }
3418 QualType desugar() const { return QualType(this, 0); }
3419
3420 static bool classof(const Type *T) {
3421 return T->getTypeClass() == DependentAddressSpace;
3422 }
3423
3424 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
3425 Profile(ID, Context, getPointeeType(), getAddrSpaceExpr());
3426 }
3427
3428 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3429 QualType PointeeType, Expr *AddrSpaceExpr);
3430};
3431
3432/// Represents an extended vector type where either the type or size is
3433/// dependent.
3434///
3435/// For example:
3436/// \code
3437/// template<typename T, int Size>
3438/// class vector {
3439/// typedef T __attribute__((ext_vector_type(Size))) type;
3440/// }
3441/// \endcode
3442class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
3443 friend class ASTContext;
3444
3445 Expr *SizeExpr;
3446
3447 /// The element type of the array.
3448 QualType ElementType;
3449
3450 SourceLocation loc;
3451
3453 Expr *SizeExpr, SourceLocation loc);
3454
3455public:
3456 Expr *getSizeExpr() const { return SizeExpr; }
3457 QualType getElementType() const { return ElementType; }
3458 SourceLocation getAttributeLoc() const { return loc; }
3459
3460 bool isSugared() const { return false; }
3461 QualType desugar() const { return QualType(this, 0); }
3462
3463 static bool classof(const Type *T) {
3464 return T->getTypeClass() == DependentSizedExtVector;
3465 }
3466
3467 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
3468 Profile(ID, Context, getElementType(), getSizeExpr());
3469 }
3470
3471 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3472 QualType ElementType, Expr *SizeExpr);
3473};
3474
3475enum class VectorKind {
3476 /// not a target-specific vector type
3477 Generic,
3478
3479 /// is AltiVec vector
3481
3482 /// is AltiVec 'vector Pixel'
3484
3485 /// is AltiVec 'vector bool ...'
3487
3488 /// is ARM Neon vector
3489 Neon,
3490
3491 /// is ARM Neon polynomial vector
3492 NeonPoly,
3493
3494 /// is AArch64 SVE fixed-length data vector
3496
3497 /// is AArch64 SVE fixed-length predicate vector
3499
3500 /// is RISC-V RVV fixed-length data vector
3502
3503 /// is RISC-V RVV fixed-length mask vector
3505};
3506
3507/// Represents a GCC generic vector type. This type is created using
3508/// __attribute__((vector_size(n)), where "n" specifies the vector size in
3509/// bytes; or from an Altivec __vector or vector declaration.
3510/// Since the constructor takes the number of vector elements, the
3511/// client is responsible for converting the size into the number of elements.
3512class VectorType : public Type, public llvm::FoldingSetNode {
3513protected:
3514 friend class ASTContext; // ASTContext creates these.
3515
3516 /// The element type of the vector.
3518
3519 VectorType(QualType vecType, unsigned nElements, QualType canonType,
3520 VectorKind vecKind);
3521
3522 VectorType(TypeClass tc, QualType vecType, unsigned nElements,
3523 QualType canonType, VectorKind vecKind);
3524
3525public:
3526 QualType getElementType() const { return ElementType; }
3527 unsigned getNumElements() const { return VectorTypeBits.NumElements; }
3528
3529 bool isSugared() const { return false; }
3530 QualType desugar() const { return QualType(this, 0); }
3531
3533 return VectorKind(VectorTypeBits.VecKind);
3534 }
3535
3536 void Profile(llvm::FoldingSetNodeID &ID) {
3537 Profile(ID, getElementType(), getNumElements(),
3538 getTypeClass(), getVectorKind());
3539 }
3540
3541 static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
3542 unsigned NumElements, TypeClass TypeClass,
3543 VectorKind VecKind) {
3544 ID.AddPointer(ElementType.getAsOpaquePtr());
3545 ID.AddInteger(NumElements);
3546 ID.AddInteger(TypeClass);
3547 ID.AddInteger(llvm::to_underlying(VecKind));
3548 }
3549
3550 static bool classof(const Type *T) {
3551 return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
3552 }
3553};
3554
3555/// Represents a vector type where either the type or size is dependent.
3556////
3557/// For example:
3558/// \code
3559/// template<typename T, int Size>
3560/// class vector {
3561/// typedef T __attribute__((vector_size(Size))) type;
3562/// }
3563/// \endcode
3564class DependentVectorType : public Type, public llvm::FoldingSetNode {
3565 friend class ASTContext;
3566
3567 QualType ElementType;
3568 Expr *SizeExpr;
3569 SourceLocation Loc;
3570
3571 DependentVectorType(QualType ElementType, QualType CanonType, Expr *SizeExpr,
3572 SourceLocation Loc, VectorKind vecKind);
3573
3574public:
3575 Expr *getSizeExpr() const { return SizeExpr; }
3576 QualType getElementType() const { return ElementType; }
3577 SourceLocation getAttributeLoc() const { return Loc; }
3579 return VectorKind(VectorTypeBits.VecKind);
3580 }
3581
3582 bool isSugared() const { return false; }
3583 QualType desugar() const { return QualType(this, 0); }
3584
3585 static bool classof(const Type *T) {
3586 return T->getTypeClass() == DependentVector;
3587 }
3588
3589 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
3590 Profile(ID, Context, getElementType(), getSizeExpr(), getVectorKind());
3591 }
3592
3593 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3594 QualType ElementType, const Expr *SizeExpr,
3595 VectorKind VecKind);
3596};
3597
3598/// ExtVectorType - Extended vector type. This type is created using
3599/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
3600/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
3601/// class enables syntactic extensions, like Vector Components for accessing
3602/// points (as .xyzw), colors (as .rgba), and textures (modeled after OpenGL
3603/// Shading Language).
3605 friend class ASTContext; // ASTContext creates these.
3606
3607 ExtVectorType(QualType vecType, unsigned nElements, QualType canonType)
3608 : VectorType(ExtVector, vecType, nElements, canonType,
3609 VectorKind::Generic) {}
3610
3611public:
3612 static int getPointAccessorIdx(char c) {
3613 switch (c) {
3614 default: return -1;
3615 case 'x': case 'r': return 0;
3616 case 'y': case 'g': return 1;
3617 case 'z': case 'b': return 2;
3618 case 'w': case 'a': return 3;
3619 }
3620 }
3621
3622 static int getNumericAccessorIdx(char c) {
3623 switch (c) {
3624 default: return -1;
3625 case '0': return 0;
3626 case '1': return 1;
3627 case '2': return 2;
3628 case '3': return 3;
3629 case '4': return 4;
3630 case '5': return 5;
3631 case '6': return 6;
3632 case '7': return 7;
3633 case '8': return 8;
3634 case '9': return 9;
3635 case 'A':
3636 case 'a': return 10;
3637 case 'B':
3638 case 'b': return 11;
3639 case 'C':
3640 case 'c': return 12;
3641 case 'D':
3642 case 'd': return 13;
3643 case 'E':
3644 case 'e': return 14;
3645 case 'F':
3646 case 'f': return 15;
3647 }
3648 }
3649
3650 static int getAccessorIdx(char c, bool isNumericAccessor) {
3651 if (isNumericAccessor)
3652 return getNumericAccessorIdx(c);
3653 else
3654 return getPointAccessorIdx(c);
3655 }
3656
3657 bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const {
3658 if (int idx = getAccessorIdx(c, isNumericAccessor)+1)
3659 return unsigned(idx-1) < getNumElements();
3660 return false;
3661 }
3662
3663 bool isSugared() const { return false; }
3664 QualType desugar() const { return QualType(this, 0); }
3665
3666 static bool classof(const Type *T) {
3667 return T->getTypeClass() == ExtVector;
3668 }
3669};
3670
3671/// Represents a matrix type, as defined in the Matrix Types clang extensions.
3672/// __attribute__((matrix_type(rows, columns))), where "rows" specifies
3673/// number of rows and "columns" specifies the number of columns.
3674class MatrixType : public Type, public llvm::FoldingSetNode {
3675protected:
3676 friend class ASTContext;
3677
3678 /// The element type of the matrix.
3680
3681 MatrixType(QualType ElementTy, QualType CanonElementTy);
3682
3683 MatrixType(TypeClass TypeClass, QualType ElementTy, QualType CanonElementTy,
3684 const Expr *RowExpr = nullptr, const Expr *ColumnExpr = nullptr);
3685
3686public:
3687 /// Returns type of the elements being stored in the matrix
3688 QualType getElementType() const { return ElementType; }
3689
3690 /// Valid elements types are the following:
3691 /// * an integer type (as in C23 6.2.5p22), but excluding enumerated types
3692 /// and _Bool
3693 /// * the standard floating types float or double
3694 /// * a half-precision floating point type, if one is supported on the target
3696 return T->isDependentType() ||
3697 (T->isRealType() && !T->isBooleanType() && !T->isEnumeralType());
3698 }
3699
3700 bool isSugared() const { return false; }
3701 QualType desugar() const { return QualType(this, 0); }
3702
3703 static bool classof(const Type *T) {
3704 return T->getTypeClass() == ConstantMatrix ||
3705 T->getTypeClass() == DependentSizedMatrix;
3706 }
3707};
3708
3709/// Represents a concrete matrix type with constant number of rows and columns
3710class ConstantMatrixType final : public MatrixType {
3711protected:
3712 friend class ASTContext;
3713
3714 /// Number of rows and columns.
3715 unsigned NumRows;
3716 unsigned NumColumns;
3717
3718 static constexpr unsigned MaxElementsPerDimension = (1 << 20) - 1;
3719
3720 ConstantMatrixType(QualType MatrixElementType, unsigned NRows,
3721 unsigned NColumns, QualType CanonElementType);
3722
3723 ConstantMatrixType(TypeClass typeClass, QualType MatrixType, unsigned NRows,
3724 unsigned NColumns, QualType CanonElementType);
3725
3726public:
3727 /// Returns the number of rows in the matrix.
3728 unsigned getNumRows() const { return NumRows; }
3729
3730 /// Returns the number of columns in the matrix.
3731 unsigned getNumColumns() const { return NumColumns; }
3732
3733 /// Returns the number of elements required to embed the matrix into a vector.
3734 unsigned getNumElementsFlattened() const {
3735 return getNumRows() * getNumColumns();
3736 }
3737
3738 /// Returns true if \p NumElements is a valid matrix dimension.
3739 static constexpr bool isDimensionValid(size_t NumElements) {
3740 return NumElements > 0 && NumElements <= MaxElementsPerDimension;
3741 }
3742
3743 /// Returns the maximum number of elements per dimension.
3744 static constexpr unsigned getMaxElementsPerDimension() {
3745 return MaxElementsPerDimension;
3746 }
3747
3748 void Profile(llvm::FoldingSetNodeID &ID) {
3749 Profile(ID, getElementType(), getNumRows(), getNumColumns(),
3750 getTypeClass());
3751 }
3752
3753 static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
3754 unsigned NumRows, unsigned NumColumns,
3756 ID.AddPointer(ElementType.getAsOpaquePtr());
3757 ID.AddInteger(NumRows);
3758 ID.AddInteger(NumColumns);
3759 ID.AddInteger(TypeClass);
3760 }
3761
3762 static bool classof(const Type *T) {
3763 return T->getTypeClass() == ConstantMatrix;
3764 }
3765};
3766
3767/// Represents a matrix type where the type and the number of rows and columns
3768/// is dependent on a template.
3770 friend class ASTContext;
3771
3772 Expr *RowExpr;
3773 Expr *ColumnExpr;
3774
3775 SourceLocation loc;
3776
3777 DependentSizedMatrixType(QualType ElementType, QualType CanonicalType,
3778 Expr *RowExpr, Expr *ColumnExpr, SourceLocation loc);
3779
3780public:
3781 Expr *getRowExpr() const { return RowExpr; }
3782 Expr *getColumnExpr() const { return ColumnExpr; }
3783 SourceLocation getAttributeLoc() const { return loc; }
3784
3785 static bool classof(const Type *T) {
3786 return T->getTypeClass() == DependentSizedMatrix;
3787 }
3788
3789 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
3790 Profile(ID, Context, getElementType(), getRowExpr(), getColumnExpr());
3791 }
3792
3793 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3794 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr);
3795};
3796
3797/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base
3798/// class of FunctionNoProtoType and FunctionProtoType.
3799class FunctionType : public Type {
3800 // The type returned by the function.
3801 QualType ResultType;
3802
3803public:
3804 /// Interesting information about a specific parameter that can't simply
3805 /// be reflected in parameter's type. This is only used by FunctionProtoType
3806 /// but is in FunctionType to make this class available during the
3807 /// specification of the bases of FunctionProtoType.
3808 ///
3809 /// It makes sense to model language features this way when there's some
3810 /// sort of parameter-specific override (such as an attribute) that
3811 /// affects how the function is called. For example, the ARC ns_consumed
3812 /// attribute changes whether a parameter is passed at +0 (the default)
3813 /// or +1 (ns_consumed). This must be reflected in the function type,
3814 /// but isn't really a change to the parameter type.
3815 ///
3816 /// One serious disadvantage of modelling language features this way is
3817 /// that they generally do not work with language features that attempt
3818 /// to destructure types. For example, template argument deduction will
3819 /// not be able to match a parameter declared as
3820 /// T (*)(U)
3821 /// against an argument of type
3822 /// void (*)(__attribute__((ns_consumed)) id)
3823 /// because the substitution of T=void, U=id into the former will
3824 /// not produce the latter.
3826 enum {
3827 ABIMask = 0x0F,
3828 IsConsumed = 0x10,
3829 HasPassObjSize = 0x20,
3830 IsNoEscape = 0x40,
3831 };
3832 unsigned char Data = 0;
3833
3834 public:
3835 ExtParameterInfo() = default;
3836
3837 /// Return the ABI treatment of this parameter.
3838 ParameterABI getABI() const { return ParameterABI(Data & ABIMask); }
3840 ExtParameterInfo copy = *this;
3841 copy.Data = (copy.Data & ~ABIMask) | unsigned(kind);
3842 return copy;
3843 }
3844
3845 /// Is this parameter considered "consumed" by Objective-C ARC?
3846 /// Consumed parameters must have retainable object type.
3847 bool isConsumed() const { return (Data & IsConsumed); }
3848 ExtParameterInfo withIsConsumed(bool consumed) const {
3849 ExtParameterInfo copy = *this;
3850 if (consumed)
3851 copy.Data |= IsConsumed;
3852 else
3853 copy.Data &= ~IsConsumed;
3854 return copy;
3855 }
3856
3857 bool hasPassObjectSize() const { return Data & HasPassObjSize; }
3859 ExtParameterInfo Copy = *this;
3860 Copy.Data |= HasPassObjSize;
3861 return Copy;
3862 }
3863
3864 bool isNoEscape() const { return Data & IsNoEscape; }
3865 ExtParameterInfo withIsNoEscape(bool NoEscape) const {
3866 ExtParameterInfo Copy = *this;
3867 if (NoEscape)
3868 Copy.Data |= IsNoEscape;
3869 else
3870 Copy.Data &= ~IsNoEscape;
3871 return Copy;
3872 }
3873
3874 unsigned char getOpaqueValue() const { return Data; }
3875 static ExtParameterInfo getFromOpaqueValue(unsigned char data) {
3876 ExtParameterInfo result;
3877 result.Data = data;
3878 return result;
3879 }
3880
3882 return lhs.Data == rhs.Data;
3883 }
3884
3886 return lhs.Data != rhs.Data;
3887 }
3888 };
3889
3890 /// A class which abstracts out some details necessary for
3891 /// making a call.
3892 ///
3893 /// It is not actually used directly for storing this information in
3894 /// a FunctionType, although FunctionType does currently use the
3895 /// same bit-pattern.
3896 ///
3897 // If you add a field (say Foo), other than the obvious places (both,
3898 // constructors, compile failures), what you need to update is
3899 // * Operator==
3900 // * getFoo
3901 // * withFoo
3902 // * functionType. Add Foo, getFoo.
3903 // * ASTContext::getFooType
3904 // * ASTContext::mergeFunctionTypes
3905 // * FunctionNoProtoType::Profile
3906 // * FunctionProtoType::Profile
3907 // * TypePrinter::PrintFunctionProto
3908 // * AST read and write
3909 // * Codegen
3910 class ExtInfo {
3911 friend class FunctionType;
3912
3913 // Feel free to rearrange or add bits, but if you go over 16, you'll need to
3914 // adjust the Bits field below, and if you add bits, you'll need to adjust
3915 // Type::FunctionTypeBitfields::ExtInfo as well.
3916
3917 // | CC |noreturn|produces|nocallersavedregs|regparm|nocfcheck|cmsenscall|
3918 // |0 .. 4| 5 | 6 | 7 |8 .. 10| 11 | 12 |
3919 //
3920 // regparm is either 0 (no regparm attribute) or the regparm value+1.
3921 enum { CallConvMask = 0x1F };
3922 enum { NoReturnMask = 0x20 };
3923 enum { ProducesResultMask = 0x40 };
3924 enum { NoCallerSavedRegsMask = 0x80 };
3925 enum {
3926 RegParmMask = 0x700,
3927 RegParmOffset = 8
3928 };
3929 enum { NoCfCheckMask = 0x800 };
3930 enum { CmseNSCallMask = 0x1000 };
3931 uint16_t Bits = CC_C;
3932
3933 ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
3934
3935 public:
3936 // Constructor with no defaults. Use this when you know that you
3937 // have all the elements (when reading an AST file for example).
3938 ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
3939 bool producesResult, bool noCallerSavedRegs, bool NoCfCheck,
3940 bool cmseNSCall) {
3941 assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
3942 Bits = ((unsigned)cc) | (noReturn ? NoReturnMask : 0) |
3943 (producesResult ? ProducesResultMask : 0) |
3944 (noCallerSavedRegs ? NoCallerSavedRegsMask : 0) |
3945 (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0) |
3946 (NoCfCheck ? NoCfCheckMask : 0) |
3947 (cmseNSCall ? CmseNSCallMask : 0);
3948 }
3949
3950 // Constructor with all defaults. Use when for example creating a
3951 // function known to use defaults.
3952 ExtInfo() = default;
3953
3954 // Constructor with just the calling convention, which is an important part
3955 // of the canonical type.
3956 ExtInfo(CallingConv CC) : Bits(CC) {}
3957
3958 bool getNoReturn() const { return Bits & NoReturnMask; }
3959 bool getProducesResult() const { return Bits & ProducesResultMask; }
3960 bool getCmseNSCall() const { return Bits & CmseNSCallMask; }
3961 bool getNoCallerSavedRegs() const { return Bits & NoCallerSavedRegsMask; }
3962 bool getNoCfCheck() const { return Bits & NoCfCheckMask; }
3963 bool getHasRegParm() const { return ((Bits & RegParmMask) >> RegParmOffset) != 0; }
3964
3965 unsigned getRegParm() const {
3966 unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset;
3967 if (RegParm > 0)
3968 --RegParm;
3969 return RegParm;
3970 }
3971
3972 CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
3973
3974 bool operator==(ExtInfo Other) const {
3975 return Bits == Other.Bits;
3976 }
3977 bool operator!=(ExtInfo Other) const {
3978 return Bits != Other.Bits;
3979 }
3980
3981 // Note that we don't have setters. That is by design, use
3982 // the following with methods instead of mutating these objects.
3983
3984 ExtInfo withNoReturn(bool noReturn) const {
3985 if (noReturn)
3986 return ExtInfo(Bits | NoReturnMask);
3987 else
3988 return ExtInfo(Bits & ~NoReturnMask);
3989 }
3990
3991 ExtInfo withProducesResult(bool producesResult) const {
3992 if (producesResult)
3993 return ExtInfo(Bits | ProducesResultMask);
3994 else
3995 return ExtInfo(Bits & ~ProducesResultMask);
3996 }
3997
3998 ExtInfo withCmseNSCall(bool cmseNSCall) const {
3999 if (cmseNSCall)
4000 return ExtInfo(Bits | CmseNSCallMask);
4001 else
4002 return ExtInfo(Bits & ~CmseNSCallMask);
4003 }
4004
4005 ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const {
4006 if (noCallerSavedRegs)
4007 return ExtInfo(Bits | NoCallerSavedRegsMask);
4008 else
4009 return ExtInfo(Bits & ~NoCallerSavedRegsMask);
4010 }
4011
4012 ExtInfo withNoCfCheck(bool noCfCheck) const {
4013 if (noCfCheck)
4014 return ExtInfo(Bits | NoCfCheckMask);
4015 else
4016 return ExtInfo(Bits & ~NoCfCheckMask);
4017 }
4018
4019 ExtInfo withRegParm(unsigned RegParm) const {
4020 assert(RegParm < 7 && "Invalid regparm value");
4021 return ExtInfo((Bits & ~RegParmMask) |
4022 ((RegParm + 1) << RegParmOffset));
4023 }
4024
4026 return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
4027 }
4028
4029 void Profile(llvm::FoldingSetNodeID &ID) const {
4030 ID.AddInteger(Bits);
4031 }
4032 };
4033
4034 /// A simple holder for a QualType representing a type in an
4035 /// exception specification. Unfortunately needed by FunctionProtoType
4036 /// because TrailingObjects cannot handle repeated types.
4038
4039 /// A simple holder for various uncommon bits which do not fit in
4040 /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
4041 /// alignment of subsequent objects in TrailingObjects.
4042 struct alignas(void *) FunctionTypeExtraBitfields {
4043 /// The number of types in the exception specification.
4044 /// A whole unsigned is not needed here and according to
4045 /// [implimits] 8 bits would be enough here.
4046 unsigned NumExceptionType : 10;
4047
4048 LLVM_PREFERRED_TYPE(bool)
4049 unsigned HasArmTypeAttributes : 1;
4050
4052 : NumExceptionType(0), HasArmTypeAttributes(false) {}
4053 };
4054
4055 /// The AArch64 SME ACLE (Arm C/C++ Language Extensions) define a number
4056 /// of function type attributes that can be set on function types, including
4057 /// function pointers.
4059 SME_NormalFunction = 0,
4060 SME_PStateSMEnabledMask = 1 << 0,
4061 SME_PStateSMCompatibleMask = 1 << 1,
4062
4063 // Describes the value of the state using ArmStateValue.
4064 SME_ZAShift = 2,
4065 SME_ZAMask = 0b111 << SME_ZAShift,
4066 SME_ZT0Shift = 5,
4067 SME_ZT0Mask = 0b111 << SME_ZT0Shift,
4068
4069 SME_AttributeMask =
4070 0b111'111'11 // We can't support more than 8 bits because of
4071 // the bitmask in FunctionTypeExtraBitfields.
4073
4074 enum ArmStateValue : unsigned {
4075 ARM_None = 0,
4076 ARM_Preserves = 1,
4077 ARM_In = 2,
4078 ARM_Out = 3,
4079 ARM_InOut = 4,
4080 };
4081
4082 static ArmStateValue getArmZAState(unsigned AttrBits) {
4083 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
4084 }
4085
4086 static ArmStateValue getArmZT0State(unsigned AttrBits) {
4087 return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
4088 }
4089
4090 /// A holder for Arm type attributes as described in the Arm C/C++
4091 /// Language extensions which are not particularly common to all
4092 /// types and therefore accounted separately from FunctionTypeBitfields.
4093 struct alignas(void *) FunctionTypeArmAttributes {
4094 /// Any AArch64 SME ACLE type attributes that need to be propagated
4095 /// on declarations and function pointers.
4097
4098 FunctionTypeArmAttributes() : AArch64SMEAttributes(SME_NormalFunction) {}
4099 };
4100
4101protected:
4104 : Type(tc, Canonical, Dependence), ResultType(res) {
4105 FunctionTypeBits.ExtInfo = Info.Bits;
4106 }
4107
4109 if (isFunctionProtoType())
4110 return Qualifiers::fromFastMask(FunctionTypeBits.FastTypeQuals);
4111
4112 return Qualifiers();
4113 }
4114
4115public:
4116 QualType getReturnType() const { return ResultType; }
4117
4118 bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
4119 unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
4120
4121 /// Determine whether this function type includes the GNU noreturn
4122 /// attribute. The C++11 [[noreturn]] attribute does not affect the function
4123 /// type.
4124 bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
4125
4126 bool getCmseNSCallAttr() const { return getExtInfo().getCmseNSCall(); }
4127 CallingConv getCallConv() const { return getExtInfo().getCC(); }
4128 ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
4129
4130 static_assert((~Qualifiers::FastMask & Qualifiers::CVRMask) == 0,
4131 "Const, volatile and restrict are assumed to be a subset of "
4132 "the fast qualifiers.");
4133
4134 bool isConst() const { return getFastTypeQuals().hasConst(); }
4135 bool isVolatile() const { return getFastTypeQuals().hasVolatile(); }
4136 bool isRestrict() const { return getFastTypeQuals().hasRestrict(); }
4137
4138 /// Determine the type of an expression that calls a function of
4139 /// this type.
4140 QualType getCallResultType(const ASTContext &Context) const {
4141 return getReturnType().getNonLValueExprType(Context);
4142 }
4143
4144 static StringRef getNameForCallConv(CallingConv CC);
4145
4146 static bool classof(const Type *T) {
4147 return T->getTypeClass() == FunctionNoProto ||
4148 T->getTypeClass() == FunctionProto;
4149 }
4150};
4151
4152/// Represents a K&R-style 'int foo()' function, which has
4153/// no information available about its arguments.
4154class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
4155 friend class ASTContext; // ASTContext creates these.
4156
4157 FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
4158 : FunctionType(FunctionNoProto, Result, Canonical,
4159 Result->getDependence() &
4160 ~(TypeDependence::DependentInstantiation |
4161 TypeDependence::UnexpandedPack),
4162 Info) {}
4163
4164public:
4165 // No additional state past what FunctionType provides.
4166
4167 bool isSugared() const { return false; }
4168 QualType desugar() const { return QualType(this, 0); }
4169
4170 void Profile(llvm::FoldingSetNodeID &ID) {
4171 Profile(ID, getReturnType(), getExtInfo());
4172 }
4173
4174 static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
4175 ExtInfo Info) {
4176 Info.Profile(ID);
4177 ID.AddPointer(ResultType.getAsOpaquePtr());
4178 }
4179
4180 static bool classof(const Type *T) {
4181 return T->getTypeClass() == FunctionNoProto;
4182 }
4183};
4184
4185/// Represents a prototype with parameter type info, e.g.
4186/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no
4187/// parameters, not as having a single void parameter. Such a type can have
4188/// an exception specification, but this specification is not part of the
4189/// canonical type. FunctionProtoType has several trailing objects, some of
4190/// which optional. For more information about the trailing objects see
4191/// the first comment inside FunctionProtoType.
4193 : public FunctionType,
4194 public llvm::FoldingSetNode,
4195 private llvm::TrailingObjects<
4196 FunctionProtoType, QualType, SourceLocation,
4197 FunctionType::FunctionTypeExtraBitfields,
4198 FunctionType::FunctionTypeArmAttributes, FunctionType::ExceptionType,
4199 Expr *, FunctionDecl *, FunctionType::ExtParameterInfo, Qualifiers> {
4200 friend class ASTContext; // ASTContext creates these.
4201 friend TrailingObjects;
4202
4203 // FunctionProtoType is followed by several trailing objects, some of
4204 // which optional. They are in order:
4205 //
4206 // * An array of getNumParams() QualType holding the parameter types.
4207 // Always present. Note that for the vast majority of FunctionProtoType,
4208 // these will be the only trailing objects.
4209 //
4210 // * Optionally if the function is variadic, the SourceLocation of the
4211 // ellipsis.
4212 //
4213 // * Optionally if some extra data is stored in FunctionTypeExtraBitfields
4214 // (see FunctionTypeExtraBitfields and FunctionTypeBitfields):
4215 // a single FunctionTypeExtraBitfields. Present if and only if
4216 // hasExtraBitfields() is true.
4217 //
4218 // * Optionally exactly one of:
4219 // * an array of getNumExceptions() ExceptionType,
4220 // * a single Expr *,
4221 // * a pair of FunctionDecl *,
4222 // * a single FunctionDecl *
4223 // used to store information about the various types of exception
4224 // specification. See getExceptionSpecSize for the details.
4225 //
4226 // * Optionally an array of getNumParams() ExtParameterInfo holding
4227 // an ExtParameterInfo for each of the parameters. Present if and
4228 // only if hasExtParameterInfos() is true.
4229 //
4230 // * Optionally a Qualifiers object to represent extra qualifiers that can't
4231 // be represented by FunctionTypeBitfields.FastTypeQuals. Present if and only
4232 // if hasExtQualifiers() is true.
4233 //
4234 // The optional FunctionTypeExtraBitfields has to be before the data
4235 // related to the exception specification since it contains the number
4236 // of exception types.
4237 //
4238 // We put the ExtParameterInfos last. If all were equal, it would make
4239 // more sense to put these before the exception specification, because
4240 // it's much easier to skip past them compared to the elaborate switch
4241 // required to skip the exception specification. However, all is not
4242 // equal; ExtParameterInfos are used to model very uncommon features,
4243 // and it's better not to burden the more common paths.
4244
4245public:
4246 /// Holds information about the various types of exception specification.
4247 /// ExceptionSpecInfo is not stored as such in FunctionProtoType but is
4248 /// used to group together the various bits of information about the
4249 /// exception specification.
4251 /// The kind of exception specification this is.
4253
4254 /// Explicitly-specified list of exception types.
4256
4257 /// Noexcept expression, if this is a computed noexcept specification.
4258 Expr *NoexceptExpr = nullptr;
4259
4260 /// The function whose exception specification this is, for
4261 /// EST_Unevaluated and EST_Uninstantiated.
4262 FunctionDecl *SourceDecl = nullptr;
4263
4264 /// The function template whose exception specification this is instantiated
4265 /// from, for EST_Uninstantiated.
4266 FunctionDecl *SourceTemplate = nullptr;
4267
4269
4271
4272 void instantiate();
4273 };
4274
4275 /// Extra information about a function prototype. ExtProtoInfo is not
4276 /// stored as such in FunctionProtoType but is used to group together
4277 /// the various bits of extra information about a function prototype.
4280 unsigned Variadic : 1;
4281 unsigned HasTrailingReturn : 1;
4286 const ExtParameterInfo *ExtParameterInfos = nullptr;
4288
4290 : Variadic(false), HasTrailingReturn(false),
4291 AArch64SMEAttributes(SME_NormalFunction) {}
4292
4294 : ExtInfo(CC), Variadic(false), HasTrailingReturn(false),
4295 AArch64SMEAttributes(SME_NormalFunction) {}
4296
4298 ExtProtoInfo Result(*this);
4299 Result.ExceptionSpec = ESI;
4300 return Result;
4301 }
4302
4304 return ExceptionSpec.Type == EST_Dynamic ||
4305 requiresFunctionProtoTypeArmAttributes();
4306 }
4307
4309 return AArch64SMEAttributes != SME_NormalFunction;
4310 }
4311
4312 void setArmSMEAttribute(AArch64SMETypeAttributes Kind, bool Enable = true) {
4313 if (Enable)
4314 AArch64SMEAttributes |= Kind;
4315 else
4316 AArch64SMEAttributes &= ~Kind;
4317 }
4318 };
4319
4320private:
4321 unsigned numTrailingObjects(OverloadToken<QualType>) const {
4322 return getNumParams();
4323 }
4324
4325 unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
4326 return isVariadic();
4327 }
4328
4329 unsigned numTrailingObjects(OverloadToken<FunctionTypeArmAttributes>) const {
4330 return hasArmTypeAttributes();
4331 }
4332
4333 unsigned numTrailingObjects(OverloadToken<FunctionTypeExtraBitfields>) const {
4334 return hasExtraBitfields();
4335 }
4336
4337 unsigned numTrailingObjects(OverloadToken<ExceptionType>) const {
4338 return getExceptionSpecSize().NumExceptionType;
4339 }
4340
4341 unsigned numTrailingObjects(OverloadToken<Expr *>) const {
4342 return getExceptionSpecSize().NumExprPtr;
4343 }
4344
4345 unsigned numTrailingObjects(OverloadToken<FunctionDecl *>) const {
4346 return getExceptionSpecSize().NumFunctionDeclPtr;
4347 }
4348
4349 unsigned numTrailingObjects(OverloadToken<ExtParameterInfo>) const {
4350 return hasExtParameterInfos() ? getNumParams() : 0;
4351 }
4352
4353 /// Determine whether there are any argument types that
4354 /// contain an unexpanded parameter pack.
4355 static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
4356 unsigned numArgs) {
4357 for (unsigned Idx = 0; Idx < numArgs; ++Idx)
4358 if (ArgArray[Idx]->containsUnexpandedParameterPack())
4359 return true;
4360
4361 return false;
4362 }
4363
4364 FunctionProtoType(QualType result, ArrayRef<QualType> params,
4365 QualType canonical, const ExtProtoInfo &epi);
4366
4367 /// This struct is returned by getExceptionSpecSize and is used to
4368 /// translate an ExceptionSpecificationType to the number and kind
4369 /// of trailing objects related to the exception specification.
4370 struct ExceptionSpecSizeHolder {
4371 unsigned NumExceptionType;
4372 unsigned NumExprPtr;
4373 unsigned NumFunctionDeclPtr;
4374 };
4375
4376 /// Return the number and kind of trailing objects
4377 /// related to the exception specification.
4378 static ExceptionSpecSizeHolder
4379 getExceptionSpecSize(ExceptionSpecificationType EST, unsigned NumExceptions) {
4380 switch (EST) {
4381 case EST_None:
4382 case EST_DynamicNone:
4383 case EST_MSAny:
4384 case EST_BasicNoexcept:
4385 case EST_Unparsed:
4386 case EST_NoThrow:
4387 return {0, 0, 0};
4388
4389 case EST_Dynamic:
4390 return {NumExceptions, 0, 0};
4391
4393 case EST_NoexceptFalse:
4394 case EST_NoexceptTrue:
4395 return {0, 1, 0};
4396
4397 case EST_Uninstantiated:
4398 return {0, 0, 2};
4399
4400 case EST_Unevaluated:
4401 return {0, 0, 1};
4402 }
4403 llvm_unreachable("bad exception specification kind");
4404 }
4405
4406 /// Return the number and kind of trailing objects
4407 /// related to the exception specification.
4408 ExceptionSpecSizeHolder getExceptionSpecSize() const {
4409 return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions());
4410 }
4411
4412 /// Whether the trailing FunctionTypeExtraBitfields is present.
4413 bool hasExtraBitfields() const {
4414 assert((getExceptionSpecType() != EST_Dynamic ||
4415 FunctionTypeBits.HasExtraBitfields) &&
4416 "ExtraBitfields are required for given ExceptionSpecType");
4417 return FunctionTypeBits.HasExtraBitfields;
4418
4419 }
4420
4421 bool hasArmTypeAttributes() const {
4422 return FunctionTypeBits.HasExtraBitfields &&
4423 getTrailingObjects<FunctionTypeExtraBitfields>()
4424 ->HasArmTypeAttributes;
4425 }
4426
4427 bool hasExtQualifiers() const {
4428 return FunctionTypeBits.HasExtQuals;
4429 }
4430
4431public:
4432 unsigned getNumParams() const { return FunctionTypeBits.NumParams; }
4433
4434 QualType getParamType(unsigned i) const {
4435 assert(i < getNumParams() && "invalid parameter index");
4436 return param_type_begin()[i];
4437 }
4438
4440 return llvm::ArrayRef(param_type_begin(), param_type_end());
4441 }
4442
4444 ExtProtoInfo EPI;
4445 EPI.ExtInfo = getExtInfo();
4446 EPI.Variadic = isVariadic();
4447 EPI.EllipsisLoc = getEllipsisLoc();
4448 EPI.HasTrailingReturn = hasTrailingReturn();
4449 EPI.ExceptionSpec = getExceptionSpecInfo();
4450 EPI.TypeQuals = getMethodQuals();
4451 EPI.RefQualifier = getRefQualifier();
4452 EPI.ExtParameterInfos = getExtParameterInfosOrNull();
4453 EPI.AArch64SMEAttributes = getAArch64SMEAttributes();
4454 return EPI;
4455 }
4456
4457 /// Get the kind of exception specification on this function.
4459 return static_cast<ExceptionSpecificationType>(
4460 FunctionTypeBits.ExceptionSpecType);
4461 }
4462
4463 /// Return whether this function has any kind of exception spec.
4464 bool hasExceptionSpec() const { return getExceptionSpecType() != EST_None; }
4465
4466 /// Return whether this function has a dynamic (throw) exception spec.
4468 return isDynamicExceptionSpec(getExceptionSpecType());
4469 }
4470
4471 /// Return whether this function has a noexcept exception spec.
4473 return isNoexceptExceptionSpec(getExceptionSpecType());
4474 }
4475
4476 /// Return whether this function has a dependent exception spec.
4477 bool hasDependentExceptionSpec() const;
4478
4479 /// Return whether this function has an instantiation-dependent exception
4480 /// spec.
4481 bool hasInstantiationDependentExceptionSpec() const;
4482
4483 /// Return all the available information about this type's exception spec.
4485 ExceptionSpecInfo Result;
4486 Result.Type = getExceptionSpecType();
4487 if (Result.Type == EST_Dynamic) {
4488 Result.Exceptions = exceptions();
4489 } else if (isComputedNoexcept(Result.Type)) {
4490 Result.NoexceptExpr = getNoexceptExpr();
4491 } else if (Result.Type == EST_Uninstantiated) {
4492 Result.SourceDecl = getExceptionSpecDecl();
4493 Result.SourceTemplate = getExceptionSpecTemplate();
4494 } else if (Result.Type == EST_Unevaluated) {
4495 Result.SourceDecl = getExceptionSpecDecl();
4496 }
4497 return Result;
4498 }
4499
4500 /// Return the number of types in the exception specification.
4501 unsigned getNumExceptions() const {
4502 return getExceptionSpecType() == EST_Dynamic
4503 ? getTrailingObjects<FunctionTypeExtraBitfields>()
4504 ->NumExceptionType
4505 : 0;
4506 }
4507
4508 /// Return the ith exception type, where 0 <= i < getNumExceptions().
4509 QualType getExceptionType(unsigned i) const {
4510 assert(i < getNumExceptions() && "Invalid exception number!");
4511 return exception_begin()[i];
4512 }
4513
4514 /// Return the expression inside noexcept(expression), or a null pointer
4515 /// if there is none (because the exception spec is not of this form).
4517 if (!isComputedNoexcept(getExceptionSpecType()))
4518 return nullptr;
4519 return *getTrailingObjects<Expr *>();
4520 }
4521
4522 /// If this function type has an exception specification which hasn't
4523 /// been determined yet (either because it has not been evaluated or because
4524 /// it has not been instantiated), this is the function whose exception
4525 /// specification is represented by this type.
4527 if (getExceptionSpecType() != EST_Uninstantiated &&
4528 getExceptionSpecType() != EST_Unevaluated)
4529 return nullptr;
4530 return getTrailingObjects<FunctionDecl *>()[0];
4531 }
4532
4533 /// If this function type has an uninstantiated exception
4534 /// specification, this is the function whose exception specification
4535 /// should be instantiated to find the exception specification for
4536 /// this type.
4538 if (getExceptionSpecType() != EST_Uninstantiated)
4539 return nullptr;
4540 return getTrailingObjects<FunctionDecl *>()[1];
4541 }
4542
4543 /// Determine whether this function type has a non-throwing exception
4544 /// specification.
4545 CanThrowResult canThrow() const;
4546
4547 /// Determine whether this function type has a non-throwing exception
4548 /// specification. If this depends on template arguments, returns
4549 /// \c ResultIfDependent.
4550 bool isNothrow(bool ResultIfDependent = false) const {
4551 return ResultIfDependent ? canThrow() != CT_Can : canThrow() == CT_Cannot;
4552 }
4553
4554 /// Whether this function prototype is variadic.
4555 bool isVariadic() const { return FunctionTypeBits.Variadic; }
4556
4558 return isVariadic() ? *getTrailingObjects<SourceLocation>()
4559 : SourceLocation();
4560 }
4561
4562 /// Determines whether this function prototype contains a
4563 /// parameter pack at the end.
4564 ///
4565 /// A function template whose last parameter is a parameter pack can be
4566 /// called with an arbitrary number of arguments, much like a variadic
4567 /// function.
4568 bool isTemplateVariadic() const;
4569
4570 /// Whether this function prototype has a trailing return type.
4571 bool hasTrailingReturn() const { return FunctionTypeBits.HasTrailingReturn; }
4572
4574 if (hasExtQualifiers())
4575 return *getTrailingObjects<Qualifiers>();
4576 else
4577 return getFastTypeQuals();
4578 }
4579
4580 /// Retrieve the ref-qualifier associated with this function type.
4582 return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
4583 }
4584
4586
4588 return llvm::ArrayRef(param_type_begin(), param_type_end());
4589 }
4590
4592 return getTrailingObjects<QualType>();
4593 }
4594
4596 return param_type_begin() + getNumParams();
4597 }
4598
4600
4602 return llvm::ArrayRef(exception_begin(), exception_end());
4603 }
4604
4606 return reinterpret_cast<exception_iterator>(
4607 getTrailingObjects<ExceptionType>());
4608 }
4609
4611 return exception_begin() + getNumExceptions();
4612 }
4613
4614 /// Is there any interesting extra information for any of the parameters
4615 /// of this function type?
4617 return FunctionTypeBits.HasExtParameterInfos;
4618 }
4619
4621 assert(hasExtParameterInfos());
4622 return ArrayRef<ExtParameterInfo>(getTrailingObjects<ExtParameterInfo>(),
4623 getNumParams());
4624 }
4625
4626 /// Return a pointer to the beginning of the array of extra parameter
4627 /// information, if present, or else null if none of the parameters
4628 /// carry it. This is equivalent to getExtProtoInfo().ExtParameterInfos.
4630 if (!hasExtParameterInfos())
4631 return nullptr;
4632 return getTrailingObjects<ExtParameterInfo>();
4633 }
4634
4635 /// Return a bitmask describing the SME attributes on the function type, see
4636 /// AArch64SMETypeAttributes for their values.
4637 unsigned getAArch64SMEAttributes() const {
4638 if (!hasArmTypeAttributes())
4639 return SME_NormalFunction;
4640 return getTrailingObjects<FunctionTypeArmAttributes>()
4641 ->AArch64SMEAttributes;
4642 }
4643
4645 assert(I < getNumParams() && "parameter index out of range");
4646 if (hasExtParameterInfos())
4647 return getTrailingObjects<ExtParameterInfo>()[I];
4648 return ExtParameterInfo();
4649 }
4650
4651 ParameterABI getParameterABI(unsigned I) const {
4652 assert(I < getNumParams() && "parameter index out of range");
4653 if (hasExtParameterInfos())
4654 return getTrailingObjects<ExtParameterInfo>()[I].getABI();
4655 return ParameterABI::Ordinary;
4656 }
4657
4658 bool isParamConsumed(unsigned I) const {
4659 assert(I < getNumParams() && "parameter index out of range");
4660 if (hasExtParameterInfos())
4661 return getTrailingObjects<ExtParameterInfo>()[I].isConsumed();
4662 return false;
4663 }
4664
4665 bool isSugared() const { return false; }
4666 QualType desugar() const { return QualType(this, 0); }
4667
4668 void printExceptionSpecification(raw_ostream &OS,
4669 const PrintingPolicy &Policy) const;
4670
4671 static bool classof(const Type *T) {
4672 return T->getTypeClass() == FunctionProto;
4673 }
4674
4675 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
4676 static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
4677 param_type_iterator ArgTys, unsigned NumArgs,
4678 const ExtProtoInfo &EPI, const ASTContext &Context,
4679 bool Canonical);
4680};
4681
4682/// Represents the dependent type named by a dependently-scoped
4683/// typename using declaration, e.g.
4684/// using typename Base<T>::foo;
4685///
4686/// Template instantiation turns these into the underlying type.
4688 friend class ASTContext; // ASTContext creates these.
4689
4691
4693 : Type(UnresolvedUsing, QualType(),
4694 TypeDependence::DependentInstantiation),
4695 Decl(const_cast<UnresolvedUsingTypenameDecl *>(D)) {}
4696
4697public:
4699
4700 bool isSugared() const { return false; }
4701 QualType desugar() const { return QualType(this, 0); }
4702
4703 static bool classof(const Type *T) {
4704 return T->getTypeClass() == UnresolvedUsing;
4705 }
4706
4707 void Profile(llvm::FoldingSetNodeID &ID) {
4708 return Profile(ID, Decl);
4709 }
4710
4711 static void Profile(llvm::FoldingSetNodeID &ID,
4713 ID.AddPointer(D);
4714 }
4715};
4716
4717class UsingType final : public Type,
4718 public llvm::FoldingSetNode,
4719 private llvm::TrailingObjects<UsingType, QualType> {
4720 UsingShadowDecl *Found;
4721 friend class ASTContext; // ASTContext creates these.
4722 friend TrailingObjects;
4723
4724 UsingType(const UsingShadowDecl *Found, QualType Underlying, QualType Canon);
4725
4726public:
4727 UsingShadowDecl *getFoundDecl() const { return Found; }
4729
4730 bool isSugared() const { return true; }
4731
4732 // This always has the 'same' type as declared, but not necessarily identical.
4733 QualType desugar() const { return getUnderlyingType(); }
4734
4735 // Internal helper, for debugging purposes.
4736 bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; }
4737
4738 void Profile(llvm::FoldingSetNodeID &ID) {
4739 Profile(ID, Found, getUnderlyingType());
4740 }
4741 static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl *Found,
4742 QualType Underlying) {
4743 ID.AddPointer(Found);
4744 Underlying.Profile(ID);
4745 }
4746 static bool classof(const Type *T) { return T->getTypeClass() == Using; }
4747};
4748
4749class TypedefType final : public Type,
4750 public llvm::FoldingSetNode,
4751 private llvm::TrailingObjects<TypedefType, QualType> {
4753 friend class ASTContext; // ASTContext creates these.
4754 friend TrailingObjects;
4755
4756 TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType underlying,
4757 QualType can);
4758
4759public:
4760 TypedefNameDecl *getDecl() const { return Decl; }
4761
4762 bool isSugared() const { return true; }
4763
4764 // This always has the 'same' type as declared, but not necessarily identical.
4765 QualType desugar() const;
4766
4767 // Internal helper, for debugging purposes.
4768 bool typeMatchesDecl() const { return !TypedefBits.hasTypeDifferentFromDecl; }
4769
4770 void Profile(llvm::FoldingSetNodeID &ID) {
4771 Profile(ID, Decl, typeMatchesDecl() ? QualType() : desugar());
4772 }
4773 static void Profile(llvm::FoldingSetNodeID &ID, const TypedefNameDecl *Decl,
4774 QualType Underlying) {
4775 ID.AddPointer(Decl);
4776 if (!Underlying.isNull())
4777 Underlying.Profile(ID);
4778 }
4779
4780 static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
4781};
4782
4783/// Sugar type that represents a type that was qualified by a qualifier written
4784/// as a macro invocation.
4785class MacroQualifiedType : public Type {
4786 friend class ASTContext; // ASTContext creates these.
4787
4788 QualType UnderlyingTy;
4789 const IdentifierInfo *MacroII;
4790
4791 MacroQualifiedType(QualType UnderlyingTy, QualType CanonTy,
4792 const IdentifierInfo *MacroII)
4793 : Type(MacroQualified, CanonTy, UnderlyingTy->getDependence()),
4794 UnderlyingTy(UnderlyingTy), MacroII(MacroII) {
4795 assert(isa<AttributedType>(UnderlyingTy) &&
4796 "Expected a macro qualified type to only wrap attributed types.");
4797 }
4798
4799public:
4800 const IdentifierInfo *getMacroIdentifier() const { return MacroII; }
4801 QualType getUnderlyingType() const { return UnderlyingTy; }
4802
4803 /// Return this attributed type's modified type with no qualifiers attached to
4804 /// it.
4805 QualType getModifiedType() const;
4806
4807 bool isSugared() const { return true; }
4808 QualType desugar() const;
4809
4810 static bool classof(const Type *T) {
4811 return T->getTypeClass() == MacroQualified;
4812 }
4813};
4814
4815/// Represents a `typeof` (or __typeof__) expression (a C23 feature and GCC
4816/// extension) or a `typeof_unqual` expression (a C23 feature).
4817class TypeOfExprType : public Type {
4818 Expr *TOExpr;
4819
4820protected:
4821 friend class ASTContext; // ASTContext creates these.
4822
4823 TypeOfExprType(Expr *E, TypeOfKind Kind, QualType Can = QualType());
4824
4825public:
4826 Expr *getUnderlyingExpr() const { return TOExpr; }
4827
4828 /// Returns the kind of 'typeof' type this is.
4830 return TypeOfBits.IsUnqual ? TypeOfKind::Unqualified
4831 : TypeOfKind::Qualified;
4832 }
4833
4834 /// Remove a single level of sugar.
4835 QualType desugar() const;
4836
4837 /// Returns whether this type directly provides sugar.
4838 bool isSugared() const;
4839
4840 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
4841};
4842
4843/// Internal representation of canonical, dependent
4844/// `typeof(expr)` types.
4845///
4846/// This class is used internally by the ASTContext to manage
4847/// canonical, dependent types, only. Clients will only see instances
4848/// of this class via TypeOfExprType nodes.
4850 public llvm::FoldingSetNode {
4851public:
4853
4854 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
4855 Profile(ID, Context, getUnderlyingExpr(),
4856 getKind() == TypeOfKind::Unqualified);
4857 }
4858
4859 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4860 Expr *E, bool IsUnqual);
4861};
4862
4863/// Represents `typeof(type)`, a C23 feature and GCC extension, or
4864/// `typeof_unqual(type), a C23 feature.
4865class TypeOfType : public Type {
4866 friend class ASTContext; // ASTContext creates these.
4867
4868 QualType TOType;
4869
4871 : Type(TypeOf,
4872 Kind == TypeOfKind::Unqualified ? Can.getAtomicUnqualifiedType()
4873 : Can,
4874 T->getDependence()),
4875 TOType(T) {
4876 TypeOfBits.IsUnqual = Kind == TypeOfKind::Unqualified;
4877 }
4878
4879public:
4880 QualType getUnmodifiedType() const { return TOType; }
4881
4882 /// Remove a single level of sugar.
4884 QualType QT = getUnmodifiedType();
4885 return TypeOfBits.IsUnqual ? QT.getAtomicUnqualifiedType() : QT;
4886 }
4887
4888 /// Returns whether this type directly provides sugar.
4889 bool isSugared() const { return true; }
4890
4891 /// Returns the kind of 'typeof' type this is.
4893 return TypeOfBits.IsUnqual ? TypeOfKind::Unqualified
4894 : TypeOfKind::Qualified;
4895 }
4896
4897 static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
4898};
4899
4900/// Represents the type `decltype(expr)` (C++11).
4901class DecltypeType : public Type {
4902 Expr *E;
4903 QualType UnderlyingType;
4904
4905protected:
4906 friend class ASTContext; // ASTContext creates these.
4907
4908 DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
4909
4910public:
4911 Expr *getUnderlyingExpr() const { return E; }
4912 QualType getUnderlyingType() const { return UnderlyingType; }
4913
4914 /// Remove a single level of sugar.
4915 QualType desugar() const;
4916
4917 /// Returns whether this type directly provides sugar.
4918 bool isSugared() const;
4919
4920 static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
4921};
4922
4923/// Internal representation of canonical, dependent
4924/// decltype(expr) types.
4925///
4926/// This class is used internally by the ASTContext to manage
4927/// canonical, dependent types, only. Clients will only see instances
4928/// of this class via DecltypeType nodes.
4929class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
4930public:
4931 DependentDecltypeType(Expr *E, QualType UnderlyingTpe);
4932
4933 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
4934 Profile(ID, Context, getUnderlyingExpr());
4935 }
4936
4937 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4938 Expr *E);
4939};
4940
4942 : public Type,
4943 public llvm::FoldingSetNode,
4944 private llvm::TrailingObjects<PackIndexingType, QualType> {
4945 friend TrailingObjects;
4946
4947 const ASTContext &Context;
4948 QualType Pattern;
4949 Expr *IndexExpr;
4950
4951 unsigned Size;
4952
4953protected:
4954 friend class ASTContext; // ASTContext creates these.
4955 PackIndexingType(const ASTContext &Context, QualType Canonical,
4956 QualType Pattern, Expr *IndexExpr,
4957 ArrayRef<QualType> Expansions = {});
4958
4959public:
4960 Expr *getIndexExpr() const { return IndexExpr; }
4961 QualType getPattern() const { return Pattern; }
4962
4963 bool isSugared() const { return hasSelectedType(); }
4964
4966 if (hasSelectedType())
4967 return getSelectedType();
4968 return QualType(this, 0);
4969 }
4970
4972 assert(hasSelectedType() && "Type is dependant");
4973 return *(getExpansionsPtr() + *getSelectedIndex());
4974 }
4975
4976 std::optional<unsigned> getSelectedIndex() const;
4977
4978 bool hasSelectedType() const { return getSelectedIndex() != std::nullopt; }
4979
4981 return {getExpansionsPtr(), Size};
4982 }
4983
4984 static bool classof(const Type *T) {
4985 return T->getTypeClass() == PackIndexing;
4986 }
4987
4988 void Profile(llvm::FoldingSetNodeID &ID) {
4989 if (hasSelectedType())
4990 getSelectedType().Profile(ID);
4991 else
4992 Profile(ID, Context, getPattern(), getIndexExpr());
4993 }
4994 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4995 QualType Pattern, Expr *E);
4996
4997private:
4998 const QualType *getExpansionsPtr() const {
4999 return getTrailingObjects<QualType>();
5000 }
5001
5002 static TypeDependence computeDependence(QualType Pattern, Expr *IndexExpr,
5003 ArrayRef<QualType> Expansions = {});
5004
5005 unsigned numTrailingObjects(OverloadToken<QualType>) const { return Size; }
5006};
5007
5008/// A unary type transform, which is a type constructed from another.
5009class UnaryTransformType : public Type {
5010public:
5011 enum UTTKind {
5012#define TRANSFORM_TYPE_TRAIT_DEF(Enum, _) Enum,
5013#include "clang/Basic/TransformTypeTraits.def"
5014 };
5015
5016private:
5017 /// The untransformed type.
5018 QualType BaseType;
5019
5020 /// The transformed type if not dependent, otherwise the same as BaseType.
5021 QualType UnderlyingType;
5022
5023 UTTKind UKind;
5024
5025protected:
5026 friend class ASTContext;
5027
5028 UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind,
5029 QualType CanonicalTy);
5030
5031public:
5032 bool isSugared() const { return !isDependentType(); }
5033 QualType desugar() const { return UnderlyingType; }
5034
5035 QualType getUnderlyingType() const { return UnderlyingType; }
5036 QualType getBaseType() const { return BaseType; }
5037
5038 UTTKind getUTTKind() const { return UKind; }
5039
5040 static bool classof(const Type *T) {
5041 return T->getTypeClass() == UnaryTransform;
5042 }
5043};
5044
5045/// Internal representation of canonical, dependent
5046/// __underlying_type(type) types.
5047///
5048/// This class is used internally by the ASTContext to manage
5049/// canonical, dependent types, only. Clients will only see instances
5050/// of this class via UnaryTransformType nodes.
5052 public llvm::FoldingSetNode {
5053public:
5055 UTTKind UKind);
5056
5057 void Profile(llvm::FoldingSetNodeID &ID) {
5058 Profile(ID, getBaseType(), getUTTKind());
5059 }
5060
5061 static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType,
5062 UTTKind UKind) {
5063 ID.AddPointer(BaseType.getAsOpaquePtr());
5064 ID.AddInteger((unsigned)UKind);
5065 }
5066};
5067
5068class TagType : public Type {
5069 friend class ASTReader;
5070 template <class T> friend class serialization::AbstractTypeReader;
5071
5072 /// Stores the TagDecl associated with this type. The decl may point to any
5073 /// TagDecl that declares the entity.
5074 TagDecl *decl;
5075
5076protected:
5077 TagType(TypeClass TC, const TagDecl *D, QualType can);
5078
5079public:
5080 TagDecl *getDecl() const;
5081
5082 /// Determines whether this type is in the process of being defined.
5083 bool isBeingDefined() const;
5084
5085 static bool classof(const Type *T) {
5086 return T->getTypeClass() == Enum || T->getTypeClass() == Record;
5087 }
5088};
5089
5090/// A helper class that allows the use of isa/cast/dyncast
5091/// to detect TagType objects of structs/unions/classes.
5092class RecordType : public TagType {
5093protected:
5094 friend class ASTContext; // ASTContext creates these.
5095
5096 explicit RecordType(const RecordDecl *D)
5097 : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) {}
5099 : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) {}
5100
5101public:
5103 return reinterpret_cast<RecordDecl*>(TagType::getDecl());
5104 }
5105
5106 /// Recursively check all fields in the record for const-ness. If any field
5107 /// is declared const, return true. Otherwise, return false.
5108 bool hasConstFields() const;
5109
5110 bool isSugared() const { return false; }
5111 QualType desugar() const { return QualType(this, 0); }
5112
5113 static bool classof(const Type *T) { return T->getTypeClass() == Record; }
5114};
5115
5116/// A helper class that allows the use of isa/cast/dyncast
5117/// to detect TagType objects of enums.
5118class EnumType : public TagType {
5119 friend class ASTContext; // ASTContext creates these.
5120
5121 explicit EnumType(const EnumDecl *D)
5122 : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) {}
5123
5124public:
5126 return reinterpret_cast<EnumDecl*>(TagType::getDecl());
5127 }
5128
5129 bool isSugared() const { return false; }
5130 QualType desugar() const { return QualType(this, 0); }
5131
5132 static bool classof(const Type *T) { return T->getTypeClass() == Enum; }
5133};
5134
5135/// An attributed type is a type to which a type attribute has been applied.
5136///
5137/// The "modified type" is the fully-sugared type to which the attributed
5138/// type was applied; generally it is not canonically equivalent to the
5139/// attributed type. The "equivalent type" is the minimally-desugared type
5140/// which the type is canonically equivalent to.
5141///
5142/// For example, in the following attributed type:
5143/// int32_t __attribute__((vector_size(16)))
5144/// - the modified type is the TypedefType for int32_t
5145/// - the equivalent type is VectorType(16, int32_t)
5146/// - the canonical type is VectorType(16, int)
5147class AttributedType : public Type, public llvm::FoldingSetNode {
5148public:
5150
5151private:
5152 friend class ASTContext; // ASTContext creates these
5153
5154 QualType ModifiedType;
5155 QualType EquivalentType;
5156
5157 AttributedType(QualType canon, attr::Kind attrKind, QualType modified,
5158 QualType equivalent)
5159 : Type(Attributed, canon, equivalent->getDependence()),
5160 ModifiedType(modified), EquivalentType(equivalent) {
5161 AttributedTypeBits.AttrKind = attrKind;
5162 }
5163
5164public:
5166 return static_cast<Kind>(AttributedTypeBits.AttrKind);
5167 }
5168
5169 QualType getModifiedType() const { return ModifiedType; }
5170 QualType getEquivalentType() const { return EquivalentType; }
5171
5172 bool isSugared() const { return true; }
5173 QualType desugar() const { return getEquivalentType(); }
5174
5175 /// Does this attribute behave like a type qualifier?
5176 ///
5177 /// A type qualifier adjusts a type to provide specialized rules for
5178 /// a specific object, like the standard const and volatile qualifiers.
5179 /// This includes attributes controlling things like nullability,
5180 /// address spaces, and ARC ownership. The value of the object is still
5181 /// largely described by the modified type.
5182 ///
5183 /// In contrast, many type attributes "rewrite" their modified type to
5184 /// produce a fundamentally different type, not necessarily related in any
5185 /// formalizable way to the original type. For example, calling convention
5186 /// and vector attributes are not simple type qualifiers.
5187 ///
5188 /// Type qualifiers are often, but not always, reflected in the canonical
5189 /// type.
5190 bool isQualifier() const;
5191
5192 bool isMSTypeSpec() const;
5193
5194 bool isWebAssemblyFuncrefSpec() const;
5195
5196 bool isCallingConv() const;
5197
5198 std::optional<NullabilityKind> getImmediateNullability() const;
5199
5200 /// Retrieve the attribute kind corresponding to the given
5201 /// nullability kind.
5203 switch (kind) {
5204 case NullabilityKind::NonNull:
5205 return attr::TypeNonNull;
5206
5207 case NullabilityKind::Nullable:
5208 return attr::TypeNullable;
5209
5210 case NullabilityKind::NullableResult:
5211 return attr::TypeNullableResult;
5212
5213 case NullabilityKind::Unspecified:
5214 return attr::TypeNullUnspecified;
5215 }
5216 llvm_unreachable("Unknown nullability kind.");
5217 }
5218
5219 /// Strip off the top-level nullability annotation on the given
5220 /// type, if it's there.
5221 ///
5222 /// \param T The type to strip. If the type is exactly an
5223 /// AttributedType specifying nullability (without looking through
5224 /// type sugar), the nullability is returned and this type changed
5225 /// to the underlying modified type.
5226 ///
5227 /// \returns the top-level nullability, if present.
5228 static std::optional<NullabilityKind> stripOuterNullability(QualType &T);
5229
5230 void Profile(llvm::FoldingSetNodeID &ID) {
5231 Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
5232 }
5233
5234 static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind,
5235 QualType modified, QualType equivalent) {
5236 ID.AddInteger(attrKind);
5237 ID.AddPointer(modified.getAsOpaquePtr());
5238 ID.AddPointer(equivalent.getAsOpaquePtr());
5239 }
5240
5241 static bool classof(const Type *T) {
5242 return T->getTypeClass() == Attributed;
5243 }
5244};
5245
5246class BTFTagAttributedType : public Type, public llvm::FoldingSetNode {
5247private:
5248 friend class ASTContext; // ASTContext creates these
5249
5250 QualType WrappedType;
5251 const BTFTypeTagAttr *BTFAttr;
5252
5253 BTFTagAttributedType(QualType Canon, QualType Wrapped,
5254 const BTFTypeTagAttr *BTFAttr)
5255 : Type(BTFTagAttributed, Canon, Wrapped->getDependence()),
5256 WrappedType(Wrapped), BTFAttr(BTFAttr) {}
5257
5258public:
5259 QualType getWrappedType() const { return WrappedType; }
5260 const BTFTypeTagAttr *getAttr() const { return BTFAttr; }
5261
5262 bool isSugared() const { return true; }
5263 QualType desugar() const { return getWrappedType(); }
5264
5265 void Profile(llvm::FoldingSetNodeID &ID) {
5266 Profile(ID, WrappedType, BTFAttr);
5267 }
5268
5269 static void Profile(llvm::FoldingSetNodeID &ID, QualType Wrapped,
5270 const BTFTypeTagAttr *BTFAttr) {
5271 ID.AddPointer(Wrapped.getAsOpaquePtr());
5272 ID.AddPointer(BTFAttr);
5273 }
5274
5275 static bool classof(const Type *T) {
5276 return T->getTypeClass() == BTFTagAttributed;
5277 }
5278};
5279
5280class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
5281 friend class ASTContext; // ASTContext creates these
5282
5283 // Helper data collector for canonical types.
5284 struct CanonicalTTPTInfo {
5285 unsigned Depth : 15;
5286 unsigned ParameterPack : 1;
5287 unsigned Index : 16;
5288 };
5289
5290 union {
5291 // Info for the canonical type.
5292 CanonicalTTPTInfo CanTTPTInfo;
5293
5294 // Info for the non-canonical type.
5296 };
5297
5298 /// Build a non-canonical type.
5300 : Type(TemplateTypeParm, Canon,
5301 TypeDependence::DependentInstantiation |
5302 (Canon->getDependence() & TypeDependence::UnexpandedPack)),
5303 TTPDecl(TTPDecl) {}
5304
5305 /// Build the canonical type.
5306 TemplateTypeParmType(unsigned D, unsigned I, bool PP)
5307 : Type(TemplateTypeParm, QualType(this, 0),
5308 TypeDependence::DependentInstantiation |
5309 (PP ? TypeDependence::UnexpandedPack : TypeDependence::None)) {
5310 CanTTPTInfo.Depth = D;
5311 CanTTPTInfo.Index = I;
5312 CanTTPTInfo.ParameterPack = PP;
5313 }
5314
5315 const CanonicalTTPTInfo& getCanTTPTInfo() const {
5316 QualType Can = getCanonicalTypeInternal();
5317 return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo;
5318 }
5319
5320public:
5321 unsigned getDepth() const { return getCanTTPTInfo().Depth; }
5322 unsigned getIndex() const { return getCanTTPTInfo().Index; }
5323 bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; }
5324
5326 return isCanonicalUnqualified() ? nullptr : TTPDecl;
5327 }
5328
5330
5331 bool isSugared() const { return false; }
5332 QualType desugar() const { return QualType(this, 0); }
5333
5334 void Profile(llvm::FoldingSetNodeID &ID) {
5335 Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
5336 }
5337
5338 static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
5339 unsigned Index, bool ParameterPack,
5340 TemplateTypeParmDecl *TTPDecl) {
5341 ID.AddInteger(Depth);
5342 ID.AddInteger(Index);
5343 ID.AddBoolean(ParameterPack);
5344 ID.AddPointer(TTPDecl);
5345 }
5346
5347 static bool classof(const Type *T) {
5348 return T->getTypeClass() == TemplateTypeParm;
5349 }
5350};
5351
5352/// Represents the result of substituting a type for a template
5353/// type parameter.
5354///
5355/// Within an instantiated template, all template type parameters have
5356/// been replaced with these. They are used solely to record that a
5357/// type was originally written as a template type parameter;
5358/// therefore they are never canonical.
5360 : public Type,
5361 public llvm::FoldingSetNode,
5362 private llvm::TrailingObjects<SubstTemplateTypeParmType, QualType> {
5363 friend class ASTContext;
5364 friend class llvm::TrailingObjects<SubstTemplateTypeParmType, QualType>;
5365
5366 Decl *AssociatedDecl;
5367
5368 SubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
5369 unsigned Index, std::optional<unsigned> PackIndex);
5370
5371public:
5372 /// Gets the type that was substituted for the template
5373 /// parameter.
5375 return SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType
5376 ? *getTrailingObjects<QualType>()
5377 : getCanonicalTypeInternal();
5378 }
5379
5380 /// A template-like entity which owns the whole pattern being substituted.
5381 /// This will usually own a set of template parameters, or in some
5382 /// cases might even be a template parameter itself.
5383 Decl *getAssociatedDecl() const { return AssociatedDecl; }
5384
5385 /// Gets the template parameter declaration that was substituted for.
5387
5388 /// Returns the index of the replaced parameter in the associated declaration.
5389 /// This should match the result of `getReplacedParameter()->getIndex()`.
5390 unsigned getIndex() const { return SubstTemplateTypeParmTypeBits.Index; }
5391
5392 std::optional<unsigned> getPackIndex() const {
5393 if (SubstTemplateTypeParmTypeBits.PackIndex == 0)
5394 return std::nullopt;
5395 return SubstTemplateTypeParmTypeBits.PackIndex - 1;
5396 }
5397
5398 bool isSugared() const { return true; }
5399 QualType desugar() const { return getReplacementType(); }
5400
5401 void Profile(llvm::FoldingSetNodeID &ID) {
5402 Profile(ID, getReplacementType(), getAssociatedDecl(), getIndex(),
5403 getPackIndex());
5404 }
5405
5406 static void Profile(llvm::FoldingSetNodeID &ID, QualType Replacement,
5407 const Decl *AssociatedDecl, unsigned Index,
5408 std::optional<unsigned> PackIndex) {
5409 Replacement.Profile(ID);
5410 ID.AddPointer(AssociatedDecl);
5411 ID.AddInteger(Index);
5412 ID.AddInteger(PackIndex ? *PackIndex - 1 : 0);
5413 }
5414
5415 static bool classof(const Type *T) {
5416 return T->getTypeClass() == SubstTemplateTypeParm;
5417 }
5418};
5419
5420/// Represents the result of substituting a set of types for a template
5421/// type parameter pack.
5422///
5423/// When a pack expansion in the source code contains multiple parameter packs
5424/// and those parameter packs correspond to different levels of template
5425/// parameter lists, this type node is used to represent a template type
5426/// parameter pack from an outer level, which has already had its argument pack
5427/// substituted but that still lives within a pack expansion that itself
5428/// could not be instantiated. When actually performing a substitution into
5429/// that pack expansion (e.g., when all template parameters have corresponding
5430/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
5431/// at the current pack substitution index.
5432class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
5433 friend class ASTContext;
5434
5435 /// A pointer to the set of template arguments that this
5436 /// parameter pack is instantiated with.
5437 const TemplateArgument *Arguments;
5438
5439 llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndFinal;
5440
5441 SubstTemplateTypeParmPackType(QualType Canon, Decl *AssociatedDecl,
5442 unsigned Index, bool Final,
5443 const TemplateArgument &ArgPack);
5444
5445public:
5447
5448 /// A template-like entity which owns the whole pattern being substituted.
5449 /// This will usually own a set of template parameters, or in some
5450 /// cases might even be a template parameter itself.
5451 Decl *getAssociatedDecl() const;
5452
5453 /// Gets the template parameter declaration that was substituted for.
5455
5456 /// Returns the index of the replaced parameter in the associated declaration.
5457 /// This should match the result of `getReplacedParameter()->getIndex()`.
5458 unsigned getIndex() const { return SubstTemplateTypeParmPackTypeBits.Index; }
5459
5460 // When true the substitution will be 'Final' (subst node won't be placed).
5461 bool getFinal() const;
5462
5463 unsigned getNumArgs() const {
5464 return SubstTemplateTypeParmPackTypeBits.NumArgs;
5465 }
5466
5467 bool isSugared() const { return false; }
5468 QualType desugar() const { return QualType(this, 0); }
5469
5470 TemplateArgument getArgumentPack() const;
5471
5472 void Profile(llvm::FoldingSetNodeID &ID);
5473 static void Profile(llvm::FoldingSetNodeID &ID, const Decl *AssociatedDecl,
5474 unsigned Index, bool Final,
5475 const TemplateArgument &ArgPack);
5476
5477 static bool classof(const Type *T) {
5478 return T->getTypeClass() == SubstTemplateTypeParmPack;
5479 }
5480};
5481
5482/// Common base class for placeholders for types that get replaced by
5483/// placeholder type deduction: C++11 auto, C++14 decltype(auto), C++17 deduced
5484/// class template types, and constrained type names.
5485///
5486/// These types are usually a placeholder for a deduced type. However, before
5487/// the initializer is attached, or (usually) if the initializer is
5488/// type-dependent, there is no deduced type and the type is canonical. In
5489/// the latter case, it is also a dependent type.
5490class DeducedType : public Type {
5491 QualType DeducedAsType;
5492
5493protected:
5494 DeducedType(TypeClass TC, QualType DeducedAsType,
5495 TypeDependence ExtraDependence, QualType Canon)
5496 : Type(TC, Canon,
5497 ExtraDependence | (DeducedAsType.isNull()
5499 : DeducedAsType->getDependence() &
5500 ~TypeDependence::VariablyModified)),
5501 DeducedAsType(DeducedAsType) {}
5502
5503public:
5504 bool isSugared() const { return !DeducedAsType.isNull(); }
5506 return isSugared() ? DeducedAsType : QualType(this, 0);
5507 }
5508
5509 /// Get the type deduced for this placeholder type, or null if it
5510 /// has not been deduced.
5511 QualType getDeducedType() const { return DeducedAsType; }
5512 bool isDeduced() const {
5513 return !DeducedAsType.isNull() || isDependentType();
5514 }
5515
5516 static bool classof(const Type *T) {
5517 return T->getTypeClass() == Auto ||
5518 T->getTypeClass() == DeducedTemplateSpecialization;
5519 }
5520};
5521
5522/// Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained
5523/// by a type-constraint.
5524class AutoType : public DeducedType, public llvm::FoldingSetNode {
5525 friend class ASTContext; // ASTContext creates these
5526
5527 ConceptDecl *TypeConstraintConcept;
5528
5529 AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword,
5530 TypeDependence ExtraDependence, QualType Canon, ConceptDecl *CD,
5531 ArrayRef<TemplateArgument> TypeConstraintArgs);
5532
5533public:
5535 return {reinterpret_cast<const TemplateArgument *>(this + 1),
5536 AutoTypeBits.NumArgs};
5537 }
5538
5540 return TypeConstraintConcept;
5541 }
5542
5543 bool isConstrained() const {
5544 return TypeConstraintConcept != nullptr;
5545 }
5546
5547 bool isDecltypeAuto() const {
5548 return getKeyword() == AutoTypeKeyword::DecltypeAuto;
5549 }
5550
5551 bool isGNUAutoType() const {
5552 return getKeyword() == AutoTypeKeyword::GNUAutoType;
5553 }
5554
5556 return (AutoTypeKeyword)AutoTypeBits.Keyword;
5557 }
5558
5559 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context);
5560 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
5561 QualType Deduced, AutoTypeKeyword Keyword,
5562 bool IsDependent, ConceptDecl *CD,
5563 ArrayRef<TemplateArgument> Arguments);
5564
5565 static bool classof(const Type *T) {
5566 return T->getTypeClass() == Auto;
5567 }
5568};
5569
5570/// Represents a C++17 deduced template specialization type.
5572 public llvm::FoldingSetNode {
5573 friend class ASTContext; // ASTContext creates these
5574
5575 /// The name of the template whose arguments will be deduced.
5576 TemplateName Template;
5577
5579 QualType DeducedAsType,
5580 bool IsDeducedAsDependent)
5581 : DeducedType(DeducedTemplateSpecialization, DeducedAsType,
5582 toTypeDependence(Template.getDependence()) |
5583 (IsDeducedAsDependent
5584 ? TypeDependence::DependentInstantiation
5585 : TypeDependence::None),
5586 DeducedAsType.isNull() ? QualType(this, 0)
5587 : DeducedAsType.getCanonicalType()),
5588 Template(Template) {}
5589
5590public:
5591 /// Retrieve the name of the template that we are deducing.
5592 TemplateName getTemplateName() const { return Template;}
5593
5594 void Profile(llvm::FoldingSetNodeID &ID) {
5595 Profile(ID, getTemplateName(), getDeducedType(), isDependentType());
5596 }
5597
5598 static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template,
5599 QualType Deduced, bool IsDependent) {
5600 Template.Profile(ID);
5601 QualType CanonicalType =
5602 Deduced.isNull() ? Deduced : Deduced.getCanonicalType();
5603 ID.AddPointer(CanonicalType.getAsOpaquePtr());
5604 ID.AddBoolean(IsDependent || Template.isDependent());
5605 }
5606
5607 static bool classof(const Type *T) {
5608 return T->getTypeClass() == DeducedTemplateSpecialization;
5609 }
5610};
5611
5612/// Represents a type template specialization; the template
5613/// must be a class template, a type alias template, or a template
5614/// template parameter. A template which cannot be resolved to one of
5615/// these, e.g. because it is written with a dependent scope
5616/// specifier, is instead represented as a
5617/// @c DependentTemplateSpecializationType.
5618///
5619/// A non-dependent template specialization type is always "sugar",
5620/// typically for a \c RecordType. For example, a class template
5621/// specialization type of \c vector<int> will refer to a tag type for
5622/// the instantiation \c std::vector<int, std::allocator<int>>
5623///
5624/// Template specializations are dependent if either the template or
5625/// any of the template arguments are dependent, in which case the
5626/// type may also be canonical.
5627///
5628/// Instances of this type are allocated with a trailing array of
5629/// TemplateArguments, followed by a QualType representing the
5630/// non-canonical aliased type when the template is a type alias
5631/// template.
5632class TemplateSpecializationType : public Type, public llvm::FoldingSetNode {
5633 friend class ASTContext; // ASTContext creates these
5634
5635 /// The name of the template being specialized. This is
5636 /// either a TemplateName::Template (in which case it is a
5637 /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a
5638 /// TypeAliasTemplateDecl*), a
5639 /// TemplateName::SubstTemplateTemplateParmPack, or a
5640 /// TemplateName::SubstTemplateTemplateParm (in which case the
5641 /// replacement must, recursively, be one of these).
5642 TemplateName Template;
5643
5646 QualType Canon,
5647 QualType Aliased);
5648
5649public:
5650 /// Determine whether any of the given template arguments are dependent.
5651 ///
5652 /// The converted arguments should be supplied when known; whether an
5653 /// argument is dependent can depend on the conversions performed on it
5654 /// (for example, a 'const int' passed as a template argument might be
5655 /// dependent if the parameter is a reference but non-dependent if the
5656 /// parameter is an int).
5657 ///
5658 /// Note that the \p Args parameter is unused: this is intentional, to remind
5659 /// the caller that they need to pass in the converted arguments, not the
5660 /// specified arguments.
5661 static bool
5662 anyDependentTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
5663 ArrayRef<TemplateArgument> Converted);
5664 static bool
5665 anyDependentTemplateArguments(const TemplateArgumentListInfo &,
5666 ArrayRef<TemplateArgument> Converted);
5667 static bool anyInstantiationDependentTemplateArguments(
5669
5670 /// True if this template specialization type matches a current
5671 /// instantiation in the context in which it is found.
5673 return isa<InjectedClassNameType>(getCanonicalTypeInternal());
5674 }
5675
5676 /// Determine if this template specialization type is for a type alias
5677 /// template that has been substituted.
5678 ///
5679 /// Nearly every template specialization type whose template is an alias
5680 /// template will be substituted. However, this is not the case when
5681 /// the specialization contains a pack expansion but the template alias
5682 /// does not have a corresponding parameter pack, e.g.,
5683 ///
5684 /// \code
5685 /// template<typename T, typename U, typename V> struct S;
5686 /// template<typename T, typename U> using A = S<T, int, U>;
5687 /// template<typename... Ts> struct X {
5688 /// typedef A<Ts...> type; // not a type alias
5689 /// };
5690 /// \endcode
5691 bool isTypeAlias() const { return TemplateSpecializationTypeBits.TypeAlias; }
5692
5693 /// Get the aliased type, if this is a specialization of a type alias
5694 /// template.
5695 QualType getAliasedType() const;
5696
5697 /// Retrieve the name of the template that we are specializing.
5698 TemplateName getTemplateName() const { return Template; }
5699
5701 return {reinterpret_cast<const TemplateArgument *>(this + 1),
5702 TemplateSpecializationTypeBits.NumArgs};
5703 }
5704
5705 bool isSugared() const {
5706 return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
5707 }
5708
5710 return isTypeAlias() ? getAliasedType() : getCanonicalTypeInternal();
5711 }
5712
5713 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
5714 static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
5716 const ASTContext &Context);
5717
5718 static bool classof(const Type *T) {
5719 return T->getTypeClass() == TemplateSpecialization;
5720 }
5721};
5722
5723/// Print a template argument list, including the '<' and '>'
5724/// enclosing the template arguments.
5725void printTemplateArgumentList(raw_ostream &OS,
5726 ArrayRef<TemplateArgument> Args,
5727 const PrintingPolicy &Policy,
5728 const TemplateParameterList *TPL = nullptr);
5729
5730void printTemplateArgumentList(raw_ostream &OS,
5731 ArrayRef<TemplateArgumentLoc> Args,
5732 const PrintingPolicy &Policy,
5733 const TemplateParameterList *TPL = nullptr);
5734
5735void printTemplateArgumentList(raw_ostream &OS,
5736 const TemplateArgumentListInfo &Args,
5737 const PrintingPolicy &Policy,
5738 const TemplateParameterList *TPL = nullptr);
5739
5740/// Make a best-effort determination of whether the type T can be produced by
5741/// substituting Args into the default argument of Param.
5742bool isSubstitutedDefaultArgument(ASTContext &Ctx, TemplateArgument Arg,
5743 const NamedDecl *Param,
5744 ArrayRef<TemplateArgument> Args,
5745 unsigned Depth);
5746
5747/// The injected class name of a C++ class template or class
5748/// template partial specialization. Used to record that a type was
5749/// spelled with a bare identifier rather than as a template-id; the
5750/// equivalent for non-templated classes is just RecordType.
5751///
5752/// Injected class name types are always dependent. Template
5753/// instantiation turns these into RecordTypes.
5754///
5755/// Injected class name types are always canonical. This works
5756/// because it is impossible to compare an injected class name type
5757/// with the corresponding non-injected template type, for the same
5758/// reason that it is impossible to directly compare template
5759/// parameters from different dependent contexts: injected class name
5760/// types can only occur within the scope of a particular templated
5761/// declaration, and within that scope every template specialization
5762/// will canonicalize to the injected class name (when appropriate
5763/// according to the rules of the language).
5765 friend class ASTContext; // ASTContext creates these.
5766 friend class ASTNodeImporter;
5767 friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
5768 // currently suitable for AST reading, too much
5769 // interdependencies.
5770 template <class T> friend class serialization::AbstractTypeReader;
5771
5773
5774 /// The template specialization which this type represents.
5775 /// For example, in
5776 /// template <class T> class A { ... };
5777 /// this is A<T>, whereas in
5778 /// template <class X, class Y> class A<B<X,Y> > { ... };
5779 /// this is A<B<X,Y> >.
5780 ///
5781 /// It is always unqualified, always a template specialization type,
5782 /// and always dependent.
5783 QualType InjectedType;
5784
5786 : Type(InjectedClassName, QualType(),
5787 TypeDependence::DependentInstantiation),
5788 Decl(D), InjectedType(TST) {
5789 assert(isa<TemplateSpecializationType>(TST));
5790 assert(!TST.hasQualifiers());
5791 assert(TST->isDependentType());
5792 }
5793
5794public:
5795 QualType getInjectedSpecializationType() const { return InjectedType; }
5796
5798 return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
5799 }
5800
5802 return getInjectedTST()->getTemplateName();
5803 }
5804
5805 CXXRecordDecl *getDecl() const;
5806
5807 bool isSugared() const { return false; }
5808 QualType desugar() const { return QualType(this, 0); }
5809
5810 static bool classof(const Type *T) {
5811 return T->getTypeClass() == InjectedClassName;
5812 }
5813};
5814
5815/// The elaboration keyword that precedes a qualified type name or
5816/// introduces an elaborated-type-specifier.
5818 /// The "struct" keyword introduces the elaborated-type-specifier.
5819 Struct,
5820
5821 /// The "__interface" keyword introduces the elaborated-type-specifier.
5822 Interface,
5823
5824 /// The "union" keyword introduces the elaborated-type-specifier.
5825 Union,
5826
5827 /// The "class" keyword introduces the elaborated-type-specifier.
5828 Class,
5829
5830 /// The "enum" keyword introduces the elaborated-type-specifier.
5831 Enum,
5832
5833 /// The "typename" keyword precedes the qualified type name, e.g.,
5834 /// \c typename T::type.
5835 Typename,
5836
5837 /// No keyword precedes the qualified type name.
5838 None
5839};
5840
5841/// The kind of a tag type.
5842enum class TagTypeKind {
5843 /// The "struct" keyword.
5844 Struct,
5845
5846 /// The "__interface" keyword.
5847 Interface,
5848
5849 /// The "union" keyword.
5850 Union,
5851
5852 /// The "class" keyword.
5853 Class,
5854
5855 /// The "enum" keyword.
5856 Enum
5857};
5858
5859/// A helper class for Type nodes having an ElaboratedTypeKeyword.
5860/// The keyword in stored in the free bits of the base class.
5861/// Also provides a few static helpers for converting and printing
5862/// elaborated type keyword and tag type kind enumerations.
5863class TypeWithKeyword : public Type {
5864protected:
5867 : Type(tc, Canonical, Dependence) {
5868 TypeWithKeywordBits.Keyword = llvm::to_underlying(Keyword);
5869 }
5870
5871public:
5873 return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
5874 }
5875
5876 /// Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
5877 static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
5878
5879 /// Converts a type specifier (DeclSpec::TST) into a tag type kind.
5880 /// It is an error to provide a type specifier which *isn't* a tag kind here.
5881 static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
5882
5883 /// Converts a TagTypeKind into an elaborated type keyword.
5884 static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
5885
5886 /// Converts an elaborated type keyword into a TagTypeKind.
5887 /// It is an error to provide an elaborated type keyword
5888 /// which *isn't* a tag kind here.
5889 static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
5890
5891 static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
5892
5893 static StringRef getKeywordName(ElaboratedTypeKeyword Keyword);
5894
5895 static StringRef getTagTypeKindName(TagTypeKind Kind) {
5896 return getKeywordName(getKeywordForTagTypeKind(Kind));
5897 }
5898
5901};
5902
5903/// Represents a type that was referred to using an elaborated type
5904/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
5905/// or both.
5906///
5907/// This type is used to keep track of a type name as written in the
5908/// source code, including tag keywords and any nested-name-specifiers.
5909/// The type itself is always "sugar", used to express what was written
5910/// in the source code but containing no additional semantic information.
5912 : public TypeWithKeyword,
5913 public llvm::FoldingSetNode,
5914 private llvm::TrailingObjects<ElaboratedType, TagDecl *> {
5915 friend class ASTContext; // ASTContext creates these
5916 friend TrailingObjects;
5917
5918 /// The nested name specifier containing the qualifier.
5920
5921 /// The type that this qualified name refers to.
5922 QualType NamedType;
5923
5924 /// The (re)declaration of this tag type owned by this occurrence is stored
5925 /// as a trailing object if there is one. Use getOwnedTagDecl to obtain
5926 /// it, or obtain a null pointer if there is none.
5927
5929 QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl)
5930 : TypeWithKeyword(Keyword, Elaborated, CanonType,
5931 // Any semantic dependence on the qualifier will have
5932 // been incorporated into NamedType. We still need to
5933 // track syntactic (instantiation / error / pack)
5934 // dependence on the qualifier.
5935 NamedType->getDependence() |
5936 (NNS ? toSyntacticDependence(
5937 toTypeDependence(NNS->getDependence()))
5938 : TypeDependence::None)),
5939 NNS(NNS), NamedType(NamedType) {
5940 ElaboratedTypeBits.HasOwnedTagDecl = false;
5941 if (OwnedTagDecl) {
5942 ElaboratedTypeBits.HasOwnedTagDecl = true;
5943 *getTrailingObjects<TagDecl *>() = OwnedTagDecl;
5944 }
5945 }
5946
5947public:
5948 /// Retrieve the qualification on this type.
5949 NestedNameSpecifier *getQualifier() const { return NNS; }
5950
5951 /// Retrieve the type named by the qualified-id.
5952 QualType getNamedType() const { return NamedType; }
5953
5954 /// Remove a single level of sugar.
5955 QualType desugar() const { return getNamedType(); }
5956
5957 /// Returns whether this type directly provides sugar.
5958 bool isSugared() const { return true; }
5959
5960 /// Return the (re)declaration of this type owned by this occurrence of this
5961 /// type, or nullptr if there is none.
5963 return ElaboratedTypeBits.HasOwnedTagDecl ? *getTrailingObjects<TagDecl *>()
5964 : nullptr;
5965 }
5966
5967 void Profile(llvm::FoldingSetNodeID &ID) {
5968 Profile(ID, getKeyword(), NNS, NamedType, getOwnedTagDecl());
5969 }
5970
5971 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
5972 NestedNameSpecifier *NNS, QualType NamedType,
5973 TagDecl *OwnedTagDecl) {
5974 ID.AddInteger(llvm::to_underlying(Keyword));
5975 ID.AddPointer(NNS);
5976 NamedType.Profile(ID);
5977 ID.AddPointer(OwnedTagDecl);
5978 }
5979
5980 static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; }
5981};
5982
5983/// Represents a qualified type name for which the type name is
5984/// dependent.
5985///
5986/// DependentNameType represents a class of dependent types that involve a
5987/// possibly dependent nested-name-specifier (e.g., "T::") followed by a
5988/// name of a type. The DependentNameType may start with a "typename" (for a
5989/// typename-specifier), "class", "struct", "union", or "enum" (for a
5990/// dependent elaborated-type-specifier), or nothing (in contexts where we
5991/// know that we must be referring to a type, e.g., in a base class specifier).
5992/// Typically the nested-name-specifier is dependent, but in MSVC compatibility
5993/// mode, this type is used with non-dependent names to delay name lookup until
5994/// instantiation.
5995class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
5996 friend class ASTContext; // ASTContext creates these
5997
5998 /// The nested name specifier containing the qualifier.
6000
6001 /// The type that this typename specifier refers to.
6002 const IdentifierInfo *Name;
6003
6005 const IdentifierInfo *Name, QualType CanonType)
6006 : TypeWithKeyword(Keyword, DependentName, CanonType,
6007 TypeDependence::DependentInstantiation |
6008 toTypeDependence(NNS->getDependence())),
6009 NNS(NNS), Name(Name) {}
6010
6011public:
6012 /// Retrieve the qualification on this type.
6013 NestedNameSpecifier *getQualifier() const { return NNS; }
6014
6015 /// Retrieve the type named by the typename specifier as an identifier.
6016 ///
6017 /// This routine will return a non-NULL identifier pointer when the
6018 /// form of the original typename was terminated by an identifier,
6019 /// e.g., "typename T::type".
6021 return Name;
6022 }
6023
6024 bool isSugared() const { return false; }
6025 QualType desugar() const { return QualType(this, 0); }
6026
6027 void Profile(llvm::FoldingSetNodeID &ID) {
6028 Profile(ID, getKeyword(), NNS, Name);
6029 }
6030
6031 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
6032 NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
6033 ID.AddInteger(llvm::to_underlying(Keyword));
6034 ID.AddPointer(NNS);
6035 ID.AddPointer(Name);
6036 }
6037
6038 static bool classof(const Type *T) {
6039 return T->getTypeClass() == DependentName;
6040 }
6041};
6042
6043/// Represents a template specialization type whose template cannot be
6044/// resolved, e.g.
6045/// A<T>::template B<T>
6047 public llvm::FoldingSetNode {
6048 friend class ASTContext; // ASTContext creates these
6049
6050 /// The nested name specifier containing the qualifier.
6052
6053 /// The identifier of the template.
6054 const IdentifierInfo *Name;
6055
6058 const IdentifierInfo *Name,
6060 QualType Canon);
6061
6062public:
6063 NestedNameSpecifier *getQualifier() const { return NNS; }
6064 const IdentifierInfo *getIdentifier() const { return Name; }
6065
6067 return {reinterpret_cast<const TemplateArgument *>(this + 1),
6068 DependentTemplateSpecializationTypeBits.NumArgs};
6069 }
6070
6071 bool isSugared() const { return false; }
6072 QualType desugar() const { return QualType(this, 0); }
6073
6074 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
6075 Profile(ID, Context, getKeyword(), NNS, Name, template_arguments());
6076 }
6077
6078 static void Profile(llvm::FoldingSetNodeID &ID,
6079 const ASTContext &Context,
6080 ElaboratedTypeKeyword Keyword,
6081 NestedNameSpecifier *Qualifier,
6082 const IdentifierInfo *Name,
6084
6085 static bool classof(const Type *T) {
6086 return T->getTypeClass() == DependentTemplateSpecialization;
6087 }
6088};
6089
6090/// Represents a pack expansion of types.
6091///
6092/// Pack expansions are part of C++11 variadic templates. A pack
6093/// expansion contains a pattern, which itself contains one or more
6094/// "unexpanded" parameter packs. When instantiated, a pack expansion
6095/// produces a series of types, each instantiated from the pattern of
6096/// the expansion, where the Ith instantiation of the pattern uses the
6097/// Ith arguments bound to each of the unexpanded parameter packs. The
6098/// pack expansion is considered to "expand" these unexpanded
6099/// parameter packs.
6100///
6101/// \code
6102/// template<typename ...Types> struct tuple;
6103///
6104/// template<typename ...Types>
6105/// struct tuple_of_references {
6106/// typedef tuple<Types&...> type;
6107/// };
6108/// \endcode
6109///
6110/// Here, the pack expansion \c Types&... is represented via a
6111/// PackExpansionType whose pattern is Types&.
6112class PackExpansionType : public Type, public llvm::FoldingSetNode {
6113 friend class ASTContext; // ASTContext creates these
6114
6115 /// The pattern of the pack expansion.
6116 QualType Pattern;
6117
6118 PackExpansionType(QualType Pattern, QualType Canon,
6119 std::optional<unsigned> NumExpansions)
6120 : Type(PackExpansion, Canon,
6121 (Pattern->getDependence() | TypeDependence::Dependent |
6122 TypeDependence::Instantiation) &
6123 ~TypeDependence::UnexpandedPack),
6124 Pattern(Pattern) {
6125 PackExpansionTypeBits.NumExpansions =
6126 NumExpansions ? *NumExpansions + 1 : 0;
6127 }
6128
6129public:
6130 /// Retrieve the pattern of this pack expansion, which is the
6131 /// type that will be repeatedly instantiated when instantiating the
6132 /// pack expansion itself.
6133 QualType getPattern() const { return Pattern; }
6134
6135 /// Retrieve the number of expansions that this pack expansion will
6136 /// generate, if known.
6137 std::optional<unsigned> getNumExpansions() const {
6138 if (PackExpansionTypeBits.NumExpansions)
6139 return PackExpansionTypeBits.NumExpansions - 1;
6140 return std::nullopt;
6141 }
6142
6143 bool isSugared() const { return false; }
6144 QualType desugar() const { return QualType(this, 0); }
6145
6146 void Profile(llvm::FoldingSetNodeID &ID) {
6147 Profile(ID, getPattern(), getNumExpansions());
6148 }
6149
6150 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern,
6151 std::optional<unsigned> NumExpansions) {
6152 ID.AddPointer(Pattern.getAsOpaquePtr());
6153 ID.AddBoolean(NumExpansions.has_value());
6154 if (NumExpansions)
6155 ID.AddInteger(*NumExpansions);
6156 }
6157
6158 static bool classof(const Type *T) {
6159 return T->getTypeClass() == PackExpansion;
6160 }
6161};
6162
6163/// This class wraps the list of protocol qualifiers. For types that can
6164/// take ObjC protocol qualifers, they can subclass this class.
6165template <class T>
6167protected:
6169
6171 return const_cast<ObjCProtocolQualifiers*>(this)->getProtocolStorage();
6172 }
6173
6175 return static_cast<T*>(this)->getProtocolStorageImpl();
6176 }
6177
6178 void setNumProtocols(unsigned N) {
6179 static_cast<T*>(this)->setNumProtocolsImpl(N);
6180 }
6181
6183 setNumProtocols(protocols.size());
6184 assert(getNumProtocols() == protocols.size() &&
6185 "bitfield overflow in protocol count");
6186 if (!protocols.empty())
6187 memcpy(getProtocolStorage(), protocols.data(),
6188 protocols.size() * sizeof(ObjCProtocolDecl*));
6189 }
6190
6191public:
6193 using qual_range = llvm::iterator_range<qual_iterator>;
6194
6195 qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
6196 qual_iterator qual_begin() const { return getProtocolStorage(); }
6197 qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
6198
6199 bool qual_empty() const { return getNumProtocols() == 0; }
6200
6201 /// Return the number of qualifying protocols in this type, or 0 if
6202 /// there are none.
6203 unsigned getNumProtocols() const {
6204 return static_cast<const T*>(this)->getNumProtocolsImpl();
6205 }
6206
6207 /// Fetch a protocol by index.
6208 ObjCProtocolDecl *getProtocol(unsigned I) const {
6209 assert(I < getNumProtocols() && "Out-of-range protocol access");
6210 return qual_begin()[I];
6211 }
6212
6213 /// Retrieve all of the protocol qualifiers.
6215 return ArrayRef<ObjCProtocolDecl *>(qual_begin(), getNumProtocols());
6216 }
6217};
6218
6219/// Represents a type parameter type in Objective C. It can take
6220/// a list of protocols.
6222 public ObjCProtocolQualifiers<ObjCTypeParamType>,
6223 public llvm::FoldingSetNode {
6224 friend class ASTContext;
6226
6227 /// The number of protocols stored on this type.
6228 unsigned NumProtocols : 6;
6229
6230 ObjCTypeParamDecl *OTPDecl;
6231
6232 /// The protocols are stored after the ObjCTypeParamType node. In the
6233 /// canonical type, the list of protocols are sorted alphabetically
6234 /// and uniqued.
6235 ObjCProtocolDecl **getProtocolStorageImpl();
6236
6237 /// Return the number of qualifying protocols in this interface type,
6238 /// or 0 if there are none.
6239 unsigned getNumProtocolsImpl() const {
6240 return NumProtocols;
6241 }
6242
6243 void setNumProtocolsImpl(unsigned N) {
6244 NumProtocols = N;
6245 }
6246
6247 ObjCTypeParamType(const ObjCTypeParamDecl *D,
6248 QualType can,
6249 ArrayRef<ObjCProtocolDecl *> protocols);
6250
6251public:
6252 bool isSugared() const { return true; }
6253 QualType desugar() const { return getCanonicalTypeInternal(); }
6254
6255 static bool classof(const Type *T) {
6256 return T->getTypeClass() == ObjCTypeParam;
6257 }
6258
6259 void Profile(llvm::FoldingSetNodeID &ID);
6260 static void Profile(llvm::FoldingSetNodeID &ID,
6261 const ObjCTypeParamDecl *OTPDecl,
6262 QualType CanonicalType,
6264
6265 ObjCTypeParamDecl *getDecl() const { return OTPDecl; }
6266};
6267
6268/// Represents a class type in Objective C.
6269///
6270/// Every Objective C type is a combination of a base type, a set of
6271/// type arguments (optional, for parameterized classes) and a list of
6272/// protocols.
6273///
6274/// Given the following declarations:
6275/// \code
6276/// \@class C<T>;
6277/// \@protocol P;
6278/// \endcode
6279///
6280/// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType
6281/// with base C and no protocols.
6282///
6283/// 'C<P>' is an unspecialized ObjCObjectType with base C and protocol list [P].
6284/// 'C<C*>' is a specialized ObjCObjectType with type arguments 'C*' and no
6285/// protocol list.
6286/// 'C<C*><P>' is a specialized ObjCObjectType with base C, type arguments 'C*',
6287/// and protocol list [P].
6288///
6289/// 'id' is a TypedefType which is sugar for an ObjCObjectPointerType whose
6290/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
6291/// and no protocols.
6292///
6293/// 'id<P>' is an ObjCObjectPointerType whose pointee is an ObjCObjectType
6294/// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually
6295/// this should get its own sugar class to better represent the source.
6296class ObjCObjectType : public Type,
6297 public ObjCProtocolQualifiers<ObjCObjectType> {
6299
6300 // ObjCObjectType.NumTypeArgs - the number of type arguments stored
6301 // after the ObjCObjectPointerType node.
6302 // ObjCObjectType.NumProtocols - the number of protocols stored
6303 // after the type arguments of ObjCObjectPointerType node.
6304 //
6305 // These protocols are those written directly on the type. If
6306 // protocol qualifiers ever become additive, the iterators will need
6307 // to get kindof complicated.
6308 //
6309 // In the canonical object type, these are sorted alphabetically
6310 // and uniqued.
6311
6312 /// Either a BuiltinType or an InterfaceType or sugar for either.
6313 QualType BaseType;
6314
6315 /// Cached superclass type.
6316 mutable llvm::PointerIntPair<const ObjCObjectType *, 1, bool>
6317 CachedSuperClassType;
6318
6319 QualType *getTypeArgStorage();
6320 const QualType *getTypeArgStorage() const {
6321 return const_cast<ObjCObjectType *>(this)->getTypeArgStorage();
6322 }
6323
6324 ObjCProtocolDecl **getProtocolStorageImpl();
6325 /// Return the number of qualifying protocols in this interface type,
6326 /// or 0 if there are none.
6327 unsigned getNumProtocolsImpl() const {
6328 return ObjCObjectTypeBits.NumProtocols;
6329 }
6330 void setNumProtocolsImpl(unsigned N) {
6331 ObjCObjectTypeBits.NumProtocols = N;
6332 }
6333
6334protected:
6336
6338 ArrayRef<QualType> typeArgs,
6340 bool isKindOf);
6341
6343 : Type(ObjCInterface, QualType(), TypeDependence::None),
6344 BaseType(QualType(this_(), 0)) {
6345 ObjCObjectTypeBits.NumProtocols = 0;
6346 ObjCObjectTypeBits.NumTypeArgs = 0;
6347 ObjCObjectTypeBits.IsKindOf = 0;
6348 }
6349
6350 void computeSuperClassTypeSlow() const;
6351
6352public:
6353 /// Gets the base type of this object type. This is always (possibly
6354 /// sugar for) one of:
6355 /// - the 'id' builtin type (as opposed to the 'id' type visible to the
6356 /// user, which is a typedef for an ObjCObjectPointerType)
6357 /// - the 'Class' builtin type (same caveat)
6358 /// - an ObjCObjectType (currently always an ObjCInterfaceType)
6359 QualType getBaseType() const { return BaseType; }
6360
6361 bool isObjCId() const {
6362 return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
6363 }
6364
6365 bool isObjCClass() const {
6366 return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
6367 }
6368
6369 bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
6370 bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
6372 if (!qual_empty()) return false;
6373 if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
6374 return T->getKind() == BuiltinType::ObjCId ||
6375 T->getKind() == BuiltinType::ObjCClass;
6376 return false;
6377 }
6378 bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
6379 bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
6380
6381 /// Gets the interface declaration for this object type, if the base type
6382 /// really is an interface.
6383 ObjCInterfaceDecl *getInterface() const;
6384
6385 /// Determine whether this object type is "specialized", meaning
6386 /// that it has type arguments.
6387 bool isSpecialized() const;
6388
6389 /// Determine whether this object type was written with type arguments.
6391 return ObjCObjectTypeBits.NumTypeArgs > 0;
6392 }
6393
6394 /// Determine whether this object type is "unspecialized", meaning
6395 /// that it has no type arguments.
6396 bool isUnspecialized() const { return !isSpecialized(); }
6397
6398 /// Determine whether this object type is "unspecialized" as
6399 /// written, meaning that it has no type arguments.
6400 bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); }
6401
6402 /// Retrieve the type arguments of this object type (semantically).
6403 ArrayRef<QualType> getTypeArgs() const;
6404
6405 /// Retrieve the type arguments of this object type as they were
6406 /// written.
6408 return llvm::ArrayRef(getTypeArgStorage(), ObjCObjectTypeBits.NumTypeArgs);
6409 }
6410
6411 /// Whether this is a "__kindof" type as written.
6412 bool isKindOfTypeAsWritten() const { return ObjCObjectTypeBits.IsKindOf; }
6413
6414 /// Whether this ia a "__kindof" type (semantically).
6415 bool isKindOfType() const;
6416
6417 /// Retrieve the type of the superclass of this object type.
6418 ///
6419 /// This operation substitutes any type arguments into the
6420 /// superclass of the current class type, potentially producing a
6421 /// specialization of the superclass type. Produces a null type if
6422 /// there is no superclass.
6424 if (!CachedSuperClassType.getInt())
6425 computeSuperClassTypeSlow();
6426
6427 assert(CachedSuperClassType.getInt() && "Superclass not set?");
6428 return QualType(CachedSuperClassType.getPointer(), 0);
6429 }
6430
6431 /// Strip off the Objective-C "kindof" type and (with it) any
6432 /// protocol qualifiers.
6433 QualType stripObjCKindOfTypeAndQuals(const ASTContext &ctx) const;
6434
6435 bool isSugared() const { return false; }
6436 QualType desugar() const { return QualType(this, 0); }
6437
6438 static bool classof(const Type *T) {
6439 return T->getTypeClass() == ObjCObject ||
6440 T->getTypeClass() == ObjCInterface;
6441 }
6442};
6443
6444/// A class providing a concrete implementation
6445/// of ObjCObjectType, so as to not increase the footprint of
6446/// ObjCInterfaceType. Code outside of ASTContext and the core type
6447/// system should not reference this type.
6448class ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
6449 friend class ASTContext;
6450
6451 // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
6452 // will need to be modified.
6453
6455 ArrayRef<QualType> typeArgs,
6457 bool isKindOf)
6458 : ObjCObjectType(Canonical, Base, typeArgs, protocols, isKindOf) {}
6459
6460public:
6461 void Profile(llvm::FoldingSetNodeID &ID);
6462 static void Profile(llvm::FoldingSetNodeID &ID,
6463 QualType Base,
6464 ArrayRef<QualType> typeArgs,
6466 bool isKindOf);
6467};
6468
6469inline QualType *ObjCObjectType::getTypeArgStorage() {
6470 return reinterpret_cast<QualType *>(static_cast<ObjCObjectTypeImpl*>(this)+1);
6471}
6472
6473inline ObjCProtocolDecl **ObjCObjectType::getProtocolStorageImpl() {
6474 return reinterpret_cast<ObjCProtocolDecl**>(
6475 getTypeArgStorage() + ObjCObjectTypeBits.NumTypeArgs);
6476}
6477
6478inline ObjCProtocolDecl **ObjCTypeParamType::getProtocolStorageImpl() {
6479 return reinterpret_cast<ObjCProtocolDecl**>(
6480 static_cast<ObjCTypeParamType*>(this)+1);
6481}
6482
6483/// Interfaces are the core concept in Objective-C for object oriented design.
6484/// They basically correspond to C++ classes. There are two kinds of interface
6485/// types: normal interfaces like `NSString`, and qualified interfaces, which
6486/// are qualified with a protocol list like `NSString<NSCopyable, NSAmazing>`.
6487///
6488/// ObjCInterfaceType guarantees the following properties when considered
6489/// as a subtype of its superclass, ObjCObjectType:
6490/// - There are no protocol qualifiers. To reinforce this, code which
6491/// tries to invoke the protocol methods via an ObjCInterfaceType will
6492/// fail to compile.
6493/// - It is its own base type. That is, if T is an ObjCInterfaceType*,
6494/// T->getBaseType() == QualType(T, 0).
6496 friend class ASTContext; // ASTContext creates these.
6497 friend class ASTReader;
6498 template <class T> friend class serialization::AbstractTypeReader;
6499
6501
6504 Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
6505
6506public:
6507 /// Get the declaration of this interface.
6508 ObjCInterfaceDecl *getDecl() const;
6509
6510 bool isSugared() const { return false; }
6511 QualType desugar() const { return QualType(this, 0); }
6512
6513 static bool classof(const Type *T) {
6514 return T->getTypeClass() == ObjCInterface;
6515 }
6516
6517 // Nonsense to "hide" certain members of ObjCObjectType within this
6518 // class. People asking for protocols on an ObjCInterfaceType are
6519 // not going to get what they want: ObjCInterfaceTypes are
6520 // guaranteed to have no protocols.
6521 enum {
6526 getProtocol
6528};
6529
6530inline ObjCInterfaceDecl *ObjCObjectType::getInterface() const {
6531 QualType baseType = getBaseType();
6532 while (const auto *ObjT = baseType->getAs<ObjCObjectType>()) {
6533 if (const auto *T = dyn_cast<ObjCInterfaceType>(ObjT))
6534 return T->getDecl();
6535
6536 baseType = ObjT->getBaseType();
6537 }
6538
6539 return nullptr;
6540}
6541
6542/// Represents a pointer to an Objective C object.
6543///
6544/// These are constructed from pointer declarators when the pointee type is
6545/// an ObjCObjectType (or sugar for one). In addition, the 'id' and 'Class'
6546/// types are typedefs for these, and the protocol-qualified types 'id<P>'
6547/// and 'Class<P>' are translated into these.
6548///
6549/// Pointers to pointers to Objective C objects are still PointerTypes;
6550/// only the first level of pointer gets it own type implementation.
6551class ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
6552 friend class ASTContext; // ASTContext creates these.
6553
6554 QualType PointeeType;
6555
6556 ObjCObjectPointerType(QualType Canonical, QualType Pointee)
6557 : Type(ObjCObjectPointer, Canonical, Pointee->getDependence()),
6558 PointeeType(Pointee) {}
6559
6560public:
6561 /// Gets the type pointed to by this ObjC pointer.
6562 /// The result will always be an ObjCObjectType or sugar thereof.
6563 QualType getPointeeType() const { return PointeeType; }
6564
6565 /// Gets the type pointed to by this ObjC pointer. Always returns non-null.
6566 ///
6567 /// This method is equivalent to getPointeeType() except that
6568 /// it discards any typedefs (or other sugar) between this
6569 /// type and the "outermost" object type. So for:
6570 /// \code
6571 /// \@class A; \@protocol P; \@protocol Q;
6572 /// typedef A<P> AP;
6573 /// typedef A A1;
6574 /// typedef A1<P> A1P;
6575 /// typedef A1P<Q> A1PQ;
6576 /// \endcode
6577 /// For 'A*', getObjectType() will return 'A'.
6578 /// For 'A<P>*', getObjectType() will return 'A<P>'.
6579 /// For 'AP*', getObjectType() will return 'A<P>'.
6580 /// For 'A1*', getObjectType() will return 'A'.
6581 /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
6582 /// For 'A1P*', getObjectType() will return 'A1<P>'.
6583 /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
6584 /// adding protocols to a protocol-qualified base discards the
6585 /// old qualifiers (for now). But if it didn't, getObjectType()
6586 /// would return 'A1P<Q>' (and we'd have to make iterating over
6587 /// qualifiers more complicated).
6589 return PointeeType->castAs<ObjCObjectType>();
6590 }
6591
6592 /// If this pointer points to an Objective C
6593 /// \@interface type, gets the type for that interface. Any protocol
6594 /// qualifiers on the interface are ignored.
6595 ///
6596 /// \return null if the base type for this pointer is 'id' or 'Class'
6597 const ObjCInterfaceType *getInterfaceType() const;
6598
6599 /// If this pointer points to an Objective \@interface
6600 /// type, gets the declaration for that interface.
6601 ///
6602 /// \return null if the base type for this pointer is 'id' or 'Class'
6604 return getObjectType()->getInterface();
6605 }
6606
6607 /// True if this is equivalent to the 'id' type, i.e. if
6608 /// its object type is the primitive 'id' type with no protocols.
6609 bool isObjCIdType() const {
6610 return getObjectType()->isObjCUnqualifiedId();
6611 }
6612
6613 /// True if this is equivalent to the 'Class' type,
6614 /// i.e. if its object tive is the primitive 'Class' type with no protocols.
6615 bool isObjCClassType() const {
6616 return getObjectType()->isObjCUnqualifiedClass();
6617 }
6618
6619 /// True if this is equivalent to the 'id' or 'Class' type,
6620 bool isObjCIdOrClassType() const {
6621 return getObjectType()->isObjCUnqualifiedIdOrClass();
6622 }
6623
6624 /// True if this is equivalent to 'id<P>' for some non-empty set of
6625 /// protocols.
6627 return getObjectType()->isObjCQualifiedId();
6628 }
6629
6630 /// True if this is equivalent to 'Class<P>' for some non-empty set of
6631 /// protocols.
6633 return getObjectType()->isObjCQualifiedClass();
6634 }
6635
6636 /// Whether this is a "__kindof" type.
6637 bool isKindOfType() const { return getObjectType()->isKindOfType(); }
6638
6639 /// Whether this type is specialized, meaning that it has type arguments.
6640 bool isSpecialized() const { return getObjectType()->isSpecialized(); }
6641
6642 /// Whether this type is specialized, meaning that it has type arguments.
6644 return getObjectType()->isSpecializedAsWritten();
6645 }
6646
6647 /// Whether this type is unspecialized, meaning that is has no type arguments.
6648 bool isUnspecialized() const { return getObjectType()->isUnspecialized(); }
6649
6650 /// Determine whether this object type is "unspecialized" as
6651 /// written, meaning that it has no type arguments.
6652 bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); }
6653
6654 /// Retrieve the type arguments for this type.
6656 return getObjectType()->getTypeArgs();
6657 }
6658
6659 /// Retrieve the type arguments for this type.
6661 return getObjectType()->getTypeArgsAsWritten();
6662 }
6663
6664 /// An iterator over the qualifiers on the object type. Provided
6665 /// for convenience. This will always iterate over the full set of
6666 /// protocols on a type, not just those provided directly.
6668 using qual_range = llvm::iterator_range<qual_iterator>;
6669
6670 qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
6671
6673 return getObjectType()->qual_begin();
6674 }
6675
6677 return getObjectType()->qual_end();
6678 }
6679
6680 bool qual_empty() const { return getObjectType()->qual_empty(); }
6681
6682 /// Return the number of qualifying protocols on the object type.
6683 unsigned getNumProtocols() const {
6684 return getObjectType()->getNumProtocols();
6685 }
6686
6687 /// Retrieve a qualifying protocol by index on the object type.
6688 ObjCProtocolDecl *getProtocol(unsigned I) const {
6689 return getObjectType()->getProtocol(I);
6690 }
6691
6692 bool isSugared() const { return false; }
6693 QualType desugar() const { return QualType(this, 0); }
6694
6695 /// Retrieve the type of the superclass of this object pointer type.
6696 ///
6697 /// This operation substitutes any type arguments into the
6698 /// superclass of the current class type, potentially producing a
6699 /// pointer to a specialization of the superclass type. Produces a
6700 /// null type if there is no superclass.
6701 QualType getSuperClassType() const;
6702
6703 /// Strip off the Objective-C "kindof" type and (with it) any
6704 /// protocol qualifiers.
6705 const ObjCObjectPointerType *stripObjCKindOfTypeAndQuals(
6706 const ASTContext &ctx) const;
6707
6708 void Profile(llvm::FoldingSetNodeID &ID) {
6709 Profile(ID, getPointeeType());
6710 }
6711
6712 static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
6713 ID.AddPointer(T.getAsOpaquePtr());
6714 }
6715
6716 static bool classof(const Type *T) {
6717 return T->getTypeClass() == ObjCObjectPointer;
6718 }
6719};
6720
6721class AtomicType : public Type, public llvm::FoldingSetNode {
6722 friend class ASTContext; // ASTContext creates these.
6723
6724 QualType ValueType;
6725
6726 AtomicType(QualType ValTy, QualType Canonical)
6727 : Type(Atomic, Canonical, ValTy->getDependence()), ValueType(ValTy) {}
6728
6729public:
6730 /// Gets the type contained by this atomic type, i.e.
6731 /// the type returned by performing an atomic load of this atomic type.
6732 QualType getValueType() const { return ValueType; }
6733
6734 bool isSugared() const { return false; }
6735 QualType desugar() const { return QualType(this, 0); }
6736
6737 void Profile(llvm::FoldingSetNodeID &ID) {
6738 Profile(ID, getValueType());
6739 }
6740
6741 static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
6742 ID.AddPointer(T.getAsOpaquePtr());
6743 }
6744
6745 static bool classof(const Type *T) {
6746 return T->getTypeClass() == Atomic;
6747 }
6748};
6749
6750/// PipeType - OpenCL20.
6751class PipeType : public Type, public llvm::FoldingSetNode {
6752 friend class ASTContext; // ASTContext creates these.
6753
6754 QualType ElementType;
6755 bool isRead;
6756
6757 PipeType(QualType elemType, QualType CanonicalPtr, bool isRead)
6758 : Type(Pipe, CanonicalPtr, elemType->getDependence()),
6759 ElementType(elemType), isRead(isRead) {}
6760
6761public:
6762 QualType getElementType() const { return ElementType; }
6763
6764 bool isSugared() const { return false; }
6765
6766 QualType desugar() const { return QualType(this, 0); }
6767
6768 void Profile(llvm::FoldingSetNodeID &ID) {
6769 Profile(ID, getElementType(), isReadOnly());
6770 }
6771
6772 static void Profile(llvm::FoldingSetNodeID &ID, QualType T, bool isRead) {
6773 ID.AddPointer(T.getAsOpaquePtr());
6774 ID.AddBoolean(isRead);
6775 }
6776
6777 static bool classof(const Type *T) {
6778 return T->getTypeClass() == Pipe;
6779 }
6780
6781 bool isReadOnly() const { return isRead; }
6782};
6783
6784/// A fixed int type of a specified bitwidth.
6785class BitIntType final : public Type, public llvm::FoldingSetNode {
6786 friend class ASTContext;
6787 LLVM_PREFERRED_TYPE(bool)
6788 unsigned IsUnsigned : 1;
6789 unsigned NumBits : 24;
6790
6791protected:
6792 BitIntType(bool isUnsigned, unsigned NumBits);
6793
6794public:
6795 bool isUnsigned() const { return IsUnsigned; }
6796 bool isSigned() const { return !IsUnsigned; }
6797 unsigned getNumBits() const { return NumBits; }
6798
6799 bool isSugared() const { return false; }
6800 QualType desugar() const { return QualType(this, 0); }
6801
6802 void Profile(llvm::FoldingSetNodeID &ID) const {
6803 Profile(ID, isUnsigned(), getNumBits());
6804 }
6805
6806 static void Profile(llvm::FoldingSetNodeID &ID, bool IsUnsigned,
6807 unsigned NumBits) {
6808 ID.AddBoolean(IsUnsigned);
6809 ID.AddInteger(NumBits);
6810 }
6811
6812 static bool classof(const Type *T) { return T->getTypeClass() == BitInt; }
6813};
6814
6815class DependentBitIntType final : public Type, public llvm::FoldingSetNode {
6816 friend class ASTContext;
6817 llvm::PointerIntPair<Expr*, 1, bool> ExprAndUnsigned;
6818
6819protected:
6820 DependentBitIntType(bool IsUnsigned, Expr *NumBits);
6821
6822public:
6823 bool isUnsigned() const;
6824 bool isSigned() const { return !isUnsigned(); }
6825 Expr *getNumBitsExpr() const;
6826
6827 bool isSugared() const { return false; }
6828 QualType desugar() const { return QualType(this, 0); }
6829
6830 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
6831 Profile(ID, Context, isUnsigned(), getNumBitsExpr());
6832 }
6833 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
6834 bool IsUnsigned, Expr *NumBitsExpr);
6835
6836 static bool classof(const Type *T) {
6837 return T->getTypeClass() == DependentBitInt;
6838 }
6839};
6840
6841/// A qualifier set is used to build a set of qualifiers.
6843public:
6845
6846 /// Collect any qualifiers on the given type and return an
6847 /// unqualified type. The qualifiers are assumed to be consistent
6848 /// with those already in the type.
6849 const Type *strip(QualType type) {
6850 addFastQualifiers(type.getLocalFastQualifiers());
6851 if (!type.hasLocalNonFastQualifiers())
6852 return type.getTypePtrUnsafe();
6853
6854 const ExtQuals *extQuals = type.getExtQualsUnsafe();
6855 addConsistentQualifiers(extQuals->getQualifiers());
6856 return extQuals->getBaseType();
6857 }
6858
6859 /// Apply the collected qualifiers to the given type.
6860 QualType apply(const ASTContext &Context, QualType QT) const;
6861
6862 /// Apply the collected qualifiers to the given type.
6863 QualType apply(const ASTContext &Context, const Type* T) const;
6864};
6865
6866/// A container of type source information.
6867///
6868/// A client can read the relevant info using TypeLoc wrappers, e.g:
6869/// @code
6870/// TypeLoc TL = TypeSourceInfo->getTypeLoc();
6871/// TL.getBeginLoc().print(OS, SrcMgr);
6872/// @endcode
6873class alignas(8) TypeSourceInfo {
6874 // Contains a memory block after the class, used for type source information,
6875 // allocated by ASTContext.
6876 friend class ASTContext;
6877
6878 QualType Ty;
6879
6880 TypeSourceInfo(QualType ty, size_t DataSize); // implemented in TypeLoc.h
6881
6882public:
6883 /// Return the type wrapped by this type source info.
6884 QualType getType() const { return Ty; }
6885
6886 /// Return the TypeLoc wrapper for the type source info.
6887 TypeLoc getTypeLoc() const; // implemented in TypeLoc.h
6888
6889 /// Override the type stored in this TypeSourceInfo. Use with caution!
6890 void overrideType(QualType T) { Ty = T; }
6891};
6892
6893// Inline function definitions.
6894
6895inline SplitQualType SplitQualType::getSingleStepDesugaredType() const {
6896 SplitQualType desugar =
6897 Ty->getLocallyUnqualifiedSingleStepDesugaredType().split();
6898 desugar.Quals.addConsistentQualifiers(Quals);
6899 return desugar;
6900}
6901
6902inline const Type *QualType::getTypePtr() const {
6903 return getCommonPtr()->BaseType;
6904}
6905
6906inline const Type *QualType::getTypePtrOrNull() const {
6907 return (isNull() ? nullptr : getCommonPtr()->BaseType);
6908}
6909
6910inline bool QualType::isReferenceable() const {
6911 // C++ [defns.referenceable]
6912 // type that is either an object type, a function type that does not have
6913 // cv-qualifiers or a ref-qualifier, or a reference type.
6914 const Type &Self = **this;
6915 if (Self.isObjectType() || Self.isReferenceType())
6916 return true;
6917 if (const auto *F = Self.getAs<FunctionProtoType>())
6918 return F->getMethodQuals().empty() && F->getRefQualifier() == RQ_None;
6919
6920 return false;
6921}
6922
6923inline SplitQualType QualType::split() const {
6924 if (!hasLocalNonFastQualifiers())
6925 return SplitQualType(getTypePtrUnsafe(),
6926 Qualifiers::fromFastMask(getLocalFastQualifiers()));
6927
6928 const ExtQuals *eq = getExtQualsUnsafe();
6929 Qualifiers qs = eq->getQualifiers();
6930 qs.addFastQualifiers(getLocalFastQualifiers());
6931 return SplitQualType(eq->getBaseType(), qs);
6932}
6933
6934inline Qualifiers QualType::getLocalQualifiers() const {
6935 Qualifiers Quals;
6936 if (hasLocalNonFastQualifiers())
6937 Quals = getExtQualsUnsafe()->getQualifiers();
6938 Quals.addFastQualifiers(getLocalFastQualifiers());
6939 return Quals;
6940}
6941
6942inline Qualifiers QualType::getQualifiers() const {
6943 Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers();
6944 quals.addFastQualifiers(getLocalFastQualifiers());
6945 return quals;
6946}
6947
6948inline unsigned QualType::getCVRQualifiers() const {
6949 unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers();
6950 cvr |= getLocalCVRQualifiers();
6951 return cvr;
6952}
6953
6954inline QualType QualType::getCanonicalType() const {
6955 QualType canon = getCommonPtr()->CanonicalType;
6956 return canon.withFastQualifiers(getLocalFastQualifiers());
6957}
6958
6959inline bool QualType::isCanonical() const {
6960 return getTypePtr()->isCanonicalUnqualified();
6961}
6962
6963inline bool QualType::isCanonicalAsParam() const {
6964 if (!isCanonical()) return false;
6965 if (hasLocalQualifiers()) return false;
6966
6967 const Type *T = getTypePtr();
6968 if (T->isVariablyModifiedType() && T->hasSizedVLAType())
6969 return false;
6970
6971 return !isa<FunctionType>(T) && !isa<ArrayType>(T);
6972}
6973
6974inline bool QualType::isConstQualified() const {
6975 return isLocalConstQualified() ||
6976 getCommonPtr()->CanonicalType.isLocalConstQualified();
6977}
6978
6979inline bool QualType::isRestrictQualified() const {
6980 return isLocalRestrictQualified() ||
6981 getCommonPtr()->CanonicalType.isLocalRestrictQualified();
6982}
6983
6984
6985inline bool QualType::isVolatileQualified() const {
6986 return isLocalVolatileQualified() ||
6987 getCommonPtr()->CanonicalType.isLocalVolatileQualified();
6988}
6989
6990inline bool QualType::hasQualifiers() const {
6991 return hasLocalQualifiers() ||
6992 getCommonPtr()->CanonicalType.hasLocalQualifiers();
6993}
6994
6995inline QualType QualType::getUnqualifiedType() const {
6996 if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
6997 return QualType(getTypePtr(), 0);
6998
6999 return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0);
7000}
7001
7002inline SplitQualType QualType::getSplitUnqualifiedType() const {
7003 if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
7004 return split();
7005
7006 return getSplitUnqualifiedTypeImpl(*this);
7007}
7008
7009inline void QualType::removeLocalConst() {
7010 removeLocalFastQualifiers(Qualifiers::Const);
7011}
7012
7013inline void QualType::removeLocalRestrict() {
7014 removeLocalFastQualifiers(Qualifiers::Restrict);
7015}
7016
7017inline void QualType::removeLocalVolatile() {
7018 removeLocalFastQualifiers(Qualifiers::Volatile);
7019}
7020
7021/// Check if this type has any address space qualifier.
7022inline bool QualType::hasAddressSpace() const {
7023 return getQualifiers().hasAddressSpace();
7024}
7025
7026/// Return the address space of this type.
7027inline LangAS QualType::getAddressSpace() const {
7028 return getQualifiers().getAddressSpace();
7029}
7030
7031/// Return the gc attribute of this type.
7032inline Qualifiers::GC QualType::getObjCGCAttr() const {
7033 return getQualifiers().getObjCGCAttr();
7034}
7035
7036inline bool QualType::hasNonTrivialToPrimitiveDefaultInitializeCUnion() const {
7037 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
7038 return hasNonTrivialToPrimitiveDefaultInitializeCUnion(RD);
7039 return false;
7040}
7041
7042inline bool QualType::hasNonTrivialToPrimitiveDestructCUnion() const {
7043 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
7044 return hasNonTrivialToPrimitiveDestructCUnion(RD);
7045 return false;
7046}
7047
7048inline bool QualType::hasNonTrivialToPrimitiveCopyCUnion() const {
7049 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
7050 return hasNonTrivialToPrimitiveCopyCUnion(RD);
7051 return false;
7052}
7053
7055 if (const auto *PT = t.getAs<PointerType>()) {
7056 if (const auto *FT = PT->getPointeeType()->getAs<FunctionType>())
7057 return FT->getExtInfo();
7058 } else if (const auto *FT = t.getAs<FunctionType>())
7059 return FT->getExtInfo();
7060
7061 return FunctionType::ExtInfo();
7062}
7063
7065 return getFunctionExtInfo(*t);
7066}
7067
7068/// Determine whether this type is more
7069/// qualified than the Other type. For example, "const volatile int"
7070/// is more qualified than "const int", "volatile int", and
7071/// "int". However, it is not more qualified than "const volatile
7072/// int".
7073inline bool QualType::isMoreQualifiedThan(QualType other) const {
7074 Qualifiers MyQuals = getQualifiers();
7075 Qualifiers OtherQuals = other.getQualifiers();
7076 return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes(OtherQuals));
7077}
7078
7079/// Determine whether this type is at last
7080/// as qualified as the Other type. For example, "const volatile
7081/// int" is at least as qualified as "const int", "volatile int",
7082/// "int", and "const volatile int".
7083inline bool QualType::isAtLeastAsQualifiedAs(QualType other) const {
7084 Qualifiers OtherQuals = other.getQualifiers();
7085
7086 // Ignore __unaligned qualifier if this type is a void.
7087 if (getUnqualifiedType()->isVoidType())
7088 OtherQuals.removeUnaligned();
7089
7090 return getQualifiers().compatiblyIncludes(OtherQuals);
7091}
7092
7093/// If Type is a reference type (e.g., const
7094/// int&), returns the type that the reference refers to ("const
7095/// int"). Otherwise, returns the type itself. This routine is used
7096/// throughout Sema to implement C++ 5p6:
7097///
7098/// If an expression initially has the type "reference to T" (8.3.2,
7099/// 8.5.3), the type is adjusted to "T" prior to any further
7100/// analysis, the expression designates the object or function
7101/// denoted by the reference, and the expression is an lvalue.
7102inline QualType QualType::getNonReferenceType() const {
7103 if (const auto *RefType = (*this)->getAs<ReferenceType>())
7104 return RefType->getPointeeType();
7105 else
7106 return *this;
7107}
7108
7109inline bool QualType::isCForbiddenLValueType() const {
7110 return ((getTypePtr()->isVoidType() && !hasQualifiers()) ||
7111 getTypePtr()->isFunctionType());
7112}
7113
7114/// Tests whether the type is categorized as a fundamental type.
7115///
7116/// \returns True for types specified in C++0x [basic.fundamental].
7117inline bool Type::isFundamentalType() const {
7118 return isVoidType() ||
7119 isNullPtrType() ||
7120 // FIXME: It's really annoying that we don't have an
7121 // 'isArithmeticType()' which agrees with the standard definition.
7122 (isArithmeticType() && !isEnumeralType());
7123}
7124
7125/// Tests whether the type is categorized as a compound type.
7126///
7127/// \returns True for types specified in C++0x [basic.compound].
7128inline bool Type::isCompoundType() const {
7129 // C++0x [basic.compound]p1:
7130 // Compound types can be constructed in the following ways:
7131 // -- arrays of objects of a given type [...];
7132 return isArrayType() ||
7133 // -- functions, which have parameters of given types [...];
7134 isFunctionType() ||
7135 // -- pointers to void or objects or functions [...];
7136 isPointerType() ||
7137 // -- references to objects or functions of a given type. [...]
7138 isReferenceType() ||
7139 // -- classes containing a sequence of objects of various types, [...];
7140 isRecordType() ||
7141 // -- unions, which are classes capable of containing objects of different
7142 // types at different times;
7143 isUnionType() ||
7144 // -- enumerations, which comprise a set of named constant values. [...];
7145 isEnumeralType() ||
7146 // -- pointers to non-static class members, [...].
7147 isMemberPointerType();
7148}
7149
7150inline bool Type::isFunctionType() const {
7151 return isa<FunctionType>(CanonicalType);
7152}
7153
7154inline bool Type::isPointerType() const {
7155 return isa<PointerType>(CanonicalType);
7156}
7157
7158inline bool Type::isAnyPointerType() const {
7159 return isPointerType() || isObjCObjectPointerType();
7160}
7161
7162inline bool Type::isBlockPointerType() const {
7163 return isa<BlockPointerType>(CanonicalType);
7164}
7165
7166inline bool Type::isReferenceType() const {
7167 return isa<ReferenceType>(CanonicalType);
7168}
7169
7170inline bool Type::isLValueReferenceType() const {
7171 return isa<LValueReferenceType>(CanonicalType);
7172}
7173
7174inline bool Type::isRValueReferenceType() const {
7175 return isa<RValueReferenceType>(CanonicalType);
7176}
7177
7178inline bool Type::isObjectPointerType() const {
7179 // Note: an "object pointer type" is not the same thing as a pointer to an
7180 // object type; rather, it is a pointer to an object type or a pointer to cv
7181 // void.
7182 if (const auto *T = getAs<PointerType>())
7183 return !T->getPointeeType()->isFunctionType();
7184 else
7185 return false;
7186}
7187
7188inline bool Type::isFunctionPointerType() const {
7189 if (const auto *T = getAs<PointerType>())
7190 return T->getPointeeType()->isFunctionType();
7191 else
7192 return false;
7193}
7194
7195inline bool Type::isFunctionReferenceType() const {
7196 if (const auto *T = getAs<ReferenceType>())
7197 return T->getPointeeType()->isFunctionType();
7198 else
7199 return false;
7200}
7201
7202inline bool Type::isMemberPointerType() const {
7203 return isa<MemberPointerType>(CanonicalType);
7204}
7205
7206inline bool Type::isMemberFunctionPointerType() const {
7207 if (const auto *T = getAs<MemberPointerType>())
7208 return T->isMemberFunctionPointer();
7209 else
7210 return false;
7211}
7212
7213inline bool Type::isMemberDataPointerType() const {
7214 if (const auto *T = getAs<MemberPointerType>())
7215 return T->isMemberDataPointer();
7216 else
7217 return false;
7218}
7219
7220inline bool Type::isArrayType() const {
7221 return isa<ArrayType>(CanonicalType);
7222}
7223
7224inline bool Type::isConstantArrayType() const {
7225 return isa<ConstantArrayType>(CanonicalType);
7226}
7227
7228inline bool Type::isIncompleteArrayType() const {
7229 return isa<IncompleteArrayType>(CanonicalType);
7230}
7231
7232inline bool Type::isVariableArrayType() const {
7233 return isa<VariableArrayType>(CanonicalType);
7234}
7235
7236inline bool Type::isDependentSizedArrayType() const {
7237 return isa<DependentSizedArrayType>(CanonicalType);
7238}
7239
7240inline bool Type::isBuiltinType() const {
7241 return isa<BuiltinType>(CanonicalType);
7242}
7243
7244inline bool Type::isRecordType() const {
7245 return isa<RecordType>(CanonicalType);
7246}
7247
7248inline bool Type::isEnumeralType() const {
7249 return isa<EnumType>(CanonicalType);
7250}
7251
7252inline bool Type::isAnyComplexType() const {
7253 return isa<ComplexType>(CanonicalType);
7254}
7255
7256inline bool Type::isVectorType() const {
7257 return isa<VectorType>(CanonicalType);
7258}
7259
7260inline bool Type::isExtVectorType() const {
7261 return isa<ExtVectorType>(CanonicalType);
7262}
7263
7264inline bool Type::isExtVectorBoolType() const {
7265 if (!isExtVectorType())
7266 return false;
7267 return cast<ExtVectorType>(CanonicalType)->getElementType()->isBooleanType();
7268}
7269
7270inline bool Type::isMatrixType() const {
7271 return isa<MatrixType>(CanonicalType);
7272}
7273
7274inline bool Type::isConstantMatrixType() const {
7275 return isa<ConstantMatrixType>(CanonicalType);
7276}
7277
7278inline bool Type::isDependentAddressSpaceType() const {
7279 return isa<DependentAddressSpaceType>(CanonicalType);
7280}
7281
7282inline bool Type::isObjCObjectPointerType() const {
7283 return isa<ObjCObjectPointerType>(CanonicalType);
7284}
7285
7286inline bool Type::isObjCObjectType() const {
7287 return isa<ObjCObjectType>(CanonicalType);
7288}
7289
7290inline bool Type::isObjCObjectOrInterfaceType() const {
7291 return isa<ObjCInterfaceType>(CanonicalType) ||
7292 isa<ObjCObjectType>(CanonicalType);
7293}
7294
7295inline bool Type::isAtomicType() const {
7296 return isa<AtomicType>(CanonicalType);
7297}
7298
7299inline bool Type::isUndeducedAutoType() const {
7300 return isa<AutoType>(CanonicalType);
7301}
7302
7303inline bool Type::isObjCQualifiedIdType() const {
7304 if (const auto *OPT = getAs<ObjCObjectPointerType>())
7305 return OPT->isObjCQualifiedIdType();
7306 return false;
7307}
7308
7309inline bool Type::isObjCQualifiedClassType() const {
7310 if (const auto *OPT = getAs<ObjCObjectPointerType>())
7311 return OPT->isObjCQualifiedClassType();
7312 return false;
7313}
7314
7315inline bool Type::isObjCIdType() const {
7316 if (const auto *OPT = getAs<ObjCObjectPointerType>())
7317 return OPT->isObjCIdType();
7318 return false;
7319}
7320
7321inline bool Type::isObjCClassType() const {
7322 if (const auto *OPT = getAs<ObjCObjectPointerType>())
7323 return OPT->isObjCClassType();
7324 return false;
7325}
7326
7327inline bool Type::isObjCSelType() const {
7328 if (const auto *OPT = getAs<PointerType>())
7329 return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
7330 return false;
7331}
7332
7333inline bool Type::isObjCBuiltinType() const {
7334 return isObjCIdType() || isObjCClassType() || isObjCSelType();
7335}
7336
7337inline bool Type::isDecltypeType() const {
7338 return isa<DecltypeType>(this);
7339}
7340
7341#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
7342 inline bool Type::is##Id##Type() const { \
7343 return isSpecificBuiltinType(BuiltinType::Id); \
7344 }
7345#include "clang/Basic/OpenCLImageTypes.def"
7346
7347inline bool Type::isSamplerT() const {
7348 return isSpecificBuiltinType(BuiltinType::OCLSampler);
7349}
7350
7351inline bool Type::isEventT() const {
7352 return isSpecificBuiltinType(BuiltinType::OCLEvent);
7353}
7354
7355inline bool Type::isClkEventT() const {
7356 return isSpecificBuiltinType(BuiltinType::OCLClkEvent);
7357}
7358
7359inline bool Type::isQueueT() const {
7360 return isSpecificBuiltinType(BuiltinType::OCLQueue);
7361}
7362
7363inline bool Type::isReserveIDT() const {
7364 return isSpecificBuiltinType(BuiltinType::OCLReserveID);
7365}
7366
7367inline bool Type::isImageType() const {
7368#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) is##Id##Type() ||
7369 return
7370#include "clang/Basic/OpenCLImageTypes.def"
7371 false; // end boolean or operation
7372}
7373
7374inline bool Type::isPipeType() const {
7375 return isa<PipeType>(CanonicalType);
7376}
7377
7378inline bool Type::isBitIntType() const {
7379 return isa<BitIntType>(CanonicalType);
7380}
7381
7382#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
7383 inline bool Type::is##Id##Type() const { \
7384 return isSpecificBuiltinType(BuiltinType::Id); \
7385 }
7386#include "clang/Basic/OpenCLExtensionTypes.def"
7387
7388inline bool Type::isOCLIntelSubgroupAVCType() const {
7389#define INTEL_SUBGROUP_AVC_TYPE(ExtType, Id) \
7390 isOCLIntelSubgroupAVC##Id##Type() ||
7391 return
7392#include "clang/Basic/OpenCLExtensionTypes.def"
7393 false; // end of boolean or operation
7394}
7395
7396inline bool Type::isOCLExtOpaqueType() const {
7397#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) is##Id##Type() ||
7398 return
7399#include "clang/Basic/OpenCLExtensionTypes.def"
7400 false; // end of boolean or operation
7401}
7402
7403inline bool Type::isOpenCLSpecificType() const {
7404 return isSamplerT() || isEventT() || isImageType() || isClkEventT() ||
7405 isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
7406}
7407
7408inline bool Type::isTemplateTypeParmType() const {
7409 return isa<TemplateTypeParmType>(CanonicalType);
7410}
7411
7412inline bool Type::isSpecificBuiltinType(unsigned K) const {
7413 if (const BuiltinType *BT = getAs<BuiltinType>()) {
7414 return BT->getKind() == static_cast<BuiltinType::Kind>(K);
7415 }
7416 return false;
7417}
7418
7419inline bool Type::isPlaceholderType() const {
7420 if (const auto *BT = dyn_cast<BuiltinType>(this))
7421 return BT->isPlaceholderType();
7422 return false;
7423}
7424
7425inline const BuiltinType *Type::getAsPlaceholderType() const {
7426 if (const auto *BT = dyn_cast<BuiltinType>(this))
7427 if (BT->isPlaceholderType())
7428 return BT;
7429 return nullptr;
7430}
7431
7432inline bool Type::isSpecificPlaceholderType(unsigned K) const {
7433 assert(BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K));
7434 return isSpecificBuiltinType(K);
7435}
7436
7437inline bool Type::isNonOverloadPlaceholderType() const {
7438 if (const auto *BT = dyn_cast<BuiltinType>(this))
7439 return BT->isNonOverloadPlaceholderType();
7440 return false;
7441}
7442
7443inline bool Type::isVoidType() const {
7444 return isSpecificBuiltinType(BuiltinType::Void);
7445}
7446
7447inline bool Type::isHalfType() const {
7448 // FIXME: Should we allow complex __fp16? Probably not.
7449 return isSpecificBuiltinType(BuiltinType::Half);
7450}
7451
7452inline bool Type::isFloat16Type() const {
7453 return isSpecificBuiltinType(BuiltinType::Float16);
7454}
7455
7456inline bool Type::isFloat32Type() const {
7457 return isSpecificBuiltinType(BuiltinType::Float);
7458}
7459
7460inline bool Type::isBFloat16Type() const {
7461 return isSpecificBuiltinType(BuiltinType::BFloat16);
7462}
7463
7464inline bool Type::isFloat128Type() const {
7465 return isSpecificBuiltinType(BuiltinType::Float128);
7466}
7467
7468inline bool Type::isIbm128Type() const {
7469 return isSpecificBuiltinType(BuiltinType::Ibm128);
7470}
7471
7472inline bool Type::isNullPtrType() const {
7473 return isSpecificBuiltinType(BuiltinType::NullPtr);
7474}
7475
7478
7479inline bool Type::isIntegerType() const {
7480 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
7481 return BT->getKind() >= BuiltinType::Bool &&
7482 BT->getKind() <= BuiltinType::Int128;
7483 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
7484 // Incomplete enum types are not treated as integer types.
7485 // FIXME: In C++, enum types are never integer types.
7486 return IsEnumDeclComplete(ET->getDecl()) &&
7487 !IsEnumDeclScoped(ET->getDecl());
7488 }
7489 return isBitIntType();
7490}
7491
7492inline bool Type::isFixedPointType() const {
7493 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
7494 return BT->getKind() >= BuiltinType::ShortAccum &&
7495 BT->getKind() <= BuiltinType::SatULongFract;
7496 }
7497 return false;
7498}
7499
7500inline bool Type::isFixedPointOrIntegerType() const {
7501 return isFixedPointType() || isIntegerType();
7502}
7503
7504inline bool Type::isConvertibleToFixedPointType() const {
7505 return isRealFloatingType() || isFixedPointOrIntegerType();
7506}
7507
7508inline bool Type::isSaturatedFixedPointType() const {
7509 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
7510 return BT->getKind() >= BuiltinType::SatShortAccum &&
7511 BT->getKind() <= BuiltinType::SatULongFract;
7512 }
7513 return false;
7514}
7515
7516inline bool Type::isUnsaturatedFixedPointType() const {
7517 return isFixedPointType() && !isSaturatedFixedPointType();
7518}
7519
7520inline bool Type::isSignedFixedPointType() const {
7521 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
7522 return ((BT->getKind() >= BuiltinType::ShortAccum &&
7523 BT->getKind() <= BuiltinType::LongAccum) ||
7524 (BT->getKind() >= BuiltinType::ShortFract &&
7525 BT->getKind() <= BuiltinType::LongFract) ||
7526 (BT->getKind() >= BuiltinType::SatShortAccum &&
7527 BT->getKind() <= BuiltinType::SatLongAccum) ||
7528 (BT->getKind() >= BuiltinType::SatShortFract &&
7529 BT->getKind() <= BuiltinType::SatLongFract));
7530 }
7531 return false;
7532}
7533
7534inline bool Type::isUnsignedFixedPointType() const {
7535 return isFixedPointType() && !isSignedFixedPointType();
7536}
7537
7538inline bool Type::isScalarType() const {
7539 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
7540 return BT->getKind() > BuiltinType::Void &&
7541 BT->getKind() <= BuiltinType::NullPtr;
7542 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
7543 // Enums are scalar types, but only if they are defined. Incomplete enums
7544 // are not treated as scalar types.
7545 return IsEnumDeclComplete(ET->getDecl());
7546 return isa<PointerType>(CanonicalType) ||
7547 isa<BlockPointerType>(CanonicalType) ||
7548 isa<MemberPointerType>(CanonicalType) ||
7549 isa<ComplexType>(CanonicalType) ||
7550 isa<ObjCObjectPointerType>(CanonicalType) ||
7551 isBitIntType();
7552}
7553
7554inline bool Type::isIntegralOrEnumerationType() const {
7555 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
7556 return BT->getKind() >= BuiltinType::Bool &&
7557 BT->getKind() <= BuiltinType::Int128;
7558
7559 // Check for a complete enum type; incomplete enum types are not properly an
7560 // enumeration type in the sense required here.
7561 if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
7562 return IsEnumDeclComplete(ET->getDecl());
7563
7564 return isBitIntType();
7565}
7566
7567inline bool Type::isBooleanType() const {
7568 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
7569 return BT->getKind() == BuiltinType::Bool;
7570 return false;
7571}
7572
7573inline bool Type::isUndeducedType() const {
7574 auto *DT = getContainedDeducedType();
7575 return DT && !DT->isDeduced();
7576}
7577
7578/// Determines whether this is a type for which one can define
7579/// an overloaded operator.
7580inline bool Type::isOverloadableType() const {
7581 return isDependentType() || isRecordType() || isEnumeralType();
7582}
7583
7584/// Determines whether this type is written as a typedef-name.
7585inline bool Type::isTypedefNameType() const {
7586 if (getAs<TypedefType>())
7587 return true;
7588 if (auto *TST = getAs<TemplateSpecializationType>())
7589 return TST->isTypeAlias();
7590 return false;
7591}
7592
7593/// Determines whether this type can decay to a pointer type.
7594inline bool Type::canDecayToPointerType() const {
7595 return isFunctionType() || isArrayType();
7596}
7597
7598inline bool Type::hasPointerRepresentation() const {
7599 return (isPointerType() || isReferenceType() || isBlockPointerType() ||
7600 isObjCObjectPointerType() || isNullPtrType());
7601}
7602
7603inline bool Type::hasObjCPointerRepresentation() const {
7604 return isObjCObjectPointerType();
7605}
7606
7607inline const Type *Type::getBaseElementTypeUnsafe() const {
7608 const Type *type = this;
7609 while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe())
7610 type = arrayType->getElementType().getTypePtr();
7611 return type;
7612}
7613
7614inline const Type *Type::getPointeeOrArrayElementType() const {
7615 const Type *type = this;
7616 if (type->isAnyPointerType())
7617 return type->getPointeeType().getTypePtr();
7618 else if (type->isArrayType())
7619 return type->getBaseElementTypeUnsafe();
7620 return type;
7621}
7622/// Insertion operator for partial diagnostics. This allows sending adress
7623/// spaces into a diagnostic with <<.
7624inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
7625 LangAS AS) {
7626 PD.AddTaggedVal(llvm::to_underlying(AS),
7627 DiagnosticsEngine::ArgumentKind::ak_addrspace);
7628 return PD;
7629}
7630
7631/// Insertion operator for partial diagnostics. This allows sending Qualifiers
7632/// into a diagnostic with <<.
7633inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
7634 Qualifiers Q) {
7636 DiagnosticsEngine::ArgumentKind::ak_qual);
7637 return PD;
7638}
7639
7640/// Insertion operator for partial diagnostics. This allows sending QualType's
7641/// into a diagnostic with <<.
7642inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
7643 QualType T) {
7644 PD.AddTaggedVal(reinterpret_cast<uint64_t>(T.getAsOpaquePtr()),
7645 DiagnosticsEngine::ak_qualtype);
7646 return PD;
7647}
7648
7649// Helper class template that is used by Type::getAs to ensure that one does
7650// not try to look through a qualified type to get to an array type.
7651template <typename T>
7653 std::integral_constant<bool, std::is_same<T, ArrayType>::value ||
7654 std::is_base_of<ArrayType, T>::value>;
7655
7656// Member-template getAs<specific type>'.
7657template <typename T> const T *Type::getAs() const {
7658 static_assert(!TypeIsArrayType<T>::value,
7659 "ArrayType cannot be used with getAs!");
7660
7661 // If this is directly a T type, return it.
7662 if (const auto *Ty = dyn_cast<T>(this))
7663 return Ty;
7664
7665 // If the canonical form of this type isn't the right kind, reject it.
7666 if (!isa<T>(CanonicalType))
7667 return nullptr;
7668
7669 // If this is a typedef for the type, strip the typedef off without
7670 // losing all typedef information.
7671 return cast<T>(getUnqualifiedDesugaredType());
7672}
7673
7674template <typename T> const T *Type::getAsAdjusted() const {
7675 static_assert(!TypeIsArrayType<T>::value, "ArrayType cannot be used with getAsAdjusted!");
7676
7677 // If this is directly a T type, return it.
7678 if (const auto *Ty = dyn_cast<T>(this))
7679 return Ty;
7680
7681 // If the canonical form of this type isn't the right kind, reject it.
7682 if (!isa<T>(CanonicalType))
7683 return nullptr;
7684
7685 // Strip off type adjustments that do not modify the underlying nature of the
7686 // type.
7687 const Type *Ty = this;
7688 while (Ty) {
7689 if (const auto *A = dyn_cast<AttributedType>(Ty))
7690 Ty = A->getModifiedType().getTypePtr();
7691 else if (const auto *A = dyn_cast<BTFTagAttributedType>(Ty))
7692 Ty = A->getWrappedType().getTypePtr();
7693 else if (const auto *E = dyn_cast<ElaboratedType>(Ty))
7694 Ty = E->desugar().getTypePtr();
7695 else if (const auto *P = dyn_cast<ParenType>(Ty))
7696 Ty = P->desugar().getTypePtr();
7697 else if (const auto *A = dyn_cast<AdjustedType>(Ty))
7698 Ty = A->desugar().getTypePtr();
7699 else if (const auto *M = dyn_cast<MacroQualifiedType>(Ty))
7700 Ty = M->desugar().getTypePtr();
7701 else
7702 break;
7703 }
7704
7705 // Just because the canonical type is correct does not mean we can use cast<>,
7706 // since we may not have stripped off all the sugar down to the base type.
7707 return dyn_cast<T>(Ty);
7708}
7709
7710inline const ArrayType *Type::getAsArrayTypeUnsafe() const {
7711 // If this is directly an array type, return it.
7712 if (const auto *arr = dyn_cast<ArrayType>(this))
7713 return arr;
7714
7715 // If the canonical form of this type isn't the right kind, reject it.
7716 if (!isa<ArrayType>(CanonicalType))
7717 return nullptr;
7718
7719 // If this is a typedef for the type, strip the typedef off without
7720 // losing all typedef information.
7721 return cast<ArrayType>(getUnqualifiedDesugaredType());
7722}
7723
7724template <typename T> const T *Type::castAs() const {
7725 static_assert(!TypeIsArrayType<T>::value,
7726 "ArrayType cannot be used with castAs!");
7727
7728 if (const auto *ty = dyn_cast<T>(this)) return ty;
7729 assert(isa<T>(CanonicalType));
7730 return cast<T>(getUnqualifiedDesugaredType());
7731}
7732
7733inline const ArrayType *Type::castAsArrayTypeUnsafe() const {
7734 assert(isa<ArrayType>(CanonicalType));
7735 if (const auto *arr = dyn_cast<ArrayType>(this)) return arr;
7736 return cast<ArrayType>(getUnqualifiedDesugaredType());
7737}
7738
7739DecayedType::DecayedType(QualType OriginalType, QualType DecayedPtr,
7740 QualType CanonicalPtr)
7741 : AdjustedType(Decayed, OriginalType, DecayedPtr, CanonicalPtr) {
7742#ifndef NDEBUG
7743 QualType Adjusted = getAdjustedType();
7745 assert(isa<PointerType>(Adjusted));
7746#endif
7747}
7748
7750 QualType Decayed = getDecayedType();
7752 return cast<PointerType>(Decayed)->getPointeeType();
7753}
7754
7755// Get the decimal string representation of a fixed point type, represented
7756// as a scaled integer.
7757// TODO: At some point, we should change the arguments to instead just accept an
7758// APFixedPoint instead of APSInt and scale.
7759void FixedPointValueToString(SmallVectorImpl<char> &Str, llvm::APSInt Val,
7760 unsigned Scale);
7761
7762} // namespace clang
7763
7764#endif // LLVM_CLANG_AST_TYPE_H
#define V(N, I)
Definition: ASTContext.h:3259
MatchType Type
StringRef P
Provides definitions for the various language-specific address spaces.
static char ID
Definition: Arena.cpp:183
static bool isUnsigned(SValBuilder &SVB, NonLoc Value)
Defines the clang::attr::Kind enum.
Defines the Diagnostic-related interfaces.
static bool isBooleanType(QualType Ty)
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1110
Defines the ExceptionSpecificationType enumeration and various utility functions.
static bool isRead(AccessKinds AK)
static QualType getObjectType(APValue::LValueBase B)
Retrieves the "underlying object type" of the given expression, as used by __builtin_object_size.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
llvm::MachO::Record Record
Definition: MachO.h:28
static StringRef getIdentifier(const Token &Tok)
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
static QualType getUnderlyingType(const SubRegion *R)
static std::string getName(const CallEvent &Call)
static bool hasAttr(const Decl *D, bool IgnoreImplicitAttr)
Definition: SemaCUDA.cpp:108
static RecordDecl * getAsRecordDecl(QualType BaseType)
static bool isRecordType(QualType T)
static bool isParameterPack(Expr *PackExpression)
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
const char * Data
static const TemplateTypeParmDecl * getReplacedParameter(Decl *D, unsigned Index)
Definition: Type.cpp:4010
Defines the clang::Visibility enumeration and various utility functions.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
__device__ __2f16 b
__device__ __2f16 float __ockl_bool s
__device__ __2f16 float c
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:366
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:86
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:2927
static bool classof(const Type *T)
Definition: Type.h:2955
static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New)
Definition: Type.h:2950
AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy, QualType CanonicalPtr)
Definition: Type.h:2934
QualType desugar() const
Definition: Type.h:2944
QualType getAdjustedType() const
Definition: Type.h:2941
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2946
bool isSugared() const
Definition: Type.h:2943
QualType getOriginalType() const
Definition: Type.h:2940
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3147
ArraySizeModifier getSizeModifier() const
Definition: Type.h:3161
Qualifiers getIndexTypeQualifiers() const
Definition: Type.h:3165
static bool classof(const Type *T)
Definition: Type.h:3173
QualType getElementType() const
Definition: Type.h:3159
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:3169
static void Profile(llvm::FoldingSetNodeID &ID, QualType T)
Definition: Type.h:6741
bool isSugared() const
Definition: Type.h:6734
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition: Type.h:6732
QualType desugar() const
Definition: Type.h:6735
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6737
static bool classof(const Type *T)
Definition: Type.h:6745
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:5147
QualType getModifiedType() const
Definition: Type.h:5169
static bool classof(const Type *T)
Definition: Type.h:5241
static Kind getNullabilityAttrKind(NullabilityKind kind)
Retrieve the attribute kind corresponding to the given nullability kind.
Definition: Type.h:5202
bool isSugared() const
Definition: Type.h:5172
static std::optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
Definition: Type.cpp:4673
static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind, QualType modified, QualType equivalent)
Definition: Type.h:5234
QualType desugar() const
Definition: Type.h:5173
QualType getEquivalentType() const
Definition: Type.h:5170
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5230
Kind getAttrKind() const
Definition: Type.h:5165
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:5524
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: Type.h:5534
static bool classof(const Type *T)
Definition: Type.h:5565
bool isDecltypeAuto() const
Definition: Type.h:5547
ConceptDecl * getTypeConstraintConcept() const
Definition: Type.h:5539
AutoTypeKeyword getKeyword() const
Definition: Type.h:5555
bool isGNUAutoType() const
Definition: Type.h:5551
bool isConstrained() const
Definition: Type.h:5543
static bool classof(const Type *T)
Definition: Type.h:5275
const BTFTypeTagAttr * getAttr() const
Definition: Type.h:5260
QualType getWrappedType() const
Definition: Type.h:5259
QualType desugar() const
Definition: Type.h:5263
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5265
static void Profile(llvm::FoldingSetNodeID &ID, QualType Wrapped, const BTFTypeTagAttr *BTFAttr)
Definition: Type.h:5269
bool isSugared() const
Definition: Type.h:5262
A fixed int type of a specified bitwidth.
Definition: Type.h:6785
bool isSigned() const
Definition: Type.h:6796
static bool classof(const Type *T)
Definition: Type.h:6812
static void Profile(llvm::FoldingSetNodeID &ID, bool IsUnsigned, unsigned NumBits)
Definition: Type.h:6806
bool isSugared() const
Definition: Type.h:6799
bool isUnsigned() const
Definition: Type.h:6795
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:6802
unsigned getNumBits() const
Definition: Type.h:6797
QualType desugar() const
Definition: Type.h:6800
Pointer to a block type.
Definition: Type.h:2978
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2995
QualType getPointeeType() const
Definition: Type.h:2990
static bool classof(const Type *T)
Definition: Type.h:3003
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee)
Definition: Type.h:2999
QualType desugar() const
Definition: Type.h:2993
bool isSugared() const
Definition: Type.h:2992
This class is used for builtin types like 'int'.
Definition: Type.h:2740
bool isPlaceholderType() const
Determines whether this type is a placeholder type, i.e.
Definition: Type.h:2823
bool isSugared() const
Definition: Type.h:2792
bool isNonOverloadPlaceholderType() const
Determines whether this type is a placeholder type other than Overload.
Definition: Type.h:2836
bool isSVECount() const
Definition: Type.h:2813
bool isSVEBool() const
Definition: Type.h:2811
QualType desugar() const
Definition: Type.h:2793
bool isInteger() const
Definition: Type.h:2795
bool isFloatingPoint() const
Definition: Type.h:2807
static bool classof(const Type *T)
Definition: Type.h:2840
bool isSignedInteger() const
Definition: Type.h:2799
bool isUnsignedInteger() const
Definition: Type.h:2803
Kind getKind() const
Definition: Type.h:2782
static bool isPlaceholderTypeKind(Kind K)
Determines whether the given kind corresponds to a placeholder type.
Definition: Type.h:2816
const char * getNameAsCString(const PrintingPolicy &Policy) const
Definition: Type.h:2785
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Complex values, per C99 6.2.5p11.
Definition: Type.h:2845
bool isSugared() const
Definition: Type.h:2857
QualType getElementType() const
Definition: Type.h:2855
static void Profile(llvm::FoldingSetNodeID &ID, QualType Element)
Definition: Type.h:2864
static bool classof(const Type *T)
Definition: Type.h:2868
QualType desugar() const
Definition: Type.h:2858
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2860
Declaration of a C++20 concept.
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3186
const llvm::APInt & getSize() const
Definition: Type.h:3207
QualType desugar() const
Definition: Type.h:3214
const Expr * getSizeExpr() const
Definition: Type.h:3208
bool isSugared() const
Definition: Type.h:3213
static bool classof(const Type *T)
Definition: Type.h:3238
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition: Type.h:3228
Represents a concrete matrix type with constant number of rows and columns.
Definition: Type.h:3710
unsigned getNumColumns() const
Returns the number of columns in the matrix.
Definition: Type.h:3731
static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, unsigned NumRows, unsigned NumColumns, TypeClass TypeClass)
Definition: Type.h:3753
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3748
static constexpr unsigned getMaxElementsPerDimension()
Returns the maximum number of elements per dimension.
Definition: Type.h:3744
unsigned getNumRows() const
Returns the number of rows in the matrix.
Definition: Type.h:3728
unsigned getNumElementsFlattened() const
Returns the number of elements required to embed the matrix into a vector.
Definition: Type.h:3734
static constexpr bool isDimensionValid(size_t NumElements)
Returns true if NumElements is a valid matrix dimension.
Definition: Type.h:3739
unsigned NumRows
Number of rows and columns.
Definition: Type.h:3715
static bool classof(const Type *T)
Definition: Type.h:3762
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2961
QualType getPointeeType() const
Definition: Type.h:7749
static bool classof(const Type *T)
Definition: Type.h:2972
QualType getDecayedType() const
Definition: Type.h:2968
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1446
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
Represents the type decltype(expr) (C++11).
Definition: Type.h:4901
static bool classof(const Type *T)
Definition: Type.h:4920
Expr * getUnderlyingExpr() const
Definition: Type.h:4911
QualType getUnderlyingType() const
Definition: Type.h:4912
Represents a C++17 deduced template specialization type.
Definition: Type.h:5572
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
Definition: Type.h:5592
static bool classof(const Type *T)
Definition: Type.h:5607
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5594
static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template, QualType Deduced, bool IsDependent)
Definition: Type.h:5598
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Definition: Type.h:5490
static bool classof(const Type *T)
Definition: Type.h:5516
bool isSugared() const
Definition: Type.h:5504
QualType desugar() const
Definition: Type.h:5505
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
Definition: Type.h:5511
DeducedType(TypeClass TC, QualType DeducedAsType, TypeDependence ExtraDependence, QualType Canon)
Definition: Type.h:5494
bool isDeduced() const
Definition: Type.h:5512
Represents an extended address space qualifier where the input address space value is dependent.
Definition: Type.h:3402
QualType desugar() const
Definition: Type.h:3418
Expr * getAddrSpaceExpr() const
Definition: Type.h:3413
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3424
QualType getPointeeType() const
Definition: Type.h:3414
static bool classof(const Type *T)
Definition: Type.h:3420
SourceLocation getAttributeLoc() const
Definition: Type.h:3415
QualType desugar() const
Definition: Type.h:6828
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:6830
bool isSigned() const
Definition: Type.h:6824
bool isSugared() const
Definition: Type.h:6827
static bool classof(const Type *T)
Definition: Type.h:6836
Internal representation of canonical, dependent decltype(expr) types.
Definition: Type.h:4929
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:4933
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:5995
bool isSugared() const
Definition: Type.h:6024
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:6013
static bool classof(const Type *T)
Definition: Type.h:6038
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
Definition: Type.h:6020
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6027
static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name)
Definition: Type.h:6031
QualType desugar() const
Definition: Type.h:6025
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3344
QualType desugar() const
Definition: Type.h:3375
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3381
static bool classof(const Type *T)
Definition: Type.h:3377
SourceRange getBracketsRange() const
Definition: Type.h:3370
Expr * getSizeExpr() const
Definition: Type.h:3364
SourceLocation getLBracketLoc() const
Definition: Type.h:3371
SourceLocation getRBracketLoc() const
Definition: Type.h:3372
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3442
QualType desugar() const
Definition: Type.h:3461
static bool classof(const Type *T)
Definition: Type.h:3463
SourceLocation getAttributeLoc() const
Definition: Type.h:3458
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3467
QualType getElementType() const
Definition: Type.h:3457
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition: Type.h:3769
Expr * getColumnExpr() const
Definition: Type.h:3782
Expr * getRowExpr() const
Definition: Type.h:3781
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3789
SourceLocation getAttributeLoc() const
Definition: Type.h:3783
static bool classof(const Type *T)
Definition: Type.h:3785
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:6047
const IdentifierInfo * getIdentifier() const
Definition: Type.h:6064
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:6074
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:6066
NestedNameSpecifier * getQualifier() const
Definition: Type.h:6063
static bool classof(const Type *T)
Definition: Type.h:6085
Internal representation of canonical, dependent typeof(expr) types.
Definition: Type.h:4850
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:4854
DependentTypeOfExprType(Expr *E, TypeOfKind Kind)
Definition: Type.h:4852
Internal representation of canonical, dependent __underlying_type(type) types.
Definition: Type.h:5052
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5057
static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType, UTTKind UKind)
Definition: Type.h:5061
Represents a vector type where either the type or size is dependent.
Definition: Type.h:3564
Expr * getSizeExpr() const
Definition: Type.h:3575
VectorKind getVectorKind() const
Definition: Type.h:3578
SourceLocation getAttributeLoc() const
Definition: Type.h:3577
bool isSugared() const
Definition: Type.h:3582
QualType getElementType() const
Definition: Type.h:3576
QualType desugar() const
Definition: Type.h:3583
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3589
static bool classof(const Type *T)
Definition: Type.h:3585
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:5914
static bool classof(const Type *T)
Definition: Type.h:5980
TagDecl * getOwnedTagDecl() const
Return the (re)declaration of this type owned by this occurrence of this type, or nullptr if there is...
Definition: Type.h:5962
QualType desugar() const
Remove a single level of sugar.
Definition: Type.h:5955
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:5949
static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl)
Definition: Type.h:5971
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.h:5958
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5967
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:5952
Represents an enum.
Definition: Decl.h:3832
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5118
EnumDecl * getDecl() const
Definition: Type.h:5125
bool isSugared() const
Definition: Type.h:5129
static bool classof(const Type *T)
Definition: Type.h:5132
QualType desugar() const
Definition: Type.h:5130
This represents one expression.
Definition: Expr.h:110
Base class that is common to both the ExtQuals and Type classes, which allows QualType to access the ...
Definition: Type.h:1460
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:1490
Qualifiers::ObjCLifetime getObjCLifetime() const
Definition: Type.h:1527
static void Profile(llvm::FoldingSetNodeID &ID, const Type *BaseType, Qualifiers Quals)
Definition: Type.h:1541
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:1537
ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
Definition: Type.h:1511
bool hasObjCGCAttr() const
Definition: Type.h:1523
Qualifiers::GC getObjCGCAttr() const
Definition: Type.h:1524
bool hasAddressSpace() const
Definition: Type.h:1531
const Type * getBaseType() const
Definition: Type.h:1534
Qualifiers getQualifiers() const
Definition: Type.h:1521
LangAS getAddressSpace() const
Definition: Type.h:1532
bool hasObjCLifetime() const
Definition: Type.h:1526
ExtVectorType - Extended vector type.
Definition: Type.h:3604
bool isSugared() const
Definition: Type.h:3663
bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const
Definition: Type.h:3657
static int getNumericAccessorIdx(char c)
Definition: Type.h:3622
static bool classof(const Type *T)
Definition: Type.h:3666
static int getPointAccessorIdx(char c)
Definition: Type.h:3612
QualType desugar() const
Definition: Type.h:3664
static int getAccessorIdx(char c, bool isNumericAccessor)
Definition: Type.h:3650
Represents a function declaration or definition.
Definition: Decl.h:1959
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4154
bool isSugared() const
Definition: Type.h:4167
static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, ExtInfo Info)
Definition: Type.h:4174
QualType desugar() const
Definition: Type.h:4168
static bool classof(const Type *T)
Definition: Type.h:4180
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4170
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4199
QualType desugar() const
Definition: Type.h:4666
param_type_iterator param_type_begin() const
Definition: Type.h:4591
ExtParameterInfo getExtParameterInfo(unsigned I) const
Definition: Type.h:4644
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:4458
bool isParamConsumed(unsigned I) const
Definition: Type.h:4658
exception_iterator exception_end() const
Definition: Type.h:4610
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present,...
Definition: Type.h:4629
unsigned getNumParams() const
Definition: Type.h:4432
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:4571
ExceptionSpecInfo getExceptionSpecInfo() const
Return all the available information about this type's exception spec.
Definition: Type.h:4484
Qualifiers getMethodQuals() const
Definition: Type.h:4573
static bool classof(const Type *T)
Definition: Type.h:4671
QualType getParamType(unsigned i) const
Definition: Type.h:4434
unsigned getAArch64SMEAttributes() const
Return a bitmask describing the SME attributes on the function type, see AArch64SMETypeAttributes for...
Definition: Type.h:4637
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
Definition: Type.h:4509
static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, param_type_iterator ArgTys, unsigned NumArgs, const ExtProtoInfo &EPI, const ASTContext &Context, bool Canonical)
SourceLocation getEllipsisLoc() const
Definition: Type.h:4557
unsigned getNumExceptions() const
Return the number of types in the exception specification.
Definition: Type.h:4501
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
Definition: Type.h:4464
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
Definition: Type.h:4467
bool hasNoexceptExceptionSpec() const
Return whether this function has a noexcept exception spec.
Definition: Type.h:4472
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:4555
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:4443
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
Definition: Type.h:4516
param_type_iterator param_type_end() const
Definition: Type.h:4595
FunctionDecl * getExceptionSpecTemplate() const
If this function type has an uninstantiated exception specification, this is the function whose excep...
Definition: Type.h:4537
bool isNothrow(bool ResultIfDependent=false) const
Determine whether this function type has a non-throwing exception specification.
Definition: Type.h:4550
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:4439
ArrayRef< QualType > exceptions() const
Definition: Type.h:4601
ParameterABI getParameterABI(unsigned I) const
Definition: Type.h:4651
ArrayRef< QualType > param_types() const
Definition: Type.h:4587
bool isSugared() const
Definition: Type.h:4665
exception_iterator exception_begin() const
Definition: Type.h:4605
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
Definition: Type.h:4620
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type?
Definition: Type.h:4616
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition: Type.h:4581
FunctionDecl * getExceptionSpecDecl() const
If this function type has an exception specification which hasn't been determined yet (either because...
Definition: Type.h:4526
A class which abstracts out some details necessary for making a call.
Definition: Type.h:3910
ExtInfo withNoCfCheck(bool noCfCheck) const
Definition: Type.h:4012
ExtInfo withCallingConv(CallingConv cc) const
Definition: Type.h:4025
CallingConv getCC() const
Definition: Type.h:3972
ExtInfo withProducesResult(bool producesResult) const
Definition: Type.h:3991
ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc, bool producesResult, bool noCallerSavedRegs, bool NoCfCheck, bool cmseNSCall)
Definition: Type.h:3938
bool getCmseNSCall() const
Definition: Type.h:3960
bool getNoCfCheck() const
Definition: Type.h:3962
unsigned getRegParm() const
Definition: Type.h:3965
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:4029
bool getNoCallerSavedRegs() const
Definition: Type.h:3961
ExtInfo withNoReturn(bool noReturn) const
Definition: Type.h:3984
bool getHasRegParm() const
Definition: Type.h:3963
bool getNoReturn() const
Definition: Type.h:3958
bool operator==(ExtInfo Other) const
Definition: Type.h:3974
bool getProducesResult() const
Definition: Type.h:3959
ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const
Definition: Type.h:4005
ExtInfo withCmseNSCall(bool cmseNSCall) const
Definition: Type.h:3998
ExtInfo(CallingConv CC)
Definition: Type.h:3956
ExtInfo withRegParm(unsigned RegParm) const
Definition: Type.h:4019
bool operator!=(ExtInfo Other) const
Definition: Type.h:3977
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition: Type.h:3825
friend bool operator==(ExtParameterInfo lhs, ExtParameterInfo rhs)
Definition: Type.h:3881
friend bool operator!=(ExtParameterInfo lhs, ExtParameterInfo rhs)
Definition: Type.h:3885
ExtParameterInfo withHasPassObjectSize() const
Definition: Type.h:3858
unsigned char getOpaqueValue() const
Definition: Type.h:3874
bool isConsumed() const
Is this parameter considered "consumed" by Objective-C ARC? Consumed parameters must have retainable ...
Definition: Type.h:3847
ParameterABI getABI() const
Return the ABI treatment of this parameter.
Definition: Type.h:3838
ExtParameterInfo withIsConsumed(bool consumed) const
Definition: Type.h:3848
ExtParameterInfo withIsNoEscape(bool NoEscape) const
Definition: Type.h:3865
ExtParameterInfo withABI(ParameterABI kind) const
Definition: Type.h:3839
static ExtParameterInfo getFromOpaqueValue(unsigned char data)
Definition: Type.h:3875
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3799
ExtInfo getExtInfo() const
Definition: Type.h:4128
static ArmStateValue getArmZT0State(unsigned AttrBits)
Definition: Type.h:4086
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
Definition: Type.h:4124
bool isConst() const
Definition: Type.h:4134
static ArmStateValue getArmZAState(unsigned AttrBits)
Definition: Type.h:4082
unsigned getRegParmType() const
Definition: Type.h:4119
CallingConv getCallConv() const
Definition: Type.h:4127
bool isRestrict() const
Definition: Type.h:4136
QualType getReturnType() const
Definition: Type.h:4116
FunctionType(TypeClass tc, QualType res, QualType Canonical, TypeDependence Dependence, ExtInfo Info)
Definition: Type.h:4102
static bool classof(const Type *T)
Definition: Type.h:4146
bool getCmseNSCallAttr() const
Definition: Type.h:4126
bool getHasRegParm() const
Definition: Type.h:4118
Qualifiers getFastTypeQuals() const
Definition: Type.h:4108
QualType getCallResultType(const ASTContext &Context) const
Determine the type of an expression that calls a function of this type.
Definition: Type.h:4140
AArch64SMETypeAttributes
The AArch64 SME ACLE (Arm C/C++ Language Extensions) define a number of function type attributes that...
Definition: Type.h:4058
bool isVolatile() const
Definition: Type.h:4135
One of these records is kept for each identifier that is lexed.
Represents a C array with an unspecified size.
Definition: Type.h:3246
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3263
static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, ArraySizeModifier SizeMod, unsigned TypeQuals)
Definition: Type.h:3268
QualType desugar() const
Definition: Type.h:3257
bool isSugared() const
Definition: Type.h:3256
static bool classof(const Type *T)
Definition: Type.h:3259
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:5764
QualType desugar() const
Definition: Type.h:5808
static bool classof(const Type *T)
Definition: Type.h:5810
const TemplateSpecializationType * getInjectedTST() const
Definition: Type.h:5797
TemplateName getTemplateName() const
Definition: Type.h:5801
QualType getInjectedSpecializationType() const
Definition: Type.h:5795
bool isSugared() const
Definition: Type.h:5807
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3053
static bool classof(const Type *T)
Definition: Type.h:3065
QualType desugar() const
Definition: Type.h:3063
bool isSugared() const
Definition: Type.h:3062
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition: Type.h:4785
bool isSugared() const
Definition: Type.h:4807
static bool classof(const Type *T)
Definition: Type.h:4810
QualType getUnderlyingType() const
Definition: Type.h:4801
const IdentifierInfo * getMacroIdentifier() const
Definition: Type.h:4800
Represents a matrix type, as defined in the Matrix Types clang extensions.
Definition: Type.h:3674
QualType getElementType() const
Returns type of the elements being stored in the matrix.
Definition: Type.h:3688
QualType desugar() const
Definition: Type.h:3701
MatrixType(QualType ElementTy, QualType CanonElementTy)
static bool isValidElementType(QualType T)
Valid elements types are the following:
Definition: Type.h:3695
QualType ElementType
The element type of the matrix.
Definition: Type.h:3679
bool isSugared() const
Definition: Type.h:3700
static bool classof(const Type *T)
Definition: Type.h:3703
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3089
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3125
QualType getPointeeType() const
Definition: Type.h:3105
bool isSugared() const
Definition: Type.h:3122
bool isMemberFunctionPointer() const
Returns true if the member type (i.e.
Definition: Type.h:3109
bool isMemberDataPointer() const
Returns true if the member type (i.e.
Definition: Type.h:3115
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, const Type *Class)
Definition: Type.h:3129
QualType desugar() const
Definition: Type.h:3123
static bool classof(const Type *T)
Definition: Type.h:3135
const Type * getClass() const
Definition: Type.h:3119
This represents a decl that may have a name.
Definition: Decl.h:249
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Represents an ObjC class declaration.
Definition: DeclObjC.h:1150
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:6495
QualType desugar() const
Definition: Type.h:6511
bool isSugared() const
Definition: Type.h:6510
static bool classof(const Type *T)
Definition: Type.h:6513
Represents a pointer to an Objective C object.
Definition: Type.h:6551
unsigned getNumProtocols() const
Return the number of qualifying protocols on the object type.
Definition: Type.h:6683
bool isSpecialized() const
Whether this type is specialized, meaning that it has type arguments.
Definition: Type.h:6640
qual_iterator qual_end() const
Definition: Type.h:6676
bool isObjCQualifiedClassType() const
True if this is equivalent to 'Class.
Definition: Type.h:6632
static void Profile(llvm::FoldingSetNodeID &ID, QualType T)
Definition: Type.h:6712
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Definition: Type.h:6626
bool isSpecializedAsWritten() const
Whether this type is specialized, meaning that it has type arguments.
Definition: Type.h:6643
bool isUnspecializedAsWritten() const
Determine whether this object type is "unspecialized" as written, meaning that it has no type argumen...
Definition: Type.h:6652
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments for this type.
Definition: Type.h:6660
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6708
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:6588
ObjCObjectType::qual_iterator qual_iterator
An iterator over the qualifiers on the object type.
Definition: Type.h:6667
llvm::iterator_range< qual_iterator > qual_range
Definition: Type.h:6668
static bool classof(const Type *T)
Definition: Type.h:6716
bool qual_empty() const
Definition: Type.h:6680
bool isUnspecialized() const
Whether this type is unspecialized, meaning that is has no type arguments.
Definition: Type.h:6648
bool isObjCIdType() const
True if this is equivalent to the 'id' type, i.e.
Definition: Type.h:6609
ObjCProtocolDecl * getProtocol(unsigned I) const
Retrieve a qualifying protocol by index on the object type.
Definition: Type.h:6688
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:6563
ObjCInterfaceDecl * getInterfaceDecl() const
If this pointer points to an Objective @interface type, gets the declaration for that interface.
Definition: Type.h:6603
QualType desugar() const
Definition: Type.h:6693
qual_range quals() const
Definition: Type.h:6670
bool isObjCClassType() const
True if this is equivalent to the 'Class' type, i.e.
Definition: Type.h:6615
bool isSugared() const
Definition: Type.h:6692
bool isObjCIdOrClassType() const
True if this is equivalent to the 'id' or 'Class' type,.
Definition: Type.h:6620
ArrayRef< QualType > getTypeArgs() const
Retrieve the type arguments for this type.
Definition: Type.h:6655
qual_iterator qual_begin() const
Definition: Type.h:6672
bool isKindOfType() const
Whether this is a "__kindof" type.
Definition: Type.h:6637
A class providing a concrete implementation of ObjCObjectType, so as to not increase the footprint of...
Definition: Type.h:6448
Represents a class type in Objective C.
Definition: Type.h:6297
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
Definition: Type.h:6412
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Definition: Type.h:6407
bool isUnspecializedAsWritten() const
Determine whether this object type is "unspecialized" as written, meaning that it has no type argumen...
Definition: Type.h:6400
bool isObjCQualifiedClass() const
Definition: Type.h:6379
ObjCObjectType(enum Nonce_ObjCInterface)
Definition: Type.h:6342
bool isObjCUnqualifiedIdOrClass() const
Definition: Type.h:6371
QualType getBaseType() const
Gets the base type of this object type.
Definition: Type.h:6359
bool isObjCClass() const
Definition: Type.h:6365
QualType desugar() const
Definition: Type.h:6436
bool isObjCQualifiedId() const
Definition: Type.h:6378
bool isSpecializedAsWritten() const
Determine whether this object type was written with type arguments.
Definition: Type.h:6390
bool isObjCUnqualifiedId() const
Definition: Type.h:6369
bool isUnspecialized() const
Determine whether this object type is "unspecialized", meaning that it has no type arguments.
Definition: Type.h:6396
bool isSugared() const
Definition: Type.h:6435
bool isObjCUnqualifiedClass() const
Definition: Type.h:6370
static bool classof(const Type *T)
Definition: Type.h:6438
QualType getSuperClassType() const
Retrieve the type of the superclass of this object type.
Definition: Type.h:6423
bool isObjCId() const
Definition: Type.h:6361
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2079
This class wraps the list of protocol qualifiers.
Definition: Type.h:6166
llvm::iterator_range< qual_iterator > qual_range
Definition: Type.h:6193
void initialize(ArrayRef< ObjCProtocolDecl * > protocols)
Definition: Type.h:6182
ObjCProtocolDecl ** getProtocolStorage()
Definition: Type.h:6174
ArrayRef< ObjCProtocolDecl * > getProtocols() const
Retrieve all of the protocol qualifiers.
Definition: Type.h:6214
unsigned getNumProtocols() const
Return the number of qualifying protocols in this type, or 0 if there are none.
Definition: Type.h:6203
void setNumProtocols(unsigned N)
Definition: Type.h:6178
qual_iterator qual_end() const
Definition: Type.h:6197
ObjCProtocolDecl *const * getProtocolStorage() const
Definition: Type.h:6170
ObjCProtocolDecl * getProtocol(unsigned I) const
Fetch a protocol by index.
Definition: Type.h:6208
qual_iterator qual_begin() const
Definition: Type.h:6196
qual_range quals() const
Definition: Type.h:6195
bool qual_empty() const
Definition: Type.h:6199
ObjCProtocolDecl *const * qual_iterator
Definition: Type.h:6192
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
Represents a type parameter type in Objective C.
Definition: Type.h:6223
static bool classof(const Type *T)
Definition: Type.h:6255
bool isSugared() const
Definition: Type.h:6252
QualType desugar() const
Definition: Type.h:6253
ObjCTypeParamDecl * getDecl() const
Definition: Type.h:6265
Represents a pack expansion of types.
Definition: Type.h:6112
bool isSugared() const
Definition: Type.h:6143
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6146
static bool classof(const Type *T)
Definition: Type.h:6158
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern, std::optional< unsigned > NumExpansions)
Definition: Type.h:6150
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Definition: Type.h:6133
std::optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:6137
QualType desugar() const
Definition: Type.h:6144
bool hasSelectedType() const
Definition: Type.h:4978
QualType getPattern() const
Definition: Type.h:4961
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4988
QualType getSelectedType() const
Definition: Type.h:4971
ArrayRef< QualType > getExpansions() const
Definition: Type.h:4980
QualType desugar() const
Definition: Type.h:4965
Expr * getIndexExpr() const
Definition: Type.h:4960
static bool classof(const Type *T)
Definition: Type.h:4984
bool isSugared() const
Definition: Type.h:4963
Sugar for parentheses used when specifying types.
Definition: Type.h:2872
QualType desugar() const
Definition: Type.h:2884
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2886
static bool classof(const Type *T)
Definition: Type.h:2894
static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner)
Definition: Type.h:2890
bool isSugared() const
Definition: Type.h:2883
QualType getInnerType() const
Definition: Type.h:2881
PipeType - OpenCL20.
Definition: Type.h:6751
QualType desugar() const
Definition: Type.h:6766
bool isSugared() const
Definition: Type.h:6764
static void Profile(llvm::FoldingSetNodeID &ID, QualType T, bool isRead)
Definition: Type.h:6772
QualType getElementType() const
Definition: Type.h:6762
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6768
static bool classof(const Type *T)
Definition: Type.h:6777
bool isReadOnly() const
Definition: Type.h:6781
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2898
QualType getPointeeType() const
Definition: Type.h:2908
static bool classof(const Type *T)
Definition: Type.h:2921
QualType desugar() const
Definition: Type.h:2911
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2913
bool isSugared() const
Definition: Type.h:2910
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee)
Definition: Type.h:2917
StreamedQualTypeHelper(const QualType &T, const PrintingPolicy &Policy, const Twine &PlaceHolder, unsigned Indentation)
Definition: Type.h:1168
friend raw_ostream & operator<<(raw_ostream &OS, const StreamedQualTypeHelper &SQT)
Definition: Type.h:1173
A (possibly-)qualified type.
Definition: Type.h:737
void addRestrict()
Add the restrict qualifier to this QualType.
Definition: Type.h:964
QualType(const ExtQuals *Ptr, unsigned Quals)
Definition: Type.h:762
bool isLocalConstQualified() const
Determine whether this particular QualType instance has the "const" qualifier set,...
Definition: Type.h:814
bool isLocalRestrictQualified() const
Determine whether this particular QualType instance has the "restrict" qualifier set,...
Definition: Type.h:844
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:6985
bool isRestrictQualified() const
Determine whether this type is restrict-qualified.
Definition: Type.h:6979
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
Definition: Type.cpp:2665
QualType IgnoreParens() const
Returns the specified type after dropping any outer-level parentheses.
Definition: Type.h:1107
Qualifiers::GC getObjCGCAttr() const
Returns gc attribute of this type.
Definition: Type.h:7032
friend bool operator==(const QualType &LHS, const QualType &RHS)
Indicate whether the specified types and qualifiers are identical.
Definition: Type.h:1114
bool hasQualifiers() const
Determine whether this type has any qualifiers.
Definition: Type.h:6990
QualType withFastQualifiers(unsigned TQs) const
Definition: Type.h:993
QualType withRestrict() const
Definition: Type.h:967
bool hasNonTrivialToPrimitiveCopyCUnion() const
Check if this is or contains a C union that is non-trivial to copy, which is a union that has a membe...
Definition: Type.h:7048
void addFastQualifiers(unsigned TQs)
Definition: Type.h:975
bool isWebAssemblyFuncrefType() const
Returns true if it is a WebAssembly Funcref Type.
Definition: Type.cpp:2785
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
Definition: Type.cpp:3403
@ DK_cxx_destructor
Definition: Type.h:1313
@ DK_nontrivial_c_struct
Definition: Type.h:1316
@ DK_objc_weak_lifetime
Definition: Type.h:1315
@ DK_objc_strong_lifetime
Definition: Type.h:1314
PrimitiveDefaultInitializeKind
Definition: Type.h:1244
@ PDIK_ARCWeak
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier.
Definition: Type.h:1256
@ PDIK_Trivial
The type does not fall into any of the following categories.
Definition: Type.h:1248
@ PDIK_ARCStrong
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier.
Definition: Type.h:1252
@ PDIK_Struct
The type is a struct containing a field whose type is not PCK_Trivial.
Definition: Type.h:1259
bool mayBeDynamicClass() const
Returns true if it is a class and it might be dynamic.
Definition: Type.cpp:95
bool hasLocalNonFastQualifiers() const
Determine whether this particular QualType instance has any "non-fast" qualifiers,...
Definition: Type.h:874
bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const
Definition: Type.cpp:2759
const IdentifierInfo * getBaseTypeIdentifier() const
Retrieves a pointer to the name of the base type.
Definition: Type.cpp:75
QualType withoutLocalFastQualifiers() const
Definition: Type.h:1006
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:1190
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
Definition: Type.h:1088
void removeLocalFastQualifiers(unsigned Mask)
Definition: Type.h:986
QualType withConst() const
Definition: Type.h:951
QualType getLocalUnqualifiedType() const
Return this type with all of the instance-specific qualifiers removed, but without removing any quali...
Definition: Type.h:1017
void addConst()
Add the const type qualifier to this QualType.
Definition: Type.h:948
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:7083
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
Definition: Type.h:864
bool isTriviallyCopyConstructibleType(const ASTContext &Context) const
Return true if this is a trivially copyable type.
Definition: Type.cpp:2670
bool isTrivialType(const ASTContext &Context) const
Return true if this is a trivial type per (C++0x [basic.types]p9)
Definition: Type.cpp:2567
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:804
PrimitiveCopyKind isNonTrivialToPrimitiveCopy() const
Check if this is a non-trivial type that would cause a C struct transitively containing this type to ...
Definition: Type.cpp:2807
bool isTriviallyRelocatableType(const ASTContext &Context) const
Return true if this is a trivially relocatable type.
Definition: Type.cpp:2676
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6902
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:7027
bool isConstant(const ASTContext &Ctx) const
Definition: Type.h:897
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:786
QualType withVolatile() const
Definition: Type.h:959
bool hasNonTrivialToPrimitiveDestructCUnion() const
Check if this is or contains a C union that is non-trivial to destruct, which is a union that has a m...
Definition: Type.h:7042
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:6942
const Type * operator->() const
Definition: Type.h:796
void setLocalFastQualifiers(unsigned Quals)
Definition: Type.h:765
bool isAddressSpaceOverlapping(QualType T) const
Returns true if address space qualifiers overlap with T address space qualifiers.
Definition: Type.h:1208
bool isCXX98PODType(const ASTContext &Context) const
Return true if this is a POD type according to the rules of the C++98 standard, regardless of the cur...
Definition: Type.cpp:2518
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1229
QualType stripObjCKindOfType(const ASTContext &ctx) const
Strip Objective-C "__kindof" types from the given type.
Definition: Type.cpp:1560
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
void getAsStringInternal(std::string &Str, const PrintingPolicy &Policy) const
bool isReferenceable() const
Definition: Type.h:6910
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:7102
QualType getCanonicalType() const
Definition: Type.h:6954
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:6995
bool isTriviallyEqualityComparableType(const ASTContext &Context) const
Return true if this is a trivially equality comparable type.
Definition: Type.cpp:2743
void removeLocalVolatile()
Definition: Type.h:7017
QualType substObjCMemberType(QualType objectType, const DeclContext *dc, ObjCSubstitutionContext context) const
Substitute type arguments from an object type for the Objective-C type parameters used in the subject...
Definition: Type.cpp:1551
bool isWebAssemblyReferenceType() const
Returns true if it is a WebAssembly Reference Type.
Definition: Type.cpp:2777
SplitQualType getSplitDesugaredType() const
Definition: Type.h:1092
std::optional< NonConstantStorageReason > isNonConstantStorage(const ASTContext &Ctx, bool ExcludeCtor, bool ExcludeDtor)
Determine whether instances of this type can be placed in immutable storage.
Definition: Type.cpp:116
QualType withCVRQualifiers(unsigned CVR) const
Definition: Type.h:971
QualType()=default
unsigned getLocalCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers local to this particular QualType instan...
Definition: Type.h:889
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:6923
bool UseExcessPrecision(const ASTContext &Ctx)
Definition: Type.cpp:1509
void addVolatile()
Add the volatile type qualifier to this QualType.
Definition: Type.h:956
bool isCForbiddenLValueType() const
Determine whether expressions of the given type are forbidden from being lvalues in C.
Definition: Type.h:7109
PrimitiveDefaultInitializeKind isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C struct types.
Definition: Type.cpp:2791
bool isObjCGCStrong() const
true when Type is objc's strong.
Definition: Type.h:1224
std::string getAsString() const
void dump() const
Definition: ASTDumper.cpp:185
void * getAsOpaquePtr() const
Definition: Type.h:784
static void print(SplitQualType split, raw_ostream &OS, const PrintingPolicy &policy, const Twine &PlaceHolder, unsigned Indentation=0)
Definition: Type.h:1138
bool isCanonicalAsParam() const
Definition: Type.h:6963
void removeLocalConst()
Definition: Type.h:7009
void removeLocalRestrict()
Definition: Type.h:7013
bool isWebAssemblyExternrefType() const
Returns true if it is a WebAssembly Externref Type.
Definition: Type.cpp:2781
QualType(const Type *Ptr, unsigned Quals)
Definition: Type.h:761
QualType getNonPackExpansionType() const
Remove an outer pack expansion type (if any) from this type.
Definition: Type.cpp:3396
bool isMoreQualifiedThan(QualType Other) const
Determine whether this type is more qualified than the other given type, requiring exact equality for...
Definition: Type.h:7073
SplitQualType getSplitUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:7002
bool isCXX11PODType(const ASTContext &Context) const
Return true if this is a POD type according to the more relaxed rules of the C++11 standard,...
Definition: Type.cpp:2946
bool mayBeNotDynamicClass() const
Returns true if it is not a class or if the class might not be dynamic.
Definition: Type.cpp:100
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition: Type.h:6974
bool hasAddressSpace() const
Check if this type has any address space qualifier.
Definition: Type.h:7022
bool isObjCGCWeak() const
true when Type is objc's weak.
Definition: Type.h:1219
QualType substObjCTypeArgs(ASTContext &ctx, ArrayRef< QualType > typeArgs, ObjCSubstitutionContext context) const
Substitute type arguments for the Objective-C type parameters used in the subject type.
Definition: Type.cpp:1544
unsigned getLocalFastQualifiers() const
Definition: Type.h:764
void removeLocalFastQualifiers()
Definition: Type.h:985
QualType getAtomicUnqualifiedType() const
Remove all qualifiers including _Atomic.
Definition: Type.cpp:1567
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition: Type.h:1323
friend bool operator<(const QualType &LHS, const QualType &RHS)
Definition: Type.h:1120
friend bool operator!=(const QualType &LHS, const QualType &RHS)
Definition: Type.h:1117
bool isCanonical() const
Definition: Type.h:6959
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition: Type.h:1180
bool isLocalVolatileQualified() const
Determine whether this particular QualType instance has the "volatile" qualifier set,...
Definition: Type.h:854
bool isConstantStorage(const ASTContext &Ctx, bool ExcludeCtor, bool ExcludeDtor)
Definition: Type.h:836
unsigned getCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers applied to this type.
Definition: Type.h:6948
static void getAsStringInternal(SplitQualType split, std::string &out, const PrintingPolicy &policy)
Definition: Type.h:1152
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
Definition: Type.h:1101
const Type * getTypePtrOrNull() const
Definition: Type.h:6906
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition: Type.h:1124
bool hasNonTrivialObjCLifetime() const
Definition: Type.h:1233
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
Definition: Type.cpp:2510
bool hasStrongOrWeakObjCLifetime() const
Definition: Type.h:1237
PrimitiveCopyKind isNonTrivialToPrimitiveDestructiveMove() const
Check if this is a non-trivial type that would cause a C struct transitively containing this type to ...
Definition: Type.cpp:2825
QualType withExactLocalFastQualifiers(unsigned TQs) const
Definition: Type.h:1001
NonConstantStorageReason
Definition: Type.h:821
@ PCK_Struct
The type is a struct containing a field whose type is neither PCK_Trivial nor PCK_VolatileTrivial.
Definition: Type.h:1295
@ PCK_Trivial
The type does not fall into any of the following categories.
Definition: Type.h:1274
@ PCK_ARCStrong
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier.
Definition: Type.h:1283
@ PCK_VolatileTrivial
The type would be trivial except that it is volatile-qualified.
Definition: Type.h:1279
@ PCK_ARCWeak
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier.
Definition: Type.h:1287
const Type & operator*() const
Definition: Type.h:792
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:6934
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Check if this is or contains a C union that is non-trivial to default-initialize, which is a union th...
Definition: Type.h:7036
A qualifier set is used to build a set of qualifiers.
Definition: Type.h:6842
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
Definition: Type.h:6849
QualifierCollector(Qualifiers Qs=Qualifiers())
Definition: Type.h:6844
bool hasAtomic() const
Definition: Type.h:641
bool hasConst() const
Definition: Type.h:639
QualifiersAndAtomic & operator+=(Qualifiers RHS)
Definition: Type.h:662
bool hasRestrict() const
Definition: Type.h:640
QualifiersAndAtomic withVolatile()
Definition: Type.h:653
QualifiersAndAtomic withAtomic()
Definition: Type.h:660
QualifiersAndAtomic withConst()
Definition: Type.h:656
bool hasVolatile() const
Definition: Type.h:638
QualifiersAndAtomic(Qualifiers Quals, bool HasAtomic)
Definition: Type.h:633
QualifiersAndAtomic withRestrict()
Definition: Type.h:657
The collection of all-type qualifiers we support.
Definition: Type.h:147
unsigned getCVRQualifiers() const
Definition: Type.h:295
@ FastWidth
The width of the "fast" qualifier mask.
Definition: Type.h:190
@ MaxAddressSpace
The maximum supported address space number.
Definition: Type.h:187
@ FastMask
The fast qualifier mask.
Definition: Type.h:193
void removeCVRQualifiers(unsigned mask)
Definition: Type.h:302
GC getObjCGCAttr() const
Definition: Type.h:326
friend Qualifiers operator-(Qualifiers L, Qualifiers R)
Compute the difference between two qualifier sets.
Definition: Type.h:593
static Qualifiers fromFastMask(unsigned Mask)
Definition: Type.h:234
void setFastQualifiers(unsigned mask)
Definition: Type.h:413
void addAddressSpace(LangAS space)
Definition: Type.h:404
static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R)
Returns the common set of qualifiers while removing them from the given sets.
Definition: Type.h:198
bool hasOnlyConst() const
Definition: Type.h:265
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
Definition: Type.h:175
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
Definition: Type.h:168
@ OCL_None
There is no lifetime qualification on this type.
Definition: Type.h:164
@ OCL_Weak
Reading or writing from this object requires a barrier call.
Definition: Type.h:178
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
Definition: Type.h:181
void removeObjCLifetime()
Definition: Type.h:358
bool hasTargetSpecificAddressSpace() const
Definition: Type.h:381
bool isStrictSupersetOf(Qualifiers Other) const
Determine whether this set of qualifiers is a strict superset of another set of qualifiers,...
Definition: Type.cpp:60
bool hasNonFastQualifiers() const
Return true if the set contains any qualifiers which require an ExtQuals node to be allocated.
Definition: Type.h:431
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:607
bool isAddressSpaceSupersetOf(Qualifiers other) const
Returns true if the address space in these qualifiers is equal to or a superset of the address space ...
Definition: Type.h:525
bool operator!=(Qualifiers Other) const
Definition: Type.h:571
bool hasConst() const
Definition: Type.h:264
bool hasNonTrivialObjCLifetime() const
True if the lifetime is neither None or ExplicitNone.
Definition: Type.h:366
void addCVRQualifiers(unsigned mask)
Definition: Type.h:309
bool hasCVRQualifiers() const
Definition: Type.h:294
void addConsistentQualifiers(Qualifiers qs)
Add the qualifiers from the given set to this set, given that they don't conflict.
Definition: Type.h:478
void removeFastQualifiers(unsigned mask)
Definition: Type.h:417
Qualifiers & operator+=(Qualifiers R)
Definition: Type.h:575
void removeFastQualifiers()
Definition: Type.h:421
bool hasQualifiers() const
Return true if the set contains any qualifiers.
Definition: Type.h:439
void removeCVRQualifiers()
Definition: Type.h:306
Qualifiers withVolatile() const
Definition: Type.h:278
void addCVRUQualifiers(unsigned mask)
Definition: Type.h:313
Qualifiers & operator-=(Qualifiers R)
Definition: Type.h:587
void addRestrict()
Definition: Type.h:287
bool hasUnaligned() const
Definition: Type.h:318
unsigned getAddressSpaceAttributePrintValue() const
Get the address space attribute value to be printed by diagnostics.
Definition: Type.h:385
bool hasAddressSpace() const
Definition: Type.h:377
bool hasRestrict() const
Definition: Type.h:284
void removeObjCGCAttr()
Definition: Type.h:330
void removeUnaligned()
Definition: Type.h:322
Qualifiers withoutAddressSpace() const
Definition: Type.h:345
void removeConst()
Definition: Type.h:266
void removeRestrict()
Definition: Type.h:286
unsigned getFastQualifiers() const
Definition: Type.h:412
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool appendSpaceIfNonEmpty=false) const
void removeAddressSpace()
Definition: Type.h:403
void addConst()
Definition: Type.h:267
void addQualifiers(Qualifiers Q)
Add the qualifiers from the given set to this set.
Definition: Type.h:443
static Qualifiers fromCVRMask(unsigned CVR)
Definition: Type.h:240
void addUnaligned()
Definition: Type.h:323
void setAddressSpace(LangAS space)
Definition: Type.h:398
unsigned getAsOpaqueValue() const
Definition: Type.h:260
static bool isAddressSpaceSupersetOf(LangAS A, LangAS B)
Returns true if address space A is equal to or a superset of B.
Definition: Type.h:495
unsigned getCVRUQualifiers() const
Definition: Type.h:296
bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const
bool hasVolatile() const
Definition: Type.h:274
void setObjCGCAttr(GC type)
Definition: Type.h:327
Qualifiers withConst() const
Definition: Type.h:268
bool hasObjCGCAttr() const
Definition: Type.h:325
void setCVRQualifiers(unsigned mask)
Definition: Type.h:298
bool hasObjCLifetime() const
Definition: Type.h:351
ObjCLifetime getObjCLifetime() const
Definition: Type.h:352
Qualifiers withoutObjCLifetime() const
Definition: Type.h:340
Qualifiers withoutObjCGCAttr() const
Definition: Type.h:335
static Qualifiers fromCVRUMask(unsigned CVRU)
Definition: Type.h:246
friend Qualifiers operator+(Qualifiers L, Qualifiers R)
Definition: Type.h:582
bool empty() const
Definition: Type.h:440
void setUnaligned(bool flag)
Definition: Type.h:319
void addFastQualifiers(unsigned mask)
Definition: Type.h:424
void removeVolatile()
Definition: Type.h:276
std::string getAsString() const
Qualifiers withRestrict() const
Definition: Type.h:288
void addObjCGCAttr(GC type)
Definition: Type.h:331
bool operator==(Qualifiers Other) const
Definition: Type.h:570
bool compatiblyIncludes(Qualifiers other) const
Determines if these qualifiers compatibly include another set.
Definition: Type.h:532
void removeQualifiers(Qualifiers Q)
Remove the qualifiers from the given set from this set.
Definition: Type.h:460
LangAS getAddressSpace() const
Definition: Type.h:378
bool hasOnlyVolatile() const
Definition: Type.h:275
static Qualifiers fromOpaqueValue(unsigned opaque)
Definition: Type.h:253
bool compatiblyIncludesObjCLifetime(Qualifiers other) const
Determines if these qualifiers compatibly include another set of qualifiers from the narrow perspecti...
Definition: Type.h:553
Qualifiers getNonFastQualifiers() const
Definition: Type.h:432
bool hasStrongOrWeakObjCLifetime() const
True if the lifetime is either strong or weak.
Definition: Type.h:372
static std::string getAddrSpaceAsString(LangAS AS)
void addVolatile()
Definition: Type.h:277
bool hasFastQualifiers() const
Definition: Type.h:411
bool hasOnlyRestrict() const
Definition: Type.h:285
void addObjCLifetime(ObjCLifetime type)
Definition: Type.h:359
void setObjCLifetime(ObjCLifetime type)
Definition: Type.h:355
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3071
static bool classof(const Type *T)
Definition: Type.h:3081
QualType desugar() const
Definition: Type.h:3079
bool isSugared() const
Definition: Type.h:3078
Represents a struct/union/class.
Definition: Decl.h:4133
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5092
RecordType(const RecordDecl *D)
Definition: Type.h:5096
bool isSugared() const
Definition: Type.h:5110
QualType desugar() const
Definition: Type.h:5111
RecordDecl * getDecl() const
Definition: Type.h:5102
RecordType(TypeClass TC, RecordDecl *D)
Definition: Type.h:5098
static bool classof(const Type *T)
Definition: Type.h:5113
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3009
bool isInnerRef() const
Definition: Type.h:3023
QualType getPointeeType() const
Definition: Type.h:3027
ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, bool SpelledAsLValue)
Definition: Type.h:3013
static bool classof(const Type *T)
Definition: Type.h:3046
QualType getPointeeTypeAsWritten() const
Definition: Type.h:3025
bool isSpelledAsLValue() const
Definition: Type.h:3022
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3035
static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee, bool SpelledAsLValue)
Definition: Type.h:3039
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
Definition: Stmt.h:84
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
Definition: Diagnostic.h:1115
void AddTaggedVal(uint64_t V, DiagnosticsEngine::ArgumentKind Kind) const
Definition: Diagnostic.h:1189
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:5432
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: Type.h:5458
static bool classof(const Type *T)
Definition: Type.h:5477
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:5362
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5401
static bool classof(const Type *T)
Definition: Type.h:5415
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: Type.h:5383
std::optional< unsigned > getPackIndex() const
Definition: Type.h:5392
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:5374
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: Type.h:5390
QualType desugar() const
Definition: Type.h:5399
static void Profile(llvm::FoldingSetNodeID &ID, QualType Replacement, const Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex)
Definition: Type.h:5406
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3549
static bool classof(const Type *T)
Definition: Type.h:5085
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
Represents a template argument.
Definition: TemplateBase.h:61
Represents a C++ template name within the type system.
Definition: TemplateName.h:202
void Profile(llvm::FoldingSetNodeID &ID)
bool isDependent() const
Determines whether this is a dependent template name.
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:5632
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:5700
static bool classof(const Type *T)
Definition: Type.h:5718
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:5698
bool isTypeAlias() const
Determine if this template specialization type is for a type alias template that has been substituted...
Definition: Type.h:5691
QualType desugar() const
Definition: Type.h:5709
bool isCurrentInstantiation() const
True if this template specialization type matches a current instantiation in the context in which it ...
Definition: Type.h:5672
Declaration of a template type parameter.
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:5325
QualType desugar() const
Definition: Type.h:5332
bool isParameterPack() const
Definition: Type.h:5323
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5334
unsigned getIndex() const
Definition: Type.h:5322
bool isSugared() const
Definition: Type.h:5331
static bool classof(const Type *T)
Definition: Type.h:5347
static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *TTPDecl)
Definition: Type.h:5338
CanonicalTTPTInfo CanTTPTInfo
Definition: Type.h:5292
TemplateTypeParmDecl * TTPDecl
Definition: Type.h:5295
unsigned getDepth() const
Definition: Type.h:5321
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:59
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Definition: Type.h:4817
static bool classof(const Type *T)
Definition: Type.h:4840
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition: Type.h:4829
Expr * getUnderlyingExpr() const
Definition: Type.h:4826
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:4865
static bool classof(const Type *T)
Definition: Type.h:4897
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition: Type.h:4892
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.h:4889
QualType desugar() const
Remove a single level of sugar.
Definition: Type.h:4883
QualType getUnmodifiedType() const
Definition: Type.h:4880
The type-property cache.
Definition: Type.cpp:4261
A container of type source information.
Definition: Type.h:6873
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6884
void overrideType(QualType T)
Override the type stored in this TypeSourceInfo. Use with caution!
Definition: Type.h:6890
A helper class for Type nodes having an ElaboratedTypeKeyword.
Definition: Type.h:5863
TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, QualType Canonical, TypeDependence Dependence)
Definition: Type.h:5865
static CannotCastToThisType classof(const Type *)
static StringRef getTagTypeKindName(TagTypeKind Kind)
Definition: Type.h:5895
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:5872
FunctionTypeBitfields store various bits belonging to FunctionProtoType.
Definition: Type.h:1709
The base class of the type hierarchy.
Definition: Type.h:1606
bool isIncompleteOrObjectType() const
Return true if this is an incomplete or object type, in other words, not a function type.
Definition: Type.h:2170
TypedefBitfields TypedefBits
Definition: Type.h:2010
UsingBitfields UsingBits
Definition: Type.h:2011
bool isBooleanType() const
Definition: Type.h:7567
Type(const Type &)=delete
ReferenceTypeBitfields ReferenceTypeBits
Definition: Type.h:2015
ElaboratedTypeBitfields ElaboratedTypeBits
Definition: Type.h:2017
ArrayTypeBitfields ArrayTypeBits
Definition: Type.h:2005
Type(Type &&)=delete
VectorTypeBitfields VectorTypeBits
Definition: Type.h:2018
TypeWithKeywordBitfields TypeWithKeywordBits
Definition: Type.h:2016
TypeOfBitfields TypeOfBits
Definition: Type.h:2009
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7724
BuiltinTypeBitfields BuiltinTypeBits
Definition: Type.h:2012
bool isReferenceType() const
Definition: Type.h:7166
bool isEnumeralType() const
Definition: Type.h:7248
bool isVisibilityExplicit() const
Return true if the visibility was explicitly set is the code.
Definition: Type.h:2654
void addDependence(TypeDependence D)
Definition: Type.h:2061
ConstantArrayTypeBitfields ConstantArrayTypeBits
Definition: Type.h:2006
Type(TypeClass tc, QualType canon, TypeDependence Dependence)
Definition: Type.h:2038
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:651
Type & operator=(const Type &)=delete
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.h:2525
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:2428
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2420
TypeBitfields TypeBits
Definition: Type.h:2004
DependentTemplateSpecializationTypeBitfields DependentTemplateSpecializationTypeBits
Definition: Type.h:2023
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:2094
QualType getCanonicalTypeInternal() const
Definition: Type.h:2703
bool containsErrors() const
Whether this type is an error type.
Definition: Type.h:2414
AttributedTypeBitfields AttributedTypeBits
Definition: Type.h:2007
bool isFunctionProtoType() const
Definition: Type.h:2263
PackExpansionTypeBitfields PackExpansionTypeBits
Definition: Type.h:2024
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Definition: Type.h:2438
bool isFromAST() const
Whether this type comes from an AST file.
Definition: Type.h:2077
bool isObjectType() const
Determine whether this type is an object type.
Definition: Type.h:2175
Type * this_()
Definition: Type.h:2055
FunctionTypeBitfields FunctionTypeBits
Definition: Type.h:2013
void setDependence(TypeDependence D)
Definition: Type.h:2057
SubstTemplateTypeParmTypeBitfields SubstTemplateTypeParmTypeBits
Definition: Type.h:2019
TypeDependence getDependence() const
Definition: Type.h:2409
Visibility getVisibility() const
Determine the visibility of this type.
Definition: Type.h:2649
bool isObjCInertUnsafeUnretainedType() const
Was this type written with the special inert-in-ARC __unsafe_unretained qualifier?
Definition: Type.h:2317
ObjCObjectTypeBitfields ObjCObjectTypeBits
Definition: Type.h:2014
ScalarTypeKind
Definition: Type.h:2393
@ STK_FloatingComplex
Definition: Type.h:2402
@ STK_Floating
Definition: Type.h:2400
@ STK_BlockPointer
Definition: Type.h:2395
@ STK_Bool
Definition: Type.h:2398
@ STK_ObjCObjectPointer
Definition: Type.h:2396
@ STK_IntegralComplex
Definition: Type.h:2401
@ STK_CPointer
Definition: Type.h:2394
@ STK_Integral
Definition: Type.h:2399
@ STK_MemberPointer
Definition: Type.h:2397
bool isRealType() const
Definition: Type.cpp:2209
bool hasSizedVLAType() const
Whether this type involves a variable-length array type with a definite size.
Definition: Type.cpp:4815
TypeClass getTypeClass() const
Definition: Type.h:2074
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: Type.h:2100
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7657
SubstTemplateTypeParmPackTypeBitfields SubstTemplateTypeParmPackTypeBits
Definition: Type.h:2020
TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits
Definition: Type.h:2021
bool isFunctionNoProtoType() const
Definition: Type.h:2262
AutoTypeBitfields AutoTypeBits
Definition: Type.h:2008
Type & operator=(Type &&)=delete
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3399
TypedefNameDecl * getDecl() const
Definition: Type.h:4760
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4770
static bool classof(const Type *T)
Definition: Type.h:4780
bool typeMatchesDecl() const
Definition: Type.h:4768
bool isSugared() const
Definition: Type.h:4762
static void Profile(llvm::FoldingSetNodeID &ID, const TypedefNameDecl *Decl, QualType Underlying)
Definition: Type.h:4773
A unary type transform, which is a type constructed from another.
Definition: Type.h:5009
QualType getUnderlyingType() const
Definition: Type.h:5035
QualType getBaseType() const
Definition: Type.h:5036
UTTKind getUTTKind() const
Definition: Type.h:5038
bool isSugared() const
Definition: Type.h:5032
static bool classof(const Type *T)
Definition: Type.h:5040
QualType desugar() const
Definition: Type.h:5033
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:4687
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4707
QualType desugar() const
Definition: Type.h:4701
static void Profile(llvm::FoldingSetNodeID &ID, UnresolvedUsingTypenameDecl *D)
Definition: Type.h:4711
UnresolvedUsingTypenameDecl * getDecl() const
Definition: Type.h:4698
static bool classof(const Type *T)
Definition: Type.h:4703
bool isSugared() const
Definition: Type.h:4700
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3952
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3313
QualType desugar() const
Definition: Type.h:4733
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4738
bool isSugared() const
Definition: Type.h:4730
static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl *Found, QualType Underlying)
Definition: Type.h:4741
static bool classof(const Type *T)
Definition: Type.h:4746
UsingShadowDecl * getFoundDecl() const
Definition: Type.h:4727
bool typeMatchesDecl() const
Definition: Type.h:4736
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3290
SourceRange getBracketsRange() const
Definition: Type.h:3315
SourceLocation getLBracketLoc() const
Definition: Type.h:3316
static bool classof(const Type *T)
Definition: Type.h:3322
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3326
Expr * getSizeExpr() const
Definition: Type.h:3309
SourceLocation getRBracketLoc() const
Definition: Type.h:3317
QualType desugar() const
Definition: Type.h:3320
bool isSugared() const
Definition: Type.h:3319
Represents a GCC generic vector type.
Definition: Type.h:3512
unsigned getNumElements() const
Definition: Type.h:3527
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3536
bool isSugared() const
Definition: Type.h:3529
static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, unsigned NumElements, TypeClass TypeClass, VectorKind VecKind)
Definition: Type.h:3541
VectorKind getVectorKind() const
Definition: Type.h:3532
QualType ElementType
The element type of the vector.
Definition: Type.h:3517
QualType desugar() const
Definition: Type.h:3530
QualType getElementType() const
Definition: Type.h:3526
static bool classof(const Type *T)
Definition: Type.h:3550
Defines the Linkage enumeration and various utility functions.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
TypeDependenceScope::TypeDependence TypeDependence
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: Type.h:1565
@ GNUAutoType
__auto_type (GNU extension)
@ DecltypeAuto
decltype(auto)
bool isTargetAddressSpace(LangAS AS)
Definition: AddressSpaces.h:77
CanThrowResult
Possible results from evaluation of a noexcept expression.
FunctionType::ExtInfo getFunctionExtInfo(const Type &t)
Definition: Type.h:7054
bool isDynamicExceptionSpec(ExceptionSpecificationType ESpecType)
NullabilityKind
Describes the nullability of a particular type.
Definition: Specifiers.h:332
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
Definition: Type.h:1553
@ RQ_None
No ref-qualifier was provided.
Definition: Type.h:1555
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
Definition: Type.h:1558
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
Definition: Type.h:1561
bool IsEnumDeclComplete(EnumDecl *ED)
Check if the given decl is complete.
Definition: Decl.h:4997
TypeOfKind
The kind of 'typeof' expression we're after.
Definition: Type.h:718
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
TypeDependence toTypeDependence(ExprDependence D)
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
unsigned toTargetAddressSpace(LangAS AS)
Definition: AddressSpaces.h:81
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:24
ObjCSubstitutionContext
The kind of type we are substituting Objective-C type arguments into.
Definition: Type.h:700
@ Superclass
The superclass of a type.
@ Property
The type of a property.
@ Parameter
The parameter type of a method or function.
@ Result
The result type of a method or function.
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: Type.h:3144
ParameterABI
Kinds of parameter ABI.
Definition: Specifiers.h:362
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
TagTypeKind
The kind of a tag type.
Definition: Type.h:5842
bool IsEnumDeclScoped(EnumDecl *ED)
Check if the given decl is scoped.
Definition: Decl.h:5005
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
void FixedPointValueToString(SmallVectorImpl< char > &Str, llvm::APSInt Val, unsigned Scale)
Definition: Type.cpp:4868
std::integral_constant< bool, std::is_same< T, ArrayType >::value||std::is_base_of< ArrayType, T >::value > TypeIsArrayType
Definition: Type.h:7654
@ TypeAlignment
Definition: Type.h:70
@ TypeAlignmentInBits
Definition: Type.h:69
bool isPtrSizeAddressSpace(LangAS AS)
Definition: AddressSpaces.h:91
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:275
@ CC_C
Definition: Specifiers.h:276
VectorKind
Definition: Type.h:3475
@ AltiVecBool
is AltiVec 'vector bool ...'
@ SveFixedLengthData
is AArch64 SVE fixed-length data vector
@ AltiVecVector
is AltiVec vector
@ AltiVecPixel
is AltiVec 'vector Pixel'
@ Neon
is ARM Neon vector
@ Generic
not a target-specific vector type
@ RVVFixedLengthData
is RISC-V RVV fixed-length data vector
@ RVVFixedLengthMask
is RISC-V RVV fixed-length mask vector
@ NeonPoly
is ARM Neon polynomial vector
@ SveFixedLengthPredicate
is AArch64 SVE fixed-length predicate vector
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:5817
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
TypeDependence toSyntacticDependence(TypeDependence D)
@ Other
Other implicit parameter.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_DependentNoexcept
noexcept(expression), value-dependent
@ EST_DynamicNone
throw()
@ EST_Uninstantiated
not instantiated yet
@ EST_Unparsed
not parsed yet
@ EST_NoThrow
Microsoft __declspec(nothrow) extension.
@ EST_None
no exception specification
@ EST_MSAny
Microsoft throw(...) extension.
@ EST_BasicNoexcept
noexcept
@ EST_NoexceptFalse
noexcept(expression), evals to 'false'
@ EST_Unevaluated
not evaluated yet, for special member function
@ EST_NoexceptTrue
noexcept(expression), evals to 'true'
@ EST_Dynamic
throw(T1, T2)
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:34
YAML serialization mapping.
Definition: Dominators.h:30
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
#define false
Definition: stdbool.h:22
#define bool
Definition: stdbool.h:20
Holds information about the various types of exception specification.
Definition: Type.h:4250
ExceptionSpecInfo(ExceptionSpecificationType EST)
Definition: Type.h:4270
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:4252
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:4255
Extra information about a function prototype.
Definition: Type.h:4278
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:4285
bool requiresFunctionProtoTypeArmAttributes() const
Definition: Type.h:4308
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:4286
bool requiresFunctionProtoTypeExtraBitfields() const
Definition: Type.h:4303
void setArmSMEAttribute(AArch64SMETypeAttributes Kind, bool Enable=true)
Definition: Type.h:4312
ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &ESI)
Definition: Type.h:4297
FunctionType::ExtInfo ExtInfo
Definition: Type.h:4279
A simple holder for a QualType representing a type in an exception specification.
Definition: Type.h:4037
A holder for Arm type attributes as described in the Arm C/C++ Language extensions which are not part...
Definition: Type.h:4093
unsigned AArch64SMEAttributes
Any AArch64 SME ACLE type attributes that need to be propagated on declarations and function pointers...
Definition: Type.h:4096
A simple holder for various uncommon bits which do not fit in FunctionTypeBitfields.
Definition: Type.h:4042
unsigned NumExceptionType
The number of types in the exception specification.
Definition: Type.h:4046
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:670
SplitQualType(const Type *ty, Qualifiers qs)
Definition: Type.h:678
SplitQualType getSingleStepDesugaredType() const
Definition: Type.h:6895
friend bool operator==(SplitQualType a, SplitQualType b)
Definition: Type.h:687
const Type * Ty
The locally-unqualified type.
Definition: Type.h:672
friend bool operator!=(SplitQualType a, SplitQualType b)
Definition: Type.h:690
std::pair< const Type *, Qualifiers > asPair() const
Definition: Type.h:683
Qualifiers Quals
The local qualifiers.
Definition: Type.h:675
static inline ::clang::ExtQuals * getFromVoidPointer(void *P)
Definition: Type.h:99
static void * getAsVoidPointer(::clang::ExtQuals *P)
Definition: Type.h:97
static void * getAsVoidPointer(::clang::Type *P)
Definition: Type.h:86
static inline ::clang::Type * getFromVoidPointer(void *P)
Definition: Type.h:88
static void * getAsVoidPointer(clang::QualType P)
Definition: Type.h:1441
static clang::QualType getFromVoidPointer(void *P)
Definition: Type.h:1445
static SimpleType getSimplifiedValue(::clang::QualType Val)
Definition: Type.h:1433