Skip to content

Commit bf0d49c

Browse files
committedSep 11, 2017
clang-rename: let -force handle multiple renames
Summary: The use case is that renaming multiple symbols in a large enough codebase is much faster if all of these can be done with a single invocation, but there will be multiple translation units where one or more symbols are not found. Old behavior was to exit with an error (default) or exit without reporting an error (-force). New behavior is that -force results in a best-effort rename: rename symbols which are found and just ignore the rest. The existing help for -force sort of already implies this behavior. Reviewers: cfe-commits, klimek, arphaman Reviewed By: klimek Differential Revision: https://reviews.llvm.org/D37634 llvm-svn: 312942
1 parent 015bded commit bf0d49c

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed
 

‎clang/lib/Tooling/Refactoring/Rename/RenamingAction.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,13 @@ class RenamingASTConsumer : public ASTConsumer {
8484
FileToReplaces(FileToReplaces), PrintLocations(PrintLocations) {}
8585

8686
void HandleTranslationUnit(ASTContext &Context) override {
87-
for (unsigned I = 0; I < NewNames.size(); ++I)
87+
for (unsigned I = 0; I < NewNames.size(); ++I) {
88+
// If the previous name was not found, ignore this rename request.
89+
if (PrevNames[I].empty())
90+
continue;
91+
8892
HandleOneRename(Context, NewNames[I], PrevNames[I], USRList[I]);
93+
}
8994
}
9095

9196
void HandleOneRename(ASTContext &Context, const std::string &NewName,

‎clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,11 @@ class NamedDeclFindingConsumer : public ASTConsumer {
198198
return false;
199199
}
200200

201-
if (Force)
201+
if (Force) {
202+
SpellingNames.push_back(std::string());
203+
USRList.push_back(std::vector<std::string>());
202204
return true;
205+
}
203206

204207
unsigned CouldNotFindSymbolNamed = Engine.getCustomDiagID(
205208
DiagnosticsEngine::Error, "clang-rename could not find symbol %0");
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class B /* Test 1 */ { // CHECK: class B2 /* Test 1 */ {
2+
};
3+
4+
class D : public B /* Test 1 */ { // CHECK: class D : public B2 /* Test 1 */ {
5+
};
6+
7+
// Test 1.
8+
// RUN: clang-rename -force -qualified-name B -new-name B2 -qualified-name E -new-name E2 %s -- | sed 's,//.*,,' | FileCheck %s

‎clang/tools/clang-rename/ClangRename.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,6 @@ int main(int argc, const char **argv) {
175175
return 1;
176176
}
177177

178-
if (Force && PrevNames.size() < NewNames.size()) {
179-
// No matching PrevName for all NewNames. Without Force this is an error
180-
// above already.
181-
return 0;
182-
}
183-
184178
// Perform the renaming.
185179
tooling::RenamingAction RenameAction(NewNames, PrevNames, USRList,
186180
Tool.getReplacements(), PrintLocations);

0 commit comments

Comments
 (0)
Please sign in to comment.