-
Notifications
You must be signed in to change notification settings - Fork 68
Add option for dart-idiomatic renaming #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @safasofuoglu, I haven't been able to find any standard or widely used way for doing this via regexp. The current regexp replace design is very similar to VSCode's. |
Hi @mannprerak2. Doing this via regex is not possible, since it requires character case transformations which is beyond the capabilities of ECMA regex. Implementation can be inspired from: https://github.com/Ephenodrom/Dart-Basic-Utils/blob/898970fb31cfbed17366dc9593d474730634616f/lib/src/StringUtils.dart#L32 (MIT) Design-wise, my suggestion is a root-level configuration:
If granularity is desired, key can be replicated in specific configs, root-level one serving as the default. Example:
For me, this granularity is not important. I just want dart code to look like other dart code. |
In general this seems a fine feature to me.
However, this can never be true. Because you have to think about resource management: freeing malloced memory, releasing file handles, closing SQLite statements, etc. (Unless you're writing very simple functions that take in all their arguments by value and return a single result by value.) I think the right mental model with FFI code is that you're writing C code in Dart syntax. And then wrap that code in an object oriented API. It might be actually kind of helpful if those C function in Dart syntax actually have C naming conventions. But of course that is a matter of preference. |
That's a good point. What I'm currently working on abstracts away memory/resource management, so I haven't thought that way. |
IMO it would be better to just make ffigen more customizable. Instead of relying on yaml, provide better support for using ffigen as library: Possible API: final config = YamlConfig.fromFile(File('ffigen.yaml'));
final customizable = CustomizableConfig(config)
customizable.enumClassDecl.customizeRename((x) => x.camelCase);
FfiGen().run(customizable) |
Similar effort is happening for jnigen: #1171 |
Cool. Another benefit of code based approach is being able to use pub.dev. For example a very common pattern in ffi is pseudo OOP with methods having an opaque pointer as first argument. @ffi.Native<ffi.Void Function(ffi.Pointer<gameboy_s>, ffi.Uint16, ffi.Uint16)>(symbol: 'GB_cpu_disassemble')
external void cpu_disassemble(ffi.Pointer<gameboy_s> gb, int pc, int count); It can be manually rewritten to an extension on Pointer: extension GameboyFfi on ffi.Pointer<gameboy_s> {
@ffi.Native<ffi.Void Function(ffi.Pointer<gameboy_s>, ffi.Uint16, ffi.Uint16)>(symbol: 'GB_cpu_disassemble')
external void cpu_disassemble(int pc, int count);
} Handling this automatically may be out of scope for ffigen, but if it was extensible, someone else would write a package that does this. |
UpperCamelCase for structs, lowerCamelCase for functions and members. Current regex-based rename mechanism is unable to achieve this with snake_case symbols.
Better if it can coexist with the existing regex-based rename (to be run before or after).
The text was updated successfully, but these errors were encountered: