How does one determine the UDAs of all symbols contained in a given module?

Andrew Edwards via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 19 00:29:55 PDT 2017


Given a module (somepackage.somemodule) how does one 
programmatically determine the symbols contained therein and 
associated UDAs?

Where symbol is a variable, function, UDT, etc... is this 
possible?

     foreach (symbol; somepackage.somemodule) {
         writeln(symbol.name, " attributes :")
         foreach(attribute; symbol) {
             writeln("\t", attribute);
         }
     }

I've looked at std.traits but for the most part the functionality 
I saw there only allowed me to grab attributes I already know of 
from symbols I already know... for instance:

     @("bold") string boldText;
     getUDAs!(boldText, "bold");

This also does not allow retrieving attributes from functions 
with void return-type. So this wouldn't work:

     @("bold") void decorateText(ref string data);
     getUDAs!(decorateText, "bold");
     // Error: cannot deduce function from arguments types 
!()(void, string);

What I'd like to do is open a module and evaluate each variable, 
instance variable, member variable, function, member function, 
etc... to see what UDAs they carry.

Please provide code sample or point me toward the appropriate 
documentation. Again, I've looked at std.traits 
(https://dlang.org/phobos/std_traits.html) and the related 
implementation 
(https://github.com/dlang/phobos/blob/master/std/traits.d#L7378-L7760) but found nothing that would help me toward this end... or maybe I've missed something?

Thanks,
Andrew


More information about the Digitalmars-d-learn mailing list