Commit 4185c8dc authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Fix parse event function

parent cb2dc33a
......@@ -175,13 +175,20 @@ def get_transitions(file, all_places=False):
# Get the names of clocks
# Some event have many clocks (like _h_2755) for the same
# ori/ext entities, so we have to extract them
if re.match('_h_[0-9_\.]+', trans.event):
eventToCondStr = {trans.event: trans.condition}
# ori/ext entities, so we have to extract them and their respective
# conditions
if trans.event == '':
# null event without clock...
# Avoids having SigConstExpr as event type in parse_event()
continue
elif re.match('_h_[0-9_\.]+', trans.event):
# 1 event (with 1 clock)
events = {trans.event: trans.condition}
else:
eventToCondStr = parse_event(trans.event)
for event in eventToCondStr:
# Many events (with many clocks with condition(s))
events = parse_event(trans.event)
for event, condition in events.iteritems():
# LOGGER.debug("NEW trans", event)
# Handle multiple transitions for 1 event
......@@ -190,7 +197,7 @@ def get_transitions(file, all_places=False):
trans.ori.name, trans.ext.name,
{
'label': event, #+ '[' + trans.condition + ']',
'condition': eventToCondStr[event],
'condition': condition,
}
)
)
......@@ -302,6 +309,9 @@ def rec(tree, inhibitors_nodes):
def get_places_from_condition(condition):
"""Parse condition string and return all places, regardless of operators.
.. note:: This function is only used to get all nodes in a condition when
we know they all are inhibitors nodes.
:param: Condition string.
:type: <str>
:return: Set of places.
......@@ -398,25 +408,61 @@ def parse_condition(condition, all_nodes, inhibitors_nodes):
# print(dir(ret))
def treeToExprDefaultsList(tree):
if isinstance(tree, SigDefaultExpr) :
return treeToExprDefaultsList(tree.left_h)+treeToExprDefaultsList(tree.right_h)
else: return [tree]
def parse_event(event):
"""
"""
def treeToExprDefaultsList(tree):
if isinstance(tree, SigDefaultExpr):
return treeToExprDefaultsList(tree.left_h) + \
treeToExprDefaultsList(tree.right_h)
def parse_event(event):
else:
# Here, some tree are from classes SigConstExpr or SigIdentExpr
# Ex: for the clock "_h_5231":
# ... default (_h_5231)" => No condition for this event
# Other examples:
# _h_2018 _h_820 _h_4939 _h_5231 _h_3301 _h_4967 _h_2303 _h_3301
return [tree]
def filterSigExpressions(expr):
"""
.. note:: No SigConstExpr here => filtered in get_transitions()
by checking null events (event="") in the model.
"""
if isinstance(expr, SigWhenExpr):
# right : SigSyncBinExpr (logical formula), BUT
# sometimes SigConstExpr (just a True boolean) when clock is empty
# Ex: "when ()"
# So, we replace this boolean with an empty condition
right = '' if isinstance(expr.right_h, SigConstExpr) \
else str(expr.right_h)
return expr.left_h.name, right
if isinstance(expr, SigIdentExpr):
return expr.name, ''
raise AssertionError("You should never have been there ! "
"Your expression type is not yer supported...")
# Error Reporter
err = Reporter()
tvi = TableVisitor(err)
symb_tab = tvi.tab_symb
# Get tree object from event string
event_sexpr = compile_event(event, symb_tab, True, err)[0]
eventToCondStr = {}
for expr in treeToExprDefaultsList(event_sexpr):
if isinstance(expr, SigWhenExpr):
eventToCondStr[str(expr.left_h)] = str(expr.right_h)
# Filter when events
eventToCondStr = \
{event_name: event_cond for event_name, event_cond in
filterSigExpressions(treeToExprDefaultsList(event_sexpr))}
LOGGER.debug("Clocks from event parsing: " + str(eventToCondStr))
return eventToCondStr
......@@ -490,6 +536,7 @@ def build_graph(solution, steps, transitions):
ext = trans[1]
event = attributes['label'].split('[')[0]
# If there is a condition formula associated to this clock
if attributes['condition'] != '':
# Add the transition as node
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment