Commit 728cb09e authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[lib] black

parent a16324b6
......@@ -44,8 +44,14 @@ Visitor for simulator generation
from __future__ import print_function
import sys
from cadbiom.models.guard_transitions.simulator.chart_simul_elem import Place, \
STransition, Event, Condition, InputPlace, InputEvent
from cadbiom.models.guard_transitions.simulator.chart_simul_elem import (
Place,
STransition,
Event,
Condition,
InputPlace,
InputEvent,
)
from cadbiom.models.biosignal.sig_expr import SigIdentExpr
from cadbiom.models.biosignal.translators.gt_visitors import compile_cond, compile_event
......@@ -58,6 +64,7 @@ class GenSimVisitor(object):
"""
Generate a simulator model - needs a symbol table of the charter model
"""
def __init__(self, tab_symb, mod, free_clocks, report):
"""
This visitor fill a simulation object - identifiers must be in
......@@ -154,8 +161,8 @@ class GenSimVisitor(object):
"""
macro nodes are treated as simple nodes (no real macros allowed)
"""
if len(node.sub_nodes) >0:
self.error_reporter.display("Macro node "+node.name+" is not empty")
if len(node.sub_nodes) > 0:
self.error_reporter.display("Macro node " + node.name + " is not empty")
self.error = True
self.visit_csimple_node(node)
return
......@@ -165,7 +172,7 @@ class GenSimVisitor(object):
trap node is unique for all the system
it is created here
"""
trap_all = Place(None, '_trap_')
trap_all = Place(None, "_trap_")
self.mod_symb_tab["__trap_all__"] = trap_all
self.sim_model.add_place(trap_all)
self.sim_model.trap = trap_all
......@@ -185,21 +192,19 @@ class GenSimVisitor(object):
main visitor - the code generation is dispatched in
several helper methods
"""
if trans.ori.is_start(): # transition from start
if trans.ori.is_start(): # transition from start
# nothing to do (start is a frontier mark)
return
elif trans.ori.is_input(): # transition from input
elif trans.ori.is_input(): # transition from input
self.build_input_transition(trans)
elif trans.ext.is_trap(): # transition to trap node
elif trans.ext.is_trap(): # transition to trap node
self.build_transition(trans, True)
else: # standard transition
self.build_transition(trans)
return
## auxiliary functions for compilation #####################################
def build_transition(self, trans, trap = False):
def build_transition(self, trans, trap=False):
"""
build a transition from a graph transition
@param trans: the chart transition
......@@ -208,7 +213,7 @@ class GenSimVisitor(object):
model = self.sim_model
tab_symb = self.tab_symb
report = self.error_reporter
report.set_context(trans.ori.name+'->'+trans.ext.name)
report.set_context(trans.ori.name + "->" + trans.ext.name)
try:
ori = self.mod_symb_tab[trans.ori.name]
if trap:
......@@ -222,18 +227,20 @@ class GenSimVisitor(object):
"%s -> %s %s\n"
"model symbol table: %s\n",
exc,
trans.ori.name, trans.ext.name, trap,
self.mod_symb_tab
trans.ori.name,
trans.ext.name,
trap,
self.mod_symb_tab,
)
sys.exit(1)
trs = STransition(ori, ext, trans)
self.mod_symb_tab[trans.get_key()] = trs
# event
if len(trans.event)>0:
if len(trans.event) > 0:
event_text = trans.event
event_tree, st_ev, fcl = compile_event(event_text, tab_symb,
self.free_clock_collect,
report)
event_tree, st_ev, fcl = compile_event(
event_text, tab_symb, self.free_clock_collect, report
)
if self.free_clock_collect:
self.free_clocks.extend(fcl)
evt = Event(event_tree)
......@@ -246,24 +253,25 @@ class GenSimVisitor(object):
evt = Event(SigIdentExpr(ev_n))
self.mod_symb_tab[ev_n] = evt
self.sim_model.add_event(evt, ev_n)
state_name = ev_n[:-1] # ev_n = state> or ev_n = state<
state_name = ev_n[:-1] # ev_n = state> or ev_n = state<
sign = ev_n[-1]
place = self.mod_symb_tab[state_name]
if sign == '>':
if sign == ">":
place.ev_up = evt
else:
place.ev_down = evt
# condition
if len(trans.condition)>0:
if len(trans.condition) > 0:
cond_text = trans.condition
cond_tree = compile_cond(cond_text, tab_symb, report)
cond = Condition(cond_tree)
trs.set_condition(cond)
# action (signal)
if len(trans.action)>0:
if len(trans.action) > 0:
act_text = trans.action
act_tree, ste, fcl = compile_event(act_text, tab_symb,
self.free_clock_collect, report)
act_tree, ste, fcl = compile_event(
act_text, tab_symb, self.free_clock_collect, report
)
if self.free_clock_collect:
self.free_clocks.extend(fcl)
if act_tree.is_ident():
......@@ -280,7 +288,6 @@ class GenSimVisitor(object):
self.error = True
self.sim_model.add_transition(trs)
def build_input_transition(self, trans):
"""
Build a perm place (if not already done) and a transition from
......@@ -305,7 +312,7 @@ class GenSimVisitor(object):
except:
LOGGER.error(
"GenSimVisitor::build_input_transition: input place not built '%s'",
perm_name
perm_name,
)
sys.exit(1)
......@@ -318,20 +325,19 @@ class GenSimVisitor(object):
try:
evt = self.mod_symb_tab[ev_name]
except:
pass #TODO internal error
pass # TODO internal error
trs.set_event(evt)
# condition
if len(trans.condition)>0:
if len(trans.condition) > 0:
cond_text = trans.condition
cond_tree = compile_cond(cond_text, tab_symb, report)
cond = Condition(cond_tree)
trs.set_condition(cond)
# action
if len(trans.action)>0:
if len(trans.action) > 0:
act_text = trans.action
# cannot find free clocks in action
act_tree, ste, fcl = compile_event(act_text, tab_symb, False,
report)
act_tree, ste, fcl = compile_event(act_text, tab_symb, False, report)
if act_tree.is_ident():
# create the event if not already done
try:
......@@ -348,17 +354,16 @@ class GenSimVisitor(object):
self.error = True
# helper functions
def input_perm_name(in_node):
"""
generate a standard name for pseudo perm places associated with inputs
"""
return "__"+in_node.name+"$$input"
return "__" + in_node.name + "$$input"
def input_trans_name(trans):
"""
generate a standard name for transitions
"""
return '__'+trans.ori.name+"__"+trans.ext.name
return "__" + trans.ori.name + "__" + trans.ext.name
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