1 //===- CanonicalType.h - C Language Family Type Representation --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the CanQual class template, which provides access to
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_CANONICALTYPE_H
16 #define LLVM_CLANG_AST_CANONICALTYPE_H
18 #include "clang/AST/Type.h"
19 #include "clang/Basic/Diagnostic.h"
20 #include "clang/Basic/SourceLocation.h"
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/FoldingSet.h"
23 #include "llvm/ADT/iterator.h"
24 #include "llvm/Support/Casting.h"
25 #include "llvm/Support/PointerLikeTypeTraits.h"
28 #include <type_traits>
32 template<typename T> class CanProxy;
33 template<typename T> struct CanProxyAdaptor;
38 class ObjCInterfaceDecl;
41 class TemplateTypeParmDecl;
43 //----------------------------------------------------------------------------//
44 // Canonical, qualified type template
45 //----------------------------------------------------------------------------//
47 /// \brief Represents a canonical, potentially-qualified type.
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.
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>.
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().
65 template<typename T = Type>
67 /// \brief The actual, canonical type.
71 /// \brief Constructs a NULL canonical type.
74 /// \brief Converting constructor that permits implicit upcasting of
75 /// canonical type pointers.
77 CanQual(const CanQual<U> &Other,
78 typename std::enable_if<std::is_base_of<T, U>::value, int>::type = 0);
80 /// \brief Retrieve the underlying type pointer, which refers to a
83 /// The underlying pointer must not be nullptr.
84 const T *getTypePtr() const { return cast<T>(Stored.getTypePtr()); }
86 /// \brief 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());
92 /// \brief Implicit conversion to a qualified type.
93 operator QualType() const { return Stored; }
95 /// \brief Implicit conversion to bool.
96 explicit operator bool() const { return !isNull(); }
99 return Stored.isNull();
102 SplitQualType split() const { return Stored.split(); }
104 /// \brief Retrieve a canonical type pointer with a different static type,
105 /// upcasting or downcasting as needed.
107 /// The getAs() function is typically used to try to downcast to a
108 /// more specific (canonical) type in the type system. For example:
111 /// void f(CanQual<Type> T) {
112 /// if (CanQual<PointerType> Ptr = T->getAs<PointerType>()) {
113 /// // look at Ptr's pointee type
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;
123 template<typename U> CanProxy<U> castAs() const;
125 /// \brief Overloaded arrow operator that produces a canonical type
127 CanProxy<T> operator->() const;
129 /// \brief Retrieve all qualifiers.
130 Qualifiers getQualifiers() const { return Stored.getLocalQualifiers(); }
132 /// \brief Retrieve the const/volatile/restrict qualifiers.
133 unsigned getCVRQualifiers() const { return Stored.getLocalCVRQualifiers(); }
135 /// \brief Determines whether this type has any qualifiers
136 bool hasQualifiers() const { return Stored.hasLocalQualifiers(); }
138 bool isConstQualified() const {
139 return Stored.isLocalConstQualified();
142 bool isVolatileQualified() const {
143 return Stored.isLocalVolatileQualified();
146 bool isRestrictQualified() const {
147 return Stored.isLocalRestrictQualified();
150 /// \brief 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();
157 /// \brief Retrieve the unqualified form of this type.
158 CanQual<T> getUnqualifiedType() const;
160 /// \brief Retrieves a version of this type with const applied.
161 /// Note that this does not always yield a canonical type.
162 QualType withConst() const {
163 return Stored.withConst();
166 /// \brief Determines whether this canonical type is more qualified than
167 /// the @p Other canonical type.
168 bool isMoreQualifiedThan(CanQual<T> Other) const {
169 return Stored.isMoreQualifiedThan(Other.Stored);
172 /// \brief Determines whether this canonical type is at least as qualified as
173 /// the @p Other canonical type.
174 bool isAtLeastAsQualifiedAs(CanQual<T> Other) const {
175 return Stored.isAtLeastAsQualifiedAs(Other.Stored);
178 /// \brief If the canonical type is a reference type, returns the type that
179 /// it refers to; otherwise, returns the type itself.
180 CanQual<Type> getNonReferenceType() const;
182 /// \brief Retrieve the internal representation of this canonical type.
183 void *getAsOpaquePtr() const { return Stored.getAsOpaquePtr(); }
185 /// \brief Construct a canonical type from its internal representation.
186 static CanQual<T> getFromOpaquePtr(void *Ptr);
188 /// \brief Builds a canonical type from a QualType.
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
193 static CanQual<T> CreateUnsafe(QualType Other);
195 void dump() const { Stored.dump(); }
197 void Profile(llvm::FoldingSetNodeID &ID) const {
198 ID.AddPointer(getAsOpaquePtr());
202 template<typename T, typename U>
203 inline bool operator==(CanQual<T> x, CanQual<U> y) {
204 return x.getAsOpaquePtr() == y.getAsOpaquePtr();
207 template<typename T, typename U>
208 inline bool operator!=(CanQual<T> x, CanQual<U> y) {
209 return x.getAsOpaquePtr() != y.getAsOpaquePtr();
212 /// \brief Represents a canonical, potentially-qualified type.
213 using CanQualType = CanQual<Type>;
215 inline CanQualType Type::getCanonicalTypeUnqualified() const {
216 return CanQualType::CreateUnsafe(getCanonicalTypeInternal());
219 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
221 DB << static_cast<QualType>(T);
225 //----------------------------------------------------------------------------//
226 // Internal proxy classes used by canonical types
227 //----------------------------------------------------------------------------//
229 #define LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(Accessor) \
230 CanQualType Accessor() const { \
231 return CanQualType::CreateUnsafe(this->getTypePtr()->Accessor()); \
234 #define LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Type, Accessor) \
235 Type Accessor() const { return this->getTypePtr()->Accessor(); }
237 /// \brief Base class of all canonical proxy types, which is responsible for
238 /// storing the underlying canonical type and providing basic conversions.
245 /// \brief Retrieve the pointer to the underlying Type
246 const T *getTypePtr() const { return Stored.getTypePtr(); }
248 /// \brief Implicit conversion to the underlying pointer.
250 /// Also provides the ability to use canonical type proxies in a Boolean
253 /// if (CanQual<PointerType> Ptr = T->getAs<PointerType>()) { ... }
255 operator const T*() const { return this->Stored.getTypePtrOrNull(); }
257 /// \brief Try to convert the given canonical type to a specific structural
259 template<typename U> CanProxy<U> getAs() const {
260 return this->Stored.template getAs<U>();
263 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Type::TypeClass, getTypeClass)
266 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjectType)
267 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIncompleteType)
268 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIncompleteOrObjectType)
269 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVariablyModifiedType)
270 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIntegerType)
271 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isEnumeralType)
272 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isBooleanType)
273 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isCharType)
274 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isWideCharType)
275 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIntegralType)
276 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIntegralOrEnumerationType)
277 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isRealFloatingType)
278 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isComplexType)
279 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAnyComplexType)
280 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isFloatingType)
281 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isRealType)
282 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isArithmeticType)
283 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVoidType)
284 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isDerivedType)
285 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isScalarType)
286 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAggregateType)
287 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAnyPointerType)
288 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVoidPointerType)
289 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isFunctionPointerType)
290 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isMemberFunctionPointerType)
291 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isClassType)
292 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isStructureType)
293 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isInterfaceType)
294 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isStructureOrClassType)
295 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isUnionType)
296 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isComplexIntegerType)
297 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isNullPtrType)
298 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isDependentType)
299 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isOverloadableType)
300 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isArrayType)
301 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasPointerRepresentation)
302 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasObjCPointerRepresentation)
303 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasIntegerRepresentation)
304 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasSignedIntegerRepresentation)
305 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasUnsignedIntegerRepresentation)
306 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasFloatingRepresentation)
307 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isPromotableIntegerType)
308 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isSignedIntegerType)
309 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isUnsignedIntegerType)
310 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isSignedIntegerOrEnumerationType)
311 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isUnsignedIntegerOrEnumerationType)
312 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isConstantSizeType)
313 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isSpecifierType)
314 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(CXXRecordDecl*, getAsCXXRecordDecl)
316 /// \brief Retrieve the proxy-adaptor type.
318 /// This arrow operator is used when CanProxyAdaptor has been specialized
319 /// for the given type T. In that case, we reference members of the
320 /// CanProxyAdaptor specialization. Otherwise, this operator will be hidden
321 /// by the arrow operator in the primary CanProxyAdaptor template.
322 const CanProxyAdaptor<T> *operator->() const {
323 return static_cast<const CanProxyAdaptor<T> *>(this);
327 /// \brief Replacable canonical proxy adaptor class that provides the link
328 /// between a canonical type and the accessors of the type.
330 /// The CanProxyAdaptor is a replaceable class template that is instantiated
331 /// as part of each canonical proxy type. The primary template merely provides
332 /// redirection to the underlying type (T), e.g., @c PointerType. One can
333 /// provide specializations of this class template for each underlying type
334 /// that provide accessors returning canonical types (@c CanQualType) rather
335 /// than the more typical @c QualType, to propagate the notion of "canonical"
336 /// through the system.
338 struct CanProxyAdaptor : CanProxyBase<T> {};
340 /// \brief Canonical proxy type returned when retrieving the members of a
341 /// canonical type or as the result of the @c CanQual<T>::getAs member
344 /// The CanProxy type mainly exists as a proxy through which operator-> will
345 /// look to either map down to a raw T* (e.g., PointerType*) or to a proxy
346 /// type that provides canonical-type access to the fields of the type.
348 class CanProxy : public CanProxyAdaptor<T> {
350 /// \brief Build a NULL proxy.
351 CanProxy() = default;
353 /// \brief Build a proxy to the given canonical type.
354 CanProxy(CanQual<T> Stored) { this->Stored = Stored; }
356 /// \brief Implicit conversion to the stored canonical type.
357 operator CanQual<T>() const { return this->Stored; }
364 /// Implement simplify_type for CanQual<T>, so that we can dyn_cast from
365 /// CanQual<T> to a specific Type class. We're prefer isa/dyn_cast/cast/etc.
366 /// to return smart pointer (proxies?).
368 struct simplify_type< ::clang::CanQual<T>> {
369 using SimpleType = const T *;
371 static SimpleType getSimplifiedValue(::clang::CanQual<T> Val) {
372 return Val.getTypePtr();
376 // Teach SmallPtrSet that CanQual<T> is "basically a pointer".
378 struct PointerLikeTypeTraits<clang::CanQual<T>> {
379 static void *getAsVoidPointer(clang::CanQual<T> P) {
380 return P.getAsOpaquePtr();
383 static clang::CanQual<T> getFromVoidPointer(void *P) {
384 return clang::CanQual<T>::getFromOpaquePtr(P);
387 // qualifier information is encoded in the low bits.
388 enum { NumLowBitsAvailable = 0 };
395 //----------------------------------------------------------------------------//
396 // Canonical proxy adaptors for canonical type nodes.
397 //----------------------------------------------------------------------------//
399 /// \brief Iterator adaptor that turns an iterator over canonical QualTypes
400 /// into an iterator over CanQualTypes.
401 template <typename InputIterator>
402 struct CanTypeIterator
403 : llvm::iterator_adaptor_base<
404 CanTypeIterator<InputIterator>, InputIterator,
405 typename std::iterator_traits<InputIterator>::iterator_category,
407 typename std::iterator_traits<InputIterator>::difference_type,
408 CanProxy<Type>, CanQualType> {
409 CanTypeIterator() = default;
410 explicit CanTypeIterator(InputIterator Iter)
411 : CanTypeIterator::iterator_adaptor_base(std::move(Iter)) {}
413 CanQualType operator*() const { return CanQualType::CreateUnsafe(*this->I); }
414 CanProxy<Type> operator->() const;
418 struct CanProxyAdaptor<ComplexType> : public CanProxyBase<ComplexType> {
419 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getElementType)
423 struct CanProxyAdaptor<PointerType> : public CanProxyBase<PointerType> {
424 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
428 struct CanProxyAdaptor<BlockPointerType>
429 : public CanProxyBase<BlockPointerType> {
430 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
434 struct CanProxyAdaptor<ReferenceType> : public CanProxyBase<ReferenceType> {
435 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
439 struct CanProxyAdaptor<LValueReferenceType>
440 : public CanProxyBase<LValueReferenceType> {
441 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
445 struct CanProxyAdaptor<RValueReferenceType>
446 : public CanProxyBase<RValueReferenceType> {
447 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
451 struct CanProxyAdaptor<MemberPointerType>
452 : public CanProxyBase<MemberPointerType> {
453 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
454 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const Type *, getClass)
457 // CanProxyAdaptors for arrays are intentionally unimplemented because
458 // they are not safe.
459 template<> struct CanProxyAdaptor<ArrayType>;
460 template<> struct CanProxyAdaptor<ConstantArrayType>;
461 template<> struct CanProxyAdaptor<IncompleteArrayType>;
462 template<> struct CanProxyAdaptor<VariableArrayType>;
463 template<> struct CanProxyAdaptor<DependentSizedArrayType>;
466 struct CanProxyAdaptor<DependentSizedExtVectorType>
467 : public CanProxyBase<DependentSizedExtVectorType> {
468 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getElementType)
469 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const Expr *, getSizeExpr)
470 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(SourceLocation, getAttributeLoc)
474 struct CanProxyAdaptor<VectorType> : public CanProxyBase<VectorType> {
475 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getElementType)
476 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumElements)
480 struct CanProxyAdaptor<ExtVectorType> : public CanProxyBase<ExtVectorType> {
481 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getElementType)
482 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumElements)
486 struct CanProxyAdaptor<FunctionType> : public CanProxyBase<FunctionType> {
487 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getReturnType)
488 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(FunctionType::ExtInfo, getExtInfo)
492 struct CanProxyAdaptor<FunctionNoProtoType>
493 : public CanProxyBase<FunctionNoProtoType> {
494 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getReturnType)
495 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(FunctionType::ExtInfo, getExtInfo)
499 struct CanProxyAdaptor<FunctionProtoType>
500 : public CanProxyBase<FunctionProtoType> {
501 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getReturnType)
502 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(FunctionType::ExtInfo, getExtInfo)
503 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumParams)
504 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasExtParameterInfos)
505 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(
506 ArrayRef<FunctionProtoType::ExtParameterInfo>, getExtParameterInfos)
508 CanQualType getParamType(unsigned i) const {
509 return CanQualType::CreateUnsafe(this->getTypePtr()->getParamType(i));
512 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVariadic)
513 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getTypeQuals)
515 using param_type_iterator =
516 CanTypeIterator<FunctionProtoType::param_type_iterator>;
518 param_type_iterator param_type_begin() const {
519 return param_type_iterator(this->getTypePtr()->param_type_begin());
522 param_type_iterator param_type_end() const {
523 return param_type_iterator(this->getTypePtr()->param_type_end());
526 // Note: canonical function types never have exception specifications
530 struct CanProxyAdaptor<TypeOfType> : public CanProxyBase<TypeOfType> {
531 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getUnderlyingType)
535 struct CanProxyAdaptor<DecltypeType> : public CanProxyBase<DecltypeType> {
536 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Expr *, getUnderlyingExpr)
537 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getUnderlyingType)
541 struct CanProxyAdaptor<UnaryTransformType>
542 : public CanProxyBase<UnaryTransformType> {
543 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getBaseType)
544 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getUnderlyingType)
545 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(UnaryTransformType::UTTKind, getUTTKind)
549 struct CanProxyAdaptor<TagType> : public CanProxyBase<TagType> {
550 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(TagDecl *, getDecl)
551 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isBeingDefined)
555 struct CanProxyAdaptor<RecordType> : public CanProxyBase<RecordType> {
556 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(RecordDecl *, getDecl)
557 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isBeingDefined)
558 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasConstFields)
562 struct CanProxyAdaptor<EnumType> : public CanProxyBase<EnumType> {
563 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(EnumDecl *, getDecl)
564 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isBeingDefined)
568 struct CanProxyAdaptor<TemplateTypeParmType>
569 : public CanProxyBase<TemplateTypeParmType> {
570 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getDepth)
571 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getIndex)
572 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isParameterPack)
573 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(TemplateTypeParmDecl *, getDecl)
574 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(IdentifierInfo *, getIdentifier)
578 struct CanProxyAdaptor<ObjCObjectType>
579 : public CanProxyBase<ObjCObjectType> {
580 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getBaseType)
581 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const ObjCInterfaceDecl *,
583 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCUnqualifiedId)
584 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCUnqualifiedClass)
585 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedId)
586 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedClass)
588 using qual_iterator = ObjCObjectPointerType::qual_iterator;
590 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_begin)
591 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_end)
592 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, qual_empty)
593 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumProtocols)
597 struct CanProxyAdaptor<ObjCObjectPointerType>
598 : public CanProxyBase<ObjCObjectPointerType> {
599 LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
600 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const ObjCInterfaceType *,
602 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCIdType)
603 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCClassType)
604 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedIdType)
605 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedClassType)
607 using qual_iterator = ObjCObjectPointerType::qual_iterator;
609 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_begin)
610 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_end)
611 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, qual_empty)
612 LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumProtocols)
615 //----------------------------------------------------------------------------//
616 // Method and function definitions
617 //----------------------------------------------------------------------------//
619 inline CanQual<T> CanQual<T>::getUnqualifiedType() const {
620 return CanQual<T>::CreateUnsafe(Stored.getLocalUnqualifiedType());
624 inline CanQual<Type> CanQual<T>::getNonReferenceType() const {
625 if (CanQual<ReferenceType> RefType = getAs<ReferenceType>())
626 return RefType->getPointeeType();
632 CanQual<T> CanQual<T>::getFromOpaquePtr(void *Ptr) {
634 Result.Stored = QualType::getFromOpaquePtr(Ptr);
635 assert((!Result || Result.Stored.getAsOpaquePtr() == (void*)-1 ||
636 Result.Stored.isCanonical()) && "Type is not canonical!");
641 CanQual<T> CanQual<T>::CreateUnsafe(QualType Other) {
642 assert((Other.isNull() || Other.isCanonical()) && "Type is not canonical!");
643 assert((Other.isNull() || isa<T>(Other.getTypePtr())) &&
644 "Dynamic type does not meet the static type's requires");
646 Result.Stored = Other;
652 CanProxy<U> CanQual<T>::getAs() const {
653 static_assert(!TypeIsArrayType<T>::value,
654 "ArrayType cannot be used with getAs!");
657 return CanProxy<U>();
659 if (isa<U>(Stored.getTypePtr()))
660 return CanQual<U>::CreateUnsafe(Stored);
662 return CanProxy<U>();
667 CanProxy<U> CanQual<T>::castAs() const {
668 static_assert(!TypeIsArrayType<U>::value,
669 "ArrayType cannot be used with castAs!");
671 assert(!Stored.isNull() && isa<U>(Stored.getTypePtr()));
672 return CanQual<U>::CreateUnsafe(Stored);
676 CanProxy<T> CanQual<T>::operator->() const {
677 return CanProxy<T>(*this);
680 template <typename InputIterator>
681 CanProxy<Type> CanTypeIterator<InputIterator>::operator->() const {
682 return CanProxy<Type>(*this);
687 #endif // LLVM_CLANG_AST_CANONICALTYPE_H