[cfe-dev] Inserting Text After Brace

Gabriel Martinez mystal at vt.edu
Mon Feb 21 12:35:59 PST 2011


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? If so, any
recommendations on how to accomplish what I'm trying to do?


Thanks!
Gabriel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110221/b5dc81c6/attachment.html>


More information about the cfe-dev mailing list