null_diagnostics.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 LocT>
  9. inline auto NullDiagnosticConverter() -> DiagnosticConverter<LocT>& {
  10. struct Converter : public DiagnosticConverter<LocT> {
  11. auto ConvertLoc(LocT /*loc*/,
  12. DiagnosticConverter<LocT>::ContextFnT /*context_fn*/) const
  13. -> ConvertedDiagnosticLoc override {
  14. return {.loc = {}, .last_byte_offset = -1};
  15. }
  16. };
  17. static auto* converter = new Converter;
  18. return *converter;
  19. }
  20. inline auto NullDiagnosticConsumer() -> DiagnosticConsumer& {
  21. struct Consumer : DiagnosticConsumer {
  22. auto HandleDiagnostic(Diagnostic /*d*/) -> void override {}
  23. };
  24. static auto* consumer = new Consumer;
  25. return *consumer;
  26. }
  27. template <typename LocT>
  28. inline auto NullDiagnosticEmitter() -> DiagnosticEmitter<LocT>& {
  29. static auto* emitter = new DiagnosticEmitter<LocT>(
  30. NullDiagnosticConverter<LocT>(), NullDiagnosticConsumer());
  31. return *emitter;
  32. }
  33. } // namespace Carbon
  34. #endif // CARBON_TOOLCHAIN_DIAGNOSTICS_NULL_DIAGNOSTICS_H_