www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - list of all defined items in a D file

reply berni44 <dlang d-ecke.de> writes:
I'd like to get a list of all items (public, package, private) 
that are defined in a D file. Is there a simple way, to get them?
Jan 23 2020
next sibling parent Anonymouse <zorael gmail.com> writes:
On Thursday, 23 January 2020 at 17:10:29 UTC, berni44 wrote:
 I'd like to get a list of all items (public, package, private) 
 that are defined in a D file. Is there a simple way, to get 
 them?
__traits(allMembers, mixin(__MODULE__))? Replace with a full module name if not the current one. You'll only get their string names with that though, not aliases to the symbols themselves (as you would have with .tupleof). I imagine you could get those with __traits(getMember, moduleName, stringName).
Jan 23 2020
prev sibling parent reply Dennis <dkorpel gmail.com> writes:
On Thursday, 23 January 2020 at 17:10:29 UTC, berni44 wrote:
 I'd like to get a list of all items (public, package, private) 
 that are defined in a D file. Is there a simple way, to get 
 them?
You can pass the -X flag to dmd, which makes it generate a .json file describing the compiled file.
Jan 24 2020
parent reply berni44 <dlang d-ecke.de> writes:
On Friday, 24 January 2020 at 12:22:49 UTC, Dennis wrote:
 You can pass the -X flag to dmd, which makes it generate a 
 .json file describing the compiled file.
Great, that's what I was looking for - although it's also good to know the __traits approach! Thanks!
Jan 24 2020
parent Basile B. <b2.temp gmx.com> writes:
On Friday, 24 January 2020 at 14:28:03 UTC, berni44 wrote:
 On Friday, 24 January 2020 at 12:22:49 UTC, Dennis wrote:
 You can pass the -X flag to dmd, which makes it generate a 
 .json file describing the compiled file.
Great, that's what I was looking for - although it's also good to know the __traits approach! Thanks!
a 3rd approach is to use libdparse and make your own AST serializer by writing a visitor. (or even with DMD front end as a library). Although if it's a matter of time the dmd -X flag is great in the sense that the output format is standard and straightforward.
Jan 25 2020