Try writing a Clang plugin. There's an example plugin that prints all function names in examples/PrintFunctionNames.<div><br></div><div>You will want to be familiar with what Clang's AST looks like. For a view of the inheritance hierarchy for the AST nodes, see here:</div>
<div><a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">http://clang.llvm.org/doxygen/classclang_1_1Decl.html</a></div><div><a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">http://clang.llvm.org/doxygen/classclang_1_1Stmt.html</a></div>
<div><br></div><div>btw: Clang's AST hierarchy has two roots, Decl and Stmt (that confused me at first).</div><div><br></div><div>--Sean Silva<br><br><div class="gmail_quote">On Tue, Feb 21, 2012 at 6:09 PM, Perry Smith <span dir="ltr"><<a href="mailto:pedzsan@gmail.com">pedzsan@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
On Feb 20, 2012, at 1:24 PM, Eli Friedman wrote:<br>
<br>
> On Mon, Feb 20, 2012 at 11:09 AM, Perry Smith <<a href="mailto:pedzsan@gmail.com">pedzsan@gmail.com</a>> wrote:<br>
>> Hi,<br>
>><br>
>> I'm looking for a skeleton C parser.  I've done C parsers before and I know to do a real parse, you need to have a symbol table so that you can keep track of typedefs.<br>
>><br>
>> I'm wanting to write a tool that will take existing C source (after the preprocessor) and, for example, tell me when a particular function is called (what source line and from within what function) and tell me the arguments to it.  I don't need a full cross reference.  And, in fact, my particular needs today are just a sample.  I'm looking for a parser that is easy to tie in to.<br>

>><br>
>> With the standard Ruby source, there is something called "ripper" which they call an "event-based style parser" (for Ruby).  It has a number of hooks that are called as the source is parsed -- e.g. start of function, start of statement, etc.  This is really easy to tie into.  This is one possibility.  The other possibility is for the parser to give me back a parse tree (or sequence of trees perhaps).<br>

><br>
> Using clang's libraries, you can generate a complete AST for C code,<br>
> find all the call expressions, and do whatever analysis of them is<br>
> necessary.  See <a href="http://clang.llvm.org/" target="_blank">http://clang.llvm.org/</a> .  Please direct further<br>
> questions to the cfe-dev mailing list.<br>
<br>
Thanks<br>
I hope this is proper netiquette to reply to a new list.<br>
<br>
I got clang working.  I put it on my Mac.  I see the -S option and I see that -emit-ast spews out some binary stuff.  I've also found a page describing how to read it back in but I'm assuming that somewhere is a utility to pretty print the AST (or perhaps it is built right into clang).<br>

<br>
Can someone help me with the next step?<br>
<br>
Thank you in advance,<br>
Perry<br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>