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