blob: fdf2ec8ccf5d016b64b4d15c4536ac08d134e3ee [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) {
Daniel Dunbar4cbe3b62009-11-29 20:58:39 +000023 llvm::SmallString<100> Buf;
24 Info.FormatDiagnostic(Buf);
Reid Spencer5f016e22007-07-11 17:01:13 +000025 switch (Level) {
26 default: assert(0 && "Diagnostic not handled during diagnostic buffering!");
Douglas Gregor233f74b2008-09-11 02:46:36 +000027 case Diagnostic::Note:
Daniel Dunbar4cbe3b62009-11-29 20:58:39 +000028 Notes.push_back(std::make_pair(Info.getLocation(), Buf.str()));
Douglas Gregor233f74b2008-09-11 02:46:36 +000029 break;
Reid Spencer5f016e22007-07-11 17:01:13 +000030 case Diagnostic::Warning:
Daniel Dunbar4cbe3b62009-11-29 20:58:39 +000031 Warnings.push_back(std::make_pair(Info.getLocation(), Buf.str()));
Reid Spencer5f016e22007-07-11 17:01:13 +000032 break;
33 case Diagnostic::Error:
Ben Laurie64ea69f2009-02-17 17:32:22 +000034 case Diagnostic::Fatal:
Daniel Dunbar4cbe3b62009-11-29 20:58:39 +000035 Errors.push_back(std::make_pair(Info.getLocation(), Buf.str()));
Reid Spencer5f016e22007-07-11 17:01:13 +000036 break;
37 }
38}
Daniel Dunbarc2389552009-11-30 08:41:34 +000039
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}