[cfe-dev] Rewriter object is not resetting correctly

Manuel Klimek klimek at google.com
Tue Jun 10 03:37:06 PDT 2014


On Mon, Jun 9, 2014 at 7:37 PM, victor <pedretti_86 at hotmail.com> wrote:

> Hello,
>
> I'm having a strange problem with my clang tool and I would like to report
> it because maybe I'm doing something wrong, but it might be a bug.
>
> My tool simply takes a source file, performs a change in the code and
> saves the new version. The program is under the version control system git
> and the new version is stored in a new git branch. This process is done a
> finite number of times and I reset the Rewriter object between a version
> and the next one (so that the change is not present in the rest of
> versions) in the following way:
>
> Rewrite = Rewriter();
> Rewrite.setSourceMgr(Context->getSourceManager(), Context->getLangOpts());
>
> Everything seemed to work right, but the other day I tested my tool with a
> program and I found something really strange. The problem is that the first
> and only the first change performed in the code remains in all the
> following versiones. For instance, if I insert a comment in each of the
> lines:
>
> Original:
> int method(int a){
>     int b = a + 1;
>     return b;
> }
>
> First version:
> /*1*/ int method(int a){
>     int b = a + 1;
>     return b;
> }
>
> Second version:
> /*1*/ int method(int a){
> /*2*/      int b = a + 1;
>           return b;
> }
>
> Third version:
> /*1*/ int method(int a){
>           int b = a + 1;
> /*3*/    return b;
> }
>
>
> The problem is that the comment "/*1*/" should be only in the first
> version, but not in the rest. As you can see, "/*2*/" is not in the third
> version and that is the expected.
>
> I have tried a lot of things, but nothing seems to solve this issue that
> only appears in this and other program that I tested today.
>
> What could be happening here?
>
> Thanks in advance.
>

My suggestion would be to output all the changes first, and then apply them
with a newly created source-manager and rewriter after-the-fact. That way,
you avoid any problems of how the source manager and rewriter interact.


>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140610/95f29173/attachment.html>


More information about the cfe-dev mailing list