Code metrics with macro code expanded?

Is there an easy way to get the program source code as seen by Crystal compiler after all macros being expanded?

I want to print code metrics at that point, such as lines of code per file/class/module/method etc.

I think RFC: Ability to expand macro (recursively) · Issue #2324 · crystal-lang/crystal · GitHub is still accurate.

*.You can expand one location. (either debug() or the expand tool)

  • Macros might have macros and those will be expanded (even by the compiler) only if used.

Additionally you will need to expand defs to their specialized versions since a macro expansion inside of them could expand to different code. I don’t think there’s support for that.

1 Like