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
cadb6378
Commit
cadb6378
authored
Mar 28, 2016
by
Maxime Perrotin
Browse files
Handle properly continuous states
Was missing elsif statements
parent
4775e60a
Changes
2
Hide whitespace changes
Inline
Side-by-side
opengeode/AdaGenerator.py
View file @
cadb6378
...
...
@@ -732,6 +732,8 @@ package {process_name} is'''.format(process_name=process_name,
# Process the continuous states in state aggregations first
done
=
[]
sep
=
'if '
last
=
''
for
cs
,
agg
in
product
(
process
.
cs_mapping
.
viewitems
(),
aggregates
.
viewitems
()):
(
statename
,
cs_item
),
(
agg_name
,
substates
)
=
cs
,
agg
...
...
@@ -747,9 +749,13 @@ package {process_name} is'''.format(process_name=process_name,
trId
=
process
.
transitions
.
index
\
(
provided_clause
.
transition
)
code
,
loc
=
generate
(
provided_clause
.
trigger
,
branch_to
=
trId
)
branch_to
=
trId
,
sep
=
sep
,
last
=
last
)
sep
=
'elsif '
taste_template
.
extend
(
code
)
done
.
append
(
statename
)
taste_template
.
append
(
u
'end if;'
)
sep
=
'if '
break
for
statename
in
process
.
cs_mapping
.
viewkeys
()
-
done
:
cs_item
=
process
.
cs_mapping
[
statename
]
...
...
@@ -758,10 +764,12 @@ package {process_name} is'''.format(process_name=process_name,
for
provided_clause
in
cs_item
:
trId
=
process
.
transitions
.
index
(
provided_clause
.
transition
)
code
,
loc
=
generate
(
provided_clause
.
trigger
,
branch_to
=
trId
)
branch_to
=
trId
,
sep
=
sep
,
last
=
last
)
sep
=
'elsif '
taste_template
.
extend
(
code
)
if
process
.
cs_mapping
:
taste_template
.
append
(
u
'end if;'
)
taste_template
.
append
(
u
'end if;'
)
taste_template
.
append
(
'end loop;'
)
taste_template
.
append
(
'end runTransition;'
)
...
...
@@ -1879,7 +1887,7 @@ def _choiceitem(choice):
@
generate
.
register
(
ogAST
.
Decision
)
def
_decision
(
dec
,
branch_to
=
None
,
**
kwargs
):
def
_decision
(
dec
,
branch_to
=
None
,
sep
=
'if '
,
last
=
'end if;'
,
**
kwargs
):
''' Generate the code for a decision
A decision is made of a question and some answers ; each answer may
be followed by a transition (ogAST.Transition). The code of the
...
...
@@ -1919,7 +1927,6 @@ def _decision(dec, branch_to=None, **kwargs):
code
.
extend
(
q_stmts
)
if
not
basic
:
code
.
append
(
'tmp{idx} := {q};'
.
format
(
idx
=
dec
.
tmpVar
,
q
=
q_str
))
sep
=
'if '
for
a
in
dec
.
answers
:
code
.
extend
(
traceability
(
a
))
if
a
.
kind
in
(
'open_range'
,
'constant'
):
...
...
@@ -1994,9 +2001,11 @@ def _decision(dec, branch_to=None, **kwargs):
code
.
extend
(
else_code
)
except
:
pass
if
sep
!=
'if '
:
if
sep
!=
'if '
and
last
:
# If there is at least one 'if' branch
code
.
append
(
'end if;'
)
# "last" is usually "end if;" but it can be changed by parameter
# e.g. if the decision is chained with other tests with "elsif"
code
.
append
(
last
)
return
code
,
local_decl
...
...
tests/regression/test-battery/og.pr
View file @
cadb6378
...
...
@@ -39,17 +39,23 @@ external;
NEXTSTATE discharge;
/* CIF STATE (152, 197), (114, 35) */
STATE discharge;
/* CIF PROVIDED (32, 252), (121, 35) */
/* CIF INPUT (215, 252), (108, 35) */
INPUT dd(charge);
/* CIF TASK (157, 302), (223, 35) */
TASK charge := (charge + 1) mod 255;
/* CIF NEXTSTATE (234, 352), (70, 35) */
NEXTSTATE -;
/* CIF PROVIDED (-13, 252), (121, 35) */
PROVIDED charge = 0;
/* CIF TASK (4
1
, 302), (104, 35) */
/* CIF TASK (
-
4, 302), (104, 35) */
TASK charge := 5;
/* CIF RETURN (
75
, 352), (35, 35) */
/* CIF RETURN (
30
, 352), (35, 35) */
RETURN battery_discharged;
/* CIF
INPUT
(3
23
, 252), (10
8
, 35) */
INPUT dd(
charge
)
;
/* CIF TASK (
265
, 302), (
223
, 35) */
TASK charge :=
(charge + 1) mod 255
;
/* CIF NEXTSTATE (
342
, 352), (70, 35) */
/* CIF
PROVIDED
(3
90
, 252), (10
1
, 35) */
PROVIDED
charge
> 5
;
/* CIF TASK (
389
, 302), (
104
, 35) */
TASK charge :=
0
;
/* CIF NEXTSTATE (
406
, 352), (70, 35) */
NEXTSTATE -;
ENDSTATE;
ENDSUBSTRUCTURE;
...
...
@@ -69,9 +75,6 @@ external;
START;
/* CIF NEXTSTATE (140, 266), (100, 35) */
NEXTSTATE nominal;
/* CIF STATE (614, 272), (95, 35) */
STATE backup;
ENDSTATE;
/* CIF STATE (422, 480), (100, 35) */
STATE nominal;
/* CIF CONNECT (472, 535), (0, 35) */
...
...
@@ -79,6 +82,9 @@ external;
/* CIF NEXTSTATE (424, 585), (95, 35) */
NEXTSTATE backup;
ENDSTATE;
/* CIF STATE (614, 272), (95, 35) */
STATE backup;
ENDSTATE;
ENDPROCESS car;
ENDBLOCK;
ENDSYSTEM;
\ No newline at end of file
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