blob: 069c86de137f66b2f92f6661b89e299d3990a9b8 [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) {
29 default: assert(0 && "Diagnostic not handled during diagnostic buffering!");
Douglas Gregor233f74b2008-09-11 02:46:36 +000030 case Diagnostic::Note:
Daniel Dunbar4cbe3b62009-11-29 20:58:39 +000031 Notes.push_back(std::make_pair(Info.getLocation(), Buf.str()));
Douglas Gregor233f74b2008-09-11 02:46:36 +000032 break;
Reid Spencer5f016e22007-07-11 17:01:13 +000033 case Diagnostic::Warning:
Daniel Dunbar4cbe3b62009-11-29 20:58:39 +000034 Warnings.push_back(std::make_pair(Info.getLocation(), Buf.str()));
Reid Spencer5f016e22007-07-11 17:01:13 +000035 break;
36 case Diagnostic::Error:
Ben Laurie64ea69f2009-02-17 17:32:22 +000037 case Diagnostic::Fatal:
Daniel Dunbar4cbe3b62009-11-29 20:58:39 +000038 Errors.push_back(std::make_pair(Info.getLocation(), Buf.str()));
Reid Spencer5f016e22007-07-11 17:01:13 +000039 break;
40 }
41}
Daniel Dunbarc2389552009-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}