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) Generator[GlobalDeclaration, None, None]#

Return declarations matched by a filter.

Parameters:
filter_fnfunction

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

Yields:
Generator[GlobalDeclaration, None, None]

Generator on 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(name: str) UseDirective#

Return a dictionary of use directives by their name or given alias. The name is the last part of the path ID.

Returns Dict[str, UseDirective]

interface() ModuleInterface#

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

static set_owner(owner: Self, children: Self | Iterable[Self])#

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 constants: Generator[ConstDecl, None, None]#

Return a generator on constant declarations.

property declaration_list: List[ModuleItem]#

Declarations as a list. Can be modified.

property declarations: Generator[ModuleItem, None, None]#

Declarations as a generator.

property extension: str#

Return module extension, with ‘.’ included.

property file_name: str#

Return a file name based on module name and namespaces.

property groups: Generator[GroupDecl, None, None]#

Return a generator on 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#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface

property name: PathIdentifier#

Module or Interface name.

property operators: Generator[Operator, None, None]#

Return a generator on operators.

property owner: Self#

Owner of current Swan construct.

property sensors: Generator[SensorDecl, None, None]#

Return a generator on sensor declarations.

property source: str | None#

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

property types: Generator[TypeDecl, None, None]#

Return a generator on type declarations.

property use_directive_list: List[UseDirective]#

Module’s use directives as a list. Can be modified.

property use_directives: Generator[UseDirective, None, None]#

Module’s use directives as a generator.

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) Generator[GlobalDeclaration, None, None]#

Return declarations matched by a filter.

Parameters:
filter_fnfunction

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

Yields:
Generator[GlobalDeclaration, None, None]

Generator on 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(name: str) UseDirective#

Return a dictionary of use directives by their name or given alias. The name is the last part of the path ID.

Returns Dict[str, UseDirective]

interface() ModuleInterface#

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

static set_owner(owner: Self, children: Self | Iterable[Self])#

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 constants: Generator[ConstDecl, None, None]#

Return a generator on constant declarations.

property declaration_list: List[ModuleItem]#

Declarations as a list. Can be modified.

property declarations: Generator[ModuleItem, None, None]#

Declarations as a generator.

property extension: str#

Return module extension, with . included.

property file_name: str#

Return a file name based on module name and namespaces.

property groups: Generator[GroupDecl, None, None]#

Return a generator on 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#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface

property name: PathIdentifier#

Module or Interface name.

property owner: Self#

Owner of current Swan construct.

property sensors: Generator[SensorDecl, None, None]#

Return a generator on sensor declarations.

property signatures: Generator[Signature, None, None]#

Return a generator on signatures.

property source: str | None#

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

property types: Generator[TypeDecl, None, None]#

Return a generator on type declarations.

property use_directive_list: List[UseDirective]#

Module’s use directives as a list. Can be modified.

property use_directives: Generator[UseDirective, None, None]#

Module’s use directives as a generator.

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: Self, children: Self | Iterable[Self])#

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#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface

property owner: Self#

Owner of current Swan construct.

property path: PathIdentifier#

Used module path.