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)

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

Inheritance diagram of UnsupportedType
property declaration
Returns:

the original declaration of the symbol. This is obviously language specific and hence this class must be subclassed.

Return type:

str

class psyclone.psyir.symbols.datatypes.UnsupportedFortranType(declaration_txt, partial_datatype=None)

Indicates that a Fortran declaration is not supported by the PSyIR.

Parameters:

Inheritance

Inheritance diagram of UnsupportedFortranType
property partial_datatype
Returns:

partial datatype information if it can be determined, else None.

Return type:

Optional[psyclone.symbols.DataType]

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

Indicates that the type declaration has not been found yet.

Inheritance

Inheritance diagram of UnresolvedType
class psyclone.psyir.symbols.datatypes.ScalarType(intrinsic, precision)

Describes a scalar datatype (and its precision).

Parameters:
Raises:
  • TypeError – if any of the arguments are of the wrong type.

  • ValueError – if any of the argument have unexpected values.

Inheritance

Inheritance diagram of ScalarType
class Intrinsic(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Enumeration of the different intrinsic scalar datatypes that are supported by the PSyIR.

class Precision(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Enumeration of the different types of ‘default’ precision that may be specified for a scalar 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 or psyclone.psyir.symbols.DataSymbol

class psyclone.psyir.symbols.datatypes.ArrayType(datatype, shape)

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 or 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 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 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

Inheritance diagram of ArrayType
class ArrayBounds(lower, upper)

namedtuple used to store lower and upper limits of an array dimension

lower

Alias for field number 0

upper

Alias for field number 1

class Extent(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Enumeration of array shape extents that are unspecified at compile time. When the extent must exist and is accessible via the run-time system it is an ‘ATTRIBUTE’. When it may or may not be defined in the current scope (e.g. the array may need to be allocated/malloc’d) it is ‘DEFERRED’.

property datatype
Returns:

the datatype of each element in the array.

Return type:

psyclone.psyir.symbols.DataSymbol

property intrinsic
Returns:

the intrinsic type of each element in the array.

Return type:

pyclone.psyir.datatypes.ScalarType.Intrinsic or psyclone.psyir.symbols.DataSymbol

property precision
Returns:

the precision of each element in the array.

Return type:

psyclone.psyir.symbols.ScalarType.Precision, int or psyclone.psyir.symbols.DataSymbol

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.

Return type:

a list of ArrayType.Extent.ATTRIBUTE, ArrayType.Extent.DEFERRED, or psyclone.psyir.nodes.ArrayType.ArrayBounds. 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 a DataNode that returns an int.

class psyclone.psyir.symbols.datatypes.StructureType

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

Inheritance diagram of StructureType
class ComponentType(name, datatype, visibility, initial_value)
datatype

Alias for field number 1

initial_value

Alias for field number 3

name

Alias for field number 0

visibility

Alias for field number 2

add(name, datatype, visibility, initial_value)

Create a component with the supplied attributes and add it to this StructureType.

Parameters:
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)

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] ]]) – the name, type, visibility (whether public or private) and initial value (if any) of each component.

Returns:

the new type object.

Return type:

psyclone.psyir.symbols.StructureType

lookup(name)
Returns:

the ComponentType tuple describing the named member of this StructureType.

Return type:

psyclone.psyir.symbols.StructureType.ComponentType