[cfe-dev] AST parsing with CLang: get whole AST tree instead of events (like XML DOM instead of SAX) ?

ramneek onewastedlife at gmail.com
Tue Dec 4 07:20:15 PST 2012


if you trap ASTConsumer::HandleTranslationUnit, it provides you clang::ASTContext (for the TU). Is that what you are looking for?

Btw this is just for one compilation unit. I am still not sure how to do it across multiple translation units.

Here is my test project although i am not using ASTContext directly too though.. 
https://github.com/ramneek-handa/clang-test

I use lib tooling in the example.

Regards,
Ramneek


On Tuesday, 4 December, 2012 at 11:12 PM, Kevin Steiner wrote:

> i'd like to use CLang to parse c++ files to AST. The examples from https://github.com/loarabia/Clang-tutorial look nice, but I don't see any parsing to a structure that would hold the whole parsed AST (i.e. comparable to the DOM tree/document generated by DOM-based XML parsers). Instead, what I see is an event-based parsing API (comparable to SAX for XML parsers) where I subclass clang::ASTConsumer and my class gets events and has to store the tree structure itself somehow.
> So before i do that (and probably re-invent the wheel in the process), I thought I'd better ask: is there some default tree structure that would save the whole parsed AST and that i can keep and use after the parsing is done (i.e. the AST equivalent of a DOM/XMLDomDocument) and some easy way to automatically get that structure filled with the whole AST tree instead of getting events?





More information about the cfe-dev mailing list