aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNate Begeman <natebegeman@mac.com>2008-04-17 18:06:57 +0000
committerNate Begeman <natebegeman@mac.com>2008-04-17 18:06:57 +0000
commit165b954fb22b4d920431f0938bc6919fa0272c51 (patch)
treef95baf3f1c5628c24a7b275757978e41105f26f5
parentff898cd0b0c9fcbad1033e0278b54a4cc7108d05 (diff)
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
-rw-r--r--Driver/TextDiagnosticPrinter.cpp26
-rw-r--r--Driver/TextDiagnosticPrinter.h4
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 <string>
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);