Files
carbon-lang/toolchain/check/cpp/context.cpp
T
Richard Smith a1e843718e Create modules for header imports. (#7613)
Make multiple imports of the same header only parse it once per C++
domain. Reuse of the same header in `--share-cpp-ast` mode now reuses
the representation.

Importing a Carbon file with C++ dependencies now makes those transitive
C++ dependencies in the same C++ domain visible too.

Assisted-by: Gemini via Antigravity
2026-08-06 13:32:37 +00:00

34 lines
1007 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"
namespace Carbon::Check {
CppContext::CppContext(SemIR::CppDomain& domain,
std::unique_ptr<CppDiagnosticListener> 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());
}
return *clang_mangle_context_;
}
} // namespace Carbon::Check