rewrite Stmts as originally written in source code

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

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

Daniel Dunbar schrieb:

Clang provides a rewriter framework that lets you put edits in, which
otherwise maintain the original source,

Hmm, that's not what I need. Sometimes the IntegerLiterals are cloned
nodes and I want to preserve their original appearance even then. I
thought this could be done by looking in the original source code with
the help of the source location infos. But atm it looks rather difficult.

Thanks anyway
Olaf