Add support for importing a trivial global C++ function (#5033)

ASTUnit is owned by `CompileSubcommand`, passed through `Unit` to be
populated in `ImportCppFiles()` and used via `SemIR::File`.
When generating the AST, pass `-x c++` args to compile C++ (temporary
until we pass args properly).
`Cpp` namespace is marked as a special namespace and has dedicated logic
in `LookupNameInExactScope()`.
The logic for importing declarations from C++ to Carbon is in
`import_cpp.cpp`, but we're likely to want to refactor this
signfiicantly over time as it grows (perhaps a dedicated directory?).

Part of #4666.
This commit is contained in:
Boaz Brickner
2025-03-03 10:38:19 +00:00
committed by GitHub
parent f0403dadab
commit 87b9cab7b1
12 changed files with 714 additions and 13 deletions
+3 -1
View File
@@ -412,6 +412,7 @@ class CompilationUnit {
std::optional<std::function<auto()->const Parse::TreeAndSubtrees&>>
tree_and_subtrees_getter_;
std::optional<SemIR::File> sem_ir_;
std::unique_ptr<clang::ASTUnit> cpp_ast_;
std::unique_ptr<llvm::LLVMContext> llvm_context_;
std::unique_ptr<llvm::Module> module_;
};
@@ -509,7 +510,8 @@ auto CompilationUnit::GetCheckUnit(SemIR::CheckIRId check_ir_id)
.value_stores = &value_stores_,
.timings = timings_ ? &*timings_ : nullptr,
.tree_and_subtrees_getter = *tree_and_subtrees_getter_,
.sem_ir = &*sem_ir_};
.sem_ir = &*sem_ir_,
.cpp_ast = &cpp_ast_};
}
auto CompilationUnit::PostCheck() -> void {