r316212 - [clang-refactor] Add "-Inplace" option to the commandline tool.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 20 05:37:16 PDT 2017
Author: hokein
Date: Fri Oct 20 05:37:16 2017
New Revision: 316212
URL: http://llvm.org/viewvc/llvm-project?rev=316212&view=rev
Log:
[clang-refactor] Add "-Inplace" option to the commandline tool.
Summary:
Change clang-refactor default behavior to print the new code after refactoring
(instead of editing the source files), which would make it easier to use
and debug the refactoring action.
Reviewers: arphaman, ioeric
Reviewed By: arphaman
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D39092
Modified:
cfe/trunk/test/Refactor/tool-apply-replacements.cpp
cfe/trunk/tools/clang-refactor/ClangRefactor.cpp
Modified: cfe/trunk/test/Refactor/tool-apply-replacements.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Refactor/tool-apply-replacements.cpp?rev=316212&r1=316211&r2=316212&view=diff
==============================================================================
--- cfe/trunk/test/Refactor/tool-apply-replacements.cpp (original)
+++ cfe/trunk/test/Refactor/tool-apply-replacements.cpp Fri Oct 20 05:37:16 2017
@@ -1,10 +1,8 @@
-// RUN: rm -f %t.cp.cpp
-// RUN: cp %s %t.cp.cpp
-// RUN: clang-refactor local-rename -selection=%t.cp.cpp:9:7 -new-name=test %t.cp.cpp --
-// RUN: grep -v CHECK %t.cp.cpp | FileCheck %t.cp.cpp
-// RUN: cp %s %t.cp.cpp
-// RUN: clang-refactor local-rename -selection=%t.cp.cpp:9:7-9:15 -new-name=test %t.cp.cpp --
-// RUN: grep -v CHECK %t.cp.cpp | FileCheck %t.cp.cpp
+// RUN: sed -e 's#//.*$##' %s > %t.cpp
+// RUN: clang-refactor local-rename -selection=%t.cpp:7:7 -new-name=test %t.cpp -- | FileCheck %s
+// RUN: clang-refactor local-rename -selection=%t.cpp:7:7-7:15 -new-name=test %t.cpp -- | FileCheck %s
+// RUN: clang-refactor local-rename -i -selection=%t.cpp:7:7 -new-name=test %t.cpp --
+// RUN: FileCheck -input-file=%t.cpp %s
class RenameMe {
// CHECK: class test {
Modified: cfe/trunk/tools/clang-refactor/ClangRefactor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-refactor/ClangRefactor.cpp?rev=316212&r1=316211&r2=316212&view=diff
==============================================================================
--- cfe/trunk/tools/clang-refactor/ClangRefactor.cpp (original)
+++ cfe/trunk/tools/clang-refactor/ClangRefactor.cpp Fri Oct 20 05:37:16 2017
@@ -40,6 +40,11 @@ static cl::OptionCategory CommonRefactor
static cl::opt<bool> Verbose("v", cl::desc("Use verbose output"),
cl::cat(cl::GeneralCategory),
cl::sub(*cl::AllSubCommands));
+
+static cl::opt<bool> Inplace("i", cl::desc("Inplace edit <file>s"),
+ cl::cat(cl::GeneralCategory),
+ cl::sub(*cl::AllSubCommands));
+
} // end namespace opts
namespace {
@@ -436,13 +441,18 @@ public:
return true;
}
- std::error_code EC;
- llvm::raw_fd_ostream OS(File, EC, llvm::sys::fs::F_Text);
- if (EC) {
- llvm::errs() << EC.message() << "\n";
- return true;
+ if (opts::Inplace) {
+ std::error_code EC;
+ llvm::raw_fd_ostream OS(File, EC, llvm::sys::fs::F_Text);
+ if (EC) {
+ llvm::errs() << EC.message() << "\n";
+ return true;
+ }
+ OS << *Result;
+ continue;
}
- OS << *Result;
+
+ llvm::outs() << *Result;
}
return false;
}
More information about the cfe-commits
mailing list