ChainedDiagnosticConsumer.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ChainedDiagnosticConsumer.h - Chain Diagnostic Clients ---*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CLANG_FRONTEND_CHAINEDDIAGNOSTICCONSUMER_H
  14. #define LLVM_CLANG_FRONTEND_CHAINEDDIAGNOSTICCONSUMER_H
  15. #include "clang/Basic/Diagnostic.h"
  16. #include <memory>
  17. namespace clang {
  18. class LangOptions;
  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> OwningPrimary;
  26. DiagnosticConsumer *Primary;
  27. std::unique_ptr<DiagnosticConsumer> Secondary;
  28. public:
  29. ChainedDiagnosticConsumer(std::unique_ptr<DiagnosticConsumer> Primary,
  30. std::unique_ptr<DiagnosticConsumer> Secondary)
  31. : OwningPrimary(std::move(Primary)), Primary(OwningPrimary.get()),
  32. Secondary(std::move(Secondary)) {}
  33. /// Construct without taking ownership of \c Primary.
  34. ChainedDiagnosticConsumer(DiagnosticConsumer *Primary,
  35. std::unique_ptr<DiagnosticConsumer> Secondary)
  36. : Primary(Primary), Secondary(std::move(Secondary)) {}
  37. void BeginSourceFile(const LangOptions &LO,
  38. const Preprocessor *PP) override {
  39. Primary->BeginSourceFile(LO, PP);
  40. Secondary->BeginSourceFile(LO, PP);
  41. }
  42. void EndSourceFile() override {
  43. Secondary->EndSourceFile();
  44. Primary->EndSourceFile();
  45. }
  46. void finish() override {
  47. Secondary->finish();
  48. Primary->finish();
  49. }
  50. bool IncludeInDiagnosticCounts() const override {
  51. return Primary->IncludeInDiagnosticCounts();
  52. }
  53. void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
  54. const Diagnostic &Info) override {
  55. // Default implementation (Warnings/errors count).
  56. DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info);
  57. Primary->HandleDiagnostic(DiagLevel, Info);
  58. Secondary->HandleDiagnostic(DiagLevel, Info);
  59. }
  60. };
  61. } // end namspace clang
  62. #endif
  63. #ifdef __GNUC__
  64. #pragma GCC diagnostic pop
  65. #endif