Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/psyclone/psyir/nodes/structure_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ def _get_cursor_shape(cursor, cursor_type):
shape = cursor_shape

if shape:
if isinstance(cursor_type, ArrayType):
return ArrayType(cursor_type.elemental_type, shape)
return ArrayType(cursor_type, shape)

# We must have a scalar.
Expand Down
22 changes: 21 additions & 1 deletion src/psyclone/tests/psyir/nodes/structure_reference_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from psyclone.core import Signature
from psyclone.errors import GenerationError, InternalError
from psyclone.psyir import symbols, nodes
from psyclone.psyir.symbols.datatypes import ArrayType, ScalarType
from psyclone.tests.utilities import check_links


Expand Down Expand Up @@ -240,7 +241,7 @@ def test_struct_ref_semantic_nav():
"found: ['broken']" in str(err.value))


def test_struct_ref_datatype():
def test_struct_ref_datatype(fortran_reader):
'''Test the datatype() method of StructureReference.'''
atype = symbols.ArrayType(symbols.REAL_TYPE, [10, 8])
rtype = symbols.StructureType.create([
Expand Down Expand Up @@ -327,6 +328,25 @@ def test_struct_ref_datatype():
create(ssym, ["nx"], overwrite_datatype=symbols.REAL_TYPE)
assert sref.datatype == symbols.REAL_TYPE

# Test that the structuretype datatype for this case does not contain
# multiply nested array types.
code = (
"subroutine test(n,m)\n"
" integer :: n, m\n"
" type :: array_type\n"
" real :: array(10,10)\n"
" end type\n"
" type(array_type) :: ref\n"
" real :: result\n"
" integer :: dimension\n"
" result = maxval(ref%array)\n"
"end subroutine\n")
psyir = fortran_reader.psyir_from_source(code)
node = psyir.walk(nodes.StructureReference)[0]
assert isinstance(node.datatype, ArrayType)
assert isinstance(node.datatype.elemental_type, ScalarType)
assert node.datatype.elemental_type.intrinsic == ScalarType.Intrinsic.REAL


def test_structure_reference_unresolved_type():
'''
Expand Down
Loading