pyccel.ast.operators module#
Module handling all Python builtin operators These operators all have a precedence as detailed here: https://docs.python.org/3/reference/expressions.html#operator-precedence They also have specific rules to determine the dtype, rank, shape, class_type
- class pyccel.ast.operators.IfTernaryOperator(cond, value_true, value_false)[source]View on GitHub#
Bases:
PyccelOperatorRepresent a ternary conditional operator in the code.
Represent a ternary conditional operator in the code, of the form (a if cond else b).
- Parameters:
cond (TypedAstNode) – The condition which determines which result is returned.
value_true (TypedAstNode) – The value returned if the condition is true.
value_false (TypedAstNode) – The value returned if the condition is false.
Examples
>>> from pyccel.ast.internals import PyccelSymbol >>> from pyccel.ast.core import Assign >>> from pyccel.ast.operators import IfTernaryOperator >>> n = PyccelSymbol('n') >>> x = 5 if n > 1 else 2 >>> IfTernaryOperator(PyccelGt(n > 1), 5, 2) IfTernaryOperator(PyccelGt(n > 1), 5, 2)
- property condView on GitHub#
The condition property for IfTernaryOperator class
- property value_falseView on GitHub#
The value_if_cond_false property for IfTernaryOperator class
- property value_trueView on GitHub#
The value_if_cond_true property for IfTernaryOperator class
- class pyccel.ast.operators.PyccelAdd(arg1, arg2)[source]View on GitHub#
Bases:
PyccelArithmeticOperatorClass representing a call to the Python addition operator.
Class representing a call to the Python addition operator. I.e:
a + b
is equivalent to: >>> PyccelAdd(a, b)
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- classmethod make_simplified(arg1, arg2)[source]View on GitHub#
Call the class constructor after making any simplifications to the expression.
Call the class constructor after making any simplifications to the expression. This method should be overridden by sub-classes.
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- class pyccel.ast.operators.PyccelAnd(*args)[source]View on GitHub#
Bases:
PyccelBooleanOperatorClass representing a call to the Python AND operator.
Class representing a call to the Python AND operator. I.e:
a and b
is equivalent to: >>> PyccelAnd(a, b)
- Parameters:
*args (TypedAstNode) – The arguments passed to the operator.
- classmethod make_simplified(*args)[source]View on GitHub#
Call the class constructor after making any simplifications to the expression.
Call the class constructor after making any simplifications to the expression. This method should be overridden by sub-classes.
- Parameters:
*args (TypedAstNode) – The arguments passed to the operator.
- class pyccel.ast.operators.PyccelArithmeticOperator(arg1, arg2)[source]View on GitHub#
Bases:
PyccelBinaryOperatorAbstract superclass representing a Python arithmetic operator.
This class is necessary to handle specific precedence rules for arithmetic operators. I.e. to handle the error: Extension: Unary operator following arithmetic operator (use parentheses).
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- class pyccel.ast.operators.PyccelAssociativeParenthesis(arg)[source]View on GitHub#
Bases:
PyccelUnaryOperatorClass representing parentheses.
Class representing parentheses around an expression to group ideas or to ensure the execution order of the code.
- Parameters:
arg (TypedAstNode) – The argument in the PyccelAssociativeParenthesis.
- class pyccel.ast.operators.PyccelBinaryOperator(arg1, arg2)[source]View on GitHub#
Bases:
PyccelOperatorSuperclass representing a Python operator with two arguments.
Abstract superclass representing a Python operator with two arguments.
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- class pyccel.ast.operators.PyccelBooleanOperator(*args)[source]View on GitHub#
Bases:
PyccelOperatorSuperclass representing a boolean operator with two arguments.
Abstract superclass representing a Python boolean operator with two arguments.
- Parameters:
*args (tuple of TypedAstNode) – The arguments passed to the operator.
- class pyccel.ast.operators.PyccelComparisonOperator(arg1, arg2)[source]View on GitHub#
Bases:
PyccelBinaryOperatorSuperclass representing a Python comparison operator.
Abstract superclass representing a Python comparison operator with two arguments.
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- class pyccel.ast.operators.PyccelDiv(arg1, arg2)[source]View on GitHub#
Bases:
PyccelArithmeticOperatorClass representing a call to the Python division operator.
Class representing a call to the Python division operator. I.e:
a / b
is equivalent to: >>> PyccelDiv(a, b)
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- classmethod make_simplified(arg1, arg2)[source]View on GitHub#
Call the class constructor after making any simplifications to the expression.
Call the class constructor after making any simplifications to the expression. This method should be overridden by sub-classes.
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- class pyccel.ast.operators.PyccelEq(arg1=None, arg2=None)[source]View on GitHub#
Bases:
PyccelComparisonOperatorClass representing a call to the Python equality operator.
Class representing a call to the Python equality operator. I.e:
a == b
is equivalent to: >>> PyccelEq(a, b)
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- op = '=='#
- class pyccel.ast.operators.PyccelFloorDiv(arg1, arg2)[source]View on GitHub#
Bases:
PyccelArithmeticOperatorClass representing a call to the Python integer division operator.
Class representing a call to the Python integer division operator. I.e:
a // b
is equivalent to: >>> PyccelFloorDiv(a, b)
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- class pyccel.ast.operators.PyccelGe(arg1, arg2)[source]View on GitHub#
Bases:
PyccelComparisonOperatorClass representing a call to the Python greater or equal operator.
Class representing a call to the Python greater or equal operator. I.e:
a >= b
is equivalent to: >>> PyccelGe(a, b)
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- op = '>='#
- class pyccel.ast.operators.PyccelGt(arg1, arg2)[source]View on GitHub#
Bases:
PyccelComparisonOperatorClass representing a call to the Python greater than operator.
Class representing a call to the Python greater than operator. I.e:
a > b
is equivalent to: >>> PyccelGt(a, b)
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- classmethod make_simplified(arg1, arg2)[source]View on GitHub#
Call the class constructor after making any simplifications to the expression.
Call the class constructor after making any simplifications to the expression. This method should be overridden by sub-classes.
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- op = '>'#
- class pyccel.ast.operators.PyccelIn(element, container)[source]View on GitHub#
Bases:
PyccelBooleanOperatorRepresents an in expression in the code.
Represents an in expression in the code.
- Parameters:
element (TypedAstNode) – The first argument passed to the operator.
container (TypedAstNode) – The first argument passed to the operator.
- property containerView on GitHub#
Second operator argument.
Second operator argument.
- property elementView on GitHub#
First operator argument.
First operator argument.
- class pyccel.ast.operators.PyccelIs(*args)[source]View on GitHub#
Bases:
PyccelBooleanOperatorRepresents an is expression in the code.
Represents an is expression in the code.
- Parameters:
*args (tuple of TypedAstNode) – The arguments passed to the operator.
Examples
>>> from pyccel.ast.operators import PyccelIs >>> from pyccel.ast.literals import Nil >>> from pyccel.ast.internals import PyccelSymbol >>> x = PyccelSymbol('x') >>> PyccelIs(x, Nil()) PyccelIs(x, None)
- eval()[source]View on GitHub#
Determines the value of the expression x is None when x is known.
If a boolean value cannot be computed, return the string “unknown”.
- property lhsView on GitHub#
First operator argument
- property rhsView on GitHub#
First operator argument
- class pyccel.ast.operators.PyccelIsNot(*args)[source]View on GitHub#
Bases:
PyccelIsRepresents a is not expression in the code.
Represents a is not expression in the code.
- Parameters:
*args (tuple of TypedAstNode) – The arguments passed to the operator.
Examples
>>> from pyccel.ast.operators import PyccelIsNot >>> from pyccel.ast.literals import Nil >>> from pyccel.ast.internals import PyccelSymbol >>> x = PyccelSymbol('x') >>> PyccelIsNot(x, Nil()) PyccelIsNot(x, None)
- eval()[source]View on GitHub#
Determines the value of the expression x is not None when x is known.
If a boolean value cannot be computed, return the string “unknown”.
- class pyccel.ast.operators.PyccelLe(arg1, arg2)[source]View on GitHub#
Bases:
PyccelComparisonOperatorClass representing a call to the Python less or equal operator.
Class representing a call to the Python less or equal operator. I.e:
a <= b
is equivalent to: >>> PyccelLe(a, b)
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- op = '<='#
- class pyccel.ast.operators.PyccelLt(arg1, arg2)[source]View on GitHub#
Bases:
PyccelComparisonOperatorClass representing a call to the Python less than operator.
Class representing a call to the Python less than operator. I.e:
a < b
is equivalent to: >>> PyccelLt(a, b)
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- op = '<'#
- class pyccel.ast.operators.PyccelMinus(arg1=None, arg2=None)[source]View on GitHub#
Bases:
PyccelArithmeticOperatorClass representing a call to the Python subtraction operator.
Class representing a call to the Python subtraction operator. I.e:
a - b
is equivalent to: >>> PyccelMinus(a, b)
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- classmethod make_simplified(arg1, arg2)[source]View on GitHub#
Call the class constructor after making any simplifications to the expression.
Call the class constructor after making any simplifications to the expression. This method should be overridden by sub-classes.
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- class pyccel.ast.operators.PyccelMod(arg1, arg2)[source]View on GitHub#
Bases:
PyccelArithmeticOperatorClass representing a call to the Python modulo operator.
Class representing a call to the Python modulo operator. I.e:
a % b
is equivalent to: >>> PyccelMod(a, b)
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- class pyccel.ast.operators.PyccelMul(arg1, arg2)[source]View on GitHub#
Bases:
PyccelArithmeticOperatorClass representing a call to the Python multiplication operator.
Class representing a call to the Python multiplication operator. I.e:
a * b
is equivalent to: >>> PyccelMul(a, b)
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- classmethod make_simplified(arg1, arg2)[source]View on GitHub#
Call the class constructor after making any simplifications to the expression.
Call the class constructor after making any simplifications to the expression. This method should be overridden by sub-classes.
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- class pyccel.ast.operators.PyccelNe(arg1=None, arg2=None)[source]View on GitHub#
Bases:
PyccelComparisonOperatorClass representing a call to the Python inequality operator.
Class representing a call to the Python inequality operator. I.e:
a != b
is equivalent to: >>> PyccelNe(a, b)
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- op = '!='#
- class pyccel.ast.operators.PyccelNot(arg)[source]View on GitHub#
Bases:
PyccelUnaryOperatorClass representing a call to the Python not operator.
Class representing a call to the Python not operator. I.e:
not a
is equivalent to: >>> PyccelNot(a).
- Parameters:
arg (TypedAstNode) – The argument passed to the operator.
- classmethod make_simplified(arg)[source]View on GitHub#
Call the class constructor after making any simplifications to the expression.
Call the class constructor after making any simplifications to the expression. This method should be overridden by sub-classes.
- Parameters:
arg (TypedAstNode) – The argument passed to the operator.
- class pyccel.ast.operators.PyccelOperator(*args)[source]View on GitHub#
Bases:
TypedAstNodeAbstract superclass for all builtin operators.
Abstract superclass for all builtin operators. The __init__ function is common but the functions called by __init__ are specialised.
- Parameters:
*args (tuple of TypedAstNode) – The arguments passed to the operator.
- property argsView on GitHub#
Arguments of the operator
- classmethod make_simplified(*args)[source]View on GitHub#
Call the class constructor after making any simplifications to the expression.
Call the class constructor after making any simplifications to the expression. This method should be overridden by sub-classes.
- Parameters:
*args (TypedAstNode) – The arguments passed to the operator.
- property precedenceView on GitHub#
The precedence of the operator.
The precedence of the operator as defined here: https://docs.python.org/3/reference/expressions.html#operator-precedence The precedence shows the order in which operators should be handled. In this file it is represented as an integer. The higher the integer value of the precedence, the higher the priority of the operator.
- Returns:
The precedence of the operator.
- Return type:
int
- class pyccel.ast.operators.PyccelOr(*args)[source]View on GitHub#
Bases:
PyccelBooleanOperatorClass representing a call to the Python OR operator.
Class representing a call to the Python OR operator. I.e:
a or b
is equivalent to: >>> PyccelOr(a, b)
- Parameters:
*args (tuple of TypedAstNode) – The arguments passed to the operator.
- classmethod make_simplified(*args)[source]View on GitHub#
Call the class constructor after making any simplifications to the expression.
Call the class constructor after making any simplifications to the expression. This method should be overridden by sub-classes.
- Parameters:
*args (TypedAstNode) – The arguments passed to the operator.
- class pyccel.ast.operators.PyccelPow(arg1, arg2)[source]View on GitHub#
Bases:
PyccelArithmeticOperatorClass representing a call to the Python exponent operator.
Class representing a call to the Python exponent operator. I.e:
a ** b
is equivalent to: >>> PyccelPow(a, b)
- Parameters:
arg1 (TypedAstNode) – The first argument passed to the operator.
arg2 (TypedAstNode) – The second argument passed to the operator.
- class pyccel.ast.operators.PyccelUnary(arg)[source]View on GitHub#
Bases:
PyccelUnaryOperatorClass representing a call to the Python positive operator.
Class representing a call to the Python positive operator. I.e:
+a
is equivalent to: >>> PyccelUnary(a)
- Parameters:
arg (TypedAstNode) – The argument passed to the operator.
- class pyccel.ast.operators.PyccelUnaryOperator(arg)[source]View on GitHub#
Bases:
PyccelOperatorSuperclass representing an operator with only one argument.
Abstract superclass representing a Python operator with only one argument.
- Parameters:
arg (TypedAstNode) – The argument passed to the operator.
- class pyccel.ast.operators.PyccelUnarySub(arg)[source]View on GitHub#
Bases:
PyccelUnaryClass representing a call to the Python negative operator.
Class representing a call to the Python negative operator. I.e:
-a
is equivalent to: >>> PyccelUnarySub(a)
- Parameters:
arg (TypedAstNode) – The argument passed to the operator.