loki.types

Collection of classes to represent type information for symbols used throughout Loki’s internal representation (IR)

Classes

BasicType(value)

Representation of intrinsic data types, names taken from the FORTRAN convention.

DataType()

Base class for data types a symbol may have

DerivedType([name, typedef])

Representation of derived data types that may have an associated TypeDef

ModuleType([name, module])

Representation of a module definition.

ProcedureType([name, is_function, ...])

Representation of a function or subroutine type definition.

SymbolAttributes(dtype, **kwargs)

Representation of a symbol's attributes, such as data type and declared properties

class DataType

Bases: object

Base class for data types a symbol may have

class BasicType(value)

Bases: DataType, int, Enum

Representation of intrinsic data types, names taken from the FORTRAN convention.

Currently, there are

and, to indicate an undefined data type (e.g., for imported symbols whose definition is not available), DEFERRED.

For convenience, string representations of FORTRAN and C99 types can be heuristically converted.

DEFERRED = -1
LOGICAL = 1
INTEGER = 2
REAL = 3
CHARACTER = 4
COMPLEX = 5
classmethod from_str(value)

Try to convert the given string using one of the from_* methods.

classmethod from_name(value)

Convert the given string representation of the BasicType.

classmethod from_fortran_type(value)

Convert the given string representation of a FORTRAN type.

classmethod from_c99_type(value)

Convert the given string representation of a C99 type.

class DerivedType(name=None, typedef=None)

Bases: DataType

Representation of derived data types that may have an associated TypeDef

Please note that the typedef attribute may be of TypeDef or BasicType.DEFERRED, if the associated type definition is not available.

Parameters:
  • name (str, optional) – The name of the derived type. Can be omitted if typedef is provided

  • typedef (TypeDef, optional) – The definition of the derived type. Takes precedence over name

property name
class ProcedureType(name=None, is_function=None, is_generic=False, procedure=None, return_type=None)

Bases: DataType

Representation of a function or subroutine type definition.

This serves also as the cross-link between the use of a procedure (e.g. in a CallStatement) to the Subroutine object that is the target of a call. If the corresponding object is not yet available when the ProcedureType object is created, or its definition is transient and subject to IR rebuilds (e.g. StatementFunction), the LazyNodeLookup utility can be used to defer the actual instantiation. In that situation, name should be provided in addition.

Parameters:
  • name (str, optional) – The name of the function or subroutine. Can be skipped if procedure is provided (not in the form of a LazyNodeLookup)

  • is_function (bool, optional) – Indicate that this is a function

  • is_generic (bool, optional) – Indicate that this is a generic function

  • procedure (Subroutine or StatementFunction or LazyNodeLookup, optional) – The procedure this type represents

property name

The name of the procedure

This looks up the name in the linked procedure if available, otherwise returns the name stored during instanation of the ProcedureType object.

property procedure

The Subroutine object of the procedure

If not provided during instantiation or if the underlying weakref is dead, this returns BasicType.DEFERRED.

property parameters

The tuple of procedure arguments, if procedure is available

property is_function

Return True if the procedure is a function, otherwise False

property is_elemental

Return True if the procedure has the elemental prefix, otherwise False

property return_type

The return type of the function (or None)

class ModuleType(name=None, module=None)

Bases: DataType

Representation of a module definition.

This serves as a caching mechanism for module definitions in symbol tables.

Parameters:
property name

The name of the module

This looks up the name in the linked module if available, otherwise returns the name stored during instantiation of the ModuleType object.

property module

The Module object represented by this type

If not provided during instantiation or if the underlying weakref is dead, this returns BasicType.DEFERRED.

class SymbolAttributes(dtype, **kwargs)

Bases: object

Representation of a symbol’s attributes, such as data type and declared properties

It has a fixed DataType associated with it, available as property SymbolAttributes.dtype.

Any other properties can be attached on-the-fly, thus allowing to store arbitrary metadata for a symbol, e.g., declaration attributes such as POINTER, ALLOCATABLE, or the shape of an array, or structural information, e.g., whether a variable is a loop index, argument, etc.

There is no need to check for the presence of attributes, undefined attributes can be queried and default to None.

Parameters:
  • dtype (DataType) – The data type associated with the symbol

  • **kwargs (optional) – Any attributes that should be stored as properties

clone(**kwargs)

Clone the SymbolAttributes, optionally overwriting any attributes

Attributes that should be removed should simply be given as None.

compare(other, ignore=None)

Compare SymbolAttributes objects while ignoring a set of select attributes.

Parameters:
  • other (SymbolAttributes) – The object to compare with

  • ignore (iterable, optional) – Names of attributes to ignore while comparing.

Return type:

bool