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