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;
74 unsigned NumRetainedOuterLevels = 0;
89 return TemplateArgumentLists.size() + NumRetainedOuterLevels;
95 return TemplateArgumentLists.size();
100 assert(NumRetainedOuterLevels <= Depth && Depth <
getNumLevels());
101 assert(Index < TemplateArgumentLists[
getNumLevels() - Depth - 1].size());
102 return TemplateArgumentLists[
getNumLevels() - Depth - 1][Index];
112 if (Depth < NumRetainedOuterLevels)
115 if (Index >= TemplateArgumentLists[
getNumLevels() - Depth - 1].size())
118 return !(*this)(
Depth, Index).isNull();
124 assert(NumRetainedOuterLevels <= Depth && Depth <
getNumLevels());
125 assert(Index < TemplateArgumentLists[
getNumLevels() - Depth - 1].size());
127 TemplateArgumentLists[
getNumLevels() - Depth - 1][Index])
135 TemplateArgs->
size()));
141 assert(!NumRetainedOuterLevels &&
142 "substituted args outside retained args?");
143 TemplateArgumentLists.push_back(Args);
150 ++NumRetainedOuterLevels;
155 return TemplateArgumentLists.front();
192 bool DeducedFromArrayBound =
false;
198 bool DeducedFromArrayBound =
false)
204 const llvm::APSInt &
Value,
206 bool DeducedFromArrayBound)
208 DeducedFromArrayBound(DeducedFromArrayBound) {}
217 DeducedFromArrayBound = Deduced;
237 using LocalDeclsMap =
238 llvm::SmallDenseMap<
const Decl *,
239 llvm::PointerUnion<Decl *, DeclArgumentPack *>, 4>;
259 LocalDeclsMap LocalDecls;
274 bool CombineWithOuterScope;
278 NamedDecl *PartiallySubstitutedPack =
nullptr;
287 unsigned NumArgsInPartiallySubstitutedPack;
291 : SemaRef(SemaRef), Outer(SemaRef.CurrentInstantiationScope),
292 CombineWithOuterScope(CombineWithOuterScope) {
311 for (
unsigned I = 0, N = ArgumentPacks.size(); I != N; ++I)
312 delete ArgumentPacks[I];
321 if (
this == Outermost)
return this;
330 newScope->Outer =
nullptr;
334 newScope->PartiallySubstitutedPack = PartiallySubstitutedPack;
335 newScope->ArgsInPartiallySubstitutedPack = ArgsInPartiallySubstitutedPack;
336 newScope->NumArgsInPartiallySubstitutedPack =
337 NumArgsInPartiallySubstitutedPack;
339 for (LocalDeclsMap::iterator I = LocalDecls.begin(), E = LocalDecls.end();
341 const Decl *D = I->first;
342 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored =
343 newScope->LocalDecls[D];
344 if (I->second.is<Decl *>()) {
345 Stored = I->second.get<Decl *>();
350 newScope->ArgumentPacks.push_back(NewPack);
362 while (Scope && Scope != Outermost) {
377 llvm::PointerUnion<Decl *, DeclArgumentPack *> *
380 void InstantiatedLocal(
const Decl *D, Decl *Inst);
381 void InstantiatedLocalPackArg(
const Decl *D,
VarDecl *Inst);
382 void MakeInstantiatedLocalArgPack(
const Decl *D);
396 void SetPartiallySubstitutedPack(
NamedDecl *Pack,
398 unsigned NumExplicitArgs);
403 assert(PartiallySubstitutedPack &&
"No partially-substituted pack");
404 PartiallySubstitutedPack =
nullptr;
405 ArgsInPartiallySubstitutedPack =
nullptr;
406 NumArgsInPartiallySubstitutedPack = 0;
413 getPartiallySubstitutedPack(
const TemplateArgument **ExplicitArgs =
nullptr,
414 unsigned *NumExplicitArgs =
nullptr)
const;
418 :
public DeclVisitor<TemplateDeclInstantiator, Decl *>
432 OutOfLinePartialSpecs;
439 std::pair<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>, 4>
440 OutOfLineVarPartialSpecs;
446 SubstIndex(SemaRef, SemaRef.ArgumentPackSubstitutionIndex),
447 Owner(Owner), TemplateArgs(TemplateArgs) {}
450 #define DECL(DERIVED, BASE) \ 451 Decl *Visit ## DERIVED ## Decl(DERIVED ## Decl *D); 452 #define ABSTRACT_DECL(DECL) 455 #define OBJCCONTAINER(DERIVED, BASE) 456 #define FILESCOPEASM(DERIVED, BASE) 457 #define IMPORT(DERIVED, BASE) 458 #define EXPORT(DERIVED, BASE) 459 #define LINKAGESPEC(DERIVED, BASE) 460 #define OBJCCOMPATIBLEALIAS(DERIVED, BASE) 461 #define OBJCMETHOD(DERIVED, BASE) 462 #define OBJCTYPEPARAM(DERIVED, BASE) 463 #define OBJCIVAR(DERIVED, BASE) 464 #define OBJCPROPERTY(DERIVED, BASE) 465 #define OBJCPROPERTYIMPL(DERIVED, BASE) 466 #define EMPTY(DERIVED, BASE) 469 #define BLOCK(DERIVED, BASE) 470 #define CAPTURED(DERIVED, BASE) 471 #define IMPLICITPARAM(DERIVED, BASE) 473 #include "clang/AST/DeclNodes.inc" 476 Decl *VisitCXXMethodDecl(CXXMethodDecl *D,
477 TemplateParameterList *TemplateParams,
478 Optional<const ASTTemplateArgumentListInfo *>
480 Decl *VisitFunctionDecl(FunctionDecl *D,
481 TemplateParameterList *TemplateParams);
482 Decl *VisitDecl(Decl *D);
483 Decl *VisitVarDecl(VarDecl *D,
bool InstantiatingVarTemplate,
484 ArrayRef<BindingDecl *> *Bindings =
nullptr);
496 StartingScope =
nullptr;
502 ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl *>>::iterator;
512 return OutOfLinePartialSpecs.begin();
516 return OutOfLineVarPartialSpecs.begin();
524 return OutOfLinePartialSpecs.end();
528 return OutOfLineVarPartialSpecs.end();
545 Decl *VisitVarTemplateSpecializationDecl(
552 ClassTemplatePartialSpecializationDecl *
553 InstantiateClassTemplatePartialSpecialization(
554 ClassTemplateDecl *ClassTemplate,
555 ClassTemplatePartialSpecializationDecl *PartialSpec);
557 InstantiateVarTemplatePartialSpecialization(
564 Decl *instantiateUnresolvedUsingDecl(T *D,
565 bool InstantiatingPackElement =
false);
570 #endif // LLVM_CLANG_SEMA_TEMPLATE_H 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...
Represents a function declaration or definition.
delayed_var_partial_spec_iterator delayed_var_partial_spec_begin()
A (possibly-)qualified type.
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.
C Language Family Type Representation.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Decl - This represents one declaration (or definition), e.g.
Defines the C++ template declaration subclasses.
void disableLateAttributeInstantiation()
Declaration of a variable template.
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
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.
LocalInstantiationScope * getStartingScope() const
Represents a variable declaration or definition.
const Sema & getSema() const
Represents a variable template specialization, which refers to a variable template with a given set o...
Stores a list of template parameters for a TemplateDecl and its derived classes.
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.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
void setArgument(unsigned Depth, unsigned Index, TemplateArgument Arg)
Clear out a specific template argument.
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.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Scope - A scope is a transient data structure that is used while parsing the program.
const TemplateArgument * data() const
Retrieve a pointer to the template argument list.
DeducedTemplateArgument(const TemplateArgument &Arg, bool DeducedFromArrayBound=false)
RAII object used to change the argument pack substitution index within a Sema object.
Sema - This implements semantic analysis and AST building for C.
Represents a ValueDecl that came out of a declarator.
unsigned getNumSubstitutedLevels() const
Determine the number of substituted levels in this template argument list.
void addOuterRetainedLevel()
Add an outermost level that we are not substituting.
const ArgList & getInnermost() const
Retrieve the innermost template argument list.
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.
Data structure that captures multiple levels of template argument lists for use in template instantia...
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. ...
const TemplateArgument & operator()(unsigned Depth, unsigned Index) const
Retrieve the template argument at a given depth and index.
void ResetPartiallySubstitutedPack()
Reset the partially-substituted pack when it is no longer of interest.
Represents the declaration of a struct/union/class/enum.
Represents a static or instance method of a struct/union/class.
MultiLevelTemplateArgumentList()=default
Construct an empty set of template argument lists.
A simple visitor class that helps create declaration visitors.
bool hasTemplateArgument(unsigned Depth, unsigned Index) const
Determine whether there is a non-NULL template argument at the given depth and index.
~LocalInstantiationScope()
Base class for declarations which introduce a typedef-name.
Represents a template argument.
Dataflow Directional Tag Classes.
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...
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...
static NamedDecl * findInstantiationOf(ASTContext &Ctx, NamedDecl *D, ForwardIterator first, ForwardIterator last)
MultiLevelTemplateArgumentList(const TemplateArgumentList &TemplateArgs)
Construct a single-level template argument list.
bool wasDeducedFromArrayBound() const
For a non-type template argument, determine whether the template argument was deduced from an array b...
void addOuterTemplateArguments(ArgList Args)
Add a new outmost level to the multi-level template argument list.
LocalInstantiationScope(Sema &SemaRef, bool CombineWithOuterScope=false)
static bool SubstQualifier(Sema &SemaRef, const DeclT *OldDecl, DeclT *NewDecl, const MultiLevelTemplateArgumentList &TemplateArgs)
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
SmallVectorImpl< std::pair< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > >::iterator delayed_var_partial_spec_iterator
A template argument list.
void enableLateAttributeInstantiation(Sema::LateInstantiatedAttrVec *LA)
TPOC
The context in which partial ordering of function templates occurs.
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
Declaration of a class template.
Partial ordering of function templates for a function call.
TemplatePartialOrderingContext(TPOC Value)
This represents a decl that may have a name.
Partial ordering of function templates in other contexts, e.g., taking the address of a function temp...