Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
OpenGEODE
Commits
a3b9ef9f
Commit
a3b9ef9f
authored
Oct 17, 2015
by
Maxime Perrotin
Browse files
Explore AST to find state aggregations
parent
e0d95abf
Changes
3
Hide whitespace changes
Inline
Side-by-side
opengeode/AdaGenerator.py
View file @
a3b9ef9f
...
...
@@ -181,6 +181,25 @@ LD_LIBRARY_PATH=. taste-gui -l
# In case model has nested states, flatten everything
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
# generate the lookup tables for the state machine runtime
mapping
=
Helper
.
map_input_state
(
process
)
...
...
opengeode/Helper.py
View file @
a3b9ef9f
...
...
@@ -171,8 +171,12 @@ def flatten(process, sep=u'_'):
# Go recursively in inner composite states
inner
.
statename
=
prefix
+
inner
.
statename
update_composite_state
(
inner
,
process
)
propagate_inputs
(
inner
,
process
.
mapping
[
inner
.
statename
])
del
process
.
mapping
[
inner
.
statename
]
propagate_inputs
(
inner
,
process
)
try
:
del
process
.
mapping
[
inner
.
statename
]
except
KeyError
:
# KeyError in case of state aggregation
pass
for
each
in
state
.
terminators
:
# Give prefix to terminators
if
each
.
label
:
...
...
@@ -200,7 +204,7 @@ def flatten(process, sep=u'_'):
each
.
inputString
=
prefix
+
each
.
inputString
process
.
content
.
inner_procedures
.
extend
(
state
.
content
.
inner_procedures
)
def
propagate_inputs
(
nested_state
,
inputlis
t
):
def
propagate_inputs
(
nested_state
,
contex
t
):
''' 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
to exit the composite state from the outer scope) must be
...
...
@@ -208,12 +212,14 @@ def flatten(process, sep=u'_'):
'''
for
_
,
val
in
nested_state
.
mapping
.
viewitems
():
try
:
inputlist
=
context
.
mapping
[
nested_state
.
statename
]
val
.
extend
(
inputlist
)
except
AttributeError
:
except
(
AttributeError
,
KeyError
):
# KeyError in case of StateAggregation
pass
for
each
in
nested_state
.
composite_states
:
# do the same recursively
propagate_inputs
(
each
,
nested_state
.
mapping
[
each
.
statename
]
)
propagate_inputs
(
each
,
nested_state
)
#del nested_state.mapping[each.statename]
def
set_terminator_states
(
context
,
prefix
=
''
):
...
...
@@ -238,7 +244,7 @@ def flatten(process, sep=u'_'):
for
each
in
process
.
composite_states
:
update_composite_state
(
each
,
process
)
propagate_inputs
(
each
,
process
.
mapping
[
each
.
statename
]
)
propagate_inputs
(
each
,
process
)
del
process
.
mapping
[
each
.
statename
]
# Update terminators at process level
...
...
tests/regression/test-aggregation1/challenge.pr
View file @
a3b9ef9f
...
...
@@ -42,6 +42,24 @@ PROCESS challenge;
STATE wait_in_sub_hello;
ENDSTATE;
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) */
dcl myresult T_UInt8 := 4;
-- Use a variable with the same name as a variable
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment