clang  3.8.0
DeclTemplate.cpp
Go to the documentation of this file.
1 //===--- DeclTemplate.cpp - Template Declaration AST Node Implementation --===//
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 implements the C++ related Decl classes for templates.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/DeclTemplate.h"
15 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/DeclCXX.h"
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/ExprCXX.h"
20 #include "clang/AST/TypeLoc.h"
21 #include "clang/Basic/Builtins.h"
23 #include "llvm/ADT/STLExtras.h"
24 #include <memory>
25 using namespace clang;
26 
27 //===----------------------------------------------------------------------===//
28 // TemplateParameterList Implementation
29 //===----------------------------------------------------------------------===//
30 
32  SourceLocation LAngleLoc,
33  ArrayRef<NamedDecl *> Params,
34  SourceLocation RAngleLoc)
35  : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
36  NumParams(Params.size()), ContainsUnexpandedParameterPack(false) {
37  assert(this->NumParams == NumParams && "Too many template parameters");
38  for (unsigned Idx = 0; Idx < NumParams; ++Idx) {
39  NamedDecl *P = Params[Idx];
40  begin()[Idx] = P;
41 
42  if (!P->isTemplateParameterPack()) {
43  if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
44  if (NTTP->getType()->containsUnexpandedParameterPack())
45  ContainsUnexpandedParameterPack = true;
46 
47  if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
48  if (TTP->getTemplateParameters()->containsUnexpandedParameterPack())
49  ContainsUnexpandedParameterPack = true;
50 
51  // FIXME: If a default argument contains an unexpanded parameter pack, the
52  // template parameter list does too.
53  }
54  }
55 }
56 
58  const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc,
59  ArrayRef<NamedDecl *> Params, SourceLocation RAngleLoc) {
60  void *Mem = C.Allocate(totalSizeToAlloc<NamedDecl *>(Params.size()),
61  llvm::alignOf<TemplateParameterList>());
62  return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params,
63  RAngleLoc);
64 }
65 
67  unsigned NumRequiredArgs = 0;
68  for (iterator P = const_cast<TemplateParameterList *>(this)->begin(),
69  PEnd = const_cast<TemplateParameterList *>(this)->end();
70  P != PEnd; ++P) {
71  if ((*P)->isTemplateParameterPack()) {
72  if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P))
73  if (NTTP->isExpandedParameterPack()) {
74  NumRequiredArgs += NTTP->getNumExpansionTypes();
75  continue;
76  }
77 
78  break;
79  }
80 
81  if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) {
82  if (TTP->hasDefaultArgument())
83  break;
84  } else if (NonTypeTemplateParmDecl *NTTP
85  = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
86  if (NTTP->hasDefaultArgument())
87  break;
88  } else if (cast<TemplateTemplateParmDecl>(*P)->hasDefaultArgument())
89  break;
90 
91  ++NumRequiredArgs;
92  }
93 
94  return NumRequiredArgs;
95 }
96 
98  if (size() == 0)
99  return 0;
100 
101  const NamedDecl *FirstParm = getParam(0);
102  if (const TemplateTypeParmDecl *TTP
103  = dyn_cast<TemplateTypeParmDecl>(FirstParm))
104  return TTP->getDepth();
105  else if (const NonTypeTemplateParmDecl *NTTP
106  = dyn_cast<NonTypeTemplateParmDecl>(FirstParm))
107  return NTTP->getDepth();
108  else
109  return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth();
110 }
111 
113  DeclContext *Owner) {
114  for (TemplateParameterList::iterator P = Params->begin(),
115  PEnd = Params->end();
116  P != PEnd; ++P) {
117  (*P)->setDeclContext(Owner);
118 
119  if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(*P))
120  AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner);
121  }
122 }
123 
124 namespace clang {
126  return new (C) char[sizeof(void*) * 2];
127 }
128 }
129 
130 //===----------------------------------------------------------------------===//
131 // RedeclarableTemplateDecl Implementation
132 //===----------------------------------------------------------------------===//
133 
135  if (Common)
136  return Common;
137 
138  // Walk the previous-declaration chain until we either find a declaration
139  // with a common pointer or we run out of previous declarations.
141  for (const RedeclarableTemplateDecl *Prev = getPreviousDecl(); Prev;
142  Prev = Prev->getPreviousDecl()) {
143  if (Prev->Common) {
144  Common = Prev->Common;
145  break;
146  }
147 
148  PrevDecls.push_back(Prev);
149  }
150 
151  // If we never found a common pointer, allocate one now.
152  if (!Common) {
153  // FIXME: If any of the declarations is from an AST file, we probably
154  // need an update record to add the common data.
155 
157  }
158 
159  // Update any previous declarations we saw with the common pointer.
160  for (unsigned I = 0, N = PrevDecls.size(); I != N; ++I)
161  PrevDecls[I]->Common = Common;
162 
163  return Common;
164 }
165 
166 template<class EntryType>
169  llvm::FoldingSetVector<EntryType> &Specs, ArrayRef<TemplateArgument> Args,
170  void *&InsertPos) {
171  typedef SpecEntryTraits<EntryType> SETraits;
172  llvm::FoldingSetNodeID ID;
173  EntryType::Profile(ID,Args, getASTContext());
174  EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
175  return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
176 }
177 
178 template<class Derived, class EntryType>
180  llvm::FoldingSetVector<EntryType> &Specializations, EntryType *Entry,
181  void *InsertPos) {
182  typedef SpecEntryTraits<EntryType> SETraits;
183  if (InsertPos) {
184 #ifndef NDEBUG
185  void *CorrectInsertPos;
186  assert(!findSpecializationImpl(Specializations,
187  SETraits::getTemplateArgs(Entry),
188  CorrectInsertPos) &&
189  InsertPos == CorrectInsertPos &&
190  "given incorrect InsertPos for specialization");
191 #endif
192  Specializations.InsertNode(Entry, InsertPos);
193  } else {
194  EntryType *Existing = Specializations.GetOrInsertNode(Entry);
195  (void)Existing;
196  assert(SETraits::getDecl(Existing)->isCanonicalDecl() &&
197  "non-canonical specialization?");
198  }
199 
201  L->AddedCXXTemplateSpecialization(cast<Derived>(this),
202  SETraits::getDecl(Entry));
203 }
204 
205 /// \brief Generate the injected template arguments for the given template
206 /// parameter list, e.g., for the injected-class-name of a class template.
208  TemplateParameterList *Params,
209  TemplateArgument *Args) {
210  for (TemplateParameterList::iterator Param = Params->begin(),
211  ParamEnd = Params->end();
212  Param != ParamEnd; ++Param) {
213  TemplateArgument Arg;
214  if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) {
215  QualType ArgType = Context.getTypeDeclType(TTP);
216  if (TTP->isParameterPack())
217  ArgType = Context.getPackExpansionType(ArgType, None);
218 
219  Arg = TemplateArgument(ArgType);
220  } else if (NonTypeTemplateParmDecl *NTTP =
221  dyn_cast<NonTypeTemplateParmDecl>(*Param)) {
222  Expr *E = new (Context) DeclRefExpr(NTTP, /*enclosing*/ false,
223  NTTP->getType().getNonLValueExprType(Context),
224  Expr::getValueKindForType(NTTP->getType()),
225  NTTP->getLocation());
226 
227  if (NTTP->isParameterPack())
228  E = new (Context) PackExpansionExpr(Context.DependentTy, E,
229  NTTP->getLocation(), None);
230  Arg = TemplateArgument(E);
231  } else {
232  TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param);
233  if (TTP->isParameterPack())
235  else
236  Arg = TemplateArgument(TemplateName(TTP));
237  }
238 
239  if ((*Param)->isTemplateParameterPack())
240  Arg = TemplateArgument::CreatePackCopy(Context, Arg);
241 
242  *Args++ = Arg;
243  }
244 }
245 
246 //===----------------------------------------------------------------------===//
247 // FunctionTemplateDecl Implementation
248 //===----------------------------------------------------------------------===//
249 
250 void FunctionTemplateDecl::DeallocateCommon(void *Ptr) {
251  static_cast<Common *>(Ptr)->~Common();
252 }
253 
255  DeclContext *DC,
256  SourceLocation L,
258  TemplateParameterList *Params,
259  NamedDecl *Decl) {
260  AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
261  return new (C, DC) FunctionTemplateDecl(C, DC, L, Name, Params, Decl);
262 }
263 
265  unsigned ID) {
266  return new (C, ID) FunctionTemplateDecl(C, nullptr, SourceLocation(),
267  DeclarationName(), nullptr, nullptr);
268 }
269 
272  Common *CommonPtr = new (C) Common;
273  C.AddDeallocation(DeallocateCommon, CommonPtr);
274  return CommonPtr;
275 }
276 
278  // Grab the most recent declaration to ensure we've loaded any lazy
279  // redeclarations of this template.
280  //
281  // FIXME: Avoid walking the entire redeclaration chain here.
282  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
283  if (CommonPtr->LazySpecializations) {
285  uint32_t *Specs = CommonPtr->LazySpecializations;
286  CommonPtr->LazySpecializations = nullptr;
287  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
288  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
289  }
290 }
291 
292 llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
295  return getCommonPtr()->Specializations;
296 }
297 
298 FunctionDecl *
300  void *&InsertPos) {
301  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
302 }
303 
305  FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
306  addSpecializationImpl<FunctionTemplateDecl>(getSpecializations(), Info,
307  InsertPos);
308 }
309 
312  Common *CommonPtr = getCommonPtr();
313  if (!CommonPtr->InjectedArgs) {
314  CommonPtr->InjectedArgs
315  = new (getASTContext()) TemplateArgument[Params->size()];
317  CommonPtr->InjectedArgs);
318  }
319 
320  return llvm::makeArrayRef(CommonPtr->InjectedArgs, Params->size());
321 }
322 
323 //===----------------------------------------------------------------------===//
324 // ClassTemplateDecl Implementation
325 //===----------------------------------------------------------------------===//
326 
327 void ClassTemplateDecl::DeallocateCommon(void *Ptr) {
328  static_cast<Common *>(Ptr)->~Common();
329 }
330 
332  DeclContext *DC,
333  SourceLocation L,
335  TemplateParameterList *Params,
336  NamedDecl *Decl,
337  ClassTemplateDecl *PrevDecl) {
338  AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
339  ClassTemplateDecl *New = new (C, DC) ClassTemplateDecl(C, DC, L, Name,
340  Params, Decl);
341  New->setPreviousDecl(PrevDecl);
342  return New;
343 }
344 
346  unsigned ID) {
347  return new (C, ID) ClassTemplateDecl(C, nullptr, SourceLocation(),
348  DeclarationName(), nullptr, nullptr);
349 }
350 
352  // Grab the most recent declaration to ensure we've loaded any lazy
353  // redeclarations of this template.
354  //
355  // FIXME: Avoid walking the entire redeclaration chain here.
356  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
357  if (CommonPtr->LazySpecializations) {
359  uint32_t *Specs = CommonPtr->LazySpecializations;
360  CommonPtr->LazySpecializations = nullptr;
361  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
362  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
363  }
364 }
365 
366 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
369  return getCommonPtr()->Specializations;
370 }
371 
372 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
376 }
377 
380  Common *CommonPtr = new (C) Common;
381  C.AddDeallocation(DeallocateCommon, CommonPtr);
382  return CommonPtr;
383 }
384 
387  void *&InsertPos) {
388  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
389 }
390 
392  void *InsertPos) {
393  addSpecializationImpl<ClassTemplateDecl>(getSpecializations(), D, InsertPos);
394 }
395 
398  void *&InsertPos) {
399  return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
400 }
401 
404  void *InsertPos) {
405  if (InsertPos)
406  getPartialSpecializations().InsertNode(D, InsertPos);
407  else {
409  = getPartialSpecializations().GetOrInsertNode(D);
410  (void)Existing;
411  assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
412  }
413 
415  L->AddedCXXTemplateSpecialization(this, D);
416 }
417 
420  llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs
422  PS.clear();
423  PS.reserve(PartialSpecs.size());
425  P = PartialSpecs.begin(), PEnd = PartialSpecs.end();
426  P != PEnd; ++P)
427  PS.push_back(P->getMostRecentDecl());
428 }
429 
433  using llvm::FoldingSetVector;
435  partial_spec_iterator;
436  for (partial_spec_iterator P = getPartialSpecializations().begin(),
437  PEnd = getPartialSpecializations().end();
438  P != PEnd; ++P) {
439  if (Context.hasSameType(P->getInjectedSpecializationType(), T))
440  return P->getMostRecentDecl();
441  }
442 
443  return nullptr;
444 }
445 
449  Decl *DCanon = D->getCanonicalDecl();
452  PEnd = getPartialSpecializations().end();
453  P != PEnd; ++P) {
454  if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
455  return P->getMostRecentDecl();
456  }
457 
458  return nullptr;
459 }
460 
461 QualType
463  Common *CommonPtr = getCommonPtr();
464  if (!CommonPtr->InjectedClassNameType.isNull())
465  return CommonPtr->InjectedClassNameType;
466 
467  // C++0x [temp.dep.type]p2:
468  // The template argument list of a primary template is a template argument
469  // list in which the nth template argument has the value of the nth template
470  // parameter of the class template. If the nth template parameter is a
471  // template parameter pack (14.5.3), the nth template argument is a pack
472  // expansion (14.5.3) whose pattern is the name of the template parameter
473  // pack.
477  TemplateArgs.resize(Params->size());
478  GenerateInjectedTemplateArgs(getASTContext(), Params, TemplateArgs.data());
479  CommonPtr->InjectedClassNameType
481  &TemplateArgs[0],
482  TemplateArgs.size());
483  return CommonPtr->InjectedClassNameType;
484 }
485 
486 //===----------------------------------------------------------------------===//
487 // TemplateTypeParm Allocation/Deallocation Method Implementations
488 //===----------------------------------------------------------------------===//
489 
492  SourceLocation KeyLoc, SourceLocation NameLoc,
493  unsigned D, unsigned P, IdentifierInfo *Id,
494  bool Typename, bool ParameterPack) {
495  TemplateTypeParmDecl *TTPDecl =
496  new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename);
497  QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
498  TTPDecl->setTypeForDecl(TTPType.getTypePtr());
499  return TTPDecl;
500 }
501 
504  return new (C, ID) TemplateTypeParmDecl(nullptr, SourceLocation(),
505  SourceLocation(), nullptr, false);
506 }
507 
509  return hasDefaultArgument()
511  : SourceLocation();
512 }
513 
516  return SourceRange(getLocStart(),
517  getDefaultArgumentInfo()->getTypeLoc().getEndLoc());
518  else
519  return TypeDecl::getSourceRange();
520 }
521 
524 }
525 
528 }
529 
532 }
533 
534 //===----------------------------------------------------------------------===//
535 // NonTypeTemplateParmDecl Method Implementations
536 //===----------------------------------------------------------------------===//
537 
538 NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(DeclContext *DC,
539  SourceLocation StartLoc,
540  SourceLocation IdLoc,
541  unsigned D, unsigned P,
542  IdentifierInfo *Id,
543  QualType T,
544  TypeSourceInfo *TInfo,
545  const QualType *ExpandedTypes,
546  unsigned NumExpandedTypes,
547  TypeSourceInfo **ExpandedTInfos)
548  : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
549  TemplateParmPosition(D, P), ParameterPack(true),
550  ExpandedParameterPack(true), NumExpandedTypes(NumExpandedTypes) {
551  if (ExpandedTypes && ExpandedTInfos) {
552  auto TypesAndInfos =
553  getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
554  for (unsigned I = 0; I != NumExpandedTypes; ++I) {
555  new (&TypesAndInfos[I].first) QualType(ExpandedTypes[I]);
556  TypesAndInfos[I].second = ExpandedTInfos[I];
557  }
558  }
559 }
560 
563  SourceLocation StartLoc, SourceLocation IdLoc,
564  unsigned D, unsigned P, IdentifierInfo *Id,
565  QualType T, bool ParameterPack,
566  TypeSourceInfo *TInfo) {
567  return new (C, DC) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id,
568  T, ParameterPack, TInfo);
569 }
570 
573  SourceLocation StartLoc, SourceLocation IdLoc,
574  unsigned D, unsigned P,
575  IdentifierInfo *Id, QualType T,
576  TypeSourceInfo *TInfo,
577  const QualType *ExpandedTypes,
578  unsigned NumExpandedTypes,
579  TypeSourceInfo **ExpandedTInfos) {
580  return new (C, DC,
581  additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>(
582  NumExpandedTypes))
583  NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, T, TInfo,
584  ExpandedTypes, NumExpandedTypes, ExpandedTInfos);
585 }
586 
589  return new (C, ID) NonTypeTemplateParmDecl(nullptr, SourceLocation(),
590  SourceLocation(), 0, 0, nullptr,
591  QualType(), false, nullptr);
592 }
593 
596  unsigned NumExpandedTypes) {
597  return new (C, ID,
598  additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>(
599  NumExpandedTypes))
601  nullptr, QualType(), nullptr, nullptr,
602  NumExpandedTypes, nullptr);
603 }
604 
607  return SourceRange(getOuterLocStart(),
608  getDefaultArgument()->getSourceRange().getEnd());
610 }
611 
613  return hasDefaultArgument()
614  ? getDefaultArgument()->getSourceRange().getBegin()
615  : SourceLocation();
616 }
617 
618 //===----------------------------------------------------------------------===//
619 // TemplateTemplateParmDecl Method Implementations
620 //===----------------------------------------------------------------------===//
621 
622 void TemplateTemplateParmDecl::anchor() { }
623 
624 TemplateTemplateParmDecl::TemplateTemplateParmDecl(
625  DeclContext *DC, SourceLocation L, unsigned D, unsigned P,
627  unsigned NumExpansions, TemplateParameterList * const *Expansions)
628  : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
629  TemplateParmPosition(D, P), ParameterPack(true),
630  ExpandedParameterPack(true), NumExpandedParams(NumExpansions) {
631  if (Expansions)
632  std::uninitialized_copy(Expansions, Expansions + NumExpandedParams,
633  getTrailingObjects<TemplateParameterList *>());
634 }
635 
638  SourceLocation L, unsigned D, unsigned P,
639  bool ParameterPack, IdentifierInfo *Id,
640  TemplateParameterList *Params) {
641  return new (C, DC) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id,
642  Params);
643 }
644 
647  SourceLocation L, unsigned D, unsigned P,
648  IdentifierInfo *Id,
649  TemplateParameterList *Params,
651  return new (C, DC,
652  additionalSizeToAlloc<TemplateParameterList *>(Expansions.size()))
653  TemplateTemplateParmDecl(DC, L, D, P, Id, Params, Expansions.size(),
654  Expansions.data());
655 }
656 
659  return new (C, ID) TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0,
660  false, nullptr, nullptr);
661 }
662 
665  unsigned NumExpansions) {
666  return new (C, ID,
667  additionalSizeToAlloc<TemplateParameterList *>(NumExpansions))
668  TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0, nullptr,
669  nullptr, NumExpansions, nullptr);
670 }
671 
674  : SourceLocation();
675 }
676 
678  const ASTContext &C, const TemplateArgumentLoc &DefArg) {
679  if (DefArg.getArgument().isNull())
680  DefaultArgument.set(nullptr);
681  else
682  DefaultArgument.set(new (C) TemplateArgumentLoc(DefArg));
683 }
684 
685 //===----------------------------------------------------------------------===//
686 // TemplateArgumentList Implementation
687 //===----------------------------------------------------------------------===//
688 TemplateArgumentList::TemplateArgumentList(const TemplateArgument *Args,
689  unsigned NumArgs)
690  : Arguments(getTrailingObjects<TemplateArgument>()), NumArguments(NumArgs) {
691  std::uninitialized_copy(Args, Args + NumArgs,
692  getTrailingObjects<TemplateArgument>());
693 }
694 
697  const TemplateArgument *Args,
698  unsigned NumArgs) {
699  void *Mem = Context.Allocate(totalSizeToAlloc<TemplateArgument>(NumArgs));
700  return new (Mem) TemplateArgumentList(Args, NumArgs);
701 }
702 
705  FunctionTemplateDecl *Template,
707  const TemplateArgumentList *TemplateArgs,
708  const TemplateArgumentListInfo *TemplateArgsAsWritten,
709  SourceLocation POI) {
710  const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
711  if (TemplateArgsAsWritten)
712  ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C,
713  *TemplateArgsAsWritten);
714 
715  return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK,
716  TemplateArgs,
717  ArgsAsWritten,
718  POI);
719 }
720 
721 //===----------------------------------------------------------------------===//
722 // TemplateDecl Implementation
723 //===----------------------------------------------------------------------===//
724 
725 void TemplateDecl::anchor() { }
726 
727 //===----------------------------------------------------------------------===//
728 // ClassTemplateSpecializationDecl Implementation
729 //===----------------------------------------------------------------------===//
732  DeclContext *DC, SourceLocation StartLoc,
733  SourceLocation IdLoc,
734  ClassTemplateDecl *SpecializedTemplate,
735  const TemplateArgument *Args,
736  unsigned NumArgs,
738  : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc,
739  SpecializedTemplate->getIdentifier(),
740  PrevDecl),
741  SpecializedTemplate(SpecializedTemplate),
742  ExplicitInfo(nullptr),
743  TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)),
744  SpecializationKind(TSK_Undeclared) {
745 }
746 
748  Kind DK)
749  : CXXRecordDecl(DK, TTK_Struct, C, nullptr, SourceLocation(),
750  SourceLocation(), nullptr, nullptr),
751  ExplicitInfo(nullptr), SpecializationKind(TSK_Undeclared) {}
752 
755  DeclContext *DC,
756  SourceLocation StartLoc,
757  SourceLocation IdLoc,
758  ClassTemplateDecl *SpecializedTemplate,
759  const TemplateArgument *Args,
760  unsigned NumArgs,
764  Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc,
765  SpecializedTemplate, Args, NumArgs, PrevDecl);
766  Result->MayHaveOutOfDateDef = false;
767 
768  Context.getTypeDeclType(Result, PrevDecl);
769  return Result;
770 }
771 
774  unsigned ID) {
776  new (C, ID) ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization);
777  Result->MayHaveOutOfDateDef = false;
778  return Result;
779 }
780 
782  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
783  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
784 
785  const TemplateArgumentList &TemplateArgs = getTemplateArgs();
787  OS, TemplateArgs.data(), TemplateArgs.size(), Policy);
788 }
789 
792  if (SpecializedPartialSpecialization *PartialSpec
793  = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
794  return PartialSpec->PartialSpecialization->getSpecializedTemplate();
795  return SpecializedTemplate.get<ClassTemplateDecl*>();
796 }
797 
800  if (ExplicitInfo) {
802  if (Begin.isValid()) {
803  // Here we have an explicit (partial) specialization or instantiation.
807  if (getExternLoc().isValid())
808  Begin = getExternLoc();
810  if (End.isInvalid())
812  return SourceRange(Begin, End);
813  }
814  // An implicit instantiation of a class template partial specialization
815  // uses ExplicitInfo to record the TypeAsWritten, but the source
816  // locations should be retrieved from the instantiation pattern.
818  CTPSDecl *ctpsd = const_cast<CTPSDecl*>(cast<CTPSDecl>(this));
819  CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember();
820  assert(inst_from != nullptr);
821  return inst_from->getSourceRange();
822  }
823  else {
824  // No explicit info available.
825  llvm::PointerUnion<ClassTemplateDecl *,
827  inst_from = getInstantiatedFrom();
828  if (inst_from.isNull())
830  if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>())
831  return ctd->getSourceRange();
832  return inst_from.get<ClassTemplatePartialSpecializationDecl*>()
833  ->getSourceRange();
834  }
835 }
836 
837 //===----------------------------------------------------------------------===//
838 // ClassTemplatePartialSpecializationDecl Implementation
839 //===----------------------------------------------------------------------===//
840 void ClassTemplatePartialSpecializationDecl::anchor() { }
841 
842 ClassTemplatePartialSpecializationDecl::
843 ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK,
844  DeclContext *DC,
845  SourceLocation StartLoc,
846  SourceLocation IdLoc,
847  TemplateParameterList *Params,
848  ClassTemplateDecl *SpecializedTemplate,
849  const TemplateArgument *Args,
850  unsigned NumArgs,
851  const ASTTemplateArgumentListInfo *ArgInfos,
854  ClassTemplatePartialSpecialization,
855  TK, DC, StartLoc, IdLoc,
856  SpecializedTemplate,
857  Args, NumArgs, PrevDecl),
858  TemplateParams(Params), ArgsAsWritten(ArgInfos),
859  InstantiatedFromMember(nullptr, false)
860 {
861  AdoptTemplateParameterList(Params, this);
862 }
863 
867  SourceLocation StartLoc, SourceLocation IdLoc,
868  TemplateParameterList *Params,
869  ClassTemplateDecl *SpecializedTemplate,
870  const TemplateArgument *Args,
871  unsigned NumArgs,
872  const TemplateArgumentListInfo &ArgInfos,
873  QualType CanonInjectedType,
875  const ASTTemplateArgumentListInfo *ASTArgInfos =
876  ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
877 
879  ClassTemplatePartialSpecializationDecl(Context, TK, DC, StartLoc, IdLoc,
880  Params, SpecializedTemplate, Args,
881  NumArgs, ASTArgInfos, PrevDecl);
883  Result->MayHaveOutOfDateDef = false;
884 
885  Context.getInjectedClassNameType(Result, CanonInjectedType);
886  return Result;
887 }
888 
891  unsigned ID) {
894  Result->MayHaveOutOfDateDef = false;
895  return Result;
896 }
897 
898 //===----------------------------------------------------------------------===//
899 // FriendTemplateDecl Implementation
900 //===----------------------------------------------------------------------===//
901 
902 void FriendTemplateDecl::anchor() { }
903 
905  DeclContext *DC,
906  SourceLocation L,
907  unsigned NParams,
908  TemplateParameterList **Params,
909  FriendUnion Friend,
910  SourceLocation FLoc) {
911  return new (Context, DC) FriendTemplateDecl(DC, L, NParams, Params,
912  Friend, FLoc);
913 }
914 
916  unsigned ID) {
917  return new (C, ID) FriendTemplateDecl(EmptyShell());
918 }
919 
920 //===----------------------------------------------------------------------===//
921 // TypeAliasTemplateDecl Implementation
922 //===----------------------------------------------------------------------===//
923 
925  DeclContext *DC,
926  SourceLocation L,
928  TemplateParameterList *Params,
929  NamedDecl *Decl) {
930  AdoptTemplateParameterList(Params, DC);
931  return new (C, DC) TypeAliasTemplateDecl(C, DC, L, Name, Params, Decl);
932 }
933 
935  unsigned ID) {
936  return new (C, ID) TypeAliasTemplateDecl(C, nullptr, SourceLocation(),
937  DeclarationName(), nullptr, nullptr);
938 }
939 
940 void TypeAliasTemplateDecl::DeallocateCommon(void *Ptr) {
941  static_cast<Common *>(Ptr)->~Common();
942 }
945  Common *CommonPtr = new (C) Common;
946  C.AddDeallocation(DeallocateCommon, CommonPtr);
947  return CommonPtr;
948 }
949 
950 //===----------------------------------------------------------------------===//
951 // ClassScopeFunctionSpecializationDecl Implementation
952 //===----------------------------------------------------------------------===//
953 
954 void ClassScopeFunctionSpecializationDecl::anchor() { }
955 
958  unsigned ID) {
960  nullptr, SourceLocation(), nullptr, false, TemplateArgumentListInfo());
961 }
962 
963 //===----------------------------------------------------------------------===//
964 // VarTemplateDecl Implementation
965 //===----------------------------------------------------------------------===//
966 
967 void VarTemplateDecl::DeallocateCommon(void *Ptr) {
968  static_cast<Common *>(Ptr)->~Common();
969 }
970 
972  VarTemplateDecl *CurD = this;
973  while (CurD) {
974  if (CurD->isThisDeclarationADefinition())
975  return CurD;
976  CurD = CurD->getPreviousDecl();
977  }
978  return nullptr;
979 }
980 
983  TemplateParameterList *Params,
984  VarDecl *Decl) {
985  return new (C, DC) VarTemplateDecl(C, DC, L, Name, Params, Decl);
986 }
987 
989  unsigned ID) {
990  return new (C, ID) VarTemplateDecl(C, nullptr, SourceLocation(),
991  DeclarationName(), nullptr, nullptr);
992 }
993 
994 // TODO: Unify across class, function and variable templates?
995 // May require moving this and Common to RedeclarableTemplateDecl.
997  // Grab the most recent declaration to ensure we've loaded any lazy
998  // redeclarations of this template.
999  //
1000  // FIXME: Avoid walking the entire redeclaration chain here.
1001  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
1002  if (CommonPtr->LazySpecializations) {
1004  uint32_t *Specs = CommonPtr->LazySpecializations;
1005  CommonPtr->LazySpecializations = nullptr;
1006  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
1007  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
1008  }
1009 }
1010 
1011 llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
1014  return getCommonPtr()->Specializations;
1015 }
1016 
1017 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
1021 }
1022 
1025  Common *CommonPtr = new (C) Common;
1026  C.AddDeallocation(DeallocateCommon, CommonPtr);
1027  return CommonPtr;
1028 }
1029 
1032  void *&InsertPos) {
1033  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
1034 }
1035 
1037  void *InsertPos) {
1038  addSpecializationImpl<VarTemplateDecl>(getSpecializations(), D, InsertPos);
1039 }
1040 
1043  void *&InsertPos) {
1044  return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
1045 }
1046 
1048  VarTemplatePartialSpecializationDecl *D, void *InsertPos) {
1049  if (InsertPos)
1050  getPartialSpecializations().InsertNode(D, InsertPos);
1051  else {
1053  getPartialSpecializations().GetOrInsertNode(D);
1054  (void)Existing;
1055  assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
1056  }
1057 
1059  L->AddedCXXTemplateSpecialization(this, D);
1060 }
1061 
1064  llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &PartialSpecs =
1066  PS.clear();
1067  PS.reserve(PartialSpecs.size());
1069  P = PartialSpecs.begin(),
1070  PEnd = PartialSpecs.end();
1071  P != PEnd; ++P)
1072  PS.push_back(P->getMostRecentDecl());
1073 }
1074 
1078  Decl *DCanon = D->getCanonicalDecl();
1081  PEnd = getPartialSpecializations().end();
1082  P != PEnd; ++P) {
1083  if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
1084  return P->getMostRecentDecl();
1085  }
1086 
1087  return nullptr;
1088 }
1089 
1090 //===----------------------------------------------------------------------===//
1091 // VarTemplateSpecializationDecl Implementation
1092 //===----------------------------------------------------------------------===//
1094  Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1095  SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1096  TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args,
1097  unsigned NumArgs)
1098  : VarDecl(DK, Context, DC, StartLoc, IdLoc,
1099  SpecializedTemplate->getIdentifier(), T, TInfo, S),
1100  SpecializedTemplate(SpecializedTemplate), ExplicitInfo(nullptr),
1101  TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)),
1102  SpecializationKind(TSK_Undeclared) {}
1103 
1105  ASTContext &C)
1106  : VarDecl(DK, C, nullptr, SourceLocation(), SourceLocation(), nullptr,
1107  QualType(), nullptr, SC_None),
1108  ExplicitInfo(nullptr), SpecializationKind(TSK_Undeclared) {}
1109 
1111  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1112  SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1113  TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args,
1114  unsigned NumArgs) {
1115  return new (Context, DC) VarTemplateSpecializationDecl(
1116  VarTemplateSpecialization, Context, DC, StartLoc, IdLoc,
1117  SpecializedTemplate, T, TInfo, S, Args, NumArgs);
1118 }
1119 
1122  return new (C, ID)
1123  VarTemplateSpecializationDecl(VarTemplateSpecialization, C);
1124 }
1125 
1127  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
1128  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
1129 
1130  const TemplateArgumentList &TemplateArgs = getTemplateArgs();
1132  OS, TemplateArgs.data(), TemplateArgs.size(), Policy);
1133 }
1134 
1136  if (SpecializedPartialSpecialization *PartialSpec =
1137  SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1138  return PartialSpec->PartialSpecialization->getSpecializedTemplate();
1139  return SpecializedTemplate.get<VarTemplateDecl *>();
1140 }
1141 
1143  const TemplateArgumentListInfo &ArgsInfo) {
1144  unsigned N = ArgsInfo.size();
1145  TemplateArgsInfo.setLAngleLoc(ArgsInfo.getLAngleLoc());
1146  TemplateArgsInfo.setRAngleLoc(ArgsInfo.getRAngleLoc());
1147  for (unsigned I = 0; I != N; ++I)
1148  TemplateArgsInfo.addArgument(ArgsInfo[I]);
1149 }
1150 
1151 //===----------------------------------------------------------------------===//
1152 // VarTemplatePartialSpecializationDecl Implementation
1153 //===----------------------------------------------------------------------===//
1154 void VarTemplatePartialSpecializationDecl::anchor() {}
1155 
1156 VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl(
1157  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1158  SourceLocation IdLoc, TemplateParameterList *Params,
1159  VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1160  StorageClass S, const TemplateArgument *Args, unsigned NumArgs,
1161  const ASTTemplateArgumentListInfo *ArgInfos)
1162  : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization, Context,
1163  DC, StartLoc, IdLoc, SpecializedTemplate, T,
1164  TInfo, S, Args, NumArgs),
1165  TemplateParams(Params), ArgsAsWritten(ArgInfos),
1166  InstantiatedFromMember(nullptr, false) {
1167  // TODO: The template parameters should be in DC by now. Verify.
1168  // AdoptTemplateParameterList(Params, DC);
1169 }
1170 
1173  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1174  SourceLocation IdLoc, TemplateParameterList *Params,
1175  VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1176  StorageClass S, const TemplateArgument *Args, unsigned NumArgs,
1177  const TemplateArgumentListInfo &ArgInfos) {
1178  const ASTTemplateArgumentListInfo *ASTArgInfos
1179  = ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
1180 
1183  Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo,
1184  S, Args, NumArgs, ASTArgInfos);
1186  return Result;
1187 }
1188 
1191  unsigned ID) {
1192  return new (C, ID) VarTemplatePartialSpecializationDecl(C);
1193 }
1194 
1195 static TemplateParameterList *
1197  // typename T
1198  auto *T = TemplateTypeParmDecl::Create(
1199  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/1, /*Position=*/0,
1200  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
1201  T->setImplicit(true);
1202 
1203  // T ...Ints
1204  TypeSourceInfo *TI =
1205  C.getTrivialTypeSourceInfo(QualType(T->getTypeForDecl(), 0));
1207  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1208  /*Id=*/nullptr, TI->getType(), /*ParameterPack=*/true, TI);
1209  N->setImplicit(true);
1210 
1211  // <typename T, T ...Ints>
1212  NamedDecl *P[2] = {T, N};
1213  auto *TPL = TemplateParameterList::Create(
1215 
1216  // template <typename T, ...Ints> class IntSeq
1217  auto *TemplateTemplateParm = TemplateTemplateParmDecl::Create(
1218  C, DC, SourceLocation(), /*Depth=*/0, /*Position=*/0,
1219  /*ParameterPack=*/false, /*Id=*/nullptr, TPL);
1220  TemplateTemplateParm->setImplicit(true);
1221 
1222  // typename T
1223  auto *TemplateTypeParm = TemplateTypeParmDecl::Create(
1224  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1225  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
1226  TemplateTypeParm->setImplicit(true);
1227 
1228  // T N
1230  QualType(TemplateTypeParm->getTypeForDecl(), 0));
1231  auto *NonTypeTemplateParm = NonTypeTemplateParmDecl::Create(
1232  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/2,
1233  /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo);
1234  NamedDecl *Params[] = {TemplateTemplateParm, TemplateTypeParm,
1235  NonTypeTemplateParm};
1236 
1237  // template <template <typename T, T ...Ints> class IntSeq, typename T, T N>
1239  Params, SourceLocation());
1240 }
1241 
1243  const ASTContext &C, DeclContext *DC, BuiltinTemplateKind BTK) {
1244  switch (BTK) {
1245  case BTK__make_integer_seq:
1246  return createMakeIntegerSeqParameterList(C, DC);
1247  }
1248 
1249  llvm_unreachable("unhandled BuiltinTemplateKind!");
1250 }
1251 
1252 void BuiltinTemplateDecl::anchor() {}
1253 
1254 BuiltinTemplateDecl::BuiltinTemplateDecl(const ASTContext &C, DeclContext *DC,
1256  BuiltinTemplateKind BTK)
1257  : TemplateDecl(BuiltinTemplate, DC, SourceLocation(), Name,
1259  BTK(BTK) {}
Defines the clang::ASTContext interface.
void setImplicit(bool I=true)
Definition: DeclBase.h:515
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1483
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getInstantiatedFrom() const
If this class template specialization is an instantiation of a template (rather than an explicit spec...
SourceLocation getDefaultArgumentLoc() const
Retrieves the location of the default argument declaration.
A (possibly-)qualified type.
Definition: Type.h:575
virtual Decl * GetExternalDecl(uint32_t ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
SourceLocation getExternLoc() const
Gets the location of the extern keyword, if present.
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
static TypeAliasTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
llvm::FoldingSetVector< VarTemplateSpecializationDecl > & getSpecializations() const
Retrieve the set of specializations of this variable template.
bool isParameterPack() const
Returns whether this is a parameter pack.
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition: Decl.h:3748
ArrayRef< TemplateArgument > getInjectedTemplateArgs()
Retrieve the "injected" template arguments that correspond to the template parameters of this functio...
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
static TemplateTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation L, unsigned D, unsigned P, bool ParameterPack, IdentifierInfo *Id, TemplateParameterList *Params)
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:77
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
Defines the C++ template declaration subclasses.
static ClassTemplateSpecializationDecl * Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, const TemplateArgument *Args, unsigned NumArgs, ClassTemplateSpecializationDecl *PrevDecl)
Declaration of a variable template.
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Definition: Expr.h:390
void setSpecializationKind(TemplateSpecializationKind TSK)
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:100
A container of type source information.
Definition: Decl.h:61
void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo)
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:537
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:699
Declaration of a redeclarable template.
Definition: DeclTemplate.h:621
llvm::FoldingSetVector< FunctionTemplateSpecializationInfo > & getSpecializations() const
Retrieve the set of function template specializations of this function template.
Represents a variable template specialization, which refers to a variable template with a given set o...
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:566
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:48
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:35
bool MayHaveOutOfDateDef
Indicates whether it is possible for declarations of this kind to have an out-of-date definition...
Definition: Decl.h:2695
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
iterator begin() const
Definition: Type.h:4072
Defines the clang::Expr interface and subclasses for C++ expressions.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclTemplate.h:368
ASTMutationListener * getASTMutationListener() const
Definition: DeclBase.cpp:315
One of these records is kept for each identifier that is lexed.
Represents a class template specialization, which refers to a class template with a given set of temp...
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4381
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:91
Defines the position of a template parameter within a template parameter list.
Definition: DeclTemplate.h:997
Common * getCommonPtr() const
VarTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
void * allocateDefaultArgStorageChain(const ASTContext &C)
SourceLocation getLocation() const
Fetches the primary location of the argument.
Definition: TemplateBase.h:453
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:232
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:1962
unsigned size() const
Definition: DeclTemplate.h:91
Declaration of a function specialization at template class scope.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1191
static FriendTemplateDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation Loc, unsigned NParams, TemplateParameterList **Params, FriendUnion Friend, SourceLocation FriendLoc)
TypeAliasTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
getNameForDiagnostic - Appends a human-readable name for this declaration into the given stream...
Definition: Decl.cpp:1490
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Definition: DeclTemplate.h:391
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:170
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
static TemplateArgumentList * CreateCopy(ASTContext &Context, const TemplateArgument *Args, unsigned NumArgs)
Create a new template argument list that copies the given set of template arguments.
void set(ArgType Arg)
Set the default argument.
Definition: DeclTemplate.h:302
A convenient class for passing around template argument information.
Definition: TemplateBase.h:517
llvm::FoldingSetVector< ClassTemplateSpecializationDecl > & getSpecializations() const
Retrieve the set of specializations of this class template.
uint32_t * LazySpecializations
If non-null, points to an array of specializations (including partial specializations) known ownly by...
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
static ClassTemplateSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
static TemplateTypeParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc, SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id, bool Typename, bool ParameterPack)
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:1739
void setSpecializationKind(TemplateSpecializationKind TSK)
static TemplateArgument CreatePackCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument pack by copying the given set of template arguments.
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:651
SourceLocation getRBraceLoc() const
Definition: Decl.h:2763
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:534
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
iterator end() const
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
static FunctionTemplateSpecializationInfo * Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template, TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs, const TemplateArgumentListInfo *TemplateArgsAsWritten, SourceLocation POI)
static FunctionTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
static void PrintTemplateArgumentList(raw_ostream &OS, const TemplateArgument *Args, unsigned NumArgs, const PrintingPolicy &Policy, bool SkipBrackets=false)
Print a template argument list, including the '<' and '>' enclosing the template arguments...
detail::InMemoryDirectory::const_iterator I
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const
getInjectedClassNameType - Return the unique reference to the injected class name type for the specif...
bool isInvalid() const
ClassTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
QualType getTemplateSpecializationType(TemplateName T, const TemplateArgument *Args, unsigned NumArgs, QualType Canon=QualType()) const
AnnotatingParser & P
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack...
Definition: DeclBase.cpp:168
TypeSourceInfo * getTypeAsWritten() const
Gets the type of this specialization as it was written by the user, if it was so written.
llvm::FoldingSetVector< FunctionTemplateSpecializationInfo > Specializations
The function template specializations for this function template, including explicit specializations ...
Definition: DeclTemplate.h:841
SpecEntryTraits< EntryType >::DeclType * findSpecializationImpl(llvm::FoldingSetVector< EntryType > &Specs, ArrayRef< TemplateArgument > Args, void *&InsertPos)
static TemplateTypeParmDecl * CreateDeserialized(const ASTContext &C, unsigned ID)
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition: DeclBase.h:96
void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
SourceLocation getLocStart() const LLVM_READONLY
Definition: Decl.h:2510
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:577
ASTContext * Context
const SmallVectorImpl< AnnotatedLine * >::const_iterator End
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > PartialSpecializations
The class template partial specializations for this class template.
ID
Defines the set of possible language-specific address spaces.
Definition: AddressSpaces.h:27
void AddPartialSpecialization(VarTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
const Type * getTypeForDecl() const
Definition: Decl.h:2507
Expr - This represents one expression.
Definition: Expr.h:104
llvm::FoldingSetVector< VarTemplatePartialSpecializationDecl > PartialSpecializations
The variable template partial specializations for this variable template.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
Declaration of a template type parameter.
static ClassTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl, ClassTemplateDecl *PrevDecl)
Create a class template node.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
Data that is common to all of the declarations of a given variable template.
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
CommonBase * getCommonPtr() const
Retrieves the "common" pointer shared by all (re-)declarations of the same template.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Represents a C++ template name within the type system.
Definition: TemplateName.h:175
Defines the clang::TypeLoc interface and its subclasses.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
StorageClass
Storage classes.
Definition: Specifiers.h:198
Declaration of an alias template.
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations()
Retrieve the set of partial specializations of this class template.
const TemplateArgument * data() const
Retrieve a pointer to the template argument list.
Definition: DeclTemplate.h:235
static ClassTemplatePartialSpecializationDecl * Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, TemplateParameterList *Params, ClassTemplateDecl *SpecializedTemplate, const TemplateArgument *Args, unsigned NumArgs, const TemplateArgumentListInfo &ArgInfos, QualType CanonInjectedType, ClassTemplatePartialSpecializationDecl *PrevDecl)
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
static TemplateParameterList * createBuiltinTemplateParameterList(const ASTContext &C, DeclContext *DC, BuiltinTemplateKind BTK)
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:3988
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
Data that is common to all of the declarations of a given class template.
The result type of a method or function.
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:1908
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
static TypeAliasTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty alias template node.
SourceLocation getEndLoc() const
Get the end source location.
Definition: TypeLoc.cpp:207
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc)
QualType getPackExpansionType(QualType Pattern, Optional< unsigned > NumExpansions)
void setTypeForDecl(const Type *TD)
Definition: Decl.h:2508
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:215
#define false
Definition: stdbool.h:33
The "struct" keyword.
Definition: Type.h:4176
SourceLocation getDefaultArgumentLoc() const
Retrieve the location of the default argument, if any.
RedeclarableTemplateDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:144
TypeSourceInfo * getDefaultArgumentInfo() const
Retrieves the default argument's source information, if any.
CommonBase * newCommon(ASTContext &C) const override
ClassTemplatePartialSpecializationDecl * findPartialSpecInstantiatedFromMember(ClassTemplatePartialSpecializationDecl *D)
Find a class template partial specialization which was instantiated from the given member partial spe...
QualType InjectedClassNameType
The injected-class-name type for this class template.
void AddDeallocation(void(*Callback)(void *), void *Data)
Add a deallocation callback that will be invoked when the ASTContext is destroyed.
Definition: ASTContext.cpp:813
SourceLocation getOuterLocStart() const
getOuterLocStart - Return SourceLocation representing start of source range taking into account any o...
Definition: Decl.cpp:1695
Encodes a location in the source.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:932
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5089
static TemplateTemplateParmDecl * CreateDeserialized(ASTContext &C, unsigned ID)
const TemplateArgument * iterator
Definition: Type.h:4070
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
This names the __make_integer_seq BuiltinTemplateDecl.
Definition: Builtins.h:216
bool isValid() const
Return true if this is a valid SourceLocation object.
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:311
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
CommonBase * newCommon(ASTContext &C) const override
unsigned getDepth() const
Retrieve the depth of the template parameter.
Expr * getDefaultArgument() const
Retrieve the default argument, if any.
Data that is common to all of the declarations of a given function template.
Definition: DeclTemplate.h:836
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition: Type.h:4095
static void AdoptTemplateParameterList(TemplateParameterList *Params, DeclContext *Owner)
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template...
BuiltinTemplateKind
Kinds of BuiltinTemplateDecl.
Definition: Builtins.h:214
FunctionTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Definition: DeclTemplate.h:860
CommonBase * Common
Pointer to the common data shared by all declarations of this template.
Definition: DeclTemplate.h:695
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:533
ClassTemplateDecl * getMostRecentDecl()
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:156
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
Definition: Specifiers.h:141
const IdentifierInfo * getIdentifier() const
Definition: Type.h:4413
static VarTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty variable template node.
static TemplateParameterList * createMakeIntegerSeqParameterList(const ASTContext &C, DeclContext *DC)
void addSpecialization(FunctionTemplateSpecializationInfo *Info, void *InsertPos)
Add a specialization of this function template.
void setLAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:536
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:69
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:557
ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, const TemplateArgument *Args, unsigned NumArgs, ClassTemplateSpecializationDecl *PrevDecl)
Represents a template argument.
Definition: TemplateBase.h:40
TagTypeKind
The kind of a tag type.
Definition: Type.h:4174
static ClassScopeFunctionSpecializationDecl * CreateDeserialized(ASTContext &Context, unsigned ID)
static NonTypeTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id, QualType T, bool ParameterPack, TypeSourceInfo *TInfo)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1121
static ClassTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty class template node.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:331
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Definition: DeclBase.h:759
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:152
static VarTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
DeclarationName - The name of a declaration.
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:3483
static NonTypeTemplateParmDecl * CreateDeserialized(ASTContext &C, unsigned ID)
QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *ParmDecl=nullptr) const
Retrieve the template type parameter type for a template parameter or parameter pack with the given d...
bool isNull() const
Determine whether this template argument has no value.
Definition: TemplateBase.h:219
detail::InMemoryDirectory::const_iterator E
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:138
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to form a template specialization. ...
static FriendTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
uint32_t * LazySpecializations
If non-null, points to an array of specializations (including partial specializations) known only by ...
VarTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const override
getNameForDiagnostic - Appends a human-readable name for this declaration into the given stream...
static VarTemplatePartialSpecializationDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, TemplateParameterList *Params, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args, unsigned NumArgs, const TemplateArgumentListInfo &ArgInfos)
void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const override
getNameForDiagnostic - Appends a human-readable name for this declaration into the given stream...
Common * getCommonPtr() const
Definition: DeclTemplate.h:868
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:421
static VarTemplateSpecializationDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args, unsigned NumArgs)
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:5675
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary variable pattern.
static ClassTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
This template specialization was declared or defined by an explicit specialization (C++ [temp...
Definition: Specifiers.h:148
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
CanQualType DependentTy
Definition: ASTContext.h:896
VarTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this variable template, or NULL if no such declaration exists...
static FunctionTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty function template node.
static VarTemplateSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
A template argument list.
Definition: DeclTemplate.h:172
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
TemplateArgument * InjectedArgs
The set of "injected" template arguments used within this function template.
Definition: DeclTemplate.h:850
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
VarTemplateDecl * getMostRecentDecl()
Represents a C++ struct/union/class.
Definition: DeclCXX.h:285
static const ASTTemplateArgumentListInfo * Create(ASTContext &C, const TemplateArgumentListInfo &List)
CommonBase * newCommon(ASTContext &C) const override
void addSpecializationImpl(llvm::FoldingSetVector< EntryType > &Specs, EntryType *Entry, void *InsertPos)
CommonBase * newCommon(ASTContext &C) const override
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:560
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
VarTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
VarTemplateSpecializationDecl(Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args, unsigned NumArgs)
static VarTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, VarDecl *Decl)
Create a variable template node.
Declaration of a class template.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:2512
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:355
unsigned getIndex() const
Retrieve the index of the template parameter.
uint32_t * LazySpecializations
If non-null, points to an array of specializations known only by their external declaration IDs...
Definition: DeclTemplate.h:857
VarTemplatePartialSpecializationDecl * findPartialSpecInstantiatedFromMember(VarTemplatePartialSpecializationDecl *D)
Find a variable template partial specialization which was instantiated from the given member partial ...
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:83
llvm::FoldingSetVector< VarTemplateSpecializationDecl > Specializations
The variable template specializations for this variable template, including explicit specializations ...
static void GenerateInjectedTemplateArgs(ASTContext &Context, TemplateParameterList *Params, TemplateArgument *Args)
Generate the injected template arguments for the given template parameter list, e.g., for the injected-class-name of a class template.
Common * getCommonPtr() const
llvm::FoldingSetVector< ClassTemplateSpecializationDecl > Specializations
The class template specializations for this class template, including explicit specializations and in...
virtual CommonBase * newCommon(ASTContext &C) const =0
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:922
#define true
Definition: stdbool.h:32
A trivial tuple used to represent a source range.
NamedDecl - This represents a decl with a name.
Definition: Decl.h:145
SourceLocation getDefaultArgumentLoc() const
Retrieve the location of the default argument, if any.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Declaration of a friend template.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:642
TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc)
VarTemplateDecl * getDefinition()
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:464
Defines enum values for all the target-independent builtin functions.
Declaration of a template function.
Definition: DeclTemplate.h:830
llvm::FoldingSetVector< VarTemplatePartialSpecializationDecl > & getPartialSpecializations()
Retrieve the set of partial specializations of this class template.
FunctionTemplateDecl * getMostRecentDecl()
Definition: DeclTemplate.h:929