[cfe-commits] r49860 - in /cfe/trunk/Driver: TextDiagnosticPrinter.cpp TextDiagnosticPrinter.h
Nate Begeman
natebegeman at mac.com
Thu Apr 17 11:06:57 PDT 2008
Author: sampo
Date: Thu Apr 17 13:06:57 2008
New Revision: 49860
URL: http://llvm.org/viewvc/llvm-project?rev=49860&view=rev
Log:
Allow redirecting text diagnostic printer output to any llvm::OStream, rather
than hard coding llvm::cerr.
Modified:
cfe/trunk/Driver/TextDiagnosticPrinter.cpp
cfe/trunk/Driver/TextDiagnosticPrinter.h
Modified: cfe/trunk/Driver/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticPrinter.cpp?rev=49860&r1=49859&r2=49860&view=diff
==============================================================================
--- cfe/trunk/Driver/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/Driver/TextDiagnosticPrinter.cpp Thu Apr 17 13:06:57 2008
@@ -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(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 @@
*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 @@
CaratLine.erase(CaratLine.end()-1);
// Emit what we have computed.
- llvm::cerr << SourceLine << "\n";
- llvm::cerr << CaratLine << "\n";
+ OS << SourceLine << "\n";
+ OS << CaratLine << "\n";
}
}
Modified: cfe/trunk/Driver/TextDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticPrinter.h?rev=49860&r1=49859&r2=49860&view=diff
==============================================================================
--- cfe/trunk/Driver/TextDiagnosticPrinter.h (original)
+++ cfe/trunk/Driver/TextDiagnosticPrinter.h Thu Apr 17 13:06:57 2008
@@ -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 TextDiagnosticPrinter : public TextDiagnostics {
FullSourceLoc LastWarningLoc;
FullSourceLoc LastLoc;
+ llvm::OStream OS;
public:
- TextDiagnosticPrinter() {}
+ TextDiagnosticPrinter(llvm::OStream &os = llvm::cerr) : OS(os) {}
void PrintIncludeStack(FullSourceLoc Pos);
More information about the cfe-commits
mailing list