[PATCH] D21676: clang-rename: add a -export-fixes option
Miklos Vajna via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 27 12:41:59 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL273910: clang-rename: add a -export-fixes option (authored by vmiklos).
Changed prior to commit:
http://reviews.llvm.org/D21676?vs=61833&id=62004#toc
Repository:
rL LLVM
http://reviews.llvm.org/D21676
Files:
clang-tools-extra/trunk/clang-rename/tool/ClangRename.cpp
clang-tools-extra/trunk/test/clang-rename/ClassTestReplacements.cpp
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
@@ -32,6 +32,7 @@
#include "clang/Rewrite/Core/Rewriter.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Refactoring.h"
+#include "clang/Tooling/ReplacementsYaml.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/Support/Host.h"
@@ -72,6 +73,12 @@
"pl",
cl::desc("Print the locations affected by renaming to stderr."),
cl::cat(ClangRenameCategory));
+static cl::opt<std::string>
+ExportFixes(
+ "export-fixes",
+ cl::desc("YAML file to store suggested fixes in."),
+ cl::value_desc("filename"),
+ cl::cat(ClangRenameCategory));
#define CLANG_RENAME_VERSION "0.0.1"
@@ -126,6 +133,26 @@
} else {
res = Tool.run(Factory.get());
+ if (!ExportFixes.empty()) {
+ std::error_code EC;
+ llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::F_None);
+ if (EC) {
+ llvm::errs() << "Error opening output file: " << EC.message() << '\n';
+ exit(1);
+ }
+
+ // Export replacements.
+ tooling::TranslationUnitReplacements TUR;
+ const tooling::Replacements &Replacements = Tool.getReplacements();
+ TUR.Replacements.insert(TUR.Replacements.end(), Replacements.begin(),
+ Replacements.end());
+
+ yaml::Output YAML(OS);
+ YAML << TUR;
+ OS.close();
+ exit(0);
+ }
+
// Write every file to stdout. Right now we just barf the files without any
// indication of which files start where, other than that we print the files
// in the same order we see them.
Index: clang-tools-extra/trunk/test/clang-rename/ClassTestReplacements.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-rename/ClassTestReplacements.cpp
+++ clang-tools-extra/trunk/test/clang-rename/ClassTestReplacements.cpp
@@ -0,0 +1,11 @@
+// RUN: mkdir -p %T/fixes
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=225 -new-name=Hector -export-fixes=%T/fixes.yaml %t.cpp --
+// RUN: clang-apply-replacements %T
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+class Cla // CHECK: class Hector
+{
+};
+
+// Use grep -FUbo 'Cla' <file> to get the correct offset of Cla when changing
+// this file.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21676.62004.patch
Type: text/x-patch
Size: 2505 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160627/4b4d0141/attachment.bin>
More information about the cfe-commits
mailing list