[cfe-dev] C AST transformations / questionable use of AST serialization
David Chisnall
David.Chisnall at cl.cam.ac.uk
Thu Jun 12 00:13:13 PDT 2014
Hi Mark,
On 11 Jun 2014, at 23:10, Mark Tullsen <tullsen at galois.com> wrote:
> seem to be designed for applying changes to the source and cannot
> be readily used to modify the AST (nor the serialized form of the AST).
>
> Correct?
This is correct, but perhaps it would help to understand the rationale behind this. For C, there are very few changes that you can make to the source that have massive impacts on the AST (although changing a typedef would be one example). For C++, there are a lot. Propagating all of the changes from one point in an AST can therefore amount to completely rewriting the AST, and may not even generate a valid one.
For this reason, the clang AST is designed to be immutable (which should make it fit nicely with Haskell...) after creation. To allow arbitrary changes to an AST, followed by the possibility of doing anything sensible to the AST, means reproducing all of the semantic analysis layer for a new input - you'd effectively need to construct a new AST based on a hopefully-valid one. There already exists a fairly good serialisation format for hopefully-valid ASTs: source code.
David
More information about the cfe-dev
mailing list