psyclone.psyir.nodes.structure_reference
This module contains the implementation of the StructureReference node.
Classes
StructureReference
: Node representing a reference to a component of a structure. As such
- class psyclone.psyir.nodes.structure_reference.StructureReference(symbol, **kwargs)
Node representing a reference to a component of a structure. As such it must have a single child representing the component being accessed.
- Parameters:
symbol (
psyclone.psyir.symbols.Symbol
) – the symbol being referenced.kwargs (unwrapped dict.) – additional keyword arguments provided to the super class.
Inheritance
- static create(symbol, members, parent=None, overwrite_datatype=None)
Create a StructureReference instance given a symbol and a list of components. e.g. for “field%bundle(2)%flag” this list would be [(“bundle”, [Literal(“2”, INTEGER4_TYPE)]), “flag”].
- Parameters:
symbol (
psyclone.psyir.symbols.DataSymbol
) – the symbol that this reference is to.members (list of str or 2-tuples containing (str, list of nodes describing array access)) – the component(s) of the structure that make up the full access. Any components that are array accesses must provide the name of the array and a list of DataNodes describing which part of it is accessed.
parent (sub-class of
psyclone.psyir.nodes.Node
) – the parent of this node in the PSyIR.overwrite_datatype (Optional[
psyclone.psyir.symbols.DataType
]) – the datatype for the reference, which will overwrite the value determined by analysing the corresponding user defined type. This is useful when e.g. the module that declares the structure cannot be accessed.
- Returns:
a StructureReference instance.
- Return type:
- Raises:
TypeError – if the supplied symbol is not a DataSymbol.
- property datatype
Walks down the list of members making up this reference to determine the type that it refers to. If an overwrite datatype was given to this reference, this datatype will be returned instead of determining the type.
In order to minimise code duplication, this method also supports ArrayOfStructuresReference by simply allowing for the case where the starting reference is to an Array.
- Returns:
the datatype of this reference.
- Return type:
- Raises:
NotImplementedError – if the structure reference represents an array of arrays.
- get_signature_and_indices()
- Returns:
the Signature of this structure reference, and a list of the indices used for each component (empty list if an access is not an array).
- Return type:
Tuple[
psyclone.core.Signature
, List[List[psyclone.psyir.nodes.Node
]]]
- property member
- Returns:
the member of the structure that this reference is to.
- Return type:
- Raises:
InternalError – if the first child of this node is not an instance of Member.