blob: c03ac54411216182084731a54d89ab5e75ec0b6a [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This is a concrete diagnostic client, which buffers the diagnostic messages.
11//
12//===----------------------------------------------------------------------===//
13
Daniel Dunbare1bd4e62009-03-02 06:16:29 +000014#include "clang/Frontend/TextDiagnosticBuffer.h"
Chris Lattnerf4c83962008-11-19 06:51:40 +000015#include "llvm/ADT/SmallString.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000016using namespace clang;
17
Douglas Gregor94b1dd22008-10-24 04:54:22 +000018/// HandleDiagnostic - Store the errors, warnings, and notes that are
19/// reported.
Mike Stump1eb44332009-09-09 15:08:12 +000020///
Chris Lattner0a14eee2008-11-18 07:04:44 +000021void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic::Level Level,
22 const DiagnosticInfo &Info) {
Argyrios Kyrtzidisf2224d82010-11-18 20:06:46 +000023 // Default implementation (Warnings/errors count).
24 DiagnosticClient::HandleDiagnostic(Level, Info);
25
Daniel Dunbar4cbe3b62009-11-29 20:58:39 +000026 llvm::SmallString<100> Buf;
27 Info.FormatDiagnostic(Buf);
Reid Spencer5f016e22007-07-11 17:01:13 +000028 switch (Level) {
David Blaikieb219cfc2011-09-23 05:06:16 +000029 default: llvm_unreachable(
30 "Diagnostic not handled during diagnostic buffering!");
Douglas Gregor233f74b2008-09-11 02:46:36 +000031 case Diagnostic::Note:
Daniel Dunbar4cbe3b62009-11-29 20:58:39 +000032 Notes.push_back(std::make_pair(Info.getLocation(), Buf.str()));
Douglas Gregor233f74b2008-09-11 02:46:36 +000033 break;
Reid Spencer5f016e22007-07-11 17:01:13 +000034 case Diagnostic::Warning:
Daniel Dunbar4cbe3b62009-11-29 20:58:39 +000035 Warnings.push_back(std::make_pair(Info.getLocation(), Buf.str()));
Reid Spencer5f016e22007-07-11 17:01:13 +000036 break;
37 case Diagnostic::Error:
Ben Laurie64ea69f2009-02-17 17:32:22 +000038 case Diagnostic::Fatal:
Daniel Dunbar4cbe3b62009-11-29 20:58:39 +000039 Errors.push_back(std::make_pair(Info.getLocation(), Buf.str()));
Reid Spencer5f016e22007-07-11 17:01:13 +000040 break;
41 }
42}
Daniel Dunbarc2389552009-11-30 08:41:34 +000043
44void TextDiagnosticBuffer::FlushDiagnostics(Diagnostic &Diags) const {
45 // FIXME: Flush the diagnostics in order.
46 for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it)
47 Diags.Report(Diags.getCustomDiagID(Diagnostic::Error, it->second.c_str()));
48 for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it)
49 Diags.Report(Diags.getCustomDiagID(Diagnostic::Warning,it->second.c_str()));
50 for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it)
51 Diags.Report(Diags.getCustomDiagID(Diagnostic::Note, it->second.c_str()));
52}