clang 19.0.0git
Template.h
Go to the documentation of this file.
1//===- SemaTemplate.h - C++ Templates ---------------------------*- C++ -*-===//
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// This file provides types used in the semantic analysis of C++ templates.
9//
10//===----------------------------------------------------------------------===//
11
12#ifndef LLVM_CLANG_SEMA_TEMPLATE_H
13#define LLVM_CLANG_SEMA_TEMPLATE_H
14
18#include "clang/AST/Type.h"
19#include "clang/Basic/LLVM.h"
20#include "clang/Sema/Sema.h"
21#include "llvm/ADT/ArrayRef.h"
22#include "llvm/ADT/DenseMap.h"
23#include "llvm/ADT/PointerUnion.h"
24#include "llvm/ADT/SmallVector.h"
25#include <cassert>
26#include <optional>
27#include <utility>
28
29namespace clang {
30
31class ASTContext;
32class BindingDecl;
33class CXXMethodDecl;
34class Decl;
35class DeclaratorDecl;
36class DeclContext;
37class EnumDecl;
38class FunctionDecl;
39class NamedDecl;
40class ParmVarDecl;
41class TagDecl;
42class TypedefNameDecl;
43class TypeSourceInfo;
44class VarDecl;
45
46/// The kind of template substitution being performed.
47enum class TemplateSubstitutionKind : char {
48 /// We are substituting template parameters for template arguments in order
49 /// to form a template specialization.
51 /// We are substituting template parameters for (typically) other template
52 /// parameters in order to rewrite a declaration as a different declaration
53 /// (for example, when forming a deduction guide from a constructor).
54 Rewrite,
55};
56
57 /// Data structure that captures multiple levels of template argument
58 /// lists for use in template instantiation.
59 ///
60 /// Multiple levels of template arguments occur when instantiating the
61 /// definitions of member templates. For example:
62 ///
63 /// \code
64 /// template<typename T>
65 /// struct X {
66 /// template<T Value>
67 /// struct Y {
68 /// void f();
69 /// };
70 /// };
71 /// \endcode
72 ///
73 /// When instantiating X<int>::Y<17>::f, the multi-level template argument
74 /// list will contain a template argument list (int) at depth 0 and a
75 /// template argument list (17) at depth 1.
77 /// The template argument list at a certain template depth
78
80 struct ArgumentListLevel {
81 llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndFinal;
82 ArgList Args;
83 };
85
86 using ArgListsIterator = ContainerType::iterator;
87 using ConstArgListsIterator = ContainerType::const_iterator;
88
89 /// The template argument lists, stored from the innermost template
90 /// argument list (first) to the outermost template argument list (last).
91 ContainerType TemplateArgumentLists;
92
93 /// The number of outer levels of template arguments that are not
94 /// being substituted.
95 unsigned NumRetainedOuterLevels = 0;
96
97 /// The kind of substitution described by this argument list.
99
100 public:
101 /// Construct an empty set of template argument lists.
103
104 /// Construct a single-level template argument list.
106 addOuterTemplateArguments(D, Args, Final);
107 }
108
109 void setKind(TemplateSubstitutionKind K) { Kind = K; }
110
111 /// Determine the kind of template substitution being performed.
112 TemplateSubstitutionKind getKind() const { return Kind; }
113
114 /// Determine whether we are rewriting template parameters rather than
115 /// substituting for them. If so, we should not leave references to the
116 /// original template parameters behind.
117 bool isRewrite() const {
119 }
120
121 /// Determine the number of levels in this template argument
122 /// list.
123 unsigned getNumLevels() const {
124 return TemplateArgumentLists.size() + NumRetainedOuterLevels;
125 }
126
127 /// Determine the number of substituted levels in this template
128 /// argument list.
129 unsigned getNumSubstitutedLevels() const {
130 return TemplateArgumentLists.size();
131 }
132
133 // Determine the number of substituted args at 'Depth'.
134 unsigned getNumSubsitutedArgs(unsigned Depth) const {
135 assert(NumRetainedOuterLevels <= Depth && Depth < getNumLevels());
136 return TemplateArgumentLists[getNumLevels() - Depth - 1].Args.size();
137 }
138
139 unsigned getNumRetainedOuterLevels() const {
140 return NumRetainedOuterLevels;
141 }
142
143 /// Determine how many of the \p OldDepth outermost template parameter
144 /// lists would be removed by substituting these arguments.
145 unsigned getNewDepth(unsigned OldDepth) const {
146 if (OldDepth < NumRetainedOuterLevels)
147 return OldDepth;
148 if (OldDepth < getNumLevels())
149 return NumRetainedOuterLevels;
150 return OldDepth - TemplateArgumentLists.size();
151 }
152
153 /// Retrieve the template argument at a given depth and index.
154 const TemplateArgument &operator()(unsigned Depth, unsigned Index) const {
155 assert(NumRetainedOuterLevels <= Depth && Depth < getNumLevels());
156 assert(Index <
157 TemplateArgumentLists[getNumLevels() - Depth - 1].Args.size());
158 return TemplateArgumentLists[getNumLevels() - Depth - 1].Args[Index];
159 }
160
161 /// A template-like entity which owns the whole pattern being substituted.
162 /// This will usually own a set of template parameters, or in some
163 /// cases might even be a template parameter itself.
164 std::pair<Decl *, bool> getAssociatedDecl(unsigned Depth) const {
165 assert(NumRetainedOuterLevels <= Depth && Depth < getNumLevels());
166 auto AD = TemplateArgumentLists[getNumLevels() - Depth - 1]
167 .AssociatedDeclAndFinal;
168 return {AD.getPointer(), AD.getInt()};
169 }
170
171 /// Determine whether there is a non-NULL template argument at the
172 /// given depth and index.
173 ///
174 /// There must exist a template argument list at the given depth.
175 bool hasTemplateArgument(unsigned Depth, unsigned Index) const {
176 assert(Depth < getNumLevels());
177
178 if (Depth < NumRetainedOuterLevels)
179 return false;
180
181 if (Index >=
182 TemplateArgumentLists[getNumLevels() - Depth - 1].Args.size())
183 return false;
184
185 return !(*this)(Depth, Index).isNull();
186 }
187
189 for (ArgumentListLevel ListLevel : TemplateArgumentLists)
190 for (const TemplateArgument &TA : ListLevel.Args)
192 return true;
193 return false;
194 }
195
196 /// Clear out a specific template argument.
197 void setArgument(unsigned Depth, unsigned Index,
198 TemplateArgument Arg) {
199 assert(NumRetainedOuterLevels <= Depth && Depth < getNumLevels());
200 assert(Index <
201 TemplateArgumentLists[getNumLevels() - Depth - 1].Args.size());
202 const_cast<TemplateArgument &>(
203 TemplateArgumentLists[getNumLevels() - Depth - 1].Args[Index]) = Arg;
204 }
205
206 /// Add a new outmost level to the multi-level template argument
207 /// list.
208 /// A 'Final' substitution means that Subst* nodes won't be built
209 /// for the replacements.
210 void addOuterTemplateArguments(Decl *AssociatedDecl, ArgList Args,
211 bool Final) {
212 assert(!NumRetainedOuterLevels &&
213 "substituted args outside retained args?");
215 TemplateArgumentLists.push_back(
216 {{AssociatedDecl ? AssociatedDecl->getCanonicalDecl() : nullptr,
217 Final},
218 Args});
219 }
220
222 assert(!NumRetainedOuterLevels &&
223 "substituted args outside retained args?");
225 TemplateArgumentLists.push_back({{}, Args});
226 }
227
228 void addOuterTemplateArguments(std::nullopt_t) {
229 assert(!NumRetainedOuterLevels &&
230 "substituted args outside retained args?");
231 TemplateArgumentLists.push_back({});
232 }
233
234 /// Replaces the current 'innermost' level with the provided argument list.
235 /// This is useful for type deduction cases where we need to get the entire
236 /// list from the AST, but then add the deduced innermost list.
237 void replaceInnermostTemplateArguments(Decl *AssociatedDecl, ArgList Args) {
238 assert((!TemplateArgumentLists.empty() || NumRetainedOuterLevels) &&
239 "Replacing in an empty list?");
240
241 if (!TemplateArgumentLists.empty()) {
242 assert((TemplateArgumentLists[0].AssociatedDeclAndFinal.getPointer() ||
243 TemplateArgumentLists[0].AssociatedDeclAndFinal.getPointer() ==
244 AssociatedDecl) &&
245 "Trying to change incorrect declaration?");
246 TemplateArgumentLists[0].Args = Args;
247 } else {
248 --NumRetainedOuterLevels;
249 TemplateArgumentLists.push_back(
250 {{AssociatedDecl, /*Final=*/false}, Args});
251 }
252 }
253
254 /// Add an outermost level that we are not substituting. We have no
255 /// arguments at this level, and do not remove it from the depth of inner
256 /// template parameters that we instantiate.
258 ++NumRetainedOuterLevels;
259 }
260 void addOuterRetainedLevels(unsigned Num) {
261 NumRetainedOuterLevels += Num;
262 }
263
264 /// Retrieve the innermost template argument list.
265 const ArgList &getInnermost() const {
266 return TemplateArgumentLists.front().Args;
267 }
268 /// Retrieve the outermost template argument list.
269 const ArgList &getOutermost() const {
270 return TemplateArgumentLists.back().Args;
271 }
272 ArgListsIterator begin() { return TemplateArgumentLists.begin(); }
273 ConstArgListsIterator begin() const {
274 return TemplateArgumentLists.begin();
275 }
276 ArgListsIterator end() { return TemplateArgumentLists.end(); }
277 ConstArgListsIterator end() const { return TemplateArgumentLists.end(); }
278
279 LLVM_DUMP_METHOD void dump() const {
280 LangOptions LO;
281 LO.CPlusPlus = true;
282 LO.Bool = true;
283 PrintingPolicy PP(LO);
284 llvm::errs() << "NumRetainedOuterLevels: " << NumRetainedOuterLevels
285 << "\n";
286 for (unsigned Depth = NumRetainedOuterLevels; Depth < getNumLevels();
287 ++Depth) {
288 llvm::errs() << Depth << ": ";
290 llvm::errs(),
291 TemplateArgumentLists[getNumLevels() - Depth - 1].Args, PP);
292 llvm::errs() << "\n";
293 }
294 }
295 };
296
297 /// The context in which partial ordering of function templates occurs.
298 enum TPOC {
299 /// Partial ordering of function templates for a function call.
301
302 /// Partial ordering of function templates for a call to a
303 /// conversion function.
305
306 /// Partial ordering of function templates in other contexts, e.g.,
307 /// taking the address of a function template or matching a function
308 /// template specialization to a function template.
310 };
311
312 // This is lame but unavoidable in a world without forward
313 // declarations of enums. The alternatives are to either pollute
314 // Sema.h (by including this file) or sacrifice type safety (by
315 // making Sema.h declare things as enums).
317 TPOC Value;
318
319 public:
321
322 operator TPOC() const { return Value; }
323 };
324
325 /// Captures a template argument whose value has been deduced
326 /// via c++ template argument deduction.
328 /// For a non-type template argument, whether the value was
329 /// deduced from an array bound.
330 bool DeducedFromArrayBound = false;
331
332 public:
334
336 bool DeducedFromArrayBound = false)
337 : TemplateArgument(Arg), DeducedFromArrayBound(DeducedFromArrayBound) {}
338
339 /// Construct an integral non-type template argument that
340 /// has been deduced, possibly from an array bound.
342 const llvm::APSInt &Value,
343 QualType ValueType,
344 bool DeducedFromArrayBound)
345 : TemplateArgument(Ctx, Value, ValueType),
346 DeducedFromArrayBound(DeducedFromArrayBound) {}
347
348 /// For a non-type template argument, determine whether the
349 /// template argument was deduced from an array bound.
350 bool wasDeducedFromArrayBound() const { return DeducedFromArrayBound; }
351
352 /// Specify whether the given non-type template argument
353 /// was deduced from an array bound.
354 void setDeducedFromArrayBound(bool Deduced) {
355 DeducedFromArrayBound = Deduced;
356 }
357 };
358
359 /// A stack-allocated class that identifies which local
360 /// variable declaration instantiations are present in this scope.
361 ///
362 /// A new instance of this class type will be created whenever we
363 /// instantiate a new function declaration, which will have its own
364 /// set of parameter declarations.
366 public:
367 /// A set of declarations.
369
370 private:
371 /// Reference to the semantic analysis that is performing
372 /// this template instantiation.
373 Sema &SemaRef;
374
375 using LocalDeclsMap =
376 llvm::SmallDenseMap<const Decl *,
377 llvm::PointerUnion<Decl *, DeclArgumentPack *>, 4>;
378
379 /// A mapping from local declarations that occur
380 /// within a template to their instantiations.
381 ///
382 /// This mapping is used during instantiation to keep track of,
383 /// e.g., function parameter and variable declarations. For example,
384 /// given:
385 ///
386 /// \code
387 /// template<typename T> T add(T x, T y) { return x + y; }
388 /// \endcode
389 ///
390 /// when we instantiate add<int>, we will introduce a mapping from
391 /// the ParmVarDecl for 'x' that occurs in the template to the
392 /// instantiated ParmVarDecl for 'x'.
393 ///
394 /// For a parameter pack, the local instantiation scope may contain a
395 /// set of instantiated parameters. This is stored as a DeclArgumentPack
396 /// pointer.
397 LocalDeclsMap LocalDecls;
398
399 /// The set of argument packs we've allocated.
401
402 /// The outer scope, which contains local variable
403 /// definitions from some other instantiation (that may not be
404 /// relevant to this particular scope).
406
407 /// Whether we have already exited this scope.
408 bool Exited = false;
409
410 /// Whether to combine this scope with the outer scope, such that
411 /// lookup will search our outer scope.
412 bool CombineWithOuterScope;
413
414 /// If non-NULL, the template parameter pack that has been
415 /// partially substituted per C++0x [temp.arg.explicit]p9.
416 NamedDecl *PartiallySubstitutedPack = nullptr;
417
418 /// If \c PartiallySubstitutedPack is non-null, the set of
419 /// explicitly-specified template arguments in that pack.
420 const TemplateArgument *ArgsInPartiallySubstitutedPack;
421
422 /// If \c PartiallySubstitutedPack, the number of
423 /// explicitly-specified template arguments in
424 /// ArgsInPartiallySubstitutedPack.
425 unsigned NumArgsInPartiallySubstitutedPack;
426
427 public:
428 LocalInstantiationScope(Sema &SemaRef, bool CombineWithOuterScope = false)
429 : SemaRef(SemaRef), Outer(SemaRef.CurrentInstantiationScope),
430 CombineWithOuterScope(CombineWithOuterScope) {
431 SemaRef.CurrentInstantiationScope = this;
432 }
433
437
439 Exit();
440 }
441
442 const Sema &getSema() const { return SemaRef; }
443
444 /// Exit this local instantiation scope early.
445 void Exit() {
446 if (Exited)
447 return;
448
449 for (unsigned I = 0, N = ArgumentPacks.size(); I != N; ++I)
450 delete ArgumentPacks[I];
451
452 SemaRef.CurrentInstantiationScope = Outer;
453 Exited = true;
454 }
455
456 /// Clone this scope, and all outer scopes, down to the given
457 /// outermost scope.
459 if (this == Outermost) return this;
460
461 // Save the current scope from SemaRef since the LocalInstantiationScope
462 // will overwrite it on construction
464
465 LocalInstantiationScope *newScope =
466 new LocalInstantiationScope(SemaRef, CombineWithOuterScope);
467
468 newScope->Outer = nullptr;
469 if (Outer)
470 newScope->Outer = Outer->cloneScopes(Outermost);
471
472 newScope->PartiallySubstitutedPack = PartiallySubstitutedPack;
473 newScope->ArgsInPartiallySubstitutedPack = ArgsInPartiallySubstitutedPack;
474 newScope->NumArgsInPartiallySubstitutedPack =
475 NumArgsInPartiallySubstitutedPack;
476
477 for (LocalDeclsMap::iterator I = LocalDecls.begin(), E = LocalDecls.end();
478 I != E; ++I) {
479 const Decl *D = I->first;
480 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored =
481 newScope->LocalDecls[D];
482 if (I->second.is<Decl *>()) {
483 Stored = I->second.get<Decl *>();
484 } else {
485 DeclArgumentPack *OldPack = I->second.get<DeclArgumentPack *>();
486 DeclArgumentPack *NewPack = new DeclArgumentPack(*OldPack);
487 Stored = NewPack;
488 newScope->ArgumentPacks.push_back(NewPack);
489 }
490 }
491 // Restore the saved scope to SemaRef
492 SemaRef.CurrentInstantiationScope = oldScope;
493 return newScope;
494 }
495
496 /// deletes the given scope, and all outer scopes, down to the
497 /// given outermost scope.
499 LocalInstantiationScope *Outermost) {
500 while (Scope && Scope != Outermost) {
501 LocalInstantiationScope *Out = Scope->Outer;
502 delete Scope;
503 Scope = Out;
504 }
505 }
506
507 /// Find the instantiation of the declaration D within the current
508 /// instantiation scope.
509 ///
510 /// \param D The declaration whose instantiation we are searching for.
511 ///
512 /// \returns A pointer to the declaration or argument pack of declarations
513 /// to which the declaration \c D is instantiated, if found. Otherwise,
514 /// returns NULL.
515 llvm::PointerUnion<Decl *, DeclArgumentPack *> *
516 findInstantiationOf(const Decl *D);
517
518 void InstantiatedLocal(const Decl *D, Decl *Inst);
519 void InstantiatedLocalPackArg(const Decl *D, VarDecl *Inst);
520 void MakeInstantiatedLocalArgPack(const Decl *D);
521
522 /// Note that the given parameter pack has been partially substituted
523 /// via explicit specification of template arguments
524 /// (C++0x [temp.arg.explicit]p9).
525 ///
526 /// \param Pack The parameter pack, which will always be a template
527 /// parameter pack.
528 ///
529 /// \param ExplicitArgs The explicitly-specified template arguments provided
530 /// for this parameter pack.
531 ///
532 /// \param NumExplicitArgs The number of explicitly-specified template
533 /// arguments provided for this parameter pack.
535 const TemplateArgument *ExplicitArgs,
536 unsigned NumExplicitArgs);
537
538 /// Reset the partially-substituted pack when it is no longer of
539 /// interest.
541 assert(PartiallySubstitutedPack && "No partially-substituted pack");
542 PartiallySubstitutedPack = nullptr;
543 ArgsInPartiallySubstitutedPack = nullptr;
544 NumArgsInPartiallySubstitutedPack = 0;
545 }
546
547 /// Retrieve the partially-substitued template parameter pack.
548 ///
549 /// If there is no partially-substituted parameter pack, returns NULL.
550 NamedDecl *
551 getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs = nullptr,
552 unsigned *NumExplicitArgs = nullptr) const;
553
554 /// Determine whether D is a pack expansion created in this scope.
555 bool isLocalPackExpansion(const Decl *D);
556 };
557
559 : public DeclVisitor<TemplateDeclInstantiator, Decl *>
560 {
561 Sema &SemaRef;
563 DeclContext *Owner;
564 const MultiLevelTemplateArgumentList &TemplateArgs;
565 Sema::LateInstantiatedAttrVec* LateAttrs = nullptr;
566 LocalInstantiationScope *StartingScope = nullptr;
567 // Whether to evaluate the C++20 constraints or simply substitute into them.
568 bool EvaluateConstraints = true;
569
570 /// A list of out-of-line class template partial
571 /// specializations that will need to be instantiated after the
572 /// enclosing class's instantiation is complete.
573 SmallVector<std::pair<ClassTemplateDecl *,
575 OutOfLinePartialSpecs;
576
577 /// A list of out-of-line variable template partial
578 /// specializations that will need to be instantiated after the
579 /// enclosing variable's instantiation is complete.
580 /// FIXME: Verify that this is needed.
582 std::pair<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>, 4>
583 OutOfLineVarPartialSpecs;
584
585 public:
587 const MultiLevelTemplateArgumentList &TemplateArgs)
588 : SemaRef(SemaRef),
589 SubstIndex(SemaRef, SemaRef.ArgumentPackSubstitutionIndex),
590 Owner(Owner), TemplateArgs(TemplateArgs) {}
591
593 EvaluateConstraints = B;
594 }
596 return EvaluateConstraints;
597 }
598
599// Define all the decl visitors using DeclNodes.inc
600#define DECL(DERIVED, BASE) \
601 Decl *Visit ## DERIVED ## Decl(DERIVED ## Decl *D);
602#define ABSTRACT_DECL(DECL)
603
604// Decls which never appear inside a class or function.
605#define OBJCCONTAINER(DERIVED, BASE)
606#define FILESCOPEASM(DERIVED, BASE)
607#define TOPLEVELSTMT(DERIVED, BASE)
608#define IMPORT(DERIVED, BASE)
609#define EXPORT(DERIVED, BASE)
610#define LINKAGESPEC(DERIVED, BASE)
611#define OBJCCOMPATIBLEALIAS(DERIVED, BASE)
612#define OBJCMETHOD(DERIVED, BASE)
613#define OBJCTYPEPARAM(DERIVED, BASE)
614#define OBJCIVAR(DERIVED, BASE)
615#define OBJCPROPERTY(DERIVED, BASE)
616#define OBJCPROPERTYIMPL(DERIVED, BASE)
617#define EMPTY(DERIVED, BASE)
618#define LIFETIMEEXTENDEDTEMPORARY(DERIVED, BASE)
619
620 // Decls which use special-case instantiation code.
621#define BLOCK(DERIVED, BASE)
622#define CAPTURED(DERIVED, BASE)
623#define IMPLICITPARAM(DERIVED, BASE)
624
625#include "clang/AST/DeclNodes.inc"
626
628
630 TypeSourceInfo *&TInfo,
631 DeclarationNameInfo &NameInfo);
632
633 // A few supplemental visitor functions.
635 TemplateParameterList *TemplateParams,
638 TemplateParameterList *TemplateParams,
640 Decl *VisitDecl(Decl *D);
641 Decl *VisitVarDecl(VarDecl *D, bool InstantiatingVarTemplate,
644 LookupResult *Lookup);
645
646 // Enable late instantiation of attributes. Late instantiated attributes
647 // will be stored in LA.
649 LateAttrs = LA;
650 StartingScope = SemaRef.CurrentInstantiationScope;
651 }
652
653 // Disable late instantiation of attributes.
655 LateAttrs = nullptr;
656 StartingScope = nullptr;
657 }
658
659 LocalInstantiationScope *getStartingScope() const { return StartingScope; }
660
663
666
667 /// Return an iterator to the beginning of the set of
668 /// "delayed" partial specializations, which must be passed to
669 /// InstantiateClassTemplatePartialSpecialization once the class
670 /// definition has been completed.
672 return OutOfLinePartialSpecs.begin();
673 }
674
676 return OutOfLineVarPartialSpecs.begin();
677 }
678
679 /// Return an iterator to the end of the set of
680 /// "delayed" partial specializations, which must be passed to
681 /// InstantiateClassTemplatePartialSpecialization once the class
682 /// definition has been completed.
684 return OutOfLinePartialSpecs.end();
685 }
686
688 return OutOfLineVarPartialSpecs.end();
689 }
690
691 // Helper functions for instantiating methods.
696
698
701
702 bool SubstQualifier(const DeclaratorDecl *OldDecl,
703 DeclaratorDecl *NewDecl);
704 bool SubstQualifier(const TagDecl *OldDecl,
705 TagDecl *NewDecl);
706
708 VarTemplateDecl *VarTemplate, VarDecl *FromVar,
709 const TemplateArgumentListInfo &TemplateArgsInfo,
711 VarTemplateSpecializationDecl *PrevDecl = nullptr);
712
713 Decl *InstantiateTypedefNameDecl(TypedefNameDecl *D, bool IsTypeAlias);
716 ClassTemplateDecl *ClassTemplate,
720 VarTemplateDecl *VarTemplate,
723
724 private:
725 template<typename T>
726 Decl *instantiateUnresolvedUsingDecl(T *D,
727 bool InstantiatingPackElement = false);
728 };
729
730} // namespace clang
731
732#endif // LLVM_CLANG_SEMA_TEMPLATE_H
Defines the C++ template declaration subclasses.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
Represents a C++ declaration that introduces decls from somewhere else.
Definition: DeclCXX.h:3414
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2057
Declaration of a class template.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1437
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:67
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:969
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:770
Captures a template argument whose value has been deduced via c++ template argument deduction.
Definition: Template.h:327
void setDeducedFromArrayBound(bool Deduced)
Specify whether the given non-type template argument was deduced from an array bound.
Definition: Template.h:354
DeducedTemplateArgument(const TemplateArgument &Arg, bool DeducedFromArrayBound=false)
Definition: Template.h:335
DeducedTemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value, QualType ValueType, bool DeducedFromArrayBound)
Construct an integral non-type template argument that has been deduced, possibly from an array bound.
Definition: Template.h:341
bool wasDeducedFromArrayBound() const
For a non-type template argument, determine whether the template argument was deduced from an array b...
Definition: Template.h:350
Represents an enum.
Definition: Decl.h:3868
Represents a function declaration or definition.
Definition: Decl.h:1971
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:454
A stack-allocated class that identifies which local variable declaration instantiations are present i...
Definition: Template.h:365
LocalInstantiationScope & operator=(const LocalInstantiationScope &)=delete
LocalInstantiationScope(const LocalInstantiationScope &)=delete
void SetPartiallySubstitutedPack(NamedDecl *Pack, const TemplateArgument *ExplicitArgs, unsigned NumExplicitArgs)
Note that the given parameter pack has been partially substituted via explicit specification of templ...
NamedDecl * getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs=nullptr, unsigned *NumExplicitArgs=nullptr) const
Retrieve the partially-substitued template parameter pack.
void Exit()
Exit this local instantiation scope early.
Definition: Template.h:445
SmallVector< VarDecl *, 4 > DeclArgumentPack
A set of declarations.
Definition: Template.h:368
bool isLocalPackExpansion(const Decl *D)
Determine whether D is a pack expansion created in this scope.
static void deleteScopes(LocalInstantiationScope *Scope, LocalInstantiationScope *Outermost)
deletes the given scope, and all outer scopes, down to the given outermost scope.
Definition: Template.h:498
const Sema & getSema() const
Definition: Template.h:442
void InstantiatedLocal(const Decl *D, Decl *Inst)
void InstantiatedLocalPackArg(const Decl *D, VarDecl *Inst)
void ResetPartiallySubstitutedPack()
Reset the partially-substituted pack when it is no longer of interest.
Definition: Template.h:540
LocalInstantiationScope(Sema &SemaRef, bool CombineWithOuterScope=false)
Definition: Template.h:428
LocalInstantiationScope * cloneScopes(LocalInstantiationScope *Outermost)
Clone this scope, and all outer scopes, down to the given outermost scope.
Definition: Template.h:458
llvm::PointerUnion< Decl *, DeclArgumentPack * > * findInstantiationOf(const Decl *D)
Find the instantiation of the declaration D within the current instantiation scope.
Represents the results of name lookup.
Definition: Lookup.h:46
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition: Template.h:76
bool hasTemplateArgument(unsigned Depth, unsigned Index) const
Determine whether there is a non-NULL template argument at the given depth and index.
Definition: Template.h:175
ConstArgListsIterator end() const
Definition: Template.h:277
const ArgList & getInnermost() const
Retrieve the innermost template argument list.
Definition: Template.h:265
unsigned getNumSubsitutedArgs(unsigned Depth) const
Definition: Template.h:134
std::pair< Decl *, bool > getAssociatedDecl(unsigned Depth) const
A template-like entity which owns the whole pattern being substituted.
Definition: Template.h:164
void addOuterRetainedLevel()
Add an outermost level that we are not substituting.
Definition: Template.h:257
ConstArgListsIterator begin() const
Definition: Template.h:273
LLVM_DUMP_METHOD void dump() const
Definition: Template.h:279
MultiLevelTemplateArgumentList(Decl *D, ArgList Args, bool Final)
Construct a single-level template argument list.
Definition: Template.h:105
TemplateSubstitutionKind getKind() const
Determine the kind of template substitution being performed.
Definition: Template.h:112
void addOuterTemplateArguments(Decl *AssociatedDecl, ArgList Args, bool Final)
Add a new outmost level to the multi-level template argument list.
Definition: Template.h:210
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
Definition: Template.h:123
void setKind(TemplateSubstitutionKind K)
Definition: Template.h:109
void replaceInnermostTemplateArguments(Decl *AssociatedDecl, ArgList Args)
Replaces the current 'innermost' level with the provided argument list.
Definition: Template.h:237
unsigned getNumSubstitutedLevels() const
Determine the number of substituted levels in this template argument list.
Definition: Template.h:129
const TemplateArgument & operator()(unsigned Depth, unsigned Index) const
Retrieve the template argument at a given depth and index.
Definition: Template.h:154
const ArgList & getOutermost() const
Retrieve the outermost template argument list.
Definition: Template.h:269
void addOuterRetainedLevels(unsigned Num)
Definition: Template.h:260
MultiLevelTemplateArgumentList()=default
Construct an empty set of template argument lists.
unsigned getNumRetainedOuterLevels() const
Definition: Template.h:139
unsigned getNewDepth(unsigned OldDepth) const
Determine how many of the OldDepth outermost template parameter lists would be removed by substitutin...
Definition: Template.h:145
void setArgument(unsigned Depth, unsigned Index, TemplateArgument Arg)
Clear out a specific template argument.
Definition: Template.h:197
void addOuterTemplateArguments(std::nullopt_t)
Definition: Template.h:228
void addOuterTemplateArguments(ArgList Args)
Definition: Template.h:221
bool isRewrite() const
Determine whether we are rewriting template parameters rather than substituting for them.
Definition: Template.h:117
This represents a decl that may have a name.
Definition: Decl.h:249
A (possibly-)qualified type.
Definition: Type.h:738
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:41
RAII object used to change the argument pack substitution index within a Sema object.
Definition: Sema.h:10297
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:457
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
Definition: Sema.h:9779
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3585
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
Represents a template argument.
Definition: TemplateBase.h:61
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
void enableLateAttributeInstantiation(Sema::LateInstantiatedAttrVec *LA)
Definition: Template.h:648
delayed_var_partial_spec_iterator delayed_var_partial_spec_end()
Definition: Template.h:687
delayed_partial_spec_iterator delayed_partial_spec_begin()
Return an iterator to the beginning of the set of "delayed" partial specializations,...
Definition: Template.h:671
void setEvaluateConstraints(bool B)
Definition: Template.h:592
TemplateDeclInstantiator(Sema &SemaRef, DeclContext *Owner, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: Template.h:586
SmallVectorImpl< std::pair< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > >::iterator delayed_var_partial_spec_iterator
Definition: Template.h:665
Decl * VisitVarDecl(VarDecl *D, bool InstantiatingVarTemplate, ArrayRef< BindingDecl * > *Bindings=nullptr)
bool InitMethodInstantiation(CXXMethodDecl *New, CXXMethodDecl *Tmpl)
Initializes common fields of an instantiated method declaration (New) from the corresponding fields o...
LocalInstantiationScope * getStartingScope() const
Definition: Template.h:659
bool InitFunctionInstantiation(FunctionDecl *New, FunctionDecl *Tmpl)
Initializes the common fields of an instantiation function declaration (New) from the corresponding f...
VarTemplatePartialSpecializationDecl * InstantiateVarTemplatePartialSpecialization(VarTemplateDecl *VarTemplate, VarTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a variable template partial specialization.
void adjustForRewrite(RewriteKind RK, FunctionDecl *Orig, QualType &T, TypeSourceInfo *&TInfo, DeclarationNameInfo &NameInfo)
TypeSourceInfo * SubstFunctionType(FunctionDecl *D, SmallVectorImpl< ParmVarDecl * > &Params)
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
Definition: Template.h:662
Decl * VisitVarTemplateSpecializationDecl(VarTemplateDecl *VarTemplate, VarDecl *FromVar, const TemplateArgumentListInfo &TemplateArgsInfo, ArrayRef< TemplateArgument > Converted, VarTemplateSpecializationDecl *PrevDecl=nullptr)
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
Decl * VisitFunctionDecl(FunctionDecl *D, TemplateParameterList *TemplateParams, RewriteKind RK=RewriteKind::None)
Normal class members are of more specific types and therefore don't make it here.
Decl * VisitCXXMethodDecl(CXXMethodDecl *D, TemplateParameterList *TemplateParams, RewriteKind RK=RewriteKind::None)
delayed_partial_spec_iterator delayed_partial_spec_end()
Return an iterator to the end of the set of "delayed" partial specializations, which must be passed t...
Definition: Template.h:683
Decl * VisitBaseUsingDecls(BaseUsingDecl *D, BaseUsingDecl *Inst, LookupResult *Lookup)
bool SubstQualifier(const DeclaratorDecl *OldDecl, DeclaratorDecl *NewDecl)
TemplateParameterList * SubstTemplateParams(TemplateParameterList *List)
Instantiates a nested template parameter list in the current instantiation context.
Decl * InstantiateTypedefNameDecl(TypedefNameDecl *D, bool IsTypeAlias)
delayed_var_partial_spec_iterator delayed_var_partial_spec_begin()
Definition: Template.h:675
ClassTemplatePartialSpecializationDecl * InstantiateClassTemplatePartialSpecialization(ClassTemplateDecl *ClassTemplate, ClassTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a class template partial specialization.
bool SubstDefaultedFunction(FunctionDecl *New, FunctionDecl *Tmpl)
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
A container of type source information.
Definition: Type.h:7120
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3433
Represents a variable declaration or definition.
Definition: Decl.h:918
Declaration of a variable template.
Represents a variable template specialization, which refers to a variable template with a given set o...
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
The JSON file list parser is used to communicate input to InstallAPI.
TemplateSubstitutionKind
The kind of template substitution being performed.
Definition: Template.h:47
@ Rewrite
We are substituting template parameters for (typically) other template parameters in order to rewrite...
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
const FunctionProtoType * T
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy, const TemplateParameterList *TPL=nullptr)
Print a template argument list, including the '<' and '>' enclosing the template arguments.
TPOC
The context in which partial ordering of function templates occurs.
Definition: Template.h:298
@ TPOC_Conversion
Partial ordering of function templates for a call to a conversion function.
Definition: Template.h:304
@ TPOC_Other
Partial ordering of function templates in other contexts, e.g., taking the address of a function temp...
Definition: Template.h:309
@ TPOC_Call
Partial ordering of function templates for a function call.
Definition: Template.h:300
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57