Parse and add debug statements in C++ source code file
<p>I am tired of debugging a flow of my official project code - it spreads across multiple files and millions / thousands of line. Hence I started to write a C++ program that would take input file names from a file whose objective is add printf( ,<strong>FILE</strong> ,<strong>LINE</strong>); - extra debug statements after each C++ statements like:</p>

<pre><code>void my_func()
{
call_other();
}
in file 1.cpp at line 1
</code></pre>

<p>Would become</p>

<pre><code>void my_func()
{
call_other();
printf("call_other() 1.cpp 1")
}
</code></pre>

<p>So each file code would be parsed and this extra debug statement would be added. </p>

<p>But the issue comes up with various type of statements:</p>

<pre><code>if(condition) statement else statement;
C++ templates
switch case
etc
</code></pre>

<p>I am not able to establish a grammar that I should follow, like:</p>

<p>If the line ends with a semicolon and next token is not '{' the add this debugging line.</p>

<p>I believe that there are more cases than I am thinking off. Any suggestions that I should consider before implementing the same across thousands of file accumulating to millions of line of code?</p>

<p>Is there a tool / known technique that I can already make use off?</p>
