Bitwise, boolean, arithmetic, relational#
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.
N-ary expressions correspond to specific operator instance calls which use the NaryOp
enumeration.
Operator |
Operation |
Kind |
---|---|---|
- |
minus / subtraction |
unary / binary |
+ |
plus / addition |
unary / binary, n-ary |
* |
multiplication |
binary, n-ary |
/ |
division |
binary |
lnot |
bitwise not |
unary |
land |
bitwise and |
binary, n-ary |
lor |
bitwise or |
binary, n-ary |
lxor |
bitwise xor |
binary, n-ary |
lsl |
bitwise left-shift |
binary |
lsr |
bitwise right-shift |
binary |
not |
logical not |
unary |
and |
logical and |
binary, n-ary |
or |
logical and |
binary, n-ary |
xor |
logical and |
binary, n-ary |
pre |
Unit delay |
unary (not initial value), binary (initial value) |
= |
relation equal |
binary |
<> |
relation difference |
binary |
< |
relation less than |
binary |
<= |
relation less than or equal to |
binary |
> |
relation greater than |
binary |
>= |
relation greater than or equal to |
binary |
-> |
initial value |
binary |
@ |
array concatenation |
binary |
(:>) |
cast operation |
binary |
Unary expressions#
A unary expression is composed of a unary operator and an expression.
Unary operators are defined with the UnaryOp
enumeration.
- class ansys.scadeone.core.swan.UnaryOp(value)#
Bases:
Enum
Unary operators:
arithmetic operators
logical operators
Unit delay operator
- Lnot = 3#
(lnot) Bitwise not.
- Minus = 1#
(-) Unary minus.
- Not = 4#
(not) Logical not.
- Plus = 2#
(+) Unary plus.
- Pre = 5#
(pre) Unit delay.
- class ansys.scadeone.core.swan.UnaryExpr(operator: UnaryOp, expr: Expression)#
Bases:
Expression
Expression with unary operators :py:class`ansys.scadeone.core.swan.expressions.UnaryOp`.
- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- 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 module: ModuleBase#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
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 BinaryOp
enumeration.
- class ansys.scadeone.core.swan.BinaryOp(value)#
Bases:
Enum
Binary operators:
arithmetic operators
relational operators
logical operators
bitwise operators
Initial value, initialed unit delay
Concat
- And = 12#
(and) Logical and.
- Diff = 7#
(<>) Different.
- Equal = 6#
(=) Equal.
- Geq = 11#
(>=) Greater than or equal to.
- Gt = 9#
(>) Greater than.
- Land = 15#
(land) Bitwise and.
- Leq = 10#
(<=) Less than or equal to.
- Lor = 16#
(lor) Bitwise or.
- Lsl = 18#
(lsl) Logical shift left.
- Lsr = 19#
(lsr) Logical shift right.
- Lt = 8#
(<) Less than.
- Lxor = 17#
(lxor) Bitwise exclusive or.
- Minus = 2#
(-) Subtraction.
- Mod = 5#
(mod) Modulo.
- Mult = 3#
(*) Multiplication.
- Or = 13#
(or) Logical or.
- Plus = 1#
(+) Addition.
- Slash = 4#
(/) Division.
- Xor = 14#
(xor) Logical exclusive or.
- 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`.
- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- 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 module: ModuleBase#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
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).
- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- 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 module: ModuleBase#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
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.NaryOp(value)#
Bases:
Enum
N-ary operators.
- And = 5#
(and) N-ary logical and.
- Concat = 8#
(@) N-ary array concat.
- Land = 3#
(land) N-ary bitwise and.
- Lor = 4#
(lor) N-ary bitwise or.
- Mult = 2#
(*) N-ary multiplication.
- Or = 6#
(or) N-ary logical or.
- Plus = 1#
(+) N-ary addition.
- Xor = 7#
(xor) N-ary exclusive or.
- class ansys.scadeone.core.swan.NAryOperator(operator: NaryOp)#
Bases:
OperatorExpression
N-ary operators: ‘+’ | ‘*’ | ‘@’ | and | or | xor | land | lor.
- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- 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#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
Owner of current Swan construct.