On Wednesday, 19 July 2017 at 07:29:55 UTC, Andrew Edwards wrote:
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
You'll want to use https://dlang.org/spec/traits.html#getMember
in conjunction with
https://dlang.org/spec/traits.html#getAttributes.
Have a look some of the projects on github e.g.
https://github.com/kaleidicassociates/excel-d/blob/master/source/xlld/wrap.d#L686