Index: clang-tools-extra/trunk/clang-rename/USRFindingAction.h =================================================================== --- clang-tools-extra/trunk/clang-rename/USRFindingAction.h +++ clang-tools-extra/trunk/clang-rename/USRFindingAction.h @@ -30,9 +30,9 @@ struct USRFindingAction { USRFindingAction(ArrayRef SymbolOffsets, - ArrayRef QualifiedNames) + ArrayRef QualifiedNames, bool Force) : SymbolOffsets(SymbolOffsets), QualifiedNames(QualifiedNames), - ErrorOccurred(false) {} + ErrorOccurred(false), Force(Force) {} std::unique_ptr newASTConsumer(); ArrayRef getUSRSpellings() { return SpellingNames; } @@ -45,6 +45,7 @@ std::vector SpellingNames; std::vector> USRList; bool ErrorOccurred; + bool Force; }; } // namespace rename Index: clang-tools-extra/trunk/clang-rename/USRFindingAction.cpp =================================================================== --- clang-tools-extra/trunk/clang-rename/USRFindingAction.cpp +++ clang-tools-extra/trunk/clang-rename/USRFindingAction.cpp @@ -145,9 +145,9 @@ ArrayRef QualifiedNames, std::vector &SpellingNames, std::vector> &USRList, - bool &ErrorOccurred) + bool Force, bool &ErrorOccurred) : SymbolOffsets(SymbolOffsets), QualifiedNames(QualifiedNames), - SpellingNames(SpellingNames), USRList(USRList), + SpellingNames(SpellingNames), USRList(USRList), Force(Force), ErrorOccurred(ErrorOccurred) {} private: @@ -182,6 +182,10 @@ ErrorOccurred = true; return false; } + + if (Force) + return true; + unsigned CouldNotFindSymbolNamed = Engine.getCustomDiagID( DiagnosticsEngine::Error, "clang-rename could not find symbol %0"); Engine.Report(CouldNotFindSymbolNamed) << QualifiedName; @@ -218,12 +222,14 @@ ArrayRef QualifiedNames; std::vector &SpellingNames; std::vector> &USRList; + bool Force; bool &ErrorOccurred; }; std::unique_ptr USRFindingAction::newASTConsumer() { return llvm::make_unique( - SymbolOffsets, QualifiedNames, SpellingNames, USRList, ErrorOccurred); + SymbolOffsets, QualifiedNames, SpellingNames, USRList, Force, + ErrorOccurred); } } // namespace rename Index: clang-tools-extra/trunk/clang-rename/tool/ClangRename.cpp =================================================================== --- clang-tools-extra/trunk/clang-rename/tool/ClangRename.cpp +++ clang-tools-extra/trunk/clang-rename/tool/ClangRename.cpp @@ -95,6 +95,9 @@ static cl::opt Input("input", cl::desc("YAML file to load oldname-newname pairs from."), cl::Optional, cl::cat(ClangRenameOptions)); +static cl::opt Force("force", + cl::desc("Ignore nonexistent qualified names."), + cl::cat(ClangRenameOptions)); int main(int argc, const char **argv) { tooling::CommonOptionsParser OP(argc, argv, ClangRenameOptions); @@ -157,7 +160,7 @@ auto Files = OP.getSourcePathList(); tooling::RefactoringTool Tool(OP.getCompilations(), Files); - rename::USRFindingAction FindingAction(SymbolOffsets, QualifiedNames); + rename::USRFindingAction FindingAction(SymbolOffsets, QualifiedNames, Force); Tool.run(tooling::newFrontendActionFactory(&FindingAction).get()); const std::vector> &USRList = FindingAction.getUSRList(); @@ -173,6 +176,12 @@ exit(1); } + if (Force && PrevNames.size() < NewNames.size()) { + // No matching PrevName for all NewNames. Without Force this is an error + // above already. + exit(0); + } + // Perform the renaming. rename::RenamingAction RenameAction(NewNames, PrevNames, USRList, Tool.getReplacements(), PrintLocations); Index: clang-tools-extra/trunk/docs/clang-rename.rst =================================================================== --- clang-tools-extra/trunk/docs/clang-rename.rst +++ clang-tools-extra/trunk/docs/clang-rename.rst @@ -124,6 +124,7 @@ -export-fixes= - YAML file to store suggested fixes in. -extra-arg= - Additional argument to append to the compiler command line -extra-arg-before= - Additional argument to prepend to the compiler command line + -force - Ignore nonexistent qualified names. -i - Overwrite edited s. -input= - YAML file to load oldname-newname pairs from. -new-name= - The new name to change the symbol to. Index: clang-tools-extra/trunk/test/clang-rename/InvalidQualifiedName.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-rename/InvalidQualifiedName.cpp +++ clang-tools-extra/trunk/test/clang-rename/InvalidQualifiedName.cpp @@ -0,0 +1,4 @@ +struct S { +}; + +// RUN: clang-rename -force -qualified-name S2 -new-name=T %s -- Index: clang-tools-extra/trunk/unittests/clang-rename/ClangRenameTest.h =================================================================== --- clang-tools-extra/trunk/unittests/clang-rename/ClangRenameTest.h +++ clang-tools-extra/trunk/unittests/clang-rename/ClangRenameTest.h @@ -56,7 +56,7 @@ Context.createInMemoryFile(HeaderName, HeaderContent); clang::FileID InputFileID = Context.createInMemoryFile(CCName, NewCode); - rename::USRFindingAction FindingAction({}, {OldName}); + rename::USRFindingAction FindingAction({}, {OldName}, false); std::unique_ptr USRFindingActionFactory = tooling::newFrontendActionFactory(&FindingAction);