Operators#
Operator are declared with the OperatorDeclaration class and defined with the OperatorDefinition class.
Fig. 6 Operator class diagram#
Operator declaration#
Declares an operator, giving its interface only. In a module interface, an operator declaration can be the declaration of an operator which body definition is given in the module body, or it can declare a public imported operator. In a module body, an operator declaration is the declaration of a private external operator if the module has an interface, otherwise it is the declaration of a public external operator.
The class SizeParameter defines size parameters that can be used for array sizes.
The class TypeConstraint defines constraints that can be applied to generic types.
- class ansys.scadeone.core.swan.OperatorDeclaration(id: Identifier, is_inlined: bool, is_node: bool, inputs: List[Variable], outputs: List[Variable], size_parameters: List[SizeParameter] | None = None, type_constraints: List[TypeConstraint] | None = None, specialization: PathIdentifier | None = None, pragmas: List[Pragma] | None = None)#
Bases:
OperatorDeclarationDefinitionBase,OperatorDeclarationCreatorOperator declaration definition.
Used in module body or interface.
- static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#
Helper to set owner as the owner of each item in the Iterable items.
- get_definition() OperatorDefinition | None#
Return the definition of this operator, if any.
An operator declaration in a module body is always external.
If the operator declaration is in a module interface, one looks for any definition in body.
- property id: Identifier#
Language item identifier.
- 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 is_public: bool#
True if declaration is public.
A declaration is public if:
it is declared in a module interface,
or it is declared in a module body, but the module has no interface.
A declaration is private if it is declared in a module body, and the module has an interface, and there is no declaration with the same name in the module interface.
If declared in both a module interface and body, the declaration is considered as public, but a warning is issued.
- property is_text: bool#
True when operator is given from {text%…%text} markup, or an interface is given from {text%…%text} markup (body) or {signature%…%signature} markup (interface).
- property model: IModel#
Return model containing the Swan item.
- property module: ModuleBase | None#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBodyandModuleInterfaceor None if the object is itself a module.
- property size_parameters: List[SizeParameter]#
Return size parameters as a list.
- property specialization: PathIdentifier | None#
Return specialization path_id or None.
- property type_constraints: List[TypeConstraint]#
Return type constraints as a list.
Size parameters#
- class ansys.scadeone.core.swan.SizeParameter(id: Identifier, pragmas: List[Pragma] | None = None)#
Bases:
DeclarationSize parameter declaration, used in operator declarations and definitions.
- static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#
Helper to set owner as the owner of each item in the Iterable items.
- property id: Identifier#
Language item identifier.
- property is_external: bool#
True if declaration has no definition.
Check if there is no alternative declaration in the module (interface or body). Warn if any, and raise an error if inconsistent.
- 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 is_public: bool#
True if declaration is public.
A declaration is public if:
it is declared in a module interface,
or it is declared in a module body, but the module has no interface.
A declaration is private if it is declared in a module body, and the module has an interface, and there is no declaration with the same name in the module interface.
If declared in both a module interface and body, the declaration is considered as public, but a warning is issued.
- property model: IModel#
Return model containing the Swan item.
- property module: ModuleBase | None#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBodyandModuleInterfaceor None if the object is itself a module.
Type constraints#
- class ansys.scadeone.core.swan.TypeConstraint(type_vars: List[VariableTypeExpression] | str, kind: NumericKind)#
Bases:
SwanItemType constraint for operator. A constraint is:
where_decl ::= where typevar {{ , typevar }} numeric_kind
The typevar list can be protected and represented with string.
- static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#
Helper to set owner as the owner of each item in the Iterable items.
- get_full_path() str#
Full path of the Swan construct.
This method is implemented by derived classes that correspond to a declaration at the module level (such as sensor, type, group, const, operator), or a module itself.
- Returns:
strPath within the owner and name of the Swan construct.
- Raises:
ScadeOneExceptionIf the method is not implemented for the current SwanItem type.
- property kind: NumericKind#
Constraint numeric kind.
- property model: IModel#
Return model containing the Swan item.
- property module: ModuleBase | None#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBodyandModuleInterfaceor None if the object is itself a module.
- property type_vars: List[VariableTypeExpression] | str#
Return type variable names of constraints.
- Returns:
Union[List[VariableTypeExpression],str]Returns the list of type names, if not protected, or the constraint names as a string.
Operator definition#
Defines an operator with a body in a module body. See Operator body for content of the body.
The operator definition has the same interface as the corresponding operator declaration in the module interface, if any,
see OperatorDeclaration, SizeParameter and TypeConstraint.
- class ansys.scadeone.core.swan.OperatorDefinition(id: Identifier, is_inlined: bool, is_node: bool, inputs: List[Variable], outputs: List[Variable], body: Scope | Equation | Callable | None = None, size_parameters: List[SizeParameter] | None = None, type_constraints: List[TypeConstraint] | None = None, specialization: PathIdentifier | None = None, pragmas: List[Pragma] | None = None)#
Bases:
OperatorDeclarationDefinitionBase,OperatorCreatorOperator definition, with a body.
Used in module body. The body may be empty.
- static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#
Helper to set owner as the owner of each item in the Iterable items.
- get_declaration() OperatorDeclaration | None#
Return the declaration of this operator, if any.
Look for declaration in interface, if any.
- get_local_variables() List[Variable]#
Return the list of all local variables declared for this operator definition. Local variables are collected from
Scopeand recursively from allDiagramsections of the operator. The returned list aggregatesScope.local_variablesandDiagram.local_variablesproperties.- Returns:
List[Variable]List of Variables found from the current operator definition.
- property id: Identifier#
Language item identifier.
- 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 is_public: bool#
True when operator is public.
An operator is public when: - it is declared in a module interface, - or it is defined in a module body, but the module has no interface.
- property is_text: bool#
True when operator is given from {text%…%text} markup, or an interface is given from {text%…%text} markup (body) or {signature%…%signature} markup (interface).
- property model: IModel#
Return model containing the Swan item.
- property module: ModuleBase | None#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBodyandModuleInterfaceor None if the object is itself a module.
- property size_parameters: List[SizeParameter]#
Return size parameters as a list.
- property specialization: PathIdentifier | None#
Return specialization path_id or None.
- property type_constraints: List[TypeConstraint]#
Return type constraints as a list.