Operators#

Operator are declared with the OperatorDeclaration class and defined with the OperatorDefinition class.

../../../_images/operator_decl.svg

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 imported operator if the module has an interface, otherwise it is the declaration of a public imported 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, OperatorDeclarationCreator

Operator declaration definition.

Used in module body or interface.

get_full_path() str#

Full path of Swan construct.

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.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

property id: Identifier#

Language item identifier.

property inputs: List[Variable]#

Return inputs as a list.

property is_inlined: bool#

True when operator is marked for inlining.

property is_node: bool#

True when operator is a node.

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_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 ModuleBody and ModuleInterface or None if the object is itself a module.

property outputs: List[Variable]#

Return outputs as a list.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

property pragmas: List[Pragma]#

List of pragmas.

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: Declaration

Size parameter declaration, used in operator declarations and definitions.

get_full_path() str#

Full path of Swan construct.

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.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

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 model: IModel#

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 | IModel | None#

Owner of current Swan construct.

property pragmas: List[Pragma]#

List of pragmas.

Type constraints#

class ansys.scadeone.core.swan.TypeConstraint(type_vars: List[VariableTypeExpression] | str, kind: NumericKind)#

Bases: SwanItem

Type constraint for operator. A constraint is:

where_decl ::= where typevar {{ , typevar }} numeric_kind

The typevar list can be protected and represented with string.

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:
str

Path within the owner and name of the Swan construct.

Raises:
ScadeOneException

If the method is not implemented for the current SwanItem type.

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.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

property is_protected: bool#

True when types are protected.

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 ModuleBody and ModuleInterface or None if the object is itself a module.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

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.

class ansys.scadeone.core.swan.NumericKind(value)#

Bases: Enum

Numeric kinds for generic type constraints.

Float = 5#

float

Integer = 2#

integer

Numeric = 1#

numeric

Signed = 3#

signed

Unsigned = 4#

unsigned

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, OperatorCreator

Operator definition, with a body.

Used in module body. The body may be empty.

get_full_path() str#

Full path of Swan construct.

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.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

property body: Scope | Equation | None#

Operator body: a scope, an equation, or None.

property diagrams: List[Diagram]#

Return a list of diagram declarations.

property has_body: bool#

True when operator has a body.

property id: Identifier#

Language item identifier.

property inputs: List[Variable]#

Return inputs as a list.

property is_equation_body: bool#

True when body is reduced to a single equation.

property is_inlined: bool#

True when operator is marked for inlining.

property is_node: bool#

True when operator is a node.

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_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 ModuleBody and ModuleInterface or None if the object is itself a module.

property outputs: List[Variable]#

Return outputs as a list.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

property pragmas: List[Pragma]#

List of pragmas.

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.