[cfe-dev] Clang-Rename usage multiple files

Manuel Klimek klimek at google.com
Sun Mar 22 00:49:43 PDT 2015


+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 <http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev>> 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/2a936ce9/attachment.html>


More information about the cfe-dev mailing list