Skip to content
Closed

ignore #10232

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
eb7cac6
methods, basic types, sync, nullable-sync, async, and classes
tarrinneal Apr 15, 2025
9fa695d
broken nullable async methods
tarrinneal Apr 15, 2025
0aff0fd
refactor type logic, add codec
tarrinneal Apr 17, 2025
1ed8a8b
objects and enums
tarrinneal Apr 22, 2025
ee50607
full codec
tarrinneal May 9, 2025
4c6eb1a
error handling and more tests
tarrinneal May 29, 2025
f87efd4
fix codec
tarrinneal May 29, 2025
3e9d9f0
flutter api and plumbing through legacy apis and tests
tarrinneal Jun 27, 2025
6ad2e37
jnigen.yaml
tarrinneal Jun 27, 2025
9b55d44
ffi just getting started
tarrinneal Jul 7, 2025
25e8c30
gen fluff
tarrinneal Jul 11, 2025
df40332
not working
tarrinneal Jul 16, 2025
d90ecca
missing files
tarrinneal Jul 17, 2025
92933f8
gitignore
tarrinneal Jul 17, 2025
cb1c0fe
ios ffigen settings
tarrinneal Jul 17, 2025
a7cc7ce
remove macos min version from ffigen config
tarrinneal Jul 17, 2025
8fb8dca
no dylibs
tarrinneal Jul 17, 2025
ab64302
more basic, still can't see class
tarrinneal Jul 17, 2025
c7d00c6
upload macos
tarrinneal Jul 17, 2025
33f8fa1
fix ffigen files
tarrinneal Jul 17, 2025
4977cc2
test
tarrinneal Jul 29, 2025
586edf2
wip
tarrinneal Jul 29, 2025
74b1cb1
Merge branch 'Frillback' of github.com:tarrinneal/packages into Frill…
tarrinneal Jul 29, 2025
3736528
ns
tarrinneal Jul 29, 2025
31d182f
dunno
tarrinneal Jul 30, 2025
c63e598
something
tarrinneal Jul 30, 2025
6dc23e7
working again
tarrinneal Jul 30, 2025
982dfe6
Merge branch 'Frillback' of https://github.com/tarrinneal/packages in…
tarrinneal Jul 30, 2025
ecc088a
enums
tarrinneal Aug 12, 2025
927fd8d
and this one
tarrinneal Aug 12, 2025
877d60d
ffi support for classes, enums, and objects (partial testing)
tarrinneal Aug 26, 2025
910ac95
tests
tarrinneal Aug 26, 2025
b522d6c
fix enums, still need to resolve Any?
tarrinneal Sep 4, 2025
bd47b34
actually fix enums
tarrinneal Sep 5, 2025
4192a89
starting nullables, gonna be a mess
tarrinneal Sep 5, 2025
86e6907
nullable base types in classes
tarrinneal Sep 17, 2025
87f4f8a
add nullable enums (no tests for null things though.....)
tarrinneal Sep 18, 2025
ed3eb93
update to latest version
tarrinneal Sep 19, 2025
457edef
Not even I understand
tarrinneal Sep 24, 2025
9214479
fix null object?
tarrinneal Sep 25, 2025
aadd859
multi-arity and nullable enums in classes
tarrinneal Sep 26, 2025
8cb24b6
nested classes
tarrinneal Sep 27, 2025
d29e86a
typed lists and maps except int keys
tarrinneal Oct 14, 2025
b32d506
Merge branch 'main' of https://github.com/flutter/packages into Frill…
tarrinneal Oct 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix enums, still need to resolve Any?
  • Loading branch information
tarrinneal committed Sep 4, 2025
commit b522d6cfcd3025e4348cd037a2f02463d5a2b0ae
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ analyzer:
# Ignore generated files
- '**/*.g.dart'
- '**/*.gen.jni.dart'
- '**/*.gen.ffi.dart'
- '**/*.mocks.dart' # Mockito @GenerateMocks

linter:
Expand Down
26 changes: 15 additions & 11 deletions packages/pigeon/lib/src/dart/dart_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class _FfiType {

String get fullFfiName {
if (type.baseName == 'List' || type.baseName == 'Map') {
return ffiName + ffiCollectionTypeAnnotations;
return ffiName;
}
return ffiName;
}
Expand Down Expand Up @@ -263,7 +263,7 @@ class _FfiType {
String asType = ' as ${getDartReturnType(true)}';
String castCall = '';
final String codecCall =
'_PigeonFfiCodec.readValue($varName)${_getForceNonNullSymbol(!type.isNullable)}';
'_PigeonFfiCodec.readValue($varName${type.isEnum ? ', ${type.baseName}' : ''})${_getForceNonNullSymbol(!type.isNullable)}';
String primitiveGetter(String converter, bool classField) {
return classField &&
!type.isNullable &&
Expand Down Expand Up @@ -322,14 +322,17 @@ class _FfiType {
type.baseName == 'bool')) {
return name;
}
return '_PigeonFfiCodec.writeValue<${getFfiCallReturnType(type.isNullable)}>($name)';
return '_PigeonFfiCodec.writeValue<${ffiType.ffiName}>($name)';
}

String getFfiCallReturnType(bool forceUnwrap, {bool forceNullable = false}) {
if (type.isEnum && forceNullable) {
return 'NSNumber?';
}
return '$ffiName$ffiCollectionTypeAnnotations${_getNullableSymbol(forceNullable || type.isNullable)}';
if (type.baseName == 'List') {
return 'NSArray?';
}
return '$ffiName${_getNullableSymbol(forceNullable || type.isNullable)}';
}

String getDartReturnType(bool forceUnwrap) {
Expand Down Expand Up @@ -1708,12 +1711,10 @@ class DartGenerator extends StructuredGenerator<InternalDartOptions> {
final _FfiType returnType = _FfiType.fromTypeDeclaration(
method.returnType,
);
final String methodCallReturnString = returnType.type.isVoid &&
final String methodCallReturnString = returnType.type.isVoid ||
method.isAsynchronous
? ''
: (returnType.type.isVoid)
? ''
: 'final ${returnType.getFfiCallReturnType(method.isAsynchronous, forceNullable: true)} res = ';
: 'final ${returnType.getFfiCallReturnType(method.isAsynchronous, forceNullable: true)} res = ';
indent.writeln(
'final ffi_bridge.${generatorOptions.ffiErrorClassName} error = ffi_bridge.${generatorOptions.ffiErrorClassName}();');
indent.writeln(
Expand Down Expand Up @@ -2679,6 +2680,9 @@ class _PigeonFfiCodec {
return value.doubleValue;
case const (bool):
return value.boolValue;
${root.enums.map((Enum enumDefinition) => '''
case const (${enumDefinition.name}):
return ${enumDefinition.name}.fromNSNumber(value);''').join('\n')}
default:
throw ArgumentError.value(value);
}
Expand Down Expand Up @@ -2708,16 +2712,16 @@ class _PigeonFfiCodec {
// list[i] = value.as(NSDoubleArray.type)[i];
// }
// return list;
} else if (value is NSMutableArray) {
} else if (value is NSArray) {
final List<Object?> res = <Object?>[];
for (int i = 0; i < value.length; i++) {
res.add(readValue(value[i] as NSObject?));
res.add(readValue(value[i]));
}
return res;
} else if (value is NSDictionary) {
final Map<Object?, Object?> res = <Object?, Object?>{};
for (final MapEntry<NSCopying?, ObjCObjectBase?> entry in value.entries) {
res[readValue(entry.key as NSObject?)] = readValue(entry.value as NSObject?);
res[readValue(entry.key)] = readValue(entry.value);
}
return res;
} else if (ffi_bridge.NSNumberWrapper.isInstance(value)) {
Expand Down
14 changes: 8 additions & 6 deletions packages/pigeon/lib/src/swift/swift_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class InternalSwiftOptions extends InternalOptions {
/// Module to use for FFI.
final String? ffiModuleName;

/// The directory that the app exists in, this is required for Jni APIs.
/// The directory that the app exists in, this is required for FFi APIs.
final String? appDirectory;
}

Expand Down Expand Up @@ -283,6 +283,7 @@ class SwiftGenerator extends StructuredGenerator<InternalSwiftOptions> {
void _writeFfiCodec(Indent indent, Root root) {
indent.newln();
indent.format('''
@available(iOS 13, macOS 16.0.0, *)
class _PigeonFfiCodec {
static func readValue(value: NSObject?, type: String?) -> Any? {
if (isNullish(value)) {
Expand Down Expand Up @@ -326,7 +327,7 @@ class _PigeonFfiCodec {
// list[i] = value.as(NSDoubleArray.type)[i]
// // }
// return list
if (value is NSMutableArray) {
if (value is NSMutableArray || value is NSArray) {
var res: Array<Any?> = []
for i in 0..<(value as! NSMutableArray).count {
res.append(readValue(value: (value as! NSMutableArray)[i] as? NSObject, type: nil))
Expand All @@ -336,7 +337,7 @@ class _PigeonFfiCodec {
if (value is NSDictionary) {
var res: Dictionary<AnyHashable?, Any?> = Dictionary()
for (key, value) in (value as! NSDictionary) {
res[readValue(value: key as? NSObject, type: nil) as! AnyHashable?] = readValue(value: value as? NSObject, type: nil)
res[readValue(value: key as? NSObject, type: nil) as? AnyHashable] = readValue(value: value as? NSObject, type: nil)
}
return res
}
Expand Down Expand Up @@ -403,14 +404,14 @@ class _PigeonFfiCodec {
if (value is Array<Any>) {
let res: NSMutableArray = NSMutableArray()
for i in 0..<(value as! NSMutableArray).count {
res.add(writeValue(value: (value as! NSMutableArray)[i])!)
res.add(writeValue(value: (value as! NSMutableArray)[i]) as! NSObject)
}
return res
}
if (value is Dictionary<AnyHashable, Any>) {
let res: NSMutableDictionary = NSMutableDictionary()
for (key, value) in (value as! NSDictionary) {
res.setObject(writeValue(value: value) as Any, forKey: writeValue(value: key) as! NSCopying)
res.setObject(writeValue(value: value) as! NSObject, forKey: writeValue(value: key) as! NSCopying)
}
return res
}
Expand Down Expand Up @@ -955,6 +956,7 @@ if (wrapped == nil) {
for (final Method method in api.methods) {
addDocumentationComments(
indent, method.documentationComments, _docCommentSpec);
indent.writeln('@available(iOS 13, macOS 16.0.0, *)');
indent.write(_getMethodSignature(
name: method.name,
parameters: method.parameters,
Expand All @@ -972,7 +974,7 @@ if (wrapped == nil) {
indent.writeln(
'return try ${_swiftToFfiConversion(method.returnType, 'api!.${method.name}(${method.parameters.map((NamedType param) {
return '${param.name}: ${_ffiToSwiftConversion(param)}';
}).join(', ')})')}');
}).join(', ')})')}${method.returnType.baseName == 'List' || method.returnType.baseName == 'Map' ? ' as? ${_ffiTypeForBuiltinGenericDartType(method.returnType)}' : ''}');
},
addTrailingNewline: false,
);
Expand Down
Loading