Skip to content

Compute Flattened Choice Transition Map

Rob Bocchino edited this page Nov 4, 2024 · 1 revision

This algorithm flattens the choice transitions in a state machine definition. By flattening transitions, we simplify the code generation and runtime logic.

Input

  1. A state machine definition smd.

  2. A state machine analysis data structure sma representing the results of analysis so far.

Output

  1. sma with the flattened choice transition map updated.

Diagrams

The following diagrams illustrate how choice transitions are flattened.

Choice Transitions to States

Figure 1 shows how choice transitions to states are flattened. S1 is a state with a choice C. S2 is a state with a substate S3. It has an initial transition specifier with actions A' and target S3.

The solid left-to-right arrow represents a transition T in the hierarchical state machine from C to S2 with actions A. T generates the flattened transition represented by the dashed arrow. The action list for this transition is the concatenation of the action lists shown. In these lists, exit(S) represents the list of exit functions specified by S, and similarly for entry(S).

Choice transitions to states
Figure 1. Choice transitions to states.

Note that each flattened transition goes from a choice to a leaf state.

Choice Transitions to Choices

Figure 2 shows how choice transitions to choices are flattened. S1 is a state with a choice C1. S2 is a state with a choice C2. The solid left-to-right arrow represents a transition T in the hierarchical state machine from C1 to C2. T generates the flattened transition represented by the dashed arrow. The action list for this transition is the concatenation of the action lists shown.

Choice transitions to choices
Figure 2. Choice transitions to choices.

Procedure

Visit each of the choices in smd.

Visiting Choices

  1. Let sd be the state definition being visited.

  2. For each choice definition cd in sd

    1. For each transition expression e in cd

      1. Let A be the actions of e.

      2. Let soc be the state or choice that is the target of e.

      3. Construct the transition t from cd to soc with actions A

      4. Map e to t in the flattened choice transition map of sma.

Clone this wiki locally