PSyclone icon indicating copy to clipboard operation
PSyclone copied to clipboard

UnknownFortranDataTypes

Open hiker opened this issue 1 year ago • 5 comments

I have found a few code examples in LFRic where an UnknownFortranDataType is used:

  real(kind=r_tran), allocatable, dimension(:) :: dep_pts_z_data_post
  ! UnknownFortranDataType
  INTEGER(KIND = i_def), PUBLIC, PROTECTED :: vertical_limit = emdi
  ! UnknownFortranDataType
  CHARACTER(LEN = str_long), PUBLIC :: log_scratch_space

Now some of these creates problem with the driver creation (since it can't find the symbols in the modules, so it creates them as local variables).

Two main issues:

  1. Is this a known issue, or should I verify these problems and open separate tickets?
  2. It would be really helpful if we could add a comment (like in the example above) that a data type is unkown. It just means that when you get e.g. compilation problems (e.g. because public etc declarations make no sense for variables in a program), you can immediately see where this strange declaration comes from.

I have a rather simple patch (not thoroughly tested, but it created the code above):

.../psyclone/src/psyclone$ git diff  psyir/backend/fortran.py
diff --git a/src/psyclone/psyir/backend/fortran.py b/src/psyclone/psyir/backend/fortran.py
index 3c6db99db..64abbd41a 100644
--- a/src/psyclone/psyir/backend/fortran.py
+++ b/src/psyclone/psyir/backend/fortran.py
@@ -557,7 +557,9 @@ class FortranWriter(LanguageWriter):
                     return f"{self._nindent}{decln}\n"
 
                 decln = symbol.datatype.declaration
-                return f"{self._nindent}{decln}\n"
+                return (f"{self._nindent}{self._COMMENT_PREFIX} "
+                        f"UnknownFortranDataType\n"
+                        f"{self._nindent}{decln}\n")
             # The Fortran backend only handles unknown *Fortran* declarations.
             raise VisitorError(
                 f"{type(symbol).__name__} '{symbol.name}' is of "

hiker avatar Dec 18 '23 04:12 hiker