mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 13:11: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.
|
||||
|
||||
Reference in New Issue
Block a user