Skip to content

Commit 83b6b84

Browse files
authored
[swift2objc] Add toll free bridged types (#2486)
1 parent 830e9cf commit 83b6b84

File tree

3 files changed

+173
-7
lines changed

3 files changed

+173
-7
lines changed

pkgs/swift2objc/lib/src/ast/declarations/built_in/built_in_declaration.dart

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,78 @@ class BuiltInDeclaration extends AstNode
3131
void visit(Visitation visitation) => visitation.visitBuiltInDeclaration(this);
3232
}
3333

34-
const _objectDecl =
35-
BuiltInDeclaration(id: 'c:objc(cs)NSObject', name: 'NSObject');
36-
const _stringDecl = BuiltInDeclaration(id: 's:SS', name: 'String');
3734
const _intDecl = BuiltInDeclaration(id: 's:Si', name: 'Int');
3835
const _floatDecl = BuiltInDeclaration(id: 's:Sf', name: 'Float');
3936
const _doubleDecl = BuiltInDeclaration(id: 's:Sd', name: 'Double');
4037
const _boolDecl = BuiltInDeclaration(id: 's:Sb', name: 'Bool');
4138
const _voidDecl = BuiltInDeclaration(id: 's:s4Voida', name: 'Void');
4239

40+
// Certain types are toll-free bridged between Swift and ObjC. These types don't
41+
// need @objc compatible wrappers. There's no complete list of these types in
42+
// the documentation. The closest thing is this, but it's incomplete:
43+
// https://developer.apple.com/documentation/swift/working-with-foundation-types
44+
// TODO(https://github.com/dart-lang/native/issues/2485): Add Array, Set, and
45+
// Dictionary to this list.
46+
const _objectDecl =
47+
BuiltInDeclaration(id: 'c:objc(cs)NSObject', name: 'NSObject');
48+
const _errorDecl = BuiltInDeclaration(id: 'c:objc(cs)NSError', name: 'NSError');
49+
const _affineTransformDecl = BuiltInDeclaration(
50+
id: 's:10Foundation15AffineTransformV', name: 'AffineTransform');
51+
const _calendarDecl =
52+
BuiltInDeclaration(id: 's:10Foundation8CalendarV', name: 'Calendar');
53+
const _characterSetDecl = BuiltInDeclaration(
54+
id: 's:10Foundation12CharacterSetV', name: 'CharacterSet');
55+
const _dataDecl = BuiltInDeclaration(id: 's:10Foundation4DataV', name: 'Data');
56+
const _dateDecl = BuiltInDeclaration(id: 's:10Foundation4DateV', name: 'Date');
57+
const _dateComponentsDecl = BuiltInDeclaration(
58+
id: 's:10Foundation14DateComponentsV', name: 'DateComponents');
59+
const _dateIntervalDecl = BuiltInDeclaration(
60+
id: 's:10Foundation12DateIntervalV', name: 'DateInterval');
61+
const _indexPathDecl =
62+
BuiltInDeclaration(id: 's:10Foundation9IndexPathV', name: 'IndexPath');
63+
const _indexSetDecl =
64+
BuiltInDeclaration(id: 's:10Foundation8IndexSetV', name: 'IndexSet');
65+
const _localeDecl =
66+
BuiltInDeclaration(id: 's:10Foundation6LocaleV', name: 'Locale');
67+
const _notificationDecl = BuiltInDeclaration(
68+
id: 's:10Foundation12NotificationV', name: 'Notification');
69+
const _stringDecl = BuiltInDeclaration(id: 's:SS', name: 'String');
70+
const _timeZoneDecl =
71+
BuiltInDeclaration(id: 's:10Foundation8TimeZoneV', name: 'TimeZone');
72+
const _urlDecl = BuiltInDeclaration(id: 's:10Foundation3URLV', name: 'URL');
73+
const _urlComponentsDecl = BuiltInDeclaration(
74+
id: 's:10Foundation13URLComponentsV', name: 'URLComponents');
75+
const _urlQueryItemDecl = BuiltInDeclaration(
76+
id: 's:10Foundation12URLQueryItemV', name: 'URLQueryItem');
77+
const _urlRequestDecl =
78+
BuiltInDeclaration(id: 's:10Foundation10URLRequestV', name: 'URLRequest');
79+
const _uuidDecl = BuiltInDeclaration(id: 's:10Foundation4UUIDV', name: 'UUID');
80+
4381
const builtInDeclarations = [
82+
_affineTransformDecl,
83+
_boolDecl,
84+
_calendarDecl,
85+
_characterSetDecl,
86+
_dataDecl,
87+
_dateComponentsDecl,
88+
_dateDecl,
89+
_dateIntervalDecl,
90+
_doubleDecl,
91+
_errorDecl,
92+
_floatDecl,
93+
_indexPathDecl,
94+
_indexSetDecl,
95+
_intDecl,
96+
_localeDecl,
97+
_notificationDecl,
4498
_objectDecl,
4599
_stringDecl,
46-
_intDecl,
47-
_floatDecl,
48-
_doubleDecl,
49-
_boolDecl,
100+
_timeZoneDecl,
101+
_urlComponentsDecl,
102+
_urlDecl,
103+
_urlQueryItemDecl,
104+
_urlRequestDecl,
105+
_uuidDecl,
50106
_voidDecl,
51107
];
52108

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import Foundation
2+
3+
// TODO(https://github.com/dart-lang/native/issues/2485): Uncomment the Array,
4+
// Dictionary, and Set functions.
5+
6+
public func funcAffineTransform() -> AffineTransform? { return nil; }
7+
// public func funcArray() -> Array<String>? { return nil; }
8+
public func funcCalendar() -> Calendar? { return nil; }
9+
public func funcCharacterSet() -> CharacterSet? { return nil; }
10+
public func funcData() -> Data? { return nil; }
11+
public func funcDate() -> Date? { return nil; }
12+
public func funcDateComponents() -> DateComponents? { return nil; }
13+
public func funcDateInterval() -> DateInterval? { return nil; }
14+
// public func funcDictionary() -> Dictionary<String, String>? { return nil; }
15+
public func funcIndexPath() -> IndexPath? { return nil; }
16+
public func funcIndexSet() -> IndexSet? { return nil; }
17+
public func funcLocale() -> Locale? { return nil; }
18+
public func funcNotification() -> Notification? { return nil; }
19+
public func funcNSError() -> NSError? { return nil; }
20+
// public func funcSet() -> Set<String>? { return nil; }
21+
public func funcString() -> String? { return nil; }
22+
public func funcTimeZone() -> TimeZone? { return nil; }
23+
public func funcURL() -> URL? { return nil; }
24+
public func funcURLComponents() -> URLComponents? { return nil; }
25+
public func funcURLQueryItem() -> URLQueryItem? { return nil; }
26+
public func funcURLRequest() -> URLRequest? { return nil; }
27+
public func funcUUID() -> UUID? { return nil; }
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Test preamble text
2+
3+
import Foundation
4+
5+
@objc public class GlobalsWrapper: NSObject {
6+
@objc static public func funcLocaleWrapper() -> Locale? {
7+
return funcLocale()
8+
}
9+
10+
@objc static public func funcStringWrapper() -> String? {
11+
return funcString()
12+
}
13+
14+
@objc static public func funcNSErrorWrapper() -> NSError? {
15+
return funcNSError()
16+
}
17+
18+
@objc static public func funcCalendarWrapper() -> Calendar? {
19+
return funcCalendar()
20+
}
21+
22+
@objc static public func funcIndexSetWrapper() -> IndexSet? {
23+
return funcIndexSet()
24+
}
25+
26+
@objc static public func funcTimeZoneWrapper() -> TimeZone? {
27+
return funcTimeZone()
28+
}
29+
30+
@objc static public func funcIndexPathWrapper() -> IndexPath? {
31+
return funcIndexPath()
32+
}
33+
34+
@objc static public func funcURLRequestWrapper() -> URLRequest? {
35+
return funcURLRequest()
36+
}
37+
38+
@objc static public func funcCharacterSetWrapper() -> CharacterSet? {
39+
return funcCharacterSet()
40+
}
41+
42+
@objc static public func funcDateIntervalWrapper() -> DateInterval? {
43+
return funcDateInterval()
44+
}
45+
46+
@objc static public func funcNotificationWrapper() -> Notification? {
47+
return funcNotification()
48+
}
49+
50+
@objc static public func funcURLQueryItemWrapper() -> URLQueryItem? {
51+
return funcURLQueryItem()
52+
}
53+
54+
@objc static public func funcURLComponentsWrapper() -> URLComponents? {
55+
return funcURLComponents()
56+
}
57+
58+
@objc static public func funcDateComponentsWrapper() -> DateComponents? {
59+
return funcDateComponents()
60+
}
61+
62+
@objc static public func funcAffineTransformWrapper() -> AffineTransform? {
63+
return funcAffineTransform()
64+
}
65+
66+
@objc static public func funcURLWrapper() -> URL? {
67+
return funcURL()
68+
}
69+
70+
@objc static public func funcDataWrapper() -> Data? {
71+
return funcData()
72+
}
73+
74+
@objc static public func funcDateWrapper() -> Date? {
75+
return funcDate()
76+
}
77+
78+
@objc static public func funcUUIDWrapper() -> UUID? {
79+
return funcUUID()
80+
}
81+
82+
}
83+

0 commit comments

Comments
 (0)