rewrite Stmts as originally written in source code

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

rewrite Stmts as originally written in source code

Olaf Krzikalla
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
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: rewrite Stmts as originally written in source code

Daniel Dunbar
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
<[hidden email]> 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
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: rewrite Stmts as originally written in source code

Olaf Krzikalla
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


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev