www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - how to get fully qualified name of a template function (if possible at

reply "timotheecour" <thelastmammoth gmail.com> writes:
how to get fully qualified name of a template function?
In the code below I want to get "util.mod.mymethod!(double)"
I tried everything (see below) to no avail, it just returns 
"mymethod";
The closest I get is demangle(mangledName!(fun)), which shouldn't 
be hard to convert to what I want, but demangle is runtime, not 
compile time.

Ideally, fullyQualifiedName should do that, but currently fails. 
(btw I have a fix for another bug with fullyQualifiedName with 
non-templated functions which I can post shortly).

----
module util.mod;
import std.stdio;
import std.traits;
import core.demangle;

void mymethod(T)(){}
void main(){ fun_aux!(mymethod!double);}
void fun_aux(alias fun)(){
	pragma(msg,fun);
	writeln(fun.stringof);
	writeln(__traits(identifier,fun));
	writeln(__traits(identifier,__traits(parent,fun)));
	pragma(msg, mangledName!(fun));
	writeln(demangle(mangledName!(fun)));
	//pragma(msg, demangle(mangledName!(fun)));//CT error:demangle 
is runtime
	//writeln(fullyQualifiedName!fun);//CT error	
----
Aug 24 2012
next sibling parent "timotheecour" <thelastmammoth gmail.com> writes:
related threads:
http://www.digitalmars.com/d/archives/digitalmars/D/learn/3530.html
from Don Clugston:
 I have implemented compile-time demangle metafunctions:
 static assert( prettynameof!(A)    == "class main.A" );
 static assert( qualifiednameof!(A) == "main.A" );
 static assert( symbolnameof!(A)    == "A" );
And also this: http://www.digitalmars.com/d/archives/digitalmars/D/Help_with_demangling_104520.html
 For an implementation that will demangle stuff at compile-time 
 and allow you
to get FQNs.
 http://www.dsource.org/projects/ddl/browser/trunk/meta/demangle.d
Although this is old (6 y) and will probably fail with invariant,shared,__gshared,inout(the new),etc. So is there a better way now? That should be in phobos.
Aug 24 2012
prev sibling parent Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
On 08/24/2012 11:16 PM, timotheecour wrote:
 how to get fully qualified name of a template function?
 In the code below I want to get "util.mod.mymethod!(double)"
 I tried everything (see below) to no avail, it just returns "mymethod";
 The closest I get is demangle(mangledName!(fun)), which shouldn't be
 hard to convert to what I want, but demangle is runtime, not compile time.
Way back when, Don wrote some code which does just this. Recently I have been whacking with a hammer, so while you're waiting for fullyQualifiedName to not fail, you might try it. https://bitbucket.org/ariovistus/pyd/src/19bef7310180/infrastructure/meta module util.mod; import meta.Nameof; void mymethod(T)(){} void main(){ fun_aux!(mymethod!double);} void fun_aux(alias fun)(){ pragma(msg, qualifiednameof!fun); pragma(msg, prettynameof!fun); } gives util.mod.mymethod.mymethod void util.mod.mymethod!(double).mymethod()
Aug 27 2012