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 virtual void anchor();
25 OwningPtr<DiagnosticConsumer> Primary;
26 OwningPtr<DiagnosticConsumer> Secondary;
29 ChainedDiagnosticConsumer(DiagnosticConsumer *_Primary,
30 DiagnosticConsumer *_Secondary) {
31 Primary.reset(_Primary);
32 Secondary.reset(_Secondary);
35 virtual void BeginSourceFile(const LangOptions &LO,
36 const Preprocessor *PP) {
37 Primary->BeginSourceFile(LO, PP);
38 Secondary->BeginSourceFile(LO, PP);
41 virtual void EndSourceFile() {
42 Secondary->EndSourceFile();
43 Primary->EndSourceFile();
46 virtual void finish() {
51 virtual bool IncludeInDiagnosticCounts() const {
52 return Primary->IncludeInDiagnosticCounts();
55 virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
56 const Diagnostic &Info) {
57 // Default implementation (Warnings/errors count).
58 DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info);
60 Primary->HandleDiagnostic(DiagLevel, Info);
61 Secondary->HandleDiagnostic(DiagLevel, Info);
65 } // end namspace clang