clang  9.0.0svn
DeclTemplate.cpp
Go to the documentation of this file.
1 //===- DeclTemplate.cpp - Template Declaration AST Node Implementation ----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the C++ related Decl classes for templates.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "clang/AST/DeclTemplate.h"
14 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/DeclCXX.h"
18 #include "clang/AST/Expr.h"
20 #include "clang/AST/TemplateBase.h"
21 #include "clang/AST/TemplateName.h"
22 #include "clang/AST/Type.h"
23 #include "clang/AST/TypeLoc.h"
24 #include "clang/Basic/Builtins.h"
25 #include "clang/Basic/LLVM.h"
27 #include "llvm/ADT/ArrayRef.h"
28 #include "llvm/ADT/FoldingSet.h"
29 #include "llvm/ADT/None.h"
30 #include "llvm/ADT/PointerUnion.h"
31 #include "llvm/ADT/SmallVector.h"
32 #include "llvm/Support/Casting.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include <algorithm>
35 #include <cassert>
36 #include <cstdint>
37 #include <memory>
38 #include <utility>
39 
40 using namespace clang;
41 
42 //===----------------------------------------------------------------------===//
43 // TemplateParameterList Implementation
44 //===----------------------------------------------------------------------===//
45 
47  SourceLocation LAngleLoc,
48  ArrayRef<NamedDecl *> Params,
49  SourceLocation RAngleLoc,
50  Expr *RequiresClause)
51  : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
52  NumParams(Params.size()), ContainsUnexpandedParameterPack(false),
53  HasRequiresClause(static_cast<bool>(RequiresClause)) {
54  for (unsigned Idx = 0; Idx < NumParams; ++Idx) {
55  NamedDecl *P = Params[Idx];
56  begin()[Idx] = P;
57 
58  if (!P->isTemplateParameterPack()) {
59  if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
60  if (NTTP->getType()->containsUnexpandedParameterPack())
61  ContainsUnexpandedParameterPack = true;
62 
63  if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
64  if (TTP->getTemplateParameters()->containsUnexpandedParameterPack())
65  ContainsUnexpandedParameterPack = true;
66 
67  // FIXME: If a default argument contains an unexpanded parameter pack, the
68  // template parameter list does too.
69  }
70  }
71  if (RequiresClause) {
72  *getTrailingObjects<Expr *>() = RequiresClause;
73  }
74 }
75 
78  SourceLocation LAngleLoc,
79  ArrayRef<NamedDecl *> Params,
80  SourceLocation RAngleLoc, Expr *RequiresClause) {
81  void *Mem = C.Allocate(totalSizeToAlloc<NamedDecl *, Expr *>(
82  Params.size(), RequiresClause ? 1u : 0u),
83  alignof(TemplateParameterList));
84  return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params,
85  RAngleLoc, RequiresClause);
86 }
87 
89  unsigned NumRequiredArgs = 0;
90  for (const NamedDecl *P : asArray()) {
91  if (P->isTemplateParameterPack()) {
92  if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
93  if (NTTP->isExpandedParameterPack()) {
94  NumRequiredArgs += NTTP->getNumExpansionTypes();
95  continue;
96  }
97 
98  break;
99  }
100 
101  if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(P)) {
102  if (TTP->hasDefaultArgument())
103  break;
104  } else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) {
105  if (NTTP->hasDefaultArgument())
106  break;
107  } else if (cast<TemplateTemplateParmDecl>(P)->hasDefaultArgument())
108  break;
109 
110  ++NumRequiredArgs;
111  }
112 
113  return NumRequiredArgs;
114 }
115 
117  if (size() == 0)
118  return 0;
119 
120  const NamedDecl *FirstParm = getParam(0);
121  if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(FirstParm))
122  return TTP->getDepth();
123  else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(FirstParm))
124  return NTTP->getDepth();
125  else
126  return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth();
127 }
128 
130  DeclContext *Owner) {
131  for (NamedDecl *P : *Params) {
132  P->setDeclContext(Owner);
133 
134  if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
135  AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner);
136  }
137 }
138 
139 namespace clang {
140 
142  return new (C) char[sizeof(void*) * 2];
143 }
144 
145 } // namespace clang
146 
147 //===----------------------------------------------------------------------===//
148 // RedeclarableTemplateDecl Implementation
149 //===----------------------------------------------------------------------===//
150 
151 void RedeclarableTemplateDecl::anchor() {}
152 
154  if (Common)
155  return Common;
156 
157  // Walk the previous-declaration chain until we either find a declaration
158  // with a common pointer or we run out of previous declarations.
160  for (const RedeclarableTemplateDecl *Prev = getPreviousDecl(); Prev;
161  Prev = Prev->getPreviousDecl()) {
162  if (Prev->Common) {
163  Common = Prev->Common;
164  break;
165  }
166 
167  PrevDecls.push_back(Prev);
168  }
169 
170  // If we never found a common pointer, allocate one now.
171  if (!Common) {
172  // FIXME: If any of the declarations is from an AST file, we probably
173  // need an update record to add the common data.
174 
175  Common = newCommon(getASTContext());
176  }
177 
178  // Update any previous declarations we saw with the common pointer.
179  for (const RedeclarableTemplateDecl *Prev : PrevDecls)
180  Prev->Common = Common;
181 
182  return Common;
183 }
184 
186  // Grab the most recent declaration to ensure we've loaded any lazy
187  // redeclarations of this template.
188  CommonBase *CommonBasePtr = getMostRecentDecl()->getCommonPtr();
189  if (CommonBasePtr->LazySpecializations) {
190  ASTContext &Context = getASTContext();
191  uint32_t *Specs = CommonBasePtr->LazySpecializations;
192  CommonBasePtr->LazySpecializations = nullptr;
193  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
194  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
195  }
196 }
197 
198 template<class EntryType>
201  llvm::FoldingSetVector<EntryType> &Specs, ArrayRef<TemplateArgument> Args,
202  void *&InsertPos) {
203  using SETraits = SpecEntryTraits<EntryType>;
204 
205  llvm::FoldingSetNodeID ID;
206  EntryType::Profile(ID, Args, getASTContext());
207  EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
208  return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
209 }
210 
211 template<class Derived, class EntryType>
213  llvm::FoldingSetVector<EntryType> &Specializations, EntryType *Entry,
214  void *InsertPos) {
215  using SETraits = SpecEntryTraits<EntryType>;
216 
217  if (InsertPos) {
218 #ifndef NDEBUG
219  void *CorrectInsertPos;
220  assert(!findSpecializationImpl(Specializations,
221  SETraits::getTemplateArgs(Entry),
222  CorrectInsertPos) &&
223  InsertPos == CorrectInsertPos &&
224  "given incorrect InsertPos for specialization");
225 #endif
226  Specializations.InsertNode(Entry, InsertPos);
227  } else {
228  EntryType *Existing = Specializations.GetOrInsertNode(Entry);
229  (void)Existing;
230  assert(SETraits::getDecl(Existing)->isCanonicalDecl() &&
231  "non-canonical specialization?");
232  }
233 
234  if (ASTMutationListener *L = getASTMutationListener())
235  L->AddedCXXTemplateSpecialization(cast<Derived>(this),
236  SETraits::getDecl(Entry));
237 }
238 
239 //===----------------------------------------------------------------------===//
240 // FunctionTemplateDecl Implementation
241 //===----------------------------------------------------------------------===//
242 
244  DeclContext *DC,
245  SourceLocation L,
246  DeclarationName Name,
247  TemplateParameterList *Params,
248  NamedDecl *Decl) {
249  AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
250  return new (C, DC) FunctionTemplateDecl(C, DC, L, Name, Params, Decl);
251 }
252 
254  unsigned ID) {
255  return new (C, ID) FunctionTemplateDecl(C, nullptr, SourceLocation(),
256  DeclarationName(), nullptr, nullptr);
257 }
258 
261  auto *CommonPtr = new (C) Common;
262  C.addDestruction(CommonPtr);
263  return CommonPtr;
264 }
265 
267  loadLazySpecializationsImpl();
268 }
269 
270 llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
272  LoadLazySpecializations();
273  return getCommonPtr()->Specializations;
274 }
275 
276 FunctionDecl *
278  void *&InsertPos) {
279  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
280 }
281 
283  FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
284  addSpecializationImpl<FunctionTemplateDecl>(getSpecializations(), Info,
285  InsertPos);
286 }
287 
289  TemplateParameterList *Params = getTemplateParameters();
290  Common *CommonPtr = getCommonPtr();
291  if (!CommonPtr->InjectedArgs) {
292  auto &Context = getASTContext();
294  Context.getInjectedTemplateArgs(Params, TemplateArgs);
295  CommonPtr->InjectedArgs =
296  new (Context) TemplateArgument[TemplateArgs.size()];
297  std::copy(TemplateArgs.begin(), TemplateArgs.end(),
298  CommonPtr->InjectedArgs);
299  }
300 
301  return llvm::makeArrayRef(CommonPtr->InjectedArgs, Params->size());
302 }
303 
306 
307  // If we haven't created a common pointer yet, then it can just be created
308  // with the usual method.
309  if (!Base::Common)
310  return;
311 
312  Common *ThisCommon = static_cast<Common *>(Base::Common);
313  Common *PrevCommon = nullptr;
315  for (; Prev; Prev = Prev->getPreviousDecl()) {
316  if (Prev->Base::Common) {
317  PrevCommon = static_cast<Common *>(Prev->Base::Common);
318  break;
319  }
320  PreviousDecls.push_back(Prev);
321  }
322 
323  // If the previous redecl chain hasn't created a common pointer yet, then just
324  // use this common pointer.
325  if (!PrevCommon) {
326  for (auto *D : PreviousDecls)
327  D->Base::Common = ThisCommon;
328  return;
329  }
330 
331  // Ensure we don't leak any important state.
332  assert(ThisCommon->Specializations.size() == 0 &&
333  "Can't merge incompatible declarations!");
334 
335  Base::Common = PrevCommon;
336 }
337 
338 //===----------------------------------------------------------------------===//
339 // ClassTemplateDecl Implementation
340 //===----------------------------------------------------------------------===//
341 
343  DeclContext *DC,
344  SourceLocation L,
345  DeclarationName Name,
346  TemplateParameterList *Params,
347  NamedDecl *Decl,
348  Expr *AssociatedConstraints) {
349  AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
350 
351  if (!AssociatedConstraints) {
352  return new (C, DC) ClassTemplateDecl(C, DC, L, Name, Params, Decl);
353  }
354 
355  auto *const CTDI = new (C) ConstrainedTemplateDeclInfo;
356  auto *const New =
357  new (C, DC) ClassTemplateDecl(CTDI, C, DC, L, Name, Params, Decl);
358  New->setAssociatedConstraints(AssociatedConstraints);
359  return New;
360 }
361 
363  unsigned ID) {
364  return new (C, ID) ClassTemplateDecl(C, nullptr, SourceLocation(),
365  DeclarationName(), nullptr, nullptr);
366 }
367 
369  loadLazySpecializationsImpl();
370 }
371 
372 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
374  LoadLazySpecializations();
375  return getCommonPtr()->Specializations;
376 }
377 
378 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
380  LoadLazySpecializations();
381  return getCommonPtr()->PartialSpecializations;
382 }
383 
386  auto *CommonPtr = new (C) Common;
387  C.addDestruction(CommonPtr);
388  return CommonPtr;
389 }
390 
393  void *&InsertPos) {
394  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
395 }
396 
398  void *InsertPos) {
399  addSpecializationImpl<ClassTemplateDecl>(getSpecializations(), D, InsertPos);
400 }
401 
404  void *&InsertPos) {
405  return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
406 }
407 
410  void *InsertPos) {
411  if (InsertPos)
412  getPartialSpecializations().InsertNode(D, InsertPos);
413  else {
415  = getPartialSpecializations().GetOrInsertNode(D);
416  (void)Existing;
417  assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
418  }
419 
420  if (ASTMutationListener *L = getASTMutationListener())
421  L->AddedCXXTemplateSpecialization(this, D);
422 }
423 
426  llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs
427  = getPartialSpecializations();
428  PS.clear();
429  PS.reserve(PartialSpecs.size());
430  for (ClassTemplatePartialSpecializationDecl &P : PartialSpecs)
431  PS.push_back(P.getMostRecentDecl());
432 }
433 
436  ASTContext &Context = getASTContext();
438  getPartialSpecializations()) {
439  if (Context.hasSameType(P.getInjectedSpecializationType(), T))
440  return P.getMostRecentDecl();
441  }
442 
443  return nullptr;
444 }
445 
449  Decl *DCanon = D->getCanonicalDecl();
450  for (ClassTemplatePartialSpecializationDecl &P : getPartialSpecializations()) {
451  if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
452  return P.getMostRecentDecl();
453  }
454 
455  return nullptr;
456 }
457 
458 QualType
460  Common *CommonPtr = getCommonPtr();
461  if (!CommonPtr->InjectedClassNameType.isNull())
462  return CommonPtr->InjectedClassNameType;
463 
464  // C++0x [temp.dep.type]p2:
465  // The template argument list of a primary template is a template argument
466  // list in which the nth template argument has the value of the nth template
467  // parameter of the class template. If the nth template parameter is a
468  // template parameter pack (14.5.3), the nth template argument is a pack
469  // expansion (14.5.3) whose pattern is the name of the template parameter
470  // pack.
471  ASTContext &Context = getASTContext();
472  TemplateParameterList *Params = getTemplateParameters();
474  Context.getInjectedTemplateArgs(Params, TemplateArgs);
475  CommonPtr->InjectedClassNameType
477  TemplateArgs);
478  return CommonPtr->InjectedClassNameType;
479 }
480 
481 //===----------------------------------------------------------------------===//
482 // TemplateTypeParm Allocation/Deallocation Method Implementations
483 //===----------------------------------------------------------------------===//
484 
487  SourceLocation KeyLoc, SourceLocation NameLoc,
488  unsigned D, unsigned P, IdentifierInfo *Id,
489  bool Typename, bool ParameterPack) {
490  auto *TTPDecl =
491  new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename);
492  QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
493  TTPDecl->setTypeForDecl(TTPType.getTypePtr());
494  return TTPDecl;
495 }
496 
499  return new (C, ID) TemplateTypeParmDecl(nullptr, SourceLocation(),
500  SourceLocation(), nullptr, false);
501 }
502 
504  return hasDefaultArgument()
505  ? getDefaultArgumentInfo()->getTypeLoc().getBeginLoc()
506  : SourceLocation();
507 }
508 
510  if (hasDefaultArgument() && !defaultArgumentWasInherited())
511  return SourceRange(getBeginLoc(),
512  getDefaultArgumentInfo()->getTypeLoc().getEndLoc());
513  else
514  return TypeDecl::getSourceRange();
515 }
516 
518  return getTypeForDecl()->getAs<TemplateTypeParmType>()->getDepth();
519 }
520 
522  return getTypeForDecl()->getAs<TemplateTypeParmType>()->getIndex();
523 }
524 
526  return getTypeForDecl()->getAs<TemplateTypeParmType>()->isParameterPack();
527 }
528 
529 //===----------------------------------------------------------------------===//
530 // NonTypeTemplateParmDecl Method Implementations
531 //===----------------------------------------------------------------------===//
532 
533 NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(
534  DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D,
535  unsigned P, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
536  ArrayRef<QualType> ExpandedTypes, ArrayRef<TypeSourceInfo *> ExpandedTInfos)
537  : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
538  TemplateParmPosition(D, P), ParameterPack(true),
539  ExpandedParameterPack(true), NumExpandedTypes(ExpandedTypes.size()) {
540  if (!ExpandedTypes.empty() && !ExpandedTInfos.empty()) {
541  auto TypesAndInfos =
542  getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
543  for (unsigned I = 0; I != NumExpandedTypes; ++I) {
544  new (&TypesAndInfos[I].first) QualType(ExpandedTypes[I]);
545  TypesAndInfos[I].second = ExpandedTInfos[I];
546  }
547  }
548 }
549 
552  SourceLocation StartLoc, SourceLocation IdLoc,
553  unsigned D, unsigned P, IdentifierInfo *Id,
554  QualType T, bool ParameterPack,
555  TypeSourceInfo *TInfo) {
556  return new (C, DC) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id,
557  T, ParameterPack, TInfo);
558 }
559 
561  const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
562  SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id,
563  QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes,
564  ArrayRef<TypeSourceInfo *> ExpandedTInfos) {
565  return new (C, DC,
566  additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>(
567  ExpandedTypes.size()))
568  NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, T, TInfo,
569  ExpandedTypes, ExpandedTInfos);
570 }
571 
574  return new (C, ID) NonTypeTemplateParmDecl(nullptr, SourceLocation(),
575  SourceLocation(), 0, 0, nullptr,
576  QualType(), false, nullptr);
577 }
578 
581  unsigned NumExpandedTypes) {
582  auto *NTTP =
583  new (C, ID, additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>(
584  NumExpandedTypes))
586  0, 0, nullptr, QualType(), nullptr, None,
587  None);
588  NTTP->NumExpandedTypes = NumExpandedTypes;
589  return NTTP;
590 }
591 
593  if (hasDefaultArgument() && !defaultArgumentWasInherited())
594  return SourceRange(getOuterLocStart(),
595  getDefaultArgument()->getSourceRange().getEnd());
597 }
598 
600  return hasDefaultArgument()
601  ? getDefaultArgument()->getSourceRange().getBegin()
602  : SourceLocation();
603 }
604 
605 //===----------------------------------------------------------------------===//
606 // TemplateTemplateParmDecl Method Implementations
607 //===----------------------------------------------------------------------===//
608 
609 void TemplateTemplateParmDecl::anchor() {}
610 
611 TemplateTemplateParmDecl::TemplateTemplateParmDecl(
612  DeclContext *DC, SourceLocation L, unsigned D, unsigned P,
615  : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
616  TemplateParmPosition(D, P), ParameterPack(true),
617  ExpandedParameterPack(true), NumExpandedParams(Expansions.size()) {
618  if (!Expansions.empty())
619  std::uninitialized_copy(Expansions.begin(), Expansions.end(),
620  getTrailingObjects<TemplateParameterList *>());
621 }
622 
625  SourceLocation L, unsigned D, unsigned P,
626  bool ParameterPack, IdentifierInfo *Id,
627  TemplateParameterList *Params) {
628  return new (C, DC) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id,
629  Params);
630 }
631 
634  SourceLocation L, unsigned D, unsigned P,
635  IdentifierInfo *Id,
636  TemplateParameterList *Params,
638  return new (C, DC,
639  additionalSizeToAlloc<TemplateParameterList *>(Expansions.size()))
640  TemplateTemplateParmDecl(DC, L, D, P, Id, Params, Expansions);
641 }
642 
645  return new (C, ID) TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0,
646  false, nullptr, nullptr);
647 }
648 
651  unsigned NumExpansions) {
652  auto *TTP =
653  new (C, ID, additionalSizeToAlloc<TemplateParameterList *>(NumExpansions))
654  TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0, nullptr,
655  nullptr, None);
656  TTP->NumExpandedParams = NumExpansions;
657  return TTP;
658 }
659 
661  return hasDefaultArgument() ? getDefaultArgument().getLocation()
662  : SourceLocation();
663 }
664 
666  const ASTContext &C, const TemplateArgumentLoc &DefArg) {
667  if (DefArg.getArgument().isNull())
668  DefaultArgument.set(nullptr);
669  else
670  DefaultArgument.set(new (C) TemplateArgumentLoc(DefArg));
671 }
672 
673 //===----------------------------------------------------------------------===//
674 // TemplateArgumentList Implementation
675 //===----------------------------------------------------------------------===//
676 TemplateArgumentList::TemplateArgumentList(ArrayRef<TemplateArgument> Args)
677  : Arguments(getTrailingObjects<TemplateArgument>()),
678  NumArguments(Args.size()) {
679  std::uninitialized_copy(Args.begin(), Args.end(),
680  getTrailingObjects<TemplateArgument>());
681 }
682 
686  void *Mem = Context.Allocate(totalSizeToAlloc<TemplateArgument>(Args.size()));
687  return new (Mem) TemplateArgumentList(Args);
688 }
689 
692  TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs,
693  const TemplateArgumentListInfo *TemplateArgsAsWritten, SourceLocation POI,
694  MemberSpecializationInfo *MSInfo) {
695  const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
696  if (TemplateArgsAsWritten)
697  ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C,
698  *TemplateArgsAsWritten);
699 
700  void *Mem =
701  C.Allocate(totalSizeToAlloc<MemberSpecializationInfo *>(MSInfo ? 1 : 0));
702  return new (Mem) FunctionTemplateSpecializationInfo(
703  FD, Template, TSK, TemplateArgs, ArgsAsWritten, POI, MSInfo);
704 }
705 
706 //===----------------------------------------------------------------------===//
707 // TemplateDecl Implementation
708 //===----------------------------------------------------------------------===//
709 
710 void TemplateDecl::anchor() {}
711 
712 //===----------------------------------------------------------------------===//
713 // ClassTemplateSpecializationDecl Implementation
714 //===----------------------------------------------------------------------===//
715 
718  DeclContext *DC, SourceLocation StartLoc,
719  SourceLocation IdLoc,
720  ClassTemplateDecl *SpecializedTemplate,
723  : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc,
724  SpecializedTemplate->getIdentifier(), PrevDecl),
725  SpecializedTemplate(SpecializedTemplate),
726  TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
727  SpecializationKind(TSK_Undeclared) {
728 }
729 
731  Kind DK)
732  : CXXRecordDecl(DK, TTK_Struct, C, nullptr, SourceLocation(),
733  SourceLocation(), nullptr, nullptr),
734  SpecializationKind(TSK_Undeclared) {}
735 
738  DeclContext *DC,
739  SourceLocation StartLoc,
740  SourceLocation IdLoc,
741  ClassTemplateDecl *SpecializedTemplate,
744  auto *Result =
745  new (Context, DC) ClassTemplateSpecializationDecl(
746  Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc,
747  SpecializedTemplate, Args, PrevDecl);
748  Result->setMayHaveOutOfDateDef(false);
749 
750  Context.getTypeDeclType(Result, PrevDecl);
751  return Result;
752 }
753 
756  unsigned ID) {
757  auto *Result =
758  new (C, ID) ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization);
759  Result->setMayHaveOutOfDateDef(false);
760  return Result;
761 }
762 
764  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
765  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
766 
767  const auto *PS = dyn_cast<ClassTemplatePartialSpecializationDecl>(this);
768  if (const ASTTemplateArgumentListInfo *ArgsAsWritten =
769  PS ? PS->getTemplateArgsAsWritten() : nullptr) {
770  printTemplateArgumentList(OS, ArgsAsWritten->arguments(), Policy);
771  } else {
772  const TemplateArgumentList &TemplateArgs = getTemplateArgs();
773  printTemplateArgumentList(OS, TemplateArgs.asArray(), Policy);
774  }
775 }
776 
779  if (const auto *PartialSpec =
780  SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
781  return PartialSpec->PartialSpecialization->getSpecializedTemplate();
782  return SpecializedTemplate.get<ClassTemplateDecl*>();
783 }
784 
787  if (ExplicitInfo) {
789  if (Begin.isValid()) {
790  // Here we have an explicit (partial) specialization or instantiation.
794  if (getExternLoc().isValid())
795  Begin = getExternLoc();
797  if (End.isInvalid())
799  return SourceRange(Begin, End);
800  }
801  // An implicit instantiation of a class template partial specialization
802  // uses ExplicitInfo to record the TypeAsWritten, but the source
803  // locations should be retrieved from the instantiation pattern.
805  auto *ctpsd = const_cast<CTPSDecl *>(cast<CTPSDecl>(this));
806  CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember();
807  assert(inst_from != nullptr);
808  return inst_from->getSourceRange();
809  }
810  else {
811  // No explicit info available.
812  llvm::PointerUnion<ClassTemplateDecl *,
814  inst_from = getInstantiatedFrom();
815  if (inst_from.isNull())
817  if (const auto *ctd = inst_from.dyn_cast<ClassTemplateDecl *>())
818  return ctd->getSourceRange();
819  return inst_from.get<ClassTemplatePartialSpecializationDecl *>()
820  ->getSourceRange();
821  }
822 }
823 
824 //===----------------------------------------------------------------------===//
825 // ConceptDecl Implementation
826 //===----------------------------------------------------------------------===//
829  TemplateParameterList *Params,
830  Expr *ConstraintExpr) {
831  AdoptTemplateParameterList(Params, DC);
832  return new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr);
833 }
834 
836  unsigned ID) {
837  ConceptDecl *Result = new (C, ID) ConceptDecl(nullptr, SourceLocation(),
838  DeclarationName(),
839  nullptr, nullptr);
840 
841  return Result;
842 }
843 
844 //===----------------------------------------------------------------------===//
845 // ClassTemplatePartialSpecializationDecl Implementation
846 //===----------------------------------------------------------------------===//
847 void ClassTemplatePartialSpecializationDecl::anchor() {}
848 
849 ClassTemplatePartialSpecializationDecl::
850 ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK,
851  DeclContext *DC,
852  SourceLocation StartLoc,
853  SourceLocation IdLoc,
854  TemplateParameterList *Params,
855  ClassTemplateDecl *SpecializedTemplate,
857  const ASTTemplateArgumentListInfo *ArgInfos,
860  ClassTemplatePartialSpecialization,
861  TK, DC, StartLoc, IdLoc,
862  SpecializedTemplate, Args, PrevDecl),
863  TemplateParams(Params), ArgsAsWritten(ArgInfos),
864  InstantiatedFromMember(nullptr, false) {
865  AdoptTemplateParameterList(Params, this);
866 }
867 
871  SourceLocation StartLoc, SourceLocation IdLoc,
872  TemplateParameterList *Params,
873  ClassTemplateDecl *SpecializedTemplate,
875  const TemplateArgumentListInfo &ArgInfos,
876  QualType CanonInjectedType,
878  const ASTTemplateArgumentListInfo *ASTArgInfos =
879  ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
880 
881  auto *Result = new (Context, DC)
882  ClassTemplatePartialSpecializationDecl(Context, TK, DC, StartLoc, IdLoc,
883  Params, SpecializedTemplate, Args,
884  ASTArgInfos, PrevDecl);
885  Result->setSpecializationKind(TSK_ExplicitSpecialization);
886  Result->setMayHaveOutOfDateDef(false);
887 
888  Context.getInjectedClassNameType(Result, CanonInjectedType);
889  return Result;
890 }
891 
894  unsigned ID) {
896  Result->setMayHaveOutOfDateDef(false);
897  return Result;
898 }
899 
900 //===----------------------------------------------------------------------===//
901 // FriendTemplateDecl Implementation
902 //===----------------------------------------------------------------------===//
903 
904 void FriendTemplateDecl::anchor() {}
905 
908  SourceLocation L,
910  FriendUnion Friend, SourceLocation FLoc) {
911  return new (Context, DC) FriendTemplateDecl(DC, L, Params, Friend, FLoc);
912 }
913 
915  unsigned ID) {
916  return new (C, ID) FriendTemplateDecl(EmptyShell());
917 }
918 
919 //===----------------------------------------------------------------------===//
920 // TypeAliasTemplateDecl Implementation
921 //===----------------------------------------------------------------------===//
922 
924  DeclContext *DC,
925  SourceLocation L,
926  DeclarationName Name,
927  TemplateParameterList *Params,
928  NamedDecl *Decl) {
929  AdoptTemplateParameterList(Params, DC);
930  return new (C, DC) TypeAliasTemplateDecl(C, DC, L, Name, Params, Decl);
931 }
932 
934  unsigned ID) {
935  return new (C, ID) TypeAliasTemplateDecl(C, nullptr, SourceLocation(),
936  DeclarationName(), nullptr, nullptr);
937 }
938 
941  auto *CommonPtr = new (C) Common;
942  C.addDestruction(CommonPtr);
943  return CommonPtr;
944 }
945 
946 //===----------------------------------------------------------------------===//
947 // ClassScopeFunctionSpecializationDecl Implementation
948 //===----------------------------------------------------------------------===//
949 
950 void ClassScopeFunctionSpecializationDecl::anchor() {}
951 
954  unsigned ID) {
956  nullptr, SourceLocation(), nullptr, nullptr);
957 }
958 
959 //===----------------------------------------------------------------------===//
960 // VarTemplateDecl Implementation
961 //===----------------------------------------------------------------------===//
962 
964  VarTemplateDecl *CurD = this;
965  while (CurD) {
966  if (CurD->isThisDeclarationADefinition())
967  return CurD;
968  CurD = CurD->getPreviousDecl();
969  }
970  return nullptr;
971 }
972 
975  TemplateParameterList *Params,
976  VarDecl *Decl) {
977  AdoptTemplateParameterList(Params, DC);
978  return new (C, DC) VarTemplateDecl(C, DC, L, Name, Params, Decl);
979 }
980 
982  unsigned ID) {
983  return new (C, ID) VarTemplateDecl(C, nullptr, SourceLocation(),
984  DeclarationName(), nullptr, nullptr);
985 }
986 
988  loadLazySpecializationsImpl();
989 }
990 
991 llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
993  LoadLazySpecializations();
994  return getCommonPtr()->Specializations;
995 }
996 
997 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
999  LoadLazySpecializations();
1000  return getCommonPtr()->PartialSpecializations;
1001 }
1002 
1005  auto *CommonPtr = new (C) Common;
1006  C.addDestruction(CommonPtr);
1007  return CommonPtr;
1008 }
1009 
1012  void *&InsertPos) {
1013  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
1014 }
1015 
1017  void *InsertPos) {
1018  addSpecializationImpl<VarTemplateDecl>(getSpecializations(), D, InsertPos);
1019 }
1020 
1023  void *&InsertPos) {
1024  return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
1025 }
1026 
1028  VarTemplatePartialSpecializationDecl *D, void *InsertPos) {
1029  if (InsertPos)
1030  getPartialSpecializations().InsertNode(D, InsertPos);
1031  else {
1033  getPartialSpecializations().GetOrInsertNode(D);
1034  (void)Existing;
1035  assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
1036  }
1037 
1039  L->AddedCXXTemplateSpecialization(this, D);
1040 }
1041 
1044  llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &PartialSpecs =
1045  getPartialSpecializations();
1046  PS.clear();
1047  PS.reserve(PartialSpecs.size());
1048  for (VarTemplatePartialSpecializationDecl &P : PartialSpecs)
1049  PS.push_back(P.getMostRecentDecl());
1050 }
1051 
1055  Decl *DCanon = D->getCanonicalDecl();
1056  for (VarTemplatePartialSpecializationDecl &P : getPartialSpecializations()) {
1057  if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
1058  return P.getMostRecentDecl();
1059  }
1060 
1061  return nullptr;
1062 }
1063 
1064 //===----------------------------------------------------------------------===//
1065 // VarTemplateSpecializationDecl Implementation
1066 //===----------------------------------------------------------------------===//
1067 
1069  Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1070  SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1072  : VarDecl(DK, Context, DC, StartLoc, IdLoc,
1073  SpecializedTemplate->getIdentifier(), T, TInfo, S),
1074  SpecializedTemplate(SpecializedTemplate),
1075  TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
1076  SpecializationKind(TSK_Undeclared), IsCompleteDefinition(false) {}
1077 
1079  ASTContext &C)
1080  : VarDecl(DK, C, nullptr, SourceLocation(), SourceLocation(), nullptr,
1081  QualType(), nullptr, SC_None),
1082  SpecializationKind(TSK_Undeclared), IsCompleteDefinition(false) {}
1083 
1085  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1086  SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1088  return new (Context, DC) VarTemplateSpecializationDecl(
1089  VarTemplateSpecialization, Context, DC, StartLoc, IdLoc,
1090  SpecializedTemplate, T, TInfo, S, Args);
1091 }
1092 
1095  return new (C, ID)
1096  VarTemplateSpecializationDecl(VarTemplateSpecialization, C);
1097 }
1098 
1100  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
1101  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
1102 
1103  const auto *PS = dyn_cast<VarTemplatePartialSpecializationDecl>(this);
1104  if (const ASTTemplateArgumentListInfo *ArgsAsWritten =
1105  PS ? PS->getTemplateArgsAsWritten() : nullptr) {
1106  printTemplateArgumentList(OS, ArgsAsWritten->arguments(), Policy);
1107  } else {
1108  const TemplateArgumentList &TemplateArgs = getTemplateArgs();
1109  printTemplateArgumentList(OS, TemplateArgs.asArray(), Policy);
1110  }
1111 }
1112 
1114  if (const auto *PartialSpec =
1115  SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1116  return PartialSpec->PartialSpecialization->getSpecializedTemplate();
1117  return SpecializedTemplate.get<VarTemplateDecl *>();
1118 }
1119 
1121  const TemplateArgumentListInfo &ArgsInfo) {
1122  TemplateArgsInfo.setLAngleLoc(ArgsInfo.getLAngleLoc());
1123  TemplateArgsInfo.setRAngleLoc(ArgsInfo.getRAngleLoc());
1124  for (const TemplateArgumentLoc &Loc : ArgsInfo.arguments())
1125  TemplateArgsInfo.addArgument(Loc);
1126 }
1127 
1128 //===----------------------------------------------------------------------===//
1129 // VarTemplatePartialSpecializationDecl Implementation
1130 //===----------------------------------------------------------------------===//
1131 
1132 void VarTemplatePartialSpecializationDecl::anchor() {}
1133 
1134 VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl(
1135  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1136  SourceLocation IdLoc, TemplateParameterList *Params,
1137  VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1139  const ASTTemplateArgumentListInfo *ArgInfos)
1140  : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization, Context,
1141  DC, StartLoc, IdLoc, SpecializedTemplate, T,
1142  TInfo, S, Args),
1143  TemplateParams(Params), ArgsAsWritten(ArgInfos),
1144  InstantiatedFromMember(nullptr, false) {
1145  // TODO: The template parameters should be in DC by now. Verify.
1146  // AdoptTemplateParameterList(Params, DC);
1147 }
1148 
1151  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1152  SourceLocation IdLoc, TemplateParameterList *Params,
1153  VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1155  const TemplateArgumentListInfo &ArgInfos) {
1156  const ASTTemplateArgumentListInfo *ASTArgInfos
1157  = ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
1158 
1159  auto *Result =
1160  new (Context, DC) VarTemplatePartialSpecializationDecl(
1161  Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo,
1162  S, Args, ASTArgInfos);
1163  Result->setSpecializationKind(TSK_ExplicitSpecialization);
1164  return Result;
1165 }
1166 
1169  unsigned ID) {
1170  return new (C, ID) VarTemplatePartialSpecializationDecl(C);
1171 }
1172 
1173 static TemplateParameterList *
1175  // typename T
1176  auto *T = TemplateTypeParmDecl::Create(
1177  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/1, /*Position=*/0,
1178  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
1179  T->setImplicit(true);
1180 
1181  // T ...Ints
1182  TypeSourceInfo *TI =
1183  C.getTrivialTypeSourceInfo(QualType(T->getTypeForDecl(), 0));
1185  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1186  /*Id=*/nullptr, TI->getType(), /*ParameterPack=*/true, TI);
1187  N->setImplicit(true);
1188 
1189  // <typename T, T ...Ints>
1190  NamedDecl *P[2] = {T, N};
1191  auto *TPL = TemplateParameterList::Create(
1192  C, SourceLocation(), SourceLocation(), P, SourceLocation(), nullptr);
1193 
1194  // template <typename T, ...Ints> class IntSeq
1195  auto *TemplateTemplateParm = TemplateTemplateParmDecl::Create(
1196  C, DC, SourceLocation(), /*Depth=*/0, /*Position=*/0,
1197  /*ParameterPack=*/false, /*Id=*/nullptr, TPL);
1198  TemplateTemplateParm->setImplicit(true);
1199 
1200  // typename T
1201  auto *TemplateTypeParm = TemplateTypeParmDecl::Create(
1202  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1203  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
1204  TemplateTypeParm->setImplicit(true);
1205 
1206  // T N
1208  QualType(TemplateTypeParm->getTypeForDecl(), 0));
1209  auto *NonTypeTemplateParm = NonTypeTemplateParmDecl::Create(
1210  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/2,
1211  /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo);
1212  NamedDecl *Params[] = {TemplateTemplateParm, TemplateTypeParm,
1213  NonTypeTemplateParm};
1214 
1215  // template <template <typename T, T ...Ints> class IntSeq, typename T, T N>
1217  Params, SourceLocation(), nullptr);
1218 }
1219 
1220 static TemplateParameterList *
1222  // std::size_t Index
1224  auto *Index = NonTypeTemplateParmDecl::Create(
1225  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/0,
1226  /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo);
1227 
1228  // typename ...T
1229  auto *Ts = TemplateTypeParmDecl::Create(
1230  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1231  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/true);
1232  Ts->setImplicit(true);
1233 
1234  // template <std::size_t Index, typename ...T>
1235  NamedDecl *Params[] = {Index, Ts};
1237  llvm::makeArrayRef(Params),
1238  SourceLocation(), nullptr);
1239 }
1240 
1242  const ASTContext &C, DeclContext *DC, BuiltinTemplateKind BTK) {
1243  switch (BTK) {
1244  case BTK__make_integer_seq:
1245  return createMakeIntegerSeqParameterList(C, DC);
1247  return createTypePackElementParameterList(C, DC);
1248  }
1249 
1250  llvm_unreachable("unhandled BuiltinTemplateKind!");
1251 }
1252 
1253 void BuiltinTemplateDecl::anchor() {}
1254 
1255 BuiltinTemplateDecl::BuiltinTemplateDecl(const ASTContext &C, DeclContext *DC,
1256  DeclarationName Name,
1257  BuiltinTemplateKind BTK)
1258  : TemplateDecl(BuiltinTemplate, DC, SourceLocation(), Name,
1260  BTK(BTK) {}
Defines the clang::ASTContext interface.
void setImplicit(bool I=true)
Definition: DeclBase.h:559
Represents a function declaration or definition.
Definition: Decl.h:1748
A (possibly-)qualified type.
Definition: Type.h:643
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:3178
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:88
ArrayRef< NamedDecl * > asArray()
Definition: DeclTemplate.h:125
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 FunctionTemplateSpecializationInfo * Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template, TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs, const TemplateArgumentListInfo *TemplateArgsAsWritten, SourceLocation POI, MemberSpecializationInfo *MSInfo)
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:132
A container of type source information.
Definition: Decl.h:86
void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo)
void mergePrevDecl(FunctionTemplateDecl *Prev)
Merge Prev with our RedeclarableTemplateDecl::Common.
SourceLocation getEndLoc() const
Get the end source location.
Definition: TypeLoc.cpp:226
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:574
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:793
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:603
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:67
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:37
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:466
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:154
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:374
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:512
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:554
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:1891
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:6142
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:730
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
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.
llvm::FoldingSetVector< FunctionTemplateSpecializationInfo > Specializations
The function template specializations for this function template, including explicit specializations ...
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:104
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:883
This represents one expression.
Definition: Expr.h:108
CommonBase * getCommonPtr() const
Retrieves the "common" pointer shared by all (re-)declarations of the same template.
void setAssociatedConstraints(Expr *AC)
Definition: DeclTemplate.h:491
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:190
Declaration of a template type parameter.
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
#define bool
Definition: stdbool.h:15
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:268
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:200
Represents a C++ template name within the type system.
Definition: TemplateName.h:187
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:234
void addDestruction(T *Ptr) const
If T isn&#39;t trivially destructible, calls AddDeallocation to register it for destruction.
Definition: ASTContext.h:2758
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:1398
The result type of a method or function.
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:708
static StringRef getIdentifier(const Token &Tok)
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:2060
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:17
The "struct" keyword.
Definition: Type.h:5103
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:203
uint32_t * LazySpecializations
If non-null, points to an array of specializations (including partial specializations) known only by ...
Definition: DeclTemplate.h:877
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:250
CommonBase * newCommon(ASTContext &C) const override
Data that is common to all of the declarations of a given function template.
static void AdoptTemplateParameterList(TemplateParameterList *Params, DeclContext *Owner)
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template...
static ConceptDecl * CreateDeserialized(ASTContext &C, unsigned ID)
BuiltinTemplateKind
Kinds of BuiltinTemplateDecl.
Definition: Builtins.h:248
FunctionTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this function template, or nullptr if no such declaration exists...
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:192
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
Definition: Specifiers.h:177
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:573
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:594
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:672
Represents a template argument.
Definition: TemplateBase.h:50
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:5101
TagTypeKind TagKind
Definition: Decl.h:3104
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:1654
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:498
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:1271
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:403
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:188
unsigned getIndex() const
Retrieve the index of the template parameter.
static VarTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
The name of a declaration.
static NonTypeTemplateParmDecl * CreateDeserialized(ASTContext &C, unsigned ID)
This names the __type_pack_element BuiltinTemplateDecl.
Definition: Builtins.h:253
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:174
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:582
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:1081
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:237
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:449
static ClassTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
This template specialization was declared or defined by an explicit specialization (C++ [temp...
Definition: Specifiers.h:184
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:2296
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:214
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:240
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.
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
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:664
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:2936
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:91
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:570
llvm::FoldingSetVector< FunctionTemplateSpecializationInfo > & getSpecializations() const
Retrieve the set of function template specializations of this function template.
static ConceptDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, Expr *ConstraintExpr)
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:571
VarTemplateDecl * getDefinition()
SourceRange getSourceRange() const LLVM_READONLY
Definition: DeclTemplate.h:175
Defines enum values for all the target-independent builtin functions.
Declaration of a template function.
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>.