title: Using clang tools for adding auto-generated code to source files
body: <p>I'm working on a logging mechanism for a project, and currently each API function needs to add </p>
  
  <pre><code>start_api_call(***)
  </code></pre>
  
  <p>in the beginning of the function
  where *** for the function <code>do_something(int foo, int bar)</code> is <code>"foo", foo, "bar",bar</code></p>
  
  <p>(The log function takes the parameters and form the desired message)<br/></p>
  
  <p>I would like to make this line auto-generated, where the vision is that somehow (mabye clang tools?) the compiler checks for each function in a .cpp if it is an API function (more details later) and if it is, just add the <code>start_api_call(***)</code> to the code.
  <br/><br/>
  I have 2 major problems regarding which direction should i go<br/>
  1) I have never wrote code that it's 'goal' is to parse a source code, hence i don't know which direction should i head, I've read some documentation about the clang tools, but maybe just a python script would be better here?<br/><br/>
  2) Our design is as follows:<br/></p>
  
  <pre><code>object_foo.h //inside .include/
  class foo{
  API functions
  }
  
  object_foo_impl.h //inside .src/
  include "object_foo.h"
  class foo_impl :foo{
  foo API functions
  a lot more functions
  }
  
  object_foo_impl.cpp
  include "object_foo_impl.h"
  {
  implementation of all foo_impl functions
  }
  </code></pre>
  
  <p>The start_api_call should be inserted only for the API functions,
  thus i need to find a way to <strong>query</strong> inside the .cpp file, if this function came from the foo.h, or from the foo_impl.h file.<br/></p>
  
  <p>I have a somehow working concept of how to do it using python scripts, that parse all of our source code, identifying using regex which text inside a /include/.h file is a function and then finding all the functions inside .cpp files that implement those functions,<br/>
  but (if possible) the concept of adding a rule in the compilation(/preprocessor) time is much more attractive.<br/>
  Any help would be very much appreciated.</p>