[refactor] Move clang-rename into the clang repository

The core engine of clang-rename will be used for local and global renames in the
new refactoring engine, as mentioned in
http://lists.llvm.org/pipermail/cfe-dev/2017-June/054286.html.

The clang-rename tool is still supported but might get deprecated in the future.

Differential Revision: https://reviews.llvm.org/D34696

llvm-svn: 306840
This commit is contained in:
Alex Lorenz 2017-06-30 16:36:09 +00:00
parent 069e5cfaf1
commit 4abbd92bf4
56 changed files with 81 additions and 96 deletions

View File

@ -1,5 +1,4 @@
add_subdirectory(clang-apply-replacements)
add_subdirectory(clang-rename)
add_subdirectory(clang-reorder-fields)
add_subdirectory(modularize)
if(CLANG_ENABLE_STATIC_ANALYZER)

View File

@ -1,19 +0,0 @@
set(LLVM_LINK_COMPONENTS support)
add_clang_library(clangRename
USRFinder.cpp
USRFindingAction.cpp
USRLocFinder.cpp
RenamingAction.cpp
LINK_LIBS
clangAST
clangASTMatchers
clangBasic
clangIndex
clangLex
clangToolingCore
clangToolingRefactor
)
add_subdirectory(tool)

View File

@ -44,7 +44,6 @@ set(CLANG_TOOLS_TEST_DEPS
clang-include-fixer
clang-move
clang-query
clang-rename
clang-reorder-fields
clang-tidy
find-all-symbols

View File

@ -10,6 +10,5 @@ add_subdirectory(clang-apply-replacements)
add_subdirectory(clang-move)
add_subdirectory(clang-query)
add_subdirectory(clang-tidy)
add_subdirectory(clang-rename)
add_subdirectory(clangd)
add_subdirectory(include-fixer)

View File

@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/RenamingAction.h - Clang rename tool ----===//
//===--- RenamingAction.h - Clang refactoring library ---------------------===//
//
// The LLVM Compiler Infrastructure
//
@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_RENAMING_ACTION_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_RENAMING_ACTION_H
#ifndef LLVM_CLANG_TOOLING_REFACTOR_RENAME_RENAMING_ACTION_H
#define LLVM_CLANG_TOOLING_REFACTOR_RENAME_RENAMING_ACTION_H
#include "clang/Tooling/Refactoring.h"
@ -21,7 +21,7 @@ namespace clang {
class ASTConsumer;
class CompilerInstance;
namespace rename {
namespace tooling {
class RenamingAction {
public:
@ -64,7 +64,7 @@ private:
std::map<std::string, tooling::Replacements> &FileToReplaces;
};
} // namespace rename
} // namespace clang
} // end namespace tooling
} // end namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_RENAMING_ACTION_H
#endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_RENAMING_ACTION_H

View File

@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/USRFinder.h - Clang rename tool ---------===//
//===--- USRFinder.h - Clang refactoring library --------------------------===//
//
// The LLVM Compiler Infrastructure
//
@ -13,8 +13,8 @@
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDER_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDER_H
#ifndef LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDER_H
#define LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDER_H
#include "clang/AST/AST.h"
#include "clang/AST/ASTContext.h"
@ -32,7 +32,7 @@ class Decl;
class SourceLocation;
class NamedDecl;
namespace rename {
namespace tooling {
// Given an AST context and a point, returns a NamedDecl identifying the symbol
// at the point. Returns null if nothing is found at the point.
@ -78,7 +78,7 @@ private:
MatchFinder Finder;
};
} // namespace rename
} // namespace clang
} // end namespace tooling
} // end namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDER_H
#endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDER_H

View File

@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/USRFindingAction.h - Clang rename tool --===//
//===--- USRFindingAction.h - Clang refactoring library -------------------===//
//
// The LLVM Compiler Infrastructure
//
@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDING_ACTION_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDING_ACTION_H
#ifndef LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDING_ACTION_H
#define LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDING_ACTION_H
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
@ -26,7 +26,7 @@ class ASTConsumer;
class CompilerInstance;
class NamedDecl;
namespace rename {
namespace tooling {
struct USRFindingAction {
USRFindingAction(ArrayRef<unsigned> SymbolOffsets,
@ -48,7 +48,7 @@ private:
bool Force;
};
} // namespace rename
} // namespace clang
} // end namespace tooling
} // end namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDING_ACTION_H
#endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDING_ACTION_H

View File

@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/USRLocFinder.h - Clang rename tool ------===//
//===--- USRLocFinder.h - Clang refactoring library -----------------------===//
//
// The LLVM Compiler Infrastructure
//
@ -13,8 +13,8 @@
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_LOC_FINDER_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_LOC_FINDER_H
#ifndef LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_LOC_FINDER_H
#define LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_LOC_FINDER_H
#include "clang/AST/AST.h"
#include "clang/Tooling/Core/Replacement.h"
@ -24,7 +24,7 @@
#include <vector>
namespace clang {
namespace rename {
namespace tooling {
/// Create atomic changes for renaming all symbol references which are
/// identified by the USRs set to a given new name.
@ -43,7 +43,7 @@ std::vector<SourceLocation>
getLocationsOfUSRs(const std::vector<std::string> &USRs,
llvm::StringRef PrevName, Decl *Decl);
} // namespace rename
} // namespace clang
} // end namespace tooling
} // end namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_LOC_FINDER_H
#endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_LOC_FINDER_H

View File

@ -133,9 +133,10 @@ module Clang_StaticAnalyzer_Frontend {
module Clang_Tooling {
requires cplusplus umbrella "Tooling" module * { export * }
// FIXME: Exclude this header to avoid pulling all of the AST matchers
// FIXME: Exclude these headers to avoid pulling all of the AST matchers
// library into clang-format. Due to inline key functions in the headers,
// importing the AST matchers library gives a link dependency on the AST
// matchers (and thus the AST), which clang-format should not have.
exclude header "Tooling/RefactoringCallbacks.h"
exclude header "Tooling/Refactoring/Rename/USRFinder.h"
}

View File

@ -5,8 +5,16 @@ set(LLVM_LINK_COMPONENTS
add_clang_library(clangToolingRefactor
AtomicChange.cpp
Rename/RenamingAction.cpp
Rename/USRFinder.cpp
Rename/USRFindingAction.cpp
Rename/USRLocFinder.cpp
LINK_LIBS
clangAST
clangASTMatchers
clangBasic
clangIndex
clangLex
clangToolingCore
)

View File

@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/RenamingAction.cpp - Clang rename tool --===//
//===--- RenamingAction.cpp - Clang refactoring library -------------------===//
//
// The LLVM Compiler Infrastructure
//
@ -12,8 +12,7 @@
///
//===----------------------------------------------------------------------===//
#include "RenamingAction.h"
#include "USRLocFinder.h"
#include "clang/Tooling/Refactoring/Rename/RenamingAction.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/Basic/FileManager.h"
@ -23,6 +22,7 @@
#include "clang/Lex/Preprocessor.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/Refactoring/Rename/USRLocFinder.h"
#include "clang/Tooling/Tooling.h"
#include <string>
#include <vector>
@ -30,7 +30,7 @@
using namespace llvm;
namespace clang {
namespace rename {
namespace tooling {
class RenamingASTConsumer : public ASTConsumer {
public:
@ -55,8 +55,8 @@ public:
std::vector<SourceLocation> RenamingCandidates;
std::vector<SourceLocation> NewCandidates;
NewCandidates =
getLocationsOfUSRs(USRs, PrevName, Context.getTranslationUnitDecl());
NewCandidates = tooling::getLocationsOfUSRs(
USRs, PrevName, Context.getTranslationUnitDecl());
RenamingCandidates.insert(RenamingCandidates.end(), NewCandidates.begin(),
NewCandidates.end());
@ -101,7 +101,7 @@ public:
for (unsigned I = 0; I < NewNames.size(); ++I) {
// FIXME: Apply AtomicChanges directly once the refactoring APIs are
// ready.
auto AtomicChanges = createRenameAtomicChanges(
auto AtomicChanges = tooling::createRenameAtomicChanges(
USRList[I], NewNames[I], Context.getTranslationUnitDecl());
for (const auto AtomicChange : AtomicChanges) {
for (const auto &Replace : AtomicChange.getReplacements()) {
@ -130,5 +130,5 @@ std::unique_ptr<ASTConsumer> QualifiedRenamingAction::newASTConsumer() {
return llvm::make_unique<USRSymbolRenamer>(NewNames, USRList, FileToReplaces);
}
} // namespace rename
} // namespace clang
} // end namespace tooling
} // end namespace clang

View File

@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/USRFinder.cpp - Clang rename tool -------===//
//===--- USRFinder.cpp - Clang refactoring library ------------------------===//
//
// The LLVM Compiler Infrastructure
//
@ -12,7 +12,7 @@
///
//===----------------------------------------------------------------------===//
#include "USRFinder.h"
#include "clang/Tooling/Refactoring/Rename/USRFinder.h"
#include "clang/AST/AST.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/RecursiveASTVisitor.h"
@ -23,7 +23,7 @@
using namespace llvm;
namespace clang {
namespace rename {
namespace tooling {
// NamedDeclFindingASTVisitor recursively visits each AST node to find the
// symbol underneath the cursor.
@ -209,5 +209,5 @@ std::string getUSRForDecl(const Decl *Decl) {
return std::string(Buff.data(), Buff.size());
}
} // namespace rename
} // namespace clang
} // end namespace tooling
} // end namespace clang

View File

@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/USRFindingAction.cpp - Clang rename tool ===//
//===--- USRFindingAction.cpp - Clang refactoring library -----------------===//
//
// The LLVM Compiler Infrastructure
//
@ -13,8 +13,7 @@
///
//===----------------------------------------------------------------------===//
#include "USRFindingAction.h"
#include "USRFinder.h"
#include "clang/Tooling/Refactoring/Rename/USRFindingAction.h"
#include "clang/AST/AST.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
@ -27,6 +26,7 @@
#include "clang/Lex/Preprocessor.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/Refactoring/Rename/USRFinder.h"
#include "clang/Tooling/Tooling.h"
#include <algorithm>
@ -37,7 +37,7 @@
using namespace llvm;
namespace clang {
namespace rename {
namespace tooling {
namespace {
// \brief NamedDeclFindingConsumer should delegate finding USRs of given Decl to
@ -232,5 +232,5 @@ std::unique_ptr<ASTConsumer> USRFindingAction::newASTConsumer() {
ErrorOccurred);
}
} // namespace rename
} // namespace clang
} // end namespace tooling
} // end namespace clang

View File

@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/USRLocFinder.cpp - Clang rename tool ----===//
//===--- USRLocFinder.cpp - Clang refactoring library ---------------------===//
//
// The LLVM Compiler Infrastructure
//
@ -8,14 +8,13 @@
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief Mehtods for finding all instances of a USR. Our strategy is very
/// \brief Methods for finding all instances of a USR. Our strategy is very
/// simple; we just compare the USR at every relevant AST node with the one
/// provided.
///
//===----------------------------------------------------------------------===//
#include "USRLocFinder.h"
#include "USRFinder.h"
#include "clang/Tooling/Refactoring/Rename/USRLocFinder.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/LLVM.h"
@ -23,6 +22,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
#include "clang/Tooling/Core/Lookup.h"
#include "clang/Tooling/Refactoring/Rename/USRFinder.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include <cstddef>
@ -33,7 +33,7 @@
using namespace llvm;
namespace clang {
namespace rename {
namespace tooling {
namespace {
@ -505,5 +505,5 @@ createRenameAtomicChanges(llvm::ArrayRef<std::string> USRs,
return AtomicChanges;
}
} // namespace rename
} // namespace clang
} // end namespace tooling
} // end namespace clang

View File

@ -47,6 +47,7 @@ list(APPEND CLANG_TEST_DEPS
clang-tblgen
clang-offload-bundler
clang-import-test
clang-rename
)
if(CLANG_ENABLE_STATIC_ANALYZER)

View File

@ -10,6 +10,8 @@ add_clang_subdirectory(clang-offload-bundler)
add_clang_subdirectory(c-index-test)
add_clang_subdirectory(clang-rename)
if(CLANG_ENABLE_ARCMT)
add_clang_subdirectory(arcmt-test)
add_clang_subdirectory(c-arcmt-test)

View File

@ -3,10 +3,10 @@ add_clang_executable(clang-rename ClangRename.cpp)
target_link_libraries(clang-rename
clangBasic
clangFrontend
clangRename
clangRewrite
clangTooling
clangToolingCore
clangToolingRefactor
)
install(TARGETS clang-rename RUNTIME DESTINATION bin)

View File

@ -13,8 +13,6 @@
///
//===----------------------------------------------------------------------===//
#include "../RenamingAction.h"
#include "../USRFindingAction.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/FileManager.h"
@ -26,6 +24,8 @@
#include "clang/Rewrite/Core/Rewriter.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/Refactoring/Rename/RenamingAction.h"
#include "clang/Tooling/Refactoring/Rename/USRFindingAction.h"
#include "clang/Tooling/ReplacementsYaml.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
@ -160,7 +160,7 @@ int main(int argc, const char **argv) {
auto Files = OP.getSourcePathList();
tooling::RefactoringTool Tool(OP.getCompilations(), Files);
rename::USRFindingAction FindingAction(SymbolOffsets, QualifiedNames, Force);
tooling::USRFindingAction FindingAction(SymbolOffsets, QualifiedNames, Force);
Tool.run(tooling::newFrontendActionFactory(&FindingAction).get());
const std::vector<std::vector<std::string>> &USRList =
FindingAction.getUSRList();
@ -183,8 +183,8 @@ int main(int argc, const char **argv) {
}
// Perform the renaming.
rename::RenamingAction RenameAction(NewNames, PrevNames, USRList,
Tool.getReplacements(), PrintLocations);
tooling::RenamingAction RenameAction(NewNames, PrevNames, USRList,
Tool.getReplacements(), PrintLocations);
std::unique_ptr<tooling::FrontendActionFactory> Factory =
tooling::newFrontendActionFactory(&RenameAction);
int ExitCode;

View File

@ -29,3 +29,4 @@ add_subdirectory(CodeGen)
if(NOT WIN32 AND CLANG_TOOL_LIBCLANG_BUILD)
add_subdirectory(libclang)
endif()
add_subdirectory(Rename)

View File

@ -2,12 +2,6 @@ set(LLVM_LINK_COMPONENTS
support
)
get_filename_component(CLANG_RENAME_SOURCE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/../../clang-rename REALPATH)
include_directories(
${CLANG_RENAME_SOURCE_DIR}
)
# We'd like clang/unittests/Tooling/RewriterTestContext.h in the test.
include_directories(${CLANG_SOURCE_DIR})
@ -21,8 +15,8 @@ target_link_libraries(ClangRenameTests
clangBasic
clangFormat
clangFrontend
clangRename
clangRewrite
clangTooling
clangToolingCore
clangToolingRefactor
)

View File

@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
#include "RenamingAction.h"
#include "USRFindingAction.h"
#include "unittests/Tooling/RewriterTestContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/FileManager.h"
@ -18,6 +16,8 @@
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/PCHContainerOperations.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/Refactoring/Rename/RenamingAction.h"
#include "clang/Tooling/Refactoring/Rename/USRFindingAction.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/StringRef.h"
@ -56,7 +56,7 @@ protected:
Context.createInMemoryFile(HeaderName, HeaderContent);
clang::FileID InputFileID = Context.createInMemoryFile(CCName, NewCode);
rename::USRFindingAction FindingAction({}, {OldName}, false);
tooling::USRFindingAction FindingAction({}, {OldName}, false);
std::unique_ptr<tooling::FrontendActionFactory> USRFindingActionFactory =
tooling::newFrontendActionFactory(&FindingAction);
@ -70,8 +70,8 @@ protected:
FindingAction.getUSRList();
std::vector<std::string> NewNames = {NewName};
std::map<std::string, tooling::Replacements> FileToReplacements;
rename::QualifiedRenamingAction RenameAction(NewNames, USRList,
FileToReplacements);
tooling::QualifiedRenamingAction RenameAction(NewNames, USRList,
FileToReplacements);
auto RenameActionFactory = tooling::newFrontendActionFactory(&RenameAction);
if (!tooling::runToolOnCodeWithArgs(
RenameActionFactory->create(), NewCode, {"-std=c++11"}, CCName,