[cfe-dev] How flexible is the AST of Clang and its file format?

Douglas Gregor dgregor at apple.com
Mon Jan 17 10:18:43 PST 2011


On Jan 16, 2011, at 7:02 PM, Samuel Crow wrote:

> Hi Clang list,
> 
> I've been on the LLVM Dev list for a while now and was getting frustrated with 
> trying to make a cross-platform bitcode distribution when I noticed there is an 
> AST file format used for higher-level representations of C-like languages under 
> Clang.
> 
> What I want to do is make a GUI that represents the parse tree of a high-level 
> language as a tree-browser gadget so that it can be edited just like the code 
> but without the parsing and the keywords.  I know it's been done before but I 
> think it will be a good exercise in programming.
> 
> Is it possible?  Moreso, is it practical?  I'd like to kind of cherry-pick the 
> capabilities I support, eg. no preprocessor but yes templates.


Clang's AST file format specifically encodes the Clang AST and all of its bits, so the file format changes as we evolve Clang's internal AST. It's fine for an intermediate format, but I strongly advise against using it as the file format for a GUI tool.

I'd love to see some kind of tree-browsing gadget. I think it's be really useful for understanding you program. Direct AST manipulations will be rather tricky, since the Clang AST is designed to be immutable once created, but you can extend an AST and probably perform some manipulations safely (e.g., replacing a function body with a new function body).

	- Doug



More information about the cfe-dev mailing list