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

Implement `enum_case` attribute in cpp backend #89

Closed jasongraffius closed 1 year ago

jasongraffius commented 1 year ago

Implements the enum_case attribute in the C++ backend to support emitting enum values with a case other than SHOUTY_CASE. Currently only the original SHOUTY_CASE and the new kCamelCase cases are supported, but adding a new case should be trivial.

Additionally, the implementation was designed to make it simple for a name attribute to be added for enum values (other IR nodes should be unaffected, it would be neither simpler nor harder to implement after this commit for other nodes).

Tests were added for case conversions, header generation, and a cc_test. All tests pass both in bazel test and python -m unittest.

A small change was made to the front-end, as some attribute handling functions were hoisted into compiler/util for reuse in the backend.

jasongraffius commented 1 year ago

Updated, there was a functional change beyond the nit, however: I tested and fixed empty/whitespace enum_case strings with no commas in them.