Skip to content

Commit

Permalink
#2642 Implement extends, procedure in derived types, class keyw…
Browse files Browse the repository at this point in the history
…ord.
  • Loading branch information
JulienRemy committed Jul 2, 2024
1 parent 349bd2b commit f3bb061
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
10 changes: 8 additions & 2 deletions src/psyclone/domain/gocean/kernel/psyir.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from psyclone.psyir.frontend.fortran import FortranReader
from psyclone.psyir.backend.fortran import FortranWriter
from psyclone.psyir.nodes import Container
from psyclone.psyir.symbols import DataTypeSymbol, UnsupportedFortranType,\
from psyclone.psyir.symbols import DataTypeSymbol, UnsupportedFortranType, \
StructureType


Expand Down Expand Up @@ -224,8 +224,14 @@ def create_from_psyir(symbol):

datatype = symbol.datatype

# TODO #2643: This is a temporary solution using FortranWriter
# to allow the current metadata extraction to work with StructureType,
# instead of relying on UnsupportedFortranType.
# This will be removed when the metadata is extracted from the PSyIR
# itself.
if isinstance(datatype, StructureType):
type_declaration = FortranWriter().gen_typedecl(symbol).replace(", public", "").replace(", private", "")
type_declaration = FortranWriter().gen_typedecl(symbol)
type_declaration.replace(", public", "").replace(", private", "")
return GOceanKernelMetadata.create_from_fortran_string(
type_declaration)

Expand Down
10 changes: 8 additions & 2 deletions src/psyclone/domain/lfric/kernel/lfric_kernel_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
from psyclone.parse.utils import ParseError
from psyclone.psyir.frontend.fortran import FortranReader
from psyclone.psyir.backend.fortran import FortranWriter
from psyclone.psyir.symbols import DataTypeSymbol, UnsupportedFortranType,\
from psyclone.psyir.symbols import DataTypeSymbol, UnsupportedFortranType, \
StructureType

# pylint: disable=too-many-lines
Expand Down Expand Up @@ -700,8 +700,14 @@ def create_from_psyir(symbol):

datatype = symbol.datatype

# TODO #2643: This is a temporary solution using FortranWriter
# to allow the current metadata extraction to work with StructureType,
# instead of relying on UnsupportedFortranType.
# This will be removed when the metadata is extracted from the PSyIR
# itself.
if isinstance(datatype, StructureType):
type_declaration = FortranWriter().gen_typedecl(symbol).replace(", public", "").replace(", private", "")
type_declaration = FortranWriter().gen_typedecl(symbol)
type_declaration.replace(", public", "").replace(", private", "")
return LFRicKernelMetadata.create_from_fortran_string(
type_declaration)

Expand Down
6 changes: 3 additions & 3 deletions src/psyclone/psyir/frontend/fparser2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3522,10 +3522,10 @@ def _add_target_attribute(var_name, table):
(e.g. a routine argument or an imported symbol).
'''
#pylint: disable=import-outside-toplevel
# pylint: disable=import-outside-toplevel
# Import here to avoid circular dependencies.
from psyclone.psyir.backend.fortran import FortranWriter

try:
symbol = table.lookup(var_name)
except KeyError as err:
Expand All @@ -3538,7 +3538,7 @@ def _add_target_attribute(var_name, table):
f"be resolved and a DataSymbol")

datatype = symbol.datatype
# If this is of UnsupportedFortranType,
# If this is of UnsupportedFortranType,
# create Fortran text for the supplied datatype from the
# supplied UnsupportedFortranType text, then parse this into an
# fparser2 tree and store the fparser2 representation of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ def test_get_procedure_name_error(fortran_reader):
"testkern_type")
datatype = datatype_symbol.datatype
metadata = LFRicKernelMetadata()
#reader = FortranStringReader(datatype.declaration)
# reader = FortranStringReader(datatype.declaration)
assert isinstance(datatype, StructureType)
type_declaration = FortranWriter().gen_typedecl(datatype_symbol)
reader = FortranStringReader(type_declaration)
Expand All @@ -1176,7 +1176,7 @@ def test_get_procedure_name_error(fortran_reader):
"testkern_type")
datatype = datatype_symbol.datatype
metadata = LFRicKernelMetadata()
#reader = FortranStringReader(datatype.declaration)
# reader = FortranStringReader(datatype.declaration)
assert isinstance(datatype, StructureType)
type_declaration = FortranWriter().gen_typedecl(datatype_symbol)
reader = FortranStringReader(type_declaration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ def test_generate_lfric_adjoint_harness(fortran_reader, fortran_writer):
" inner2 = inner2 + ascalar * ascalar_input\n"
" inner2 = inner2 + field_field_input_inner_prod\n" in gen)


@pytest.mark.xfail(reason="func_type and gh_quadrature_xyoz are neither "
"declared nor imported in the TL code.")
def test_generate_lfric_adj_test_quadrature(fortran_reader):
Expand Down
5 changes: 3 additions & 2 deletions src/psyclone/tests/psyir/symbols/datatype_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def test_structure_type():
assert not flag.initial_value
assert isinstance(flag, StructureType.ComponentType)
stype.add_component("flag2", INTEGER_TYPE, Symbol.Visibility.PUBLIC,
Literal("1", INTEGER_TYPE))
Literal("1", INTEGER_TYPE))
flag2 = stype.lookup_component("flag2")
assert isinstance(flag2, StructureType.ComponentType)
assert flag2.initial_value.value == "1"
Expand All @@ -714,7 +714,8 @@ def test_structure_type():
assert ("visibility of a component of a StructureType must be an instance "
"of 'Symbol.Visibility' but got 'str'" in str(err.value))
with pytest.raises(TypeError) as err:
stype.add_component("hello", INTEGER_TYPE, Symbol.Visibility.PUBLIC, "Hello")
stype.add_component("hello", INTEGER_TYPE, Symbol.Visibility.PUBLIC,
"Hello")
assert ("The initial value of a component of a StructureType must be "
"None or an instance of 'DataNode', but got 'str'."
in str(err.value))
Expand Down

0 comments on commit f3bb061

Please sign in to comment.