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(project_path: str | Path) Project#
Create a new project.
- Parameters:
- project_path
Union[str,Path] Project location.
- project_path
- Returns:
ProjectProject object.
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:
- kind
ResourceKind Kind of the resource.
- file_path
Union[Path,str] Path to the resource file.
- key_name
Optional[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.
- kind
- Returns:
ResourceThe created resource object.
- Raises:
ScadeOneExceptionIf 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:
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_elt
swan.ModuleBody Content of the module body
- swan_elt
- Model.add_interface(swan_elt: ModuleInterface) None#
Add a module interface to the model.
- Parameters:
- swan_elt
swan.ModuleInterface Content of the module interface
- swan_elt
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:
ModuleModule object.
- Project.add_module_interface(name: str) ModuleInterface#
Create a module interface and add it to the model.
- Parameters:
- name: str
Module name.
- Returns:
ModuleInterfaceModuleInterface 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:
DeclarationDeclaration 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:
UseDirectiveUseDirective 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:
ConstDeclConstant 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:
SensorDeclSensor 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:
TypeDeclType 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:
TypeDeclType 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:
GroupDeclGroup 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:
TypeDeclType 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:
OperatorOperator 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:
OperatorDeclarationOperator 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:
OperatorOperator 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:
OperatorDeclarationOperator 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:
VarDeclVariable 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:
VarDeclVariable object.
- OperatorDefinition.add_diagram() swan.Diagram#
Add a diagram to the operator definition.
- Returns:
DiagramDiagram object.
Equation content creation#
Equations are grouped in a let section. For more information about LetSection, see Equations.
Following LetSection methods are used for creation:
- LetCreator.add_automaton(name: str | None = None, lhs: list[swan.LHSItem | str] | None = None, is_partial: bool = False) swan.StateMachine#
Create and add an automaton as equation of the LetSection.
- Parameters:
- name
str,optional The optional name of the automaton to create.
- lhs
List[swan.LHSItem|str] |None,optional List of LHS (left-hand side) items or None. Can be provided as string list for convenience.
- is_partialbool,
optional Flag indicating whether the LHS equation is partial or complete. Default is False.
- name
- Returns:
StateMachineThe created automaton.
- LetCreator.remove_automaton(name: str) None#
Remove by name an automaton from the LetSection.
- Parameters:
- name
str The name of the automaton to remove.
- name
- Raises:
ValueErrorIf the automaton name is not defined.
Diagram content creation#
Following Diagram 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:
BlockBlock 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:
DefBlockDefBlock 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:
ExprBlockExprBlock object.
- DiagramCreator.add_automaton(name: str) swan.StateMachine#
Add an automaton to the operator diagram.
- Parameters:
- name
str Automaton name.
- name
- Returns:
StateMachineThe created state machine instance.
- 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:
WireWire object that connects the blocks.
State machine creation#
Following StateMachine methods are used for creation:
- StateMachineCreator.add_state(name: str, is_initial: bool = False, is_default: bool = False) swan.State#
Add a state to the state machine.
- StateMachineCreator.add_weak_transition(source: swan.State, target: swan.State, priority: int | None = None, guard: swan.Expression | str = 'true', action: swan.Scope | str | None = None) swan.Transition#
Add a weak transition between states.
The created transition declaration is added to
StateMachine.transition_declsproperty of the state machine.- Parameters:
- source
swan.State The state from which the transition starts.
- target
swan.State The state to which the transition goes.
- priority
Optional[int],optional The transition priority when several transitions have the same source state.
- guard
Union[swan.Expression|str],optional Expression representing the guard condition. Can be either a
swan.Expressionor a string. Default value is theswan.BooleanLiteraltrue.- action
Optional[swan.Scope|str],optional Expression representing the action to trigger. Can be either a
swan.Scopeor a string.
- source
- Returns:
TransitionThe created transition.
- StateMachineCreator.add_strong_transition(source: swan.State, target: swan.State, priority: int | None = None, guard: swan.Expression | str = 'true', action: swan.Scope | str | None = None) swan.Transition#
Add a strong transition between states.
The created transition declaration is added to
StateMachine.transition_declsproperty of the state machine.- Parameters:
- source
swan.State The state from which the transition starts.
- target
swan.State The state to which the transition goes.
- priority
Optional[int],optional The transition priority when several transitions have the same source state.
- guard
Union[swan.Expression|str],optional Expression representing the guard condition. Can be either a
swan.Expressionor a string. Default value is theswan.BooleanLiteraltrue.- action
Optional[swan.Scope|str],optional Expression representing the action to trigger. Can be either a
swan.Scopeor a string.
- source
- Returns:
TransitionThe created transition.
- StateMachineCreator.remove_transition(transition: swan.Transition) None#
Remove a transition from its owner.
- Parameters:
- transition
Transition The transition to remove.
- transition
State content creation#
Following State methods are used for creation:
- StateCreator.add_local_variable(name: str, var_type: str) swan.VarDecl#
Add a local variable to the state’s diagram.
- StateCreator.add_section(section: str | swan.Scope) None#
Add a section to the state.
- Parameters:
- section
Scope The section to add to the state.
- section
Transition content creation#
Following Transition methods are used for creation:
- TransitionCreator.add_fork(guard: swan.Expression | str = 'true', action: swan.Scope | str | None = None) tuple[swan.Fork, swan.Transition]#
Add a fork to the transition (either between two states or between a fork and a state).
The target of the transition is modified to point to the future fork. The returned fork is created with one default outgoing transition pointing to the original transition target. The outgoing transition type (strong or weak) is the same as the original transition type.
- Parameters:
- guard
Union[swan.Expression|str],optional Expression representing the guard condition. Can be either a
swan.Expressionor a string. Default value is theswan.BooleanLiteraltrue.- action
Optional[swan.Section|str],optional Expression representing the action to trigger. Can be either a
swan.Sectionor a string.
- guard
- Returns:
Fork,TransitionThe created fork with one outgoing transition between the fork and the original transition target
Fork content creation#
Following Fork methods are used for creation:
- ForkCreator.add_fork_transition(target: swan.State, priority: int, guard: swan.Expression | str = 'true', action: swan.Scope | str | None = None, is_resume: bool = False, is_else: bool = False) swan.Transition#
Add a new transition starting from the fork to the state provided in argument.
The transition type (weak or strong) is the same as the incoming transition of the fork. To create an else branch transition, do not provide any guard condition, use parameter is_else=True and invoke this method last after creating all other fork transitions.
- Parameters:
- target
swan.State The state to which the transition goes.
- priority
int The transition priority when several transitions have the same source fork.
- guard
Union[swan.Expression|str],optional Expression representing the guard condition. Can be either a
swan.Expressionor a string. Default value is theswan.BooleanLiteraltrue.- action
Optional[swan.Scope|str],optional Expression representing the action to trigger. Can be either a
swan.Scopeor a string.- is_resumebool,
optional True if the transition is a resume transition, False for restart transition. Default is False.
- is_elsebool,
optional True if the transition is an else branch transition, False otherwise. Default is False. Note that an else branch transition must not have any guard condition.
- target
- Returns:
TransitionThe transition starting from the fork to the target state
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:
TestHarnessTest harness object.
Test harness creation#
A harness contains a diagram.
- TestHarness.add_diagram() swan.Diagram#
Add a diagram to the operator definition.
- Returns:
DiagramDiagram 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:
BlockBlock object.
- DiagramCreator.add_oracle(key: str) swan.Block#
Add an oracle block.
- Parameters:
- key: str
Oracle key.
- Returns:
BlockBlock object.
- DiagramCreator.add_set_sensor(instance: swan.SensorDecl) swan.SetSensorBlock#
Add a set sensor block to the diagram.
- Parameters:
- instance: SensorDecl
Sensor instance.
- Returns:
SetSensorBlockSet 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:
BlockBlock object.