[cfe-dev] about AST of clang

Manuel Klimek klimek at google.com
Fri Apr 20 15:33:55 PDT 2012

On Fri, Apr 20, 2012 at 9:57 PM, Douglas Gregor <dgregor at apple.com> wrote:
> On Apr 13, 2012, at 2:42 AM, Zhe Chen <mr.zhechen at gmail.com> wrote:
>> Hi Clang list,
>> I noticed there is an AST file format used for higher-level
>> representations of C codes under Clang.
>> What I want to do is make the parse trees of C programs, and then the
>> trees can be edited, e.g., insert new node, modify existing nodes,
>> etc. Finally, I want to compile these modified trees into executables.
>> Is it possible?  Moreso, is it practical?  I'd like to know where can
>> I find such examples or supporting features from clang.
> The Clang AST is not designed to be edited. It can be done, but ensuring that the resulting AST is well-formed is a non-trivial task.

And to propose an alternative solution (which might of course not
apply to the situation at hand): we've had great success with
identifying nodes in the AST that we want to change, mapping it to
source code, doing text transformations on the source code, and then
compiling the resulting source code back into an AST / an executable.


More information about the cfe-dev mailing list