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