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( ,FILE ,LINE); – extra debug statements after each C++ statements like:
void my_func()
{
call_other();
}
in file 1.cpp at line 1
Would become
void my_func()
{
call_other();
printf("call_other() 1.cpp 1")
}
So each file code would be parsed and this extra debug statement would be added.
But the issue comes up with various type of statements:
if(condition) statement else statement;
C++ templates
switch case
etc
I am not able to establish a grammar that I should follow, like:
If the line ends with a semicolon and next token is not ‘{‘ the add this debugging line.
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?
Is there a tool / known technique that I can already make use off?
If you absolutely need to do this, take a look at clang, and write a source-to-source translator that works on the AST level. There are various posts around the net that can get you started with this. One example: http://eli.thegreenplace.net/2012/06/08/basic-source-to-source-transformation-with-clang/