loki.ir.nodes.leaf_nodes
Control flow node classes for Control flow tree
Classes
|
Internal representation of a variable allocation. |
|
Internal representation of a variable assignment. |
|
Internal representation of a subroutine call. |
|
Internal representation of a single comment. |
|
Internal representation of a block comment that is formed from multiple single-line comments. |
|
Internal representation of an inline conditional assignment using a ternary operator. |
|
Internal representation of a |
|
Internal representation of a variable deallocation. |
|
Internal representation of an |
|
Internal representation of a FORALL statement or construct. |
|
Internal representation of an import. |
|
Internal representation of a masked array assignment ( |
|
Internal representation of a multi-value conditional (eg. |
|
Internal representation of a pointer nullification. |
|
Internal representation of a pragma. |
|
Internal representation of a preprocessor directive. |
|
Internal representation of a procedure declaration. |
|
Generic node for unparsed source code sections |
|
Internal representation of Fortran statement function statements |
|
Internal representation of a multi-type conditional (eg. |
|
Internal representation of a derived type definition. |
|
Internal representation of a variable declaration. |
- class Assignment(lhs: Expression, rhs: Expression, ptr: bool = False, comment: Node | None = None, source: Source | str | None = None, label: str | None = None)
Bases:
LeafNode,_AssignmentBaseInternal 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 toFalse.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,_ConditionalAssignmentBaseInternal 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,_CallStatementBaseInternal 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 defaultPragmanodes appear as standalone nodes in the IR before. Only a bespoke context created bypragmas_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
The
ProcedureTypeof theSubroutineobject of the called routineFor a
CallStatementnode calledcall, this is shorthand forcall.name.type.dtype.If the procedure type object has been linked up with the corresponding
Subroutineobject, then it is available viacall.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:
- property routine
The
Subroutineobject of the called routineShorthand for
call.name.type.dtype.procedure- Returns:
If the
ProcedureTypeobject of theProcedureSymbolinnameis linked up to the target routine, this returns the correspondingSubroutineobject, otherwise None.- Return type:
- arg_iter()
Iterator that maps argument definitions in the target
Subroutineto 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,_AllocationBaseInternal representation of a variable allocation.
- Parameters:
variables (tuple of
pymbolic.primitives.Expression) – The list of variables that are allocated.data_source (
pymbolic.primitives.Expressionor str) – Fortran’sSOURCEallocation option.status_var (
pymbolic.primitives.Expression) – Fortran’sSTATallocation 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,_DeallocationBaseInternal 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’sSTATdeallocation 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,_NullifyBaseInternal 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,_CommentBaseInternal 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,_CommentBlockBaseInternal 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,_PragmaBaseInternal representation of a pragma.
Pragmas are assumed to appear in Fortran source code in the form of !$<keyword> <content>.
- class PreprocessorDirective(text: str = None, source: Source | str | None = None, label: str | None = None)
Bases:
LeafNode,_PreprocessorDirectiveBaseInternal 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,_ImportBaseInternal representation of an import.
- Parameters:
module (str) – The name of the module or header file to import from.
symbols (tuple of
ExpressionorDataType, optional) – The list of names imported. Can be empty when importing all.nature (str, optional) – The module nature (
INTRINSICorNON_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,_VariableDeclarationBaseInternal 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 defaultPragmanodes appear as standalone nodes in the IR. Only a bespoke context created bypragmas_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,_ProcedureDeclarationBaseInternal representation of a procedure declaration.
- Parameters:
symbols (tuple of
pymbolic.primitives.Expression) – The list of procedure symbols declared by this declaration.interface (
pymbolic.primitives.ExpressionorDataType, optional) – The procedure interface of the declared procedure entity names.external (bool, optional) – This is a Fortran
EXTERNALdeclaration.module (bool, optional) – This is a Fortran
MODULE PROCEDUREdeclaration in an interface (i.e. includes the keywordMODULE)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 defaultPragmanodes appear as standalone nodes in the IR. Only a bespoke context created bypragmas_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,_DataDeclarationBaseInternal representation of a
DATAdeclaration 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)
Bases:
LeafNode,_StatementFunctionBaseInternal representation of Fortran statement function statements
- Parameters:
variable (
pymbolic.primitives.Expression) – The name of the statement functionarguments (tuple of
pymbolic.primitives.Expression) – The list of dummy argumentsrhs (
pymbolic.primitives.Expression) – The expression defining the statement functionreturn_type (
SymbolAttributes) – The return type of the statement function
- property name
- 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,_TypeDefBaseInternal representation of a derived type definition.
Similar to
Sourcefile,Module, andSubroutine, it forms its own scope for symbols and types. This is required to instantiateTypedSymbolinstances 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
PRIVATEpublic (bool, optional) – Flag to indicate that this has been declared explicitly as
PUBLICparent (
Scope, optional) – The parent scope in which the type definition appearssymbol_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
DerivedTyperepresenting 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.cloneand force rescoping of variables, unlesssymbol_attrsandrescope_symbolsare 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,_MultiConditionalBaseInternal 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
DEFAULTcase.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,_TypeConditionalBaseInternal 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 betweenTYPE ISandCLASS IS)bodies (tuple of tuple) – The corresponding bodies for each case.
else_body (tuple) – The body for the
DEFAULTcase.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,_ForallBaseInternal 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,_MaskedStatementBaseInternal representation of a masked array assignment (
WHEREclause).- Parameters:
conditions (tuple of
pymbolic.primitives.Expression) – The conditions that define the maskbodies (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 (ELSEWHEREstatement).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,_EnumerationBaseInternal representation of an
ENUMThe constants declared by this are represented as
Variableobjects with their value (if specified explicitly) stored as theinitialproperty 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,_RawSourceBaseGeneric node for unparsed source code sections
This is used by the
REGEXfrontend 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.