2018-03-22 08:53:26 +08:00
|
|
|
//===- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics -----------------===//
|
2007-06-27 11:19:45 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2007-06-27 11:19:45 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is a concrete diagnostic client, which buffers the diagnostic messages.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-03-02 14:16:29 +08:00
|
|
|
#include "clang/Frontend/TextDiagnosticBuffer.h"
|
2018-03-22 08:53:26 +08:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
|
|
|
#include "clang/Basic/LLVM.h"
|
2008-11-19 14:51:40 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2011-09-23 13:57:42 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2018-03-22 08:53:26 +08:00
|
|
|
|
2007-06-27 11:19:45 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2008-10-24 12:54:22 +08:00
|
|
|
/// HandleDiagnostic - Store the errors, warnings, and notes that are
|
|
|
|
/// reported.
|
2011-09-26 07:23:43 +08:00
|
|
|
void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level,
|
2011-09-26 09:18:08 +08:00
|
|
|
const Diagnostic &Info) {
|
2010-11-19 04:06:46 +08:00
|
|
|
// Default implementation (Warnings/errors count).
|
2011-09-26 07:39:51 +08:00
|
|
|
DiagnosticConsumer::HandleDiagnostic(Level, Info);
|
2010-11-19 04:06:46 +08:00
|
|
|
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<100> Buf;
|
2009-11-30 04:58:39 +08:00
|
|
|
Info.FormatDiagnostic(Buf);
|
2007-06-27 11:19:45 +08:00
|
|
|
switch (Level) {
|
2011-09-23 13:06:16 +08:00
|
|
|
default: llvm_unreachable(
|
|
|
|
"Diagnostic not handled during diagnostic buffering!");
|
2011-09-26 07:23:43 +08:00
|
|
|
case DiagnosticsEngine::Note:
|
2017-12-16 09:40:19 +08:00
|
|
|
All.emplace_back(Level, Notes.size());
|
2015-05-30 03:42:19 +08:00
|
|
|
Notes.emplace_back(Info.getLocation(), Buf.str());
|
2008-09-11 10:46:36 +08:00
|
|
|
break;
|
2011-09-26 07:23:43 +08:00
|
|
|
case DiagnosticsEngine::Warning:
|
2017-12-16 09:40:19 +08:00
|
|
|
All.emplace_back(Level, Warnings.size());
|
2015-05-30 03:42:19 +08:00
|
|
|
Warnings.emplace_back(Info.getLocation(), Buf.str());
|
2007-06-27 11:19:45 +08:00
|
|
|
break;
|
2014-05-01 22:06:01 +08:00
|
|
|
case DiagnosticsEngine::Remark:
|
2017-12-16 09:40:19 +08:00
|
|
|
All.emplace_back(Level, Remarks.size());
|
2015-05-30 03:42:19 +08:00
|
|
|
Remarks.emplace_back(Info.getLocation(), Buf.str());
|
2014-05-01 22:06:01 +08:00
|
|
|
break;
|
2011-09-26 07:23:43 +08:00
|
|
|
case DiagnosticsEngine::Error:
|
|
|
|
case DiagnosticsEngine::Fatal:
|
2017-12-16 09:40:19 +08:00
|
|
|
All.emplace_back(Level, Errors.size());
|
2015-05-30 03:42:19 +08:00
|
|
|
Errors.emplace_back(Info.getLocation(), Buf.str());
|
2007-06-27 11:19:45 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-30 16:41:34 +08:00
|
|
|
|
2011-09-26 07:23:43 +08:00
|
|
|
void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const {
|
2018-03-22 08:53:26 +08:00
|
|
|
for (const auto &I : All) {
|
|
|
|
auto Diag = Diags.Report(Diags.getCustomDiagID(I.first, "%0"));
|
|
|
|
switch (I.first) {
|
2017-12-16 09:40:19 +08:00
|
|
|
default: llvm_unreachable(
|
|
|
|
"Diagnostic not handled during diagnostic flushing!");
|
|
|
|
case DiagnosticsEngine::Note:
|
2018-03-22 08:53:26 +08:00
|
|
|
Diag << Notes[I.second].second;
|
2017-12-16 09:40:19 +08:00
|
|
|
break;
|
|
|
|
case DiagnosticsEngine::Warning:
|
2018-03-22 08:53:26 +08:00
|
|
|
Diag << Warnings[I.second].second;
|
2017-12-16 09:40:19 +08:00
|
|
|
break;
|
|
|
|
case DiagnosticsEngine::Remark:
|
2018-03-22 08:53:26 +08:00
|
|
|
Diag << Remarks[I.second].second;
|
2017-12-16 09:40:19 +08:00
|
|
|
break;
|
|
|
|
case DiagnosticsEngine::Error:
|
|
|
|
case DiagnosticsEngine::Fatal:
|
2018-03-22 08:53:26 +08:00
|
|
|
Diag << Errors[I.second].second;
|
2017-12-16 09:40:19 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-30 16:41:34 +08:00
|
|
|
}
|