Add some encapsulation to CppDomain (#7579)

Start tracking the domain within `CppContext`s instead of having them
duplicate its fields. This allows us to remove the shared ownership of
the clang parser.

---------

Co-authored-by: Christopher Di Bella <cjdb.ns@gmail.com>
This commit is contained in:
Richard Smith
2026-07-31 18:08:13 +00:00
committed by GitHub
co-authored by Christopher Di Bella
parent 9b8a2124b9
commit 9bcee64b32
13 changed files with 141 additions and 66 deletions
+11 -7
View File
@@ -6,20 +6,24 @@
#include "clang/AST/Mangle.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Parse/Parser.h"
#include "toolchain/check/cpp/domain.h"
namespace Carbon::Check {
CppContext::CppContext(clang::CompilerInstance& instance,
std::shared_ptr<clang::Parser> parser,
CppContext::CppContext(CppDomain& domain,
std::unique_ptr<CppDiagnosticListener> listener)
: ast_context_(&instance.getASTContext()),
sema_(&instance.getSema()),
parser_(std::move(parser)),
diagnostic_listener_(std::move(listener)) {}
: domain_(&domain), diagnostic_listener_(std::move(listener)) {}
CppContext::~CppContext() = default;
auto CppContext::ast_context() -> clang::ASTContext& {
return domain_->clang_instance().getASTContext();
}
auto CppContext::sema() -> clang::Sema& {
return domain_->clang_instance().getSema();
}
auto CppContext::clang_mangle_context() -> clang::MangleContext& {
if (!clang_mangle_context_) {
clang_mangle_context_.reset(ast_context().createMangleContext());