mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-30 10:35:03 +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
65 lines
1.5 KiB
Plaintext
65 lines
1.5 KiB
Plaintext
// 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
|
|
//
|
|
// ARGS: compile --phase=check --share-cpp-ast %s
|
|
//
|
|
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/share_ast.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/share_ast.carbon
|
|
|
|
// --- a.h
|
|
#ifndef A_H
|
|
#define A_H
|
|
inline int GetA() { return 42; }
|
|
#endif
|
|
|
|
// --- b.h
|
|
#ifndef B_H
|
|
#define B_H
|
|
#include "a.h"
|
|
inline int GetB() { return 100; }
|
|
#endif
|
|
|
|
// --- a.carbon
|
|
library "[[@TEST_NAME]]";
|
|
import Cpp library "a.h";
|
|
|
|
fn CallA() -> i32 {
|
|
return Cpp.GetA();
|
|
}
|
|
|
|
// --- todo_a_leaks.carbon
|
|
library "[[@TEST_NAME]]";
|
|
import Cpp;
|
|
|
|
fn CallLeakedA() -> i32 {
|
|
// TODO: This should not be found as we have not imported "a.h".
|
|
return Cpp.GetA();
|
|
}
|
|
|
|
// --- a_again.carbon
|
|
library "[[@TEST_NAME]]";
|
|
import Cpp library "a.h";
|
|
|
|
fn CallAAgain() -> i32 {
|
|
// This should be accepted as we have imported "a.h", even though we will just reuse the version from `a.carbon`.
|
|
return Cpp.GetA();
|
|
}
|
|
|
|
// --- b.carbon
|
|
library "[[@TEST_NAME]]";
|
|
import Cpp library "b.h";
|
|
|
|
fn CallAIndirect() -> i32 {
|
|
return Cpp.GetA();
|
|
}
|
|
|
|
fn CallB() -> i32 {
|
|
return Cpp.GetB();
|
|
}
|