Sema: add support for __attribute__((__swift_objc_members__))

This adds the `__swift_objc_members__` attribute to the semantic
analysis.  It allows for annotating ObjC interfaces to provide Swift
semantics indicating that the types derived from this interface will be
back-bridged to Objective-C to allow interoperability with Objective-C
and Swift.

This is based on the work of the original changes in
8afaf3aad2

Differential Revision: https://reviews.llvm.org/D87395
Reviewed By: Aaron Ballman, Dmitri Gribenko
This commit is contained in:
Saleem Abdulrasool 2020-09-08 22:33:02 +00:00
parent 7526376164
commit 916b434035
5 changed files with 44 additions and 0 deletions

View file

@ -2130,6 +2130,12 @@ def Regparm : TypeAttr {
let ASTNode = 0;
}
def SwiftObjCMembers : Attr {
let Spellings = [GNU<"swift_objc_members">];
let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
let Documentation = [SwiftObjCMembersDocs];
}
def SwiftError : InheritableAttr {
let Spellings = [GNU<"swift_error">];
let Args = [

View file

@ -3476,6 +3476,16 @@ Swift.
}];
}
def SwiftObjCMembersDocs : Documentation {
let Category = SwiftDocs;
let Heading = "swift_objc_members";
let Content = [{
This attribute indicates that Swift subclasses and members of Swift extensions
of this class will be implicitly marked with the ``@objcMembers`` Swift
attribute, exposing them back to Objective-C.
}];
}
def SwiftErrorDocs : Documentation {
let Category = SwiftDocs;
let Heading = "swift_error";

View file

@ -7536,6 +7536,9 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
case ParsedAttr::AT_SwiftError:
handleSwiftError(S, D, AL);
break;
case ParsedAttr::AT_SwiftObjCMembers:
handleSimpleAttribute<SwiftObjCMembersAttr>(S, D, AL);
break;
// XRay attributes.
case ParsedAttr::AT_XRayLogArgs:

View file

@ -150,6 +150,7 @@
// CHECK-NEXT: SwiftError (SubjectMatchRule_function, SubjectMatchRule_objc_method)
// CHECK-NEXT: SwiftErrorResult (SubjectMatchRule_variable_is_parameter)
// CHECK-NEXT: SwiftIndirectResult (SubjectMatchRule_variable_is_parameter)
// CHECK-NEXT: SwiftObjCMembers (SubjectMatchRule_objc_interface)
// CHECK-NEXT: TLSModel (SubjectMatchRule_variable_is_thread_local)
// CHECK-NEXT: Target (SubjectMatchRule_function)
// CHECK-NEXT: TestTypestate (SubjectMatchRule_function_is_member)

View file

@ -0,0 +1,24 @@
// RUN: %clang_cc1 -verify -fsyntax-only %s
#if !__has_attribute(swift_objc_members)
#error cannot verify presence of swift_objc_members attribute
#endif
__attribute__((__swift_objc_members__))
__attribute__((__objc_root_class__))
@interface I
@end
__attribute__((swift_objc_members))
@protocol P
@end
// expected-error@-3 {{'swift_objc_members' attribute only applies to Objective-C interfaces}}
__attribute__((swift_objc_members))
extern void f(void);
// expected-error@-2 {{'swift_objc_members' attribute only applies to Objective-C interfaces}}
// expected-error@+1 {{'__swift_objc_members__' attribute takes no arguments}}
__attribute__((__swift_objc_members__("J")))
@interface J
@end