psyclone.psyir.nodes.operation
This module contains the implementation of the Operation class and its sub-classes.
Classes
Operation
: Abstract base class for PSyIR nodes representing operators.UnaryOperation
: Node representing a UnaryOperation expression. As such it has one operandBinaryOperation
: Node representing a BinaryOperation expression. As such it has two operands
- class psyclone.psyir.nodes.operation.Operation(operator, parent=None)
Abstract base class for PSyIR nodes representing operators.
- Parameters:
operator (
psyclone.psyir.nodes.UnaryOperation.Operator
orpsyclone.psyir.nodes.BinaryOperation.Operator
orpsyclone.psyir.nodes.NaryOperation.Operator
) – the operator used in the operation.parent (
psyclone.psyir.nodes.Node
) – the parent node of this Operation in the PSyIR.
- Raises:
TypeError – if the supplied operator is not an instance of self.Operator.
Inheritance
- Operator
alias of
object
- node_str(colour=True)
Construct a text representation of this node, optionally with control codes for coloured display in a suitable terminal.
- Parameters:
colour (bool) – whether or not to include colour control codes.
- Returns:
description of this PSyIR node.
- Return type:
str
- property operator
Return the operator.
- Returns:
Enumerated type capturing the operator.
- Return type:
psyclone.psyir.nodes.UnaryOperation.Operator
orpsyclone.psyir.nodes.BinaryOperation.Operator
orpsyclone.psyir.nodes.NaryOperation.Operator
- class psyclone.psyir.nodes.operation.UnaryOperation(operator, parent=None)
Node representing a UnaryOperation expression. As such it has one operand as child 0, and an attribute with the operator type.
Inheritance
- class Operator(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)
- static create(operator, operand)
Create a UnaryOperation instance given an operator and operand.
- Parameters:
operator (
psyclone.psyir.nodes.UnaryOperation.Operator
) – the specified operator.operand (Union[
psyclone.psyir.nodes.Node
| Tuple[str, :py:class:psyclone.psyir.nodes.Node
]]) – the PSyIR node that oper operates on, or a tuple containing the name of the argument and the PSyIR node.
- Returns:
a UnaryOperation instance.
- Return type:
- Raises:
GenerationError – if the arguments to the create method are not of the expected type.
- property datatype
- Returns:
the datatype of the result of this UnaryOperation.
- Return type:
- class psyclone.psyir.nodes.operation.BinaryOperation(operator, parent=None)
Node representing a BinaryOperation expression. As such it has two operands as children 0 and 1, and an attribute with the operator type.
Inheritance
- class Operator(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)
- static create(operator, lhs, rhs)
Create a BinaryOperator instance given an operator and lhs and rhs child instances with optional names.
- Parameters:
operator (
psyclone.psyir.nodes.BinaryOperation.Operator
) – the operator used in the operation.lhs (Union[
psyclone.psyir.nodes.Node
, Tuple[str,psyclone.psyir.nodes.Node
]]) – the PSyIR node containing the left hand side of the assignment, or a tuple containing the name of the argument and the PSyIR node.rhs (Union[
psyclone.psyir.nodes.Node
, Tuple[str,psyclone.psyir.nodes.Node
]]) – the PSyIR node containing the right hand side of the assignment, or a tuple containing the name of the argument and the PSyIR node.
- Returns:
a BinaryOperator instance.
- Return type:
- Raises:
GenerationError – if the arguments to the create method are not of the expected type.
- property datatype
Determines the datatype of this operation. If it cannot be determined for any reason then an instance of UnresolvedType is returned.
- Returns:
the datatype of the result of this BinaryOperation.
- Return type:
- Raises:
InternalError – if the operands are both arrays but are of different shapes.