2007-06-27 03:19:45 +00:00
|
|
|
//===--- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics ---------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:25 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-06-27 03:19:45 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is a concrete diagnostic client, which buffers the diagnostic messages.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-03-02 06:16:29 +00:00
|
|
|
#include "clang/Frontend/TextDiagnosticBuffer.h"
|
2008-11-19 06:51:40 +00:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2011-09-23 05:57:42 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2007-06-27 03:19:45 +00:00
|
|
|
using namespace clang;
|
|
|
|
|
2008-10-24 04:54:22 +00:00
|
|
|
/// HandleDiagnostic - Store the errors, warnings, and notes that are
|
|
|
|
/// reported.
|
2009-09-09 15:08:12 +00:00
|
|
|
///
|
2011-09-25 23:23:43 +00:00
|
|
|
void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level,
|
2011-09-26 01:18:08 +00:00
|
|
|
const Diagnostic &Info) {
|
2010-11-18 20:06:46 +00:00
|
|
|
// Default implementation (Warnings/errors count).
|
2011-09-25 23:39:51 +00:00
|
|
|
DiagnosticConsumer::HandleDiagnostic(Level, Info);
|
2010-11-18 20:06:46 +00:00
|
|
|
|
2012-02-05 02:13:05 +00:00
|
|
|
SmallString<100> Buf;
|
2009-11-29 20:58:39 +00:00
|
|
|
Info.FormatDiagnostic(Buf);
|
2007-06-27 03:19:45 +00:00
|
|
|
switch (Level) {
|
2011-09-23 05:06:16 +00:00
|
|
|
default: llvm_unreachable(
|
|
|
|
"Diagnostic not handled during diagnostic buffering!");
|
2011-09-25 23:23:43 +00:00
|
|
|
case DiagnosticsEngine::Note:
|
2015-05-29 19:42:19 +00:00
|
|
|
Notes.emplace_back(Info.getLocation(), Buf.str());
|
2008-09-11 02:46:36 +00:00
|
|
|
break;
|
2011-09-25 23:23:43 +00:00
|
|
|
case DiagnosticsEngine::Warning:
|
2015-05-29 19:42:19 +00:00
|
|
|
Warnings.emplace_back(Info.getLocation(), Buf.str());
|
2007-06-27 03:19:45 +00:00
|
|
|
break;
|
2014-05-01 14:06:01 +00:00
|
|
|
case DiagnosticsEngine::Remark:
|
2015-05-29 19:42:19 +00:00
|
|
|
Remarks.emplace_back(Info.getLocation(), Buf.str());
|
2014-05-01 14:06:01 +00:00
|
|
|
break;
|
2011-09-25 23:23:43 +00:00
|
|
|
case DiagnosticsEngine::Error:
|
|
|
|
case DiagnosticsEngine::Fatal:
|
2015-05-29 19:42:19 +00:00
|
|
|
Errors.emplace_back(Info.getLocation(), Buf.str());
|
2007-06-27 03:19:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-30 08:41:34 +00:00
|
|
|
|
2011-09-25 23:23:43 +00:00
|
|
|
void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const {
|
2009-11-30 08:41:34 +00:00
|
|
|
// FIXME: Flush the diagnostics in order.
|
|
|
|
for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it)
|
2013-12-23 07:47:48 +00:00
|
|
|
Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, "%0"))
|
2013-12-21 05:20:03 +00:00
|
|
|
<< it->second;
|
2009-11-30 08:41:34 +00:00
|
|
|
for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it)
|
2013-12-23 07:47:48 +00:00
|
|
|
Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Warning, "%0"))
|
2013-12-21 05:20:03 +00:00
|
|
|
<< it->second;
|
2014-05-01 14:06:01 +00:00
|
|
|
for (const_iterator it = remark_begin(), ie = remark_end(); it != ie; ++it)
|
|
|
|
Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Remark, "%0"))
|
|
|
|
<< it->second;
|
2009-11-30 08:41:34 +00:00
|
|
|
for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it)
|
2013-12-23 07:47:48 +00:00
|
|
|
Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Note, "%0"))
|
2013-12-21 05:20:03 +00:00
|
|
|
<< it->second;
|
2009-11-30 08:41:34 +00:00
|
|
|
}
|
2011-09-29 00:38:00 +00:00
|
|
|
|