loki.types
Collection of classes to represent type information for symbols used throughout Loki’s internal representation (IR)
Classes
|
Representation of intrinsic data types, names taken from the FORTRAN convention. |
|
Base class for data types a symbol may have |
|
Representation of derived data types that may have an associated |
|
Representation of a module definition. |
|
Representation of a function or subroutine type definition. |
|
Representation of a symbol's attributes, such as data type and declared properties |
- class BasicType(value)
-
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_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
orBasicType.DEFERRED
, if the associated type definition is not available.- Parameters:
- 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 theSubroutine
object that is the target of a call. If the corresponding object is not yet available when theProcedureType
object is created, or its definition is transient and subject to IR rebuilds (e.g.StatementFunction
), theLazyNodeLookup
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 aLazyNodeLookup
)is_function (bool, optional) – Indicate that this is a function
is_generic (bool, optional) – Indicate that this is a generic function
procedure (
Subroutine
orStatementFunction
orLazyNodeLookup
, 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 theProcedureType
object.
- property procedure
The
Subroutine
object of the procedureIf not provided during instantiation or if the underlying
weakref
is dead, this returnsBasicType.DEFERRED
.
- property is_function
Return True if the procedure is a function, otherwise False
- property is_elemental
Return
True
if the procedure has theelemental
prefix, otherwiseFalse
- 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:
name (str, optional) – The name of the module. Can be skipped if
module
is provided (not in the form of aLazyNodeLookup
)module (
Module
LazyNodeLookup
, optional) – The procedure this type represents
- 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 theModuleType
object.
- property module
The
Module
object represented by this typeIf not provided during instantiation or if the underlying
weakref
is dead, this returnsBasicType.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 propertySymbolAttributes.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 attributesAttributes 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 withignore (iterable, optional) – Names of attributes to ignore while comparing.
- Return type: