/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Frontend/ChainedDiagnosticConsumer.h
Line | Count | Source |
1 | | //===- ChainedDiagnosticConsumer.h - Chain Diagnostic Clients ---*- C++ -*-===// |
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 | | #ifndef LLVM_CLANG_FRONTEND_CHAINEDDIAGNOSTICCONSUMER_H |
10 | | #define LLVM_CLANG_FRONTEND_CHAINEDDIAGNOSTICCONSUMER_H |
11 | | |
12 | | #include "clang/Basic/Diagnostic.h" |
13 | | #include <memory> |
14 | | |
15 | | namespace clang { |
16 | | class LangOptions; |
17 | | |
18 | | /// ChainedDiagnosticConsumer - Chain two diagnostic clients so that diagnostics |
19 | | /// go to the first client and then the second. The first diagnostic client |
20 | | /// should be the "primary" client, and will be used for computing whether the |
21 | | /// diagnostics should be included in counts. |
22 | | class ChainedDiagnosticConsumer : public DiagnosticConsumer { |
23 | | virtual void anchor(); |
24 | | std::unique_ptr<DiagnosticConsumer> OwningPrimary; |
25 | | DiagnosticConsumer *Primary; |
26 | | std::unique_ptr<DiagnosticConsumer> Secondary; |
27 | | |
28 | | public: |
29 | | ChainedDiagnosticConsumer(std::unique_ptr<DiagnosticConsumer> Primary, |
30 | | std::unique_ptr<DiagnosticConsumer> Secondary) |
31 | | : OwningPrimary(std::move(Primary)), Primary(OwningPrimary.get()), |
32 | 47 | Secondary(std::move(Secondary)) {} |
33 | | |
34 | | /// Construct without taking ownership of \c Primary. |
35 | | ChainedDiagnosticConsumer(DiagnosticConsumer *Primary, |
36 | | std::unique_ptr<DiagnosticConsumer> Secondary) |
37 | 1 | : Primary(Primary), Secondary(std::move(Secondary)) {} |
38 | | |
39 | | void BeginSourceFile(const LangOptions &LO, |
40 | 31 | const Preprocessor *PP) override { |
41 | 31 | Primary->BeginSourceFile(LO, PP); |
42 | 31 | Secondary->BeginSourceFile(LO, PP); |
43 | 31 | } |
44 | | |
45 | 26 | void EndSourceFile() override { |
46 | 26 | Secondary->EndSourceFile(); |
47 | 26 | Primary->EndSourceFile(); |
48 | 26 | } |
49 | | |
50 | 39 | void finish() override { |
51 | 39 | Secondary->finish(); |
52 | 39 | Primary->finish(); |
53 | 39 | } |
54 | | |
55 | 226 | bool IncludeInDiagnosticCounts() const override { |
56 | 226 | return Primary->IncludeInDiagnosticCounts(); |
57 | 226 | } |
58 | | |
59 | | void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, |
60 | 93 | const Diagnostic &Info) override { |
61 | | // Default implementation (Warnings/errors count). |
62 | 93 | DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info); |
63 | | |
64 | 93 | Primary->HandleDiagnostic(DiagLevel, Info); |
65 | 93 | Secondary->HandleDiagnostic(DiagLevel, Info); |
66 | 93 | } |
67 | | }; |
68 | | |
69 | | } // end namspace clang |
70 | | |
71 | | #endif |