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
dtypeproperty 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
PsExpressionshould not override this method, but implement_clone_exprinstead. That implementation shall callcloneon any of its subexpressions, but does not need to fix thedtypeproperty. Thedtypeis correctly applied byPsExpression.cloneinternally.
- abstract _clone_expr()#
Implementation of expression cloning.
- Return type: