llvm-project
74 строки · 2.6 Кб
1//===- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This is a concrete diagnostic client, which buffers the diagnostic messages.
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/Frontend/TextDiagnosticBuffer.h"14#include "clang/Basic/Diagnostic.h"15#include "clang/Basic/LLVM.h"16#include "llvm/ADT/SmallString.h"17#include "llvm/Support/ErrorHandling.h"18
19using namespace clang;20
21/// HandleDiagnostic - Store the errors, warnings, and notes that are
22/// reported.
23void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level,24const Diagnostic &Info) {25// Default implementation (Warnings/errors count).26DiagnosticConsumer::HandleDiagnostic(Level, Info);27
28SmallString<100> Buf;29Info.FormatDiagnostic(Buf);30switch (Level) {31default: llvm_unreachable(32"Diagnostic not handled during diagnostic buffering!");33case DiagnosticsEngine::Note:34All.emplace_back(Level, Notes.size());35Notes.emplace_back(Info.getLocation(), std::string(Buf));36break;37case DiagnosticsEngine::Warning:38All.emplace_back(Level, Warnings.size());39Warnings.emplace_back(Info.getLocation(), std::string(Buf));40break;41case DiagnosticsEngine::Remark:42All.emplace_back(Level, Remarks.size());43Remarks.emplace_back(Info.getLocation(), std::string(Buf));44break;45case DiagnosticsEngine::Error:46case DiagnosticsEngine::Fatal:47All.emplace_back(Level, Errors.size());48Errors.emplace_back(Info.getLocation(), std::string(Buf));49break;50}51}
52
53void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const {54for (const auto &I : All) {55auto Diag = Diags.Report(Diags.getCustomDiagID(I.first, "%0"));56switch (I.first) {57default: llvm_unreachable(58"Diagnostic not handled during diagnostic flushing!");59case DiagnosticsEngine::Note:60Diag << Notes[I.second].second;61break;62case DiagnosticsEngine::Warning:63Diag << Warnings[I.second].second;64break;65case DiagnosticsEngine::Remark:66Diag << Remarks[I.second].second;67break;68case DiagnosticsEngine::Error:69case DiagnosticsEngine::Fatal:70Diag << Errors[I.second].second;71break;72}73}74}
75