psyclone.psyir.symbols.datatypes#
This module contains the datatype definitions.
Classes#
UnsupportedType: Indicates that a variable declaration is not supported by the PSyIR.UnsupportedFortranType: Indicates that a Fortran declaration is not supported by the PSyIR.UnresolvedType: Indicates that the type declaration has not been found yet.ScalarType: Describes a scalar datatype (and its precision).ArrayType: Describes an array datatype. Can be an array of intrinsic types (e.g.StructureType: Describes a ‘structure’ or ‘derived’ datatype that is itself composed
- class psyclone.psyir.symbols.datatypes.UnsupportedType(declaration_txt)[source]#
Indicates that a variable declaration is not supported by the PSyIR. This class is abstract and must be subclassed for each language supported by the PSyIR frontends.
- Parameters:
declaration_txt (str) – the original textual declaration of the symbol.
- Raises:
TypeError – if the supplied declaration_txt is not a str.
Inheritance

- property declaration#
- Returns:
the original declaration of the symbol.
- Return type:
str
- class psyclone.psyir.symbols.datatypes.UnsupportedFortranType(declaration_txt, partial_datatype=None)[source]#
Indicates that a Fortran declaration is not supported by the PSyIR.
- Parameters:
declaration_txt (str) – string containing the original variable declaration.
partial_datatype (Optional[
psyclone.psyir.symbols.DataTypeorpsyclone.psyir.symbols.DataTypeSymbol]) – a PSyIR datatype representing the subset of type attributes that are supported.
Inheritance

- copy()[source]#
- Returns:
a copy of this datatype.
- Return type:
psyclone.psyir.symbols.datatypes.UnknownFortranType
- get_all_accessed_symbols()[source]#
- Return type:
set[Symbol]- Returns:
a set of all the symbols accessed inside this DataType.
- property intrinsic#
- Returns:
the intrinsic used by this type (this is often recoverable from the partial datatype).
- Return type:
pyclone.psyir.datatypes.ScalarType.Intrinsic
- property is_allocatable: bool | None#
If we have enough information in the partial_datatype, determines whether this data type is allocatable or not. If it is unknown, it will return None. Note that atm PSyclone only supports the allocatable attribute for arrays. # TODO #2898 If we support non-array allocatable types, the test for arrays can be removed
- Returns:
whether this UnsupportedFortranType is known to be allocatable.
- property partial_datatype#
- Returns:
partial datatype information if it can be determined, else None.
- Return type:
Optional[
psyclone.psyir.symbols.DataType|psyclone.symbols.symbols.DataTypeSymbol]
- replace_symbols_using(table_or_symbol)[source]#
Replace any Symbols referred to by this object with those in the supplied SymbolTable (or just the supplied Symbol instance) if they have matching names. If there is no match for a given Symbol then it is left unchanged.
This base implementation simply propagates the call to any child Nodes.
- Parameters:
table_or_symbol (
psyclone.psyir.symbols.SymbolTable|psyclone.psyir.symbols.Symbol) – the symbol table from which to get replacement symbols or a single, replacement Symbol.
- property type_text#
Parses the original Fortran declaration and uses the resulting parse tree to extract the type information. This is returned in text form and also cached.
TODO #2137 - alter Unsupported(Fortran)Type so that it is only the type information that is stored as a string. i.e. remove the name of the variable being declared. Once that is done this method won’t be required.
Note that UnsupportedFortranType is also used to hold things like ‘SAVE :: /my_common/’ and thus it is not always possible/appropriate to extract a type expression.
- Returns:
the Fortran code specifying the type.
- Return type:
str
- Raises:
NotImplementedError – if declaration text cannot be extracted from the original Fortran declaration.
- class psyclone.psyir.symbols.datatypes.UnresolvedType[source]#
Indicates that the type declaration has not been found yet.
Inheritance

- property is_allocatable: bool | None#
- Returns:
whether this DataType is allocatable. In case of an UnresolvedType we don’t know.
- class psyclone.psyir.symbols.datatypes.ScalarType(intrinsic, precision)[source]#
Describes a scalar datatype (and its precision).
- Parameters:
intrinsic (
pyclone.psyir.datatypes.ScalarType.Intrinsic) – the intrinsic of this scalar type.precision (
psyclone.psyir.symbols.ScalarType.Precision| int |psyclone.psyir.nodes.DataNode) – the precision of this scalar type.
- Raises:
TypeError – if any of the arguments are of the wrong type.
ValueError – if any of the argument have unexpected values.
Inheritance

- class Intrinsic(*values)[source]#
Enumeration of the different intrinsic scalar datatypes that are supported by the PSyIR.
- class Precision(*values)[source]#
Enumeration of the different types of ‘default’ precision that may be specified for a scalar datatype.
- TYPE_MAP_TO_PYTHON = {Intrinsic.BOOLEAN: <class 'bool'>, Intrinsic.CHARACTER: <class 'str'>, Intrinsic.INTEGER: <class 'int'>, Intrinsic.REAL: <class 'float'>}#
Mapping from PSyIR scalar data types to intrinsic Python types ignoring precision.
- get_all_accessed_symbols()[source]#
- Return type:
set[Symbol]- Returns:
a set of all the symbols accessed inside this DataType.
- property intrinsic#
- Returns:
the intrinsic used by this scalar type.
- Return type:
pyclone.psyir.datatypes.ScalarType.Intrinsic
- property precision#
- Returns:
the precision of this scalar type.
- Return type:
psyclone.psyir.symbols.ScalarType.Precision| int |psyclone.psyir.nodes.DataNode
- replace_symbols_using(table_or_symbol)[source]#
Replace any Symbols referred to by this object with those in the supplied SymbolTable (or just the supplied Symbol instance) if they have matching names. If there is no match for a given Symbol then it is left unchanged.
- Parameters:
table_or_symbol (
psyclone.psyir.symbols.SymbolTable|psyclone.psyir.symbols.Symbol) – the symbol table from which to get replacement symbols or a single, replacement Symbol.
- class psyclone.psyir.symbols.datatypes.ArrayType(datatype, shape)[source]#
Describes an array datatype. Can be an array of intrinsic types (e.g. integer) or of structure types. For the latter, the type must currently be specified as a DataTypeSymbol (see #1031).
- Parameters:
datatype (
psyclone.psyir.datatypes.DataType|psyclone.psyir.symbols.DataTypeSymbol) – the datatype of the array elements.shape (list) – shape of the symbol in column-major order (leftmost index is contiguous in memory). Each entry represents an array dimension. If it is ArrayType.Extent.ATTRIBUTE the extent of that dimension is unknown but the lower bound is 1 and the extent can be obtained by querying the appropriate intrinsic (e.g. using the SIZE intrinsic in Fortran). If it is ArrayType.Extent.DEFERRED then the extent and bounds are all unknown and may or may not be possible to query them using intrinsics (e.g. the array is ALLOCATABLE in Fortran). Otherwise it can be an int or a DataNode (that returns an int) or a 2-tuple of such quantities. If only a single value is provided then that is taken to be the upper bound and the lower bound defaults to 1. If a 2-tuple is provided then the two members specify the lower and upper bounds, respectively, of the current dimension. Note that providing an int is supported as a convenience, the provided value will be stored internally as a Literal node.
- Raises:
TypeError – if the arguments are of the wrong type.
NotImplementedError – if a structure type does not have a DataTypeSymbol as its type.
Inheritance

- class ArrayBounds(lower, upper)[source]#
Class to store lower and upper limits of a declared array dimension.
- Parameters:
lower (
psyclone.psyir.nodes.DataNode) – the lower bound of the array dimension.upper (Union[
psyclone.psyir.nodes.DataNode, psyclone.psyir.symbols.datatypes.ArrayType.Extent.ATTRIBUTE]) – the upper bound of the array dimension or ArrayType.Extent.ATTRIBUTE if unspecified.
- class Extent(*values)[source]#
Enumeration of array shape extents that are unspecified at compile time. An ‘ATTRIBUTE’ extent means that the lower bound is known (defaults to 1 if not specified) with an unknown extent (which can be retrieved at run-time with the UBOUND intrinsic). A ‘DEFERRED’ extent means that we don’t know anything about the bounds, and run-time intrinsics may or may not be able to retrieve them (e.g. the array may need to be allocated/malloc’d).
- copy()[source]#
Create a copy of this ArrayType. Any shape expressions will be re-created but any referenced Symbols will remain unchanged.
- Returns:
a copy of this ArrayType.
- Return type:
psyclone.psyir.datatype.ArrayType
- property datatype#
- Returns:
the datatype of each element in the array.
- Return type:
- get_all_accessed_symbols()[source]#
- Return type:
set[Symbol]- Returns:
a set of all the symbols accessed inside this DataType.
- property intrinsic#
- Returns:
the intrinsic type of each element in the array.
- Return type:
pyclone.psyir.datatypes.ScalarType.Intrinsic|psyclone.psyir.symbols.DataTypeSymbol
- property is_allocatable: bool#
- Returns:
whether this array is allocatable or not.
- property precision#
- Returns:
the precision of each element in the array.
- Return type:
psyclone.psyir.symbols.ScalarType.Precision, int orpsyclone.psyir.symbols.DataSymbol
- replace_symbols_using(table_or_symbol)[source]#
Replace any Symbols referred to by this object with those in the supplied SymbolTable (or just the supplied Symbol instance) if they have matching names. If there is no match for a given Symbol then it is left unchanged.
- Parameters:
table_or_symbol (
psyclone.psyir.symbols.SymbolTable|psyclone.psyir.symbols.Symbol) – the symbol table from which to get replacement symbols or a single, replacement Symbol.
- property shape#
- Returns:
the (validated) shape of the symbol in column-major order (leftmost index is contiguous in memory) with each entry representing an array dimension. If an entry is ArrayType.Extent.ATTRIBUTE the extent of that dimension is unknown but can be obtained by querying the run-time system (e.g. using the SIZE intrinsic in Fortran). If it is ArrayType.Extent.DEFERRED then the extent is also unknown and may or may not be defined at run-time (e.g. the array is ALLOCATABLE in Fortran). Otherwise an entry is an ArrayBounds namedtuple with lower and upper components.
- Return type:
list[ArrayType.Extent.ATTRIBUTE | ArrayType.Extent.DEFERRED |
psyclone.psyir.nodes.ArrayType.ArrayBounds].
- class psyclone.psyir.symbols.datatypes.StructureType[source]#
Describes a ‘structure’ or ‘derived’ datatype that is itself composed of a list of other datatypes. Those datatypes are stored as an OrderedDict of namedtuples.
Note, we could have chosen to use a SymbolTable to store the properties of the constituents of the type. (Since they too have a name, a type, and visibility.) If this class ends up duplicating a lot of the SymbolTable functionality then this decision could be revisited.
Inheritance

- class ComponentType(name, datatype, visibility, initial_value)[source]#
Represents a member of a StructureType.
- Parameters:
name (
str) – the name of the member.datatype (
Union[DataType,DataTypeSymbol]) – the type of the member.visibility (
Visibility) – whether this member is public or private.initial_value (Optional[
psyclone.psyir.nodes.Node]) – the initial value of this member (if any).
- add(name, datatype, visibility, initial_value=None, preceding_comment='', inline_comment='')[source]#
Create a component with the supplied attributes and add it to this StructureType.
- Parameters:
name (
str) – the name of the new component.datatype (
psyclone.psyir.symbols.DataType|psyclone.psyir.symbols.DataTypeSymbol) – the type of the new component.visibility (
psyclone.psyir.symbols.Symbol.Visibility) – whether this component is public or private.initial_value (Optional[
psyclone.psyir.nodes.DataNode]) – the initial value of the new component.preceding_comment (
str) – a comment that precedes this component.inline_comment (
str) – a comment that follows this component on the same line.
- Raises:
TypeError – if any of the supplied values are of the wrong type.
- property components#
- Returns:
Ordered dictionary of the components of this type.
- Return type:
collections.OrderedDict
- static create(components)[source]#
Creates a StructureType from the supplied list of properties.
- Parameters:
components (List[tuple[ str,
psyclone.psyir.symbols.DataType|psyclone.psyir.symbols.DataTypeSymbol,psyclone.psyir.symbols.Symbol.Visibility, Optional[psyclone.psyir.symbols.DataNode], Optional[str], Optional[str] ]]) – the name, type, visibility (whether public or private), initial value (if any), preceding comment (if any) and inline comment (if any) of each component.- Returns:
the new type object.
- Return type:
- get_all_accessed_symbols()[source]#
- Return type:
set[Symbol]- Returns:
a set of all the symbols accessed inside this DataType.
- lookup(name)[source]#
- Returns:
the ComponentType tuple describing the named member of this StructureType.
- Return type:
- replace_symbols_using(table_or_symbol)[source]#
Replace any Symbols referred to by this object with those in the supplied SymbolTable (or just the supplied Symbol instance) if they have matching names. If there is no match for a given Symbol then it is left unchanged.
This base implementation simply propagates the call to any child Nodes.
- Parameters:
table_or_symbol (
psyclone.psyir.symbols.SymbolTable|psyclone.psyir.symbols.Symbol) – the symbol table from which to get replacement symbols or a single, replacement Symbol.