From 40c45b6b43180221acb49f387e7d3158adf49e3e Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Wed, 18 Sep 2024 08:25:58 -0400 Subject: [PATCH] Remove clang-rename (#108988) clang-rename has largely been superseded by clangd and this project hasn't received much attention in many years. Further, our documentation on it still claims it's in very early stages of development despite being ~10 years old. One of the primary people driving the tool has mentioned that they don't believe there is a reason to continue to support it unless it's still being actively used (https://reviews.llvm.org/D148439#4303202) and I've found no evidence to suggest that is the case. Original RFC: https://discourse.llvm.org/t/rfc-time-to-deprecate-remove-clang-rename/70707 --- clang-tools-extra/CODE_OWNERS.TXT | 2 +- clang-tools-extra/docs/ReleaseNotes.rst | 3 - clang-tools-extra/docs/clang-rename.rst | 168 ---- clang-tools-extra/docs/index.rst | 1 - clang-tools-extra/test/CMakeLists.txt | 3 - .../ClangRenameClassReplacements.cpp | 11 - clang/docs/ClangFormattedStatus.rst | 5 - clang/docs/ReleaseNotes.rst | 2 + clang/docs/tools/clang-formatted-files.txt | 1 - clang/test/CMakeLists.txt | 1 - .../clang-rename/ClassAsTemplateArgument.cpp | 21 - clang/test/clang-rename/ClassFindByName.cpp | 10 - .../test/clang-rename/ClassSimpleRenaming.cpp | 14 - clang/test/clang-rename/ClassTestMulti.cpp | 11 - .../clang-rename/ClassTestMultiByName.cpp | 8 - .../clang-rename/ComplexFunctionOverride.cpp | 47 - .../clang-rename/ComplicatedClassType.cpp | 63 -- clang/test/clang-rename/Ctor.cpp | 14 - clang/test/clang-rename/CtorInitializer.cpp | 17 - clang/test/clang-rename/DeclRefExpr.cpp | 24 - clang/test/clang-rename/ForceMulti.cpp | 8 - clang/test/clang-rename/ForwardClassDecl.cpp | 4 - clang/test/clang-rename/FunctionMacro.cpp | 20 - clang/test/clang-rename/FunctionOverride.cpp | 13 - clang/test/clang-rename/FunctionTemplate.cpp | 19 - .../FunctionWithClassFindByName.cpp | 12 - .../clang-rename/IncludeHeaderWithSymbol.cpp | 10 - .../clang-rename/Inputs/HeaderWithSymbol.h | 1 - .../clang-rename/Inputs/OffsetToNewName.yaml | 6 - .../Inputs/QualifiedNameToNewName.yaml | 6 - clang/test/clang-rename/InvalidNewName.cpp | 2 - clang/test/clang-rename/InvalidOffset.cpp | 9 - .../clang-rename/InvalidQualifiedName.cpp | 4 - clang/test/clang-rename/MemberExprMacro.cpp | 22 - clang/test/clang-rename/Namespace.cpp | 13 - clang/test/clang-rename/NoNewName.cpp | 4 - clang/test/clang-rename/NonExistFile.cpp | 2 - .../TemplateClassInstantiation.cpp | 42 - clang/test/clang-rename/TemplateCtor.cpp | 10 - clang/test/clang-rename/TemplateTypename.cpp | 24 - .../clang-rename/TemplatedClassFunction.cpp | 27 - clang/test/clang-rename/Typedef.cpp | 8 - .../clang-rename/UserDefinedConversion.cpp | 26 - clang/test/clang-rename/Variable.cpp | 33 - clang/test/clang-rename/VariableMacro.cpp | 21 - clang/test/clang-rename/VariableTemplate.cpp | 32 - clang/test/clang-rename/YAMLInput.cpp | 10 - clang/tools/CMakeLists.txt | 1 - clang/tools/clang-rename/CMakeLists.txt | 26 - clang/tools/clang-rename/ClangRename.cpp | 242 ------ clang/tools/clang-rename/clang-rename.el | 80 -- clang/tools/clang-rename/clang-rename.py | 70 -- clang/unittests/CMakeLists.txt | 1 - clang/unittests/Rename/CMakeLists.txt | 29 - clang/unittests/Rename/ClangRenameTest.h | 116 --- clang/unittests/Rename/RenameAliasTest.cpp | 303 ------- clang/unittests/Rename/RenameClassTest.cpp | 820 ------------------ clang/unittests/Rename/RenameEnumTest.cpp | 189 ---- clang/unittests/Rename/RenameFunctionTest.cpp | 573 ------------ clang/unittests/Rename/RenameMemberTest.cpp | 228 ----- .../secondary/clang-tools-extra/test/BUILD.gn | 1 - llvm/utils/gn/secondary/clang/test/BUILD.gn | 1 - .../clang/tools/clang-rename/BUILD.gn | 14 - .../llvm-project-overlay/clang/BUILD.bazel | 15 - 64 files changed, 3 insertions(+), 3520 deletions(-) delete mode 100644 clang-tools-extra/docs/clang-rename.rst delete mode 100644 clang-tools-extra/test/clang-apply-replacements/ClangRenameClassReplacements.cpp delete mode 100644 clang/test/clang-rename/ClassAsTemplateArgument.cpp delete mode 100644 clang/test/clang-rename/ClassFindByName.cpp delete mode 100644 clang/test/clang-rename/ClassSimpleRenaming.cpp delete mode 100644 clang/test/clang-rename/ClassTestMulti.cpp delete mode 100644 clang/test/clang-rename/ClassTestMultiByName.cpp delete mode 100644 clang/test/clang-rename/ComplexFunctionOverride.cpp delete mode 100644 clang/test/clang-rename/ComplicatedClassType.cpp delete mode 100644 clang/test/clang-rename/Ctor.cpp delete mode 100644 clang/test/clang-rename/CtorInitializer.cpp delete mode 100644 clang/test/clang-rename/DeclRefExpr.cpp delete mode 100644 clang/test/clang-rename/ForceMulti.cpp delete mode 100644 clang/test/clang-rename/ForwardClassDecl.cpp delete mode 100644 clang/test/clang-rename/FunctionMacro.cpp delete mode 100644 clang/test/clang-rename/FunctionOverride.cpp delete mode 100644 clang/test/clang-rename/FunctionTemplate.cpp delete mode 100644 clang/test/clang-rename/FunctionWithClassFindByName.cpp delete mode 100644 clang/test/clang-rename/IncludeHeaderWithSymbol.cpp delete mode 100644 clang/test/clang-rename/Inputs/HeaderWithSymbol.h delete mode 100644 clang/test/clang-rename/Inputs/OffsetToNewName.yaml delete mode 100644 clang/test/clang-rename/Inputs/QualifiedNameToNewName.yaml delete mode 100644 clang/test/clang-rename/InvalidNewName.cpp delete mode 100644 clang/test/clang-rename/InvalidOffset.cpp delete mode 100644 clang/test/clang-rename/InvalidQualifiedName.cpp delete mode 100644 clang/test/clang-rename/MemberExprMacro.cpp delete mode 100644 clang/test/clang-rename/Namespace.cpp delete mode 100644 clang/test/clang-rename/NoNewName.cpp delete mode 100644 clang/test/clang-rename/NonExistFile.cpp delete mode 100644 clang/test/clang-rename/TemplateClassInstantiation.cpp delete mode 100644 clang/test/clang-rename/TemplateCtor.cpp delete mode 100644 clang/test/clang-rename/TemplateTypename.cpp delete mode 100644 clang/test/clang-rename/TemplatedClassFunction.cpp delete mode 100644 clang/test/clang-rename/Typedef.cpp delete mode 100644 clang/test/clang-rename/UserDefinedConversion.cpp delete mode 100644 clang/test/clang-rename/Variable.cpp delete mode 100644 clang/test/clang-rename/VariableMacro.cpp delete mode 100644 clang/test/clang-rename/VariableTemplate.cpp delete mode 100644 clang/test/clang-rename/YAMLInput.cpp delete mode 100644 clang/tools/clang-rename/CMakeLists.txt delete mode 100644 clang/tools/clang-rename/ClangRename.cpp delete mode 100644 clang/tools/clang-rename/clang-rename.el delete mode 100644 clang/tools/clang-rename/clang-rename.py delete mode 100644 clang/unittests/Rename/CMakeLists.txt delete mode 100644 clang/unittests/Rename/ClangRenameTest.h delete mode 100644 clang/unittests/Rename/RenameAliasTest.cpp delete mode 100644 clang/unittests/Rename/RenameClassTest.cpp delete mode 100644 clang/unittests/Rename/RenameEnumTest.cpp delete mode 100644 clang/unittests/Rename/RenameFunctionTest.cpp delete mode 100644 clang/unittests/Rename/RenameMemberTest.cpp delete mode 100644 llvm/utils/gn/secondary/clang/tools/clang-rename/BUILD.gn diff --git a/clang-tools-extra/CODE_OWNERS.TXT b/clang-tools-extra/CODE_OWNERS.TXT index 4cf80aa2b0b8..2831ec7e25f5 100644 --- a/clang-tools-extra/CODE_OWNERS.TXT +++ b/clang-tools-extra/CODE_OWNERS.TXT @@ -23,7 +23,7 @@ D: clang-tidy N: Manuel Klimek E: klimek@google.com -D: clang-rename, all parts of clang-tools-extra not covered by someone else +D: all parts of clang-tools-extra not covered by someone else N: Sam McCall E: sammccall@google.com diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 2370b594d222..d284bb62f7c7 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -87,9 +87,6 @@ Improvements to clang-doc Improvements to clang-query --------------------------- -Improvements to clang-rename ----------------------------- - The improvements are... Improvements to clang-tidy diff --git a/clang-tools-extra/docs/clang-rename.rst b/clang-tools-extra/docs/clang-rename.rst deleted file mode 100644 index e13d8c3ad25f..000000000000 --- a/clang-tools-extra/docs/clang-rename.rst +++ /dev/null @@ -1,168 +0,0 @@ -============ -Clang-Rename -============ - -.. contents:: - -See also: - -.. toctree:: - :maxdepth: 1 - - -:program:`clang-rename` is a C++ refactoring tool. Its purpose is to perform -efficient renaming actions in large-scale projects such as renaming classes, -functions, variables, arguments, namespaces etc. - -The tool is in a very early development stage, so you might encounter bugs and -crashes. Submitting reports with information about how to reproduce the issue -to `the LLVM bugtracker `_ will definitely help the -project. If you have any ideas or suggestions, you might want to put a feature -request there. - -Using Clang-Rename -================== - -:program:`clang-rename` is a `LibTooling -`_-based tool, and it's easier to -work with if you set up a compile command database for your project (for an -example of how to do this see `How To Setup Tooling For LLVM -`_). You can also -specify compilation options on the command line after `--`: - -.. code-block:: console - - $ clang-rename -offset=42 -new-name=foo test.cpp -- -Imy_project/include -DMY_DEFINES ... - - -To get an offset of a symbol in a file run - -.. code-block:: console - - $ grep -FUbo 'foo' file.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. - -:program:`clang-rename` also aims to be easily integrated into popular text -editors, such as Vim and Emacs, and improve the workflow of users. - -Although a command line interface exists, it is highly recommended to use the -text editor interface instead for better experience. - -You can also identify one or more symbols to be renamed by giving the fully -qualified name: - -.. code-block:: console - - $ clang-rename -qualified-name=foo -new-name=bar test.cpp - -Renaming multiple symbols at once is supported, too. However, -:program:`clang-rename` doesn't accept both `-offset` and `-qualified-name` at -the same time. So, you can either specify multiple `-offset` or -`-qualified-name`. - -.. code-block:: console - - $ clang-rename -offset=42 -new-name=bar1 -offset=150 -new-name=bar2 test.cpp - -or - -.. code-block:: console - - $ clang-rename -qualified-name=foo1 -new-name=bar1 -qualified-name=foo2 -new-name=bar2 test.cpp - - -Alternatively, {offset | qualified-name} / new-name pairs can be put into a YAML -file: - -.. code-block:: yaml - - --- - - Offset: 42 - NewName: bar1 - - Offset: 150 - NewName: bar2 - ... - -or - -.. code-block:: yaml - - --- - - QualifiedName: foo1 - NewName: bar1 - - QualifiedName: foo2 - NewName: bar2 - ... - -That way you can avoid spelling out all the names as command line arguments: - -.. code-block:: console - - $ clang-rename -input=test.yaml test.cpp - -:program:`clang-rename` offers the following options: - -.. code-block:: console - - $ clang-rename --help - USAGE: clang-rename [subcommand] [options] [... ] - - 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 common options: - - -export-fixes= - YAML file to store suggested fixes in. - -extra-arg= - Additional argument to append to the compiler command line - Can be used several times. - -extra-arg-before= - Additional argument to prepend to the compiler command line - Can be used several times. - -force - Ignore nonexistent qualified names. - -i - Overwrite edited s. - -input= - YAML file to load oldname-newname pairs from. - -new-name= - The new name to change the symbol to. - -offset= - Locates the symbol by offset as opposed to :. - -p - Build path - -pl - Print the locations affected by renaming to stderr. - -pn - Print the found symbol's name prior to renaming to stderr. - -qualified-name= - The fully qualified name of the symbol. - -Vim Integration -=============== - -You can call :program:`clang-rename` directly from Vim! To set up -:program:`clang-rename` integration for Vim see -`clang/tools/clang-rename/clang-rename.py -`_. - -Please note that **you have to save all buffers, in which the replacement will -happen before running the tool**. - -Once installed, you can point your cursor to symbols you want to rename, press -`cr` and type new desired name. The ` key -`_ -is a reference to a specific key defined by the mapleader variable and is bound -to backslash by default. - -Emacs Integration -================= - -You can also use :program:`clang-rename` while using Emacs! To set up -:program:`clang-rename` integration for Emacs see -`clang-rename/tool/clang-rename.el -`_. - -Once installed, you can point your cursor to symbols you want to rename, press -`M-X`, type `clang-rename` and new desired name. - -Please note that **you have to save all buffers, in which the replacement will -happen before running the tool**. diff --git a/clang-tools-extra/docs/index.rst b/clang-tools-extra/docs/index.rst index d5c00b89a155..9f7324fcf741 100644 --- a/clang-tools-extra/docs/index.rst +++ b/clang-tools-extra/docs/index.rst @@ -19,7 +19,6 @@ Contents clang-include-fixer modularize pp-trace - clang-rename clangd clang-doc diff --git a/clang-tools-extra/test/CMakeLists.txt b/clang-tools-extra/test/CMakeLists.txt index 0953ff2531e1..d72a117166a0 100644 --- a/clang-tools-extra/test/CMakeLists.txt +++ b/clang-tools-extra/test/CMakeLists.txt @@ -28,9 +28,6 @@ configure_lit_site_cfg( ) set(CLANG_TOOLS_TEST_DEPS - # For the clang-apply-replacements test that uses clang-rename. - clang-rename - # For the clang-doc tests that emit bitcode files. llvm-bcanalyzer diff --git a/clang-tools-extra/test/clang-apply-replacements/ClangRenameClassReplacements.cpp b/clang-tools-extra/test/clang-apply-replacements/ClangRenameClassReplacements.cpp deleted file mode 100644 index 2b478bbf900d..000000000000 --- a/clang-tools-extra/test/clang-apply-replacements/ClangRenameClassReplacements.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// RUN: rm -rf %t -// RUN: mkdir -p %t/fixes -// RUN: cat %s > %t.cpp -// RUN: clang-rename -offset=254 -new-name=Bar -export-fixes=%t/fixes/clang-rename.yaml %t.cpp -- -// RUN: clang-apply-replacements %t -// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s - -class Foo {}; // CHECK: class Bar {}; - -// Use grep -FUbo 'Foo' to get the correct offset of Cla when changing -// this file. diff --git a/clang/docs/ClangFormattedStatus.rst b/clang/docs/ClangFormattedStatus.rst index 0ee0782879ef..b917e077679b 100644 --- a/clang/docs/ClangFormattedStatus.rst +++ b/clang/docs/ClangFormattedStatus.rst @@ -809,11 +809,6 @@ tree in terms of conformance to :doc:`ClangFormat` as of: March 06, 2022 17:32:2 - `4` - `0` - :good:`100%` - * - clang/tools/clang-rename - - `1` - - `1` - - `0` - - :good:`100%` * - clang/tools/clang-repl - `1` - `1` diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index dd004228b679..7b612e3c65f4 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -39,6 +39,8 @@ code bases. - The ``le32`` and ``le64`` targets have been removed. +- The ``clang-rename`` tool has been removed. + C/C++ Language Potentially Breaking Changes ------------------------------------------- diff --git a/clang/docs/tools/clang-formatted-files.txt b/clang/docs/tools/clang-formatted-files.txt index 48ded9c75455..fa40ea74fb7e 100644 --- a/clang/docs/tools/clang-formatted-files.txt +++ b/clang/docs/tools/clang-formatted-files.txt @@ -608,7 +608,6 @@ clang/tools/clang-refactor/ClangRefactor.cpp clang/tools/clang-refactor/TestSupport.cpp clang/tools/clang-refactor/TestSupport.h clang/tools/clang-refactor/ToolRefactoringResultConsumer.h -clang/tools/clang-rename/ClangRename.cpp clang/tools/clang-repl/ClangRepl.cpp clang/tools/clang-scan-deps/ClangScanDeps.cpp clang/tools/clang-shlib/clang-shlib.cpp diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt index 299a35723b59..2d84b0d73053 100644 --- a/clang/test/CMakeLists.txt +++ b/clang/test/CMakeLists.txt @@ -72,7 +72,6 @@ list(APPEND CLANG_TEST_DEPS clang-tblgen clang-offload-bundler clang-import-test - clang-rename clang-refactor clang-diff clang-installapi diff --git a/clang/test/clang-rename/ClassAsTemplateArgument.cpp b/clang/test/clang-rename/ClassAsTemplateArgument.cpp deleted file mode 100644 index 2e09a5b529e7..000000000000 --- a/clang/test/clang-rename/ClassAsTemplateArgument.cpp +++ /dev/null @@ -1,21 +0,0 @@ -class Foo /* Test 1 */ {}; // CHECK: class Bar /* Test 1 */ {}; - -template -void func() {} - -template -class Baz {}; - -int main() { - func(); // CHECK: func(); - Baz /* Test 2 */ obj; // CHECK: Baz /* Test 2 */ obj; - return 0; -} - -// Test 1. -// RUN: clang-rename -offset=7 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=215 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/ClassFindByName.cpp b/clang/test/clang-rename/ClassFindByName.cpp deleted file mode 100644 index 4430891ec4b1..000000000000 --- a/clang/test/clang-rename/ClassFindByName.cpp +++ /dev/null @@ -1,10 +0,0 @@ -class Foo { // CHECK: class Bar { -}; - -int main() { - Foo *Pointer = 0; // CHECK: Bar *Pointer = 0; - return 0; -} - -// Test 1. -// RUN: clang-rename -qualified-name=Foo -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s diff --git a/clang/test/clang-rename/ClassSimpleRenaming.cpp b/clang/test/clang-rename/ClassSimpleRenaming.cpp deleted file mode 100644 index 086f55736cb7..000000000000 --- a/clang/test/clang-rename/ClassSimpleRenaming.cpp +++ /dev/null @@ -1,14 +0,0 @@ -class Foo /* Test 1 */ { // CHECK: class Bar /* Test 1 */ { -public: - void foo(int x); -}; - -void Foo::foo(int x) /* Test 2 */ {} // CHECK: void Bar::foo(int x) /* Test 2 */ {} - -// Test 1. -// RUN: clang-rename -offset=6 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=109 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/ClassTestMulti.cpp b/clang/test/clang-rename/ClassTestMulti.cpp deleted file mode 100644 index 81e65c760652..000000000000 --- a/clang/test/clang-rename/ClassTestMulti.cpp +++ /dev/null @@ -1,11 +0,0 @@ -class Foo1 /* Offset 1 */ { // CHECK: class Bar1 /* Offset 1 */ { -}; - -class Foo2 /* Offset 2 */ { // CHECK: class Bar2 /* Offset 2 */ { -}; - -// Test 1. -// RUN: clang-rename -offset=6 -new-name=Bar1 -offset=76 -new-name=Bar2 %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/ClassTestMultiByName.cpp b/clang/test/clang-rename/ClassTestMultiByName.cpp deleted file mode 100644 index 61b69a1bdf4c..000000000000 --- a/clang/test/clang-rename/ClassTestMultiByName.cpp +++ /dev/null @@ -1,8 +0,0 @@ -class Foo1 { // CHECK: class Bar1 -}; - -class Foo2 { // CHECK: class Bar2 -}; - -// Test 1. -// RUN: clang-rename -qualified-name=Foo1 -new-name=Bar1 -qualified-name=Foo2 -new-name=Bar2 %s -- | sed 's,//.*,,' | FileCheck %s diff --git a/clang/test/clang-rename/ComplexFunctionOverride.cpp b/clang/test/clang-rename/ComplexFunctionOverride.cpp deleted file mode 100644 index ccf3a20e5400..000000000000 --- a/clang/test/clang-rename/ComplexFunctionOverride.cpp +++ /dev/null @@ -1,47 +0,0 @@ -struct A { - virtual void foo() {} /* Test 1 */ // CHECK: virtual void bar() {} -}; - -struct B : A { - void foo() override {} /* Test 2 */ // CHECK: void bar() override {} -}; - -struct C : B { - void foo() override {} /* Test 3 */ // CHECK: void bar() override {} -}; - -struct D : B { - void foo() override {} /* Test 4 */ // CHECK: void bar() override {} -}; - -struct E : D { - void foo() override {} /* Test 5 */ // CHECK: void bar() override {} -}; - -int main() { - A a; - a.foo(); // CHECK: a.bar(); - B b; - b.foo(); // CHECK: b.bar(); - C c; - c.foo(); // CHECK: c.bar(); - D d; - d.foo(); // CHECK: d.bar(); - E e; - e.foo(); // CHECK: e.bar(); - return 0; -} - -// Test 1. -// RUN: clang-rename -offset=26 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=109 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 3. -// RUN: clang-rename -offset=201 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 4. -// RUN: clang-rename -offset=293 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 5. -// RUN: clang-rename -offset=385 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'foo.*' diff --git a/clang/test/clang-rename/ComplicatedClassType.cpp b/clang/test/clang-rename/ComplicatedClassType.cpp deleted file mode 100644 index 880195303127..000000000000 --- a/clang/test/clang-rename/ComplicatedClassType.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Forward declaration. -class Foo; /* Test 1 */ // CHECK: class Bar; /* Test 1 */ - -class Baz { - virtual int getValue() const = 0; -}; - -class Foo : public Baz { /* Test 2 */// CHECK: class Bar : public Baz { -public: - Foo(int value = 0) : x(value) {} // CHECK: Bar(int value = 0) : x(value) {} - - Foo &operator++(int) { // CHECK: Bar &operator++(int) { - x++; - return *this; - } - - bool operator<(Foo const &rhs) { // CHECK: bool operator<(Bar const &rhs) { - return this->x < rhs.x; - } - - int getValue() const { - return 0; - } - -private: - int x; -}; - -int main() { - Foo *Pointer = 0; // CHECK: Bar *Pointer = 0; - Foo Variable = Foo(10); // CHECK: Bar Variable = Bar(10); - for (Foo it; it < Variable; it++) { // CHECK: for (Bar it; it < Variable; it++) { - } - const Foo *C = new Foo(); // CHECK: const Bar *C = new Bar(); - const_cast(C)->getValue(); // CHECK: const_cast(C)->getValue(); - Foo foo; // CHECK: Bar foo; - const Baz &BazReference = foo; - const Baz *BazPointer = &foo; - dynamic_cast(BazReference).getValue(); /* Test 3 */ // CHECK: dynamic_cast(BazReference).getValue(); - dynamic_cast(BazPointer)->getValue(); /* Test 4 */ // CHECK: dynamic_cast(BazPointer)->getValue(); - reinterpret_cast(BazPointer)->getValue(); /* Test 5 */ // CHECK: reinterpret_cast(BazPointer)->getValue(); - static_cast(BazReference).getValue(); /* Test 6 */ // CHECK: static_cast(BazReference).getValue(); - static_cast(BazPointer)->getValue(); /* Test 7 */ // CHECK: static_cast(BazPointer)->getValue(); - return 0; -} - -// Test 1. -// RUN: clang-rename -offset=30 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=155 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s -// Test 3. -// RUN: clang-rename -offset=1133 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s -// Test 4. -// RUN: clang-rename -offset=1266 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s -// Test 5. -// RUN: clang-rename -offset=1402 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s -// Test 6. -// RUN: clang-rename -offset=1533 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s -// Test 7. -// RUN: clang-rename -offset=1665 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/Ctor.cpp b/clang/test/clang-rename/Ctor.cpp deleted file mode 100644 index 9908a4123ddf..000000000000 --- a/clang/test/clang-rename/Ctor.cpp +++ /dev/null @@ -1,14 +0,0 @@ -class Foo { // CHECK: class Bar { -public: - Foo(); /* Test 1 */ // CHECK: Bar(); -}; - -Foo::Foo() /* Test 2 */ {} // CHECK: Bar::Bar() /* Test 2 */ {} - -// Test 1. -// RUN: clang-rename -offset=62 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=116 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/CtorInitializer.cpp b/clang/test/clang-rename/CtorInitializer.cpp deleted file mode 100644 index fed4f5b06c27..000000000000 --- a/clang/test/clang-rename/CtorInitializer.cpp +++ /dev/null @@ -1,17 +0,0 @@ -class Baz {}; - -class Qux { - Baz Foo; /* Test 1 */ // CHECK: Baz Bar; -public: - Qux(); -}; - -Qux::Qux() : Foo() /* Test 2 */ {} // CHECK: Qux::Qux() : Bar() /* Test 2 */ {} - -// Test 1. -// RUN: clang-rename -offset=33 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=118 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/DeclRefExpr.cpp b/clang/test/clang-rename/DeclRefExpr.cpp deleted file mode 100644 index 6462862d82ad..000000000000 --- a/clang/test/clang-rename/DeclRefExpr.cpp +++ /dev/null @@ -1,24 +0,0 @@ -class C { -public: - static int Foo; /* Test 1 */ // CHECK: static int Bar; -}; - -int foo(int x) { return 0; } -#define MACRO(a) foo(a) - -int main() { - C::Foo = 1; /* Test 2 */ // CHECK: C::Bar = 1; - MACRO(C::Foo); // CHECK: MACRO(C::Bar); - int y = C::Foo; /* Test 3 */ // CHECK: int y = C::Bar; - return 0; -} - -// Test 1. -// RUN: clang-rename -offset=31 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=152 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 3. -// RUN: clang-rename -offset=271 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/ForceMulti.cpp b/clang/test/clang-rename/ForceMulti.cpp deleted file mode 100644 index 41983ce260c8..000000000000 --- a/clang/test/clang-rename/ForceMulti.cpp +++ /dev/null @@ -1,8 +0,0 @@ -class B /* Test 1 */ { // CHECK: class B2 /* Test 1 */ { -}; - -class D : public B /* Test 1 */ { // CHECK: class D : public B2 /* Test 1 */ { -}; - -// Test 1. -// RUN: clang-rename -force -qualified-name B -new-name B2 -qualified-name E -new-name E2 %s -- | sed 's,//.*,,' | FileCheck %s diff --git a/clang/test/clang-rename/ForwardClassDecl.cpp b/clang/test/clang-rename/ForwardClassDecl.cpp deleted file mode 100644 index ef731a16d6e0..000000000000 --- a/clang/test/clang-rename/ForwardClassDecl.cpp +++ /dev/null @@ -1,4 +0,0 @@ -class Foo; // CHECK: class Bar; -Foo *f(); // CHECK: Bar *f(); - -// RUN: clang-rename -offset=6 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s diff --git a/clang/test/clang-rename/FunctionMacro.cpp b/clang/test/clang-rename/FunctionMacro.cpp deleted file mode 100644 index 6e87026ec706..000000000000 --- a/clang/test/clang-rename/FunctionMacro.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#define moo foo // CHECK: #define moo macro_function - -int foo() /* Test 1 */ { // CHECK: int macro_function() /* Test 1 */ { - return 42; -} - -void boo(int value) {} - -void qoo() { - foo(); // CHECK: macro_function(); - boo(foo()); // CHECK: boo(macro_function()); - moo(); - boo(moo()); -} - -// Test 1. -// RUN: clang-rename -offset=68 -new-name=macro_function %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'foo.*' diff --git a/clang/test/clang-rename/FunctionOverride.cpp b/clang/test/clang-rename/FunctionOverride.cpp deleted file mode 100644 index adfeb739e66d..000000000000 --- a/clang/test/clang-rename/FunctionOverride.cpp +++ /dev/null @@ -1,13 +0,0 @@ -class A { virtual void foo(); /* Test 1 */ }; // CHECK: class A { virtual void bar(); -class B : public A { void foo(); /* Test 2 */ }; // CHECK: class B : public A { void bar(); -class C : public B { void foo(); /* Test 3 */ }; // CHECK: class C : public B { void bar(); - -// Test 1. -// RUN: clang-rename -offset=23 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=116 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 3. -// RUN: clang-rename -offset=209 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'foo.*' diff --git a/clang/test/clang-rename/FunctionTemplate.cpp b/clang/test/clang-rename/FunctionTemplate.cpp deleted file mode 100644 index 51b2515b8894..000000000000 --- a/clang/test/clang-rename/FunctionTemplate.cpp +++ /dev/null @@ -1,19 +0,0 @@ -template -void Foo(T t); // CHECK: void Bar(T t); - -template <> -void Foo(int a); // CHECK: void Bar(int a); - -void test() { - Foo(1); // CHECK: Bar(1); -} - -// Test 1. -// RUN: clang-rename -offset=28 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=81 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 3. -// RUN: clang-rename -offset=137 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/FunctionWithClassFindByName.cpp b/clang/test/clang-rename/FunctionWithClassFindByName.cpp deleted file mode 100644 index 2cae09a1c244..000000000000 --- a/clang/test/clang-rename/FunctionWithClassFindByName.cpp +++ /dev/null @@ -1,12 +0,0 @@ -void foo() { -} - -class Foo { // CHECK: class Bar -}; - -int main() { - Foo *Pointer = 0; // CHECK: Bar *Pointer = 0; - return 0; -} - -// RUN: clang-rename -qualified-name=Foo -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s diff --git a/clang/test/clang-rename/IncludeHeaderWithSymbol.cpp b/clang/test/clang-rename/IncludeHeaderWithSymbol.cpp deleted file mode 100644 index cb2baee57b89..000000000000 --- a/clang/test/clang-rename/IncludeHeaderWithSymbol.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "Inputs/HeaderWithSymbol.h" - -int main() { - return 0; // CHECK: {{^ return 0;}} -} - -// Test 1. -// The file IncludeHeaderWithSymbol.cpp doesn't contain the symbol Foo -// and is expected to be written to stdout without modifications -// RUN: clang-rename -qualified-name=Foo -new-name=Bar %s -- | FileCheck %s diff --git a/clang/test/clang-rename/Inputs/HeaderWithSymbol.h b/clang/test/clang-rename/Inputs/HeaderWithSymbol.h deleted file mode 100644 index 1fe02e89786c..000000000000 --- a/clang/test/clang-rename/Inputs/HeaderWithSymbol.h +++ /dev/null @@ -1 +0,0 @@ -struct Foo {}; diff --git a/clang/test/clang-rename/Inputs/OffsetToNewName.yaml b/clang/test/clang-rename/Inputs/OffsetToNewName.yaml deleted file mode 100644 index d8e972880f36..000000000000 --- a/clang/test/clang-rename/Inputs/OffsetToNewName.yaml +++ /dev/null @@ -1,6 +0,0 @@ ---- -- Offset: 6 - NewName: Bar1 -- Offset: 44 - NewName: Bar2 -... diff --git a/clang/test/clang-rename/Inputs/QualifiedNameToNewName.yaml b/clang/test/clang-rename/Inputs/QualifiedNameToNewName.yaml deleted file mode 100644 index 6e3783671dfa..000000000000 --- a/clang/test/clang-rename/Inputs/QualifiedNameToNewName.yaml +++ /dev/null @@ -1,6 +0,0 @@ ---- -- QualifiedName: Foo1 - NewName: Bar1 -- QualifiedName: Foo2 - NewName: Bar2 -... diff --git a/clang/test/clang-rename/InvalidNewName.cpp b/clang/test/clang-rename/InvalidNewName.cpp deleted file mode 100644 index e6b38e59420a..000000000000 --- a/clang/test/clang-rename/InvalidNewName.cpp +++ /dev/null @@ -1,2 +0,0 @@ -// RUN: not clang-rename -new-name=class -offset=133 %s 2>&1 | FileCheck %s -// CHECK: ERROR: new name is not a valid identifier in C++17. diff --git a/clang/test/clang-rename/InvalidOffset.cpp b/clang/test/clang-rename/InvalidOffset.cpp deleted file mode 100644 index 2ae04d01e4a7..000000000000 --- a/clang/test/clang-rename/InvalidOffset.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Inputs/HeaderWithSymbol.h" -#define FOO int bar; -FOO - -int foo; - -// RUN: not clang-rename -new-name=qux -offset=259 %s -- 2>&1 | FileCheck %s -// CHECK-NOT: CHECK -// CHECK: error: SourceLocation in file {{.*}}InvalidOffset.cpp at offset 259 is invalid diff --git a/clang/test/clang-rename/InvalidQualifiedName.cpp b/clang/test/clang-rename/InvalidQualifiedName.cpp deleted file mode 100644 index 5280e3939ccd..000000000000 --- a/clang/test/clang-rename/InvalidQualifiedName.cpp +++ /dev/null @@ -1,4 +0,0 @@ -struct S { -}; - -// RUN: clang-rename -force -qualified-name S2 -new-name=T %s -- diff --git a/clang/test/clang-rename/MemberExprMacro.cpp b/clang/test/clang-rename/MemberExprMacro.cpp deleted file mode 100644 index 56cd8d95f6e8..000000000000 --- a/clang/test/clang-rename/MemberExprMacro.cpp +++ /dev/null @@ -1,22 +0,0 @@ -class Baz { -public: - int Foo; /* Test 1 */ // CHECK: int Bar; -}; - -int qux(int x) { return 0; } -#define MACRO(a) qux(a) - -int main() { - Baz baz; - baz.Foo = 1; /* Test 2 */ // CHECK: baz.Bar = 1; - MACRO(baz.Foo); // CHECK: MACRO(baz.Bar); - int y = baz.Foo; // CHECK: int y = baz.Bar; -} - -// Test 1. -// RUN: clang-rename -offset=26 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=155 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/Namespace.cpp b/clang/test/clang-rename/Namespace.cpp deleted file mode 100644 index ec9630fdedb6..000000000000 --- a/clang/test/clang-rename/Namespace.cpp +++ /dev/null @@ -1,13 +0,0 @@ -namespace gcc /* Test 1 */ { // CHECK: namespace clang /* Test 1 */ { - int x; -} - -void boo() { - gcc::x = 42; // CHECK: clang::x = 42; -} - -// Test 1. -// RUN: clang-rename -offset=10 -new-name=clang %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/NoNewName.cpp b/clang/test/clang-rename/NoNewName.cpp deleted file mode 100644 index 4f882d83b0c1..000000000000 --- a/clang/test/clang-rename/NoNewName.cpp +++ /dev/null @@ -1,4 +0,0 @@ -// 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: clang-rename: -new-name must be specified. diff --git a/clang/test/clang-rename/NonExistFile.cpp b/clang/test/clang-rename/NonExistFile.cpp deleted file mode 100644 index f45839be8047..000000000000 --- a/clang/test/clang-rename/NonExistFile.cpp +++ /dev/null @@ -1,2 +0,0 @@ -// RUN: not clang-rename -offset=0 -new-name=bar non-existing-file 2>&1 | FileCheck %s -// CHECK: clang-rename: non-existing-file does not exist. diff --git a/clang/test/clang-rename/TemplateClassInstantiation.cpp b/clang/test/clang-rename/TemplateClassInstantiation.cpp deleted file mode 100644 index 493d0951df57..000000000000 --- a/clang/test/clang-rename/TemplateClassInstantiation.cpp +++ /dev/null @@ -1,42 +0,0 @@ -template -class Foo { /* Test 1 */ // CHECK: class Bar { /* Test 1 */ -public: - T foo(T arg, T& ref, T* ptr) { - T value; - int number = 42; - value = (T)number; - value = static_cast(number); - return value; - } - static void foo(T value) {} - T member; -}; - -template -void func() { - Foo obj; /* Test 2 */ // CHECK: Bar obj; - obj.member = T(); - Foo::foo(); // CHECK: Bar::foo(); -} - -int main() { - Foo i; /* Test 3 */ // CHECK: Bar i; - i.member = 0; - Foo::foo(0); // CHECK: Bar::foo(0); - - Foo b; // CHECK: Bar b; - b.member = false; - Foo::foo(false); // CHECK: Bar::foo(false); - - return 0; -} - -// Test 1. -// RUN: clang-rename -offset=29 -new-name=Bar %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=324 -new-name=Bar %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s -// Test 3. -// RUN: clang-rename -offset=463 -new-name=Bar %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/TemplateCtor.cpp b/clang/test/clang-rename/TemplateCtor.cpp deleted file mode 100644 index 9a59194ac3f4..000000000000 --- a/clang/test/clang-rename/TemplateCtor.cpp +++ /dev/null @@ -1,10 +0,0 @@ -class Foo { // CHECK: class Bar { -public: - template - Foo(); // CHECK: Bar(); - - template - Foo(Foo &); // CHECK: Bar(Bar &); -}; - -// RUN: clang-rename -offset=6 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s diff --git a/clang/test/clang-rename/TemplateTypename.cpp b/clang/test/clang-rename/TemplateTypename.cpp deleted file mode 100644 index 559ec1f9ade7..000000000000 --- a/clang/test/clang-rename/TemplateTypename.cpp +++ /dev/null @@ -1,24 +0,0 @@ -template // CHECK: template -class Foo { -T foo(T arg, T& ref, T* /* Test 2 */ ptr) { // CHECK: U foo(U arg, U& ref, U* /* Test 2 */ ptr) { - T value; // CHECK: U value; - int number = 42; - value = (T)number; // CHECK: value = (U)number; - value = static_cast(number); // CHECK: value = static_cast(number); - return value; -} - -static void foo(T value) {} // CHECK: static void foo(U value) {} - -T member; // CHECK: U member; -}; - -// Test 1. -// RUN: clang-rename -offset=19 -new-name=U %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=126 -new-name=U %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s -// Test 3. -// RUN: clang-rename -offset=392 -new-name=U %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'T.*' diff --git a/clang/test/clang-rename/TemplatedClassFunction.cpp b/clang/test/clang-rename/TemplatedClassFunction.cpp deleted file mode 100644 index d7f21e0847c9..000000000000 --- a/clang/test/clang-rename/TemplatedClassFunction.cpp +++ /dev/null @@ -1,27 +0,0 @@ -template -class A { -public: - void foo() /* Test 1 */ {} // CHECK: void bar() /* Test 1 */ {} -}; - -int main(int argc, char **argv) { - A a; - A b; - A c; - a.foo(); /* Test 2 */ // CHECK: a.bar(); /* Test 2 */ - b.foo(); /* Test 3 */ // CHECK: b.bar(); /* Test 3 */ - c.foo(); /* Test 4 */ // CHECK: c.bar(); /* Test 4 */ - return 0; -} - -// Test 1. -// RUN: clang-rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=191 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 3. -// RUN: clang-rename -offset=255 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 4. -// RUN: clang-rename -offset=319 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'foo.*' diff --git a/clang/test/clang-rename/Typedef.cpp b/clang/test/clang-rename/Typedef.cpp deleted file mode 100644 index 64d337fae22c..000000000000 --- a/clang/test/clang-rename/Typedef.cpp +++ /dev/null @@ -1,8 +0,0 @@ -namespace std { -class basic_string {}; -typedef basic_string string; -} // namespace std - -std::string foo(); // // CHECK: std::new_string foo(); - -// RUN: clang-rename -offset=93 -new-name=new_string %s -- | sed 's,//.*,,' | FileCheck %s diff --git a/clang/test/clang-rename/UserDefinedConversion.cpp b/clang/test/clang-rename/UserDefinedConversion.cpp deleted file mode 100644 index 60f251ab4483..000000000000 --- a/clang/test/clang-rename/UserDefinedConversion.cpp +++ /dev/null @@ -1,26 +0,0 @@ -class Foo { /* Test 1 */ // CHECK: class Bar { -public: - Foo() {} // CHECK: Bar() {} -}; - -class Baz { -public: - operator Foo() /* Test 2 */ const { // CHECK: operator Bar() /* Test 2 */ const { - Foo foo; // CHECK: Bar foo; - return foo; - } -}; - -int main() { - Baz boo; - Foo foo = static_cast(boo); // CHECK: Bar foo = static_cast(boo); - return 0; -} - -// Test 1. -// RUN: clang-rename -offset=7 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=164 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/Variable.cpp b/clang/test/clang-rename/Variable.cpp deleted file mode 100644 index d7e670fb43ee..000000000000 --- a/clang/test/clang-rename/Variable.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#define NAMESPACE namespace A -NAMESPACE { -int Foo; /* Test 1 */ // CHECK: int Bar; -} -int Foo; // CHECK: int Foo; -int Qux = Foo; // CHECK: int Qux = Foo; -int Baz = A::Foo; /* Test 2 */ // CHECK: Baz = A::Bar; -void fun() { - struct { - int Foo; // CHECK: int Foo; - } b = {100}; - int Foo = 100; // CHECK: int Foo = 100; - Baz = Foo; // CHECK: Baz = Foo; - { - extern int Foo; // CHECK: extern int Foo; - Baz = Foo; // CHECK: Baz = Foo; - Foo = A::Foo /* Test 3 */ + Baz; // CHECK: Foo = A::Bar /* Test 3 */ + Baz; - A::Foo /* Test 4 */ = b.Foo; // CHECK: A::Bar /* Test 4 */ = b.Foo; - } - Foo = b.Foo; // Foo = b.Foo; -} - -// Test 1. -// RUN: clang-rename -offset=46 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=234 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 3. -// RUN: clang-rename -offset=641 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 4. -// RUN: clang-rename -offset=716 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/VariableMacro.cpp b/clang/test/clang-rename/VariableMacro.cpp deleted file mode 100644 index 622e825d3e41..000000000000 --- a/clang/test/clang-rename/VariableMacro.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#define Baz Foo // CHECK: #define Baz Bar - -void foo(int value) {} - -void macro() { - int Foo; /* Test 1 */ // CHECK: int Bar; - Foo = 42; /* Test 2 */ // CHECK: Bar = 42; - Baz -= 0; - foo(Foo); /* Test 3 */ // CHECK: foo(Bar); - foo(Baz); -} - -// Test 1. -// RUN: clang-rename -offset=88 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=129 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 3. -// RUN: clang-rename -offset=191 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/VariableTemplate.cpp b/clang/test/clang-rename/VariableTemplate.cpp deleted file mode 100644 index a345ede5a7f6..000000000000 --- a/clang/test/clang-rename/VariableTemplate.cpp +++ /dev/null @@ -1,32 +0,0 @@ -template -bool Foo = true; // CHECK: bool Bar = true; - -// explicit template specialization -template <> -bool Foo = false; // CHECK: bool Bar = false; - -// partial template specialization -template -bool Foo = false; // bool Bar = false; - -void k() { - // ref to the explicit template specialization - Foo; // CHECK: Bar; - // ref to the primary template. - Foo; // CHECK: Bar; -} - - -// Test 1. -// RUN: clang-rename -offset=34 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=128 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 3. -// RUN: clang-rename -offset=248 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 4. -// RUN: clang-rename -offset=357 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 5. -// RUN: clang-rename -offset=431 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' diff --git a/clang/test/clang-rename/YAMLInput.cpp b/clang/test/clang-rename/YAMLInput.cpp deleted file mode 100644 index 55dbc6d66a5a..000000000000 --- a/clang/test/clang-rename/YAMLInput.cpp +++ /dev/null @@ -1,10 +0,0 @@ -class Foo1 { // CHECK: class Bar1 -}; - -class Foo2 { // CHECK: class Bar2 -}; - -// Test 1. -// RUN: clang-rename -input %S/Inputs/OffsetToNewName.yaml %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -input %S/Inputs/QualifiedNameToNewName.yaml %s -- | sed 's,//.*,,' | FileCheck %s diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt index f588a3634ee6..9a3512712a28 100644 --- a/clang/tools/CMakeLists.txt +++ b/clang/tools/CMakeLists.txt @@ -19,7 +19,6 @@ endif() add_clang_subdirectory(c-index-test) -add_clang_subdirectory(clang-rename) add_clang_subdirectory(clang-refactor) # For MinGW we only enable shared library if LLVM_LINK_LLVM_DYLIB=ON. # Without that option resulting library is too close to 2^16 DLL exports limit. diff --git a/clang/tools/clang-rename/CMakeLists.txt b/clang/tools/clang-rename/CMakeLists.txt deleted file mode 100644 index f4c4e520520d..000000000000 --- a/clang/tools/clang-rename/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -set(LLVM_LINK_COMPONENTS - Option - Support - ) - -add_clang_tool(clang-rename - ClangRename.cpp - ) - -clang_target_link_libraries(clang-rename - PRIVATE - clangBasic - clangFrontend - clangRewrite - clangSerialization - clangTooling - clangToolingCore - clangToolingRefactoring - ) - -install(FILES clang-rename.py - DESTINATION "${CMAKE_INSTALL_DATADIR}/clang" - COMPONENT clang-rename) -install(FILES clang-rename.el - DESTINATION "${CMAKE_INSTALL_DATADIR}/clang" - COMPONENT clang-rename) diff --git a/clang/tools/clang-rename/ClangRename.cpp b/clang/tools/clang-rename/ClangRename.cpp deleted file mode 100644 index f2ac0c4360e0..000000000000 --- a/clang/tools/clang-rename/ClangRename.cpp +++ /dev/null @@ -1,242 +0,0 @@ -//===--- tools/extra/clang-rename/ClangRename.cpp - Clang rename tool -----===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -/// -/// \file -/// This file implements a clang-rename tool that automatically finds and -/// renames symbols in C++ code. -/// -//===----------------------------------------------------------------------===// - -#include "clang/Basic/Diagnostic.h" -#include "clang/Basic/DiagnosticOptions.h" -#include "clang/Basic/FileManager.h" -#include "clang/Basic/IdentifierTable.h" -#include "clang/Basic/LangOptions.h" -#include "clang/Basic/SourceManager.h" -#include "clang/Basic/TokenKinds.h" -#include "clang/Frontend/TextDiagnosticPrinter.h" -#include "clang/Rewrite/Core/Rewriter.h" -#include "clang/Tooling/CommonOptionsParser.h" -#include "clang/Tooling/Refactoring.h" -#include "clang/Tooling/Refactoring/Rename/RenamingAction.h" -#include "clang/Tooling/Refactoring/Rename/USRFindingAction.h" -#include "clang/Tooling/ReplacementsYaml.h" -#include "clang/Tooling/Tooling.h" -#include "llvm/ADT/IntrusiveRefCntPtr.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/FileSystem.h" -#include "llvm/Support/YAMLTraits.h" -#include "llvm/Support/raw_ostream.h" -#include -#include - -using namespace llvm; -using namespace clang; - -/// An oldname -> newname rename. -struct RenameAllInfo { - unsigned Offset = 0; - std::string QualifiedName; - std::string NewName; -}; - -LLVM_YAML_IS_SEQUENCE_VECTOR(RenameAllInfo) - -namespace llvm { -namespace yaml { - -/// Specialized MappingTraits to describe how a RenameAllInfo is -/// (de)serialized. -template <> struct MappingTraits { - static void mapping(IO &IO, RenameAllInfo &Info) { - IO.mapOptional("Offset", Info.Offset); - IO.mapOptional("QualifiedName", Info.QualifiedName); - IO.mapRequired("NewName", Info.NewName); - } -}; - -} // end namespace yaml -} // end namespace llvm - -static cl::OptionCategory ClangRenameOptions("clang-rename common options"); - -static cl::list SymbolOffsets( - "offset", - cl::desc("Locates the symbol by offset as opposed to :."), - cl::cat(ClangRenameOptions)); -static cl::opt Inplace("i", cl::desc("Overwrite edited s."), - cl::cat(ClangRenameOptions)); -static cl::list - QualifiedNames("qualified-name", - cl::desc("The fully qualified name of the symbol."), - cl::cat(ClangRenameOptions)); - -static cl::list - NewNames("new-name", cl::desc("The new name to change the symbol to."), - cl::cat(ClangRenameOptions)); -static cl::opt PrintName( - "pn", - cl::desc("Print the found symbol's name prior to renaming to stderr."), - cl::cat(ClangRenameOptions)); -static cl::opt PrintLocations( - "pl", cl::desc("Print the locations affected by renaming to stderr."), - cl::cat(ClangRenameOptions)); -static cl::opt - ExportFixes("export-fixes", - cl::desc("YAML file to store suggested fixes in."), - cl::value_desc("filename"), cl::cat(ClangRenameOptions)); -static cl::opt - Input("input", cl::desc("YAML file to load oldname-newname pairs from."), - cl::Optional, cl::cat(ClangRenameOptions)); -static cl::opt Force("force", - cl::desc("Ignore nonexistent qualified names."), - cl::cat(ClangRenameOptions)); - -int main(int argc, const char **argv) { - auto ExpectedParser = - tooling::CommonOptionsParser::create(argc, argv, ClangRenameOptions); - if (!ExpectedParser) { - llvm::errs() << ExpectedParser.takeError(); - return 1; - } - tooling::CommonOptionsParser &OP = ExpectedParser.get(); - - if (!Input.empty()) { - // Populate QualifiedNames and NewNames from a YAML file. - ErrorOr> Buffer = - llvm::MemoryBuffer::getFile(Input); - if (!Buffer) { - errs() << "clang-rename: failed to read " << Input << ": " - << Buffer.getError().message() << "\n"; - return 1; - } - - std::vector Infos; - llvm::yaml::Input YAML(Buffer.get()->getBuffer()); - YAML >> Infos; - for (const auto &Info : Infos) { - if (!Info.QualifiedName.empty()) - QualifiedNames.push_back(Info.QualifiedName); - else - SymbolOffsets.push_back(Info.Offset); - NewNames.push_back(Info.NewName); - } - } - - // Check the arguments for correctness. - if (NewNames.empty()) { - errs() << "clang-rename: -new-name must be specified.\n\n"; - return 1; - } - - if (SymbolOffsets.empty() == QualifiedNames.empty()) { - errs() << "clang-rename: -offset and -qualified-name can't be present at " - "the same time.\n"; - return 1; - } - - // Check if NewNames is a valid identifier in C++17. - LangOptions Options; - Options.CPlusPlus = true; - Options.CPlusPlus17 = true; - IdentifierTable Table(Options); - for (const auto &NewName : NewNames) { - auto NewNameTokKind = Table.get(NewName).getTokenID(); - if (!tok::isAnyIdentifier(NewNameTokKind)) { - errs() << "ERROR: new name is not a valid identifier in C++17.\n\n"; - return 1; - } - } - - if (SymbolOffsets.size() + QualifiedNames.size() != NewNames.size()) { - errs() << "clang-rename: number of symbol offsets(" << SymbolOffsets.size() - << ") + number of qualified names (" << QualifiedNames.size() - << ") must be equal to number of new names(" << NewNames.size() - << ").\n\n"; - cl::PrintHelpMessage(); - return 1; - } - - auto Files = OP.getSourcePathList(); - tooling::RefactoringTool Tool(OP.getCompilations(), Files); - tooling::USRFindingAction FindingAction(SymbolOffsets, QualifiedNames, Force); - Tool.run(tooling::newFrontendActionFactory(&FindingAction).get()); - const std::vector> &USRList = - FindingAction.getUSRList(); - const std::vector &PrevNames = FindingAction.getUSRSpellings(); - if (PrintName) { - for (const auto &PrevName : PrevNames) { - outs() << "clang-rename found name: " << PrevName << '\n'; - } - } - - if (FindingAction.errorOccurred()) { - // Diagnostics are already issued at this point. - return 1; - } - - // Perform the renaming. - tooling::RenamingAction RenameAction(NewNames, PrevNames, USRList, - Tool.getReplacements(), PrintLocations); - std::unique_ptr Factory = - tooling::newFrontendActionFactory(&RenameAction); - int ExitCode; - - if (Inplace) { - ExitCode = Tool.runAndSave(Factory.get()); - } else { - ExitCode = Tool.run(Factory.get()); - - if (!ExportFixes.empty()) { - std::error_code EC; - llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::OF_None); - if (EC) { - llvm::errs() << "Error opening output file: " << EC.message() << '\n'; - return 1; - } - - // Export replacements. - tooling::TranslationUnitReplacements TUR; - const auto &FileToReplacements = Tool.getReplacements(); - for (const auto &Entry : FileToReplacements) - TUR.Replacements.insert(TUR.Replacements.end(), Entry.second.begin(), - Entry.second.end()); - - yaml::Output YAML(OS); - YAML << TUR; - OS.close(); - return 0; - } - - // Write every file to stdout. Right now we just barf the files without any - // indication of which files start where, other than that we print the files - // in the same order we see them. - LangOptions DefaultLangOptions; - IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); - TextDiagnosticPrinter DiagnosticPrinter(errs(), &*DiagOpts); - DiagnosticsEngine Diagnostics( - IntrusiveRefCntPtr(new DiagnosticIDs()), &*DiagOpts, - &DiagnosticPrinter, false); - auto &FileMgr = Tool.getFiles(); - SourceManager Sources(Diagnostics, FileMgr); - Rewriter Rewrite(Sources, DefaultLangOptions); - - Tool.applyAllReplacements(Rewrite); - for (const auto &File : Files) { - auto Entry = FileMgr.getOptionalFileRef(File); - if (!Entry) { - errs() << "clang-rename: " << File << " does not exist.\n"; - return 1; - } - const auto ID = Sources.getOrCreateFileID(*Entry, SrcMgr::C_User); - Rewrite.getEditBuffer(ID).write(outs()); - } - } - - return ExitCode; -} diff --git a/clang/tools/clang-rename/clang-rename.el b/clang/tools/clang-rename/clang-rename.el deleted file mode 100644 index 3f47c11e2c75..000000000000 --- a/clang/tools/clang-rename/clang-rename.el +++ /dev/null @@ -1,80 +0,0 @@ -;;; clang-rename.el --- Renames every occurrence of a symbol found at . -*- lexical-binding: t; -*- - -;; Version: 0.1.0 -;; Keywords: tools, c - -;;; Commentary: - -;; To install clang-rename.el make sure the directory of this file is in your -;; `load-path' and add -;; -;; (require 'clang-rename) -;; -;; to your .emacs configuration. - -;;; Code: - -(defgroup clang-rename nil - "Integration with clang-rename" - :group 'c) - -(defcustom clang-rename-binary "clang-rename" - "Path to clang-rename executable." - :type '(file :must-match t) - :group 'clang-rename) - -;;;###autoload -(defun clang-rename (new-name) - "Rename all instances of the symbol at point to NEW-NAME using clang-rename." - (interactive "sEnter a new name: ") - (save-some-buffers :all) - ;; clang-rename should not be combined with other operations when undoing. - (undo-boundary) - (let ((output-buffer (get-buffer-create "*clang-rename*"))) - (with-current-buffer output-buffer (erase-buffer)) - (let ((exit-code (call-process - clang-rename-binary nil output-buffer nil - (format "-offset=%d" - ;; clang-rename wants file (byte) offsets, not - ;; buffer (character) positions. - (clang-rename--bufferpos-to-filepos - ;; Emacs treats one character after a symbol as - ;; part of the symbol, but clang-rename doesn’t. - ;; Use the beginning of the current symbol, if - ;; available, to resolve the inconsistency. - (or (car (bounds-of-thing-at-point 'symbol)) - (point)) - 'exact)) - (format "-new-name=%s" new-name) - "-i" (buffer-file-name)))) - (if (and (integerp exit-code) (zerop exit-code)) - ;; Success; revert current buffer so it gets the modifications. - (progn - (kill-buffer output-buffer) - (revert-buffer :ignore-auto :noconfirm :preserve-modes)) - ;; Failure; append exit code to output buffer and display it. - (let ((message (clang-rename--format-message - "clang-rename failed with %s %s" - (if (integerp exit-code) "exit status" "signal") - exit-code))) - (with-current-buffer output-buffer - (insert ?\n message ?\n)) - (message "%s" message) - (display-buffer output-buffer)))))) - -(defalias 'clang-rename--bufferpos-to-filepos - (if (fboundp 'bufferpos-to-filepos) - 'bufferpos-to-filepos - ;; Emacs 24 doesn’t have ‘bufferpos-to-filepos’, simulate it using - ;; ‘position-bytes’. - (lambda (position &optional _quality _coding-system) - (1- (position-bytes position))))) - -;; ‘format-message’ is new in Emacs 25.1. Provide a fallback for older -;; versions. -(defalias 'clang-rename--format-message - (if (fboundp 'format-message) 'format-message 'format)) - -(provide 'clang-rename) - -;;; clang-rename.el ends here diff --git a/clang/tools/clang-rename/clang-rename.py b/clang/tools/clang-rename/clang-rename.py deleted file mode 100644 index 1cbabaf859a5..000000000000 --- a/clang/tools/clang-rename/clang-rename.py +++ /dev/null @@ -1,70 +0,0 @@ -""" -Minimal clang-rename integration with Vim. - -Before installing make sure one of the following is satisfied: - -* clang-rename is in your PATH -* `g:clang_rename_path` in ~/.vimrc points to valid clang-rename executable -* `binary` in clang-rename.py points to valid to clang-rename executable - -To install, simply put this into your ~/.vimrc for python2 support - - noremap cr :pyf /clang-rename.py - -For python3 use the following command (note the change from :pyf to :py3f) - - noremap cr :py3f /clang-rename.py - -IMPORTANT NOTE: Before running the tool, make sure you saved the file. - -All you have to do now is to place a cursor on a variable/function/class which -you would like to rename and press 'cr'. You will be prompted for a new -name if the cursor points to a valid symbol. -""" - -from __future__ import absolute_import, division, print_function -import vim -import subprocess -import sys - - -def main(): - binary = "clang-rename" - if vim.eval('exists("g:clang_rename_path")') == "1": - binary = vim.eval("g:clang_rename_path") - - # Get arguments for clang-rename binary. - offset = int(vim.eval('line2byte(line("."))+col(".")')) - 2 - if offset < 0: - print( - "Couldn't determine cursor position. Is your file empty?", file=sys.stderr - ) - return - filename = vim.current.buffer.name - - new_name_request_message = "type new name:" - new_name = vim.eval("input('{}\n')".format(new_name_request_message)) - - # Call clang-rename. - command = [ - binary, - filename, - "-i", - "-offset", - str(offset), - "-new-name", - str(new_name), - ] - # FIXME: make it possible to run the tool on unsaved file. - p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = p.communicate() - - if stderr: - print(stderr) - - # Reload all buffers in Vim. - vim.command("checktime") - - -if __name__ == "__main__": - main() diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt index e43ee7bfa88a..85d265426ec8 100644 --- a/clang/unittests/CMakeLists.txt +++ b/clang/unittests/CMakeLists.txt @@ -48,7 +48,6 @@ if(NOT WIN32 AND CLANG_TOOL_LIBCLANG_BUILD) add_subdirectory(libclang) endif() add_subdirectory(DirectoryWatcher) -add_subdirectory(Rename) add_subdirectory(Index) add_subdirectory(InstallAPI) add_subdirectory(Serialization) diff --git a/clang/unittests/Rename/CMakeLists.txt b/clang/unittests/Rename/CMakeLists.txt deleted file mode 100644 index 6ec0c521551c..000000000000 --- a/clang/unittests/Rename/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -set(LLVM_LINK_COMPONENTS - FrontendOpenMP - support - ) - -# We'd like clang/unittests/Tooling/RewriterTestContext.h in the test. -include_directories(${CLANG_SOURCE_DIR}) - -add_clang_unittest(ClangRenameTests - RenameClassTest.cpp - RenameEnumTest.cpp - RenameAliasTest.cpp - RenameMemberTest.cpp - RenameFunctionTest.cpp - ) - -clang_target_link_libraries(ClangRenameTests - PRIVATE - clangAST - clangASTMatchers - clangBasic - clangFormat - clangFrontend - clangRewrite - clangSerialization - clangTooling - clangToolingCore - clangToolingRefactoring - ) diff --git a/clang/unittests/Rename/ClangRenameTest.h b/clang/unittests/Rename/ClangRenameTest.h deleted file mode 100644 index 64033657b579..000000000000 --- a/clang/unittests/Rename/ClangRenameTest.h +++ /dev/null @@ -1,116 +0,0 @@ -//===-- ClangRenameTests.cpp - clang-rename unit tests --------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_UNITTESTS_RENAME_CLANGRENAMETEST_H -#define LLVM_CLANG_UNITTESTS_RENAME_CLANGRENAMETEST_H - -#include "unittests/Tooling/RewriterTestContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" -#include "clang/Basic/FileManager.h" -#include "clang/Basic/FileSystemOptions.h" -#include "clang/Format/Format.h" -#include "clang/Frontend/CompilerInstance.h" -#include "clang/Frontend/PCHContainerOperations.h" -#include "clang/Tooling/Refactoring.h" -#include "clang/Tooling/Refactoring/Rename/RenamingAction.h" -#include "clang/Tooling/Refactoring/Rename/USRFindingAction.h" -#include "clang/Tooling/Tooling.h" -#include "llvm/ADT/IntrusiveRefCntPtr.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/Support/Format.h" -#include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/VirtualFileSystem.h" -#include "gtest/gtest.h" -#include -#include -#include - -namespace clang { -namespace clang_rename { -namespace test { - -struct Case { - std::string Before; - std::string After; - std::string OldName; - std::string NewName; -}; - -class ClangRenameTest : public testing::Test, - public testing::WithParamInterface { -protected: - void AppendToHeader(StringRef Code) { HeaderContent += Code.str(); } - - std::string runClangRenameOnCode(llvm::StringRef Code, - llvm::StringRef OldName, - llvm::StringRef NewName) { - std::string NewCode; - llvm::raw_string_ostream(NewCode) << llvm::format( - "#include \"%s\"\n%s", HeaderName.c_str(), Code.str().c_str()); - tooling::FileContentMappings FileContents = {{HeaderName, HeaderContent}, - {CCName, NewCode}}; - clang::RewriterTestContext Context; - Context.createInMemoryFile(HeaderName, HeaderContent); - clang::FileID InputFileID = Context.createInMemoryFile(CCName, NewCode); - - tooling::USRFindingAction FindingAction({}, {std::string(OldName)}, false); - std::unique_ptr USRFindingActionFactory = - tooling::newFrontendActionFactory(&FindingAction); - - if (!tooling::runToolOnCodeWithArgs( - USRFindingActionFactory->create(), NewCode, {"-std=c++11"}, CCName, - "clang-rename", std::make_shared(), - FileContents)) - return ""; - - const std::vector> &USRList = - FindingAction.getUSRList(); - std::vector NewNames = {std::string(NewName)}; - std::map FileToReplacements; - tooling::QualifiedRenamingAction RenameAction(NewNames, USRList, - FileToReplacements); - auto RenameActionFactory = tooling::newFrontendActionFactory(&RenameAction); - if (!tooling::runToolOnCodeWithArgs( - RenameActionFactory->create(), NewCode, {"-std=c++11"}, CCName, - "clang-rename", std::make_shared(), - FileContents)) - return ""; - - formatAndApplyAllReplacements(FileToReplacements, Context.Rewrite, "llvm"); - return Context.getRewrittenText(InputFileID); - } - - void CompareSnippets(StringRef Expected, StringRef Actual) { - std::string ExpectedCode; - llvm::raw_string_ostream(ExpectedCode) << llvm::format( - "#include \"%s\"\n%s", HeaderName.c_str(), Expected.str().c_str()); - EXPECT_EQ(format(ExpectedCode), format(Actual)); - } - - std::string format(llvm::StringRef Code) { - tooling::Replacements Replaces = format::reformat( - format::getLLVMStyle(), Code, {tooling::Range(0, Code.size())}); - auto ChangedCode = tooling::applyAllReplacements(Code, Replaces); - EXPECT_TRUE(static_cast(ChangedCode)); - if (!ChangedCode) { - llvm::errs() << llvm::toString(ChangedCode.takeError()); - return ""; - } - return *ChangedCode; - } - - std::string HeaderContent; - std::string HeaderName = "header.h"; - std::string CCName = "input.cc"; -}; - -} // namespace test -} // namespace clang_rename -} // namesdpace clang - -#endif diff --git a/clang/unittests/Rename/RenameAliasTest.cpp b/clang/unittests/Rename/RenameAliasTest.cpp deleted file mode 100644 index 50fa2c104263..000000000000 --- a/clang/unittests/Rename/RenameAliasTest.cpp +++ /dev/null @@ -1,303 +0,0 @@ -//===-- RenameAliasTest.cpp - unit tests for renaming alias ---------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "ClangRenameTest.h" - -namespace clang { -namespace clang_rename { -namespace test { -namespace { - -class RenameAliasTest : public ClangRenameTest { -public: - RenameAliasTest() { - AppendToHeader(R"( - #define MACRO(x) x - namespace some_ns { - class A { - public: - void foo() {} - struct Nested { - enum NestedEnum { - E1, E2, - }; - }; - }; - } // namespace some_ns - namespace a { - typedef some_ns::A TA; - using UA = some_ns::A; - } // namespace a - namespace b { - typedef some_ns::A TA; - using UA = some_ns::A; - } - template class ptr {}; - template - - using TPtr = ptr; - )"); - } -}; - -INSTANTIATE_TEST_SUITE_P( - RenameAliasTests, RenameAliasTest, - testing::ValuesIn(std::vector({ - // basic functions - {"void f(a::TA a1) {}", "void f(b::TB a1) {}", "a::TA", "b::TB"}, - {"void f(a::UA a1) {}", "void f(b::UB a1) {}", "a::UA", "b::UB"}, - {"void f(a::TA* a1) {}", "void f(b::TB* a1) {}", "a::TA", "b::TB"}, - {"void f(a::TA** a1) {}", "void f(b::TB** a1) {}", "a::TA", "b::TB"}, - {"a::TA f() { return a::TA(); }", "b::TB f() { return b::TB(); }", - "a::TA", "b::TB"}, - {"a::TA f() { return a::UA(); }", "b::TB f() { return a::UA(); }", - "a::TA", "b::TB"}, - {"a::TA f() { return a::UA(); }", "a::TA f() { return b::UB(); }", - "a::UA", "b::UB"}, - {"void f() { a::TA a; }", "void f() { b::TB a; }", "a::TA", "b::TB"}, - {"void f(const a::TA& a1) {}", "void f(const b::TB& a1) {}", "a::TA", - "b::TB"}, - {"void f(const a::UA& a1) {}", "void f(const b::UB& a1) {}", "a::UA", - "b::UB"}, - {"void f(const a::TA* a1) {}", "void f(const b::TB* a1) {}", "a::TA", - "b::TB"}, - {"namespace a { void f(TA a1) {} }", - "namespace a { void f(b::TB a1) {} }", "a::TA", "b::TB"}, - {"void f(MACRO(a::TA) a1) {}", "void f(MACRO(b::TB) a1) {}", "a::TA", - "b::TB"}, - {"void f(MACRO(a::TA a1)) {}", "void f(MACRO(b::TB a1)) {}", "a::TA", - "b::TB"}, - - // shorten/add namespace. - {"namespace b { void f(a::UA a1) {} }", - "namespace b {void f(UB a1) {} }", "a::UA", "b::UB"}, - {"namespace a { void f(UA a1) {} }", - "namespace a {void f(b::UB a1) {} }", "a::UA", "b::UB"}, - - // use namespace and typedefs - {"struct S { using T = a::TA; T a_; };", - "struct S { using T = b::TB; T a_; };", "a::TA", "b::TB"}, - {"using T = a::TA; T gA;", "using T = b::TB; T gA;", "a::TA", "b::TB"}, - {"using T = a::UA; T gA;", "using T = b::UB; T gA;", "a::UA", "b::UB"}, - {"typedef a::TA T; T gA;", "typedef b::TB T; T gA;", "a::TA", "b::TB"}, - {"typedef a::UA T; T gA;", "typedef b::UB T; T gA;", "a::UA", "b::UB"}, - {"typedef MACRO(a::TA) T; T gA;", "typedef MACRO(b::TB) T; T gA;", - "a::TA", "b::TB"}, - - // types in using shadows. - {"using a::TA; TA gA;", "using b::TB; b::TB gA;", "a::TA", "b::TB"}, - {"using a::UA; UA gA;", "using b::UB; b::UB gA;", "a::UA", "b::UB"}, - - // struct members and other oddities - {"struct S : public a::TA {};", "struct S : public b::TB {};", "a::TA", - "b::TB"}, - {"struct S : public a::UA {};", "struct S : public b::UB {};", "a::UA", - "b::UB"}, - {"struct F { void f(a::TA a1) {} };", - "struct F { void f(b::TB a1) {} };", "a::TA", "b::TB"}, - {"struct F { a::TA a_; };", "struct F { b::TB a_; };", "a::TA", - "b::TB"}, - {"struct F { ptr a_; };", "struct F { ptr a_; };", - "a::TA", "b::TB"}, - {"struct F { ptr a_; };", "struct F { ptr a_; };", - "a::UA", "b::UB"}, - - // types in nested name specifiers - {"void f() { a::TA::Nested ne; }", "void f() { b::TB::Nested ne; }", - "a::TA", "b::TB"}, - {"void f() { a::UA::Nested ne; }", "void f() { b::UB::Nested ne; }", - "a::UA", "b::UB"}, - {"void f() { a::TA::Nested::NestedEnum e; }", - "void f() { b::TB::Nested::NestedEnum e; }", "a::TA", "b::TB"}, - {"void f() { auto e = a::TA::Nested::NestedEnum::E1; }", - "void f() { auto e = b::TB::Nested::NestedEnum::E1; }", "a::TA", - "b::TB"}, - {"void f() { auto e = a::TA::Nested::E1; }", - "void f() { auto e = b::TB::Nested::E1; }", "a::TA", "b::TB"}, - - // templates - {"template struct Foo { T t; }; void f() { Foo " - "foo; }", - "template struct Foo { T t; }; void f() { Foo " - "foo; }", - "a::TA", "b::TB"}, - {"template struct Foo { a::TA a; };", - "template struct Foo { b::TB a; };", "a::TA", "b::TB"}, - {"template void f(T t) {} void g() { f(a::TA()); }", - "template void f(T t) {} void g() { f(b::TB()); }", - "a::TA", "b::TB"}, - {"template void f(T t) {} void g() { f(a::UA()); }", - "template void f(T t) {} void g() { f(b::UB()); }", - "a::UA", "b::UB"}, - {"template int f() { return 1; } template <> int " - "f() { return 2; } int g() { return f(); }", - "template int f() { return 1; } template <> int " - "f() { return 2; } int g() { return f(); }", - "a::TA", "b::TB"}, - {"struct Foo { template T foo(); }; void g() { Foo f; " - "auto a = f.template foo(); }", - "struct Foo { template T foo(); }; void g() { Foo f; " - "auto a = f.template foo(); }", - "a::TA", "b::TB"}, - {"struct Foo { template T foo(); }; void g() { Foo f; " - "auto a = f.template foo(); }", - "struct Foo { template T foo(); }; void g() { Foo f; " - "auto a = f.template foo(); }", - "a::UA", "b::UB"}, - - // The following two templates are distilled from regressions found in - // unique_ptr<> and type_traits.h - {"template struct outer { typedef T type; type Baz(); }; " - "outer g_A;", - "template struct outer { typedef T type; type Baz(); }; " - "outer g_A;", - "a::TA", "b::TB"}, - {"template struct nested { typedef T type; }; template " - " struct outer { typename nested::type Foo(); }; " - "outer g_A;", - "template struct nested { typedef T type; }; template " - " struct outer { typename nested::type Foo(); }; " - "outer g_A;", - "a::TA", "b::TB"}, - - // macros - {"#define FOO(T, t) T t\nvoid f() { FOO(a::TA, a1); FOO(a::TA, a2); }", - "#define FOO(T, t) T t\nvoid f() { FOO(b::TB, a1); FOO(b::TB, a2); }", - "a::TA", "b::TB"}, - {"#define FOO(n) a::TA n\nvoid f() { FOO(a1); FOO(a2); }", - "#define FOO(n) b::TB n\nvoid f() { FOO(a1); FOO(a2); }", "a::TA", - "b::TB"}, - {"#define FOO(n) a::UA n\nvoid f() { FOO(a1); FOO(a2); }", - "#define FOO(n) b::UB n\nvoid f() { FOO(a1); FOO(a2); }", "a::UA", - "b::UB"}, - - // Pointer to member functions - {"auto gA = &a::TA::foo;", "auto gA = &b::TB::foo;", "a::TA", "b::TB"}, - {"using a::TA; auto gA = &TA::foo;", - "using b::TB; auto gA = &b::TB::foo;", "a::TA", "b::TB"}, - {"typedef a::TA T; auto gA = &T::foo;", - "typedef b::TB T; auto gA = &T::foo;", "a::TA", "b::TB"}, - {"auto gA = &MACRO(a::TA)::foo;", "auto gA = &MACRO(b::TB)::foo;", - "a::TA", "b::TB"}, - - // templated using alias. - {"void f(TPtr p) {}", "void f(NewTPtr p) {}", "TPtr", - "NewTPtr"}, - {"void f(::TPtr p) {}", "void f(::NewTPtr p) {}", "TPtr", - "NewTPtr"}, - }))); - -TEST_P(RenameAliasTest, RenameAlias) { - auto Param = GetParam(); - assert(!Param.OldName.empty()); - assert(!Param.NewName.empty()); - std::string Actual = - runClangRenameOnCode(Param.Before, Param.OldName, Param.NewName); - CompareSnippets(Param.After, Actual); -} - -TEST_F(RenameAliasTest, RenameTypedefDefinitions) { - std::string Before = R"( - class X {}; - typedef X TOld; - )"; - std::string Expected = R"( - class X {}; - typedef X TNew; - )"; - std::string After = runClangRenameOnCode(Before, "TOld", "TNew"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameAliasTest, RenameUsingAliasDefinitions) { - std::string Before = R"( - class X {}; - using UOld = X; - )"; - std::string Expected = R"( - class X {}; - using UNew = X; - )"; - std::string After = runClangRenameOnCode(Before, "UOld", "UNew"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameAliasTest, RenameTemplatedAliasDefinitions) { - std::string Before = R"( - template - class X { T t; }; - - template - using Old = X; - )"; - std::string Expected = R"( - template - class X { T t; }; - - template - using New = X; - )"; - std::string After = runClangRenameOnCode(Before, "Old", "New"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameAliasTest, RenameAliasesInNamespaces) { - std::string Before = R"( - namespace x { class X {}; } - namespace ns { - using UOld = x::X; - } - )"; - std::string Expected = R"( - namespace x { class X {}; } - namespace ns { - using UNew = x::X; - } - )"; - std::string After = runClangRenameOnCode(Before, "ns::UOld", "ns::UNew"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameAliasTest, AliasesInMacros) { - std::string Before = R"( - namespace x { class Old {}; } - namespace ns { - #define REF(alias) alias alias_var; - - #define ALIAS(old) \ - using old##Alias = x::old; \ - REF(old##Alias); - - ALIAS(Old); - - OldAlias old_alias; - } - )"; - std::string Expected = R"( - namespace x { class Old {}; } - namespace ns { - #define REF(alias) alias alias_var; - - #define ALIAS(old) \ - using old##Alias = x::old; \ - REF(old##Alias); - - ALIAS(Old); - - NewAlias old_alias; - } - )"; - std::string After = - runClangRenameOnCode(Before, "ns::OldAlias", "ns::NewAlias"); - CompareSnippets(Expected, After); -} - -} // anonymous namespace -} // namespace test -} // namespace clang_rename -} // namesdpace clang diff --git a/clang/unittests/Rename/RenameClassTest.cpp b/clang/unittests/Rename/RenameClassTest.cpp deleted file mode 100644 index 24370b5795e9..000000000000 --- a/clang/unittests/Rename/RenameClassTest.cpp +++ /dev/null @@ -1,820 +0,0 @@ -//===-- RenameClassTest.cpp - unit tests for renaming classes -------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "ClangRenameTest.h" - -namespace clang { -namespace clang_rename { -namespace test { -namespace { - -class RenameClassTest : public ClangRenameTest { -public: - RenameClassTest() { - AppendToHeader(R"( - namespace a { - class Foo { - public: - struct Nested { - enum NestedEnum {E1, E2}; - }; - void func() {} - static int Constant; - }; - class Goo { - public: - struct Nested { - enum NestedEnum {E1, E2}; - }; - }; - int Foo::Constant = 1; - } // namespace a - namespace b { - class Foo {}; - } // namespace b - - #define MACRO(x) x - - template class ptr {}; - )"); - } -}; - -INSTANTIATE_TEST_SUITE_P( - RenameClassTests, RenameClassTest, - testing::ValuesIn(std::vector({ - // basic classes - {"a::Foo f;", "b::Bar f;", "", ""}, - {"::a::Foo f;", "::b::Bar f;", "", ""}, - {"void f(a::Foo f) {}", "void f(b::Bar f) {}", "", ""}, - {"void f(a::Foo *f) {}", "void f(b::Bar *f) {}", "", ""}, - {"a::Foo f() { return a::Foo(); }", "b::Bar f() { return b::Bar(); }", - "", ""}, - {"namespace a {a::Foo f() { return Foo(); }}", - "namespace a {b::Bar f() { return b::Bar(); }}", "", ""}, - {"void f(const a::Foo& a1) {}", "void f(const b::Bar& a1) {}", "", ""}, - {"void f(const a::Foo* a1) {}", "void f(const b::Bar* a1) {}", "", ""}, - {"namespace a { void f(Foo a1) {} }", - "namespace a { void f(b::Bar a1) {} }", "", ""}, - {"void f(MACRO(a::Foo) a1) {}", "void f(MACRO(b::Bar) a1) {}", "", ""}, - {"void f(MACRO(a::Foo a1)) {}", "void f(MACRO(b::Bar a1)) {}", "", ""}, - {"a::Foo::Nested ns;", "b::Bar::Nested ns;", "", ""}, - {"auto t = a::Foo::Constant;", "auto t = b::Bar::Constant;", "", ""}, - {"a::Foo::Nested ns;", "a::Foo::Nested2 ns;", "a::Foo::Nested", - "a::Foo::Nested2"}, - - // use namespace and typedefs - {"using a::Foo; Foo gA;", "using b::Bar; b::Bar gA;", "", ""}, - {"using a::Foo; void f(Foo gA) {}", "using b::Bar; void f(Bar gA) {}", - "", ""}, - {"using a::Foo; namespace x { Foo gA; }", - "using b::Bar; namespace x { Bar gA; }", "", ""}, - {"struct S { using T = a::Foo; T a_; };", - "struct S { using T = b::Bar; T a_; };", "", ""}, - {"using T = a::Foo; T gA;", "using T = b::Bar; T gA;", "", ""}, - {"typedef a::Foo T; T gA;", "typedef b::Bar T; T gA;", "", ""}, - {"typedef MACRO(a::Foo) T; T gA;", "typedef MACRO(b::Bar) T; T gA;", "", - ""}, - - // struct members and other oddities - {"struct S : public a::Foo {};", "struct S : public b::Bar {};", "", - ""}, - {"struct F { void f(a::Foo a1) {} };", - "struct F { void f(b::Bar a1) {} };", "", ""}, - {"struct F { a::Foo a_; };", "struct F { b::Bar a_; };", "", ""}, - {"struct F { ptr a_; };", "struct F { ptr a_; };", "", - ""}, - - {"void f() { a::Foo::Nested ne; }", "void f() { b::Bar::Nested ne; }", - "", ""}, - {"void f() { a::Goo::Nested ne; }", "void f() { a::Goo::Nested ne; }", - "", ""}, - {"void f() { a::Foo::Nested::NestedEnum e; }", - "void f() { b::Bar::Nested::NestedEnum e; }", "", ""}, - {"void f() { auto e = a::Foo::Nested::NestedEnum::E1; }", - "void f() { auto e = b::Bar::Nested::NestedEnum::E1; }", "", ""}, - {"void f() { auto e = a::Foo::Nested::E1; }", - "void f() { auto e = b::Bar::Nested::E1; }", "", ""}, - - // templates - {"template struct Foo { T t; };\n" - "void f() { Foo foo; }", - "template struct Foo { T t; };\n" - "void f() { Foo foo; }", - "", ""}, - {"template struct Foo { a::Foo a; };", - "template struct Foo { b::Bar a; };", "", ""}, - {"template void f(T t) {}\n" - "void g() { f(a::Foo()); }", - "template void f(T t) {}\n" - "void g() { f(b::Bar()); }", - "", ""}, - {"template int f() { return 1; }\n" - "template <> int f() { return 2; }\n" - "int g() { return f(); }", - "template int f() { return 1; }\n" - "template <> int f() { return 2; }\n" - "int g() { return f(); }", - "", ""}, - {"struct Foo { template T foo(); };\n" - "void g() { Foo f; auto a = f.template foo(); }", - "struct Foo { template T foo(); };\n" - "void g() { Foo f; auto a = f.template foo(); }", - "", ""}, - - // The following two templates are distilled from regressions found in - // unique_ptr<> and type_traits.h - {"template struct outer {\n" - " typedef T type;\n" - " type Baz();\n" - " };\n" - " outer g_A;", - "template struct outer {\n" - " typedef T type;\n" - " type Baz();\n" - " };\n" - " outer g_A;", - "", ""}, - {"template struct nested { typedef T type; };\n" - "template struct outer { typename nested::type Foo(); " - "};\n" - "outer g_A;", - "template struct nested { typedef T type; };\n" - "template struct outer { typename nested::type Foo(); " - "};\n" - "outer g_A;", - "", ""}, - - // macros - {"#define FOO(T, t) T t\n" - "void f() { FOO(a::Foo, a1); FOO(a::Foo, a2); }", - "#define FOO(T, t) T t\n" - "void f() { FOO(b::Bar, a1); FOO(b::Bar, a2); }", - "", ""}, - {"#define FOO(n) a::Foo n\n" - " void f() { FOO(a1); FOO(a2); }", - "#define FOO(n) b::Bar n\n" - " void f() { FOO(a1); FOO(a2); }", - "", ""}, - - // Pointer to member functions - {"auto gA = &a::Foo::func;", "auto gA = &b::Bar::func;", "", ""}, - {"using a::Foo; auto gA = &Foo::func;", - "using b::Bar; auto gA = &b::Bar::func;", "", ""}, - {"using a::Foo; namespace x { auto gA = &Foo::func; }", - "using b::Bar; namespace x { auto gA = &Bar::func; }", "", ""}, - {"typedef a::Foo T; auto gA = &T::func;", - "typedef b::Bar T; auto gA = &T::func;", "", ""}, - {"auto gA = &MACRO(a::Foo)::func;", "auto gA = &MACRO(b::Bar)::func;", - "", ""}, - - // Short match inside a namespace - {"namespace a { void f(Foo a1) {} }", - "namespace a { void f(b::Bar a1) {} }", "", ""}, - - // Correct match. - {"using a::Foo; struct F { ptr a_; };", - "using b::Bar; struct F { ptr a_; };", "", ""}, - - // avoid false positives - {"void f(b::Foo a) {}", "void f(b::Foo a) {}", "", ""}, - {"namespace b { void f(Foo a) {} }", "namespace b { void f(Foo a) {} }", - "", ""}, - - // friends, everyone needs friends. - {"class Foo { int i; friend class a::Foo; };", - "class Foo { int i; friend class b::Bar; };", "", ""}, - })) ); - -TEST_P(RenameClassTest, RenameClasses) { - auto Param = GetParam(); - std::string OldName = Param.OldName.empty() ? "a::Foo" : Param.OldName; - std::string NewName = Param.NewName.empty() ? "b::Bar" : Param.NewName; - std::string Actual = runClangRenameOnCode(Param.Before, OldName, NewName); - CompareSnippets(Param.After, Actual); -} - -class NamespaceDetectionTest : public ClangRenameTest { -protected: - NamespaceDetectionTest() { - AppendToHeader(R"( - class Old {}; - namespace o1 { - class Old {}; - namespace o2 { - class Old {}; - namespace o3 { - class Old {}; - } // namespace o3 - } // namespace o2 - } // namespace o1 - )"); - } -}; - -INSTANTIATE_TEST_SUITE_P( - RenameClassTest, NamespaceDetectionTest, - ::testing::ValuesIn(std::vector({ - // Test old and new namespace overlap. - {"namespace o1 { namespace o2 { namespace o3 { Old moo; } } }", - "namespace o1 { namespace o2 { namespace o3 { New moo; } } }", - "o1::o2::o3::Old", "o1::o2::o3::New"}, - {"namespace o1 { namespace o2 { namespace o3 { Old moo; } } }", - "namespace o1 { namespace o2 { namespace o3 { n3::New moo; } } }", - "o1::o2::o3::Old", "o1::o2::n3::New"}, - {"namespace o1 { namespace o2 { namespace o3 { Old moo; } } }", - "namespace o1 { namespace o2 { namespace o3 { n2::n3::New moo; } } }", - "o1::o2::o3::Old", "o1::n2::n3::New"}, - {"namespace o1 { namespace o2 { Old moo; } }", - "namespace o1 { namespace o2 { New moo; } }", "::o1::o2::Old", - "::o1::o2::New"}, - {"namespace o1 { namespace o2 { Old moo; } }", - "namespace o1 { namespace o2 { n2::New moo; } }", "::o1::o2::Old", - "::o1::n2::New"}, - {"namespace o1 { namespace o2 { Old moo; } }", - "namespace o1 { namespace o2 { ::n1::n2::New moo; } }", - "::o1::o2::Old", "::n1::n2::New"}, - {"namespace o1 { namespace o2 { Old moo; } }", - "namespace o1 { namespace o2 { n1::n2::New moo; } }", "::o1::o2::Old", - "n1::n2::New"}, - - // Test old and new namespace with differing depths. - {"namespace o1 { namespace o2 { namespace o3 { Old moo; } } }", - "namespace o1 { namespace o2 { namespace o3 { New moo; } } }", - "o1::o2::o3::Old", "::o1::New"}, - {"namespace o1 { namespace o2 { namespace o3 { Old moo; } } }", - "namespace o1 { namespace o2 { namespace o3 { New moo; } } }", - "o1::o2::o3::Old", "::o1::o2::New"}, - {"namespace o1 { namespace o2 { namespace o3 { Old moo; } } }", - "namespace o1 { namespace o2 { namespace o3 { New moo; } } }", - "o1::o2::o3::Old", "o1::New"}, - {"namespace o1 { namespace o2 { namespace o3 { Old moo; } } }", - "namespace o1 { namespace o2 { namespace o3 { New moo; } } }", - "o1::o2::o3::Old", "o1::o2::New"}, - {"Old moo;", "o1::New moo;", "::Old", "o1::New"}, - {"Old moo;", "o1::New moo;", "Old", "o1::New"}, - {"namespace o1 { ::Old moo; }", "namespace o1 { New moo; }", "Old", - "o1::New"}, - {"namespace o1 { namespace o2 { Old moo; } }", - "namespace o1 { namespace o2 { ::New moo; } }", "::o1::o2::Old", - "::New"}, - {"namespace o1 { namespace o2 { Old moo; } }", - "namespace o1 { namespace o2 { New moo; } }", "::o1::o2::Old", "New"}, - - // Test moving into the new namespace at different levels. - {"namespace n1 { namespace n2 { o1::o2::Old moo; } }", - "namespace n1 { namespace n2 { New moo; } }", "::o1::o2::Old", - "::n1::n2::New"}, - {"namespace n1 { namespace n2 { o1::o2::Old moo; } }", - "namespace n1 { namespace n2 { New moo; } }", "::o1::o2::Old", - "n1::n2::New"}, - {"namespace n1 { namespace n2 { o1::o2::Old moo; } }", - "namespace n1 { namespace n2 { o2::New moo; } }", "::o1::o2::Old", - "::n1::o2::New"}, - {"namespace n1 { namespace n2 { o1::o2::Old moo; } }", - "namespace n1 { namespace n2 { o2::New moo; } }", "::o1::o2::Old", - "n1::o2::New"}, - {"namespace n1 { namespace n2 { o1::o2::Old moo; } }", - "namespace n1 { namespace n2 { ::o1::o2::New moo; } }", - "::o1::o2::Old", "::o1::o2::New"}, - {"namespace n1 { namespace n2 { o1::o2::Old moo; } }", - "namespace n1 { namespace n2 { o1::o2::New moo; } }", "::o1::o2::Old", - "o1::o2::New"}, - - // Test friends declarations. - {"class Foo { friend class o1::Old; };", - "class Foo { friend class o1::New; };", "o1::Old", "o1::New"}, - {"class Foo { int i; friend class o1::Old; };", - "class Foo { int i; friend class ::o1::New; };", "::o1::Old", - "::o1::New"}, - {"namespace o1 { class Foo { int i; friend class Old; }; }", - "namespace o1 { class Foo { int i; friend class New; }; }", "o1::Old", - "o1::New"}, - {"namespace o1 { class Foo { int i; friend class Old; }; }", - "namespace o1 { class Foo { int i; friend class New; }; }", - "::o1::Old", "::o1::New"}, - })) ); - -TEST_P(NamespaceDetectionTest, RenameClasses) { - auto Param = GetParam(); - std::string Actual = - runClangRenameOnCode(Param.Before, Param.OldName, Param.NewName); - CompareSnippets(Param.After, Actual); -} - -class TemplatedClassRenameTest : public ClangRenameTest { -protected: - TemplatedClassRenameTest() { - AppendToHeader(R"( - template struct Old { - T t_; - T f() { return T(); }; - static T s(T t) { return t; } - }; - namespace ns { - template struct Old { - T t_; - T f() { return T(); }; - static T s(T t) { return t; } - }; - } // namespace ns - - namespace o1 { - namespace o2 { - namespace o3 { - template struct Old { - T t_; - T f() { return T(); }; - static T s(T t) { return t; } - }; - } // namespace o3 - } // namespace o2 - } // namespace o1 - )"); - } -}; - -INSTANTIATE_TEST_SUITE_P( - RenameClassTests, TemplatedClassRenameTest, - ::testing::ValuesIn(std::vector({ - {"Old gI; Old gB;", "New gI; New gB;", "Old", - "New"}, - {"ns::Old gI; ns::Old gB;", - "ns::New gI; ns::New gB;", "ns::Old", "ns::New"}, - {"auto gI = &Old::f; auto gB = &Old::f;", - "auto gI = &New::f; auto gB = &New::f;", "Old", "New"}, - {"auto gI = &ns::Old::f;", "auto gI = &ns::New::f;", - "ns::Old", "ns::New"}, - - {"int gI = Old::s(0); bool gB = Old::s(false);", - "int gI = New::s(0); bool gB = New::s(false);", "Old", - "New"}, - {"int gI = ns::Old::s(0); bool gB = ns::Old::s(false);", - "int gI = ns::New::s(0); bool gB = ns::New::s(false);", - "ns::Old", "ns::New"}, - - {"struct S { Old o_; };", "struct S { New o_; };", "Old", - "New"}, - {"struct S { ns::Old o_; };", "struct S { ns::New o_; };", - "ns::Old", "ns::New"}, - - {"auto a = reinterpret_cast*>(new Old);", - "auto a = reinterpret_cast*>(new New);", "Old", "New"}, - {"auto a = reinterpret_cast*>(new ns::Old);", - "auto a = reinterpret_cast*>(new ns::New);", - "ns::Old", "ns::New"}, - {"auto a = reinterpret_cast*>(new Old);", - "auto a = reinterpret_cast*>(new New);", "Old", - "New"}, - {"auto a = reinterpret_cast*>(new ns::Old);", - "auto a = reinterpret_cast*>(new ns::New);", - "ns::Old", "ns::New"}, - - {"Old& foo();", "New& foo();", "Old", "New"}, - {"ns::Old& foo();", "ns::New& foo();", "ns::Old", - "ns::New"}, - {"o1::o2::o3::Old& foo();", "o1::o2::o3::New& foo();", - "o1::o2::o3::Old", "o1::o2::o3::New"}, - {"namespace ns { Old& foo(); }", - "namespace ns { New& foo(); }", "ns::Old", "ns::New"}, - {"const Old& foo();", "const New& foo();", "Old", "New"}, - {"const ns::Old& foo();", "const ns::New& foo();", - "ns::Old", "ns::New"}, - - // FIXME: figure out why this only works when Moo gets - // specialized at some point. - {"template struct Moo { Old o_; }; Moo m;", - "template struct Moo { New o_; }; Moo m;", "Old", - "New"}, - {"template struct Moo { ns::Old o_; }; Moo m;", - "template struct Moo { ns::New o_; }; Moo m;", - "ns::Old", "ns::New"}, - })) ); - -TEST_P(TemplatedClassRenameTest, RenameTemplateClasses) { - auto Param = GetParam(); - std::string Actual = - runClangRenameOnCode(Param.Before, Param.OldName, Param.NewName); - CompareSnippets(Param.After, Actual); -} - -TEST_F(ClangRenameTest, RenameClassWithOutOfLineMembers) { - std::string Before = R"( - class Old { - public: - Old(); - ~Old(); - - Old* next(); - - private: - Old* next_; - }; - - Old::Old() {} - Old::~Old() {} - Old* Old::next() { return next_; } - )"; - std::string Expected = R"( - class New { - public: - New(); - ~New(); - - New* next(); - - private: - New* next_; - }; - - New::New() {} - New::~New() {} - New* New::next() { return next_; } - )"; - std::string After = runClangRenameOnCode(Before, "Old", "New"); - CompareSnippets(Expected, After); -} - -TEST_F(ClangRenameTest, RenameClassWithInlineMembers) { - std::string Before = R"( - class Old { - public: - Old() {} - ~Old() {} - - Old* next() { return next_; } - - private: - Old* next_; - }; - )"; - std::string Expected = R"( - class New { - public: - New() {} - ~New() {} - - New* next() { return next_; } - - private: - New* next_; - }; - )"; - std::string After = runClangRenameOnCode(Before, "Old", "New"); - CompareSnippets(Expected, After); -} - -TEST_F(ClangRenameTest, RenameClassWithNamespaceWithInlineMembers) { - std::string Before = R"( - namespace ns { - class Old { - public: - Old() {} - ~Old() {} - - Old* next() { return next_; } - - private: - Old* next_; - }; - } // namespace ns - )"; - std::string Expected = R"( - namespace ns { - class New { - public: - New() {} - ~New() {} - - New* next() { return next_; } - - private: - New* next_; - }; - } // namespace ns - )"; - std::string After = runClangRenameOnCode(Before, "ns::Old", "ns::New"); - CompareSnippets(Expected, After); -} - -TEST_F(ClangRenameTest, RenameClassWithNamespaceWithOutOfInlineMembers) { - std::string Before = R"( - namespace ns { - class Old { - public: - Old(); - ~Old(); - - Old* next(); - - private: - Old* next_; - }; - - Old::Old() {} - Old::~Old() {} - Old* Old::next() { return next_; } - } // namespace ns - )"; - std::string Expected = R"( - namespace ns { - class New { - public: - New(); - ~New(); - - New* next(); - - private: - New* next_; - }; - - New::New() {} - New::~New() {} - New* New::next() { return next_; } - } // namespace ns - )"; - std::string After = runClangRenameOnCode(Before, "ns::Old", "ns::New"); - CompareSnippets(Expected, After); -} - -TEST_F(ClangRenameTest, RenameClassInInheritedConstructor) { - // `using Base::Base;` will generate an implicit constructor containing usage - // of `::ns::Old` which should not be matched. - std::string Before = R"( - namespace ns { - class Old; - class Old { - int x; - }; - class Base { - protected: - Old *moo_; - public: - Base(Old *moo) : moo_(moo) {} - }; - class Derived : public Base { - public: - using Base::Base; - }; - } // namespace ns - int main() { - ::ns::Old foo; - ::ns::Derived d(&foo); - return 0; - })"; - std::string Expected = R"( - namespace ns { - class New; - class New { - int x; - }; - class Base { - protected: - New *moo_; - public: - Base(New *moo) : moo_(moo) {} - }; - class Derived : public Base { - public: - using Base::Base; - }; - } // namespace ns - int main() { - ::ns::New foo; - ::ns::Derived d(&foo); - return 0; - })"; - std::string After = runClangRenameOnCode(Before, "ns::Old", "ns::New"); - CompareSnippets(Expected, After); -} - -TEST_F(ClangRenameTest, DontRenameReferencesInImplicitFunction) { - std::string Before = R"( - namespace ns { - class Old { - }; - } // namespace ns - struct S { - int y; - ns::Old old; - }; - void f() { - S s1, s2, s3; - // This causes an implicit assignment operator to be created. - s1 = s2 = s3; - } - )"; - std::string Expected = R"( - namespace ns { - class New { - }; - } // namespace ns - struct S { - int y; - ::new_ns::New old; - }; - void f() { - S s1, s2, s3; - // This causes an implicit assignment operator to be created. - s1 = s2 = s3; - } - )"; - std::string After = runClangRenameOnCode(Before, "ns::Old", "::new_ns::New"); - CompareSnippets(Expected, After); -} - -TEST_F(ClangRenameTest, ReferencesInLambdaFunctionParameters) { - std::string Before = R"( - template - class function; - template - class function { - public: - template - function(Functor f) {} - - function() {} - - R operator()(ArgTypes...) const {} - }; - - namespace ns { - class Old {}; - void f() { - function func; - } - } // namespace ns)"; - std::string Expected = R"( - template - class function; - template - class function { - public: - template - function(Functor f) {} - - function() {} - - R operator()(ArgTypes...) const {} - }; - - namespace ns { - class New {}; - void f() { - function func; - } - } // namespace ns)"; - std::string After = runClangRenameOnCode(Before, "ns::Old", "::new_ns::New"); - CompareSnippets(Expected, After); -} - -TEST_F(ClangRenameTest, DontChangeIfSameName) { - std::string Before = R"( - namespace foo { - class Old { - public: - static void foo() {} - }; - } - - void f(foo::Old * x) { - foo::Old::foo() ; - } - using foo::Old;)"; - std::string Expected = R"( - namespace foo { - class Old { - public: - static void foo() {} - }; - } - - void f(foo::Old * x) { - foo::Old::foo() ; - } - using foo::Old;)"; - std::string After = runClangRenameOnCode(Before, "foo::Old", "foo::Old"); - CompareSnippets(Expected, After); -} - -TEST_F(ClangRenameTest, ChangeIfNewNameWithLeadingDotDot) { - std::string Before = R"( - namespace foo { - class Old { - public: - static void foo() {} - }; - } - - void f(foo::Old * x) { - foo::Old::foo() ; - } - using foo::Old;)"; - std::string Expected = R"( - namespace foo { - class Old { - public: - static void foo() {} - }; - } - - void f(::foo::Old * x) { - ::foo::Old::foo() ; - } - using ::foo::Old;)"; - std::string After = runClangRenameOnCode(Before, "foo::Old", "::foo::Old"); - CompareSnippets(Expected, After); -} - -TEST_F(ClangRenameTest, ChangeIfSameNameWithLeadingDotDot) { - std::string Before = R"( - namespace foo { - class Old { - public: - static void foo() {} - }; - } - - void f(foo::Old * x) { - foo::Old::foo() ; - } - using foo::Old;)"; - std::string Expected = R"( - namespace foo { - class Old { - public: - static void foo() {} - }; - } - - void f(::foo::Old * x) { - ::foo::Old::foo() ; - } - using ::foo::Old;)"; - std::string After = runClangRenameOnCode(Before, "::foo::Old", "::foo::Old"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameClassTest, UsingAlias) { - std::string Before = R"( - namespace a { struct A {}; } - - namespace foo { - using Alias = a::A; - Alias a; - })"; - std::string Expected = R"( - namespace a { struct B {}; } - - namespace foo { - using Alias = b::B; - Alias a; - })"; - std::string After = runClangRenameOnCode(Before, "a::A", "b::B"); - CompareSnippets(Expected, After); -} - -TEST_F(ClangRenameTest, FieldDesignatedInitializers) { - std::string Before = R"( - struct S { - int a; - }; - void foo() { - S s = { .a = 10 }; - s.a = 20; - })"; - std::string Expected = R"( - struct S { - int b; - }; - void foo() { - S s = { .b = 10 }; - s.b = 20; - })"; - std::string After = runClangRenameOnCode(Before, "S::a", "S::b"); - CompareSnippets(Expected, After); -} - -// FIXME: investigate why the test fails when adding a new USR to the USRSet. -TEST_F(ClangRenameTest, DISABLED_NestedTemplates) { - std::string Before = R"( - namespace a { template struct A {}; } - a::A> foo;)"; - std::string Expected = R"( - namespace a { template struct B {}; } - b::B> foo;)"; - std::string After = runClangRenameOnCode(Before, "a::A", "b::B"); - CompareSnippets(Expected, After); -} - - -} // anonymous namespace -} // namespace test -} // namespace clang_rename -} // namesdpace clang diff --git a/clang/unittests/Rename/RenameEnumTest.cpp b/clang/unittests/Rename/RenameEnumTest.cpp deleted file mode 100644 index dc3440047c4a..000000000000 --- a/clang/unittests/Rename/RenameEnumTest.cpp +++ /dev/null @@ -1,189 +0,0 @@ -#include "ClangRenameTest.h" - -namespace clang { -namespace clang_rename { -namespace test { -namespace { - -class RenameEnumTest : public ClangRenameTest { -public: - RenameEnumTest() { - AppendToHeader(R"( - #define MACRO(x) x - namespace a { - enum A1 { Red }; - enum class A2 { Blue }; - struct C { - enum NestedEnum { White }; - enum class NestedScopedEnum { Black }; - }; - namespace d { - enum A3 { Orange }; - } // namespace d - enum A4 { Pink }; - } // namespace a - enum A5 { Green };)"); - } -}; - -INSTANTIATE_TEST_SUITE_P( - RenameEnumTests, RenameEnumTest, - testing::ValuesIn(std::vector({ - {"void f(a::A2 arg) { a::A2 t = a::A2::Blue; }", - "void f(b::B2 arg) { b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"}, - {"void f() { a::A1* t1; }", "void f() { b::B1* t1; }", "a::A1", - "b::B1"}, - {"void f() { a::A2* t1; }", "void f() { b::B2* t1; }", "a::A2", - "b::B2"}, - {"void f() { enum a::A2 t = a::A2::Blue; }", - "void f() { enum b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"}, - {"void f() { enum a::A2 t = a::A2::Blue; }", - "void f() { enum b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"}, - - {"void f() { a::A1 t = a::Red; }", "void f() { b::B1 t = b::B1::Red; }", - "a::A1", "b::B1"}, - {"void f() { a::A1 t = a::A1::Red; }", - "void f() { b::B1 t = b::B1::Red; }", "a::A1", "b::B1"}, - {"void f() { auto t = a::Red; }", "void f() { auto t = b::B1::Red; }", - "a::A1", "b::B1"}, - {"namespace b { void f() { a::A1 t = a::Red; } }", - "namespace b { void f() { B1 t = B1::Red; } }", "a::A1", "b::B1"}, - {"void f() { a::d::A3 t = a::d::Orange; }", - "void f() { a::b::B3 t = a::b::B3::Orange; }", "a::d::A3", "a::b::B3"}, - {"namespace a { void f() { a::d::A3 t = a::d::Orange; } }", - "namespace a { void f() { b::B3 t = b::B3::Orange; } }", "a::d::A3", - "a::b::B3"}, - {"void f() { A5 t = Green; }", "void f() { B5 t = Green; }", "A5", - "B5"}, - // FIXME: the new namespace qualifier should be added to the unscoped - // enum constant. - {"namespace a { void f() { auto t = Green; } }", - "namespace a { void f() { auto t = Green; } }", "a::A1", "b::B1"}, - - // namespace qualifiers - {"namespace a { void f(A1 a1) {} }", - "namespace a { void f(b::B1 a1) {} }", "a::A1", "b::B1"}, - {"namespace a { void f(A2 a2) {} }", - "namespace a { void f(b::B2 a2) {} }", "a::A2", "b::B2"}, - {"namespace b { void f(a::A1 a1) {} }", - "namespace b { void f(B1 a1) {} }", "a::A1", "b::B1"}, - {"namespace b { void f(a::A2 a2) {} }", - "namespace b { void f(B2 a2) {} }", "a::A2", "b::B2"}, - - // nested enums - {"void f() { a::C::NestedEnum t = a::C::White; }", - "void f() { a::C::NewNestedEnum t = a::C::NewNestedEnum::White; }", - "a::C::NestedEnum", "a::C::NewNestedEnum"}, - {"void f() { a::C::NestedScopedEnum t = a::C::NestedScopedEnum::Black; " - "}", - "void f() { a::C::NewNestedScopedEnum t = " - "a::C::NewNestedScopedEnum::Black; }", - "a::C::NestedScopedEnum", "a::C::NewNestedScopedEnum"}, - - // macros - {"void f(MACRO(a::A1) a1) {}", "void f(MACRO(b::B1) a1) {}", "a::A1", - "b::B1"}, - {"void f(MACRO(a::A2) a2) {}", "void f(MACRO(b::B2) a2) {}", "a::A2", - "b::B2"}, - {"#define FOO(T, t) T t\nvoid f() { FOO(a::A1, a1); }", - "#define FOO(T, t) T t\nvoid f() { FOO(b::B1, a1); }", "a::A1", - "b::B1"}, - {"#define FOO(T, t) T t\nvoid f() { FOO(a::A2, a2); }", - "#define FOO(T, t) T t\nvoid f() { FOO(b::B2, a2); }", "a::A2", - "b::B2"}, - {"#define FOO(n) a::A1 n\nvoid f() { FOO(a1); FOO(a2); }", - "#define FOO(n) b::B1 n\nvoid f() { FOO(a1); FOO(a2); }", "a::A1", - "b::B1"}, - - // using and type alias - {"using a::A1; A1 gA;", "using b::B1; b::B1 gA;", "a::A1", "b::B1"}, - {"using a::A2; A2 gA;", "using b::B2; b::B2 gA;", "a::A2", "b::B2"}, - {"struct S { using T = a::A1; T a_; };", - "struct S { using T = b::B1; T a_; };", "a::A1", "b::B1"}, - {"using T = a::A1; T gA;", "using T = b::B1; T gA;", "a::A1", "b::B1"}, - {"using T = a::A2; T gA;", "using T = b::B2; T gA;", "a::A2", "b::B2"}, - {"typedef a::A1 T; T gA;", "typedef b::B1 T; T gA;", "a::A1", "b::B1"}, - {"typedef a::A2 T; T gA;", "typedef b::B2 T; T gA;", "a::A2", "b::B2"}, - {"typedef MACRO(a::A1) T; T gA;", "typedef MACRO(b::B1) T; T gA;", - "a::A1", "b::B1"}, - - // templates - {"template struct Foo { T t; }; void f() { Foo " - "foo1; }", - "template struct Foo { T t; }; void f() { Foo " - "foo1; }", - "a::A1", "b::B1"}, - {"template struct Foo { T t; }; void f() { Foo " - "foo2; }", - "template struct Foo { T t; }; void f() { Foo " - "foo2; }", - "a::A2", "b::B2"}, - {"template struct Foo { a::A1 a1; };", - "template struct Foo { b::B1 a1; };", "a::A1", "b::B1"}, - {"template struct Foo { a::A2 a2; };", - "template struct Foo { b::B2 a2; };", "a::A2", "b::B2"}, - {"template int f() { return 1; } template<> int f() " - "{ return 2; } int g() { return f(); }", - "template int f() { return 1; } template<> int f() " - "{ return 2; } int g() { return f(); }", - "a::A1", "b::B1"}, - {"template int f() { return 1; } template<> int f() " - "{ return 2; } int g() { return f(); }", - "template int f() { return 1; } template<> int f() " - "{ return 2; } int g() { return f(); }", - "a::A2", "b::B2"}, - {"struct Foo { template T foo(); }; void g() { Foo f; " - "f.foo(); }", - "struct Foo { template T foo(); }; void g() { Foo f; " - "f.foo(); }", - "a::A1", "b::B1"}, - {"struct Foo { template T foo(); }; void g() { Foo f; " - "f.foo(); }", - "struct Foo { template T foo(); }; void g() { Foo f; " - "f.foo(); }", - "a::A2", "b::B2"}, - })) ); - -TEST_P(RenameEnumTest, RenameEnums) { - auto Param = GetParam(); - assert(!Param.OldName.empty()); - assert(!Param.NewName.empty()); - std::string Actual = - runClangRenameOnCode(Param.Before, Param.OldName, Param.NewName); - CompareSnippets(Param.After, Actual); -} - -TEST_F(RenameEnumTest, RenameEnumDecl) { - std::string Before = R"( - namespace ns { - enum Old1 { Blue }; - } - )"; - std::string Expected = R"( - namespace ns { - enum New1 { Blue }; - } - )"; - std::string After = runClangRenameOnCode(Before, "ns::Old1", "ns::New1"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameEnumTest, RenameScopedEnumDecl) { - std::string Before = R"( - namespace ns { - enum class Old1 { Blue }; - } - )"; - std::string Expected = R"( - namespace ns { - enum class New1 { Blue }; - } - )"; - std::string After = runClangRenameOnCode(Before, "ns::Old1", "ns::New1"); - CompareSnippets(Expected, After); -} - -} // anonymous namespace -} // namespace test -} // namespace clang_rename -} // namesdpace clang diff --git a/clang/unittests/Rename/RenameFunctionTest.cpp b/clang/unittests/Rename/RenameFunctionTest.cpp deleted file mode 100644 index 1c9b112232eb..000000000000 --- a/clang/unittests/Rename/RenameFunctionTest.cpp +++ /dev/null @@ -1,573 +0,0 @@ -//===-- RenameFunctionTest.cpp - unit tests for renaming functions --------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "ClangRenameTest.h" - -namespace clang { -namespace clang_rename { -namespace test { -namespace { - -class RenameFunctionTest : public ClangRenameTest { -public: - RenameFunctionTest() { - AppendToHeader(R"( - struct A { - static bool Foo(); - static bool Spam(); - }; - struct B { - static void Same(); - static bool Foo(); - static int Eric(int x); - }; - void Same(int x); - int Eric(int x); - namespace base { - void Same(); - void ToNanoSeconds(); - void ToInt64NanoSeconds(); - })"); - } -}; - -TEST_F(RenameFunctionTest, RefactorsAFoo) { - std::string Before = R"( - void f() { - A::Foo(); - ::A::Foo(); - })"; - std::string Expected = R"( - void f() { - A::Bar(); - ::A::Bar(); - })"; - - std::string After = runClangRenameOnCode(Before, "A::Foo", "A::Bar"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, RefactorsNonCallingAFoo) { - std::string Before = R"( - bool g(bool (*func)()) { - return func(); - } - void f() { - auto *ref1 = A::Foo; - auto *ref2 = ::A::Foo; - g(A::Foo); - })"; - std::string Expected = R"( - bool g(bool (*func)()) { - return func(); - } - void f() { - auto *ref1 = A::Bar; - auto *ref2 = ::A::Bar; - g(A::Bar); - })"; - std::string After = runClangRenameOnCode(Before, "A::Foo", "A::Bar"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, RefactorsEric) { - std::string Before = R"( - void f() { - if (Eric(3)==4) ::Eric(2); - })"; - std::string Expected = R"( - void f() { - if (Larry(3)==4) ::Larry(2); - })"; - std::string After = runClangRenameOnCode(Before, "Eric", "Larry"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, RefactorsNonCallingEric) { - std::string Before = R"( - int g(int (*func)(int)) { - return func(1); - } - void f() { - auto *ref = ::Eric; - g(Eric); - })"; - std::string Expected = R"( - int g(int (*func)(int)) { - return func(1); - } - void f() { - auto *ref = ::Larry; - g(Larry); - })"; - std::string After = runClangRenameOnCode(Before, "Eric", "Larry"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, DoesNotRefactorBFoo) { - std::string Before = R"( - void f() { - B::Foo(); - })"; - std::string After = runClangRenameOnCode(Before, "A::Foo", "A::Bar"); - CompareSnippets(Before, After); -} - -TEST_F(RenameFunctionTest, DoesNotRefactorBEric) { - std::string Before = R"( - void f() { - B::Eric(2); - })"; - std::string After = runClangRenameOnCode(Before, "Eric", "Larry"); - CompareSnippets(Before, After); -} - -TEST_F(RenameFunctionTest, DoesNotRefactorCEric) { - std::string Before = R"( - namespace C { int Eric(int x); } - void f() { - if (C::Eric(3)==4) ::C::Eric(2); - })"; - std::string Expected = R"( - namespace C { int Eric(int x); } - void f() { - if (C::Eric(3)==4) ::C::Eric(2); - })"; - std::string After = runClangRenameOnCode(Before, "Eric", "Larry"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, DoesNotRefactorEricInNamespaceC) { - std::string Before = R"( - namespace C { - int Eric(int x); - void f() { - if (Eric(3)==4) Eric(2); - } - } // namespace C)"; - std::string After = runClangRenameOnCode(Before, "Eric", "Larry"); - CompareSnippets(Before, After); -} - -TEST_F(RenameFunctionTest, NamespaceQualified) { - std::string Before = R"( - void f() { - base::ToNanoSeconds(); - ::base::ToNanoSeconds(); - } - void g() { - using base::ToNanoSeconds; - base::ToNanoSeconds(); - ::base::ToNanoSeconds(); - ToNanoSeconds(); - } - namespace foo { - namespace base { - void ToNanoSeconds(); - void f() { - base::ToNanoSeconds(); - } - } - void f() { - ::base::ToNanoSeconds(); - } - })"; - std::string Expected = R"( - void f() { - base::ToInt64NanoSeconds(); - ::base::ToInt64NanoSeconds(); - } - void g() { - using base::ToInt64NanoSeconds; - base::ToInt64NanoSeconds(); - ::base::ToInt64NanoSeconds(); - base::ToInt64NanoSeconds(); - } - namespace foo { - namespace base { - void ToNanoSeconds(); - void f() { - base::ToNanoSeconds(); - } - } - void f() { - ::base::ToInt64NanoSeconds(); - } - })"; - std::string After = runClangRenameOnCode(Before, "base::ToNanoSeconds", - "base::ToInt64NanoSeconds"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, RenameFunctionDecls) { - std::string Before = R"( - namespace na { - void X(); - void X() {} - })"; - std::string Expected = R"( - namespace na { - void Y(); - void Y() {} - })"; - std::string After = runClangRenameOnCode(Before, "na::X", "na::Y"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, RenameTemplateFunctions) { - std::string Before = R"( - namespace na { - template T X(); - } - namespace na { void f() { X(); } } - namespace nb { void g() { na::X (); } } - )"; - std::string Expected = R"( - namespace na { - template T Y(); - } - namespace na { void f() { nb::Y(); } } - namespace nb { void g() { Y(); } } - )"; - std::string After = runClangRenameOnCode(Before, "na::X", "nb::Y"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, RenameOutOfLineFunctionDecls) { - std::string Before = R"( - namespace na { - void X(); - } - void na::X() {} - )"; - std::string Expected = R"( - namespace na { - void Y(); - } - void na::Y() {} - )"; - std::string After = runClangRenameOnCode(Before, "na::X", "na::Y"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, NewNamespaceWithoutLeadingDotDot) { - std::string Before = R"( - namespace old_ns { - void X(); - void X() {} - } - // Assume that the reference is in another file. - void f() { old_ns::X(); } - namespace old_ns { void g() { X(); } } - namespace new_ns { void h() { ::old_ns::X(); } } - )"; - std::string Expected = R"( - namespace old_ns { - void Y(); - void Y() {} - } - // Assume that the reference is in another file. - void f() { new_ns::Y(); } - namespace old_ns { void g() { new_ns::Y(); } } - namespace new_ns { void h() { Y(); } } - )"; - std::string After = runClangRenameOnCode(Before, "::old_ns::X", "new_ns::Y"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, NewNamespaceWithLeadingDotDot) { - std::string Before = R"( - namespace old_ns { - void X(); - void X() {} - } - // Assume that the reference is in another file. - void f() { old_ns::X(); } - namespace old_ns { void g() { X(); } } - namespace new_ns { void h() { ::old_ns::X(); } } - )"; - std::string Expected = R"( - namespace old_ns { - void Y(); - void Y() {} - } - // Assume that the reference is in another file. - void f() { ::new_ns::Y(); } - namespace old_ns { void g() { ::new_ns::Y(); } } - namespace new_ns { void h() { Y(); } } - )"; - std::string After = - runClangRenameOnCode(Before, "::old_ns::X", "::new_ns::Y"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, DontRenameSymbolsDefinedInAnonymousNamespace) { - std::string Before = R"( - namespace old_ns { - class X {}; - namespace { - void X(); - void X() {} - void f() { X(); } - } - } - )"; - std::string Expected = R"( - namespace old_ns { - class Y {}; - namespace { - void X(); - void X() {} - void f() { X(); } - } - } - )"; - std::string After = - runClangRenameOnCode(Before, "::old_ns::X", "::old_ns::Y"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, NewNestedNamespace) { - std::string Before = R"( - namespace old_ns { - void X(); - void X() {} - } - // Assume that the reference is in another file. - namespace old_ns { - void f() { X(); } - } - )"; - std::string Expected = R"( - namespace old_ns { - void X(); - void X() {} - } - // Assume that the reference is in another file. - namespace old_ns { - void f() { older_ns::X(); } - } - )"; - std::string After = - runClangRenameOnCode(Before, "::old_ns::X", "::old_ns::older_ns::X"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, MoveFromGlobalToNamespaceWithoutLeadingDotDot) { - std::string Before = R"( - void X(); - void X() {} - - // Assume that the reference is in another file. - namespace some_ns { - void f() { X(); } - } - )"; - std::string Expected = R"( - void X(); - void X() {} - - // Assume that the reference is in another file. - namespace some_ns { - void f() { ns::X(); } - } - )"; - std::string After = - runClangRenameOnCode(Before, "::X", "ns::X"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, MoveFromGlobalToNamespaceWithLeadingDotDot) { - std::string Before = R"( - void Y() {} - - // Assume that the reference is in another file. - namespace some_ns { - void f() { Y(); } - } - )"; - std::string Expected = R"( - void Y() {} - - // Assume that the reference is in another file. - namespace some_ns { - void f() { ::ns::Y(); } - } - )"; - std::string After = - runClangRenameOnCode(Before, "::Y", "::ns::Y"); - CompareSnippets(Expected, After); -} - -// FIXME: the rename of overloaded operator is not fully supported yet. -TEST_F(RenameFunctionTest, DISABLED_DoNotRenameOverloadedOperatorCalls) { - std::string Before = R"( - namespace old_ns { - class T { public: int x; }; - bool operator==(const T& lhs, const T& rhs) { - return lhs.x == rhs.x; - } - } // namespace old_ns - - // Assume that the reference is in another file. - bool f() { - auto eq = old_ns::operator==; - old_ns::T t1, t2; - old_ns::operator==(t1, t2); - return t1 == t2; - } - )"; - std::string Expected = R"( - namespace old_ns { - class T { public: int x; }; - bool operator==(const T& lhs, const T& rhs) { - return lhs.x == rhs.x; - } - } // namespace old_ns - - // Assume that the reference is in another file. - bool f() { - auto eq = new_ns::operator==; - old_ns::T t1, t2; - new_ns::operator==(t1, t2); - return t1 == t2; - } - )"; - std::string After = - runClangRenameOnCode(Before, "old_ns::operator==", "new_ns::operator=="); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, FunctionRefAsTemplate) { - std::string Before = R"( - void X(); - - // Assume that the reference is in another file. - namespace some_ns { - template - class TIterator {}; - - template - class T { - public: - typedef TIterator IterType; - using TI = TIterator; - void g() { - Func(); - auto func = Func; - TIterator iter; - } - }; - - - void f() { T tx; tx.g(); } - } // namespace some_ns - )"; - std::string Expected = R"( - void X(); - - // Assume that the reference is in another file. - namespace some_ns { - template - class TIterator {}; - - template - class T { - public: - typedef TIterator IterType; - using TI = TIterator; - void g() { - Func(); - auto func = Func; - TIterator iter; - } - }; - - - void f() { T tx; tx.g(); } - } // namespace some_ns - )"; - std::string After = runClangRenameOnCode(Before, "::X", "ns::X"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameFunctionTest, RenameFunctionInUsingDecl) { - std::string Before = R"( - using base::ToNanoSeconds; - namespace old_ns { - using base::ToNanoSeconds; - void f() { - using base::ToNanoSeconds; - } - } - )"; - std::string Expected = R"( - using base::ToInt64NanoSeconds; - namespace old_ns { - using base::ToInt64NanoSeconds; - void f() { - using base::ToInt64NanoSeconds; - } - } - )"; - std::string After = runClangRenameOnCode(Before, "base::ToNanoSeconds", - "base::ToInt64NanoSeconds"); - CompareSnippets(Expected, After); -} - -// FIXME: Fix the complex the case where the symbol being renamed is located in -// `std::function>`. -TEST_F(ClangRenameTest, DISABLED_ReferencesInLambdaFunctionParameters) { - std::string Before = R"( - template - class function; - template - class function { - public: - template - function(Functor f) {} - - function() {} - - R operator()(ArgTypes...) const {} - }; - - namespace ns { - void Old() {} - void f() { - function func; - } - } // namespace ns)"; - std::string Expected = R"( - template - class function; - template - class function { - public: - template - function(Functor f) {} - - function() {} - - R operator()(ArgTypes...) const {} - }; - - namespace ns { - void New() {} - void f() { - function func; - } - } // namespace ns)"; - std::string After = runClangRenameOnCode(Before, "ns::Old", "::new_ns::New"); - CompareSnippets(Expected, After); -} - -} // anonymous namespace -} // namespace test -} // namespace clang_rename -} // namesdpace clang diff --git a/clang/unittests/Rename/RenameMemberTest.cpp b/clang/unittests/Rename/RenameMemberTest.cpp deleted file mode 100644 index c16d16aa25f0..000000000000 --- a/clang/unittests/Rename/RenameMemberTest.cpp +++ /dev/null @@ -1,228 +0,0 @@ -//===-- ClangMemberTests.cpp - unit tests for renaming class members ------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "ClangRenameTest.h" - -namespace clang { -namespace clang_rename { -namespace test { -namespace { - -class RenameMemberTest : public ClangRenameTest { -public: - RenameMemberTest() { - AppendToHeader(R"( - struct NA { - void Foo(); - void NotFoo(); - static void SFoo(); - static void SNotFoo(); - int Moo; - }; - struct A { - virtual void Foo(); - void NotFoo(); - static void SFoo(); - static void SNotFoo(); - int Moo; - int NotMoo; - static int SMoo; - }; - struct B : public A { - void Foo() override; - }; - template struct TA { - T* Foo(); - T* NotFoo(); - static T* SFoo(); - static T* NotSFoo(); - }; - template struct TB : public TA {}; - namespace ns { - template struct TA { - T* Foo(); - T* NotFoo(); - static T* SFoo(); - static T* NotSFoo(); - static int SMoo; - }; - template struct TB : public TA {}; - struct A { - void Foo(); - void NotFoo(); - static void SFoo(); - static void SNotFoo(); - }; - struct B : public A {}; - struct C { - template - void SFoo(const T& t) {} - template - void Foo() {} - }; - })"); - } -}; - -INSTANTIATE_TEST_SUITE_P( - DISABLED_RenameTemplatedClassStaticVariableTest, RenameMemberTest, - testing::ValuesIn(std::vector({ - // FIXME: support renaming static variables for template classes. - {"void f() { ns::TA::SMoo; }", - "void f() { ns::TA::SMeh; }", "ns::TA::SMoo", "ns::TA::SMeh"}, - })) ); - -INSTANTIATE_TEST_SUITE_P( - RenameMemberTest, RenameMemberTest, - testing::ValuesIn(std::vector({ - // Normal methods and fields. - {"void f() { A a; a.Foo(); }", "void f() { A a; a.Bar(); }", "A::Foo", - "A::Bar"}, - {"void f() { ns::A a; a.Foo(); }", "void f() { ns::A a; a.Bar(); }", - "ns::A::Foo", "ns::A::Bar"}, - {"void f() { A a; int x = a.Moo; }", "void f() { A a; int x = a.Meh; }", - "A::Moo", "A::Meh"}, - {"void f() { B b; b.Foo(); }", "void f() { B b; b.Bar(); }", "B::Foo", - "B::Bar"}, - {"void f() { ns::B b; b.Foo(); }", "void f() { ns::B b; b.Bar(); }", - "ns::A::Foo", "ns::A::Bar"}, - {"void f() { B b; int x = b.Moo; }", "void f() { B b; int x = b.Meh; }", - "A::Moo", "A::Meh"}, - - // Static methods. - {"void f() { A::SFoo(); }", "void f() { A::SBar(); }", "A::SFoo", - "A::SBar"}, - {"void f() { ns::A::SFoo(); }", "void f() { ns::A::SBar(); }", - "ns::A::SFoo", "ns::A::SBar"}, - {"void f() { TA::SFoo(); }", "void f() { TA::SBar(); }", - "TA::SFoo", "TA::SBar"}, - {"void f() { ns::TA::SFoo(); }", - "void f() { ns::TA::SBar(); }", "ns::TA::SFoo", "ns::TA::SBar"}, - - // Static variables. - {"void f() { A::SMoo; }", - "void f() { A::SMeh; }", "A::SMoo", "A::SMeh"}, - - // Templated methods. - {"void f() { TA a; a.Foo(); }", "void f() { TA a; a.Bar(); }", - "TA::Foo", "TA::Bar"}, - {"void f() { ns::TA a; a.Foo(); }", - "void f() { ns::TA a; a.Bar(); }", "ns::TA::Foo", "ns::TA::Bar"}, - {"void f() { TB b; b.Foo(); }", "void f() { TB b; b.Bar(); }", - "TA::Foo", "TA::Bar"}, - {"void f() { ns::TB b; b.Foo(); }", - "void f() { ns::TB b; b.Bar(); }", "ns::TA::Foo", "ns::TA::Bar"}, - {"void f() { ns::C c; int x; c.SFoo(x); }", - "void f() { ns::C c; int x; c.SBar(x); }", "ns::C::SFoo", - "ns::C::SBar"}, - {"void f() { ns::C c; c.Foo(); }", - "void f() { ns::C c; c.Bar(); }", "ns::C::Foo", "ns::C::Bar"}, - - // Pointers to methods. - {"void f() { auto p = &A::Foo; }", "void f() { auto p = &A::Bar; }", - "A::Foo", "A::Bar"}, - {"void f() { auto p = &A::SFoo; }", "void f() { auto p = &A::SBar; }", - "A::SFoo", "A::SBar"}, - {"void f() { auto p = &B::Foo; }", "void f() { auto p = &B::Bar; }", - "B::Foo", "B::Bar"}, - {"void f() { auto p = &ns::A::Foo; }", - "void f() { auto p = &ns::A::Bar; }", "ns::A::Foo", "ns::A::Bar"}, - {"void f() { auto p = &ns::A::SFoo; }", - "void f() { auto p = &ns::A::SBar; }", "ns::A::SFoo", "ns::A::SBar"}, - {"void f() { auto p = &ns::C::SFoo; }", - "void f() { auto p = &ns::C::SBar; }", "ns::C::SFoo", - "ns::C::SBar"}, - - // These methods are not declared or overridden in the subclass B, we - // have to use the qualified name with parent class A to identify them. - {"void f() { auto p = &ns::B::Foo; }", - "void f() { auto p = &ns::B::Bar; }", "ns::A::Foo", "ns::B::Bar"}, - {"void f() { B::SFoo(); }", "void f() { B::SBar(); }", "A::SFoo", - "B::SBar"}, - {"void f() { ns::B::SFoo(); }", "void f() { ns::B::SBar(); }", - "ns::A::SFoo", "ns::B::SBar"}, - {"void f() { auto p = &B::SFoo; }", "void f() { auto p = &B::SBar; }", - "A::SFoo", "B::SBar"}, - {"void f() { auto p = &ns::B::SFoo; }", - "void f() { auto p = &ns::B::SBar; }", "ns::A::SFoo", "ns::B::SBar"}, - {"void f() { TB::SFoo(); }", "void f() { TB::SBar(); }", - "TA::SFoo", "TB::SBar"}, - {"void f() { ns::TB::SFoo(); }", - "void f() { ns::TB::SBar(); }", "ns::TA::SFoo", "ns::TB::SBar"}, - })) ); - -TEST_P(RenameMemberTest, RenameMembers) { - auto Param = GetParam(); - assert(!Param.OldName.empty()); - assert(!Param.NewName.empty()); - std::string Actual = - runClangRenameOnCode(Param.Before, Param.OldName, Param.NewName); - CompareSnippets(Param.After, Actual); -} - -TEST_F(RenameMemberTest, RenameMemberInsideClassMethods) { - std::string Before = R"( - struct X { - int Moo; - void Baz() { Moo = 1; } - };)"; - std::string Expected = R"( - struct X { - int Meh; - void Baz() { Meh = 1; } - };)"; - std::string After = runClangRenameOnCode(Before, "X::Moo", "Y::Meh"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameMemberTest, RenameMethodInsideClassMethods) { - std::string Before = R"( - struct X { - void Foo() {} - void Baz() { Foo(); } - };)"; - std::string Expected = R"( - struct X { - void Bar() {} - void Baz() { Bar(); } - };)"; - std::string After = runClangRenameOnCode(Before, "X::Foo", "X::Bar"); - CompareSnippets(Expected, After); -} - -TEST_F(RenameMemberTest, RenameCtorInitializer) { - std::string Before = R"( - class X { - public: - X(); - A a; - A a2; - B b; - }; - - X::X():a(), b() {} - )"; - std::string Expected = R"( - class X { - public: - X(); - A bar; - A a2; - B b; - }; - - X::X():bar(), b() {} - )"; - std::string After = runClangRenameOnCode(Before, "X::a", "X::bar"); - CompareSnippets(Expected, After); -} - -} // anonymous namespace -} // namespace test -} // namespace clang_rename -} // namesdpace clang diff --git a/llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn b/llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn index 2227ad42cf40..4f9ba335859b 100644 --- a/llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn +++ b/llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn @@ -83,7 +83,6 @@ group("test") { "//clang-tools-extra/unittests", "//clang/lib/Headers", "//clang/tools/c-index-test", - "//clang/tools/clang-rename", "//clang/tools/driver:symlinks", "//llvm/tools/llvm-bcanalyzer", "//llvm/utils/FileCheck", diff --git a/llvm/utils/gn/secondary/clang/test/BUILD.gn b/llvm/utils/gn/secondary/clang/test/BUILD.gn index 1ec94a419f56..1d5b8025a12a 100644 --- a/llvm/utils/gn/secondary/clang/test/BUILD.gn +++ b/llvm/utils/gn/secondary/clang/test/BUILD.gn @@ -171,7 +171,6 @@ group("test") { "//clang/tools/clang-installapi", "//clang/tools/clang-offload-bundler", "//clang/tools/clang-refactor", - "//clang/tools/clang-rename", "//clang/tools/clang-repl", "//clang/tools/clang-scan-deps", "//clang/tools/diagtool", diff --git a/llvm/utils/gn/secondary/clang/tools/clang-rename/BUILD.gn b/llvm/utils/gn/secondary/clang/tools/clang-rename/BUILD.gn deleted file mode 100644 index 1c517b989345..000000000000 --- a/llvm/utils/gn/secondary/clang/tools/clang-rename/BUILD.gn +++ /dev/null @@ -1,14 +0,0 @@ -executable("clang-rename") { - configs += [ "//llvm/utils/gn/build:clang_code" ] - deps = [ - "//clang/lib/Basic", - "//clang/lib/Frontend", - "//clang/lib/Rewrite", - "//clang/lib/Tooling", - "//clang/lib/Tooling/Core", - "//clang/lib/Tooling/Refactoring", - "//llvm/lib/Option", - "//llvm/lib/Support", - ] - sources = [ "ClangRename.cpp" ] -} diff --git a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel index 1d0ba8bd4d58..b39fb8f6795e 100644 --- a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel @@ -26,7 +26,6 @@ exports_files([ "tools/clang-format/clang-format.el", "tools/clang-format/clang-format-test.el", "tools/clang-format/clang-format.py", - "tools/clang-rename/clang-rename.el", "tools/extra/clang-include-fixer/tool/clang-include-fixer.el", "tools/extra/clang-include-fixer/tool/clang-include-fixer-test.el", ]) @@ -2590,20 +2589,6 @@ cc_binary( ], ) -cc_binary( - name = "clang-rename", - srcs = glob(["tools/clang-rename/*.cpp"]), - stamp = 0, - deps = [ - ":basic", - ":frontend", - ":rewrite", - ":tooling", - ":tooling_refactoring", - "//llvm:Support", - ], -) - cc_binary( name = "clang-repl", srcs = glob(["tools/clang-repl/*.cpp"]),