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