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:
DataTypeRepresentation of derived data types that may have an associated
TypeDefPlease note that the typedef attribute may be of
TypeDeforBasicType.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:
DataTypeRepresentation 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 theSubroutineobject that is the target of a call. If the corresponding object is not yet available when theProcedureTypeobject is created, or its definition is transient and subject to IR rebuilds (e.g.StatementFunction), theLazyNodeLookuputility can be used to defer the actual instantiation. In that situation,nameshould be provided in addition.- Parameters:
name (str, optional) – The name of the function or subroutine. Can be skipped if
procedureis 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 (
SubroutineorStatementFunctionorLazyNodeLookup, optional) – The procedure this type represents
- property name
The name of the procedure
This looks up the name in the linked
procedureif available, otherwise returns the name stored during instanation of theProcedureTypeobject.
- property procedure
The
Subroutineobject of the procedureIf not provided during instantiation or if the underlying
weakrefis dead, this returnsBasicType.DEFERRED.
- property is_function
Return True if the procedure is a function, otherwise False
- property is_elemental
Return
Trueif the procedure has theelementalprefix, otherwiseFalse
- property return_type
The return type of the function (or None)
- class ModuleType(name=None, module=None)
Bases:
DataTypeRepresentation 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
moduleis provided (not in the form of aLazyNodeLookup)module (
ModuleLazyNodeLookup, optional) – The procedure this type represents
- property name
The name of the module
This looks up the name in the linked
moduleif available, otherwise returns the name stored during instantiation of theModuleTypeobject.
- property module
The
Moduleobject represented by this typeIf not provided during instantiation or if the underlying
weakrefis dead, this returnsBasicType.DEFERRED.
- class SymbolAttributes(dtype, **kwargs)
Bases:
objectRepresentation of a symbol’s attributes, such as data type and declared properties
It has a fixed
DataTypeassociated 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
SymbolAttributesobjects 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: