[cfe-dev] Source to Source Transformation guide lines

Magnus Reftel magnus.reftel at gmail.com
Tue Apr 6 02:23:53 PDT 2010


Hi,

On 5 April 2010 10:48, moataz ragab <mtzrgb at gmail.com> wrote:
> There are two approaches for tsource-to-source
> transformation (Rewriting, AST re-build). Im the Rewriting approach the AST
> is traversed and the transformed code is generated as you traverse the AST,
> this is what is used in RewriteObjC. The other approach is to build the
> transformed AST from the original AST and then use the prettyprinter to
> generate the code. This approach is flexible and allows you to apply a chain
> of transformations on the AST.

There is a third option as well: traverse the AST and make notes of
changes that need to be made and where, and then search-and-replace in
the source text (e.g. by alternating between coying from the source
and from a modification to a new file). I used that with good results
for a tool that did some fancy search-and-replace on hand-written code
that will stay maintained by humans. The only problem I've run into is
that getting the actual source position for something can be tricky
(but possible) when it's a macro.

Best Regards
Magnus Reftel



More information about the cfe-dev mailing list