clang  6.0.0svn
DeclTemplate.cpp
Go to the documentation of this file.
1 //===- DeclTemplate.cpp - Template Declaration AST Node Implementation ----===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the C++ related Decl classes for templates.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/DeclTemplate.h"
15 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/Expr.h"
20 #include "clang/AST/TemplateBase.h"
21 #include "clang/AST/TemplateName.h"
22 #include "clang/AST/Type.h"
23 #include "clang/AST/TypeLoc.h"
24 #include "clang/Basic/Builtins.h"
25 #include "clang/Basic/LLVM.h"
27 #include "llvm/ADT/ArrayRef.h"
28 #include "llvm/ADT/FoldingSet.h"
29 #include "llvm/ADT/None.h"
30 #include "llvm/ADT/PointerUnion.h"
31 #include "llvm/ADT/SmallVector.h"
32 #include "llvm/Support/Casting.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include <algorithm>
35 #include <cassert>
36 #include <cstdint>
37 #include <memory>
38 #include <utility>
39 
40 using namespace clang;
41 
42 //===----------------------------------------------------------------------===//
43 // TemplateParameterList Implementation
44 //===----------------------------------------------------------------------===//
45 
47  SourceLocation LAngleLoc,
48  ArrayRef<NamedDecl *> Params,
49  SourceLocation RAngleLoc,
50  Expr *RequiresClause)
51  : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
52  NumParams(Params.size()), ContainsUnexpandedParameterPack(false),
53  HasRequiresClause(static_cast<bool>(RequiresClause)) {
54  for (unsigned Idx = 0; Idx < NumParams; ++Idx) {
55  NamedDecl *P = Params[Idx];
56  begin()[Idx] = P;
57 
58  if (!P->isTemplateParameterPack()) {
59  if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
60  if (NTTP->getType()->containsUnexpandedParameterPack())
61  ContainsUnexpandedParameterPack = true;
62 
63  if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
64  if (TTP->getTemplateParameters()->containsUnexpandedParameterPack())
65  ContainsUnexpandedParameterPack = true;
66 
67  // FIXME: If a default argument contains an unexpanded parameter pack, the
68  // template parameter list does too.
69  }
70  }
71  if (RequiresClause) {
72  *getTrailingObjects<Expr *>() = RequiresClause;
73  }
74 }
75 
78  SourceLocation LAngleLoc,
79  ArrayRef<NamedDecl *> Params,
80  SourceLocation RAngleLoc, Expr *RequiresClause) {
81  void *Mem = C.Allocate(totalSizeToAlloc<NamedDecl *, Expr *>(
82  Params.size(), RequiresClause ? 1u : 0u),
83  alignof(TemplateParameterList));
84  return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params,
85  RAngleLoc, RequiresClause);
86 }
87 
89  unsigned NumRequiredArgs = 0;
90  for (const NamedDecl *P : asArray()) {
91  if (P->isTemplateParameterPack()) {
92  if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
93  if (NTTP->isExpandedParameterPack()) {
94  NumRequiredArgs += NTTP->getNumExpansionTypes();
95  continue;
96  }
97 
98  break;
99  }
100 
101  if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(P)) {
102  if (TTP->hasDefaultArgument())
103  break;
104  } else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) {
105  if (NTTP->hasDefaultArgument())
106  break;
107  } else if (cast<TemplateTemplateParmDecl>(P)->hasDefaultArgument())
108  break;
109 
110  ++NumRequiredArgs;
111  }
112 
113  return NumRequiredArgs;
114 }
115 
117  if (size() == 0)
118  return 0;
119 
120  const NamedDecl *FirstParm = getParam(0);
121  if (const TemplateTypeParmDecl *TTP
122  = dyn_cast<TemplateTypeParmDecl>(FirstParm))
123  return TTP->getDepth();
124  else if (const NonTypeTemplateParmDecl *NTTP
125  = dyn_cast<NonTypeTemplateParmDecl>(FirstParm))
126  return NTTP->getDepth();
127  else
128  return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth();
129 }
130 
132  DeclContext *Owner) {
133  for (NamedDecl *P : *Params) {
134  P->setDeclContext(Owner);
135 
136  if (auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
137  AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner);
138  }
139 }
140 
141 namespace clang {
142 
144  return new (C) char[sizeof(void*) * 2];
145 }
146 
147 } // namespace clang
148 
149 //===----------------------------------------------------------------------===//
150 // RedeclarableTemplateDecl Implementation
151 //===----------------------------------------------------------------------===//
152 
154  if (Common)
155  return Common;
156 
157  // Walk the previous-declaration chain until we either find a declaration
158  // with a common pointer or we run out of previous declarations.
160  for (const RedeclarableTemplateDecl *Prev = getPreviousDecl(); Prev;
161  Prev = Prev->getPreviousDecl()) {
162  if (Prev->Common) {
163  Common = Prev->Common;
164  break;
165  }
166 
167  PrevDecls.push_back(Prev);
168  }
169 
170  // If we never found a common pointer, allocate one now.
171  if (!Common) {
172  // FIXME: If any of the declarations is from an AST file, we probably
173  // need an update record to add the common data.
174 
175  Common = newCommon(getASTContext());
176  }
177 
178  // Update any previous declarations we saw with the common pointer.
179  for (const RedeclarableTemplateDecl *Prev : PrevDecls)
180  Prev->Common = Common;
181 
182  return Common;
183 }
184 
185 template<class EntryType>
188  llvm::FoldingSetVector<EntryType> &Specs, ArrayRef<TemplateArgument> Args,
189  void *&InsertPos) {
190  using SETraits = SpecEntryTraits<EntryType>;
191 
192  llvm::FoldingSetNodeID ID;
193  EntryType::Profile(ID,Args, getASTContext());
194  EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
195  return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
196 }
197 
198 template<class Derived, class EntryType>
200  llvm::FoldingSetVector<EntryType> &Specializations, EntryType *Entry,
201  void *InsertPos) {
202  using SETraits = SpecEntryTraits<EntryType>;
203 
204  if (InsertPos) {
205 #ifndef NDEBUG
206  void *CorrectInsertPos;
207  assert(!findSpecializationImpl(Specializations,
208  SETraits::getTemplateArgs(Entry),
209  CorrectInsertPos) &&
210  InsertPos == CorrectInsertPos &&
211  "given incorrect InsertPos for specialization");
212 #endif
213  Specializations.InsertNode(Entry, InsertPos);
214  } else {
215  EntryType *Existing = Specializations.GetOrInsertNode(Entry);
216  (void)Existing;
217  assert(SETraits::getDecl(Existing)->isCanonicalDecl() &&
218  "non-canonical specialization?");
219  }
220 
221  if (ASTMutationListener *L = getASTMutationListener())
222  L->AddedCXXTemplateSpecialization(cast<Derived>(this),
223  SETraits::getDecl(Entry));
224 }
225 
226 //===----------------------------------------------------------------------===//
227 // FunctionTemplateDecl Implementation
228 //===----------------------------------------------------------------------===//
229 
231  DeclContext *DC,
232  SourceLocation L,
233  DeclarationName Name,
234  TemplateParameterList *Params,
235  NamedDecl *Decl) {
236  AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
237  return new (C, DC) FunctionTemplateDecl(C, DC, L, Name, Params, Decl);
238 }
239 
241  unsigned ID) {
242  return new (C, ID) FunctionTemplateDecl(C, nullptr, SourceLocation(),
243  DeclarationName(), nullptr, nullptr);
244 }
245 
248  Common *CommonPtr = new (C) Common;
249  C.addDestruction(CommonPtr);
250  return CommonPtr;
251 }
252 
254  // Grab the most recent declaration to ensure we've loaded any lazy
255  // redeclarations of this template.
256  //
257  // FIXME: Avoid walking the entire redeclaration chain here.
258  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
259  if (CommonPtr->LazySpecializations) {
260  ASTContext &Context = getASTContext();
261  uint32_t *Specs = CommonPtr->LazySpecializations;
262  CommonPtr->LazySpecializations = nullptr;
263  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
264  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
265  }
266 }
267 
268 llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
270  LoadLazySpecializations();
271  return getCommonPtr()->Specializations;
272 }
273 
274 FunctionDecl *
276  void *&InsertPos) {
277  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
278 }
279 
281  FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
282  addSpecializationImpl<FunctionTemplateDecl>(getSpecializations(), Info,
283  InsertPos);
284 }
285 
287  TemplateParameterList *Params = getTemplateParameters();
288  Common *CommonPtr = getCommonPtr();
289  if (!CommonPtr->InjectedArgs) {
290  auto &Context = getASTContext();
292  Context.getInjectedTemplateArgs(Params, TemplateArgs);
293  CommonPtr->InjectedArgs =
294  new (Context) TemplateArgument[TemplateArgs.size()];
295  std::copy(TemplateArgs.begin(), TemplateArgs.end(),
296  CommonPtr->InjectedArgs);
297  }
298 
299  return llvm::makeArrayRef(CommonPtr->InjectedArgs, Params->size());
300 }
301 
302 //===----------------------------------------------------------------------===//
303 // ClassTemplateDecl Implementation
304 //===----------------------------------------------------------------------===//
305 
307  DeclContext *DC,
308  SourceLocation L,
309  DeclarationName Name,
310  TemplateParameterList *Params,
311  NamedDecl *Decl,
312  Expr *AssociatedConstraints) {
313  AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
314 
315  if (!AssociatedConstraints) {
316  return new (C, DC) ClassTemplateDecl(C, DC, L, Name, Params, Decl);
317  }
318 
320  ClassTemplateDecl *const New =
321  new (C, DC) ClassTemplateDecl(CTDI, C, DC, L, Name, Params, Decl);
322  New->setAssociatedConstraints(AssociatedConstraints);
323  return New;
324 }
325 
327  unsigned ID) {
328  return new (C, ID) ClassTemplateDecl(C, nullptr, SourceLocation(),
329  DeclarationName(), nullptr, nullptr);
330 }
331 
333  // Grab the most recent declaration to ensure we've loaded any lazy
334  // redeclarations of this template.
335  //
336  // FIXME: Avoid walking the entire redeclaration chain here.
337  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
338  if (CommonPtr->LazySpecializations) {
339  ASTContext &Context = getASTContext();
340  uint32_t *Specs = CommonPtr->LazySpecializations;
341  CommonPtr->LazySpecializations = nullptr;
342  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
343  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
344  }
345 }
346 
347 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
349  LoadLazySpecializations();
350  return getCommonPtr()->Specializations;
351 }
352 
353 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
355  LoadLazySpecializations();
356  return getCommonPtr()->PartialSpecializations;
357 }
358 
361  Common *CommonPtr = new (C) Common;
362  C.addDestruction(CommonPtr);
363  return CommonPtr;
364 }
365 
368  void *&InsertPos) {
369  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
370 }
371 
373  void *InsertPos) {
374  addSpecializationImpl<ClassTemplateDecl>(getSpecializations(), D, InsertPos);
375 }
376 
379  void *&InsertPos) {
380  return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
381 }
382 
385  void *InsertPos) {
386  if (InsertPos)
387  getPartialSpecializations().InsertNode(D, InsertPos);
388  else {
390  = getPartialSpecializations().GetOrInsertNode(D);
391  (void)Existing;
392  assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
393  }
394 
395  if (ASTMutationListener *L = getASTMutationListener())
396  L->AddedCXXTemplateSpecialization(this, D);
397 }
398 
401  llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs
402  = getPartialSpecializations();
403  PS.clear();
404  PS.reserve(PartialSpecs.size());
405  for (ClassTemplatePartialSpecializationDecl &P : PartialSpecs)
406  PS.push_back(P.getMostRecentDecl());
407 }
408 
411  ASTContext &Context = getASTContext();
413  getPartialSpecializations()) {
414  if (Context.hasSameType(P.getInjectedSpecializationType(), T))
415  return P.getMostRecentDecl();
416  }
417 
418  return nullptr;
419 }
420 
424  Decl *DCanon = D->getCanonicalDecl();
425  for (ClassTemplatePartialSpecializationDecl &P : getPartialSpecializations()) {
426  if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
427  return P.getMostRecentDecl();
428  }
429 
430  return nullptr;
431 }
432 
433 QualType
435  Common *CommonPtr = getCommonPtr();
436  if (!CommonPtr->InjectedClassNameType.isNull())
437  return CommonPtr->InjectedClassNameType;
438 
439  // C++0x [temp.dep.type]p2:
440  // The template argument list of a primary template is a template argument
441  // list in which the nth template argument has the value of the nth template
442  // parameter of the class template. If the nth template parameter is a
443  // template parameter pack (14.5.3), the nth template argument is a pack
444  // expansion (14.5.3) whose pattern is the name of the template parameter
445  // pack.
446  ASTContext &Context = getASTContext();
447  TemplateParameterList *Params = getTemplateParameters();
449  Context.getInjectedTemplateArgs(Params, TemplateArgs);
450  CommonPtr->InjectedClassNameType
452  TemplateArgs);
453  return CommonPtr->InjectedClassNameType;
454 }
455 
456 //===----------------------------------------------------------------------===//
457 // TemplateTypeParm Allocation/Deallocation Method Implementations
458 //===----------------------------------------------------------------------===//
459 
462  SourceLocation KeyLoc, SourceLocation NameLoc,
463  unsigned D, unsigned P, IdentifierInfo *Id,
464  bool Typename, bool ParameterPack) {
465  TemplateTypeParmDecl *TTPDecl =
466  new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename);
467  QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
468  TTPDecl->setTypeForDecl(TTPType.getTypePtr());
469  return TTPDecl;
470 }
471 
474  return new (C, ID) TemplateTypeParmDecl(nullptr, SourceLocation(),
475  SourceLocation(), nullptr, false);
476 }
477 
479  return hasDefaultArgument()
480  ? getDefaultArgumentInfo()->getTypeLoc().getBeginLoc()
481  : SourceLocation();
482 }
483 
485  if (hasDefaultArgument() && !defaultArgumentWasInherited())
486  return SourceRange(getLocStart(),
487  getDefaultArgumentInfo()->getTypeLoc().getEndLoc());
488  else
489  return TypeDecl::getSourceRange();
490 }
491 
493  return getTypeForDecl()->getAs<TemplateTypeParmType>()->getDepth();
494 }
495 
497  return getTypeForDecl()->getAs<TemplateTypeParmType>()->getIndex();
498 }
499 
501  return getTypeForDecl()->getAs<TemplateTypeParmType>()->isParameterPack();
502 }
503 
504 //===----------------------------------------------------------------------===//
505 // NonTypeTemplateParmDecl Method Implementations
506 //===----------------------------------------------------------------------===//
507 
508 NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(
509  DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D,
510  unsigned P, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
511  ArrayRef<QualType> ExpandedTypes, ArrayRef<TypeSourceInfo *> ExpandedTInfos)
512  : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
513  TemplateParmPosition(D, P), ParameterPack(true),
514  ExpandedParameterPack(true), NumExpandedTypes(ExpandedTypes.size()) {
515  if (!ExpandedTypes.empty() && !ExpandedTInfos.empty()) {
516  auto TypesAndInfos =
517  getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
518  for (unsigned I = 0; I != NumExpandedTypes; ++I) {
519  new (&TypesAndInfos[I].first) QualType(ExpandedTypes[I]);
520  TypesAndInfos[I].second = ExpandedTInfos[I];
521  }
522  }
523 }
524 
527  SourceLocation StartLoc, SourceLocation IdLoc,
528  unsigned D, unsigned P, IdentifierInfo *Id,
529  QualType T, bool ParameterPack,
530  TypeSourceInfo *TInfo) {
531  return new (C, DC) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id,
532  T, ParameterPack, TInfo);
533 }
534 
536  const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
537  SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id,
538  QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes,
539  ArrayRef<TypeSourceInfo *> ExpandedTInfos) {
540  return new (C, DC,
541  additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>(
542  ExpandedTypes.size()))
543  NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, T, TInfo,
544  ExpandedTypes, ExpandedTInfos);
545 }
546 
549  return new (C, ID) NonTypeTemplateParmDecl(nullptr, SourceLocation(),
550  SourceLocation(), 0, 0, nullptr,
551  QualType(), false, nullptr);
552 }
553 
556  unsigned NumExpandedTypes) {
557  auto *NTTP =
558  new (C, ID, additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>(
559  NumExpandedTypes))
561  0, 0, nullptr, QualType(), nullptr, None,
562  None);
563  NTTP->NumExpandedTypes = NumExpandedTypes;
564  return NTTP;
565 }
566 
568  if (hasDefaultArgument() && !defaultArgumentWasInherited())
569  return SourceRange(getOuterLocStart(),
570  getDefaultArgument()->getSourceRange().getEnd());
572 }
573 
575  return hasDefaultArgument()
576  ? getDefaultArgument()->getSourceRange().getBegin()
577  : SourceLocation();
578 }
579 
580 //===----------------------------------------------------------------------===//
581 // TemplateTemplateParmDecl Method Implementations
582 //===----------------------------------------------------------------------===//
583 
584 void TemplateTemplateParmDecl::anchor() {}
585 
586 TemplateTemplateParmDecl::TemplateTemplateParmDecl(
587  DeclContext *DC, SourceLocation L, unsigned D, unsigned P,
590  : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
591  TemplateParmPosition(D, P), ParameterPack(true),
592  ExpandedParameterPack(true), NumExpandedParams(Expansions.size()) {
593  if (!Expansions.empty())
594  std::uninitialized_copy(Expansions.begin(), Expansions.end(),
595  getTrailingObjects<TemplateParameterList *>());
596 }
597 
600  SourceLocation L, unsigned D, unsigned P,
601  bool ParameterPack, IdentifierInfo *Id,
602  TemplateParameterList *Params) {
603  return new (C, DC) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id,
604  Params);
605 }
606 
609  SourceLocation L, unsigned D, unsigned P,
610  IdentifierInfo *Id,
611  TemplateParameterList *Params,
613  return new (C, DC,
614  additionalSizeToAlloc<TemplateParameterList *>(Expansions.size()))
615  TemplateTemplateParmDecl(DC, L, D, P, Id, Params, Expansions);
616 }
617 
620  return new (C, ID) TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0,
621  false, nullptr, nullptr);
622 }
623 
626  unsigned NumExpansions) {
627  auto *TTP =
628  new (C, ID, additionalSizeToAlloc<TemplateParameterList *>(NumExpansions))
629  TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0, nullptr,
630  nullptr, None);
631  TTP->NumExpandedParams = NumExpansions;
632  return TTP;
633 }
634 
636  return hasDefaultArgument() ? getDefaultArgument().getLocation()
637  : SourceLocation();
638 }
639 
641  const ASTContext &C, const TemplateArgumentLoc &DefArg) {
642  if (DefArg.getArgument().isNull())
643  DefaultArgument.set(nullptr);
644  else
645  DefaultArgument.set(new (C) TemplateArgumentLoc(DefArg));
646 }
647 
648 //===----------------------------------------------------------------------===//
649 // TemplateArgumentList Implementation
650 //===----------------------------------------------------------------------===//
651 TemplateArgumentList::TemplateArgumentList(ArrayRef<TemplateArgument> Args)
652  : Arguments(getTrailingObjects<TemplateArgument>()),
653  NumArguments(Args.size()) {
654  std::uninitialized_copy(Args.begin(), Args.end(),
655  getTrailingObjects<TemplateArgument>());
656 }
657 
661  void *Mem = Context.Allocate(totalSizeToAlloc<TemplateArgument>(Args.size()));
662  return new (Mem) TemplateArgumentList(Args);
663 }
664 
667  FunctionTemplateDecl *Template,
669  const TemplateArgumentList *TemplateArgs,
670  const TemplateArgumentListInfo *TemplateArgsAsWritten,
671  SourceLocation POI) {
672  const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
673  if (TemplateArgsAsWritten)
674  ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C,
675  *TemplateArgsAsWritten);
676 
677  return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK,
678  TemplateArgs,
679  ArgsAsWritten,
680  POI);
681 }
682 
683 //===----------------------------------------------------------------------===//
684 // TemplateDecl Implementation
685 //===----------------------------------------------------------------------===//
686 
687 void TemplateDecl::anchor() {}
688 
689 //===----------------------------------------------------------------------===//
690 // ClassTemplateSpecializationDecl Implementation
691 //===----------------------------------------------------------------------===//
692 
695  DeclContext *DC, SourceLocation StartLoc,
696  SourceLocation IdLoc,
697  ClassTemplateDecl *SpecializedTemplate,
700  : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc,
701  SpecializedTemplate->getIdentifier(), PrevDecl),
702  SpecializedTemplate(SpecializedTemplate),
703  TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
704  SpecializationKind(TSK_Undeclared) {
705 }
706 
708  Kind DK)
709  : CXXRecordDecl(DK, TTK_Struct, C, nullptr, SourceLocation(),
710  SourceLocation(), nullptr, nullptr),
711  SpecializationKind(TSK_Undeclared) {}
712 
715  DeclContext *DC,
716  SourceLocation StartLoc,
717  SourceLocation IdLoc,
718  ClassTemplateDecl *SpecializedTemplate,
722  new (Context, DC) ClassTemplateSpecializationDecl(
723  Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc,
724  SpecializedTemplate, Args, PrevDecl);
725  Result->MayHaveOutOfDateDef = false;
726 
727  Context.getTypeDeclType(Result, PrevDecl);
728  return Result;
729 }
730 
733  unsigned ID) {
735  new (C, ID) ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization);
736  Result->MayHaveOutOfDateDef = false;
737  return Result;
738 }
739 
741  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
742  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
743 
744  auto *PS = dyn_cast<ClassTemplatePartialSpecializationDecl>(this);
745  if (const ASTTemplateArgumentListInfo *ArgsAsWritten =
746  PS ? PS->getTemplateArgsAsWritten() : nullptr) {
747  printTemplateArgumentList(OS, ArgsAsWritten->arguments(), Policy);
748  } else {
749  const TemplateArgumentList &TemplateArgs = getTemplateArgs();
750  printTemplateArgumentList(OS, TemplateArgs.asArray(), Policy);
751  }
752 }
753 
756  if (SpecializedPartialSpecialization *PartialSpec
757  = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
758  return PartialSpec->PartialSpecialization->getSpecializedTemplate();
759  return SpecializedTemplate.get<ClassTemplateDecl*>();
760 }
761 
764  if (ExplicitInfo) {
766  if (Begin.isValid()) {
767  // Here we have an explicit (partial) specialization or instantiation.
771  if (getExternLoc().isValid())
772  Begin = getExternLoc();
774  if (End.isInvalid())
776  return SourceRange(Begin, End);
777  }
778  // An implicit instantiation of a class template partial specialization
779  // uses ExplicitInfo to record the TypeAsWritten, but the source
780  // locations should be retrieved from the instantiation pattern.
782  CTPSDecl *ctpsd = const_cast<CTPSDecl*>(cast<CTPSDecl>(this));
783  CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember();
784  assert(inst_from != nullptr);
785  return inst_from->getSourceRange();
786  }
787  else {
788  // No explicit info available.
789  llvm::PointerUnion<ClassTemplateDecl *,
791  inst_from = getInstantiatedFrom();
792  if (inst_from.isNull())
794  if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>())
795  return ctd->getSourceRange();
796  return inst_from.get<ClassTemplatePartialSpecializationDecl*>()
797  ->getSourceRange();
798  }
799 }
800 
801 //===----------------------------------------------------------------------===//
802 // ClassTemplatePartialSpecializationDecl Implementation
803 //===----------------------------------------------------------------------===//
804 void ClassTemplatePartialSpecializationDecl::anchor() {}
805 
806 ClassTemplatePartialSpecializationDecl::
807 ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK,
808  DeclContext *DC,
809  SourceLocation StartLoc,
810  SourceLocation IdLoc,
811  TemplateParameterList *Params,
812  ClassTemplateDecl *SpecializedTemplate,
814  const ASTTemplateArgumentListInfo *ArgInfos,
817  ClassTemplatePartialSpecialization,
818  TK, DC, StartLoc, IdLoc,
819  SpecializedTemplate, Args, PrevDecl),
820  TemplateParams(Params), ArgsAsWritten(ArgInfos),
821  InstantiatedFromMember(nullptr, false) {
822  AdoptTemplateParameterList(Params, this);
823 }
824 
828  SourceLocation StartLoc, SourceLocation IdLoc,
829  TemplateParameterList *Params,
830  ClassTemplateDecl *SpecializedTemplate,
832  const TemplateArgumentListInfo &ArgInfos,
833  QualType CanonInjectedType,
835  const ASTTemplateArgumentListInfo *ASTArgInfos =
836  ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
837 
839  ClassTemplatePartialSpecializationDecl(Context, TK, DC, StartLoc, IdLoc,
840  Params, SpecializedTemplate, Args,
841  ASTArgInfos, PrevDecl);
843  Result->MayHaveOutOfDateDef = false;
844 
845  Context.getInjectedClassNameType(Result, CanonInjectedType);
846  return Result;
847 }
848 
851  unsigned ID) {
854  Result->MayHaveOutOfDateDef = false;
855  return Result;
856 }
857 
858 //===----------------------------------------------------------------------===//
859 // FriendTemplateDecl Implementation
860 //===----------------------------------------------------------------------===//
861 
862 void FriendTemplateDecl::anchor() {}
863 
866  SourceLocation L,
868  FriendUnion Friend, SourceLocation FLoc) {
869  return new (Context, DC) FriendTemplateDecl(DC, L, Params, Friend, FLoc);
870 }
871 
873  unsigned ID) {
874  return new (C, ID) FriendTemplateDecl(EmptyShell());
875 }
876 
877 //===----------------------------------------------------------------------===//
878 // TypeAliasTemplateDecl Implementation
879 //===----------------------------------------------------------------------===//
880 
882  DeclContext *DC,
883  SourceLocation L,
884  DeclarationName Name,
885  TemplateParameterList *Params,
886  NamedDecl *Decl) {
887  AdoptTemplateParameterList(Params, DC);
888  return new (C, DC) TypeAliasTemplateDecl(C, DC, L, Name, Params, Decl);
889 }
890 
892  unsigned ID) {
893  return new (C, ID) TypeAliasTemplateDecl(C, nullptr, SourceLocation(),
894  DeclarationName(), nullptr, nullptr);
895 }
896 
899  Common *CommonPtr = new (C) Common;
900  C.addDestruction(CommonPtr);
901  return CommonPtr;
902 }
903 
904 //===----------------------------------------------------------------------===//
905 // ClassScopeFunctionSpecializationDecl Implementation
906 //===----------------------------------------------------------------------===//
907 
908 void ClassScopeFunctionSpecializationDecl::anchor() {}
909 
912  unsigned ID) {
914  nullptr, SourceLocation(), nullptr, false, TemplateArgumentListInfo());
915 }
916 
917 //===----------------------------------------------------------------------===//
918 // VarTemplateDecl Implementation
919 //===----------------------------------------------------------------------===//
920 
922  VarTemplateDecl *CurD = this;
923  while (CurD) {
924  if (CurD->isThisDeclarationADefinition())
925  return CurD;
926  CurD = CurD->getPreviousDecl();
927  }
928  return nullptr;
929 }
930 
933  TemplateParameterList *Params,
934  VarDecl *Decl) {
935  return new (C, DC) VarTemplateDecl(C, DC, L, Name, Params, Decl);
936 }
937 
939  unsigned ID) {
940  return new (C, ID) VarTemplateDecl(C, nullptr, SourceLocation(),
941  DeclarationName(), nullptr, nullptr);
942 }
943 
944 // TODO: Unify across class, function and variable templates?
945 // May require moving this and Common to RedeclarableTemplateDecl.
947  // Grab the most recent declaration to ensure we've loaded any lazy
948  // redeclarations of this template.
949  //
950  // FIXME: Avoid walking the entire redeclaration chain here.
951  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
952  if (CommonPtr->LazySpecializations) {
953  ASTContext &Context = getASTContext();
954  uint32_t *Specs = CommonPtr->LazySpecializations;
955  CommonPtr->LazySpecializations = nullptr;
956  for (uint32_t I = 0, N = *Specs++; I != N; ++I)
957  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
958  }
959 }
960 
961 llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
963  LoadLazySpecializations();
964  return getCommonPtr()->Specializations;
965 }
966 
967 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
969  LoadLazySpecializations();
970  return getCommonPtr()->PartialSpecializations;
971 }
972 
975  Common *CommonPtr = new (C) Common;
976  C.addDestruction(CommonPtr);
977  return CommonPtr;
978 }
979 
982  void *&InsertPos) {
983  return findSpecializationImpl(getSpecializations(), Args, InsertPos);
984 }
985 
987  void *InsertPos) {
988  addSpecializationImpl<VarTemplateDecl>(getSpecializations(), D, InsertPos);
989 }
990 
993  void *&InsertPos) {
994  return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
995 }
996 
998  VarTemplatePartialSpecializationDecl *D, void *InsertPos) {
999  if (InsertPos)
1000  getPartialSpecializations().InsertNode(D, InsertPos);
1001  else {
1003  getPartialSpecializations().GetOrInsertNode(D);
1004  (void)Existing;
1005  assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
1006  }
1007 
1009  L->AddedCXXTemplateSpecialization(this, D);
1010 }
1011 
1014  llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &PartialSpecs =
1015  getPartialSpecializations();
1016  PS.clear();
1017  PS.reserve(PartialSpecs.size());
1018  for (VarTemplatePartialSpecializationDecl &P : PartialSpecs)
1019  PS.push_back(P.getMostRecentDecl());
1020 }
1021 
1025  Decl *DCanon = D->getCanonicalDecl();
1026  for (VarTemplatePartialSpecializationDecl &P : getPartialSpecializations()) {
1027  if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
1028  return P.getMostRecentDecl();
1029  }
1030 
1031  return nullptr;
1032 }
1033 
1034 //===----------------------------------------------------------------------===//
1035 // VarTemplateSpecializationDecl Implementation
1036 //===----------------------------------------------------------------------===//
1037 
1039  Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1040  SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1042  : VarDecl(DK, Context, DC, StartLoc, IdLoc,
1043  SpecializedTemplate->getIdentifier(), T, TInfo, S),
1044  SpecializedTemplate(SpecializedTemplate),
1045  TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
1046  SpecializationKind(TSK_Undeclared), IsCompleteDefinition(false) {}
1047 
1049  ASTContext &C)
1050  : VarDecl(DK, C, nullptr, SourceLocation(), SourceLocation(), nullptr,
1051  QualType(), nullptr, SC_None),
1052  SpecializationKind(TSK_Undeclared), IsCompleteDefinition(false) {}
1053 
1055  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1056  SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1058  return new (Context, DC) VarTemplateSpecializationDecl(
1059  VarTemplateSpecialization, Context, DC, StartLoc, IdLoc,
1060  SpecializedTemplate, T, TInfo, S, Args);
1061 }
1062 
1065  return new (C, ID)
1066  VarTemplateSpecializationDecl(VarTemplateSpecialization, C);
1067 }
1068 
1070  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
1071  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
1072 
1073  auto *PS = dyn_cast<VarTemplatePartialSpecializationDecl>(this);
1074  if (const ASTTemplateArgumentListInfo *ArgsAsWritten =
1075  PS ? PS->getTemplateArgsAsWritten() : nullptr) {
1076  printTemplateArgumentList(OS, ArgsAsWritten->arguments(), Policy);
1077  } else {
1078  const TemplateArgumentList &TemplateArgs = getTemplateArgs();
1079  printTemplateArgumentList(OS, TemplateArgs.asArray(), Policy);
1080  }
1081 }
1082 
1084  if (SpecializedPartialSpecialization *PartialSpec =
1085  SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1086  return PartialSpec->PartialSpecialization->getSpecializedTemplate();
1087  return SpecializedTemplate.get<VarTemplateDecl *>();
1088 }
1089 
1091  const TemplateArgumentListInfo &ArgsInfo) {
1092  TemplateArgsInfo.setLAngleLoc(ArgsInfo.getLAngleLoc());
1093  TemplateArgsInfo.setRAngleLoc(ArgsInfo.getRAngleLoc());
1094  for (const TemplateArgumentLoc &Loc : ArgsInfo.arguments())
1095  TemplateArgsInfo.addArgument(Loc);
1096 }
1097 
1098 //===----------------------------------------------------------------------===//
1099 // VarTemplatePartialSpecializationDecl Implementation
1100 //===----------------------------------------------------------------------===//
1101 
1102 void VarTemplatePartialSpecializationDecl::anchor() {}
1103 
1104 VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl(
1105  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1106  SourceLocation IdLoc, TemplateParameterList *Params,
1107  VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1109  const ASTTemplateArgumentListInfo *ArgInfos)
1110  : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization, Context,
1111  DC, StartLoc, IdLoc, SpecializedTemplate, T,
1112  TInfo, S, Args),
1113  TemplateParams(Params), ArgsAsWritten(ArgInfos),
1114  InstantiatedFromMember(nullptr, false) {
1115  // TODO: The template parameters should be in DC by now. Verify.
1116  // AdoptTemplateParameterList(Params, DC);
1117 }
1118 
1121  ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1122  SourceLocation IdLoc, TemplateParameterList *Params,
1123  VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1125  const TemplateArgumentListInfo &ArgInfos) {
1126  const ASTTemplateArgumentListInfo *ASTArgInfos
1127  = ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
1128 
1130  new (Context, DC) VarTemplatePartialSpecializationDecl(
1131  Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo,
1132  S, Args, ASTArgInfos);
1134  return Result;
1135 }
1136 
1139  unsigned ID) {
1140  return new (C, ID) VarTemplatePartialSpecializationDecl(C);
1141 }
1142 
1143 static TemplateParameterList *
1145  // typename T
1146  auto *T = TemplateTypeParmDecl::Create(
1147  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/1, /*Position=*/0,
1148  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
1149  T->setImplicit(true);
1150 
1151  // T ...Ints
1152  TypeSourceInfo *TI =
1153  C.getTrivialTypeSourceInfo(QualType(T->getTypeForDecl(), 0));
1155  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1156  /*Id=*/nullptr, TI->getType(), /*ParameterPack=*/true, TI);
1157  N->setImplicit(true);
1158 
1159  // <typename T, T ...Ints>
1160  NamedDecl *P[2] = {T, N};
1161  auto *TPL = TemplateParameterList::Create(
1162  C, SourceLocation(), SourceLocation(), P, SourceLocation(), nullptr);
1163 
1164  // template <typename T, ...Ints> class IntSeq
1165  auto *TemplateTemplateParm = TemplateTemplateParmDecl::Create(
1166  C, DC, SourceLocation(), /*Depth=*/0, /*Position=*/0,
1167  /*ParameterPack=*/false, /*Id=*/nullptr, TPL);
1168  TemplateTemplateParm->setImplicit(true);
1169 
1170  // typename T
1171  auto *TemplateTypeParm = TemplateTypeParmDecl::Create(
1172  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1173  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false);
1174  TemplateTypeParm->setImplicit(true);
1175 
1176  // T N
1178  QualType(TemplateTypeParm->getTypeForDecl(), 0));
1179  auto *NonTypeTemplateParm = NonTypeTemplateParmDecl::Create(
1180  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/2,
1181  /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo);
1182  NamedDecl *Params[] = {TemplateTemplateParm, TemplateTypeParm,
1183  NonTypeTemplateParm};
1184 
1185  // template <template <typename T, T ...Ints> class IntSeq, typename T, T N>
1187  Params, SourceLocation(), nullptr);
1188 }
1189 
1190 static TemplateParameterList *
1192  // std::size_t Index
1194  auto *Index = NonTypeTemplateParmDecl::Create(
1195  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/0,
1196  /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo);
1197 
1198  // typename ...T
1199  auto *Ts = TemplateTypeParmDecl::Create(
1200  C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1,
1201  /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/true);
1202  Ts->setImplicit(true);
1203 
1204  // template <std::size_t Index, typename ...T>
1205  NamedDecl *Params[] = {Index, Ts};
1207  llvm::makeArrayRef(Params),
1208  SourceLocation(), nullptr);
1209 }
1210 
1212  const ASTContext &C, DeclContext *DC, BuiltinTemplateKind BTK) {
1213  switch (BTK) {
1214  case BTK__make_integer_seq:
1215  return createMakeIntegerSeqParameterList(C, DC);
1217  return createTypePackElementParameterList(C, DC);
1218  }
1219 
1220  llvm_unreachable("unhandled BuiltinTemplateKind!");
1221 }
1222 
1223 void BuiltinTemplateDecl::anchor() {}
1224 
1225 BuiltinTemplateDecl::BuiltinTemplateDecl(const ASTContext &C, DeclContext *DC,
1226  DeclarationName Name,
1227  BuiltinTemplateKind BTK)
1228  : TemplateDecl(BuiltinTemplate, DC, SourceLocation(), Name,
1230  BTK(BTK) {}
Defines the clang::ASTContext interface.
void setImplicit(bool I=true)
Definition: DeclBase.h:552
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1698
A (possibly-)qualified type.
Definition: Type.h:653
virtual Decl * GetExternalDecl(uint32_t ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
llvm::FoldingSetVector< VarTemplateSpecializationDecl > & getSpecializations() const
Retrieve the set of specializations of this variable template.
static TypeAliasTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
SourceRange getBraceRange() const
Definition: Decl.h:3066
ArrayRef< TemplateArgument > getInjectedTemplateArgs()
Retrieve the "injected" template arguments that correspond to the template parameters of this functio...
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
C Language Family Type Representation.
static TemplateTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation L, unsigned D, unsigned P, bool ParameterPack, IdentifierInfo *Id, TemplateParameterList *Params)
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
ArrayRef< NamedDecl * > asArray()
Definition: DeclTemplate.h:126
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
Defines the C++ template declaration subclasses.
StringRef P
Declaration of a variable template.
void setSpecializationKind(TemplateSpecializationKind TSK)
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:133
A container of type source information.
Definition: Decl.h:86
void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo)
SourceLocation getEndLoc() const
Get the end source location.
Definition: TypeLoc.cpp:227
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:566
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:807
ASTMutationListener * getASTMutationListener() const
Definition: DeclBase.cpp:369
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
Declaration of a redeclarable template.
Definition: DeclTemplate.h:736
SourceLocation getExternLoc() const
Gets the location of the extern keyword, if present.
Represents a variable template specialization, which refers to a variable template with a given set o...
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:595
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:68
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclTemplate.h:462
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:265
SourceLocation getDefaultArgumentLoc() const
Retrieve the location of the default argument, if any.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
One of these records is kept for each identifier that is lexed.
Represents a class template specialization, which refers to a class template with a given set of temp...
unsigned getDepth() const
Retrieve the depth of the template parameter.
VarTemplateSpecializationDecl(Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< TemplateArgument > Args)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
Defines the position of a template parameter within a template parameter list.
VarTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
void * allocateDefaultArgStorageChain(const ASTContext &C)
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
ClassTemplateSpecializationDecl * getMostRecentDecl()
Stores the template parameter list and associated constraints for TemplateDecl objects that track ass...
Definition: DeclTemplate.h:370
Declaration of a function specialization at template class scope.
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Definition: DeclTemplate.h:507
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to form a template specialization. ...
A convenient class for passing around template argument information.
Definition: TemplateBase.h:546
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
uint32_t * LazySpecializations
If non-null, points to an array of specializations (including partial specializations) known ownly by...
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:1804
SourceLocation getDefaultArgumentLoc() const
Retrieves the location of the default argument declaration.
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
void setSpecializationKind(TemplateSpecializationKind TSK)
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5720
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:705
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:681
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:871
Expr - This represents one expression.
Definition: Expr.h:106
CommonBase * getCommonPtr() const
Retrieves the "common" pointer shared by all (re-)declarations of the same template.
void setAssociatedConstraints(Expr *AC)
Definition: DeclTemplate.h:486
SourceLocation End
static ClassTemplatePartialSpecializationDecl * Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, TemplateParameterList *Params, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, const TemplateArgumentListInfo &ArgInfos, QualType CanonInjectedType, ClassTemplatePartialSpecializationDecl *PrevDecl)
int Id
Definition: ASTDiff.cpp:191
const FunctionProtoType * T
Declaration of a template type parameter.
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
#define bool
Definition: stdbool.h:31
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Data that is common to all of the declarations of a given variable template.
SourceLocation Begin
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:264
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack...
Definition: DeclBase.cpp:201
Represents a C++ template name within the type system.
Definition: TemplateName.h:178
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy)
Print a template argument list, including the &#39;<&#39; and &#39;>&#39; enclosing the template arguments.
Defines the clang::TypeLoc interface and its subclasses.
StorageClass
Storage classes.
Definition: Specifiers.h:203
Declaration of an alias template.
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations()
Retrieve the set of partial specializations of this class template.
SourceLocation getEnd() const
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
static TemplateParameterList * createBuiltinTemplateParameterList(const ASTContext &C, DeclContext *DC, BuiltinTemplateKind BTK)
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
Data that is common to all of the declarations of a given class template.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1347
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:2618
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:719
static StringRef getIdentifier(const Token &Tok)
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:1973
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl *> Params, SourceLocation RAngleLoc, Expr *RequiresClause)
static TypeAliasTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty alias template node.
void setTypeForDecl(const Type *TD)
Definition: Decl.h:2779
#define false
Definition: stdbool.h:33
The "struct" keyword.
Definition: Type.h:4690
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
static ClassTemplateSpecializationDecl * Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, ClassTemplateSpecializationDecl *PrevDecl)
CommonBase * newCommon(ASTContext &C) const override
ClassTemplatePartialSpecializationDecl * findPartialSpecInstantiatedFromMember(ClassTemplatePartialSpecializationDecl *D)
Find a class template partial specialization which was instantiated from the given member partial spe...
QualType InjectedClassNameType
The injected-class-name type for this class template.
bool isParameterPack() const
Returns whether this is a parameter pack.
Encodes a location in the source.
static TemplateTemplateParmDecl * CreateDeserialized(ASTContext &C, unsigned ID)
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getInstantiatedFrom() const
If this class template specialization is an instantiation of a template (rather than an explicit spec...
This names the __make_integer_seq BuiltinTemplateDecl.
Definition: Builtins.h:232
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:365
CommonBase * newCommon(ASTContext &C) const override
Data that is common to all of the declarations of a given function template.
Definition: DeclTemplate.h:964
static void AdoptTemplateParameterList(TemplateParameterList *Params, DeclContext *Owner)
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template...
BuiltinTemplateKind
Kinds of BuiltinTemplateDecl.
Definition: Builtins.h:230
static FriendTemplateDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation Loc, MutableArrayRef< TemplateParameterList *> Params, FriendUnion Friend, SourceLocation FriendLoc)
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:161
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
Definition: Specifiers.h:146
TypeSourceInfo * getTypeAsWritten() const
Gets the type of this specialization as it was written by the user, if it was so written.
static VarTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty variable template node.
static TemplateParameterList * createMakeIntegerSeqParameterList(const ASTContext &C, DeclContext *DC)
void addSpecialization(FunctionTemplateSpecializationInfo *Info, void *InsertPos)
Add a specialization of this function template.
void setLAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:565
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:586
static ClassTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl, Expr *AssociatedConstraints=nullptr)
Create a class template node.
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:650
Represents a template argument.
Definition: TemplateBase.h:51
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
TagTypeKind
The kind of a tag type.
Definition: Type.h:4688
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
getNameForDiagnostic - Appends a human-readable name for this declaration into the given stream...
Definition: Decl.cpp:1567
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:1252
static ClassTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty class template node.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:399
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:157
unsigned getIndex() const
Retrieve the index of the template parameter.
static VarTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
DeclarationName - The name of a declaration.
static NonTypeTemplateParmDecl * CreateDeserialized(ASTContext &C, unsigned ID)
This names the __type_pack_element BuiltinTemplateDecl.
Definition: Builtins.h:235
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:143
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:574
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:1048
static FriendTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
uint32_t * LazySpecializations
If non-null, points to an array of specializations (including partial specializations) known only by ...
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
getNameForDiagnostic - 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
getNameForDiagnostic - Appends a human-readable name for this declaration into the given stream...
unsigned MayHaveOutOfDateDef
Indicates whether it is possible for declarations of this kind to have an out-of-date definition...
Definition: Decl.h:2990
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:450
static ClassTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
This template specialization was declared or defined by an explicit specialization (C++ [temp...
Definition: Specifiers.h:153
static VarTemplatePartialSpecializationDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, TemplateParameterList *Params, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< TemplateArgument > Args, const TemplateArgumentListInfo &ArgInfos)
VarTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this variable template, or nullptr if no such declaration exists...
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2190
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:976
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *ParmDecl=nullptr) const
Retrieve the template type parameter type for a template parameter or parameter pack with the given d...
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
Defines the clang::SourceLocation class and associated facilities.
Represents a C++ struct/union/class.
Definition: DeclCXX.h:299
static const ASTTemplateArgumentListInfo * Create(ASTContext &C, const TemplateArgumentListInfo &List)
TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl *> Params, SourceLocation RAngleLoc, Expr *RequiresClause)
CommonBase * newCommon(ASTContext &C) const override
void addSpecializationImpl(llvm::FoldingSetVector< EntryType > &Specs, EntryType *Entry, void *InsertPos)
CommonBase * newCommon(ASTContext &C) const override
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
static VarTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, VarDecl *Decl)
Create a variable template node.
Declaration of a class template.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:2783
QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const
getInjectedClassNameType - Return the unique reference to the injected class name type for the specif...
uint32_t * LazySpecializations
If non-null, points to an array of specializations known only by their external declaration IDs...
Definition: DeclTemplate.h:983
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)
NamedDecl - This represents a decl with a name.
Definition: Decl.h:245
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:958
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>.