From: Chris Lattner Date: Wed, 19 Nov 2008 06:56:25 +0000 (+0000) Subject: switch TextDiagnosticPrinter to raw_ostream. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a03a5b5a84989b1cbd3917b967e8fe64f99cfa80;p=clang switch TextDiagnosticPrinter to raw_ostream. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59597 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 4314180c45..ead873447b 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -1443,7 +1443,8 @@ int main(int argc, char **argv) { if (!VerifyDiagnostics) { // Print diagnostics to stderr by default. - TextDiagClient = new TextDiagnosticPrinter(!NoShowColumn, + TextDiagClient = new TextDiagnosticPrinter(llvm::errs(), + !NoShowColumn, !NoCaretDiagnostics); } else { // When checking diagnostics, just buffer them up. diff --git a/include/clang/Driver/TextDiagnosticPrinter.h b/include/clang/Driver/TextDiagnosticPrinter.h index e5ef9fca82..e6d570c5e3 100644 --- a/include/clang/Driver/TextDiagnosticPrinter.h +++ b/include/clang/Driver/TextDiagnosticPrinter.h @@ -17,7 +17,10 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceLocation.h" -#include "llvm/Support/Streams.h" + +namespace llvm { + class raw_ostream; +} namespace clang { class SourceManager; @@ -25,12 +28,12 @@ class SourceManager; class TextDiagnosticPrinter : public DiagnosticClient { FullSourceLoc LastWarningLoc; FullSourceLoc LastLoc; - llvm::OStream OS; + llvm::raw_ostream &OS; bool ShowColumn; bool CaretDiagnostics; public: - TextDiagnosticPrinter(bool showColumn = true, bool caretDiagnistics = true, - llvm::OStream &os = llvm::cerr) + TextDiagnosticPrinter(llvm::raw_ostream &os, bool showColumn = true, + bool caretDiagnistics = true) : OS(os), ShowColumn(showColumn), CaretDiagnostics(caretDiagnistics) {} void PrintIncludeStack(FullSourceLoc Pos); diff --git a/lib/Driver/TextDiagnosticPrinter.cpp b/lib/Driver/TextDiagnosticPrinter.cpp index cfbe8a7f92..b4be9307ea 100644 --- a/lib/Driver/TextDiagnosticPrinter.cpp +++ b/lib/Driver/TextDiagnosticPrinter.cpp @@ -14,6 +14,7 @@ #include "clang/Driver/TextDiagnosticPrinter.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/Lexer.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/ADT/SmallString.h" using namespace clang; @@ -29,7 +30,7 @@ PrintIncludeStack(FullSourceLoc Pos) { unsigned LineNo = Pos.getLineNumber(); OS << "In file included from " << Pos.getSourceName() - << ":" << LineNo << ":\n"; + << ':' << LineNo << ":\n"; } /// HighlightRange - Given a SourceRange and a line number, highlight (with ~'s) @@ -127,10 +128,10 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, *LineEnd != '\n' && *LineEnd != '\r') ++LineEnd; - OS << Buffer->getBufferIdentifier() << ":" << LineNo << ":"; + OS << Buffer->getBufferIdentifier() << ':' << LineNo << ':'; if (ColNo && ShowColumn) - OS << ColNo << ":"; - OS << " "; + OS << ColNo << ':'; + OS << ' '; } switch (Level) { @@ -193,7 +194,9 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, CaretLine.erase(CaretLine.end()-1); // Emit what we have computed. - OS << SourceLine << "\n"; - OS << CaretLine << "\n"; + OS << SourceLine << '\n'; + OS << CaretLine << '\n'; } + + OS.flush(); }