I have been able to use CDT’s AST API for parsing source code successfully. My question involves the reverse: How can I build an C AST programmatically, and then tell it to write itself to a file? I have seen the class ASTWriter (but that is internal) and can’t find any tutorials or documentation on building the actual AST.
I have found a paper that goes over the idea of what I want to do: Generating Rewritable Abstract Syntax Trees which makes it seem like generating code would be easy if I could construct the tree and say ‘write yourself’. Is this possible in CDT and how might I get started (preferably without deprecated/internal methods?)
I would recommend you to start with exploring CRefactoring and its subclasses (e.g. ExtractFunctionRefactoring).
There are many problems that CDT refactoring framework tries to address:
I am pretty sure that even if you don’t need all those features, these two classes should be a good starting point.