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
e3146a5e
Commit
e3146a5e
authored
Oct 17, 2015
by
Maxime Perrotin
Browse files
Work on state aggregation
parent
a3b9ef9f
Changes
4
Hide whitespace changes
Inline
Side-by-side
opengeode/AdaGenerator.py
View file @
e3146a5e
...
...
@@ -72,6 +72,7 @@
import
logging
import
traceback
import
os
from
itertools
import
chain
from
singledispatch
import
singledispatch
import
ogAST
...
...
@@ -181,22 +182,13 @@ 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
)
# Process State aggregations (Parallel states)
# Get list of parallel states to be added to the global list of states,
# and list of their inner substates
aggregates
,
substates
=
Helper
.
state_aggregations
(
process
)
for
each
in
substates
:
print
'{}{}state'
.
format
(
each
.
encode
(
'utf-8'
),
UNICODE_SEP
.
encode
(
'utf-8'
))
# End debug
...
...
@@ -209,8 +201,9 @@ LD_LIBRARY_PATH=. taste-gui -l
process_level_decl
=
[]
# Establish the list of states (excluding START states)
statelist
=
', '
.
join
(
name
for
name
in
process
.
mapping
.
iterkeys
()
if
not
name
.
endswith
(
u
'START'
))
or
'No_State'
statelist
=
', '
.
join
(
chain
(
aggregates
,
(
name
for
name
in
process
.
mapping
.
iterkeys
()
if
not
name
.
endswith
(
u
'START'
))))
or
'No_State'
if
statelist
:
states_decl
=
u
'type States is ({});'
.
format
(
statelist
)
process_level_decl
.
append
(
states_decl
)
...
...
@@ -221,6 +214,11 @@ LD_LIBRARY_PATH=. taste-gui -l
if
statelist
:
process_level_decl
.
append
(
'state : States;'
)
# State aggregation: add list of substates (XXX to be added in C generator)
for
each
in
substates
:
process_level_decl
.
append
(
u
'{}{}state: States;'
.
format
(
each
,
UNICODE_SEP
))
for
var_name
,
(
var_type
,
def_value
)
in
process
.
variables
.
viewitems
():
if
def_value
:
# Expression must be a ground expression, i.e. must not
...
...
opengeode/Helper.py
View file @
e3146a5e
...
...
@@ -13,8 +13,10 @@
input-state-transition
sorted_fields(SEQ/CHOICE) : returns the ordered list of fields
of an ASN.1 SEQUENCE or CHOICE type
state_aggregations: enrich AST with state aggregation flags,
and return list of substates and parallel states
Copyright (c) 2012-201
4
European Space Agency
Copyright (c) 2012-201
5
European Space Agency
Designed and implemented by Maxime Perrotin
...
...
@@ -33,7 +35,40 @@ import ogAST
LOG
=
logging
.
getLogger
(
__name__
)
__all__
=
[
'flatten'
,
'rename_everything'
,
'inner_labels_to_floating'
,
'map_input_state'
,
'sorted_fields'
]
'map_input_state'
,
'sorted_fields'
,
'state_aggregations'
]
def
state_aggregations
(
process
):
''' Return the list of state aggregations and substates '''
aggregates
,
substates
=
[],
[]
def
do_composite
(
comp
,
aggregate
=
''
):
''' Recursively find all state aggregations in order to create
variables to store the state of each parallel state '''
for
each
in
comp
.
composite_states
:
pre
=
comp
.
statename
if
isinstance
(
comp
,
ogAST
.
StateAggregation
)
\
else
''
do_composite
(
each
,
pre
)
if
isinstance
(
each
,
ogAST
.
StateAggregation
):
for
term
in
comp
.
terminators
:
if
term
.
inputString
.
lower
()
==
each
.
statename
.
lower
():
each
.
next_is_aggregation
=
True
if
isinstance
(
comp
,
ogAST
.
StateAggregation
):
aggregates
.
append
(
comp
.
statename
)
elif
aggregate
:
# Elif: no state for an inner state aggregation
# Composite state inside a state aggregation
substates
.
append
(
comp
.
statename
)
# Here, all the terminators inside the composite states must
# be flagged with the name of the substate so that the NEXTSTATE
# will not be using the main "context.state" variable but will
# use the parallel substate name when generating code.
for
each
in
comp
.
terminators
:
each
.
substate
=
comp
.
statename
for
each
in
process
.
composite_states
:
do_composite
(
each
)
for
each
in
process
.
terminators
:
if
each
.
inputString
.
lower
()
in
aggregates
:
each
.
next_is_aggregation
=
True
return
aggregates
,
substates
def
map_input_state
(
process
):
...
...
opengeode/ogAST.py
View file @
e3146a5e
...
...
@@ -463,6 +463,11 @@ class Terminator(object):
self
.
possible_states
=
[]
# optional composite state content (type CompositeState)
self
.
composite
=
None
# Flag to indicate if the nextstate is a state aggregation
self
.
is_aggregation
=
False
# If this terminator is within a state aggregation, store the name
# of the parallel substate (set by Helper.state_aggregations)
self
.
substate
=
''
def
trace
(
self
):
''' Debug output for terminators '''
...
...
tests/regression/test-aggregation1/challenge.pr
View file @
e3146a5e
...
...
@@ -144,7 +144,7 @@ state';
/* CIF LABEL (929, 366), (88, 35) */
nslabel:
/* CIF NEXTSTATE (938, 416), (70, 35) */
NEXTSTATE
h
ello;
NEXTSTATE
AggregNextToH
ello;
/* CIF LABEL (512, 472), (141, 35) */
CONNECTION another_floating:
/* CIF PROCEDURECALL (526, 522), (113, 35) */
...
...
@@ -175,6 +175,8 @@ result := 33;
/* CIF JOIN (24, 229), (35, 35) */
JOIN to_label;
ENDSTATE;
state AggregNextToHello;
endstate;
ENDSUBSTRUCTURE;
/* CIF TEXT (51, 0), (298, 56) */
-- This system tests nested states
...
...
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