[cfe-dev] Rewriting AST through Clang's LibTooling APIs

George Karpenkov via cfe-dev cfe-dev at lists.llvm.org
Wed Jun 13 17:56:46 PDT 2018



> On Jun 13, 2018, at 1:30 PM, Koustubha Bhat via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Hi All,
> 
> I am exploring the LibTooling APIs to parse and perform targeted modifications to the AST.
> I see that Rewriter interface allows to insert or replace text, however the writing remains in terms of text. 
> May I know if rewriting the AST itself by means of inserting or modifying AST nodes, is supported?

To the best of my knowledge, not really.
There are a couple of places which do that: BodyFarm.cpp file in the static analyzer, and ASTImporter,
used in LLDB and the static analyzer.
Both usages are very often broken: the main problem is that once you start modifying the AST,
the chances of violating some internal invariants is pretty high,
and there’s no way to “check” that the modified AST is correct.

> 
> Thank you.
> 
> Regards,
> Koustubha
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list