r193594 - Use Rewriter::overwriteChangedFiles() directly

Alp Toker alp at nuanti.com
Tue Oct 29 01:32:42 PDT 2013


Author: alp
Date: Tue Oct 29 03:32:41 2013
New Revision: 193594

URL: http://llvm.org/viewvc/llvm-project?rev=193594&view=rev
Log:
Use Rewriter::overwriteChangedFiles() directly

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.

Modified:
    cfe/trunk/include/clang/Rewrite/Core/Rewriter.h
    cfe/trunk/lib/Tooling/Refactoring.cpp

Modified: cfe/trunk/include/clang/Rewrite/Core/Rewriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/Core/Rewriter.h?rev=193594&r1=193593&r2=193594&view=diff
==============================================================================
--- cfe/trunk/include/clang/Rewrite/Core/Rewriter.h (original)
+++ cfe/trunk/include/clang/Rewrite/Core/Rewriter.h Tue Oct 29 03:32:41 2013
@@ -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();

Modified: cfe/trunk/lib/Tooling/Refactoring.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring.cpp?rev=193594&r1=193593&r2=193594&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/Refactoring.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring.cpp Tue Oct 29 03:32:41 2013
@@ -301,23 +301,7 @@ bool RefactoringTool::applyAllReplacemen
 }
 
 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





More information about the cfe-commits mailing list