[cfe-dev] Inserting Text After Brace
dgregor at apple.com
Mon Feb 21 12:47:47 PST 2011
On Feb 21, 2011, at 12:35 PM, Gabriel Martinez wrote:
> I have been working on a source-to-source translator using Clang. I have created a Clang plugin with my own ASTConsumer that mainly uses the Rewriter class for performing code transformations. Just had a quick question.
> I am trying to insert some code at the top of the main method, before any other statements. To do this I start by getting the location of the left brace using CompoundStmts getLBracLoc method. This works fine, but when I then try to insert text after that location with Rewriter's InsertTextAfter, it inserts it before the brace. Is this an expected behavior?
Yes, insertion inserts before the beginning of the source location.
> If so, any recommendations on how to accomplish what I'm trying to do?
You want Preprocessor::getLocForEndOfToken().
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev