ddmd.dtemplate
Source: dtemplate.d
- Expression
isExpression(RootObjecto); - These functions substitute for dynamic_cast. dynamic_cast does not work on earlier versions of gcc.
- bool
isError(RootObjecto); - Is this Object an error?
- bool
arrayObjectIsError(Objects*args); - Are any of the Objects an error?
- Type
getType(RootObjecto); - Try to get arg as a type.
- class
TemplateDeclaration: ddmd.dsymbol.ScopeDsymbol; -
- bool
overloadInsert(Dsymbols); - Overload existing TemplateDeclaration 'this' with the new one '
s'. Returntrueif successful; i.e. no conflict. - bool
evaluateConstraint(TemplateInstanceti, Scope*sc, Scope*paramscope, Objects*dedargs, FuncDeclarationfd); - Check to see if constraint is satisfied.
- MATCH
matchWithInstance(Scope*sc, TemplateInstanceti, Objects*dedtypes, Expressions*fargs, intflag); - Given that
tiis an instance of this TemplateDeclaration, deduce the types of the parameters to this, and store those deduced types indedtypes[].Input:
flag1: don't do semantic() because of dummy types 2: don't change types in matchArg()Output:
dedtypesdeduced arguments Return match level. - MATCH
leastAsSpecialized(Scope*sc, TemplateDeclarationtd2, Expressions*fargs); - Determine partial specialization order of 'this' vs
td2.Returns:match this is at least as specialized astd20td2is more specialized than this - MATCH
deduceFunctionTemplateMatch(TemplateInstanceti, Scope*sc, ref FuncDeclarationfd, Typetthis, Expressions*fargs); - Match function arguments against a specific template function.
Input:
tiscinstantiation scopefdtthis'this' argument if !NULLfargsarguments to functionOutput:
fdPartially instantiated function declarationti.tdtypes Expression/Type deduced template argumentsReturns:match level bit 0-3 Match template parameters by inferred template arguments bit 4-7 Match template parameters by initial template arguments - RootObject
declareParameter(Scope*sc, TemplateParametertp, RootObjecto); - Declare template parameter
tpwith valueo, and install it in the scopesc. - FuncDeclaration
doHeaderInstantiation(TemplateInstanceti, Scope*sc2, FuncDeclarationfd, Typetthis, Expressions*fargs); - Limited function template instantiation for using
fd.leastAsSpecialized() - TemplateInstance
findExistingInstance(TemplateInstancetithis, Expressions*fargs); - Given a new instance
tithisof this TemplateDeclaration, see if there already exists an instance. If so, return that existing instance. - TemplateInstance
addInstance(TemplateInstanceti); - Add instance
tito TemplateDeclaration's table of instances. Return a handle we can use to later remove it if it fails instantiation. - void
removeInstance(TemplateInstanceti); - Remove TemplateInstance from table of instances.
Input: handle returned by addInstance()
- TemplateTupleParameter
isVariadic(); - Check if the last template parameter is a tuple one, and returns it if so, else returns null.Returns:The last template parameter if it's a TemplateTupleParameter
- bool
isOverloadable(); - We can overload templates.
- void
functionResolve(Match*m, Dsymboldstart, Locloc, Scope*sc, Objects*tiargs, Typetthis, Expressions*fargs); - Given function arguments, figure out which template function to expand, and return matching result.
Input:
mmatching resultdstartthe root of overloaded function templateslocinstantiation locationscinstantiation scopetiargsinitial list of template argumentstthisif !NULL, the 'this' pointer argumentfargsarguments to function - abstract class
TemplateParameter; -
- MATCH
matchArg(LocinstLoc, Scope*sc, Objects*tiargs, size_ti, TemplateParameters*parameters, Objects*dedtypes, Declaration*psparam); - Match to a particular TemplateParameter.
Input:
instLoclocation that the template is instantiated.tiargs[] actual arguments to template instanceii'th argumentparameters[] templateparametersdedtypes[] deduced arguments to template instance *psparamset to symbol declared and initialized todedtypes[i]
- class
TemplateTypeParameter: ddmd.dtemplate.TemplateParameter; Syntax: ident : specType = defaultType
- class
TemplateThisParameter: ddmd.dtemplate.TemplateTypeParameter; Syntax: this ident : specType = defaultType
- class
TemplateValueParameter: ddmd.dtemplate.TemplateParameter; Syntax: valType ident : specValue = defaultValue
- class
TemplateAliasParameter: ddmd.dtemplate.TemplateParameter; Syntax: specType ident : specAlias = defaultAlias
- class
TemplateTupleParameter: ddmd.dtemplate.TemplateParameter; Syntax: ident ...
- class
TemplateInstance: ddmd.dsymbol.ScopeDsymbol; Given: foo!(args) => name = foo tiargs = args
- final this(Loc
loc, TemplateDeclarationtd, Objects*tiargs); - This constructor is only called when we figured out which function template to instantiate.
- final 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.
- final Identifier
getIdent(); - Lazily generate identifier for template instance. This is because 75% of the ident's are never needed.
- final int
compare(RootObjecto); - Compare proposed template instantiation with existing template instantiation. Note that this is not commutative because of the auto ref check.Parameters:
this proposed template instantiation RootObject oexisting template instantiation Returns:0 for match, 1 for no match - final bool
needsCodegen(); - Returns
trueif 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.
- final bool
findTempDecl(Scope*sc, WithScopeSymbol*pwithsym); - Find template declaration corresponding to template instance.Returns:
falseif 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. - final bool
updateTempDecl(Scope*sc, Dsymbols); - Confirm
sis a valid template, then store it.Input:
scscandidate symbol of template. It may be: TemplateDeclaration FuncDeclaration with findTemplateDeclRoot() != NULL OverloadSet which contains candidatesReturns:trueif updating succeeds. - static bool
semanticTiargs(Locloc, Scope*sc, Objects*tiargs, intflags); - Run semantic of
tiargsas arguments of template.Input:
locsctiargsarray of template argumentsflags1: replace const variables with their initializers 2: don't devolve Parameter to TypeReturns:falseif one or more arguments have errors. - final bool
semanticTiargs(Scope*sc); - Run semantic on the elements of tiargs.
Input:
scReturns:falseif 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. - final bool
needsTypeInference(Scope*sc, intflag= 0); - Determine if template instance is really a template function, and that template function needs to infer types from the function arguments.Like findBestMatch, iterate possible template candidates, but just looks only the necessity of type inference.
- final bool
hasNestedArgs(Objects*args, boolisstatic); - Determines if a TemplateInstance will need a nested generation of the TemplateDeclaration. Sets enclosing property if so, and returns != 0;
- final Dsymbols*
appendToModuleMember(); - Append 'this' to the specific module members[]
- final void
declareParameters(Scope*sc); - Declare parameters of template instance, initialize them with the template instance arguments.
- final 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.
- void
unSpeculative(Scope*sc, RootObjecto); - IsExpression can evaluate the specified type speculatively, and even if it instantiates any symbols, they are normally unnecessary for the final executable. However, if those symbols leak to the actual code, compiler should remark them as non-speculative to generate their code and link to the final executable.
- bool
definitelyValueParameter(Expressione); - Return
trueifecould be valid only as a template value parameter. Returnfalseif it might be an alias or tuple. (Note that even in this case, it could still turn out to be a value). - class
TemplateMixin: ddmd.dtemplate.TemplateInstance; - 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=15812 and
https: //issues.dlang.org/show_bug.cgi?id=15813 would make it unnecessary.