PSyclone
PSyclone copied to clipboard
USE with intrinsic attribute and rename is not handled
Code such as:
use, intrinsic :: ieee_arithmetic, only: isnan => ieee_is_nan
becomes
use :: ieee_arithmetic, only isnan
Intrinsic
is stored in decl.items[0]
in fparser.py::_process_use_stmts
. It doesn't look like we do anything with this information right now.
We could pull this value out (not sure if it has any other value other than intrinsic
?) and then it would need to be stored somewhere in the ContainerSymbol
(or maybe FortranModuleInterface
?) I think and then output at output time.
My idea for a solution would be something like:
In fparser.py
- grab the intrinsic attribute (or anything else it can be? You'd have to check the standard there)
if decl.items[0] is not None:
intrinsic_attr = str(decl.items[0])
else:
intrinsic_attr = None
and add it to the ContainerSymbol:
container = ContainerSymbol(mod_name,
visibility=mod_visibility,
intrinsic=intrinsic_attr)
In containersymbol.py
we'd need to store this somewhere, e.g. in _process_arguments
:
if "intrinsic" not in kwargs or kwargs["intrinsic"] is None:
kwargs["interface"]._intrinsic = None
else:
kwargs["interface"]._intrinsic = kwargs["intrinsic"]
if"intrinsic" in kwargs:
kwargs.pop("intrinsic")
I'm not totally sure about this, the ContainerSymbol
structure is a bit confusing to me at first look.
Then it would need to be output in backend/fortran.py
, e.g.
if isinstance(symbol.interface, ContainerSymbol) and symbol.interface._intrinsic:
intrinsic_label = dsym._intrinsic + " "
else:
intrinsic_label = ""
# Finally construct the use statements for this Container (module)
if not only_list and not symbol.wildcard_import:
# We have a "use xxx, only:" - i.e. an empty only list
return f"{self._nindent}use {intrinsic_label}{symbol.name}, only :\n"
if only_list and not symbol.wildcard_import:
return f"{self._nindent}use {intrinsic_label}{symbol.name}, only : " + \
", ".join(sorted(only_list)) + "\n"
return f"{self._nindent}use {intrinsic_label}{symbol.name}\n"
This didn't quite work for me - similar to #2206 I think I'm losing the _intrinsic
attribute somewhere in the deep copy, but I couldn't work out where as I didn't understand the structure to begin with. I also don't know if this is the cleanest solution but I had a look as I was hoping i could fit it in with the other PR, but it doesn't look to be so straightforward :(.