null_diagnostics.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 CARBON_TOOLCHAIN_DIAGNOSTICS_NULL_DIAGNOSTICS_H_
  5. #define CARBON_TOOLCHAIN_DIAGNOSTICS_NULL_DIAGNOSTICS_H_
  6. #include "toolchain/diagnostics/diagnostic_emitter.h"
  7. namespace Carbon {
  8. template <typename LocationT>
  9. inline auto NullDiagnosticConverter() -> DiagnosticConverter<LocationT>& {
  10. struct Converter : public DiagnosticConverter<LocationT> {
  11. auto ConvertLocation(
  12. LocationT /*loc*/,
  13. DiagnosticConverter<LocationT>::ContextFnT /*context_fn*/) const
  14. -> DiagnosticLocation override {
  15. return {};
  16. }
  17. };
  18. static auto* converter = new Converter;
  19. return *converter;
  20. }
  21. inline auto NullDiagnosticConsumer() -> DiagnosticConsumer& {
  22. struct Consumer : DiagnosticConsumer {
  23. auto HandleDiagnostic(Diagnostic /*d*/) -> void override {}
  24. };
  25. static auto* consumer = new Consumer;
  26. return *consumer;
  27. }
  28. template <typename LocationT>
  29. inline auto NullDiagnosticEmitter() -> DiagnosticEmitter<LocationT>& {
  30. static auto* emitter = new DiagnosticEmitter<LocationT>(
  31. NullDiagnosticConverter<LocationT>(), NullDiagnosticConsumer());
  32. return *emitter;
  33. }
  34. } // namespace Carbon
  35. #endif // CARBON_TOOLCHAIN_DIAGNOSTICS_NULL_DIAGNOSTICS_H_