Daniel Dunbar | 9df2349 | 2011-04-07 18:31:10 +0000 | [diff] [blame^] | 1 | //===--- LogDiagnosticPrinter.cpp - Log Diagnostic Printer ----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "clang/Frontend/LogDiagnosticPrinter.h" |
| 11 | #include "llvm/ADT/SmallString.h" |
| 12 | #include "llvm/Support/raw_ostream.h" |
| 13 | using namespace clang; |
| 14 | |
| 15 | LogDiagnosticPrinter::LogDiagnosticPrinter(llvm::raw_ostream &os, |
| 16 | const DiagnosticOptions &diags, |
| 17 | bool _OwnsOutputStream) |
| 18 | : OS(os), LangOpts(0), DiagOpts(&diags), |
| 19 | OwnsOutputStream(_OwnsOutputStream) { |
| 20 | } |
| 21 | |
| 22 | LogDiagnosticPrinter::~LogDiagnosticPrinter() { |
| 23 | if (OwnsOutputStream) |
| 24 | delete &OS; |
| 25 | } |
| 26 | |
| 27 | void LogDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, |
| 28 | const DiagnosticInfo &Info) { |
| 29 | // Default implementation (Warnings/errors count). |
| 30 | DiagnosticClient::HandleDiagnostic(Level, Info); |
| 31 | |
| 32 | // Write to a temporary string to ensure atomic write of diagnostic object. |
| 33 | llvm::SmallString<512> Msg; |
| 34 | llvm::raw_svector_ostream OS(Msg); |
| 35 | |
| 36 | OS << "hello!\n"; |
| 37 | |
| 38 | this->OS << OS.str(); |
| 39 | } |