canadensis
canadensis copied to clipboard
codegen: enum
I don't know the best way to do this, but it'd be really great if the dsdl definitions could compile into rust enums, for instance if you have
uint8 REQ_A = 0
uint8 REQ_B = 1
it would be compiled into
enum REQ {
A = 0,
B = 1,
}
Of course this would be kinda hard to do automatically as well as this with regards to naming in a predictable way, but anything like this would be really great. Could do it automatically if the file just contains a bunch of defines like this, maybe look for a specific comment, or take a config file / cli args.
Ways I can think of
Note: we can use rust-like #[] because # declares a comment in dsdl
Start & end
#[canadensis(enum_start)]
uint8 REQ_A = 0
uint8 REQ_B = 1
#[canadensis(enum_end)]
Explicit member
Here we can specify the name of the enum, and it would remove this prefix from the enum members, like in the rust example above.
#[canadensis_enum(REQ)]
uint8 REQ_A = 0
#[canadensis_enum(REQ)]
uint8 REQ_B = 1
Smart compiler
If the "block" consists of constants of the same type, just turn them into an enum