13 #ifndef LLVM_CLANG_SEMA_TEMPLATE_H 14 #define LLVM_CLANG_SEMA_TEMPLATE_H 22 #include "llvm/ADT/ArrayRef.h" 23 #include "llvm/ADT/DenseMap.h" 24 #include "llvm/ADT/PointerUnion.h" 25 #include "llvm/ADT/SmallVector.h" 42 class TypedefNameDecl;
75 unsigned NumRetainedOuterLevels = 0;
90 return TemplateArgumentLists.size() + NumRetainedOuterLevels;
96 return TemplateArgumentLists.size();
101 assert(NumRetainedOuterLevels <= Depth && Depth <
getNumLevels());
102 assert(Index < TemplateArgumentLists[
getNumLevels() - Depth - 1].size());
103 return TemplateArgumentLists[
getNumLevels() - Depth - 1][Index];
113 if (Depth < NumRetainedOuterLevels)
116 if (Index >= TemplateArgumentLists[
getNumLevels() - Depth - 1].size())
119 return !(*this)(
Depth, Index).isNull();
125 assert(NumRetainedOuterLevels <= Depth && Depth <
getNumLevels());
126 assert(Index < TemplateArgumentLists[
getNumLevels() - Depth - 1].size());
128 TemplateArgumentLists[
getNumLevels() - Depth - 1][Index])
136 TemplateArgs->
size()));
142 assert(!NumRetainedOuterLevels &&
143 "substituted args outside retained args?");
144 TemplateArgumentLists.push_back(Args);
151 ++NumRetainedOuterLevels;
156 return TemplateArgumentLists.front();
193 bool DeducedFromArrayBound =
false;
199 bool DeducedFromArrayBound =
false)
205 const llvm::APSInt &
Value,
207 bool DeducedFromArrayBound)
209 DeducedFromArrayBound(DeducedFromArrayBound) {}
218 DeducedFromArrayBound = Deduced;
238 using LocalDeclsMap =
239 llvm::SmallDenseMap<
const Decl *,
240 llvm::PointerUnion<Decl *, DeclArgumentPack *>, 4>;
260 LocalDeclsMap LocalDecls;
275 bool CombineWithOuterScope;
279 NamedDecl *PartiallySubstitutedPack =
nullptr;
288 unsigned NumArgsInPartiallySubstitutedPack;
292 : SemaRef(SemaRef), Outer(SemaRef.CurrentInstantiationScope),
293 CombineWithOuterScope(CombineWithOuterScope) {
312 for (
unsigned I = 0, N = ArgumentPacks.size(); I != N; ++I)
313 delete ArgumentPacks[I];
322 if (
this == Outermost)
return this;
331 newScope->Outer =
nullptr;
335 newScope->PartiallySubstitutedPack = PartiallySubstitutedPack;
336 newScope->ArgsInPartiallySubstitutedPack = ArgsInPartiallySubstitutedPack;
337 newScope->NumArgsInPartiallySubstitutedPack =
338 NumArgsInPartiallySubstitutedPack;
340 for (LocalDeclsMap::iterator I = LocalDecls.begin(), E = LocalDecls.end();
342 const Decl *D = I->first;
343 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored =
344 newScope->LocalDecls[D];
345 if (I->second.is<Decl *>()) {
346 Stored = I->second.get<Decl *>();
351 newScope->ArgumentPacks.push_back(NewPack);
363 while (Scope && Scope != Outermost) {
378 llvm::PointerUnion<Decl *, DeclArgumentPack *> *
381 void InstantiatedLocal(
const Decl *D, Decl *Inst);
382 void InstantiatedLocalPackArg(
const Decl *D,
ParmVarDecl *Inst);
383 void MakeInstantiatedLocalArgPack(
const Decl *D);
397 void SetPartiallySubstitutedPack(
NamedDecl *Pack,
399 unsigned NumExplicitArgs);
404 assert(PartiallySubstitutedPack &&
"No partially-substituted pack");
405 PartiallySubstitutedPack =
nullptr;
406 ArgsInPartiallySubstitutedPack =
nullptr;
407 NumArgsInPartiallySubstitutedPack = 0;
414 getPartiallySubstitutedPack(
const TemplateArgument **ExplicitArgs =
nullptr,
415 unsigned *NumExplicitArgs =
nullptr)
const;
419 :
public DeclVisitor<TemplateDeclInstantiator, Decl *>
433 OutOfLinePartialSpecs;
440 std::pair<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>, 4>
441 OutOfLineVarPartialSpecs;
447 SubstIndex(SemaRef, SemaRef.ArgumentPackSubstitutionIndex),
448 Owner(Owner), TemplateArgs(TemplateArgs) {}
451 #define DECL(DERIVED, BASE) \ 452 Decl *Visit ## DERIVED ## Decl(DERIVED ## Decl *D); 453 #define ABSTRACT_DECL(DECL) 456 #define OBJCCONTAINER(DERIVED, BASE) 457 #define FILESCOPEASM(DERIVED, BASE) 458 #define IMPORT(DERIVED, BASE) 459 #define EXPORT(DERIVED, BASE) 460 #define LINKAGESPEC(DERIVED, BASE) 461 #define OBJCCOMPATIBLEALIAS(DERIVED, BASE) 462 #define OBJCMETHOD(DERIVED, BASE) 463 #define OBJCTYPEPARAM(DERIVED, BASE) 464 #define OBJCIVAR(DERIVED, BASE) 465 #define OBJCPROPERTY(DERIVED, BASE) 466 #define OBJCPROPERTYIMPL(DERIVED, BASE) 467 #define EMPTY(DERIVED, BASE) 470 #define BLOCK(DERIVED, BASE) 471 #define CAPTURED(DERIVED, BASE) 472 #define IMPLICITPARAM(DERIVED, BASE) 474 #include "clang/AST/DeclNodes.inc" 477 Decl *VisitCXXMethodDecl(CXXMethodDecl *D,
478 TemplateParameterList *TemplateParams,
479 bool IsClassScopeSpecialization =
false);
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(
551 ClassTemplatePartialSpecializationDecl *
552 InstantiateClassTemplatePartialSpecialization(
553 ClassTemplateDecl *ClassTemplate,
554 ClassTemplatePartialSpecializationDecl *PartialSpec);
556 InstantiateVarTemplatePartialSpecialization(
563 Decl *instantiateUnresolvedUsingDecl(T *D,
564 bool InstantiatingPackElement =
false);
569 #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
Stores a list of template parameters for a TemplateDecl and its derived classes.
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.
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...