[cfe-dev] about AST of clang

Ronan Keryell Ronan.Keryell at wild-systems.com
Fri Apr 20 17:55:29 PDT 2012

> On Fri, Apr 20, 2012 at 9:57 PM, Douglas Gregor <dgregor at apple.com> wrote:

    >> 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.

>>>>> On Sat, 21 Apr 2012 00:33:55 +0200, Manuel Klimek <klimek at google.com> said:

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

Because of a lack of resources, we did this more than 15 years ago in
another compiler we work on and it is still there. Now I really
understand in the real life this concept:

So, yes it works on some simple cases... But it is a nightmare to have
to apply patches on a kludge when you have to improve the parser or
change the internal representation only a little bit or to deal with
more general cases.

That is why we are thinking to add support to Clang to have a
cleaner way to have source-to-source transformations that preserve
comments and so on.
  Ronan KERYELL                          |\/  Phone:  +1 408 658 9453
  Wild Systems / HPC Project             |/)
  5201 Great America Parkway, Suite 320  K    Ronan.Keryell at wild-systems.com
  Santa Clara, CA 95054                  |\   skype:keryell
  USA                                    | \  http://wild-systems.com

More information about the cfe-dev mailing list