Project creation#
This section provides the elements for creating or modifying a Scade One project. An example is provided in Create a Scade One project.
Best practices#
Constructing a Scade One project can be a complex task. The following best practices are recommended:
Create objects in the order of their dependencies. For example, create a module before creating its declarations.
Create a use directive before adding objects from other modules to its module. For instance, if a constant is created in a module, that constant cannot be used in another module unless the proper directive is created first. In the consumer module, the identifier of the constant depends on the use directive.
Project creation#
Following ScadeOne
methods is used for creation:
Module body and interface creation#
A module body or a module interface can be created from a model or a project. When added to a project, the module body or interface is automatically added to the model and its source is updated with respect to the project path.
Following Model
methods are used for creation:
- Model.add_body(swan_elt: SwanFile | ModuleBody) None #
Add a module body to the model.
The module body can be a SwanFile or a ModuleBody object. If it is a SwanFile, it is not loaded: this happens when needed. If it is a ModuleBody it is directly added to the model.
- Parameters:
- swan_elt
Union
[swan.SwanFile
,swan.ModuleBody
] Content of the module body
- swan_elt
- Model.add_interface(swan_elt: SwanFile | ModuleInterface) None #
Add a module interface to the model.
The module interface can be a SwanFile or a ModuleInterface object. If it is a SwanFile, it is not loaded: this happens when needed. If it is a ModuleInterfacee it is directly added to the model.
- Parameters:
- swan_elt
Union
[swan.SwanFile
,swan.ModuleInterface
] Content of the module interface
- swan_elt
Following Project
methods are used for creation:
- Project.add_module(name: str) Module #
Add a module to the project.
- Parameters:
- name: str
Module name.
- Returns:
Module
Module object.
- Project.add_module_interface(name: str) ModuleInterface #
Add a module interface to the model.
- Parameters:
- name: str
Module name.
- Returns:
ModuleInterface
ModuleInterface object.
Module declarations#
Following ModuleBody
and ModuleInterface
methods are used for creation:
Any declaration#
Add a declaration of any kind.
- Module.add_declaration(decl_expr: str) common.Declaration #
Add a declaration to the module.
- Parameters:
- decl_expr: str
Declaration expression.
- Returns:
Declaration
Declaration object.
Use directive creation#
- Module.use(module: swan.Module | str, alias: str = None) swan.UseDirective #
Add a use directive to the module.
- Parameters:
- module: Module
Module name.
- alias: Str
Module alias.
- Returns:
UseDirective
UseDirective object.
Constant and sensor declarations#
- Module.add_constant(name: str, type_str: str, value: str) swan.ConstDecl #
Add a constant to the module.
- Parameters:
- name: str
Constant name.
- type_str: Str
Constant type.
- value: Str
Constant value.
- Returns:
ConstDecl
Constant object.
- Module.add_sensor(name: str, type_str: str) swan.SensorDecl #
Add a sensor to the module.
- Parameters:
- name: str
Sensor name.
- type_str: Str
Sensor type.
- Returns:
SensorDecl
Sensor object.
Type creation#
- Module.add_enum(name: str, values: List[str]) swan.TypeDecl #
Add an enum to the module.
- Parameters:
- name: str
Enum name.
- values: List[Str]
Enum values.
- Returns:
TypeDecl
Type object.
- Module.add_struct(name: str, fields: dict[str, str]) swan.TypeDecl #
Add a struct to the module.
- Parameters:
- name: str
Struct name.
- fields: dict[str, str]
Struct fields (name, type).
- Returns:
TypeDecl
Type object.
- Module.add_group(name: str, types: str | List[str] | dict[str, str]) swan.GroupDecl #
Add a group to the module.
- Parameters:
- name: str
Group name.
- types: Union[str, List[str], dict[str, str]]
List of types (type or {name: type}).
- Returns:
GroupDecl
Group object.
- Module.add_type(name: str, type_str: str) swan.TypeDecl #
Add a type to the module.
- Parameters:
- name: str
Type name.
- type_str: str
Type definition as a string.
- Returns:
TypeDecl
Type object.
Operator creation#
- Module.add_operator(name: str, is_node: bool = True, is_inlined: bool = False) swan.Operator #
Add an operator to the module body.
- Parameters:
- name: str
Operator name.
- is_node: Bool
True if Node, otherwise Function.
- is_inlined: Bool
True if inline operator.
- Returns:
Operator
Operator object.
- Module.add_signature(name: str, is_node: bool = True, is_inlined: bool = False) swan.Signature #
Add an operator signature to the module.
- Parameters:
- name: str
Operator name.
- is_inlined: Bool
True if inline operator.
- is_node: Bool
True if Node, otherwise Function.
- Returns:
Signature
Signature object.
- Module.add_textual_operator(operator_str: str) swan.Operator #
Add a textual operator to the module body.
- Parameters:
- operator_str: str
Operator string.
- Returns:
Operator
Operator object.
- Module.add_textual_signature(operator_str: str) swan.Signature #
Add a textual operator signature to the module.
- Parameters:
- operator_str: str
Operator string.
- Returns:
Signature
Signature object.
Operator content creation#
Following Operator
methods are used for creation:
- Operator.add_input(name: str | None = None, input_type: str | swan.Declaration = None, is_clock: bool | None = False, is_probe: bool | None = False, when: str | None = None, default: str | None = None, last: str | None = None, declaration: str | None = None) swan.VarDecl #
Add an input to the operator. Input can be defined by name, type, … or by a text declaration.
- Parameters:
- name: str
Input name.
- input type: str or Declaration
Input type. It could be a text declaration or a Declaration object.
- is_clock: bool
Clock variable.
- is_probe: bool
Probe variable.
- when: str
When condition.
- default: str
Default value.
- last: str
Last value.
- declaration: str
Text declaration.
- Returns:
VarDecl
Variable object.
- Operator.add_output(name: str | None = None, output_type: str | swan.Declaration = None, is_clock: bool | None = False, is_probe: bool | None = False, when: str | None = None, default: str | None = None, last: str | None = None, declaration: str | None = None) swan.VarDecl #
Add an output to the operator signature. Output can be defined by name, type, … or by a text declaration.
- Parameters:
- name: str
Variable name.
- output_type: str or Declaration
Output type. It could be a text declaration or a Declaration object.
- is_clock: bool
Clock variable.
- is_probe: bool
Probe variable.
- when: str
When condition.
- default: str
Default value.
- last: str
Last value.
- declaration: str
Textual declaration.
- Returns:
VarDecl
Variable object.
- Operator.add_diagram() swan.Diagram #
Add a diagram to the operator.
- Returns:
Diagram
Diagram object.
Diagram content creation#
Following Diagram
methods are used for creation:
- Diagram.add_block(instance: swan.Operator) swan.Block #
Add an operator call to the operator.
- Parameters:
- instance: Operator
Operator instance.
- Returns:
Block
Block object.
- Diagram.add_def_block(variable: swan.VarDecl) swan.DefBlock #
Add a definition block to the operator.
- Parameters:
- variable: VarDecl
Local, input or output variable.
- Returns:
DefBlock
DefBlock object.
- Diagram.add_expr_block(declaration: swan.Declaration) swan.ExprBlock #
Add an expression block to the operator.
- Parameters:
- declaration: Declaration
Local or output variable.
- Returns:
ExprBlock
ExprBlock object.
- Diagram.connect(source: swan.DiagramObject | tuple[swan.DiagramObject, str], targets: swan.DiagramObject | tuple[swan.DiagramObject, str] | List[swan.DiagramObject] | List[tuple[swan.DiagramObject, str]]) swan.Wire #
Connect a block to one or more blocks.
- Parameters:
- source: DiagramObject
Block object.
- targets: Union[DiagramObject, List[DiagramObject]]
A block object or a list of block objects.
- Returns:
Wire
Wire object that connects the blocks.