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 operand

  • BinaryOperation: 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:
Raises:

TypeError – if the supplied operator is not an instance of self.Operator.

Inheritance

Inheritance diagram of Operation
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 or psyclone.psyir.nodes.BinaryOperation.Operator or psyclone.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

Inheritance diagram of UnaryOperation
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:
Returns:

a UnaryOperation instance.

Return type:

psyclone.psyir.nodes.UnaryOperation

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:

psyclone.psyir.symbols.DataType

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

Inheritance diagram of BinaryOperation
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:
Returns:

a BinaryOperator instance.

Return type:

psyclone.psyir.nodes.BinaryOperation

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:

psyclone.psyir.symbols.DataType

Raises:

InternalError – if the operands are both arrays but are of different shapes.