www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Iterate module membres

reply crimaniak <crimaniak gmail.com> writes:
Hi!

I need to iterate module members and find specific classes (and 
make tuple).

     class foo{};
     pragma (msg, __traits(allMembers,mixin(__MODULE__)));

gives me empty tuple. I found also this thread from 2011: 
http://forum.dlang.org/post/mailman.325.1293887146.4748.digitalmars-d-learn puremagic.com
This is exactly what I need but this code also gives empty tuple.
Is this possible for now to iterate classes from module? Is this 
possible to iterate by classes, public imported to module? (in 
fact, I need to iterate classes imported using package.d file).
Jan 07 2017
next sibling parent ketmar <ketmar ketmar.no-ip.org> writes:
On Saturday, 7 January 2017 at 09:46:54 UTC, crimaniak wrote:
 Hi!

 I need to iterate module members and find specific classes (and 
 make tuple).

     class foo{};
     pragma (msg, __traits(allMembers,mixin(__MODULE__)));

 gives me empty tuple.
works like a charm both in 2.071 and in git HEAD.
Jan 07 2017
prev sibling parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Saturday, 7 January 2017 at 09:46:54 UTC, crimaniak wrote:
 Hi!

 I need to iterate module members and find specific classes (and 
 make tuple).

     class foo{};
     pragma (msg, __traits(allMembers,mixin(__MODULE__)));

 gives me empty tuple. I found also this thread from 2011: 
 http://forum.dlang.org/post/mailman.325.1293887146.4748.digitalmars-d-learn puremagic.com
 This is exactly what I need but this code also gives empty 
 tuple.
 Is this possible for now to iterate classes from module? Is 
 this possible to iterate by classes, public imported to module? 
 (in fact, I need to iterate classes imported using package.d 
 file).
Do you require a module statement per chance?
Jan 07 2017
parent reply ketmar <ketmar ketmar.no-ip.org> writes:
On Saturday, 7 January 2017 at 10:27:51 UTC, Nicholas Wilson 
wrote:
 Do you require a module statement per chance?
it doesn't matter. if there is no explicit module declaration, compiler will insert implicit one. from the code PoV, there is no difference at all.
Jan 07 2017
parent reply crimaniak <crimaniak gmail.com> writes:
On Saturday, 7 January 2017 at 10:38:29 UTC, ketmar wrote:
 On Saturday, 7 January 2017 at 10:27:51 UTC, Nicholas Wilson 
 wrote:
 Do you require a module statement per chance?
it doesn't matter. if there is no explicit module declaration, compiler will insert implicit one. from the code PoV, there is no difference at all.
Yes, module statement is no reason. package.d is reason. The same code in two files: class foo{}; struct bar{}; pragma (msg, "allMembers of "~__MODULE__~" in "~__FILE__); pragma(msg, __traits(allMembers, mixin(__MODULE__))); Result: allMembers of vcm.bll.event in source/vcm/bll/event/package.d tuple() allMembers of vcm.bll.event.test in source/vcm/bll/event/test.d tuple("object", "vcm", "foo", "bar") So allMembers gives empty tuple for module in package.d file. Please check it. As I understand documentation, package.d is ordinary module and special here is only file name used when module name is directory. DMD 2.071.1. Is this a bug or documentation problem?
Jan 07 2017
next sibling parent reply ketmar <ketmar ketmar.no-ip.org> writes:
On Saturday, 7 January 2017 at 12:11:20 UTC, crimaniak wrote:
 Is this a bug or documentation problem?
well, it's hard to say. package.d is one of the cases where you *have* to provide explicit module definition. ;-) 'cause implicit one creates module with name `package`, which is teh keyword. and then all the hell broke loose. this actually may be both bug and documentation problem.
Jan 07 2017
parent reply crimaniak <crimaniak gmail.com> writes:
On Saturday, 7 January 2017 at 12:29:34 UTC, ketmar wrote:
 On Saturday, 7 January 2017 at 12:11:20 UTC, crimaniak wrote:
 Is this a bug or documentation problem?
well, it's hard to say. package.d is one of the cases where you *have* to provide explicit module definition. ;-) 'cause implicit one creates module with name `package`, which is teh keyword. and then all the hell broke loose. this actually may be both bug and documentation problem.
Yes, removing 'module' statement leads to error on __traits(allMembers, mixin(__MODULE__)) expression: Error: expression expected, not 'package'. But it's not related, I provide module statement in package.d.
Jan 07 2017
parent reply crimaniak <crimaniak gmail.com> writes:
....
Ok, I found it: https://issues.dlang.org/show_bug.cgi?id=16044
Jan 07 2017
parent ketmar <ketmar ketmar.no-ip.org> writes:
On Saturday, 7 January 2017 at 13:45:53 UTC, crimaniak wrote:
 ....
 Ok, I found it: https://issues.dlang.org/show_bug.cgi?id=16044
yep. sorry, my search-fu is completely broken, so i didn't provide you with the number.
Jan 07 2017
prev sibling parent ketmar <ketmar ketmar.no-ip.org> writes:
p.s.: otherwise, it *should* work with explicit module 
declaration. but then, we have some well-known bugs with 
cross-module introspection, and some heisenbugs with package 
introspection.
Jan 07 2017