]> granicus.if.org Git - clang/commitdiff
Use Rewriter::overwriteChangedFiles() directly
authorAlp Toker <alp@nuanti.com>
Tue, 29 Oct 2013 08:32:41 +0000 (08:32 +0000)
committerAlp Toker <alp@nuanti.com>
Tue, 29 Oct 2013 08:32:41 +0000 (08:32 +0000)
This replaces the custom code in RefactoringTool::saveRewrittenFiles() which
lacked atomic file saving and error diagnostics, resolving an old FIXME from
r157331.

Landing this time with the proper return code, plus a very unhelpful comment
cleared up.

Rubber-stamped by Manuel Klimek.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193594 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Rewrite/Core/Rewriter.h
lib/Tooling/Refactoring.cpp

index 1c147f3c29c3e889fd245d0b7fb40d25543c4930..f791d5528c811cb91ff38d9240f28ea7cf3ab663 100644 (file)
@@ -284,7 +284,7 @@ public:
 
   /// overwriteChangedFiles - Save all changed files to disk.
   ///
-  /// Returns whether not all changes were saved successfully.
+  /// Returns true if any files were not saved successfully.
   /// Outputs diagnostics via the source manager's diagnostic engine
   /// in case of an error.
   bool overwriteChangedFiles();
index 9e58db0f482443c6a01ad42a8506e87110bf7c8f..e165c12e0009ec656e065f7f7aa7240773c96442 100644 (file)
@@ -301,23 +301,7 @@ bool RefactoringTool::applyAllReplacements(Rewriter &Rewrite) {
 }
 
 int RefactoringTool::saveRewrittenFiles(Rewriter &Rewrite) {
-  for (Rewriter::buffer_iterator I = Rewrite.buffer_begin(),
-                                 E = Rewrite.buffer_end();
-       I != E; ++I) {
-    // FIXME: This code is copied from the FixItRewriter.cpp - I think it should
-    // go into directly into Rewriter (there we also have the Diagnostics to
-    // handle the error cases better).
-    const FileEntry *Entry =
-        Rewrite.getSourceMgr().getFileEntryForID(I->first);
-    std::string ErrorInfo;
-    llvm::raw_fd_ostream FileStream(Entry->getName(), ErrorInfo,
-                                    llvm::sys::fs::F_Binary);
-    if (!ErrorInfo.empty())
-      return 1;
-    I->second.write(FileStream);
-    FileStream.flush();
-  }
-  return 0;
+  return Rewrite.overwriteChangedFiles() ? 1 : 0;
 }
 
 } // end namespace tooling