[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"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace move {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const char TestHeaderName[] = "foo.h";
|
|
|
|
|
|
|
|
const char TestCCName[] = "foo.cc";
|
|
|
|
|
|
|
|
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"
|
|
|
|
"*/\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"
|
[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 Foo::f() { f1(); }\n"
|
|
|
|
"\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"
|
|
|
|
" 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"
|
|
|
|
"*/\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"
|
|
|
|
" 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"
|
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"
|
|
|
|
"*/\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"
|
[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 Foo::f() { f1(); }\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";
|
|
|
|
|
|
|
|
std::map<std::string, std::string>
|
2016-11-09 03:55:13 +08:00
|
|
|
runClangMoveOnCode(const move::ClangMoveTool::MoveDefinitionSpec &Spec,
|
|
|
|
const char *const Header = TestHeader,
|
|
|
|
const char *const CC = TestCC) {
|
[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;
|
|
|
|
|
|
|
|
std::map<llvm::StringRef, clang::FileID> FileToFileID;
|
|
|
|
std::vector<std::pair<std::string, std::string>> FileToSourceText = {
|
2016-11-09 03:55:13 +08:00
|
|
|
{TestHeaderName, Header}, {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
|
|
|
|
|
|
|
auto CreateFiles = [&FileToSourceText, &Context, &FileToFileID](
|
|
|
|
llvm::StringRef Name, llvm::StringRef Code) {
|
|
|
|
if (!Name.empty()) {
|
|
|
|
FileToFileID[Name] = Context.createInMemoryFile(Name, Code);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
CreateFiles(Spec.NewCC, "");
|
|
|
|
CreateFiles(Spec.NewHeader, "");
|
2016-11-09 03:55:13 +08:00
|
|
|
CreateFiles(Spec.OldHeader, Header);
|
|
|
|
CreateFiles(Spec.OldCC, 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;
|
2016-10-04 17:05:31 +08:00
|
|
|
llvm::SmallString<128> InitialDirectory;
|
|
|
|
std::error_code EC = llvm::sys::fs::current_path(InitialDirectory);
|
|
|
|
assert(!EC);
|
|
|
|
(void)EC;
|
[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-10-06 16:29:32 +08:00
|
|
|
Spec, FileToReplacements, InitialDirectory.str(), "LLVM");
|
[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(
|
2016-11-09 03:55:13 +08:00
|
|
|
Factory->create(), CC, {"-std=c++11", "-fparse-all-comments"},
|
2016-10-06 16:59:24 +08:00
|
|
|
TestCCName, "clang-move", std::make_shared<PCHContainerOperations>(),
|
|
|
|
FileToSourceText);
|
[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) {
|
|
|
|
StringRef FilePath = It.first;
|
|
|
|
Results[FilePath] = Context.getRewrittenText(FileToFileID[FilePath]);
|
|
|
|
}
|
|
|
|
return Results;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ClangMove, MoveHeaderAndCC) {
|
|
|
|
move::ClangMoveTool::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) {
|
|
|
|
move::ClangMoveTool::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) {
|
|
|
|
move::ClangMoveTool::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) {
|
|
|
|
move::ClangMoveTool::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
|
|
|
}
|
|
|
|
|
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; }";
|
|
|
|
move::ClangMoveTool::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";
|
|
|
|
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) {
|
|
|
|
move::ClangMoveTool::MoveDefinitionSpec Spec;
|
|
|
|
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
|
|
|
"typedef int Int;\nclass A {\npublic:\n int f();\n};\n",
|
|
|
|
"using Int=int;\nclass A {\npublic:\n int f();\n};\n",
|
|
|
|
"class B {};\nclass A {\npublic:\n int f();\n};\n",
|
|
|
|
"void f() {};\nclass A {\npublic:\n int f();\n};\n",
|
|
|
|
"enum Color { RED };\nclass A {\npublic:\n int f();\n};\n",
|
2016-11-09 03:55:13 +08:00
|
|
|
};
|
|
|
|
move::ClangMoveTool::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";
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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";
|
|
|
|
move::ClangMoveTool::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;
|
|
|
|
move::ClangMoveTool::MoveDefinitionSpec Spec;
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
[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
|