1 //===- unittests/Driver/SimpleDiagnosticConsumer.h ------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Simple diagnostic consumer to grab up diagnostics for testing.
11 //===----------------------------------------------------------------------===//
13 #ifndef CLANG_UNITTESTS_SIMPLEDIAGNOSTICCONSUMER_H
14 #define CLANG_UNITTESTS_SIMPLEDIAGNOSTICCONSUMER_H
16 #include "clang/Basic/Diagnostic.h"
17 #include "llvm/ADT/SmallString.h"
19 struct SimpleDiagnosticConsumer
: public clang::DiagnosticConsumer
{
20 void HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel
,
21 const clang::Diagnostic
&Info
) override
{
22 if (DiagLevel
== clang::DiagnosticsEngine::Level::Error
) {
23 Errors
.emplace_back();
24 Info
.FormatDiagnostic(Errors
.back());
27 Info
.FormatDiagnostic(Msgs
.back());
30 void clear() override
{
33 DiagnosticConsumer::clear();
35 std::vector
<llvm::SmallString
<32>> Msgs
;
36 std::vector
<llvm::SmallString
<32>> Errors
;
39 #endif // CLANG_UNITTESTS_SIMPLEDIAGNOSTICCONSUMER_H