[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
//===-- ClangMoveTest.cpp - clang-move unit tests -------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ClangMove.h"
|
|
|
|
#include "unittests/Tooling/RewriterTestContext.h"
|
|
|
|
#include "clang/Format/Format.h"
|
|
|
|
#include "clang/Frontend/FrontendActions.h"
|
|
|
|
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
|
|
|
#include "clang/Rewrite/Core/Rewriter.h"
|
|
|
|
#include "clang/Tooling/Refactoring.h"
|
|
|
|
#include "clang/Tooling/Tooling.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2018-10-09 01:22:50 +08:00
|
|
|
#include "gmock/gmock-matchers.h"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace move {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const char TestHeader[] = "namespace a {\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"class C1; // test\n"
|
2016-10-22 03:26:43 +08:00
|
|
|
"template <typename T> class C2;\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"namespace b {\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"// This is a Foo class\n"
|
|
|
|
"// which is used in\n"
|
|
|
|
"// test.\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"class Foo {\n"
|
|
|
|
"public:\n"
|
|
|
|
" void f();\n"
|
|
|
|
"\n"
|
|
|
|
"private:\n"
|
|
|
|
" C1 *c1;\n"
|
|
|
|
" static int b;\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"}; // abc\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"\n"
|
|
|
|
"class Foo2 {\n"
|
|
|
|
"public:\n"
|
|
|
|
" int f();\n"
|
|
|
|
"};\n"
|
|
|
|
"} // namespace b\n"
|
|
|
|
"} // namespace a\n";
|
|
|
|
|
|
|
|
const char TestCC[] = "#include \"foo.h\"\n"
|
|
|
|
"namespace a {\n"
|
|
|
|
"namespace b {\n"
|
|
|
|
"namespace {\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"// comment1.\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"void f1() {}\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"/// comment2.\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"int kConstInt1 = 0;\n"
|
|
|
|
"} // namespace\n"
|
|
|
|
"\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"/* comment 3*/\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"static int kConstInt2 = 1;\n"
|
|
|
|
"\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"/** comment4\n"
|
2017-02-16 21:17:38 +08:00
|
|
|
" */\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"static int help() {\n"
|
|
|
|
" int a = 0;\n"
|
|
|
|
" return a;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"// comment5\n"
|
|
|
|
"// comment5\n"
|
2017-01-03 17:00:51 +08:00
|
|
|
"void Foo::f() {\n"
|
|
|
|
" f1();\n"
|
|
|
|
" kConstInt1;\n"
|
|
|
|
" kConstInt2;\n"
|
|
|
|
" help();\n"
|
|
|
|
"}\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"/////////////\n"
|
|
|
|
"// comment //\n"
|
|
|
|
"/////////////\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"int Foo::b = 2;\n"
|
|
|
|
"int Foo2::f() {\n"
|
2017-01-03 17:00:51 +08:00
|
|
|
" kConstInt1;\n"
|
|
|
|
" kConstInt2;\n"
|
|
|
|
" help();\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
" f1();\n"
|
|
|
|
" return 1;\n"
|
|
|
|
"}\n"
|
|
|
|
"} // namespace b\n"
|
|
|
|
"} // namespace a\n";
|
|
|
|
|
|
|
|
const char ExpectedTestHeader[] = "namespace a {\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"class C1; // test\n"
|
2016-10-22 03:26:43 +08:00
|
|
|
"template <typename T> class C2;\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"namespace b {\n"
|
|
|
|
"\n"
|
|
|
|
"class Foo2 {\n"
|
|
|
|
"public:\n"
|
|
|
|
" int f();\n"
|
|
|
|
"};\n"
|
|
|
|
"} // namespace b\n"
|
|
|
|
"} // namespace a\n";
|
|
|
|
|
|
|
|
const char ExpectedTestCC[] = "#include \"foo.h\"\n"
|
|
|
|
"namespace a {\n"
|
|
|
|
"namespace b {\n"
|
|
|
|
"namespace {\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"// comment1.\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"void f1() {}\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"/// comment2.\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"int kConstInt1 = 0;\n"
|
|
|
|
"} // namespace\n"
|
|
|
|
"\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"/* comment 3*/\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"static int kConstInt2 = 1;\n"
|
|
|
|
"\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"/** comment4\n"
|
2017-02-16 21:17:38 +08:00
|
|
|
" */\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"static int help() {\n"
|
|
|
|
" int a = 0;\n"
|
|
|
|
" return a;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"int Foo2::f() {\n"
|
2017-01-03 17:00:51 +08:00
|
|
|
" kConstInt1;\n"
|
|
|
|
" kConstInt2;\n"
|
|
|
|
" help();\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
" f1();\n"
|
|
|
|
" return 1;\n"
|
|
|
|
"}\n"
|
|
|
|
"} // namespace b\n"
|
|
|
|
"} // namespace a\n";
|
|
|
|
|
2016-10-14 21:01:36 +08:00
|
|
|
const char ExpectedNewHeader[] = "#ifndef NEW_FOO_H\n"
|
|
|
|
"#define NEW_FOO_H\n"
|
2016-11-15 17:06:59 +08:00
|
|
|
"\n"
|
2016-10-14 21:01:36 +08:00
|
|
|
"namespace a {\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"class C1; // test\n"
|
2016-11-15 17:06:59 +08:00
|
|
|
"\n"
|
2016-10-22 03:26:43 +08:00
|
|
|
"template <typename T> class C2;\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"namespace b {\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"// This is a Foo class\n"
|
|
|
|
"// which is used in\n"
|
|
|
|
"// test.\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"class Foo {\n"
|
|
|
|
"public:\n"
|
|
|
|
" void f();\n"
|
|
|
|
"\n"
|
|
|
|
"private:\n"
|
|
|
|
" C1 *c1;\n"
|
|
|
|
" static int b;\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"}; // abc\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"} // namespace b\n"
|
2016-10-14 21:01:36 +08:00
|
|
|
"} // namespace a\n"
|
2016-11-15 17:06:59 +08:00
|
|
|
"\n"
|
2016-10-14 21:01:36 +08:00
|
|
|
"#endif // NEW_FOO_H\n";
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
|
2016-09-23 21:28:38 +08:00
|
|
|
const char ExpectedNewCC[] = "namespace a {\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"namespace b {\n"
|
|
|
|
"namespace {\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"// comment1.\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"void f1() {}\n"
|
2017-01-03 17:00:51 +08:00
|
|
|
"\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"/// comment2.\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"int kConstInt1 = 0;\n"
|
|
|
|
"} // namespace\n"
|
2016-11-15 17:06:59 +08:00
|
|
|
"\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"/* comment 3*/\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"static int kConstInt2 = 1;\n"
|
2016-11-15 17:06:59 +08:00
|
|
|
"\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"/** comment4\n"
|
2017-02-16 21:17:38 +08:00
|
|
|
" */\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"static int help() {\n"
|
|
|
|
" int a = 0;\n"
|
|
|
|
" return a;\n"
|
|
|
|
"}\n"
|
2016-11-15 17:06:59 +08:00
|
|
|
"\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"// comment5\n"
|
|
|
|
"// comment5\n"
|
2017-01-03 17:00:51 +08:00
|
|
|
"void Foo::f() {\n"
|
|
|
|
" f1();\n"
|
|
|
|
" kConstInt1;\n"
|
|
|
|
" kConstInt2;\n"
|
|
|
|
" help();\n"
|
|
|
|
"}\n"
|
2016-11-15 17:06:59 +08:00
|
|
|
"\n"
|
2016-10-06 16:59:24 +08:00
|
|
|
"/////////////\n"
|
|
|
|
"// comment //\n"
|
|
|
|
"/////////////\n"
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
"int Foo::b = 2;\n"
|
|
|
|
"} // namespace b\n"
|
|
|
|
"} // namespace a\n";
|
|
|
|
|
2018-05-19 00:08:18 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
const char WorkingDir[] = "C:\\test";
|
|
|
|
#else
|
|
|
|
const char WorkingDir[] = "/test";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const char TestHeaderName[] = "foo.h";
|
|
|
|
const char TestCCName[] = "foo.cc";
|
|
|
|
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
std::map<std::string, std::string>
|
2016-11-24 18:17:17 +08:00
|
|
|
runClangMoveOnCode(const move::MoveDefinitionSpec &Spec,
|
2016-11-09 03:55:13 +08:00
|
|
|
const char *const Header = TestHeader,
|
2016-11-24 18:17:17 +08:00
|
|
|
const char *const CC = TestCC,
|
|
|
|
DeclarationReporter *const Reporter = nullptr) {
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
clang::RewriterTestContext Context;
|
|
|
|
|
2018-05-19 00:08:18 +08:00
|
|
|
Context.InMemoryFileSystem->setCurrentWorkingDirectory(WorkingDir);
|
|
|
|
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
std::map<llvm::StringRef, clang::FileID> FileToFileID;
|
|
|
|
|
2017-01-14 03:02:50 +08:00
|
|
|
auto CreateFiles = [&Context, &FileToFileID](llvm::StringRef Name,
|
|
|
|
llvm::StringRef Code) {
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
if (!Name.empty()) {
|
|
|
|
FileToFileID[Name] = Context.createInMemoryFile(Name, Code);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
CreateFiles(Spec.NewCC, "");
|
|
|
|
CreateFiles(Spec.NewHeader, "");
|
2018-05-19 00:08:18 +08:00
|
|
|
CreateFiles(TestHeaderName, Header);
|
|
|
|
CreateFiles(TestCCName, CC);
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
|
|
|
|
std::map<std::string, tooling::Replacements> FileToReplacements;
|
2018-05-19 00:08:18 +08:00
|
|
|
ClangMoveContext MoveContext = {Spec, FileToReplacements, WorkingDir, "LLVM",
|
2016-11-24 18:17:17 +08:00
|
|
|
Reporter != nullptr};
|
|
|
|
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
auto Factory = llvm::make_unique<clang::move::ClangMoveActionFactory>(
|
2016-11-24 18:17:17 +08:00
|
|
|
&MoveContext, Reporter);
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
|
2018-05-19 00:08:18 +08:00
|
|
|
// std::string IncludeArg = Twine("-I" + WorkingDir;
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
tooling::runToolOnCodeWithArgs(
|
2018-05-19 00:08:18 +08:00
|
|
|
Factory->create(), CC, Context.InMemoryFileSystem,
|
|
|
|
{"-std=c++11", "-fparse-all-comments", "-I."}, TestCCName, "clang-move",
|
|
|
|
std::make_shared<PCHContainerOperations>());
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
formatAndApplyAllReplacements(FileToReplacements, Context.Rewrite, "llvm");
|
|
|
|
// The Key is file name, value is the new code after moving the class.
|
|
|
|
std::map<std::string, std::string> Results;
|
|
|
|
for (const auto &It : FileToReplacements) {
|
2018-07-05 22:53:17 +08:00
|
|
|
// The path may come out as "./foo.h", normalize to "foo.h".
|
|
|
|
SmallString<32> FilePath (It.first);
|
|
|
|
llvm::sys::path::remove_dots(FilePath);
|
|
|
|
Results[FilePath.str().str()] = Context.getRewrittenText(FileToFileID[FilePath]);
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
}
|
|
|
|
return Results;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ClangMove, MoveHeaderAndCC) {
|
2016-11-24 18:17:17 +08:00
|
|
|
move::MoveDefinitionSpec Spec;
|
ClangMoveTests.cpp: Appease msc18.
clang-tools-extra\unittests\clang-move\ClangMoveTests.cpp(216) : error C2593: 'operator =' is ambiguous
llvm\include\llvm/ADT/SmallVector.h(898): could be 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(std::initializer_list<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>)'
llvm\include\llvm/ADT/SmallVector.h(893): or 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(llvm::SmallVectorImpl<T> &&)'
with
[
T=std::string
]
llvm\include\llvm/ADT/SmallVector.h(883): or 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(llvm::SmallVector<std::string,4> &&)'
llvm\include\llvm/ADT/SmallVector.h(873): or 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(const llvm::SmallVector<std::string,4> &)'
while trying to match the argument list '(llvm::SmallVector<std::string,4>, initializer-list)'
llvm-svn: 284360
2016-10-17 13:09:58 +08:00
|
|
|
Spec.Names = {std::string("a::b::Foo")};
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
Spec.OldHeader = "foo.h";
|
|
|
|
Spec.OldCC = "foo.cc";
|
|
|
|
Spec.NewHeader = "new_foo.h";
|
|
|
|
Spec.NewCC = "new_foo.cc";
|
2016-10-06 16:59:24 +08:00
|
|
|
std::string ExpectedHeader = "#include \"" + Spec.NewHeader + "\"\n\n";
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
auto Results = runClangMoveOnCode(Spec);
|
|
|
|
EXPECT_EQ(ExpectedTestHeader, Results[Spec.OldHeader]);
|
|
|
|
EXPECT_EQ(ExpectedTestCC, Results[Spec.OldCC]);
|
|
|
|
EXPECT_EQ(ExpectedNewHeader, Results[Spec.NewHeader]);
|
2016-09-23 21:28:38 +08:00
|
|
|
EXPECT_EQ(ExpectedHeader + ExpectedNewCC, Results[Spec.NewCC]);
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ClangMove, MoveHeaderOnly) {
|
2016-11-24 18:17:17 +08:00
|
|
|
move::MoveDefinitionSpec Spec;
|
ClangMoveTests.cpp: Appease msc18.
clang-tools-extra\unittests\clang-move\ClangMoveTests.cpp(216) : error C2593: 'operator =' is ambiguous
llvm\include\llvm/ADT/SmallVector.h(898): could be 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(std::initializer_list<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>)'
llvm\include\llvm/ADT/SmallVector.h(893): or 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(llvm::SmallVectorImpl<T> &&)'
with
[
T=std::string
]
llvm\include\llvm/ADT/SmallVector.h(883): or 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(llvm::SmallVector<std::string,4> &&)'
llvm\include\llvm/ADT/SmallVector.h(873): or 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(const llvm::SmallVector<std::string,4> &)'
while trying to match the argument list '(llvm::SmallVector<std::string,4>, initializer-list)'
llvm-svn: 284360
2016-10-17 13:09:58 +08:00
|
|
|
Spec.Names = {std::string("a::b::Foo")};
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
Spec.OldHeader = "foo.h";
|
|
|
|
Spec.NewHeader = "new_foo.h";
|
|
|
|
auto Results = runClangMoveOnCode(Spec);
|
2016-09-21 23:19:04 +08:00
|
|
|
EXPECT_EQ(2u, Results.size());
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
EXPECT_EQ(ExpectedTestHeader, Results[Spec.OldHeader]);
|
|
|
|
EXPECT_EQ(ExpectedNewHeader, Results[Spec.NewHeader]);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ClangMove, MoveCCOnly) {
|
2016-11-24 18:17:17 +08:00
|
|
|
move::MoveDefinitionSpec Spec;
|
ClangMoveTests.cpp: Appease msc18.
clang-tools-extra\unittests\clang-move\ClangMoveTests.cpp(216) : error C2593: 'operator =' is ambiguous
llvm\include\llvm/ADT/SmallVector.h(898): could be 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(std::initializer_list<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>)'
llvm\include\llvm/ADT/SmallVector.h(893): or 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(llvm::SmallVectorImpl<T> &&)'
with
[
T=std::string
]
llvm\include\llvm/ADT/SmallVector.h(883): or 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(llvm::SmallVector<std::string,4> &&)'
llvm\include\llvm/ADT/SmallVector.h(873): or 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(const llvm::SmallVector<std::string,4> &)'
while trying to match the argument list '(llvm::SmallVector<std::string,4>, initializer-list)'
llvm-svn: 284360
2016-10-17 13:09:58 +08:00
|
|
|
Spec.Names = {std::string("a::b::Foo")};
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
Spec.OldCC = "foo.cc";
|
|
|
|
Spec.NewCC = "new_foo.cc";
|
2016-10-06 16:59:24 +08:00
|
|
|
std::string ExpectedHeader = "#include \"foo.h\"\n\n";
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
auto Results = runClangMoveOnCode(Spec);
|
2016-09-21 23:19:04 +08:00
|
|
|
EXPECT_EQ(2u, Results.size());
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
EXPECT_EQ(ExpectedTestCC, Results[Spec.OldCC]);
|
2016-09-23 21:28:38 +08:00
|
|
|
EXPECT_EQ(ExpectedHeader + ExpectedNewCC, Results[Spec.NewCC]);
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ClangMove, MoveNonExistClass) {
|
2016-11-24 18:17:17 +08:00
|
|
|
move::MoveDefinitionSpec Spec;
|
ClangMoveTests.cpp: Appease msc18.
clang-tools-extra\unittests\clang-move\ClangMoveTests.cpp(216) : error C2593: 'operator =' is ambiguous
llvm\include\llvm/ADT/SmallVector.h(898): could be 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(std::initializer_list<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>)'
llvm\include\llvm/ADT/SmallVector.h(893): or 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(llvm::SmallVectorImpl<T> &&)'
with
[
T=std::string
]
llvm\include\llvm/ADT/SmallVector.h(883): or 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(llvm::SmallVector<std::string,4> &&)'
llvm\include\llvm/ADT/SmallVector.h(873): or 'const llvm::SmallVector<std::string,4> &llvm::SmallVector<std::string,4>::operator =(const llvm::SmallVector<std::string,4> &)'
while trying to match the argument list '(llvm::SmallVector<std::string,4>, initializer-list)'
llvm-svn: 284360
2016-10-17 13:09:58 +08:00
|
|
|
Spec.Names = {std::string("NonExistFoo")};
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
Spec.OldHeader = "foo.h";
|
|
|
|
Spec.OldCC = "foo.cc";
|
|
|
|
Spec.NewHeader = "new_foo.h";
|
|
|
|
Spec.NewCC = "new_foo.cc";
|
|
|
|
auto Results = runClangMoveOnCode(Spec);
|
2016-09-21 23:19:04 +08:00
|
|
|
EXPECT_EQ(0u, Results.size());
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
}
|
|
|
|
|
2018-01-31 20:12:29 +08:00
|
|
|
TEST(ClangMove, HeaderIncludeSelf) {
|
|
|
|
move::MoveDefinitionSpec Spec;
|
|
|
|
Spec.Names = {std::string("Foo")};
|
|
|
|
Spec.OldHeader = "foo.h";
|
|
|
|
Spec.OldCC = "foo.cc";
|
|
|
|
Spec.NewHeader = "new_foo.h";
|
|
|
|
Spec.NewCC = "new_foo.cc";
|
|
|
|
|
|
|
|
const char TestHeader[] = "#ifndef FOO_H\n"
|
|
|
|
"#define FOO_H\n"
|
|
|
|
"#include \"foo.h\"\n"
|
|
|
|
"class Foo {};\n"
|
|
|
|
"#endif\n";
|
|
|
|
const char TestCode[] = "#include \"foo.h\"";
|
|
|
|
const char ExpectedNewHeader[] = "#ifndef FOO_H\n"
|
|
|
|
"#define FOO_H\n"
|
|
|
|
"#include \"new_foo.h\"\n"
|
|
|
|
"class Foo {};\n"
|
|
|
|
"#endif\n";
|
|
|
|
const char ExpectedNewCC[] = "#include \"new_foo.h\"";
|
|
|
|
auto Results = runClangMoveOnCode(Spec, TestHeader, TestCode);
|
|
|
|
EXPECT_EQ("", Results[Spec.OldHeader]);
|
|
|
|
EXPECT_EQ(ExpectedNewHeader, Results[Spec.NewHeader]);
|
|
|
|
EXPECT_EQ(ExpectedNewCC, Results[Spec.NewCC]);
|
|
|
|
}
|
|
|
|
|
2016-11-09 03:55:13 +08:00
|
|
|
TEST(ClangMove, MoveAll) {
|
|
|
|
std::vector<std::string> TestHeaders = {
|
|
|
|
"class A {\npublic:\n int f();\n};",
|
|
|
|
// forward declaration.
|
|
|
|
"class B;\nclass A {\npublic:\n int f();\n};",
|
|
|
|
// template forward declaration.
|
|
|
|
"template <typename T> class B;\nclass A {\npublic:\n int f();\n};",
|
|
|
|
"namespace a {}\nclass A {\npublic:\n int f();\n};",
|
|
|
|
"namespace a {}\nusing namespace a;\nclass A {\npublic:\n int f();\n};",
|
|
|
|
};
|
|
|
|
const char Code[] = "#include \"foo.h\"\nint A::f() { return 0; }";
|
2016-11-24 18:17:17 +08:00
|
|
|
move::MoveDefinitionSpec Spec;
|
2016-11-09 03:55:13 +08:00
|
|
|
Spec.Names.push_back("A");
|
|
|
|
Spec.OldHeader = "foo.h";
|
|
|
|
Spec.OldCC = "foo.cc";
|
|
|
|
Spec.NewHeader = "new_foo.h";
|
|
|
|
Spec.NewCC = "new_foo.cc";
|
|
|
|
for (const auto& Header : TestHeaders) {
|
|
|
|
auto Results = runClangMoveOnCode(Spec, Header.c_str(), Code);
|
|
|
|
EXPECT_EQ(Header, Results[Spec.NewHeader]);
|
|
|
|
EXPECT_EQ("", Results[Spec.OldHeader]);
|
|
|
|
EXPECT_EQ("", Results[Spec.OldCC]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ClangMove, MoveAllMultipleClasses) {
|
2016-11-24 18:17:17 +08:00
|
|
|
move::MoveDefinitionSpec Spec;
|
2016-11-09 03:55:13 +08:00
|
|
|
std::vector<std::string> TestHeaders = {
|
|
|
|
"class C;\nclass A {\npublic:\n int f();\n};\nclass B {};",
|
|
|
|
"class C;\nclass B;\nclass A {\npublic:\n int f();\n};\nclass B {};",
|
|
|
|
};
|
|
|
|
const char Code[] = "#include \"foo.h\"\nint A::f() { return 0; }";
|
|
|
|
Spec.Names = {std::string("A"), std::string("B")};
|
|
|
|
Spec.OldHeader = "foo.h";
|
|
|
|
Spec.OldCC = "foo.cc";
|
|
|
|
Spec.NewHeader = "new_foo.h";
|
|
|
|
Spec.NewCC = "new_foo.cc";
|
|
|
|
for (const auto& Header : TestHeaders) {
|
|
|
|
auto Results = runClangMoveOnCode(Spec, Header.c_str(), Code);
|
|
|
|
EXPECT_EQ(Header, Results[Spec.NewHeader]);
|
|
|
|
EXPECT_EQ("", Results[Spec.OldHeader]);
|
|
|
|
EXPECT_EQ("", Results[Spec.OldCC]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ClangMove, DontMoveAll) {
|
|
|
|
const char ExpectedHeader[] = "#ifndef NEW_FOO_H\n"
|
|
|
|
"#define NEW_FOO_H\n"
|
2016-11-15 17:06:59 +08:00
|
|
|
"\n"
|
2016-11-09 03:55:13 +08:00
|
|
|
"class A {\npublic:\n int f();\n};\n"
|
2016-11-15 17:06:59 +08:00
|
|
|
"\n"
|
2016-11-09 03:55:13 +08:00
|
|
|
"#endif // NEW_FOO_H\n";
|
|
|
|
const char Code[] = "#include \"foo.h\"\nint A::f() { return 0; }";
|
|
|
|
std::vector<std::string> TestHeaders = {
|
2016-11-15 17:06:59 +08:00
|
|
|
"class B {};\nclass A {\npublic:\n int f();\n};\n",
|
|
|
|
"void f() {};\nclass A {\npublic:\n int f();\n};\n",
|
2016-11-09 03:55:13 +08:00
|
|
|
};
|
2016-11-24 18:17:17 +08:00
|
|
|
move::MoveDefinitionSpec Spec;
|
2016-11-09 03:55:13 +08:00
|
|
|
Spec.Names.push_back("A");
|
|
|
|
Spec.OldHeader = "foo.h";
|
|
|
|
Spec.OldCC = "foo.cc";
|
|
|
|
Spec.NewHeader = "new_foo.h";
|
|
|
|
Spec.NewCC = "new_foo.cc";
|
|
|
|
for (const auto& Header : TestHeaders) {
|
|
|
|
auto Results = runClangMoveOnCode(Spec, Header.c_str(), Code);
|
|
|
|
EXPECT_EQ(ExpectedHeader, Results[Spec.NewHeader]);
|
|
|
|
// The expected old header should not contain class A definition.
|
2016-11-15 17:06:59 +08:00
|
|
|
std::string ExpectedOldHeader = Header.substr(0, Header.size() - 32);
|
2016-11-09 03:55:13 +08:00
|
|
|
EXPECT_EQ(ExpectedOldHeader, Results[Spec.OldHeader]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 23:57:30 +08:00
|
|
|
TEST(ClangMove, IgnoreMacroSymbolsAndMoveAll) {
|
|
|
|
const char TestCode[] = "#include \"foo.h\"";
|
|
|
|
std::vector<std::string> TestHeaders = {
|
|
|
|
"#define DEFINE_Foo int Foo = 1;\nDEFINE_Foo;\nclass Bar {};\n",
|
|
|
|
"#define DEFINE(x) int var_##x = 1;\nDEFINE(foo);\nclass Bar {};\n",
|
|
|
|
};
|
|
|
|
move::MoveDefinitionSpec Spec;
|
|
|
|
Spec.Names.push_back("Bar");
|
|
|
|
Spec.OldHeader = "foo.h";
|
|
|
|
Spec.OldCC = "foo.cc";
|
|
|
|
Spec.NewHeader = "new_foo.h";
|
|
|
|
Spec.NewCC = "new_foo.cc";
|
|
|
|
|
|
|
|
for (const auto& Header : TestHeaders) {
|
|
|
|
auto Results = runClangMoveOnCode(Spec, Header.c_str(), TestCode);
|
|
|
|
EXPECT_EQ("", Results[Spec.OldHeader]);
|
|
|
|
EXPECT_EQ(Header, Results[Spec.NewHeader]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-14 22:46:48 +08:00
|
|
|
TEST(ClangMove, MacroInFunction) {
|
|
|
|
const char TestHeader[] = "#define INT int\n"
|
|
|
|
"class A {\npublic:\n int f();\n};\n"
|
|
|
|
"class B {};\n";
|
|
|
|
const char TestCode[] = "#include \"foo.h\"\n"
|
|
|
|
"INT A::f() { return 0; }\n";
|
|
|
|
const char ExpectedNewCode[] = "#include \"new_foo.h\"\n\n"
|
|
|
|
"INT A::f() { return 0; }\n";
|
2016-11-24 18:17:17 +08:00
|
|
|
move::MoveDefinitionSpec Spec;
|
2016-11-14 22:46:48 +08:00
|
|
|
Spec.Names.push_back("A");
|
|
|
|
Spec.OldHeader = "foo.h";
|
|
|
|
Spec.OldCC = "foo.cc";
|
|
|
|
Spec.NewHeader = "new_foo.h";
|
|
|
|
Spec.NewCC = "new_foo.cc";
|
|
|
|
auto Results = runClangMoveOnCode(Spec, TestHeader, TestCode);
|
|
|
|
EXPECT_EQ(ExpectedNewCode, Results[Spec.NewCC]);
|
|
|
|
}
|
|
|
|
|
2016-12-13 23:35:47 +08:00
|
|
|
TEST(ClangMove, DefinitionInMacro) {
|
|
|
|
const char TestHeader[] = "#define DEF(CLASS) void CLASS##_::f() {}\n"
|
2018-02-12 20:26:12 +08:00
|
|
|
"#define DEF2(CLASS, ...) void CLASS##_::f2() {}\n"
|
|
|
|
"class A_ {\nvoid f();\nvoid f2();\n};\n"
|
2016-12-13 23:35:47 +08:00
|
|
|
"class B {};\n";
|
|
|
|
const char TestCode[] = "#include \"foo.h\"\n"
|
2018-02-12 20:26:12 +08:00
|
|
|
"DEF(A)\n\n"
|
|
|
|
"DEF2(A,\n"
|
|
|
|
" 123)\n";
|
2016-12-13 23:35:47 +08:00
|
|
|
const char ExpectedNewCode[] = "#include \"new_foo.h\"\n\n"
|
2018-02-12 20:26:12 +08:00
|
|
|
"DEF(A)\n\n"
|
|
|
|
"DEF2(A, 123)\n";
|
2016-12-13 23:35:47 +08:00
|
|
|
move::MoveDefinitionSpec Spec;
|
|
|
|
Spec.Names.push_back("A_");
|
|
|
|
Spec.OldHeader = "foo.h";
|
|
|
|
Spec.OldCC = "foo.cc";
|
|
|
|
Spec.NewHeader = "new_foo.h";
|
|
|
|
Spec.NewCC = "new_foo.cc";
|
|
|
|
auto Results = runClangMoveOnCode(Spec, TestHeader, TestCode);
|
|
|
|
EXPECT_EQ(ExpectedNewCode, Results[Spec.NewCC]);
|
|
|
|
}
|
|
|
|
|
2016-11-15 17:06:59 +08:00
|
|
|
TEST(ClangMove, WellFormattedCode) {
|
|
|
|
const std::string CommonHeader =
|
|
|
|
"namespace a {\n"
|
|
|
|
"namespace b {\n"
|
|
|
|
"namespace c {\n"
|
|
|
|
"class C;\n"
|
|
|
|
"\n"
|
|
|
|
"class A {\npublic:\n void f();\n void f2();\n};\n"
|
|
|
|
"} // namespace c\n"
|
|
|
|
"} // namespace b\n"
|
|
|
|
"\n"
|
|
|
|
"namespace d {\n"
|
|
|
|
"namespace e {\n"
|
|
|
|
"class B {\npublic:\n void f();\n};\n"
|
|
|
|
"} // namespace e\n"
|
|
|
|
"} // namespace d\n"
|
|
|
|
"} // namespace a\n";
|
|
|
|
const std::string CommonCode = "\n"
|
|
|
|
"namespace a {\n"
|
|
|
|
"namespace b {\n"
|
|
|
|
"namespace c {\n"
|
|
|
|
"void A::f() {}\n"
|
|
|
|
"\n"
|
|
|
|
"void A::f2() {}\n"
|
|
|
|
"} // namespace c\n"
|
|
|
|
"} // namespace b\n"
|
|
|
|
"\n"
|
|
|
|
"namespace d {\n"
|
|
|
|
"namespace e {\n"
|
|
|
|
"void B::f() {}\n"
|
|
|
|
"} // namespace e\n"
|
|
|
|
"} // namespace d\n"
|
|
|
|
"} // namespace a\n";
|
|
|
|
// Add dummy class to prevent behavior of moving all declarations from header.
|
|
|
|
const std::string TestHeader = CommonHeader + "class D {};\n";
|
|
|
|
const std::string TestCode = "#include \"foo.h\"\n" + CommonCode;
|
|
|
|
const std::string ExpectedNewHeader = "#ifndef NEW_FOO_H\n"
|
|
|
|
"#define NEW_FOO_H\n"
|
|
|
|
"\n" +
|
|
|
|
CommonHeader +
|
|
|
|
"\n"
|
|
|
|
"#endif // NEW_FOO_H\n";
|
|
|
|
const std::string ExpectedNewCC = "#include \"new_foo.h\"\n" + CommonCode;
|
2016-11-24 18:17:17 +08:00
|
|
|
move::MoveDefinitionSpec Spec;
|
2016-11-15 17:06:59 +08:00
|
|
|
Spec.Names.push_back("a::b::c::A");
|
|
|
|
Spec.Names.push_back("a::d::e::B");
|
|
|
|
Spec.OldHeader = "foo.h";
|
|
|
|
Spec.OldCC = "foo.cc";
|
|
|
|
Spec.NewHeader = "new_foo.h";
|
|
|
|
Spec.NewCC = "new_foo.cc";
|
|
|
|
auto Results = runClangMoveOnCode(Spec, TestHeader.c_str(), TestCode.c_str());
|
|
|
|
EXPECT_EQ(ExpectedNewCC, Results[Spec.NewCC]);
|
|
|
|
EXPECT_EQ(ExpectedNewHeader, Results[Spec.NewHeader]);
|
|
|
|
}
|
|
|
|
|
2016-11-23 18:04:19 +08:00
|
|
|
TEST(ClangMove, AddDependentNewHeader) {
|
|
|
|
const char TestHeader[] = "class A {};\n"
|
|
|
|
"class B {};\n";
|
|
|
|
const char TestCode[] = "#include \"foo.h\"\n";
|
|
|
|
const char ExpectedOldHeader[] = "#include \"new_foo.h\"\nclass B {};\n";
|
|
|
|
const char ExpectedNewHeader[] = "#ifndef NEW_FOO_H\n"
|
|
|
|
"#define NEW_FOO_H\n"
|
|
|
|
"\n"
|
|
|
|
"class A {};\n"
|
|
|
|
"\n"
|
|
|
|
"#endif // NEW_FOO_H\n";
|
2016-11-24 18:17:17 +08:00
|
|
|
move::MoveDefinitionSpec Spec;
|
2016-11-23 18:04:19 +08:00
|
|
|
Spec.Names.push_back("A");
|
|
|
|
Spec.OldHeader = "foo.h";
|
|
|
|
Spec.OldCC = "foo.cc";
|
|
|
|
Spec.NewHeader = "new_foo.h";
|
|
|
|
Spec.NewCC = "new_foo.cc";
|
|
|
|
Spec.OldDependOnNew = true;
|
|
|
|
auto Results = runClangMoveOnCode(Spec, TestHeader, TestCode);
|
|
|
|
EXPECT_EQ(ExpectedOldHeader, Results[Spec.OldHeader]);
|
|
|
|
EXPECT_EQ(ExpectedNewHeader, Results[Spec.NewHeader]);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ClangMove, AddDependentOldHeader) {
|
|
|
|
const char TestHeader[] = "class A {};\n"
|
|
|
|
"class B {};\n";
|
|
|
|
const char TestCode[] = "#include \"foo.h\"\n";
|
|
|
|
const char ExpectedNewHeader[] = "#ifndef NEW_FOO_H\n"
|
|
|
|
"#define NEW_FOO_H\n"
|
|
|
|
"\n"
|
|
|
|
"#include \"foo.h\"\n"
|
|
|
|
"\n"
|
|
|
|
"class B {};\n"
|
|
|
|
"\n"
|
|
|
|
"#endif // NEW_FOO_H\n";
|
|
|
|
const char ExpectedOldHeader[] = "class A {};\n";
|
2016-11-24 18:17:17 +08:00
|
|
|
move::MoveDefinitionSpec Spec;
|
2016-11-23 18:04:19 +08:00
|
|
|
Spec.Names.push_back("B");
|
|
|
|
Spec.OldHeader = "foo.h";
|
|
|
|
Spec.OldCC = "foo.cc";
|
|
|
|
Spec.NewHeader = "new_foo.h";
|
|
|
|
Spec.NewCC = "new_foo.cc";
|
|
|
|
Spec.NewDependOnOld = true;
|
|
|
|
auto Results = runClangMoveOnCode(Spec, TestHeader, TestCode);
|
|
|
|
EXPECT_EQ(ExpectedNewHeader, Results[Spec.NewHeader]);
|
|
|
|
EXPECT_EQ(ExpectedOldHeader, Results[Spec.OldHeader]);
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:17:17 +08:00
|
|
|
TEST(ClangMove, DumpDecls) {
|
|
|
|
const char TestHeader[] = "template <typename T>\n"
|
|
|
|
"class A {\n"
|
|
|
|
" public:\n"
|
|
|
|
" void f();\n"
|
|
|
|
" template <typename U> void h();\n"
|
|
|
|
" static int b;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"template <typename T> void A<T>::f() {}\n"
|
|
|
|
"\n"
|
|
|
|
"template <typename T>\n"
|
|
|
|
"template <typename U>\n"
|
|
|
|
"void A<T>::h() {}\n"
|
|
|
|
"\n"
|
|
|
|
"template <typename T> int A<T>::b = 2;\n"
|
|
|
|
"\n"
|
|
|
|
"template <> class A<int> {};\n"
|
|
|
|
"\n"
|
|
|
|
"class B {};\n"
|
|
|
|
"\n"
|
|
|
|
"namespace a {\n"
|
|
|
|
"class Move1 {};\n"
|
|
|
|
"void f1() {}\n"
|
2018-10-09 01:22:50 +08:00
|
|
|
"template <typename T>"
|
|
|
|
"void f2(T t);\n"
|
2016-11-24 18:17:17 +08:00
|
|
|
"} // namespace a\n"
|
|
|
|
"\n"
|
2017-05-02 20:15:11 +08:00
|
|
|
"class ForwardClass;\n"
|
2016-11-24 18:17:17 +08:00
|
|
|
"namespace a {\n"
|
|
|
|
"namespace b {\n"
|
|
|
|
"class Move1 { public : void f(); };\n"
|
|
|
|
"void f() {}\n"
|
2017-01-16 17:34:07 +08:00
|
|
|
"enum E1 { Green };\n"
|
|
|
|
"enum class E2 { Red };\n"
|
|
|
|
"typedef int Int2;\n"
|
2017-05-02 20:15:11 +08:00
|
|
|
"typedef A<double> A_d;"
|
2017-01-16 17:34:07 +08:00
|
|
|
"using Int = int;\n"
|
2018-10-09 01:22:50 +08:00
|
|
|
"template <typename T>\n"
|
|
|
|
"using AA = A<T>;\n"
|
2017-02-27 21:19:13 +08:00
|
|
|
"extern int kGlobalInt;\n"
|
|
|
|
"extern const char* const kGlobalStr;\n"
|
2016-11-24 18:17:17 +08:00
|
|
|
"} // namespace b\n"
|
2018-02-09 23:57:30 +08:00
|
|
|
"} // namespace a\n"
|
|
|
|
"#define DEFINE_FOO class Foo {};\n"
|
|
|
|
"DEFINE_FOO\n";
|
2016-11-24 18:17:17 +08:00
|
|
|
const char TestCode[] = "#include \"foo.h\"\n";
|
|
|
|
move::MoveDefinitionSpec Spec;
|
|
|
|
Spec.Names.push_back("B");
|
|
|
|
Spec.OldHeader = "foo.h";
|
|
|
|
Spec.OldCC = "foo.cc";
|
|
|
|
Spec.NewHeader = "new_foo.h";
|
|
|
|
Spec.NewCC = "new_foo.cc";
|
|
|
|
DeclarationReporter Reporter;
|
2018-10-09 01:22:50 +08:00
|
|
|
std::vector<DeclarationReporter::Declaration> ExpectedDeclarations = {
|
|
|
|
{"A", "Class", true},
|
|
|
|
{"B", "Class", false},
|
|
|
|
{"a::Move1", "Class", false},
|
|
|
|
{"a::f1", "Function", false},
|
|
|
|
{"a::f2", "Function", true},
|
|
|
|
{"a::b::Move1", "Class", false},
|
|
|
|
{"a::b::f", "Function", false},
|
|
|
|
{"a::b::E1", "Enum", false},
|
|
|
|
{"a::b::E2", "Enum", false},
|
|
|
|
{"a::b::Int2", "TypeAlias", false},
|
|
|
|
{"a::b::A_d", "TypeAlias", false},
|
|
|
|
{"a::b::Int", "TypeAlias", false},
|
|
|
|
{"a::b::AA", "TypeAlias", true},
|
|
|
|
{"a::b::kGlobalInt", "Variable", false},
|
|
|
|
{"a::b::kGlobalStr", "Variable", false}};
|
2016-11-24 18:17:17 +08:00
|
|
|
runClangMoveOnCode(Spec, TestHeader, TestCode, &Reporter);
|
2018-10-09 01:22:50 +08:00
|
|
|
std::vector<DeclarationReporter::Declaration> Results;
|
|
|
|
for (const auto &DelPair : Reporter.getDeclarationList())
|
|
|
|
Results.push_back(DelPair);
|
|
|
|
EXPECT_THAT(ExpectedDeclarations,
|
|
|
|
testing::UnorderedElementsAreArray(Results));
|
2016-11-24 18:17:17 +08:00
|
|
|
}
|
|
|
|
|
[clang-move] A prototype tool for moving class definition to new file.
Summary:
This patch introduces a new tool which moves a specific class definition
from files (.h, .cc) to new files (.h, .cc), which mostly acts like
"Extract class defintion". In the long term, this tool should be
merged in to clang-refactoring as a subtool.
clang-move not only moves class definition, but also moves all the
forward declarations, functions defined in anonymous namespace and #include
headers to new files, to make sure the new files are compliable as much
as possible.
To move `Foo` from old.[h/cc] to new.[h/cc], use:
```
clang-move -name=Foo -old_header=old.h -old_cc=old.cc -new_header=new.h
-new_cc=new.cc old.cc
```
To move `Foo` from old.h to new.h, use:
```
clang-move -name=Foo -old_header=old.h -new_header=new.h old.cc
```
Reviewers: klimek, djasper, ioeric
Subscribers: mgorny, beanz, Eugene.Zelenko, bkramer, omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24243
llvm-svn: 282070
2016-09-21 21:18:19 +08:00
|
|
|
} // namespace
|
|
|
|
} // namespce move
|
|
|
|
} // namespace clang
|