Need DMD AST expertise
Guillaume Chatelet via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jun 21 14:05:40 PDT 2016
On Tuesday, 21 June 2016 at 19:42:54 UTC, Elie Morisse wrote:
> On Monday, 20 June 2016 at 20:52:02 UTC, Guillaume Chatelet
> wrote:
>> [...]
>
> The templated function is the child symbol of the
> TemplateDeclaration which shares the same name i.e
>
> [...]
Thx Elie! It helps :)
I came up with this quick and dirty piece of code to get the
parameters from the template declaration and the function
declaration:
code:
> auto declaration =
> cast(TemplateDeclaration)templateInstance.tempdecl;
> assert(declaration);
> printf("TemplateDeclaration %x\n", declaration);
> foreach(parameter; *declaration.parameters) {
> printf("Parameter %s\n", parameter.ident.toChars());
> }
>
> if (declaration.onemember) {
> FuncDeclaration fd =
> declaration.onemember.isFuncDeclaration();
> if (fd && fd.type) {
> TypeFunction tf = cast(TypeFunction)fd.type;
> assert(tf);
> printf("TypeFunction %x\n", tf);
> if(tf.next) printf("Parameter return %s\n",
> tf.next.toChars());
> if(tf.parameters) foreach(parameter; *tf.parameters) {
> printf("Parameter %s\n", parameter.type.toChars());
> }
> }
> }
input:
> extern(C++) C foo(A, B, C)(B, A);
output:
> TemplateDeclaration 764f76b0
> Parameter A
> Parameter B
> Parameter C
> TypeFunction 764f7370
> Parameter return C
> Parameter B
> Parameter A
It works as expected. I still need to do the mapping and handle
subtleties like this but I'm on the right track.
> extern(C++) ref C foo(A, B, C)(B*, const(A)*);
Thx!
More information about the Digitalmars-d
mailing list