How to view Clang AST?

username_4567 picture username_4567 · Sep 1, 2013 · Viewed 33.5k times · Source

I am trying to get hold on Clang. So, I would like to view the AST generated by Clang after parsing the given program. Is it possible to dump AST in .dot or .viz format? Is there any tool out there?

Answer

cpt. jazz picture cpt. jazz · Sep 3, 2013

Clang supports showing the AST with Graphviz's dotty -- you can grab the temporary .dot file generated (name is printed out) to get the graph source.

clang -cc1 -ast-view your_file.c

You can also print to the command line with:

clang -cc1 -ast-dump your_file.c

or:

clang -cc1 -ast-print your_file.c

or in 3.3:

clang -cc1 -ast-dump-xml your_file.c

but this was removed later as pointed by Lukas Kubanek in the comment.