Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics ---------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This is a concrete diagnostic client, which buffers the diagnostic messages. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Daniel Dunbar | e1bd4e6 | 2009-03-02 06:16:29 +0000 | [diff] [blame] | 14 | #include "clang/Frontend/TextDiagnosticBuffer.h" |
Chris Lattner | f4c8396 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/SmallString.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | using namespace clang; |
| 17 | |
Douglas Gregor | 94b1dd2 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 18 | /// HandleDiagnostic - Store the errors, warnings, and notes that are |
| 19 | /// reported. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 20 | /// |
Chris Lattner | 0a14eee | 2008-11-18 07:04:44 +0000 | [diff] [blame] | 21 | void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic::Level Level, |
| 22 | const DiagnosticInfo &Info) { |
Daniel Dunbar | 4cbe3b6 | 2009-11-29 20:58:39 +0000 | [diff] [blame] | 23 | llvm::SmallString<100> Buf; |
| 24 | Info.FormatDiagnostic(Buf); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 25 | switch (Level) { |
| 26 | default: assert(0 && "Diagnostic not handled during diagnostic buffering!"); |
Douglas Gregor | 233f74b | 2008-09-11 02:46:36 +0000 | [diff] [blame] | 27 | case Diagnostic::Note: |
Daniel Dunbar | 4cbe3b6 | 2009-11-29 20:58:39 +0000 | [diff] [blame] | 28 | Notes.push_back(std::make_pair(Info.getLocation(), Buf.str())); |
Douglas Gregor | 233f74b | 2008-09-11 02:46:36 +0000 | [diff] [blame] | 29 | break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 30 | case Diagnostic::Warning: |
Daniel Dunbar | 4cbe3b6 | 2009-11-29 20:58:39 +0000 | [diff] [blame] | 31 | Warnings.push_back(std::make_pair(Info.getLocation(), Buf.str())); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 32 | break; |
| 33 | case Diagnostic::Error: |
Ben Laurie | 64ea69f | 2009-02-17 17:32:22 +0000 | [diff] [blame] | 34 | case Diagnostic::Fatal: |
Daniel Dunbar | 4cbe3b6 | 2009-11-29 20:58:39 +0000 | [diff] [blame] | 35 | Errors.push_back(std::make_pair(Info.getLocation(), Buf.str())); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 36 | break; |
| 37 | } |
| 38 | } |
Daniel Dunbar | c238955 | 2009-11-30 08:41:34 +0000 | [diff] [blame^] | 39 | |
| 40 | void TextDiagnosticBuffer::FlushDiagnostics(Diagnostic &Diags) const { |
| 41 | // FIXME: Flush the diagnostics in order. |
| 42 | for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it) |
| 43 | Diags.Report(Diags.getCustomDiagID(Diagnostic::Error, it->second.c_str())); |
| 44 | for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it) |
| 45 | Diags.Report(Diags.getCustomDiagID(Diagnostic::Warning,it->second.c_str())); |
| 46 | for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it) |
| 47 | Diags.Report(Diags.getCustomDiagID(Diagnostic::Note, it->second.c_str())); |
| 48 | } |