Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
opengeode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TASTE
opengeode
Commits
b7d1ce87
PL1
Commit
b7d1ce87
authored
9 years ago
by
Maxime Francois Perrotin
Browse files
Options
Downloads
Patches
Plain Diff
Use the proper list of states in 1st-level switch-case
parent
7c1d739d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
opengeode/AdaGenerator.py
+19
-15
19 additions, 15 deletions
opengeode/AdaGenerator.py
opengeode/Helper.py
+22
-5
22 additions, 5 deletions
opengeode/Helper.py
with
41 additions
and
20 deletions
opengeode/AdaGenerator.py
+
19
−
15
View file @
b7d1ce87
...
...
@@ -184,12 +184,13 @@ LD_LIBRARY_PATH=. taste-gui -l
# 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)
# Find recursively in the AST all state aggregations
# Format: {'aggregation_name' : [list of ogAST.CompositeState]
aggregates
=
Helper
.
state_aggregations
(
process
)
# End debug
# Extract the list of parallel states names inside the composite states
# of state aggregations XXX add to C generator
parallel_states
=
Helper
.
parallel_states
(
aggregates
)
# Make an maping {input: {state: transition...}} in order to easily
# generate the lookup tables for the state machine runtime
...
...
@@ -199,18 +200,20 @@ LD_LIBRARY_PATH=. taste-gui -l
process_level_decl
=
[]
# Establish the list of states (excluding START states)
statelist
=
'
,
'
.
join
(
chain
(
aggregates
.
viewkeys
(),
(
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
)
# Establish the list of states (excluding START states) XXX update C backend
full_statelist
=
list
(
chain
(
aggregates
.
viewkeys
(),
(
name
for
name
in
process
.
mapping
.
iterkeys
()
if
not
name
.
endswith
(
u
'
START
'
))))
reduced_statelist
=
[
s
for
s
in
full_statelist
if
s
not
in
parallel_states
]
if
full_statelist
:
process_level_decl
.
append
(
u
'
type States is ({});
'
.
format
(
u
'
,
'
.
join
(
full_statelist
)
or
u
'
No_State
'
))
# Generate the code to declare process-level context
process_level_decl
.
extend
([
'
type {}_Ty is
'
.
format
(
LPREFIX
),
'
record
'
])
if
statelist
:
if
full_
statelist
:
process_level_decl
.
append
(
'
state : States;
'
)
# State aggregation: add list of substates (XXX to be added in C generator)
...
...
@@ -218,7 +221,7 @@ LD_LIBRARY_PATH=. taste-gui -l
for
substates
in
aggregates
.
viewvalues
():
for
each
in
substates
:
process_level_decl
.
append
(
u
'
{}{}state: States;
'
.
format
(
each
,
UNICODE_SEP
))
.
format
(
each
.
statename
,
UNICODE_SEP
))
for
var_name
,
(
var_type
,
def_value
)
in
process
.
variables
.
viewitems
():
if
def_value
:
...
...
@@ -253,7 +256,8 @@ LD_LIBRARY_PATH=. taste-gui -l
aggreg_start_proc
.
extend
([
u
'
{} is
'
.
format
(
proc_name
),
'
begin
'
])
aggreg_start_proc
.
extend
(
u
'
runTransition({sub}{sep}START);
'
.
format
(
sub
=
subname
,
sep
=
UNICODE_SEP
)
.
format
(
sub
=
subname
.
statename
,
sep
=
UNICODE_SEP
)
for
subname
in
substates
)
#Following done in the transition, not needed here
#aggreg_start_proc.append(u'{ctxt}.state := {name};'
...
...
@@ -408,7 +412,7 @@ package {process_name} is'''.format(process_name=process_name,
taste_template
.
append
(
pi_header
)
taste_template
.
append
(
'
begin
'
)
taste_template
.
append
(
'
case {ctxt}.state is
'
.
format
(
ctxt
=
LPREFIX
))
for
state
in
process
.
mapping
.
viewkeys
():
for
state
in
reduced_statelist
:
#
process.mapping.viewkeys():
XXX C Backend
if
state
.
endswith
(
u
'
START
'
):
continue
taste_template
.
append
(
u
'
when {state} =>
'
.
format
(
state
=
state
))
...
...
This diff is collapsed.
Click to expand it.
opengeode/Helper.py
+
22
−
5
View file @
b7d1ce87
...
...
@@ -14,7 +14,8 @@
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
and return the list of substates of aggregations
parallel_states: return a list of strings naming all parallel states
Copyright (c) 2012-2015 European Space Agency
...
...
@@ -35,17 +36,22 @@ import ogAST
LOG
=
logging
.
getLogger
(
__name__
)
__all__
=
[
'
flatten
'
,
'
rename_everything
'
,
'
inner_labels_to_floating
'
,
'
map_input_state
'
,
'
sorted_fields
'
,
'
state_aggregations
'
]
'
map_input_state
'
,
'
sorted_fields
'
,
'
state_aggregations
'
,
'
parallel_states
'
]
def
state_aggregations
(
process
):
'''
Return the list of state aggregations and substates
'''
'''
Explore recursively the AST to find all state aggregations, and
return the composite states inside them
input: ogAST.Process element
output: {state_aggregation: {list of ogAST.CompositeState}
'''
# { aggregate_name : [list of parallel states] }
aggregates
=
defaultdict
(
list
)
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
:
for
each
in
comp
.
composite_states
:
# CHECKME
pre
=
comp
.
statename
if
isinstance
(
comp
,
ogAST
.
StateAggregation
)
\
else
''
do_composite
(
each
,
pre
)
...
...
@@ -55,7 +61,7 @@ def state_aggregations(process):
term
.
next_is_aggregation
=
True
if
aggregate
and
not
isinstance
(
comp
,
ogAST
.
StateAggregation
):
# Composite state inside a state aggregation
aggregates
[
aggregate
].
append
(
comp
.
statename
)
aggregates
[
aggregate
].
append
(
comp
)
# 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
...
...
@@ -70,6 +76,17 @@ def state_aggregations(process):
return
aggregates
def
parallel_states
(
aggregates
):
'''
Given a mapping obtained with state_aggregation(process), extract
all parallel states and return a list of state names
'''
parallel_states
=
[]
for
name
,
comp
in
aggregates
.
viewitems
():
for
each
in
comp
:
parallel_states
.
extend
(
name
for
name
in
each
.
mapping
.
viewkeys
()
if
not
name
.
endswith
(
u
'
START
'
))
return
parallel_states
def
map_input_state
(
process
):
'''
Create a mapping dict {input1: {state1: transition, ...}, ...}
'''
mapping
=
defaultdict
(
dict
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment