psyclone.psyir.symbols#

Symbols package module

Submodules#

Classes#

  • ArgumentInterface: Captures the interface to a Symbol that is accessed as a routine

  • ArrayType: Describes an array datatype. Can be an array of intrinsic types (e.g.

  • AutomaticInterface: The symbol is declared without attributes. Its data will live

  • CommonBlockInterface: A symbol declared in the local scope but acts as a global that

  • ContainerSymbol: Symbol that represents a reference to a Container. The reference

  • DataSymbol: Symbol identifying a data element. It contains information about:

  • DataType: Abstract base class from which all types are derived.

  • DataTypeSymbol: Symbol identifying a user-defined type (e.g. a derived type in Fortran).

  • DefaultModuleInterface: The symbol contains data declared in a module scope without additional

  • GenericInterfaceSymbol: Symbol identifying a generic interface that maps to a number of

  • ImportInterface: Describes the interface to a Symbol that is imported from an

  • IntrinsicSymbol: Symbol identifying a callable intrinsic routine.

  • NoType: Indicates that the associated symbol has an empty type (equivalent

  • PreprocessorInterface: The symbol exists in the file through compiler macros or preprocessor

  • RoutineSymbol: Symbol identifying a callable routine.

  • ScalarType: Describes a scalar datatype (and its precision).

  • StaticInterface: The symbol contains data that is kept alive through the execution

  • StructureType: Describes a ‘structure’ or ‘derived’ datatype that is itself composed

  • Symbol: Generic Symbol item for the Symbol Table and PSyIR References.

  • SymbolTable: Encapsulates the symbol table and provides methods to add new

  • TypedSymbol: Abstract base class for those Symbols that have an associated datatype.

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

  • UnknownInterface: We have a symbol with a declaration but PSyclone does not support its

  • UnsupportedType: Indicates that a variable declaration is not supported by the PSyIR.

  • UnresolvedInterface: We have a symbol but we don’t know where it is declared.

  • UnresolvedType: Indicates that the type declaration has not been found yet.

class psyclone.psyir.symbols.ArgumentInterface(access=None)[source]#

Captures the interface to a Symbol that is accessed as a routine argument.

Parameters:

access (psyclone.psyir.symbols.ArgumentInterface.Access) – specifies how the argument is used in the Schedule

Inheritance

Inheritance diagram of ArgumentInterface
class Access(*values)[source]#

Enumeration for the different types of access that an Argument Symbol is permitted to have.

property access#
Returns:

the access-type for this argument.

Return type:

psyclone.psyir.symbols.ArgumentInterface.Access

copy()[source]#
Returns:

a copy of this object.

Return type:

psyclone.psyir.symbol.SymbolInterface

class psyclone.psyir.symbols.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

Inheritance diagram of ArrayType
class ArrayBounds(lower, upper)[source]#

Class to store lower and upper limits of a declared array dimension.

Parameters:
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]#
Returns:

a copy of self.

Return type:

psyclone.psyir.symbols.ArrayType.Extent

get_all_accessed_symbols()[source]#
Return type:

set[Symbol]

Returns:

a set of all the symbols accessed inside this Extent.

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:

psyclone.psyir.symbols.DataSymbol

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 or psyclone.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.AutomaticInterface[source]#

The symbol is declared without attributes. Its data will live during the local context.

Inheritance

Inheritance diagram of AutomaticInterface
class psyclone.psyir.symbols.CommonBlockInterface[source]#

A symbol declared in the local scope but acts as a global that can be accessed by any scope referencing the same CommonBlock name.

Inheritance

Inheritance diagram of CommonBlockInterface
class psyclone.psyir.symbols.ContainerSymbol(name, **kwargs)[source]#

Symbol that represents a reference to a Container. The reference is lazy evaluated, this means that the Symbol will be created without parsing and importing the referenced container, but this can be imported when needed.

Parameters:
  • name (str) – name of the symbol.

  • wildcard_import (bool) – if all public Symbols of the Container are imported into the current scope. Defaults to False.

  • is_intrinsic (bool) – if the module is an intrinsic import. Defauts to False.

  • kwargs (unwrapped dict.) – additional keyword arguments provided by psyclone.psyir.symbols.Symbol.

Inheritance

Inheritance diagram of ContainerSymbol
copy()[source]#

Create and return a copy of this object. Any references to the original will not be affected so the copy will not be referred to by any other object.

Returns:

A symbol object with the same properties as this symbol object.

Return type:

psyclone.psyir.symbols.Symbol

find_container_psyir(local_node=None)[source]#

Searches for the Container that this Symbol refers to. If it is not available, use the interface to import the container. If local_node is supplied then the PSyIR tree below it is searched for the container first.

Parameters:

local_node (Optional[psyclone.psyir.nodes.Node]) – root of PSyIR sub-tree to include in search for the container.

Returns:

referenced container.

Return type:

psyclone.psyir.nodes.Container

property is_intrinsic#
Returns:

whether or not this module is an intrinsic module.

Return type:

bool

property wildcard_import#
Returns:

whether or not there is a wildcard import of all public symbols from this Container.

Return type:

bool

class psyclone.psyir.symbols.DataSymbol(name, datatype, is_constant=False, initial_value=None, **kwargs)[source]#

Symbol identifying a data element. It contains information about: the datatype, the shape (in column-major order) and the interface to that symbol (i.e. Local, Global, Argument).

Parameters:
  • name (str) – name of the symbol.

  • datatype (psyclone.psyir.symbols.DataType) – data type of the symbol.

  • is_constant (bool) – whether this DataSymbol is a compile-time constant (default is False). If True then an initial_value must also be provided.

  • initial_value (Optional[item of TYPE_MAP_TO_PYTHON | psyclone.psyir.nodes.Node]) – sets a fixed known expression as an initial value for this DataSymbol. If is_constant is True then this Symbol will always have this value. If the value is None then this symbol does not have an initial value (and cannot be a constant). Otherwise it can receive PSyIR expressions or Python intrinsic types available in the TYPE_MAP_TO_PYTHON map. By default it is None.

  • kwargs (unwrapped dict.) – additional keyword arguments provided by psyclone.psyir.symbols.TypedSymbol

Inheritance

Inheritance diagram of DataSymbol
copy()[source]#

Create and return a copy of this object. Any references to the original will not be affected so the copy will not be referred to by any other object.

N.B. any other Symbols referenced in either the datatype or the initial_value properties of the original symbol will remain unchanged in the copied object. See the replace_symbols_using method.

Returns:

An object with the same properties as this symbol object.

Return type:

psyclone.psyir.symbols.DataSymbol

copy_properties(symbol_in, exclude_interface=False)[source]#

Replace all properties in this object with the properties from symbol_in, apart from the name (which is immutable) and visibility. If exclude_interface is True, the interface is also not updated.

Parameters:
  • symbol_in (DataSymbol) – the symbol from which the properties are copied.

  • exclude_interface (bool) – whether to copy the interface from the provided symbol.

Raises:

TypeError – if the argument is not the expected type.

get_all_accessed_symbols()[source]#
Return type:

set[Symbol]

Returns:

a set of all the symbols accessed inside this Symbol.

get_bounds(idx)[source]#
Returns:

the lower and upper bounds of the specified (0-indexed) array dimension.

Return type:

Tuple[psyclone.psyir.nodes.DataNode, psyclone.psyir.nodes.DataNode]

Raises:

IndexError – if the requested array dimension is invalid.

property initial_value#
Returns:

the initial value associated with this symbol (if any).

Return type:

psyclone.psyir.nodes.Node

property is_constant#
Returns:

Whether the symbol is a compile-time constant (True) or not (False).

Return type:

bool

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.DataType[source]#

Abstract base class from which all types are derived.

Inheritance

Inheritance diagram of DataType
copy()[source]#
Returns:

a copy of this datatype.

Return type:

psyclone.psyir.symbols.datatypes.DataType

get_all_accessed_symbols()[source]#
Return type:

set[Symbol]

Returns:

a set of all the symbols accessed inside this DataType.

property is_allocatable: bool | None#
Returns:

whether this DataType is allocatable. In the base class set this to be always False.

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.DataTypeSymbol(name, datatype, visibility=Visibility.PUBLIC, interface=None)[source]#

Symbol identifying a user-defined type (e.g. a derived type in Fortran).

Parameters:

Inheritance

Inheritance diagram of DataTypeSymbol
copy()[source]#

Create and return a copy of this object. Any references to the original will not be affected so the copy will not be referred to by any other object.

Returns:

A symbol object with the same properties as this symbol object.

Return type:

psyclone.psyir.symbols.TypeSymbol

copy_properties(symbol_in, exclude_interface=False)[source]#

Replace all properties in this object with the properties from symbol_in, apart from the name (which is immutable) and visibility. If exclude_interface is True, the interface is also not updated.

Parameters:
  • symbol_in (DataTypeSymbol) – the symbol from which the properties are copied.

  • exclude_interface (bool) – whether or not to exclude the interface when copying properties.

Raises:

TypeError – if the argument is not the expected type.

property datatype#
Returns:

datatype that this DataTypeSymbol represents.

Return type:

psyclone.psyir.symbols.DataType

get_all_accessed_symbols()[source]#
Return type:

set[Symbol]

Returns:

a set of all the symbols accessed inside this Symbol.

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.DefaultModuleInterface[source]#

The symbol contains data declared in a module scope without additional attributes.

Inheritance

Inheritance diagram of DefaultModuleInterface
class psyclone.psyir.symbols.GenericInterfaceSymbol(name, routines, **kwargs)[source]#

Symbol identifying a generic interface that maps to a number of different callable routines.

Unlike the parent classes, the constructor for this class cannot be supplied with the ‘is_pure’, ‘is_elemental’ or ‘datatype’ properties as these are derived from the RoutineSymbols contained within this interface.

Parameters:
  • name (str) – name of the interface.

  • routines (list[tuple[ psyclone.psyir.symbols.RoutineSymbol, bool]]) – the routines that this interface provides access to and whether or not each of them is a module procedure.

  • kwargs (unwrapped dict.) – additional keyword arguments provided by psyclone.psyir.symbols.TypedSymbol. Note that ‘is_pure’, ‘is_elemental’ and ‘datatype’ are not supported.

Raises:

ValueError – if passed the ‘is_pure’, ‘is_elemental’ or ‘datatype’ properties.

Inheritance

Inheritance diagram of GenericInterfaceSymbol
class RoutineInfo(symbol, from_container)[source]#

Holds information on a single routine member of an interface.

Parameters:
  • symbol (RoutineSymbol) – the symbol representing the routine.

  • from_container (bool) – whether or not this routine is from a Container (i.e. a ‘module procedure’ in Fortran).

property container_routines#
Returns:

those routines that are defined in a Container.

Return type:

list[psyclone.psyir.symbols.RoutineSymbol]

copy()[source]#

Create and return a copy of this object. Any references to the original will not be affected so the copy will not be referred to by any other object.

Returns:

A symbol object with the same properties as this symbol object.

Return type:

psyclone.psyir.symbols.GenericInterfaceSymbol

copy_properties(symbol_in, exclude_interface=False)[source]#

Replace all properties in this object with the properties from symbol_in, apart from the name (which is immutable) and visibility. If exclude_interface is True, the interface is also not updated.

Parameters:
  • symbol_in (RoutineSymbol) – the Symbol to copy properties from.

  • exclude_interface (bool) – whether or not to copy the interface property of the provided Symbol (default is to include it).

property datatype: DataType | DataTypeSymbol#
Returns:

the datatype of this symbol if it can be determined.

property external_routines#
Returns:

those routines that are external procedures.

Return type:

list[psyclone.psyir.symbols.RoutineSymbol]

get_all_accessed_symbols()[source]#
Return type:

set[Symbol]

Returns:

a set of all the symbols accessed inside this interface.

property is_elemental: bool | None#
Returns:

whether the routine represented by this Symbol is elemental (acts element-by-element on supplied array arguments) or None if this is not known.

property is_pure: bool | None#
Returns:

whether the routine represented by this Symbol has no side effects (guarantees that the routine always returns the same result for a given set of inputs).

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.

Before performing any replacement, the supplied symbol is specialised to a RoutineSymbol, if necessary.

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 routines#
Returns:

information on all of the routines to which this interface provides access.

Return type:

list[tuple[psyclone.psyir.symbols.RoutineSymbol, bool]]

class psyclone.psyir.symbols.ImportInterface(container_symbol, orig_name=None)[source]#

Describes the interface to a Symbol that is imported from an external PSyIR container. The symbol can be renamed on import and, if so, its original name in the Container is specified using the optional ‘orig_name’ argument.

Parameters:
  • container_symbol (psyclone.psyir.symbols.ContainerSymbol) – symbol representing the external container from which the symbol is imported.

  • orig_name (Optional[str]) – the name of the symbol in the external container before it is renamed, or None (the default) if it is not renamed.

Raises:

TypeError – if the orig_name argument is an unexpected type.

Inheritance

Inheritance diagram of ImportInterface
property container_symbol#
Returns:

symbol representing the container containing this Symbol.

Return type:

psyclone.psyir.symbols.ContainerSymbol

copy()[source]#
Returns:

a copy of this object.

Return type:

psyclone.psyir.symbol.SymbolInterface

property orig_name#
Returns:

the symbol’s original name if it is renamed on import, or None otherwise.

Return type:

Optional[str]

class psyclone.psyir.symbols.IntrinsicSymbol(name, intrinsic, **kwargs)[source]#

Symbol identifying a callable intrinsic routine.

Parameters:

# TODO #2541: Currently name and the intrinsic should match, we really # just need the name, and make all the Intrinsic singature information # live inside the IntrinsicSymbol class.

Inheritance

Inheritance diagram of IntrinsicSymbol
property intrinsic#
Returns:

the intrinsic enum describing this Symbol.

Return type:

psyclone.psyir.nodes.IntrinsicCall.Intrinsic

class psyclone.psyir.symbols.NoType[source]#

Indicates that the associated symbol has an empty type (equivalent to void in C).

Inheritance

Inheritance diagram of NoType
class psyclone.psyir.symbols.PreprocessorInterface[source]#

The symbol exists in the file through compiler macros or preprocessor directives.

Note that this is different from UnresolvedInterface because the backend will not check if is importing statements that could bring them into scope.

Inheritance

Inheritance diagram of PreprocessorInterface
class psyclone.psyir.symbols.RoutineSymbol(name, datatype=None, **kwargs)[source]#

Symbol identifying a callable routine.

Parameters:

Inheritance

Inheritance diagram of RoutineSymbol
copy()[source]#

Create and return a copy of this object. Any references to the original will not be affected so the copy will not be referred to by any other object.

Returns:

A symbol object with the same properties as this symbol object.

Return type:

psyclone.psyir.symbols.RoutineSymbol

copy_properties(symbol_in, exclude_interface=False)[source]#

Replace all properties in this object with the properties from symbol_in, apart from the name (which is immutable) and visibility.

Parameters:
  • symbol_in (RoutineSymbol) – the symbol from which the properties are copied.

  • exclude_interface (bool) – whether or not to copy the interface property of the provided Symbol (default is to include it).

Raises:

TypeError – if the argument is not the expected type.

property is_elemental#
Returns:

whether the routine represented by this Symbol is elemental (acts element-by-element on supplied array arguments) or None if this is not known.

Return type:

bool | NoneType

property is_pure#
Returns:

whether the routine represented by this Symbol has no side effects (guarantees that the routine always returns the same result for a given set of inputs).

Return type:

bool | NoneType

class psyclone.psyir.symbols.ScalarType(intrinsic, precision)[source]#

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(*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.

copy()[source]#
Returns:

a copy of self.

Return type:

psyclone.psyir.symbols.ScalarType.Precision

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.

copy()[source]#
Returns:

a copy of self.

Return type:

psyclone.psyir.symbols.DatatTypes.ScalarType

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.StaticInterface[source]#

The symbol contains data that is kept alive through the execution of the program.

Inheritance

Inheritance diagram of StaticInterface
class psyclone.psyir.symbols.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

Inheritance diagram of StructureType
class ComponentType(name, datatype, visibility, initial_value)[source]#

Represents a member of a StructureType.

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

psyclone.psyir.symbols.StructureType

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:

psyclone.psyir.symbols.StructureType.ComponentType

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.

class psyclone.psyir.symbols.Symbol(name, visibility=Visibility.PUBLIC, interface=None)[source]#

Generic Symbol item for the Symbol Table and PSyIR References. It has an immutable name label because it must always match with the key in the SymbolTable. If the symbol is private then it is only visible to those nodes that are descendants of the Node to which its containing Symbol Table belongs.

Parameters:
Raises:

TypeError – if the name is not a str.

Inheritance

Inheritance diagram of Symbol
class Visibility(*values)[source]#

Enumeration of the different visibility attributes supported in the PSyIR. If no visibility information is supplied for a Symbol then it is given the DEFAULT_VISIBILITY value.

PUBLIC: the symbol is visible in any scoping region that has access to

the SymbolTable containing it.

PRIVATE: the symbol is only visibile inside the scoping region that

contains the SymbolTable to which it belongs.

copy()[source]#

Create and return a copy of this object. Any references to the original will not be affected so the copy will not be referred to by any other object.

Returns:

A symbol object with the same properties as this symbol object.

Return type:

psyclone.psyir.symbols.Symbol

copy_properties(symbol_in, exclude_interface=False)[source]#

Replace all properties in this object with the properties from symbol_in, apart from the name (which is immutable) and visibility. If exclude_interface is True, the interface is also not updated.

Parameters:
  • symbol_in (Symbol) – the symbol from which the properties are copied.

  • exclude_interface (bool) – whether or not to copy the interface property of the provided Symbol (default is to include it).

Raises:

TypeError – if the argument is not the expected type.

find_symbol_table(node)[source]#

Searches back up the PSyIR tree for the SymbolTable that contains this Symbol.

Parameters:

node (psyclone.psyir.nodes.Node) – the PSyIR node from which to search.

Returns:

the SymbolTable containing this Symbol or None.

Return type:

psyclone.psyir.symbols.SymbolTable or NoneType

Raises:

TypeError – if the supplied node argument is not a PSyIR Node.

get_all_accessed_symbols()[source]#
Return type:

set[Symbol]

Returns:

a set of all the symbols accessed inside this Symbol.

get_external_symbol()[source]#

Looks-up and returns the Symbol referred to by this Symbol’s Import Interface.

Raises:
  • SymbolError – if the module pointed to by the symbol interface does not contain the symbol (or the symbol is not public).

  • NotImplementedError – if this symbol does not have an ImportInterface.

property interface#
Returns:

the an object describing the interface to this Symbol.

Return type:

Sub-class of psyclone.psyir.symbols.symbol.SymbolInterface

property is_argument#
Returns:

whether the Symbol has an ArgumentInterface.

Return type:

bool

property is_array#
Returns:

True if this symbol is an array and False if it is not or there is not enough symbol information to determine it.

Return type:

bool

is_array_access(index_variable=None, access_info=None)[source]#

This method detects if a variable is used as an array or not. If available, it will use the access information, i.e. how the variable is used (e.g. if it has indices somewhere, like a(i)%b). This can be incorrect in case of implicit loops (e.g. a=b+1, where a and b are arrays) where the variable usage information will not have information about indices. In this case this function will fallback to querying the symbol itself.

This can cause significant slowdown if this symbol is imported from a module, since then these modules need to be parsed. # TODO #1213: Parsing modules is not yet supported.

If a loop_variable is specified, a variable access will only be considered an array access if the specified variable is used in at least one of the indices. For example: >>> do i=1, n >>> a(j) = 2

the access to a is not considered an array if loop_variable is set to i. If loop_variable is specified, access_information must be specified.

Parameters:
  • index_variable (str) – optional loop variable that is used to to determine if an access is an array access using this variable.

  • access_info (psyclone.core.AccessSequence) – variable access information, optional.

Returns:

whether or not the variable is an array.

Rtype bool:

Raises:

InternalError – if a loop_variable is specified, but no access information is given.

property is_automatic#
Returns:

whether the Symbol has an AutomaticInterface.

Return type:

bool

property is_commonblock#
Returns:

whether the Symbol has a CommonBlockInterface.

Return type:

bool

property is_import#
Returns:

whether the Symbol has an ImportInterface.

Return type:

bool

property is_modulevar#
Returns:

whether the Symbol has a DefaultModuleInterface.

Return type:

bool

property is_static#
Returns:

whether the Symbol has a StaticInterface.

Return type:

bool

property is_unknown_interface#
Returns:

whether the Symbol has an UnknownInterface.

Return type:

bool

property is_unresolved#
Returns:

whether the Symbol has an UnresolvedInterface.

Return type:

bool

property name#
Returns:

name of the Symbol.

Return type:

str

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.

resolve_type()[source]#

Update the properties of this Symbol by using the definition imported from the external Container. If this symbol does not have an ImportInterface then there is no lookup needed and we just return this symbol.

Returns:

a symbol object with the class and type determined by examining the Container from which it is imported.

Return type:

subclass of psyclone.psyir.symbols.Symbol

Raises:

SymbolError – if the type could not be resolved.

specialise(subclass, **kwargs)[source]#

Specialise this symbol so that it becomes an instance of the class provided in the subclass argument. This allows this instance to become a subclass without any references to it becoming invalid.

Parameters:

subclass (type of sub-class of psyclone.psyir.symbols.Symbol) – the class that this symbol will become.

Raises:

TypeError – if subclass is not a sub-class of Symbol.

property visibility#
Returns:

the visibility of this Symbol.

Return type:

psyclone.psyir.symbol.Symbol.Visibility

class psyclone.psyir.symbols.SymbolTable(node=None, default_visibility=Visibility.PUBLIC)[source]#

Encapsulates the symbol table and provides methods to add new symbols and look up existing symbols. Nested scopes are supported and, by default, the add and lookup methods take any ancestor symbol tables into consideration (ones attached to nodes that are ancestors of the node that this symbol table is attached to). If the default visibility is not specified then it defaults to Symbol.Visbility.PUBLIC.

Parameters:
Raises:

TypeError – if node argument is not a Schedule or a Container.

Inheritance

Inheritance diagram of SymbolTable
add(new_symbol, tag=None)[source]#

Add a new symbol to the symbol table if the symbol name is not already in use.

Parameters:
  • new_symbol (psyclone.psyir.symbols.Symbol) – the symbol to add to the symbol table.

  • tag (str) – a tag identifier for the new symbol, by default no tag is given.

Raises:
  • InternalError – if the new_symbol argument is not a symbol.

  • KeyError – if the symbol name is already in use.

  • KeyError – if a tag is supplied and it is already in use.

append_argument(argument)[source]#

Append the given argument to the argument list and add it in the symbol table itself. If the argument is already part of the argument_list it does nothing.

Parameters:

argument (psyclone.psyir.symbols.DataSymbol) – the new argument to add to the list.

Raises:
  • InternalError – if the entries of the SymbolTable are not self-consistent.

  • TypeError – if the supplied argument is not a DataSymbol.

  • ValueError – if the supplied argument is not marked as a kernel argument.

property argument_datasymbols#
Returns:

list of symbols representing arguments.

Return type:

List[psyclone.psyir.symbols.DataSymbol]

property argument_list#

Checks that the contents of the SymbolTable are self-consistent and then returns the list of kernel arguments.

Returns:

ordered list of arguments.

Return type:

list of psyclone.psyir.symbols.DataSymbol

Raises:

InternalError – if the entries of the SymbolTable are not self-consistent.

attach(node)[source]#

Attach this symbol table to the provided scope.

Parameters:

node (py:class:psyclone.psyir.nodes.ScopingNode) – the scoped node this symbol table will attach to.

property automatic_datasymbols#
Returns:

list of symbols representing automatic variables.

Return type:

List[psyclone.psyir.symbols.DataSymbol]

check_for_clashes(other_table, symbols_to_skip=())[source]#

Checks the symbols in the supplied table against those in this table. If there is a name clash that cannot be resolved by renaming then a SymbolError is raised. Any symbols appearing in symbols_to_skip are excluded from the checks.

Parameters:
Raises:
  • TypeError – if symbols_to_skip is supplied but is not an instance of Iterable.

  • SymbolError – if there would be an unresolvable name clash when importing symbols from other_table into this table.

property containersymbols#
Returns:

a list of the ContainerSymbols present in the Symbol Table.

Return type:

List[psyclone.psyir.symbols.ContainerSymbol]

copy_external_import(imported_var, tag=None)[source]#

Copy the given imported variable (and its referenced ContainerSymbol if needed) into the SymbolTable.

Parameters:
Raises:
  • TypeError – if the given variable is not an imported variable.

  • KeyError – if the given variable name already exists in the symbol table.

property data_arguments#
Returns:

list of symbols representing kernel data arguments.

Return type:

List[psyclone.psyir.symbols.DataSymbol]

Raises:

NotImplementedError – this method is abstract.

property datasymbols#
Returns:

list of symbols representing data variables.

Return type:

List[psyclone.psyir.symbols.DataSymbol]

property datatypesymbols#
Returns:

the DataTypeSymbols present in the Symbol Table.

Return type:

List[psyclone.psyir.symbols.DataTypeSymbol]

deep_copy(new_node=None)[source]#

Create a copy of the symbol table with new instances of the top-level data structures and also new instances of the symbols contained in these data structures. Modifying a symbol attribute will not affect the equivalent named symbol in the original symbol table.

The only attribute not copied is the _node reference to the scope, since that scope can only have one symbol table associated to it.

Parameters:

new_node (psyclone.psyir.nodes.ScopingNode) – the PSyIR Node to be associated with the copied table (if different from self.node).

Returns:

a deep copy of this symbol table.

Return type:

psyclone.psyir.symbols.SymbolTable

property default_visibility#
Returns:

the default visibility of symbols in this table.

Return type:

psyclone.psyir.symbols.Symbol.Visibility

detach()[source]#

Detach this symbol table from the associated scope and return self.

Returns:

this symbol table.

Return type:

py:class:psyclone.psyir.symbols.SymbolTable

find_or_create(name, **new_symbol_args)[source]#

Lookup a symbol by its name, if it doesn’t exist create a new symbol with the given properties.

Parameters:
  • name (str) – name of the symbol to lookup or create.

  • new_symbol_args (unwrapped Dict[str, object]) – arguments to create a new symbol.

Raises:

SymbolError – if the symbol already exists but the type_symbol argument does not match the type of the symbol found.

find_or_create_tag(tag, root_name=None, **new_symbol_args)[source]#

Lookup a tag, if it doesn’t exist create a new symbol with the given tag. By default it creates a generic Symbol with the tag as the root of the symbol name. Optionally, a different root_name or any of the arguments available in the new_symbol() method can be given to refine the name and the type of the created Symbol.

Parameters:
  • tag (str) – tag identifier.

  • root_name (str) – optional name of the new symbol if it needs to be created. Otherwise it is ignored.

  • shadowing (bool) – optional logical flag indicating whether the name can be overlapping with a symbol in any of the ancestors symbol tables. Defaults to False.

  • symbol_type (type object of class (or subclasses) of psyclone.psyir.symbols.Symbol) – class type of the new symbol.

  • allow_renaming (bool) – whether to allow the newly created

  • allow_renaming – whether to allow the newly created symbol to be renamed from root_name. Defaults to True.

  • new_symbol_args (unwrapped dict[str, Any]) – arguments to create a new symbol.

Returns:

symbol associated with the given tag.

Return type:

psyclone.psyir.symbols.Symbol

Raises:

SymbolError – if the symbol already exists but the type_symbol argument does not match the type of the symbol found.

get_all_accessed_symbols()[source]#
Return type:

set[Symbol]

Returns:

a set of all the symbols accessed inside this SymbolTable, including the symbols that are not in this scope, but are used in declarations of the symbols in this scope.

get_reverse_tags_dict()[source]#

Constructs and returns a reverse of the map returned by tags_dict method.

Returns:

ordered dictionary of tags indexed by symbol.

Return type:

OrderedDict[psyclone.psyir.symbols.Symbol, str]

get_symbols(scope_limit=None)[source]#

Return symbols from this symbol table and all symbol tables associated with ancestors of the node that this symbol table is attached to. If there are name duplicates we only return the one from the closest ancestor including self. It accepts an optional scope_limit argument.

Parameters:

scope_limit (Optional[psyclone.psyir.nodes.Node]) – optional Node which limits the symbol search space to the symbol tables of the nodes within the given scope. If it is None (the default), the whole scope (all symbol tables in ancestor nodes) is searched otherwise ancestors of the scope_limit node are not searched.

Returns:

ordered dictionary of symbols indexed by symbol name.

Return type:

OrderedDict[str] = psyclone.psyir.symbols.Symbol

get_tags(scope_limit=None)[source]#

Return tags from this symbol table and all symbol tables associated with ancestors of the node that this symbol table is attached to. If there are tag duplicates we only return the one from the closest ancestor including self. It accepts an optional scope_limit argument.

Parameters:

scope_limit (psyclone.psyir.nodes.Node or NoneType) – optional Node which limits the symbol search space to the symbol tables of the nodes within the given scope. If it is None (the default), the whole scope (all symbol tables in ancestor nodes) is searched otherwise ancestors of the scope_limit node are not searched.

Returns:

ordered dictionary of symbols indexed by tag.

Return type:

OrderedDict[str] = psyclone.psyir.symbols.Symbol

property imported_symbols#
Returns:

list of symbols that have an imported interface (are associated with data that exists outside the current scope).

Return type:

List[psyclone.psyir.symbols.Symbol]

insert_argument(index, argument)[source]#

Insert a new argument at a given index in the argument list and add it in the symbol table itself.

Parameters:
  • index (int) – the position in the argument list where the new argument should be inserted.

  • argument (psyclone.psyir.symbols.DataSymbol) – the new argument to add to the list.

Raises:
  • InternalError – if the entries of the SymbolTable are not self-consistent.

  • TypeError – if the supplied index is not an integer.

  • TypeError – if the supplied argument is not a DataSymbol.

  • ValueError – if the supplied argument is not marked as a kernel argument.

is_empty()[source]#
Returns:

True if the symbol table is empty, and False otherwise.

Return type:

bool

property iteration_indices#
Returns:

list of symbols representing kernel iteration indices.

Return type:

List[psyclone.psyir.symbols.DataSymbol]

Raises:

NotImplementedError – this method is abstract.

lookup(name, visibility=None, scope_limit=None, otherwise=<object object>)[source]#

Look up a symbol in the symbol table. The lookup can be limited by visibility (e.g. just show public methods) or by scope_limit (e.g. just show symbols up to a certain scope).

Parameters:
  • name (str) – name of the symbol.

  • visibilty – the visibility or list of visibilities that the symbol must have.

  • scope_limit (Optional[psyclone.psyir.nodes.Node]) – optional Node which limits the symbol search space to the symbol tables of the nodes within the given scope. If it is None (the default), the whole scope (all symbol tables in ancestor nodes) is searched otherwise ancestors of the scope_limit node are not searched.

  • otherwise (Any) – an optional value to return if the named symbol cannot be found (rather than raising a KeyError).

Return type:

Any

Returns:

the symbol with the given name and, if specified, visibility. If no match is found and ‘otherwise’ is supplied then that value is returned.

Raises:
  • TypeError – if the name argument is not a string.

  • SymbolError – if the name exists in the Symbol Table but does not have the specified visibility.

  • TypeError – if the visibility argument has the wrong type.

  • KeyError – if the given name is not in the Symbol Table and otherwise is not supplied.

lookup_with_tag(tag, scope_limit=None)[source]#

Look up a symbol by its tag. The lookup can be limited by scope_limit (e.g. just show symbols up to a certain scope).

Parameters:
  • tag (str) – tag identifier.

  • scope_limit – optional Node which limits the symbol search space to the symbol tables of the nodes within the given scope. If it is None (the default), the whole scope (all symbol tables in ancestor nodes) is searched otherwise ancestors of the scope_limit node are not searched.

Returns:

symbol with the given tag.

Return type:

psyclone.psyir.symbols.Symbol

Raises:
  • TypeError – if the tag argument is not a string.

  • KeyError – if the given tag is not in the Symbol Table.

merge(other_table, symbols_to_skip=())[source]#

Merges all of the symbols found in other_table into this table. Symbol objects in either table may be renamed in the event of clashes.

Any Symbols appearing in symbols_to_skip are excluded.

Parameters:
Raises:
  • TypeError – if other_table is not a SymbolTable.

  • TypeError – if symbols_to_skip is not an Iterable.

  • SymbolError – if name clashes prevent the merge.

new_symbol(root_name=None, tag=None, shadowing=False, symbol_type=None, allow_renaming=True, **symbol_init_args)[source]#

Create a new symbol. Optional root_name and shadowing arguments can be given to choose the name following the rules of next_available_name(). An optional tag can also be given. By default it creates a generic symbol but a symbol_type argument and any additional initialization keyword arguments of this symbol_type can be provided to refine the created Symbol.

Parameters:
  • root_name (Optional[str]) – optional name to use when creating a new symbol name. This will be appended with an integer if the name clashes with an existing symbol name.

  • tag (str) – optional tag identifier for the new symbol.

  • shadowing (bool) – optional logical flag indicating whether the name can be overlapping with a symbol in any of the ancestors symbol tables. Defaults to False.

  • symbol_type (type object of class (or subclasses) of psyclone.psyir.symbols.Symbol) – class type of the new symbol.

  • allow_renaming (bool) – whether to allow the newly created symbol to be renamed from root_name. Defaults to True.

  • symbol_init_args (unwrapped dict[str, Any]) – arguments to create a new symbol.

Raises:
  • TypeError – if the type_symbol argument is not the type of a Symbol object class or one of its subclasses.

  • SymbolError – if the the symbol needs to be created but would need to be renamed to be created and allow_renaming is False.

next_available_name(root_name=None, shadowing=False, other_table=None)[source]#

Return a name that is not in the symbol table and therefore can be used to declare a new symbol. If the root_name argument is not supplied or if it is an empty string then the name is generated internally, otherwise the root_name is used. If required, an additional integer is appended to avoid clashes. If the shadowing argument is True (is False by default), the names in parent symbol tables will not be considered. If other_table is supplied, the new name is constructed so as not to clash with any entries in that table.

Parameters:
  • root_name (str) – optional name to use when creating a new symbol name. This will be appended with an integer if the name clashes with an existing symbol name.

  • shadowing (bool) – optional logical flag indicating whether the name can be overlapping with a symbol in any of the ancestors symbol tables. Defaults to False.

  • other_table (:py:class`psyclone.psyir.symbols.SymbolTable`) – an optional, second symbol table to take into account when constructing a new name.

Returns:

the new unique symbol name.

Return type:

str

Raises:

TypeError – if any of the arguments are of the wrong type.

property node#
Returns:

the Schedule or Container to which this symbol table belongs.

Return type:

psyclone.psyir.nodes.Schedule, psyclone.psyir.nodes.Container or NoneType

parent_symbol_table(scope_limit=None)[source]#

If this symbol table is enclosed in another scope, return the symbol table of the next outer scope. Otherwise return None.

Parameters:

scope_limit (Optional[psyclone.psyir.nodes.Node]) – optional Node which limits the symbol search space to the symbol tables of the nodes within the given scope. If it is None (the default), the whole scope (all symbol tables in ancestor nodes) is searched otherwise ancestors of the scope_limit node are not searched.

Returns:

the ‘parent’ SymbolTable of the current SymbolTable (i.e. the one that encloses this one in the PSyIR hierarchy).

Return type:

psyclone.psyir.symbols.SymbolTable or NoneType

property precision_datasymbols#
Returns:

list of all symbols used to define the precision of other symbols within the table.

Return type:

List[psyclone.psyir.symbols.DataSymbol]

remove(symbol)[source]#

Remove the supplied symbol from the Symbol Table. This has a high potential to leave broken links, so this method checks for some references to the removed symbol depending on the symbol type.

Currently, generic Symbols, ContainerSymbols and RoutineSymbols are supported. Support for removing other types of Symbol will be added as required.

TODO #898. This method should check for any references/uses of the target symbol.

Parameters:

symbol (psyclone.psyir.symbols.Symbol) – the symbol to remove.

Raises:
  • TypeError – if the supplied parameter is not of type Symbol.

  • NotImplementedError – the removal of this symbol type is not supported yet.

  • KeyError – if the supplied symbol is not in the symbol table.

  • ValueError – if the supplied container symbol is referenced by one or more DataSymbols.

  • InternalError – if the supplied symbol is not the same as the entry with that name in this SymbolTable.

rename_symbol(symbol, name, dry_run=False)[source]#

Rename the given symbol which should belong to this symbol table with the new name provided.

Parameters:
  • symbol (psyclone.psyir.symbols.Symbol) – the symbol to be renamed.

  • name (str) – the new name.

  • dry_run (bool) – if True then only the validation checks are performed.

Raises:
  • TypeError – if the symbol is not a Symbol.

  • TypeError – if the name is not a str.

  • ValueError – if the given symbol does not belong to this symbol table.

  • KeyError – if the given variable name already exists in the symbol table.

  • SymbolError – if the specified Symbol is a ContainerSymbol, is imported/unresolved or is a formal routine argument.

  • SymbolError – if the specified Symbol is accessed within a CodeBlock in the scope of this table.

  • SymbolError – if the symbol has a common block interface.

resolve_imports(container_symbols=None, symbol_target=None)[source]#

Try to resolve deferred and unknown information from imported symbols in this symbol table by searching for their definitions in referred external container. A single symbol to resolve can be specified for a more targeted import.

Parameters:
  • container_symbols (Iterable[ psyclone.psyir.symbols.ContainerSymbol]) – list of container symbols to search in order to resolve imported symbols. Defaults to all container symbols in the symbol table.

  • symbol_target (Optional[ psyclone.psyir.symbols.Symbol]) – If a symbol is given, this method will just resolve information for the given symbol. Otherwise it will resolve all possible symbols information. Defaults to None.

Raises:
  • SymbolError – if a symbol name clash is found between multiple imports or an import and a local symbol.

  • TypeError – if the provided container_symbols is not an Iterable of ContainerSymbols.

  • TypeError – if the provided symbol_target is not a Symbol.

  • KeyError – if a symbol_target has been specified but this has not been found in any of the searched containers.

property scope#
Returns:

the scope associated to this symbol table.

Return type:

psyclone.psyir.nodes.ScopingNode

shallow_copy()[source]#

Create a copy of the symbol table with new instances of the top-level data structures but keeping the same existing symbol objects. Symbols added to the new symbol table will not be added in the original but the existing objects are still the same.

Returns:

a shallow copy of this symbol table.

Return type:

psyclone.psyir.symbols.SymbolTable

specify_argument_list(argument_symbols)[source]#

Sets-up the internal list storing the order of the arguments to this kernel.

Parameters:

argument_symbols (list) – ordered list of the DataSymbols representing the kernel arguments.

Raises:

ValueError – if the new argument_list is not consistent with the existing entries in the SymbolTable.

swap(old_symbol, new_symbol)[source]#

Remove the old_symbol from the table and replace it with the new_symbol. Any references to old_symbol in the PSyIR tree associated with this table (if any) will also be updated.

Parameters:
Raises:
  • TypeError – if either old/new_symbol are not Symbols.

  • SymbolError – if old_symbol and new_symbol don’t have the same name (after normalising).

swap_symbol_properties(symbol1, symbol2)[source]#

Swaps the properties of symbol1 and symbol2 apart from the symbol name. Argument list positions are also updated appropriately.

Parameters:
Raises:
  • KeyError – if either of the supplied symbols are not in the symbol table.

  • TypeError – if the supplied arguments are not symbols, or the names of the symbols are the same in the SymbolTable instance.

property symbols#
Returns:

list of symbols.

Return type:

List[psyclone.psyir.symbols.Symbol]

property symbols_dict#
Returns:

ordered dictionary of symbols indexed by symbol name.

Return type:

OrderedDict[str] = psyclone.psyir.symbols.Symbol

symbols_imported_from(csymbol)[source]#

Examines the contents of this symbol table to see which DataSymbols (if any) are imported from the supplied ContainerSymbol (which must be present in the SymbolTable).

Parameters:

csymbol (psyclone.psyir.symbols.ContainerSymbol) – the ContainerSymbol to search for imports from.

Returns:

list of DataSymbols that are imported from the supplied ContainerSymbol. If none are found then the list is empty.

Return type:

list of psyclone.psyir.symbols.DataSymbol

Raises:
  • TypeError – if the supplied object is not a ContainerSymbol.

  • KeyError – if the supplied object is not in this SymbolTable.

property tags_dict#
Returns:

ordered dictionary of symbols indexed by tag.

Return type:

OrderedDict[str] = psyclone.psyir.symbols.Symbol

property unresolved_datasymbols#
Returns:

list of symbols representing unresolved variables.

Return type:

List[psyclone.psyir.symbols.DataSymbol]

view()[source]#
Returns:

a representation of this Symbol Table.

Return type:

str

wildcard_imports(scope_limit=None)[source]#

Searches this symbol table and then up through any parent symbol tables for ContainerSymbols that have a wildcard import.

Parameters:

scope_limit (Optional[psyclone.psyir.nodes.Node]) – optional Node which limits the search to the symbol tables of the nodes within the given scope. If it is None (the default), the whole scope (all symbol tables in ancestor nodes) is searched, otherwise ancestors of the scope_limit node are not searched.

Return type:

List[ContainerSymbol]

Returns:

the ContainerSymbols which have wildcard imports into the current scope.

class psyclone.psyir.symbols.TypedSymbol(name, datatype, **kwargs)[source]#

Abstract base class for those Symbols that have an associated datatype.

Parameters:

Inheritance

Inheritance diagram of TypedSymbol
copy()[source]#

Create and return a copy of this object. Any references to the original will not be affected so the copy will not be referred to by any other object.

Returns:

A symbol object with the same properties as this symbol object.

Return type:

psyclone.psyir.symbols.TypedSymbol

copy_properties(symbol_in, exclude_interface=False)[source]#

Replace all properties in this object with the properties from symbol_in, apart from the name (which is immutable) and visibility. If exclude_interface is True, the interface is also not updated.

Parameters:
  • symbol_in (TypedSymbol) – the symbol from which the properties are copied.

  • exclude_interface (bool) – whether or not to copy the interface property of the provided Symbol (default is to include it).

Raises:

TypeError – if the argument is not the expected type.

property datatype#
Returns:

datatype of the TypedSymbol.

Return type:

psyclone.psyir.symbols.DataType or psyclone.psyir.symbols.DataTypeSymbol

get_all_accessed_symbols()[source]#
Return type:

set[Symbol]

Returns:

a set of all the symbols accessed inside this DataType.

property is_array#
Returns:

True if this symbol is an array and False if it is not or there is not enough symbol information to determine it.

Return type:

bool

property is_scalar#
Returns:

True if this symbol is a scalar and False otherwise.

Return type:

bool

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.

resolve_type()[source]#

If the symbol has an Unresolved datatype or is an import and is of NoType (indicating a RoutineSymbol), find where it is defined (i.e. an external container) and obtain the properties of the symbol.

Return type:

TypedSymbol

Returns:

this TypedSymbol with its properties updated. This is for consistency with the equivalent method in the Symbol class which returns a new Symbol object.

property shape#
Returns:

shape of the symbol in column-major order (leftmost index is contiguous in memory). Each entry represents an array dimension. If it is ‘None’ the extent of that dimension is unknown, otherwise it holds an integer literal or a reference to an integer symbol with the extent. If it is an empty list then the symbol represents a scalar.

Return type:

List[Optional[psyclone.psyir.nodes.Literal | psyclone.psyir.nodes.Reference]]

class psyclone.psyir.symbols.UnsupportedFortranType(declaration_txt, partial_datatype=None)[source]#

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

Parameters:

Inheritance

Inheritance diagram of UnsupportedFortranType
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.UnknownInterface[source]#

We have a symbol with a declaration but PSyclone does not support its attributes.

Inheritance

Inheritance diagram of UnknownInterface
class psyclone.psyir.symbols.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

Inheritance diagram of UnsupportedType
property declaration#
Returns:

the original declaration of the symbol.

Return type:

str

class psyclone.psyir.symbols.UnresolvedInterface[source]#

We have a symbol but we don’t know where it is declared.

Inheritance

Inheritance diagram of UnresolvedInterface
class psyclone.psyir.symbols.UnresolvedType[source]#

Indicates that the type declaration has not been found yet.

Inheritance

Inheritance diagram of UnresolvedType
property is_allocatable: bool | None#
Returns:

whether this DataType is allocatable. In case of an UnresolvedType we don’t know.

Exceptions#

  • SymbolError: PSyclone-specific exception for use with errors relating to the Symbol and

exception psyclone.psyir.symbols.SymbolError(value)[source]#

PSyclone-specific exception for use with errors relating to the Symbol and SymbolTable in the PSyIR.

Parameters:

value (str) – the message associated with the error.

Inheritance

Inheritance diagram of SymbolError

Variables#

psyclone.psyir.symbols.BOOLEAN_TYPE#

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.

<psyclone.psyir.symbols.datatypes.ScalarType object at 0x7bac78efa0f0>
psyclone.psyir.symbols.CHARACTER_TYPE#

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.

<psyclone.psyir.symbols.datatypes.ScalarType object at 0x7bac78efa1b0>
psyclone.psyir.symbols.INTEGER_TYPE#

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.

<psyclone.psyir.symbols.datatypes.ScalarType object at 0x7bac78ef98e0>
psyclone.psyir.symbols.INTEGER_SINGLE_TYPE#

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.

<psyclone.psyir.symbols.datatypes.ScalarType object at 0x7bac78ef9970>
psyclone.psyir.symbols.INTEGER_DOUBLE_TYPE#

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.

<psyclone.psyir.symbols.datatypes.ScalarType object at 0x7bac78ef9850>
psyclone.psyir.symbols.INTEGER4_TYPE#

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.

<psyclone.psyir.symbols.datatypes.ScalarType object at 0x7bac78ef99d0>
psyclone.psyir.symbols.INTEGER8_TYPE#

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.

<psyclone.psyir.symbols.datatypes.ScalarType object at 0x7bac78ef9a30>
psyclone.psyir.symbols.REAL_TYPE#

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.

<psyclone.psyir.symbols.datatypes.ScalarType object at 0x7bac79007f20>
psyclone.psyir.symbols.REAL_SINGLE_TYPE#

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.

<psyclone.psyir.symbols.datatypes.ScalarType object at 0x7bac799902f0>
psyclone.psyir.symbols.REAL_DOUBLE_TYPE#

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.

<psyclone.psyir.symbols.datatypes.ScalarType object at 0x7bac796d6870>
psyclone.psyir.symbols.REAL4_TYPE#

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.

<psyclone.psyir.symbols.datatypes.ScalarType object at 0x7bac78ef99a0>
psyclone.psyir.symbols.REAL8_TYPE#

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.

<psyclone.psyir.symbols.datatypes.ScalarType object at 0x7bac78ef9a00>