Index: clang-rename/tool/ClangRename.cpp =================================================================== --- clang-rename/tool/ClangRename.cpp +++ clang-rename/tool/ClangRename.cpp @@ -63,6 +63,11 @@ cl::desc("Overwrite edited s."), cl::cat(ClangRenameCategory)); static cl::opt +Suffix( + "s", + cl::desc("Similar to -i, but write out edited s with a '.new-rename' suffix."), + cl::cat(ClangRenameCategory)); +static cl::opt PrintName( "pn", cl::desc("Print the found symbol's name prior to renaming to stderr."), @@ -144,7 +149,18 @@ for (const auto &File : Files) { const auto *Entry = FileMgr.getFile(File); auto ID = Sources.translateFile(Entry); - Rewrite.getEditBuffer(ID).write(outs()); + if (Suffix) { + // Write files with a '.new-rename' suffix instead of overwriting. + std::string FileName = std::string(Entry->getName()) + ".new-rename"; + std::error_code Error; + llvm::raw_fd_ostream Stream(FileName, Error, llvm::sys::fs::F_None); + if (!Error) { + Rewrite.getEditBuffer(ID).write(Stream); + } + } else { + // Write to stdout. + Rewrite.getEditBuffer(ID).write(outs()); + } } } Index: test/clang-rename/ClassTestSuffix.cpp =================================================================== --- /dev/null +++ test/clang-rename/ClassTestSuffix.cpp @@ -0,0 +1,15 @@ +// RUN: cat %s > %T/test.cpp +// RUN: clang-rename -offset=164 -new-name=Hector %T/test.cpp -s -- +// RUN: sed 's,//.*,,' %T/test.cpp.new-rename | FileCheck %s +class Cla // CHECK: class Hector +{ +}; + +int main() +{ + Cla *Pointer = 0; // CHECK: Hector *Pointer = 0; + return 0; +} + +// Use grep -FUbo 'Cla' to get the correct offset of Cla when changing +// this file.