TemplateInstance

https://dlang.org/spec/template.html#explicit_tmp_instantiation

Given: foo!(args) => name = foo tiargs = args

extern (C++)
class TemplateInstance : ScopeDsymbol {
Identifier name;
Objects* tiargs;
Objects tdtypes;
Modules importedModules;
Dsymbol tempdecl;
Dsymbol enclosing;
Dsymbol aliasdecl;
TemplateInstance inst;
ScopeDsymbol argsym;
int inuse;
int nest;
bool semantictiargsdone;
bool havetempdecl;
bool gagged;
size_t hash;
Expressions* fargs;
TemplateInstances* deferred;
Module memberOf;
TemplateInstance tinst;
TemplateInstance tnext;
Module minst;
}

Constructors

this
this(const ref Loc loc, TemplateDeclaration td, Objects* tiargs)

This constructor is only called when we figured out which function template to instantiate.

Members

Functions

appendToModuleMember
Dsymbols* appendToModuleMember()

Append 'this' to the specific module members[]

declareParameters
void declareParameters(Scope* sc)

Declare parameters of template instance, initialize them with the template instance arguments.

equalsx
bool equalsx(TemplateInstance ti)

Compare proposed template instantiation with existing template instantiation. Note that this is not commutative because of the auto ref check.

findTempDecl
bool findTempDecl(Scope* sc, WithScopeSymbol* pwithsym)

Find template declaration corresponding to template instance.

genIdent
Identifier genIdent(Objects* args)

This instance needs an identifier for name mangling purposes. Create one by taking the template declaration name and adding the type signature for it.

getIdent
Identifier getIdent()

Lazily generate identifier for template instance. This is because 75% of the ident's are never needed.

hasNestedArgs
bool hasNestedArgs(Objects* args, bool isstatic)

Determines if a TemplateInstance will need a nested generation of the TemplateDeclaration. Sets enclosing property if so, and returns != 0;

needsCodegen
bool needsCodegen()

Returns true if this is not instantiated in non-root module, and is a part of non-speculative instantiatiation.

needsTypeInference
bool needsTypeInference(Scope* sc, int flag = 0)

Determine if template instance is really a template function, and that template function needs to infer types from the function arguments.

printInstantiationTrace
void printInstantiationTrace()

Given an error instantiating the TemplateInstance, give the nested TemplateInstance instantiations that got us here. Those are a list threaded into the nested scopes.

semanticTiargs
bool semanticTiargs(Scope* sc)

Run semantic on the elements of tiargs. Input: sc

updateTempDecl
bool updateTempDecl(Scope* sc, Dsymbol s)

Confirm s is a valid template, then store it. Input: sc s candidate symbol of template. It may be: TemplateDeclaration FuncDeclaration with findTemplateDeclRoot() != NULL OverloadSet which contains candidates

Static functions

semanticTiargs
bool semanticTiargs(const ref Loc loc, Scope* sc, Objects* tiargs, int flags)

Run semantic of tiargs as arguments of template. Input: loc sc tiargs array of template arguments flags 1: replace const variables with their initializers 2: don't devolve Parameter to Type

Inherited Members

From ScopeDsymbol

search
Dsymbol search(const ref Loc loc, Identifier ident, int flags = SearchLocalsOnly)

This function is #1 on the list of functions that eat cpu time. Be very, very careful about slowing it down.

findGetMembers
FuncDeclaration findGetMembers()

Look for member of the form: const(MemberInfo)[] getMembers(string); Returns NULL if not found

symtabLookup
Dsymbol symtabLookup(Dsymbol s, Identifier id)

Look up identifier in symbol table.

hasStaticCtorOrDtor
bool hasStaticCtorOrDtor()

Return true if any of the members are static ctors or static dtors, or if any members have members that are.

_foreach
int _foreach(Scope* sc, Dsymbols* members, scope ForeachDg dg, size_t* pn = null)

Expands attribute declarations in members in depth first order. Calls dg(size_t symidx, Dsymbol *sym) for each member. If dg returns !=0, stops and returns that value else returns 0. Use this function to avoid the O(N + N^2/2) complexity of calculating dim and calling N times getNth.

Meta