1 //===- ChainedDiagnosticConsumer.h - Chain Diagnostic Clients ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_FRONTEND_CHAINEDDIAGNOSTICCONSUMER_H
11 #define LLVM_CLANG_FRONTEND_CHAINEDDIAGNOSTICCONSUMER_H
13 #include "clang/Basic/Diagnostic.h"
14 #include "llvm/ADT/OwningPtr.h"
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 llvm::OwningPtr<DiagnosticConsumer> Primary;
25 llvm::OwningPtr<DiagnosticConsumer> Secondary;
28 ChainedDiagnosticConsumer(DiagnosticConsumer *_Primary,
29 DiagnosticConsumer *_Secondary) {
30 Primary.reset(_Primary);
31 Secondary.reset(_Secondary);
34 virtual void BeginSourceFile(const LangOptions &LO,
35 const Preprocessor *PP) {
36 Primary->BeginSourceFile(LO, PP);
37 Secondary->BeginSourceFile(LO, PP);
40 virtual void EndSourceFile() {
41 Secondary->EndSourceFile();
42 Primary->EndSourceFile();
45 virtual bool IncludeInDiagnosticCounts() const {
46 return Primary->IncludeInDiagnosticCounts();
49 virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
50 const Diagnostic &Info) {
51 // Default implementation (Warnings/errors count).
52 DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info);
54 Primary->HandleDiagnostic(DiagLevel, Info);
55 Secondary->HandleDiagnostic(DiagLevel, Info);
58 DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
59 return new ChainedDiagnosticConsumer(Primary->clone(Diags),
60 Secondary->clone(Diags));
65 } // end namspace clang