[cfe-dev] Clang-Rename usage multiple files

Matthew Plant maplant2 at illinois.edu
Sun Mar 22 14:53:35 PDT 2015


I can't say that I'm entirely sure why this happens; I haven't looked at the code in a long time, and even when it was submitted it was far from complete - I had the intention of pushing more updates, but then school was all "nope." 

Here are some issues I have with the code right now that could possibly explain the problem:

• The file we check for the name in is the first file returned by CommonOptionsParser::getSourceFileList. I have no idea what order that actually is - it is something I should have determined.

• There are a bunch of methods left out of both of the visitors (I have the cases I some file on my Dropbox, but never got the chance to submit a patch). This could be the reason the parens are being overwritten. 

There is nothing I would like to do more than fix these issues. Unfortunately it is spring break and I am far away from any computer that I could use.

My advice for now: don't use clang rename. Or: fix clang rename before using it. 

Regardless, file a bug report if that's even possible for clang tools extra, and I will try to determine the problem within the coming month before classes start to kick my posterior again. It's very unfortunate for my pride that the only acknowledgement of my work has been how bloody broken it is, so I will try to rectify that.

-M

> On Mar 22, 2015, at 12:49 AM, Manuel Klimek <klimek at google.com> wrote:
> 
> +matthew
> 
>> On Sun, Mar 22, 2015 at 7:03 AM Johan Fänge <johanfange at gmail.com> wrote:
>> I saw this mail from December and decided to give it a try. Short investigation below.
>> Best Regards
>> Johan Fänge
>> ----------
>> 
>> It does indeed work on the given example after some tweaking, but breaks down on something slightly more complex.
>> 
>> I added another file:
>> 
>> ~/test $ cat foo2.c
>> #include "foo.h"
>> 
>> int fox (int x, int y, int zz)
>> {
>>     return foo(x,x) + foo(y,y) - zz;
>> }
>> 
>> ... and used this invocation: clang-rename foo2.c foo.c main.c -offset=46 -new-name=sum200 -pn -pl
>> 
>> As you can see below, it also tries to rename zz in foo2.c (which is at offset 46). What's worse: it overwrites the code following it, including the parenthesis after the argument list and the comma in the statement below.
>> 
>> 
>> ~/test $ clang-rename foo2.c foo.c main.c -offset=46 -new-name=sum200 -pn -pl
>> clang-rename: could not find symbol at :1:1 (offset 46).
>> clang-rename: found name: fooclang-rename: renamed at: foo2.c:3:28
>> clang-rename: renamed at: foo2.c:5:34
>> clang-rename: renamed at: ./foo.h:1:12
>> clang-rename: renamed at: foo2.c:5:12
>> clang-rename: renamed at: foo2.c:5:23
>> clang-rename: renamed at: foo.c:1:5
>> clang-rename: renamed at: ./foo.h:1:12
>> clang-rename: renamed at: main.c:4:12
>> #include "foo.h"
>> 
>> int fox (int x, int y, int sum200
>> {
>>     return sum200(x,x) + sum200(y,y) - sum200
>> }
>> int sum200 (int x, int y)
>> {
>>     return x + y;
>> }
>> #include "foo.h"
>> int main (void)
>> {
>>     return sum200(1, 1);
>> }
>> 
>> 
>> Another example:
>> ~/test $ cat foo2.c
>> #include "foo.h"
>> 
>> int fox (int x, int y, int zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz)
>> {
>>     return foo(x,x) + foo(y,y) - zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz;
>> }
>> 
>> ~/test $ clang-rename foo2.c foo.c main.c -offset=46 -new-name=sum200 -pn -pl
>> clang-rename: could not find symbol at :1:1 (offset 46).
>> clang-rename: found name: fooclang-rename: renamed at: foo2.c:3:28
>> clang-rename: renamed at: foo2.c:5:34
>> clang-rename: renamed at: ./foo.h:1:12
>> clang-rename: renamed at: foo2.c:5:12
>> clang-rename: renamed at: foo2.c:5:23
>> clang-rename: renamed at: foo.c:1:5
>> clang-rename: renamed at: ./foo.h:1:12
>> clang-rename: renamed at: main.c:4:12
>> #include "foo.h"
>> 
>> int fox (int x, int y, int sum200zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz)
>> {
>>     return sum200(x,x) + sum200(y,y) - sum200zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz;
>> }
>> int sum200 (int x, int y)
>> {
>>     return x + y;
>> }
>> #include "foo.h"
>> int main (void)
>> {
>>     return sum200(1, 1);
>> }
>> 
>> 
>> --------
>> 
>> Your command invocation only includes main.c, try adding foo.c as well.
>> 
>> -M
>> 
>> > On Dec 9, 2014, at 2:27 PM, Dan Walmsley <dan at walms.co.uk> wrote:
>> > 
>> > Hello,
>> > 
>> >     I have managed to compile clang-rename and to get it to rename some symbols.
>> > 
>> > I have simple example I cant get to work correctly if anyone can help me out it would be greatly appreciated.
>> > 
>> > 3 files:
>> > 
>> > [foo.c]
>> > int foo (int x, int y)
>> > {
>> >     return x + y;
>> > }
>> > 
>> > [foo.h]
>> > extern int foo (int x, int y);
>> > 
>> > [main.c]
>> > #include "foo.h"
>> > int main (void)
>> > {
>> >     return foo(1, 1);
>> > }
>> > 
>> > [compile_commands.json]
>> > [
>> > {
>> >   "directory": "c:\\ClangRenameTest\\",
>> >   "command": "clang main.c",
>> >   "file": "main.c"
>> > },
>> > {
>> >   "directory": "c:\\ClangRenameTest\\",
>> >   "command": "clang foo.c",
>> >   "file": "foo.c"
>> > }
>> > ]
>> > 
>> > I run clang-rename with the following arguments:
>> > 
>> > "clang-rename main.c -offset=50 -i -new-name=sum -pl"
>> > 
>> > All the instances of foo are renamed to sum except in foo.c.
>> > 
>> > Can anyone help me how to get clang-rename to work for foo.c also?
>> > 
>> > Any advice is greatly appreciated.
>> > 
>> > Dan
>> _______________________________________________
>> 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/20150322/701b465a/attachment.html>


More information about the cfe-dev mailing list