[ffigen] feat: generate cpp class constructor bindings#3395
Conversation
Package publishing
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
PR HealthBreaking changes ✔️
This check can be disabled by tagging the PR with API leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
This check can be disabled by tagging the PR with Changelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. This check can be disabled by tagging the PR with |
|
|
||
| final ctorInfos = [ | ||
| for (var i = 0; i < constructors.length; i++) | ||
| (ctor: constructors[i], suffix: constructors.length == 1 ? '' : '_$i'), |
There was a problem hiding this comment.
Can you use the existing Scope and Symbol infra for this? Change CppMethod.name to a Symbol, wire it up in the visitors etc, and set the base name of all the constructors to the glueName below (without the suffix, so I guess ${name}_new?)
| p.name, | ||
| objCRetain: false, | ||
| objCAutorelease: false, | ||
| localVariables: LocalVariables(localScope), |
There was a problem hiding this comment.
Constructing LocalVariables inline like this means you're never actually writing the local variables it creates. I think once you start dealing with memory management stuff, you'll need to deal with LocalVariables properly, since safely unwrapping a pointer from a NativeFinalizer requires creating a temporary local variable.
Take a look at how other bindings generators deal with LocalVariables. You'll basically need to create one LocalVariables instance per method, do all your conversions (but don't write them to your bindings yet), then call LocalVariables.generateDeclarations() and write the string to your bindings, then write the conversion strings. Basically, the local variable declarations need to be written to the bindings before the conversions that use those local variables.
Example of writing LocalVariables to the bindings. Example showing how LocalVariables are being used for pointer unwrapping (you'll need to do this sort of thing when you start doing memory management). This bug and this one explain why this unwrapping step is needed, if you want to read more about it.
There was a problem hiding this comment.
Ok, I have tried to follow the links you mentioned; let me know if there are any other enhancements
No description provided.