loki.ir.nodes.abstract_nodes
Abstract base classes for node definitions in the Loki IR.
Classes
|
Internal representation of a control flow node that has a traversable body property. |
|
Internal representation of a control flow node without a body. |
|
Base class for all node types in Loki's internal representation. |
|
Mix-in to attache a scope to an IR |
- class Node(source: Source | str | None = None, label: str | None = None)
Bases:
objectBase class for all node types in Loki’s internal representation.
Provides the common functionality shared by all node types; specifically, this comprises functionality to update or rebuild a node, and source metadata.
- traversable
The traversable fields of the Node; that is, fields walked over by a
Visitor. All arguments in__init__()whose name appear in this list are treated as traversable fields.
- Parameters:
- property children
The traversable children of the node.
- clone(*args, **kwargs)
Rebuild the node.
Constructs an identical copy of the node from when it was first created. Optionally, some or all of the arguments for it can be overwritten.
- Parameters:
*args (optional) – The traversable arguments used to create the node. By default,
argsare used.**kwargs (optional) – The non-traversable arguments used to create the node, By default,
args_frozenare used.
- property args
Arguments used to construct the Node.
- property args_frozen
Arguments used to construct the Node that cannot be traversed.
- view()
Pretty-print the node hierachy under this node.
- ir_graph(show_comments=False, show_expressions=False, linewidth=40, symgen=<class 'str'>)
Get the IR graph to visualize the node hierachy under this node.
- property live_symbols
Yield the list of live symbols at this node, i.e., variables that have been defined (potentially) prior to this point in the control flow graph.
This property is attached to the Node by
loki.analyse.analyse_dataflow.attach_dataflow_analysis()or when using theloki.analyse.analyse_dataflow.dataflow_analysis_attached()context manager.
- property defines_symbols
Yield the list of symbols (potentially) defined by this node.
This property is attached to the Node by
loki.analyse.analyse_dataflow.attach_dataflow_analysis()or when using theloki.analyse.analyse_dataflow.dataflow_analysis_attached()context manager.
- property uses_symbols
Yield the list of symbols used by this node before defining it.
This property is attached to the Node by
loki.analyse.analyse_dataflow.attach_dataflow_analysis()or when using theloki.analyse.analyse_dataflow.dataflow_analysis_attached()context manager.
- class InternalNode(body: Tuple[Node | Scope, ...] = (), source: Source | str | None = None, label: str | None = None)
Bases:
Node,_InternalNodeInternal representation of a control flow node that has a traversable body property.
- Parameters:
body (tuple) – The nodes that make up the body.
- classmethod ensure_tuple(value)
- class LeafNode(source: Source | str | None = None, label: str | None = None)
Bases:
NodeInternal representation of a control flow node without a body.
- class ScopedNode(parent: dataclasses.InitVar[object] | None = None)
Bases:
ScopeMix-in to attache a scope to an IR
NodeAdditionally, this specializes the node’s
_update()and_rebuild()methods to make sure that an existing symbol table is carried over correctly.- property args
Arguments used to construct the
ScopedNode, excluding the symbol table.
- abstract property variables
Return the variables defined in this
ScopedNode.
- get_symbol(name)
Returns the symbol for a given name as defined in its declaration.
The returned symbol might include dimension symbols if it was declared as an array.
- Parameters:
name (str) – Base name of the symbol to be retrieved
- Variable(**kwargs)
Factory method for
TypedSymbolorMetaSymbolclasses.This invokes the
Variablewith this node as the scope.- Parameters:
name (str) – The name of the variable.
type (optional) – The type of that symbol. Defaults to
BasicType.DEFERRED.parent (
ScalarorArray, optional) – The derived type variable this variable belongs to.dimensions (
ArraySubscript, optional) – The array subscript expression.
- parse_expr(expr_str, strict=False, evaluate=False, context=None)
Uses
parse_expr()to convert expression(s) represented in a string to Loki expression(s)/IR.- Parameters:
expr_str (str) – The expression as a string
strict (bool, optional) – Whether to raise exception for unknown variables/symbols when evaluating an expression (default: False)
evaluate (bool, optional) – Whether to evaluate the expression or not (default: False)
context (dict, optional) – Symbol context, defining variables/symbols/procedures to help/support evaluating an expression
- Returns:
The expression tree corresponding to the expression
- Return type: