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 using enum values in requires #67

Closed BenjaminLawson closed 1 year ago

BenjaminLawson commented 1 year ago

It would be nice to be able to use enum values in requires expressions:

enum PageScan:
   MIN = 1
   MAX = 100

struct Example:
  0 [+2] PageScan page_scan
    [requires: PageScan.MIN < this < PageScan.MAX] 
reventlov commented 1 year ago

After thinking about this a bit, I think there are two real options:

  1. Support casts from enum types to integer.
  2. Support the full set of comparison operators on enums.

I'm leaning towards option 2, which means moving the type checks for the <, >, <=, >= operators over to the same function that type checks == and !=. I think that's the only change needed: the way the various comparison operators are implemented in C++ and for inline evaluation should already work with enums.