DeclTemplate.h revision 200583
1//===-- DeclTemplate.h - Classes for representing C++ templates -*- 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 C++ template declaration subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_DECLTEMPLATE_H
15#define LLVM_CLANG_AST_DECLTEMPLATE_H
16
17#include "clang/AST/DeclCXX.h"
18#include "clang/AST/TemplateBase.h"
19#include "llvm/ADT/PointerUnion.h"
20#include <limits>
21
22namespace clang {
23
24class TemplateParameterList;
25class TemplateDecl;
26class FunctionTemplateDecl;
27class ClassTemplateDecl;
28class ClassTemplatePartialSpecializationDecl;
29class TemplateTypeParmDecl;
30class NonTypeTemplateParmDecl;
31class TemplateTemplateParmDecl;
32
33/// \brief Stores a template parameter of any kind.
34typedef llvm::PointerUnion3<TemplateTypeParmDecl*, NonTypeTemplateParmDecl*,
35                            TemplateTemplateParmDecl*> TemplateParameter;
36
37/// TemplateParameterList - Stores a list of template parameters for a
38/// TemplateDecl and its derived classes.
39class TemplateParameterList {
40  /// The location of the 'template' keyword.
41  SourceLocation TemplateLoc;
42
43  /// The locations of the '<' and '>' angle brackets.
44  SourceLocation LAngleLoc, RAngleLoc;
45
46  /// The number of template parameters in this template
47  /// parameter list.
48  unsigned NumParams;
49
50  TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc,
51                        NamedDecl **Params, unsigned NumParams,
52                        SourceLocation RAngleLoc);
53
54public:
55  static TemplateParameterList *Create(ASTContext &C,
56                                       SourceLocation TemplateLoc,
57                                       SourceLocation LAngleLoc,
58                                       NamedDecl **Params,
59                                       unsigned NumParams,
60                                       SourceLocation RAngleLoc);
61
62  /// iterator - Iterates through the template parameters in this list.
63  typedef NamedDecl** iterator;
64
65  /// const_iterator - Iterates through the template parameters in this list.
66  typedef NamedDecl* const* const_iterator;
67
68  iterator begin() { return reinterpret_cast<NamedDecl **>(this + 1); }
69  const_iterator begin() const {
70    return reinterpret_cast<NamedDecl * const *>(this + 1);
71  }
72  iterator end() { return begin() + NumParams; }
73  const_iterator end() const { return begin() + NumParams; }
74
75  unsigned size() const { return NumParams; }
76
77  NamedDecl* getParam(unsigned Idx) {
78    assert(Idx < size() && "Template parameter index out-of-range");
79    return begin()[Idx];
80  }
81
82  const NamedDecl* getParam(unsigned Idx) const {
83    assert(Idx < size() && "Template parameter index out-of-range");
84    return begin()[Idx];
85  }
86
87  /// \btief Returns the minimum number of arguments needed to form a
88  /// template specialization. This may be fewer than the number of
89  /// template parameters, if some of the parameters have default
90  /// arguments or if there is a parameter pack.
91  unsigned getMinRequiredArguments() const;
92
93  /// \brief Get the depth of this template parameter list in the set of
94  /// template parameter lists.
95  ///
96  /// The first template parameter list in a declaration will have depth 0,
97  /// the second template parameter list will have depth 1, etc.
98  unsigned getDepth() const;
99
100  SourceLocation getTemplateLoc() const { return TemplateLoc; }
101  SourceLocation getLAngleLoc() const { return LAngleLoc; }
102  SourceLocation getRAngleLoc() const { return RAngleLoc; }
103
104  SourceRange getSourceRange() const {
105    return SourceRange(TemplateLoc, RAngleLoc);
106  }
107};
108
109/// \brief A helper class for making template argument lists.
110class TemplateArgumentListBuilder {
111  TemplateArgument *StructuredArgs;
112  unsigned MaxStructuredArgs;
113  unsigned NumStructuredArgs;
114
115  TemplateArgument *FlatArgs;
116  unsigned MaxFlatArgs;
117  unsigned NumFlatArgs;
118
119  bool AddingToPack;
120  unsigned PackBeginIndex;
121
122public:
123  TemplateArgumentListBuilder(const TemplateParameterList *Parameters,
124                              unsigned NumTemplateArgs)
125  : StructuredArgs(0), MaxStructuredArgs(Parameters->size()),
126  NumStructuredArgs(0), FlatArgs(0),
127  MaxFlatArgs(std::max(MaxStructuredArgs, NumTemplateArgs)), NumFlatArgs(0),
128  AddingToPack(false), PackBeginIndex(0) { }
129
130  void Append(const TemplateArgument& Arg);
131  void BeginPack();
132  void EndPack();
133
134  void ReleaseArgs();
135
136  unsigned flatSize() const {
137    return NumFlatArgs;
138  }
139  const TemplateArgument *getFlatArguments() const {
140    return FlatArgs;
141  }
142
143  unsigned structuredSize() const {
144    // If we don't have any structured args, just reuse the flat size.
145    if (!StructuredArgs)
146      return flatSize();
147
148    return NumStructuredArgs;
149  }
150  const TemplateArgument *getStructuredArguments() const {
151    // If we don't have any structured args, just reuse the flat args.
152    if (!StructuredArgs)
153      return getFlatArguments();
154
155    return StructuredArgs;
156  }
157};
158
159/// \brief A template argument list.
160///
161/// FIXME: In the future, this class will be extended to support
162/// variadic templates and member templates, which will make some of
163/// the function names below make more sense.
164class TemplateArgumentList {
165  /// \brief The template argument list.
166  ///
167  /// The integer value will be non-zero to indicate that this
168  /// template argument list does not own the pointer.
169  llvm::PointerIntPair<const TemplateArgument *, 1> FlatArguments;
170
171  /// \brief The number of template arguments in this template
172  /// argument list.
173  unsigned NumFlatArguments;
174
175  llvm::PointerIntPair<const TemplateArgument *, 1> StructuredArguments;
176  unsigned NumStructuredArguments;
177
178public:
179  TemplateArgumentList(ASTContext &Context,
180                       TemplateArgumentListBuilder &Builder,
181                       bool TakeArgs);
182
183  /// \brief Produces a shallow copy of the given template argument list
184  TemplateArgumentList(const TemplateArgumentList &Other);
185
186  ~TemplateArgumentList();
187
188  /// \brief Retrieve the template argument at a given index.
189  const TemplateArgument &get(unsigned Idx) const {
190    assert(Idx < NumFlatArguments && "Invalid template argument index");
191    return getFlatArgumentList()[Idx];
192  }
193
194  /// \brief Retrieve the template argument at a given index.
195  const TemplateArgument &operator[](unsigned Idx) const { return get(Idx); }
196
197  /// \brief Retrieve the number of template arguments in this
198  /// template argument list.
199  unsigned size() const { return NumFlatArguments; }
200
201  /// \brief Retrieve the number of template arguments in the
202  /// flattened template argument list.
203  unsigned flat_size() const { return NumFlatArguments; }
204
205  /// \brief Retrieve the flattened template argument list.
206  const TemplateArgument *getFlatArgumentList() const {
207    return FlatArguments.getPointer();
208  }
209};
210
211//===----------------------------------------------------------------------===//
212// Kinds of Templates
213//===----------------------------------------------------------------------===//
214
215/// TemplateDecl - The base class of all kinds of template declarations (e.g.,
216/// class, function, etc.). The TemplateDecl class stores the list of template
217/// parameters and a reference to the templated scoped declaration: the
218/// underlying AST node.
219class TemplateDecl : public NamedDecl {
220protected:
221  // This is probably never used.
222  TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L,
223               DeclarationName Name)
224    : NamedDecl(DK, DC, L, Name), TemplatedDecl(0), TemplateParams(0) { }
225
226  // Construct a template decl with the given name and parameters.
227  // Used when there is not templated element (tt-params, alias?).
228  TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L,
229               DeclarationName Name, TemplateParameterList *Params)
230    : NamedDecl(DK, DC, L, Name), TemplatedDecl(0), TemplateParams(Params) { }
231
232  // Construct a template decl with name, parameters, and templated element.
233  TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L,
234               DeclarationName Name, TemplateParameterList *Params,
235               NamedDecl *Decl)
236    : NamedDecl(DK, DC, L, Name), TemplatedDecl(Decl),
237      TemplateParams(Params) { }
238public:
239  ~TemplateDecl();
240
241  /// Get the list of template parameters
242  TemplateParameterList *getTemplateParameters() const {
243    return TemplateParams;
244  }
245
246  /// Get the underlying, templated declaration.
247  NamedDecl *getTemplatedDecl() const { return TemplatedDecl; }
248
249  // Implement isa/cast/dyncast/etc.
250  static bool classof(const Decl *D) {
251      return D->getKind() >= TemplateFirst && D->getKind() <= TemplateLast;
252  }
253  static bool classof(const TemplateDecl *D) { return true; }
254  static bool classof(const FunctionTemplateDecl *D) { return true; }
255  static bool classof(const ClassTemplateDecl *D) { return true; }
256  static bool classof(const TemplateTemplateParmDecl *D) { return true; }
257
258protected:
259  NamedDecl *TemplatedDecl;
260  TemplateParameterList* TemplateParams;
261};
262
263/// \brief Provides information about a function template specialization,
264/// which is a FunctionDecl that has been explicitly specialization or
265/// instantiated from a function template.
266class FunctionTemplateSpecializationInfo : public llvm::FoldingSetNode {
267public:
268  /// \brief The function template specialization that this structure
269  /// describes.
270  FunctionDecl *Function;
271
272  /// \brief The function template from which this function template
273  /// specialization was generated.
274  ///
275  /// The two bits are contain the top 4 values of TemplateSpecializationKind.
276  llvm::PointerIntPair<FunctionTemplateDecl *, 2> Template;
277
278  /// \brief The template arguments used to produce the function template
279  /// specialization from the function template.
280  const TemplateArgumentList *TemplateArguments;
281
282  /// \brief The point at which this function template specialization was
283  /// first instantiated.
284  SourceLocation PointOfInstantiation;
285
286  /// \brief Retrieve the template from which this function was specialized.
287  FunctionTemplateDecl *getTemplate() const { return Template.getPointer(); }
288
289  /// \brief Determine what kind of template specialization this is.
290  TemplateSpecializationKind getTemplateSpecializationKind() const {
291    return (TemplateSpecializationKind)(Template.getInt() + 1);
292  }
293
294  /// \brief Set the template specialization kind.
295  void setTemplateSpecializationKind(TemplateSpecializationKind TSK) {
296    assert(TSK != TSK_Undeclared &&
297         "Cannot encode TSK_Undeclared for a function template specialization");
298    Template.setInt(TSK - 1);
299  }
300
301  /// \brief Retrieve the first point of instantiation of this function
302  /// template specialization.
303  ///
304  /// The point of instantiation may be an invalid source location if this
305  /// function has yet to be instantiated.
306  SourceLocation getPointOfInstantiation() const {
307    return PointOfInstantiation;
308  }
309
310  /// \brief Set the (first) point of instantiation of this function template
311  /// specialization.
312  void setPointOfInstantiation(SourceLocation POI) {
313    PointOfInstantiation = POI;
314  }
315
316  void Profile(llvm::FoldingSetNodeID &ID) {
317    Profile(ID, TemplateArguments->getFlatArgumentList(),
318            TemplateArguments->flat_size(),
319            Function->getASTContext());
320  }
321
322  static void
323  Profile(llvm::FoldingSetNodeID &ID, const TemplateArgument *TemplateArgs,
324          unsigned NumTemplateArgs, ASTContext &Context) {
325    ID.AddInteger(NumTemplateArgs);
326    for (unsigned Arg = 0; Arg != NumTemplateArgs; ++Arg)
327      TemplateArgs[Arg].Profile(ID, Context);
328  }
329};
330
331/// \brief Provides information a specialization of a member of a class
332/// template, which may be a member function, static data member, or
333/// member class.
334class MemberSpecializationInfo {
335  // The member declaration from which this member was instantiated, and the
336  // manner in which the instantiation occurred (in the lower two bits).
337  llvm::PointerIntPair<NamedDecl *, 2> MemberAndTSK;
338
339  // The point at which this member was first instantiated.
340  SourceLocation PointOfInstantiation;
341
342public:
343  explicit
344  MemberSpecializationInfo(NamedDecl *IF, TemplateSpecializationKind TSK)
345    : MemberAndTSK(IF, TSK - 1), PointOfInstantiation() {
346    assert(TSK != TSK_Undeclared &&
347           "Cannot encode undeclared template specializations for members");
348  }
349
350  /// \brief Retrieve the member declaration from which this member was
351  /// instantiated.
352  NamedDecl *getInstantiatedFrom() const { return MemberAndTSK.getPointer(); }
353
354  /// \brief Determine what kind of template specialization this is.
355  TemplateSpecializationKind getTemplateSpecializationKind() const {
356    return (TemplateSpecializationKind)(MemberAndTSK.getInt() + 1);
357  }
358
359  /// \brief Set the template specialization kind.
360  void setTemplateSpecializationKind(TemplateSpecializationKind TSK) {
361    assert(TSK != TSK_Undeclared &&
362           "Cannot encode undeclared template specializations for members");
363    MemberAndTSK.setInt(TSK - 1);
364  }
365
366  /// \brief Retrieve the first point of instantiation of this member.
367  /// If the point of instantiation is an invalid location, then this member
368  /// has not yet been instantiated.
369  SourceLocation getPointOfInstantiation() const {
370    return PointOfInstantiation;
371  }
372
373  /// \brief Set the first point of instantiation.
374  void setPointOfInstantiation(SourceLocation POI) {
375    PointOfInstantiation = POI;
376  }
377};
378
379/// Declaration of a template function.
380class FunctionTemplateDecl : public TemplateDecl {
381protected:
382  /// \brief Data that is common to all of the declarations of a given
383  /// function template.
384  struct Common {
385    Common() : InstantiatedFromMember(0, false) { }
386
387    /// \brief The function template specializations for this function
388    /// template, including explicit specializations and instantiations.
389    llvm::FoldingSet<FunctionTemplateSpecializationInfo> Specializations;
390
391    /// \brief The member function template from which this was most
392    /// directly instantiated (or null).
393    ///
394    /// The boolean value indicates whether this member function template
395    /// was explicitly specialized.
396    llvm::PointerIntPair<FunctionTemplateDecl*, 1, bool> InstantiatedFromMember;
397  };
398
399  /// \brief A pointer to the previous declaration (if this is a redeclaration)
400  /// or to the data that is common to all declarations of this function
401  /// template.
402  llvm::PointerUnion<Common*, FunctionTemplateDecl*> CommonOrPrev;
403
404  /// \brief Retrieves the "common" pointer shared by all
405  /// (re-)declarations of the same function template. Calling this routine
406  /// may implicitly allocate memory for the common pointer.
407  Common *getCommonPtr();
408
409  FunctionTemplateDecl(DeclContext *DC, SourceLocation L, DeclarationName Name,
410                       TemplateParameterList *Params, NamedDecl *Decl)
411    : TemplateDecl(FunctionTemplate, DC, L, Name, Params, Decl),
412      CommonOrPrev((Common*)0) { }
413
414public:
415  void Destroy(ASTContext &C);
416
417  /// Get the underlying function declaration of the template.
418  FunctionDecl *getTemplatedDecl() const {
419    return static_cast<FunctionDecl*>(TemplatedDecl);
420  }
421
422  /// \brief Retrieve the set of function template specializations of this
423  /// function template.
424  llvm::FoldingSet<FunctionTemplateSpecializationInfo> &getSpecializations() {
425    return getCommonPtr()->Specializations;
426  }
427
428  /// \brief Retrieve the previous declaration of this function template, or
429  /// NULL if no such declaration exists.
430  const FunctionTemplateDecl *getPreviousDeclaration() const {
431    return CommonOrPrev.dyn_cast<FunctionTemplateDecl*>();
432  }
433
434  /// \brief Retrieve the previous declaration of this function template, or
435  /// NULL if no such declaration exists.
436  FunctionTemplateDecl *getPreviousDeclaration() {
437    return CommonOrPrev.dyn_cast<FunctionTemplateDecl*>();
438  }
439
440  /// \brief Set the previous declaration of this function template.
441  void setPreviousDeclaration(FunctionTemplateDecl *Prev) {
442    if (Prev)
443      CommonOrPrev = Prev;
444  }
445
446  virtual FunctionTemplateDecl *getCanonicalDecl();
447
448  /// \brief Retrieve the member function template that this function template
449  /// was instantiated from.
450  ///
451  /// This routine will return non-NULL for member function templates of
452  /// class templates.  For example, given:
453  ///
454  /// \code
455  /// template <typename T>
456  /// struct X {
457  ///   template <typename U> void f();
458  /// };
459  /// \endcode
460  ///
461  /// X<int>::A<float> is a CXXMethodDecl (whose parent is X<int>, a
462  /// ClassTemplateSpecializationDecl) for which getPrimaryTemplate() will
463  /// return X<int>::f, a FunctionTemplateDecl (whose parent is again
464  /// X<int>) for which getInstantiatedFromMemberTemplate() will return
465  /// X<T>::f, a FunctionTemplateDecl (whose parent is X<T>, a
466  /// ClassTemplateDecl).
467  ///
468  /// \returns NULL if this is not an instantiation of a member function
469  /// template.
470  FunctionTemplateDecl *getInstantiatedFromMemberTemplate() {
471    return getCommonPtr()->InstantiatedFromMember.getPointer();
472  }
473
474  void setInstantiatedFromMemberTemplate(FunctionTemplateDecl *FTD) {
475    assert(!getCommonPtr()->InstantiatedFromMember.getPointer());
476    getCommonPtr()->InstantiatedFromMember.setPointer(FTD);
477  }
478
479  /// \brief Determines whether this template was a specialization of a
480  /// member template.
481  ///
482  /// In the following example, the function template \c X<int>::f is a
483  /// member specialization.
484  ///
485  /// \code
486  /// template<typename T>
487  /// struct X {
488  ///   template<typename U> void f(T, U);
489  /// };
490  ///
491  /// template<> template<typename T>
492  /// void X<int>::f(int, T);
493  /// \endcode
494  bool isMemberSpecialization() {
495    return getCommonPtr()->InstantiatedFromMember.getInt();
496  }
497
498  /// \brief Note that this member template is a specialization.
499  void setMemberSpecialization() {
500    assert(getCommonPtr()->InstantiatedFromMember.getPointer() &&
501           "Only member templates can be member template specializations");
502    getCommonPtr()->InstantiatedFromMember.setInt(true);
503  }
504
505  /// Create a template function node.
506  static FunctionTemplateDecl *Create(ASTContext &C, DeclContext *DC,
507                                      SourceLocation L,
508                                      DeclarationName Name,
509                                      TemplateParameterList *Params,
510                                      NamedDecl *Decl);
511
512  // Implement isa/cast/dyncast support
513  static bool classof(const Decl *D)
514  { return D->getKind() == FunctionTemplate; }
515  static bool classof(const FunctionTemplateDecl *D)
516  { return true; }
517};
518
519//===----------------------------------------------------------------------===//
520// Kinds of Template Parameters
521//===----------------------------------------------------------------------===//
522
523/// The TemplateParmPosition class defines the position of a template parameter
524/// within a template parameter list. Because template parameter can be listed
525/// sequentially for out-of-line template members, each template parameter is
526/// given a Depth - the nesting of template parameter scopes - and a Position -
527/// the occurrence within the parameter list.
528/// This class is inheritedly privately by different kinds of template
529/// parameters and is not part of the Decl hierarchy. Just a facility.
530class TemplateParmPosition {
531protected:
532  // FIXME: This should probably never be called, but it's here as
533  TemplateParmPosition()
534    : Depth(0), Position(0)
535  { /* assert(0 && "Cannot create positionless template parameter"); */ }
536
537  TemplateParmPosition(unsigned D, unsigned P)
538    : Depth(D), Position(P)
539  { }
540
541  // FIXME: These probably don't need to be ints. int:5 for depth, int:8 for
542  // position? Maybe?
543  unsigned Depth;
544  unsigned Position;
545
546public:
547  /// Get the nesting depth of the template parameter.
548  unsigned getDepth() const { return Depth; }
549
550  /// Get the position of the template parameter within its parameter list.
551  unsigned getPosition() const { return Position; }
552
553  /// Get the index of the template parameter within its parameter list.
554  unsigned getIndex() const { return Position; }
555};
556
557/// TemplateTypeParmDecl - Declaration of a template type parameter,
558/// e.g., "T" in
559/// @code
560/// template<typename T> class vector;
561/// @endcode
562class TemplateTypeParmDecl : public TypeDecl {
563  /// \brief Whether this template type parameter was declaration with
564  /// the 'typename' keyword. If false, it was declared with the
565  /// 'class' keyword.
566  bool Typename : 1;
567
568  /// \brief Whether this template type parameter inherited its
569  /// default argument.
570  bool InheritedDefault : 1;
571
572  /// \brief Whether this is a parameter pack.
573  bool ParameterPack : 1;
574
575  /// \brief The default template argument, if any.
576  TypeSourceInfo *DefaultArgument;
577
578  TemplateTypeParmDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
579                       bool Typename, QualType Type, bool ParameterPack)
580    : TypeDecl(TemplateTypeParm, DC, L, Id), Typename(Typename),
581      InheritedDefault(false), ParameterPack(ParameterPack), DefaultArgument() {
582    TypeForDecl = Type.getTypePtr();
583  }
584
585public:
586  static TemplateTypeParmDecl *Create(ASTContext &C, DeclContext *DC,
587                                      SourceLocation L, unsigned D, unsigned P,
588                                      IdentifierInfo *Id, bool Typename,
589                                      bool ParameterPack);
590
591  /// \brief Whether this template type parameter was declared with
592  /// the 'typename' keyword. If not, it was declared with the 'class'
593  /// keyword.
594  bool wasDeclaredWithTypename() const { return Typename; }
595
596  /// \brief Determine whether this template parameter has a default
597  /// argument.
598  bool hasDefaultArgument() const { return DefaultArgument != 0; }
599
600  /// \brief Retrieve the default argument, if any.
601  QualType getDefaultArgument() const { return DefaultArgument->getType(); }
602
603  /// \brief Retrieves the default argument's source information, if any.
604  TypeSourceInfo *getDefaultArgumentInfo() const { return DefaultArgument; }
605
606  /// \brief Retrieves the location of the default argument declaration.
607  SourceLocation getDefaultArgumentLoc() const;
608
609  /// \brief Determines whether the default argument was inherited
610  /// from a previous declaration of this template.
611  bool defaultArgumentWasInherited() const { return InheritedDefault; }
612
613  /// \brief Set the default argument for this template parameter, and
614  /// whether that default argument was inherited from another
615  /// declaration.
616  void setDefaultArgument(TypeSourceInfo *DefArg, bool Inherited) {
617    DefaultArgument = DefArg;
618    InheritedDefault = Inherited;
619  }
620
621  /// \brief Removes the default argument of this template parameter.
622  void removeDefaultArgument() {
623    DefaultArgument = 0;
624    InheritedDefault = false;
625  }
626
627  /// \brief Retrieve the depth of the template parameter.
628  unsigned getDepth() const;
629
630  /// \brief Retrieve the index of the template parameter.
631  unsigned getIndex() const;
632
633  /// \brief Returns whether this is a parameter pack.
634  bool isParameterPack() const { return ParameterPack; }
635
636  // Implement isa/cast/dyncast/etc.
637  static bool classof(const Decl *D) {
638    return D->getKind() == TemplateTypeParm;
639  }
640  static bool classof(const TemplateTypeParmDecl *D) { return true; }
641};
642
643/// NonTypeTemplateParmDecl - Declares a non-type template parameter,
644/// e.g., "Size" in
645/// @code
646/// template<int Size> class array { };
647/// @endcode
648class NonTypeTemplateParmDecl
649  : public VarDecl, protected TemplateParmPosition {
650  /// \brief The default template argument, if any.
651  Expr *DefaultArgument;
652
653  NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation L, unsigned D,
654                          unsigned P, IdentifierInfo *Id, QualType T,
655                          TypeSourceInfo *TInfo)
656    : VarDecl(NonTypeTemplateParm, DC, L, Id, T, TInfo, VarDecl::None),
657      TemplateParmPosition(D, P), DefaultArgument(0)
658  { }
659
660public:
661  static NonTypeTemplateParmDecl *
662  Create(ASTContext &C, DeclContext *DC, SourceLocation L, unsigned D,
663         unsigned P, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo);
664
665  using TemplateParmPosition::getDepth;
666  using TemplateParmPosition::getPosition;
667  using TemplateParmPosition::getIndex;
668
669  /// \brief Determine whether this template parameter has a default
670  /// argument.
671  bool hasDefaultArgument() const { return DefaultArgument; }
672
673  /// \brief Retrieve the default argument, if any.
674  Expr *getDefaultArgument() const { return DefaultArgument; }
675
676  /// \brief Retrieve the location of the default argument, if any.
677  SourceLocation getDefaultArgumentLoc() const;
678
679  /// \brief Set the default argument for this template parameter.
680  void setDefaultArgument(Expr *DefArg) {
681    DefaultArgument = DefArg;
682  }
683
684  // Implement isa/cast/dyncast/etc.
685  static bool classof(const Decl *D) {
686    return D->getKind() == NonTypeTemplateParm;
687  }
688  static bool classof(const NonTypeTemplateParmDecl *D) { return true; }
689};
690
691/// TemplateTemplateParmDecl - Declares a template template parameter,
692/// e.g., "T" in
693/// @code
694/// template <template <typename> class T> class container { };
695/// @endcode
696/// A template template parameter is a TemplateDecl because it defines the
697/// name of a template and the template parameters allowable for substitution.
698class TemplateTemplateParmDecl
699  : public TemplateDecl, protected TemplateParmPosition {
700
701  /// \brief The default template argument, if any.
702  TemplateArgumentLoc DefaultArgument;
703
704  TemplateTemplateParmDecl(DeclContext *DC, SourceLocation L,
705                           unsigned D, unsigned P,
706                           IdentifierInfo *Id, TemplateParameterList *Params)
707    : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
708      TemplateParmPosition(D, P), DefaultArgument()
709    { }
710
711public:
712  static TemplateTemplateParmDecl *Create(ASTContext &C, DeclContext *DC,
713                                          SourceLocation L, unsigned D,
714                                          unsigned P, IdentifierInfo *Id,
715                                          TemplateParameterList *Params);
716
717  using TemplateParmPosition::getDepth;
718  using TemplateParmPosition::getPosition;
719  using TemplateParmPosition::getIndex;
720
721  /// \brief Determine whether this template parameter has a default
722  /// argument.
723  bool hasDefaultArgument() const {
724    return !DefaultArgument.getArgument().isNull();
725  }
726
727  /// \brief Retrieve the default argument, if any.
728  const TemplateArgumentLoc &getDefaultArgument() const {
729    return DefaultArgument;
730  }
731
732  /// \brief Set the default argument for this template parameter.
733  void setDefaultArgument(const TemplateArgumentLoc &DefArg) {
734    DefaultArgument = DefArg;
735  }
736
737  // Implement isa/cast/dyncast/etc.
738  static bool classof(const Decl *D) {
739    return D->getKind() == TemplateTemplateParm;
740  }
741  static bool classof(const TemplateTemplateParmDecl *D) { return true; }
742};
743
744/// \brief Represents a class template specialization, which refers to
745/// a class template with a given set of template arguments.
746///
747/// Class template specializations represent both explicit
748/// specialization of class templates, as in the example below, and
749/// implicit instantiations of class templates.
750///
751/// \code
752/// template<typename T> class array;
753///
754/// template<>
755/// class array<bool> { }; // class template specialization array<bool>
756/// \endcode
757class ClassTemplateSpecializationDecl
758  : public CXXRecordDecl, public llvm::FoldingSetNode {
759
760  /// \brief Structure that stores information about a class template
761  /// specialization that was instantiated from a class template partial
762  /// specialization.
763  struct SpecializedPartialSpecialization {
764    /// \brief The class template partial specialization from which this
765    /// class template specialization was instantiated.
766    ClassTemplatePartialSpecializationDecl *PartialSpecialization;
767
768    /// \brief The template argument list deduced for the class template
769    /// partial specialization itself.
770    TemplateArgumentList *TemplateArgs;
771  };
772
773  /// \brief The template that this specialization specializes
774  llvm::PointerUnion<ClassTemplateDecl *, SpecializedPartialSpecialization *>
775    SpecializedTemplate;
776
777  /// \brief The template arguments used to describe this specialization.
778  TemplateArgumentList TemplateArgs;
779
780  /// \brief The point where this template was instantiated (if any)
781  SourceLocation PointOfInstantiation;
782
783  /// \brief The kind of specialization this declaration refers to.
784  /// Really a value of type TemplateSpecializationKind.
785  unsigned SpecializationKind : 3;
786
787protected:
788  ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK,
789                                  DeclContext *DC, SourceLocation L,
790                                  ClassTemplateDecl *SpecializedTemplate,
791                                  TemplateArgumentListBuilder &Builder,
792                                  ClassTemplateSpecializationDecl *PrevDecl);
793
794public:
795  static ClassTemplateSpecializationDecl *
796  Create(ASTContext &Context, DeclContext *DC, SourceLocation L,
797         ClassTemplateDecl *SpecializedTemplate,
798         TemplateArgumentListBuilder &Builder,
799         ClassTemplateSpecializationDecl *PrevDecl);
800
801  virtual void Destroy(ASTContext& C);
802
803  virtual void getNameForDiagnostic(std::string &S,
804                                    const PrintingPolicy &Policy,
805                                    bool Qualified) const;
806
807  /// \brief Retrieve the template that this specialization specializes.
808  ClassTemplateDecl *getSpecializedTemplate() const;
809
810  /// \brief Retrieve the template arguments of the class template
811  /// specialization.
812  const TemplateArgumentList &getTemplateArgs() const {
813    return TemplateArgs;
814  }
815
816  /// \brief Determine the kind of specialization that this
817  /// declaration represents.
818  TemplateSpecializationKind getSpecializationKind() const {
819    return static_cast<TemplateSpecializationKind>(SpecializationKind);
820  }
821
822  void setSpecializationKind(TemplateSpecializationKind TSK) {
823    SpecializationKind = TSK;
824  }
825
826  /// \brief Get the point of instantiation (if any), or null if none.
827  SourceLocation getPointOfInstantiation() const {
828    return PointOfInstantiation;
829  }
830
831  void setPointOfInstantiation(SourceLocation Loc) {
832    assert(Loc.isValid() && "point of instantiation must be valid!");
833    PointOfInstantiation = Loc;
834  }
835
836  /// \brief If this class template specialization is an instantiation of
837  /// a template (rather than an explicit specialization), return the
838  /// class template or class template partial specialization from which it
839  /// was instantiated.
840  llvm::PointerUnion<ClassTemplateDecl *,
841                     ClassTemplatePartialSpecializationDecl *>
842  getInstantiatedFrom() const {
843    if (getSpecializationKind() != TSK_ImplicitInstantiation &&
844        getSpecializationKind() != TSK_ExplicitInstantiationDefinition &&
845        getSpecializationKind() != TSK_ExplicitInstantiationDeclaration)
846      return (ClassTemplateDecl*)0;
847
848    if (SpecializedPartialSpecialization *PartialSpec
849          = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
850      return PartialSpec->PartialSpecialization;
851
852    return const_cast<ClassTemplateDecl*>(
853                             SpecializedTemplate.get<ClassTemplateDecl*>());
854  }
855
856  /// \brief Retrieve the set of template arguments that should be used
857  /// to instantiate members of the class template or class template partial
858  /// specialization from which this class template specialization was
859  /// instantiated.
860  ///
861  /// \returns For a class template specialization instantiated from the primary
862  /// template, this function will return the same template arguments as
863  /// getTemplateArgs(). For a class template specialization instantiated from
864  /// a class template partial specialization, this function will return the
865  /// deduced template arguments for the class template partial specialization
866  /// itself.
867  const TemplateArgumentList &getTemplateInstantiationArgs() const {
868    if (SpecializedPartialSpecialization *PartialSpec
869        = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
870      return *PartialSpec->TemplateArgs;
871
872    return getTemplateArgs();
873  }
874
875  /// \brief Note that this class template specialization is actually an
876  /// instantiation of the given class template partial specialization whose
877  /// template arguments have been deduced.
878  void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec,
879                          TemplateArgumentList *TemplateArgs) {
880    SpecializedPartialSpecialization *PS
881      = new (getASTContext()) SpecializedPartialSpecialization();
882    PS->PartialSpecialization = PartialSpec;
883    PS->TemplateArgs = TemplateArgs;
884    SpecializedTemplate = PS;
885  }
886
887  /// \brief Sets the type of this specialization as it was written by
888  /// the user. This will be a class template specialization type.
889  void setTypeAsWritten(QualType T) {
890    TypeForDecl = T.getTypePtr();
891  }
892
893  void Profile(llvm::FoldingSetNodeID &ID) const {
894    Profile(ID, TemplateArgs.getFlatArgumentList(), TemplateArgs.flat_size(),
895            getASTContext());
896  }
897
898  static void
899  Profile(llvm::FoldingSetNodeID &ID, const TemplateArgument *TemplateArgs,
900          unsigned NumTemplateArgs, ASTContext &Context) {
901    ID.AddInteger(NumTemplateArgs);
902    for (unsigned Arg = 0; Arg != NumTemplateArgs; ++Arg)
903      TemplateArgs[Arg].Profile(ID, Context);
904  }
905
906  static bool classof(const Decl *D) {
907    return D->getKind() == ClassTemplateSpecialization ||
908           D->getKind() == ClassTemplatePartialSpecialization;
909  }
910
911  static bool classof(const ClassTemplateSpecializationDecl *) {
912    return true;
913  }
914
915  static bool classof(const ClassTemplatePartialSpecializationDecl *) {
916    return true;
917  }
918};
919
920class ClassTemplatePartialSpecializationDecl
921  : public ClassTemplateSpecializationDecl {
922  /// \brief The list of template parameters
923  TemplateParameterList* TemplateParams;
924
925  /// \brief The source info for the template arguments as written.
926  TemplateArgumentLoc *ArgsAsWritten;
927  unsigned NumArgsAsWritten;
928
929  /// \brief The class template partial specialization from which this
930  /// class template partial specialization was instantiated.
931  ///
932  /// The boolean value will be true to indicate that this class template
933  /// partial specialization was specialized at this level.
934  llvm::PointerIntPair<ClassTemplatePartialSpecializationDecl *, 1, bool>
935      InstantiatedFromMember;
936
937  ClassTemplatePartialSpecializationDecl(ASTContext &Context,
938                                         DeclContext *DC, SourceLocation L,
939                                         TemplateParameterList *Params,
940                                         ClassTemplateDecl *SpecializedTemplate,
941                                         TemplateArgumentListBuilder &Builder,
942                                         TemplateArgumentLoc *ArgInfos,
943                                         unsigned NumArgInfos,
944                               ClassTemplatePartialSpecializationDecl *PrevDecl)
945    : ClassTemplateSpecializationDecl(Context,
946                                      ClassTemplatePartialSpecialization,
947                                      DC, L, SpecializedTemplate, Builder,
948                                      PrevDecl),
949      TemplateParams(Params), ArgsAsWritten(ArgInfos),
950      NumArgsAsWritten(NumArgInfos), InstantiatedFromMember(0, false) { }
951
952public:
953  static ClassTemplatePartialSpecializationDecl *
954  Create(ASTContext &Context, DeclContext *DC, SourceLocation L,
955         TemplateParameterList *Params,
956         ClassTemplateDecl *SpecializedTemplate,
957         TemplateArgumentListBuilder &Builder,
958         const TemplateArgumentListInfo &ArgInfos,
959         ClassTemplatePartialSpecializationDecl *PrevDecl);
960
961  /// Get the list of template parameters
962  TemplateParameterList *getTemplateParameters() const {
963    return TemplateParams;
964  }
965
966  /// Get the template arguments as written.
967  TemplateArgumentLoc *getTemplateArgsAsWritten() const {
968    return ArgsAsWritten;
969  }
970
971  /// Get the number of template arguments as written.
972  unsigned getNumTemplateArgsAsWritten() const {
973    return NumArgsAsWritten;
974  }
975
976  /// \brief Retrieve the member class template partial specialization from
977  /// which this particular class template partial specialization was
978  /// instantiated.
979  ///
980  /// \code
981  /// template<typename T>
982  /// struct Outer {
983  ///   template<typename U> struct Inner;
984  ///   template<typename U> struct Inner<U*> { }; // #1
985  /// };
986  ///
987  /// Outer<float>::Inner<int*> ii;
988  /// \endcode
989  ///
990  /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
991  /// end up instantiating the partial specialization
992  /// \c Outer<float>::Inner<U*>, which itself was instantiated from the class
993  /// template partial specialization \c Outer<T>::Inner<U*>. Given
994  /// \c Outer<float>::Inner<U*>, this function would return
995  /// \c Outer<T>::Inner<U*>.
996  ClassTemplatePartialSpecializationDecl *getInstantiatedFromMember() {
997    ClassTemplatePartialSpecializationDecl *First
998      = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration());
999    return First->InstantiatedFromMember.getPointer();
1000  }
1001
1002  void setInstantiatedFromMember(
1003                          ClassTemplatePartialSpecializationDecl *PartialSpec) {
1004    ClassTemplatePartialSpecializationDecl *First
1005      = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration());
1006    First->InstantiatedFromMember.setPointer(PartialSpec);
1007  }
1008
1009  /// \brief Determines whether this class template partial specialization
1010  /// template was a specialization of a member partial specialization.
1011  ///
1012  /// In the following example, the member template partial specialization
1013  /// \c X<int>::Inner<T*> is a member specialization.
1014  ///
1015  /// \code
1016  /// template<typename T>
1017  /// struct X {
1018  ///   template<typename U> struct Inner;
1019  ///   template<typename U> struct Inner<U*>;
1020  /// };
1021  ///
1022  /// template<> template<typename T>
1023  /// struct X<int>::Inner<T*> { /* ... */ };
1024  /// \endcode
1025  bool isMemberSpecialization() {
1026    ClassTemplatePartialSpecializationDecl *First
1027      = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration());
1028    return First->InstantiatedFromMember.getInt();
1029  }
1030
1031  /// \brief Note that this member template is a specialization.
1032  void setMemberSpecialization() {
1033    ClassTemplatePartialSpecializationDecl *First
1034      = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration());
1035    assert(First->InstantiatedFromMember.getPointer() &&
1036           "Only member templates can be member template specializations");
1037    return First->InstantiatedFromMember.setInt(true);
1038  }
1039
1040  // FIXME: Add Profile support!
1041
1042  static bool classof(const Decl *D) {
1043    return D->getKind() == ClassTemplatePartialSpecialization;
1044  }
1045
1046  static bool classof(const ClassTemplatePartialSpecializationDecl *) {
1047    return true;
1048  }
1049};
1050
1051/// Declaration of a class template.
1052class ClassTemplateDecl : public TemplateDecl {
1053protected:
1054  /// \brief Data that is common to all of the declarations of a given
1055  /// class template.
1056  struct Common {
1057    Common() : InstantiatedFromMember(0, 0) {}
1058
1059    /// \brief The class template specializations for this class
1060    /// template, including explicit specializations and instantiations.
1061    llvm::FoldingSet<ClassTemplateSpecializationDecl> Specializations;
1062
1063    /// \brief The class template partial specializations for this class
1064    /// template.
1065    llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>
1066      PartialSpecializations;
1067
1068    /// \brief The injected-class-name type for this class template.
1069    QualType InjectedClassNameType;
1070
1071    /// \brief The templated member class from which this was most
1072    /// directly instantiated (or null).
1073    ///
1074    /// The boolean value indicates whether this member class template
1075    /// was explicitly specialized.
1076    llvm::PointerIntPair<ClassTemplateDecl *, 1, bool> InstantiatedFromMember;
1077  };
1078
1079  // FIXME: Combine PreviousDeclaration with CommonPtr, as in
1080  // FunctionTemplateDecl.
1081
1082  /// \brief Previous declaration of this class template.
1083  ClassTemplateDecl *PreviousDeclaration;
1084
1085  /// \brief Pointer to the data that is common to all of the
1086  /// declarations of this class template.
1087  ///
1088  /// The first declaration of a class template (e.g., the declaration
1089  /// with no "previous declaration") owns this pointer.
1090  Common *CommonPtr;
1091
1092  ClassTemplateDecl(DeclContext *DC, SourceLocation L, DeclarationName Name,
1093                    TemplateParameterList *Params, NamedDecl *Decl,
1094                    ClassTemplateDecl *PrevDecl, Common *CommonPtr)
1095    : TemplateDecl(ClassTemplate, DC, L, Name, Params, Decl),
1096      PreviousDeclaration(PrevDecl), CommonPtr(CommonPtr) { }
1097
1098  ~ClassTemplateDecl();
1099
1100public:
1101  /// Get the underlying class declarations of the template.
1102  CXXRecordDecl *getTemplatedDecl() const {
1103    return static_cast<CXXRecordDecl *>(TemplatedDecl);
1104  }
1105
1106  /// \brief Retrieve the previous declaration of this template.
1107  ClassTemplateDecl *getPreviousDeclaration() const {
1108    return PreviousDeclaration;
1109  }
1110
1111  virtual ClassTemplateDecl *getCanonicalDecl();
1112
1113  /// Create a class template node.
1114  static ClassTemplateDecl *Create(ASTContext &C, DeclContext *DC,
1115                                   SourceLocation L,
1116                                   DeclarationName Name,
1117                                   TemplateParameterList *Params,
1118                                   NamedDecl *Decl,
1119                                   ClassTemplateDecl *PrevDecl);
1120
1121  /// \brief Retrieve the set of specializations of this class template.
1122  llvm::FoldingSet<ClassTemplateSpecializationDecl> &getSpecializations() {
1123    return CommonPtr->Specializations;
1124  }
1125
1126  /// \brief Retrieve the set of partial specializations of this class
1127  /// template.
1128  llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> &
1129  getPartialSpecializations() {
1130    return CommonPtr->PartialSpecializations;
1131  }
1132
1133  /// \brief Find a class template partial specialization with the given
1134  /// type T.
1135  ///
1136  /// \brief A dependent type that names a specialization of this class
1137  /// template.
1138  ///
1139  /// \returns the class template partial specialization that exactly matches
1140  /// the type \p T, or NULL if no such partial specialization exists.
1141  ClassTemplatePartialSpecializationDecl *findPartialSpecialization(QualType T);
1142
1143  /// \brief Retrieve the type of the injected-class-name for this
1144  /// class template.
1145  ///
1146  /// The injected-class-name for a class template \c X is \c
1147  /// X<template-args>, where \c template-args is formed from the
1148  /// template arguments that correspond to the template parameters of
1149  /// \c X. For example:
1150  ///
1151  /// \code
1152  /// template<typename T, int N>
1153  /// struct array {
1154  ///   typedef array this_type; // "array" is equivalent to "array<T, N>"
1155  /// };
1156  /// \endcode
1157  QualType getInjectedClassNameType(ASTContext &Context);
1158
1159  /// \brief Retrieve the member class template that this class template was
1160  /// derived from.
1161  ///
1162  /// This routine will return non-NULL for templated member classes of
1163  /// class templates.  For example, given:
1164  ///
1165  /// \code
1166  /// template <typename T>
1167  /// struct X {
1168  ///   template <typename U> struct A {};
1169  /// };
1170  /// \endcode
1171  ///
1172  /// X<int>::A<float> is a ClassTemplateSpecializationDecl (whose parent
1173  /// is X<int>, also a CTSD) for which getSpecializedTemplate() will
1174  /// return X<int>::A<U>, a TemplateClassDecl (whose parent is again
1175  /// X<int>) for which getInstantiatedFromMemberTemplate() will return
1176  /// X<T>::A<U>, a TemplateClassDecl (whose parent is X<T>, also a TCD).
1177  ///
1178  /// \returns null if this is not an instantiation of a member class template.
1179  ClassTemplateDecl *getInstantiatedFromMemberTemplate() const {
1180    return CommonPtr->InstantiatedFromMember.getPointer();
1181  }
1182
1183  void setInstantiatedFromMemberTemplate(ClassTemplateDecl *CTD) {
1184    assert(!CommonPtr->InstantiatedFromMember.getPointer());
1185    CommonPtr->InstantiatedFromMember.setPointer(CTD);
1186  }
1187
1188  /// \brief Determines whether this template was a specialization of a
1189  /// member template.
1190  ///
1191  /// In the following example, the member template \c X<int>::Inner is a
1192  /// member specialization.
1193  ///
1194  /// \code
1195  /// template<typename T>
1196  /// struct X {
1197  ///   template<typename U> struct Inner;
1198  /// };
1199  ///
1200  /// template<> template<typename T>
1201  /// struct X<int>::Inner { /* ... */ };
1202  /// \endcode
1203  bool isMemberSpecialization() {
1204    return CommonPtr->InstantiatedFromMember.getInt();
1205  }
1206
1207  /// \brief Note that this member template is a specialization.
1208  void setMemberSpecialization() {
1209    assert(CommonPtr->InstantiatedFromMember.getPointer() &&
1210           "Only member templates can be member template specializations");
1211    CommonPtr->InstantiatedFromMember.setInt(true);
1212  }
1213
1214  // Implement isa/cast/dyncast support
1215  static bool classof(const Decl *D)
1216  { return D->getKind() == ClassTemplate; }
1217  static bool classof(const ClassTemplateDecl *D)
1218  { return true; }
1219
1220  virtual void Destroy(ASTContext& C);
1221};
1222
1223/// Declaration of a friend template.  For example:
1224///
1225/// template <typename T> class A {
1226///   friend class MyVector<T>; // not a friend template
1227///   template <typename U> friend class B; // friend template
1228///   template <typename U> friend class Foo<T>::Nested; // friend template
1229class FriendTemplateDecl : public Decl {
1230public:
1231  typedef llvm::PointerUnion<NamedDecl*,Type*> FriendUnion;
1232
1233private:
1234  // The number of template parameters;  always non-zero.
1235  unsigned NumParams;
1236
1237  // The parameter list.
1238  TemplateParameterList **Params;
1239
1240  // The declaration that's a friend of this class.
1241  FriendUnion Friend;
1242
1243  // Location of the 'friend' specifier.
1244  SourceLocation FriendLoc;
1245
1246
1247  FriendTemplateDecl(DeclContext *DC, SourceLocation Loc,
1248                     unsigned NParams,
1249                     TemplateParameterList **Params,
1250                     FriendUnion Friend,
1251                     SourceLocation FriendLoc)
1252    : Decl(Decl::FriendTemplate, DC, Loc),
1253      NumParams(NParams),
1254      Params(Params),
1255      Friend(Friend),
1256      FriendLoc(FriendLoc)
1257  {}
1258
1259public:
1260  static FriendTemplateDecl *Create(ASTContext &Context,
1261                                    DeclContext *DC, SourceLocation Loc,
1262                                    unsigned NParams,
1263                                    TemplateParameterList **Params,
1264                                    FriendUnion Friend,
1265                                    SourceLocation FriendLoc);
1266
1267  /// If this friend declaration names a templated type (or
1268  /// a dependent member type of a templated type), return that
1269  /// type;  otherwise return null.
1270  Type *getFriendType() const {
1271    return Friend.dyn_cast<Type*>();
1272  }
1273
1274  /// If this friend declaration names a templated function (or
1275  /// a member function of a templated type), return that type;
1276  /// otherwise return null.
1277  NamedDecl *getFriendDecl() const {
1278    return Friend.dyn_cast<NamedDecl*>();
1279  }
1280
1281  /// Retrieves the location of the 'friend' keyword.
1282  SourceLocation getFriendLoc() const {
1283    return FriendLoc;
1284  }
1285
1286  TemplateParameterList *getTemplateParameterList(unsigned i) const {
1287    assert(i <= NumParams);
1288    return Params[i];
1289  }
1290
1291  unsigned getNumTemplateParameters() const {
1292    return NumParams;
1293  }
1294
1295  // Implement isa/cast/dyncast/etc.
1296  static bool classof(const Decl *D) {
1297    return D->getKind() == Decl::FriendTemplate;
1298  }
1299  static bool classof(const FriendTemplateDecl *D) { return true; }
1300};
1301
1302/// Implementation of inline functions that require the template declarations
1303inline AnyFunctionDecl::AnyFunctionDecl(FunctionTemplateDecl *FTD)
1304  : Function(FTD) { }
1305
1306} /* end of namespace clang */
1307
1308#endif
1309