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

Olaf Krzikalla Olaf.Krzikalla at tu-dresden.de
Thu Jun 10 03:13:20 PDT 2010


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




More information about the cfe-dev mailing list