On Thursday, 18 July 2013 at 11:46:39 UTC, John Colvin wrote:
On Thursday, 18 July 2013 at 11:16:26 UTC, JS wrote:
Anyone successful at debugging templates and ctfe?
Also, I am using pragma a lot because it seems to be the most
direct way to get ctfe state information.
I would like to be able to toggle when to show pragma so I can
conditionally enable it during compilation.
e.g., suppose I have a template T that I has pragma debug
messaging and I want to enable it only for a call to T:
___DEBUG___ = true;
T!()
___DEBUG___ = false;
(Not sure if this will produce the correct result depending on
how the compiler analyzes the code)
Right now I have to use an immutable bool for debug which is a
global toggle... I don't see any thing around it because I
can't change an immutable at compile time(or can I?)... which,
technically should be valid because an immutable is a
declaration about the state of a variable at run time, so I
should be able to change it at compile time without changing
that fact.
e.g.,
immutable bool x = true;
x $= false; // $= means static assignment, a compile time
assignment.. not sure if x should be true or false for the
whole program at run time(probably true, site of definition).
Or
ctfe bool x = true; defines a ctfe variable at compile time. x
doesn't exist a run time.
If I understand you correctly, this might be useful to you:
void Msg(msgs ...)()
{
debug
{
foreach(m; msgs)
{
pragma(msg, m);
}
}
}
which is a no-op if you don't pass -debug on the command line.
or alternatively you could wrap your pragma(msg, ...) statments
in version(TemplateNameDebug), meaning you can turn them on
individually with -version switches
? It is still global.
T!("x");
T!("y"); // I want to see the pragma outputs of only this template
T!("z");
I also want "library" level debugging instead of whole program
debugging. (although I suppose one could compile each module
separately each with it's own -debug).
For example
immutable bool _MyLibrary_DEBUG_ = true;
is a library level debug toggle, not whole program... it won't
effect other libraries.