clang API Documentation

ChainedDiagnosticConsumer.h
Go to the documentation of this file.
00001 //===- ChainedDiagnosticConsumer.h - Chain Diagnostic Clients ---*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_CLANG_FRONTEND_CHAINEDDIAGNOSTICCONSUMER_H
00011 #define LLVM_CLANG_FRONTEND_CHAINEDDIAGNOSTICCONSUMER_H
00012 
00013 #include "clang/Basic/Diagnostic.h"
00014 #include <memory>
00015 
00016 namespace clang {
00017 class LangOptions;
00018 
00019 /// ChainedDiagnosticConsumer - Chain two diagnostic clients so that diagnostics
00020 /// go to the first client and then the second. The first diagnostic client
00021 /// should be the "primary" client, and will be used for computing whether the
00022 /// diagnostics should be included in counts.
00023 class ChainedDiagnosticConsumer : public DiagnosticConsumer {
00024   virtual void anchor();
00025   std::unique_ptr<DiagnosticConsumer> OwningPrimary;
00026   DiagnosticConsumer *Primary;
00027   std::unique_ptr<DiagnosticConsumer> Secondary;
00028 
00029 public:
00030   ChainedDiagnosticConsumer(std::unique_ptr<DiagnosticConsumer> Primary,
00031                             std::unique_ptr<DiagnosticConsumer> Secondary)
00032       : OwningPrimary(std::move(Primary)), Primary(OwningPrimary.get()),
00033         Secondary(std::move(Secondary)) {}
00034 
00035   /// \brief Construct without taking ownership of \c Primary.
00036   ChainedDiagnosticConsumer(DiagnosticConsumer *Primary,
00037                             std::unique_ptr<DiagnosticConsumer> Secondary)
00038       : Primary(Primary), Secondary(std::move(Secondary)) {}
00039 
00040   void BeginSourceFile(const LangOptions &LO,
00041                        const Preprocessor *PP) override {
00042     Primary->BeginSourceFile(LO, PP);
00043     Secondary->BeginSourceFile(LO, PP);
00044   }
00045 
00046   void EndSourceFile() override {
00047     Secondary->EndSourceFile();
00048     Primary->EndSourceFile();
00049   }
00050 
00051   void finish() override {
00052     Secondary->finish();
00053     Primary->finish();
00054   }
00055 
00056   bool IncludeInDiagnosticCounts() const override {
00057     return Primary->IncludeInDiagnosticCounts();
00058   }
00059 
00060   void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
00061                         const Diagnostic &Info) override {
00062     // Default implementation (Warnings/errors count).
00063     DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info);
00064 
00065     Primary->HandleDiagnostic(DiagLevel, Info);
00066     Secondary->HandleDiagnostic(DiagLevel, Info);
00067   }
00068 };
00069 
00070 } // end namspace clang
00071 
00072 #endif