Files
carbon-lang/toolchain/diagnostics/null_diagnostics.h
T
Jon Ross-Perkins 6c458ffe7e Add import context for locations. (#3807)
As discussed around #3792, identify the import a diagnostic message came
from prior to the diagnostic message itself. This occurs during location
translation so that the logic can be central.

I'd considered associating the parse node with ImportRef instructions,
but I realized about halfway through that because I need to store the
ImportDirectiveId on the ImportIR for cross-package imports, it's there
for use in location translation without extra work. That saves a fair
amount of stringing it through declarations, as well as an oddity where
ImportRef instructions would have a node that didn't really represent
them.
2024-03-27 22:22:15 +00:00

44 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 NullDiagnosticConverter() -> DiagnosticConverter<LocationT>& {
struct Converter : public DiagnosticConverter<LocationT> {
auto ConvertLocation(
LocationT /*loc*/,
DiagnosticConverter<LocationT>::ContextFnT /*context_fn*/) const
-> DiagnosticLocation override {
return {};
}
};
static auto* converter = new Converter;
return *converter;
}
inline auto NullDiagnosticConsumer() -> DiagnosticConsumer& {
struct Consumer : DiagnosticConsumer {
auto HandleDiagnostic(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>(
NullDiagnosticConverter<LocationT>(), NullDiagnosticConsumer());
return *emitter;
}
} // namespace Carbon
#endif // CARBON_TOOLCHAIN_DIAGNOSTICS_NULL_DIAGNOSTICS_H_