Go to the documentation of this file.
12 #ifndef LLVM_CLANG_SEMA_TEMPLATE_H
13 #define LLVM_CLANG_SEMA_TEMPLATE_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"
41 class TypedefNameDecl;
85 unsigned NumRetainedOuterLevels = 0;
115 return TemplateArgumentLists.size() + NumRetainedOuterLevels;
121 return TemplateArgumentLists.size();
125 return NumRetainedOuterLevels;
131 if (OldDepth < NumRetainedOuterLevels)
134 return NumRetainedOuterLevels;
135 return OldDepth - TemplateArgumentLists.size();
152 if (
Depth < NumRetainedOuterLevels)
158 return !(*this)(
Depth, Index).isNull();
175 TemplateArgs->
size()));
181 assert(!NumRetainedOuterLevels &&
182 "substituted args outside retained args?");
183 TemplateArgumentLists.push_back(Args);
190 ++NumRetainedOuterLevels;
193 NumRetainedOuterLevels += Num;
198 return TemplateArgumentLists.front();
235 bool DeducedFromArrayBound =
false;
241 bool DeducedFromArrayBound =
false)
249 bool DeducedFromArrayBound)
251 DeducedFromArrayBound(DeducedFromArrayBound) {}
260 DeducedFromArrayBound = Deduced;
280 using LocalDeclsMap =
281 llvm::SmallDenseMap<
const Decl *,
282 llvm::PointerUnion<Decl *, DeclArgumentPack *>, 4>;
302 LocalDeclsMap LocalDecls;
317 bool CombineWithOuterScope;
321 NamedDecl *PartiallySubstitutedPack =
nullptr;
330 unsigned NumArgsInPartiallySubstitutedPack;
334 : SemaRef(SemaRef), Outer(SemaRef.CurrentInstantiationScope),
335 CombineWithOuterScope(CombineWithOuterScope) {
354 for (
unsigned I = 0, N = ArgumentPacks.size(); I != N; ++I)
355 delete ArgumentPacks[I];
364 if (
this == Outermost)
return this;
373 newScope->Outer =
nullptr;
377 newScope->PartiallySubstitutedPack = PartiallySubstitutedPack;
378 newScope->ArgsInPartiallySubstitutedPack = ArgsInPartiallySubstitutedPack;
379 newScope->NumArgsInPartiallySubstitutedPack =
380 NumArgsInPartiallySubstitutedPack;
382 for (LocalDeclsMap::iterator I = LocalDecls.begin(), E = LocalDecls.end();
384 const Decl *D = I->first;
385 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored =
386 newScope->LocalDecls[D];
387 if (I->second.is<
Decl *>()) {
388 Stored = I->second.get<
Decl *>();
393 newScope->ArgumentPacks.push_back(NewPack);
420 llvm::PointerUnion<Decl *, DeclArgumentPack *> *
441 unsigned NumExplicitArgs);
446 assert(PartiallySubstitutedPack &&
"No partially-substituted pack");
447 PartiallySubstitutedPack =
nullptr;
448 ArgsInPartiallySubstitutedPack =
nullptr;
449 NumArgsInPartiallySubstitutedPack = 0;
457 unsigned *NumExplicitArgs =
nullptr)
const;
464 :
public DeclVisitor<TemplateDeclInstantiator, Decl *>
478 OutOfLinePartialSpecs;
485 std::pair<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>, 4>
486 OutOfLineVarPartialSpecs;
492 SubstIndex(SemaRef, SemaRef.ArgumentPackSubstitutionIndex),
493 Owner(Owner), TemplateArgs(TemplateArgs) {}
496 #define DECL(DERIVED, BASE) \
497 Decl *Visit ## DERIVED ## Decl(DERIVED ## Decl *D);
498 #define ABSTRACT_DECL(DECL)
501 #define OBJCCONTAINER(DERIVED, BASE)
502 #define FILESCOPEASM(DERIVED, BASE)
503 #define IMPORT(DERIVED, BASE)
504 #define EXPORT(DERIVED, BASE)
505 #define LINKAGESPEC(DERIVED, BASE)
506 #define OBJCCOMPATIBLEALIAS(DERIVED, BASE)
507 #define OBJCMETHOD(DERIVED, BASE)
508 #define OBJCTYPEPARAM(DERIVED, BASE)
509 #define OBJCIVAR(DERIVED, BASE)
510 #define OBJCPROPERTY(DERIVED, BASE)
511 #define OBJCPROPERTYIMPL(DERIVED, BASE)
512 #define EMPTY(DERIVED, BASE)
513 #define LIFETIMEEXTENDEDTEMPORARY(DERIVED, BASE)
516 #define BLOCK(DERIVED, BASE)
517 #define CAPTURED(DERIVED, BASE)
518 #define IMPLICITPARAM(DERIVED, BASE)
520 #include "clang/AST/DeclNodes.inc"
532 ClassScopeSpecializationArgs = llvm::None,
553 StartingScope =
nullptr;
569 return OutOfLinePartialSpecs.begin();
573 return OutOfLineVarPartialSpecs.begin();
581 return OutOfLinePartialSpecs.end();
585 return OutOfLineVarPartialSpecs.end();
623 Decl *instantiateUnresolvedUsingDecl(T *D,
624 bool InstantiatingPackElement =
false);
629 #endif // LLVM_CLANG_SEMA_TEMPLATE_H
void setArgument(unsigned Depth, unsigned Index, TemplateArgument Arg)
Clear out a specific template argument.
Decl * VisitVarTemplateSpecializationDecl(VarTemplateDecl *VarTemplate, VarDecl *FromVar, const TemplateArgumentListInfo &TemplateArgsInfo, ArrayRef< TemplateArgument > Converted, VarTemplateSpecializationDecl *PrevDecl=nullptr)
delayed_var_partial_spec_iterator delayed_var_partial_spec_begin()
void addOuterTemplateArguments(ArgList Args)
Add a new outmost level to the multi-level template argument list.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
@ TPOC_Conversion
Partial ordering of function templates for a call to a conversion function.
This represents a decl that may have a name.
A (possibly-)qualified type.
TemplateSubstitutionKind getKind() const
Determine the kind of template substitution being performed.
TemplateParameterList * SubstTemplateParams(TemplateParameterList *List)
Instantiates a nested template parameter list in the current instantiation context.
@ Rewrite
We are substituting template parameters for (typically) other template parameters in order to rewrite...
Represents the results of name lookup.
SmallVectorImpl< std::pair< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > >::iterator delayed_var_partial_spec_iterator
DeducedTemplateArgument(const TemplateArgument &Arg, bool DeducedFromArrayBound=false)
@ RewriteSpaceshipAsEqualEqual
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
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.
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...
Captures a template argument whose value has been deduced via c++ template argument deduction.
static void deleteScopes(LocalInstantiationScope *Scope, LocalInstantiationScope *Outermost)
deletes the given scope, and all outer scopes, down to the given outermost scope.
void disableLateAttributeInstantiation()
Represents a variable template specialization, which refers to a variable template with a given set o...
@ TPOC_Other
Partial ordering of function templates in other contexts, e.g., taking the address of a function temp...
const TemplateArgument * data() const
Retrieve a pointer to the template argument list.
MultiLevelTemplateArgumentList(const TemplateArgumentList &TemplateArgs)
Construct a single-level template argument list.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
bool SubstDefaultedFunction(FunctionDecl *New, FunctionDecl *Tmpl)
A convenient class for passing around template argument information.
RAII object used to change the argument pack substitution index within a Sema object.
Scope - A scope is a transient data structure that is used while parsing the program.
void adjustForRewrite(RewriteKind RK, FunctionDecl *Orig, QualType &T, TypeSourceInfo *&TInfo, DeclarationNameInfo &NameInfo)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
void Exit()
Exit this local instantiation scope early.
void setDeducedFromArrayBound(bool Deduced)
Specify whether the given non-type template argument was deduced from an array bound.
Represents a template argument.
Data structure that captures multiple levels of template argument lists for use in template instantia...
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.
Represents a variable declaration or definition.
Represents the declaration of a struct/union/class/enum.
Stores a list of template parameters for a TemplateDecl and its derived classes.
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
bool wasDeducedFromArrayBound() const
For a non-type template argument, determine whether the template argument was deduced from an array b...
Decl * VisitBaseUsingDecls(BaseUsingDecl *D, BaseUsingDecl *Inst, LookupResult *Lookup)
SmallVector< VarDecl *, 4 > DeclArgumentPack
A set of declarations.
unsigned getNumRetainedOuterLevels() const
~LocalInstantiationScope()
Decl * InstantiateTypedefNameDecl(TypedefNameDecl *D, bool IsTypeAlias)
delayed_var_partial_spec_iterator delayed_var_partial_spec_end()
delayed_partial_spec_iterator delayed_partial_spec_begin()
Return an iterator to the beginning of the set of "delayed" partial specializations,...
Decl * VisitCXXMethodDecl(CXXMethodDecl *D, TemplateParameterList *TemplateParams, Optional< const ASTTemplateArgumentListInfo * > ClassScopeSpecializationArgs=llvm::None, RewriteKind RK=RewriteKind::None)
bool SubstQualifier(const DeclaratorDecl *OldDecl, DeclaratorDecl *NewDecl)
NamedDecl * getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs=nullptr, unsigned *NumExplicitArgs=nullptr) const
Retrieve the partially-substitued template parameter pack.
LocalInstantiationScope * cloneScopes(LocalInstantiationScope *Outermost)
Clone this scope, and all outer scopes, down to the given outermost scope.
bool hasTemplateArgument(unsigned Depth, unsigned Index) const
Determine whether there is a non-NULL template argument at the given depth and index.
Declaration of a class template.
const Sema & getSema() const
TemplateSubstitutionKind
The kind of template substitution being performed.
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
LocalInstantiationScope & operator=(const LocalInstantiationScope &)=delete
Decl - This represents one declaration (or definition), e.g.
Represents a ValueDecl that came out of a declarator.
const ArgList & getInnermost() const
Retrieve the innermost template argument list.
Sema - This implements semantic analysis and AST building for C.
Decl * VisitDecl(Decl *D)
A template argument list.
bool InitMethodInstantiation(CXXMethodDecl *New, CXXMethodDecl *Tmpl)
Initializes common fields of an instantiated method declaration (New) from the corresponding fields o...
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
bool InitFunctionInstantiation(FunctionDecl *New, FunctionDecl *Tmpl)
Initializes the common fields of an instantiation function declaration (New) from the corresponding f...
DeducedTemplateArgument()=default
unsigned getNewDepth(unsigned OldDepth) const
Determine how many of the OldDepth outermost template parameter lists would be removed by substitutin...
void addOuterRetainedLevels(unsigned Num)
void setKind(TemplateSubstitutionKind K)
void SetPartiallySubstitutedPack(NamedDecl *Pack, const TemplateArgument *ExplicitArgs, unsigned NumExplicitArgs)
Note that the given parameter pack has been partially substituted via explicit specification of templ...
unsigned getNumSubstitutedLevels() const
Determine the number of substituted levels in this template argument list.
TPOC
The context in which partial ordering of function templates occurs.
const TemplateArgument & operator()(unsigned Depth, unsigned Index) const
Retrieve the template argument at a given depth and index.
TemplateDeclInstantiator(Sema &SemaRef, DeclContext *Owner, const MultiLevelTemplateArgumentList &TemplateArgs)
LocalInstantiationScope(Sema &SemaRef, bool CombineWithOuterScope=false)
A simple visitor class that helps create declaration visitors.
@ TPOC_Call
Partial ordering of function templates for a function call.
A container of type source information.
VarTemplatePartialSpecializationDecl * InstantiateVarTemplatePartialSpecialization(VarTemplateDecl *VarTemplate, VarTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a variable template partial specialization.
A stack-allocated class that identifies which local variable declaration instantiations are present i...
void ResetPartiallySubstitutedPack()
Reset the partially-substituted pack when it is no longer of interest.
void InstantiatedLocalPackArg(const Decl *D, VarDecl *Inst)
Base class for declarations which introduce a typedef-name.
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
TemplatePartialOrderingContext(TPOC Value)
ClassTemplatePartialSpecializationDecl * InstantiateClassTemplatePartialSpecialization(ClassTemplateDecl *ClassTemplate, ClassTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a class template partial specialization.
TypeSourceInfo * SubstFunctionType(FunctionDecl *D, SmallVectorImpl< ParmVarDecl * > &Params)
MultiLevelTemplateArgumentList()=default
Construct an empty set of template argument lists.
bool isRewrite() const
Determine whether we are rewriting template parameters rather than substituting for them.
LocalInstantiationScope * getStartingScope() const
Declaration of a variable template.
Represents a C++ declaration that introduces decls from somewhere else.
void addOuterRetainedLevel()
Add an outermost level that we are not substituting.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
bool isLocalPackExpansion(const Decl *D)
Determine whether D is a pack expansion created in this scope.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Represents a function declaration or definition.
void MakeInstantiatedLocalArgPack(const Decl *D)
llvm::PointerUnion< Decl *, DeclArgumentPack * > * findInstantiationOf(const Decl *D)
Find the instantiation of the declaration D within the current instantiation scope.
Represents a static or instance method of a struct/union/class.
Decl * VisitVarDecl(VarDecl *D, bool InstantiatingVarTemplate, ArrayRef< BindingDecl * > *Bindings=nullptr)
void addOuterTemplateArguments(const TemplateArgumentList *TemplateArgs)
Add a new outermost level to the multi-level template argument list.
void enableLateAttributeInstantiation(Sema::LateInstantiatedAttrVec *LA)
void InstantiatedLocal(const Decl *D, Decl *Inst)