Need DMD AST expertise
Guillaume Chatelet via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 20 13:52:02 PDT 2016
On Monday, 20 June 2016 at 18:59:09 UTC, Jacob Carlborg wrote:
> On 2016-06-20 14:33, Guillaume Chatelet wrote:
>
>> Problem 2:
>> ----------
>> Template arguments that are of basic types are mangled in a
>> special way
>> which requires to understand which 'int' is which.
>>
>>> extern(C++) A foo(A, B)(B, A, B);
>>> static assert(foo!(int,int).mangleof ==
>>> "_Z3fooIiiET_T0_S0_S1_");
>>
>> In the example above the first 'int' is not the same as the
>> second one,
>> it's a distinct substitution.
>>
>> Question:
>> ---------
>> - How can I know which is which since from the AST
>> perspective, the
>> FunDeclaration's Parameters are just TypeBasic 'int'?
>>
>> ------------------------------------------------------------
>
> Not sure I understand the question.
Sorry about not being too clear.
> Are you saying that the two integers are mangled differently
> because there are two template parameters?
Yes exactly.
> I'm guessing you need to look at the template declaration to
> get more information about the template parameters.
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).
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
More information about the Digitalmars-d
mailing list