@@ -44,7 +44,6 @@ class ObjCBuiltInFunctions {
4444 static const protocolListenableMethod =
4545 ObjCImport ('ObjCProtocolListenableMethod' );
4646 static const protocolBuilder = ObjCImport ('ObjCProtocolBuilder' );
47- static const dartProxy = ObjCImport ('DartProxy' );
4847 static const unimplementedOptionalMethodException =
4948 ObjCImport ('UnimplementedOptionalMethodException' );
5049 static const checkOsVersion = ObjCImport ('checkOsVersion' );
@@ -54,8 +53,8 @@ class ObjCBuiltInFunctions {
5453 @visibleForTesting
5554 static const builtInInterfaces = {
5655 'DartInputStreamAdapter' ,
57- 'DartProxy ' ,
58- 'DartProxyBuilder ' ,
56+ 'DartProtocol ' ,
57+ 'DartProtocolBuilder ' ,
5958 'NSArray' ,
6059 'NSCharacterSet' ,
6160 'NSCoder' ,
@@ -83,7 +82,6 @@ class ObjCBuiltInFunctions {
8382 'NSOrderedCollectionDifference' ,
8483 'NSOrderedSet' ,
8584 'NSOutputStream' ,
86- 'NSProxy' ,
8785 'NSRunLoop' ,
8886 'NSSet' ,
8987 'NSStream' ,
@@ -178,12 +176,9 @@ class ObjCBuiltInFunctions {
178176 ObjCMsgSendFunc getMsgSendFunc (Type returnType, List <Parameter > params) {
179177 params = _methodSigParams (params);
180178 returnType = _methodSigType (returnType);
181- final id = _methodSigId (returnType, params);
179+ final (id, idHash) = _methodSigId (returnType, params);
182180 return _msgSendFuncs[id] ?? = ObjCMsgSendFunc (
183- '_objc_msgSend_${fnvHash32 (id ).toRadixString (36 )}' ,
184- returnType,
185- params,
186- useMsgSendVariants);
181+ '_objc_msgSend_$idHash ' , returnType, params, useMsgSendVariants);
187182 }
188183
189184 final _selObjects = < String , ObjCInternalGlobal > {};
@@ -194,7 +189,7 @@ class ObjCBuiltInFunctions {
194189 );
195190 }
196191
197- String _methodSigId (Type returnType, List <Parameter > params) {
192+ ( String , String ) _methodSigId (Type returnType, List <Parameter > params) {
198193 final paramIds = < String > [];
199194 for (final p in params) {
200195 // The trampoline ID is based on the getNativeType of the param. Objects
@@ -205,7 +200,8 @@ class ObjCBuiltInFunctions {
205200 }
206201 final rt =
207202 returnType.getNativeType (varName: returnType.generateRetain ('' ) ?? '' );
208- return '$rt ,${paramIds .join (',' )}' ;
203+ final id = '$rt ,${paramIds .join (',' )}' ;
204+ return (id, fnvHash32 (id).toRadixString (36 ));
209205 }
210206
211207 Type _methodSigType (Type t) {
@@ -242,8 +238,7 @@ class ObjCBuiltInFunctions {
242238
243239 final _blockTrampolines = < String , ObjCBlockWrapperFuncs > {};
244240 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);
247242 return _blockTrampolines[id] ?? = ObjCBlockWrapperFuncs (
248243 _blockTrampolineFunc ('_${wrapperName }_wrapListenerBlock_$idHash ' ),
249244 _blockTrampolineFunc ('_${wrapperName }_wrapBlockingBlock_$idHash ' ,
@@ -285,6 +280,27 @@ class ObjCBuiltInFunctions {
285280 ffiNativeConfig: const FfiNativeConfig (enabled: true ),
286281 );
287282
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+
288304 static bool isInstanceType (Type type) {
289305 if (type is ObjCInstanceType ) return true ;
290306 final baseType = type.typealiasType;
@@ -308,6 +324,24 @@ class ObjCBlockWrapperFuncs extends AstNode {
308324 }
309325}
310326
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+
311345/// A function, global variable, or helper type defined in package:objective_c.
312346class ObjCImport {
313347 final String name;
0 commit comments