mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 14:40:11 +01: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
34 lines
1.0 KiB
C++
34 lines
1.0 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
|
|
|
|
#include "toolchain/check/cpp/context.h"
|
|
|
|
#include "clang/AST/Mangle.h"
|
|
#include "clang/Frontend/CompilerInstance.h"
|
|
#include "clang/Parse/Parser.h"
|
|
|
|
namespace Carbon::Check {
|
|
|
|
CppContext::CppContext(clang::CompilerInstance& instance,
|
|
std::unique_ptr<clang::Parser> parser)
|
|
: ast_context_(&instance.getASTContext()),
|
|
sema_(&instance.getSema()),
|
|
parser_(std::move(parser)) {}
|
|
|
|
CppContext::~CppContext() = default;
|
|
|
|
auto CppContext::set_diagnostic_listener(
|
|
std::unique_ptr<CppDiagnosticListener> listener) -> void {
|
|
diagnostic_listener_ = std::move(listener);
|
|
}
|
|
|
|
auto CppContext::clang_mangle_context() -> clang::MangleContext& {
|
|
if (!clang_mangle_context_) {
|
|
clang_mangle_context_.reset(ast_context().createMangleContext());
|
|
}
|
|
return *clang_mangle_context_;
|
|
}
|
|
|
|
} // namespace Carbon::Check
|