generative programming and debugging

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Wed Oct 19 03:50:36 PDT 2011


good point. I'll need to generate comments for that code, that contain
information about the place, where the code was generated.

There are 2 things I'd really like to have:
1. Be able to obtain the name (possibly an alias) of a function on the
call stack on the given depth.
2. Be able to obtain file and line of a function on the call stack on
the given depth.
This would be awesome for generating very convenient debug info.

On Wed, Oct 19, 2011 at 2:32 PM, Timon Gehr <timon.gehr at gmx.ch> wrote:
> On 10/19/2011 11:07 AM, Gor Gyolchanyan wrote:
>>
>> Do anybody know a good way to (statically) debug a generated code?
>> Currently it takes lots of effort to determine the place, where the
>> code is being incorrectly generated.
>
> pragma(msg, foo()); // debug
> mixin(foo());
>
> You can additionally use something in the lines of the following if it is
> not immediately obvious which function generated the incorrect code.
>
> import std.stdio, std.conv;
>
> string X(string file=__FILE__, int line=__LINE__){
>     return "// "~file~"("~to!string(line)~")\n";
> }
>
> string foo(){
>    string r;
>    foreach(i;0..3) r~=q{writeln("hello world");}~X();
>    foreach(i;0..3) r~=q{writekn("hello world");}~X(); // whoops
>    return r;
> }
>
> void main(){
>    pragma(msg, foo());
>    mixin(foo());
> }
>
>
> It would be kinda nice if the compiler pointed directly to the source
> location that generated the incorrect code.
>


More information about the Digitalmars-d mailing list