mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #79514 from swiftlang/gaborh/objc-in-generics
[cxx-interop] Support ObjC classes in generic context in reverse interop
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include "swift/Strings.h"
|
||||
|
||||
#include "clang/AST/Decl.h"
|
||||
#include "clang/AST/DeclObjC.h"
|
||||
#include "clang/Basic/Module.h"
|
||||
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
@@ -539,10 +540,20 @@ public:
|
||||
}
|
||||
|
||||
void emitReferencedClangTypeMetadata(const TypeDecl *typeDecl) {
|
||||
if (!isa<clang::TypeDecl>(typeDecl->getClangDecl()))
|
||||
const auto *clangDecl = typeDecl->getClangDecl();
|
||||
if (const auto *objCInt = dyn_cast<clang::ObjCInterfaceDecl>(clangDecl)) {
|
||||
auto clangType = clangDecl->getASTContext()
|
||||
.getObjCInterfaceType(objCInt)
|
||||
.getCanonicalType();
|
||||
auto it = seenClangTypes.insert(clangType.getTypePtr());
|
||||
if (it.second)
|
||||
ClangValueTypePrinter::printClangTypeSwiftGenericTraits(os, typeDecl, &M,
|
||||
printer);
|
||||
return;
|
||||
}
|
||||
if (!isa<clang::TypeDecl>(clangDecl))
|
||||
return;
|
||||
// Get the underlying clang type from a type alias decl or record decl.
|
||||
auto clangDecl = typeDecl->getClangDecl();
|
||||
auto clangType = clangDecl->getASTContext()
|
||||
.getTypeDeclType(cast<clang::TypeDecl>(clangDecl))
|
||||
.getCanonicalType();
|
||||
@@ -568,6 +579,8 @@ public:
|
||||
forwardDeclareCxxValueTypeIfNeeded(NTD);
|
||||
else if (isa<StructDecl>(TD) && NTD->hasClangNode())
|
||||
emitReferencedClangTypeMetadata(NTD);
|
||||
else if (isa<ClassDecl>(TD) && TD->isObjC())
|
||||
emitReferencedClangTypeMetadata(NTD);
|
||||
} else if (auto TAD = dyn_cast<TypeAliasDecl>(TD)) {
|
||||
if (TAD->hasClangNode())
|
||||
emitReferencedClangTypeMetadata(TAD);
|
||||
|
||||
Reference in New Issue
Block a user