]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/clang/include/clang/AST/CanonicalType.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / llvm / tools / clang / include / clang / AST / CanonicalType.h
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_CANONICAL_TYPE_H
16 #define LLVM_CLANG_AST_CANONICAL_TYPE_H
17
18 #include "clang/AST/Type.h"
19 #include "llvm/Support/Casting.h"
20 #include "llvm/Support/type_traits.h"
21 #include <iterator>
22
23 namespace clang {
24
25 template<typename T> class CanProxy;
26 template<typename T> struct CanProxyAdaptor;
27
28 //----------------------------------------------------------------------------//
29 // Canonical, qualified type template
30 //----------------------------------------------------------------------------//
31
32 /// \brief Represents a canonical, potentially-qualified type.
33 ///
34 /// The CanQual template is a lightweight smart pointer that provides access
35 /// to the canonical representation of a type, where all typedefs and other
36 /// syntactic sugar has been eliminated. A CanQualType may also have various
37 /// qualifiers (const, volatile, restrict) attached to it.
38 ///
39 /// The template type parameter @p T is one of the Type classes (PointerType,
40 /// BuiltinType, etc.). The type stored within @c CanQual<T> will be of that
41 /// type (or some subclass of that type). The typedef @c CanQualType is just
42 /// a shorthand for @c CanQual<Type>.
43 ///
44 /// An instance of @c CanQual<T> can be implicitly converted to a
45 /// @c CanQual<U> when T is derived from U, which essentially provides an
46 /// implicit upcast. For example, @c CanQual<LValueReferenceType> can be
47 /// converted to @c CanQual<ReferenceType>. Note that any @c CanQual type can
48 /// be implicitly converted to a QualType, but the reverse operation requires
49 /// a call to ASTContext::getCanonicalType().
50 ///
51 ///
52 template<typename T = Type>
53 class CanQual {
54   /// \brief The actual, canonical type.
55   QualType Stored;
56
57 public:
58   /// \brief Constructs a NULL canonical type.
59   CanQual() : Stored() { }
60
61   /// \brief Converting constructor that permits implicit upcasting of
62   /// canonical type pointers.
63   template<typename U>
64   CanQual(const CanQual<U>& Other,
65           typename llvm::enable_if<llvm::is_base_of<T, U>, int>::type = 0);
66
67   /// \brief Retrieve the underlying type pointer, which refers to a
68   /// canonical type.
69   ///
70   /// The underlying pointer must not be NULL.
71   const T *getTypePtr() const { return cast<T>(Stored.getTypePtr()); }
72
73   /// \brief Retrieve the underlying type pointer, which refers to a
74   /// canonical type, or NULL.
75   ///
76   const T *getTypePtrOrNull() const { 
77     return cast_or_null<T>(Stored.getTypePtrOrNull()); 
78   }
79
80   /// \brief Implicit conversion to a qualified type.
81   operator QualType() const { return Stored; }
82
83   /// \brief Implicit conversion to bool.
84   operator bool() const { return !isNull(); }
85   
86   bool isNull() const {
87     return Stored.isNull();
88   }
89
90   SplitQualType split() const { return Stored.split(); }
91
92   /// \brief Retrieve a canonical type pointer with a different static type,
93   /// upcasting or downcasting as needed.
94   ///
95   /// The getAs() function is typically used to try to downcast to a
96   /// more specific (canonical) type in the type system. For example:
97   ///
98   /// @code
99   /// void f(CanQual<Type> T) {
100   ///   if (CanQual<PointerType> Ptr = T->getAs<PointerType>()) {
101   ///     // look at Ptr's pointee type
102   ///   }
103   /// }
104   /// @endcode
105   ///
106   /// \returns A proxy pointer to the same type, but with the specified
107   /// static type (@p U). If the dynamic type is not the specified static type
108   /// or a derived class thereof, a NULL canonical type.
109   template<typename U> CanProxy<U> getAs() const;
110
111   template<typename U> CanProxy<U> castAs() const;
112
113   /// \brief Overloaded arrow operator that produces a canonical type
114   /// proxy.
115   CanProxy<T> operator->() const;
116
117   /// \brief Retrieve all qualifiers.
118   Qualifiers getQualifiers() const { return Stored.getLocalQualifiers(); }
119
120   /// \brief Retrieve the const/volatile/restrict qualifiers.
121   unsigned getCVRQualifiers() const { return Stored.getLocalCVRQualifiers(); }
122
123   /// \brief Determines whether this type has any qualifiers
124   bool hasQualifiers() const { return Stored.hasLocalQualifiers(); }
125
126   bool isConstQualified() const {
127     return Stored.isLocalConstQualified();
128   }
129   bool isVolatileQualified() const {
130     return Stored.isLocalVolatileQualified();
131   }
132   bool isRestrictQualified() const {
133     return Stored.isLocalRestrictQualified();
134   }
135
136   /// \brief Determines if this canonical type is furthermore
137   /// canonical as a parameter.  The parameter-canonicalization
138   /// process decays arrays to pointers and drops top-level qualifiers.
139   bool isCanonicalAsParam() const {
140     return Stored.isCanonicalAsParam();
141   }
142
143   /// \brief Retrieve the unqualified form of this type.
144   CanQual<T> getUnqualifiedType() const;
145
146   /// \brief Retrieves a version of this type with const applied.
147   /// Note that this does not always yield a canonical type.
148   QualType withConst() const {
149     return Stored.withConst();
150   }
151
152   /// \brief Determines whether this canonical type is more qualified than
153   /// the @p Other canonical type.
154   bool isMoreQualifiedThan(CanQual<T> Other) const {
155     return Stored.isMoreQualifiedThan(Other.Stored);
156   }
157
158   /// \brief Determines whether this canonical type is at least as qualified as
159   /// the @p Other canonical type.
160   bool isAtLeastAsQualifiedAs(CanQual<T> Other) const {
161     return Stored.isAtLeastAsQualifiedAs(Other.Stored);
162   }
163
164   /// \brief If the canonical type is a reference type, returns the type that
165   /// it refers to; otherwise, returns the type itself.
166   CanQual<Type> getNonReferenceType() const;
167
168   /// \brief Retrieve the internal representation of this canonical type.
169   void *getAsOpaquePtr() const { return Stored.getAsOpaquePtr(); }
170
171   /// \brief Construct a canonical type from its internal representation.
172   static CanQual<T> getFromOpaquePtr(void *Ptr);
173
174   /// \brief Builds a canonical type from a QualType.
175   ///
176   /// This routine is inherently unsafe, because it requires the user to
177   /// ensure that the given type is a canonical type with the correct
178   // (dynamic) type.
179   static CanQual<T> CreateUnsafe(QualType Other);
180
181   void dump() const { Stored.dump(); }
182
183   void Profile(llvm::FoldingSetNodeID &ID) const {
184     ID.AddPointer(getAsOpaquePtr());
185   }
186 };
187
188 template<typename T, typename U>
189 inline bool operator==(CanQual<T> x, CanQual<U> y) {
190   return x.getAsOpaquePtr() == y.getAsOpaquePtr();
191 }
192
193 template<typename T, typename U>
194 inline bool operator!=(CanQual<T> x, CanQual<U> y) {
195   return x.getAsOpaquePtr() != y.getAsOpaquePtr();
196 }
197
198 /// \brief Represents a canonical, potentially-qualified type.
199 typedef CanQual<Type> CanQualType;
200
201 inline CanQualType Type::getCanonicalTypeUnqualified() const {
202   return CanQualType::CreateUnsafe(getCanonicalTypeInternal());
203 }
204
205 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
206                                            CanQualType T) {
207   DB << static_cast<QualType>(T);
208   return DB;
209 }
210
211 //----------------------------------------------------------------------------//
212 // Internal proxy classes used by canonical types
213 //----------------------------------------------------------------------------//
214
215 #define LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(Accessor)                    \
216 CanQualType Accessor() const {                                           \
217 return CanQualType::CreateUnsafe(this->getTypePtr()->Accessor());      \
218 }
219
220 #define LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Type, Accessor)             \
221 Type Accessor() const { return this->getTypePtr()->Accessor(); }
222
223 /// \brief Base class of all canonical proxy types, which is responsible for
224 /// storing the underlying canonical type and providing basic conversions.
225 template<typename T>
226 class CanProxyBase {
227 protected:
228   CanQual<T> Stored;
229
230 public:
231   /// \brief Retrieve the pointer to the underlying Type
232   const T *getTypePtr() const { return Stored.getTypePtr(); }
233
234   /// \brief Implicit conversion to the underlying pointer.
235   ///
236   /// Also provides the ability to use canonical type proxies in a Boolean
237   // context,e.g.,
238   /// @code
239   ///   if (CanQual<PointerType> Ptr = T->getAs<PointerType>()) { ... }
240   /// @endcode
241   operator const T*() const { return this->Stored.getTypePtrOrNull(); }
242
243   /// \brief Try to convert the given canonical type to a specific structural
244   /// type.
245   template<typename U> CanProxy<U> getAs() const {
246     return this->Stored.template getAs<U>();
247   }
248
249   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Type::TypeClass, getTypeClass)
250
251   // Type predicates
252   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjectType)
253   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIncompleteType)
254   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIncompleteOrObjectType)
255   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVariablyModifiedType)
256   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIntegerType)
257   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isEnumeralType)
258   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isBooleanType)
259   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isCharType)
260   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isWideCharType)
261   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIntegralType)
262   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isIntegralOrEnumerationType)
263   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isRealFloatingType)
264   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isComplexType)
265   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAnyComplexType)
266   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isFloatingType)
267   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isRealType)
268   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isArithmeticType)
269   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVoidType)
270   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isDerivedType)
271   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isScalarType)
272   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAggregateType)
273   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAnyPointerType)
274   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVoidPointerType)
275   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isFunctionPointerType)
276   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isMemberFunctionPointerType)
277   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isClassType)
278   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isStructureType)
279   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isInterfaceType)
280   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isStructureOrClassType)
281   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isUnionType)
282   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isComplexIntegerType)
283   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isNullPtrType)
284   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isDependentType)
285   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isOverloadableType)
286   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isArrayType)
287   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasPointerRepresentation)
288   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasObjCPointerRepresentation)
289   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasIntegerRepresentation)
290   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasSignedIntegerRepresentation)
291   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasUnsignedIntegerRepresentation)
292   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasFloatingRepresentation)
293   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isPromotableIntegerType)
294   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isSignedIntegerType)
295   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isUnsignedIntegerType)
296   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isSignedIntegerOrEnumerationType)
297   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isUnsignedIntegerOrEnumerationType)
298   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isConstantSizeType)
299   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isSpecifierType)
300   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(CXXRecordDecl*, getAsCXXRecordDecl)
301
302   /// \brief Retrieve the proxy-adaptor type.
303   ///
304   /// This arrow operator is used when CanProxyAdaptor has been specialized
305   /// for the given type T. In that case, we reference members of the
306   /// CanProxyAdaptor specialization. Otherwise, this operator will be hidden
307   /// by the arrow operator in the primary CanProxyAdaptor template.
308   const CanProxyAdaptor<T> *operator->() const {
309     return static_cast<const CanProxyAdaptor<T> *>(this);
310   }
311 };
312
313 /// \brief Replacable canonical proxy adaptor class that provides the link
314 /// between a canonical type and the accessors of the type.
315 ///
316 /// The CanProxyAdaptor is a replaceable class template that is instantiated
317 /// as part of each canonical proxy type. The primary template merely provides
318 /// redirection to the underlying type (T), e.g., @c PointerType. One can
319 /// provide specializations of this class template for each underlying type
320 /// that provide accessors returning canonical types (@c CanQualType) rather
321 /// than the more typical @c QualType, to propagate the notion of "canonical"
322 /// through the system.
323 template<typename T>
324 struct CanProxyAdaptor : CanProxyBase<T> { };
325
326 /// \brief Canonical proxy type returned when retrieving the members of a
327 /// canonical type or as the result of the @c CanQual<T>::getAs member
328 /// function.
329 ///
330 /// The CanProxy type mainly exists as a proxy through which operator-> will
331 /// look to either map down to a raw T* (e.g., PointerType*) or to a proxy
332 /// type that provides canonical-type access to the fields of the type.
333 template<typename T>
334 class CanProxy : public CanProxyAdaptor<T> {
335 public:
336   /// \brief Build a NULL proxy.
337   CanProxy() { }
338
339   /// \brief Build a proxy to the given canonical type.
340   CanProxy(CanQual<T> Stored) { this->Stored = Stored; }
341
342   /// \brief Implicit conversion to the stored canonical type.
343   operator CanQual<T>() const { return this->Stored; }
344 };
345
346 } // end namespace clang
347
348 namespace llvm {
349
350 /// Implement simplify_type for CanQual<T>, so that we can dyn_cast from
351 /// CanQual<T> to a specific Type class. We're prefer isa/dyn_cast/cast/etc.
352 /// to return smart pointer (proxies?).
353 template<typename T>
354 struct simplify_type< ::clang::CanQual<T> > {
355   typedef const T *SimpleType;
356   static SimpleType getSimplifiedValue(::clang::CanQual<T> Val) {
357     return Val.getTypePtr();
358   }
359 };
360
361 // Teach SmallPtrSet that CanQual<T> is "basically a pointer".
362 template<typename T>
363 class PointerLikeTypeTraits<clang::CanQual<T> > {
364 public:
365   static inline void *getAsVoidPointer(clang::CanQual<T> P) {
366     return P.getAsOpaquePtr();
367   }
368   static inline clang::CanQual<T> getFromVoidPointer(void *P) {
369     return clang::CanQual<T>::getFromOpaquePtr(P);
370   }
371   // qualifier information is encoded in the low bits.
372   enum { NumLowBitsAvailable = 0 };
373 };
374
375 } // end namespace llvm
376
377 namespace clang {
378
379 //----------------------------------------------------------------------------//
380 // Canonical proxy adaptors for canonical type nodes.
381 //----------------------------------------------------------------------------//
382
383 /// \brief Iterator adaptor that turns an iterator over canonical QualTypes
384 /// into an iterator over CanQualTypes.
385 template<typename InputIterator>
386 class CanTypeIterator {
387   InputIterator Iter;
388
389 public:
390   typedef CanQualType    value_type;
391   typedef value_type     reference;
392   typedef CanProxy<Type> pointer;
393   typedef typename std::iterator_traits<InputIterator>::difference_type
394     difference_type;
395   typedef typename std::iterator_traits<InputIterator>::iterator_category
396     iterator_category;
397
398   CanTypeIterator() : Iter() { }
399   explicit CanTypeIterator(InputIterator Iter) : Iter(Iter) { }
400
401   // Input iterator
402   reference operator*() const {
403     return CanQualType::CreateUnsafe(*Iter);
404   }
405
406   pointer operator->() const;
407
408   CanTypeIterator &operator++() {
409     ++Iter;
410     return *this;
411   }
412
413   CanTypeIterator operator++(int) {
414     CanTypeIterator Tmp(*this);
415     ++Iter;
416     return Tmp;
417   }
418
419   friend bool operator==(const CanTypeIterator& X, const CanTypeIterator &Y) {
420     return X.Iter == Y.Iter;
421   }
422   friend bool operator!=(const CanTypeIterator& X, const CanTypeIterator &Y) {
423     return X.Iter != Y.Iter;
424   }
425
426   // Bidirectional iterator
427   CanTypeIterator &operator--() {
428     --Iter;
429     return *this;
430   }
431
432   CanTypeIterator operator--(int) {
433     CanTypeIterator Tmp(*this);
434     --Iter;
435     return Tmp;
436   }
437
438   // Random access iterator
439   reference operator[](difference_type n) const {
440     return CanQualType::CreateUnsafe(Iter[n]);
441   }
442
443   CanTypeIterator &operator+=(difference_type n) {
444     Iter += n;
445     return *this;
446   }
447
448   CanTypeIterator &operator-=(difference_type n) {
449     Iter -= n;
450     return *this;
451   }
452
453   friend CanTypeIterator operator+(CanTypeIterator X, difference_type n) {
454     X += n;
455     return X;
456   }
457
458   friend CanTypeIterator operator+(difference_type n, CanTypeIterator X) {
459     X += n;
460     return X;
461   }
462
463   friend CanTypeIterator operator-(CanTypeIterator X, difference_type n) {
464     X -= n;
465     return X;
466   }
467
468   friend difference_type operator-(const CanTypeIterator &X,
469                                    const CanTypeIterator &Y) {
470     return X - Y;
471   }
472 };
473
474 template<>
475 struct CanProxyAdaptor<ComplexType> : public CanProxyBase<ComplexType> {
476   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getElementType)
477 };
478
479 template<>
480 struct CanProxyAdaptor<PointerType> : public CanProxyBase<PointerType> {
481   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
482 };
483
484 template<>
485 struct CanProxyAdaptor<BlockPointerType>
486   : public CanProxyBase<BlockPointerType> {
487   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
488 };
489
490 template<>
491 struct CanProxyAdaptor<ReferenceType> : public CanProxyBase<ReferenceType> {
492   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
493 };
494
495 template<>
496 struct CanProxyAdaptor<LValueReferenceType>
497   : public CanProxyBase<LValueReferenceType> {
498   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
499 };
500
501 template<>
502 struct CanProxyAdaptor<RValueReferenceType>
503   : public CanProxyBase<RValueReferenceType> {
504   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
505 };
506
507 template<>
508 struct CanProxyAdaptor<MemberPointerType>
509   : public CanProxyBase<MemberPointerType> {
510   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
511   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const Type *, getClass)
512 };
513
514 // CanProxyAdaptors for arrays are intentionally unimplemented because
515 // they are not safe.
516 template<> struct CanProxyAdaptor<ArrayType>;
517 template<> struct CanProxyAdaptor<ConstantArrayType>;
518 template<> struct CanProxyAdaptor<IncompleteArrayType>;
519 template<> struct CanProxyAdaptor<VariableArrayType>;
520 template<> struct CanProxyAdaptor<DependentSizedArrayType>;
521
522 template<>
523 struct CanProxyAdaptor<DependentSizedExtVectorType>
524   : public CanProxyBase<DependentSizedExtVectorType> {
525   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getElementType)
526   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const Expr *, getSizeExpr)
527   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(SourceLocation, getAttributeLoc)
528 };
529
530 template<>
531 struct CanProxyAdaptor<VectorType> : public CanProxyBase<VectorType> {
532   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getElementType)
533   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumElements)
534 };
535
536 template<>
537 struct CanProxyAdaptor<ExtVectorType> : public CanProxyBase<ExtVectorType> {
538   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getElementType)
539   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumElements)
540 };
541
542 template<>
543 struct CanProxyAdaptor<FunctionType> : public CanProxyBase<FunctionType> {
544   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getResultType)
545   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(FunctionType::ExtInfo, getExtInfo)
546 };
547
548 template<>
549 struct CanProxyAdaptor<FunctionNoProtoType>
550   : public CanProxyBase<FunctionNoProtoType> {
551   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getResultType)
552   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(FunctionType::ExtInfo, getExtInfo)
553 };
554
555 template<>
556 struct CanProxyAdaptor<FunctionProtoType>
557   : public CanProxyBase<FunctionProtoType> {
558   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getResultType)
559   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(FunctionType::ExtInfo, getExtInfo)
560   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumArgs)
561   CanQualType getArgType(unsigned i) const {
562     return CanQualType::CreateUnsafe(this->getTypePtr()->getArgType(i));
563   }
564
565   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVariadic)
566   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getTypeQuals)
567
568   typedef CanTypeIterator<FunctionProtoType::arg_type_iterator>
569     arg_type_iterator;
570
571   arg_type_iterator arg_type_begin() const {
572     return arg_type_iterator(this->getTypePtr()->arg_type_begin());
573   }
574
575   arg_type_iterator arg_type_end() const {
576     return arg_type_iterator(this->getTypePtr()->arg_type_end());
577   }
578
579   // Note: canonical function types never have exception specifications
580 };
581
582 template<>
583 struct CanProxyAdaptor<TypeOfType> : public CanProxyBase<TypeOfType> {
584   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getUnderlyingType)
585 };
586
587 template<>
588 struct CanProxyAdaptor<DecltypeType> : public CanProxyBase<DecltypeType> {
589   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Expr *, getUnderlyingExpr)
590   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getUnderlyingType)
591 };
592
593 template <>
594 struct CanProxyAdaptor<UnaryTransformType>
595     : public CanProxyBase<UnaryTransformType> {
596   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getBaseType)
597   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getUnderlyingType)
598   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(UnaryTransformType::UTTKind, getUTTKind)
599 };
600
601 template<>
602 struct CanProxyAdaptor<TagType> : public CanProxyBase<TagType> {
603   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(TagDecl *, getDecl)
604   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isBeingDefined)
605 };
606
607 template<>
608 struct CanProxyAdaptor<RecordType> : public CanProxyBase<RecordType> {
609   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(RecordDecl *, getDecl)
610   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isBeingDefined)
611   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasConstFields)
612 };
613
614 template<>
615 struct CanProxyAdaptor<EnumType> : public CanProxyBase<EnumType> {
616   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(EnumDecl *, getDecl)
617   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isBeingDefined)
618 };
619
620 template<>
621 struct CanProxyAdaptor<TemplateTypeParmType>
622   : public CanProxyBase<TemplateTypeParmType> {
623   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getDepth)
624   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getIndex)
625   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isParameterPack)
626   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(TemplateTypeParmDecl *, getDecl)
627   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(IdentifierInfo *, getIdentifier)
628 };
629
630 template<>
631 struct CanProxyAdaptor<ObjCObjectType>
632   : public CanProxyBase<ObjCObjectType> {
633   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getBaseType)
634   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const ObjCInterfaceDecl *,
635                                       getInterface)
636   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCUnqualifiedId)
637   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCUnqualifiedClass)
638   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedId)
639   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedClass)
640
641   typedef ObjCObjectPointerType::qual_iterator qual_iterator;
642   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_begin)
643   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_end)
644   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, qual_empty)
645   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumProtocols)
646 };
647
648 template<>
649 struct CanProxyAdaptor<ObjCObjectPointerType>
650   : public CanProxyBase<ObjCObjectPointerType> {
651   LLVM_CLANG_CANPROXY_TYPE_ACCESSOR(getPointeeType)
652   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(const ObjCInterfaceType *,
653                                       getInterfaceType)
654   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCIdType)
655   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCClassType)
656   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedIdType)
657   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isObjCQualifiedClassType)
658
659   typedef ObjCObjectPointerType::qual_iterator qual_iterator;
660   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_begin)
661   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(qual_iterator, qual_end)
662   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, qual_empty)
663   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getNumProtocols)
664 };
665
666 //----------------------------------------------------------------------------//
667 // Method and function definitions
668 //----------------------------------------------------------------------------//
669 template<typename T>
670 inline CanQual<T> CanQual<T>::getUnqualifiedType() const {
671   return CanQual<T>::CreateUnsafe(Stored.getLocalUnqualifiedType());
672 }
673
674 template<typename T>
675 inline CanQual<Type> CanQual<T>::getNonReferenceType() const {
676   if (CanQual<ReferenceType> RefType = getAs<ReferenceType>())
677     return RefType->getPointeeType();
678   else
679     return *this;
680 }
681
682 template<typename T>
683 CanQual<T> CanQual<T>::getFromOpaquePtr(void *Ptr) {
684   CanQual<T> Result;
685   Result.Stored = QualType::getFromOpaquePtr(Ptr);
686   assert((!Result || Result.Stored.getAsOpaquePtr() == (void*)-1 ||
687           Result.Stored.isCanonical()) && "Type is not canonical!");
688   return Result;
689 }
690
691 template<typename T>
692 CanQual<T> CanQual<T>::CreateUnsafe(QualType Other) {
693   assert((Other.isNull() || Other.isCanonical()) && "Type is not canonical!");
694   assert((Other.isNull() || isa<T>(Other.getTypePtr())) &&
695          "Dynamic type does not meet the static type's requires");
696   CanQual<T> Result;
697   Result.Stored = Other;
698   return Result;
699 }
700
701 template<typename T>
702 template<typename U>
703 CanProxy<U> CanQual<T>::getAs() const {
704   ArrayType_cannot_be_used_with_getAs<U> at;
705   (void)at;
706
707   if (Stored.isNull())
708     return CanProxy<U>();
709
710   if (isa<U>(Stored.getTypePtr()))
711     return CanQual<U>::CreateUnsafe(Stored);
712
713   return CanProxy<U>();
714 }
715
716 template<typename T>
717 template<typename U>
718 CanProxy<U> CanQual<T>::castAs() const {
719   ArrayType_cannot_be_used_with_getAs<U> at;
720   (void)at;
721
722   assert(!Stored.isNull() && isa<U>(Stored.getTypePtr()));
723   return CanQual<U>::CreateUnsafe(Stored);
724 }
725
726 template<typename T>
727 CanProxy<T> CanQual<T>::operator->() const {
728   return CanProxy<T>(*this);
729 }
730
731 template<typename InputIterator>
732 typename CanTypeIterator<InputIterator>::pointer
733 CanTypeIterator<InputIterator>::operator->() const {
734   return CanProxy<Type>(*this);
735 }
736
737 }
738
739
740 #endif // LLVM_CLANG_AST_CANONICAL_TYPE_H