From 165b954fb22b4d920431f0938bc6919fa0272c51 Mon Sep 17 00:00:00 2001 From: Nate Begeman Date: Thu, 17 Apr 2008 18:06:57 +0000 Subject: [PATCH] Allow redirecting text diagnostic printer output to any llvm::OStream, rather than hard coding llvm::cerr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49860 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/TextDiagnosticPrinter.cpp | 26 ++++++++++++-------------- Driver/TextDiagnosticPrinter.h | 4 +++- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Driver/TextDiagnosticPrinter.cpp b/Driver/TextDiagnosticPrinter.cpp index 012c3abf94..5d06ebea2d 100644 --- a/Driver/TextDiagnosticPrinter.cpp +++ b/Driver/TextDiagnosticPrinter.cpp @@ -18,7 +18,6 @@ #include "clang/Lex/Lexer.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/Streams.h" #include using namespace clang; @@ -40,8 +39,8 @@ PrintIncludeStack(FullSourceLoc Pos) { PrintIncludeStack(Pos.getIncludeLoc()); unsigned LineNo = Pos.getLineNumber(); - llvm::cerr << "In file included from " << Pos.getSourceName() - << ":" << LineNo << ":\n"; + OS << "In file included from " << Pos.getSourceName() + << ":" << LineNo << ":\n"; } /// HighlightRange - Given a SourceRange and a line number, highlight (with ~'s) @@ -141,23 +140,22 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic &Diags, *LineEnd != '\n' && *LineEnd != '\r') ++LineEnd; - llvm::cerr << Buffer->getBufferIdentifier() - << ":" << LineNo << ":"; + OS << Buffer->getBufferIdentifier() << ":" << LineNo << ":"; if (ColNo && !NoShowColumn) - llvm::cerr << ColNo << ":"; - llvm::cerr << " "; + OS << ColNo << ":"; + OS << " "; } switch (Level) { default: assert(0 && "Unknown diagnostic type!"); - case Diagnostic::Note: llvm::cerr << "note: "; break; - case Diagnostic::Warning: llvm::cerr << "warning: "; break; - case Diagnostic::Error: llvm::cerr << "error: "; break; - case Diagnostic::Fatal: llvm::cerr << "fatal error: "; break; + case Diagnostic::Note: OS << "note: "; break; + case Diagnostic::Warning: OS << "warning: "; break; + case Diagnostic::Error: OS << "error: "; break; + case Diagnostic::Fatal: OS << "fatal error: "; break; break; } - llvm::cerr << FormatDiagnostic(Diags, Level, ID, Strs, NumStrs) << "\n"; + OS << FormatDiagnostic(Diags, Level, ID, Strs, NumStrs) << "\n"; if (!NoCaretDiagnostics && Pos.isValid() && ((LastLoc != Pos) || Ranges)) { // Cache the LastLoc, it allows us to omit duplicate source/caret spewage. @@ -205,7 +203,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic &Diags, CaratLine.erase(CaratLine.end()-1); // Emit what we have computed. - llvm::cerr << SourceLine << "\n"; - llvm::cerr << CaratLine << "\n"; + OS << SourceLine << "\n"; + OS << CaratLine << "\n"; } } diff --git a/Driver/TextDiagnosticPrinter.h b/Driver/TextDiagnosticPrinter.h index e9c2e3a2e5..633f29edbe 100644 --- a/Driver/TextDiagnosticPrinter.h +++ b/Driver/TextDiagnosticPrinter.h @@ -17,6 +17,7 @@ #include "TextDiagnostics.h" #include "clang/Basic/SourceLocation.h" +#include "llvm/Support/Streams.h" namespace clang { class SourceManager; @@ -24,8 +25,9 @@ class SourceManager; class TextDiagnosticPrinter : public TextDiagnostics { FullSourceLoc LastWarningLoc; FullSourceLoc LastLoc; + llvm::OStream OS; public: - TextDiagnosticPrinter() {} + TextDiagnosticPrinter(llvm::OStream &os = llvm::cerr) : OS(os) {} void PrintIncludeStack(FullSourceLoc Pos); -- 2.40.0