Re: Iterate all visible symbols, even from imported modules
On Monday, 18 July 2016 at 21:12:38 UTC, Meta wrote: On Monday, 18 July 2016 at 13:00:16 UTC, Lodovico Giaretta wrote: As per title, is it possible to iterate all visible symbols of the current module and of all imported modules and packages? My aim is to find everything in scope that has a specific UDA. module foo; import std.stdio, std.array, std.algorithm; void bar(){} struct S{} void main() { // prints ["object", "std", "bar", "S", "main"] // how do I discover that "std" is a package? writeln([__traits(allMembers, foo)]); // prints ["object", "core", "std", "KeepTerminator", "GCC_IO", ... ] // strange thing: it looks the same even if I remove all imports other than std.stdio writeln([__traits(allMembers, foo.std)]); } Thank you in advance. This answer to a similar question on StackOverflow may be useful: http://stackoverflow.com/questions/2329/d-finding-all-functions-with-certain-attribute/25560800#25560800 Wow! Looks exactly what I was looking for. I'll give this a try as soon as possible. Thank you.
Re: Iterate all visible symbols, even from imported modules
On Monday, 18 July 2016 at 18:21:41 UTC, ketmar wrote: short answer: no. there is still no way to write a reliable enumerator like this: too much things to hack around. as for module symbols, it is easy: they has no type. literally: `!is(typeof(...))`. `is(typeof(...))` is a necessary safeguard anyway if you are enumerating symbols in module, as you can't do much with module names anyway, and you *have* to filter 'em out with top-level static if. Thank you. It looks like the check `is(typeof(T)) || is(T)` is passed by every symbol `T` that is not a module nor a package, so I think I'll use its complementary as a filter.
Re: Iterate all visible symbols, even from imported modules
On Monday, 18 July 2016 at 13:00:16 UTC, Lodovico Giaretta wrote: As per title, is it possible to iterate all visible symbols of the current module and of all imported modules and packages? My aim is to find everything in scope that has a specific UDA. module foo; import std.stdio, std.array, std.algorithm; void bar(){} struct S{} void main() { // prints ["object", "std", "bar", "S", "main"] // how do I discover that "std" is a package? writeln([__traits(allMembers, foo)]); // prints ["object", "core", "std", "KeepTerminator", "GCC_IO", ... ] // strange thing: it looks the same even if I remove all imports other than std.stdio writeln([__traits(allMembers, foo.std)]); } Thank you in advance. This answer to a similar question on StackOverflow may be useful: http://stackoverflow.com/questions/2329/d-finding-all-functions-with-certain-attribute/25560800#25560800
Re: Iterate all visible symbols, even from imported modules
On Monday, 18 July 2016 at 13:00:16 UTC, Lodovico Giaretta wrote: // how do I discover that "std" is a package? I've got a DMD pull request that adds __traits(isPackage, someSymbol), but it's stuck waiting for approval. If and when it gets merged, it could be useful for that. https://github.com/dlang/dmd/pull/5290
Re: Iterate all visible symbols, even from imported modules
short answer: no. there is still no way to write a reliable enumerator like this: too much things to hack around. as for module symbols, it is easy: they has no type. literally: `!is(typeof(...))`. `is(typeof(...))` is a necessary safeguard anyway if you are enumerating symbols in module, as you can't do much with module names anyway, and you *have* to filter 'em out with top-level static if.
Iterate all visible symbols, even from imported modules
As per title, is it possible to iterate all visible symbols of the current module and of all imported modules and packages? My aim is to find everything in scope that has a specific UDA. module foo; import std.stdio, std.array, std.algorithm; void bar(){} struct S{} void main() { // prints ["object", "std", "bar", "S", "main"] // how do I discover that "std" is a package? writeln([__traits(allMembers, foo)]); // prints ["object", "core", "std", "KeepTerminator", "GCC_IO", ... ] // strange thing: it looks the same even if I remove all imports other than std.stdio writeln([__traits(allMembers, foo.std)]); } Thank you in advance.