1 | //===- unittests/Driver/SimpleDiagnosticConsumer.h ------------------------===// |
---|---|
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 | // Simple diagnostic consumer to grab up diagnostics for testing. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef CLANG_UNITTESTS_SIMPLEDIAGNOSTICCONSUMER_H |
14 | #define CLANG_UNITTESTS_SIMPLEDIAGNOSTICCONSUMER_H |
15 | |
16 | #include "clang/Basic/Diagnostic.h" |
17 | #include "llvm/ADT/SmallString.h" |
18 | |
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(OutStr&: Errors.back()); |
25 | } else { |
26 | Msgs.emplace_back(); |
27 | Info.FormatDiagnostic(OutStr&: Msgs.back()); |
28 | } |
29 | } |
30 | void clear() override { |
31 | Msgs.clear(); |
32 | Errors.clear(); |
33 | DiagnosticConsumer::clear(); |
34 | } |
35 | std::vector<llvm::SmallString<32>> Msgs; |
36 | std::vector<llvm::SmallString<32>> Errors; |
37 | }; |
38 | |
39 | #endif // CLANG_UNITTESTS_SIMPLEDIAGNOSTICCONSUMER_H |
40 |