compnerd updated this revision to Diff 291346.
compnerd edited the summary of this revision.
compnerd added a comment.
Address feedback
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87396/new/
https://reviews.llvm.org/D87396
Files:
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test
clang/test/SemaObjC/attr-swift_bridged_typedef.m
Index: clang/test/SemaObjC/attr-swift_bridged_typedef.m
===================================================================
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_bridged_typedef.m
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+@interface NSString
+@end
+
+typedef NSString *NSStringAlias __attribute__((__swift_bridged_typedef__));
+
+struct __attribute__((swift_bridged_typedef)) S {};
+// expected-error@-1 {{'swift_bridged_typedef' attribute only applies to
typedefs}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===================================================================
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -146,6 +146,7 @@
// CHECK-NEXT: Section (SubjectMatchRule_function,
SubjectMatchRule_variable_is_global, SubjectMatchRule_objc_method,
SubjectMatchRule_objc_property)
// CHECK-NEXT: SetTypestate (SubjectMatchRule_function_is_member)
// CHECK-NEXT: SpeculativeLoadHardening (SubjectMatchRule_function,
SubjectMatchRule_objc_method)
+// CHECK-NEXT: SwiftBridgedTypedef (SubjectMatchRule_type_alias)
// CHECK-NEXT: SwiftContext (SubjectMatchRule_variable_is_parameter)
// CHECK-NEXT: SwiftError (SubjectMatchRule_function,
SubjectMatchRule_objc_method)
// CHECK-NEXT: SwiftErrorResult (SubjectMatchRule_variable_is_parameter)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -7533,6 +7533,9 @@
break;
// Swift attributes.
+ case ParsedAttr::AT_SwiftBridgedTypedef:
+ handleSimpleAttribute<SwiftBridgedTypedefAttr>(S, D, AL);
+ break;
case ParsedAttr::AT_SwiftError:
handleSwiftError(S, D, AL);
break;
Index: clang/include/clang/Basic/AttrDocs.td
===================================================================
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -3476,6 +3476,27 @@
}];
}
+def SwiftBridgedTypedefDocs : Documentation {
+ let Category = SwiftDocs;
+ let Heading = "swift_bridged";
+ let Content = [{
+The ``swift_bridged_typedef`` attribute indicates that when the typedef to
which
+the attribute appertains is imported into Swift, it should refer to the bridged
+Swift type (e.g. Swift's ``String``) rather than the Objective-C type as
written
+(e.g. ``NSString``).
+
+ .. code-block:: c
+
+ @interface NSString;
+ typedef NSString *AliasedString __attribute__((__swift_bridged_typedef__));
+
+ extern void acceptsAliasedString(AliasedString _Nonnull parameter);
+
+In this case, the function ``acceptsAliasedString`` will be imported into Swift
+as a function which accepts a ``String`` type parameter.
+ }];
+}
+
def SwiftObjCMembersDocs : Documentation {
let Category = SwiftDocs;
let Heading = "swift_objc_members";
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2130,6 +2130,12 @@
let ASTNode = 0;
}
+def SwiftBridgedTypedef : Attr {
+ let Spellings = [GNU<"swift_bridged_typedef">];
+ let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+ let Documentation = [SwiftBridgedTypedefDocs];
+}
+
def SwiftObjCMembers : Attr {
let Spellings = [GNU<"swift_objc_members">];
let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
Index: clang/test/SemaObjC/attr-swift_bridged_typedef.m
===================================================================
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_bridged_typedef.m
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+@interface NSString
+@end
+
+typedef NSString *NSStringAlias __attribute__((__swift_bridged_typedef__));
+
+struct __attribute__((swift_bridged_typedef)) S {};
+// expected-error@-1 {{'swift_bridged_typedef' attribute only applies to typedefs}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===================================================================
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -146,6 +146,7 @@
// CHECK-NEXT: Section (SubjectMatchRule_function, SubjectMatchRule_variable_is_global, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property)
// CHECK-NEXT: SetTypestate (SubjectMatchRule_function_is_member)
// CHECK-NEXT: SpeculativeLoadHardening (SubjectMatchRule_function, SubjectMatchRule_objc_method)
+// CHECK-NEXT: SwiftBridgedTypedef (SubjectMatchRule_type_alias)
// CHECK-NEXT: SwiftContext (SubjectMatchRule_variable_is_parameter)
// CHECK-NEXT: SwiftError (SubjectMatchRule_function, SubjectMatchRule_objc_method)
// CHECK-NEXT: SwiftErrorResult (SubjectMatchRule_variable_is_parameter)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -7533,6 +7533,9 @@
break;
// Swift attributes.
+ case ParsedAttr::AT_SwiftBridgedTypedef:
+ handleSimpleAttribute<SwiftBridgedTypedefAttr>(S, D, AL);
+ break;
case ParsedAttr::AT_SwiftError:
handleSwiftError(S, D, AL);
break;
Index: clang/include/clang/Basic/AttrDocs.td
===================================================================
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -3476,6 +3476,27 @@
}];
}
+def SwiftBridgedTypedefDocs : Documentation {
+ let Category = SwiftDocs;
+ let Heading = "swift_bridged";
+ let Content = [{
+The ``swift_bridged_typedef`` attribute indicates that when the typedef to which
+the attribute appertains is imported into Swift, it should refer to the bridged
+Swift type (e.g. Swift's ``String``) rather than the Objective-C type as written
+(e.g. ``NSString``).
+
+ .. code-block:: c
+
+ @interface NSString;
+ typedef NSString *AliasedString __attribute__((__swift_bridged_typedef__));
+
+ extern void acceptsAliasedString(AliasedString _Nonnull parameter);
+
+In this case, the function ``acceptsAliasedString`` will be imported into Swift
+as a function which accepts a ``String`` type parameter.
+ }];
+}
+
def SwiftObjCMembersDocs : Documentation {
let Category = SwiftDocs;
let Heading = "swift_objc_members";
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2130,6 +2130,12 @@
let ASTNode = 0;
}
+def SwiftBridgedTypedef : Attr {
+ let Spellings = [GNU<"swift_bridged_typedef">];
+ let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+ let Documentation = [SwiftBridgedTypedefDocs];
+}
+
def SwiftObjCMembers : Attr {
let Spellings = [GNU<"swift_objc_members">];
let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits