Skip to content

Commit

Permalink
[refactor] Move clang-rename into the clang repository
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hyp committed Jun 30, 2017
1 parent 069e5cf commit 4abbd92
Show file tree
Hide file tree
Showing 56 changed files with 81 additions and 96 deletions.
1 change: 0 additions & 1 deletion clang-tools-extra/CMakeLists.txt
@@ -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)
Expand Down
19 changes: 0 additions & 19 deletions clang-tools-extra/clang-rename/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion clang-tools-extra/test/CMakeLists.txt
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion clang-tools-extra/unittests/CMakeLists.txt
Expand Up @@ -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)
@@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/RenamingAction.h - Clang rename tool ----===//
//===--- RenamingAction.h - Clang refactoring library ---------------------===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -12,16 +12,16 @@
///
//===----------------------------------------------------------------------===//

#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"

namespace clang {
class ASTConsumer;
class CompilerInstance;

namespace rename {
namespace tooling {

class RenamingAction {
public:
Expand Down Expand Up @@ -64,7 +64,7 @@ class QualifiedRenamingAction {
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
@@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/USRFinder.h - Clang rename tool ---------===//
//===--- USRFinder.h - Clang refactoring library --------------------------===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -78,7 +78,7 @@ class NestedNameSpecifierLocFinder : public MatchFinder::MatchCallback {
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
@@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/USRFindingAction.h - Clang rename tool --===//
//===--- USRFindingAction.h - Clang refactoring library -------------------===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -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"
Expand All @@ -26,7 +26,7 @@ class ASTConsumer;
class CompilerInstance;
class NamedDecl;

namespace rename {
namespace tooling {

struct USRFindingAction {
USRFindingAction(ArrayRef<unsigned> SymbolOffsets,
Expand All @@ -48,7 +48,7 @@ struct USRFindingAction {
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
@@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/USRLocFinder.h - Clang rename tool ------===//
//===--- USRLocFinder.h - Clang refactoring library -----------------------===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -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"
Expand All @@ -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.
Expand All @@ -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
3 changes: 2 additions & 1 deletion clang/include/clang/module.modulemap
Expand Up @@ -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"
}
8 changes: 8 additions & 0 deletions clang/lib/Tooling/Refactoring/CMakeLists.txt
Expand Up @@ -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
)
@@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/RenamingAction.cpp - Clang rename tool --===//
//===--- RenamingAction.cpp - Clang refactoring library -------------------===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -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"
Expand All @@ -23,14 +22,15 @@
#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>

using namespace llvm;

namespace clang {
namespace rename {
namespace tooling {

class RenamingASTConsumer : public ASTConsumer {
public:
Expand All @@ -55,8 +55,8 @@ class RenamingASTConsumer : public ASTConsumer {
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());

Expand Down Expand Up @@ -101,7 +101,7 @@ class USRSymbolRenamer : public ASTConsumer {
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()) {
Expand Down Expand Up @@ -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
@@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/USRFinder.cpp - Clang rename tool -------===//
//===--- USRFinder.cpp - Clang refactoring library ------------------------===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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
@@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/USRFindingAction.cpp - Clang rename tool ===//
//===--- USRFindingAction.cpp - Clang refactoring library -----------------===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -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"
Expand All @@ -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>
Expand All @@ -37,7 +37,7 @@
using namespace llvm;

namespace clang {
namespace rename {
namespace tooling {

namespace {
// \brief NamedDeclFindingConsumer should delegate finding USRs of given Decl to
Expand Down Expand Up @@ -232,5 +232,5 @@ std::unique_ptr<ASTConsumer> USRFindingAction::newASTConsumer() {
ErrorOccurred);
}

} // namespace rename
} // namespace clang
} // end namespace tooling
} // end namespace clang
@@ -1,4 +1,4 @@
//===--- tools/extra/clang-rename/USRLocFinder.cpp - Clang rename tool ----===//
//===--- USRLocFinder.cpp - Clang refactoring library ---------------------===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -8,21 +8,21 @@
//===----------------------------------------------------------------------===//
///
/// \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"
#include "clang/Basic/SourceLocation.h"
#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>
Expand All @@ -33,7 +33,7 @@
using namespace llvm;

namespace clang {
namespace rename {
namespace tooling {

namespace {

Expand Down Expand Up @@ -505,5 +505,5 @@ createRenameAtomicChanges(llvm::ArrayRef<std::string> USRs,
return AtomicChanges;
}

} // namespace rename
} // namespace clang
} // end namespace tooling
} // end namespace clang

0 comments on commit 4abbd92

Please sign in to comment.