clang  5.0.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  Expr *RequiresClause)
36  : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
37  NumParams(Params.size()), ContainsUnexpandedParameterPack(false),
38  HasRequiresClause(static_cast<bool>(RequiresClause)) {
39  for (unsigned Idx = 0; Idx < NumParams; ++Idx) {
40  NamedDecl *P = Params[Idx];
41  begin()[Idx] = P;
42 
43  if (!P->isTemplateParameterPack()) {
44  if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
45  if (NTTP->getType()->containsUnexpandedParameterPack())
46  ContainsUnexpandedParameterPack = true;
47 
48  if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
49  if (TTP->getTemplateParameters()->containsUnexpandedParameterPack())
50  ContainsUnexpandedParameterPack = true;
51 
52  // FIXME: If a default argument contains an unexpanded parameter pack, the
53  // template parameter list does too.
54  }
55  }
56  if (RequiresClause) {
57  *getTrailingObjects<Expr *>() = RequiresClause;
58  }
59 }
60 
63  SourceLocation LAngleLoc,
64  ArrayRef<NamedDecl *> Params,
65  SourceLocation RAngleLoc, Expr *RequiresClause) {
66  void *Mem = C.Allocate(totalSizeToAlloc<NamedDecl *, Expr *>(
67  Params.size(), RequiresClause ? 1u : 0u),
68  alignof(TemplateParameterList));
69  return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params,
70  RAngleLoc, RequiresClause);
71 }
72 
74  unsigned NumRequiredArgs = 0;
75  for (const NamedDecl *P : asArray()) {
76  if (P->isTemplateParameterPack()) {
77  if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
78  if (NTTP->isExpandedParameterPack()) {
79  NumRequiredArgs += NTTP->getNumExpansionTypes();
80  continue;
81  }
82 
83  break;
84  }
85 
86  if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(P)) {
87  if (TTP->hasDefaultArgument())
88  break;
89  } else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) {
90  if (NTTP->hasDefaultArgument())
91  break;
92  } else if (cast<TemplateTemplateParmDecl>(P)->hasDefaultArgument())
93  break;
94 
95  ++NumRequiredArgs;
96  }
97 
98  return NumRequiredArgs;
99 }
100 
102  if (size() == 0)
103  return 0;
104 
105  const NamedDecl *FirstParm = getParam(0);
106  if (const TemplateTypeParmDecl *TTP
107  = dyn_cast<TemplateTypeParmDecl>(FirstParm))
108  return TTP->getDepth();
109  else if (const NonTypeTemplateParmDecl *NTTP
110  = dyn_cast<NonTypeTemplateParmDecl>(FirstParm))
111  return NTTP->getDepth();
112  else
113  return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth();
114 }
115 
117  DeclContext *Owner) {
118  for (NamedDecl *P : *Params) {
119  P->setDeclContext(Owner);
120 
121  if (auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
122  AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner);
123  }
124 }
125 
126 namespace clang {
128  return new (C) char[sizeof(void*) * 2];
129 }
130 }
131 
132 //===----------------------------------------------------------------------===//
133 // RedeclarableTemplateDecl Implementation
134 //===----------------------------------------------------------------------===//
135 
137  if (Common)
138  return Common;
139 
140  // Walk the previous-declaration chain until we either find a declaration
141  // with a common pointer or we run out of previous declarations.
143  for (const RedeclarableTemplateDecl *Prev = getPreviousDecl(); Prev;
144  Prev = Prev->getPreviousDecl()) {
145  if (Prev->Common) {
146  Common = Prev->Common;
147  break;
148  }
149 
150  PrevDecls.push_back(Prev);
151  }
152 
153  // If we never found a common pointer, allocate one now.
154  if (!Common) {
155  // FIXME: If any of the declarations is from an AST file, we probably
156  // need an update record to add the common data.
157 
159  }
160 
161  // Update any previous declarations we saw with the common pointer.
162  for (const RedeclarableTemplateDecl *Prev : PrevDecls)
163  Prev->Common = Common;
164 
165  return Common;
166 }
167 
168 template<class EntryType>
171  llvm::FoldingSetVector<EntryType> &Specs, ArrayRef<TemplateArgument> Args,
172  void *&InsertPos) {
173  typedef SpecEntryTraits<EntryType> SETraits;
174  llvm::FoldingSetNodeID ID;
175  EntryType::Profile(ID,Args, getASTContext());
176  EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
177  return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
178 }
179 
180 template<class Derived, class EntryType>
182  llvm::FoldingSetVector<EntryType> &Specializations, EntryType *Entry,
183  void *InsertPos) {
184  typedef SpecEntryTraits<EntryType> SETraits;
185  if (InsertPos) {
186 #ifndef NDEBUG
187  void *CorrectInsertPos;
188  assert(!findSpecializationImpl(Specializations,
189  SETraits::getTemplateArgs(Entry),
190  CorrectInsertPos) &&
191  InsertPos == CorrectInsertPos &&
192  "given incorrect InsertPos for specialization");
193 #endif
194  Specializations.InsertNode(Entry, InsertPos);
195  } else {
196  EntryType *Existing = Specializations.GetOrInsertNode(Entry);
197  (void)Existing;
198  assert(SETraits::getDecl(Existing)->isCanonicalDecl() &&
199  "non-canonical specialization?");
200  }
201 
203  L->AddedCXXTemplateSpecialization(cast<Derived>(this),
204  SETraits::getDecl(Entry));
205 }
206 
207 //===----------------------------------------------------------------------===//
208 // FunctionTemplateDecl Implementation
209 //===----------------------------------------------------------------------===//
210 
212  DeclContext *DC,
213  SourceLocation L,
215  TemplateParameterList *Params,
216  NamedDecl *Decl) {
217  AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
218  return new (C, DC) FunctionTemplateDecl(C, DC, L, Name, Params, Decl);
219 }
220 
222  unsigned ID) {
223  return new (C, ID) FunctionTemplateDecl(C, nullptr, SourceLocation(),
224  DeclarationName(), nullptr, nullptr);
225 }
226 
229  Common *CommonPtr = new (C) Common;
230  C.addDestruction(CommonPtr);
231  return CommonPtr;
232 }
233 
235  // Grab the most recent declaration to ensure we've loaded any lazy
236  // redeclarations of this template.
237  //
238  // FIXME: Avoid walking the entire redeclaration chain here.
239  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
240  if (CommonPtr->LazySpecializations) {
242  uint32_t *Specs = CommonPtr->LazySpecializations;
243  CommonPtr->LazySpecializations = nullptr;
244  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
245  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
246  }
247 }
248 
249 llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
252  return getCommonPtr()->Specializations;
253 }
254 
255 FunctionDecl *
257  void *&InsertPos) {
258  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
259 }
260 
262  FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
263  addSpecializationImpl<FunctionTemplateDecl>(getSpecializations(), Info,
264  InsertPos);
265 }
266 
269  Common *CommonPtr = getCommonPtr();
270  if (!CommonPtr->InjectedArgs) {
271  auto &Context = getASTContext();
273  Context.getInjectedTemplateArgs(Params, TemplateArgs);
274  CommonPtr->InjectedArgs =
275  new (Context) TemplateArgument[TemplateArgs.size()];
276  std::copy(TemplateArgs.begin(), TemplateArgs.end(),
277  CommonPtr->InjectedArgs);
278  }
279 
280  return llvm::makeArrayRef(CommonPtr->InjectedArgs, Params->size());
281 }
282 
283 //===----------------------------------------------------------------------===//
284 // ClassTemplateDecl Implementation
285 //===----------------------------------------------------------------------===//
286 
288  DeclContext *DC,
289  SourceLocation L,
291  TemplateParameterList *Params,
292  NamedDecl *Decl,
293  Expr *AssociatedConstraints) {
294  AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
295 
296  if (!AssociatedConstraints) {
297  return new (C, DC) ClassTemplateDecl(C, DC, L, Name, Params, Decl);
298  }
299 
301  ClassTemplateDecl *const New =
302  new (C, DC) ClassTemplateDecl(CTDI, C, DC, L, Name, Params, Decl);
303  New->setAssociatedConstraints(AssociatedConstraints);
304  return New;
305 }
306 
308  unsigned ID) {
309  return new (C, ID) ClassTemplateDecl(C, nullptr, SourceLocation(),
310  DeclarationName(), nullptr, nullptr);
311 }
312 
314  // Grab the most recent declaration to ensure we've loaded any lazy
315  // redeclarations of this template.
316  //
317  // FIXME: Avoid walking the entire redeclaration chain here.
318  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
319  if (CommonPtr->LazySpecializations) {
321  uint32_t *Specs = CommonPtr->LazySpecializations;
322  CommonPtr->LazySpecializations = nullptr;
323  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
324  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
325  }
326 }
327 
328 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
331  return getCommonPtr()->Specializations;
332 }
333 
334 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
338 }
339 
342  Common *CommonPtr = new (C) Common;
343  C.addDestruction(CommonPtr);
344  return CommonPtr;
345 }
346 
349  void *&InsertPos) {
350  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
351 }
352 
354  void *InsertPos) {
355  addSpecializationImpl<ClassTemplateDecl>(getSpecializations(), D, InsertPos);
356 }
357 
360  void *&InsertPos) {
361  return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
362 }
363 
366  void *InsertPos) {
367  if (InsertPos)
368  getPartialSpecializations().InsertNode(D, InsertPos);
369  else {
371  = getPartialSpecializations().GetOrInsertNode(D);
372  (void)Existing;
373  assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
374  }
375 
377  L->AddedCXXTemplateSpecialization(this, D);
378 }
379 
382  llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs
384  PS.clear();
385  PS.reserve(PartialSpecs.size());
386  for (ClassTemplatePartialSpecializationDecl &P : PartialSpecs)
387  PS.push_back(P.getMostRecentDecl());
388 }
389 
395  if (Context.hasSameType(P.getInjectedSpecializationType(), T))
396  return P.getMostRecentDecl();
397  }
398 
399  return nullptr;
400 }
401 
405  Decl *DCanon = D->getCanonicalDecl();
407  if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
408  return P.getMostRecentDecl();
409  }
410 
411  return nullptr;
412 }
413 
414 QualType
416  Common *CommonPtr = getCommonPtr();
417  if (!CommonPtr->InjectedClassNameType.isNull())
418  return CommonPtr->InjectedClassNameType;
419 
420  // C++0x [temp.dep.type]p2:
421  // The template argument list of a primary template is a template argument
422  // list in which the nth template argument has the value of the nth template
423  // parameter of the class template. If the nth template parameter is a
424  // template parameter pack (14.5.3), the nth template argument is a pack
425  // expansion (14.5.3) whose pattern is the name of the template parameter
426  // pack.
430  Context.getInjectedTemplateArgs(Params, TemplateArgs);
431  CommonPtr->InjectedClassNameType
433  TemplateArgs);
434  return CommonPtr->InjectedClassNameType;
435 }
436 
437 //===----------------------------------------------------------------------===//
438 // TemplateTypeParm Allocation/Deallocation Method Implementations
439 //===----------------------------------------------------------------------===//
440 
443  SourceLocation KeyLoc, SourceLocation NameLoc,
444  unsigned D, unsigned P, IdentifierInfo *Id,
445  bool Typename, bool ParameterPack) {
446  TemplateTypeParmDecl *TTPDecl =
447  new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename);
448  QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
449  TTPDecl->setTypeForDecl(TTPType.getTypePtr());
450  return TTPDecl;
451 }
452 
455  return new (C, ID) TemplateTypeParmDecl(nullptr, SourceLocation(),
456  SourceLocation(), nullptr, false);
457 }
458 
460  return hasDefaultArgument()
462  : SourceLocation();
463 }
464 
467  return SourceRange(getLocStart(),
468  getDefaultArgumentInfo()->getTypeLoc().getEndLoc());
469  else
470  return TypeDecl::getSourceRange();
471 }
472 
475 }
476 
479 }
480 
483 }
484 
485 //===----------------------------------------------------------------------===//
486 // NonTypeTemplateParmDecl Method Implementations
487 //===----------------------------------------------------------------------===//
488 
489 NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(
490  DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D,
491  unsigned P, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
492  ArrayRef<QualType> ExpandedTypes, ArrayRef<TypeSourceInfo *> ExpandedTInfos)
493  : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
494  TemplateParmPosition(D, P), ParameterPack(true),
495  ExpandedParameterPack(true), NumExpandedTypes(ExpandedTypes.size()) {
496  if (!ExpandedTypes.empty() && !ExpandedTInfos.empty()) {
497  auto TypesAndInfos =
498  getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
499  for (unsigned I = 0; I != NumExpandedTypes; ++I) {
500  new (&TypesAndInfos[I].first) QualType(ExpandedTypes[I]);
501  TypesAndInfos[I].second = ExpandedTInfos[I];
502  }
503  }
504 }
505 
508  SourceLocation StartLoc, SourceLocation IdLoc,
509  unsigned D, unsigned P, IdentifierInfo *Id,
510  QualType T, bool ParameterPack,
511  TypeSourceInfo *TInfo) {
512  return new (C, DC) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id,
513  T, ParameterPack, TInfo);
514 }
515 
517  const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
518  SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id,
519  QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes,
520  ArrayRef<TypeSourceInfo *> ExpandedTInfos) {
521  return new (C, DC,
522  additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>(
523  ExpandedTypes.size()))
524  NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, T, TInfo,
525  ExpandedTypes, ExpandedTInfos);
526 }
527 
530  return new (C, ID) NonTypeTemplateParmDecl(nullptr, SourceLocation(),
531  SourceLocation(), 0, 0, nullptr,
532  QualType(), false, nullptr);
533 }
534 
537  unsigned NumExpandedTypes) {
538  auto *NTTP =
539  new (C, ID, additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>(
540  NumExpandedTypes))
542  0, 0, nullptr, QualType(), nullptr, None,
543  None);
544  NTTP->NumExpandedTypes = NumExpandedTypes;
545  return NTTP;
546 }
547 
550  return SourceRange(getOuterLocStart(),
551  getDefaultArgument()->getSourceRange().getEnd());
553 }
554 
556  return hasDefaultArgument()
558  : SourceLocation();
559 }
560 
561 //===----------------------------------------------------------------------===//
562 // TemplateTemplateParmDecl Method Implementations
563 //===----------------------------------------------------------------------===//
564 
565 void TemplateTemplateParmDecl::anchor() { }
566 
567 TemplateTemplateParmDecl::TemplateTemplateParmDecl(
568  DeclContext *DC, SourceLocation L, unsigned D, unsigned P,
570  ArrayRef<TemplateParameterList *> Expansions)
571  : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
572  TemplateParmPosition(D, P), ParameterPack(true),
573  ExpandedParameterPack(true), NumExpandedParams(Expansions.size()) {
574  if (!Expansions.empty())
575  std::uninitialized_copy(Expansions.begin(), Expansions.end(),
576  getTrailingObjects<TemplateParameterList *>());
577 }
578 
581  SourceLocation L, unsigned D, unsigned P,
582  bool ParameterPack, IdentifierInfo *Id,
583  TemplateParameterList *Params) {
584  return new (C, DC) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id,
585  Params);
586 }
587 
590  SourceLocation L, unsigned D, unsigned P,
591  IdentifierInfo *Id,
592  TemplateParameterList *Params,
594  return new (C, DC,
595  additionalSizeToAlloc<TemplateParameterList *>(Expansions.size()))
596  TemplateTemplateParmDecl(DC, L, D, P, Id, Params, Expansions);
597 }
598 
601  return new (C, ID) TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0,
602  false, nullptr, nullptr);
603 }
604 
607  unsigned NumExpansions) {
608  auto *TTP =
609  new (C, ID, additionalSizeToAlloc<TemplateParameterList *>(NumExpansions))
610  TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0, nullptr,
611  nullptr, None);
612  TTP->NumExpandedParams = NumExpansions;
613  return TTP;
614 }
615 
618  : SourceLocation();
619 }
620 
622  const ASTContext &C, const TemplateArgumentLoc &DefArg) {
623  if (DefArg.getArgument().isNull())
624  DefaultArgument.set(nullptr);
625  else
626  DefaultArgument.set(new (C) TemplateArgumentLoc(DefArg));
627 }
628 
629 //===----------------------------------------------------------------------===//
630 // TemplateArgumentList Implementation
631 //===----------------------------------------------------------------------===//
632 TemplateArgumentList::TemplateArgumentList(ArrayRef<TemplateArgument> Args)
633  : Arguments(getTrailingObjects<TemplateArgument>()),
634  NumArguments(Args.size()) {
635  std::uninitialized_copy(Args.begin(), Args.end(),
636  getTrailingObjects<TemplateArgument>());
637 }
638 
642  void *Mem = Context.Allocate(totalSizeToAlloc<TemplateArgument>(Args.size()));
643  return new (Mem) TemplateArgumentList(Args);
644 }
645 
648  FunctionTemplateDecl *Template,
650  const TemplateArgumentList *TemplateArgs,
651  const TemplateArgumentListInfo *TemplateArgsAsWritten,
652  SourceLocation POI) {
653  const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
654  if (TemplateArgsAsWritten)
655  ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C,
656  *TemplateArgsAsWritten);
657 
658  return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK,
659  TemplateArgs,
660  ArgsAsWritten,
661  POI);
662 }
663 
664 //===----------------------------------------------------------------------===//
665 // TemplateDecl Implementation
666 //===----------------------------------------------------------------------===//
667 
668 void TemplateDecl::anchor() { }
669 
670 //===----------------------------------------------------------------------===//
671 // ClassTemplateSpecializationDecl Implementation
672 //===----------------------------------------------------------------------===//
675  DeclContext *DC, SourceLocation StartLoc,
676  SourceLocation IdLoc,
677  ClassTemplateDecl *SpecializedTemplate,
680  : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc,
681  SpecializedTemplate->getIdentifier(),
682  PrevDecl),
683  SpecializedTemplate(SpecializedTemplate),
684  ExplicitInfo(nullptr),
685  TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
686  SpecializationKind(TSK_Undeclared) {
687 }
688 
690  Kind DK)
691  : CXXRecordDecl(DK, TTK_Struct, C, nullptr, SourceLocation(),
692  SourceLocation(), nullptr, nullptr),
693  ExplicitInfo(nullptr), SpecializationKind(TSK_Undeclared) {}
694 
697  DeclContext *DC,
698  SourceLocation StartLoc,
699  SourceLocation IdLoc,
700  ClassTemplateDecl *SpecializedTemplate,
705  Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc,
706  SpecializedTemplate, Args, PrevDecl);
707  Result->MayHaveOutOfDateDef = false;
708 
709  Context.getTypeDeclType(Result, PrevDecl);
710  return Result;
711 }
712 
715  unsigned ID) {
717  new (C, ID) ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization);
718  Result->MayHaveOutOfDateDef = false;
719  return Result;
720 }
721 
723  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
724  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
725 
726  auto *PS = dyn_cast<ClassTemplatePartialSpecializationDecl>(this);
727  if (const ASTTemplateArgumentListInfo *ArgsAsWritten =
728  PS ? PS->getTemplateArgsAsWritten() : nullptr) {
730  OS, ArgsAsWritten->arguments(), Policy);
731  } else {
732  const TemplateArgumentList &TemplateArgs = getTemplateArgs();
734  OS, TemplateArgs.asArray(), Policy);
735  }
736 }
737 
740  if (SpecializedPartialSpecialization *PartialSpec
741  = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
742  return PartialSpec->PartialSpecialization->getSpecializedTemplate();
743  return SpecializedTemplate.get<ClassTemplateDecl*>();
744 }
745 
748  if (ExplicitInfo) {
750  if (Begin.isValid()) {
751  // Here we have an explicit (partial) specialization or instantiation.
755  if (getExternLoc().isValid())
756  Begin = getExternLoc();
758  if (End.isInvalid())
760  return SourceRange(Begin, End);
761  }
762  // An implicit instantiation of a class template partial specialization
763  // uses ExplicitInfo to record the TypeAsWritten, but the source
764  // locations should be retrieved from the instantiation pattern.
766  CTPSDecl *ctpsd = const_cast<CTPSDecl*>(cast<CTPSDecl>(this));
767  CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember();
768  assert(inst_from != nullptr);
769  return inst_from->getSourceRange();
770  }
771  else {
772  // No explicit info available.
773  llvm::PointerUnion<ClassTemplateDecl *,
775  inst_from = getInstantiatedFrom();
776  if (inst_from.isNull())
778  if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>())
779  return ctd->getSourceRange();
780  return inst_from.get<ClassTemplatePartialSpecializationDecl*>()
781  ->getSourceRange();
782  }
783 }
784 
785 //===----------------------------------------------------------------------===//
786 // ClassTemplatePartialSpecializationDecl Implementation
787 //===----------------------------------------------------------------------===//
788 void ClassTemplatePartialSpecializationDecl::anchor() { }
789 
790 ClassTemplatePartialSpecializationDecl::
791 ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK,
792  DeclContext *DC,
793  SourceLocation StartLoc,
794  SourceLocation IdLoc,
795  TemplateParameterList *Params,
796  ClassTemplateDecl *SpecializedTemplate,
797  ArrayRef<TemplateArgument> Args,
798  const ASTTemplateArgumentListInfo *ArgInfos,
801  ClassTemplatePartialSpecialization,
802  TK, DC, StartLoc, IdLoc,
803  SpecializedTemplate,
804  Args, PrevDecl),
805  TemplateParams(Params), ArgsAsWritten(ArgInfos),
806  InstantiatedFromMember(nullptr, false)
807 {
808  AdoptTemplateParameterList(Params, this);
809 }
810 
814  SourceLocation StartLoc, SourceLocation IdLoc,
815  TemplateParameterList *Params,
816  ClassTemplateDecl *SpecializedTemplate,
818  const TemplateArgumentListInfo &ArgInfos,
819  QualType CanonInjectedType,
821  const ASTTemplateArgumentListInfo *ASTArgInfos =
822  ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
823 
825  ClassTemplatePartialSpecializationDecl(Context, TK, DC, StartLoc, IdLoc,
826  Params, SpecializedTemplate, Args,
827  ASTArgInfos, PrevDecl);
829  Result->MayHaveOutOfDateDef = false;
830 
831  Context.getInjectedClassNameType(Result, CanonInjectedType);
832  return Result;
833 }
834 
837  unsigned ID) {
840  Result->MayHaveOutOfDateDef = false;
841  return Result;
842 }
843 
844 //===----------------------------------------------------------------------===//
845 // FriendTemplateDecl Implementation
846 //===----------------------------------------------------------------------===//
847 
848 void FriendTemplateDecl::anchor() { }
849 
852  SourceLocation L,
854  FriendUnion Friend, SourceLocation FLoc) {
855  return new (Context, DC) FriendTemplateDecl(DC, L, Params, Friend, FLoc);
856 }
857 
859  unsigned ID) {
860  return new (C, ID) FriendTemplateDecl(EmptyShell());
861 }
862 
863 //===----------------------------------------------------------------------===//
864 // TypeAliasTemplateDecl Implementation
865 //===----------------------------------------------------------------------===//
866 
868  DeclContext *DC,
869  SourceLocation L,
871  TemplateParameterList *Params,
872  NamedDecl *Decl) {
873  AdoptTemplateParameterList(Params, DC);
874  return new (C, DC) TypeAliasTemplateDecl(C, DC, L, Name, Params, Decl);
875 }
876 
878  unsigned ID) {
879  return new (C, ID) TypeAliasTemplateDecl(C, nullptr, SourceLocation(),
880  DeclarationName(), nullptr, nullptr);
881 }
882 
885  Common *CommonPtr = new (C) Common;
886  C.addDestruction(CommonPtr);
887  return CommonPtr;
888 }
889 
890 //===----------------------------------------------------------------------===//
891 // ClassScopeFunctionSpecializationDecl Implementation
892 //===----------------------------------------------------------------------===//
893 
894 void ClassScopeFunctionSpecializationDecl::anchor() { }
895 
898  unsigned ID) {
900  nullptr, SourceLocation(), nullptr, false, TemplateArgumentListInfo());
901 }
902 
903 //===----------------------------------------------------------------------===//
904 // VarTemplateDecl Implementation
905 //===----------------------------------------------------------------------===//
906 
908  VarTemplateDecl *CurD = this;
909  while (CurD) {
910  if (CurD->isThisDeclarationADefinition())
911  return CurD;
912  CurD = CurD->getPreviousDecl();
913  }
914  return nullptr;
915 }
916 
919  TemplateParameterList *Params,
920  VarDecl *Decl) {
921  return new (C, DC) VarTemplateDecl(C, DC, L, Name, Params, Decl);
922 }
923 
925  unsigned ID) {
926  return new (C, ID) VarTemplateDecl(C, nullptr, SourceLocation(),
927  DeclarationName(), nullptr, nullptr);
928 }
929 
930 // TODO: Unify across class, function and variable templates?
931 // May require moving this and Common to RedeclarableTemplateDecl.
933  // Grab the most recent declaration to ensure we've loaded any lazy
934  // redeclarations of this template.
935  //
936  // FIXME: Avoid walking the entire redeclaration chain here.
937  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
938  if (CommonPtr->LazySpecializations) {
940  uint32_t *Specs = CommonPtr->LazySpecializations;
941  CommonPtr->LazySpecializations = nullptr;
942  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
943  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
944  }
945 }
946 
947 llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
950  return getCommonPtr()->Specializations;
951 }
952 
953 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
957 }
958 
961  Common *CommonPtr = new (C) Common;
962  C.addDestruction(CommonPtr);
963  return CommonPtr;
964 }
965 
968  void *&InsertPos) {
969  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
970 }
971 
973  void *InsertPos) {
974  addSpecializationImpl<VarTemplateDecl>(getSpecializations(), D, InsertPos);
975 }
976 
979  void *&InsertPos) {
980  return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
981 }
982 
984  VarTemplatePartialSpecializationDecl *D, void *InsertPos) {
985  if (InsertPos)
986  getPartialSpecializations().InsertNode(D, InsertPos);
987  else {
989  getPartialSpecializations().GetOrInsertNode(D);
990  (void)Existing;
991  assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
992  }
993 
995  L->AddedCXXTemplateSpecialization(this, D);
996 }
997 
1000  llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &PartialSpecs =
1002  PS.clear();
1003  PS.reserve(PartialSpecs.size());
1004  for (VarTemplatePartialSpecializationDecl &P : PartialSpecs)
1005  PS.push_back(P.getMostRecentDecl());
1006 }
1007 
1011  Decl *DCanon = D->getCanonicalDecl();
1013  if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
1014  return P.getMostRecentDecl();
1015  }
1016 
1017  return nullptr;
1018 }
1019 
1020 //===----------------------------------------------------------------------===//
1021 // VarTemplateSpecializationDecl Implementation
1022 //===----------------------------------------------------------------------===//
1024  Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1025  SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1027  : VarDecl(DK, Context, DC, StartLoc, IdLoc,
1028  SpecializedTemplate->getIdentifier(), T, TInfo, S),
1029  SpecializedTemplate(SpecializedTemplate), ExplicitInfo(nullptr),
1030  TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
1031  SpecializationKind(TSK_Undeclared) {}
1032 
1034  ASTContext &C)
1035  : VarDecl(DK, C, nullptr, SourceLocation(), SourceLocation(), nullptr,
1036  QualType(), nullptr, SC_None),
1037  ExplicitInfo(nullptr), SpecializationKind(TSK_Undeclared) {}
1038 
1040  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1041  SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1043  return new (Context, DC) VarTemplateSpecializationDecl(
1044  VarTemplateSpecialization, Context, DC, StartLoc, IdLoc,
1045  SpecializedTemplate, T, TInfo, S, Args);
1046 }
1047 
1050  return new (C, ID)
1051  VarTemplateSpecializationDecl(VarTemplateSpecialization, C);
1052 }
1053 
1055  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
1056  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
1057 
1058  auto *PS = dyn_cast<VarTemplatePartialSpecializationDecl>(this);
1059  if (const ASTTemplateArgumentListInfo *ArgsAsWritten =
1060  PS ? PS->getTemplateArgsAsWritten() : nullptr) {
1062  OS, ArgsAsWritten->arguments(), Policy);
1063  } else {
1064  const TemplateArgumentList &TemplateArgs = getTemplateArgs();
1066  OS, TemplateArgs.asArray(), Policy);
1067  }
1068 }
1069 
1071  if (SpecializedPartialSpecialization *PartialSpec =
1072  SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1073  return PartialSpec->PartialSpecialization->getSpecializedTemplate();
1074  return SpecializedTemplate.get<VarTemplateDecl *>();
1075 }
1076 
1078  const TemplateArgumentListInfo &ArgsInfo) {
1079  TemplateArgsInfo.setLAngleLoc(ArgsInfo.getLAngleLoc());
1080  TemplateArgsInfo.setRAngleLoc(ArgsInfo.getRAngleLoc());
1081  for (const TemplateArgumentLoc &Loc : ArgsInfo.arguments())
1082  TemplateArgsInfo.addArgument(Loc);
1083 }
1084 
1085 //===----------------------------------------------------------------------===//
1086 // VarTemplatePartialSpecializationDecl Implementation
1087 //===----------------------------------------------------------------------===//
1088 void VarTemplatePartialSpecializationDecl::anchor() {}
1089 
1090 VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl(
1091  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1092  SourceLocation IdLoc, TemplateParameterList *Params,
1093  VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1094  StorageClass S, ArrayRef<TemplateArgument> Args,
1095  const ASTTemplateArgumentListInfo *ArgInfos)
1096  : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization, Context,
1097  DC, StartLoc, IdLoc, SpecializedTemplate, T,
1098  TInfo, S, Args),
1099  TemplateParams(Params), ArgsAsWritten(ArgInfos),
1100  InstantiatedFromMember(nullptr, false) {
1101  // TODO: The template parameters should be in DC by now. Verify.
1102  // AdoptTemplateParameterList(Params, DC);
1103 }
1104 
1107  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1108  SourceLocation IdLoc, TemplateParameterList *Params,
1109  VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1111  const TemplateArgumentListInfo &ArgInfos) {
1112  const ASTTemplateArgumentListInfo *ASTArgInfos
1113  = ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
1114 
1117  Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo,
1118  S, Args, ASTArgInfos);
1120  return Result;
1121 }
1122 
1125  unsigned ID) {
1126  return new (C, ID) VarTemplatePartialSpecializationDecl(C);
1127 }
1128 
1129 static TemplateParameterList *
1131  // typename T
1132  auto *T = TemplateTypeParmDecl::Create(
1133  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/1, /*Position=*/0,
1134  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
1135  T->setImplicit(true);
1136 
1137  // T ...Ints
1138  TypeSourceInfo *TI =
1139  C.getTrivialTypeSourceInfo(QualType(T->getTypeForDecl(), 0));
1141  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1142  /*Id=*/nullptr, TI->getType(), /*ParameterPack=*/true, TI);
1143  N->setImplicit(true);
1144 
1145  // <typename T, T ...Ints>
1146  NamedDecl *P[2] = {T, N};
1147  auto *TPL = TemplateParameterList::Create(
1148  C, SourceLocation(), SourceLocation(), P, SourceLocation(), nullptr);
1149 
1150  // template <typename T, ...Ints> class IntSeq
1151  auto *TemplateTemplateParm = TemplateTemplateParmDecl::Create(
1152  C, DC, SourceLocation(), /*Depth=*/0, /*Position=*/0,
1153  /*ParameterPack=*/false, /*Id=*/nullptr, TPL);
1154  TemplateTemplateParm->setImplicit(true);
1155 
1156  // typename T
1157  auto *TemplateTypeParm = TemplateTypeParmDecl::Create(
1158  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1159  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
1160  TemplateTypeParm->setImplicit(true);
1161 
1162  // T N
1164  QualType(TemplateTypeParm->getTypeForDecl(), 0));
1165  auto *NonTypeTemplateParm = NonTypeTemplateParmDecl::Create(
1166  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/2,
1167  /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo);
1168  NamedDecl *Params[] = {TemplateTemplateParm, TemplateTypeParm,
1169  NonTypeTemplateParm};
1170 
1171  // template <template <typename T, T ...Ints> class IntSeq, typename T, T N>
1173  Params, SourceLocation(), nullptr);
1174 }
1175 
1176 static TemplateParameterList *
1178  // std::size_t Index
1180  auto *Index = NonTypeTemplateParmDecl::Create(
1181  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/0,
1182  /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo);
1183 
1184  // typename ...T
1185  auto *Ts = TemplateTypeParmDecl::Create(
1186  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1187  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/true);
1188  Ts->setImplicit(true);
1189 
1190  // template <std::size_t Index, typename ...T>
1191  NamedDecl *Params[] = {Index, Ts};
1193  llvm::makeArrayRef(Params),
1194  SourceLocation(), nullptr);
1195 }
1196 
1198  const ASTContext &C, DeclContext *DC, BuiltinTemplateKind BTK) {
1199  switch (BTK) {
1200  case BTK__make_integer_seq:
1201  return createMakeIntegerSeqParameterList(C, DC);
1203  return createTypePackElementParameterList(C, DC);
1204  }
1205 
1206  llvm_unreachable("unhandled BuiltinTemplateKind!");
1207 }
1208 
1209 void BuiltinTemplateDecl::anchor() {}
1210 
1211 BuiltinTemplateDecl::BuiltinTemplateDecl(const ASTContext &C, DeclContext *DC,
1213  BuiltinTemplateKind BTK)
1214  : TemplateDecl(BuiltinTemplate, DC, SourceLocation(), Name,
1216  BTK(BTK) {}
Defines the clang::ASTContext interface.
SourceLocation getEnd() const
void setImplicit(bool I=true)
Definition: DeclBase.h:538
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1618
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:616
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.
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)
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:81
ArrayRef< NamedDecl * > asArray()
Definition: DeclTemplate.h:105
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 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...
void setSpecializationKind(TemplateSpecializationKind TSK)
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:112
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:544
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:758
Declaration of a redeclarable template.
Definition: DeclTemplate.h:724
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:573
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:50
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Defines the clang::Expr interface and subclasses for C++ expressions.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclTemplate.h:439
ASTMutationListener * getASTMutationListener() const
Definition: DeclBase.cpp:350
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)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:128
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:460
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:2103
Stores the template parameter list and associated constraints for TemplateDecl objects that track ass...
Definition: DeclTemplate.h:349
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:1295
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:1548
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Definition: DeclTemplate.h:494
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:169
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
void set(ArgType Arg)
Set the default argument.
Definition: DeclTemplate.h:323
A convenient class for passing around template argument information.
Definition: TemplateBase.h:524
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
Source range that this declaration covers.
Definition: Decl.cpp:1797
void setSpecializationKind(TemplateSpecializationKind TSK)
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:671
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:541
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
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
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack...
Definition: DeclBase.cpp:180
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:948
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:97
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:2666
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:636
ASTContext * Context
const SmallVectorImpl< AnnotatedLine * >::const_iterator End
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:247
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:2663
Expr - This represents one expression.
Definition: Expr.h:105
void setAssociatedConstraints(Expr *AC)
Definition: DeclTemplate.h:473
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.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
#define bool
Definition: stdbool.h:31
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...
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
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:202
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.
void addDestruction(T *Ptr)
If T isn't trivially destructible, calls AddDeallocation to register it for destruction.
Definition: ASTContext.h:2505
static StringRef getIdentifier(const Token &Tok)
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:1966
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:206
void setTypeForDecl(const Type *TD)
Definition: Decl.h:2664
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:222
#define false
Definition: stdbool.h:33
The "struct" keyword.
Definition: Type.h:4490
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:197
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.
SourceLocation getOuterLocStart() const
getOuterLocStart - Return SourceLocation representing start of source range taking into account any o...
Definition: Decl.cpp:1753
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:1014
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5489
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:229
SourceRange getBraceRange() const
Definition: Decl.h:2935
bool isValid() const
Return true if this is a valid SourceLocation object.
const std::string ID
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:346
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:943
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:227
FunctionTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Definition: DeclTemplate.h:967
CommonBase * Common
Pointer to the common data shared by all declarations of this template.
Definition: DeclTemplate.h:798
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:540
ClassTemplateDecl * getMostRecentDecl()
SourceLocation getBegin() const
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:160
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
Definition: Specifiers.h:145
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:543
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:70
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:564
static ClassTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl, Expr *AssociatedConstraints=nullptr)
Create a class template node.
Represents a template argument.
Definition: TemplateBase.h:40
TagTypeKind
The kind of a tag type.
Definition: Type.h:4488
void getInjectedTemplateArgs(const TemplateParameterList *Params, SmallVectorImpl< TemplateArgument > &Args)
Get a template argument list with one argument per template parameter in a template parameter list...
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:1215
static ClassTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty class template node.
StringRef Name
Definition: USRFinder.cpp:123
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:378
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Definition: DeclBase.h:847
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:156
static VarTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
DeclarationName - The name of a declaration.
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:216
This names the __type_pack_element BuiltinTemplateDecl.
Definition: Builtins.h:232
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:142
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:2867
ClassTemplateDecl(ConstrainedTemplateDeclInfo *CTDI, ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Common * getCommonPtr() const
Definition: DeclTemplate.h:975
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:428
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:6042
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:152
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...
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:552
static VarTemplateSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
A template argument list.
Definition: DeclTemplate.h:195
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:957
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:267
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:623
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
Source range that this declaration covers.
Definition: Decl.h:2668
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:410
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:245
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:964
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:84
llvm::FoldingSetVector< VarTemplateSpecializationDecl > Specializations
The variable template specializations for this variable template, including explicit specializations ...
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
#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
Source range that this declaration covers.
Declaration of a friend template.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:683
VarTemplateDecl * getDefinition()
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:471
Defines enum values for all the target-independent builtin functions.
Declaration of a template function.
Definition: DeclTemplate.h:939
ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, ClassTemplateSpecializationDecl *PrevDecl)
std::vector< const ClassTemplatePartialSpecializationDecl * > PartialSpecs
llvm::FoldingSetVector< VarTemplatePartialSpecializationDecl > & getPartialSpecializations()
Retrieve the set of partial specializations of this class template.
FunctionTemplateDecl * getMostRecentDecl()