dmd.dtemplate
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.
Source dtemplate.d
Documentation https://dlang.org/phobos/dmd_dtemplate.html
- pure nothrow @nogc @trusted inout(Expression)isExpression(inout RootObjecto);
- These functions substitute for dynamic_cast. dynamic_cast does not work on earlier versions of gcc.
- pure nothrow @nogc @safe boolisError(const RootObjecto);
- Is this Object an error?
- pure nothrow @nogc @safe boolarrayObjectIsError(ref const Objectsargs);
- Are any of the Objects an error?
- pure nothrow @nogc @safe inout(Type)getType(inout RootObjecto);
- Try to get arg as a type.
- DsymbolgetDsymbol(RootObjectoarg);
- If oarg represents a Dsymbol, return that DsymbolParameters:RootObject oargargument to check Returns:Dsymbol if a symbol, null if not
- boolarrayObjectMatch(ref Objectsoa1, ref Objectsoa2);
- Match an array of them.
- classTemplateDeclaration: dmd.dsymbol.ScopeDsymbol;
- [mixin] template Identifier (parameters) [Constraint] https://dlang.org/spec/template.html https://dlang.org/spec/template-mixin.html- boolisTrivialAliasSeq;
- matches pattern template AliasSeq(T...) { alias AliasSeq = T; }
- boolisTrivialAlias;
- matches pattern template Alias(T) { alias Alias = qualifiers(T); }
- booldeprecated_;
- this template declaration is deprecated
- ExpressionlastConstraint;
- the constraint after the last failed evaluation
- Array!ExpressionlastConstraintNegs;
- its negative parts
- Objects*lastConstraintTiargs;
- template instance arguments for lastConstraint
- booloverloadInsert(Dsymbols);
- Overload existing TemplateDeclaration 'this' with the new one 's'.Parameters:Dsymbol ssymbol to be inserted Return true if successful; i.e. no conflict. 
- const(char)*toCharsNoConstraints() const;
- Similar to toChars, but does not print the template constraints
- const(char)*getConstraintEvalError(ref const(char)*tip);
- Destructively get the error message from the last constraint evaluationParameters:const(char)* tiptip to show after printing all overloads 
- TemplateInstancefindExistingInstance(TemplateInstancetithis, ArgumentListargumentList);
- Given a new instancetithisof this TemplateDeclaration, see if there already exists an instance.Parameters:TemplateInstance tithistemplate instance to check ArgumentList argumentListFor function templates, needed because different auto ref resolutions create different instances, even when template parameters are identical Returns:that existing instance, or null when it doesn't exist
- TemplateInstanceaddInstance(TemplateInstanceti);
- Add instance ti to TemplateDeclaration's table of instances. Return a handle we can use to later remove it if it fails instantiation.
- voidremoveInstance(TemplateInstanceti);
- Remove TemplateInstance from table of instances.Input handle returned by addInstance() 
- TemplateTupleParameterisVariadic();
- 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
- boolisOverloadable() const;
- We can overload templates.
 
- boolreliesOnTident(Typet, TemplateParameters*tparams, size_tiStart= 0);
- Check whether the type t representation relies on one or more the template parameters.Parameters:Type tTested type, if null, returns false. TemplateParameters* tparamsTemplate parameters. size_t iStartStart index of tparams to limit the tested parameters. If it's nonzero, tparams[0..iStart] will be excluded from the test target. 
- boolreliesOnTemplateParameters(Typet, TemplateParameter[]tparams);
- Check whether the type t representation relies on one or more the template parameters.Parameters:Type tTested type, if null, returns false. TemplateParameter[] tparamsTemplate parameters. 
- abstract classTemplateParameter: dmd.ast_node.ASTNode;
- classTemplateTypeParameter: dmd.dtemplate.TemplateParameter;
- Syntax ident : specType = defaultType 
- classTemplateThisParameter: dmd.dtemplate.TemplateTypeParameter;
- Syntax this ident : specType = defaultType 
- classTemplateValueParameter: dmd.dtemplate.TemplateParameter;
- Syntax valType ident : specValue = defaultValue 
- classTemplateAliasParameter: dmd.dtemplate.TemplateParameter;
- Syntax specType ident : specAlias = defaultAlias 
- classTemplateTupleParameter: dmd.dtemplate.TemplateParameter;
- Syntax ident ... 
- classTemplateInstance: dmd.dsymbol.ScopeDsymbol;
- Given foo!(args) => name = foo tiargs = args - TemplateInstanceinst;
- If this is not null and it has a value that is not the current object, then this field points to an existing template instance and that object has been duplicated into us.If this object is a duplicate, the memberOf field will be set to a root module (passed on CLI). This information is useful to deduplicate analysis that may occur after semantic 3 has completed.See Also:memberOf
- Expressions*fargs;
- For function template, these are the function names and arguments Relevant because different resolutions of auto ref parameters create different template instances even with the same template arguments
- ModulememberOf;
- If this is not null then this template instance appears in a root module's members.Note This is not useful for determining duplication status of this template instance. Use the field inst for determining if a template instance has been duplicated into this object. See Also:inst
- final pure nothrow @nogc @property @safe boolsemantictiargsdone() const;
- has semanticTiargs() been done?
- final pure nothrow @nogc @property @safe boolhavetempdecl() const;
- if used second constructor
- final pure nothrow @nogc @property @safe boolgagged() const;
- if the instantiation is done with error gagging
- this(Locloc, TemplateDeclarationtd, Objects*tiargs) scope;
- This constructor is only called when we figured out which function template to instantiate.
- final voidprintInstantiationTrace(Classificationcl= Classification.error, const(uint)max_shown= global.params.v.errorSupplementCount());
- Given an error instantiating the TemplateInstance, give the nested TemplateInstance instantiations that got us here. Those are a list threaded into the nested scopes.Parameters:Classification clclassification of this trace as printing either errors or deprecations const(uint) max_shownmaximum number of trace elements printed (controlled with -v/-verror-limit) 
- final IdentifiergetIdent();
- Lazily generate identifier for template instance. This is because 75% of the ident's are never needed.
- final boolequalsx(TemplateInstanceti);
- Compare proposed template instantiation with existing template instantiation. Note that this is not commutative because of the auto ref check.Parameters:TemplateInstance tiexisting template instantiation Returns:true for match
- final boolisDiscardable();
- 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.
- final boolneedsCodegen();
- 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. 
- final boolfindTempDecl(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. 
- final boolupdateTempDecl(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.
- static boolsemanticTiargs(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.
- final boolsemanticTiargs(Scope*sc);
- Run semantic on the elements of tiargs.Input sc 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. 
- final boolfindBestMatch(Scope*sc, ArgumentListargumentList);
- Find the TemplateDeclaration that matches this TemplateInstance best.Parameters: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
- final boolhasNestedArgs(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 voiddeclareParameters(Scope*sc);
- Declare parameters of template instance, initialize them with the template instance arguments.
- final IdentifiergenIdent(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.
 
- voidunSpeculative(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.
- @safe booldefinitelyValueParameter(Expressione);
- 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).
- classTemplateMixin: dmd.dtemplate.TemplateInstance;
- Syntax mixin MixinTemplateName [TemplateArguments] - Identifier;
- structTemplateInstanceBox;
- 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.
- MATCHmatchArg(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] 
- structTemplateStats;
- Collect and print statistics on template instantiations.- static voidincInstance(const TemplateDeclarationtd, const TemplateInstanceti, boollistInstances);
- Add this instanceParameters:TemplateDeclaration tdtemplate declaration TemplateInstance tiinstance of td bool listInstanceskeep track of instances of templates 
- static voidincUnique(const TemplateDeclarationtd, const TemplateInstanceti);
- Add this unique instance
 
- voidprintTemplateStats(boollistInstances, ErrorSinkeSink);
- Print informational statistics on template instantiations.Parameters:bool listInstanceslist instances of templates ErrorSink eSinkwhere the print is sent 
- structMATCHpair;
- Pair of MATCHes- MATCHmta;
- match template parameters by initial template arguments
- MATCHmfa;
- match template parameters by inferred template arguments