Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/34.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
refactor: Use ansys-eseg-lbsjv 0.1.0 for generating `pydata.py`
16 changes: 8 additions & 8 deletions src/ansys/scade/python_wrapper/kcg_data_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ def _build_operator(model: data.Model, m_op: m.Operator):
op.context.pointer = True
# if assertions fail, remove shortcomings in the implementation
assert len(c_op.get_init().get_parameters()) == 1
op.init.link_parameter(op.context)
op.init.add_parameter(op.context)
assert len(c_op.get_reset().get_parameters()) == 1
op.reset.link_parameter(op.context)
op.reset.add_parameter(op.context)

for m_input in m_op.get_inputs():
c_input = m_input.get_generated()
Expand All @@ -169,10 +169,10 @@ def _build_operator(model: data.Model, m_op: m.Operator):
op.add_io(io)
if isinstance(c_input, c.Parameter):
assert op.cycle
op.cycle.link_parameter(io)
op.cycle.add_parameter(io)
else:
assert op.in_context
op.in_context.link_io(io)
op.in_context.add_io(io)
model.map_item(c_input, io)

for m_output in m_op.get_outputs():
Expand All @@ -191,10 +191,10 @@ def _build_operator(model: data.Model, m_op: m.Operator):
io.sizes, io.type = _build_type(model, c_type)
if isinstance(c_output, c.Parameter):
assert op.cycle
op.cycle.link_parameter(io)
op.cycle.add_parameter(io)
else:
assert op.context
op.context.link_io(io)
op.context.add_io(io)
model.map_item(c_output, io)
else:
# single scalar output
Expand All @@ -215,9 +215,9 @@ def _build_operator(model: data.Model, m_op: m.Operator):
# update the parameters of cycle w.r.t. the contexts
if op.in_context:
assert not op.cycle.parameters
op.cycle.link_parameter(op.in_context)
op.cycle.add_parameter(op.in_context)
if op.context:
op.cycle.link_parameter(op.context)
op.cycle.add_parameter(op.context)

model.add_operator(op)
model.map_item(c_op, op)
62 changes: 43 additions & 19 deletions src/ansys/scade/python_wrapper/pydata.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CK(Enum):
#%% classes

#{{class(2)
class Entity(object):
class Entity:
def __init__(self, c_name: str = '', m_name: str = '', path: str = '', *args, **kwargs):
self.c_name: str = c_name
self.m_name: str = m_name
Expand Down Expand Up @@ -107,6 +107,10 @@ def __init__(self, input: bool = False, return_: bool = False, pointer: bool = F
self.return_: bool = return_
self.context: Context = None
self.pointer: bool = pointer

def set_context(self, context: 'Context'):
self.context = context
context.ios.append(self)
#}}class


Expand All @@ -124,9 +128,11 @@ def __init__(self, *args, **kwargs):
self.fields: List[Feature] = []
self.context: Context = None

def add_field(self, field: Feature):
def add_field(self, field: 'Feature'):
self.fields.append(field)
#<<link_25
field._owner = self
#>>link_25
#}}class


Expand All @@ -138,14 +144,14 @@ def __init__(self, pointer: bool = False, kind: CK = CK.CONTEXT, *args, **kwargs
self.pointer: bool = pointer
self.kind: CK = kind

def add_io(self, io: 'IO'):
self.ios.append(io)
io.context = self

#<<cls
def link_type(self, type_: Type):
self.type = type_
type_.context = self

def link_io(self, io: IO):
self.ios.append(io)
io.context = self
#>>cls
#}}class

Expand All @@ -165,10 +171,10 @@ def __init__(self, *args, **kwargs):
self.parameters: List[Typed] = []
self.return_: Typed = None

#<<cls
def link_parameter(self, typed: Typed):
self.parameters.append(typed)
def add_parameter(self, parameter: 'Typed'):
self.parameters.append(parameter)

#<<cls
def link_return(self, typed: Typed):
self.return_ = typed
#>>cls
Expand All @@ -187,34 +193,46 @@ def __init__(self, header: str = '', *args, **kwargs):
self.reset: Function = None
self.header: str = header

def set_in_context(self, in_context: Context):
def set_in_context(self, in_context: 'Context'):
self.in_context = in_context
#<<link_11
in_context._owner = self
#>>link_11

def set_context(self, context: Context):
def set_context(self, context: 'Context'):
self.context = context
#<<link_12
context._owner = self
#>>link_12

def add_io(self, io: IO):
def add_io(self, io: 'IO'):
self.ios.append(io)
#<<link_13
io._owner = self
#>>link_13

def set_cycle(self, cycle: Function):
def set_cycle(self, cycle: 'Function'):
self.cycle = cycle
#<<link_33
cycle._owner = self
#>>link_33

def set_init(self, init: Function):
def set_init(self, init: 'Function'):
self.init = init
#<<link_34
init._owner = self
#>>link_34

def set_reset(self, reset: Function):
def set_reset(self, reset: 'Function'):
self.reset = reset
#<<link_35
reset._owner = self
#>>link_35
#}}class


#{{class(26)
class Model(object):
class Model:
def __init__(self, prefix: str = '', elaboration: str = '', *args, **kwargs):
self.types: List[Type] = []
self.operators: List[Operator] = []
Expand All @@ -226,17 +244,23 @@ def __init__(self, prefix: str = '', elaboration: str = '', *args, **kwargs):
self._mapping = {}
#>>init

def add_type(self, type: Type):
def add_type(self, type: 'Type'):
self.types.append(type)
#<<link_27
type._owner = self
#>>link_27

def add_operator(self, operator: Operator):
def add_operator(self, operator: 'Operator'):
self.operators.append(operator)
#<<link_28
operator._owner = self
#>>link_28

def add_sensor(self, sensor: Global):
def add_sensor(self, sensor: 'Global'):
self.sensors.append(sensor)
#<<link_29
sensor._owner = self
#>>link_29

#<<cls
def get_mapped_entity(self, item: object) -> Entity:
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/scade/python_wrapper/swan_data_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def _build_function(model: data.Model, file, atts):
typed.pointer = parameter['pointer']
if not typed.type:
_build_typed(model, typed, parameter['type'])
function.link_parameter(typed)
function.add_parameter(typed)

type_id = atts.get('return_type')
if type_id:
Expand All @@ -354,7 +354,7 @@ def _build_function(model: data.Model, file, atts):
for field in op.context.type.fields:
io = ios.get(field.m_name)
if io:
op.context.link_io(io)
op.context.add_io(io)
io.sizes = field.sizes
io.type = field.type
io.c_name = field.c_name
Expand Down
Loading
Loading