statechart.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from sccd.statechart.static.tree import *
  2. from sccd.action_lang.static.scope import *
  3. from sccd.statechart.static.semantic_configuration import *
  4. @dataclass
  5. class Statechart(Freezable):
  6. __slots__ = ["semantics", "scope", "datamodel", "internal_events", "internally_raised_events", "inport_events", "event_outport", "tree"]
  7. def __init__(self, semantics: SemanticConfiguration, scope: Scope, datamodel: Optional[Block], internal_events: Bitmap, internally_raised_events: Bitmap, inport_events: Dict[str, Set[int]], event_outport: Dict[str, str], tree: StateTree):
  8. super().__init__()
  9. # Semantic configuration for statechart execution
  10. self.semantics: SemanticConfiguration = semantics
  11. # Instance scope, the set of variable names (and their types and offsets in memory) that belong to the statechart
  12. self.scope: Scope = scope
  13. # Block of statements setting up the datamodel (variables in instance scope)
  14. self.datamodel: Optional[Block] = datamodel
  15. # Union of internally raised and input events. Basically all the events that a transition could be triggered by.
  16. self.internal_events: Bitmap = internal_events
  17. # All internally raised events in the statechart, may overlap with input events, as an event can be both an input event and internally raised.
  18. self.internally_raised_events: Bitmap = internally_raised_events
  19. # Mapping from inport to set of event IDs - currently unused
  20. self.inport_events: Dict[str, Bitmap] = inport_events
  21. # Mapping from event name to outport
  22. self.event_outport: Dict[str, str] = event_outport
  23. self.tree: StateTree = tree
  24. def generate_semantic_variants(self) -> List['Statechart']:
  25. return [Statechart(
  26. semantics=variant,
  27. # All other fields remain the same.
  28. scope=self.scope,
  29. datamodel=self.datamodel,
  30. internal_events=self.internal_events,
  31. internally_raised_events=self.internally_raised_events,
  32. inport_events=self.inport_events,
  33. event_outport=self.event_outport,
  34. tree=self.tree)
  35. for variant in self.semantics.generate_variants()]