blob: fdf2ec8ccf5d016b64b4d15c4536ac08d134e3ee [file] [log] [blame]
Shih-wei Liaof8fd82b2010-02-10 11:10:31 -08001//===--- 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"
16using namespace clang;
17
18/// HandleDiagnostic - Store the errors, warnings, and notes that are
19/// reported.
20///
21void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic::Level Level,
22 const DiagnosticInfo &Info) {
23 llvm::SmallString<100> Buf;
24 Info.FormatDiagnostic(Buf);
25 switch (Level) {
26 default: assert(0 && "Diagnostic not handled during diagnostic buffering!");
27 case Diagnostic::Note:
28 Notes.push_back(std::make_pair(Info.getLocation(), Buf.str()));
29 break;
30 case Diagnostic::Warning:
31 Warnings.push_back(std::make_pair(Info.getLocation(), Buf.str()));
32 break;
33 case Diagnostic::Error:
34 case Diagnostic::Fatal:
35 Errors.push_back(std::make_pair(Info.getLocation(), Buf.str()));
36 break;
37 }
38}
39
40void TextDiagnosticBuffer::FlushDiagnostics(Diagnostic &Diags) const {
41 // FIXME: Flush the diagnostics in order.
42 for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it)
43 Diags.Report(Diags.getCustomDiagID(Diagnostic::Error, it->second.c_str()));
44 for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it)
45 Diags.Report(Diags.getCustomDiagID(Diagnostic::Warning,it->second.c_str()));
46 for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it)
47 Diags.Report(Diags.getCustomDiagID(Diagnostic::Note, it->second.c_str()));
48}