Modules and Interfaces#

This section describes the classes that represent a module body or a module interface. It also describes the class representing a use directive which is used to reference a module/interface in an other module/interface.

../../../_images/module.svg

See also Operator declaration and Global declarations.

class ansys.scadeone.core.swan.ModuleBody(name: PathIdentifier, use_directives: List[UseDirective] | None = None, declarations: List[GlobalDeclaration] | None = None)#

Bases: Module

Module body definition.

body() ModuleBody#

Return the module body for a module interface if it exists.

filter_declarations(filter_fn) List[GlobalDeclaration]#

Return declarations matched by a filter.

Parameters:
filter_fnfunction

A function of one argument of type GlobalDeclaration, returning True or False.

Returns:
List[GlobalDeclaration]

List of matching declarations.

get_declaration(name: str) GlobalDeclaration#

Return the type, global, or operator declaration searching by namespace.

get_full_path() str#

Full Swan path of module.

get_use_directive(module_name: str) UseDirective | None#

Return the use directive searching by module name or alias name.

Aliases are searched first, the module name is searched if no alias is found. When a module name is searched, use directive with first occurrence is returned.

Parameters:
module_namestr

Name of the module (last part of a path) or alias.

Returns:
Found UseDirective or None
harness()#

Return the test harness if it exists.

interface() ModuleInterface#

Return the module interface for a module body if it exists.

static module_name_from_path(path: Path) str#

Returns a module name from a path.

Parameters:
pathPath

Path to the module, e.g. /path/to/namespace-module.swan

Returns:
str

Module name, e.g. namespace::module

static set_owner(owner: SwanItem | IProject | None, children: SwanItem | Iterable[SwanItem]) None#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem]]

Items to set owner.

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.

property constants: List[ConstDecl]#

Return a list of constant declarations.

property declarations: List[ModuleItem]#

Module’s declarations

property extension: str#

Return module extension, with ‘.’ included.

property file_name: str#

Return a file name based on module name and namespaces.

property groups: List[GroupDecl]#

Return a list of group declarations.

property is_protected: bool#

Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).

property model: Model#

Return model containing the Swan item.

property module: ModuleBase | None#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface or None if the object is itself a module.

property name: PathIdentifier#

Module or Interface name.

property operators: List[Operator]#

Return a list of operators.

property owner: SwanItem | IProject | None#

Owner of current Swan construct.

property sensors: List[SensorDecl]#

Return a list of sensor declarations.

property signatures: List[Signature]#

Return a list of signatures.

property source: str | None#

Source of the module, as a string (file name).

property types: List[TypeDecl]#

Return a list of type declarations.

property use_directives: List[UseDirective]#

Module’s use directives as a list.

class ansys.scadeone.core.swan.ModuleInterface(name: PathIdentifier, use_directives: List[UseDirective] | None = None, declarations: List[ModuleItem] | None = None)#

Bases: Module

Module interface definition.

body() ModuleBody#

Return the module body for a module interface if it exists.

filter_declarations(filter_fn) List[GlobalDeclaration]#

Return declarations matched by a filter.

Parameters:
filter_fnfunction

A function of one argument of type GlobalDeclaration, returning True or False.

Returns:
List[GlobalDeclaration]

List of matching declarations.

get_declaration(name: str) GlobalDeclaration#

Return the type, global, or operator declaration searching by namespace.

get_full_path() str#

Full Swan path of module.

get_use_directive(module_name: str) UseDirective | None#

Return the use directive searching by module name or alias name.

Aliases are searched first, the module name is searched if no alias is found. When a module name is searched, use directive with first occurrence is returned.

Parameters:
module_namestr

Name of the module (last part of a path) or alias.

Returns:
Found UseDirective or None
harness()#

Return the test harness if it exists.

interface() ModuleInterface#

Return the module interface for a module body if it exists.

static module_name_from_path(path: Path) str#

Returns a module name from a path.

Parameters:
pathPath

Path to the module, e.g. /path/to/namespace-module.swan

Returns:
str

Module name, e.g. namespace::module

static set_owner(owner: SwanItem | IProject | None, children: SwanItem | Iterable[SwanItem]) None#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem]]

Items to set owner.

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.

property constants: List[ConstDecl]#

Return a list of constant declarations.

property declarations: List[ModuleItem]#

Module’s declarations

property extension: str#

Return module extension, with . included.

property file_name: str#

Return a file name based on module name and namespaces.

property groups: List[GroupDecl]#

Return a list of group declarations.

property is_protected: bool#

Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).

property model: Model#

Return model containing the Swan item.

property module: ModuleBase | None#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface or None if the object is itself a module.

property name: PathIdentifier#

Module or Interface name.

property owner: SwanItem | IProject | None#

Owner of current Swan construct.

property sensors: List[SensorDecl]#

Return a list of sensor declarations.

property signatures: List[Signature]#

Return a list of signatures.

property source: str | None#

Source of the module, as a string (file name).

property types: List[TypeDecl]#

Return a list of type declarations.

property use_directives: List[UseDirective]#

Module’s use directives as a list.

class ansys.scadeone.core.swan.UseDirective(path: PathIdentifier, alias: Identifier | None = None)#

Bases: ModuleItem

Class for use directive.

get_full_path() str#

Full path of Swan construct.

static set_owner(owner: SwanItem | IProject | None, children: SwanItem | Iterable[SwanItem]) None#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem]]

Items to set owner.

property alias: Identifier | None#

Renaming of module.

property is_protected: bool#

Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).

property model: Model#

Return model containing the Swan item.

property module: ModuleBase | None#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface or None if the object is itself a module.

property owner: SwanItem | IProject | None#

Owner of current Swan construct.

property path: PathIdentifier#

Used module path.