psyclone.psyir.nodes.array_mixin#

This module contains the implementation of the abstract ArrayMixin.

Classes#

  • ArrayMixin: Abstract class used to add functionality common to Nodes that represent

class psyclone.psyir.nodes.array_mixin.ArrayMixin[source]#

Abstract class used to add functionality common to Nodes that represent Array accesses.

Inheritance

Inheritance diagram of ArrayMixin
get_full_range(pos)[source]#

Returns a Range object that covers the full indexing of the dimension specified by pos for this ArrayMixin object.

Parameters:

pos (int) – the dimension of the array for which to lookup the upper bound.

Returns:

A Range representing the full range for the dimension of pos for this ArrayMixin.

Return type:

psyclone.psyir.nodes.Range

get_lbound_expression(pos)[source]#

Lookup the lower bound of this ArrayMixin. If we don’t have the necessary type information then a call to the LBOUND intrinsic is constructed and returned.

Parameters:

pos (int) – the dimension of the array for which to lookup the lower bound.

Returns:

the declared lower bound for the specified dimension of the array accesed or a call to the LBOUND intrinsic if it is unknown.

Return type:

psyclone.psyir.nodes.Node

get_outer_range_index()[source]#

Return the index of the child that represents the outermost array dimension with a Range construct.

Returns:

the outermost index of the children that is a Range node.

Return type:

int

Raises:

IndexError – if the array does not contain a Range node.

get_signature_and_indices()[source]#

Constructs the Signature of this array access and a list of the indices used.

Returns:

the Signature of this array reference, and a list of the indices used for each component (empty list if an access is not an array). In this base class there is no other component, so it just returns a list with a list of all indices.

Return type:

tuple(psyclone.core.Signature, list of lists of indices)

get_ubound_expression(pos)[source]#

Lookup the upper bound of this ArrayMixin. If we don’t have the necessary type information then a call to the UBOUND intrinsic is constructed and returned.

Parameters:

pos (int) – the dimension of the array for which to lookup the upper bound.

Returns:

the declared upper bound for the specified dimension of the array accesed or a call to the UBOUND intrinsic if it is unknown.

Return type:

psyclone.psyir.nodes.Node

index_of(node)[source]#

If the given node is one of the index expressions of the array, it returns the zero-indexed dimension of the array that it belongs to. Note that this is different to node.position because ArraysOfStructures have a Member child, and it is different from array.indices.index(node) because that would use the equality operator, but sibling indices may be equal and provide unexpected results.

Parameters:

node (psyclone.psyir.nodes.Node) – the node to get the index of.

Returns:

the index of the given node in the array.

Return type:

int

Raises:

ValueError – if node is not an index of the array.

property indices: Tuple[Node]#

Supports semantic-navigation by returning the list of nodes representing the index expressions for this array reference.

Returns:

the PSyIR nodes representing the array-index expressions.

Raises:

InternalError – if this node has no children or if they are not valid array-index expressions.

is_full_range(index=None)[source]#

Returns whether the array access iterates over the whole associated array. Can optionally be provided a single index to check if it iterates over a whole dimension of the array.

Parameters:

index (Optional[int]) – only check the given array index.

Return type:

bool

Returns:

True if the access to this array (or specified array dimension) iterates over all elements. Otherwise returns False.

is_lower_bound(index)[source]#

Returns whether this array access includes the lower bound of the array for the specified index. Returns True if it is and False if it is not or if it could not be determined.

Parameters:

index (int) – the array index to check.

Returns:

True if it can be determined that the lower bound of the array is accessed in this array reference for the specified index.

Return type:

bool

is_same_array(node)[source]#

Checks that the provided array is the same as this node (including the chain of parent accessor expressions if the array is part of a Structure). If the array is part of a structure then any indices on the innermost member access are ignored, e.g. A(3)%B%C(1) will match with A(3)%B%C but not with A(2)%B%C(1)

Parameters:

node (Union[psyclone.psyir.nodes.Reference, psyclone.psyir.nodes.Member]) – the node representing the access that is to be compared with this node.

Return type:

bool

Returns:

True if the array accesses match, False otherwise.

is_upper_bound(index)[source]#

Returns whether this array access includes the upper bound of the array for the specified index. Returns True if it is and False if it is not or if it could not be determined.

Parameters:

index (int) – the array index to check.

Returns:

True if it can be determined that the upper bound of the array is accessed in this array reference for the specified index.

Return type:

bool

same_range(index, array2, index2)[source]#

This method compares the range of this array node at a given index with the range of a second array at a second index. This is useful to verify if array operations are valid, e.g.: A(3,:,5) + B(:,2,2).

Note that this check supports symbolic comparisons, e.g.: A(3:4) has the same range as B(2+1:5-1), and will consider compile-time unknown dimensions as equal, e.g.: A(:) has the same range as B(:).

TODO #2485. This method has false negatives: cases when the range is the same but it can not be proved, so we return False.

TODO #2004. This method currently compares exact ranges, not just the length of them, which could be done with “(upper-lower)/step” symbolic comparisons. This is because arrayrange2loop does not account for arrays declared with different lbounds, but this could be improved.

Parameters:
  • index (int) – the index indicating the location of a range node in this array.

  • array2 – the array accessor that we want to compare it to.

  • index2 (int) – the index indicating the location of a range node in array2.

Return type:

bool

Returns:

True if the ranges are the same and False if they are not the same, or if it is not possible to determine.

Raises:

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