diff --git a/mkhelper.mk.in b/mkhelper.mk.in index cf37635..b66f21d 100644 --- a/mkhelper.mk.in +++ b/mkhelper.mk.in @@ -193,6 +193,7 @@ sanitize-mod-proxies: extra_f90.d: mkhelper.mk $(silent_DEPGEN):;{ \ echo 'src/program/main.o:| src/program/implicit_external.o'; \ + echo 'src/program/main.o:| src/modules/submo_test_submodule.o'; \ } >$@ # Configure delayed bundled libraries: diff --git a/mkhelper/depgen.py b/mkhelper/depgen.py index e75b3de..ae34679 100755 --- a/mkhelper/depgen.py +++ b/mkhelper/depgen.py @@ -460,6 +460,9 @@ def module_declare_callback(module): def module_use_callback(module): required_modules.add(module) + def submodule_declare_callback(module, submodule): + required_modules.add(module) + lc_debug_info = None pp_debug_info = None ftn_debug_info = None @@ -478,6 +481,7 @@ def module_use_callback(module): ftn.include_callback = include_callback ftn.module_declare_callback = module_declare_callback + ftn.submodule_declare_callback = submodule_declare_callback ftn.module_use_callback = module_use_callback def debug_callback(line, msg): diff --git a/mkhelper/depgen/fortran_parser.py b/mkhelper/depgen/fortran_parser.py index fb642a8..6c6776f 100644 --- a/mkhelper/depgen/fortran_parser.py +++ b/mkhelper/depgen/fortran_parser.py @@ -46,6 +46,8 @@ class FortranParser: _re_module_declare = re.compile( r"^\s*module\s+(?!(?:procedure|subroutine|function)\s)(\w+)", re.I ) + _re_submodule_declare = re.compile( + r"^\s*submodule\s+\(\s*(\w+)\s*\)\s+(\w+)", re.I) _re_module_use = re.compile( r"^\s*use(?:\s+|(?:\s*,\s*((?:non_)?intrinsic))?\s*::\s*)(\w+)", re.I ) @@ -73,6 +75,7 @@ def __init__( # Callbacks: self.include_callback = None self.module_declare_callback = None + self.submodule_declare_callback = None self.module_use_callback = None self.debug_callback = None @@ -124,6 +127,19 @@ def parse(self, stream): ) continue + # submodule declared + match = FortranParser._re_submodule_declare.match(line) + if match: + module_name = match.group(1).lower() + submodule_name = match.group(2).lower() + if self.submodule_declare_callback: + self.submodule_declare_callback(module_name, submodule_name) + if self.debug_callback: + self.debug_callback( + line, "declared submodule '%s' of module '%s'" % (submodule_name, module_name) + ) + continue + # module used match = FortranParser._re_module_use.match(line) if match: diff --git a/src/modules/mo_test_submodule.f90 b/src/modules/mo_test_submodule.f90 new file mode 100644 index 0000000..11ae05f --- /dev/null +++ b/src/modules/mo_test_submodule.f90 @@ -0,0 +1,18 @@ +module mo_test_submodule + implicit none + public + + interface + module subroutine print_hello_subroutine() + end subroutine print_hello_subroutine + + module function print_hello_function() + integer :: print_hello_function + end function print_hello_function + end interface + + contains + subroutine print_hello() + print *, "Hello from submodule test (parent module)." + end subroutine print_hello +end module mo_test_submodule diff --git a/src/modules/submo_test_submodule.f90 b/src/modules/submo_test_submodule.f90 new file mode 100644 index 0000000..72c8f0a --- /dev/null +++ b/src/modules/submo_test_submodule.f90 @@ -0,0 +1,14 @@ +submodule (mo_test_submodule) submo_test_submodule + implicit none + +contains + module subroutine print_hello_subroutine() + print *, "Hello from submodule test (submodule subroutine)." + end subroutine print_hello_subroutine + + module function print_hello_function() + integer :: print_hello_function + print_hello_function = 0 + print *, "Hello from submodule test (submodule function)." + end function print_hello_function +end submodule submo_test_submodule diff --git a/src/program/main.f90 b/src/program/main.f90 index 0ba1c2b..7104dfb 100644 --- a/src/program/main.f90 +++ b/src/program/main.f90 @@ -3,6 +3,10 @@ program main use mo_mkhelper, only: print_mkhelper_hello => print_hello + use mo_test_submodule, only: & + & print_test_submodule_parent => print_hello, & + & print_test_submodule_subroutine => print_hello_subroutine, & + & print_test_submodule_function => print_hello_function use mo_threaded_hello, only: print_threaded_hello => print_hello use mo_delayed, only: print_delayed_hello => print_hello use mo_cmake_based, only: print_cmake_based_hello => print_hello @@ -82,6 +86,10 @@ program main call print_mkhelper_hello() + call print_test_submodule_parent() + call print_test_submodule_subroutine() + retval = print_test_submodule_function() + print *, "Running threaded bundled library..." retval = print_threaded_hello() if (retval .ne. 0) stop 2