Files
carbon-lang/toolchain/check/cpp/diagnostic_consumer.h
T
Richard Smith 39916ad2ca Split up C++ diagnostic emitter and factor it out. (#7558)
Split the diagnostic emitter into a separate emitter (regietered with
Clang) and listener (registered with the emitter). The purpose of this
split is to make the Clang emitter not depend on the `Check::Context`,
so that we can use it, and hence the same Clang instance, with multiple
`Check::Context`s. A fallback listener is registered to collect and emit
any diagnostics produced while we don't have a `Check::Context`
registered with the emitter.

Assisted-by: Gemini via Antigravity
2026-07-24 20:14:50 +00:00

41 lines
1.2 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_CHECK_CPP_DIAGNOSTIC_CONSUMER_H_
#define CARBON_TOOLCHAIN_CHECK_CPP_DIAGNOSTIC_CONSUMER_H_
#include <memory>
#include "clang/Basic/Diagnostic.h"
namespace clang {
class CompilerInvocation;
class DiagnosticConsumer;
} // namespace clang
namespace Carbon::Diagnostics {
class Consumer;
} // namespace Carbon::Diagnostics
namespace Carbon::Check {
class Context;
class CppDiagnosticListener;
// Creates a Clang DiagnosticConsumer that adapts Clang diagnostics to Carbon.
auto MakeDiagnosticConsumer(
Diagnostics::Consumer& consumer,
std::shared_ptr<clang::CompilerInvocation> invocation)
-> std::unique_ptr<clang::DiagnosticConsumer>;
// Creates a diagnostic listener attached to the given Carbon context. The
// returned listener must not outlive the context.
auto MakeContextDiagnosticListener(clang::DiagnosticConsumer& consumer,
Context& context)
-> std::unique_ptr<CppDiagnosticListener>;
} // namespace Carbon::Check
#endif // CARBON_TOOLCHAIN_CHECK_CPP_DIAGNOSTIC_CONSUMER_H_