]> granicus.if.org Git - clang/commitdiff
Allow redirecting text diagnostic printer output to any llvm::OStream, rather
authorNate Begeman <natebegeman@mac.com>
Thu, 17 Apr 2008 18:06:57 +0000 (18:06 +0000)
committerNate Begeman <natebegeman@mac.com>
Thu, 17 Apr 2008 18:06:57 +0000 (18:06 +0000)
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
Driver/TextDiagnosticPrinter.h

index 012c3abf946605f6e66600506fc570a77828a2e4..5d06ebea2d14c2fb8948660f283805f24d9d63c8 100644 (file)
@@ -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";
   }
 }
index e9c2e3a2e5ef3ccdd97b1bc8e3c25a12ba7b6f5a..633f29edbefefb9edb5be0883d15eadb51ca4481 100644 (file)
@@ -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);