can Clang Plugin modify the AST and send it back to the next step of compliation?

All the examples of Clang plugin and FrontendActions I’ve read are to get the AST and print some information, I’m curious if I can modify the AST to make some dialect C++ language?

I got some examples I think is easy to do if AST could be modified:

  1. make all subclasses inherit baseclasses’ friend class
  2. make all method virtual (like Java)

Hi,

Hi Miklos, I think applying replacements to original source file is not what I expect, it does not act as a “dialect” to me.

What I want to do gives a feeling of “AST programming” (I just made up this term).

You can have a plugin AST action run before the ‘main’ action (i.e. before compilation) which means that the AST after
the action has run is what is compiled. There’s an example at
https://github.com/llvm/llvm-project/blob/master/clang/examples/AnnotateFunctions/AnnotateFunctions.cpp
which modifies the AST by adding function attributes.

John