[dmd-internals] Getting the calling scope for a function (e.g. to get __FUNC__ from the caller)

Simen Kjaeraas via dmd-internals dmd-internals at puremagic.com
Tue Apr 5 07:54:05 PDT 2016


To get to know DMD a bit more, I decided to implement __GENSYM__, 
as touched upon in Nordlöw's post on Units of Measurements[1].

My implementation uses the mangled name of the instantiation 
scope and an associated counter to create a unique string, and 
works great for template default parameters (which is where I 
imagine it would see use).

For completeness though, I wanted to make it work as a function 
default parameter as well. Looking at how __FILE__ and __LINE__ 
are implemented, they use only Loc, not Scope. Is it at all 
possible to get the calling scope for a function?

[1]: 
http://forum.dlang.org/post/mtniwehednpdofmcftwc@forum.dlang.org


More information about the dmd-internals mailing list