# loki.ir.nodes.leaf_nodes module

Control flow node classes for Control flow tree

class Assignment(lhs: Expression, rhs: Expression, ptr: bool = False, comment: Node | None = None, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_AssignmentBase`

  Internal representation of a variable assignment.

  Parameters:

    - lhs (`pymbolic.primitives.Expression`) – The left-hand side of the assignment.

    - rhs (`pymbolic.primitives.Expression`) – The right-hand side expression of the assignment.

    - ptr (bool, optional) – Flag to indicate pointer assignment (`=>`). Defaults to `False`.

    - comment (`Comment`, optional) – Inline comment that appears in-line after the right-hand side in the original source.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class ConditionalAssignment(lhs: Expression | None = None, condition: Expression | None = None, rhs: Expression | None = None, else_rhs: Expression | None = None, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_ConditionalAssignmentBase`

  Internal representation of an inline conditional assignment using a ternary operator.

  There is no Fortran-equivalent to this. In C, this takes the following form:

      lhs = condition ? rhs : else_rhs;

  Parameters:

    - lhs (`pymbolic.primitives.Expression`) – The left-hand side of the assignment.

    - condition (`pymbolic.primitives.Expression`) – The condition of the ternary operator.

    - rhs (`pymbolic.primitives.Expression`) – The right-hand side expression of the assignment that is assigned when the condition applies.

    - else_rhs (`pymbolic.primitives.Expression`) – The right-hand side expression of the assignment that is assigned when the condition does not apply.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class CallStatement(name: Expression, arguments: Tuple[Expression, ...] | None = (), kwarguments: Tuple[Tuple[str, Expression], ...] | None = (), pragma: Tuple[Node, ...] | None = None, not_active: bool | None = None, chevron: Tuple[Expression, ...] | None = None, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_CallStatementBase`

  Internal representation of a subroutine call.

  Parameters:

    - name (`pymbolic.primitives.Expression`) – The name of the subroutine to call.

    - arguments (tuple of `pymbolic.primitives.Expression`) – The list of positional arguments.

    - kwarguments (tuple of tuple) – The list of keyword arguments, provided as pairs of (name, value).

    - pragma (tuple of `Pragma`, optional) – Pragma(s) that appear in front of the statement. By default `Pragma` nodes appear as standalone nodes in the IR before. Only a bespoke context created by `pragmas_attached()` attaches them for convenience.

    - not_active (bool, optional) – Flag to indicate that this call has explicitly been marked as inactive for the purpose of processing call trees (Default: None)

    - chevron (tuple of `pymbolic.primitives.Expression`) – Launch configuration for CUDA Fortran Kernels. See [CUDA Fortran programming guide](https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/).

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

  classmethod ensure_tuple(value)
  classmethod ensure_nested_tuple(value)
  property procedure_type: DataType

    The `ProcedureType` of the `Subroutine` object of the called routine

    For a `CallStatement` node called `call`, this is shorthand for `call.name.type.dtype`.

    If the procedure type object has been linked up with the corresponding `Subroutine` object, then it is available via `call.procedure_type.procedure`.

    Returns:

      The type of the called procedure. If the symbol type of the called routine has not been identified correctly, this may yield `BasicType.DEFERRED`.

    Return type:

      `ProcedureType` or `BasicType.DEFERRED`

  property routine: Function | Subroutine | StatementFunction | BasicType

    The `Subroutine` object of the called routine

    Shorthand for `call.name.type.dtype.procedure`

    Returns:

      If the `ProcedureType` object of the `ProcedureSymbol` in `name` is linked up to the target routine, this returns the corresponding `Subroutine` object, otherwise None.

    Return type:

      `Subroutine` or `BasicType.DEFERRED`

  arg_iter()

    Iterator that maps argument definitions in the target `Subroutine` to arguments and keyword arguments in the call.

    Returns:

      An iterator that traverses the mapping `(arg name, call arg)` for all positional and then keyword arguments.

    Return type:

      iterator

  property arg_map

    A full map of all qualified argument matches from arguments and keyword arguments.

  is_kwargs_order_correct()

    Check whether kwarguments are correctly ordered in respect to the arguments (`self.routine.arguments`).

  sort_kwarguments()

    Sort and update the kwarguments according to the order of the arguments (`self.routine.arguments`).

  convert_kwargs_to_args()

    Convert all kwarguments to arguments and update the call accordingly.

class Allocation(variables: Tuple[Expression, ...], data_source: Expression | None = None, status_var: Expression | None = None, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_AllocationBase`

  Internal representation of a variable allocation.

  Parameters:

    - variables (tuple of `pymbolic.primitives.Expression`) – The list of variables that are allocated.

    - data_source (`pymbolic.primitives.Expression` or str) – Fortran’s `SOURCE` allocation option.

    - status_var (`pymbolic.primitives.Expression`) – Fortran’s `STAT` allocation option.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class Deallocation(variables: Tuple[Expression, ...], status_var: Expression | None = None, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_DeallocationBase`

  Internal representation of a variable deallocation.

  Parameters:

    - variables (tuple of `pymbolic.primitives.Expression`) – The list of variables that are deallocated.

    - status_var (`pymbolic.primitives.Expression`) – Fortran’s `STAT` deallocation option.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class Nullify(variables: Tuple[Expression, ...], source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_NullifyBase`

  Internal representation of a pointer nullification.

  Parameters:

    - variables (tuple of `pymbolic.primitives.Expression`) – The list of pointer variables that are nullified.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class Comment(text: str, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_CommentBase`

  Internal representation of a single comment.

  Parameters:

    - text (str, optional) – The content of the comment. Can be empty to represent empty lines in the original source.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class CommentBlock(comments: Tuple[Node, ...], source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_CommentBlockBase`

  Internal representation of a block comment that is formed from multiple single-line comments.

  Parameters:

    - comments (tuple of `Comment`) – The individual (subsequent) comments that make up the block.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

  property text

    The combined string of all comments in this block

class Pragma(keyword: str, content: str | None = None, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_PragmaBase`

  Internal representation of a pragma.

  Pragmas are assumed to appear in Fortran source code in the form of !$<keyword> <content>.

  Parameters:

    - keyword (str) – The keyword of the pragma.

    - content (str, optional) – The content of the pragma after the keyword.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class PreprocessorDirective(text: str = None, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_PreprocessorDirectiveBase`

  Internal representation of a preprocessor directive.

  Preprocessor directives are typically assumed to start at the beginning of a line with the letter `#` in the original source.

  Parameters:

    - text (str, optional) – The content of the directive.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class Import(module: str | None, symbols: Tuple[Expression, ...] = (), nature: str | None = None, c_import: bool = False, f_include: bool = False, f_import: bool = False, rename_list: Tuple[Any, ...] | None = None, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_ImportBase`

  Internal representation of an import.

  Parameters:

    - module (str) – The name of the module or header file to import from.

    - symbols (tuple of `Expression` or `DataType`, optional) – The list of names imported. Can be empty when importing all.

    - nature (str, optional) – The module nature (`INTRINSIC` or `NON_INTRINSIC`)

    - c_import (bool, optional) – Flag to indicate that this is a C-style include. Defaults to False.

    - f_include (bool, optional) – Flag to indicate that this is a preprocessor-style include in Fortran source code.

    - f_import (bool, optional) – Flag to indicate that this is a Fortran `IMPORT`.

    - rename_list (tuple of tuples (str, `Expression`), optional) – Rename list with pairs of (use name, local name) entries

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class VariableDeclaration(symbols: Tuple[Expression, ...], dimensions: Tuple[Expression, ...] | None = None, comment: Node | None = None, pragma: Node | None = None, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_VariableDeclarationBase`

  Internal representation of a variable declaration.

  Parameters:

    - symbols (tuple of `pymbolic.primitives.Expression`) – The list of variables declared by this declaration.

    - dimensions (tuple of `pymbolic.primitives.Expression`, optional) – The declared allocation size if given as part of the declaration attributes.

    - comment (`Comment`, optional) – Inline comment that appears in-line after the declaration in the original source.

    - pragma (tuple of `Pragma`, optional) – Pragma(s) that appear before the declaration. By default `Pragma` nodes appear as standalone nodes in the IR. Only a bespoke context created by `pragmas_attached()` attaches them for convenience.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class ProcedureDeclaration(symbols: Tuple[Expression, ...], interface: Expression | DataType | None = None, external: bool = False, module: bool = False, generic: bool = False, final: bool = False, comment: Node | None = None, pragma: Tuple[Node, ...] | None = None, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_ProcedureDeclarationBase`

  Internal representation of a procedure declaration.

  Parameters:

    - symbols (tuple of `pymbolic.primitives.Expression`) – The list of procedure symbols declared by this declaration.

    - interface (`pymbolic.primitives.Expression` or `DataType`, optional) – The procedure interface of the declared procedure entity names.

    - external (bool, optional) – This is a Fortran `EXTERNAL` declaration.

    - module (bool, optional) – This is a Fortran `MODULE PROCEDURE` declaration in an interface (i.e. includes the keyword `MODULE`)

    - generic (bool, optional) – This is a generic binding procedure statement in a derived type.

    - final (bool, optional) – This is a declaration to mark a subroutine for clean-up of a derived type.

    - comment (`Comment`, optional) – Inline comment that appears in-line after the declaration in the original source.

    - pragma (tuple of `Pragma`, optional) – Pragma(s) that appear before the declaration. By default `Pragma` nodes appear as standalone nodes in the IR. Only a bespoke context created by `pragmas_attached()` attaches them for convenience.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class DataDeclaration(variable: Any, values: Tuple[Expression, ...], source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_DataDeclarationBase`

  Internal representation of a `DATA` declaration for explicit array value lists.

  Parameters:

    - variable (`pymbolic.primitives.Expression`) – The left-hand side of the data declaration.

    - values (tuple of `pymbolic.primitives.Expression`) – The right-hand side of the data declaration.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class StatementFunction(variable: Expression, arguments: Tuple[Expression, ...], rhs: Expression, return_type: SymbolAttributes, source: Source | str | None = None, label: str | None = None, parent: dataclasses.InitVar[object] = None)

  Bases: `ScopedNode`, `LeafNode`, `_StatementFunctionBase`

  Internal representation of Fortran statement function statements.

  Internally, this is considered a `ScopedNode`, because it may be the target of a `ProcedureType`.

  Parameters:

    - variable (`pymbolic.primitives.Expression`) – The name of the statement function

    - arguments (tuple of `pymbolic.primitives.Expression`) – The list of dummy arguments

    - rhs (`pymbolic.primitives.Expression`) – The expression defining the statement function

    - return_type (`SymbolAttributes`) – The return type of the statement function

  property name
  property variables

    Return the variables defined in this `ScopedNode`.

  property is_function

class TypeDef(name: str | None = None, body: Tuple[Node | Scope, ...] = (), abstract: bool = False, extends: str | None = None, bind_c: bool = False, private: bool = False, public: bool = False, source: Source | str | None = None, label: str | None = None, parent: dataclasses.InitVar[object] = None)

  Bases: `ScopedNode`, `InternalNode`, `_TypeDefBase`

  Internal representation of a derived type definition.

  Similar to `Sourcefile`, `Module`, and `Subroutine`, it forms its own scope for symbols and types. This is required to instantiate `TypedSymbol` instances in declarations, imports etc. without having them show up in the enclosing scope.

  Parameters:

    - name (str) – The name of the type.

    - body (tuple) – The body of the type definition.

    - abstract (bool, optional) – Flag to indicate that this is an abstract type definition.

    - extends (str, optional) – The parent type name

    - bind_c (bool, optional) – Flag to indicate that this contains a `BIND(C)` attribute.

    - private (bool, optional) – Flag to indicate that this has been declared explicitly as `PRIVATE`

    - public (bool, optional) – Flag to indicate that this has been declared explicitly as `PUBLIC`

    - parent (`Scope`, optional) – The parent scope in which the type definition appears

    - symbol_attrs (`SymbolTable`, optional) – An existing symbol table to use

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

  property ir
  property parent_type
  property declarations
  property comments
  property variables

    Return the variables defined in this `ScopedNode`.

  property imported_symbols

    Return the symbols imported in this typedef

  property imported_symbol_map

    Map of imported symbol names to objects

  property interface_symbols

    Return the list of symbols declared via interfaces in this unit

    This returns always an empty tuple since there are no interface declarations allowed in typedefs.

  property dtype

    Return the `DerivedType` representing this type

  clone(**kwargs)

    Create a copy of the scope object with the option to override individual parameters

    Note that this will also create a copy of the symbol table via `SymbolTable.clone` and force rescoping of variables, unless `symbol_attrs` and `rescope_symbols` are explicitly specified.

    Parameters:

      **kwargs (Any parameter from the constructor)

    Returns:

      The cloned scope object

    Return type:

      type(self)

class MultiConditional(expr: Expression, values: Tuple[Tuple[Expression, ...], ...], bodies: Tuple[Any, ...], else_body: Tuple[Node, ...], name: str | None = None, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_MultiConditionalBase`

  Internal representation of a multi-value conditional (eg. `SELECT CASE`).

  Parameters:

    - expr (`pymbolic.primitives.Expression`) – The expression that is evaluated to choose the appropriate case.

    - values (tuple of tuple of `pymbolic.primitives.Expression`) – The list of values, a tuple for each case.

    - bodies (tuple of tuple) – The corresponding bodies for each case.

    - else_body (tuple) – The body for the `DEFAULT` case.

    - name (str, optional) – The construct-name of the multi conditional in the original source.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

  classmethod ensure_tuple(value)
  classmethod ensure_nested_tuple(value)

class TypeConditional(expr: Expression, values: Tuple[Tuple[Expression, bool], ...], bodies: Tuple[Any, ...], else_body: Tuple[Node, ...], name: str | None = None, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_TypeConditionalBase`

  Internal representation of a multi-type conditional (eg. `SELECT TYPE`).

  Parameters:

    - expr (`pymbolic.primitives.Expression`) – The expression that is evaluated to choose the appropriate type case.

    - values (tuple of 2-tuple with (`pymbolic.primitives.Expression`, bool)) – The list of values, a tuple for each case consisting of the type name and a bool value to indicate if this is a derived/polymorphic type case (in Fortran, this yields the difference between `TYPE IS` and `CLASS IS`)

    - bodies (tuple of tuple) – The corresponding bodies for each case.

    - else_body (tuple) – The body for the `DEFAULT` case.

    - name (str, optional) – The construct-name of the multi conditional in the original source.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class Forall(named_bounds: Tuple[Tuple[Expression, Expression], ...], body: Tuple[Node | Scope, ...] = (), mask: Expression | None = None, name: str | None = None, inline: bool = False, source: Source | str | None = None, label: str | None = None)

  Bases: `InternalNode`, `_ForallBase`

  Internal representation of a FORALL statement or construct.

  Parameters:

    - named_bounds (tuple of pairs (<variable>, <range>) of type `pymbolic.primitives.Expression`) – The collection of named variables with bounds (ranges).

    - body (tuple of `Node`) – The collection of assignment statements, nested FORALLs, and/or comments.

    - mask (`pymbolic.primitives.Expression`, optional) – The condition that define the mask.

    - name (str, optional) – The name of the multi-line FORALL construct in the original source.

    - inline (bool, optional) – Flag to indicate a single-line FORALL statement.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class MaskedStatement(conditions: Tuple[Expression, ...], bodies: Tuple[Tuple[Node, ...], ...], default: Tuple[Node, ...] | None = None, inline: bool = False, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_MaskedStatementBase`

  Internal representation of a masked array assignment (`WHERE` clause).

  Parameters:

    - conditions (tuple of `pymbolic.primitives.Expression`) – The conditions that define the mask

    - bodies (tuple of tuple of `Node`) – The conditional assignment statements corresponding to each condition.

    - default (tuple of `Node`, optional) – The assignment statements to be executed for array entries not captured by the mask (`ELSEWHERE` statement).

    - inline (bool, optional) – Flag to indicate this is a one-line where-stmt

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class Enumeration(symbols: Tuple[Expression, ...], source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_EnumerationBase`

  Internal representation of an `ENUM`

  The constants declared by this are represented as `Variable` objects with their value (if specified explicitly) stored as the `initial` property in the symbol’s type.

  Parameters:

    - symbols (list of `Expression`) – The named constants declared in this enum

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class RawSource(text: str, source: Source | str | None = None, label: str | None = None)

  Bases: `LeafNode`, `_RawSourceBase`

  Generic node for unparsed source code sections

  This is used by the `REGEX` frontend to store unparsed code sections in the IR. Currently, they don’t serve any other purpose than making sure the entire string content of the original Fortran source is retained.

  Parameters:

    - text (str) – The source code as a string.

    - **kwargs (optional) – Other parameters that are passed on to the parent class constructor.