Home | History | Annotate | Download | only in Frontend
      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 "llvm/ADT/OwningPtr.h"
     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   llvm::OwningPtr<DiagnosticConsumer> Primary;
     25   llvm::OwningPtr<DiagnosticConsumer> Secondary;
     26 
     27 public:
     28   ChainedDiagnosticConsumer(DiagnosticConsumer *_Primary,
     29                           DiagnosticConsumer *_Secondary) {
     30     Primary.reset(_Primary);
     31     Secondary.reset(_Secondary);
     32   }
     33 
     34   virtual void BeginSourceFile(const LangOptions &LO,
     35                                const Preprocessor *PP) {
     36     Primary->BeginSourceFile(LO, PP);
     37     Secondary->BeginSourceFile(LO, PP);
     38   }
     39 
     40   virtual void EndSourceFile() {
     41     Secondary->EndSourceFile();
     42     Primary->EndSourceFile();
     43   }
     44 
     45   virtual bool IncludeInDiagnosticCounts() const {
     46     return Primary->IncludeInDiagnosticCounts();
     47   }
     48 
     49   virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
     50                                 const Diagnostic &Info) {
     51     // Default implementation (Warnings/errors count).
     52     DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info);
     53 
     54     Primary->HandleDiagnostic(DiagLevel, Info);
     55     Secondary->HandleDiagnostic(DiagLevel, Info);
     56   }
     57 
     58   DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
     59     return new ChainedDiagnosticConsumer(Primary->clone(Diags),
     60                                          Secondary->clone(Diags));
     61   }
     62 
     63 };
     64 
     65 } // end namspace clang
     66 
     67 #endif
     68