From: Alp Toker Date: Tue, 29 Oct 2013 08:32:41 +0000 (+0000) Subject: Use Rewriter::overwriteChangedFiles() directly X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6bf97fb15c09db9a0238ccb73be2dbf9cd77a7ee;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193594 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Rewrite/Core/Rewriter.h b/include/clang/Rewrite/Core/Rewriter.h index 1c147f3c29..f791d5528c 100644 --- a/include/clang/Rewrite/Core/Rewriter.h +++ b/include/clang/Rewrite/Core/Rewriter.h @@ -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(); diff --git a/lib/Tooling/Refactoring.cpp b/lib/Tooling/Refactoring.cpp index 9e58db0f48..e165c12e00 100644 --- a/lib/Tooling/Refactoring.cpp +++ b/lib/Tooling/Refactoring.cpp @@ -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