0

I am looking for a C/C++ library. It should be able to parse C++ source code and generate abstract syntax tree. I would also like to explore/edit the AST from my program, for example to add a function call. This means, the syntax tree should not be in some text format, but as a collection of C++ objects, based on the object model of the library itself.

It should also be able to generate C++ code from an AST.

It is clear that any compiler does this and probably has some API. I have heard that GCC exposes some functionality, but it is quite overwhelming under the hood.

I am aware of Elsa, but the project seems to be inactive for quite some time.

I was wondering if there are other options. Anything that is cross-platform is a plus.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
Sogartar
  • 2,035
  • 2
  • 19
  • 35

1 Answers1

1

clang and libtooling is what you are looking for. It is able to do everything you want, but the downside is that it's not very well documented (to my knowledge). Here is a blog post with useful examples: http://eli.thegreenplace.net/2014/05/01/modern-source-to-source-transformation-with-clang-and-libtooling

Tamás Szelei
  • 23,169
  • 18
  • 105
  • 180