mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
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:
co-authored by
Christopher Di Bella
parent
9b8a2124b9
commit
9bcee64b32
@@ -33,6 +33,7 @@
|
||||
#include "toolchain/check/cpp/access.h"
|
||||
#include "toolchain/check/cpp/diagnostic_consumer.h"
|
||||
#include "toolchain/check/cpp/diagnostic_listener.h"
|
||||
#include "toolchain/check/cpp/domain.h"
|
||||
#include "toolchain/check/cpp/export.h"
|
||||
#include "toolchain/check/cpp/import.h"
|
||||
#include "toolchain/check/cpp/location.h"
|
||||
@@ -727,7 +728,7 @@ auto InitializeCppDomain(
|
||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
|
||||
llvm::LLVMContext* llvm_context,
|
||||
std::shared_ptr<clang::CompilerInvocation> base_invocation)
|
||||
-> std::shared_ptr<CppDomain> {
|
||||
-> std::unique_ptr<CppDomain> {
|
||||
std::shared_ptr<clang::CompilerInstance> clang_instance;
|
||||
llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> diags;
|
||||
|
||||
@@ -810,11 +811,9 @@ auto InitializeCppDomain(
|
||||
auto parser = action.TakeParser();
|
||||
CARBON_CHECK(parser);
|
||||
|
||||
return std::make_shared<CppDomain>(
|
||||
CppDomain{.clang_instance = std::move(clang_instance),
|
||||
.parser = std::move(parser),
|
||||
.code_generator = action.code_generator(),
|
||||
.llvm_context = llvm_context});
|
||||
return std::make_unique<CppDomain>(std::move(clang_instance),
|
||||
std::move(parser), action.code_generator(),
|
||||
llvm_context);
|
||||
}
|
||||
|
||||
auto GenerateAst(Context& context,
|
||||
@@ -830,22 +829,20 @@ auto GenerateAst(Context& context,
|
||||
Diagnostics::AnnotationScope annotate_diagnostics(&context.emitter(),
|
||||
[](auto& /*builder*/) {});
|
||||
|
||||
auto clang_instance = domain.clang_instance;
|
||||
auto parser = domain.parser;
|
||||
auto clang_instance = domain.clang_instance_ptr();
|
||||
|
||||
// Set up CppFile for the current SemIR::File.
|
||||
auto cpp_file =
|
||||
std::make_unique<SemIR::CppFile>(clang_instance, domain.llvm_context);
|
||||
if (domain.code_generator) {
|
||||
cpp_file->SetCodeGenerator(domain.code_generator);
|
||||
std::make_unique<SemIR::CppFile>(clang_instance, domain.llvm_context());
|
||||
if (domain.code_generator()) {
|
||||
cpp_file->SetCodeGenerator(domain.code_generator());
|
||||
}
|
||||
context.sem_ir().set_cpp_file(std::move(cpp_file));
|
||||
|
||||
// Set up CppContext for the current Context.
|
||||
context.set_cpp_context(std::make_unique<CppContext>(
|
||||
*clang_instance, parser,
|
||||
MakeContextDiagnosticListener(
|
||||
*clang_instance->getDiagnostics().getClient(), context)));
|
||||
domain, MakeContextDiagnosticListener(
|
||||
*clang_instance->getDiagnostics().getClient(), context)));
|
||||
|
||||
// The AST context is now available, so the mangle context (used to compute
|
||||
// stable identities for imported C++ types) can be created.
|
||||
@@ -917,10 +914,10 @@ auto FinishAst(Context& context) -> void {
|
||||
}
|
||||
|
||||
auto FinalizeCppDomain(CppDomain& domain) -> void {
|
||||
if (domain.clang_instance) {
|
||||
domain.clang_instance->getSema().ActOnEndOfTranslationUnit();
|
||||
if (domain.clang_instance_ptr()) {
|
||||
domain.clang_instance().getSema().ActOnEndOfTranslationUnit();
|
||||
FlushDiagnosticConsumer(
|
||||
*domain.clang_instance->getDiagnostics().getClient());
|
||||
*domain.clang_instance().getDiagnostics().getClient());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user