Skip to content

Commit 2aef199

Browse files
committed
job #42 improve state and transition labels
- Include 'InstanceStateMachine' or 'ClassStateMachine' to indicate the type of action. - Instead of naming transitions after the event, name them with the start state, event, and destination state. The destination state is not strictly required to uniquely identify a transition, however it is helpful since the label is used for debugging purposes.
1 parent b3b7b20 commit 2aef199

File tree

1 file changed

+50
-25
lines changed

1 file changed

+50
-25
lines changed

bridgepoint/prebuild.py

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,21 +1620,23 @@ class TransitionPrebuilder(ActionPrebuilder):
16201620
def __init__(self, metamodel, sm_act):
16211621
self._sm_act = sm_act
16221622
self._sm_evt = (one(sm_act).SM_AH[514].SM_TAH[513].SM_TXN[530].
1623-
SM_NSTXN[507].SM_SEME[504].SM_SEVT[503].SM_EVT[525]())
1623+
SM_NSTXN[507].SM_SEME[504].SM_SEVT[503].SM_EVT[525]() or
1624+
one(sm_act).SM_AH[514].SM_TAH[513].SM_TXN[530].
1625+
SM_CRTXN[507].SM_LEVT[509].SM_SEVT[526].SM_EVT[525]())
16241626
self._sm_state = one(sm_act).SM_AH[514].SM_MOAH[513].SM_STATE[511]()
16251627
self._o_obj = (one(sm_act).SM_SM[515].SM_ISM[517].O_OBJ[518]() or
16261628
one(sm_act).SM_SM[515].SM_ASM[517].O_OBJ[519]())
1627-
1628-
if self._sm_evt:
1629-
self.element_type = 'Transition'
1630-
action_name = self.get_event_name(self._sm_evt)
16311629

1632-
elif self._sm_state:
1630+
if self._sm_state:
16331631
self.element_type = 'State'
16341632
action_name = self._sm_state.Name
1633+
1634+
else:
1635+
self.element_type = 'Transition'
1636+
action_name = self.get_txn_name()
16351637

16361638
self.label = '::'.join([get_parent_label(self._o_obj), self._o_obj.Name,
1637-
action_name])
1639+
self.get_sm_type(), action_name])
16381640

16391641
c_c = get_defining_component(self._o_obj)
16401642
ActionPrebuilder.__init__(self, metamodel, c_c)
@@ -1647,26 +1649,49 @@ def find_symbol(self, node, name):
16471649

16481650
return v_var
16491651

1650-
def get_event_name(self, event):
1651-
sm_nlevt = one(event).SM_SEVT[525].SM_NLEVT[526]()
1652-
sm_sgevt = one(event).SM_SEVT[525].SM_SGEVT[526]()
1653-
sm_pevt = one(sm_nlevt).SM_PEVT[527]()
1654-
1655-
# If polymorphic and the polymorphic event is not local,
1656-
# use the poly local class name
1657-
if sm_pevt and sm_pevt.SM_ID != sm_nlevt.SM_ID:
1658-
return event.Mning + "::" + sm_pevt.localClassName
1659-
1660-
# If an orphaned polymorphic, append that to the name
1661-
if sm_nlevt is not None and sm_pevt is None:
1662-
return event.Mning + "::Orphaned"
1652+
def get_event_name(self):
1653+
if self._sm_evt:
1654+
sm_nlevt = one(self._sm_evt).SM_SEVT[525].SM_NLEVT[526]()
1655+
sm_sgevt = one(self._sm_evt).SM_SEVT[525].SM_SGEVT[526]()
1656+
sm_pevt = one(sm_nlevt).SM_PEVT[527]()
1657+
1658+
# If polymorphic and the polymorphic event is not local,
1659+
# use the poly local class name
1660+
if sm_pevt and sm_pevt.SM_ID != sm_nlevt.SM_ID:
1661+
return sm_pevt.localClassName + '::' + self._sm_evt.Mning
1662+
1663+
# If an orphaned polymorphic, append that to the name
1664+
if sm_nlevt is not None and sm_pevt is None:
1665+
return 'Orphaned::' + self._sm_evt.Mning
16631666

1664-
# If a signal event we use only the derived label
1665-
if sm_sgevt is not None:
1666-
return event.Drv_Lbl
1667+
# If a signal event we use only the derived label
1668+
if sm_sgevt is not None:
1669+
return self._sm_evt.Drv_Lbl
16671670

1668-
# otherwise we combine the label with the event Mning
1669-
return event.Drv_Lbl + ": " + event.Mning
1671+
# otherwise we combine the label with the event Mning
1672+
return self._sm_evt.Drv_Lbl + ": " + self._sm_evt.Mning
1673+
else:
1674+
return 'No Event'
1675+
1676+
def get_sm_type(self):
1677+
sm_ism = one(self._sm_act).SM_SM[515].SM_ISM[517]()
1678+
return 'InstanceStateMachine' if sm_ism else 'ClassStateMachine'
1679+
1680+
def get_txn_name(self):
1681+
dest_state = (one(self._sm_act).SM_AH[514].SM_TAH[513].SM_TXN[530].
1682+
SM_STATE[506]())
1683+
if dest_state:
1684+
start_state = (one(self._sm_act).SM_AH[514].SM_TAH[513].SM_TXN[530].
1685+
SM_NSTXN[507].SM_SEME[504].SM_STATE[503]() or
1686+
one(self._sm_act).SM_AH[514].SM_TAH[513].SM_TXN[530].
1687+
SM_NETXN[507].SM_STATE[508]())
1688+
if start_state:
1689+
return (start_state.Name + ' [' + self.get_event_name() + '] => ' +
1690+
dest_state.Name)
1691+
else:
1692+
# for creation states, use the imaginary "Non Existent" state
1693+
return ('Non Existent [' + self.get_event_name() + '] => ' +
1694+
dest_state.Name)
16701695

16711696
def accept_BodyNode(self, node):
16721697
sm_moah = one(self._sm_act).SM_AH[514].SM_MOAH[513]()

0 commit comments

Comments
 (0)