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