[cfe-dev] rewrite Stmts as originally written in source code

Daniel Dunbar daniel at zuster.org
Thu Jun 10 07:10:58 PDT 2010


Clang provides a rewriter framework that lets you put edits in, which
otherwise maintain the original source, but we don't have anything to
do something more sophisticated with macros.

 - Daniel

On Thu, Jun 10, 2010 at 3:13 AM, Olaf Krzikalla
<Olaf.Krzikalla at tu-dresden.de> wrote:
> Hi @clang,
>
> I wonder if it is already possible to rewrite an AST node (at least Stmt
> and derived classes) exactly as it was written in source code.
> Actually I want to reconstruct macros in the target rewritten file.
> IntegerLiteral is a good example:
>
> #define ARG_TEST(a) a
> #define TEST 2
>
> int i = TEST;
> int j = ARG_TEST(1);
> int k = ARG_TEST(TEST);
>
> All three cases should work.
> Stmt->getSourceRange seems not to help here: IntegerLiteral just returns
> SourceRange(loc, loc). Computing the actual end of the literal can
> become hairy esp. for the initializer of j and k.
> Does clang already provide any means for this form of rewriting or am I
> on my own?
>
> Best regards
> Olaf Krzikalla
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>



More information about the cfe-dev mailing list