Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
Fix nits
Browse files Browse the repository at this point in the history
  • Loading branch information
liamappelbe committed Oct 10, 2023
1 parent 0581992 commit fa682f5
Show file tree
Hide file tree
Showing 12 changed files with 1,607 additions and 13,894 deletions.
1 change: 1 addition & 0 deletions example/c_json/cjson_generated_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,7 @@ final class cJSON_Hooks extends ffi.Struct {
}

typedef cJSON_bool = ffi.Int;

typedef DartcJSON_bool = int;

const int CJSON_VERSION_MAJOR = 1;
Expand Down
2,418 changes: 1,445 additions & 973 deletions example/libclang-example/generated_bindings.dart

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions lib/src/code_generator/typealias.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import 'writer.dart';
/// ```
class Typealias extends BindingType {
final Type type;
bool _genFfiDartType;
String? _ffiDartAliasName;
String? _dartAliasName;

Expand Down Expand Up @@ -74,7 +73,11 @@ class Typealias extends BindingType {
required this.type,
bool genFfiDartType = false,
bool isInternal = false,
}) : _genFfiDartType = genFfiDartType,
}) : _ffiDartAliasName = genFfiDartType ? 'Dart$name' : null,
_dartAliasName =
(!genFfiDartType && type is! Typealias && !type.sameDartAndCType)
? 'Dart$name'
: null,
super(
usr: usr,
name: genFfiDartType ? 'Native$name' : name,
Expand All @@ -100,26 +103,23 @@ class Typealias extends BindingType {

@override
BindingString toBindingString(Writer w) {
if (_ffiDartAliasName == null && _genFfiDartType) {
_ffiDartAliasName = w.topLevelUniqueNamer.makeUnique('Dart$name');
if (_ffiDartAliasName != null) {
_ffiDartAliasName = w.topLevelUniqueNamer.makeUnique(_ffiDartAliasName!);
}
if (_dartAliasName == null &&
!_genFfiDartType &&
type is! Typealias &&
!type.sameDartAndCType) {
_dartAliasName = w.topLevelUniqueNamer.makeUnique('Dart$name');
if (_dartAliasName != null) {
_dartAliasName = w.topLevelUniqueNamer.makeUnique(_dartAliasName!);
}

final sb = StringBuffer();
if (dartDoc != null) {
sb.write(makeDartDoc(dartDoc!));
}
sb.write('typedef $name = ${type.getCType(w)};\n');
sb.write('typedef $name = ${type.getCType(w)};\n\n');
if (_ffiDartAliasName != null) {
sb.write('typedef $_ffiDartAliasName = ${type.getFfiDartType(w)};\n');
sb.write('typedef $_ffiDartAliasName = ${type.getFfiDartType(w)};\n\n');
}
if (_dartAliasName != null) {
sb.write('typedef $_dartAliasName = ${type.getDartType(w)};\n');
sb.write('typedef $_dartAliasName = ${type.getDartType(w)};\n\n');
}
return BindingString(
type: BindingStringType.typeDef, string: sb.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ignore_for_file: unused_element, camel_case_types, non_constant_identifier_names

// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
Expand All @@ -19,13 +20,15 @@ class Bindings1 {
ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
lookup)
: _lookup = lookup;

void _library() {
return __library();
}

late final __libraryPtr =
_lookup<ffi.NativeFunction<Native_library>>('_library');
late final __library = __libraryPtr.asFunction<void Function()>();
late final __library = __libraryPtr.asFunction<Dart_library>();

void _SymbolAddresses_1() {
return __SymbolAddresses_1();
}
Expand All @@ -34,6 +37,7 @@ class Bindings1 {
_lookup<ffi.NativeFunction<ffi.Void Function()>>('_SymbolAddresses_1');
late final __SymbolAddresses_1 =
__SymbolAddresses_1Ptr.asFunction<void Function()>();

late final addresses = _SymbolAddresses1(this);
}

Expand All @@ -53,4 +57,5 @@ final class _SymbolAddresses extends ffi.Opaque {}
abstract class Bindings {}

typedef Native_library = ffi.Void Function();
typedef DartNative_library = void Function();

typedef Dart_library = void Function();
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class NativeLibrary {
}

typedef Typedef1 = ffi.Pointer<ffi.NativeFunction<Typedef1Function>>;

typedef Typedef1Function = ffi.Void Function(ffi.Handle);

typedef DartTypedef1Function = void Function(Object);

final class Struct1 extends ffi.Opaque {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ final class Struct extends ffi.Struct {

typedef WithTypedefReturnType
= ffi.Pointer<ffi.NativeFunction<WithTypedefReturnTypeFunction>>;

typedef WithTypedefReturnTypeFunction = InsideReturnType Function();

typedef InsideReturnType
= ffi.Pointer<ffi.NativeFunction<InsideReturnTypeFunction>>;

typedef InsideReturnTypeFunction = ffi.Void Function();

typedef DartInsideReturnTypeFunction = void Function();

final class Struct2 extends ffi.Struct {
Expand All @@ -86,5 +90,7 @@ final class Struct2 extends ffi.Struct {

typedef VoidFuncPointer
= ffi.Pointer<ffi.NativeFunction<VoidFuncPointerFunction>>;

typedef VoidFuncPointerFunction = ffi.Void Function();

typedef DartVoidFuncPointerFunction = void Function();
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,42 @@ import 'dart:ffi' as ffi;

final class S extends ffi.Struct {
external ffi.Pointer<ffi.NativeFunction<ffi.Int Function()>> func1;

external ffi
.Pointer<ffi.NativeFunction<ffi.Int Function(ffi.Int a, ffi.Int b)>>
comparator;

external ffi.Pointer<
ffi.NativeFunction<
ffi.Int Function(ffi.Double a, ffi.Float b, ffi.Pointer<ffi.Char> c,
ffi.Int d, ffi.LongLong e)>> veryManyArguments;

external ffi.Pointer<
ffi.NativeFunction<
ffi.Int Function(
ffi.Int, ffi.Int, ffi.Int, ffi.Float, ffi.Pointer<ffi.Char>)>>
argsDontHaveNames;

external ArithmeticOperation operation;

external ffi.Pointer<
ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(ffi.Pointer<ffi.Int> array, ffi.Int len)>>>
sortPtr;

external ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(
ffi.Pointer<ffi.Int> array,
ffi.Int len,
ffi.Pointer<ffi.NativeFunction<ffi.Int Function(ffi.Int x)>>
evaluator)>> sortBy;

external ffi.Pointer<
ffi.NativeFunction<ffi.Void Function(ffi.Int, ffi.Int, ffi.Char)>>
improperlyDeclaredParams;

external ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(
Expand All @@ -42,15 +50,18 @@ final class S extends ffi.Struct {
primaryEvaluator,
ffi.Pointer<ffi.NativeFunction<ffi.Int Function(ffi.Int x)>>
fallbackEvaluator)>> sortByWithFallback;

@ffi.Array.multi([2])
external ffi.Array<
ffi
.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Char, ffi.Char)>>>
manyFunctions;

external ffi.Pointer<
ffi.NativeFunction<
ffi.Pointer<ffi.NativeFunction<ffi.Int Function(ffi.Int, ffi.Int)>>
Function(ffi.Int, ffi.Int)>> functionReturningFunction;

external ffi.Pointer<
ffi.NativeFunction<
ffi.Pointer<ffi.NativeFunction<ffi.Int Function(ffi.Int, ffi.Int)>>
Expand All @@ -59,5 +70,7 @@ final class S extends ffi.Struct {

typedef ArithmeticOperation
= ffi.Pointer<ffi.NativeFunction<ArithmeticOperationFunction>>;

typedef ArithmeticOperationFunction = ffi.Int Function(ffi.Int a, ffi.Int b);

typedef DartArithmeticOperationFunction = int Function(int a, int b);
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,17 @@ final class Struct1 extends ffi.Struct {

typedef NamedFunctionProto
= ffi.Pointer<ffi.NativeFunction<NamedFunctionProtoFunction>>;

typedef NamedFunctionProtoFunction = ffi.Void Function();

typedef DartNamedFunctionProtoFunction = void Function();

final class AnonymousStructInTypedef extends ffi.Opaque {}

final class _NamedStructInTypedef extends ffi.Opaque {}

typedef NTyperef1 = ExcludedStruct;

typedef ExcludedStruct = _ExcludedStruct;

final class _ExcludedStruct extends ffi.Opaque {}
Expand All @@ -114,6 +117,7 @@ abstract class _NamedEnumInTypedef {
}

typedef NestingASpecifiedType = ffi.IntPtr;

typedef DartNestingASpecifiedType = int;

final class Struct2 extends ffi.Opaque {}
Expand Down
Loading

0 comments on commit fa682f5

Please sign in to comment.