Refactor ASTConsumers to take a raw_ostream instead of a filename where
appropriate. There shouldn't be any significant functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72052 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/clang-cc/RewriteObjC.cpp b/tools/clang-cc/RewriteObjC.cpp
index 37dd524..b104747 100644
--- a/tools/clang-cc/RewriteObjC.cpp
+++ b/tools/clang-cc/RewriteObjC.cpp
@@ -93,7 +93,7 @@
bool IsHeader;
std::string InFileName;
- std::string OutFileName;
+ llvm::raw_ostream* OutFile;
std::string Preamble;
@@ -136,7 +136,7 @@
}
void HandleTopLevelSingleDecl(Decl *D);
void HandleDeclInMainFile(Decl *D);
- RewriteObjC(std::string inFile, std::string outFile,
+ RewriteObjC(std::string inFile, llvm::raw_ostream *OS,
Diagnostic &D, const LangOptions &LOpts);
~RewriteObjC() {}
@@ -416,12 +416,10 @@
return Ext == "h" || Ext == "hh" || Ext == "H";
}
-RewriteObjC::RewriteObjC(std::string inFile, std::string outFile,
+RewriteObjC::RewriteObjC(std::string inFile, llvm::raw_ostream* OS,
Diagnostic &D, const LangOptions &LOpts)
- : Diags(D), LangOpts(LOpts) {
+ : Diags(D), LangOpts(LOpts), InFileName(inFile), OutFile(OS) {
IsHeader = IsHeaderFile(inFile);
- InFileName = inFile;
- OutFileName = outFile;
RewriteFailedDiag = Diags.getCustomDiagID(Diagnostic::Warning,
"rewriting sub-expression within a macro (may not be correct)");
TryFinallyContainsReturnDiag = Diags.getCustomDiagID(Diagnostic::Warning,
@@ -430,10 +428,10 @@
}
ASTConsumer *clang::CreateCodeRewriterTest(const std::string& InFile,
- const std::string& OutFile,
+ llvm::raw_ostream* OS,
Diagnostic &Diags,
const LangOptions &LOpts) {
- return new RewriteObjC(InFile, OutFile, Diags, LOpts);
+ return new RewriteObjC(InFile, OS, Diags, LOpts);
}
void RewriteObjC::Initialize(ASTContext &context) {
@@ -4654,33 +4652,6 @@
if (Diags.hasErrorOccurred())
return;
-
- // Create the output file.
-
- llvm::OwningPtr<llvm::raw_ostream> OwnedStream;
- llvm::raw_ostream *OutFile;
- if (OutFileName == "-") {
- OutFile = &llvm::outs();
- } else if (!OutFileName.empty()) {
- std::string Err;
- OutFile = new llvm::raw_fd_ostream(OutFileName.c_str(),
- // set binary mode (critical for Windoze)
- true,
- Err);
- OwnedStream.reset(OutFile);
- } else if (InFileName == "-") {
- OutFile = &llvm::outs();
- } else {
- llvm::sys::Path Path(InFileName);
- Path.eraseSuffix();
- Path.appendSuffix("cpp");
- std::string Err;
- OutFile = new llvm::raw_fd_ostream(Path.toString().c_str(),
- // set binary mode (critical for Windoze)
- true,
- Err);
- OwnedStream.reset(OutFile);
- }
RewriteInclude();