661 lines · plain
1! RUN: %python %S/test_modfile.py %s %flang_fc12! Check modfile generation for generic interfaces3module m14 interface foo5 real function s1(x,y)6 real, intent(in) :: x7 logical, intent(in) :: y8 end function9 complex function s2(x,y)10 complex, intent(in) :: x11 logical, intent(in) :: y12 end function13 end interface14 generic :: operator ( + ) => s1, s215 interface operator ( /= )16 logical function f1(x, y)17 real, intent(in) :: x18 logical, intent(in) :: y19 end function20 end interface21 interface22 logical function f2(x, y)23 complex, intent(in) :: x24 logical, intent(in) :: y25 end function26 logical function f3(x, y)27 integer, intent(in) :: x28 logical, intent(in) :: y29 end function30 end interface31 generic :: operator(.ne.) => f232 generic :: operator(<>) => f333 private :: operator( .ne. )34 interface bar35 procedure :: s136 procedure :: s237 procedure :: s338 procedure :: s439 end interface40 interface operator( .bar.)41 procedure :: s142 procedure :: s243 procedure :: s344 procedure :: s445 end interface46contains47 logical function s3(x,y)48 logical, intent(in) :: x,y49 end function50 integer function s4(x,y)51 integer, intent(in) :: x,y52 end function53end54!Expect: m1.mod55!module m156! interface57! function s1(x,y)58! real(4),intent(in)::x59! logical(4),intent(in)::y60! real(4)::s161! end62! end interface63! interface64! function s2(x,y)65! complex(4),intent(in)::x66! logical(4),intent(in)::y67! complex(4)::s268! end69! end interface70! interface71! function f1(x,y)72! real(4),intent(in)::x73! logical(4),intent(in)::y74! logical(4)::f175! end76! end interface77! interface78! function f2(x,y)79! complex(4),intent(in)::x80! logical(4),intent(in)::y81! logical(4)::f282! end83! end interface84! interface85! function f3(x,y)86! integer(4),intent(in)::x87! logical(4),intent(in)::y88! logical(4)::f389! end90! end interface91! interface foo92! procedure::s193! procedure::s294! end interface95! interface operator(+)96! procedure::s197! procedure::s298! end interface99! interface operator(/=)100! procedure::f1101! procedure::f2102! procedure::f3103! end interface104! private::operator(/=)105! interface bar106! procedure::s1107! procedure::s2108! procedure::s3109! procedure::s4110! end interface111! interface operator(.bar.)112! procedure::s1113! procedure::s2114! procedure::s3115! procedure::s4116! end interface117!contains118! function s3(x,y)119! logical(4),intent(in)::x120! logical(4),intent(in)::y121! logical(4)::s3122! end123! function s4(x,y)124! integer(4),intent(in)::x125! integer(4),intent(in)::y126! integer(4)::s4127! end128!end129 130module m1b131 use m1132end133!Expect: m1b.mod134!module m1b135! use m1,only:foo136! use m1,only:s1137! use m1,only:s2138! use m1,only:operator(+)139! use m1,only:f1140! use m1,only:f2141! use m1,only:f3142! use m1,only:bar143! use m1,only:operator(.bar.)144! use m1,only:s3145! use m1,only:s4146!end147 148module m1c149 use m1, only: myfoo => foo150 use m1, only: operator(.bar.)151 use m1, only: operator(.mybar.) => operator(.bar.)152 use m1, only: operator(+)153end154!Expect: m1c.mod155!module m1c156! use m1,only:myfoo=>foo157! use m1,only:operator(.bar.)158! use m1,only:operator(.mybar.)=>operator(.bar.)159! use m1,only:operator(+)160!end161 162module m2163 interface foo164 procedure foo165 end interface166contains167 complex function foo()168 foo = 1.0169 end170end171!Expect: m2.mod172!module m2173! interface foo174! procedure::foo175! end interface176!contains177! function foo()178! complex(4)::foo179! end180!end181 182module m2b183 type :: foo184 real :: x185 end type186 interface foo187 end interface188 private :: bar189 interface bar190 end interface191end192!Expect: m2b.mod193!module m2b194! type::foo195! real(4)::x196! end type197! interface foo198! end interface199! interface bar200! end interface201! private::bar202!end203 204! Test interface nested inside another interface205module m3206 interface g207 subroutine s1(f)208 interface209 real function f(x)210 interface211 subroutine x()212 end subroutine213 end interface214 end function215 end interface216 end subroutine217 end interface218end219!Expect: m3.mod220!module m3221! interface222! subroutine s1(f)223! interface224! function f(x)225! interface226! subroutine x()227! end228! end interface229! real(4)::f230! end231! end interface232! end233! end interface234! interface g235! procedure::s1236! end interface237!end238 239module m4240 interface foo241 integer function foo()242 end function243 integer function f(x)244 end function245 end interface246end247subroutine s4248 use m4249 i = foo()250end251!Expect: m4.mod252!module m4253! interface254! function foo()255! integer(4)::foo256! end257! end interface258! interface259! function f(x)260! real(4)::x261! integer(4)::f262! end263! end interface264! interface foo265! procedure::foo266! procedure::f267! end interface268!end269 270! Compile contents of m4.mod and verify it gets the same thing again.271module m5272 interface foo273 procedure::foo274 procedure::f275 end interface276 interface277 function foo()278 integer(4)::foo279 end280 end interface281 interface282 function f(x)283 integer(4)::f284 real(4)::x285 end286 end interface287end288!Expect: m5.mod289!module m5290! interface291! function foo()292! integer(4)::foo293! end294! end interface295! interface296! function f(x)297! real(4)::x298! integer(4)::f299! end300! end interface301! interface foo302! procedure::foo303! procedure::f304! end interface305!end306 307module m6a308 interface operator(<)309 logical function lt(x, y)310 logical, intent(in) :: x, y311 end function312 end interface313end314!Expect: m6a.mod315!module m6a316! interface317! function lt(x,y)318! logical(4),intent(in)::x319! logical(4),intent(in)::y320! logical(4)::lt321! end322! end interface323! interface operator(<)324! procedure::lt325! end interface326!end327 328module m6b329 use m6a, only: operator(.lt.)330end331!Expect: m6b.mod332!module m6b333! use m6a,only:operator(.lt.)334!end335 336module m7a337 interface g_integer338 module procedure s339 end interface340 private :: s341contains342 subroutine s(x)343 integer :: x344 end345end346!Expect: m7a.mod347!module m7a348! private :: s349! interface g_integer350! procedure :: s351! end interface352!contains353! subroutine s(x)354! integer(4) :: x355! end356!end357 358module m7b359 interface g_real360 module procedure s361 end interface362 private :: s363contains364 subroutine s(x)365 real :: x366 end subroutine367end368!Expect: m7b.mod369!module m7b370! private :: s371! interface g_real372! procedure :: s373! end interface374!contains375! subroutine s(x)376! real(4) :: x377! end378!end379 380module m7c381 use m7a, only: g => g_integer382 use m7b, only: g => g_real383 interface g384 module procedure s385 end interface386 private :: s387contains388 subroutine s(x)389 complex :: x390 end subroutine391 subroutine test()392 real :: x393 integer :: y394 complex :: z395 call g(x)396 call g(y)397 call g(z)398 end399end400!Expect: m7c.mod401!module m7c402! use m7a, only: g => g_integer403! use m7b, only: g => g_real404! private :: s405! interface g406! procedure :: s407! end interface408!contains409! subroutine s(x)410! complex(4) :: x411! end412! subroutine test()413! end414!end415 416! Test m8 is like m7 but without renaming.417 418module m8a419 interface g420 module procedure s421 end interface422 private :: s423contains424 subroutine s(x)425 integer :: x426 end427end428!Expect: m8a.mod429!module m8a430! private :: s431! interface g432! procedure :: s433! end interface434!contains435! subroutine s(x)436! integer(4) :: x437! end438!end439 440module m8b441 interface g442 module procedure s443 end interface444 private :: s445contains446 subroutine s(x)447 real :: x448 end subroutine449end450!Expect: m8b.mod451!module m8b452! private :: s453! interface g454! procedure :: s455! end interface456!contains457! subroutine s(x)458! real(4) :: x459! end460!end461 462module m8c463 use m8a464 use m8b465 interface g466 module procedure s467 end interface468 private :: s469contains470 subroutine s(x)471 complex :: x472 end subroutine473 subroutine test()474 real :: x475 integer :: y476 complex :: z477 call g(x)478 call g(y)479 call g(z)480 end481end482!Expect: m8c.mod483!module m8c484! use m8a, only: g485! use m8b, only: g486! private :: s487! interface g488! procedure :: s489! end interface490!contains491! subroutine s(x)492! complex(4) :: x493! end494! subroutine test()495! end496!end497 498! Merging a use-associated generic with a local generic499 500module m9a501 interface g502 module procedure s503 end interface504 private :: s505contains506 subroutine s(x)507 integer :: x508 end509end510!Expect: m9a.mod511!module m9a512! private :: s513! interface g514! procedure :: s515! end interface516!contains517! subroutine s(x)518! integer(4) :: x519! end520!end521 522module m9b523 use m9a524 interface g525 module procedure s526 end interface527 private :: s528contains529 subroutine s(x)530 real :: x531 end532 subroutine test()533 call g(1)534 call g(1.0)535 end536end537!Expect: m9b.mod538!module m9b539! use m9a,only:g540! private::s541! interface g542! procedure::s543! end interface544!contains545! subroutine s(x)546! real(4)::x547! end548! subroutine test()549! end550!end551 552! Verify that equivalent names are used when generic operators are merged553 554module m10a555 interface operator(.ne.)556 end interface557end558!Expect: m10a.mod559!module m10a560! interface operator(.ne.)561! end interface562!end563 564module m10b565 interface operator(<>)566 end interface567end568!Expect: m10b.mod569!module m10b570! interface operator(<>)571! end interface572!end573 574module m10c575 use m10a576 use m10b577 interface operator(/=)578 end interface579end580!Expect: m10c.mod581!module m10c582! use m10a,only:operator(.ne.)583! use m10b,only:operator(.ne.)584! interface operator(.ne.)585! end interface586!end587 588module m10d589 use m10a590 use m10c591 private :: operator(<>)592end593!Expect: m10d.mod594!module m10d595! use m10a,only:operator(.ne.)596! use m10c,only:operator(.ne.)597! interface operator(.ne.)598! end interface599! private::operator(.ne.)600!end601 602module m11a603contains604 subroutine s1()605 end606end607!Expect: m11a.mod608!module m11a609!contains610! subroutine s1()611! end612!end613 614module m11b615 use m11a616 interface g617 module procedure s1618 end interface619end620!Expect: m11b.mod621!module m11b622! use m11a,only:s1623! interface g624! procedure::s1625! end interface626!end627 628module m12629 interface generic630 module procedure specific631 end interface632 interface633 module subroutine s(a1,a2)634 character(*) a1635 character(generic(a1)) a2636 end637 end interface638 contains639 pure integer function specific(x)640 character(*), intent(in) :: x641 specific = len(x)642 end643end644!Expect: m12.mod645!module m12646! interface647! module subroutine s(a1,a2)648! character(*,1)::a1649! character(specific(a1),1)::a2650! end651! end interface652! interface generic653! procedure::specific654! end interface655!contains656! pure function specific(x)657! character(*,1),intent(in)::x658! integer(4)::specific659! end660!end661