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"
21 #include "clang/AST/TemplateBase.h"
22 #include "clang/AST/TemplateName.h"
23 #include "clang/AST/Type.h"
24 #include "clang/AST/TypeLoc.h"
25 #include "clang/Basic/Builtins.h"
26 #include "clang/Basic/LLVM.h"
28 #include "llvm/ADT/ArrayRef.h"
29 #include "llvm/ADT/FoldingSet.h"
30 #include "llvm/ADT/None.h"
31 #include "llvm/ADT/PointerUnion.h"
32 #include "llvm/ADT/SmallVector.h"
33 #include "llvm/Support/Casting.h"
34 #include "llvm/Support/ErrorHandling.h"
35 #include <algorithm>
36 #include <cassert>
37 #include <cstdint>
38 #include <memory>
39 #include <utility>
40 
41 using namespace clang;
42 
43 //===----------------------------------------------------------------------===//
44 // TemplateParameterList Implementation
45 //===----------------------------------------------------------------------===//
46 
48  SourceLocation LAngleLoc,
49  ArrayRef<NamedDecl *> Params,
50  SourceLocation RAngleLoc,
51  Expr *RequiresClause)
52  : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
53  NumParams(Params.size()), ContainsUnexpandedParameterPack(false),
54  HasRequiresClause(static_cast<bool>(RequiresClause)) {
55  for (unsigned Idx = 0; Idx < NumParams; ++Idx) {
56  NamedDecl *P = Params[Idx];
57  begin()[Idx] = P;
58 
59  if (!P->isTemplateParameterPack()) {
60  if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
61  if (NTTP->getType()->containsUnexpandedParameterPack())
62  ContainsUnexpandedParameterPack = true;
63 
64  if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
65  if (TTP->getTemplateParameters()->containsUnexpandedParameterPack())
66  ContainsUnexpandedParameterPack = true;
67 
68  // FIXME: If a default argument contains an unexpanded parameter pack, the
69  // template parameter list does too.
70  }
71  }
72  if (RequiresClause) {
73  *getTrailingObjects<Expr *>() = RequiresClause;
74  }
75 }
76 
79  SourceLocation LAngleLoc,
80  ArrayRef<NamedDecl *> Params,
81  SourceLocation RAngleLoc, Expr *RequiresClause) {
82  void *Mem = C.Allocate(totalSizeToAlloc<NamedDecl *, Expr *>(
83  Params.size(), RequiresClause ? 1u : 0u),
84  alignof(TemplateParameterList));
85  return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params,
86  RAngleLoc, RequiresClause);
87 }
88 
90  unsigned NumRequiredArgs = 0;
91  for (const NamedDecl *P : asArray()) {
92  if (P->isTemplateParameterPack()) {
93  if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
94  if (NTTP->isExpandedParameterPack()) {
95  NumRequiredArgs += NTTP->getNumExpansionTypes();
96  continue;
97  }
98 
99  break;
100  }
101 
102  if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(P)) {
103  if (TTP->hasDefaultArgument())
104  break;
105  } else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) {
106  if (NTTP->hasDefaultArgument())
107  break;
108  } else if (cast<TemplateTemplateParmDecl>(P)->hasDefaultArgument())
109  break;
110 
111  ++NumRequiredArgs;
112  }
113 
114  return NumRequiredArgs;
115 }
116 
118  if (size() == 0)
119  return 0;
120 
121  const NamedDecl *FirstParm = getParam(0);
122  if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(FirstParm))
123  return TTP->getDepth();
124  else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(FirstParm))
125  return NTTP->getDepth();
126  else
127  return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth();
128 }
129 
131  DeclContext *Owner) {
132  for (NamedDecl *P : *Params) {
133  P->setDeclContext(Owner);
134 
135  if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
136  AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner);
137  }
138 }
139 
140 namespace clang {
141 
143  return new (C) char[sizeof(void*) * 2];
144 }
145 
146 } // namespace clang
147 
148 //===----------------------------------------------------------------------===//
149 // RedeclarableTemplateDecl Implementation
150 //===----------------------------------------------------------------------===//
151 
153  if (Common)
154  return Common;
155 
156  // Walk the previous-declaration chain until we either find a declaration
157  // with a common pointer or we run out of previous declarations.
159  for (const RedeclarableTemplateDecl *Prev = getPreviousDecl(); Prev;
160  Prev = Prev->getPreviousDecl()) {
161  if (Prev->Common) {
162  Common = Prev->Common;
163  break;
164  }
165 
166  PrevDecls.push_back(Prev);
167  }
168 
169  // If we never found a common pointer, allocate one now.
170  if (!Common) {
171  // FIXME: If any of the declarations is from an AST file, we probably
172  // need an update record to add the common data.
173 
174  Common = newCommon(getASTContext());
175  }
176 
177  // Update any previous declarations we saw with the common pointer.
178  for (const RedeclarableTemplateDecl *Prev : PrevDecls)
179  Prev->Common = Common;
180 
181  return Common;
182 }
183 
185  // Grab the most recent declaration to ensure we've loaded any lazy
186  // redeclarations of this template.
187  CommonBase *CommonBasePtr = getMostRecentDecl()->getCommonPtr();
188  if (CommonBasePtr->LazySpecializations) {
189  ASTContext &Context = getASTContext();
190  uint32_t *Specs = CommonBasePtr->LazySpecializations;
191  CommonBasePtr->LazySpecializations = nullptr;
192  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
193  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
194  }
195 }
196 
197 template<class EntryType>
200  llvm::FoldingSetVector<EntryType> &Specs, ArrayRef<TemplateArgument> Args,
201  void *&InsertPos) {
202  using SETraits = SpecEntryTraits<EntryType>;
203 
204  llvm::FoldingSetNodeID ID;
205  EntryType::Profile(ID, Args, getASTContext());
206  EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
207  return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
208 }
209 
210 template<class Derived, class EntryType>
212  llvm::FoldingSetVector<EntryType> &Specializations, EntryType *Entry,
213  void *InsertPos) {
214  using SETraits = SpecEntryTraits<EntryType>;
215 
216  if (InsertPos) {
217 #ifndef NDEBUG
218  void *CorrectInsertPos;
219  assert(!findSpecializationImpl(Specializations,
220  SETraits::getTemplateArgs(Entry),
221  CorrectInsertPos) &&
222  InsertPos == CorrectInsertPos &&
223  "given incorrect InsertPos for specialization");
224 #endif
225  Specializations.InsertNode(Entry, InsertPos);
226  } else {
227  EntryType *Existing = Specializations.GetOrInsertNode(Entry);
228  (void)Existing;
229  assert(SETraits::getDecl(Existing)->isCanonicalDecl() &&
230  "non-canonical specialization?");
231  }
232 
233  if (ASTMutationListener *L = getASTMutationListener())
234  L->AddedCXXTemplateSpecialization(cast<Derived>(this),
235  SETraits::getDecl(Entry));
236 }
237 
238 //===----------------------------------------------------------------------===//
239 // FunctionTemplateDecl Implementation
240 //===----------------------------------------------------------------------===//
241 
243  DeclContext *DC,
244  SourceLocation L,
245  DeclarationName Name,
246  TemplateParameterList *Params,
247  NamedDecl *Decl) {
248  AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
249  return new (C, DC) FunctionTemplateDecl(C, DC, L, Name, Params, Decl);
250 }
251 
253  unsigned ID) {
254  return new (C, ID) FunctionTemplateDecl(C, nullptr, SourceLocation(),
255  DeclarationName(), nullptr, nullptr);
256 }
257 
260  auto *CommonPtr = new (C) Common;
261  C.addDestruction(CommonPtr);
262  return CommonPtr;
263 }
264 
266  loadLazySpecializationsImpl();
267 }
268 
269 llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
271  LoadLazySpecializations();
272  return getCommonPtr()->Specializations;
273 }
274 
275 FunctionDecl *
277  void *&InsertPos) {
278  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
279 }
280 
282  FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
283  addSpecializationImpl<FunctionTemplateDecl>(getSpecializations(), Info,
284  InsertPos);
285 }
286 
288  TemplateParameterList *Params = getTemplateParameters();
289  Common *CommonPtr = getCommonPtr();
290  if (!CommonPtr->InjectedArgs) {
291  auto &Context = getASTContext();
293  Context.getInjectedTemplateArgs(Params, TemplateArgs);
294  CommonPtr->InjectedArgs =
295  new (Context) TemplateArgument[TemplateArgs.size()];
296  std::copy(TemplateArgs.begin(), TemplateArgs.end(),
297  CommonPtr->InjectedArgs);
298  }
299 
300  return llvm::makeArrayRef(CommonPtr->InjectedArgs, Params->size());
301 }
302 
303 //===----------------------------------------------------------------------===//
304 // ClassTemplateDecl Implementation
305 //===----------------------------------------------------------------------===//
306 
308  DeclContext *DC,
309  SourceLocation L,
310  DeclarationName Name,
311  TemplateParameterList *Params,
312  NamedDecl *Decl,
313  Expr *AssociatedConstraints) {
314  AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
315 
316  if (!AssociatedConstraints) {
317  return new (C, DC) ClassTemplateDecl(C, DC, L, Name, Params, Decl);
318  }
319 
320  auto *const CTDI = new (C) ConstrainedTemplateDeclInfo;
321  auto *const New =
322  new (C, DC) ClassTemplateDecl(CTDI, C, DC, L, Name, Params, Decl);
323  New->setAssociatedConstraints(AssociatedConstraints);
324  return New;
325 }
326 
328  unsigned ID) {
329  return new (C, ID) ClassTemplateDecl(C, nullptr, SourceLocation(),
330  DeclarationName(), nullptr, nullptr);
331 }
332 
334  loadLazySpecializationsImpl();
335 }
336 
337 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
339  LoadLazySpecializations();
340  return getCommonPtr()->Specializations;
341 }
342 
343 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
345  LoadLazySpecializations();
346  return getCommonPtr()->PartialSpecializations;
347 }
348 
351  auto *CommonPtr = new (C) Common;
352  C.addDestruction(CommonPtr);
353  return CommonPtr;
354 }
355 
358  void *&InsertPos) {
359  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
360 }
361 
363  void *InsertPos) {
364  addSpecializationImpl<ClassTemplateDecl>(getSpecializations(), D, InsertPos);
365 }
366 
369  void *&InsertPos) {
370  return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
371 }
372 
375  void *InsertPos) {
376  if (InsertPos)
377  getPartialSpecializations().InsertNode(D, InsertPos);
378  else {
380  = getPartialSpecializations().GetOrInsertNode(D);
381  (void)Existing;
382  assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
383  }
384 
385  if (ASTMutationListener *L = getASTMutationListener())
386  L->AddedCXXTemplateSpecialization(this, D);
387 }
388 
391  llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs
392  = getPartialSpecializations();
393  PS.clear();
394  PS.reserve(PartialSpecs.size());
395  for (ClassTemplatePartialSpecializationDecl &P : PartialSpecs)
396  PS.push_back(P.getMostRecentDecl());
397 }
398 
401  ASTContext &Context = getASTContext();
403  getPartialSpecializations()) {
404  if (Context.hasSameType(P.getInjectedSpecializationType(), T))
405  return P.getMostRecentDecl();
406  }
407 
408  return nullptr;
409 }
410 
414  Decl *DCanon = D->getCanonicalDecl();
415  for (ClassTemplatePartialSpecializationDecl &P : getPartialSpecializations()) {
416  if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
417  return P.getMostRecentDecl();
418  }
419 
420  return nullptr;
421 }
422 
423 QualType
425  Common *CommonPtr = getCommonPtr();
426  if (!CommonPtr->InjectedClassNameType.isNull())
427  return CommonPtr->InjectedClassNameType;
428 
429  // C++0x [temp.dep.type]p2:
430  // The template argument list of a primary template is a template argument
431  // list in which the nth template argument has the value of the nth template
432  // parameter of the class template. If the nth template parameter is a
433  // template parameter pack (14.5.3), the nth template argument is a pack
434  // expansion (14.5.3) whose pattern is the name of the template parameter
435  // pack.
436  ASTContext &Context = getASTContext();
437  TemplateParameterList *Params = getTemplateParameters();
439  Context.getInjectedTemplateArgs(Params, TemplateArgs);
440  CommonPtr->InjectedClassNameType
442  TemplateArgs);
443  return CommonPtr->InjectedClassNameType;
444 }
445 
446 //===----------------------------------------------------------------------===//
447 // TemplateTypeParm Allocation/Deallocation Method Implementations
448 //===----------------------------------------------------------------------===//
449 
452  SourceLocation KeyLoc, SourceLocation NameLoc,
453  unsigned D, unsigned P, IdentifierInfo *Id,
454  bool Typename, bool ParameterPack) {
455  auto *TTPDecl =
456  new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename);
457  QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
458  TTPDecl->setTypeForDecl(TTPType.getTypePtr());
459  return TTPDecl;
460 }
461 
464  return new (C, ID) TemplateTypeParmDecl(nullptr, SourceLocation(),
465  SourceLocation(), nullptr, false);
466 }
467 
469  return hasDefaultArgument()
470  ? getDefaultArgumentInfo()->getTypeLoc().getBeginLoc()
471  : SourceLocation();
472 }
473 
475  if (hasDefaultArgument() && !defaultArgumentWasInherited())
476  return SourceRange(getLocStart(),
477  getDefaultArgumentInfo()->getTypeLoc().getEndLoc());
478  else
479  return TypeDecl::getSourceRange();
480 }
481 
483  return getTypeForDecl()->getAs<TemplateTypeParmType>()->getDepth();
484 }
485 
487  return getTypeForDecl()->getAs<TemplateTypeParmType>()->getIndex();
488 }
489 
491  return getTypeForDecl()->getAs<TemplateTypeParmType>()->isParameterPack();
492 }
493 
494 //===----------------------------------------------------------------------===//
495 // NonTypeTemplateParmDecl Method Implementations
496 //===----------------------------------------------------------------------===//
497 
498 NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(
499  DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D,
500  unsigned P, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
501  ArrayRef<QualType> ExpandedTypes, ArrayRef<TypeSourceInfo *> ExpandedTInfos)
502  : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
503  TemplateParmPosition(D, P), ParameterPack(true),
504  ExpandedParameterPack(true), NumExpandedTypes(ExpandedTypes.size()) {
505  if (!ExpandedTypes.empty() && !ExpandedTInfos.empty()) {
506  auto TypesAndInfos =
507  getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
508  for (unsigned I = 0; I != NumExpandedTypes; ++I) {
509  new (&TypesAndInfos[I].first) QualType(ExpandedTypes[I]);
510  TypesAndInfos[I].second = ExpandedTInfos[I];
511  }
512  }
513 }
514 
517  SourceLocation StartLoc, SourceLocation IdLoc,
518  unsigned D, unsigned P, IdentifierInfo *Id,
519  QualType T, bool ParameterPack,
520  TypeSourceInfo *TInfo) {
521  return new (C, DC) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id,
522  T, ParameterPack, TInfo);
523 }
524 
526  const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
527  SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id,
528  QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes,
529  ArrayRef<TypeSourceInfo *> ExpandedTInfos) {
530  return new (C, DC,
531  additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>(
532  ExpandedTypes.size()))
533  NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, T, TInfo,
534  ExpandedTypes, ExpandedTInfos);
535 }
536 
539  return new (C, ID) NonTypeTemplateParmDecl(nullptr, SourceLocation(),
540  SourceLocation(), 0, 0, nullptr,
541  QualType(), false, nullptr);
542 }
543 
546  unsigned NumExpandedTypes) {
547  auto *NTTP =
548  new (C, ID, additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>(
549  NumExpandedTypes))
551  0, 0, nullptr, QualType(), nullptr, None,
552  None);
553  NTTP->NumExpandedTypes = NumExpandedTypes;
554  return NTTP;
555 }
556 
558  if (hasDefaultArgument() && !defaultArgumentWasInherited())
559  return SourceRange(getOuterLocStart(),
560  getDefaultArgument()->getSourceRange().getEnd());
562 }
563 
565  return hasDefaultArgument()
566  ? getDefaultArgument()->getSourceRange().getBegin()
567  : SourceLocation();
568 }
569 
570 //===----------------------------------------------------------------------===//
571 // TemplateTemplateParmDecl Method Implementations
572 //===----------------------------------------------------------------------===//
573 
574 void TemplateTemplateParmDecl::anchor() {}
575 
576 TemplateTemplateParmDecl::TemplateTemplateParmDecl(
577  DeclContext *DC, SourceLocation L, unsigned D, unsigned P,
580  : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
581  TemplateParmPosition(D, P), ParameterPack(true),
582  ExpandedParameterPack(true), NumExpandedParams(Expansions.size()) {
583  if (!Expansions.empty())
584  std::uninitialized_copy(Expansions.begin(), Expansions.end(),
585  getTrailingObjects<TemplateParameterList *>());
586 }
587 
590  SourceLocation L, unsigned D, unsigned P,
591  bool ParameterPack, IdentifierInfo *Id,
592  TemplateParameterList *Params) {
593  return new (C, DC) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id,
594  Params);
595 }
596 
599  SourceLocation L, unsigned D, unsigned P,
600  IdentifierInfo *Id,
601  TemplateParameterList *Params,
603  return new (C, DC,
604  additionalSizeToAlloc<TemplateParameterList *>(Expansions.size()))
605  TemplateTemplateParmDecl(DC, L, D, P, Id, Params, Expansions);
606 }
607 
610  return new (C, ID) TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0,
611  false, nullptr, nullptr);
612 }
613 
616  unsigned NumExpansions) {
617  auto *TTP =
618  new (C, ID, additionalSizeToAlloc<TemplateParameterList *>(NumExpansions))
619  TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0, nullptr,
620  nullptr, None);
621  TTP->NumExpandedParams = NumExpansions;
622  return TTP;
623 }
624 
626  return hasDefaultArgument() ? getDefaultArgument().getLocation()
627  : SourceLocation();
628 }
629 
631  const ASTContext &C, const TemplateArgumentLoc &DefArg) {
632  if (DefArg.getArgument().isNull())
633  DefaultArgument.set(nullptr);
634  else
635  DefaultArgument.set(new (C) TemplateArgumentLoc(DefArg));
636 }
637 
638 //===----------------------------------------------------------------------===//
639 // TemplateArgumentList Implementation
640 //===----------------------------------------------------------------------===//
641 TemplateArgumentList::TemplateArgumentList(ArrayRef<TemplateArgument> Args)
642  : Arguments(getTrailingObjects<TemplateArgument>()),
643  NumArguments(Args.size()) {
644  std::uninitialized_copy(Args.begin(), Args.end(),
645  getTrailingObjects<TemplateArgument>());
646 }
647 
651  void *Mem = Context.Allocate(totalSizeToAlloc<TemplateArgument>(Args.size()));
652  return new (Mem) TemplateArgumentList(Args);
653 }
654 
657  FunctionTemplateDecl *Template,
659  const TemplateArgumentList *TemplateArgs,
660  const TemplateArgumentListInfo *TemplateArgsAsWritten,
661  SourceLocation POI) {
662  const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
663  if (TemplateArgsAsWritten)
664  ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C,
665  *TemplateArgsAsWritten);
666 
667  return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK,
668  TemplateArgs,
669  ArgsAsWritten,
670  POI);
671 }
672 
673 //===----------------------------------------------------------------------===//
674 // TemplateDecl Implementation
675 //===----------------------------------------------------------------------===//
676 
677 void TemplateDecl::anchor() {}
678 
679 //===----------------------------------------------------------------------===//
680 // ClassTemplateSpecializationDecl Implementation
681 //===----------------------------------------------------------------------===//
682 
685  DeclContext *DC, SourceLocation StartLoc,
686  SourceLocation IdLoc,
687  ClassTemplateDecl *SpecializedTemplate,
690  : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc,
691  SpecializedTemplate->getIdentifier(), PrevDecl),
692  SpecializedTemplate(SpecializedTemplate),
693  TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
694  SpecializationKind(TSK_Undeclared) {
695 }
696 
698  Kind DK)
699  : CXXRecordDecl(DK, TTK_Struct, C, nullptr, SourceLocation(),
700  SourceLocation(), nullptr, nullptr),
701  SpecializationKind(TSK_Undeclared) {}
702 
705  DeclContext *DC,
706  SourceLocation StartLoc,
707  SourceLocation IdLoc,
708  ClassTemplateDecl *SpecializedTemplate,
711  auto *Result =
712  new (Context, DC) ClassTemplateSpecializationDecl(
713  Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc,
714  SpecializedTemplate, Args, PrevDecl);
715  Result->MayHaveOutOfDateDef = false;
716 
717  Context.getTypeDeclType(Result, PrevDecl);
718  return Result;
719 }
720 
723  unsigned ID) {
724  auto *Result =
725  new (C, ID) ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization);
726  Result->MayHaveOutOfDateDef = false;
727  return Result;
728 }
729 
731  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
732  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
733 
734  const auto *PS = dyn_cast<ClassTemplatePartialSpecializationDecl>(this);
735  if (const ASTTemplateArgumentListInfo *ArgsAsWritten =
736  PS ? PS->getTemplateArgsAsWritten() : nullptr) {
737  printTemplateArgumentList(OS, ArgsAsWritten->arguments(), Policy);
738  } else {
739  const TemplateArgumentList &TemplateArgs = getTemplateArgs();
740  printTemplateArgumentList(OS, TemplateArgs.asArray(), Policy);
741  }
742 }
743 
746  if (const auto *PartialSpec =
747  SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
748  return PartialSpec->PartialSpecialization->getSpecializedTemplate();
749  return SpecializedTemplate.get<ClassTemplateDecl*>();
750 }
751 
754  if (ExplicitInfo) {
756  if (Begin.isValid()) {
757  // Here we have an explicit (partial) specialization or instantiation.
761  if (getExternLoc().isValid())
762  Begin = getExternLoc();
764  if (End.isInvalid())
766  return SourceRange(Begin, End);
767  }
768  // An implicit instantiation of a class template partial specialization
769  // uses ExplicitInfo to record the TypeAsWritten, but the source
770  // locations should be retrieved from the instantiation pattern.
772  auto *ctpsd = const_cast<CTPSDecl *>(cast<CTPSDecl>(this));
773  CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember();
774  assert(inst_from != nullptr);
775  return inst_from->getSourceRange();
776  }
777  else {
778  // No explicit info available.
779  llvm::PointerUnion<ClassTemplateDecl *,
781  inst_from = getInstantiatedFrom();
782  if (inst_from.isNull())
784  if (const auto *ctd = inst_from.dyn_cast<ClassTemplateDecl *>())
785  return ctd->getSourceRange();
786  return inst_from.get<ClassTemplatePartialSpecializationDecl *>()
787  ->getSourceRange();
788  }
789 }
790 
791 //===----------------------------------------------------------------------===//
792 // ClassTemplatePartialSpecializationDecl Implementation
793 //===----------------------------------------------------------------------===//
794 void ClassTemplatePartialSpecializationDecl::anchor() {}
795 
796 ClassTemplatePartialSpecializationDecl::
797 ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK,
798  DeclContext *DC,
799  SourceLocation StartLoc,
800  SourceLocation IdLoc,
801  TemplateParameterList *Params,
802  ClassTemplateDecl *SpecializedTemplate,
804  const ASTTemplateArgumentListInfo *ArgInfos,
807  ClassTemplatePartialSpecialization,
808  TK, DC, StartLoc, IdLoc,
809  SpecializedTemplate, Args, PrevDecl),
810  TemplateParams(Params), ArgsAsWritten(ArgInfos),
811  InstantiatedFromMember(nullptr, false) {
812  AdoptTemplateParameterList(Params, this);
813 }
814 
818  SourceLocation StartLoc, SourceLocation IdLoc,
819  TemplateParameterList *Params,
820  ClassTemplateDecl *SpecializedTemplate,
822  const TemplateArgumentListInfo &ArgInfos,
823  QualType CanonInjectedType,
825  const ASTTemplateArgumentListInfo *ASTArgInfos =
826  ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
827 
828  auto *Result = new (Context, DC)
829  ClassTemplatePartialSpecializationDecl(Context, TK, DC, StartLoc, IdLoc,
830  Params, SpecializedTemplate, Args,
831  ASTArgInfos, PrevDecl);
832  Result->setSpecializationKind(TSK_ExplicitSpecialization);
833  Result->MayHaveOutOfDateDef = false;
834 
835  Context.getInjectedClassNameType(Result, CanonInjectedType);
836  return Result;
837 }
838 
841  unsigned ID) {
843  Result->MayHaveOutOfDateDef = false;
844  return Result;
845 }
846 
847 //===----------------------------------------------------------------------===//
848 // FriendTemplateDecl Implementation
849 //===----------------------------------------------------------------------===//
850 
851 void FriendTemplateDecl::anchor() {}
852 
855  SourceLocation L,
857  FriendUnion Friend, SourceLocation FLoc) {
858  return new (Context, DC) FriendTemplateDecl(DC, L, Params, Friend, FLoc);
859 }
860 
862  unsigned ID) {
863  return new (C, ID) FriendTemplateDecl(EmptyShell());
864 }
865 
866 //===----------------------------------------------------------------------===//
867 // TypeAliasTemplateDecl Implementation
868 //===----------------------------------------------------------------------===//
869 
871  DeclContext *DC,
872  SourceLocation L,
873  DeclarationName Name,
874  TemplateParameterList *Params,
875  NamedDecl *Decl) {
876  AdoptTemplateParameterList(Params, DC);
877  return new (C, DC) TypeAliasTemplateDecl(C, DC, L, Name, Params, Decl);
878 }
879 
881  unsigned ID) {
882  return new (C, ID) TypeAliasTemplateDecl(C, nullptr, SourceLocation(),
883  DeclarationName(), nullptr, nullptr);
884 }
885 
888  auto *CommonPtr = new (C) Common;
889  C.addDestruction(CommonPtr);
890  return CommonPtr;
891 }
892 
893 //===----------------------------------------------------------------------===//
894 // ClassScopeFunctionSpecializationDecl Implementation
895 //===----------------------------------------------------------------------===//
896 
897 void ClassScopeFunctionSpecializationDecl::anchor() {}
898 
901  unsigned ID) {
903  nullptr, SourceLocation(), nullptr, false, TemplateArgumentListInfo());
904 }
905 
906 //===----------------------------------------------------------------------===//
907 // VarTemplateDecl Implementation
908 //===----------------------------------------------------------------------===//
909 
911  VarTemplateDecl *CurD = this;
912  while (CurD) {
913  if (CurD->isThisDeclarationADefinition())
914  return CurD;
915  CurD = CurD->getPreviousDecl();
916  }
917  return nullptr;
918 }
919 
922  TemplateParameterList *Params,
923  VarDecl *Decl) {
924  return new (C, DC) VarTemplateDecl(C, DC, L, Name, Params, Decl);
925 }
926 
928  unsigned ID) {
929  return new (C, ID) VarTemplateDecl(C, nullptr, SourceLocation(),
930  DeclarationName(), nullptr, nullptr);
931 }
932 
934  loadLazySpecializationsImpl();
935 }
936 
937 llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
939  LoadLazySpecializations();
940  return getCommonPtr()->Specializations;
941 }
942 
943 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
945  LoadLazySpecializations();
946  return getCommonPtr()->PartialSpecializations;
947 }
948 
951  auto *CommonPtr = new (C) Common;
952  C.addDestruction(CommonPtr);
953  return CommonPtr;
954 }
955 
958  void *&InsertPos) {
959  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
960 }
961 
963  void *InsertPos) {
964  addSpecializationImpl<VarTemplateDecl>(getSpecializations(), D, InsertPos);
965 }
966 
969  void *&InsertPos) {
970  return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
971 }
972 
974  VarTemplatePartialSpecializationDecl *D, void *InsertPos) {
975  if (InsertPos)
976  getPartialSpecializations().InsertNode(D, InsertPos);
977  else {
979  getPartialSpecializations().GetOrInsertNode(D);
980  (void)Existing;
981  assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
982  }
983 
985  L->AddedCXXTemplateSpecialization(this, D);
986 }
987 
990  llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &PartialSpecs =
991  getPartialSpecializations();
992  PS.clear();
993  PS.reserve(PartialSpecs.size());
994  for (VarTemplatePartialSpecializationDecl &P : PartialSpecs)
995  PS.push_back(P.getMostRecentDecl());
996 }
997 
1001  Decl *DCanon = D->getCanonicalDecl();
1002  for (VarTemplatePartialSpecializationDecl &P : getPartialSpecializations()) {
1003  if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
1004  return P.getMostRecentDecl();
1005  }
1006 
1007  return nullptr;
1008 }
1009 
1010 //===----------------------------------------------------------------------===//
1011 // VarTemplateSpecializationDecl Implementation
1012 //===----------------------------------------------------------------------===//
1013 
1015  Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1016  SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1018  : VarDecl(DK, Context, DC, StartLoc, IdLoc,
1019  SpecializedTemplate->getIdentifier(), T, TInfo, S),
1020  SpecializedTemplate(SpecializedTemplate),
1021  TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
1022  SpecializationKind(TSK_Undeclared), IsCompleteDefinition(false) {}
1023 
1025  ASTContext &C)
1026  : VarDecl(DK, C, nullptr, SourceLocation(), SourceLocation(), nullptr,
1027  QualType(), nullptr, SC_None),
1028  SpecializationKind(TSK_Undeclared), IsCompleteDefinition(false) {}
1029 
1031  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1032  SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1034  return new (Context, DC) VarTemplateSpecializationDecl(
1035  VarTemplateSpecialization, Context, DC, StartLoc, IdLoc,
1036  SpecializedTemplate, T, TInfo, S, Args);
1037 }
1038 
1041  return new (C, ID)
1042  VarTemplateSpecializationDecl(VarTemplateSpecialization, C);
1043 }
1044 
1046  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
1047  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
1048 
1049  const auto *PS = dyn_cast<VarTemplatePartialSpecializationDecl>(this);
1050  if (const ASTTemplateArgumentListInfo *ArgsAsWritten =
1051  PS ? PS->getTemplateArgsAsWritten() : nullptr) {
1052  printTemplateArgumentList(OS, ArgsAsWritten->arguments(), Policy);
1053  } else {
1054  const TemplateArgumentList &TemplateArgs = getTemplateArgs();
1055  printTemplateArgumentList(OS, TemplateArgs.asArray(), Policy);
1056  }
1057 }
1058 
1060  if (const auto *PartialSpec =
1061  SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1062  return PartialSpec->PartialSpecialization->getSpecializedTemplate();
1063  return SpecializedTemplate.get<VarTemplateDecl *>();
1064 }
1065 
1067  const TemplateArgumentListInfo &ArgsInfo) {
1068  TemplateArgsInfo.setLAngleLoc(ArgsInfo.getLAngleLoc());
1069  TemplateArgsInfo.setRAngleLoc(ArgsInfo.getRAngleLoc());
1070  for (const TemplateArgumentLoc &Loc : ArgsInfo.arguments())
1071  TemplateArgsInfo.addArgument(Loc);
1072 }
1073 
1074 //===----------------------------------------------------------------------===//
1075 // VarTemplatePartialSpecializationDecl Implementation
1076 //===----------------------------------------------------------------------===//
1077 
1078 void VarTemplatePartialSpecializationDecl::anchor() {}
1079 
1080 VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl(
1081  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1082  SourceLocation IdLoc, TemplateParameterList *Params,
1083  VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1085  const ASTTemplateArgumentListInfo *ArgInfos)
1086  : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization, Context,
1087  DC, StartLoc, IdLoc, SpecializedTemplate, T,
1088  TInfo, S, Args),
1089  TemplateParams(Params), ArgsAsWritten(ArgInfos),
1090  InstantiatedFromMember(nullptr, false) {
1091  // TODO: The template parameters should be in DC by now. Verify.
1092  // AdoptTemplateParameterList(Params, DC);
1093 }
1094 
1097  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1098  SourceLocation IdLoc, TemplateParameterList *Params,
1099  VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1101  const TemplateArgumentListInfo &ArgInfos) {
1102  const ASTTemplateArgumentListInfo *ASTArgInfos
1103  = ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
1104 
1105  auto *Result =
1106  new (Context, DC) VarTemplatePartialSpecializationDecl(
1107  Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo,
1108  S, Args, ASTArgInfos);
1109  Result->setSpecializationKind(TSK_ExplicitSpecialization);
1110  return Result;
1111 }
1112 
1115  unsigned ID) {
1116  return new (C, ID) VarTemplatePartialSpecializationDecl(C);
1117 }
1118 
1119 static TemplateParameterList *
1121  // typename T
1122  auto *T = TemplateTypeParmDecl::Create(
1123  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/1, /*Position=*/0,
1124  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
1125  T->setImplicit(true);
1126 
1127  // T ...Ints
1128  TypeSourceInfo *TI =
1129  C.getTrivialTypeSourceInfo(QualType(T->getTypeForDecl(), 0));
1131  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1132  /*Id=*/nullptr, TI->getType(), /*ParameterPack=*/true, TI);
1133  N->setImplicit(true);
1134 
1135  // <typename T, T ...Ints>
1136  NamedDecl *P[2] = {T, N};
1137  auto *TPL = TemplateParameterList::Create(
1138  C, SourceLocation(), SourceLocation(), P, SourceLocation(), nullptr);
1139 
1140  // template <typename T, ...Ints> class IntSeq
1141  auto *TemplateTemplateParm = TemplateTemplateParmDecl::Create(
1142  C, DC, SourceLocation(), /*Depth=*/0, /*Position=*/0,
1143  /*ParameterPack=*/false, /*Id=*/nullptr, TPL);
1144  TemplateTemplateParm->setImplicit(true);
1145 
1146  // typename T
1147  auto *TemplateTypeParm = TemplateTypeParmDecl::Create(
1148  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1149  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
1150  TemplateTypeParm->setImplicit(true);
1151 
1152  // T N
1154  QualType(TemplateTypeParm->getTypeForDecl(), 0));
1155  auto *NonTypeTemplateParm = NonTypeTemplateParmDecl::Create(
1156  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/2,
1157  /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo);
1158  NamedDecl *Params[] = {TemplateTemplateParm, TemplateTypeParm,
1159  NonTypeTemplateParm};
1160 
1161  // template <template <typename T, T ...Ints> class IntSeq, typename T, T N>
1163  Params, SourceLocation(), nullptr);
1164 }
1165 
1166 static TemplateParameterList *
1168  // std::size_t Index
1170  auto *Index = NonTypeTemplateParmDecl::Create(
1171  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/0,
1172  /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo);
1173 
1174  // typename ...T
1175  auto *Ts = TemplateTypeParmDecl::Create(
1176  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1177  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/true);
1178  Ts->setImplicit(true);
1179 
1180  // template <std::size_t Index, typename ...T>
1181  NamedDecl *Params[] = {Index, Ts};
1183  llvm::makeArrayRef(Params),
1184  SourceLocation(), nullptr);
1185 }
1186 
1188  const ASTContext &C, DeclContext *DC, BuiltinTemplateKind BTK) {
1189  switch (BTK) {
1190  case BTK__make_integer_seq:
1191  return createMakeIntegerSeqParameterList(C, DC);
1193  return createTypePackElementParameterList(C, DC);
1194  }
1195 
1196  llvm_unreachable("unhandled BuiltinTemplateKind!");
1197 }
1198 
1199 void BuiltinTemplateDecl::anchor() {}
1200 
1201 BuiltinTemplateDecl::BuiltinTemplateDecl(const ASTContext &C, DeclContext *DC,
1202  DeclarationName Name,
1203  BuiltinTemplateKind BTK)
1204  : TemplateDecl(BuiltinTemplate, DC, SourceLocation(), Name,
1206  BTK(BTK) {}
Defines the clang::ASTContext interface.
void setImplicit(bool I=true)
Definition: DeclBase.h:553
Represents a function declaration or definition.
Definition: Decl.h:1714
A (possibly-)qualified type.
Definition: Type.h:655
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:3133
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.
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:380
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
Declaration of a redeclarable template.
Definition: DeclTemplate.h:737
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:150
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:508
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:1837
SourceLocation getDefaultArgumentLoc() const
Retrieves the location of the default argument declaration.
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5825
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:728
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:881
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:487
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:206
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:1369
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:2658
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:720
static StringRef getIdentifier(const Token &Tok)
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:2006
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.
#define false
Definition: stdbool.h:33
The "struct" keyword.
Definition: Type.h:4785
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:820
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:243
CommonBase * newCommon(ASTContext &C) const override
Data that is common to all of the declarations of a given function template.
Definition: DeclTemplate.h:974
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:241
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:164
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
Definition: Specifiers.h:149
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:651
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:4783
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:1600
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:1262
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:160
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:246
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:146
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:1061
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.
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:156
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:2223
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:986
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:300
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:2845
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:968
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>.