clang  14.0.0git
ChainedDiagnosticConsumer.h
Go to the documentation of this file.
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.
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  /// Construct without taking ownership of \c 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 
60  const Diagnostic &Info) override {
61  // Default implementation (Warnings/errors count).
62  DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info);
63 
64  Primary->HandleDiagnostic(DiagLevel, Info);
65  Secondary->HandleDiagnostic(DiagLevel, Info);
66  }
67 };
68 
69 } // end namspace clang
70 
71 #endif
clang::DiagnosticsEngine::Level
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:194
clang::DiagnosticConsumer
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1707
clang::DiagnosticConsumer::EndSourceFile
virtual void EndSourceFile()
Callback to inform the diagnostic client that processing of a source file has ended.
Definition: Diagnostic.h:1739
clang::Diagnostic
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1532
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:547
clang::ChainedDiagnosticConsumer
ChainedDiagnosticConsumer - Chain two diagnostic clients so that diagnostics go to the first client a...
Definition: ChainedDiagnosticConsumer.h:22
Diagnostic.h
clang::ChainedDiagnosticConsumer::finish
void finish() override
Callback to inform the diagnostic client that processing of all source files has ended.
Definition: ChainedDiagnosticConsumer.h:50
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:59
clang::ChainedDiagnosticConsumer::ChainedDiagnosticConsumer
ChainedDiagnosticConsumer(std::unique_ptr< DiagnosticConsumer > Primary, std::unique_ptr< DiagnosticConsumer > Secondary)
Definition: ChainedDiagnosticConsumer.h:29
clang::DiagnosticConsumer::IncludeInDiagnosticCounts
virtual bool IncludeInDiagnosticCounts() const
Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number...
Definition: Diagnostic.cpp:1131
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:39
clang::ChainedDiagnosticConsumer::ChainedDiagnosticConsumer
ChainedDiagnosticConsumer(DiagnosticConsumer *Primary, std::unique_ptr< DiagnosticConsumer > Secondary)
Construct without taking ownership of Primary.
Definition: ChainedDiagnosticConsumer.h:35
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:1731
clang::ChainedDiagnosticConsumer::IncludeInDiagnosticCounts
bool IncludeInDiagnosticCounts() const override
Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number...
Definition: ChainedDiagnosticConsumer.h:55
clang::DiagnosticConsumer::finish
virtual void finish()
Callback to inform the diagnostic client that processing of all source files has ended.
Definition: Diagnostic.h:1743
clang::ChainedDiagnosticConsumer::EndSourceFile
void EndSourceFile() override
Callback to inform the diagnostic client that processing of a source file has ended.
Definition: ChainedDiagnosticConsumer.h:45
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:58
std
Definition: Format.h:3832
clang
Definition: CalledOnceCheck.h:17
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:130