Skip to content

Commit

Permalink
Enrich type-bound procedure calls
Browse files Browse the repository at this point in the history
  • Loading branch information
reuterbal committed Nov 16, 2023
1 parent af4546e commit 50de1be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 12 additions & 8 deletions loki/subroutine.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
parse_omni_ast, parse_ofp_ast, parse_fparser_ast, get_fparser_node,
parse_regex_source
)
from loki.logging import debug
from loki.pragma_utils import is_loki_pragma, pragmas_attached
from loki.program_unit import ProgramUnit
from loki.visitors import FindNodes, Transformer
from loki.tools import as_tuple, CaseInsensitiveDict
from loki.types import BasicType, ProcedureType, SymbolAttributes
from loki.visitors import FindNodes, Transformer


__all__ = ['Subroutine']
Expand Down Expand Up @@ -458,14 +459,16 @@ def enrich(self, definitions, recurse=False):
call._update(not_active=not_active)

symbol = call.name

routine = definitions_map.get(symbol.name)
if isinstance(routine, sym.ProcedureSymbol):
# Type-bound procedure: shortcut to bound procedure if not generic
if routine.type.bind_names and len(routine.type.bind_names) == 1:
routine = routine.type.bind_names[0].type.dtype.procedure
else:
routine = None

if not routine and symbol.parent:
# Type-bound procedure: try to obtain procedure from typedef
if (dtype := symbol.parent.type.dtype) is not BasicType.DEFERRED:
if (typedef := dtype.typedef) is not BasicType.DEFERRED:
if proc_symbol := typedef.variable_map.get(symbol.name_parts[-1]):
if (dtype := proc_symbol.type.dtype) is not BasicType.DEFERRED:
if dtype.procedure is not BasicType.DEFERRED:
routine = dtype.procedure

is_not_enriched = (
symbol.scope is None or # No scope attached
Expand All @@ -475,6 +478,7 @@ def enrich(self, definitions, recurse=False):

# Skip already enriched symbols and routines without definitions
if not (routine and is_not_enriched):
debug('Cannot enrich call to %s', symbol)
continue

# Remove existing symbol from symbol table if defined in interface block
Expand Down
2 changes: 2 additions & 0 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,8 @@ def test_scheduler_nested_type_enrichment(frontend, config):
assert isinstance(call.name.type.dtype, ProcedureType)
assert call.name.parent
assert isinstance(call.name.parent.type.dtype, DerivedType)
assert isinstance(call.routine, Subroutine)
assert isinstance(call.name.type.dtype.procedure, Subroutine)

assert isinstance(calls[0].name.parent, Scalar)
assert calls[0].name.parent.type.dtype.name == 'third_type'
Expand Down

0 comments on commit 50de1be

Please sign in to comment.