clang 8.0.0

ChainedDiagnosticConsumer.h
Go to the documentation of this file.
1 //===- ChainedDiagnosticConsumer.h - Chain Diagnostic Clients ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_FRONTEND_CHAINEDDIAGNOSTICCONSUMER_H
11 #define LLVM_CLANG_FRONTEND_CHAINEDDIAGNOSTICCONSUMER_H
12
13 #include "clang/Basic/Diagnostic.h"
14 #include <memory>
15
16 namespace clang {
17 class LangOptions;
18
19 /// ChainedDiagnosticConsumer - Chain two diagnostic clients so that diagnostics
20 /// go to the first client and then the second. The first diagnostic client
21 /// should be the "primary" client, and will be used for computing whether the
22 /// diagnostics should be included in counts.
23 class ChainedDiagnosticConsumer : public DiagnosticConsumer {
24 virtual void anchor();
25 std::unique_ptr<DiagnosticConsumer> OwningPrimary;
26 DiagnosticConsumer *Primary;
27 std::unique_ptr<DiagnosticConsumer> Secondary;
28
29 public:
30 ChainedDiagnosticConsumer(std::unique_ptr<DiagnosticConsumer> Primary,
31 std::unique_ptr<DiagnosticConsumer> Secondary)
32 : OwningPrimary(std::move(Primary)), Primary(OwningPrimary.get()),
33 Secondary(std::move(Secondary)) {}
34
35 /// Construct without taking ownership of \c Primary.
36 ChainedDiagnosticConsumer(DiagnosticConsumer *Primary,
37 std::unique_ptr<DiagnosticConsumer> Secondary)
38 : Primary(Primary), Secondary(std::move(Secondary)) {}
39
40 void BeginSourceFile(const LangOptions &LO,
41 const Preprocessor *PP) override {
42 Primary->BeginSourceFile(LO, PP);
43 Secondary->BeginSourceFile(LO, PP);
44 }
45
46 void EndSourceFile() override {
47 Secondary->EndSourceFile();
48 Primary->EndSourceFile();
49 }
50
51 void finish() override {
52 Secondary->finish();
53 Primary->finish();
54 }
55
56 bool IncludeInDiagnosticCounts() const override {
57 return Primary->IncludeInDiagnosticCounts();
58 }
59
60 void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
61 const Diagnostic &Info) override {
62 // Default implementation (Warnings/errors count).
63 DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info);
64
65 Primary->HandleDiagnostic(DiagLevel, Info);
66 Secondary->HandleDiagnostic(DiagLevel, Info);
67 }
68 };
69
70 } // end namspace clang
71
72 #endif
clang::ChainedDiagnosticConsumer::ChainedDiagnosticConsumer
ChainedDiagnosticConsumer(DiagnosticConsumer *Primary, std::unique_ptr< DiagnosticConsumer > Secondary)
Construct without taking ownership of Primary.
Definition: ChainedDiagnosticConsumer.h:36
clang::ChainedDiagnosticConsumer::EndSourceFile
void EndSourceFile() override
Callback to inform the diagnostic client that processing of a source file has ended.
Definition: ChainedDiagnosticConsumer.h:46
clang::ChainedDiagnosticConsumer
ChainedDiagnosticConsumer - Chain two diagnostic clients so that diagnostics go to the first client a...
Definition: ChainedDiagnosticConsumer.h:23
clang::DiagnosticConsumer::IncludeInDiagnosticCounts
virtual bool IncludeInDiagnosticCounts() const
Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number...
Definition: Diagnostic.cpp:1116
clang::DiagnosticConsumer::EndSourceFile
virtual void EndSourceFile()
Callback to inform the diagnostic client that processing of a source file has ended.
Definition: Diagnostic.h:1520
clang::DiagnosticConsumer
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1488
clang::ChainedDiagnosticConsumer::BeginSourceFile
void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override
Callback to inform the diagnostic client that processing of a source file is beginning.
Definition: ChainedDiagnosticConsumer.h:40
std
Definition: Format.h:2072
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
Diagnostic.h
Defines the Diagnostic-related interfaces.
clang::ChainedDiagnosticConsumer::IncludeInDiagnosticCounts
bool IncludeInDiagnosticCounts() const override
Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number...
Definition: ChainedDiagnosticConsumer.h:56
clang::ChainedDiagnosticConsumer::HandleDiagnostic
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
Definition: ChainedDiagnosticConsumer.h:60
clang::DiagnosticConsumer::finish
virtual void finish()
Callback to inform the diagnostic client that processing of all source files has ended.
Definition: Diagnostic.h:1524
clang::DiagnosticConsumer::HandleDiagnostic
virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info)
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
Definition: Diagnostic.cpp:533
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::ChainedDiagnosticConsumer::ChainedDiagnosticConsumer
ChainedDiagnosticConsumer(std::unique_ptr< DiagnosticConsumer > Primary, std::unique_ptr< DiagnosticConsumer > Secondary)
Definition: ChainedDiagnosticConsumer.h:30
clang::ChainedDiagnosticConsumer::finish
void finish() override
Callback to inform the diagnostic client that processing of all source files has ended.
Definition: ChainedDiagnosticConsumer.h:51
clang::DiagnosticsEngine::Level
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:152
clang::Diagnostic
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1316
clang::DiagnosticConsumer::BeginSourceFile
virtual void BeginSourceFile(const LangOptions &LangOpts, const Preprocessor *PP=nullptr)
Callback to inform the diagnostic client that processing of a source file is beginning.
Definition: Diagnostic.h:1512
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:125