[cfe-dev] looking for an AST traversal example

Garrison Venn gvenn.cfe.dev at gmail.com
Mon Oct 31 09:59:04 PDT 2011


Attached is a very non-complete, and simple example which I created awhile
back. Even though this it uses RecursiveASTVisitor, one can get 
the basics on how to use ASTConsumers from it. One caveat here is that
if you do want to use RecursiveASTVisitor, you must really have a good
understanding of tablegen generated header files such as DeclNodes.inc.
Using these files, along with redefined macros, is where the real power
of RecursiveASTVisitor manifests itself (IMHO). The second caveat is that there
is no cleanup here. For example I'm including headers (such as some JIT 
stuff), which I do not need. This was just a quick hack which got me started.

Hope this helps

Garrison

PS: This example was tested with TOT

-------------- next part --------------
A non-text attachment was scrubbed...
Name: recurseVisitAst.cpp
Type: application/octet-stream
Size: 8229 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111031/66cf0f95/attachment.obj>
-------------- next part --------------


On Oct 31, 2011, at 9:11, josef maxim pohl wrote:

> Hi there, 
> 
> I am still on my search for a relatively simple example to work with which creates an AST from a source file and traverses it doing even the most rudimentary tasks.  Does anyone have such an example?  Or does anyone have any tips on how to go about building one?
> 
> 
> What I am attempting to do is build a stand-alone application (ie not a plugin) that sets up the AST (ie build preprocessor, set appropriate options (header search, etc), initialize ParseAST routine, ...) and then use an ASTConsumer to traverse the tree.
> 
> Any feed back would be greatly appreciated.
> 
> Thanks,
> Josef
> 
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list