Generated code#
This section contains the classes related to Scade One Generated Code.
It relies on the JSON mapping file generated by Scade One CG via a code generation job defined in a Scade One project.
from ansys.scadeone.core import ScadeOne
from ansys.scadeone.core.svc.generated_code import GeneratedCode
with ScadeOne() as app:
project = app.load_project('project.sproj')
code_gen = GeneratedCode(project, "CodeGen")
From the GeneratedCode
object, methods are provided to navigate in the model as it is defined in the mapping file
in order to get the corresponding generated code artifacts.
The next sections describe:
the main class for generated code
GeneratedCode
,the classes related to model elements,
the classes related to generated code.
Main class#
This section describes the main class for generated code.
- class ansys.scadeone.core.svc.generated_code.GeneratedCode(project: Project, job_name: str)#
Bases:
object
Generated code main class.
- Parameters:
- project: Project
Current project.
- job_name: str
Code generation name.
- decompose_code_type(ctype: dict) dict #
Returns (as a dictionary) the C type name, category (array, struct, enum, union, typedef, predefined_type) and sub elements of a given type element.
The sub elements depends on the category:
For an array, it is a dictionary with base_type giving the type data of the element (same format as this method) and size giving the size of the array.
For a struct, it is a list of dictionaries, with name giving the field name, type giving the field type data (same format as this method), pointer indicating if field is a pointer type and size giving optional list of integer or constant names.
For an enum, it is a dictionary with tag_name giving internal tag name for the enum, and values giving the list of names corresponding to the enum values.
For a union, it is a list of dictionaries, with name giving the variant field name, type giving the variant field type data (same format as this method) and enum_value giving optional integer value.
For a typedef (imported type), it is the function names used to manipulate the imported type.
For a predefined_type, it is None.
- get_code_elem(code_id: int) dict #
Returns (as a dictionary) the code data corresponding to given code identifier.
code_index: position of the element in the code section list
parent_category: category (declarations, function, struct, enum, union) of the parent code element
parent_name: name of the parent code element
parent_id: code identifier of the parent code element
category: category (declarations, function, struct, enum, union) of the code element
content: data content (the element itself)
index: position of the element in the declaration
- get_code_id(model_id: int, role: str = '', silent: bool = False) int #
Returns the code identifier associated to a given model identifier for a given role.
If silent is set to True, the functions returns -1 in case no code is found. Otherwise, exception is raised.
- get_code_ids(model_id: int) Generator[Tuple[int, str], None, None] #
Returns the list of code identifiers associated to a given model identifier (as a Generator of code, role tuples).
- get_model_elements(filter: str = '') Generator[List[str | dict], None, None] #
Returns the list of model elements defined in the mapping file (as a Generator of MapElem objects).
If filter is set, returns only the elements of the given category (elaboration, predefined_type, array, struct, enum, variant, named_type, sensor, operator, mono).
- get_model_monomorphic_instance(name: str) ModelMonomorphicInstance #
Returns the ModelMonomorphicInstance object corresponding to given operator path name.
- get_model_monomorphic_instances() List[ModelMonomorphicInstance] #
Returns the list of ModelMonomorphicInstance objects for the mapping file.
- get_model_operator(name: str) ModelOperator #
Returns the ModelOperator object corresponding to given operator path name.
- get_model_operators() List[ModelOperator] #
Returns the list of ModelOperator objects for the mapping file.
- get_model_sensor(name: str) ModelSensor #
Returns the ModelSensor object corresponding to given sensor path name.
- get_model_sensors() List[ModelSensor] #
Returns the list of ModelSensor objects for the mapping file.
Model classes#
Model classes are used to represent the model elements:
ModelOperator
represents a model operatorModelMonomorphicInstance
represents a monomorphic instance (after generic type resolution)ModelVariable
represents a model variable (input or output)ModelVariableMonomorphic
represents a monomorphic variable (after generic type resolution)ModelSensor
represents a model sensor
- class ansys.scadeone.core.svc.generated_code.ModelOperator(gen_code: GeneratedCode, oper_elem: dict)#
Bases:
ModelOperatorBase
Class for model operator.
gen_code: GeneratedCode object
oper_elem: mapping file element
- get_code_elem(role: str = '', silent: bool = False) dict | None #
Returns the data associated to the model element, if any.
- property cycle_method: CFunction | None#
Returns the cycle method C function for the operator (as a CFunction object), if any.
- property init_method: CFunction | None#
Returns the init method C function for the operator (as a CFunction object), if any.
- property inputs: List[ModelVariable]#
Returns the list of inputs for the operator (as ModelVariable objects).
- property instances: List[dict]#
Returns the list of instances for the operator (as raw data, to be completed).
- property outputs: List[ModelVariable]#
Returns the list of outputs for the operator (as ModelVariable objects).
- class ansys.scadeone.core.svc.generated_code.ModelMonomorphicInstance(gen_code: GeneratedCode, oper_elem: dict)#
Bases:
ModelOperatorBase
Class for monomorphic instance of polymorphic model operator.
gen_code: GeneratedCode object
oper_elem: mapping file element
- get_code_elem(role: str = '', silent: bool = False) dict | None #
Returns the data associated to the model element, if any.
- property cycle_method: CFunction | None#
Returns the cycle method C function for the operator (as a CFunction object), if any.
- property init_method: CFunction | None#
Returns the init method C function for the operator (as a CFunction object), if any.
- property inputs: List[ModelVariableMonomorphic]#
Returns the list of inputs for the operator (as ModelVariableMonomorphic objects).
- property instances: List[dict]#
Returns the list of instances for the operator (as raw data, to be completed).
- property outputs: List[ModelVariableMonomorphic]#
Returns the list of outputs for the operator (as ModelVariableMonomorphic objects).
- property reset_method: CFunction | None#
Returns the reset method C function for the operator (as a CFunction object), if any.
- property source: ModelOperator#
Returns ModelOperator object source of the monomorphic instance.
- class ansys.scadeone.core.svc.generated_code.ModelVariable(gen_code: GeneratedCode, var_elem: dict, parent: ModelOperator)#
Bases:
ModelVariableBase
Class for model variables (inputs or outputs) of operator.
gen_code: GeneratedCode object
var_elem: mapping file element
parent: ModelOperator object of the parent operator
- full_name(separator: str = '_') str #
Returns variable name taking into account group item(s) to suffix the name when applicable (main separator between the operator variable name and group item(s) name can be changed, default is ‘_’)
- get_code_elem(role: str = '', silent: bool = False) dict | None #
Returns the data associated to the model element, if any.
- property code_type: dict#
Returns the generated C code data corresponding to the variable type. (‘name’: C type name, ‘category’: type category and ‘elements’: sub elements of the type)
- property group_items: List[str | int]#
Returns the group item(s) associated with variable (only applicable for group type).
- property parent: ModelOperator#
Returns the model operator object owning the variable
- class ansys.scadeone.core.svc.generated_code.ModelVariableMonomorphic(gen_code: GeneratedCode, var_elem: dict, parent: ModelMonomorphicInstance)#
Bases:
ModelVariableBase
Class for model variables (inputs or outputs) of monomorphic instance of operator.
gen_code: GeneratedCode object
var_elem: mapping file element
parent: ModelMonomorphicInstance object of the parent monomorphic instance
- get_code_elem(role: str = '', silent: bool = False) dict | None #
Returns the data associated to the model element, if any.
- property code_type: dict#
Returns the generated C code data corresponding to the variable type. (‘name’: C type name, ‘category’: type category and ‘elements’: sub elements of the type)
- property parent: ModelMonomorphicInstance#
Returns the model operator object owning the variable
- property source: ModelVariable#
Returns ModelVariable object source of the monomorphic instance variable.
- class ansys.scadeone.core.svc.generated_code.ModelSensor(gen_code: GeneratedCode, sensor_elem: dict)#
Bases:
ModelObject
Class for model sensors.
gen_code: GeneratedCode object
var_elem: mapping file element
- get_code_elem(role: str = '', silent: bool = False) dict | None #
Returns the data associated to the model element, if any.
Code classes#
Generated code classes are used to represent the generated code elements:
CFunction
represents a C functionCParameter
represents a C parameter
- class ansys.scadeone.core.svc.generated_code.CFunction(gen_code: GeneratedCode, function_elem: dict, code_container_index: int)#
Bases:
CDeclaration
Class for a generated C function.
gen_code: GeneratedCode object
function_elem: mapping file element
code_container_index: position in the list of code container elements
- property parameters: List[CParameter]#
Returns the function parameters as a list of CParameter objects.
- class ansys.scadeone.core.svc.generated_code.CParameter(gen_code: GeneratedCode, param_elem: dict)#
Bases:
MappingObject
Class for a parameter of a generated C function.
gen_code: GeneratedCode object
param_elem: mapping file element
Base classes#
- class ansys.scadeone.core.svc.generated_code.ModelOperatorBase(gen_code: GeneratedCode, oper_elem: dict)#
Bases:
ModelObject
Base class for model operator or monomorphic instance of an operator.
gen_code: GeneratedCode object
oper_elem: mapping file element
- get_code_elem(role: str = '', silent: bool = False) dict | None #
Returns the data associated to the model element, if any.
- property cycle_method: CFunction | None#
Returns the cycle method C function for the operator (as a CFunction object), if any.
- property init_method: CFunction | None#
Returns the init method C function for the operator (as a CFunction object), if any.
- property instances: List[dict]#
Returns the list of instances for the operator (as raw data, to be completed).
- class ansys.scadeone.core.svc.generated_code.ModelVariableBase(gen_code: GeneratedCode, var_elem: dict)#
Bases:
ModelObject
Base class for model variables (operators inputs or outputs).
gen_code: GeneratedCode object
var_elem: mapping file element
- get_code_elem(role: str = '', silent: bool = False) dict | None #
Returns the data associated to the model element, if any.
- property code_type: dict#
Returns the generated C code data corresponding to the variable type. (‘name’: C type name, ‘category’: type category and ‘elements’: sub elements of the type)
- abstract property parent: ModelOperatorBase#
Returns the model operator object owning the variable
- class ansys.scadeone.core.svc.generated_code.ModelObject(gen_code: GeneratedCode, model_elem: dict)#
Bases:
MappingObject
Base Class for mapping file model elements.
gen_code: GeneratedCode object
model_elem: mapping file element
- class ansys.scadeone.core.svc.generated_code.CDeclaration(gen_code: GeneratedCode, decl_elem: dict, code_container_index: int)#
Bases:
MappingObject
Base class for C declaration (function, global, macro, predefined_type, struct, array, enum, union, typedef, imported_type).
gen_code: GeneratedCode object
decl_elem: mapping file element
code_container_index: position in the list of code container elements
- class ansys.scadeone.core.svc.generated_code.MappingObject(gen_code: GeneratedCode, mapping_elem: dict)#
Bases:
ABC
Base class for all mapping file elements.
gen_code: GeneratedCode object
mapping_elem: mapping file element