Add support for exporting Carbon functions as constructors. (#7560)

Co-authored-by: Nicholas Bishop <nbishop@nbishop.net>
This commit is contained in:
Geoff Romer
2026-07-24 18:43:12 +00:00
committed by GitHub
co-authored by Nicholas Bishop
parent de68b19784
commit 3cb143e878
7 changed files with 576 additions and 100 deletions
+15 -4
View File
@@ -574,10 +574,21 @@ auto CarbonExternalASTSource::FindExternalVisibleDeclsByName(
return false;
}
auto* identifier = decl_name.getAsIdentifierInfo();
if (!identifier) {
// Only supporting identifiers for now.
return false;
clang::IdentifierInfo* identifier = nullptr;
switch (decl_name.getNameKind()) {
case clang::DeclarationName::Identifier: {
identifier = decl_name.getAsIdentifierInfo();
break;
}
case clang::DeclarationName::CXXConstructorName: {
// The Carbon counterpart of a constructor is a function whose name
// matches the class name.
identifier =
llvm::cast<clang::CXXRecordDecl>(decl_context)->getIdentifier();
break;
}
default:
return false;
}
auto name_id = AddIdentifierName(*context_, identifier->getName());