www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to find all modules in a package?

reply Domain <dont_email empty.com> writes:
I want to find out all public functions in all modules in a 
package. Can I do that at compile time?
Aug 02 2022
next sibling parent Piotr Mitana <piotr.mitana e.email> writes:
On Wednesday, 3 August 2022 at 03:36:55 UTC, Domain wrote:
 I want to find out all public functions in all modules in a 
 package. Can I do that at compile time?
I think it's not possible.
Aug 03 2022
prev sibling next sibling parent Adam D Ruppe <destructionator gmail.com> writes:
On Wednesday, 3 August 2022 at 03:36:55 UTC, Domain wrote:
 I want to find out all public functions in all modules in a 
 package. Can I do that at compile time?
No, D packages are not closed; anyone can add new modules to them at any time.
Aug 03 2022
prev sibling parent reply frame <frame86 live.com> writes:
On Wednesday, 3 August 2022 at 03:36:55 UTC, Domain wrote:
 I want to find out all public functions in all modules in a 
 package. Can I do that at compile time?
You can do something like that: ```d static foreach (sym; __traits(allMembers, mixin("std.string"))) { pragma(msg, sym.stringof); } ``` Then you would have to check if `sym` is a template or function or something else.
Aug 03 2022
parent reply Domain <dont_email empty.com> writes:
On Wednesday, 3 August 2022 at 12:27:32 UTC, frame wrote:
 On Wednesday, 3 August 2022 at 03:36:55 UTC, Domain wrote:
 I want to find out all public functions in all modules in a 
 package. Can I do that at compile time?
You can do something like that: ```d static foreach (sym; __traits(allMembers, mixin("std.string"))) { pragma(msg, sym.stringof); } ``` Then you would have to check if `sym` is a template or function or something else.
This give me all symbols in the package.d file.
Aug 04 2022
parent "H. S. Teoh" <hsteoh qfbox.info> writes:
On Thu, Aug 04, 2022 at 07:22:04AM +0000, Domain via Digitalmars-d-learn wrote:
 On Wednesday, 3 August 2022 at 12:27:32 UTC, frame wrote:
 On Wednesday, 3 August 2022 at 03:36:55 UTC, Domain wrote:
 I want to find out all public functions in all modules in a package.
 Can I do that at compile time?
You can do something like that: ```d static foreach (sym; __traits(allMembers, mixin("std.string"))) { pragma(msg, sym.stringof); } ``` Then you would have to check if `sym` is a template or function or something else.
This give me all symbols in the package.d file.
static foreach (sym; __traits(allMembers, mixin("std.string"))) { // Note that sym is already a string, there is no need to use .stringof static if (is(typeof(mixin(sym)) == function)) pragma(msg, sym); } Note, however, that this doesn't pick up on template functions, only non-template global functions. You can detect templates with `static if (__traits(isTemplate, mixin(sym)))`, but in general there is no way to know whether it's a template function, because in order to introspect it you have to instantiate it first, but there is no general way to automatically instantiate a template. Its arguments can be subject to arbitrary signature constraints, and it may in theory be a template function only for a subset of its possible arguments, so there isn't any good way to automatically deduce what template arguments would instantiate into a valid function. You can only get at a template function if you already have an instantiation of it. T -- Guns don't kill people. Bullets do.
Aug 04 2022