Comments (3)
I like the idea and would favor using lower camel case names in generated zig code. However, all of the other implementations I looked at used title camel case including go, cpp and python if i remember correctly. So I chose to follow them because its a little easier to compare generated code.
I'm not sure why this is a thing. I can see why the go impl does this as it follows the go style guide. But the cpp and python impls aren't following their style guides.
Maybe we could add a build or config option for changing the function casing? I would be glad to accept a PR for this. But I'd like to default to title case for now, at least until a day when this project is more trusted (known to work well) and comparing generated code shouldn't be necessary.
from flatbufferz.
Hey @travisstaloch , would you accept a PR refactoring src/codegen.zig
?
Serious issues
--no-gen-object-api
still imports object API...T
types andUnpack
functions- Property name collisions with unions can lead to generated code calling non-existent functions. For example:
union Type { Null, Int }
table Field { type: Type }
generates a non-existent call to rcv.Type_Type()
instead of the correct rcv.TypeType()
:
pub fn UnpackTo(rcv: Field, t: *FieldT, __pack_opts: fb.common.PackOptions) !void {
if (rcv.Type_()) |_tab| {
t.type = try TypeT.Unpack(rcv.Type_Type(), _tab, __pack_opts);
}
}
- Object API optionals should be
optional_field: ?T
instead ofoptional_field: ?*T
to prevent unnecessary allocation. - Add error printing on invalid codegen (useful for when Zig breaks codegenned syntax and for codegen devs)
Style issues
- Remove
_
s from variable names. Zig purposefully disallows private struct members. Also, constants like__file_indent
are already namespaced to the source file. Parameters like__builder
can simply be renamed tobuilder
. - Consistently use
self: Self
instead of inconsitentlyrcv: {type}
andself: {type}
- Add option for an index file with all generated types since there's a file generated per table/struct/union which can add up quickly.
- As for the casing, I think a reason for
Title
oversnake_case
is to prevent parameter name shadowing like:
pub fn rcv(rcv: Field) bool {
...
}
This can of course be solved by renaming the parameter to rcv_
or something similar but adds another layer of complexity.
Sorry to hijack this issue, let me know if there's a better way to contact you. I'm happy to make all these changes.
from flatbufferz.
Hey @travisstaloch , would you accept a PR refactoring
src/codegen.zig
?
Sorry so long. Looked at this earler today and forgot to respond.
These all sound like legitimate problems to me and I would gladly accpt a PR. 👍
I've created #3 with the text from above. Lets discuss there
from flatbufferz.
Related Issues (15)
- address some api and style issues HOT 25
- Fix --no-gen-object-api HOT 1
- Fix enum unpacking for enum names ending in `Type` HOT 1
- Only use field pointers for recursive fields in tables
- Add error printing on invalid codegen HOT 1
- Handle identifier collisions in codegen HOT 1
- Allow type, function, and field casing to be user-configurable
- Allow array types
- Change `Create(list, of, fields)` to `init(t: Type)`
- Rename `Type` to `PackedType`. Rename `TypeT` to `Type`
- generate simple round trip tests for structs, tables and unions HOT 2
- Properly handle bit flags HOT 1
- testing glci 1
- testing gcli 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flatbufferz.