@@ -699,7 +699,7 @@ void ASTMangler::appendDeclName(const ValueDecl *decl) {
699
699
break ;
700
700
}
701
701
} else if (auto objCName =
702
- getOverriddenSwiftProtocolObjCName (decl, UseObjCProtocolNames )) {
702
+ getOverriddenSwiftProtocolObjCName (decl, UseObjCRuntimeNames )) {
703
703
// @objc Swift protocols should be mangled as Objective-C protocols,
704
704
// so append the Objective-C runtime name.
705
705
appendIdentifier (*objCName);
@@ -1298,7 +1298,7 @@ void ASTMangler::appendBoundGenericArgs(Type type, bool &isFirstArgList) {
1298
1298
genericArgs = boundType->getGenericArgs ();
1299
1299
if (Type parent = boundType->getParent ()) {
1300
1300
GenericTypeDecl *decl = boundType->getAnyGeneric ();
1301
- if (!getSpecialManglingContext (decl, UseObjCProtocolNames ))
1301
+ if (!getSpecialManglingContext (decl, UseObjCRuntimeNames ))
1302
1302
appendBoundGenericArgs (parent->getDesugaredType (), isFirstArgList);
1303
1303
}
1304
1304
}
@@ -1610,7 +1610,7 @@ ASTMangler::getSpecialManglingContext(const ValueDecl *decl,
1610
1610
// / This is the top-level entrypoint for mangling <context>.
1611
1611
void ASTMangler::appendContextOf (const ValueDecl *decl) {
1612
1612
// Check for a special mangling context.
1613
- if (auto context = getSpecialManglingContext (decl, UseObjCProtocolNames )) {
1613
+ if (auto context = getSpecialManglingContext (decl, UseObjCRuntimeNames )) {
1614
1614
switch (*context) {
1615
1615
case ClangImporterContext:
1616
1616
return appendOperator (" SC" );
@@ -1857,7 +1857,10 @@ void ASTMangler::appendProtocolName(const ProtocolDecl *protocol,
1857
1857
1858
1858
appendContextOf (protocol);
1859
1859
auto *clangDecl = protocol->getClangDecl ();
1860
- if (auto *clangProto = cast_or_null<clang::ObjCProtocolDecl>(clangDecl))
1860
+ auto clangProto = cast_or_null<clang::ObjCProtocolDecl>(clangDecl);
1861
+ if (clangProto && UseObjCRuntimeNames)
1862
+ appendIdentifier (clangProto->getObjCRuntimeNameAsString ());
1863
+ else if (clangProto)
1861
1864
appendIdentifier (clangProto->getName ());
1862
1865
else
1863
1866
appendDeclName (protocol);
@@ -1928,15 +1931,25 @@ void ASTMangler::appendAnyGenericType(const GenericTypeDecl *decl) {
1928
1931
if (!namedDecl)
1929
1932
return false ;
1930
1933
1931
- appendIdentifier (namedDecl->getName ());
1934
+ // Mangle ObjC classes using their runtime names.
1935
+ auto interface = dyn_cast<clang::ObjCInterfaceDecl>(namedDecl);
1936
+ auto protocol = dyn_cast<clang::ObjCProtocolDecl>(namedDecl);
1937
+
1938
+ if (UseObjCRuntimeNames && interface) {
1939
+ appendIdentifier (interface->getObjCRuntimeNameAsString ());
1940
+ } else if (UseObjCRuntimeNames && protocol) {
1941
+ appendIdentifier (protocol->getObjCRuntimeNameAsString ());
1942
+ } else {
1943
+ appendIdentifier (namedDecl->getName ());
1944
+ }
1932
1945
1933
1946
// The important distinctions to maintain here are Objective-C's various
1934
1947
// namespaces: protocols, tags (struct/enum/union), and unqualified names.
1935
1948
// We continue to mangle "class" the standard Swift way because it feels
1936
1949
// weird to call that an alias, but they're really in the same namespace.
1937
- if (isa<clang::ObjCInterfaceDecl>(namedDecl) ) {
1950
+ if (interface ) {
1938
1951
appendOperator (" C" );
1939
- } else if (isa<clang::ObjCProtocolDecl>(namedDecl) ) {
1952
+ } else if (protocol ) {
1940
1953
appendOperator (" P" );
1941
1954
} else if (isa<clang::TagDecl>(namedDecl)) {
1942
1955
// Note: This includes enums, but that's okay. A Clang enum is not always
0 commit comments