mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-26 15:31:18 +00:00
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
41 lines
1.2 KiB
C++
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_
|