Revert "Use Rewriter::overwriteChangedFiles() directly"
This wasn't ready for prime time yet, seems to break tools-extra.
This reverts commit r193590.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193592 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Tooling/Refactoring.cpp b/lib/Tooling/Refactoring.cpp
index fa35a74..9e58db0 100644
--- a/lib/Tooling/Refactoring.cpp
+++ b/lib/Tooling/Refactoring.cpp
@@ -301,7 +301,23 @@
}
int RefactoringTool::saveRewrittenFiles(Rewriter &Rewrite) {
- return Rewrite.overwriteChangedFiles() ? 0 : 1;
+ 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;
}
} // end namespace tooling