www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How can we view source code that has been generated (say via "static

reply james.p.leblanc <james.p.leblanc gmail.com> writes:
Dear All,

In attempting to learn and use code generation, it
would be useful to be able to view the source code
that gets generated.

However, with various combinations of templates, UDAs, and
mixins it has not been easy.

Is there some standard way this is done?

Optimal would be to print out the entire generated source
code to allow inspection.

Best Regards,
James
Sep 15 2021
next sibling parent reply Tejas <notrealemail gmail.com> writes:
On Wednesday, 15 September 2021 at 19:59:43 UTC, james.p.leblanc 
wrote:
 Dear All,

 In attempting to learn and use code generation, it
 would be useful to be able to view the source code
 that gets generated.

 However, with various combinations of templates, UDAs, and
 mixins it has not been easy.

 Is there some standard way this is done?

 Optimal would be to print out the entire generated source
 code to allow inspection.

 Best Regards,
 James
Use the `mixin` compiler flag `dmd -mixin=<whatever-name> file.d` Beware, this will also include **all** the mixin code from standard library and runtime. But it's manageable, reflecting on my experience.
Sep 15 2021
parent reply james.p.leblanc <james.p.leblanc gmail.com> writes:
On Thursday, 16 September 2021 at 03:26:46 UTC, Tejas wrote:
 On Wednesday, 15 September 2021 at 19:59:43 UTC, 
 james.p.leblanc wrote:
s
 Use the `mixin` compiler flag

 `dmd -mixin=<whatever-name> file.d`

 Beware, this will also include **all** the mixin code from 
 standard library and runtime.

 But it's manageable, reflecting on my experience.
Tejas, Thank you for your kind response. Wow, at first the large output file from a small test program was a bit surprising .., but actually it is manageable to dig through to find the interesting bits. So, this is quite useful! Thanks again, now I am off to do some digging... Best Regards, James
Sep 15 2021
parent Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Thursday, 16 September 2021 at 04:54:21 UTC, james.p.leblanc 
wrote:
 Thank you for your kind response.  Wow, at first the large 
 output file
 from a small test program was a bit surprising .., but actually 
 it is
 manageable to dig through to find the interesting bits.

 So, this is quite useful!  Thanks again, now I am off to do 
 some digging...

 Best Regards,
 James
Note that that will only give the expansions from string mixins, not from template mixins, templates and other things.
Sep 17 2021
prev sibling parent Dennis <dkorpel gmail.com> writes:
On Wednesday, 15 September 2021 at 19:59:43 UTC, james.p.leblanc 
wrote:
 However, with various combinations of templates, UDAs, and
 mixins it has not been easy.
Apart from -mixin, there's also the undocumented -vcg-ast switch that prints the AST before code generation, showing instantiated templates and unrolled static foreach loops.
Sep 17 2021