clang  3.9.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 (const NamedDecl *P : asArray()) {
69  if (P->isTemplateParameterPack()) {
70  if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
71  if (NTTP->isExpandedParameterPack()) {
72  NumRequiredArgs += NTTP->getNumExpansionTypes();
73  continue;
74  }
75 
76  break;
77  }
78 
79  if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(P)) {
80  if (TTP->hasDefaultArgument())
81  break;
82  } else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) {
83  if (NTTP->hasDefaultArgument())
84  break;
85  } else if (cast<TemplateTemplateParmDecl>(P)->hasDefaultArgument())
86  break;
87 
88  ++NumRequiredArgs;
89  }
90 
91  return NumRequiredArgs;
92 }
93 
95  if (size() == 0)
96  return 0;
97 
98  const NamedDecl *FirstParm = getParam(0);
99  if (const TemplateTypeParmDecl *TTP
100  = dyn_cast<TemplateTypeParmDecl>(FirstParm))
101  return TTP->getDepth();
102  else if (const NonTypeTemplateParmDecl *NTTP
103  = dyn_cast<NonTypeTemplateParmDecl>(FirstParm))
104  return NTTP->getDepth();
105  else
106  return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth();
107 }
108 
110  DeclContext *Owner) {
111  for (NamedDecl *P : *Params) {
112  P->setDeclContext(Owner);
113 
114  if (auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
115  AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner);
116  }
117 }
118 
119 namespace clang {
121  return new (C) char[sizeof(void*) * 2];
122 }
123 }
124 
125 //===----------------------------------------------------------------------===//
126 // RedeclarableTemplateDecl Implementation
127 //===----------------------------------------------------------------------===//
128 
130  if (Common)
131  return Common;
132 
133  // Walk the previous-declaration chain until we either find a declaration
134  // with a common pointer or we run out of previous declarations.
136  for (const RedeclarableTemplateDecl *Prev = getPreviousDecl(); Prev;
137  Prev = Prev->getPreviousDecl()) {
138  if (Prev->Common) {
139  Common = Prev->Common;
140  break;
141  }
142 
143  PrevDecls.push_back(Prev);
144  }
145 
146  // If we never found a common pointer, allocate one now.
147  if (!Common) {
148  // FIXME: If any of the declarations is from an AST file, we probably
149  // need an update record to add the common data.
150 
151  Common = newCommon(getASTContext());
152  }
153 
154  // Update any previous declarations we saw with the common pointer.
155  for (const RedeclarableTemplateDecl *Prev : PrevDecls)
156  Prev->Common = Common;
157 
158  return Common;
159 }
160 
161 template<class EntryType>
164  llvm::FoldingSetVector<EntryType> &Specs, ArrayRef<TemplateArgument> Args,
165  void *&InsertPos) {
166  typedef SpecEntryTraits<EntryType> SETraits;
167  llvm::FoldingSetNodeID ID;
168  EntryType::Profile(ID,Args, getASTContext());
169  EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
170  return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
171 }
172 
173 template<class Derived, class EntryType>
175  llvm::FoldingSetVector<EntryType> &Specializations, EntryType *Entry,
176  void *InsertPos) {
177  typedef SpecEntryTraits<EntryType> SETraits;
178  if (InsertPos) {
179 #ifndef NDEBUG
180  void *CorrectInsertPos;
181  assert(!findSpecializationImpl(Specializations,
182  SETraits::getTemplateArgs(Entry),
183  CorrectInsertPos) &&
184  InsertPos == CorrectInsertPos &&
185  "given incorrect InsertPos for specialization");
186 #endif
187  Specializations.InsertNode(Entry, InsertPos);
188  } else {
189  EntryType *Existing = Specializations.GetOrInsertNode(Entry);
190  (void)Existing;
191  assert(SETraits::getDecl(Existing)->isCanonicalDecl() &&
192  "non-canonical specialization?");
193  }
194 
195  if (ASTMutationListener *L = getASTMutationListener())
196  L->AddedCXXTemplateSpecialization(cast<Derived>(this),
197  SETraits::getDecl(Entry));
198 }
199 
200 /// \brief Generate the injected template arguments for the given template
201 /// parameter list, e.g., for the injected-class-name of a class template.
203  TemplateParameterList *Params,
204  TemplateArgument *Args) {
205  for (NamedDecl *Param : *Params) {
206  TemplateArgument Arg;
207  if (auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
208  QualType ArgType = Context.getTypeDeclType(TTP);
209  if (TTP->isParameterPack())
210  ArgType = Context.getPackExpansionType(ArgType, None);
211 
212  Arg = TemplateArgument(ArgType);
213  } else if (auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
214  Expr *E = new (Context) DeclRefExpr(NTTP, /*enclosing*/ false,
215  NTTP->getType().getNonLValueExprType(Context),
216  Expr::getValueKindForType(NTTP->getType()),
217  NTTP->getLocation());
218 
219  if (NTTP->isParameterPack())
220  E = new (Context) PackExpansionExpr(Context.DependentTy, E,
221  NTTP->getLocation(), None);
222  Arg = TemplateArgument(E);
223  } else {
224  auto *TTP = cast<TemplateTemplateParmDecl>(Param);
225  if (TTP->isParameterPack())
227  else
228  Arg = TemplateArgument(TemplateName(TTP));
229  }
230 
231  if (Param->isTemplateParameterPack())
232  Arg = TemplateArgument::CreatePackCopy(Context, Arg);
233 
234  *Args++ = Arg;
235  }
236 }
237 
238 //===----------------------------------------------------------------------===//
239 // FunctionTemplateDecl Implementation
240 //===----------------------------------------------------------------------===//
241 
242 void FunctionTemplateDecl::DeallocateCommon(void *Ptr) {
243  static_cast<Common *>(Ptr)->~Common();
244 }
245 
247  DeclContext *DC,
248  SourceLocation L,
250  TemplateParameterList *Params,
251  NamedDecl *Decl) {
252  AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
253  return new (C, DC) FunctionTemplateDecl(C, DC, L, Name, Params, Decl);
254 }
255 
257  unsigned ID) {
258  return new (C, ID) FunctionTemplateDecl(C, nullptr, SourceLocation(),
259  DeclarationName(), nullptr, nullptr);
260 }
261 
264  Common *CommonPtr = new (C) Common;
265  C.AddDeallocation(DeallocateCommon, CommonPtr);
266  return CommonPtr;
267 }
268 
270  // Grab the most recent declaration to ensure we've loaded any lazy
271  // redeclarations of this template.
272  //
273  // FIXME: Avoid walking the entire redeclaration chain here.
274  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
275  if (CommonPtr->LazySpecializations) {
276  ASTContext &Context = getASTContext();
277  uint32_t *Specs = CommonPtr->LazySpecializations;
278  CommonPtr->LazySpecializations = nullptr;
279  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
280  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
281  }
282 }
283 
284 llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
287  return getCommonPtr()->Specializations;
288 }
289 
290 FunctionDecl *
292  void *&InsertPos) {
293  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
294 }
295 
297  FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
298  addSpecializationImpl<FunctionTemplateDecl>(getSpecializations(), Info,
299  InsertPos);
300 }
301 
304  Common *CommonPtr = getCommonPtr();
305  if (!CommonPtr->InjectedArgs) {
306  CommonPtr->InjectedArgs
307  = new (getASTContext()) TemplateArgument[Params->size()];
308  GenerateInjectedTemplateArgs(getASTContext(), Params,
309  CommonPtr->InjectedArgs);
310  }
311 
312  return llvm::makeArrayRef(CommonPtr->InjectedArgs, Params->size());
313 }
314 
315 //===----------------------------------------------------------------------===//
316 // ClassTemplateDecl Implementation
317 //===----------------------------------------------------------------------===//
318 
319 void ClassTemplateDecl::DeallocateCommon(void *Ptr) {
320  static_cast<Common *>(Ptr)->~Common();
321 }
322 
324  DeclContext *DC,
325  SourceLocation L,
327  TemplateParameterList *Params,
328  NamedDecl *Decl,
329  ClassTemplateDecl *PrevDecl) {
330  AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
331  ClassTemplateDecl *New = new (C, DC) ClassTemplateDecl(C, DC, L, Name,
332  Params, Decl);
333  New->setPreviousDecl(PrevDecl);
334  return New;
335 }
336 
338  unsigned ID) {
339  return new (C, ID) ClassTemplateDecl(C, nullptr, SourceLocation(),
340  DeclarationName(), nullptr, nullptr);
341 }
342 
344  // Grab the most recent declaration to ensure we've loaded any lazy
345  // redeclarations of this template.
346  //
347  // FIXME: Avoid walking the entire redeclaration chain here.
348  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
349  if (CommonPtr->LazySpecializations) {
350  ASTContext &Context = getASTContext();
351  uint32_t *Specs = CommonPtr->LazySpecializations;
352  CommonPtr->LazySpecializations = nullptr;
353  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
354  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
355  }
356 }
357 
358 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
361  return getCommonPtr()->Specializations;
362 }
363 
364 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
368 }
369 
372  Common *CommonPtr = new (C) Common;
373  C.AddDeallocation(DeallocateCommon, CommonPtr);
374  return CommonPtr;
375 }
376 
379  void *&InsertPos) {
380  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
381 }
382 
384  void *InsertPos) {
385  addSpecializationImpl<ClassTemplateDecl>(getSpecializations(), D, InsertPos);
386 }
387 
390  void *&InsertPos) {
391  return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
392 }
393 
396  void *InsertPos) {
397  if (InsertPos)
398  getPartialSpecializations().InsertNode(D, InsertPos);
399  else {
401  = getPartialSpecializations().GetOrInsertNode(D);
402  (void)Existing;
403  assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
404  }
405 
406  if (ASTMutationListener *L = getASTMutationListener())
407  L->AddedCXXTemplateSpecialization(this, D);
408 }
409 
412  llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs
414  PS.clear();
415  PS.reserve(PartialSpecs.size());
416  for (ClassTemplatePartialSpecializationDecl &P : PartialSpecs)
417  PS.push_back(P.getMostRecentDecl());
418 }
419 
422  ASTContext &Context = getASTContext();
425  if (Context.hasSameType(P.getInjectedSpecializationType(), T))
426  return P.getMostRecentDecl();
427  }
428 
429  return nullptr;
430 }
431 
435  Decl *DCanon = D->getCanonicalDecl();
437  if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
438  return P.getMostRecentDecl();
439  }
440 
441  return nullptr;
442 }
443 
444 QualType
446  Common *CommonPtr = getCommonPtr();
447  if (!CommonPtr->InjectedClassNameType.isNull())
448  return CommonPtr->InjectedClassNameType;
449 
450  // C++0x [temp.dep.type]p2:
451  // The template argument list of a primary template is a template argument
452  // list in which the nth template argument has the value of the nth template
453  // parameter of the class template. If the nth template parameter is a
454  // template parameter pack (14.5.3), the nth template argument is a pack
455  // expansion (14.5.3) whose pattern is the name of the template parameter
456  // pack.
457  ASTContext &Context = getASTContext();
460  TemplateArgs.resize(Params->size());
461  GenerateInjectedTemplateArgs(getASTContext(), Params, TemplateArgs.data());
462  CommonPtr->InjectedClassNameType
464  TemplateArgs);
465  return CommonPtr->InjectedClassNameType;
466 }
467 
468 //===----------------------------------------------------------------------===//
469 // TemplateTypeParm Allocation/Deallocation Method Implementations
470 //===----------------------------------------------------------------------===//
471 
474  SourceLocation KeyLoc, SourceLocation NameLoc,
475  unsigned D, unsigned P, IdentifierInfo *Id,
476  bool Typename, bool ParameterPack) {
477  TemplateTypeParmDecl *TTPDecl =
478  new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename);
479  QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
480  TTPDecl->setTypeForDecl(TTPType.getTypePtr());
481  return TTPDecl;
482 }
483 
486  return new (C, ID) TemplateTypeParmDecl(nullptr, SourceLocation(),
487  SourceLocation(), nullptr, false);
488 }
489 
491  return hasDefaultArgument()
493  : SourceLocation();
494 }
495 
498  return SourceRange(getLocStart(),
499  getDefaultArgumentInfo()->getTypeLoc().getEndLoc());
500  else
501  return TypeDecl::getSourceRange();
502 }
503 
506 }
507 
510 }
511 
514 }
515 
516 //===----------------------------------------------------------------------===//
517 // NonTypeTemplateParmDecl Method Implementations
518 //===----------------------------------------------------------------------===//
519 
520 NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(
521  DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D,
522  unsigned P, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
523  ArrayRef<QualType> ExpandedTypes, ArrayRef<TypeSourceInfo *> ExpandedTInfos)
524  : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
525  TemplateParmPosition(D, P), ParameterPack(true),
526  ExpandedParameterPack(true), NumExpandedTypes(ExpandedTypes.size()) {
527  if (!ExpandedTypes.empty() && !ExpandedTInfos.empty()) {
528  auto TypesAndInfos =
529  getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
530  for (unsigned I = 0; I != NumExpandedTypes; ++I) {
531  new (&TypesAndInfos[I].first) QualType(ExpandedTypes[I]);
532  TypesAndInfos[I].second = ExpandedTInfos[I];
533  }
534  }
535 }
536 
539  SourceLocation StartLoc, SourceLocation IdLoc,
540  unsigned D, unsigned P, IdentifierInfo *Id,
541  QualType T, bool ParameterPack,
542  TypeSourceInfo *TInfo) {
543  return new (C, DC) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id,
544  T, ParameterPack, TInfo);
545 }
546 
548  const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
549  SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id,
550  QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes,
551  ArrayRef<TypeSourceInfo *> ExpandedTInfos) {
552  return new (C, DC,
553  additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>(
554  ExpandedTypes.size()))
555  NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, T, TInfo,
556  ExpandedTypes, ExpandedTInfos);
557 }
558 
561  return new (C, ID) NonTypeTemplateParmDecl(nullptr, SourceLocation(),
562  SourceLocation(), 0, 0, nullptr,
563  QualType(), false, nullptr);
564 }
565 
568  unsigned NumExpandedTypes) {
569  auto *NTTP =
570  new (C, ID, additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>(
571  NumExpandedTypes))
573  0, 0, nullptr, QualType(), nullptr, None,
574  None);
575  NTTP->NumExpandedTypes = NumExpandedTypes;
576  return NTTP;
577 }
578 
581  return SourceRange(getOuterLocStart(),
582  getDefaultArgument()->getSourceRange().getEnd());
584 }
585 
587  return hasDefaultArgument()
588  ? getDefaultArgument()->getSourceRange().getBegin()
589  : SourceLocation();
590 }
591 
592 //===----------------------------------------------------------------------===//
593 // TemplateTemplateParmDecl Method Implementations
594 //===----------------------------------------------------------------------===//
595 
596 void TemplateTemplateParmDecl::anchor() { }
597 
598 TemplateTemplateParmDecl::TemplateTemplateParmDecl(
599  DeclContext *DC, SourceLocation L, unsigned D, unsigned P,
601  ArrayRef<TemplateParameterList *> Expansions)
602  : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
603  TemplateParmPosition(D, P), ParameterPack(true),
604  ExpandedParameterPack(true), NumExpandedParams(Expansions.size()) {
605  if (!Expansions.empty())
606  std::uninitialized_copy(Expansions.begin(), Expansions.end(),
607  getTrailingObjects<TemplateParameterList *>());
608 }
609 
612  SourceLocation L, unsigned D, unsigned P,
613  bool ParameterPack, IdentifierInfo *Id,
614  TemplateParameterList *Params) {
615  return new (C, DC) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id,
616  Params);
617 }
618 
621  SourceLocation L, unsigned D, unsigned P,
622  IdentifierInfo *Id,
623  TemplateParameterList *Params,
625  return new (C, DC,
626  additionalSizeToAlloc<TemplateParameterList *>(Expansions.size()))
627  TemplateTemplateParmDecl(DC, L, D, P, Id, Params, Expansions);
628 }
629 
632  return new (C, ID) TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0,
633  false, nullptr, nullptr);
634 }
635 
638  unsigned NumExpansions) {
639  auto *TTP =
640  new (C, ID, additionalSizeToAlloc<TemplateParameterList *>(NumExpansions))
641  TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0, nullptr,
642  nullptr, None);
643  TTP->NumExpandedParams = NumExpansions;
644  return TTP;
645 }
646 
649  : SourceLocation();
650 }
651 
653  const ASTContext &C, const TemplateArgumentLoc &DefArg) {
654  if (DefArg.getArgument().isNull())
655  DefaultArgument.set(nullptr);
656  else
657  DefaultArgument.set(new (C) TemplateArgumentLoc(DefArg));
658 }
659 
660 //===----------------------------------------------------------------------===//
661 // TemplateArgumentList Implementation
662 //===----------------------------------------------------------------------===//
663 TemplateArgumentList::TemplateArgumentList(ArrayRef<TemplateArgument> Args)
664  : Arguments(getTrailingObjects<TemplateArgument>()),
665  NumArguments(Args.size()) {
666  std::uninitialized_copy(Args.begin(), Args.end(),
667  getTrailingObjects<TemplateArgument>());
668 }
669 
673  void *Mem = Context.Allocate(totalSizeToAlloc<TemplateArgument>(Args.size()));
674  return new (Mem) TemplateArgumentList(Args);
675 }
676 
679  FunctionTemplateDecl *Template,
681  const TemplateArgumentList *TemplateArgs,
682  const TemplateArgumentListInfo *TemplateArgsAsWritten,
683  SourceLocation POI) {
684  const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
685  if (TemplateArgsAsWritten)
686  ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C,
687  *TemplateArgsAsWritten);
688 
689  return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK,
690  TemplateArgs,
691  ArgsAsWritten,
692  POI);
693 }
694 
695 //===----------------------------------------------------------------------===//
696 // TemplateDecl Implementation
697 //===----------------------------------------------------------------------===//
698 
699 void TemplateDecl::anchor() { }
700 
701 //===----------------------------------------------------------------------===//
702 // ClassTemplateSpecializationDecl Implementation
703 //===----------------------------------------------------------------------===//
706  DeclContext *DC, SourceLocation StartLoc,
707  SourceLocation IdLoc,
708  ClassTemplateDecl *SpecializedTemplate,
711  : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc,
712  SpecializedTemplate->getIdentifier(),
713  PrevDecl),
714  SpecializedTemplate(SpecializedTemplate),
715  ExplicitInfo(nullptr),
716  TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
717  SpecializationKind(TSK_Undeclared) {
718 }
719 
721  Kind DK)
722  : CXXRecordDecl(DK, TTK_Struct, C, nullptr, SourceLocation(),
723  SourceLocation(), nullptr, nullptr),
724  ExplicitInfo(nullptr), SpecializationKind(TSK_Undeclared) {}
725 
728  DeclContext *DC,
729  SourceLocation StartLoc,
730  SourceLocation IdLoc,
731  ClassTemplateDecl *SpecializedTemplate,
736  Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc,
737  SpecializedTemplate, Args, PrevDecl);
738  Result->MayHaveOutOfDateDef = false;
739 
740  Context.getTypeDeclType(Result, PrevDecl);
741  return Result;
742 }
743 
746  unsigned ID) {
748  new (C, ID) ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization);
749  Result->MayHaveOutOfDateDef = false;
750  return Result;
751 }
752 
754  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
755  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
756 
757  const TemplateArgumentList &TemplateArgs = getTemplateArgs();
759  OS, TemplateArgs.asArray(), Policy);
760 }
761 
764  if (SpecializedPartialSpecialization *PartialSpec
765  = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
766  return PartialSpec->PartialSpecialization->getSpecializedTemplate();
767  return SpecializedTemplate.get<ClassTemplateDecl*>();
768 }
769 
772  if (ExplicitInfo) {
774  if (Begin.isValid()) {
775  // Here we have an explicit (partial) specialization or instantiation.
779  if (getExternLoc().isValid())
780  Begin = getExternLoc();
782  if (End.isInvalid())
784  return SourceRange(Begin, End);
785  }
786  // An implicit instantiation of a class template partial specialization
787  // uses ExplicitInfo to record the TypeAsWritten, but the source
788  // locations should be retrieved from the instantiation pattern.
790  CTPSDecl *ctpsd = const_cast<CTPSDecl*>(cast<CTPSDecl>(this));
791  CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember();
792  assert(inst_from != nullptr);
793  return inst_from->getSourceRange();
794  }
795  else {
796  // No explicit info available.
797  llvm::PointerUnion<ClassTemplateDecl *,
799  inst_from = getInstantiatedFrom();
800  if (inst_from.isNull())
802  if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>())
803  return ctd->getSourceRange();
804  return inst_from.get<ClassTemplatePartialSpecializationDecl*>()
805  ->getSourceRange();
806  }
807 }
808 
809 //===----------------------------------------------------------------------===//
810 // ClassTemplatePartialSpecializationDecl Implementation
811 //===----------------------------------------------------------------------===//
812 void ClassTemplatePartialSpecializationDecl::anchor() { }
813 
814 ClassTemplatePartialSpecializationDecl::
815 ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK,
816  DeclContext *DC,
817  SourceLocation StartLoc,
818  SourceLocation IdLoc,
819  TemplateParameterList *Params,
820  ClassTemplateDecl *SpecializedTemplate,
821  ArrayRef<TemplateArgument> Args,
822  const ASTTemplateArgumentListInfo *ArgInfos,
825  ClassTemplatePartialSpecialization,
826  TK, DC, StartLoc, IdLoc,
827  SpecializedTemplate,
828  Args, PrevDecl),
829  TemplateParams(Params), ArgsAsWritten(ArgInfos),
830  InstantiatedFromMember(nullptr, false)
831 {
832  AdoptTemplateParameterList(Params, this);
833 }
834 
838  SourceLocation StartLoc, SourceLocation IdLoc,
839  TemplateParameterList *Params,
840  ClassTemplateDecl *SpecializedTemplate,
842  const TemplateArgumentListInfo &ArgInfos,
843  QualType CanonInjectedType,
845  const ASTTemplateArgumentListInfo *ASTArgInfos =
846  ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
847 
849  ClassTemplatePartialSpecializationDecl(Context, TK, DC, StartLoc, IdLoc,
850  Params, SpecializedTemplate, Args,
851  ASTArgInfos, PrevDecl);
853  Result->MayHaveOutOfDateDef = false;
854 
855  Context.getInjectedClassNameType(Result, CanonInjectedType);
856  return Result;
857 }
858 
861  unsigned ID) {
864  Result->MayHaveOutOfDateDef = false;
865  return Result;
866 }
867 
868 //===----------------------------------------------------------------------===//
869 // FriendTemplateDecl Implementation
870 //===----------------------------------------------------------------------===//
871 
872 void FriendTemplateDecl::anchor() { }
873 
876  SourceLocation L,
878  FriendUnion Friend, SourceLocation FLoc) {
879  return new (Context, DC) FriendTemplateDecl(DC, L, Params, Friend, FLoc);
880 }
881 
883  unsigned ID) {
884  return new (C, ID) FriendTemplateDecl(EmptyShell());
885 }
886 
887 //===----------------------------------------------------------------------===//
888 // TypeAliasTemplateDecl Implementation
889 //===----------------------------------------------------------------------===//
890 
892  DeclContext *DC,
893  SourceLocation L,
895  TemplateParameterList *Params,
896  NamedDecl *Decl) {
897  AdoptTemplateParameterList(Params, DC);
898  return new (C, DC) TypeAliasTemplateDecl(C, DC, L, Name, Params, Decl);
899 }
900 
902  unsigned ID) {
903  return new (C, ID) TypeAliasTemplateDecl(C, nullptr, SourceLocation(),
904  DeclarationName(), nullptr, nullptr);
905 }
906 
907 void TypeAliasTemplateDecl::DeallocateCommon(void *Ptr) {
908  static_cast<Common *>(Ptr)->~Common();
909 }
912  Common *CommonPtr = new (C) Common;
913  C.AddDeallocation(DeallocateCommon, CommonPtr);
914  return CommonPtr;
915 }
916 
917 //===----------------------------------------------------------------------===//
918 // ClassScopeFunctionSpecializationDecl Implementation
919 //===----------------------------------------------------------------------===//
920 
921 void ClassScopeFunctionSpecializationDecl::anchor() { }
922 
925  unsigned ID) {
927  nullptr, SourceLocation(), nullptr, false, TemplateArgumentListInfo());
928 }
929 
930 //===----------------------------------------------------------------------===//
931 // VarTemplateDecl Implementation
932 //===----------------------------------------------------------------------===//
933 
934 void VarTemplateDecl::DeallocateCommon(void *Ptr) {
935  static_cast<Common *>(Ptr)->~Common();
936 }
937 
939  VarTemplateDecl *CurD = this;
940  while (CurD) {
941  if (CurD->isThisDeclarationADefinition())
942  return CurD;
943  CurD = CurD->getPreviousDecl();
944  }
945  return nullptr;
946 }
947 
950  TemplateParameterList *Params,
951  VarDecl *Decl) {
952  return new (C, DC) VarTemplateDecl(C, DC, L, Name, Params, Decl);
953 }
954 
956  unsigned ID) {
957  return new (C, ID) VarTemplateDecl(C, nullptr, SourceLocation(),
958  DeclarationName(), nullptr, nullptr);
959 }
960 
961 // TODO: Unify across class, function and variable templates?
962 // May require moving this and Common to RedeclarableTemplateDecl.
964  // Grab the most recent declaration to ensure we've loaded any lazy
965  // redeclarations of this template.
966  //
967  // FIXME: Avoid walking the entire redeclaration chain here.
968  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
969  if (CommonPtr->LazySpecializations) {
970  ASTContext &Context = getASTContext();
971  uint32_t *Specs = CommonPtr->LazySpecializations;
972  CommonPtr->LazySpecializations = nullptr;
973  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
974  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
975  }
976 }
977 
978 llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
981  return getCommonPtr()->Specializations;
982 }
983 
984 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
988 }
989 
992  Common *CommonPtr = new (C) Common;
993  C.AddDeallocation(DeallocateCommon, CommonPtr);
994  return CommonPtr;
995 }
996 
999  void *&InsertPos) {
1000  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
1001 }
1002 
1004  void *InsertPos) {
1005  addSpecializationImpl<VarTemplateDecl>(getSpecializations(), D, InsertPos);
1006 }
1007 
1010  void *&InsertPos) {
1011  return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
1012 }
1013 
1015  VarTemplatePartialSpecializationDecl *D, void *InsertPos) {
1016  if (InsertPos)
1017  getPartialSpecializations().InsertNode(D, InsertPos);
1018  else {
1020  getPartialSpecializations().GetOrInsertNode(D);
1021  (void)Existing;
1022  assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
1023  }
1024 
1025  if (ASTMutationListener *L = getASTMutationListener())
1026  L->AddedCXXTemplateSpecialization(this, D);
1027 }
1028 
1031  llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &PartialSpecs =
1033  PS.clear();
1034  PS.reserve(PartialSpecs.size());
1035  for (VarTemplatePartialSpecializationDecl &P : PartialSpecs)
1036  PS.push_back(P.getMostRecentDecl());
1037 }
1038 
1042  Decl *DCanon = D->getCanonicalDecl();
1044  if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
1045  return P.getMostRecentDecl();
1046  }
1047 
1048  return nullptr;
1049 }
1050 
1051 //===----------------------------------------------------------------------===//
1052 // VarTemplateSpecializationDecl Implementation
1053 //===----------------------------------------------------------------------===//
1055  Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1056  SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1058  : VarDecl(DK, Context, DC, StartLoc, IdLoc,
1059  SpecializedTemplate->getIdentifier(), T, TInfo, S),
1060  SpecializedTemplate(SpecializedTemplate), ExplicitInfo(nullptr),
1061  TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
1062  SpecializationKind(TSK_Undeclared) {}
1063 
1065  ASTContext &C)
1066  : VarDecl(DK, C, nullptr, SourceLocation(), SourceLocation(), nullptr,
1067  QualType(), nullptr, SC_None),
1068  ExplicitInfo(nullptr), SpecializationKind(TSK_Undeclared) {}
1069 
1071  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1072  SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1074  return new (Context, DC) VarTemplateSpecializationDecl(
1075  VarTemplateSpecialization, Context, DC, StartLoc, IdLoc,
1076  SpecializedTemplate, T, TInfo, S, Args);
1077 }
1078 
1081  return new (C, ID)
1082  VarTemplateSpecializationDecl(VarTemplateSpecialization, C);
1083 }
1084 
1086  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
1087  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
1088 
1089  const TemplateArgumentList &TemplateArgs = getTemplateArgs();
1091  OS, TemplateArgs.asArray(), Policy);
1092 }
1093 
1095  if (SpecializedPartialSpecialization *PartialSpec =
1096  SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1097  return PartialSpec->PartialSpecialization->getSpecializedTemplate();
1098  return SpecializedTemplate.get<VarTemplateDecl *>();
1099 }
1100 
1102  const TemplateArgumentListInfo &ArgsInfo) {
1103  TemplateArgsInfo.setLAngleLoc(ArgsInfo.getLAngleLoc());
1104  TemplateArgsInfo.setRAngleLoc(ArgsInfo.getRAngleLoc());
1105  for (const TemplateArgumentLoc &Loc : ArgsInfo.arguments())
1106  TemplateArgsInfo.addArgument(Loc);
1107 }
1108 
1109 //===----------------------------------------------------------------------===//
1110 // VarTemplatePartialSpecializationDecl Implementation
1111 //===----------------------------------------------------------------------===//
1112 void VarTemplatePartialSpecializationDecl::anchor() {}
1113 
1114 VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl(
1115  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1116  SourceLocation IdLoc, TemplateParameterList *Params,
1117  VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1118  StorageClass S, ArrayRef<TemplateArgument> Args,
1119  const ASTTemplateArgumentListInfo *ArgInfos)
1120  : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization, Context,
1121  DC, StartLoc, IdLoc, SpecializedTemplate, T,
1122  TInfo, S, Args),
1123  TemplateParams(Params), ArgsAsWritten(ArgInfos),
1124  InstantiatedFromMember(nullptr, false) {
1125  // TODO: The template parameters should be in DC by now. Verify.
1126  // AdoptTemplateParameterList(Params, DC);
1127 }
1128 
1131  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1132  SourceLocation IdLoc, TemplateParameterList *Params,
1133  VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1135  const TemplateArgumentListInfo &ArgInfos) {
1136  const ASTTemplateArgumentListInfo *ASTArgInfos
1137  = ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
1138 
1141  Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo,
1142  S, Args, ASTArgInfos);
1144  return Result;
1145 }
1146 
1149  unsigned ID) {
1150  return new (C, ID) VarTemplatePartialSpecializationDecl(C);
1151 }
1152 
1153 static TemplateParameterList *
1155  // typename T
1156  auto *T = TemplateTypeParmDecl::Create(
1157  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/1, /*Position=*/0,
1158  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
1159  T->setImplicit(true);
1160 
1161  // T ...Ints
1162  TypeSourceInfo *TI =
1163  C.getTrivialTypeSourceInfo(QualType(T->getTypeForDecl(), 0));
1165  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1166  /*Id=*/nullptr, TI->getType(), /*ParameterPack=*/true, TI);
1167  N->setImplicit(true);
1168 
1169  // <typename T, T ...Ints>
1170  NamedDecl *P[2] = {T, N};
1171  auto *TPL = TemplateParameterList::Create(
1173 
1174  // template <typename T, ...Ints> class IntSeq
1175  auto *TemplateTemplateParm = TemplateTemplateParmDecl::Create(
1176  C, DC, SourceLocation(), /*Depth=*/0, /*Position=*/0,
1177  /*ParameterPack=*/false, /*Id=*/nullptr, TPL);
1178  TemplateTemplateParm->setImplicit(true);
1179 
1180  // typename T
1181  auto *TemplateTypeParm = TemplateTypeParmDecl::Create(
1182  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1183  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
1184  TemplateTypeParm->setImplicit(true);
1185 
1186  // T N
1188  QualType(TemplateTypeParm->getTypeForDecl(), 0));
1189  auto *NonTypeTemplateParm = NonTypeTemplateParmDecl::Create(
1190  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/2,
1191  /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo);
1192  NamedDecl *Params[] = {TemplateTemplateParm, TemplateTypeParm,
1193  NonTypeTemplateParm};
1194 
1195  // template <template <typename T, T ...Ints> class IntSeq, typename T, T N>
1197  Params, SourceLocation());
1198 }
1199 
1200 static TemplateParameterList *
1202  // std::size_t Index
1204  auto *Index = NonTypeTemplateParmDecl::Create(
1205  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/0,
1206  /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo);
1207 
1208  // typename ...T
1209  auto *Ts = TemplateTypeParmDecl::Create(
1210  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1211  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/true);
1212  Ts->setImplicit(true);
1213 
1214  // template <std::size_t Index, typename ...T>
1215  NamedDecl *Params[] = {Index, Ts};
1217  llvm::makeArrayRef(Params),
1218  SourceLocation());
1219 }
1220 
1222  const ASTContext &C, DeclContext *DC, BuiltinTemplateKind BTK) {
1223  switch (BTK) {
1224  case BTK__make_integer_seq:
1225  return createMakeIntegerSeqParameterList(C, DC);
1227  return createTypePackElementParameterList(C, DC);
1228  }
1229 
1230  llvm_unreachable("unhandled BuiltinTemplateKind!");
1231 }
1232 
1233 void BuiltinTemplateDecl::anchor() {}
1234 
1235 BuiltinTemplateDecl::BuiltinTemplateDecl(const ASTContext &C, DeclContext *DC,
1237  BuiltinTemplateKind BTK)
1238  : TemplateDecl(BuiltinTemplate, DC, SourceLocation(), Name,
1240  BTK(BTK) {}
Defines the clang::ASTContext interface.
SourceLocation getEnd() const
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1561
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:598
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:3818
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...
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
static TemplateTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation L, unsigned D, unsigned P, bool ParameterPack, IdentifierInfo *Id, TemplateParameterList *Params)
ArrayRef< NamedDecl * > asArray()
Definition: DeclTemplate.h:94
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.
StringRef P
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:391
void setSpecializationKind(TemplateSpecializationKind TSK)
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:101
A container of type source information.
Definition: Decl.h:62
void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo)
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:543
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:768
Declaration of a redeclarable template.
Definition: DeclTemplate.h:629
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:572
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:49
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
SourceRange getSourceRange() const override LLVM_READONLY
Defines the clang::Expr interface and subclasses for C++ expressions.
SourceRange getSourceRange() const override LLVM_READONLY
Definition: DeclTemplate.h:366
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...
VarTemplateSpecializationDecl(Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< TemplateArgument > Args)
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4549
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:92
Defines the position of a template parameter within a template parameter list.
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:459
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:1982
unsigned size() const
Definition: DeclTemplate.h:92
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:1199
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:399
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:170
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
void set(ArgType Arg)
Set the default argument.
Definition: DeclTemplate.h:301
A convenient class for passing around template argument information.
Definition: TemplateBase.h:523
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 TemplateParameterList * createTypePackElementParameterList(const ASTContext &C, DeclContext *DC)
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
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
Definition: DeclCXX.h:654
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:540
SourceRange getSourceRange() const override LLVM_READONLY
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.
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)
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:849
SpecEntryTraits< EntryType >::DeclType * findSpecializationImpl(llvm::FoldingSetVector< EntryType > &Specs, ArrayRef< TemplateArgument > Args, void *&InsertPos)
static TemplateTypeParmDecl * CreateDeserialized(const ASTContext &C, unsigned ID)
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:2593
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:646
ASTContext * Context
const SmallVectorImpl< AnnotatedLine * >::const_iterator End
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:225
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > PartialSpecializations
The class template partial specializations for this class template.
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:2590
Expr - This represents one expression.
Definition: Expr.h:105
static ClassTemplatePartialSpecializationDecl * Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, TemplateParameterList *Params, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, const TemplateArgumentListInfo &ArgInfos, QualType CanonInjectedType, ClassTemplatePartialSpecializationDecl *PrevDecl)
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:176
Defines the clang::TypeLoc interface and its subclasses.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
StorageClass
Storage classes.
Definition: Specifiers.h:201
Declaration of an alias template.
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations()
Retrieve the set of partial specializations of this class template.
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)
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
Definition: Decl.cpp:1908
static FriendTemplateDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation Loc, MutableArrayRef< TemplateParameterList * > Params, FriendUnion Friend, SourceLocation FriendLoc)
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:2591
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:4344
Kind
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
static ClassTemplateSpecializationDecl * Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, ClassTemplateSpecializationDecl *PrevDecl)
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:812
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:943
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5259
static TemplateTemplateParmDecl * CreateDeserialized(ASTContext &C, unsigned ID)
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
This names the __make_integer_seq BuiltinTemplateDecl.
Definition: Builtins.h:222
SourceRange getBraceRange() const
Definition: Decl.h:2846
bool isValid() const
Return true if this is a valid SourceLocation object.
const std::string ID
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.
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
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:844
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition: Type.h:4262
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:220
FunctionTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Definition: DeclTemplate.h:868
CommonBase * Common
Pointer to the common data shared by all declarations of this template.
Definition: DeclTemplate.h:703
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:539
ClassTemplateDecl * getMostRecentDecl()
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:159
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
Definition: Specifiers.h:144
const IdentifierInfo * getIdentifier() const
Definition: Type.h:4580
static void PrintTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy, bool SkipBrackets=false)
Print a template argument list, including the '<' and '>' enclosing the template arguments...
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:542
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:70
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:563
Represents a template argument.
Definition: TemplateBase.h:40
TagTypeKind
The kind of a tag type.
Definition: Type.h:4342
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:1135
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:330
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:155
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:3581
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
This names the __type_pack_element BuiltinTemplateDecl.
Definition: Builtins.h:225
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:141
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...
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...
unsigned MayHaveOutOfDateDef
Indicates whether it is possible for declarations of this kind to have an out-of-date definition...
Definition: Decl.h:2778
Common * getCommonPtr() const
Definition: DeclTemplate.h:876
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:427
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:5818
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:151
static VarTemplatePartialSpecializationDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, TemplateParameterList *Params, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< TemplateArgument > Args, const TemplateArgumentListInfo &ArgInfos)
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
CanQualType DependentTy
Definition: ASTContext.h:909
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.
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:551
static VarTemplateSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
A template argument list.
Definition: DeclTemplate.h:173
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:858
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:263
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:568
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)
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
Definition: Decl.h:2595
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:353
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:865
VarTemplatePartialSpecializationDecl * findPartialSpecInstantiatedFromMember(VarTemplatePartialSpecializationDecl *D)
Find a variable template partial specialization which was instantiated from the given member partial ...
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:932
#define true
Definition: stdbool.h:32
A trivial tuple used to represent a source range.
static VarTemplateSpecializationDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< TemplateArgument > Args)
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
SourceLocation getDefaultArgumentLoc() const
Retrieve the location of the default argument, if any.
SourceRange getSourceRange() const override LLVM_READONLY
Declaration of a friend template.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:665
TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc)
VarTemplateDecl * getDefinition()
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:470
Defines enum values for all the target-independent builtin functions.
Declaration of a template function.
Definition: DeclTemplate.h:838
ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, ClassTemplateSpecializationDecl *PrevDecl)
llvm::FoldingSetVector< VarTemplatePartialSpecializationDecl > & getPartialSpecializations()
Retrieve the set of partial specializations of this class template.
FunctionTemplateDecl * getMostRecentDecl()
Definition: DeclTemplate.h:937