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