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 method is used for creation:

ScadeOne.new_project(storage: str | Path) Project#

Create a new project.

Parameters:
storageUnion[str, Path]

Project location.

Returns:
Project

Project object.

property ScadeOne.version: str#

API version.

Resource creation#

Resource files can be added to a project and used on it. For more information about resources, see Resources.

For simulation data creation or edition, see Simulation data.

Following Project methods are used for managing resources:

Project.add_resource(kind: ResourceKind, file_path: Path | str, key_name: str | None = None, exist_check: bool = True) Resource#

Add a new resource to the project. For simulation data files (ResourceKind.SIMULATION_DATA), key_name must be provided.

Parameters:
kindResourceKind

Kind of the resource.

file_pathUnion[Path, str]

Path to the resource file.

key_nameOptional[str]

Key of the resource (for simulation data only).

exist_checkbool

Checks if file exists, raises exception if not. Default True. Can be disabled for debugging or placeholder use.

Returns:
Resource

The created resource object.

Raises:
ScadeOneException

If the resource file does not exist and exist_check is True. If the key name is already used in the project. If the file path is already in the project resources.

Dependencies management#

Following Project methods are used for managing dependencies:

Project.add_dependency(project: IProject) None#

Add a project as a dependency.

Parameters:
projectIProject

Project to add as a dependency.

Raises:
ScadeOneException

If the project is the same as the current project.

Project.remove_dependency(project: IProject) None#

Remove a project from the dependencies.

Parameters:
projectIProject

Project to remove from the dependencies.

Raises:
ScadeOneException

If the project is not a dependency.

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: ModuleBody) None#

Add a module body to the model.

Parameters:
swan_eltswan.ModuleBody

Content of the module body

Model.add_interface(swan_elt: ModuleInterface) None#

Add a module interface to the model.

Parameters:
swan_eltswan.ModuleInterface

Content of the module interface

Following Project methods are used for creation:

Project.add_module_body(name: str) ModuleBody#

Create a module body and add it to the model.

Parameters:
name: str

Module name.

Returns:
Module

Module object.

Project.add_module_interface(name: str) ModuleInterface#

Create a module interface and add it 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.

ModuleBodyCreator.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#

ModuleBodyCreator.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#

ModuleBodyCreator.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.

ModuleBodyCreator.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#

ModuleBodyCreator.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.

ModuleBodyCreator.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.

ModuleBodyCreator.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.

ModuleBodyCreator.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#

ModuleBodyCreator.add_operator_definition(name: str, is_node: bool = True, is_inlined: bool = False) swan.OperatorDefinition#

Add an operator definition to the module body or the test module.

Parameters:
name: str

Operator name.

is_node: bool

True if Node, otherwise Function.

is_inlined: bool

True if inline operator.

Returns:
Operator

Operator definition object.

ModuleBodyCreator.add_operator_declaration(name: str, is_node: bool = True, is_inlined: bool = False) swan.OperatorDeclaration#

Add an operator declaration to the module.

Parameters:
name: str

Operator name.

is_node: bool

True if Node, otherwise Function.

is_inlined: bool

True if inline operator.

Returns:
OperatorDeclaration

Operator declaration object.

ModuleBodyCreator.add_textual_operator_definition(operator_str: str) swan.OperatorDefinition#

Add a textual operator definition to the module body.

Parameters:
operator_str: str

Operator string.

Returns:
Operator

Operator definition object.

ModuleBodyCreator.add_textual_operator_declaration(operator_str: str) swan.OperatorDeclaration#

Add a textual operator declaration to the module.

Parameters:
operator_str: str

Operator string.

Returns:
OperatorDeclaration

Operator declaration object.

Operator content creation#

Following OperatorDefinition methods are used for creation:

OperatorDefinition.add_input(name: str | None = None, input_type: str | swan.Declaration = None, is_probe: bool = False, default: str | None = None, last: str | None = None, declaration: str | None = None) swan.VarDecl#

Add an input to the operator declaration. 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_probe: bool

Probe variable.

default: str

Default value.

last: str

Last value.

declaration: str

Text declaration.

Returns:
VarDecl

Variable object.

OperatorDefinition.add_output(name: str | None = None, output_type: str | swan.Declaration = None, is_probe: bool = False, default: str | None = None, last: str | None = None, declaration: str | None = None) swan.VarDecl#

Add an output to the operator declaration. 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_probe: bool

Probe variable.

default: str

Default value.

last: str

Last value.

declaration: str

Textual declaration.

Returns:
VarDecl

Variable object.

OperatorDefinition.add_diagram() swan.Diagram#

Add a diagram to the operator definition.

Returns:
Diagram

Diagram object.

Diagram content creation#

Following DiagramCreator methods are used for creation:

DiagramCreator.add_block(instance: swan.OperatorDefinition) swan.Block#

Add an operator call to the operator.

Parameters:
instance: OperatorDefinition

OperatorDefinition instance.

Returns:
Block

Block object.

DiagramCreator.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.

DiagramCreator.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.

DiagramCreator.add_bar() swan.Bar#

Add a bar to the operator.

Returns:
Bar

Bar object.

DiagramCreator.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.

Test creation#

Test module creation#

Module level:

TestModuleCreator.add_test_harness(name: str) swan.TestHarness#

Add a test harness to the module.

Parameters:
name: str

Test harness name.

Returns:
TestHarness

Test harness object.

Test harness creation#

A harness contains a diagram.

TestHarness.add_diagram() swan.Diagram#

Add a diagram to the operator definition.

Returns:
Diagram

Diagram object.

see Diagram content creation section.

Harness specific methods:

DiagramCreator.add_data_source(key: str) swan.Block#

Add a data source.

Parameters:
key: str

Source key.

Returns:
Block

Block object.

DiagramCreator.add_oracle(key: str) swan.Block#

Add an oracle block.

Parameters:
key: str

Oracle key.

Returns:
Block

Block object.

DiagramCreator.add_set_sensor(instance: swan.SensorDecl) swan.SetSensorBlock#

Add a set sensor block to the diagram.

Parameters:
instance: SensorDecl

Sensor instance.

Returns:
SetSensorBlock

Set sensor block object.

DiagramCreator.add_instance_under_test(instance: swan.OperatorDefinition) swan.Block#

Add an under test operator to the test harness.

Parameters:
instance: OperatorDefinition

Operator instance.

Returns:
Block

Block object.