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

Operator 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.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

add_pragmas(*pragmas) → None#

Add one or more pragmas to the current object.

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.

get_full_path() → str#

Full path of Swan construct.

property has_definition: bool#

True if declaration has a definition part.

property id: Identifier#

Language item identifier.

property inputs: List[Variable]#

Return inputs as a list.

property is_external: bool#

True when operator has no definition.

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_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 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.

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.

add_pragmas(*pragmas) → None#

Add one or more pragmas to the current object.

get_full_path() → str#

Full path of Swan construct.

property has_definition: bool#

True if declaration has a definition part.

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 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.

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.

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.

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(*values)#

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.

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.

add_pragmas(*pragmas) → None#

Add one or more pragmas to the current object.

get_declaration() → OperatorDeclaration | None#

Return the declaration of this operator, if any.

Look for declaration in interface, if any.

get_full_path() → str#

Full path of Swan construct.

get_local_variables() → List[Variable]#

Return the list of all local variables declared for this operator definition. Local variables are collected from Scope and recursively from all Diagram sections of the operator. The returned list aggregates Scope.local_variables and Diagram.local_variables properties.

Returns:
List[Variable]

List of Variables found from the current operator definition.

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 has_definition: bool#

True if declaration has a definition part.

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_external: bool#

Always False.

Note that a body cannot be None in a final model.

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_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 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.