clang 20.0.0git
CanonicalType.h
Go to the documentation of this file.
1//===- CanonicalType.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// This file defines the CanQual class template, which provides access to
10// canonical types.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_CANONICALTYPE_H
15#define LLVM_CLANG_AST_CANONICALTYPE_H
16
17#include "clang/AST/Type.h"
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/FoldingSet.h"
22#include "llvm/ADT/iterator.h"
23#include "llvm/Support/Casting.h"
24#include "llvm/Support/PointerLikeTypeTraits.h"
25#include <cassert>
26#include <iterator>
27#include <type_traits>
28
29namespace clang {
30
31template<typename T> class CanProxy;
32template<typename T> struct CanProxyAdaptor;
33class ASTContext;
34class CXXRecordDecl;
35class EnumDecl;
36class Expr;
37class IdentifierInfo;
38class ObjCInterfaceDecl;
39class RecordDecl;
40class TagDecl;
41class TemplateTypeParmDecl;
42
43//----------------------------------------------------------------------------//
44// Canonical, qualified type template
45//----------------------------------------------------------------------------//
46
47/// Represents a canonical, potentially-qualified type.
48///
49/// The CanQual template is a lightweight smart pointer that provides access
50/// to the canonical representation of a type, where all typedefs and other
51/// syntactic sugar has been eliminated. A CanQualType may also have various
52/// qualifiers (const, volatile, restrict) attached to it.
53///
54/// The template type parameter @p T is one of the Type classes (PointerType,
55/// BuiltinType, etc.). The type stored within @c CanQual<T> will be of that
56/// type (or some subclass of that type). The typedef @c CanQualType is just
57/// a shorthand for @c CanQual<Type>.
58///
59/// An instance of @c CanQual<T> can be implicitly converted to a
60/// @c CanQual<U> when T is derived from U, which essentially provides an
61/// implicit upcast. For example, @c CanQual<LValueReferenceType> can be
62/// converted to @c CanQual<ReferenceType>. Note that any @c CanQual type can
63/// be implicitly converted to a QualType, but the reverse operation requires
64/// a call to ASTContext::getCanonicalType().
65template<typename T = Type>
66class CanQual {
67 /// The actual, canonical type.
68 QualType Stored;
69
70public:
71 /// Constructs a NULL canonical type.
72 CanQual() = default;
73
74 /// Converting constructor that permits implicit upcasting of
75 /// canonical type pointers.
76 template <typename U>
78 std::enable_if_t<std::is_base_of<T, U>::value, int> = 0);
79
80 /// Retrieve the underlying type pointer, which refers to a
81 /// canonical type.
82 ///
83 /// The underlying pointer must not be nullptr.
84 const T *getTypePtr() const { return cast<T>(Stored.getTypePtr()); }
85
86 /// Retrieve the underlying type pointer, which refers to a
87 /// canonical type, or nullptr.
88 const T *getTypePtrOrNull() const {
89 return cast_or_null<T>(Stored.getTypePtrOrNull());
90 }
91
92 /// Implicit conversion to a qualified type.
93 operator QualType() const { return Stored; }
94
95 /// Implicit conversion to bool.
96 explicit operator bool() const { return !isNull(); }
97
98 bool isNull() const {
99 return Stored.isNull();
100 }
101
102 SplitQualType split() const { return Stored.split(); }
103
104 /// Retrieve a canonical type pointer with a different static type,
105 /// upcasting or downcasting as needed.
106 ///
107 /// The getAs() function is typically used to try to downcast to a
108 /// more specific (canonical) type in the type system. For example:
109 ///
110 /// @code
111 /// void f(CanQual<Type> T) {
112 /// if (CanQual<PointerType> Ptr = T->getAs<PointerType>()) {
113 /// // look at Ptr's pointee type
114 /// }
115 /// }
116 /// @endcode
117 ///
118 /// \returns A proxy pointer to the same type, but with the specified
119 /// static type (@p U). If the dynamic type is not the specified static type
120 /// or a derived class thereof, a NULL canonical type.
121 template<typename U> CanProxy<U> getAs() const;
122
123 template<typename U> CanProxy<U> castAs() const;
124
125 /// Overloaded arrow operator that produces a canonical type
126 /// proxy.
128
129 /// Retrieve all qualifiers.
130 Qualifiers getQualifiers() const { return Stored.getLocalQualifiers(); }
131
132 /// Retrieve the const/volatile/restrict qualifiers.
133 unsigned getCVRQualifiers() const { return Stored.getLocalCVRQualifiers(); }
134
135 /// Determines whether this type has any qualifiers
136 bool hasQualifiers() const { return Stored.hasLocalQualifiers(); }
137
138 bool isConstQualified() const {
139 return Stored.isLocalConstQualified();
140 }
141
142 bool isVolatileQualified() const {
143 return Stored.isLocalVolatileQualified();
144 }
145
146 bool isRestrictQualified() const {
147 return Stored.isLocalRestrictQualified();
148 }
149
150 /// Determines if this canonical type is furthermore
151 /// canonical as a parameter. The parameter-canonicalization
152 /// process decays arrays to pointers and drops top-level qualifiers.
153 bool isCanonicalAsParam() const {
154 return Stored.isCanonicalAsParam();
155 }
156
157 /// Retrieve the unqualified form of this type.
159
160 /// Retrieves a version of this type with const applied.
161 /// Note that this does not always yield a canonical type.
163 return Stored.withConst();
164 }
165
166 /// Determines whether this canonical type is more qualified than
167 /// the @p Other canonical type.
169 return Stored.isMoreQualifiedThan(Other.Stored, Ctx);
170 }
171
172 /// Determines whether this canonical type is at least as qualified as
173 /// the @p Other canonical type.
175 return Stored.isAtLeastAsQualifiedAs(Other.Stored, Ctx);
176 }
177
178 /// If the canonical type is a reference type, returns the type that
179 /// it refers to; otherwise, returns the type itself.
181
182 /// Retrieve the internal representation of this canonical type.
183 void *getAsOpaquePtr() const { return Stored.getAsOpaquePtr(); }
184
185 /// Construct a canonical type from its internal representation.
186 static CanQual<T> getFromOpaquePtr(void *Ptr);
187
188 /// Builds a canonical type from a QualType.
189 ///
190 /// This routine is inherently unsafe, because it requires the user to
191 /// ensure that the given type is a canonical type with the correct
192 // (dynamic) type.
194
195 void dump() const { Stored.dump(); }
196
197 void Profile(llvm::FoldingSetNodeID &ID) const {
198 ID.AddPointer(getAsOpaquePtr());
199 }
200};
201
202template<typename T, typename U>
204 return x.getAsOpaquePtr() == y.getAsOpaquePtr();
205}
206
207template<typename T, typename U>
209 return x.getAsOpaquePtr() != y.getAsOpaquePtr();
210}
211
212/// Represents a canonical, potentially-qualified type.
214
217}
218
220 CanQualType T) {
221 DB << static_cast<QualType>(T);
222 return DB;
223}
224
225//----------------------------------------------------------------------------//
226// Internal proxy classes used by canonical types
227//----------------------------------------------------------------------------//
228
229#define LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(Accessor) \
230CanQualType Accessor() const { \
231return CanQualType::CreateUnsafe(this->getTypePtr()->Accessor()); \
232}
233
234#define LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Type, Accessor) \
235Type Accessor() const { return this->getTypePtr()->Accessor(); }
236
237/// Base class of all canonical proxy types, which is responsible for
238/// storing the underlying canonical type and providing basic conversions.
239template<typename T>
241protected:
243
244public:
245 /// Retrieve the pointer to the underlying Type
246 const T *getTypePtr() const { return Stored.getTypePtr(); }
247
248 /// Implicit conversion to the underlying pointer.
249 ///
250 /// Also provides the ability to use canonical type proxies in a Boolean
251 // context,e.g.,
252 /// @code
253 /// if (CanQual<PointerType> Ptr = T->getAs<PointerType>()) { ... }
254 /// @endcode
255 operator const T*() const { return this->Stored.getTypePtrOrNull(); }
256
257 /// Try to convert the given canonical type to a specific structural
258 /// type.
259 template<typename U> CanProxy<U> getAs() const {
260 return this->Stored.template getAs<U>();
261 }
262
264
265 // Type predicates
266 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjectType)
267 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIncompleteType)
268 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isSizelessType)
269 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isSizelessBuiltinType)
270 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIncompleteOrObjectType)
271 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVariablyModifiedType)
272 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIntegerType)
273 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isEnumeralType)
276 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isWideCharType)
277 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIntegralType)
278 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIntegralOrEnumerationType)
279 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isRealFloatingType)
280 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isComplexType)
281 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAnyComplexType)
282 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isFloatingType)
284 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isArithmeticType)
286 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isDerivedType)
287 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isScalarType)
288 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAggregateType)
289 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAnyPointerType)
290 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVoidPointerType)
291 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isFunctionPointerType)
292 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isMemberFunctionPointerType)
293 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isClassType)
294 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isStructureType)
295 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isInterfaceType)
296 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isStructureOrClassType)
297 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isUnionType)
298 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isComplexIntegerType)
299 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isNullPtrType)
300 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isDependentType)
301 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isOverloadableType)
302 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isArrayType)
303 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isConstantArrayType)
304 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasPointerRepresentation)
305 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasObjCPointerRepresentation)
306 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasIntegerRepresentation)
307 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasSignedIntegerRepresentation)
308 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasUnsignedIntegerRepresentation)
309 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasFloatingRepresentation)
310 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isSignedIntegerType)
311 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isUnsignedIntegerType)
312 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isSignedIntegerOrEnumerationType)
313 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isUnsignedIntegerOrEnumerationType)
314 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isConstantSizeType)
315 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isSpecifierType)
317
318 /// Retrieve the proxy-adaptor type.
319 ///
320 /// This arrow operator is used when CanProxyAdaptor has been specialized
321 /// for the given type T. In that case, we reference members of the
322 /// CanProxyAdaptor specialization. Otherwise, this operator will be hidden
323 /// by the arrow operator in the primary CanProxyAdaptor template.
324 const CanProxyAdaptor<T> *operator->() const {
325 return static_cast<const CanProxyAdaptor<T> *>(this);
326 }
327};
328
329/// Replaceable canonical proxy adaptor class that provides the link
330/// between a canonical type and the accessors of the type.
331///
332/// The CanProxyAdaptor is a replaceable class template that is instantiated
333/// as part of each canonical proxy type. The primary template merely provides
334/// redirection to the underlying type (T), e.g., @c PointerType. One can
335/// provide specializations of this class template for each underlying type
336/// that provide accessors returning canonical types (@c CanQualType) rather
337/// than the more typical @c QualType, to propagate the notion of "canonical"
338/// through the system.
339template<typename T>
341
342/// Canonical proxy type returned when retrieving the members of a
343/// canonical type or as the result of the @c CanQual<T>::getAs member
344/// function.
345///
346/// The CanProxy type mainly exists as a proxy through which operator-> will
347/// look to either map down to a raw T* (e.g., PointerType*) or to a proxy
348/// type that provides canonical-type access to the fields of the type.
349template<typename T>
350class CanProxy : public CanProxyAdaptor<T> {
351public:
352 /// Build a NULL proxy.
353 CanProxy() = default;
354
355 /// Build a proxy to the given canonical type.
356 CanProxy(CanQual<T> Stored) { this->Stored = Stored; }
357
358 /// Implicit conversion to the stored canonical type.
359 operator CanQual<T>() const { return this->Stored; }
360};
361
362} // namespace clang
363
364namespace llvm {
365
366/// Implement simplify_type for CanQual<T>, so that we can dyn_cast from
367/// CanQual<T> to a specific Type class. We're prefer isa/dyn_cast/cast/etc.
368/// to return smart pointer (proxies?).
369template<typename T>
370struct simplify_type< ::clang::CanQual<T>> {
371 using SimpleType = const T *;
372
374 return Val.getTypePtr();
375 }
376};
377
378// Teach SmallPtrSet that CanQual<T> is "basically a pointer".
379template<typename T>
380struct PointerLikeTypeTraits<clang::CanQual<T>> {
382 return P.getAsOpaquePtr();
383 }
384
387 }
388
389 // qualifier information is encoded in the low bits.
390 static constexpr int NumLowBitsAvailable = 0;
391};
392
393} // namespace llvm
394
395namespace clang {
396
397//----------------------------------------------------------------------------//
398// Canonical proxy adaptors for canonical type nodes.
399//----------------------------------------------------------------------------//
400
401/// Iterator adaptor that turns an iterator over canonical QualTypes
402/// into an iterator over CanQualTypes.
403template <typename InputIterator>
405 : llvm::iterator_adaptor_base<
406 CanTypeIterator<InputIterator>, InputIterator,
407 typename std::iterator_traits<InputIterator>::iterator_category,
408 CanQualType,
409 typename std::iterator_traits<InputIterator>::difference_type,
410 CanProxy<Type>, CanQualType> {
411 CanTypeIterator() = default;
412 explicit CanTypeIterator(InputIterator Iter)
413 : CanTypeIterator::iterator_adaptor_base(std::move(Iter)) {}
414
415 CanQualType operator*() const { return CanQualType::CreateUnsafe(*this->I); }
417};
418
419template<>
420struct CanProxyAdaptor<ComplexType> : public CanProxyBase<ComplexType> {
422};
423
424template<>
425struct CanProxyAdaptor<PointerType> : public CanProxyBase<PointerType> {
427};
428
429template<>
431 : public CanProxyBase<BlockPointerType> {
433};
434
435template<>
436struct CanProxyAdaptor<ReferenceType> : public CanProxyBase<ReferenceType> {
438};
439
440template<>
442 : public CanProxyBase<LValueReferenceType> {
444};
445
446template<>
448 : public CanProxyBase<RValueReferenceType> {
450};
451
452template<>
454 : public CanProxyBase<MemberPointerType> {
457};
458
459// CanProxyAdaptors for arrays are intentionally unimplemented because
460// they are not safe.
461template<> struct CanProxyAdaptor<ArrayType>;
462template<> struct CanProxyAdaptor<ConstantArrayType>;
463template<> struct CanProxyAdaptor<IncompleteArrayType>;
464template<> struct CanProxyAdaptor<VariableArrayType>;
466
467template<>
469 : public CanProxyBase<DependentSizedExtVectorType> {
471 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const Expr *, getSizeExpr)
473};
474
475template<>
476struct CanProxyAdaptor<VectorType> : public CanProxyBase<VectorType> {
478 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumElements)
479};
480
481template<>
482struct CanProxyAdaptor<ExtVectorType> : public CanProxyBase<ExtVectorType> {
484 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumElements)
485};
486
487template<>
488struct CanProxyAdaptor<FunctionType> : public CanProxyBase<FunctionType> {
491};
492
493template<>
495 : public CanProxyBase<FunctionNoProtoType> {
498};
499
500template<>
502 : public CanProxyBase<FunctionProtoType> {
505 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumParams)
506 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasExtParameterInfos)
508 ArrayRef<FunctionProtoType::ExtParameterInfo>, getExtParameterInfos)
509
510 CanQualType getParamType(unsigned i) const {
512 }
513
516
519
520 param_type_iterator param_type_begin() const {
521 return param_type_iterator(this->getTypePtr()->param_type_begin());
522 }
523
525 return param_type_iterator(this->getTypePtr()->param_type_end());
526 }
527
528 // Note: canonical function types never have exception specifications
529};
530
531template<>
532struct CanProxyAdaptor<TypeOfType> : public CanProxyBase<TypeOfType> {
533 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getUnmodifiedType)
534};
535
536template<>
537struct CanProxyAdaptor<DecltypeType> : public CanProxyBase<DecltypeType> {
538 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Expr *, getUnderlyingExpr)
540};
541
542template <>
544 : public CanProxyBase<UnaryTransformType> {
548};
549
550template<>
551struct CanProxyAdaptor<TagType> : public CanProxyBase<TagType> {
553 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isBeingDefined)
554};
555
556template<>
557struct CanProxyAdaptor<RecordType> : public CanProxyBase<RecordType> {
559 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isBeingDefined)
560 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasConstFields)
561};
562
563template<>
564struct CanProxyAdaptor<EnumType> : public CanProxyBase<EnumType> {
566 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isBeingDefined)
567};
568
569template<>
571 : public CanProxyBase<TemplateTypeParmType> {
572 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getDepth)
577};
578
579template<>
581 : public CanProxyBase<ObjCObjectType> {
584 getInterface)
585 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCUnqualifiedId)
586 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCUnqualifiedClass)
587 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedId)
588 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedClass)
589
590 using qual_iterator = ObjCObjectPointerType::qual_iterator;
591
592 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_begin)
593 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_end)
595 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumProtocols)
596};
597
598template<>
603 getInterfaceType)
604 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCIdType)
605 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCClassType)
606 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedIdType)
607 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedClassType)
608
609 using qual_iterator = ObjCObjectPointerType::qual_iterator;
610
611 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_begin)
612 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_end)
614 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumProtocols)
615};
616
617//----------------------------------------------------------------------------//
618// Method and function definitions
619//----------------------------------------------------------------------------//
620template<typename T>
621inline CanQual<T> CanQual<T>::getUnqualifiedType() const {
622 return CanQual<T>::CreateUnsafe(Stored.getLocalUnqualifiedType());
623}
624
625template<typename T>
627 if (CanQual<ReferenceType> RefType = getAs<ReferenceType>())
628 return RefType->getPointeeType();
629 else
630 return *this;
631}
632
633template<typename T>
637 assert((!Result || Result.Stored.getAsOpaquePtr() == (void*)-1 ||
638 Result.Stored.isCanonical()) && "Type is not canonical!");
639 return Result;
640}
641
642template<typename T>
644 assert((Other.isNull() || Other.isCanonical()) && "Type is not canonical!");
645 assert((Other.isNull() || isa<T>(Other.getTypePtr())) &&
646 "Dynamic type does not meet the static type's requires");
648 Result.Stored = Other;
649 return Result;
650}
651
652template<typename T>
653template<typename U>
655 static_assert(!TypeIsArrayType<T>::value,
656 "ArrayType cannot be used with getAs!");
657
658 if (Stored.isNull())
659 return CanProxy<U>();
660
661 if (isa<U>(Stored.getTypePtr()))
663
664 return CanProxy<U>();
665}
666
667template<typename T>
668template<typename U>
670 static_assert(!TypeIsArrayType<U>::value,
671 "ArrayType cannot be used with castAs!");
672
673 assert(!Stored.isNull() && isa<U>(Stored.getTypePtr()));
675}
676
677template<typename T>
679 return CanProxy<T>(*this);
680}
681
682template <typename InputIterator>
684 return CanProxy<Type>(*this);
685}
686
687} // namespace clang
688
689#endif // LLVM_CLANG_AST_CANONICALTYPE_H
StringRef P
static char ID
Definition: Arena.cpp:183
Defines the Diagnostic-related interfaces.
static bool isBooleanType(QualType Ty)
static std::optional< NonLoc > getIndex(ProgramStateRef State, const ElementRegion *ER, CharKind CK)
#define LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(Accessor)
#define LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Type, Accessor)
unsigned Iter
Definition: HTMLLogger.cpp:153
static StringRef getIdentifier(const Token &Tok)
static QualType getUnderlyingType(const SubRegion *R)
static QualType getParamType(Sema &SemaRef, ArrayRef< ResultCandidate > Candidates, unsigned N)
Get the type of the Nth parameter from a given set of overload candidates.
static bool isParameterPack(Expr *PackExpression)
Defines the clang::SourceLocation class and associated facilities.
static QualType getPointeeType(const MemRegion *R)
C Language Family Type Representation.
#define bool
Definition: amdgpuintrin.h:20
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3577
Pointer to a block type.
Definition: Type.h:3408
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Base class of all canonical proxy types, which is responsible for storing the underlying canonical ty...
CanProxy< U > getAs() const
Try to convert the given canonical type to a specific structural type.
const T * getTypePtr() const
Retrieve the pointer to the underlying Type.
CanQual< T > Stored
Canonical proxy type returned when retrieving the members of a canonical type or as the result of the...
CanProxy(CanQual< T > Stored)
Build a proxy to the given canonical type.
CanProxy()=default
Build a NULL proxy.
Represents a canonical, potentially-qualified type.
Definition: CanonicalType.h:66
void * getAsOpaquePtr() const
Retrieve the internal representation of this canonical type.
CanQual< Type > getNonReferenceType() const
If the canonical type is a reference type, returns the type that it refers to; otherwise,...
CanQual()=default
Constructs a NULL canonical type.
const T * getTypePtrOrNull() const
Retrieve the underlying type pointer, which refers to a canonical type, or nullptr.
Definition: CanonicalType.h:88
bool isMoreQualifiedThan(CanQual< T > Other, const ASTContext &Ctx) const
Determines whether this canonical type is more qualified than the Other canonical type.
bool isRestrictQualified() const
unsigned getCVRQualifiers() const
Retrieve the const/volatile/restrict qualifiers.
CanProxy< T > operator->() const
Overloaded arrow operator that produces a canonical type proxy.
SplitQualType split() const
bool hasQualifiers() const
Determines whether this type has any qualifiers.
bool isAtLeastAsQualifiedAs(CanQual< T > Other, const ASTContext &Ctx) const
Determines whether this canonical type is at least as qualified as the Other canonical type.
static CanQual< T > CreateUnsafe(QualType Other)
Builds a canonical type from a QualType.
QualType withConst() const
Retrieves a version of this type with const applied.
CanQual(const CanQual< U > &Other, std::enable_if_t< std::is_base_of< T, U >::value, int >=0)
Converting constructor that permits implicit upcasting of canonical type pointers.
CanProxy< U > castAs() const
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
void dump() const
bool isConstQualified() const
bool isNull() const
Definition: CanonicalType.h:98
bool isCanonicalAsParam() const
Determines if this canonical type is furthermore canonical as a parameter.
Qualifiers getQualifiers() const
Retrieve all qualifiers.
void Profile(llvm::FoldingSetNodeID &ID) const
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed.
static CanQual< T > getFromOpaquePtr(void *Ptr)
Construct a canonical type from its internal representation.
bool isVolatileQualified() const
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
Definition: CanonicalType.h:84
Complex values, per C99 6.2.5p11.
Definition: Type.h:3145
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3615
Represents the type decltype(expr) (C++11).
Definition: Type.h:5874
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3862
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3960
Represents an enum.
Definition: Decl.h:3847
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:6098
This represents one expression.
Definition: Expr.h:110
ExtVectorType - Extended vector type.
Definition: Type.h:4126
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4681
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5102
A class which abstracts out some details necessary for making a call.
Definition: Type.h:4432
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:4321
One of these records is kept for each identifier that is lexed.
Represents a C array with an unspecified size.
Definition: Type.h:3764
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3483
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3519
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:7524
Represents a pointer to an Objective C object.
Definition: Type.h:7580
Represents a class type in Objective C.
Definition: Type.h:7326
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3198
A (possibly-)qualified type.
Definition: Type.h:929
bool isLocalConstQualified() const
Determine whether this particular QualType instance has the "const" qualifier set,...
Definition: Type.h:1006
bool isLocalRestrictQualified() const
Determine whether this particular QualType instance has the "restrict" qualifier set,...
Definition: Type.h:1036
QualType withConst() const
Definition: Type.h:1154
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
Definition: Type.h:1056
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:996
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7931
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:978
void dump(const char *s) const
Definition: ASTDumper.cpp:177
unsigned getLocalCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers local to this particular QualType instan...
Definition: Type.h:1081
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:7952
void * getAsOpaquePtr() const
Definition: Type.h:976
bool isMoreQualifiedThan(QualType Other, const ASTContext &Ctx) const
Determine whether this type is more qualified than the other given type, requiring exact equality for...
Definition: Type.h:8103
bool isCanonicalAsParam() const
Definition: Type.h:7992
bool isLocalVolatileQualified() const
Determine whether this particular QualType instance has the "volatile" qualifier set,...
Definition: Type.h:1046
const Type * getTypePtrOrNull() const
Definition: Type.h:7935
bool isAtLeastAsQualifiedAs(QualType Other, const ASTContext &Ctx) const
Determine whether this type is at least as qualified as the other given type, requiring exact equalit...
Definition: Type.h:8114
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:7963
The collection of all-type qualifiers we support.
Definition: Type.h:324
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3501
Represents a struct/union/class.
Definition: Decl.h:4148
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:6072
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3439
Encodes a location in the source.
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
Definition: Diagnostic.h:1102
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3564
Declaration of a template type parameter.
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:5847
The base class of the type hierarchy.
Definition: Type.h:1828
CanQualType getCanonicalTypeUnqualified() const
QualType getCanonicalTypeInternal() const
Definition: Type.h:2989
A unary type transform, which is a type constructed from another.
Definition: Type.h:5989
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3808
Represents a GCC generic vector type.
Definition: Type.h:4034
The JSON file list parser is used to communicate input to InstallAPI.
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
Definition: CallGraph.h:204
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
@ Result
The result type of a method or function.
bool operator!=(CanQual< T > x, CanQual< U > y)
std::integral_constant< bool, std::is_same< T, ArrayType >::value||std::is_base_of< ArrayType, T >::value > TypeIsArrayType
Definition: Type.h:8728
const FunctionProtoType * T
@ Other
Other implicit parameter.
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
param_type_iterator param_type_end() const
Replaceable canonical proxy adaptor class that provides the link between a canonical type and the acc...
Iterator adaptor that turns an iterator over canonical QualTypes into an iterator over CanQualTypes.
CanQualType operator*() const
CanProxy< Type > operator->() const
CanTypeIterator(InputIterator Iter)
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:862
static clang::CanQual< T > getFromVoidPointer(void *P)
static void * getAsVoidPointer(clang::CanQual< T > P)
static SimpleType getSimplifiedValue(::clang::CanQual< T > Val)