null_diagnostics.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef TOOLCHAIN_DIAGNOSTICS_NULL_DIAGNOSTICS_H_
  5. #define TOOLCHAIN_DIAGNOSTICS_NULL_DIAGNOSTICS_H_
  6. #include "toolchain/diagnostics/diagnostic_emitter.h"
  7. namespace Carbon {
  8. template <typename LocationT>
  9. inline auto NullDiagnosticLocationTranslator()
  10. -> DiagnosticLocationTranslator<LocationT>& {
  11. struct Translator : DiagnosticLocationTranslator<LocationT> {
  12. auto GetLocation(LocationT) -> Diagnostic::Location override { return {}; }
  13. };
  14. static Translator* translator = new Translator;
  15. return *translator;
  16. }
  17. inline auto NullDiagnosticConsumer() -> DiagnosticConsumer& {
  18. struct Consumer : DiagnosticConsumer {
  19. auto HandleDiagnostic(const Diagnostic& d) -> void override {}
  20. };
  21. static auto* consumer = new Consumer;
  22. return *consumer;
  23. }
  24. template <typename LocationT>
  25. inline auto NullDiagnosticEmitter() -> DiagnosticEmitter<LocationT>& {
  26. static auto* emitter = new DiagnosticEmitter<LocationT>(
  27. NullDiagnosticLocationTranslator<LocationT>(), NullDiagnosticConsumer());
  28. return *emitter;
  29. }
  30. } // namespace Carbon
  31. #endif // TOOLCHAIN_DIAGNOSTICS_NULL_DIAGNOSTICS_H_