From 4d511a3ba79f031d7092d4bc483fb038996f39c3 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Fri, 17 Jul 2015 17:27:42 +0000 Subject: [PATCH] re PR fortran/52846 ([F2008] Support submodules) 2015-07-17 Paul Thomas PR fortran/52846 * decl.c (gfc_match_end): Pick out declared submodule name from the composite identifier. * gfortran.h : Add 'submodule_name' to gfc_use_list structure. * module.c (gfc_match_submodule): Define submodule_name and add static 'submodule_name'. (gfc_match_submodule): Build up submodule filenames, using '@' as a delimiter. Store the output filename in 'submodule_name'. Similarly, the submodule identifier is built using '.' as an identifier. (gfc_dump_module): If current state is COMP_SUBMODULE, write to file 'submodule_name', using SUBMODULE_EXTENSION. (gfc_use_module): Similarly, use the 'submodule_name' field in the gfc_use_list structure and SUBMODULE_EXTENSION to read the implicitly used submodule files. 2015-07-17 Paul Thomas PR fortran/52846 * lib/fortran-modules.exp (proc cleanup-submodules): New procedure. * gfortran.dg/submodule_1.f08: Change extension and clean up the submodule files. * gfortran.dg/submodule_2.f08: ditto * gfortran.dg/submodule_6.f08: ditto * gfortran.dg/submodule_7.f08: ditto * gfortran.dg/submodule_8.f08: New test * gfortran.dg/submodule_9.f08: New test From-SVN: r225957 --- gcc/testsuite/gfortran.dg/submodule_8.f08 | 44 +++++++++++++++++++++++ gcc/testsuite/gfortran.dg/submodule_9.f08 | 40 +++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/submodule_8.f08 create mode 100644 gcc/testsuite/gfortran.dg/submodule_9.f08 diff --git a/gcc/testsuite/gfortran.dg/submodule_8.f08 b/gcc/testsuite/gfortran.dg/submodule_8.f08 new file mode 100644 index 00000000000..15a38a58833 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/submodule_8.f08 @@ -0,0 +1,44 @@ +! { dg-do run } +! +! Checks that F2008:11.2.3 para 2 is correctly implemented so that +! no error results from using 'mod_s' for both a module name and +! a submodule name. The submodule is now identified as 'mod_a.mod_s' +! internally and the submodule file as 'mod_a@mod_s.smod'. +! +! Contributed by Reinhold Bader +! +module mod_a + implicit none + interface + module subroutine p() + end subroutine + end interface +end module + +submodule (mod_a) mod_s + implicit none + integer :: i=-2 +contains + module procedure p + if (i .ne. -2) then + call abort + end if + end procedure +end submodule + +module mod_s + use mod_a + implicit none + integer :: i=2 +end module + +program a_s + use mod_s + implicit none + if (i==2) then + call p() + else + call abort + end if +end program +! { dg-final { cleanup-submodules "mod_a@mod_s" } } diff --git a/gcc/testsuite/gfortran.dg/submodule_9.f08 b/gcc/testsuite/gfortran.dg/submodule_9.f08 new file mode 100644 index 00000000000..4589ebcd6d2 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/submodule_9.f08 @@ -0,0 +1,40 @@ +! { dg-do compile } +! +! Checks that the name clash between the two submodules 'mod_s' is an error. +! +! Contributed by Reinhold Bader +! +module mod_a + implicit none + interface + module subroutine p() + end subroutine + end interface +end module + +submodule (mod_a) mod_s ! { dg-error "already being used as a MODULE" } +end submodule + +submodule (mod_a:mod_s) b +end submodule + +submodule (mod_a:b) mod_s ! { dg-error "already being used as a MODULE" } + implicit none + integer :: i=-2 +contains + module procedure p + write(*,*) 'FAIL' + end procedure +end submodule + +module mod_s + use mod_a + implicit none + integer :: i=2 +end module + +program a_s + use mod_s + implicit none + call p() +end program -- 2.30.2