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, ...@@ -732,6 +732,8 @@ package {process_name} is'''.format(process_name=process_name,
# Process the continuous states in state aggregations first # Process the continuous states in state aggregations first
done = [] done = []
sep = 'if '
last = ''
for cs, agg in product(process.cs_mapping.viewitems(), for cs, agg in product(process.cs_mapping.viewitems(),
aggregates.viewitems()): aggregates.viewitems()):
(statename, cs_item), (agg_name, substates) = cs, agg (statename, cs_item), (agg_name, substates) = cs, agg
...@@ -747,9 +749,13 @@ package {process_name} is'''.format(process_name=process_name, ...@@ -747,9 +749,13 @@ package {process_name} is'''.format(process_name=process_name,
trId = process.transitions.index\ trId = process.transitions.index\
(provided_clause.transition) (provided_clause.transition)
code, loc = generate(provided_clause.trigger, code, loc = generate(provided_clause.trigger,
branch_to=trId) branch_to=trId,
sep=sep, last=last)
sep='elsif '
taste_template.extend(code) taste_template.extend(code)
done.append(statename) done.append(statename)
taste_template.append(u'end if;')
sep = 'if '
break break
for statename in process.cs_mapping.viewkeys() - done: for statename in process.cs_mapping.viewkeys() - done:
cs_item = process.cs_mapping[statename] cs_item = process.cs_mapping[statename]
...@@ -758,10 +764,12 @@ package {process_name} is'''.format(process_name=process_name, ...@@ -758,10 +764,12 @@ package {process_name} is'''.format(process_name=process_name,
for provided_clause in cs_item: for provided_clause in cs_item:
trId = process.transitions.index(provided_clause.transition) trId = process.transitions.index(provided_clause.transition)
code, loc = generate(provided_clause.trigger, code, loc = generate(provided_clause.trigger,
branch_to=trId) branch_to=trId, sep=sep, last=last)
sep='elsif '
taste_template.extend(code) taste_template.extend(code)
if process.cs_mapping: if process.cs_mapping:
taste_template.append(u'end if;') taste_template.append(u'end if;')
taste_template.append(u'end if;')
taste_template.append('end loop;') taste_template.append('end loop;')
taste_template.append('end runTransition;') taste_template.append('end runTransition;')
...@@ -1879,7 +1887,7 @@ def _choiceitem(choice): ...@@ -1879,7 +1887,7 @@ def _choiceitem(choice):
@generate.register(ogAST.Decision) @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 ''' Generate the code for a decision
A decision is made of a question and some answers ; each answer may A decision is made of a question and some answers ; each answer may
be followed by a transition (ogAST.Transition). The code of the be followed by a transition (ogAST.Transition). The code of the
...@@ -1919,7 +1927,6 @@ def _decision(dec, branch_to=None, **kwargs): ...@@ -1919,7 +1927,6 @@ def _decision(dec, branch_to=None, **kwargs):
code.extend(q_stmts) code.extend(q_stmts)
if not basic: if not basic:
code.append('tmp{idx} := {q};'.format(idx=dec.tmpVar, q=q_str)) code.append('tmp{idx} := {q};'.format(idx=dec.tmpVar, q=q_str))
sep = 'if '
for a in dec.answers: for a in dec.answers:
code.extend(traceability(a)) code.extend(traceability(a))
if a.kind in ('open_range', 'constant'): if a.kind in ('open_range', 'constant'):
...@@ -1994,9 +2001,11 @@ def _decision(dec, branch_to=None, **kwargs): ...@@ -1994,9 +2001,11 @@ def _decision(dec, branch_to=None, **kwargs):
code.extend(else_code) code.extend(else_code)
except: except:
pass pass
if sep != 'if ': if sep != 'if ' and last:
# If there is at least one 'if' branch # 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 return code, local_decl
......
...@@ -39,17 +39,23 @@ external; ...@@ -39,17 +39,23 @@ external;
NEXTSTATE discharge; NEXTSTATE discharge;
/* CIF STATE (152, 197), (114, 35) */ /* CIF STATE (152, 197), (114, 35) */
STATE discharge; 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; PROVIDED charge = 0;
/* CIF TASK (41, 302), (104, 35) */ /* CIF TASK (-4, 302), (104, 35) */
TASK charge := 5; TASK charge := 5;
/* CIF RETURN (75, 352), (35, 35) */ /* CIF RETURN (30, 352), (35, 35) */
RETURN battery_discharged; RETURN battery_discharged;
/* CIF INPUT (323, 252), (108, 35) */ /* CIF PROVIDED (390, 252), (101, 35) */
INPUT dd(charge); PROVIDED charge > 5;
/* CIF TASK (265, 302), (223, 35) */ /* CIF TASK (389, 302), (104, 35) */
TASK charge := (charge + 1) mod 255; TASK charge := 0;
/* CIF NEXTSTATE (342, 352), (70, 35) */ /* CIF NEXTSTATE (406, 352), (70, 35) */
NEXTSTATE -; NEXTSTATE -;
ENDSTATE; ENDSTATE;
ENDSUBSTRUCTURE; ENDSUBSTRUCTURE;
...@@ -69,9 +75,6 @@ external; ...@@ -69,9 +75,6 @@ external;
START; START;
/* CIF NEXTSTATE (140, 266), (100, 35) */ /* CIF NEXTSTATE (140, 266), (100, 35) */
NEXTSTATE nominal; NEXTSTATE nominal;
/* CIF STATE (614, 272), (95, 35) */
STATE backup;
ENDSTATE;
/* CIF STATE (422, 480), (100, 35) */ /* CIF STATE (422, 480), (100, 35) */
STATE nominal; STATE nominal;
/* CIF CONNECT (472, 535), (0, 35) */ /* CIF CONNECT (472, 535), (0, 35) */
...@@ -79,6 +82,9 @@ external; ...@@ -79,6 +82,9 @@ external;
/* CIF NEXTSTATE (424, 585), (95, 35) */ /* CIF NEXTSTATE (424, 585), (95, 35) */
NEXTSTATE backup; NEXTSTATE backup;
ENDSTATE; ENDSTATE;
/* CIF STATE (614, 272), (95, 35) */
STATE backup;
ENDSTATE;
ENDPROCESS car; ENDPROCESS car;
ENDBLOCK; ENDBLOCK;
ENDSYSTEM; 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