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

Typedefs for Dart types #625

Merged
merged 24 commits into from
Oct 11, 2023
Merged

Typedefs for Dart types #625

merged 24 commits into from
Oct 11, 2023

Conversation

liamappelbe
Copy link
Contributor

@liamappelbe liamappelbe commented Sep 29, 2023

For typedefs that have a different getDartType to their getFfiDartType or getCType (whichever is used in the existing typedef), define a second typedef that uses the getDartType, with an Dart prefix.

Fixes dart-lang/native#235

Example (from the new objc typedef test):

typedef SomeClass* SomeClassPtr;

Generates:

typedef SomeClassPtr = ffi.Pointer<ObjCObject>;
typedef DartSomeClassPtr = SomeClass;

@liamappelbe liamappelbe changed the title WIP Fix #386 Typedefs for Dart types Sep 29, 2023
@liamappelbe liamappelbe marked this pull request as ready for review September 29, 2023 21:11
Copy link
Contributor

@mannprerak2 mannprerak2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM👍

Copy link
Contributor

@dcharkes dcharkes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm w comments

Thanks @liamappelbe!

example/libclang-example/generated_bindings.dart Outdated Show resolved Hide resolved
@@ -10990,7 +11142,6 @@ final class IndexerCallbacks extends ffi.Struct {
CXIdxClientContainer Function(
CXClientData client_data, ffi.Pointer<ffi.Void> reserved)>>
startedTranslationUnit;

external ffi.Pointer<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the declarations separeted by newlines, that's more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know when this change happened, but it's not caused by this PR. I'm just the first one to regenerate this file in a while. We didn't notice the change because our unit tests were intentionally ignoring all the empty lines when diffing the expected and actual output. I've removed this behavior so we'll notice such changes in future.

@@ -48,6 +48,12 @@ abstract class Type {
/// as getFfiDartType. For ObjC bindings this refers to the wrapper object.
String getDartType(Writer w) => getFfiDartType(w);

/// Returns whether the FFI dart type and C type string are same.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe refer to the methods above with [] so it's easier to understand.

Avoid "Return"s.

@@ -48,6 +48,12 @@ abstract class Type {
/// as getFfiDartType. For ObjC bindings this refers to the wrapper object.
String getDartType(Writer w) => getFfiDartType(w);

/// Returns whether the FFI dart type and C type string are same.
bool get sameFfiDartAndCType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to ffiDartAndCTypeEqual. "Equal" seems a more logical word to use than "same".

Also, can we use foo.getCType() == foo.getFfiDartType() on the call-sites and avoid declaring this method? (I know we had this structure already before the PR, so feel free to punt to a separate refactoring.)

lib/src/code_generator/func_type.dart Outdated Show resolved Hide resolved
test/native_objc_test/typedef_test.dart Outdated Show resolved Hide resolved
@liamappelbe liamappelbe merged commit ffaef08 into main Oct 11, 2023
6 checks passed
@liamappelbe liamappelbe deleted the typedef branch October 11, 2023 21:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

ObjC: Unnecessarily abstract types generated for some typedefs
3 participants