[cfe-commits] r86823 - in /cfe/trunk: include/clang/Frontend/TextDiagnosticPrinter.h lib/Frontend/TextDiagnosticPrinter.cpp tools/clang-cc/clang-cc.cpp
Daniel Dunbar
daniel at zuster.org
Wed Nov 11 01:38:27 PST 2009
Author: ddunbar
Date: Wed Nov 11 03:38:24 2009
New Revision: 86823
URL: http://llvm.org/viewvc/llvm-project?rev=86823&view=rev
Log:
Allow TextDiagnosticPrinter to have optional ownership of its output stream.
Modified:
cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h
cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
cfe/trunk/tools/clang-cc/clang-cc.cpp
Modified: cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h?rev=86823&r1=86822&r2=86823&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h (original)
+++ cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h Wed Nov 11 03:38:24 2009
@@ -34,10 +34,13 @@
SourceLocation LastWarningLoc;
FullSourceLoc LastLoc;
- bool LastCaretDiagnosticWasNote;
+ unsigned LastCaretDiagnosticWasNote : 1;
+ unsigned OwnsOutputStream : 1;
public:
- TextDiagnosticPrinter(llvm::raw_ostream &os, const DiagnosticOptions &diags);
+ TextDiagnosticPrinter(llvm::raw_ostream &os, const DiagnosticOptions &diags,
+ bool OwnsOutputStream = false);
+ virtual ~TextDiagnosticPrinter();
void BeginSourceFile(const LangOptions &LO) {
LangOpts = &LO;
Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=86823&r1=86822&r2=86823&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Wed Nov 11 03:38:24 2009
@@ -39,9 +39,16 @@
const unsigned WordWrapIndentation = 6;
TextDiagnosticPrinter::TextDiagnosticPrinter(llvm::raw_ostream &os,
- const DiagnosticOptions &diags)
+ const DiagnosticOptions &diags,
+ bool _OwnsOutputStream)
: OS(os), LangOpts(0), DiagOpts(&diags),
- LastCaretDiagnosticWasNote(false) {
+ LastCaretDiagnosticWasNote(0),
+ OwnsOutputStream(_OwnsOutputStream) {
+}
+
+TextDiagnosticPrinter::~TextDiagnosticPrinter() {
+ if (OwnsOutputStream)
+ delete &OS;
}
void TextDiagnosticPrinter::
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=86823&r1=86822&r2=86823&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Wed Nov 11 03:38:24 2009
@@ -517,31 +517,27 @@
llvm::cl::value_desc("filename"),
llvm::cl::desc("output a dump of some build information to a file"));
-static llvm::raw_ostream *BuildLogFile = 0;
-
static void SetUpBuildDumpLog(const DiagnosticOptions &DiagOpts,
unsigned argc, char **argv,
llvm::OwningPtr<DiagnosticClient> &DiagClient) {
std::string ErrorInfo;
- BuildLogFile = new llvm::raw_fd_ostream(DumpBuildInformation.c_str(),
- ErrorInfo);
-
+ llvm::raw_ostream *OS = new llvm::raw_fd_ostream(DumpBuildInformation.c_str(),
+ ErrorInfo);
if (!ErrorInfo.empty()) {
llvm::errs() << "error opening -dump-build-information file '"
<< DumpBuildInformation << "', option ignored!\n";
- delete BuildLogFile;
- BuildLogFile = 0;
- DumpBuildInformation = "";
+ delete OS;
return;
}
- (*BuildLogFile) << "clang-cc command line arguments: ";
+ (*OS) << "clang-cc command line arguments: ";
for (unsigned i = 0; i != argc; ++i)
- (*BuildLogFile) << argv[i] << ' ';
- (*BuildLogFile) << '\n';
+ (*OS) << argv[i] << ' ';
+ (*OS) << '\n';
// Chain in a diagnostic client which will log the diagnostics.
- DiagnosticClient *Logger = new TextDiagnosticPrinter(*BuildLogFile, DiagOpts);
+ DiagnosticClient *Logger =
+ new TextDiagnosticPrinter(*OS, DiagOpts, /*OwnsOutputStream=*/true);
DiagClient.reset(new ChainedDiagnosticClient(DiagClient.take(), Logger));
}
@@ -1316,7 +1312,6 @@
}
delete ClangFrontendTimer;
- delete BuildLogFile;
// If verifying diagnostics and we reached here, all is well.
if (VerifyDiagnostics)
More information about the cfe-commits
mailing list