Bill Wendling | 469211a | 2007-06-27 03:19:45 +0000 | [diff] [blame] | 1 | //===--- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics ---------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 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. |
Bill Wendling | 469211a | 2007-06-27 03:19:45 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This is a concrete diagnostic client, which buffers the diagnostic messages. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Daniel Dunbar | 51adf58 | 2009-03-02 06:16:29 +0000 | [diff] [blame] | 14 | #include "clang/Frontend/TextDiagnosticBuffer.h" |
Chris Lattner | 23be067 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/SmallString.h" |
David Blaikie | 7900020 | 2011-09-23 05:57:42 +0000 | [diff] [blame] | 16 | #include "llvm/Support/ErrorHandling.h" |
Bill Wendling | 469211a | 2007-06-27 03:19:45 +0000 | [diff] [blame] | 17 | using namespace clang; |
| 18 | |
Douglas Gregor | 39c16d4 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 19 | /// HandleDiagnostic - Store the errors, warnings, and notes that are |
| 20 | /// reported. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 21 | /// |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 22 | void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level, |
David Blaikie | b578432 | 2011-09-26 01:18:08 +0000 | [diff] [blame] | 23 | const Diagnostic &Info) { |
Argyrios Kyrtzidis | c79346a | 2010-11-18 20:06:46 +0000 | [diff] [blame] | 24 | // Default implementation (Warnings/errors count). |
David Blaikie | e2eefae | 2011-09-25 23:39:51 +0000 | [diff] [blame] | 25 | DiagnosticConsumer::HandleDiagnostic(Level, Info); |
Argyrios Kyrtzidis | c79346a | 2010-11-18 20:06:46 +0000 | [diff] [blame] | 26 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 27 | SmallString<100> Buf; |
Daniel Dunbar | ecd0444 | 2009-11-29 20:58:39 +0000 | [diff] [blame] | 28 | Info.FormatDiagnostic(Buf); |
Bill Wendling | 469211a | 2007-06-27 03:19:45 +0000 | [diff] [blame] | 29 | switch (Level) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 30 | default: llvm_unreachable( |
| 31 | "Diagnostic not handled during diagnostic buffering!"); |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 32 | case DiagnosticsEngine::Note: |
Hal Finkel | cc15219 | 2017-12-16 01:40:19 +0000 | [diff] [blame^] | 33 | All.emplace_back(Level, Notes.size()); |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 34 | Notes.emplace_back(Info.getLocation(), Buf.str()); |
Douglas Gregor | e972aa4 | 2008-09-11 02:46:36 +0000 | [diff] [blame] | 35 | break; |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 36 | case DiagnosticsEngine::Warning: |
Hal Finkel | cc15219 | 2017-12-16 01:40:19 +0000 | [diff] [blame^] | 37 | All.emplace_back(Level, Warnings.size()); |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 38 | Warnings.emplace_back(Info.getLocation(), Buf.str()); |
Bill Wendling | 469211a | 2007-06-27 03:19:45 +0000 | [diff] [blame] | 39 | break; |
Tobias Grosser | 86a8567 | 2014-05-01 14:06:01 +0000 | [diff] [blame] | 40 | case DiagnosticsEngine::Remark: |
Hal Finkel | cc15219 | 2017-12-16 01:40:19 +0000 | [diff] [blame^] | 41 | All.emplace_back(Level, Remarks.size()); |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 42 | Remarks.emplace_back(Info.getLocation(), Buf.str()); |
Tobias Grosser | 86a8567 | 2014-05-01 14:06:01 +0000 | [diff] [blame] | 43 | break; |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 44 | case DiagnosticsEngine::Error: |
| 45 | case DiagnosticsEngine::Fatal: |
Hal Finkel | cc15219 | 2017-12-16 01:40:19 +0000 | [diff] [blame^] | 46 | All.emplace_back(Level, Errors.size()); |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 47 | Errors.emplace_back(Info.getLocation(), Buf.str()); |
Bill Wendling | 469211a | 2007-06-27 03:19:45 +0000 | [diff] [blame] | 48 | break; |
| 49 | } |
| 50 | } |
Daniel Dunbar | 05762b1 | 2009-11-30 08:41:34 +0000 | [diff] [blame] | 51 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 52 | void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const { |
Hal Finkel | cc15219 | 2017-12-16 01:40:19 +0000 | [diff] [blame^] | 53 | for (auto it = All.begin(), ie = All.end(); it != ie; ++it) { |
| 54 | auto Diag = Diags.Report(Diags.getCustomDiagID(it->first, "%0")); |
| 55 | switch (it->first) { |
| 56 | default: llvm_unreachable( |
| 57 | "Diagnostic not handled during diagnostic flushing!"); |
| 58 | case DiagnosticsEngine::Note: |
| 59 | Diag << Notes[it->second].second; |
| 60 | break; |
| 61 | case DiagnosticsEngine::Warning: |
| 62 | Diag << Warnings[it->second].second; |
| 63 | break; |
| 64 | case DiagnosticsEngine::Remark: |
| 65 | Diag << Remarks[it->second].second; |
| 66 | break; |
| 67 | case DiagnosticsEngine::Error: |
| 68 | case DiagnosticsEngine::Fatal: |
| 69 | Diag << Errors[it->second].second; |
| 70 | break; |
| 71 | } |
| 72 | } |
Daniel Dunbar | 05762b1 | 2009-11-30 08:41:34 +0000 | [diff] [blame] | 73 | } |
Douglas Gregor | d0e9e3a | 2011-09-29 00:38:00 +0000 | [diff] [blame] | 74 | |