Is there a way to "see" source code generated by templates after a compile?

Stefan Koch via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 18 11:18:00 PDT 2016


On Monday, 18 July 2016 at 17:35:29 UTC, Stefan Koch wrote:
>
> I did it for function templates just now.
> It will the instantiated bodys to std-out.

Okay here is the frist really hacky draft patch

In dtemplate.d line 6691 right at the end of semantic3 insert the 
following code :

         if (auto a = toAlias2) {
             scope hgs = HdrGenState();
             scope ob = OutBuffer();
             scope ppv = new PrettyPrintVisitor(&ob, &hgs);

             if (auto fd = a.isFuncDeclaration()) {
                 printf("FunctionTemplate: %s\n{", toChars);
                 if (auto fb = fd.fbody)
                     fb.accept(ppv);
             }

             printf("%.*s\n}\n", ob.size, cast(char*)ob.data);

         }
     }

Without warranty of any kind of course :)




More information about the Digitalmars-d-learn mailing list