Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix same subroutine names in different modules #215

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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: 1 addition & 1 deletion examples/arrays/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ LIBSRC_FPP_FILES = $(addsuffix .fpp,${LIBSRC_SOURCES})
#=======================================================================

# names (without suffix), f90 sources
LIBSRC_WRAP_SOURCES = library
LIBSRC_WRAP_SOURCES = library parameters

# file names
LIBSRC_WRAP_FILES = $(addsuffix .f90,${LIBSRC_WRAP_SOURCES})
Expand Down
3 changes: 3 additions & 0 deletions examples/arrays/parameters.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ module parameters

implicit none
private
!public :: idp, isp, do_array_stuff
public :: idp, isp

INTEGER, PARAMETER :: idp=kind(1d0)
INTEGER, PARAMETER :: isp=kind(1e0)

contains
subroutine do_array_stuff()
end subroutine do_array_stuff

end module parameters

11 changes: 6 additions & 5 deletions f90wrap/f90wrapgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,11 @@ def visit_Procedure(self, node):
call_name = node.call_name
log.info(
'F90WrapperGenerator visiting routine %s call_name %s mod_name %r' % (node.name, call_name, node.mod_name))
self.write("subroutine %(sub_name)s%(arg_names)s" %
{'sub_name': self.prefix + node.name,
'arg_names': '(' + ', '.join([arg.name for arg in node.arguments]) + ')'
if node.arguments else ''})
sub_name = self.prefix + node.name
arg_names = '(' + ', '.join([arg.name for arg in node.arguments]) + ')' if node.arguments else ''
if node.mod_name is not None:
sub_name = self.prefix + node.mod_name + '__' + node.name
self.write("subroutine %s%s" % (sub_name, arg_names))
self.indent()
self.write_uses_lines(node)
self.write("implicit none")
Expand All @@ -420,7 +421,7 @@ def visit_Procedure(self, node):
self.write_transfer_out_lines(node)
self.write_finalise_lines(node)
self.dedent()
self.write("end subroutine %(sub_name)s" % {'sub_name': self.prefix + node.name})
self.write("end subroutine %s" % (sub_name))
self.write()
return self.generic_visit(node)

Expand Down
10 changes: 10 additions & 0 deletions f90wrap/pywrapgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ def write_constructor(self, node):
for arg in args]),
f90_arg_names=', '.join(['%s=%s' % (arg.name, arg.py_value) for arg in node.arguments]))

if node.mod_name is not None:
dct['func_name'] = node.mod_name + '__' + node.name

self.write("def __init__(self, %(py_arg_names)s):" % dct)
self.indent()
self.write(format_doc_string(node))
Expand Down Expand Up @@ -361,6 +364,9 @@ def write_classmethod(self, node):
('None if %(arg_py_name)s is None else %('
'arg_py_name)s._handle') %
{'arg_py_name': arg.py_name})
if node.mod_name is not None:
dct['func_name'] = node.mod_name + '__' + node.name

call_line = '%(call)s%(mod_name)s.%(prefix)s%(func_name)s(%(f90_arg_names)s)' % dct

self.write('@classmethod')
Expand All @@ -386,6 +392,8 @@ def write_destructor(self, node):
'optional' in arg.attributes and '=None' or '')
for arg in node.arguments]),
f90_arg_names=', '.join(['%s=%s' % (arg.name, arg.py_value) for arg in node.arguments]))
if node.mod_name is not None:
dct['func_name'] = node.mod_name + '__' + node.name
self.write("def __del__(%(py_arg_names)s):" % dct)
self.indent()
self.write(format_doc_string(node))
Expand Down Expand Up @@ -414,6 +422,8 @@ def visit_Procedure(self, node):
py_arg_names=', '.join([arg.py_name + py_arg_value(arg) for arg in node.arguments]),
f90_arg_names=', '.join(['%s=%s' % (arg.name, arg.py_value) for arg in node.arguments]),
call='')
if node.mod_name is not None:
dct['func_name'] = node.mod_name + '__' + node.name

if isinstance(node, ft.Function):
dct['result'] = ', '.join([ret_val.name for ret_val in node.ret_val])
Expand Down
Loading