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

Handle properly continuous states

Was missing elsif statements
parent 4775e60a
......@@ -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
......
......@@ -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 (41, 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 (323, 252), (108, 35) */
INPUT dd(charge);
/* CIF TASK (265, 302), (223, 35) */
TASK charge := (charge + 1) mod 255;
/* CIF NEXTSTATE (342, 352), (70, 35) */
/* CIF PROVIDED (390, 252), (101, 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
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