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" |
David Blaikie | 548f6c8 | 2011-09-23 05:57:42 +0000 | [diff] [blame] | 16 | #include "llvm/Support/ErrorHandling.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 17 | using namespace clang; |
| 18 | |
Douglas Gregor | 94b1dd2 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 19 | /// HandleDiagnostic - Store the errors, warnings, and notes that are |
| 20 | /// reported. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 21 | /// |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 22 | void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level, |
David Blaikie | 40847cf | 2011-09-26 01:18:08 +0000 | [diff] [blame^] | 23 | const Diagnostic &Info) { |
Argyrios Kyrtzidis | f2224d8 | 2010-11-18 20:06:46 +0000 | [diff] [blame] | 24 | // Default implementation (Warnings/errors count). |
David Blaikie | 78ad0b9 | 2011-09-25 23:39:51 +0000 | [diff] [blame] | 25 | DiagnosticConsumer::HandleDiagnostic(Level, Info); |
Argyrios Kyrtzidis | f2224d8 | 2010-11-18 20:06:46 +0000 | [diff] [blame] | 26 | |
Daniel Dunbar | 4cbe3b6 | 2009-11-29 20:58:39 +0000 | [diff] [blame] | 27 | llvm::SmallString<100> Buf; |
| 28 | Info.FormatDiagnostic(Buf); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 29 | switch (Level) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 30 | default: llvm_unreachable( |
| 31 | "Diagnostic not handled during diagnostic buffering!"); |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 32 | case DiagnosticsEngine::Note: |
Daniel Dunbar | 4cbe3b6 | 2009-11-29 20:58:39 +0000 | [diff] [blame] | 33 | Notes.push_back(std::make_pair(Info.getLocation(), Buf.str())); |
Douglas Gregor | 233f74b | 2008-09-11 02:46:36 +0000 | [diff] [blame] | 34 | break; |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 35 | case DiagnosticsEngine::Warning: |
Daniel Dunbar | 4cbe3b6 | 2009-11-29 20:58:39 +0000 | [diff] [blame] | 36 | Warnings.push_back(std::make_pair(Info.getLocation(), Buf.str())); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 37 | break; |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 38 | case DiagnosticsEngine::Error: |
| 39 | case DiagnosticsEngine::Fatal: |
Daniel Dunbar | 4cbe3b6 | 2009-11-29 20:58:39 +0000 | [diff] [blame] | 40 | Errors.push_back(std::make_pair(Info.getLocation(), Buf.str())); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 41 | break; |
| 42 | } |
| 43 | } |
Daniel Dunbar | c238955 | 2009-11-30 08:41:34 +0000 | [diff] [blame] | 44 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 45 | void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const { |
Daniel Dunbar | c238955 | 2009-11-30 08:41:34 +0000 | [diff] [blame] | 46 | // FIXME: Flush the diagnostics in order. |
| 47 | for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it) |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 48 | Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 49 | it->second.c_str())); |
Daniel Dunbar | c238955 | 2009-11-30 08:41:34 +0000 | [diff] [blame] | 50 | for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it) |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 51 | Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Warning, |
| 52 | it->second.c_str())); |
Daniel Dunbar | c238955 | 2009-11-30 08:41:34 +0000 | [diff] [blame] | 53 | for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it) |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 54 | Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Note, |
| 55 | it->second.c_str())); |
Daniel Dunbar | c238955 | 2009-11-30 08:41:34 +0000 | [diff] [blame] | 56 | } |