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

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

Inheritance

Inheritance diagram of ArrayMixin
get_full_range(pos)

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)

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()

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()

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)

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

property indices

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.

Return type:

list of psyclone.psyir.nodes.Node

Raises:

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

property is_array
Returns:

if this instance indicates an array access.

Return type:

bool

is_full_range(index)

Returns True if the specified array index is a Range Node that specifies all elements in this index. In the PSyIR this is specified by using LBOUND(name,index) for the lower bound of the range, UBOUND(name,index) for the upper bound of the range and “1” for the range step.

Parameters:

index (int) – the array index to check.

Returns:

True if the access to this array index is a range that specifies all index elements. Otherwise returns False.

Return type:

bool

is_lower_bound(index)

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)

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 (psyclone.psyir.nodes.Reference or psyclone.psyir.nodes.Member) – the node representing the access that is to be compared with this node.

Returns:

True if the array accesses match, False otherwise.

Return type:

bool

is_upper_bound(index)

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: int, array2, index2: int) bool

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 – the index indicating the location of a range node in this array.

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

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

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.