Commit 0dc96941 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Prepare Ada backend for continous signals

parent 6a6adb9f
......@@ -148,6 +148,9 @@ The fonts are the fonts from Ubuntu, check licence in file FONT-LICENSE.TXT
Changelog
=========
1.3.5 (11/2015)
- Better support for continous signals
1.3.4 (11/2015)
- Early support for continous signals
- Regression issue fixed (test-nocif2)
......
......@@ -127,8 +127,7 @@ In the state() function, we replace the placeholder we added at step 2:
provided_part, err, warn = continuous_signal(child, state_def,
context)
state_def.continuous_signals.append(provided_part)
warnings.extend(warn)
errors.extend(err)
(...)
Then we can implement the continuous_signal function.
......@@ -152,6 +151,7 @@ new feature:
- Create an icon and add the new symbol to the palette
- Update the statechart renderer (Statechart.py)
- Update other backends that can be impacted, such as code generators (AdaGenerator.py, etc.)
- Update clipboard
5) Syntax checker in ogParser.py
......
......@@ -72,7 +72,7 @@
import logging
import traceback
import os
from itertools import chain
from itertools import chain, product
from singledispatch import singledispatch
import ogAST
......@@ -182,7 +182,7 @@ LD_LIBRARY_PATH=. taste-gui -l
# In case model has nested states, flatten everything
Helper.flatten(process, sep=UNICODE_SEP)
# Process State aggregations (Parallel states)
# Process State aggregations (Parallel states) XXX Add to C backend
# Find recursively in the AST all state aggregations
# Format: {'aggregation_name' : [list of ogAST.CompositeState]
......@@ -465,7 +465,7 @@ package {process_name} is'''.format(process_name=process_name,
else:
taste_template.append('null;')
taste_template.append('case {ctxt}.state is'.format(ctxt=LPREFIX))
taste_template.append('case {}.state is'.format(LPREFIX))
def case_state(state):
''' Recursive function (in case of state aggregation) to generate
......@@ -477,7 +477,6 @@ package {process_name} is'''.format(process_name=process_name,
return
taste_template.append(u'when {state} =>'.format(state=state))
input_def = mapping[signame].get(state)
#print signame, input_def
if state in aggregates.viewkeys():
# State aggregation:
# - find which substate manages this input
......@@ -720,9 +719,41 @@ package {process_name} is'''.format(process_name=process_name,
# Add the code for the floating labels
taste_template.extend(code_labels)
#if code_labels:
taste_template.append('<<next_transition>>')
taste_template.append('null;')
# After completing active transition(s), check continuous signals:
# - Check current state(s)
# - For each continuous signal generate code (test+transition)
# XXX add to C backend
if process.cs_mapping:
taste_template.append('-- Process continuous signals')
else:
taste_template.append('null;')
# Process the continuous states in state aggregations first
done = []
for cs, agg in product(process.cs_mapping.viewitems(),
aggregates.viewitems()):
(statename, cs_item), (agg_name, substates) = cs, agg
for each in substates:
if statename in each.mapping.viewkeys():
taste_template.append(u'{first}if trId = -1 and '
u'{ctxt}.state = {s1} and '
u'{ctxt}.{s2}{sep}state = {s3} then'
.format(ctxt=LPREFIX, s1=agg_name,
s2=each.statename, sep=UNICODE_SEP,
s3=statename, first='els' if done else ''))
taste_template.append(u'null;')
done.append(statename)
break
for statename in process.cs_mapping.viewkeys() - done:
cs_item = process.cs_mapping[statename]
taste_template.append(u'{first}if trId = -1 and {}.state = {} then'
.format(LPREFIX, statename, first='els' if done else ''))
taste_template.append(u'null;')
if process.cs_mapping:
taste_template.append(u'end if;')
taste_template.append('end loop;')
taste_template.append('end runTransition;')
taste_template.append('\n')
......
......@@ -98,7 +98,7 @@ def copy_branch(top_level_item):
for symbol in symbols:
if (isinstance(symbol, sdlSymbols.State) and [c for c in
symbol.childSymbols() if isinstance(c, (sdlSymbols.Input,
sdlSymbols.Connect))]):
sdlSymbols.Connect, sdlSymbols.ContinuousSignal))]):
term_branch, term_inators = copy_branch(symbol)
branch.extend(term_branch)
res_terminators.extend(term_inators)
......
......@@ -150,7 +150,6 @@ def flatten(process, sep=u'_'):
term.next_id = u'{term}{sep}{entry}_START'.format(
term=term.inputString, entry=term.entrypoint, sep=sep)
elif term.inputString.strip() == '-':
#term.candidate_id = defaultdict(list)
for each in term.possible_states:
term.candidate_id[-1].append(each)
for comp in context.composite_states:
......@@ -176,6 +175,9 @@ def flatten(process, sep=u'_'):
state.mapping = {prefix + key: state.mapping.pop(key)
for key in state.mapping.keys()}
# Continuous signal mappings
state.cs_mapping = {prefix + key: state.cs_mapping.pop(key)
for key in state.cs_mapping.keys()}
process.transitions.extend(state.transitions)
# Add prefix to local variable names and push them at process level
......@@ -197,10 +199,16 @@ def flatten(process, sep=u'_'):
for key, value in state.mapping.viewitems():
# Update transition indices
if isinstance(value, int):
# START transitions
state.mapping[key] = value + trans_idx
else:
values.extend(value)
for each in state.cs_mapping.viewvalues():
# Update transition indices of continuous signals
# XXX shouldn't we do it also for CONNECT parts?
values.extend(value)
for inp in set(values):
# values may contain duplicate entries if an input corresponds
# to multiple states. In that case we must update the index of the
......@@ -208,6 +216,7 @@ def flatten(process, sep=u'_'):
inp.transition_id += trans_idx
process.mapping.update(state.mapping)
process.cs_mapping.update(state.cs_mapping)
# If composite state has entry procedures, add the call
if state.entry_procedure:
......
......@@ -547,7 +547,7 @@ class Transition(object):
self.terminator = None
# All Terminators of this transition
self.terminators = []
# List of State that can lead to this transition
# List of states (string) that can lead to this transition
# There can be several if state has multiple names (e.g. STATE a, b)
# Note, this field is updated by the Helper.flatten function
# and is needed to properly know when to call a nested state exit
......@@ -869,6 +869,9 @@ class Process(object):
# then Input contains the inputs list and corresponding transition
self.mapping = {}
# Similar mapping for continuous signals
self.cs_mapping = defaultdict(list)
# list of type Transition - use 'mapping' to map index to inputs/states
self.transitions = []
......
......@@ -3007,6 +3007,15 @@ def state(root, parent, context):
provided_part, err, warn = continuous_signal(child, state_def,
context)
state_def.continuous_signals.append(provided_part)
# Add the continuous signal to a mapping at context level,
# useful for code generation. Also check for duplicates.
for statename in state_def.statelist:
if provided_part in \
context.cs_mapping.get(statename.lower(), []):
sterr.append('Continous signal is defined more than once '
'below state "{}"'.format(statename.lower()))
else:
context.cs_mapping[statename.lower()].append(provided_part)
warnings.extend(warn)
errors.extend(err)
elif child.type == 0:
......
......@@ -116,7 +116,7 @@ except ImportError:
__all__ = ['opengeode', 'SDL_Scene', 'SDL_View', 'parse']
__version__ = '1.3.4'
__version__ = '1.3.5'
if hasattr(sys, 'frozen'):
# Detect if we are running on Windows (py2exe-generated)
......
......@@ -76,7 +76,7 @@ signal telemetry(tm_type);
STATE mode_manager;
ENDSTATE;
ENDSUBSTRUCTURE;
/* CIF TEXT (0, 310), (327, 168) */
/* CIF TEXT (0, 310), (327, 208) */
-- This system tests the provided clause
-- (continuous signal)
......@@ -85,6 +85,8 @@ dcl tc TC_type;
dcl tm TM_type;
dcl got_tc Boolean_type;
dcl anything boolean_Type := true;
/* CIF ENDTEXT */
/* CIF START (337, 297), (70, 35) */
START;
......@@ -92,6 +94,14 @@ dcl got_tc Boolean_type;
NEXTSTATE wait;
/* CIF STATE (412, 344), (70, 35) */
STATE wait;
/* CIF PROVIDED (394, 399), (106, 35) */
PROVIDED anything;
/* CIF TASK (363, 449), (168, 35) */
TASK anything := false;
/* CIF PROCEDURECALL (359, 499), (177, 35) */
CALL writeln('Lets go');
/* CIF NEXTSTATE (412, 549), (70, 35) */
NEXTSTATE wait;
ENDSTATE;
ENDPROCESS og;
ENDBLOCK;
......
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