57 changes: 52 additions & 5 deletions clang-tools-extra/docs/clang-rename.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ To get an offset of a symbol in a file run
$ grep -FUbo 'foo' file.cpp
You can also identify one or more symbols to be renamed by giving the fully qualified
name:

.. code-block:: console
$ clang-rename rename-all -old-name=foo -new-name=bar test.cpp
The tool currently supports renaming actions inside a single Translation Unit
only. It is planned to extend the tool's functionality to support multi-TU
renaming actions in the future.
Expand All @@ -55,34 +63,73 @@ text editor interface instead for better experience.
.. code-block:: console
$ clang-rename -help
Usage: clang-rename {rename-at|rename-all} [OPTION]...
A tool to rename symbols in C/C++ code.
Subcommands:
rename-at: Perform rename off of a location in a file. (This is the default.)
rename-all: Perform rename of all symbols matching one or more fully qualified names.
.. code-block:: console
$ clang-rename rename-at -help
OVERVIEW: A tool to rename symbols in C/C++ code.
clang-rename renames every occurrence of a symbol found at <offset> in
<source0>. If -i is specified, the edited files are overwritten to disk.
Otherwise, the results are written to stdout.
USAGE: clang-rename [subcommand] [options] <source0> [... <sourceN>]
USAGE: clang-rename rename-at [subcommand] [options] <source0> [... <sourceN>]
OPTIONS:
Generic Options:
-help - Display available options (-help-hidden for more)
-help-list - Display list of available options (-help-list-hidden for more)
-version - Display the version of this program
Clang-rename options:
clang-rename rename-at options:
-export-fixes=<filename> - YAML file to store suggested fixes in.
-extra-arg=<string> - Additional argument to append to the compiler command line
-extra-arg-before=<string> - Additional argument to prepend to the compiler command line
-i - Overwrite edited <file>s.
-new-name=<string> - The new name to change the symbol to.
-offset=<uint> - Locates the symbol by offset as opposed to <line>:<column>.
-old-name=<string> - The fully qualified name of the symbol, if -offset is not used.
-p=<string> - Build path
-pl - Print the locations affected by renaming to stderr.
-pn - Print the found symbol's name prior to renaming to stderr.
.. code-block:: console
$ clang-rename rename-all -help
OVERVIEW: A tool to rename symbols in C/C++ code.
clang-rename renames every occurrence of a symbol named <old-name>.
USAGE: clang-rename rename-all [subcommand] [options] <source0> [... <sourceN>]
OPTIONS:
Generic Options:
-help - Display available options (-help-hidden for more)
-help-list - Display list of available options (-help-list-hidden for more)
-version - Display the version of this program
clang-rename rename-all options:
-export-fixes=<filename> - YAML file to store suggested fixes in.
-extra-arg=<string> - Additional argument to append to the compiler command line
-extra-arg-before=<string> - Additional argument to prepend to the compiler command line
-i - Overwrite edited <file>s.
-new-name=<string> - The new name to change the symbol to.
-offset=<uint> - Locates the symbol by offset as opposed to <line>:<column>.
-old-name=<string> - The fully qualified name of the symbol, if -offset is not used.
-p=<string> - Build path
Vim Integration
===============
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/test/clang-rename/ClassFindByName.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename -old-name=Foo -new-name=Bar %t.cpp -i --
// RUN: clang-rename rename-all -old-name=Foo -new-name=Bar %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s

class Foo { // CHECK: class Bar
Expand Down
8 changes: 8 additions & 0 deletions clang-tools-extra/test/clang-rename/ClassTestMulti.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename rename-all -offset=174 -new-name=Bar1 -offset=212 -new-name=Bar2 %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
class Foo1 { // CHECK: class Bar1
};

class Foo2 { // CHECK: class Bar2
};
8 changes: 8 additions & 0 deletions clang-tools-extra/test/clang-rename/ClassTestMultiByName.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename rename-all -old-name=Foo1 -new-name=Bar1 -old-name=Foo2 -new-name=Bar2 %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
class Foo1 { // CHECK: class Bar1
};

class Foo2 { // CHECK: class Bar2
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename -old-name=Foo -new-name=Bar %t.cpp -i --
// RUN: clang-rename rename-all -old-name=Foo -new-name=Bar %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s

void foo() {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/test/clang-rename/NoNewName.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Check for an error while -new-name argument has not been passed to
// clang-rename.
// RUN: not clang-rename -offset=133 %s 2>&1 | FileCheck %s
// CHECK: ERROR: no new name provided.
// CHECK: clang-rename: for the -new-name option: must be specified