mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Instead of building one Clang `ASTContext` per compilation, the `--share-cpp-ast` flag causes us to build a single `ASTContext` and share it across all contexts. One new abstraction is added: `CppDomain` represents the Carbon-side view of a Clang AST that might be shared across multiple `SemIR::File`s. This object owns the Clang instance and the AST. For now, we have no isolation between the C++ state exposed to different Carbon compilations, and we have no multiplexing of generated LLVM IR from C++ into different Carbon compilations, so the mode is not usable yet. The plan is to keep it behind a flag until it's ready. Assisted-by: Gemini via Antigravity
31 lines
1006 B
C++
31 lines
1006 B
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::shared_ptr<clang::Parser> parser,
|
|
std::unique_ptr<CppDiagnosticListener> listener)
|
|
: ast_context_(&instance.getASTContext()),
|
|
sema_(&instance.getSema()),
|
|
parser_(std::move(parser)),
|
|
diagnostic_listener_(std::move(listener)) {}
|
|
|
|
CppContext::~CppContext() = default;
|
|
|
|
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
|