Skip to content

Commit

Permalink
Handle several interfaces referencing same procedures
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel committed Nov 18, 2024
1 parent ed3bd8f commit 41bc6db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
7 changes: 7 additions & 0 deletions f90wrap/f90wrapgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def __init__(
self.kind_map = kind_map
self.types = types
self.default_to_inout = default_to_inout
self.routines = []

def visit_Root(self, node):
"""
Expand Down Expand Up @@ -465,6 +466,12 @@ def visit_Procedure(self, node):
call_name = node.orig_name
if hasattr(node, "call_name"):
call_name = node.call_name

if node.name in self.routines:
return self.generic_visit(node)

self.routines.append(node.name)

log.info(
"F90WrapperGenerator visiting routine %s call_name %s mod_name %r"
% (node.name, call_name, node.mod_name)
Expand Down
32 changes: 8 additions & 24 deletions f90wrap/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,22 +1131,6 @@ def visit_Module(self, node):
# original resolution logic was implemented when resolution occurred in
# the parser. Technically this is quadratic complexity, but the number
# of interface prototypes is generally small...
def inject_procedure(interfaces, procedure):
for iface in interfaces:
for i, p in enumerate(iface.procedures):
if procedure.name == p.name:
log.debug("Procedure %s moved to interface %s", procedure.name, iface.name)
iface.procedures[i] = procedure # Replace the prototype
return True
log.debug(f"Procedure %s is not used in any interface", procedure.name)
return False

unused = []
for mp in node.procedures:
if not inject_procedure(node.interfaces, mp):
unused.append(mp)
node.procedures = unused
return node

# Attempt 1:
# Insert procedures at first reference. Elegant and equivalent to Option 0,
Expand All @@ -1163,14 +1147,14 @@ def inject_procedure(interfaces, procedure):
# fortran code gen b/c identically named wrappers will be generated for
# each interface, causing a name clash. This could be fixed in code gen
# by adding the interface name to the wrapper function name.
#procedure_map = { p.name:p for p in node.procedures }
#unused = set(procedure_map.keys())
#for int in node.interfaces:
# iprocs = { p.name for p in int.procedures }
# unused -= iprocs # Can't eagerly remove b/c may be in multiple interfaces
# int.procedures = [ procedure_map[p] for p in iprocs ]
#node.procedures = [ procedure_map[p] for p in unused ]
#return node
procedure_map = { p.name:p for p in node.procedures }
unused = set(procedure_map.keys())
for int in node.interfaces:
iprocs = { p.name for p in int.procedures }
unused -= iprocs # Can't eagerly remove b/c may be in multiple interfaces
int.procedures = [ procedure_map[p] for p in iprocs ]
node.procedures = [ procedure_map[p] for p in unused ]
return node


class ResolveBindingPrototypes(ft.FortranTransformer):
Expand Down

0 comments on commit 41bc6db

Please sign in to comment.