Off subject

Ary Borenszweig ary at esperanto.org.ar
Tue Jan 6 06:44:19 PST 2009


Vincent Richomme wrote:
> Hi,
> 
> sorry to ask my question here but since people are motivated by new 
> language, source code, ... I thought it was a good place to ask my 
> question about source code analysis.
> I would like to know if there are some parsers/scripts that could parse 
> some C/C++ language and that could insert printf in each function.
> 
> Actually I am trying to understand a huge program and debugging step by 
> step would take me ages.
> What I want is something like :
> 
> void myfunc(int aFoo)
> {
> 
> ...
> 
> }
> 
> I want a parser that could add
> 
> void myfunc(int aFoo)
> {
> fprintf(stderr, "myfunc(int aFoo)");
> ...
> 
> }

I'm sure you can do this with CDT (the Eclipse plugin for C/C++). The 
API is here:

http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.cdt.doc.isv/reference/api/overview-summary.html

I haven't worked with that API but more or less you'll need to:

1. Get an ITranslationUnit, which represents a source file.
2. From it, invoke getAST().
3. Implement an IASTVisitor to traverse all the nodes and print them, 
with the exception of function bodies, where you'll add an pfritf.

You could even make it a plugin and then just open the file in Eclipse, 
select an action from the menu and have it done for a whole project or a 
bunch of source files.



More information about the Digitalmars-d mailing list