[cfe-dev] Question about printing abstract syntax tree in Clang

Ted Kremenek kremenek at apple.com
Mon Jun 28 15:58:07 PDT 2010


The CFG is just a layer on top of the ASTs.  The basic blocks consist of CFGElements, which is a discriminated union to represent references to statements, etc.  Currently CFGElements only wrap Stmt*, but in the near future they will also represent destructor calls, etc.  Going back to the AST is as simple as iterating over the CFG.

To pretty-print the AST, there are a variety of dumpers.  The Stmt class has a dumpPretty() and dumpMethod(), for example.  The dumpPretty() method is not intended, however, to reprint the original code as it was written.

On Jun 27, 2010, at 10:17 PM, Yang Ye wrote:

> Hello everyone,
> 
> This is Yang Ye, a new researcher working on Clang. I want to use
> clang to print out the abstract syntax tree in a human readable, not
> getting the binary bytecode one.
> Can anyone show me how to use the API to do it?
> 
> 
> 
> Another question, I found some sample code on the website about
> dumping the CFG, it uses:
> 
>   Stmt* FooBody = ...
>   CFG* FooCFG = CFG::buildCFG(FooBody);
>  FooCFG->dump():
> 
> This is also helpful, but how can I construct a statement from give code?
> 
> 
> Thanks a lot
> 
> -----------------------
> Yang Ye
> 646-417-0326
> 
> Ph.D.
> Department of Computer Science
> The Fu Foundation School of Engineering and Applied Science Columbia University
> yy2314 at columbia.edu
> 
> _______________________________________________
> 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