Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:55

0001 //===- ChainedDiagnosticConsumer.h - Chain Diagnostic Clients ---*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_FRONTEND_CHAINEDDIAGNOSTICCONSUMER_H
0010 #define LLVM_CLANG_FRONTEND_CHAINEDDIAGNOSTICCONSUMER_H
0011 
0012 #include "clang/Basic/Diagnostic.h"
0013 #include <memory>
0014 
0015 namespace clang {
0016 class LangOptions;
0017 
0018 /// ChainedDiagnosticConsumer - Chain two diagnostic clients so that diagnostics
0019 /// go to the first client and then the second. The first diagnostic client
0020 /// should be the "primary" client, and will be used for computing whether the
0021 /// diagnostics should be included in counts.
0022 class ChainedDiagnosticConsumer : public DiagnosticConsumer {
0023   virtual void anchor();
0024   std::unique_ptr<DiagnosticConsumer> OwningPrimary;
0025   DiagnosticConsumer *Primary;
0026   std::unique_ptr<DiagnosticConsumer> Secondary;
0027 
0028 public:
0029   ChainedDiagnosticConsumer(std::unique_ptr<DiagnosticConsumer> Primary,
0030                             std::unique_ptr<DiagnosticConsumer> Secondary)
0031       : OwningPrimary(std::move(Primary)), Primary(OwningPrimary.get()),
0032         Secondary(std::move(Secondary)) {}
0033 
0034   /// Construct without taking ownership of \c Primary.
0035   ChainedDiagnosticConsumer(DiagnosticConsumer *Primary,
0036                             std::unique_ptr<DiagnosticConsumer> Secondary)
0037       : Primary(Primary), Secondary(std::move(Secondary)) {}
0038 
0039   void BeginSourceFile(const LangOptions &LO,
0040                        const Preprocessor *PP) override {
0041     Primary->BeginSourceFile(LO, PP);
0042     Secondary->BeginSourceFile(LO, PP);
0043   }
0044 
0045   void EndSourceFile() override {
0046     Secondary->EndSourceFile();
0047     Primary->EndSourceFile();
0048   }
0049 
0050   void finish() override {
0051     Secondary->finish();
0052     Primary->finish();
0053   }
0054 
0055   bool IncludeInDiagnosticCounts() const override {
0056     return Primary->IncludeInDiagnosticCounts();
0057   }
0058 
0059   void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
0060                         const Diagnostic &Info) override {
0061     // Default implementation (Warnings/errors count).
0062     DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info);
0063 
0064     Primary->HandleDiagnostic(DiagLevel, Info);
0065     Secondary->HandleDiagnostic(DiagLevel, Info);
0066   }
0067 };
0068 
0069 } // end namspace clang
0070 
0071 #endif