Commit a3b9ef9f authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Explore AST to find state aggregations

parent e0d95abf
...@@ -181,6 +181,25 @@ LD_LIBRARY_PATH=. taste-gui -l ...@@ -181,6 +181,25 @@ LD_LIBRARY_PATH=. taste-gui -l
# In case model has nested states, flatten everything # In case model has nested states, flatten everything
Helper.flatten(process, sep=UNICODE_SEP) Helper.flatten(process, sep=UNICODE_SEP)
# Debug:
# After flattening, display all states, recursively. We need to find the
# composite states internal to state aggregations.
def do_composite(comp, aggregate=''):
for each in comp.composite_states:
pre = comp.statename if isinstance(comp, ogAST.StateAggregation) \
else ''
do_composite(each, pre)
if isinstance(comp, ogAST.StateAggregation):
print 'State Aggregation:', comp.statename.encode('utf-8')
if aggregate:
print 'In aggregation:', aggregate.encode('utf-8'), comp.statename.encode('utf-8')
for each in process.composite_states:
do_composite(each)
# End debug
# Make an maping {input: {state: transition...}} in order to easily # Make an maping {input: {state: transition...}} in order to easily
# generate the lookup tables for the state machine runtime # generate the lookup tables for the state machine runtime
mapping = Helper.map_input_state(process) mapping = Helper.map_input_state(process)
......
...@@ -171,8 +171,12 @@ def flatten(process, sep=u'_'): ...@@ -171,8 +171,12 @@ def flatten(process, sep=u'_'):
# Go recursively in inner composite states # Go recursively in inner composite states
inner.statename = prefix + inner.statename inner.statename = prefix + inner.statename
update_composite_state(inner, process) update_composite_state(inner, process)
propagate_inputs(inner, process.mapping[inner.statename]) propagate_inputs(inner, process)
try:
del process.mapping[inner.statename] del process.mapping[inner.statename]
except KeyError:
# KeyError in case of state aggregation
pass
for each in state.terminators: for each in state.terminators:
# Give prefix to terminators # Give prefix to terminators
if each.label: if each.label:
...@@ -200,7 +204,7 @@ def flatten(process, sep=u'_'): ...@@ -200,7 +204,7 @@ def flatten(process, sep=u'_'):
each.inputString = prefix + each.inputString each.inputString = prefix + each.inputString
process.content.inner_procedures.extend(state.content.inner_procedures) process.content.inner_procedures.extend(state.content.inner_procedures)
def propagate_inputs(nested_state, inputlist): def propagate_inputs(nested_state, context):
''' Nested states: Inputs at level N must be handled at level N-1 ''' Nested states: Inputs at level N must be handled at level N-1
that is, all inputs of a composite states (the ones that allow that is, all inputs of a composite states (the ones that allow
to exit the composite state from the outer scope) must be to exit the composite state from the outer scope) must be
...@@ -208,12 +212,14 @@ def flatten(process, sep=u'_'): ...@@ -208,12 +212,14 @@ def flatten(process, sep=u'_'):
''' '''
for _, val in nested_state.mapping.viewitems(): for _, val in nested_state.mapping.viewitems():
try: try:
inputlist = context.mapping[nested_state.statename]
val.extend(inputlist) val.extend(inputlist)
except AttributeError: except (AttributeError, KeyError):
# KeyError in case of StateAggregation
pass pass
for each in nested_state.composite_states: for each in nested_state.composite_states:
# do the same recursively # do the same recursively
propagate_inputs(each, nested_state.mapping[each.statename]) propagate_inputs(each, nested_state)
#del nested_state.mapping[each.statename] #del nested_state.mapping[each.statename]
def set_terminator_states(context, prefix=''): def set_terminator_states(context, prefix=''):
...@@ -238,7 +244,7 @@ def flatten(process, sep=u'_'): ...@@ -238,7 +244,7 @@ def flatten(process, sep=u'_'):
for each in process.composite_states: for each in process.composite_states:
update_composite_state(each, process) update_composite_state(each, process)
propagate_inputs(each, process.mapping[each.statename]) propagate_inputs(each, process)
del process.mapping[each.statename] del process.mapping[each.statename]
# Update terminators at process level # Update terminators at process level
......
...@@ -42,6 +42,24 @@ PROCESS challenge; ...@@ -42,6 +42,24 @@ PROCESS challenge;
STATE wait_in_sub_hello; STATE wait_in_sub_hello;
ENDSTATE; ENDSTATE;
ENDSUBSTRUCTURE; ENDSUBSTRUCTURE;
STATE AGGREGATION AggregNextToHello;
SUBSTRUCTURE
STATE C;
SUBSTRUCTURE
START;
NEXTSTATE CEH;
STATE CEH;
ENDSTATE;
ENDSUBSTRUCTURE;
STATE D;
SUBSTRUCTURE
START;
NEXTSTATE DEH;
STATE DEH;
ENDSTATE;
ENDSUBSTRUCTURE;
ENDSUBSTRUCTURE;
/* CIF TEXT (242, 251), (334, 95) */ /* CIF TEXT (242, 251), (334, 95) */
dcl myresult T_UInt8 := 4; dcl myresult T_UInt8 := 4;
-- Use a variable with the same name as a variable -- Use a variable with the same name as a variable
......
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