2018-03-22 00:53:26 +00:00
|
|
|
//===- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics -----------------===//
|
2007-06-27 03:19:45 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00: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 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"
|
2018-03-22 00:53:26 +00:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
|
|
|
#include "clang/Basic/LLVM.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"
|
2018-03-22 00:53:26 +00:00
|
|
|
|
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.
|
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:
|
2017-12-16 01:40:19 +00:00
|
|
|
All.emplace_back(Level, Notes.size());
|
2024-01-20 14:30:36 -08:00
|
|
|
Notes.emplace_back(Info.getLocation(), std::string(Buf));
|
2008-09-11 02:46:36 +00:00
|
|
|
break;
|
2011-09-25 23:23:43 +00:00
|
|
|
case DiagnosticsEngine::Warning:
|
2017-12-16 01:40:19 +00:00
|
|
|
All.emplace_back(Level, Warnings.size());
|
2024-01-20 14:30:36 -08:00
|
|
|
Warnings.emplace_back(Info.getLocation(), std::string(Buf));
|
2007-06-27 03:19:45 +00:00
|
|
|
break;
|
2014-05-01 14:06:01 +00:00
|
|
|
case DiagnosticsEngine::Remark:
|
2017-12-16 01:40:19 +00:00
|
|
|
All.emplace_back(Level, Remarks.size());
|
2024-01-20 14:30:36 -08:00
|
|
|
Remarks.emplace_back(Info.getLocation(), std::string(Buf));
|
2014-05-01 14:06:01 +00:00
|
|
|
break;
|
2011-09-25 23:23:43 +00:00
|
|
|
case DiagnosticsEngine::Error:
|
|
|
|
case DiagnosticsEngine::Fatal:
|
2017-12-16 01:40:19 +00:00
|
|
|
All.emplace_back(Level, Errors.size());
|
2024-01-20 14:30:36 -08:00
|
|
|
Errors.emplace_back(Info.getLocation(), std::string(Buf));
|
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 {
|
2018-03-22 00:53:26 +00:00
|
|
|
for (const auto &I : All) {
|
|
|
|
auto Diag = Diags.Report(Diags.getCustomDiagID(I.first, "%0"));
|
|
|
|
switch (I.first) {
|
2017-12-16 01:40:19 +00:00
|
|
|
default: llvm_unreachable(
|
|
|
|
"Diagnostic not handled during diagnostic flushing!");
|
|
|
|
case DiagnosticsEngine::Note:
|
2018-03-22 00:53:26 +00:00
|
|
|
Diag << Notes[I.second].second;
|
2017-12-16 01:40:19 +00:00
|
|
|
break;
|
|
|
|
case DiagnosticsEngine::Warning:
|
2018-03-22 00:53:26 +00:00
|
|
|
Diag << Warnings[I.second].second;
|
2017-12-16 01:40:19 +00:00
|
|
|
break;
|
|
|
|
case DiagnosticsEngine::Remark:
|
2018-03-22 00:53:26 +00:00
|
|
|
Diag << Remarks[I.second].second;
|
2017-12-16 01:40:19 +00:00
|
|
|
break;
|
|
|
|
case DiagnosticsEngine::Error:
|
|
|
|
case DiagnosticsEngine::Fatal:
|
2018-03-22 00:53:26 +00:00
|
|
|
Diag << Errors[I.second].second;
|
2017-12-16 01:40:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-30 08:41:34 +00:00
|
|
|
}
|