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.