generative programming and debugging

Don nospam at nospam.com
Wed Oct 19 05:46:10 PDT 2011


On 19.10.2011 12:50, Gor Gyolchanyan wrote:
> 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.

I've made a couple of improvements to the CTFE engine for the next 
release, which gives a substantially better call stack trace when an 
error occurs.
Please suggest further improvements.


> 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.

I don't know how it could really do that. I mean, what if at the end of 
foo, you looped over 'r' and changed every 'k' to 'l', and every 'l' to 'k'?
Then the first line would be the one with the error!





More information about the Digitalmars-d mailing list