3

Suppose I have a file foo.d which instantiates a bunch of templates. Is there any way I can ask GDC (specifically) to give me foo.d with all its templates instantiated, but nothing else done? The GCC -E option obviously doesn't work, as D templates are not expanded by the C preprocessor, but I'm not sure what option I should try (or if one even exists).

Koz Ross
  • 3,040
  • 2
  • 24
  • 44
  • 1
    What, exactly, do you mean by templates expanded? If you compile it normally, it instantiates them in the object file, but there's no way to spit them out as source code... well, there actually is a way, you could modify the compiler to add an option like that, parse and semantically analyze the program then output the ASTs as code... but nothing easy. – Adam D. Ruppe Nov 19 '14 at 14:12
  • This is actually a very good idea. – DejanLekic Nov 19 '14 at 15:53
  • @AdamD.Ruppe: What I meant was exactly this: I want to take a source file ``foo.d`` and run it through *something*, that outputs another source file ``bar.d``, such that ``bar.d`` is the same as ``foo.d``, but has all templates in ``foo.d`` instantiated in source form. But if there isn't such a tool yet, I should probably write one. – Koz Ross Nov 19 '14 at 21:14
  • DMD has an `-allinst` option which is supposed instantiate all templates and produce source code, but I couldn't get it to do what I thought it would do. Maybe you'll have better luck. GDC doesn't seem to have such an option. – Verax Nov 20 '14 at 00:20

0 Answers0