1 //===- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This is a concrete diagnostic client, which buffers the diagnostic messages.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Frontend/TextDiagnosticBuffer.h"
15 #include "clang/Basic/Diagnostic.h"
16 #include "clang/Basic/LLVM.h"
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/Support/ErrorHandling.h"
20 using namespace clang;
22 /// HandleDiagnostic - Store the errors, warnings, and notes that are
24 void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level,
25 const Diagnostic &Info) {
26 // Default implementation (Warnings/errors count).
27 DiagnosticConsumer::HandleDiagnostic(Level, Info);
30 Info.FormatDiagnostic(Buf);
32 default: llvm_unreachable(
33 "Diagnostic not handled during diagnostic buffering!");
34 case DiagnosticsEngine::Note:
35 All.emplace_back(Level, Notes.size());
36 Notes.emplace_back(Info.getLocation(), Buf.str());
38 case DiagnosticsEngine::Warning:
39 All.emplace_back(Level, Warnings.size());
40 Warnings.emplace_back(Info.getLocation(), Buf.str());
42 case DiagnosticsEngine::Remark:
43 All.emplace_back(Level, Remarks.size());
44 Remarks.emplace_back(Info.getLocation(), Buf.str());
46 case DiagnosticsEngine::Error:
47 case DiagnosticsEngine::Fatal:
48 All.emplace_back(Level, Errors.size());
49 Errors.emplace_back(Info.getLocation(), Buf.str());
54 void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const {
55 for (const auto &I : All) {
56 auto Diag = Diags.Report(Diags.getCustomDiagID(I.first, "%0"));
58 default: llvm_unreachable(
59 "Diagnostic not handled during diagnostic flushing!");
60 case DiagnosticsEngine::Note:
61 Diag << Notes[I.second].second;
63 case DiagnosticsEngine::Warning:
64 Diag << Warnings[I.second].second;
66 case DiagnosticsEngine::Remark:
67 Diag << Remarks[I.second].second;
69 case DiagnosticsEngine::Error:
70 case DiagnosticsEngine::Fatal:
71 Diag << Errors[I.second].second;