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.
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_fn
function
A function of one argument of type GlobalDeclaration, returning True or False.
- filter_fn
- Returns:
List
[GlobalDeclaration
]List of matching declarations.
- get_declaration(name: str) GlobalDeclaration #
Return the type, global, or operator declaration searching by namespace.
- 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_name
str
Name of the module (last part of a path) or alias.
- module_name
- Returns:
Found
UseDirective
orNone
- 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:
- path
Path
Path to the module, e.g. /path/to/namespace-module.swan
- path
- 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.
- 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 is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property module: ModuleBase | None#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
or None if the object is itself a module.
- property name: PathIdentifier#
Module or Interface name.
- property sensors: List[SensorDecl]#
Return a list of sensor 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_fn
function
A function of one argument of type GlobalDeclaration, returning True or False.
- filter_fn
- Returns:
List
[GlobalDeclaration
]List of matching declarations.
- get_declaration(name: str) GlobalDeclaration #
Return the type, global, or operator declaration searching by namespace.
- 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_name
str
Name of the module (last part of a path) or alias.
- module_name
- Returns:
Found
UseDirective
orNone
- 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:
- path
Path
Path to the module, e.g. /path/to/namespace-module.swan
- path
- 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.
- 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 is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property module: ModuleBase | None#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
or None if the object is itself a module.
- property name: PathIdentifier#
Module or Interface name.
- property sensors: List[SensorDecl]#
Return a list of sensor 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.
- 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.
- 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 module: ModuleBase | None#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
or None if the object is itself a module.
- property path: PathIdentifier#
Used module path.