@@ -44,7 +44,6 @@ class ObjCBuiltInFunctions {
44
44
static const protocolListenableMethod =
45
45
ObjCImport ('ObjCProtocolListenableMethod' );
46
46
static const protocolBuilder = ObjCImport ('ObjCProtocolBuilder' );
47
- static const dartProxy = ObjCImport ('DartProxy' );
48
47
static const unimplementedOptionalMethodException =
49
48
ObjCImport ('UnimplementedOptionalMethodException' );
50
49
static const checkOsVersion = ObjCImport ('checkOsVersion' );
@@ -54,8 +53,8 @@ class ObjCBuiltInFunctions {
54
53
@visibleForTesting
55
54
static const builtInInterfaces = {
56
55
'DartInputStreamAdapter' ,
57
- 'DartProxy ' ,
58
- 'DartProxyBuilder ' ,
56
+ 'DartProtocol ' ,
57
+ 'DartProtocolBuilder ' ,
59
58
'NSArray' ,
60
59
'NSCharacterSet' ,
61
60
'NSCoder' ,
@@ -83,7 +82,6 @@ class ObjCBuiltInFunctions {
83
82
'NSOrderedCollectionDifference' ,
84
83
'NSOrderedSet' ,
85
84
'NSOutputStream' ,
86
- 'NSProxy' ,
87
85
'NSRunLoop' ,
88
86
'NSSet' ,
89
87
'NSStream' ,
@@ -178,12 +176,9 @@ class ObjCBuiltInFunctions {
178
176
ObjCMsgSendFunc getMsgSendFunc (Type returnType, List <Parameter > params) {
179
177
params = _methodSigParams (params);
180
178
returnType = _methodSigType (returnType);
181
- final id = _methodSigId (returnType, params);
179
+ final (id, idHash) = _methodSigId (returnType, params);
182
180
return _msgSendFuncs[id] ?? = ObjCMsgSendFunc (
183
- '_objc_msgSend_${fnvHash32 (id ).toRadixString (36 )}' ,
184
- returnType,
185
- params,
186
- useMsgSendVariants);
181
+ '_objc_msgSend_$idHash ' , returnType, params, useMsgSendVariants);
187
182
}
188
183
189
184
final _selObjects = < String , ObjCInternalGlobal > {};
@@ -194,7 +189,7 @@ class ObjCBuiltInFunctions {
194
189
);
195
190
}
196
191
197
- String _methodSigId (Type returnType, List <Parameter > params) {
192
+ ( String , String ) _methodSigId (Type returnType, List <Parameter > params) {
198
193
final paramIds = < String > [];
199
194
for (final p in params) {
200
195
// The trampoline ID is based on the getNativeType of the param. Objects
@@ -205,7 +200,8 @@ class ObjCBuiltInFunctions {
205
200
}
206
201
final rt =
207
202
returnType.getNativeType (varName: returnType.generateRetain ('' ) ?? '' );
208
- return '$rt ,${paramIds .join (',' )}' ;
203
+ final id = '$rt ,${paramIds .join (',' )}' ;
204
+ return (id, fnvHash32 (id).toRadixString (36 ));
209
205
}
210
206
211
207
Type _methodSigType (Type t) {
@@ -242,8 +238,7 @@ class ObjCBuiltInFunctions {
242
238
243
239
final _blockTrampolines = < String , ObjCBlockWrapperFuncs > {};
244
240
ObjCBlockWrapperFuncs ? getBlockTrampolines (ObjCBlock block) {
245
- final id = _methodSigId (block.returnType, block.params);
246
- final idHash = fnvHash32 (id).toRadixString (36 );
241
+ final (id, idHash) = _methodSigId (block.returnType, block.params);
247
242
return _blockTrampolines[id] ?? = ObjCBlockWrapperFuncs (
248
243
_blockTrampolineFunc ('_${wrapperName }_wrapListenerBlock_$idHash ' ),
249
244
_blockTrampolineFunc ('_${wrapperName }_wrapBlockingBlock_$idHash ' ,
@@ -285,6 +280,27 @@ class ObjCBuiltInFunctions {
285
280
ffiNativeConfig: const FfiNativeConfig (enabled: true ),
286
281
);
287
282
283
+ final _protocolTrampolines = < String , ObjCProtocolMethodTrampoline > {};
284
+ ObjCProtocolMethodTrampoline ? getProtocolMethodTrampoline (ObjCBlock block) {
285
+ final (id, idHash) = _methodSigId (block.returnType, block.params);
286
+ return _protocolTrampolines[id] ?? = ObjCProtocolMethodTrampoline (Func (
287
+ name: '_${wrapperName }_protocolTrampoline_$idHash ' ,
288
+ returnType: block.returnType,
289
+ parameters: [
290
+ Parameter (
291
+ name: 'target' ,
292
+ type: PointerType (objCObjectType),
293
+ objCConsumed: false ),
294
+ ...block.params,
295
+ ],
296
+ objCReturnsRetained: false ,
297
+ isLeaf: false ,
298
+ isInternal: true ,
299
+ useNameForLookup: true ,
300
+ ffiNativeConfig: const FfiNativeConfig (enabled: true ),
301
+ ));
302
+ }
303
+
288
304
static bool isInstanceType (Type type) {
289
305
if (type is ObjCInstanceType ) return true ;
290
306
final baseType = type.typealiasType;
@@ -308,6 +324,24 @@ class ObjCBlockWrapperFuncs extends AstNode {
308
324
}
309
325
}
310
326
327
+ /// A native trampoline function for a protocol method.
328
+ class ObjCProtocolMethodTrampoline extends AstNode {
329
+ final Func func;
330
+ bool objCBindingsGenerated = false ;
331
+
332
+ ObjCProtocolMethodTrampoline (this .func);
333
+
334
+ @override
335
+ void visitChildren (Visitor visitor) {
336
+ super .visitChildren (visitor);
337
+ visitor.visit (func);
338
+ }
339
+
340
+ @override
341
+ void visit (Visitation visitation) =>
342
+ visitation.visitObjCProtocolMethodTrampoline (this );
343
+ }
344
+
311
345
/// A function, global variable, or helper type defined in package:objective_c.
312
346
class ObjCImport {
313
347
final String name;
0 commit comments