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 "llvm/ADT/SmallString.h"
16 #include "llvm/Support/ErrorHandling.h"
17 using namespace clang;
19 /// HandleDiagnostic - Store the errors, warnings, and notes that are
22 void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level,
23 const Diagnostic &Info) {
24 // Default implementation (Warnings/errors count).
25 DiagnosticConsumer::HandleDiagnostic(Level, Info);
28 Info.FormatDiagnostic(Buf);
30 default: llvm_unreachable(
31 "Diagnostic not handled during diagnostic buffering!");
32 case DiagnosticsEngine::Note:
33 All.emplace_back(Level, Notes.size());
34 Notes.emplace_back(Info.getLocation(), Buf.str());
36 case DiagnosticsEngine::Warning:
37 All.emplace_back(Level, Warnings.size());
38 Warnings.emplace_back(Info.getLocation(), Buf.str());
40 case DiagnosticsEngine::Remark:
41 All.emplace_back(Level, Remarks.size());
42 Remarks.emplace_back(Info.getLocation(), Buf.str());
44 case DiagnosticsEngine::Error:
45 case DiagnosticsEngine::Fatal:
46 All.emplace_back(Level, Errors.size());
47 Errors.emplace_back(Info.getLocation(), Buf.str());
52 void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const {
53 for (auto it = All.begin(), ie = All.end(); it != ie; ++it) {
54 auto Diag = Diags.Report(Diags.getCustomDiagID(it->first, "%0"));
56 default: llvm_unreachable(
57 "Diagnostic not handled during diagnostic flushing!");
58 case DiagnosticsEngine::Note:
59 Diag << Notes[it->second].second;
61 case DiagnosticsEngine::Warning:
62 Diag << Warnings[it->second].second;
64 case DiagnosticsEngine::Remark:
65 Diag << Remarks[it->second].second;
67 case DiagnosticsEngine::Error:
68 case DiagnosticsEngine::Fatal:
69 Diag << Errors[it->second].second;