aboutsummaryrefslogtreecommitdiff
path: root/Driver/RewriteMacros.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-09-13 05:16:45 +0000
committerTed Kremenek <kremenek@apple.com>2008-09-13 05:16:45 +0000
commita95d3750441ac8ad03e36af8e6e74039c9a3109d (patch)
treeff6594ca38fba0ebad2d5a63583a909bdfb72a9f /Driver/RewriteMacros.cpp
parent635d04fe2a14fe79ac9b3802b66f6314ca8bc539 (diff)
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
Diffstat (limited to 'Driver/RewriteMacros.cpp')
-rw-r--r--Driver/RewriteMacros.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/Driver/RewriteMacros.cpp b/Driver/RewriteMacros.cpp
index 5500186f20..5106367839 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 @@ void clang::RewriteMacrosInInput(Preprocessor &PP,const std::string &InFileName,
}
// 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 @@ void clang::RewriteMacrosInInput(Preprocessor &PP,const std::string &InFileName,
} else {
fprintf(stderr, "No changes\n");
}
+ OutFile->flush();
}