forked from llvm-mirror/clang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306840 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
52 changed files
with
3,135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//===--- RenamingAction.h - Clang refactoring library ---------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// \brief Provides an action to rename every symbol at a point. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#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 tooling { | ||
|
||
class RenamingAction { | ||
public: | ||
RenamingAction(const std::vector<std::string> &NewNames, | ||
const std::vector<std::string> &PrevNames, | ||
const std::vector<std::vector<std::string>> &USRList, | ||
std::map<std::string, tooling::Replacements> &FileToReplaces, | ||
bool PrintLocations = false) | ||
: NewNames(NewNames), PrevNames(PrevNames), USRList(USRList), | ||
FileToReplaces(FileToReplaces), PrintLocations(PrintLocations) {} | ||
|
||
std::unique_ptr<ASTConsumer> newASTConsumer(); | ||
|
||
private: | ||
const std::vector<std::string> &NewNames, &PrevNames; | ||
const std::vector<std::vector<std::string>> &USRList; | ||
std::map<std::string, tooling::Replacements> &FileToReplaces; | ||
bool PrintLocations; | ||
}; | ||
|
||
/// Rename all symbols identified by the given USRs. | ||
class QualifiedRenamingAction { | ||
public: | ||
QualifiedRenamingAction( | ||
const std::vector<std::string> &NewNames, | ||
const std::vector<std::vector<std::string>> &USRList, | ||
std::map<std::string, tooling::Replacements> &FileToReplaces) | ||
: NewNames(NewNames), USRList(USRList), FileToReplaces(FileToReplaces) {} | ||
|
||
std::unique_ptr<ASTConsumer> newASTConsumer(); | ||
|
||
private: | ||
/// New symbol names. | ||
const std::vector<std::string> &NewNames; | ||
|
||
/// A list of USRs. Each element represents USRs of a symbol being renamed. | ||
const std::vector<std::vector<std::string>> &USRList; | ||
|
||
/// A file path to replacements map. | ||
std::map<std::string, tooling::Replacements> &FileToReplaces; | ||
}; | ||
|
||
} // end namespace tooling | ||
} // end namespace clang | ||
|
||
#endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_RENAMING_ACTION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
//===--- USRFinder.h - Clang refactoring library --------------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// \brief Methods for determining the USR of a symbol at a location in source | ||
/// code. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#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" | ||
#include "clang/ASTMatchers/ASTMatchFinder.h" | ||
#include <string> | ||
#include <vector> | ||
|
||
using namespace llvm; | ||
using namespace clang::ast_matchers; | ||
|
||
namespace clang { | ||
|
||
class ASTContext; | ||
class Decl; | ||
class SourceLocation; | ||
class NamedDecl; | ||
|
||
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. | ||
const NamedDecl *getNamedDeclAt(const ASTContext &Context, | ||
const SourceLocation Point); | ||
|
||
// Given an AST context and a fully qualified name, returns a NamedDecl | ||
// identifying the symbol with a matching name. Returns null if nothing is | ||
// found for the name. | ||
const NamedDecl *getNamedDeclFor(const ASTContext &Context, | ||
const std::string &Name); | ||
|
||
// Converts a Decl into a USR. | ||
std::string getUSRForDecl(const Decl *Decl); | ||
|
||
// FIXME: Implement RecursiveASTVisitor<T>::VisitNestedNameSpecifier instead. | ||
class NestedNameSpecifierLocFinder : public MatchFinder::MatchCallback { | ||
public: | ||
explicit NestedNameSpecifierLocFinder(ASTContext &Context) | ||
: Context(Context) {} | ||
|
||
std::vector<NestedNameSpecifierLoc> getNestedNameSpecifierLocations() { | ||
addMatchers(); | ||
Finder.matchAST(Context); | ||
return Locations; | ||
} | ||
|
||
private: | ||
void addMatchers() { | ||
const auto NestedNameSpecifierLocMatcher = | ||
nestedNameSpecifierLoc().bind("nestedNameSpecifierLoc"); | ||
Finder.addMatcher(NestedNameSpecifierLocMatcher, this); | ||
} | ||
|
||
void run(const MatchFinder::MatchResult &Result) override { | ||
const auto *NNS = Result.Nodes.getNodeAs<NestedNameSpecifierLoc>( | ||
"nestedNameSpecifierLoc"); | ||
Locations.push_back(*NNS); | ||
} | ||
|
||
ASTContext &Context; | ||
std::vector<NestedNameSpecifierLoc> Locations; | ||
MatchFinder Finder; | ||
}; | ||
|
||
} // end namespace tooling | ||
} // end namespace clang | ||
|
||
#endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDER_H |
54 changes: 54 additions & 0 deletions
54
include/clang/Tooling/Refactoring/Rename/USRFindingAction.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//===--- USRFindingAction.h - Clang refactoring library -------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// \brief Provides an action to find all relevant USRs at a point. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#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" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace clang { | ||
class ASTConsumer; | ||
class CompilerInstance; | ||
class NamedDecl; | ||
|
||
namespace tooling { | ||
|
||
struct USRFindingAction { | ||
USRFindingAction(ArrayRef<unsigned> SymbolOffsets, | ||
ArrayRef<std::string> QualifiedNames, bool Force) | ||
: SymbolOffsets(SymbolOffsets), QualifiedNames(QualifiedNames), | ||
ErrorOccurred(false), Force(Force) {} | ||
std::unique_ptr<ASTConsumer> newASTConsumer(); | ||
|
||
ArrayRef<std::string> getUSRSpellings() { return SpellingNames; } | ||
ArrayRef<std::vector<std::string>> getUSRList() { return USRList; } | ||
bool errorOccurred() { return ErrorOccurred; } | ||
|
||
private: | ||
std::vector<unsigned> SymbolOffsets; | ||
std::vector<std::string> QualifiedNames; | ||
std::vector<std::string> SpellingNames; | ||
std::vector<std::vector<std::string>> USRList; | ||
bool ErrorOccurred; | ||
bool Force; | ||
}; | ||
|
||
} // end namespace tooling | ||
} // end namespace clang | ||
|
||
#endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDING_ACTION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//===--- USRLocFinder.h - Clang refactoring library -----------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// \brief Provides functionality for finding all instances of a USR in a given | ||
/// AST. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#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" | ||
#include "clang/Tooling/Refactoring/AtomicChange.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace clang { | ||
namespace tooling { | ||
|
||
/// Create atomic changes for renaming all symbol references which are | ||
/// identified by the USRs set to a given new name. | ||
/// | ||
/// \param USRs The set containing USRs of a particular old symbol. | ||
/// \param NewName The new name to replace old symbol name. | ||
/// \param TranslationUnitDecl The translation unit declaration. | ||
/// | ||
/// \return Atomic changes for renaming. | ||
std::vector<tooling::AtomicChange> | ||
createRenameAtomicChanges(llvm::ArrayRef<std::string> USRs, | ||
llvm::StringRef NewName, Decl *TranslationUnitDecl); | ||
|
||
// FIXME: make this an AST matcher. Wouldn't that be awesome??? I agree! | ||
std::vector<SourceLocation> | ||
getLocationsOfUSRs(const std::vector<std::string> &USRs, | ||
llvm::StringRef PrevName, Decl *Decl); | ||
|
||
} // end namespace tooling | ||
} // end namespace clang | ||
|
||
#endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_LOC_FINDER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.