null_diagnostics.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 NullDiagnosticLocationTranslator()
  10. -> DiagnosticLocationTranslator<LocationT>& {
  11. struct Translator : DiagnosticLocationTranslator<LocationT> {
  12. auto GetLocation(LocationT /*loc*/) -> DiagnosticLocation override {
  13. return {};
  14. }
  15. };
  16. static auto* translator = new Translator;
  17. return *translator;
  18. }
  19. inline auto NullDiagnosticConsumer() -> DiagnosticConsumer& {
  20. struct Consumer : DiagnosticConsumer {
  21. auto HandleDiagnostic(Diagnostic /*d*/) -> void override {}
  22. };
  23. static auto* consumer = new Consumer;
  24. return *consumer;
  25. }
  26. template <typename LocationT>
  27. inline auto NullDiagnosticEmitter() -> DiagnosticEmitter<LocationT>& {
  28. static auto* emitter = new DiagnosticEmitter<LocationT>(
  29. NullDiagnosticLocationTranslator<LocationT>(), NullDiagnosticConsumer());
  30. return *emitter;
  31. }
  32. } // namespace Carbon
  33. #endif // CARBON_TOOLCHAIN_DIAGNOSTICS_NULL_DIAGNOSTICS_H_