dmd.dtemplate

Defines TemplateDeclaration, TemplateInstance and a few utilities

This modules holds the two main template types: TemplateDeclaration, which is the user-provided declaration of a template, and TemplateInstance, which is an instance of a TemplateDeclaration with specific arguments.

More...

Members

Classes

TemplateAliasParameter
class TemplateAliasParameter

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

Syntax: specType ident : specAlias = defaultAlias

TemplateDeclaration
class TemplateDeclaration

mixin template Identifier (parameters) Constraint https://dlang.org/spec/template.html

https://dlang.org/spec/template-mixin.html

TemplateInstance
class TemplateInstance

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

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

TemplateMixin
class TemplateMixin

https://dlang.org/spec/template-mixin.html

Syntax: mixin MixinTemplateName TemplateArguments Identifier;

TemplateParameter
class TemplateParameter

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

TemplateThisParameter
class TemplateThisParameter

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

Syntax: this ident : specType = defaultType

TemplateTupleParameter
class TemplateTupleParameter

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

Syntax: ident ...

TemplateTypeParameter
class TemplateTypeParameter

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

Syntax: ident : specType = defaultType

TemplateValueParameter
class TemplateValueParameter

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

Syntax: valType ident : specValue = defaultValue

Tuple
class Tuple

Functions

arrayObjectIsError
bool arrayObjectIsError(const Objects* args)

Are any of the Objects an error?

definitelyValueParameter
bool definitelyValueParameter(Expression e)

Return true if e could be valid only as a template value parameter. Return false if it might be an alias or tuple. (Note that even in this case, it could still turn out to be a value).

functionResolve
void functionResolve(ref MatchAccumulator m, Dsymbol dstart, Loc loc, Scope* sc, Objects* tiargs, Type tthis, Expressions* fargs, const(char)** pMessage = null)

Given function arguments, figure out which template function to expand, and return matching result.

getType
inout(Type) getType(inout RootObject o)

Try to get arg as a type.

isError
bool isError(const RootObject o)

Is this Object an error?

isExpression
inout(Expression) isExpression(inout RootObject o)

These functions substitute for dynamic_cast. dynamic_cast does not work on earlier versions of gcc.

matchArg
MATCH matchArg(TemplateParameter tp, Loc instLoc, Scope* sc, Objects* tiargs, size_t i, TemplateParameters* parameters, Objects* dedtypes, 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 dedtypesi

reliesOnTident
bool reliesOnTident(Type t, TemplateParameters* tparams, size_t iStart = 0)

Check whether the type t representation relies on one or more the template parameters.

unSpeculative
void unSpeculative(Scope* sc, RootObject o)

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.

Structs

TemplateInstanceBox
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.

Detailed Description

Template Parameter

Additionally, the classes for template parameters are defined in this module. The base class, TemplateParameter, is inherited by: - TemplateTypeParameter - TemplateThisParameter - TemplateValueParameter - TemplateAliasParameter - TemplateTupleParameter

Templates semantic

The start of the template instantiation process looks like this: - A TypeInstance or TypeIdentifier is encountered. TypeInstance have a bang (e.g. Foo!(arg)) while TypeIdentifier don't. - A TemplateInstance is instantiated - Semantic is run on the TemplateInstance (see dmd.dsymbolsem) - The TemplateInstance search for its TemplateDeclaration, runs semantic on the template arguments and deduce the best match among the possible overloads. - The TemplateInstance search for existing instances with the same arguments, and uses it if found. - Otherwise, the rest of semantic is run on the TemplateInstance.

Meta