dmd.templatesem
Source templatesem.d
Documentation https://dlang.org/phobos/dmd_templatesem.html
- struct
TemplateInstanceBox; - This struct is needed for TemplateInstance to be the key in an associative array. Fixing https://issues.dlang.org/show_bug.cgi?id=15813 would make it unnecessary.
- void
templateDeclarationSemantic(Scope*sc, TemplateDeclarationtempdecl); - Perform semantic analysis on template.Parameters:
Scope* sccontext TemplateDeclaration tempdecltemplate declaration - bool
findTempDecl(TemplateInstanceti, Scope*sc, WithScopeSymbol*pwithsym); - Find template declaration corresponding to template instance.Returns:false if finding fails.
Note This function is reentrant against error occurrence. If returns false, any members of this object won't be modified, and repetition call will reproduce same error.
- MATCH
matchArg(TemplateParametertp, LocinstLoc, Scope*sc, Objects*tiargs, size_ti, TemplateParameters*parameters, ref Objectsdedtypes, Declaration*psparam); - Match to a particular TemplateParameter.
Input instLoc location that the template is instantiated. tiargs[] actual arguments to template instance i i'th argument parameters[] template parameters dedtypes[] deduced arguments to template instance *psparam set to symbol declared and initialized to dedtypes[i]
- bool
updateTempDecl(TemplateInstanceti, Scope*sc, Dsymbols); - 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
Returns:true if updating succeeds. - MATCH
matchWithInstance(Scope*sc, TemplateDeclarationtd, TemplateInstanceti, ref Objectsdedtypes, ArgumentListargumentList, intflag); - Given that ti is an instance of this TemplateDeclaration, deduce the types of the parameters to this, and store those deduced types in dedtypes[].Parameters:
Scope* sccontext TemplateDeclaration tdtemplate TemplateInstance tiinstance of td Objects dedtypesfill in with deduced types ArgumentList argumentListarguments to template instance int flag1 - don't do semantic() because of dummy types 2 - don't change types in matchArg() Returns:match level. - bool
isDiscardable(TemplateInstanceti); - Returns:true if the instances' innards are discardable. The idea of this function is to see if the template instantiation can be 100% replaced with its eponymous member. All other members can be discarded, even in the compiler to free memory (for example, the template could be expanded in a region allocator, deemed trivial, the end result copied back out independently and the entire region freed), and can be elided entirely from the binary. The current implementation affects code that generally looks like:
template foo(args...) { some_basic_type_or_string helper() { .... } enum foo = helper(); }
since it was the easiest starting point of implementation but it can and should be expanded more later. - bool
needsCodegen(TemplateInstanceti); - Returns true if this is not instantiated in non-root module, and is a part of non-speculative instantiatiation.
Note minst does not stabilize until semantic analysis is completed, so don't call this function during semantic analysis to return precise result.
- const(char)*
getConstraintEvalError(TemplateDeclarationtd, ref const(char)*tip); - Destructively get the error message from the last constraint evaluationParameters:
TemplateDeclaration tdTemplateDeclaration const(char)* tiptip to show after printing all overloads - bool
findBestMatch(TemplateInstanceti, Scope*sc, ArgumentListargumentList); - Find the TemplateDeclaration that matches this TemplateInstance best.Parameters:
TemplateInstance tiTemplateInstance Scope* scthe scope this TemplateInstance resides in ArgumentList argumentListfunction arguments in case of a template function Returns:true if a match was found, false otherwise - MATCH
leastAsSpecialized(Scope*sc, TemplateDeclarationtd, TemplateDeclarationtd2, ArgumentListargumentList); - Determine partial specialization order of
tdvstd2.Parameters:Scope* sccontext TemplateDeclaration tdfirst template TemplateDeclaration td2second template ArgumentList argumentListarguments to template Returns:MATCH - td is at least as specialized as td2 MATCH.nomatch - td2 is more specialized than td - void
declareParameters(TemplateInstanceti, Scope*sc); - Declare parameters of template instance, initialize them with the template instance arguments.
- bool
semanticTiargs(TemplateInstanceti, Scope*sc); - Run semantic on the elements of
ti.tiargs.Input ti = template instance whose tiargs should have semantic done sc = scope
Returns:false if one or more arguments have errors.Note This function is reentrant against error occurrence. If returns false, all elements of tiargs won't be modified.
- bool
TemplateInstance_semanticTiargs(Locloc, Scope*sc, Objects*tiargs, intflags, TupleDeclarationatd= null); - 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 atd tuple being optimized. If found, it's not expanded here but in AliasAssign semantic.
Returns:false if one or more arguments have errors. - void
functionResolve(ref MatchAccumulatorm, Dsymboldstart, Locloc, Scope*sc, Objects*tiargs, Typetthis, ArgumentListargumentList, void delegate(const(char)*) scopeerrorHelper= null); - Given function arguments, figure out which template function to expand, and return matching result.Parameters:
MatchAccumulator mmatching result Dsymbol dstartthe root of overloaded function templates Loc locinstantiation location Scope* scinstantiation scope Objects* tiargsinitial list of template arguments Type tthisif !NULL, the 'this' pointer argument ArgumentList argumentListarguments to function void delegate(const(char)*) scope errorHelperdelegate to send error message to if not null