pystencils.backend.ast.expressions.PsExpression#
- class pystencils.backend.ast.expressions.PsExpression(dtype=None)#
Base class for all expressions.
Types: Each expression should be annotated with its type. Upon construction, the
dtype
property of most expression nodes is unset; only constant expressions, symbol expressions, and array accesses immediately inherit their type from their constant, symbol, or array, respectively.The type assigned to an expression must never be
const
. Constness and mutability are properties of memory objects, not of expressions; they are verified by inspecting the memory objects referred to by an expression.The canonical way to add types to newly constructed expressions is through the
Typifier
. It should be run at least once on any expression constructed by the backend.The type annotations are used by various transformation passes to make decisions, e.g. in function materialization and intrinsic selection.
Attention
The
structurally_equal <PsAstNode.structurally_equal>
check currently does not take expression data types into account. This may change in the future.- Parameters:
dtype (PsType | None)
- get_dtype()#
Retrieve the data type assigned to this expression.
- Raises:
PsInternalCompilerError – If this expression has no data type assigned
- Return type:
- clone()#
Clone this expression.
Note
Subclasses of
PsExpression
should not override this method, but implement_clone_expr
instead. That implementation shall callclone
on any of its subexpressions, but does not need to fix thedtype
property. Thedtype
is correctly applied byPsExpression.clone
internally.
- abstract _clone_expr()#
Implementation of expression cloning.
- Return type: