Life span of AST data

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

Life span of AST data

Ilya Mirsky
Greetings,

I'm working on a src-2-src transformer, and I want it to be as modular as possible.
Currently I'm doing the transformations by invoking Rewriter from within ASTConsumer methods.
What I want is to have methods like: setFuncName, insertTextAfterCall etc, which will be separated from the parsing process, and could be invoked independantly. The problem is that all the data generated during the parsing (Decl, Stmt, SourceLocation) is deleted after the parsing ends.

Is there a better way but doing a deep copy of the required data during the parsing?


Thanks,
Ilya


--
Best Regards,
Ilya Mirsky
www.cs.bgu.ac.il/~mirskyil


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Life span of AST data

Douglas Gregor

On Sep 5, 2010, at 12:12 AM, Ilya Mirsky wrote:

> Greetings,
>
> I'm working on a src-2-src transformer, and I want it to be as modular as possible.
> Currently I'm doing the transformations by invoking Rewriter from within ASTConsumer methods.

Good, that's the right approach.

> What I want is to have methods like: setFuncName, insertTextAfterCall etc, which will be separated from the parsing process, and could be invoked independantly. The problem is that all the data generated during the parsing (Decl, Stmt, SourceLocation) is deleted after the parsing ends.

Why can't you just perform all of the necessary operations within ASTConsumer::HandleTranslationUnit?

        - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Life span of AST data

John McCall
In reply to this post by Ilya Mirsky
On Sep 5, 2010, at 12:12 AM, Ilya Mirsky wrote:
> I'm working on a src-2-src transformer, and I want it to be as modular as possible.
> Currently I'm doing the transformations by invoking Rewriter from within ASTConsumer methods.
> What I want is to have methods like: setFuncName, insertTextAfterCall etc, which will be separated from the parsing process, and could be invoked independantly. The problem is that all the data generated during the parsing (Decl, Stmt, SourceLocation) is deleted after the parsing ends.

It's not deleted after parsing ends;  it's deleted when you destroy the ASTContext (or the SourceManager, for SourceLocations).

John.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Life span of AST data

John McCall
In reply to this post by Ilya Mirsky
On Sep 5, 2010, at 12:12 AM, Ilya Mirsky wrote:
> I'm working on a src-2-src transformer, and I want it to be as modular as possible.
> Currently I'm doing the transformations by invoking Rewriter from within ASTConsumer methods.
> What I want is to have methods like: setFuncName, insertTextAfterCall etc, which will be separated from the parsing process, and could be invoked independantly. The problem is that all the data generated during the parsing (Decl, Stmt, SourceLocation) is deleted after the parsing ends.

It's not deleted after parsing ends;  it's deleted when you destroy the ASTContext (or the SourceManager, for SourceLocations).

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