12 #ifndef LLVM_CLANG_SEMA_TEMPLATE_H
13 #define LLVM_CLANG_SEMA_TEMPLATE_H
18 #include "llvm/ADT/SmallVector.h"
52 unsigned NumRetainedOuterLevels = 0;
67 return TemplateArgumentLists.size() + NumRetainedOuterLevels;
73 return TemplateArgumentLists.size();
78 assert(NumRetainedOuterLevels <= Depth && Depth <
getNumLevels());
79 assert(Index < TemplateArgumentLists[
getNumLevels() - Depth - 1].size());
80 return TemplateArgumentLists[
getNumLevels() - Depth - 1][Index];
90 if (Depth < NumRetainedOuterLevels)
93 if (Index >= TemplateArgumentLists[
getNumLevels() - Depth - 1].size())
96 return !(*this)(
Depth, Index).isNull();
102 assert(NumRetainedOuterLevels <= Depth && Depth <
getNumLevels());
103 assert(Index < TemplateArgumentLists[
getNumLevels() - Depth - 1].size());
105 TemplateArgumentLists[
getNumLevels() - Depth - 1][Index])
113 TemplateArgs->
size()));
119 assert(!NumRetainedOuterLevels &&
120 "substituted args outside retained args?");
121 TemplateArgumentLists.push_back(Args);
128 ++NumRetainedOuterLevels;
133 return TemplateArgumentLists.front();
166 bool DeducedFromArrayBound;
173 bool DeducedFromArrayBound =
false)
179 const llvm::APSInt &
Value,
181 bool DeducedFromArrayBound)
183 DeducedFromArrayBound(DeducedFromArrayBound) { }
192 DeducedFromArrayBound = Deduced;
212 typedef llvm::SmallDenseMap<
213 const Decl *, llvm::PointerUnion<Decl *, DeclArgumentPack *>, 4>
234 LocalDeclsMap LocalDecls;
249 bool CombineWithOuterScope;
262 unsigned NumArgsInPartiallySubstitutedPack;
271 : SemaRef(SemaRef), Outer(SemaRef.CurrentInstantiationScope),
272 Exited(
false), CombineWithOuterScope(CombineWithOuterScope),
273 PartiallySubstitutedPack(nullptr)
289 for (
unsigned I = 0, N = ArgumentPacks.size();
I != N; ++
I)
290 delete ArgumentPacks[
I];
299 if (
this == Outermost)
return this;
308 newScope->Outer =
nullptr;
312 newScope->PartiallySubstitutedPack = PartiallySubstitutedPack;
313 newScope->ArgsInPartiallySubstitutedPack = ArgsInPartiallySubstitutedPack;
314 newScope->NumArgsInPartiallySubstitutedPack =
315 NumArgsInPartiallySubstitutedPack;
317 for (LocalDeclsMap::iterator
I = LocalDecls.begin(),
E = LocalDecls.end();
319 const Decl *D =
I->first;
320 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored =
321 newScope->LocalDecls[D];
322 if (
I->second.is<
Decl *>()) {
323 Stored =
I->second.get<
Decl *>();
328 newScope->ArgumentPacks.push_back(NewPack);
340 while (Scope && Scope != Outermost) {
355 llvm::PointerUnion<Decl *, DeclArgumentPack *> *
376 unsigned NumExplicitArgs);
381 assert(PartiallySubstitutedPack &&
"No partially-substituted pack");
382 PartiallySubstitutedPack =
nullptr;
383 ArgsInPartiallySubstitutedPack =
nullptr;
384 NumArgsInPartiallySubstitutedPack = 0;
392 unsigned *NumExplicitArgs =
nullptr)
const;
396 :
public DeclVisitor<TemplateDeclInstantiator, Decl *>
410 OutOfLinePartialSpecs;
417 std::pair<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>, 4>
418 OutOfLineVarPartialSpecs;
424 SubstIndex(SemaRef, SemaRef.ArgumentPackSubstitutionIndex),
425 Owner(Owner), TemplateArgs(TemplateArgs), LateAttrs(nullptr),
426 StartingScope(nullptr) {}
429 #define DECL(DERIVED, BASE) \
430 Decl *Visit ## DERIVED ## Decl(DERIVED ## Decl *D);
431 #define ABSTRACT_DECL(DECL)
434 #define OBJCCONTAINER(DERIVED, BASE)
435 #define FILESCOPEASM(DERIVED, BASE)
436 #define IMPORT(DERIVED, BASE)
437 #define EXPORT(DERIVED, BASE)
438 #define LINKAGESPEC(DERIVED, BASE)
439 #define OBJCCOMPATIBLEALIAS(DERIVED, BASE)
440 #define OBJCMETHOD(DERIVED, BASE)
441 #define OBJCTYPEPARAM(DERIVED, BASE)
442 #define OBJCIVAR(DERIVED, BASE)
443 #define OBJCPROPERTY(DERIVED, BASE)
444 #define OBJCPROPERTYIMPL(DERIVED, BASE)
445 #define EMPTY(DERIVED, BASE)
448 #define BLOCK(DERIVED, BASE)
449 #define CAPTURED(DERIVED, BASE)
450 #define IMPLICITPARAM(DERIVED, BASE)
452 #include "clang/AST/DeclNodes.inc"
456 TemplateParameterList *TemplateParams,
457 bool IsClassScopeSpecialization =
false);
459 TemplateParameterList *TemplateParams);
461 Decl *
VisitVarDecl(VarDecl *D,
bool InstantiatingVarTemplate,
462 ArrayRef<BindingDecl *> *Bindings =
nullptr);
474 StartingScope =
nullptr;
494 return OutOfLinePartialSpecs.begin();
498 return OutOfLineVarPartialSpecs.begin();
506 return OutOfLinePartialSpecs.end();
510 return OutOfLineVarPartialSpecs.end();
545 Decl *instantiateUnresolvedUsingDecl(T *D,
546 bool InstantiatingPackElement =
false);
550 #endif // LLVM_CLANG_SEMA_TEMPLATE_H
MultiLevelTemplateArgumentList()
Construct an empty set of template argument lists.
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...
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
delayed_var_partial_spec_iterator delayed_var_partial_spec_begin()
A (possibly-)qualified type.
void InstantiatedLocal(const Decl *D, Decl *Inst)
A stack-allocated class that identifies which local variable declaration instantiations are present i...
void addOuterTemplateArguments(const TemplateArgumentList *TemplateArgs)
Add a new outermost level to the multi-level template argument list.
bool hasTemplateArgument(unsigned Depth, unsigned Index) const
Determine whether there is a non-NULL template argument at the given depth and index.
Decl - This represents one declaration (or definition), e.g.
llvm::PointerUnion< Decl *, DeclArgumentPack * > * findInstantiationOf(const Decl *D)
Find the instantiation of the declaration D within the current instantiation scope.
Defines the C++ template declaration subclasses.
Decl * InstantiateTypedefNameDecl(TypedefNameDecl *D, bool IsTypeAlias)
void disableLateAttributeInstantiation()
Declaration of a variable template.
A container of type source information.
TemplateDeclInstantiator(Sema &SemaRef, DeclContext *Owner, const MultiLevelTemplateArgumentList &TemplateArgs)
Partial ordering of function templates for a call to a conversion function.
VarTemplatePartialSpecializationDecl * InstantiateVarTemplatePartialSpecialization(VarTemplateDecl *VarTemplate, VarTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a variable template partial specialization.
void SetPartiallySubstitutedPack(NamedDecl *Pack, const TemplateArgument *ExplicitArgs, unsigned NumExplicitArgs)
Note that the given parameter pack has been partially substituted via explicit specification of templ...
void InstantiatedLocalPackArg(const Decl *D, ParmVarDecl *Inst)
VarDecl - An instance of this class is created to represent a variable declaration or definition...
bool SubstQualifier(const DeclaratorDecl *OldDecl, DeclaratorDecl *NewDecl)
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
Stores a list of template parameters for a TemplateDecl and its derived classes.
ParmVarDecl - Represents a parameter to a function.
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
void setDeducedFromArrayBound(bool Deduced)
Specify whether the given non-type template argument was deduced from an array bound.
bool wasDeducedFromArrayBound() const
For a non-type template argument, determine whether the template argument was deduced from an array b...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SmallVector< ParmVarDecl *, 4 > DeclArgumentPack
A set of declarations.
void setArgument(unsigned Depth, unsigned Index, TemplateArgument Arg)
Clear out a specific template argument.
Decl * VisitVarTemplateSpecializationDecl(VarTemplateDecl *VarTemplate, VarDecl *FromVar, void *InsertPos, const TemplateArgumentListInfo &TemplateArgsInfo, ArrayRef< TemplateArgument > Converted)
unsigned size() const
Retrieve the number of template arguments in this template argument list.
void Exit()
Exit this local instantiation scope early.
delayed_var_partial_spec_iterator delayed_var_partial_spec_end()
A convenient class for passing around template argument information.
bool InitFunctionInstantiation(FunctionDecl *New, FunctionDecl *Tmpl)
Initializes the common fields of an instantiation function declaration (New) from the corresponding f...
const TemplateArgument & operator()(unsigned Depth, unsigned Index) const
Retrieve the template argument at a given depth and index.
Scope - A scope is a transient data structure that is used while parsing the program.
DeducedTemplateArgument(const TemplateArgument &Arg, bool DeducedFromArrayBound=false)
detail::InMemoryDirectory::const_iterator I
RAII object used to change the argument pack substitution index within a Sema object.
void MakeInstantiatedLocalArgPack(const Decl *D)
Sema - This implements semantic analysis and AST building for C.
Represents a ValueDecl that came out of a declarator.
void addOuterRetainedLevel()
Add an outermost level that we are not substituting.
Decl * VisitVarDecl(VarDecl *D, bool InstantiatingVarTemplate, ArrayRef< BindingDecl * > *Bindings=nullptr)
delayed_partial_spec_iterator delayed_partial_spec_begin()
Return an iterator to the beginning of the set of "delayed" partial specializations, which must be passed to InstantiateClassTemplatePartialSpecialization once the class definition has been completed.
ClassTemplatePartialSpecializationDecl * InstantiateClassTemplatePartialSpecialization(ClassTemplateDecl *ClassTemplate, ClassTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a class template partial specialization.
unsigned getNumSubstitutedLevels() const
Determine the number of substituted levels in this template argument list.
const TemplateArgument * data() const
Retrieve a pointer to the template argument list.
Data structure that captures multiple levels of template argument lists for use in template instantia...
const Sema & getSema() const
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 otuer scopes, down to the given outermost scope. ...
void ResetPartiallySubstitutedPack()
Reset the partially-substituted pack when it is no longer of interest.
NamedDecl * getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs=nullptr, unsigned *NumExplicitArgs=nullptr) const
Retrieve the partially-substitued template parameter pack.
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
SmallVectorImpl< std::pair< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > >::iterator delayed_var_partial_spec_iterator
TagDecl - Represents the declaration of a struct/union/class/enum.
TemplateParameterList * SubstTemplateParams(TemplateParameterList *List)
Instantiates a nested template parameter list in the current instantiation context.
Represents a static or instance method of a struct/union/class.
Decl * VisitDecl(Decl *D)
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
A simple visitor class that helps create declaration visitors.
const ArgList & getInnermost() const
Retrieve the innermost template argument list.
~LocalInstantiationScope()
Base class for declarations which introduce a typedef-name.
Represents a template argument.
Decl * VisitFunctionDecl(FunctionDecl *D, TemplateParameterList *TemplateParams)
Normal class members are of more specific types and therefore don't make it here. ...
LocalInstantiationScope * cloneScopes(LocalInstantiationScope *Outermost)
Clone this scope, and all outer scopes, down to the given outermost scope.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
LocalInstantiationScope * getStartingScope() const
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...
EnumDecl - Represents an enum.
detail::InMemoryDirectory::const_iterator E
MultiLevelTemplateArgumentList(const TemplateArgumentList &TemplateArgs)
Construct a single-level template argument list.
void addOuterTemplateArguments(ArgList Args)
Add a new outmost level to the multi-level template argument list.
TypeSourceInfo * SubstFunctionType(FunctionDecl *D, SmallVectorImpl< ParmVarDecl * > &Params)
LocalInstantiationScope(Sema &SemaRef, bool CombineWithOuterScope=false)
A template argument list.
DeducedTemplateArgument()
void enableLateAttributeInstantiation(Sema::LateInstantiatedAttrVec *LA)
TPOC
The context in which partial ordering of function templates occurs.
Declaration of a class template.
Partial ordering of function templates for a function call.
TemplatePartialOrderingContext(TPOC Value)
NamedDecl - This represents a decl with a name.
Partial ordering of function templates in other contexts, e.g., taking the address of a function temp...
bool InitMethodInstantiation(CXXMethodDecl *New, CXXMethodDecl *Tmpl)
Initializes common fields of an instantiated method declaration (New) from the corresponding fields o...
Decl * VisitCXXMethodDecl(CXXMethodDecl *D, TemplateParameterList *TemplateParams, bool IsClassScopeSpecialization=false)