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

Removed config dart-bool and target Bool / bool #391

Merged
merged 1 commit into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 6.0.0
- Removed config `dart-bool`. Booleans are now always generated with `bool`
and `ffi.Bool` as it's Dart and C Type respectively.

# 5.0.1

- Add a the xcode tools llvm as default path on MacOS.
Expand Down
29 changes: 4 additions & 25 deletions lib/src/code_generator/func.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,39 +98,18 @@ class Func extends LookUpBinding {
p.name = paramNamer.makeUnique(p.name);
}
// Write enclosing function.
if (w.dartBool && functionType.returnType.typealiasType is BooleanType) {
// Use bool return type in enclosing function.
s.write('bool $enclosingFuncName(\n');
} else {
s.write(
'${functionType.returnType.getDartType(w)} $enclosingFuncName(\n');
}
s.write('${functionType.returnType.getDartType(w)} $enclosingFuncName(\n');
for (final p in functionType.parameters) {
if (w.dartBool && p.type.typealiasType is BooleanType) {
// Use bool parameter type in enclosing function.
s.write(' bool ${p.name},\n');
} else {
s.write(' ${p.type.getDartType(w)} ${p.name},\n');
}
s.write(' ${p.type.getDartType(w)} ${p.name},\n');
}
s.write(') {\n');
s.write('return $funcVarName');

s.write('(\n');
for (final p in functionType.parameters) {
if (w.dartBool && p.type.typealiasType is BooleanType) {
// Convert bool parameter to int before calling.
s.write(' ${p.name}?1:0,\n');
} else {
s.write(' ${p.name},\n');
}
}
if (w.dartBool && functionType.returnType.typealiasType is BooleanType) {
// Convert int return type to bool.
s.write(' )!=0;\n');
} else {
s.write(' );\n');
s.write(' ${p.name},\n');
}
s.write(' );\n');
s.write('}\n');

final cType = exposeFunctionTypedefs
Expand Down
2 changes: 0 additions & 2 deletions lib/src/code_generator/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Library {
String? description,
required List<Binding> bindings,
String? header,
bool dartBool = true,
bool sort = false,
StructPackingOverride? packingOverride,
Set<LibraryImport>? libraryImports,
Expand Down Expand Up @@ -75,7 +74,6 @@ class Library {
className: name,
classDocComment: description,
header: header,
dartBool: dartBool,
additionalImports: libraryImports,
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/code_generator/native_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class NativeType extends Type {

class BooleanType extends NativeType {
// Booleans are treated as uint8.
const BooleanType._() : super._('Uint8', 'int', '0');
const BooleanType._() : super._('Bool', 'bool', 'false');
static const _boolean = BooleanType._();
factory BooleanType() => _boolean;

Expand Down
3 changes: 0 additions & 3 deletions lib/src/code_generator/writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class Writer {
late String _symbolAddressVariableName;
late String _symbolAddressLibraryVarName;

final bool dartBool;

/// Initial namers set after running constructor. Namers are reset to this
/// initial state everytime [generate] is called.
late UniqueNamer _initialTopLevelUniqueNamer, _initialWrapperLevelUniqueNamer;
Expand All @@ -82,7 +80,6 @@ class Writer {
required this.lookUpBindings,
required this.noLookUpBindings,
required String className,
required this.dartBool,
Set<LibraryImport>? additionalImports,
this.classDocComment,
this.header,
Expand Down
11 changes: 0 additions & 11 deletions lib/src/config_provider/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ class Config {
StructPackingOverride get structPackingOverride => _structPackingOverride;
late StructPackingOverride _structPackingOverride;

/// If dart bool should be generated for C booleans.
bool get dartBool => _dartBool;
late bool _dartBool;

/// Name of the wrapper class.
String get wrapperName => _wrapperName;
late String _wrapperName;
Expand Down Expand Up @@ -437,13 +433,6 @@ class Config {
extractedResult: (dynamic result) =>
_structPackingOverride = result as StructPackingOverride,
),
[strings.dartBool]: Specification<bool>(
requirement: Requirement.no,
validator: booleanValidator,
extractor: booleanExtractor,
defaultValue: () => true,
extractedResult: (dynamic result) => _dartBool = result as bool,
),
[strings.name]: Specification<String>(
requirement: Requirement.prefer,
validator: dartClassNameValidator,
Expand Down
1 change: 0 additions & 1 deletion lib/src/header_parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Library parse(Config c) {
name: config.wrapperName,
description: config.wrapperDocComment,
header: config.preamble,
dartBool: config.dartBool,
sort: config.sort,
packingOverride: config.structPackingOverride,
libraryImports: c.libraryImports.values.toSet(),
Expand Down
1 change: 0 additions & 1 deletion lib/src/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ const supportedNativeType_mappings = <String, SupportedNativeType>{
// Boolean flags.
const sort = 'sort';
const useSupportedTypedefs = 'use-supported-typedefs';
const dartBool = 'dart-bool';
const useDartHandle = 'use-dart-handle';

const comments = 'comments';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# BSD-style license that can be found in the LICENSE file.

name: ffigen
version: 5.0.1
version: 6.0.0
description: Generator for FFI bindings, using LibClang to parse C header files.
repository: https://github.com/dart-lang/ffigen

Expand Down
24 changes: 0 additions & 24 deletions test/code_generator_tests/code_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ void main() {
test('boolean_dartBool', () {
final library = Library(
name: 'Bindings',
dartBool: true,
bindings: [
Func(
name: 'test1',
Expand All @@ -353,29 +352,6 @@ void main() {
);
_matchLib(library, 'boolean_dartbool');
});
test('boolean_no_dartBool', () {
final library = Library(
name: 'Bindings',
dartBool: false,
bindings: [
Func(
name: 'test1',
returnType: BooleanType(),
parameters: [
Parameter(name: 'a', type: BooleanType()),
Parameter(name: 'b', type: PointerType(BooleanType())),
],
),
Struct(
name: 'Test2',
members: [
Member(name: 'a', type: BooleanType()),
],
),
],
);
_matchLib(library, 'boolean_no_dartbool');
});
test('sort bindings', () {
final library = Library(
name: 'Bindings',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@ class Bindings {

bool test1(
bool a,
ffi.Pointer<ffi.Uint8> b,
ffi.Pointer<ffi.Bool> b,
) {
return _test1(
a ? 1 : 0,
b,
) !=
0;
a,
b,
);
}

late final _test1Ptr = _lookup<
ffi.NativeFunction<
ffi.Uint8 Function(ffi.Uint8, ffi.Pointer<ffi.Uint8>)>>('test1');
ffi.Bool Function(ffi.Bool, ffi.Pointer<ffi.Bool>)>>('test1');
late final _test1 =
_test1Ptr.asFunction<int Function(int, ffi.Pointer<ffi.Uint8>)>();
_test1Ptr.asFunction<bool Function(bool, ffi.Pointer<ffi.Bool>)>();
}

class Test2 extends ffi.Struct {
@ffi.Uint8()
external int a;
@ffi.Bool()
external bool a;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,18 @@ class Bindings {
late final _func3 = _func3Ptr.asFunction<void Function(int, int)>();

bool func4(
ffi.Pointer<ffi.Uint8> a,
ffi.Pointer<ffi.Bool> a,
) {
return _func4(
a,
) !=
0;
a,
);
}

late final _func4Ptr =
_lookup<ffi.NativeFunction<ffi.Uint8 Function(ffi.Pointer<ffi.Uint8>)>>(
_lookup<ffi.NativeFunction<ffi.Bool Function(ffi.Pointer<ffi.Bool>)>>(
'func4');
late final _func4 =
_func4Ptr.asFunction<int Function(ffi.Pointer<ffi.Uint8>)>();
_func4Ptr.asFunction<bool Function(ffi.Pointer<ffi.Bool>)>();
}

class Struct1 extends ffi.Struct {
Expand Down Expand Up @@ -115,6 +114,6 @@ typedef NestingASpecifiedType = ffi.IntPtr;
class Struct2 extends ffi.Opaque {}

class WithBoolAlias extends ffi.Struct {
@ffi.Uint8()
external int b;
@ffi.Bool()
external bool b;
}
11 changes: 5 additions & 6 deletions test/native_test/native_test_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ class NativeLibrary {
bool x,
) {
return _Function1Bool(
x ? 1 : 0,
) !=
0;
x,
);
}

late final _Function1BoolPtr =
_lookup<ffi.NativeFunction<ffi.Uint8 Function(ffi.Uint8)>>(
'Function1Bool');
late final _Function1Bool = _Function1BoolPtr.asFunction<int Function(int)>();
_lookup<ffi.NativeFunction<ffi.Bool Function(ffi.Bool)>>('Function1Bool');
late final _Function1Bool =
_Function1BoolPtr.asFunction<bool Function(bool)>();

int Function1Uint8(
int x,
Expand Down