Need DMD AST expertise

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 20 23:25:26 PDT 2016


On 2016-06-20 22:52, Guillaume Chatelet wrote:

> The TemplateInstance [1] gives me `tiargs` and `tdtypes`.
>
>     // Array of Types/Expressions of template
>     // instance arguments [int*, char, 10*10]
>     Objects* tiargs;
>
>     // Array of Types/Expressions corresponding
>     // to TemplateDeclaration.parameters
>     // [int, char, 100]
>     Objects tdtypes;
>
> I'm using `tiargs` right now (I'm not really sure what `tdtypes` is).

A guess: "tiargs" is the types of the values passed to the template.
"tdtypes" is the types the template is instantiated with.

void foo(T)(T* a);

int b;
foo!(int)(&b*);

"tiargs" is "int*" and "tdtypes" is "int". But this can easily be 
confirmed using some printf debugging.

> AFAIU I can access TemplateDeclaration from TemplateInstance through
> `tempdecl` even though it's stored as a Dsymbol.
>
> I'll have a look at `parameters` from TemplateDeclaration [2] but I
> still need to match it to the function arguments somehow. The following
> example illustrates the process of pairing the int to the template
> parameter.
>
>     extern(C++) B foo(A, B)(*B, ref const A);
>
>     foo!(int, int) => int foo(*int, ref const int);
>           ^    ^       ^        ^              ^
>           1    2       2        1              2
>
> 1. https://github.com/dlang/dmd/blob/master/src/dtemplate.d#L5895
> 2. https://github.com/dlang/dmd/blob/master/src/dtemplate.d#L406

Are the types the same objects so you can compare by just comparing the 
pointers?

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list