template debuging

John Colvin john.loughran.colvin at gmail.com
Thu Jul 18 04:46:38 PDT 2013


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


More information about the Digitalmars-d-learn mailing list