1 | |
2 | |
3 | |
4 | |
5 | |
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 | |
19 | |
20 | |
21 | |
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 | Secondary(std::move(Secondary)) {} |
33 | |
34 | |
35 | ChainedDiagnosticConsumer(DiagnosticConsumer *Primary, |
36 | std::unique_ptr<DiagnosticConsumer> Secondary) |
37 | : Primary(Primary), Secondary(std::move(Secondary)) {} |
38 | |
39 | void BeginSourceFile(const LangOptions &LO, |
40 | const Preprocessor *PP) override { |
41 | Primary->BeginSourceFile(LO, PP); |
42 | Secondary->BeginSourceFile(LO, PP); |
43 | } |
44 | |
45 | void EndSourceFile() override { |
46 | Secondary->EndSourceFile(); |
47 | Primary->EndSourceFile(); |
48 | } |
49 | |
50 | void finish() override { |
51 | Secondary->finish(); |
52 | Primary->finish(); |
53 | } |
54 | |
55 | bool IncludeInDiagnosticCounts() const override { |
56 | return Primary->IncludeInDiagnosticCounts(); |
57 | } |
58 | |
59 | void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, |
60 | const Diagnostic &Info) override { |
61 | |
62 | DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info); |
63 | |
64 | Primary->HandleDiagnostic(DiagLevel, Info); |
65 | Secondary->HandleDiagnostic(DiagLevel, Info); |
66 | } |
67 | }; |
68 | |
69 | } |
70 | |
71 | #endif |
72 | |