mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 16:31:04 +01:00
Basic support for use of C++ modules via interop. (#7241)
Create a multiplex source to pull information from both the AST reader and from our custom source. Assisted-by: Gemini via Antigravity
This commit is contained in:
@@ -323,7 +323,7 @@ class ShallowCopyCompilerInvocation : public clang::CompilerInvocation {
|
||||
};
|
||||
|
||||
// Provides clang AST nodes representing Carbon SemIR entities.
|
||||
class CarbonExternalASTSource : public clang::ExternalASTSource {
|
||||
class CarbonExternalASTSource : public clang::ExternalSemaSource {
|
||||
public:
|
||||
explicit CarbonExternalASTSource(Context* context) : context_(context) {}
|
||||
|
||||
@@ -896,13 +896,17 @@ auto GenerateAst(Context& context,
|
||||
}
|
||||
|
||||
auto& ast = clang_instance.getASTContext();
|
||||
// TODO: Clang's modules support is implemented as an ExternalASTSource
|
||||
// (ASTReader) and there's no multiplexing support for ExternalASTSources at
|
||||
// the moment - so registering CarbonExternalASTSource breaks Clang modules
|
||||
// support. Implement multiplexing support (possibly in Clang) to restore
|
||||
// modules functionality.
|
||||
ast.setExternalSource(
|
||||
llvm::makeIntrusiveRefCnt<CarbonExternalASTSource>(&context));
|
||||
llvm::IntrusiveRefCntPtr<clang::ExternalSemaSource> carbon_source =
|
||||
llvm::makeIntrusiveRefCnt<CarbonExternalASTSource>(&context);
|
||||
if (auto* existing_source = llvm::cast_or_null<clang::ExternalSemaSource>(
|
||||
ast.getExternalSource())) {
|
||||
auto multiplex_source =
|
||||
llvm::makeIntrusiveRefCnt<clang::MultiplexExternalSemaSource>(
|
||||
existing_source, std::move(carbon_source));
|
||||
ast.setExternalSource(std::move(multiplex_source));
|
||||
} else {
|
||||
ast.setExternalSource(std::move(carbon_source));
|
||||
}
|
||||
|
||||
if (llvm::Error error = action.Execute()) {
|
||||
// `Execute` currently never fails, but its contract allows it to.
|
||||
|
||||
+1
-13
@@ -37,25 +37,13 @@ struct B {};
|
||||
|
||||
B *_Nonnull makeB(A *_Nonnull);
|
||||
|
||||
// --- fail_todo_use_a_b.carbon
|
||||
// --- use_a_b.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "a.h";
|
||||
import Cpp library "b.h";
|
||||
|
||||
// CHECK:STDERR: fail_todo_use_a_b.carbon:[[@LINE+4]]:12: error: member name `B` not found in `Cpp` [MemberNameNotFoundInInstScope]
|
||||
// CHECK:STDERR: fn Go() -> Cpp.B* {
|
||||
// CHECK:STDERR: ^~~~~
|
||||
// CHECK:STDERR:
|
||||
fn Go() -> Cpp.B* {
|
||||
// CHECK:STDERR: fail_todo_use_a_b.carbon:[[@LINE+8]]:10: error: member name `makeB` not found in `Cpp` [MemberNameNotFoundInInstScope]
|
||||
// CHECK:STDERR: return Cpp.makeB(Cpp.makeA());
|
||||
// CHECK:STDERR: ^~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_todo_use_a_b.carbon:[[@LINE+4]]:20: error: member name `makeA` not found in `Cpp` [MemberNameNotFoundInInstScope]
|
||||
// CHECK:STDERR: return Cpp.makeB(Cpp.makeA());
|
||||
// CHECK:STDERR: ^~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
return Cpp.makeB(Cpp.makeA());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user