google / emboss

Emboss is a tool for generating code that reads and writes binary data structures.
Apache License 2.0
68 stars 21 forks source link

Support kCamelCase names for enum values #59

Closed acsaeed closed 1 year ago

acsaeed commented 1 year ago

Currently, enum values are always SHOUTY_CASE. The Google C++ style guide prefers kCamelCase for enum names, so we would like to migrate our Emboss enum names to this style eventually. A possible implementation is adding a configuration option for enum name style at the top of .emb files.

jasongraffius commented 1 year ago

As of #89 this should be implemented. To use kCamelCase enum names for all enums in a module, you should be able to add:

[(cpp) $default enum_case: "kCamelCase"]

To the top of the module (alongside other attributes like namespace and default endianness, if applicable). If you need to transition between the two, you should be able to use:

[(cpp) $default enum_case: "SHOUTY_CASE, kCamelCase"]

Then update all references from SHOUTY_CASE to kCamelCase, and remove the "SHOUTY_CASE" entry from the enum cases.

Note: You can also apply this only to specific enum values, or all enum values in an enum, or all enums within a struct or bits, etc. by putting the annotation at the appropriate level.