I’m a little confused with the documentation, is there something equivalent to -ast-dump but producing actual C++ code which has a mutable data-structure?
In Python I have this:
…and the class_reduction_v2.body is a mutable property (to a regular list).
I’ve started filling things out, but it’s not obvious what to put where…
How do I construct a mutable clang::RecordDecl with clang::FieldDecl and a name?
(C not C++ is my focus, so don’t need to worry about inheritance, member visibility, &etc.)
No, the clang AST is tightly coupled to language semantics (with syntax present, but somewhat second-class). It doesn’t support syntactic mutation.
We’d like to have such a thing, producing a different data structure that follows the grammar (syntax trees) either directly from source code or guided by a clang parse (pseudo parser RFC) but it’s not done yet - @hokein and I are working on this this year.
Be aware such a structure would follow the grammar, and the grammatical structure of C/C++ doesn’t match most people’s mental model as well as e.g. python’s does, so it’s going to be more awkward to use.
(e.g. a “struct definition” isn’t a top-level thing, but a type specifier within a declaration that often happens to have no declarators).