[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
|
|
|
//===-- ClangMove.h - Clang move -----------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_MOVE_CLANGMOVE_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_MOVE_CLANGMOVE_H
|
|
|
|
|
2017-01-03 17:00:51 +08:00
|
|
|
#include "HelperDeclRefGraph.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 "clang/ASTMatchers/ASTMatchFinder.h"
|
|
|
|
#include "clang/Frontend/FrontendAction.h"
|
|
|
|
#include "clang/Tooling/Core/Replacement.h"
|
|
|
|
#include "clang/Tooling/Tooling.h"
|
2016-11-09 03:55:13 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2016-11-23 18:04:19 +08:00
|
|
|
#include "llvm/ADT/StringMap.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 <map>
|
2016-11-14 22:15:44 +08:00
|
|
|
#include <memory>
|
[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 <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace move {
|
|
|
|
|
2016-11-24 18:17:17 +08:00
|
|
|
// A reporter which collects and reports declarations in old header.
|
|
|
|
class DeclarationReporter {
|
|
|
|
public:
|
|
|
|
DeclarationReporter() = default;
|
|
|
|
~DeclarationReporter() = default;
|
|
|
|
|
|
|
|
void reportDeclaration(llvm::StringRef DeclarationName,
|
|
|
|
llvm::StringRef Type) {
|
|
|
|
DeclarationList.emplace_back(DeclarationName, Type);
|
|
|
|
};
|
|
|
|
|
|
|
|
// A <DeclarationName, DeclarationKind> pair.
|
|
|
|
// The DeclarationName is a fully qualified name for the declaration, like
|
|
|
|
// A::B::Foo. The DeclarationKind is a string represents the kind of the
|
|
|
|
// declaration, currently only "Function" and "Class" are supported.
|
|
|
|
typedef std::pair<std::string, std::string> DeclarationPair;
|
|
|
|
|
|
|
|
const std::vector<DeclarationPair> getDeclarationList() const {
|
|
|
|
return DeclarationList;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<DeclarationPair> DeclarationList;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Specify declarations being moved. It contains all information of the moved
|
|
|
|
// declarations.
|
|
|
|
struct MoveDefinitionSpec {
|
|
|
|
// The list of fully qualified names, e.g. Foo, a::Foo, b::Foo.
|
|
|
|
SmallVector<std::string, 4> Names;
|
|
|
|
// The file path of old header, can be relative path and absolute path.
|
|
|
|
std::string OldHeader;
|
|
|
|
// The file path of old cc, can be relative path and absolute path.
|
|
|
|
std::string OldCC;
|
|
|
|
// The file path of new header, can be relative path and absolute path.
|
|
|
|
std::string NewHeader;
|
|
|
|
// The file path of new cc, can be relative path and absolute path.
|
|
|
|
std::string NewCC;
|
|
|
|
// Whether old.h depends on new.h. If true, #include "new.h" will be added
|
|
|
|
// in old.h.
|
|
|
|
bool OldDependOnNew = false;
|
|
|
|
// Whether new.h depends on old.h. If true, #include "old.h" will be added
|
|
|
|
// in new.h.
|
|
|
|
bool NewDependOnOld = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A Context which contains extra options which are used in ClangMoveTool.
|
|
|
|
struct ClangMoveContext {
|
|
|
|
MoveDefinitionSpec Spec;
|
|
|
|
// The Key is file path, value is the replacements being applied to the file.
|
|
|
|
std::map<std::string, tooling::Replacements> &FileToReplacements;
|
|
|
|
// The original working directory where the local clang-move binary runs.
|
|
|
|
//
|
|
|
|
// clang-move will change its current working directory to the build
|
|
|
|
// directory when analyzing the source file. We save the original working
|
|
|
|
// directory in order to get the absolute file path for the fields in Spec.
|
|
|
|
std::string OriginalRunningDirectory;
|
|
|
|
// The name of a predefined code style.
|
|
|
|
std::string FallbackStyle;
|
|
|
|
// Whether dump all declarations in old header.
|
|
|
|
bool DumpDeclarations;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This tool is used to move class/function definitions from the given source
|
2017-01-03 17:00:51 +08:00
|
|
|
// files (old.h/cc) to new files (new.h/cc).
|
|
|
|
// The goal of this tool is to make the new/old files as compilable as possible.
|
|
|
|
//
|
|
|
|
// When moving a symbol,all used helper declarations (e.g. static
|
|
|
|
// functions/variables definitions in global/named namespace,
|
|
|
|
// functions/variables/classes definitions in anonymous namespace) used by the
|
|
|
|
// moved symbol in old.cc are moved to the new.cc. In addition, all
|
|
|
|
// using-declarations in old.cc are also moved to new.cc; forward class
|
|
|
|
// declarations in old.h are also moved to new.h.
|
|
|
|
//
|
|
|
|
// The remaining helper declarations which are unused by non-moved symbols in
|
|
|
|
// old.cc will be removed.
|
2016-11-09 03:55:13 +08:00
|
|
|
//
|
2016-11-24 18:17:17 +08:00
|
|
|
// Note: When all declarations in old header are being moved, all code in
|
2016-12-06 18:12:23 +08:00
|
|
|
// old.h/cc will be moved, which means old.h/cc are empty. This ignores symbols
|
|
|
|
// that are not supported (e.g. typedef and enum) so that we always move old
|
|
|
|
// files to new files when all symbols produced from dump_decls are moved.
|
[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 ClangMoveTool : public ast_matchers::MatchFinder::MatchCallback {
|
|
|
|
public:
|
2016-11-24 18:17:17 +08:00
|
|
|
ClangMoveTool(ClangMoveContext *const Context,
|
|
|
|
DeclarationReporter *const 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
|
|
|
|
|
|
|
void registerMatchers(ast_matchers::MatchFinder *Finder);
|
|
|
|
|
|
|
|
void run(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
|
|
|
|
|
|
|
void onEndOfTranslationUnit() override;
|
|
|
|
|
2016-10-04 17:05:31 +08:00
|
|
|
/// Add #includes from old.h/cc files.
|
|
|
|
///
|
|
|
|
/// \param IncludeHeader The name of the file being included, as written in
|
|
|
|
/// the source code.
|
|
|
|
/// \param IsAngled Whether the file name was enclosed in angle brackets.
|
|
|
|
/// \param SearchPath The search path which was used to find the IncludeHeader
|
|
|
|
/// in the file system. It can be a relative path or an absolute path.
|
|
|
|
/// \param FileName The name of file where the IncludeHeader comes from.
|
2016-11-24 18:17:17 +08:00
|
|
|
/// \param IncludeFilenameRange The source range for the written file name in
|
|
|
|
/// #include (i.e. "old.h" for #include "old.h") in old.cc.
|
2016-10-04 18:40:52 +08:00
|
|
|
/// \param SM The SourceManager.
|
2016-11-08 15:50:19 +08:00
|
|
|
void addIncludes(llvm::StringRef IncludeHeader, bool IsAngled,
|
|
|
|
llvm::StringRef SearchPath, llvm::StringRef FileName,
|
2016-11-09 03:55:13 +08:00
|
|
|
clang::CharSourceRange IncludeFilenameRange,
|
2016-11-08 15:50:19 +08:00
|
|
|
const SourceManager &SM);
|
[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-12-02 20:39:39 +08:00
|
|
|
std::vector<const NamedDecl *> &getMovedDecls() { return MovedDecls; }
|
2016-11-14 22:15:44 +08:00
|
|
|
|
2016-11-23 18:04:19 +08:00
|
|
|
/// Add declarations being removed from old.h/cc. For each declarations, the
|
|
|
|
/// method also records the mapping relationship between the corresponding
|
|
|
|
/// FilePath and its FileID.
|
2016-12-02 20:39:39 +08:00
|
|
|
void addRemovedDecl(const NamedDecl *Decl);
|
2016-11-14 22:15:44 +08:00
|
|
|
|
|
|
|
llvm::SmallPtrSet<const NamedDecl *, 8> &getUnremovedDeclsInOldHeader() {
|
|
|
|
return UnremovedDeclsInOldHeader;
|
|
|
|
}
|
|
|
|
|
[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
|
|
|
private:
|
2016-11-09 03:55:13 +08:00
|
|
|
// Make the Path absolute using the OrignalRunningDirectory if the Path is not
|
|
|
|
// an absolute path. An empty Path will result in an empty string.
|
|
|
|
std::string makeAbsolutePath(StringRef Path);
|
|
|
|
|
2016-12-02 20:39:39 +08:00
|
|
|
void removeDeclsInOldFiles();
|
|
|
|
void moveDeclsToNewFiles();
|
2016-11-09 03:55:13 +08:00
|
|
|
void moveAll(SourceManager& SM, StringRef OldFile, StringRef NewFile);
|
[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-14 22:15:44 +08:00
|
|
|
// Stores all MatchCallbacks created by this tool.
|
|
|
|
std::vector<std::unique_ptr<ast_matchers::MatchFinder::MatchCallback>>
|
|
|
|
MatchCallbacks;
|
2017-01-03 17:00:51 +08:00
|
|
|
// Store all potential declarations (decls being moved, forward decls) that
|
|
|
|
// might need to move to new.h/cc. It includes all helper declarations
|
|
|
|
// (include unused ones) by default. The unused ones will be filtered out in
|
|
|
|
// the last stage. Saving in an AST-visited order.
|
2016-12-02 20:39:39 +08:00
|
|
|
std::vector<const NamedDecl *> MovedDecls;
|
[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
|
|
|
// The declarations that needs to be removed in old.cc/h.
|
2016-12-02 20:39:39 +08:00
|
|
|
std::vector<const NamedDecl *> RemovedDecls;
|
[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
|
|
|
// The #includes in old_header.h.
|
|
|
|
std::vector<std::string> HeaderIncludes;
|
|
|
|
// The #includes in old_cc.cc.
|
|
|
|
std::vector<std::string> CCIncludes;
|
2017-01-03 17:00:51 +08:00
|
|
|
// Records all helper declarations (function/variable/class definitions in
|
|
|
|
// anonymous namespaces, static function/variable definitions in global/named
|
|
|
|
// namespaces) in old.cc. saving in an AST-visited order.
|
|
|
|
std::vector<const NamedDecl *> HelperDeclarations;
|
2016-11-09 03:55:13 +08:00
|
|
|
// The unmoved named declarations in old header.
|
|
|
|
llvm::SmallPtrSet<const NamedDecl*, 8> UnremovedDeclsInOldHeader;
|
|
|
|
/// The source range for the written file name in #include (i.e. "old.h" for
|
|
|
|
/// #include "old.h") in old.cc, including the enclosing quotes or angle
|
|
|
|
/// brackets.
|
|
|
|
clang::CharSourceRange OldHeaderIncludeRange;
|
2016-11-23 18:04:19 +08:00
|
|
|
/// Mapping from FilePath to FileID, which can be used in post processes like
|
|
|
|
/// cleanup around replacements.
|
|
|
|
llvm::StringMap<FileID> FilePathToFileID;
|
2016-11-24 18:17:17 +08:00
|
|
|
/// A context contains all running options. It is not owned.
|
|
|
|
ClangMoveContext *const Context;
|
|
|
|
/// A reporter to report all declarations from old header. It is not owned.
|
|
|
|
DeclarationReporter *const Reporter;
|
2017-01-03 17:00:51 +08:00
|
|
|
/// Builder for helper declarations reference graph.
|
|
|
|
HelperDeclRGBuilder RGBuilder;
|
[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 ClangMoveAction : public clang::ASTFrontendAction {
|
|
|
|
public:
|
2016-11-24 18:17:17 +08:00
|
|
|
ClangMoveAction(ClangMoveContext *const Context,
|
|
|
|
DeclarationReporter *const Reporter)
|
|
|
|
: MoveTool(Context, 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
|
|
|
MoveTool.registerMatchers(&MatchFinder);
|
|
|
|
}
|
|
|
|
|
|
|
|
~ClangMoveAction() override = default;
|
|
|
|
|
|
|
|
std::unique_ptr<clang::ASTConsumer>
|
|
|
|
CreateASTConsumer(clang::CompilerInstance &Compiler,
|
|
|
|
llvm::StringRef InFile) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ast_matchers::MatchFinder MatchFinder;
|
|
|
|
ClangMoveTool MoveTool;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ClangMoveActionFactory : public tooling::FrontendActionFactory {
|
|
|
|
public:
|
2016-11-24 18:17:17 +08:00
|
|
|
ClangMoveActionFactory(ClangMoveContext *const Context,
|
|
|
|
DeclarationReporter *const Reporter = nullptr)
|
|
|
|
: Context(Context), Reporter(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
|
|
|
|
|
|
|
clang::FrontendAction *create() override {
|
2016-11-24 18:17:17 +08:00
|
|
|
return new ClangMoveAction(Context, 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
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-11-24 18:17:17 +08:00
|
|
|
// Not owned.
|
|
|
|
ClangMoveContext *const Context;
|
|
|
|
DeclarationReporter *const 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
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace move
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_MOVE_CLANGMOVE_H
|