Skip to content

Add State Enums

Andrei Tumbar edited this page Sep 24, 2026 · 1 revision

This algorithm traverses a source model and adds to each state machine definition that has a body an enum definition named State, called the state enum. The constants of the state enum represent the leaf states of the state machine.

Input

  1. A list tul of translation units.

Output

  1. A list tul' of translation units in which each state machine definition that has a body has a state enum as its first member, if the transformation succeeds; otherwise an error.

Procedure

For each state machine definition d that has a body:

  1. Collect the leaf states of d. A leaf state is a state with no substates. Its name is the names of its enclosing states followed by its own name, joined with underscore characters. Throw an error if there are too many leaf states.

  2. Construct the enumerated constants of the state enum: first __FPRIME_UNINITIALIZED, then the leaf state names in increasing order, carrying the annotations of their state definitions. No constant has an explicit value.

  3. Construct the state enum with these constants and with representation type U8 if there are fewer than 256 constants, U16 if fewer than 65536, and U32 otherwise.

  4. Add the state enum as the first member of d.

Clone this wiki locally