/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Frontend/TextDiagnosticBuffer.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics -----------------===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This is a concrete diagnostic client, which buffers the diagnostic messages. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "clang/Frontend/TextDiagnosticBuffer.h" |
14 | | #include "clang/Basic/Diagnostic.h" |
15 | | #include "clang/Basic/LLVM.h" |
16 | | #include "llvm/ADT/SmallString.h" |
17 | | #include "llvm/Support/ErrorHandling.h" |
18 | | |
19 | | using namespace clang; |
20 | | |
21 | | /// HandleDiagnostic - Store the errors, warnings, and notes that are |
22 | | /// reported. |
23 | | void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level, |
24 | 400k | const Diagnostic &Info) { |
25 | | // Default implementation (Warnings/errors count). |
26 | 400k | DiagnosticConsumer::HandleDiagnostic(Level, Info); |
27 | | |
28 | 400k | SmallString<100> Buf; |
29 | 400k | Info.FormatDiagnostic(Buf); |
30 | 400k | switch (Level) { |
31 | 0 | default: llvm_unreachable( |
32 | 0 | "Diagnostic not handled during diagnostic buffering!"); |
33 | 126k | case DiagnosticsEngine::Note: |
34 | 126k | All.emplace_back(Level, Notes.size()); |
35 | 126k | Notes.emplace_back(Info.getLocation(), std::string(Buf.str())); |
36 | 126k | break; |
37 | 63.1k | case DiagnosticsEngine::Warning: |
38 | 63.1k | All.emplace_back(Level, Warnings.size()); |
39 | 63.1k | Warnings.emplace_back(Info.getLocation(), std::string(Buf.str())); |
40 | 63.1k | break; |
41 | 114 | case DiagnosticsEngine::Remark: |
42 | 114 | All.emplace_back(Level, Remarks.size()); |
43 | 114 | Remarks.emplace_back(Info.getLocation(), std::string(Buf.str())); |
44 | 114 | break; |
45 | 210k | case DiagnosticsEngine::Error: |
46 | 210k | case DiagnosticsEngine::Fatal: |
47 | 210k | All.emplace_back(Level, Errors.size()); |
48 | 210k | Errors.emplace_back(Info.getLocation(), std::string(Buf.str())); |
49 | 210k | break; |
50 | 400k | } |
51 | 400k | } |
52 | | |
53 | 41.6k | void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const { |
54 | 41.6k | for (const auto &I : All) { |
55 | 245 | auto Diag = Diags.Report(Diags.getCustomDiagID(I.first, "%0")); |
56 | 245 | switch (I.first) { |
57 | 0 | default: llvm_unreachable( |
58 | 0 | "Diagnostic not handled during diagnostic flushing!"); |
59 | 94 | case DiagnosticsEngine::Note: |
60 | 94 | Diag << Notes[I.second].second; |
61 | 94 | break; |
62 | 16 | case DiagnosticsEngine::Warning: |
63 | 16 | Diag << Warnings[I.second].second; |
64 | 16 | break; |
65 | 2 | case DiagnosticsEngine::Remark: |
66 | 2 | Diag << Remarks[I.second].second; |
67 | 2 | break; |
68 | 133 | case DiagnosticsEngine::Error: |
69 | 133 | case DiagnosticsEngine::Fatal: |
70 | 133 | Diag << Errors[I.second].second; |
71 | 133 | break; |
72 | 245 | } |
73 | 245 | } |
74 | 41.6k | } |