clang API Documentation
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 "llvm/ADT/OwningPtr.h" 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 OwningPtr<DiagnosticConsumer> Primary; 00026 OwningPtr<DiagnosticConsumer> Secondary; 00027 00028 public: 00029 ChainedDiagnosticConsumer(DiagnosticConsumer *_Primary, 00030 DiagnosticConsumer *_Secondary) { 00031 Primary.reset(_Primary); 00032 Secondary.reset(_Secondary); 00033 } 00034 00035 virtual void BeginSourceFile(const LangOptions &LO, 00036 const Preprocessor *PP) { 00037 Primary->BeginSourceFile(LO, PP); 00038 Secondary->BeginSourceFile(LO, PP); 00039 } 00040 00041 virtual void EndSourceFile() { 00042 Secondary->EndSourceFile(); 00043 Primary->EndSourceFile(); 00044 } 00045 00046 virtual void finish() { 00047 Secondary->finish(); 00048 Primary->finish(); 00049 } 00050 00051 virtual bool IncludeInDiagnosticCounts() const { 00052 return Primary->IncludeInDiagnosticCounts(); 00053 } 00054 00055 virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, 00056 const Diagnostic &Info) { 00057 // Default implementation (Warnings/errors count). 00058 DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info); 00059 00060 Primary->HandleDiagnostic(DiagLevel, Info); 00061 Secondary->HandleDiagnostic(DiagLevel, Info); 00062 } 00063 00064 DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const { 00065 return new ChainedDiagnosticConsumer(Primary->clone(Diags), 00066 Secondary->clone(Diags)); 00067 } 00068 00069 }; 00070 00071 } // end namspace clang 00072 00073 #endif