clang  6.0.0svn
CanonicalType.h
Go to the documentation of this file.
1 //===-- CanonicalType.h - C Language Family Type Representation -*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the CanQual class template, which provides access to
11 // canonical types.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_AST_CANONICALTYPE_H
16 #define LLVM_CLANG_AST_CANONICALTYPE_H
17 
18 #include "clang/AST/Type.h"
19 #include "llvm/ADT/iterator.h"
20 #include "llvm/Support/Casting.h"
21 
22 namespace clang {
23 
24 template<typename T> class CanProxy;
25 template<typename T> struct CanProxyAdaptor;
26 
27 //----------------------------------------------------------------------------//
28 // Canonical, qualified type template
29 //----------------------------------------------------------------------------//
30 
31 /// \brief Represents a canonical, potentially-qualified type.
32 ///
33 /// The CanQual template is a lightweight smart pointer that provides access
34 /// to the canonical representation of a type, where all typedefs and other
35 /// syntactic sugar has been eliminated. A CanQualType may also have various
36 /// qualifiers (const, volatile, restrict) attached to it.
37 ///
38 /// The template type parameter @p T is one of the Type classes (PointerType,
39 /// BuiltinType, etc.). The type stored within @c CanQual<T> will be of that
40 /// type (or some subclass of that type). The typedef @c CanQualType is just
41 /// a shorthand for @c CanQual<Type>.
42 ///
43 /// An instance of @c CanQual<T> can be implicitly converted to a
44 /// @c CanQual<U> when T is derived from U, which essentially provides an
45 /// implicit upcast. For example, @c CanQual<LValueReferenceType> can be
46 /// converted to @c CanQual<ReferenceType>. Note that any @c CanQual type can
47 /// be implicitly converted to a QualType, but the reverse operation requires
48 /// a call to ASTContext::getCanonicalType().
49 ///
50 ///
51 template<typename T = Type>
52 class CanQual {
53  /// \brief The actual, canonical type.
54  QualType Stored;
55 
56 public:
57  /// \brief Constructs a NULL canonical type.
58  CanQual() : Stored() { }
59 
60  /// \brief Converting constructor that permits implicit upcasting of
61  /// canonical type pointers.
62  template <typename U>
63  CanQual(const CanQual<U> &Other,
64  typename std::enable_if<std::is_base_of<T, U>::value, int>::type = 0);
65 
66  /// \brief Retrieve the underlying type pointer, which refers to a
67  /// canonical type.
68  ///
69  /// The underlying pointer must not be NULL.
70  const T *getTypePtr() const { return cast<T>(Stored.getTypePtr()); }
71 
72  /// \brief Retrieve the underlying type pointer, which refers to a
73  /// canonical type, or NULL.
74  ///
75  const T *getTypePtrOrNull() const {
76  return cast_or_null<T>(Stored.getTypePtrOrNull());
77  }
78 
79  /// \brief Implicit conversion to a qualified type.
80  operator QualType() const { return Stored; }
81 
82  /// \brief Implicit conversion to bool.
83  explicit operator bool() const { return !isNull(); }
84 
85  bool isNull() const {
86  return Stored.isNull();
87  }
88 
89  SplitQualType split() const { return Stored.split(); }
90 
91  /// \brief Retrieve a canonical type pointer with a different static type,
92  /// upcasting or downcasting as needed.
93  ///
94  /// The getAs() function is typically used to try to downcast to a
95  /// more specific (canonical) type in the type system. For example:
96  ///
97  /// @code
98  /// void f(CanQual<Type> T) {
99  /// if (CanQual<PointerType> Ptr = T->getAs<PointerType>()) {
100  /// // look at Ptr's pointee type
101  /// }
102  /// }
103  /// @endcode
104  ///
105  /// \returns A proxy pointer to the same type, but with the specified
106  /// static type (@p U). If the dynamic type is not the specified static type
107  /// or a derived class thereof, a NULL canonical type.
108  template<typename U> CanProxy<U> getAs() const;
109 
110  template<typename U> CanProxy<U> castAs() const;
111 
112  /// \brief Overloaded arrow operator that produces a canonical type
113  /// proxy.
114  CanProxy<T> operator->() const;
115 
116  /// \brief Retrieve all qualifiers.
117  Qualifiers getQualifiers() const { return Stored.getLocalQualifiers(); }
118 
119  /// \brief Retrieve the const/volatile/restrict qualifiers.
120  unsigned getCVRQualifiers() const { return Stored.getLocalCVRQualifiers(); }
121 
122  /// \brief Determines whether this type has any qualifiers
123  bool hasQualifiers() const { return Stored.hasLocalQualifiers(); }
124 
125  bool isConstQualified() const {
126  return Stored.isLocalConstQualified();
127  }
128  bool isVolatileQualified() const {
129  return Stored.isLocalVolatileQualified();
130  }
131  bool isRestrictQualified() const {
132  return Stored.isLocalRestrictQualified();
133  }
134 
135  /// \brief Determines if this canonical type is furthermore
136  /// canonical as a parameter. The parameter-canonicalization
137  /// process decays arrays to pointers and drops top-level qualifiers.
138  bool isCanonicalAsParam() const {
139  return Stored.isCanonicalAsParam();
140  }
141 
142  /// \brief Retrieve the unqualified form of this type.
144 
145  /// \brief Retrieves a version of this type with const applied.
146  /// Note that this does not always yield a canonical type.
147  QualType withConst() const {
148  return Stored.withConst();
149  }
150 
151  /// \brief Determines whether this canonical type is more qualified than
152  /// the @p Other canonical type.
153  bool isMoreQualifiedThan(CanQual<T> Other) const {
154  return Stored.isMoreQualifiedThan(Other.Stored);
155  }
156 
157  /// \brief Determines whether this canonical type is at least as qualified as
158  /// the @p Other canonical type.
159  bool isAtLeastAsQualifiedAs(CanQual<T> Other) const {
160  return Stored.isAtLeastAsQualifiedAs(Other.Stored);
161  }
162 
163  /// \brief If the canonical type is a reference type, returns the type that
164  /// it refers to; otherwise, returns the type itself.
166 
167  /// \brief Retrieve the internal representation of this canonical type.
168  void *getAsOpaquePtr() const { return Stored.getAsOpaquePtr(); }
169 
170  /// \brief Construct a canonical type from its internal representation.
171  static CanQual<T> getFromOpaquePtr(void *Ptr);
172 
173  /// \brief Builds a canonical type from a QualType.
174  ///
175  /// This routine is inherently unsafe, because it requires the user to
176  /// ensure that the given type is a canonical type with the correct
177  // (dynamic) type.
178  static CanQual<T> CreateUnsafe(QualType Other);
179 
180  void dump() const { Stored.dump(); }
181 
182  void Profile(llvm::FoldingSetNodeID &ID) const {
183  ID.AddPointer(getAsOpaquePtr());
184  }
185 };
186 
187 template<typename T, typename U>
188 inline bool operator==(CanQual<T> x, CanQual<U> y) {
189  return x.getAsOpaquePtr() == y.getAsOpaquePtr();
190 }
191 
192 template<typename T, typename U>
193 inline bool operator!=(CanQual<T> x, CanQual<U> y) {
194  return x.getAsOpaquePtr() != y.getAsOpaquePtr();
195 }
196 
197 /// \brief Represents a canonical, potentially-qualified type.
199 
200 inline CanQualType Type::getCanonicalTypeUnqualified() const {
201  return CanQualType::CreateUnsafe(getCanonicalTypeInternal());
202 }
203 
205  CanQualType T) {
206  DB << static_cast<QualType>(T);
207  return DB;
208 }
209 
210 //----------------------------------------------------------------------------//
211 // Internal proxy classes used by canonical types
212 //----------------------------------------------------------------------------//
213 
214 #define LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(Accessor) \
215 CanQualType Accessor() const { \
216 return CanQualType::CreateUnsafe(this->getTypePtr()->Accessor()); \
217 }
218 
219 #define LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Type, Accessor) \
220 Type Accessor() const { return this->getTypePtr()->Accessor(); }
221 
222 /// \brief Base class of all canonical proxy types, which is responsible for
223 /// storing the underlying canonical type and providing basic conversions.
224 template<typename T>
226 protected:
228 
229 public:
230  /// \brief Retrieve the pointer to the underlying Type
231  const T *getTypePtr() const { return Stored.getTypePtr(); }
232 
233  /// \brief Implicit conversion to the underlying pointer.
234  ///
235  /// Also provides the ability to use canonical type proxies in a Boolean
236  // context,e.g.,
237  /// @code
238  /// if (CanQual<PointerType> Ptr = T->getAs<PointerType>()) { ... }
239  /// @endcode
240  operator const T*() const { return this->Stored.getTypePtrOrNull(); }
241 
242  /// \brief Try to convert the given canonical type to a specific structural
243  /// type.
244  template<typename U> CanProxy<U> getAs() const {
245  return this->Stored.template getAs<U>();
246  }
247 
249 
250  // Type predicates
251  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjectType)
252  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIncompleteType)
253  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIncompleteOrObjectType)
254  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVariablyModifiedType)
255  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIntegerType)
256  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isEnumeralType)
259  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isWideCharType)
260  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIntegralType)
261  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIntegralOrEnumerationType)
262  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isRealFloatingType)
263  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isComplexType)
264  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAnyComplexType)
265  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isFloatingType)
266  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isRealType)
267  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isArithmeticType)
268  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVoidType)
269  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isDerivedType)
270  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isScalarType)
271  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAggregateType)
272  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAnyPointerType)
273  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVoidPointerType)
274  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isFunctionPointerType)
275  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isMemberFunctionPointerType)
276  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isClassType)
277  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isStructureType)
278  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isInterfaceType)
279  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isStructureOrClassType)
280  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isUnionType)
281  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isComplexIntegerType)
282  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isNullPtrType)
283  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isDependentType)
284  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isOverloadableType)
285  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isArrayType)
286  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasPointerRepresentation)
287  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasObjCPointerRepresentation)
288  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasIntegerRepresentation)
289  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasSignedIntegerRepresentation)
290  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasUnsignedIntegerRepresentation)
291  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasFloatingRepresentation)
292  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isPromotableIntegerType)
293  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isSignedIntegerType)
294  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isUnsignedIntegerType)
295  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isSignedIntegerOrEnumerationType)
296  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isUnsignedIntegerOrEnumerationType)
297  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isConstantSizeType)
298  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isSpecifierType)
300 
301  /// \brief Retrieve the proxy-adaptor type.
302  ///
303  /// This arrow operator is used when CanProxyAdaptor has been specialized
304  /// for the given type T. In that case, we reference members of the
305  /// CanProxyAdaptor specialization. Otherwise, this operator will be hidden
306  /// by the arrow operator in the primary CanProxyAdaptor template.
307  const CanProxyAdaptor<T> *operator->() const {
308  return static_cast<const CanProxyAdaptor<T> *>(this);
309  }
310 };
311 
312 /// \brief Replacable canonical proxy adaptor class that provides the link
313 /// between a canonical type and the accessors of the type.
314 ///
315 /// The CanProxyAdaptor is a replaceable class template that is instantiated
316 /// as part of each canonical proxy type. The primary template merely provides
317 /// redirection to the underlying type (T), e.g., @c PointerType. One can
318 /// provide specializations of this class template for each underlying type
319 /// that provide accessors returning canonical types (@c CanQualType) rather
320 /// than the more typical @c QualType, to propagate the notion of "canonical"
321 /// through the system.
322 template<typename T>
323 struct CanProxyAdaptor : CanProxyBase<T> { };
324 
325 /// \brief Canonical proxy type returned when retrieving the members of a
326 /// canonical type or as the result of the @c CanQual<T>::getAs member
327 /// function.
328 ///
329 /// The CanProxy type mainly exists as a proxy through which operator-> will
330 /// look to either map down to a raw T* (e.g., PointerType*) or to a proxy
331 /// type that provides canonical-type access to the fields of the type.
332 template<typename T>
333 class CanProxy : public CanProxyAdaptor<T> {
334 public:
335  /// \brief Build a NULL proxy.
336  CanProxy() { }
337 
338  /// \brief Build a proxy to the given canonical type.
339  CanProxy(CanQual<T> Stored) { this->Stored = Stored; }
340 
341  /// \brief Implicit conversion to the stored canonical type.
342  operator CanQual<T>() const { return this->Stored; }
343 };
344 
345 } // end namespace clang
346 
347 namespace llvm {
348 
349 /// Implement simplify_type for CanQual<T>, so that we can dyn_cast from
350 /// CanQual<T> to a specific Type class. We're prefer isa/dyn_cast/cast/etc.
351 /// to return smart pointer (proxies?).
352 template<typename T>
353 struct simplify_type< ::clang::CanQual<T> > {
354  typedef const T *SimpleType;
355  static SimpleType getSimplifiedValue(::clang::CanQual<T> Val) {
356  return Val.getTypePtr();
357  }
358 };
359 
360 // Teach SmallPtrSet that CanQual<T> is "basically a pointer".
361 template<typename T>
363  static inline void *getAsVoidPointer(clang::CanQual<T> P) {
364  return P.getAsOpaquePtr();
365  }
366  static inline clang::CanQual<T> getFromVoidPointer(void *P) {
368  }
369  // qualifier information is encoded in the low bits.
370  enum { NumLowBitsAvailable = 0 };
371 };
372 
373 } // end namespace llvm
374 
375 namespace clang {
376 
377 //----------------------------------------------------------------------------//
378 // Canonical proxy adaptors for canonical type nodes.
379 //----------------------------------------------------------------------------//
380 
381 /// \brief Iterator adaptor that turns an iterator over canonical QualTypes
382 /// into an iterator over CanQualTypes.
383 template <typename InputIterator>
385  : llvm::iterator_adaptor_base<
386  CanTypeIterator<InputIterator>, InputIterator,
387  typename std::iterator_traits<InputIterator>::iterator_category,
388  CanQualType,
389  typename std::iterator_traits<InputIterator>::difference_type,
390  CanProxy<Type>, CanQualType> {
392  explicit CanTypeIterator(InputIterator Iter)
393  : CanTypeIterator::iterator_adaptor_base(std::move(Iter)) {}
394 
395  CanQualType operator*() const { return CanQualType::CreateUnsafe(*this->I); }
396  CanProxy<Type> operator->() const;
397 };
398 
399 template<>
400 struct CanProxyAdaptor<ComplexType> : public CanProxyBase<ComplexType> {
401  LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getElementType)
402 };
403 
404 template<>
405 struct CanProxyAdaptor<PointerType> : public CanProxyBase<PointerType> {
406  LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
407 };
408 
409 template<>
411  : public CanProxyBase<BlockPointerType> {
412  LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
413 };
414 
415 template<>
416 struct CanProxyAdaptor<ReferenceType> : public CanProxyBase<ReferenceType> {
417  LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
418 };
419 
420 template<>
422  : public CanProxyBase<LValueReferenceType> {
423  LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
424 };
425 
426 template<>
428  : public CanProxyBase<RValueReferenceType> {
429  LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
430 };
431 
432 template<>
434  : public CanProxyBase<MemberPointerType> {
435  LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
436  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const Type *, getClass)
437 };
438 
439 // CanProxyAdaptors for arrays are intentionally unimplemented because
440 // they are not safe.
441 template<> struct CanProxyAdaptor<ArrayType>;
442 template<> struct CanProxyAdaptor<ConstantArrayType>;
443 template<> struct CanProxyAdaptor<IncompleteArrayType>;
444 template<> struct CanProxyAdaptor<VariableArrayType>;
445 template<> struct CanProxyAdaptor<DependentSizedArrayType>;
446 
447 template<>
449  : public CanProxyBase<DependentSizedExtVectorType> {
450  LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getElementType)
451  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const Expr *, getSizeExpr)
453 };
454 
455 template<>
456 struct CanProxyAdaptor<VectorType> : public CanProxyBase<VectorType> {
457  LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getElementType)
458  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumElements)
459 };
460 
461 template<>
462 struct CanProxyAdaptor<ExtVectorType> : public CanProxyBase<ExtVectorType> {
463  LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getElementType)
464  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumElements)
465 };
466 
467 template<>
468 struct CanProxyAdaptor<FunctionType> : public CanProxyBase<FunctionType> {
469  LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getReturnType)
471 };
472 
473 template<>
475  : public CanProxyBase<FunctionNoProtoType> {
476  LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getReturnType)
478 };
479 
480 template<>
482  : public CanProxyBase<FunctionProtoType> {
483  LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getReturnType)
485  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumParams)
486  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasExtParameterInfos)
488  ArrayRef<FunctionProtoType::ExtParameterInfo>, getExtParameterInfos)
489  CanQualType getParamType(unsigned i) const {
491  }
492 
493  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVariadic)
494  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getTypeQuals)
495 
498 
500  return param_type_iterator(this->getTypePtr()->param_type_begin());
501  }
502 
504  return param_type_iterator(this->getTypePtr()->param_type_end());
505  }
506 
507  // Note: canonical function types never have exception specifications
508 };
509 
510 template<>
511 struct CanProxyAdaptor<TypeOfType> : public CanProxyBase<TypeOfType> {
513 };
514 
515 template<>
516 struct CanProxyAdaptor<DecltypeType> : public CanProxyBase<DecltypeType> {
517  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Expr *, getUnderlyingExpr)
519 };
520 
521 template <>
523  : public CanProxyBase<UnaryTransformType> {
527 };
528 
529 template<>
530 struct CanProxyAdaptor<TagType> : public CanProxyBase<TagType> {
532  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isBeingDefined)
533 };
534 
535 template<>
536 struct CanProxyAdaptor<RecordType> : public CanProxyBase<RecordType> {
538  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isBeingDefined)
539  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasConstFields)
540 };
541 
542 template<>
543 struct CanProxyAdaptor<EnumType> : public CanProxyBase<EnumType> {
545  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isBeingDefined)
546 };
547 
548 template<>
550  : public CanProxyBase<TemplateTypeParmType> {
551  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getDepth)
552  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getIndex)
553  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isParameterPack)
556 };
557 
558 template<>
560  : public CanProxyBase<ObjCObjectType> {
563  getInterface)
564  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCUnqualifiedId)
565  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCUnqualifiedClass)
566  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedId)
567  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedClass)
568 
569  typedef ObjCObjectPointerType::qual_iterator qual_iterator;
570  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_begin)
571  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_end)
572  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, qual_empty)
573  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumProtocols)
574 };
575 
576 template<>
578  : public CanProxyBase<ObjCObjectPointerType> {
579  LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
581  getInterfaceType)
582  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCIdType)
583  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCClassType)
584  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedIdType)
585  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedClassType)
586 
587  typedef ObjCObjectPointerType::qual_iterator qual_iterator;
588  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_begin)
589  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_end)
590  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, qual_empty)
591  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumProtocols)
592 };
593 
594 //----------------------------------------------------------------------------//
595 // Method and function definitions
596 //----------------------------------------------------------------------------//
597 template<typename T>
599  return CanQual<T>::CreateUnsafe(Stored.getLocalUnqualifiedType());
600 }
601 
602 template<typename T>
604  if (CanQual<ReferenceType> RefType = getAs<ReferenceType>())
605  return RefType->getPointeeType();
606  else
607  return *this;
608 }
609 
610 template<typename T>
613  Result.Stored = QualType::getFromOpaquePtr(Ptr);
614  assert((!Result || Result.Stored.getAsOpaquePtr() == (void*)-1 ||
615  Result.Stored.isCanonical()) && "Type is not canonical!");
616  return Result;
617 }
618 
619 template<typename T>
621  assert((Other.isNull() || Other.isCanonical()) && "Type is not canonical!");
622  assert((Other.isNull() || isa<T>(Other.getTypePtr())) &&
623  "Dynamic type does not meet the static type's requires");
625  Result.Stored = Other;
626  return Result;
627 }
628 
629 template<typename T>
630 template<typename U>
632  static_assert(!TypeIsArrayType<T>::value,
633  "ArrayType cannot be used with getAs!");
634 
635  if (Stored.isNull())
636  return CanProxy<U>();
637 
638  if (isa<U>(Stored.getTypePtr()))
639  return CanQual<U>::CreateUnsafe(Stored);
640 
641  return CanProxy<U>();
642 }
643 
644 template<typename T>
645 template<typename U>
647  static_assert(!TypeIsArrayType<U>::value,
648  "ArrayType cannot be used with castAs!");
649 
650  assert(!Stored.isNull() && isa<U>(Stored.getTypePtr()));
651  return CanQual<U>::CreateUnsafe(Stored);
652 }
653 
654 template<typename T>
656  return CanProxy<T>(*this);
657 }
658 
659 template <typename InputIterator>
661  return CanProxy<Type>(*this);
662 }
663 
664 }
665 
666 
667 #endif
static CanQual< T > CreateUnsafe(QualType Other)
Builds a canonical type from a QualType.
Replacable canonical proxy adaptor class that provides the link between a canonical type and the acce...
Definition: CanonicalType.h:25
QualType withConst() const
Retrieves a version of this type with const applied.
static clang::CanQual< T > getFromVoidPointer(void *P)
SplitQualType split() const
Definition: CanonicalType.h:89
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2222
A (possibly-)qualified type.
Definition: Type.h:614
bool isNull() const
Definition: CanonicalType.h:85
bool operator==(CanQual< T > x, CanQual< U > y)
#define LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(Accessor)
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:26
bool isConstQualified() const
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:2964
CanProxy(CanQual< T > Stored)
Build a proxy to the given canonical type.
C Language Family Type Representation.
StringRef P
CanTypeIterator(InputIterator Iter)
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
Definition: Attr.h:195
The base class of the type hierarchy.
Definition: Type.h:1300
void Profile(llvm::FoldingSetNodeID &ID) const
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
Canonical proxy type returned when retrieving the members of a canonical type or as the result of the...
Definition: CanonicalType.h:24
QualType withConst() const
Definition: Type.h:780
void dump() const
const T * getTypePtr() const
Retrieve the pointer to the underlying Type.
CanProxy()
Build a NULL proxy.
The collection of all-type qualifiers we support.
Definition: Type.h:116
Qualifiers getQualifiers() const
Retrieve all qualifiers.
const T * getTypePtrOrNull() const
Retrieve the underlying type pointer, which refers to a canonical type, or NULL.
Definition: CanonicalType.h:75
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3384
One of these records is kept for each identifier that is lexed.
bool isLocalRestrictQualified() const
Determine whether this particular QualType instance has the "restrict" qualifier set, without looking through typedefs that may have added "restrict" at a different level.
Definition: Type.h:698
Represents a class type in Objective C.
Definition: Type.h:5023
Definition: Format.h:1821
ObjCObjectType::qual_iterator qual_iterator
An iterator over the qualifiers on the object type.
Definition: Type.h:5393
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:5697
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:5562
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2422
bool isRestrictQualified() const
CanTypeIterator< FunctionProtoType::param_type_iterator > param_type_iterator
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5543
static bool isBooleanType(QualType Ty)
void * getAsOpaquePtr() const
Definition: Type.h:662
Represents an ObjC class declaration.
Definition: DeclObjC.h:1108
static void * getAsVoidPointer(clang::CanQual< T > P)
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
Definition: CanonicalType.h:70
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:2800
Represents a K&R-style &#39;int foo()&#39; function, which has no information available about its arguments...
Definition: Type.h:3136
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:953
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3170
bool isMoreQualifiedThan(QualType Other) const
Determine whether this type is more qualified than the other given type, requiring exact equality for...
Definition: Type.h:5687
Expr - This represents one expression.
Definition: Expr.h:106
CanProxy< Type > operator->() const
const FunctionProtoType * T
Declaration of a template type parameter.
bool hasQualifiers() const
Determines whether this type has any qualifiers.
#define bool
Definition: stdbool.h:31
Represents the type decltype(expr) (C++11).
Definition: Type.h:3722
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:557
unsigned getCVRQualifiers() const
Retrieve the const/volatile/restrict qualifiers.
CanProxy< U > getAs() const
Try to convert the given canonical type to a specific structural type.
A unary type transform, which is a type constructed from another.
Definition: Type.h:3763
bool isAtLeastAsQualifiedAs(CanQual< T > Other) const
Determines whether this canonical type is at least as qualified as the Other canonical type...
CanProxy< T > operator->() const
Overloaded arrow operator that produces a canonical type proxy.
static SimpleType getSimplifiedValue(::clang::CanQual< T > Val)
Represents a GCC generic vector type.
Definition: Type.h:2838
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2405
The result type of a method or function.
CanQualType operator*() const
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:681
bool isVolatileQualified() const
static StringRef getIdentifier(const Token &Tok)
CanQualType getCanonicalTypeUnqualified() const
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:5551
CanProxy< U > castAs() const
Encodes a location in the source.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:3864
Represents typeof(type), a GCC extension.
Definition: Type.h:3698
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:5219
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2846
static QualType getUnderlyingType(const SubRegion *R)
unsigned getLocalCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers local to this particular QualType instan...
Definition: Type.h:743
Represents a canonical, potentially-qualified type.
Definition: CanonicalType.h:52
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
CanQual< T > Stored
#define LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Type, Accessor)
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:663
bool isCanonical() const
Definition: Type.h:5587
bool isLocalVolatileQualified() const
Determine whether this particular QualType instance has the "volatile" qualifier set, without looking through typedefs that may have added "volatile" at a different level.
Definition: Type.h:708
bool isMoreQualifiedThan(CanQual< T > Other) const
Determines whether this canonical type is more qualified than the Other canonical type...
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed...
Dataflow Directional Tag Classes.
Iterator adaptor that turns an iterator over canonical QualTypes into an iterator over CanQualTypes...
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
Definition: Type.h:718
Base class of all canonical proxy types, which is responsible for storing the underlying canonical ty...
EnumDecl - Represents an enum.
Definition: Decl.h:3132
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2440
Represents a pointer to an Objective C object.
Definition: Type.h:5274
Pointer to a block type.
Definition: Type.h:2325
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:3839
Complex values, per C99 6.2.5p11.
Definition: Type.h:2162
static CanQual< T > getFromOpaquePtr(void *Ptr)
Construct a canonical type from its internal representation.
std::integral_constant< bool, std::is_same< T, ArrayType >::value||std::is_base_of< ArrayType, T >::value > TypeIsArrayType
Definition: Type.h:6096
CanQual< Type > getNonReferenceType() const
If the canonical type is a reference type, returns the type that it refers to; otherwise, returns the type itself.
ExtVectorType - Extended vector type.
Definition: Type.h:2899
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2358
void * getAsOpaquePtr() const
Retrieve the internal representation of this canonical type.
const Type * getTypePtrOrNull() const
Definition: Type.h:5547
bool isCanonicalAsParam() const
Definition: Type.h:5591
Represents a C++ struct/union/class.
Definition: DeclCXX.h:266
bool isLocalConstQualified() const
Determine whether this particular QualType instance has the "const" qualifier set, without looking through typedefs that may have added "const" at a different level.
Definition: Type.h:688
param_type_iterator param_type_begin() const
param_type_iterator param_type_end() const
bool operator!=(CanQual< T > x, CanQual< U > y)
static bool isCharType(QualType T)
bool isCanonicalAsParam() const
Determines if this canonical type is furthermore canonical as a parameter.
void dump(const char *s) const
Definition: ASTDumper.cpp:2660
CanQual()
Constructs a NULL canonical type.
Definition: CanonicalType.h:58
A class which abstracts out some details necessary for making a call.
Definition: Type.h:2989
static QualType getParamType(Sema &SemaRef, ArrayRef< ResultCandidate > Candidates, unsigned N)
Get the type of the Nth parameter from a given set of overload candidates.