Patch by Csaba Hruska!
"Here is a patch what replaces std::ostream with llvm::raw_ostream. This patch
covers the AST library, but ignores Analysis lib."
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56185 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/RewriteMacros.cpp b/Driver/RewriteMacros.cpp
index 5500186..5106367 100644
--- a/Driver/RewriteMacros.cpp
+++ b/Driver/RewriteMacros.cpp
@@ -17,8 +17,9 @@
#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Path.h"
-#include <fstream>
+#include "llvm/ADT/OwningPtr.h"
using namespace clang;
/// isSameToken - Return true if the two specified tokens start have the same
@@ -205,20 +206,23 @@
}
// Create the output file.
- std::ostream *OutFile;
+ llvm::OwningPtr<llvm::raw_ostream> OwnedStream;
+ llvm::raw_ostream *OutFile;
if (OutFileName == "-") {
- OutFile = llvm::cout.stream();
+ OutFile = &llvm::outs();
} else if (!OutFileName.empty()) {
- OutFile = new std::ofstream(OutFileName.c_str(),
- std::ios_base::binary|std::ios_base::out);
+ std::string Err;
+ OutFile = new llvm::raw_fd_ostream(OutFileName.c_str(), Err);
+ OwnedStream.reset(OutFile);
} else if (InFileName == "-") {
- OutFile = llvm::cout.stream();
+ OutFile = &llvm::outs();
} else {
llvm::sys::Path Path(InFileName);
Path.eraseSuffix();
Path.appendSuffix("cpp");
- OutFile = new std::ofstream(Path.toString().c_str(),
- std::ios_base::binary|std::ios_base::out);
+ std::string Err;
+ OutFile = new llvm::raw_fd_ostream(Path.toString().c_str(), Err);
+ OwnedStream.reset(OutFile);
}
// Get the buffer corresponding to MainFileID. If we haven't changed it, then
@@ -230,4 +234,5 @@
} else {
fprintf(stderr, "No changes\n");
}
+ OutFile->flush();
}