Bitwise, boolean, arithmetic, relational, sequential#

Arithmetic, logical, bitwise, and relational expressions are represented by unary expressions (ex: not X), binary expressions (ex: 1 + 2), or n-ary expressions.

Unary and binary expressions are implemented with the UnaryExpr and BinaryExpr classes with the appropriate operator as an enumeration value.

N-ary expressions correspond to specific operator NAryOperator with the appropriate operator as an enumeration value.

../../../_images/arithmetic.svg
Table 1 Bitwise#

Operator

Operation

Class and operator as enum value

lnot

bitwise not

UnaryExpr with UnaryOp.Lnot operator

land

bitwise and

BinaryExpr with BinaryOp.Land operator / NAryOrator with NaryOp.And operator

lor

bitwise or

BinaryExpr with BinaryOp.Lor operator / NAryOrator with NaryOp.Or operator

lxor

bitwise xor

BinaryExpr with BinaryOp.Xor operator / NAryOrator with NaryOp.Xor operator

lsl

logical shift left

BinaryExpr with BinaryOp.Lsl operator

lsr

logical shift right

BinaryExpr with BinaryOp.Lsr operator

Table 2 Boolean#

Operator

Operation

Class and operator as enum value

not

logical not

UnaryExpr with UnaryOp.Not operator

and

logical and

BinaryExpr with BinaryOp.And operator / NAryOrator with NaryOp.And operator

or

logical or

BinaryExpr with BinaryOp.Or operator / NAryOrator with NaryOp.Or operator

xor

logical xor

BinaryExpr with BinaryOp.Xor operator / NAryOrator with NaryOp.Xor operator

Table 3 Arithmetic#

Operator

Operation

Class and operator as enum value

-

minus / subtraction

UnaryExp with UnaryOp.Minus operator / BinaryExpr with BinaryOp.Minus operator

+

plus / addition

UnaryExpr with UnaryOp.Plus operator / BinaryExpr with BinaryOp.Plus operator / NAryOrator with NaryOp.Plus operator

*

multiplication

BinaryExpr with BinaryOp.Mult operator / NAryOrator with NaryOp.Mult operator

/

division

BinaryExpr with BinaryOp.Slash operator

mod

modulo

BinaryExpr with BinaryOp.Mod operator

(:>)

cast operation

NumericCast (special class for cast operator)

Table 4 Relational#

Operator

Operation

Class and operator as enum value

=

equal

BinaryExpr with BinaryOp.Equal operator

<>

different

BinaryExpr with BinaryOp.Diff operator

<

less than

BinaryExpr with BinaryOp.Lt operator

<=

less than or equal to

BinaryExpr with BinaryOp.Leq operator

>

greater than

BinaryExpr with BinaryOp.Gt operator

>=

greater than or equal to

BinaryExpr with BinaryOp.Gte operator

Unary expressions#

A unary expression is composed of a unary operator and an expression. Unary operators are defined with the UnaryExpr enumeration.

class ansys.scadeone.core.swan.UnaryExpr(operator: UnaryOp, expr: Expression)#

Bases: Expression

Expression with unary operators :py:class`ansys.scadeone.core.swan.expressions.UnaryOp`.

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 at: Identifier | None#

Memory constrained location.

property expr: Expression#

Expression.

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 operator: UnaryOp#

Unary operator.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

Binary expressions#

A binary expression is composed of a binary operator and two expressions. Binary operators are defined with the BinaryExpr enumeration.

class ansys.scadeone.core.swan.BinaryExpr(operator: BinaryOp, left: Expression, right: Expression)#

Bases: Expression

Expression with binary operators :py:class`ansys.scadeone.swan.expressions.BinaryOp`.

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 at: Identifier | None#

Memory constrained location.

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 left: Expression#

Left expression.

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 operator: BinaryOp#

Binary operator.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

property right: Expression#

Right expression.

Cast operators#

A cast operator ( :> ) is a specific binary expression as it takes an expression and a type.

class ansys.scadeone.core.swan.NumericCast(expr: Expression, type: TypeExpression)#

Bases: Expression

Cast expression: ( expr :> type_expr).

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 at: Identifier | None#

Memory constrained location.

property expr: Expression#

Expression.

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 type: TypeExpression#

Type expression.

N-ary expressions#

N-ary operators are a special case of operator calls. The n-ary operations are given by the following enumeration.

class ansys.scadeone.core.swan.NAryOperator(operator: NaryOp)#

Bases: OperatorExpression

N-ary operators: ‘+’ | ‘*’ | ‘@’ | and | or | xor | land | lor | lxor.

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

Return True if item is an operator expression.

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 operator: NaryOp#

N-ary operator.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

Sequential expressions#

class ansys.scadeone.core.swan.PreExpr(expr: Expression)#

Bases: UnaryExpr

Unit delay expression: pre(expr).

This is a unary expression with the operator ansys.scadeone.swan.expressions.UnaryOp.Pre.

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 at: Identifier | None#

Memory constrained location.

property expr: Expression#

Expression.

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 operator: UnaryOp#

Unary operator.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

class ansys.scadeone.core.swan.PreWithInitialValueExpr(left: Expression, right: Expression)#

Bases: BinaryExpr

Unit delay with initial value expression: expr pre expr).

This is a binary expression with the operator ansys.scadeone.swan.expressions.BinaryOp.Pre.

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 at: Identifier | None#

Memory constrained location.

property expr: Expression#

Delayed expression.

property initial: Expression#

Initial value expression.

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 left: Expression#

Left expression.

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 operator: BinaryOp#

Binary operator.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

property right: Expression#

Right expression.

class ansys.scadeone.core.swan.InitialValueExpr(left: Expression, right: Expression)#

Bases: BinaryExpr

Initial value expression: (expr -> expr).

This is a binary expression with the operator ansys.scadeone.swan.expressions.BinaryOp.Arrow.

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 at: Identifier | None#

Memory constrained location.

property expr: Expression#

Delayed expression.

property initial: Expression#

Initial value expression.

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 left: Expression#

Left expression.

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 operator: BinaryOp#

Binary operator.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

property right: Expression#

Right expression.