Files
carbon-lang/toolchain/diagnostics/null_diagnostics.h
T
Jon Meow 20728dbd3a CARBON_ header guards (#1261)
This modifies scripts/check_header_guards.py to add the CARBON_ prefix; everything else is pre-commit.
2022-05-12 17:25:43 -07:00

42 lines
1.3 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_TOOLCHAIN_DIAGNOSTICS_NULL_DIAGNOSTICS_H_
#define CARBON_TOOLCHAIN_DIAGNOSTICS_NULL_DIAGNOSTICS_H_
#include "toolchain/diagnostics/diagnostic_emitter.h"
namespace Carbon {
template <typename LocationT>
inline auto NullDiagnosticLocationTranslator()
-> DiagnosticLocationTranslator<LocationT>& {
struct Translator : DiagnosticLocationTranslator<LocationT> {
auto GetLocation(LocationT /*loc*/) -> DiagnosticLocation override {
return {};
}
};
static auto* translator = new Translator;
return *translator;
}
inline auto NullDiagnosticConsumer() -> DiagnosticConsumer& {
struct Consumer : DiagnosticConsumer {
auto HandleDiagnostic(const Diagnostic& d) -> void override {}
};
static auto* consumer = new Consumer;
return *consumer;
}
template <typename LocationT>
inline auto NullDiagnosticEmitter() -> DiagnosticEmitter<LocationT>& {
static auto* emitter = new DiagnosticEmitter<LocationT>(
NullDiagnosticLocationTranslator<LocationT>(), NullDiagnosticConsumer());
return *emitter;
}
} // namespace Carbon
#endif // CARBON_TOOLCHAIN_DIAGNOSTICS_NULL_DIAGNOSTICS_H_