1f4a2713aSLionel Sambuc //===--- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics ---------------===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc // This is a concrete diagnostic client, which buffers the diagnostic messages.
11f4a2713aSLionel Sambuc //
12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
13f4a2713aSLionel Sambuc
14f4a2713aSLionel Sambuc #include "clang/Frontend/TextDiagnosticBuffer.h"
15f4a2713aSLionel Sambuc #include "llvm/ADT/SmallString.h"
16f4a2713aSLionel Sambuc #include "llvm/Support/ErrorHandling.h"
17f4a2713aSLionel Sambuc using namespace clang;
18f4a2713aSLionel Sambuc
19f4a2713aSLionel Sambuc /// HandleDiagnostic - Store the errors, warnings, and notes that are
20f4a2713aSLionel Sambuc /// reported.
21f4a2713aSLionel Sambuc ///
HandleDiagnostic(DiagnosticsEngine::Level Level,const Diagnostic & Info)22f4a2713aSLionel Sambuc void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level,
23f4a2713aSLionel Sambuc const Diagnostic &Info) {
24f4a2713aSLionel Sambuc // Default implementation (Warnings/errors count).
25f4a2713aSLionel Sambuc DiagnosticConsumer::HandleDiagnostic(Level, Info);
26f4a2713aSLionel Sambuc
27f4a2713aSLionel Sambuc SmallString<100> Buf;
28f4a2713aSLionel Sambuc Info.FormatDiagnostic(Buf);
29f4a2713aSLionel Sambuc switch (Level) {
30f4a2713aSLionel Sambuc default: llvm_unreachable(
31f4a2713aSLionel Sambuc "Diagnostic not handled during diagnostic buffering!");
32f4a2713aSLionel Sambuc case DiagnosticsEngine::Note:
33f4a2713aSLionel Sambuc Notes.push_back(std::make_pair(Info.getLocation(), Buf.str()));
34f4a2713aSLionel Sambuc break;
35f4a2713aSLionel Sambuc case DiagnosticsEngine::Warning:
36f4a2713aSLionel Sambuc Warnings.push_back(std::make_pair(Info.getLocation(), Buf.str()));
37f4a2713aSLionel Sambuc break;
38*0a6a1f1dSLionel Sambuc case DiagnosticsEngine::Remark:
39*0a6a1f1dSLionel Sambuc Remarks.push_back(std::make_pair(Info.getLocation(), Buf.str()));
40*0a6a1f1dSLionel Sambuc break;
41f4a2713aSLionel Sambuc case DiagnosticsEngine::Error:
42f4a2713aSLionel Sambuc case DiagnosticsEngine::Fatal:
43f4a2713aSLionel Sambuc Errors.push_back(std::make_pair(Info.getLocation(), Buf.str()));
44f4a2713aSLionel Sambuc break;
45f4a2713aSLionel Sambuc }
46f4a2713aSLionel Sambuc }
47f4a2713aSLionel Sambuc
FlushDiagnostics(DiagnosticsEngine & Diags) const48f4a2713aSLionel Sambuc void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const {
49f4a2713aSLionel Sambuc // FIXME: Flush the diagnostics in order.
50f4a2713aSLionel Sambuc for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it)
51*0a6a1f1dSLionel Sambuc Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, "%0"))
52*0a6a1f1dSLionel Sambuc << it->second;
53f4a2713aSLionel Sambuc for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it)
54*0a6a1f1dSLionel Sambuc Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Warning, "%0"))
55*0a6a1f1dSLionel Sambuc << it->second;
56*0a6a1f1dSLionel Sambuc for (const_iterator it = remark_begin(), ie = remark_end(); it != ie; ++it)
57*0a6a1f1dSLionel Sambuc Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Remark, "%0"))
58*0a6a1f1dSLionel Sambuc << it->second;
59f4a2713aSLionel Sambuc for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it)
60*0a6a1f1dSLionel Sambuc Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Note, "%0"))
61*0a6a1f1dSLionel Sambuc << it->second;
62f4a2713aSLionel Sambuc }
63f4a2713aSLionel Sambuc
64