clang  7.0.0svn
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"
19 #include "clang/AST/Expr.h"
20 #include "clang/AST/TemplateBase.h"
21 #include "clang/AST/TemplateName.h"
22 #include "clang/AST/Type.h"
23 #include "clang/AST/TypeLoc.h"
24 #include "clang/Basic/Builtins.h"
25 #include "clang/Basic/LLVM.h"
27 #include "llvm/ADT/ArrayRef.h"
28 #include "llvm/ADT/FoldingSet.h"
29 #include "llvm/ADT/None.h"
30 #include "llvm/ADT/PointerUnion.h"
31 #include "llvm/ADT/SmallVector.h"
32 #include "llvm/Support/Casting.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include <algorithm>
35 #include <cassert>
36 #include <cstdint>
37 #include <memory>
38 #include <utility>
39 
40 using namespace clang;
41 
42 //===----------------------------------------------------------------------===//
43 // TemplateParameterList Implementation
44 //===----------------------------------------------------------------------===//
45 
47  SourceLocation LAngleLoc,
48  ArrayRef<NamedDecl *> Params,
49  SourceLocation RAngleLoc,
50  Expr *RequiresClause)
51  : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
52  NumParams(Params.size()), ContainsUnexpandedParameterPack(false),
53  HasRequiresClause(static_cast<bool>(RequiresClause)) {
54  for (unsigned Idx = 0; Idx < NumParams; ++Idx) {
55  NamedDecl *P = Params[Idx];
56  begin()[Idx] = P;
57 
58  if (!P->isTemplateParameterPack()) {
59  if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
60  if (NTTP->getType()->containsUnexpandedParameterPack())
61  ContainsUnexpandedParameterPack = true;
62 
63  if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
64  if (TTP->getTemplateParameters()->containsUnexpandedParameterPack())
65  ContainsUnexpandedParameterPack = true;
66 
67  // FIXME: If a default argument contains an unexpanded parameter pack, the
68  // template parameter list does too.
69  }
70  }
71  if (RequiresClause) {
72  *getTrailingObjects<Expr *>() = RequiresClause;
73  }
74 }
75 
78  SourceLocation LAngleLoc,
79  ArrayRef<NamedDecl *> Params,
80  SourceLocation RAngleLoc, Expr *RequiresClause) {
81  void *Mem = C.Allocate(totalSizeToAlloc<NamedDecl *, Expr *>(
82  Params.size(), RequiresClause ? 1u : 0u),
83  alignof(TemplateParameterList));
84  return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params,
85  RAngleLoc, RequiresClause);
86 }
87 
89  unsigned NumRequiredArgs = 0;
90  for (const NamedDecl *P : asArray()) {
91  if (P->isTemplateParameterPack()) {
92  if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
93  if (NTTP->isExpandedParameterPack()) {
94  NumRequiredArgs += NTTP->getNumExpansionTypes();
95  continue;
96  }
97 
98  break;
99  }
100 
101  if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(P)) {
102  if (TTP->hasDefaultArgument())
103  break;
104  } else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) {
105  if (NTTP->hasDefaultArgument())
106  break;
107  } else if (cast<TemplateTemplateParmDecl>(P)->hasDefaultArgument())
108  break;
109 
110  ++NumRequiredArgs;
111  }
112 
113  return NumRequiredArgs;
114 }
115 
117  if (size() == 0)
118  return 0;
119 
120  const NamedDecl *FirstParm = getParam(0);
121  if (const TemplateTypeParmDecl *TTP
122  = dyn_cast<TemplateTypeParmDecl>(FirstParm))
123  return TTP->getDepth();
124  else if (const NonTypeTemplateParmDecl *NTTP
125  = dyn_cast<NonTypeTemplateParmDecl>(FirstParm))
126  return NTTP->getDepth();
127  else
128  return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth();
129 }
130 
132  DeclContext *Owner) {
133  for (NamedDecl *P : *Params) {
134  P->setDeclContext(Owner);
135 
136  if (auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
137  AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner);
138  }
139 }
140 
141 namespace clang {
142 
144  return new (C) char[sizeof(void*) * 2];
145 }
146 
147 } // namespace clang
148 
149 //===----------------------------------------------------------------------===//
150 // RedeclarableTemplateDecl Implementation
151 //===----------------------------------------------------------------------===//
152 
154  if (Common)
155  return Common;
156 
157  // Walk the previous-declaration chain until we either find a declaration
158  // with a common pointer or we run out of previous declarations.
160  for (const RedeclarableTemplateDecl *Prev = getPreviousDecl(); Prev;
161  Prev = Prev->getPreviousDecl()) {
162  if (Prev->Common) {
163  Common = Prev->Common;
164  break;
165  }
166 
167  PrevDecls.push_back(Prev);
168  }
169 
170  // If we never found a common pointer, allocate one now.
171  if (!Common) {
172  // FIXME: If any of the declarations is from an AST file, we probably
173  // need an update record to add the common data.
174 
175  Common = newCommon(getASTContext());
176  }
177 
178  // Update any previous declarations we saw with the common pointer.
179  for (const RedeclarableTemplateDecl *Prev : PrevDecls)
180  Prev->Common = Common;
181 
182  return Common;
183 }
184 
186  // Grab the most recent declaration to ensure we've loaded any lazy
187  // redeclarations of this template.
188  CommonBase *CommonBasePtr = getMostRecentDecl()->getCommonPtr();
189  if (CommonBasePtr->LazySpecializations) {
190  ASTContext &Context = getASTContext();
191  uint32_t *Specs = CommonBasePtr->LazySpecializations;
192  CommonBasePtr->LazySpecializations = nullptr;
193  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
194  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
195  }
196 }
197 
198 template<class EntryType>
201  llvm::FoldingSetVector<EntryType> &Specs, ArrayRef<TemplateArgument> Args,
202  void *&InsertPos) {
203  using SETraits = SpecEntryTraits<EntryType>;
204 
205  llvm::FoldingSetNodeID ID;
206  EntryType::Profile(ID, Args, getASTContext());
207  EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
208  return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
209 }
210 
211 template<class Derived, class EntryType>
213  llvm::FoldingSetVector<EntryType> &Specializations, EntryType *Entry,
214  void *InsertPos) {
215  using SETraits = SpecEntryTraits<EntryType>;
216 
217  if (InsertPos) {
218 #ifndef NDEBUG
219  void *CorrectInsertPos;
220  assert(!findSpecializationImpl(Specializations,
221  SETraits::getTemplateArgs(Entry),
222  CorrectInsertPos) &&
223  InsertPos == CorrectInsertPos &&
224  "given incorrect InsertPos for specialization");
225 #endif
226  Specializations.InsertNode(Entry, InsertPos);
227  } else {
228  EntryType *Existing = Specializations.GetOrInsertNode(Entry);
229  (void)Existing;
230  assert(SETraits::getDecl(Existing)->isCanonicalDecl() &&
231  "non-canonical specialization?");
232  }
233 
234  if (ASTMutationListener *L = getASTMutationListener())
235  L->AddedCXXTemplateSpecialization(cast<Derived>(this),
236  SETraits::getDecl(Entry));
237 }
238 
239 //===----------------------------------------------------------------------===//
240 // FunctionTemplateDecl Implementation
241 //===----------------------------------------------------------------------===//
242 
244  DeclContext *DC,
245  SourceLocation L,
246  DeclarationName Name,
247  TemplateParameterList *Params,
248  NamedDecl *Decl) {
249  AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
250  return new (C, DC) FunctionTemplateDecl(C, DC, L, Name, Params, Decl);
251 }
252 
254  unsigned ID) {
255  return new (C, ID) FunctionTemplateDecl(C, nullptr, SourceLocation(),
256  DeclarationName(), nullptr, nullptr);
257 }
258 
261  Common *CommonPtr = new (C) Common;
262  C.addDestruction(CommonPtr);
263  return CommonPtr;
264 }
265 
267  loadLazySpecializationsImpl();
268 }
269 
270 llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
272  LoadLazySpecializations();
273  return getCommonPtr()->Specializations;
274 }
275 
276 FunctionDecl *
278  void *&InsertPos) {
279  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
280 }
281 
283  FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
284  addSpecializationImpl<FunctionTemplateDecl>(getSpecializations(), Info,
285  InsertPos);
286 }
287 
289  TemplateParameterList *Params = getTemplateParameters();
290  Common *CommonPtr = getCommonPtr();
291  if (!CommonPtr->InjectedArgs) {
292  auto &Context = getASTContext();
294  Context.getInjectedTemplateArgs(Params, TemplateArgs);
295  CommonPtr->InjectedArgs =
296  new (Context) TemplateArgument[TemplateArgs.size()];
297  std::copy(TemplateArgs.begin(), TemplateArgs.end(),
298  CommonPtr->InjectedArgs);
299  }
300 
301  return llvm::makeArrayRef(CommonPtr->InjectedArgs, Params->size());
302 }
303 
304 //===----------------------------------------------------------------------===//
305 // ClassTemplateDecl Implementation
306 //===----------------------------------------------------------------------===//
307 
309  DeclContext *DC,
310  SourceLocation L,
311  DeclarationName Name,
312  TemplateParameterList *Params,
313  NamedDecl *Decl,
314  Expr *AssociatedConstraints) {
315  AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
316 
317  if (!AssociatedConstraints) {
318  return new (C, DC) ClassTemplateDecl(C, DC, L, Name, Params, Decl);
319  }
320 
322  ClassTemplateDecl *const New =
323  new (C, DC) ClassTemplateDecl(CTDI, C, DC, L, Name, Params, Decl);
324  New->setAssociatedConstraints(AssociatedConstraints);
325  return New;
326 }
327 
329  unsigned ID) {
330  return new (C, ID) ClassTemplateDecl(C, nullptr, SourceLocation(),
331  DeclarationName(), nullptr, nullptr);
332 }
333 
335  loadLazySpecializationsImpl();
336 }
337 
338 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
340  LoadLazySpecializations();
341  return getCommonPtr()->Specializations;
342 }
343 
344 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
346  LoadLazySpecializations();
347  return getCommonPtr()->PartialSpecializations;
348 }
349 
352  Common *CommonPtr = new (C) Common;
353  C.addDestruction(CommonPtr);
354  return CommonPtr;
355 }
356 
359  void *&InsertPos) {
360  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
361 }
362 
364  void *InsertPos) {
365  addSpecializationImpl<ClassTemplateDecl>(getSpecializations(), D, InsertPos);
366 }
367 
370  void *&InsertPos) {
371  return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
372 }
373 
376  void *InsertPos) {
377  if (InsertPos)
378  getPartialSpecializations().InsertNode(D, InsertPos);
379  else {
381  = getPartialSpecializations().GetOrInsertNode(D);
382  (void)Existing;
383  assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
384  }
385 
386  if (ASTMutationListener *L = getASTMutationListener())
387  L->AddedCXXTemplateSpecialization(this, D);
388 }
389 
392  llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs
393  = getPartialSpecializations();
394  PS.clear();
395  PS.reserve(PartialSpecs.size());
396  for (ClassTemplatePartialSpecializationDecl &P : PartialSpecs)
397  PS.push_back(P.getMostRecentDecl());
398 }
399 
402  ASTContext &Context = getASTContext();
404  getPartialSpecializations()) {
405  if (Context.hasSameType(P.getInjectedSpecializationType(), T))
406  return P.getMostRecentDecl();
407  }
408 
409  return nullptr;
410 }
411 
415  Decl *DCanon = D->getCanonicalDecl();
416  for (ClassTemplatePartialSpecializationDecl &P : getPartialSpecializations()) {
417  if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
418  return P.getMostRecentDecl();
419  }
420 
421  return nullptr;
422 }
423 
424 QualType
426  Common *CommonPtr = getCommonPtr();
427  if (!CommonPtr->InjectedClassNameType.isNull())
428  return CommonPtr->InjectedClassNameType;
429 
430  // C++0x [temp.dep.type]p2:
431  // The template argument list of a primary template is a template argument
432  // list in which the nth template argument has the value of the nth template
433  // parameter of the class template. If the nth template parameter is a
434  // template parameter pack (14.5.3), the nth template argument is a pack
435  // expansion (14.5.3) whose pattern is the name of the template parameter
436  // pack.
437  ASTContext &Context = getASTContext();
438  TemplateParameterList *Params = getTemplateParameters();
440  Context.getInjectedTemplateArgs(Params, TemplateArgs);
441  CommonPtr->InjectedClassNameType
443  TemplateArgs);
444  return CommonPtr->InjectedClassNameType;
445 }
446 
447 //===----------------------------------------------------------------------===//
448 // TemplateTypeParm Allocation/Deallocation Method Implementations
449 //===----------------------------------------------------------------------===//
450 
453  SourceLocation KeyLoc, SourceLocation NameLoc,
454  unsigned D, unsigned P, IdentifierInfo *Id,
455  bool Typename, bool ParameterPack) {
456  TemplateTypeParmDecl *TTPDecl =
457  new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename);
458  QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
459  TTPDecl->setTypeForDecl(TTPType.getTypePtr());
460  return TTPDecl;
461 }
462 
465  return new (C, ID) TemplateTypeParmDecl(nullptr, SourceLocation(),
466  SourceLocation(), nullptr, false);
467 }
468 
470  return hasDefaultArgument()
471  ? getDefaultArgumentInfo()->getTypeLoc().getBeginLoc()
472  : SourceLocation();
473 }
474 
476  if (hasDefaultArgument() && !defaultArgumentWasInherited())
477  return SourceRange(getLocStart(),
478  getDefaultArgumentInfo()->getTypeLoc().getEndLoc());
479  else
480  return TypeDecl::getSourceRange();
481 }
482 
484  return getTypeForDecl()->getAs<TemplateTypeParmType>()->getDepth();
485 }
486 
488  return getTypeForDecl()->getAs<TemplateTypeParmType>()->getIndex();
489 }
490 
492  return getTypeForDecl()->getAs<TemplateTypeParmType>()->isParameterPack();
493 }
494 
495 //===----------------------------------------------------------------------===//
496 // NonTypeTemplateParmDecl Method Implementations
497 //===----------------------------------------------------------------------===//
498 
499 NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(
500  DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D,
501  unsigned P, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
502  ArrayRef<QualType> ExpandedTypes, ArrayRef<TypeSourceInfo *> ExpandedTInfos)
503  : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
504  TemplateParmPosition(D, P), ParameterPack(true),
505  ExpandedParameterPack(true), NumExpandedTypes(ExpandedTypes.size()) {
506  if (!ExpandedTypes.empty() && !ExpandedTInfos.empty()) {
507  auto TypesAndInfos =
508  getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
509  for (unsigned I = 0; I != NumExpandedTypes; ++I) {
510  new (&TypesAndInfos[I].first) QualType(ExpandedTypes[I]);
511  TypesAndInfos[I].second = ExpandedTInfos[I];
512  }
513  }
514 }
515 
518  SourceLocation StartLoc, SourceLocation IdLoc,
519  unsigned D, unsigned P, IdentifierInfo *Id,
520  QualType T, bool ParameterPack,
521  TypeSourceInfo *TInfo) {
522  return new (C, DC) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id,
523  T, ParameterPack, TInfo);
524 }
525 
527  const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
528  SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id,
529  QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes,
530  ArrayRef<TypeSourceInfo *> ExpandedTInfos) {
531  return new (C, DC,
532  additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>(
533  ExpandedTypes.size()))
534  NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, T, TInfo,
535  ExpandedTypes, ExpandedTInfos);
536 }
537 
540  return new (C, ID) NonTypeTemplateParmDecl(nullptr, SourceLocation(),
541  SourceLocation(), 0, 0, nullptr,
542  QualType(), false, nullptr);
543 }
544 
547  unsigned NumExpandedTypes) {
548  auto *NTTP =
549  new (C, ID, additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>(
550  NumExpandedTypes))
552  0, 0, nullptr, QualType(), nullptr, None,
553  None);
554  NTTP->NumExpandedTypes = NumExpandedTypes;
555  return NTTP;
556 }
557 
559  if (hasDefaultArgument() && !defaultArgumentWasInherited())
560  return SourceRange(getOuterLocStart(),
561  getDefaultArgument()->getSourceRange().getEnd());
563 }
564 
566  return hasDefaultArgument()
567  ? getDefaultArgument()->getSourceRange().getBegin()
568  : SourceLocation();
569 }
570 
571 //===----------------------------------------------------------------------===//
572 // TemplateTemplateParmDecl Method Implementations
573 //===----------------------------------------------------------------------===//
574 
575 void TemplateTemplateParmDecl::anchor() {}
576 
577 TemplateTemplateParmDecl::TemplateTemplateParmDecl(
578  DeclContext *DC, SourceLocation L, unsigned D, unsigned P,
581  : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
582  TemplateParmPosition(D, P), ParameterPack(true),
583  ExpandedParameterPack(true), NumExpandedParams(Expansions.size()) {
584  if (!Expansions.empty())
585  std::uninitialized_copy(Expansions.begin(), Expansions.end(),
586  getTrailingObjects<TemplateParameterList *>());
587 }
588 
591  SourceLocation L, unsigned D, unsigned P,
592  bool ParameterPack, IdentifierInfo *Id,
593  TemplateParameterList *Params) {
594  return new (C, DC) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id,
595  Params);
596 }
597 
600  SourceLocation L, unsigned D, unsigned P,
601  IdentifierInfo *Id,
602  TemplateParameterList *Params,
604  return new (C, DC,
605  additionalSizeToAlloc<TemplateParameterList *>(Expansions.size()))
606  TemplateTemplateParmDecl(DC, L, D, P, Id, Params, Expansions);
607 }
608 
611  return new (C, ID) TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0,
612  false, nullptr, nullptr);
613 }
614 
617  unsigned NumExpansions) {
618  auto *TTP =
619  new (C, ID, additionalSizeToAlloc<TemplateParameterList *>(NumExpansions))
620  TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0, nullptr,
621  nullptr, None);
622  TTP->NumExpandedParams = NumExpansions;
623  return TTP;
624 }
625 
627  return hasDefaultArgument() ? getDefaultArgument().getLocation()
628  : SourceLocation();
629 }
630 
632  const ASTContext &C, const TemplateArgumentLoc &DefArg) {
633  if (DefArg.getArgument().isNull())
634  DefaultArgument.set(nullptr);
635  else
636  DefaultArgument.set(new (C) TemplateArgumentLoc(DefArg));
637 }
638 
639 //===----------------------------------------------------------------------===//
640 // TemplateArgumentList Implementation
641 //===----------------------------------------------------------------------===//
642 TemplateArgumentList::TemplateArgumentList(ArrayRef<TemplateArgument> Args)
643  : Arguments(getTrailingObjects<TemplateArgument>()),
644  NumArguments(Args.size()) {
645  std::uninitialized_copy(Args.begin(), Args.end(),
646  getTrailingObjects<TemplateArgument>());
647 }
648 
652  void *Mem = Context.Allocate(totalSizeToAlloc<TemplateArgument>(Args.size()));
653  return new (Mem) TemplateArgumentList(Args);
654 }
655 
658  FunctionTemplateDecl *Template,
660  const TemplateArgumentList *TemplateArgs,
661  const TemplateArgumentListInfo *TemplateArgsAsWritten,
662  SourceLocation POI) {
663  const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
664  if (TemplateArgsAsWritten)
665  ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C,
666  *TemplateArgsAsWritten);
667 
668  return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK,
669  TemplateArgs,
670  ArgsAsWritten,
671  POI);
672 }
673 
674 //===----------------------------------------------------------------------===//
675 // TemplateDecl Implementation
676 //===----------------------------------------------------------------------===//
677 
678 void TemplateDecl::anchor() {}
679 
680 //===----------------------------------------------------------------------===//
681 // ClassTemplateSpecializationDecl Implementation
682 //===----------------------------------------------------------------------===//
683 
686  DeclContext *DC, SourceLocation StartLoc,
687  SourceLocation IdLoc,
688  ClassTemplateDecl *SpecializedTemplate,
691  : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc,
692  SpecializedTemplate->getIdentifier(), PrevDecl),
693  SpecializedTemplate(SpecializedTemplate),
694  TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
695  SpecializationKind(TSK_Undeclared) {
696 }
697 
699  Kind DK)
700  : CXXRecordDecl(DK, TTK_Struct, C, nullptr, SourceLocation(),
701  SourceLocation(), nullptr, nullptr),
702  SpecializationKind(TSK_Undeclared) {}
703 
706  DeclContext *DC,
707  SourceLocation StartLoc,
708  SourceLocation IdLoc,
709  ClassTemplateDecl *SpecializedTemplate,
713  new (Context, DC) ClassTemplateSpecializationDecl(
714  Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc,
715  SpecializedTemplate, Args, PrevDecl);
716  Result->MayHaveOutOfDateDef = false;
717 
718  Context.getTypeDeclType(Result, PrevDecl);
719  return Result;
720 }
721 
724  unsigned ID) {
726  new (C, ID) ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization);
727  Result->MayHaveOutOfDateDef = false;
728  return Result;
729 }
730 
732  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
733  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
734 
735  auto *PS = dyn_cast<ClassTemplatePartialSpecializationDecl>(this);
736  if (const ASTTemplateArgumentListInfo *ArgsAsWritten =
737  PS ? PS->getTemplateArgsAsWritten() : nullptr) {
738  printTemplateArgumentList(OS, ArgsAsWritten->arguments(), Policy);
739  } else {
740  const TemplateArgumentList &TemplateArgs = getTemplateArgs();
741  printTemplateArgumentList(OS, TemplateArgs.asArray(), Policy);
742  }
743 }
744 
747  if (SpecializedPartialSpecialization *PartialSpec
748  = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
749  return PartialSpec->PartialSpecialization->getSpecializedTemplate();
750  return SpecializedTemplate.get<ClassTemplateDecl*>();
751 }
752 
755  if (ExplicitInfo) {
757  if (Begin.isValid()) {
758  // Here we have an explicit (partial) specialization or instantiation.
762  if (getExternLoc().isValid())
763  Begin = getExternLoc();
765  if (End.isInvalid())
767  return SourceRange(Begin, End);
768  }
769  // An implicit instantiation of a class template partial specialization
770  // uses ExplicitInfo to record the TypeAsWritten, but the source
771  // locations should be retrieved from the instantiation pattern.
773  CTPSDecl *ctpsd = const_cast<CTPSDecl*>(cast<CTPSDecl>(this));
774  CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember();
775  assert(inst_from != nullptr);
776  return inst_from->getSourceRange();
777  }
778  else {
779  // No explicit info available.
780  llvm::PointerUnion<ClassTemplateDecl *,
782  inst_from = getInstantiatedFrom();
783  if (inst_from.isNull())
785  if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>())
786  return ctd->getSourceRange();
787  return inst_from.get<ClassTemplatePartialSpecializationDecl*>()
788  ->getSourceRange();
789  }
790 }
791 
792 //===----------------------------------------------------------------------===//
793 // ClassTemplatePartialSpecializationDecl Implementation
794 //===----------------------------------------------------------------------===//
795 void ClassTemplatePartialSpecializationDecl::anchor() {}
796 
797 ClassTemplatePartialSpecializationDecl::
798 ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK,
799  DeclContext *DC,
800  SourceLocation StartLoc,
801  SourceLocation IdLoc,
802  TemplateParameterList *Params,
803  ClassTemplateDecl *SpecializedTemplate,
805  const ASTTemplateArgumentListInfo *ArgInfos,
808  ClassTemplatePartialSpecialization,
809  TK, DC, StartLoc, IdLoc,
810  SpecializedTemplate, Args, PrevDecl),
811  TemplateParams(Params), ArgsAsWritten(ArgInfos),
812  InstantiatedFromMember(nullptr, false) {
813  AdoptTemplateParameterList(Params, this);
814 }
815 
819  SourceLocation StartLoc, SourceLocation IdLoc,
820  TemplateParameterList *Params,
821  ClassTemplateDecl *SpecializedTemplate,
823  const TemplateArgumentListInfo &ArgInfos,
824  QualType CanonInjectedType,
826  const ASTTemplateArgumentListInfo *ASTArgInfos =
827  ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
828 
830  ClassTemplatePartialSpecializationDecl(Context, TK, DC, StartLoc, IdLoc,
831  Params, SpecializedTemplate, Args,
832  ASTArgInfos, PrevDecl);
834  Result->MayHaveOutOfDateDef = false;
835 
836  Context.getInjectedClassNameType(Result, CanonInjectedType);
837  return Result;
838 }
839 
842  unsigned ID) {
845  Result->MayHaveOutOfDateDef = false;
846  return Result;
847 }
848 
849 //===----------------------------------------------------------------------===//
850 // FriendTemplateDecl Implementation
851 //===----------------------------------------------------------------------===//
852 
853 void FriendTemplateDecl::anchor() {}
854 
857  SourceLocation L,
859  FriendUnion Friend, SourceLocation FLoc) {
860  return new (Context, DC) FriendTemplateDecl(DC, L, Params, Friend, FLoc);
861 }
862 
864  unsigned ID) {
865  return new (C, ID) FriendTemplateDecl(EmptyShell());
866 }
867 
868 //===----------------------------------------------------------------------===//
869 // TypeAliasTemplateDecl Implementation
870 //===----------------------------------------------------------------------===//
871 
873  DeclContext *DC,
874  SourceLocation L,
875  DeclarationName Name,
876  TemplateParameterList *Params,
877  NamedDecl *Decl) {
878  AdoptTemplateParameterList(Params, DC);
879  return new (C, DC) TypeAliasTemplateDecl(C, DC, L, Name, Params, Decl);
880 }
881 
883  unsigned ID) {
884  return new (C, ID) TypeAliasTemplateDecl(C, nullptr, SourceLocation(),
885  DeclarationName(), nullptr, nullptr);
886 }
887 
890  Common *CommonPtr = new (C) Common;
891  C.addDestruction(CommonPtr);
892  return CommonPtr;
893 }
894 
895 //===----------------------------------------------------------------------===//
896 // ClassScopeFunctionSpecializationDecl Implementation
897 //===----------------------------------------------------------------------===//
898 
899 void ClassScopeFunctionSpecializationDecl::anchor() {}
900 
903  unsigned ID) {
905  nullptr, SourceLocation(), nullptr, false, TemplateArgumentListInfo());
906 }
907 
908 //===----------------------------------------------------------------------===//
909 // VarTemplateDecl Implementation
910 //===----------------------------------------------------------------------===//
911 
913  VarTemplateDecl *CurD = this;
914  while (CurD) {
915  if (CurD->isThisDeclarationADefinition())
916  return CurD;
917  CurD = CurD->getPreviousDecl();
918  }
919  return nullptr;
920 }
921 
924  TemplateParameterList *Params,
925  VarDecl *Decl) {
926  return new (C, DC) VarTemplateDecl(C, DC, L, Name, Params, Decl);
927 }
928 
930  unsigned ID) {
931  return new (C, ID) VarTemplateDecl(C, nullptr, SourceLocation(),
932  DeclarationName(), nullptr, nullptr);
933 }
934 
936  loadLazySpecializationsImpl();
937 }
938 
939 llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
941  LoadLazySpecializations();
942  return getCommonPtr()->Specializations;
943 }
944 
945 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
947  LoadLazySpecializations();
948  return getCommonPtr()->PartialSpecializations;
949 }
950 
953  Common *CommonPtr = new (C) Common;
954  C.addDestruction(CommonPtr);
955  return CommonPtr;
956 }
957 
960  void *&InsertPos) {
961  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
962 }
963 
965  void *InsertPos) {
966  addSpecializationImpl<VarTemplateDecl>(getSpecializations(), D, InsertPos);
967 }
968 
971  void *&InsertPos) {
972  return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
973 }
974 
976  VarTemplatePartialSpecializationDecl *D, void *InsertPos) {
977  if (InsertPos)
978  getPartialSpecializations().InsertNode(D, InsertPos);
979  else {
981  getPartialSpecializations().GetOrInsertNode(D);
982  (void)Existing;
983  assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
984  }
985 
987  L->AddedCXXTemplateSpecialization(this, D);
988 }
989 
992  llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &PartialSpecs =
993  getPartialSpecializations();
994  PS.clear();
995  PS.reserve(PartialSpecs.size());
996  for (VarTemplatePartialSpecializationDecl &P : PartialSpecs)
997  PS.push_back(P.getMostRecentDecl());
998 }
999 
1003  Decl *DCanon = D->getCanonicalDecl();
1004  for (VarTemplatePartialSpecializationDecl &P : getPartialSpecializations()) {
1005  if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
1006  return P.getMostRecentDecl();
1007  }
1008 
1009  return nullptr;
1010 }
1011 
1012 //===----------------------------------------------------------------------===//
1013 // VarTemplateSpecializationDecl Implementation
1014 //===----------------------------------------------------------------------===//
1015 
1017  Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1018  SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1020  : VarDecl(DK, Context, DC, StartLoc, IdLoc,
1021  SpecializedTemplate->getIdentifier(), T, TInfo, S),
1022  SpecializedTemplate(SpecializedTemplate),
1023  TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
1024  SpecializationKind(TSK_Undeclared), IsCompleteDefinition(false) {}
1025 
1027  ASTContext &C)
1028  : VarDecl(DK, C, nullptr, SourceLocation(), SourceLocation(), nullptr,
1029  QualType(), nullptr, SC_None),
1030  SpecializationKind(TSK_Undeclared), IsCompleteDefinition(false) {}
1031 
1033  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1034  SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1036  return new (Context, DC) VarTemplateSpecializationDecl(
1037  VarTemplateSpecialization, Context, DC, StartLoc, IdLoc,
1038  SpecializedTemplate, T, TInfo, S, Args);
1039 }
1040 
1043  return new (C, ID)
1044  VarTemplateSpecializationDecl(VarTemplateSpecialization, C);
1045 }
1046 
1048  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
1049  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
1050 
1051  auto *PS = dyn_cast<VarTemplatePartialSpecializationDecl>(this);
1052  if (const ASTTemplateArgumentListInfo *ArgsAsWritten =
1053  PS ? PS->getTemplateArgsAsWritten() : nullptr) {
1054  printTemplateArgumentList(OS, ArgsAsWritten->arguments(), Policy);
1055  } else {
1056  const TemplateArgumentList &TemplateArgs = getTemplateArgs();
1057  printTemplateArgumentList(OS, TemplateArgs.asArray(), Policy);
1058  }
1059 }
1060 
1062  if (SpecializedPartialSpecialization *PartialSpec =
1063  SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1064  return PartialSpec->PartialSpecialization->getSpecializedTemplate();
1065  return SpecializedTemplate.get<VarTemplateDecl *>();
1066 }
1067 
1069  const TemplateArgumentListInfo &ArgsInfo) {
1070  TemplateArgsInfo.setLAngleLoc(ArgsInfo.getLAngleLoc());
1071  TemplateArgsInfo.setRAngleLoc(ArgsInfo.getRAngleLoc());
1072  for (const TemplateArgumentLoc &Loc : ArgsInfo.arguments())
1073  TemplateArgsInfo.addArgument(Loc);
1074 }
1075 
1076 //===----------------------------------------------------------------------===//
1077 // VarTemplatePartialSpecializationDecl Implementation
1078 //===----------------------------------------------------------------------===//
1079 
1080 void VarTemplatePartialSpecializationDecl::anchor() {}
1081 
1082 VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl(
1083  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1084  SourceLocation IdLoc, TemplateParameterList *Params,
1085  VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1087  const ASTTemplateArgumentListInfo *ArgInfos)
1088  : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization, Context,
1089  DC, StartLoc, IdLoc, SpecializedTemplate, T,
1090  TInfo, S, Args),
1091  TemplateParams(Params), ArgsAsWritten(ArgInfos),
1092  InstantiatedFromMember(nullptr, false) {
1093  // TODO: The template parameters should be in DC by now. Verify.
1094  // AdoptTemplateParameterList(Params, DC);
1095 }
1096 
1099  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1100  SourceLocation IdLoc, TemplateParameterList *Params,
1101  VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1103  const TemplateArgumentListInfo &ArgInfos) {
1104  const ASTTemplateArgumentListInfo *ASTArgInfos
1105  = ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
1106 
1108  new (Context, DC) VarTemplatePartialSpecializationDecl(
1109  Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo,
1110  S, Args, ASTArgInfos);
1112  return Result;
1113 }
1114 
1117  unsigned ID) {
1118  return new (C, ID) VarTemplatePartialSpecializationDecl(C);
1119 }
1120 
1121 static TemplateParameterList *
1123  // typename T
1124  auto *T = TemplateTypeParmDecl::Create(
1125  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/1, /*Position=*/0,
1126  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
1127  T->setImplicit(true);
1128 
1129  // T ...Ints
1130  TypeSourceInfo *TI =
1131  C.getTrivialTypeSourceInfo(QualType(T->getTypeForDecl(), 0));
1133  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1134  /*Id=*/nullptr, TI->getType(), /*ParameterPack=*/true, TI);
1135  N->setImplicit(true);
1136 
1137  // <typename T, T ...Ints>
1138  NamedDecl *P[2] = {T, N};
1139  auto *TPL = TemplateParameterList::Create(
1140  C, SourceLocation(), SourceLocation(), P, SourceLocation(), nullptr);
1141 
1142  // template <typename T, ...Ints> class IntSeq
1143  auto *TemplateTemplateParm = TemplateTemplateParmDecl::Create(
1144  C, DC, SourceLocation(), /*Depth=*/0, /*Position=*/0,
1145  /*ParameterPack=*/false, /*Id=*/nullptr, TPL);
1146  TemplateTemplateParm->setImplicit(true);
1147 
1148  // typename T
1149  auto *TemplateTypeParm = TemplateTypeParmDecl::Create(
1150  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1151  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
1152  TemplateTypeParm->setImplicit(true);
1153 
1154  // T N
1156  QualType(TemplateTypeParm->getTypeForDecl(), 0));
1157  auto *NonTypeTemplateParm = NonTypeTemplateParmDecl::Create(
1158  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/2,
1159  /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo);
1160  NamedDecl *Params[] = {TemplateTemplateParm, TemplateTypeParm,
1161  NonTypeTemplateParm};
1162 
1163  // template <template <typename T, T ...Ints> class IntSeq, typename T, T N>
1165  Params, SourceLocation(), nullptr);
1166 }
1167 
1168 static TemplateParameterList *
1170  // std::size_t Index
1172  auto *Index = NonTypeTemplateParmDecl::Create(
1173  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/0,
1174  /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo);
1175 
1176  // typename ...T
1177  auto *Ts = TemplateTypeParmDecl::Create(
1178  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1179  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/true);
1180  Ts->setImplicit(true);
1181 
1182  // template <std::size_t Index, typename ...T>
1183  NamedDecl *Params[] = {Index, Ts};
1185  llvm::makeArrayRef(Params),
1186  SourceLocation(), nullptr);
1187 }
1188 
1190  const ASTContext &C, DeclContext *DC, BuiltinTemplateKind BTK) {
1191  switch (BTK) {
1192  case BTK__make_integer_seq:
1193  return createMakeIntegerSeqParameterList(C, DC);
1195  return createTypePackElementParameterList(C, DC);
1196  }
1197 
1198  llvm_unreachable("unhandled BuiltinTemplateKind!");
1199 }
1200 
1201 void BuiltinTemplateDecl::anchor() {}
1202 
1203 BuiltinTemplateDecl::BuiltinTemplateDecl(const ASTContext &C, DeclContext *DC,
1204  DeclarationName Name,
1205  BuiltinTemplateKind BTK)
1206  : TemplateDecl(BuiltinTemplate, DC, SourceLocation(), Name,
1208  BTK(BTK) {}
Defines the clang::ASTContext interface.
void setImplicit(bool I=true)
Definition: DeclBase.h:552
Represents a function declaration or definition.
Definition: Decl.h:1696
A (possibly-)qualified type.
Definition: Type.h:653
virtual Decl * GetExternalDecl(uint32_t ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
llvm::FoldingSetVector< VarTemplateSpecializationDecl > & getSpecializations() const
Retrieve the set of specializations of this variable template.
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...
SourceRange getBraceRange() const
Definition: Decl.h:3095
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...
C Language Family Type Representation.
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:86
ArrayRef< NamedDecl * > asArray()
Definition: DeclTemplate.h:126
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.
void setSpecializationKind(TemplateSpecializationKind TSK)
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:133
A container of type source information.
Definition: Decl.h:86
void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo)
SourceLocation getEndLoc() const
Get the end source location.
Definition: TypeLoc.cpp:227
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:566
Represents a variable declaration or definition.
Definition: Decl.h:812
ASTMutationListener * getASTMutationListener() const
Definition: DeclBase.cpp:382
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
Declaration of a redeclarable template.
Definition: DeclTemplate.h:736
SourceLocation getExternLoc() const
Gets the location of the extern keyword, if present.
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:595
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:68
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclTemplate.h:462
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:269
SourceLocation getDefaultArgumentLoc() const
Retrieve the location of the default argument, if any.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
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...
unsigned getDepth() const
Retrieve the depth of the template parameter.
VarTemplateSpecializationDecl(Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< TemplateArgument > Args)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
Defines the position of a template parameter within a template parameter list.
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)
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
Stores the template parameter list and associated constraints for TemplateDecl objects that track ass...
Definition: DeclTemplate.h:370
Declaration of a function specialization at template class scope.
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Definition: DeclTemplate.h:507
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to form a template specialization. ...
A convenient class for passing around template argument information.
Definition: TemplateBase.h:546
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
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
Source range that this declaration covers.
Definition: Decl.cpp:1809
SourceLocation getDefaultArgumentLoc() const
Retrieves the location of the default argument declaration.
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
void setSpecializationKind(TemplateSpecializationKind TSK)
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5724
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:716
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
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.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
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:102
void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:688
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.
void AddPartialSpecialization(VarTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Definition: DeclBase.h:875
Expr - This represents one expression.
Definition: Expr.h:106
CommonBase * getCommonPtr() const
Retrieves the "common" pointer shared by all (re-)declarations of the same template.
void setAssociatedConstraints(Expr *AC)
Definition: DeclTemplate.h:486
SourceLocation End
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)
int Id
Definition: ASTDiff.cpp:191
const FunctionProtoType * T
Declaration of a template type parameter.
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
#define bool
Definition: stdbool.h:31
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Data that is common to all of the declarations of a given variable template.
SourceLocation Begin
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:264
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack...
Definition: DeclBase.cpp:201
Represents a C++ template name within the type system.
Definition: TemplateName.h:178
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy)
Print a template argument list, including the &#39;<&#39; and &#39;>&#39; enclosing the template arguments.
Defines the clang::TypeLoc interface and its subclasses.
StorageClass
Storage classes.
Definition: Specifiers.h:203
Declaration of an alias template.
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations()
Retrieve the set of partial specializations of this class template.
SourceLocation getEnd() const
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
static TemplateParameterList * createBuiltinTemplateParameterList(const ASTContext &C, DeclContext *DC, BuiltinTemplateKind BTK)
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
Data that is common to all of the declarations of a given class template.
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:1358
The result type of a method or function.
void addDestruction(T *Ptr)
If T isn&#39;t trivially destructible, calls AddDeallocation to register it for destruction.
Definition: ASTContext.h:2629
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:719
static StringRef getIdentifier(const Token &Tok)
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:1978
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl *> Params, SourceLocation RAngleLoc, Expr *RequiresClause)
static TypeAliasTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty alias template node.
void setTypeForDecl(const Type *TD)
Definition: Decl.h:2803
#define false
Definition: stdbool.h:33
The "struct" keyword.
Definition: Type.h:4694
llvm::FoldingSetVector< ClassTemplateSpecializationDecl > & getSpecializations() const
Retrieve the set of specializations of this class template.
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:208
uint32_t * LazySpecializations
If non-null, points to an array of specializations (including partial specializations) known only by ...
Definition: DeclTemplate.h:819
static ClassTemplateSpecializationDecl * Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, ClassTemplateSpecializationDecl *PrevDecl)
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.
bool isParameterPack() const
Returns whether this is a parameter pack.
Encodes a location in the source.
static TemplateTemplateParmDecl * CreateDeserialized(ASTContext &C, unsigned ID)
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getInstantiatedFrom() const
If this class template specialization is an instantiation of a template (rather than an explicit spec...
This names the __make_integer_seq BuiltinTemplateDecl.
Definition: Builtins.h:232
CommonBase * newCommon(ASTContext &C) const override
Data that is common to all of the declarations of a given function template.
Definition: DeclTemplate.h:973
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:230
static FriendTemplateDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation Loc, MutableArrayRef< TemplateParameterList *> Params, FriendUnion Friend, SourceLocation FriendLoc)
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:161
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
Definition: Specifiers.h:146
TypeSourceInfo * getTypeAsWritten() const
Gets the type of this specialization as it was written by the user, if it was so written.
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:565
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:586
static ClassTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl, Expr *AssociatedConstraints=nullptr)
Create a class template node.
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:650
Represents a template argument.
Definition: TemplateBase.h:51
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
TagTypeKind
The kind of a tag type.
Definition: Type.h:4692
Dataflow Directional Tag Classes.
void getInjectedTemplateArgs(const TemplateParameterList *Params, SmallVectorImpl< TemplateArgument > &Args)
Get a template argument list with one argument per template parameter in a template parameter list...
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
Appends a human-readable name for this declaration into the given stream.
Definition: Decl.cpp:1572
bool isValid() const
Return true if this is a valid SourceLocation object.
static ClassScopeFunctionSpecializationDecl * CreateDeserialized(ASTContext &Context, unsigned ID)
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:493
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:1256
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:399
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:157
unsigned getIndex() const
Retrieve the index of the template parameter.
static VarTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
DeclarationName - The name of a declaration.
static NonTypeTemplateParmDecl * CreateDeserialized(ASTContext &C, unsigned ID)
This names the __type_pack_element BuiltinTemplateDecl.
Definition: Builtins.h:235
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:143
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:574
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:1048
static FriendTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary variable pattern.
bool isNull() const
Determine whether this template argument has no value.
Definition: TemplateBase.h:238
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
Appends a human-readable name for this declaration into the given stream.
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const override
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:3019
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:450
static ClassTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
This template specialization was declared or defined by an explicit specialization (C++ [temp...
Definition: Specifiers.h:153
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)
VarTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this variable template, or nullptr if no such declaration exists...
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2201
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:210
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:239
SourceLocation getDefaultArgumentLoc() const
Retrieve the location of the default argument, if any.
TemplateArgument * InjectedArgs
The set of "injected" template arguments used within this function template.
Definition: DeclTemplate.h:985
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
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...
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
Defines the clang::SourceLocation class and associated facilities.
Represents a C++ struct/union/class.
Definition: DeclCXX.h:299
static const ASTTemplateArgumentListInfo * Create(ASTContext &C, const TemplateArgumentListInfo &List)
TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl *> Params, SourceLocation RAngleLoc, Expr *RequiresClause)
CommonBase * newCommon(ASTContext &C) const override
void addSpecializationImpl(llvm::FoldingSetVector< EntryType > &Specs, EntryType *Entry, void *InsertPos)
CommonBase * newCommon(ASTContext &C) const override
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
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:2807
QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const
getInjectedClassNameType - Return the unique reference to the injected class name type for the specif...
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:89
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:562
llvm::FoldingSetVector< FunctionTemplateSpecializationInfo > & getSpecializations() const
Retrieve the set of function template specializations of this function template.
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)
This represents a decl that may have a name.
Definition: Decl.h:248
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Declaration of a friend template.
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:563
VarTemplateDecl * getDefinition()
SourceRange getSourceRange() const LLVM_READONLY
Definition: DeclTemplate.h:176
Defines enum values for all the target-independent builtin functions.
Declaration of a template function.
Definition: DeclTemplate.h:967
ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, ClassTemplateSpecializationDecl *PrevDecl)
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:97
llvm::FoldingSetVector< VarTemplatePartialSpecializationDecl > & getPartialSpecializations()
Retrieve the set of partial specializations of this class template.
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.