blob: d49e983fcd3774b43c93beaa79fc7ba9b43b9226 [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"
David Blaikie79000202011-09-23 05:57:42 +000016#include "llvm/Support/ErrorHandling.h"
Bill Wendling469211a2007-06-27 03:19:45 +000017using namespace clang;
18
Douglas Gregor39c16d42008-10-24 04:54:22 +000019/// HandleDiagnostic - Store the errors, warnings, and notes that are
20/// reported.
Mike Stump11289f42009-09-09 15:08:12 +000021///
David Blaikie9c902b52011-09-25 23:23:43 +000022void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level,
David Blaikieb5784322011-09-26 01:18:08 +000023 const Diagnostic &Info) {
Argyrios Kyrtzidisc79346a2010-11-18 20:06:46 +000024 // Default implementation (Warnings/errors count).
David Blaikiee2eefae2011-09-25 23:39:51 +000025 DiagnosticConsumer::HandleDiagnostic(Level, Info);
Argyrios Kyrtzidisc79346a2010-11-18 20:06:46 +000026
Dylan Noblesmith2c1dd272012-02-05 02:13:05 +000027 SmallString<100> Buf;
Daniel Dunbarecd04442009-11-29 20:58:39 +000028 Info.FormatDiagnostic(Buf);
Bill Wendling469211a2007-06-27 03:19:45 +000029 switch (Level) {
David Blaikie83d382b2011-09-23 05:06:16 +000030 default: llvm_unreachable(
31 "Diagnostic not handled during diagnostic buffering!");
David Blaikie9c902b52011-09-25 23:23:43 +000032 case DiagnosticsEngine::Note:
Benjamin Kramer3204b152015-05-29 19:42:19 +000033 Notes.emplace_back(Info.getLocation(), Buf.str());
Douglas Gregore972aa42008-09-11 02:46:36 +000034 break;
David Blaikie9c902b52011-09-25 23:23:43 +000035 case DiagnosticsEngine::Warning:
Benjamin Kramer3204b152015-05-29 19:42:19 +000036 Warnings.emplace_back(Info.getLocation(), Buf.str());
Bill Wendling469211a2007-06-27 03:19:45 +000037 break;
Tobias Grosser86a85672014-05-01 14:06:01 +000038 case DiagnosticsEngine::Remark:
Benjamin Kramer3204b152015-05-29 19:42:19 +000039 Remarks.emplace_back(Info.getLocation(), Buf.str());
Tobias Grosser86a85672014-05-01 14:06:01 +000040 break;
David Blaikie9c902b52011-09-25 23:23:43 +000041 case DiagnosticsEngine::Error:
42 case DiagnosticsEngine::Fatal:
Benjamin Kramer3204b152015-05-29 19:42:19 +000043 Errors.emplace_back(Info.getLocation(), Buf.str());
Bill Wendling469211a2007-06-27 03:19:45 +000044 break;
45 }
46}
Daniel Dunbar05762b12009-11-30 08:41:34 +000047
David Blaikie9c902b52011-09-25 23:23:43 +000048void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const {
Daniel Dunbar05762b12009-11-30 08:41:34 +000049 // FIXME: Flush the diagnostics in order.
50 for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it)
Alp Tokera8b02c22013-12-23 07:47:48 +000051 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, "%0"))
Alp Tokerbc043f22013-12-21 05:20:03 +000052 << it->second;
Daniel Dunbar05762b12009-11-30 08:41:34 +000053 for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it)
Alp Tokera8b02c22013-12-23 07:47:48 +000054 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Warning, "%0"))
Alp Tokerbc043f22013-12-21 05:20:03 +000055 << it->second;
Tobias Grosser86a85672014-05-01 14:06:01 +000056 for (const_iterator it = remark_begin(), ie = remark_end(); it != ie; ++it)
57 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Remark, "%0"))
58 << it->second;
Daniel Dunbar05762b12009-11-30 08:41:34 +000059 for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it)
Alp Tokera8b02c22013-12-23 07:47:48 +000060 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Note, "%0"))
Alp Tokerbc043f22013-12-21 05:20:03 +000061 << it->second;
Daniel Dunbar05762b12009-11-30 08:41:34 +000062}
Douglas Gregord0e9e3a2011-09-29 00:38:00 +000063