1 //===-- DeclTemplate.h - Classes for representing C++ templates -*- 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 //===----------------------------------------------------------------------===//
11 /// \brief Defines the C++ template declaration subclasses.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_DECLTEMPLATE_H
16 #define LLVM_CLANG_AST_DECLTEMPLATE_H
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/Redeclarable.h"
20 #include "clang/AST/TemplateBase.h"
21 #include "llvm/ADT/PointerUnion.h"
22 #include "llvm/Support/Compiler.h"
27 class TemplateParameterList;
29 class RedeclarableTemplateDecl;
30 class FunctionTemplateDecl;
31 class ClassTemplateDecl;
32 class ClassTemplatePartialSpecializationDecl;
33 class TemplateTypeParmDecl;
34 class NonTypeTemplateParmDecl;
35 class TemplateTemplateParmDecl;
36 class TypeAliasTemplateDecl;
38 /// \brief Stores a template parameter of any kind.
39 typedef llvm::PointerUnion3<TemplateTypeParmDecl*, NonTypeTemplateParmDecl*,
40 TemplateTemplateParmDecl*> TemplateParameter;
42 /// \brief Stores a list of template parameters for a TemplateDecl and its
44 class TemplateParameterList {
45 /// The location of the 'template' keyword.
46 SourceLocation TemplateLoc;
48 /// The locations of the '<' and '>' angle brackets.
49 SourceLocation LAngleLoc, RAngleLoc;
51 /// The number of template parameters in this template
56 TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc,
57 NamedDecl **Params, unsigned NumParams,
58 SourceLocation RAngleLoc);
61 static TemplateParameterList *Create(const ASTContext &C,
62 SourceLocation TemplateLoc,
63 SourceLocation LAngleLoc,
66 SourceLocation RAngleLoc);
68 /// \brief Iterates through the template parameters in this list.
69 typedef NamedDecl** iterator;
71 /// \brief Iterates through the template parameters in this list.
72 typedef NamedDecl* const* const_iterator;
74 iterator begin() { return reinterpret_cast<NamedDecl **>(this + 1); }
75 const_iterator begin() const {
76 return reinterpret_cast<NamedDecl * const *>(this + 1);
78 iterator end() { return begin() + NumParams; }
79 const_iterator end() const { return begin() + NumParams; }
81 unsigned size() const { return NumParams; }
83 NamedDecl* getParam(unsigned Idx) {
84 assert(Idx < size() && "Template parameter index out-of-range");
88 const NamedDecl* getParam(unsigned Idx) const {
89 assert(Idx < size() && "Template parameter index out-of-range");
93 /// \brief Returns the minimum number of arguments needed to form a
94 /// template specialization.
96 /// This may be fewer than the number of template parameters, if some of
97 /// the parameters have default arguments or if there is a parameter pack.
98 unsigned getMinRequiredArguments() const;
100 /// \brief Get the depth of this template parameter list in the set of
101 /// template parameter lists.
103 /// The first template parameter list in a declaration will have depth 0,
104 /// the second template parameter list will have depth 1, etc.
105 unsigned getDepth() const;
107 SourceLocation getTemplateLoc() const { return TemplateLoc; }
108 SourceLocation getLAngleLoc() const { return LAngleLoc; }
109 SourceLocation getRAngleLoc() const { return RAngleLoc; }
111 SourceRange getSourceRange() const LLVM_READONLY {
112 return SourceRange(TemplateLoc, RAngleLoc);
116 /// \brief Stores a list of template parameters for a TemplateDecl and its
117 /// derived classes. Suitable for creating on the stack.
119 class FixedSizeTemplateParameterList : public TemplateParameterList {
120 NamedDecl *Params[N];
123 FixedSizeTemplateParameterList(SourceLocation TemplateLoc,
124 SourceLocation LAngleLoc,
125 NamedDecl **Params, SourceLocation RAngleLoc) :
126 TemplateParameterList(TemplateLoc, LAngleLoc, Params, N, RAngleLoc) {
130 /// \brief A template argument list.
131 class TemplateArgumentList {
132 /// \brief The template argument list.
134 /// The integer value will be non-zero to indicate that this
135 /// template argument list does own the pointer.
136 llvm::PointerIntPair<const TemplateArgument *, 1> Arguments;
138 /// \brief The number of template arguments in this template
140 unsigned NumArguments;
142 TemplateArgumentList(const TemplateArgumentList &Other); // DO NOT IMPL
143 void operator=(const TemplateArgumentList &Other); // DO NOT IMPL
145 TemplateArgumentList(const TemplateArgument *Args, unsigned NumArgs,
147 : Arguments(Args, Owned), NumArguments(NumArgs) { }
150 /// \brief Type used to indicate that the template argument list itself is a
151 /// stack object. It does not own its template arguments.
152 enum OnStackType { OnStack };
154 /// \brief Create a new template argument list that copies the given set of
155 /// template arguments.
156 static TemplateArgumentList *CreateCopy(ASTContext &Context,
157 const TemplateArgument *Args,
160 /// \brief Construct a new, temporary template argument list on the stack.
162 /// The template argument list does not own the template arguments
164 explicit TemplateArgumentList(OnStackType,
165 const TemplateArgument *Args, unsigned NumArgs)
166 : Arguments(Args, false), NumArguments(NumArgs) { }
168 /// \brief Produces a shallow copy of the given template argument list.
170 /// This operation assumes that the input argument list outlives it.
171 /// This takes the list as a pointer to avoid looking like a copy
172 /// constructor, since this really really isn't safe to use that
174 explicit TemplateArgumentList(const TemplateArgumentList *Other)
175 : Arguments(Other->data(), false), NumArguments(Other->size()) { }
177 /// \brief Retrieve the template argument at a given index.
178 const TemplateArgument &get(unsigned Idx) const {
179 assert(Idx < NumArguments && "Invalid template argument index");
183 /// \brief Retrieve the template argument at a given index.
184 const TemplateArgument &operator[](unsigned Idx) const { return get(Idx); }
186 /// \brief Retrieve the number of template arguments in this
187 /// template argument list.
188 unsigned size() const { return NumArguments; }
190 /// \brief Retrieve a pointer to the template argument list.
191 const TemplateArgument *data() const {
192 return Arguments.getPointer();
196 //===----------------------------------------------------------------------===//
197 // Kinds of Templates
198 //===----------------------------------------------------------------------===//
200 /// \brief The base class of all kinds of template declarations (e.g.,
201 /// class, function, etc.).
203 /// The TemplateDecl class stores the list of template parameters and a
204 /// reference to the templated scoped declaration: the underlying AST node.
205 class TemplateDecl : public NamedDecl {
206 virtual void anchor();
208 // This is probably never used.
209 TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L,
210 DeclarationName Name)
211 : NamedDecl(DK, DC, L, Name), TemplatedDecl(0), TemplateParams(0) { }
213 // Construct a template decl with the given name and parameters.
214 // Used when there is not templated element (tt-params, alias?).
215 TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L,
216 DeclarationName Name, TemplateParameterList *Params)
217 : NamedDecl(DK, DC, L, Name), TemplatedDecl(0), TemplateParams(Params) { }
219 // Construct a template decl with name, parameters, and templated element.
220 TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L,
221 DeclarationName Name, TemplateParameterList *Params,
223 : NamedDecl(DK, DC, L, Name), TemplatedDecl(Decl),
224 TemplateParams(Params) { }
226 /// Get the list of template parameters
227 TemplateParameterList *getTemplateParameters() const {
228 return TemplateParams;
231 /// Get the underlying, templated declaration.
232 NamedDecl *getTemplatedDecl() const { return TemplatedDecl; }
234 // Implement isa/cast/dyncast/etc.
235 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
236 static bool classof(const TemplateDecl *D) { return true; }
237 static bool classof(const RedeclarableTemplateDecl *D) { return true; }
238 static bool classof(const FunctionTemplateDecl *D) { return true; }
239 static bool classof(const ClassTemplateDecl *D) { return true; }
240 static bool classof(const TemplateTemplateParmDecl *D) { return true; }
241 static bool classof(const TypeAliasTemplateDecl *D) { return true; }
242 static bool classofKind(Kind K) {
243 return K >= firstTemplate && K <= lastTemplate;
246 SourceRange getSourceRange() const LLVM_READONLY {
247 return SourceRange(TemplateParams->getTemplateLoc(),
248 TemplatedDecl->getSourceRange().getEnd());
252 NamedDecl *TemplatedDecl;
253 TemplateParameterList* TemplateParams;
256 /// \brief Initialize the underlying templated declaration and
257 /// template parameters.
258 void init(NamedDecl *templatedDecl, TemplateParameterList* templateParams) {
259 assert(TemplatedDecl == 0 && "TemplatedDecl already set!");
260 assert(TemplateParams == 0 && "TemplateParams already set!");
261 TemplatedDecl = templatedDecl;
262 TemplateParams = templateParams;
266 /// \brief Provides information about a function template specialization,
267 /// which is a FunctionDecl that has been explicitly specialization or
268 /// instantiated from a function template.
269 class FunctionTemplateSpecializationInfo : public llvm::FoldingSetNode {
270 FunctionTemplateSpecializationInfo(FunctionDecl *FD,
271 FunctionTemplateDecl *Template,
272 TemplateSpecializationKind TSK,
273 const TemplateArgumentList *TemplateArgs,
274 const ASTTemplateArgumentListInfo *TemplateArgsAsWritten,
277 Template(Template, TSK - 1),
278 TemplateArguments(TemplateArgs),
279 TemplateArgumentsAsWritten(TemplateArgsAsWritten),
280 PointOfInstantiation(POI) { }
283 static FunctionTemplateSpecializationInfo *
284 Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
285 TemplateSpecializationKind TSK,
286 const TemplateArgumentList *TemplateArgs,
287 const TemplateArgumentListInfo *TemplateArgsAsWritten,
290 /// \brief The function template specialization that this structure
292 FunctionDecl *Function;
294 /// \brief The function template from which this function template
295 /// specialization was generated.
297 /// The two bits are contain the top 4 values of TemplateSpecializationKind.
298 llvm::PointerIntPair<FunctionTemplateDecl *, 2> Template;
300 /// \brief The template arguments used to produce the function template
301 /// specialization from the function template.
302 const TemplateArgumentList *TemplateArguments;
304 /// \brief The template arguments as written in the sources, if provided.
305 const ASTTemplateArgumentListInfo *TemplateArgumentsAsWritten;
307 /// \brief The point at which this function template specialization was
308 /// first instantiated.
309 SourceLocation PointOfInstantiation;
311 /// \brief Retrieve the template from which this function was specialized.
312 FunctionTemplateDecl *getTemplate() const { return Template.getPointer(); }
314 /// \brief Determine what kind of template specialization this is.
315 TemplateSpecializationKind getTemplateSpecializationKind() const {
316 return (TemplateSpecializationKind)(Template.getInt() + 1);
319 bool isExplicitSpecialization() const {
320 return getTemplateSpecializationKind() == TSK_ExplicitSpecialization;
323 /// \brief Set the template specialization kind.
324 void setTemplateSpecializationKind(TemplateSpecializationKind TSK) {
325 assert(TSK != TSK_Undeclared &&
326 "Cannot encode TSK_Undeclared for a function template specialization");
327 Template.setInt(TSK - 1);
330 /// \brief Retrieve the first point of instantiation of this function
331 /// template specialization.
333 /// The point of instantiation may be an invalid source location if this
334 /// function has yet to be instantiated.
335 SourceLocation getPointOfInstantiation() const {
336 return PointOfInstantiation;
339 /// \brief Set the (first) point of instantiation of this function template
341 void setPointOfInstantiation(SourceLocation POI) {
342 PointOfInstantiation = POI;
345 void Profile(llvm::FoldingSetNodeID &ID) {
346 Profile(ID, TemplateArguments->data(),
347 TemplateArguments->size(),
348 Function->getASTContext());
352 Profile(llvm::FoldingSetNodeID &ID, const TemplateArgument *TemplateArgs,
353 unsigned NumTemplateArgs, ASTContext &Context) {
354 ID.AddInteger(NumTemplateArgs);
355 for (unsigned Arg = 0; Arg != NumTemplateArgs; ++Arg)
356 TemplateArgs[Arg].Profile(ID, Context);
360 /// \brief Provides information a specialization of a member of a class
361 /// template, which may be a member function, static data member,
362 /// member class or member enumeration.
363 class MemberSpecializationInfo {
364 // The member declaration from which this member was instantiated, and the
365 // manner in which the instantiation occurred (in the lower two bits).
366 llvm::PointerIntPair<NamedDecl *, 2> MemberAndTSK;
368 // The point at which this member was first instantiated.
369 SourceLocation PointOfInstantiation;
373 MemberSpecializationInfo(NamedDecl *IF, TemplateSpecializationKind TSK,
374 SourceLocation POI = SourceLocation())
375 : MemberAndTSK(IF, TSK - 1), PointOfInstantiation(POI) {
376 assert(TSK != TSK_Undeclared &&
377 "Cannot encode undeclared template specializations for members");
380 /// \brief Retrieve the member declaration from which this member was
382 NamedDecl *getInstantiatedFrom() const { return MemberAndTSK.getPointer(); }
384 /// \brief Determine what kind of template specialization this is.
385 TemplateSpecializationKind getTemplateSpecializationKind() const {
386 return (TemplateSpecializationKind)(MemberAndTSK.getInt() + 1);
389 /// \brief Set the template specialization kind.
390 void setTemplateSpecializationKind(TemplateSpecializationKind TSK) {
391 assert(TSK != TSK_Undeclared &&
392 "Cannot encode undeclared template specializations for members");
393 MemberAndTSK.setInt(TSK - 1);
396 /// \brief Retrieve the first point of instantiation of this member.
397 /// If the point of instantiation is an invalid location, then this member
398 /// has not yet been instantiated.
399 SourceLocation getPointOfInstantiation() const {
400 return PointOfInstantiation;
403 /// \brief Set the first point of instantiation.
404 void setPointOfInstantiation(SourceLocation POI) {
405 PointOfInstantiation = POI;
409 /// \brief Provides information about a dependent function-template
410 /// specialization declaration.
412 /// Since explicit function template specialization and instantiation
413 /// declarations can only appear in namespace scope, and you can only
414 /// specialize a member of a fully-specialized class, the only way to
415 /// get one of these is in a friend declaration like the following:
418 /// template \<class T> void foo(T);
419 /// template \<class T> class A {
420 /// friend void foo<>(T);
423 class DependentFunctionTemplateSpecializationInfo {
425 // Force sizeof to be a multiple of sizeof(void*) so that the
426 // trailing data is aligned.
430 /// The number of potential template candidates.
431 unsigned NumTemplates;
433 /// The number of template arguments.
438 /// The locations of the left and right angle brackets.
439 SourceRange AngleLocs;
441 FunctionTemplateDecl * const *getTemplates() const {
442 return reinterpret_cast<FunctionTemplateDecl*const*>(this+1);
446 DependentFunctionTemplateSpecializationInfo(
447 const UnresolvedSetImpl &Templates,
448 const TemplateArgumentListInfo &TemplateArgs);
450 /// \brief Returns the number of function templates that this might
451 /// be a specialization of.
452 unsigned getNumTemplates() const {
453 return d.NumTemplates;
456 /// \brief Returns the i'th template candidate.
457 FunctionTemplateDecl *getTemplate(unsigned I) const {
458 assert(I < getNumTemplates() && "template index out of range");
459 return getTemplates()[I];
462 /// \brief Returns the explicit template arguments that were given.
463 const TemplateArgumentLoc *getTemplateArgs() const {
464 return reinterpret_cast<const TemplateArgumentLoc*>(
465 &getTemplates()[getNumTemplates()]);
468 /// \brief Returns the number of explicit template arguments that were given.
469 unsigned getNumTemplateArgs() const {
473 /// \brief Returns the nth template argument.
474 const TemplateArgumentLoc &getTemplateArg(unsigned I) const {
475 assert(I < getNumTemplateArgs() && "template arg index out of range");
476 return getTemplateArgs()[I];
479 SourceLocation getLAngleLoc() const {
480 return AngleLocs.getBegin();
483 SourceLocation getRAngleLoc() const {
484 return AngleLocs.getEnd();
488 /// Declaration of a redeclarable template.
489 class RedeclarableTemplateDecl : public TemplateDecl,
490 public Redeclarable<RedeclarableTemplateDecl>
492 typedef Redeclarable<RedeclarableTemplateDecl> redeclarable_base;
493 virtual RedeclarableTemplateDecl *getNextRedeclaration() {
494 return RedeclLink.getNext();
496 virtual RedeclarableTemplateDecl *getPreviousDeclImpl() {
497 return getPreviousDecl();
499 virtual RedeclarableTemplateDecl *getMostRecentDeclImpl() {
500 return getMostRecentDecl();
504 template <typename EntryType> struct SpecEntryTraits {
505 typedef EntryType DeclType;
507 static DeclType *getMostRecentDecl(EntryType *D) {
508 return D->getMostRecentDecl();
512 template <typename EntryType,
513 typename _SETraits = SpecEntryTraits<EntryType>,
514 typename _DeclType = typename _SETraits::DeclType>
515 class SpecIterator : public std::iterator<std::forward_iterator_tag,
516 _DeclType*, ptrdiff_t,
517 _DeclType*, _DeclType*> {
518 typedef _SETraits SETraits;
519 typedef _DeclType DeclType;
521 typedef typename llvm::FoldingSetVector<EntryType>::iterator
524 SetIteratorType SetIter;
527 SpecIterator() : SetIter() {}
528 SpecIterator(SetIteratorType SetIter) : SetIter(SetIter) {}
530 DeclType *operator*() const {
531 return SETraits::getMostRecentDecl(&*SetIter);
533 DeclType *operator->() const { return **this; }
535 SpecIterator &operator++() { ++SetIter; return *this; }
536 SpecIterator operator++(int) {
537 SpecIterator tmp(*this);
542 bool operator==(SpecIterator Other) const {
543 return SetIter == Other.SetIter;
545 bool operator!=(SpecIterator Other) const {
546 return SetIter != Other.SetIter;
550 template <typename EntryType>
551 SpecIterator<EntryType>
552 makeSpecIterator(llvm::FoldingSetVector<EntryType> &Specs, bool isEnd) {
553 return SpecIterator<EntryType>(isEnd ? Specs.end() : Specs.begin());
556 template <class EntryType> typename SpecEntryTraits<EntryType>::DeclType*
557 findSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs,
558 const TemplateArgument *Args, unsigned NumArgs,
562 CommonBase() : InstantiatedFromMember(0, false) { }
564 /// \brief The template from which this was most
565 /// directly instantiated (or null).
567 /// The boolean value indicates whether this template
568 /// was explicitly specialized.
569 llvm::PointerIntPair<RedeclarableTemplateDecl*, 1, bool>
570 InstantiatedFromMember;
573 /// \brief Pointer to the common data shared by all declarations of this
577 /// \brief Retrieves the "common" pointer shared by all (re-)declarations of
578 /// the same template. Calling this routine may implicitly allocate memory
579 /// for the common pointer.
580 CommonBase *getCommonPtr();
582 virtual CommonBase *newCommon(ASTContext &C) = 0;
584 // Construct a template decl with name, parameters, and templated element.
585 RedeclarableTemplateDecl(Kind DK, DeclContext *DC, SourceLocation L,
586 DeclarationName Name, TemplateParameterList *Params,
588 : TemplateDecl(DK, DC, L, Name, Params, Decl), Common() { }
591 template <class decl_type> friend class RedeclarableTemplate;
593 /// \brief Retrieves the canonical declaration of this template.
594 RedeclarableTemplateDecl *getCanonicalDecl() { return getFirstDeclaration(); }
595 const RedeclarableTemplateDecl *getCanonicalDecl() const {
596 return getFirstDeclaration();
599 /// \brief Determines whether this template was a specialization of a
602 /// In the following example, the function template \c X<int>::f and the
603 /// member template \c X<int>::Inner are member specializations.
606 /// template<typename T>
608 /// template<typename U> void f(T, U);
609 /// template<typename U> struct Inner;
612 /// template<> template<typename T>
613 /// void X<int>::f(int, T);
614 /// template<> template<typename T>
615 /// struct X<int>::Inner { /* ... */ };
617 bool isMemberSpecialization() {
618 return getCommonPtr()->InstantiatedFromMember.getInt();
621 /// \brief Note that this member template is a specialization.
622 void setMemberSpecialization() {
623 assert(getCommonPtr()->InstantiatedFromMember.getPointer() &&
624 "Only member templates can be member template specializations");
625 getCommonPtr()->InstantiatedFromMember.setInt(true);
628 /// \brief Retrieve the member template from which this template was
629 /// instantiated, or NULL if this template was not instantiated from a
632 /// A template is instantiated from a member template when the member
633 /// template itself is part of a class template (or member thereof). For
637 /// template<typename T>
639 /// template<typename U> void f(T, U);
642 /// void test(X<int> x) {
647 /// \c X<int>::f is a FunctionTemplateDecl that describes the function
651 /// template<typename U> void X<int>::f(int, U);
654 /// which was itself created during the instantiation of \c X<int>. Calling
655 /// getInstantiatedFromMemberTemplate() on this FunctionTemplateDecl will
656 /// retrieve the FunctionTemplateDecl for the original template \c f within
657 /// the class template \c X<T>, i.e.,
660 /// template<typename T>
661 /// template<typename U>
662 /// void X<T>::f(T, U);
664 RedeclarableTemplateDecl *getInstantiatedFromMemberTemplate() {
665 return getCommonPtr()->InstantiatedFromMember.getPointer();
668 void setInstantiatedFromMemberTemplate(RedeclarableTemplateDecl *TD) {
669 assert(!getCommonPtr()->InstantiatedFromMember.getPointer());
670 getCommonPtr()->InstantiatedFromMember.setPointer(TD);
673 typedef redeclarable_base::redecl_iterator redecl_iterator;
674 using redeclarable_base::redecls_begin;
675 using redeclarable_base::redecls_end;
676 using redeclarable_base::getPreviousDecl;
677 using redeclarable_base::getMostRecentDecl;
679 // Implement isa/cast/dyncast/etc.
680 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
681 static bool classof(const RedeclarableTemplateDecl *D) { return true; }
682 static bool classof(const FunctionTemplateDecl *D) { return true; }
683 static bool classof(const ClassTemplateDecl *D) { return true; }
684 static bool classof(const TypeAliasTemplateDecl *D) { return true; }
685 static bool classofKind(Kind K) {
686 return K >= firstRedeclarableTemplate && K <= lastRedeclarableTemplate;
689 friend class ASTReader;
690 friend class ASTDeclReader;
691 friend class ASTDeclWriter;
694 template <> struct RedeclarableTemplateDecl::
695 SpecEntryTraits<FunctionTemplateSpecializationInfo> {
696 typedef FunctionDecl DeclType;
699 getMostRecentDecl(FunctionTemplateSpecializationInfo *I) {
700 return I->Function->getMostRecentDecl();
704 /// Declaration of a template function.
705 class FunctionTemplateDecl : public RedeclarableTemplateDecl {
706 static void DeallocateCommon(void *Ptr);
709 /// \brief Data that is common to all of the declarations of a given
710 /// function template.
711 struct Common : CommonBase {
712 Common() : InjectedArgs(0) { }
714 /// \brief The function template specializations for this function
715 /// template, including explicit specializations and instantiations.
716 llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> Specializations;
718 /// \brief The set of "injected" template arguments used within this
719 /// function template.
721 /// This pointer refers to the template arguments (there are as
722 /// many template arguments as template parameaters) for the function
723 /// template, and is allocated lazily, since most function templates do not
724 /// require the use of this information.
725 TemplateArgument *InjectedArgs;
728 FunctionTemplateDecl(DeclContext *DC, SourceLocation L, DeclarationName Name,
729 TemplateParameterList *Params, NamedDecl *Decl)
730 : RedeclarableTemplateDecl(FunctionTemplate, DC, L, Name, Params, Decl) { }
732 CommonBase *newCommon(ASTContext &C);
734 Common *getCommonPtr() {
735 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
738 friend class FunctionDecl;
740 /// \brief Retrieve the set of function template specializations of this
741 /// function template.
742 llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
743 getSpecializations() {
744 return getCommonPtr()->Specializations;
747 /// \brief Add a specialization of this function template.
749 /// \param InsertPos Insert position in the FoldingSetVector, must have been
750 /// retrieved by an earlier call to findSpecialization().
751 void addSpecialization(FunctionTemplateSpecializationInfo* Info,
755 /// Get the underlying function declaration of the template.
756 FunctionDecl *getTemplatedDecl() const {
757 return static_cast<FunctionDecl*>(TemplatedDecl);
760 /// Returns whether this template declaration defines the primary
762 bool isThisDeclarationADefinition() const {
763 return getTemplatedDecl()->isThisDeclarationADefinition();
766 /// \brief Return the specialization with the provided arguments if it exists,
767 /// otherwise return the insertion point.
768 FunctionDecl *findSpecialization(const TemplateArgument *Args,
769 unsigned NumArgs, void *&InsertPos);
771 FunctionTemplateDecl *getCanonicalDecl() {
772 return cast<FunctionTemplateDecl>(
773 RedeclarableTemplateDecl::getCanonicalDecl());
775 const FunctionTemplateDecl *getCanonicalDecl() const {
776 return cast<FunctionTemplateDecl>(
777 RedeclarableTemplateDecl::getCanonicalDecl());
780 /// \brief Retrieve the previous declaration of this function template, or
781 /// NULL if no such declaration exists.
782 FunctionTemplateDecl *getPreviousDecl() {
783 return cast_or_null<FunctionTemplateDecl>(
784 RedeclarableTemplateDecl::getPreviousDecl());
787 /// \brief Retrieve the previous declaration of this function template, or
788 /// NULL if no such declaration exists.
789 const FunctionTemplateDecl *getPreviousDecl() const {
790 return cast_or_null<FunctionTemplateDecl>(
791 RedeclarableTemplateDecl::getPreviousDecl());
794 FunctionTemplateDecl *getInstantiatedFromMemberTemplate() {
795 return cast_or_null<FunctionTemplateDecl>(
796 RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate());
799 typedef SpecIterator<FunctionTemplateSpecializationInfo> spec_iterator;
801 spec_iterator spec_begin() {
802 return makeSpecIterator(getSpecializations(), false);
805 spec_iterator spec_end() {
806 return makeSpecIterator(getSpecializations(), true);
809 /// \brief Retrieve the "injected" template arguments that correspond to the
810 /// template parameters of this function template.
812 /// Although the C++ standard has no notion of the "injected" template
813 /// arguments for a function template, the notion is convenient when
814 /// we need to perform substitutions inside the definition of a function
816 std::pair<const TemplateArgument *, unsigned> getInjectedTemplateArgs();
818 /// \brief Create a function template node.
819 static FunctionTemplateDecl *Create(ASTContext &C, DeclContext *DC,
821 DeclarationName Name,
822 TemplateParameterList *Params,
825 /// \brief Create an empty function template node.
826 static FunctionTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID);
828 // Implement isa/cast/dyncast support
829 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
830 static bool classof(const FunctionTemplateDecl *D) { return true; }
831 static bool classofKind(Kind K) { return K == FunctionTemplate; }
833 friend class ASTDeclReader;
834 friend class ASTDeclWriter;
837 //===----------------------------------------------------------------------===//
838 // Kinds of Template Parameters
839 //===----------------------------------------------------------------------===//
841 /// \brief Defines the position of a template parameter within a template
844 /// Because template parameter can be listed
845 /// sequentially for out-of-line template members, each template parameter is
846 /// given a Depth - the nesting of template parameter scopes - and a Position -
847 /// the occurrence within the parameter list.
848 /// This class is inheritedly privately by different kinds of template
849 /// parameters and is not part of the Decl hierarchy. Just a facility.
850 class TemplateParmPosition {
852 // FIXME: This should probably never be called, but it's here as
853 TemplateParmPosition()
854 : Depth(0), Position(0)
855 { /* llvm_unreachable("Cannot create positionless template parameter"); */ }
857 TemplateParmPosition(unsigned D, unsigned P)
858 : Depth(D), Position(P)
861 // FIXME: These probably don't need to be ints. int:5 for depth, int:8 for
867 /// Get the nesting depth of the template parameter.
868 unsigned getDepth() const { return Depth; }
869 void setDepth(unsigned D) { Depth = D; }
871 /// Get the position of the template parameter within its parameter list.
872 unsigned getPosition() const { return Position; }
873 void setPosition(unsigned P) { Position = P; }
875 /// Get the index of the template parameter within its parameter list.
876 unsigned getIndex() const { return Position; }
879 /// \brief Declaration of a template type parameter.
881 /// For example, "T" in
883 /// template<typename T> class vector;
885 class TemplateTypeParmDecl : public TypeDecl {
886 /// \brief Whether this template type parameter was declaration with
887 /// the 'typename' keyword.
889 /// If false, it was declared with the 'class' keyword.
892 /// \brief Whether this template type parameter inherited its
893 /// default argument.
894 bool InheritedDefault : 1;
896 /// \brief The default template argument, if any.
897 TypeSourceInfo *DefaultArgument;
899 TemplateTypeParmDecl(DeclContext *DC, SourceLocation KeyLoc,
900 SourceLocation IdLoc, IdentifierInfo *Id,
902 : TypeDecl(TemplateTypeParm, DC, IdLoc, Id, KeyLoc), Typename(Typename),
903 InheritedDefault(false), DefaultArgument() { }
905 /// Sema creates these on the stack during auto type deduction.
909 static TemplateTypeParmDecl *Create(const ASTContext &C, DeclContext *DC,
910 SourceLocation KeyLoc,
911 SourceLocation NameLoc,
912 unsigned D, unsigned P,
913 IdentifierInfo *Id, bool Typename,
915 static TemplateTypeParmDecl *CreateDeserialized(const ASTContext &C,
918 /// \brief Whether this template type parameter was declared with
919 /// the 'typename' keyword.
921 /// If not, it was declared with the 'class' keyword.
922 bool wasDeclaredWithTypename() const { return Typename; }
924 /// \brief Determine whether this template parameter has a default
926 bool hasDefaultArgument() const { return DefaultArgument != 0; }
928 /// \brief Retrieve the default argument, if any.
929 QualType getDefaultArgument() const { return DefaultArgument->getType(); }
931 /// \brief Retrieves the default argument's source information, if any.
932 TypeSourceInfo *getDefaultArgumentInfo() const { return DefaultArgument; }
934 /// \brief Retrieves the location of the default argument declaration.
935 SourceLocation getDefaultArgumentLoc() const;
937 /// \brief Determines whether the default argument was inherited
938 /// from a previous declaration of this template.
939 bool defaultArgumentWasInherited() const { return InheritedDefault; }
941 /// \brief Set the default argument for this template parameter, and
942 /// whether that default argument was inherited from another
944 void setDefaultArgument(TypeSourceInfo *DefArg, bool Inherited) {
945 DefaultArgument = DefArg;
946 InheritedDefault = Inherited;
949 /// \brief Removes the default argument of this template parameter.
950 void removeDefaultArgument() {
952 InheritedDefault = false;
955 /// \brief Set whether this template type parameter was declared with
956 /// the 'typename' or 'class' keyword.
957 void setDeclaredWithTypename(bool withTypename) { Typename = withTypename; }
959 /// \brief Retrieve the depth of the template parameter.
960 unsigned getDepth() const;
962 /// \brief Retrieve the index of the template parameter.
963 unsigned getIndex() const;
965 /// \brief Returns whether this is a parameter pack.
966 bool isParameterPack() const;
968 SourceRange getSourceRange() const LLVM_READONLY;
970 // Implement isa/cast/dyncast/etc.
971 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
972 static bool classof(const TemplateTypeParmDecl *D) { return true; }
973 static bool classofKind(Kind K) { return K == TemplateTypeParm; }
976 /// NonTypeTemplateParmDecl - Declares a non-type template parameter,
979 /// template<int Size> class array { };
981 class NonTypeTemplateParmDecl
982 : public DeclaratorDecl, protected TemplateParmPosition {
983 /// \brief The default template argument, if any, and whether or not
984 /// it was inherited.
985 llvm::PointerIntPair<Expr*, 1, bool> DefaultArgumentAndInherited;
987 // FIXME: Collapse this into TemplateParamPosition; or, just move depth/index
988 // down here to save memory.
990 /// \brief Whether this non-type template parameter is a parameter pack.
993 /// \brief Whether this non-type template parameter is an "expanded"
994 /// parameter pack, meaning that its type is a pack expansion and we
995 /// already know the set of types that expansion expands to.
996 bool ExpandedParameterPack;
998 /// \brief The number of types in an expanded parameter pack.
999 unsigned NumExpandedTypes;
1001 NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation StartLoc,
1002 SourceLocation IdLoc, unsigned D, unsigned P,
1003 IdentifierInfo *Id, QualType T,
1004 bool ParameterPack, TypeSourceInfo *TInfo)
1005 : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
1006 TemplateParmPosition(D, P), DefaultArgumentAndInherited(0, false),
1007 ParameterPack(ParameterPack), ExpandedParameterPack(false),
1011 NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation StartLoc,
1012 SourceLocation IdLoc, unsigned D, unsigned P,
1013 IdentifierInfo *Id, QualType T,
1014 TypeSourceInfo *TInfo,
1015 const QualType *ExpandedTypes,
1016 unsigned NumExpandedTypes,
1017 TypeSourceInfo **ExpandedTInfos);
1019 friend class ASTDeclReader;
1022 static NonTypeTemplateParmDecl *
1023 Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1024 SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id,
1025 QualType T, bool ParameterPack, TypeSourceInfo *TInfo);
1027 static NonTypeTemplateParmDecl *
1028 Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1029 SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id,
1030 QualType T, TypeSourceInfo *TInfo,
1031 const QualType *ExpandedTypes, unsigned NumExpandedTypes,
1032 TypeSourceInfo **ExpandedTInfos);
1034 static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C,
1036 static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C,
1038 unsigned NumExpandedTypes);
1040 using TemplateParmPosition::getDepth;
1041 using TemplateParmPosition::setDepth;
1042 using TemplateParmPosition::getPosition;
1043 using TemplateParmPosition::setPosition;
1044 using TemplateParmPosition::getIndex;
1046 SourceRange getSourceRange() const LLVM_READONLY;
1048 /// \brief Determine whether this template parameter has a default
1050 bool hasDefaultArgument() const {
1051 return DefaultArgumentAndInherited.getPointer() != 0;
1054 /// \brief Retrieve the default argument, if any.
1055 Expr *getDefaultArgument() const {
1056 return DefaultArgumentAndInherited.getPointer();
1059 /// \brief Retrieve the location of the default argument, if any.
1060 SourceLocation getDefaultArgumentLoc() const;
1062 /// \brief Determines whether the default argument was inherited
1063 /// from a previous declaration of this template.
1064 bool defaultArgumentWasInherited() const {
1065 return DefaultArgumentAndInherited.getInt();
1068 /// \brief Set the default argument for this template parameter, and
1069 /// whether that default argument was inherited from another
1071 void setDefaultArgument(Expr *DefArg, bool Inherited) {
1072 DefaultArgumentAndInherited.setPointer(DefArg);
1073 DefaultArgumentAndInherited.setInt(Inherited);
1076 /// \brief Removes the default argument of this template parameter.
1077 void removeDefaultArgument() {
1078 DefaultArgumentAndInherited.setPointer(0);
1079 DefaultArgumentAndInherited.setInt(false);
1082 /// \brief Whether this parameter is a non-type template parameter pack.
1084 /// If the parameter is a parameter pack, the type may be a
1085 /// \c PackExpansionType. In the following example, the \c Dims parameter
1086 /// is a parameter pack (whose type is 'unsigned').
1089 /// template<typename T, unsigned ...Dims> struct multi_array;
1091 bool isParameterPack() const { return ParameterPack; }
1093 /// \brief Whether this parameter is a non-type template parameter pack
1094 /// that has different types at different positions.
1096 /// A parameter pack is an expanded parameter pack when the original
1097 /// parameter pack's type was itself a pack expansion, and that expansion
1098 /// has already been expanded. For example, given:
1101 /// template<typename ...Types>
1103 /// template<Types ...Values>
1104 /// struct Y { /* ... */ };
1108 /// The parameter pack \c Values has a \c PackExpansionType as its type,
1109 /// which expands \c Types. When \c Types is supplied with template arguments
1110 /// by instantiating \c X, the instantiation of \c Values becomes an
1111 /// expanded parameter pack. For example, instantiating
1112 /// \c X<int, unsigned int> results in \c Values being an expanded parameter
1113 /// pack with expansion types \c int and \c unsigned int.
1115 /// The \c getExpansionType() and \c getExpansionTypeSourceInfo() functions
1116 /// return the expansion types.
1117 bool isExpandedParameterPack() const { return ExpandedParameterPack; }
1119 /// \brief Retrieves the number of expansion types in an expanded parameter
1121 unsigned getNumExpansionTypes() const {
1122 assert(ExpandedParameterPack && "Not an expansion parameter pack");
1123 return NumExpandedTypes;
1126 /// \brief Retrieve a particular expansion type within an expanded parameter
1128 QualType getExpansionType(unsigned I) const {
1129 assert(I < NumExpandedTypes && "Out-of-range expansion type index");
1130 void * const *TypesAndInfos = reinterpret_cast<void * const*>(this + 1);
1131 return QualType::getFromOpaquePtr(TypesAndInfos[2*I]);
1134 /// \brief Retrieve a particular expansion type source info within an
1135 /// expanded parameter pack.
1136 TypeSourceInfo *getExpansionTypeSourceInfo(unsigned I) const {
1137 assert(I < NumExpandedTypes && "Out-of-range expansion type index");
1138 void * const *TypesAndInfos = reinterpret_cast<void * const*>(this + 1);
1139 return static_cast<TypeSourceInfo *>(TypesAndInfos[2*I+1]);
1142 // Implement isa/cast/dyncast/etc.
1143 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1144 static bool classof(const NonTypeTemplateParmDecl *D) { return true; }
1145 static bool classofKind(Kind K) { return K == NonTypeTemplateParm; }
1148 /// TemplateTemplateParmDecl - Declares a template template parameter,
1151 /// template <template <typename> class T> class container { };
1153 /// A template template parameter is a TemplateDecl because it defines the
1154 /// name of a template and the template parameters allowable for substitution.
1155 class TemplateTemplateParmDecl : public TemplateDecl,
1156 protected TemplateParmPosition
1158 virtual void anchor();
1160 /// DefaultArgument - The default template argument, if any.
1161 TemplateArgumentLoc DefaultArgument;
1162 /// Whether or not the default argument was inherited.
1163 bool DefaultArgumentWasInherited;
1165 /// \brief Whether this parameter is a parameter pack.
1168 TemplateTemplateParmDecl(DeclContext *DC, SourceLocation L,
1169 unsigned D, unsigned P, bool ParameterPack,
1170 IdentifierInfo *Id, TemplateParameterList *Params)
1171 : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
1172 TemplateParmPosition(D, P), DefaultArgument(),
1173 DefaultArgumentWasInherited(false), ParameterPack(ParameterPack)
1177 static TemplateTemplateParmDecl *Create(const ASTContext &C, DeclContext *DC,
1178 SourceLocation L, unsigned D,
1179 unsigned P, bool ParameterPack,
1181 TemplateParameterList *Params);
1183 static TemplateTemplateParmDecl *CreateDeserialized(ASTContext &C,
1186 using TemplateParmPosition::getDepth;
1187 using TemplateParmPosition::getPosition;
1188 using TemplateParmPosition::getIndex;
1190 /// \brief Whether this template template parameter is a template
1194 /// template<template <class T> ...MetaFunctions> struct Apply;
1196 bool isParameterPack() const { return ParameterPack; }
1198 /// \brief Determine whether this template parameter has a default
1200 bool hasDefaultArgument() const {
1201 return !DefaultArgument.getArgument().isNull();
1204 /// \brief Retrieve the default argument, if any.
1205 const TemplateArgumentLoc &getDefaultArgument() const {
1206 return DefaultArgument;
1209 /// \brief Retrieve the location of the default argument, if any.
1210 SourceLocation getDefaultArgumentLoc() const;
1212 /// \brief Determines whether the default argument was inherited
1213 /// from a previous declaration of this template.
1214 bool defaultArgumentWasInherited() const {
1215 return DefaultArgumentWasInherited;
1218 /// \brief Set the default argument for this template parameter, and
1219 /// whether that default argument was inherited from another
1221 void setDefaultArgument(const TemplateArgumentLoc &DefArg, bool Inherited) {
1222 DefaultArgument = DefArg;
1223 DefaultArgumentWasInherited = Inherited;
1226 /// \brief Removes the default argument of this template parameter.
1227 void removeDefaultArgument() {
1228 DefaultArgument = TemplateArgumentLoc();
1229 DefaultArgumentWasInherited = false;
1232 SourceRange getSourceRange() const LLVM_READONLY {
1233 SourceLocation End = getLocation();
1234 if (hasDefaultArgument() && !defaultArgumentWasInherited())
1235 End = getDefaultArgument().getSourceRange().getEnd();
1236 return SourceRange(getTemplateParameters()->getTemplateLoc(), End);
1239 // Implement isa/cast/dyncast/etc.
1240 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1241 static bool classof(const TemplateTemplateParmDecl *D) { return true; }
1242 static bool classofKind(Kind K) { return K == TemplateTemplateParm; }
1244 friend class ASTDeclReader;
1245 friend class ASTDeclWriter;
1248 /// \brief Represents a class template specialization, which refers to
1249 /// a class template with a given set of template arguments.
1251 /// Class template specializations represent both explicit
1252 /// specialization of class templates, as in the example below, and
1253 /// implicit instantiations of class templates.
1256 /// template<typename T> class array;
1259 /// class array<bool> { }; // class template specialization array<bool>
1261 class ClassTemplateSpecializationDecl
1262 : public CXXRecordDecl, public llvm::FoldingSetNode {
1264 /// \brief Structure that stores information about a class template
1265 /// specialization that was instantiated from a class template partial
1267 struct SpecializedPartialSpecialization {
1268 /// \brief The class template partial specialization from which this
1269 /// class template specialization was instantiated.
1270 ClassTemplatePartialSpecializationDecl *PartialSpecialization;
1272 /// \brief The template argument list deduced for the class template
1273 /// partial specialization itself.
1274 TemplateArgumentList *TemplateArgs;
1277 /// \brief The template that this specialization specializes
1278 llvm::PointerUnion<ClassTemplateDecl *, SpecializedPartialSpecialization *>
1279 SpecializedTemplate;
1281 /// \brief Further info for explicit template specialization/instantiation.
1282 struct ExplicitSpecializationInfo {
1283 /// \brief The type-as-written.
1284 TypeSourceInfo *TypeAsWritten;
1285 /// \brief The location of the extern keyword.
1286 SourceLocation ExternLoc;
1287 /// \brief The location of the template keyword.
1288 SourceLocation TemplateKeywordLoc;
1290 ExplicitSpecializationInfo()
1291 : TypeAsWritten(0), ExternLoc(), TemplateKeywordLoc() {}
1294 /// \brief Further info for explicit template specialization/instantiation.
1295 /// Does not apply to implicit specializations.
1296 ExplicitSpecializationInfo *ExplicitInfo;
1298 /// \brief The template arguments used to describe this specialization.
1299 TemplateArgumentList *TemplateArgs;
1301 /// \brief The point where this template was instantiated (if any)
1302 SourceLocation PointOfInstantiation;
1304 /// \brief The kind of specialization this declaration refers to.
1305 /// Really a value of type TemplateSpecializationKind.
1306 unsigned SpecializationKind : 3;
1309 ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK,
1310 DeclContext *DC, SourceLocation StartLoc,
1311 SourceLocation IdLoc,
1312 ClassTemplateDecl *SpecializedTemplate,
1313 const TemplateArgument *Args,
1315 ClassTemplateSpecializationDecl *PrevDecl);
1317 explicit ClassTemplateSpecializationDecl(Kind DK);
1320 static ClassTemplateSpecializationDecl *
1321 Create(ASTContext &Context, TagKind TK, DeclContext *DC,
1322 SourceLocation StartLoc, SourceLocation IdLoc,
1323 ClassTemplateDecl *SpecializedTemplate,
1324 const TemplateArgument *Args,
1326 ClassTemplateSpecializationDecl *PrevDecl);
1327 static ClassTemplateSpecializationDecl *
1328 CreateDeserialized(ASTContext &C, unsigned ID);
1330 virtual void getNameForDiagnostic(std::string &S,
1331 const PrintingPolicy &Policy,
1332 bool Qualified) const;
1334 ClassTemplateSpecializationDecl *getMostRecentDecl() {
1335 CXXRecordDecl *Recent
1336 = cast<CXXRecordDecl>(CXXRecordDecl::getMostRecentDecl());
1337 if (!isa<ClassTemplateSpecializationDecl>(Recent)) {
1338 // FIXME: Does injected class name need to be in the redeclarations chain?
1339 assert(Recent->isInjectedClassName() && Recent->getPreviousDecl());
1340 Recent = Recent->getPreviousDecl();
1342 return cast<ClassTemplateSpecializationDecl>(Recent);
1345 /// \brief Retrieve the template that this specialization specializes.
1346 ClassTemplateDecl *getSpecializedTemplate() const;
1348 /// \brief Retrieve the template arguments of the class template
1350 const TemplateArgumentList &getTemplateArgs() const {
1351 return *TemplateArgs;
1354 /// \brief Determine the kind of specialization that this
1355 /// declaration represents.
1356 TemplateSpecializationKind getSpecializationKind() const {
1357 return static_cast<TemplateSpecializationKind>(SpecializationKind);
1360 bool isExplicitSpecialization() const {
1361 return getSpecializationKind() == TSK_ExplicitSpecialization;
1364 void setSpecializationKind(TemplateSpecializationKind TSK) {
1365 SpecializationKind = TSK;
1368 /// \brief Get the point of instantiation (if any), or null if none.
1369 SourceLocation getPointOfInstantiation() const {
1370 return PointOfInstantiation;
1373 void setPointOfInstantiation(SourceLocation Loc) {
1374 assert(Loc.isValid() && "point of instantiation must be valid!");
1375 PointOfInstantiation = Loc;
1378 /// \brief If this class template specialization is an instantiation of
1379 /// a template (rather than an explicit specialization), return the
1380 /// class template or class template partial specialization from which it
1381 /// was instantiated.
1382 llvm::PointerUnion<ClassTemplateDecl *,
1383 ClassTemplatePartialSpecializationDecl *>
1384 getInstantiatedFrom() const {
1385 if (getSpecializationKind() != TSK_ImplicitInstantiation &&
1386 getSpecializationKind() != TSK_ExplicitInstantiationDefinition &&
1387 getSpecializationKind() != TSK_ExplicitInstantiationDeclaration)
1388 return llvm::PointerUnion<ClassTemplateDecl *,
1389 ClassTemplatePartialSpecializationDecl *>();
1391 if (SpecializedPartialSpecialization *PartialSpec
1392 = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
1393 return PartialSpec->PartialSpecialization;
1395 return const_cast<ClassTemplateDecl*>(
1396 SpecializedTemplate.get<ClassTemplateDecl*>());
1399 /// \brief Retrieve the class template or class template partial
1400 /// specialization which was specialized by this.
1401 llvm::PointerUnion<ClassTemplateDecl *,
1402 ClassTemplatePartialSpecializationDecl *>
1403 getSpecializedTemplateOrPartial() const {
1404 if (SpecializedPartialSpecialization *PartialSpec
1405 = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
1406 return PartialSpec->PartialSpecialization;
1408 return const_cast<ClassTemplateDecl*>(
1409 SpecializedTemplate.get<ClassTemplateDecl*>());
1412 /// \brief Retrieve the set of template arguments that should be used
1413 /// to instantiate members of the class template or class template partial
1414 /// specialization from which this class template specialization was
1417 /// \returns For a class template specialization instantiated from the primary
1418 /// template, this function will return the same template arguments as
1419 /// getTemplateArgs(). For a class template specialization instantiated from
1420 /// a class template partial specialization, this function will return the
1421 /// deduced template arguments for the class template partial specialization
1423 const TemplateArgumentList &getTemplateInstantiationArgs() const {
1424 if (SpecializedPartialSpecialization *PartialSpec
1425 = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
1426 return *PartialSpec->TemplateArgs;
1428 return getTemplateArgs();
1431 /// \brief Note that this class template specialization is actually an
1432 /// instantiation of the given class template partial specialization whose
1433 /// template arguments have been deduced.
1434 void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec,
1435 TemplateArgumentList *TemplateArgs) {
1436 assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() &&
1437 "Already set to a class template partial specialization!");
1438 SpecializedPartialSpecialization *PS
1439 = new (getASTContext()) SpecializedPartialSpecialization();
1440 PS->PartialSpecialization = PartialSpec;
1441 PS->TemplateArgs = TemplateArgs;
1442 SpecializedTemplate = PS;
1445 /// \brief Note that this class template specialization is an instantiation
1446 /// of the given class template.
1447 void setInstantiationOf(ClassTemplateDecl *TemplDecl) {
1448 assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() &&
1449 "Previously set to a class template partial specialization!");
1450 SpecializedTemplate = TemplDecl;
1453 /// \brief Sets the type of this specialization as it was written by
1454 /// the user. This will be a class template specialization type.
1455 void setTypeAsWritten(TypeSourceInfo *T) {
1457 ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
1458 ExplicitInfo->TypeAsWritten = T;
1460 /// \brief Gets the type of this specialization as it was written by
1461 /// the user, if it was so written.
1462 TypeSourceInfo *getTypeAsWritten() const {
1463 return ExplicitInfo ? ExplicitInfo->TypeAsWritten : 0;
1466 /// \brief Gets the location of the extern keyword, if present.
1467 SourceLocation getExternLoc() const {
1468 return ExplicitInfo ? ExplicitInfo->ExternLoc : SourceLocation();
1470 /// \brief Sets the location of the extern keyword.
1471 void setExternLoc(SourceLocation Loc) {
1473 ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
1474 ExplicitInfo->ExternLoc = Loc;
1477 /// \brief Sets the location of the template keyword.
1478 void setTemplateKeywordLoc(SourceLocation Loc) {
1480 ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
1481 ExplicitInfo->TemplateKeywordLoc = Loc;
1483 /// \brief Gets the location of the template keyword, if present.
1484 SourceLocation getTemplateKeywordLoc() const {
1485 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
1488 SourceRange getSourceRange() const LLVM_READONLY;
1490 void Profile(llvm::FoldingSetNodeID &ID) const {
1491 Profile(ID, TemplateArgs->data(), TemplateArgs->size(), getASTContext());
1495 Profile(llvm::FoldingSetNodeID &ID, const TemplateArgument *TemplateArgs,
1496 unsigned NumTemplateArgs, ASTContext &Context) {
1497 ID.AddInteger(NumTemplateArgs);
1498 for (unsigned Arg = 0; Arg != NumTemplateArgs; ++Arg)
1499 TemplateArgs[Arg].Profile(ID, Context);
1502 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1503 static bool classofKind(Kind K) {
1504 return K >= firstClassTemplateSpecialization &&
1505 K <= lastClassTemplateSpecialization;
1508 static bool classof(const ClassTemplateSpecializationDecl *) {
1512 static bool classof(const ClassTemplatePartialSpecializationDecl *) {
1516 friend class ASTDeclReader;
1517 friend class ASTDeclWriter;
1520 class ClassTemplatePartialSpecializationDecl
1521 : public ClassTemplateSpecializationDecl {
1522 virtual void anchor();
1524 /// \brief The list of template parameters
1525 TemplateParameterList* TemplateParams;
1527 /// \brief The source info for the template arguments as written.
1528 /// FIXME: redundant with TypeAsWritten?
1529 TemplateArgumentLoc *ArgsAsWritten;
1530 unsigned NumArgsAsWritten;
1532 /// \brief Sequence number indicating when this class template partial
1533 /// specialization was added to the set of partial specializations for
1534 /// its owning class template.
1535 unsigned SequenceNumber;
1537 /// \brief The class template partial specialization from which this
1538 /// class template partial specialization was instantiated.
1540 /// The boolean value will be true to indicate that this class template
1541 /// partial specialization was specialized at this level.
1542 llvm::PointerIntPair<ClassTemplatePartialSpecializationDecl *, 1, bool>
1543 InstantiatedFromMember;
1545 ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK,
1547 SourceLocation StartLoc,
1548 SourceLocation IdLoc,
1549 TemplateParameterList *Params,
1550 ClassTemplateDecl *SpecializedTemplate,
1551 const TemplateArgument *Args,
1553 TemplateArgumentLoc *ArgInfos,
1554 unsigned NumArgInfos,
1555 ClassTemplatePartialSpecializationDecl *PrevDecl,
1556 unsigned SequenceNumber);
1558 ClassTemplatePartialSpecializationDecl()
1559 : ClassTemplateSpecializationDecl(ClassTemplatePartialSpecialization),
1560 TemplateParams(0), ArgsAsWritten(0),
1561 NumArgsAsWritten(0), SequenceNumber(0),
1562 InstantiatedFromMember(0, false) { }
1565 static ClassTemplatePartialSpecializationDecl *
1566 Create(ASTContext &Context, TagKind TK, DeclContext *DC,
1567 SourceLocation StartLoc, SourceLocation IdLoc,
1568 TemplateParameterList *Params,
1569 ClassTemplateDecl *SpecializedTemplate,
1570 const TemplateArgument *Args,
1572 const TemplateArgumentListInfo &ArgInfos,
1573 QualType CanonInjectedType,
1574 ClassTemplatePartialSpecializationDecl *PrevDecl,
1575 unsigned SequenceNumber);
1577 static ClassTemplatePartialSpecializationDecl *
1578 CreateDeserialized(ASTContext &C, unsigned ID);
1580 ClassTemplatePartialSpecializationDecl *getMostRecentDecl() {
1581 return cast<ClassTemplatePartialSpecializationDecl>(
1582 ClassTemplateSpecializationDecl::getMostRecentDecl());
1585 /// Get the list of template parameters
1586 TemplateParameterList *getTemplateParameters() const {
1587 return TemplateParams;
1590 /// Get the template arguments as written.
1591 TemplateArgumentLoc *getTemplateArgsAsWritten() const {
1592 return ArgsAsWritten;
1595 /// Get the number of template arguments as written.
1596 unsigned getNumTemplateArgsAsWritten() const {
1597 return NumArgsAsWritten;
1600 /// \brief Get the sequence number for this class template partial
1602 unsigned getSequenceNumber() const { return SequenceNumber; }
1604 /// \brief Retrieve the member class template partial specialization from
1605 /// which this particular class template partial specialization was
1609 /// template<typename T>
1611 /// template<typename U> struct Inner;
1612 /// template<typename U> struct Inner<U*> { }; // #1
1615 /// Outer<float>::Inner<int*> ii;
1618 /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
1619 /// end up instantiating the partial specialization
1620 /// \c Outer<float>::Inner<U*>, which itself was instantiated from the class
1621 /// template partial specialization \c Outer<T>::Inner<U*>. Given
1622 /// \c Outer<float>::Inner<U*>, this function would return
1623 /// \c Outer<T>::Inner<U*>.
1624 ClassTemplatePartialSpecializationDecl *getInstantiatedFromMember() {
1625 ClassTemplatePartialSpecializationDecl *First
1626 = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration());
1627 return First->InstantiatedFromMember.getPointer();
1630 void setInstantiatedFromMember(
1631 ClassTemplatePartialSpecializationDecl *PartialSpec) {
1632 ClassTemplatePartialSpecializationDecl *First
1633 = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration());
1634 First->InstantiatedFromMember.setPointer(PartialSpec);
1637 /// \brief Determines whether this class template partial specialization
1638 /// template was a specialization of a member partial specialization.
1640 /// In the following example, the member template partial specialization
1641 /// \c X<int>::Inner<T*> is a member specialization.
1644 /// template<typename T>
1646 /// template<typename U> struct Inner;
1647 /// template<typename U> struct Inner<U*>;
1650 /// template<> template<typename T>
1651 /// struct X<int>::Inner<T*> { /* ... */ };
1653 bool isMemberSpecialization() {
1654 ClassTemplatePartialSpecializationDecl *First
1655 = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration());
1656 return First->InstantiatedFromMember.getInt();
1659 /// \brief Note that this member template is a specialization.
1660 void setMemberSpecialization() {
1661 ClassTemplatePartialSpecializationDecl *First
1662 = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration());
1663 assert(First->InstantiatedFromMember.getPointer() &&
1664 "Only member templates can be member template specializations");
1665 return First->InstantiatedFromMember.setInt(true);
1668 /// Retrieves the injected specialization type for this partial
1669 /// specialization. This is not the same as the type-decl-type for
1670 /// this partial specialization, which is an InjectedClassNameType.
1671 QualType getInjectedSpecializationType() const {
1672 assert(getTypeForDecl() && "partial specialization has no type set!");
1673 return cast<InjectedClassNameType>(getTypeForDecl())
1674 ->getInjectedSpecializationType();
1677 // FIXME: Add Profile support!
1679 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1680 static bool classofKind(Kind K) {
1681 return K == ClassTemplatePartialSpecialization;
1684 static bool classof(const ClassTemplatePartialSpecializationDecl *) {
1688 friend class ASTDeclReader;
1689 friend class ASTDeclWriter;
1692 /// Declaration of a class template.
1693 class ClassTemplateDecl : public RedeclarableTemplateDecl {
1694 static void DeallocateCommon(void *Ptr);
1697 /// \brief Data that is common to all of the declarations of a given
1699 struct Common : CommonBase {
1700 Common() : LazySpecializations() { }
1702 /// \brief The class template specializations for this class
1703 /// template, including explicit specializations and instantiations.
1704 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> Specializations;
1706 /// \brief The class template partial specializations for this class
1708 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>
1709 PartialSpecializations;
1711 /// \brief The injected-class-name type for this class template.
1712 QualType InjectedClassNameType;
1714 /// \brief If non-null, points to an array of specializations (including
1715 /// partial specializations) known ownly by their external declaration IDs.
1717 /// The first value in the array is the number of of specializations/
1718 /// partial specializations that follow.
1719 uint32_t *LazySpecializations;
1722 /// \brief Load any lazily-loaded specializations from the external source.
1723 void LoadLazySpecializations();
1725 /// \brief Retrieve the set of specializations of this class template.
1726 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &getSpecializations();
1728 /// \brief Retrieve the set of partial specializations of this class
1730 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
1731 getPartialSpecializations();
1733 ClassTemplateDecl(DeclContext *DC, SourceLocation L, DeclarationName Name,
1734 TemplateParameterList *Params, NamedDecl *Decl)
1735 : RedeclarableTemplateDecl(ClassTemplate, DC, L, Name, Params, Decl) { }
1737 ClassTemplateDecl(EmptyShell Empty)
1738 : RedeclarableTemplateDecl(ClassTemplate, 0, SourceLocation(),
1739 DeclarationName(), 0, 0) { }
1741 CommonBase *newCommon(ASTContext &C);
1743 Common *getCommonPtr() {
1744 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
1748 /// \brief Get the underlying class declarations of the template.
1749 CXXRecordDecl *getTemplatedDecl() const {
1750 return static_cast<CXXRecordDecl *>(TemplatedDecl);
1753 /// \brief Returns whether this template declaration defines the primary
1755 bool isThisDeclarationADefinition() const {
1756 return getTemplatedDecl()->isThisDeclarationADefinition();
1759 /// \brief Create a class template node.
1760 static ClassTemplateDecl *Create(ASTContext &C, DeclContext *DC,
1762 DeclarationName Name,
1763 TemplateParameterList *Params,
1765 ClassTemplateDecl *PrevDecl);
1767 /// \brief Create an empty class template node.
1768 static ClassTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1770 /// \brief Return the specialization with the provided arguments if it exists,
1771 /// otherwise return the insertion point.
1772 ClassTemplateSpecializationDecl *
1773 findSpecialization(const TemplateArgument *Args, unsigned NumArgs,
1776 /// \brief Insert the specified specialization knowing that it is not already
1777 /// in. InsertPos must be obtained from findSpecialization.
1778 void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos);
1780 ClassTemplateDecl *getCanonicalDecl() {
1781 return cast<ClassTemplateDecl>(
1782 RedeclarableTemplateDecl::getCanonicalDecl());
1784 const ClassTemplateDecl *getCanonicalDecl() const {
1785 return cast<ClassTemplateDecl>(
1786 RedeclarableTemplateDecl::getCanonicalDecl());
1789 /// \brief Retrieve the previous declaration of this class template, or
1790 /// NULL if no such declaration exists.
1791 ClassTemplateDecl *getPreviousDecl() {
1792 return cast_or_null<ClassTemplateDecl>(
1793 RedeclarableTemplateDecl::getPreviousDecl());
1796 /// \brief Retrieve the previous declaration of this class template, or
1797 /// NULL if no such declaration exists.
1798 const ClassTemplateDecl *getPreviousDecl() const {
1799 return cast_or_null<ClassTemplateDecl>(
1800 RedeclarableTemplateDecl::getPreviousDecl());
1803 ClassTemplateDecl *getInstantiatedFromMemberTemplate() {
1804 return cast_or_null<ClassTemplateDecl>(
1805 RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate());
1808 /// \brief Return the partial specialization with the provided arguments if it
1809 /// exists, otherwise return the insertion point.
1810 ClassTemplatePartialSpecializationDecl *
1811 findPartialSpecialization(const TemplateArgument *Args, unsigned NumArgs,
1814 /// \brief Insert the specified partial specialization knowing that it is not
1815 /// already in. InsertPos must be obtained from findPartialSpecialization.
1816 void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D,
1819 /// \brief Return the next partial specialization sequence number.
1820 unsigned getNextPartialSpecSequenceNumber() {
1821 return getPartialSpecializations().size();
1824 /// \brief Retrieve the partial specializations as an ordered list.
1825 void getPartialSpecializations(
1826 SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS);
1828 /// \brief Find a class template partial specialization with the given
1831 /// \param T a dependent type that names a specialization of this class
1834 /// \returns the class template partial specialization that exactly matches
1835 /// the type \p T, or NULL if no such partial specialization exists.
1836 ClassTemplatePartialSpecializationDecl *findPartialSpecialization(QualType T);
1838 /// \brief Find a class template partial specialization which was instantiated
1839 /// from the given member partial specialization.
1841 /// \param D a member class template partial specialization.
1843 /// \returns the class template partial specialization which was instantiated
1844 /// from the given member partial specialization, or NULL if no such partial
1845 /// specialization exists.
1846 ClassTemplatePartialSpecializationDecl *
1847 findPartialSpecInstantiatedFromMember(
1848 ClassTemplatePartialSpecializationDecl *D);
1850 /// \brief Retrieve the template specialization type of the
1851 /// injected-class-name for this class template.
1853 /// The injected-class-name for a class template \c X is \c
1854 /// X<template-args>, where \c template-args is formed from the
1855 /// template arguments that correspond to the template parameters of
1856 /// \c X. For example:
1859 /// template<typename T, int N>
1861 /// typedef array this_type; // "array" is equivalent to "array<T, N>"
1864 QualType getInjectedClassNameSpecialization();
1866 typedef SpecIterator<ClassTemplateSpecializationDecl> spec_iterator;
1868 spec_iterator spec_begin() {
1869 return makeSpecIterator(getSpecializations(), false);
1872 spec_iterator spec_end() {
1873 return makeSpecIterator(getSpecializations(), true);
1876 typedef SpecIterator<ClassTemplatePartialSpecializationDecl>
1877 partial_spec_iterator;
1879 partial_spec_iterator partial_spec_begin() {
1880 return makeSpecIterator(getPartialSpecializations(), false);
1883 partial_spec_iterator partial_spec_end() {
1884 return makeSpecIterator(getPartialSpecializations(), true);
1887 // Implement isa/cast/dyncast support
1888 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1889 static bool classof(const ClassTemplateDecl *D) { return true; }
1890 static bool classofKind(Kind K) { return K == ClassTemplate; }
1892 friend class ASTDeclReader;
1893 friend class ASTDeclWriter;
1896 /// \brief Declaration of a friend template.
1900 /// template \<typename T> class A {
1901 /// friend class MyVector<T>; // not a friend template
1902 /// template \<typename U> friend class B; // not a friend template
1903 /// template \<typename U> friend class Foo<T>::Nested; // friend template
1907 /// \note This class is not currently in use. All of the above
1908 /// will yield a FriendDecl, not a FriendTemplateDecl.
1909 class FriendTemplateDecl : public Decl {
1910 virtual void anchor();
1912 typedef llvm::PointerUnion<NamedDecl*,TypeSourceInfo*> FriendUnion;
1915 // The number of template parameters; always non-zero.
1918 // The parameter list.
1919 TemplateParameterList **Params;
1921 // The declaration that's a friend of this class.
1924 // Location of the 'friend' specifier.
1925 SourceLocation FriendLoc;
1928 FriendTemplateDecl(DeclContext *DC, SourceLocation Loc,
1930 TemplateParameterList **Params,
1932 SourceLocation FriendLoc)
1933 : Decl(Decl::FriendTemplate, DC, Loc),
1937 FriendLoc(FriendLoc)
1940 FriendTemplateDecl(EmptyShell Empty)
1941 : Decl(Decl::FriendTemplate, Empty),
1947 static FriendTemplateDecl *Create(ASTContext &Context,
1948 DeclContext *DC, SourceLocation Loc,
1950 TemplateParameterList **Params,
1952 SourceLocation FriendLoc);
1954 static FriendTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1956 /// If this friend declaration names a templated type (or
1957 /// a dependent member type of a templated type), return that
1958 /// type; otherwise return null.
1959 TypeSourceInfo *getFriendType() const {
1960 return Friend.dyn_cast<TypeSourceInfo*>();
1963 /// If this friend declaration names a templated function (or
1964 /// a member function of a templated type), return that type;
1965 /// otherwise return null.
1966 NamedDecl *getFriendDecl() const {
1967 return Friend.dyn_cast<NamedDecl*>();
1970 /// \brief Retrieves the location of the 'friend' keyword.
1971 SourceLocation getFriendLoc() const {
1975 TemplateParameterList *getTemplateParameterList(unsigned i) const {
1976 assert(i <= NumParams);
1980 unsigned getNumTemplateParameters() const {
1984 // Implement isa/cast/dyncast/etc.
1985 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1986 static bool classofKind(Kind K) { return K == Decl::FriendTemplate; }
1987 static bool classof(const FriendTemplateDecl *D) { return true; }
1989 friend class ASTDeclReader;
1992 /// \brief Declaration of an alias template.
1996 /// template \<typename T> using V = std::map<T*, int, MyCompare<T>>;
1998 class TypeAliasTemplateDecl : public RedeclarableTemplateDecl {
1999 static void DeallocateCommon(void *Ptr);
2002 typedef CommonBase Common;
2004 TypeAliasTemplateDecl(DeclContext *DC, SourceLocation L, DeclarationName Name,
2005 TemplateParameterList *Params, NamedDecl *Decl)
2006 : RedeclarableTemplateDecl(TypeAliasTemplate, DC, L, Name, Params, Decl) { }
2008 CommonBase *newCommon(ASTContext &C);
2010 Common *getCommonPtr() {
2011 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2015 /// Get the underlying function declaration of the template.
2016 TypeAliasDecl *getTemplatedDecl() const {
2017 return static_cast<TypeAliasDecl*>(TemplatedDecl);
2021 TypeAliasTemplateDecl *getCanonicalDecl() {
2022 return cast<TypeAliasTemplateDecl>(
2023 RedeclarableTemplateDecl::getCanonicalDecl());
2025 const TypeAliasTemplateDecl *getCanonicalDecl() const {
2026 return cast<TypeAliasTemplateDecl>(
2027 RedeclarableTemplateDecl::getCanonicalDecl());
2030 /// \brief Retrieve the previous declaration of this function template, or
2031 /// NULL if no such declaration exists.
2032 TypeAliasTemplateDecl *getPreviousDecl() {
2033 return cast_or_null<TypeAliasTemplateDecl>(
2034 RedeclarableTemplateDecl::getPreviousDecl());
2037 /// \brief Retrieve the previous declaration of this function template, or
2038 /// NULL if no such declaration exists.
2039 const TypeAliasTemplateDecl *getPreviousDecl() const {
2040 return cast_or_null<TypeAliasTemplateDecl>(
2041 RedeclarableTemplateDecl::getPreviousDecl());
2044 TypeAliasTemplateDecl *getInstantiatedFromMemberTemplate() {
2045 return cast_or_null<TypeAliasTemplateDecl>(
2046 RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate());
2050 /// \brief Create a function template node.
2051 static TypeAliasTemplateDecl *Create(ASTContext &C, DeclContext *DC,
2053 DeclarationName Name,
2054 TemplateParameterList *Params,
2057 /// \brief Create an empty alias template node.
2058 static TypeAliasTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2060 // Implement isa/cast/dyncast support
2061 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2062 static bool classof(const TypeAliasTemplateDecl *D) { return true; }
2063 static bool classofKind(Kind K) { return K == TypeAliasTemplate; }
2065 friend class ASTDeclReader;
2066 friend class ASTDeclWriter;
2069 /// \brief Declaration of a function specialization at template class scope.
2071 /// This is a non standard extension needed to support MSVC.
2075 /// template <class T>
2077 /// template <class U> void foo(U a) { }
2078 /// template<> void foo(int a) { }
2082 /// "template<> foo(int a)" will be saved in Specialization as a normal
2083 /// CXXMethodDecl. Then during an instantiation of class A, it will be
2084 /// transformed into an actual function specialization.
2085 class ClassScopeFunctionSpecializationDecl : public Decl {
2086 virtual void anchor();
2088 ClassScopeFunctionSpecializationDecl(DeclContext *DC, SourceLocation Loc,
2089 CXXMethodDecl *FD, bool Args,
2090 TemplateArgumentListInfo TemplArgs)
2091 : Decl(Decl::ClassScopeFunctionSpecialization, DC, Loc),
2092 Specialization(FD), HasExplicitTemplateArgs(Args),
2093 TemplateArgs(TemplArgs) {}
2095 ClassScopeFunctionSpecializationDecl(EmptyShell Empty)
2096 : Decl(Decl::ClassScopeFunctionSpecialization, Empty) {}
2098 CXXMethodDecl *Specialization;
2099 bool HasExplicitTemplateArgs;
2100 TemplateArgumentListInfo TemplateArgs;
2103 CXXMethodDecl *getSpecialization() const { return Specialization; }
2104 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
2105 const TemplateArgumentListInfo& templateArgs() const { return TemplateArgs; }
2107 static ClassScopeFunctionSpecializationDecl *Create(ASTContext &C,
2111 bool HasExplicitTemplateArgs,
2112 TemplateArgumentListInfo TemplateArgs) {
2113 return new (C) ClassScopeFunctionSpecializationDecl(DC , Loc, FD,
2114 HasExplicitTemplateArgs,
2118 static ClassScopeFunctionSpecializationDecl *
2119 CreateDeserialized(ASTContext &Context, unsigned ID);
2121 // Implement isa/cast/dyncast/etc.
2122 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2123 static bool classofKind(Kind K) {
2124 return K == Decl::ClassScopeFunctionSpecialization;
2126 static bool classof(const ClassScopeFunctionSpecializationDecl *D) {
2130 friend class ASTDeclReader;
2131 friend class ASTDeclWriter;
2134 /// Implementation of inline functions that require the template declarations
2135 inline AnyFunctionDecl::AnyFunctionDecl(FunctionTemplateDecl *FTD)
2138 } /* end of namespace clang */