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

Improvements to generating code, support for typedef. #224

Merged
merged 14 commits into from
Jun 3, 2021
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
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
# 4.0.0-dev.0
- Added support for generating typedefs (_referred_ typedefs only).
<table>
<tr>
<td>Example C Code</td>
<td>Generated Dart typedef</td>
</tr>
<tr>
<td>

```C++
typedef struct A{
...
} TA, *PA;

TA func(PA ptr);
```
</td>
<td>

```dart
class A extends ffi.Struct {...}
typedef TA = A;
typedef PA = ffi.Pointer<A>;
TA func(PA ptr){...}
```
</td>
</tr>
</table>

- All declarations that are excluded by the user are now only included if being
used somewhere.
- Improved struct/union include/exclude. These declarations can now be targetted
by their actual name, or if they are unnamed then by the name of the first
typedef that refers to them.

# 3.1.0-dev.1
- Users can now specify exact path to dynamic library in `llvm-path`.

Expand Down
40 changes: 36 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ class NativeLibrary {
return _sum(a, b);
}

late final _sum_ptr = _lookup<NativeFunction<_c_sum>>('sum');
late final _dart_sum _sum = _sum_ptr.asFunction<_dart_sum>();
late final _sum_ptr = _lookup<ffi.NativeFunction<ffi.Int32 Function(ffi.Int32, ffi.Int32)>>('sum');
late final _sum = _sum_ptr.asFunction<int Function(int, int)>();
}
typedef _c_sum = Int32 Function(Int32 a, Int32 b);
typedef _dart_sum = int Function(int a, int b);
```
## Using this package
- Add `ffigen` under `dev_dependencies` in your `pubspec.yaml`.
Expand Down Expand Up @@ -233,6 +231,27 @@ globals:
# Removes '_' from
# beginning of a name.
'_(.*)': '$1'
```
mannprerak2 marked this conversation as resolved.
Show resolved Hide resolved
</td>
</tr>
<tr>
<td>typedefs</td>
<td>Filters for referred typedefs.<br><br>
Options -<br>
- Include/Exclude (referred typedefs only).<br>
- Rename typedefs.<br><br>
Note: Typedefs that are not referred to anywhere will not be generated.
</td>
<td>

```yaml
typedefs:
exclude:
# Typedefs starting with `p` are not generated.
- 'p.*'
rename:
# Removes '_' from beginning of a typedef.
'_(.*)': '$1'
```
</td>
</tr>
Expand Down Expand Up @@ -511,3 +530,16 @@ functions:
- 'myFunc'
- '.*' # Do this to expose all pointers.
```

### How are Structs/Unions/Enums that are reffered to via typedefs handled?

Named declarations use their own names even when inside another typedef.
However, unnamed declarations inside typedefs take the name of the _first_ typedef
that refers to them.

### Why are some typedefs not generated?

The following typedefs are not generated -
- They are not referred to anywhere in the included declarations.
- They refer to a struct/union having the same name as itself.
- They refer to a boolean, enum, inline array, Handle or any unsupported type.
Loading