Skip to content

Commit 1b4f171

Browse files
committed
PrintAsObjC: Add support for @_weakLinked attribute
Clang already takes availability into account when checking if a declaration is weak imported, so this is only needed for testing.
1 parent fbd8b97 commit 1b4f171

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
322322
void visitClassDecl(ClassDecl *CD) {
323323
printDocumentationComment(CD);
324324

325+
// This is just for testing, so we check explicitly for the attribute instead
326+
// of asking if the class is weak imported. If the class has availablility,
327+
// we'll print a SWIFT_AVAIALBLE() which implies __attribute__((weak_imported))
328+
// already.
329+
if (CD->getAttrs().hasAttribute<WeakLinkedAttr>())
330+
os << "SWIFT_WEAK_IMPORT\n";
331+
325332
bool hasResilientAncestry =
326333
CD->checkAncestry().contains(AncestryFlags::ResilientOther);
327334
if (hasResilientAncestry) {
@@ -2717,6 +2724,9 @@ class ModuleWriter {
27172724
"#if !defined(SWIFT_AVAILABILITY)\n"
27182725
"# define SWIFT_AVAILABILITY(plat, ...) __attribute__((availability(plat, __VA_ARGS__)))\n"
27192726
"#endif\n"
2727+
"#if !defined(SWIFT_WEAK_IMPORT)\n"
2728+
"# define SWIFT_WEAK_IMPORT __attribute__((weak_import))\n"
2729+
"#endif\n"
27202730
"#if !defined(SWIFT_DEPRECATED)\n"
27212731
"# define SWIFT_DEPRECATED __attribute__((deprecated))\n"
27222732
"#endif\n"

test/PrintAsObjC/classes.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,3 +805,9 @@ public class NonObjCClass { }
805805
@objc func referenceSingleGenericClass(_: SingleImportedObjCGeneric<AnyObject>?) {}
806806
}
807807
// CHECK: @end
808+
809+
// CHECK: SWIFT_WEAK_IMPORT
810+
// CHECK-NEXT: SWIFT_CLASS("_TtC7classes17WeakImportedClass")
811+
// CHECK-NEXT: @interface WeakImportedClass
812+
// CHECK-NEXT: @end
813+
@_weakLinked @objc class WeakImportedClass {}

0 commit comments

Comments
 (0)