325 lines · plain
1! RUN: %python %S/test_modfile.py %s %flang_fc12! Resolution of generic names in expressions.3! Test by using generic function in a specification expression that needs4! to be written to a .mod file.5 6! Resolve based on number of arguments7module m18 interface f9 pure integer(8) function f1(x)10 real, intent(in) :: x11 end12 pure integer(8) function f2(x, y)13 real, intent(in) :: x, y14 end15 pure integer(8) function f3(x, y, z, w)16 real, intent(in) :: x, y, z, w17 optional :: w18 end19 end interface20contains21 subroutine s1(x, z)22 real :: z(f(x)) ! resolves to f123 end24 subroutine s2(x, y, z)25 real :: z(f(x, y)) ! resolves to f226 end27 subroutine s3(x, y, z, w)28 real :: w(f(x, y, z)) ! resolves to f329 end30 subroutine s4(x, y, z, w, u)31 real :: u(f(x, y, z, w)) ! resolves to f332 end33end34!Expect: m1.mod35!module m136! interface37! pure function f1(x)38! real(4), intent(in) :: x39! integer(8) :: f140! end41! end interface42! interface43! pure function f2(x, y)44! real(4), intent(in) :: x45! real(4), intent(in) :: y46! integer(8) :: f247! end48! end interface49! interface50! pure function f3(x, y, z, w)51! real(4), intent(in) :: x52! real(4), intent(in) :: y53! real(4), intent(in) :: z54! real(4), intent(in), optional :: w55! integer(8) :: f356! end57! end interface58! interface f59! procedure :: f160! procedure :: f261! procedure :: f362! end interface63!contains64! subroutine s1(x, z)65! real(4) :: x66! real(4) :: z(1_8:f1(x))67! end68! subroutine s2(x, y, z)69! real(4) :: x70! real(4) :: y71! real(4) :: z(1_8:f2(x, y))72! end73! subroutine s3(x, y, z, w)74! real(4) :: x75! real(4) :: y76! real(4) :: z77! real(4) :: w(1_8:f3(x, y, z))78! end79! subroutine s4(x, y, z, w, u)80! real(4) :: x81! real(4) :: y82! real(4) :: z83! real(4) :: w84! real(4) :: u(1_8:f3(x, y, z, w))85! end86!end87 88! Resolve based on type or kind89module m290 interface f91 pure integer(8) function f_real4(x)92 real(4), intent(in) :: x93 end94 pure integer(8) function f_real8(x)95 real(8), intent(in) :: x96 end97 pure integer(8) function f_integer(x)98 integer, intent(in) :: x99 end100 end interface101contains102 subroutine s1(x, y)103 real(4) :: x104 real :: y(f(x)) ! resolves to f_real4105 end106 subroutine s2(x, y)107 real(8) :: x108 real :: y(f(x)) ! resolves to f_real8109 end110 subroutine s3(x, y)111 integer :: x112 real :: y(f(x)) ! resolves to f_integer113 end114end115!Expect: m2.mod116!module m2117! interface118! pure function f_real4(x)119! real(4), intent(in) :: x120! integer(8) :: f_real4121! end122! end interface123! interface124! pure function f_real8(x)125! real(8), intent(in) :: x126! integer(8) :: f_real8127! end128! end interface129! interface130! pure function f_integer(x)131! integer(4), intent(in) :: x132! integer(8) :: f_integer133! end134! end interface135! interface f136! procedure :: f_real4137! procedure :: f_real8138! procedure :: f_integer139! end interface140!contains141! subroutine s1(x, y)142! real(4) :: x143! real(4) :: y(1_8:f_real4(x))144! end145! subroutine s2(x, y)146! real(8) :: x147! real(4) :: y(1_8:f_real8(x))148! end149! subroutine s3(x, y)150! integer(4) :: x151! real(4) :: y(1_8:f_integer(x))152! end153!end154 155! Resolve based on rank156module m3a157 interface f158 procedure :: f_elem159 procedure :: f_vector160 end interface161contains162 pure integer(8) elemental function f_elem(x) result(result)163 real, intent(in) :: x164 result = 1_8165 end166 pure integer(8) function f_vector(x) result(result)167 real, intent(in) :: x(:)168 result = 2_8169 end170end171!Expect: m3a.mod172!module m3a173! interface f174! procedure :: f_elem175! procedure :: f_vector176! end interface177!contains178! elemental pure function f_elem(x) result(result)179! real(4), intent(in) :: x180! integer(8) :: result181! end182! pure function f_vector(x) result(result)183! real(4), intent(in) :: x(:)184! integer(8) :: result185! end186!end187 188module m3b189use m3a190contains191 subroutine s1(x, y)192 real :: x193 real :: y(f(x)) ! resolves to f_elem194 end195 subroutine s2(x, y)196 real :: x(10)197 real :: y(f(x)) ! resolves to f_vector (preferred over elemental one)198 end199 subroutine s3(x, y)200 real :: x(10, 10)201 real :: y(ubound(f(x), 1)) ! resolves to f_elem202 end203end204!Expect: m3b.mod205!module m3b206! use m3a, only: f207! use m3a, only: f_elem208! use m3a, only: f_vector209!contains210! subroutine s1(x, y)211! real(4) :: x212! real(4) :: y(1_8:f_elem(x))213! end214! subroutine s2(x, y)215! real(4) :: x(1_8:10_8)216! real(4) :: y(1_8:f_vector(x))217! end218! subroutine s3(x, y)219! real(4) :: x(1_8:10_8, 1_8:10_8)220! real(4) :: y(1_8:10_8)221! end222!end223 224! Resolve defined unary operator based on type225module m4226 interface operator(.foo.)227 pure integer(8) function f_real(x)228 real, intent(in) :: x229 end230 pure integer(8) function f_integer(x)231 integer, intent(in) :: x232 end233 end interface234contains235 subroutine s1(x, y)236 real :: x237 real :: y(.foo. x) ! resolves to f_real238 end239 subroutine s2(x, y)240 integer :: x241 real :: y(.foo. x) ! resolves to f_integer242 end243end244!Expect: m4.mod245!module m4246! interface247! pure function f_real(x)248! real(4), intent(in) :: x249! integer(8) :: f_real250! end251! end interface252! interface253! pure function f_integer(x)254! integer(4), intent(in) :: x255! integer(8) :: f_integer256! end257! end interface258! interface operator(.foo.)259! procedure :: f_real260! procedure :: f_integer261! end interface262!contains263! subroutine s1(x, y)264! real(4) :: x265! real(4) :: y(1_8:f_real(x))266! end267! subroutine s2(x, y)268! integer(4) :: x269! real(4) :: y(1_8:f_integer(x))270! end271!end272 273! Resolve defined binary operator based on type274module m5275 interface operator(.foo.)276 pure integer(8) function f1(x, y)277 real, intent(in) :: x278 real, intent(in) :: y279 end280 pure integer(8) function f2(x, y)281 real, intent(in) :: x282 complex, intent(in) :: y283 end284 end interface285contains286 subroutine s1(x, y)287 complex :: x288 real :: y(1.0 .foo. x) ! resolves to f2289 end290 subroutine s2(x, y)291 real :: x292 real :: y(1.0 .foo. x) ! resolves to f1293 end294end295!Expect: m5.mod296!module m5297! interface298! pure function f1(x, y)299! real(4), intent(in) :: x300! real(4), intent(in) :: y301! integer(8) :: f1302! end303! end interface304! interface305! pure function f2(x, y)306! real(4), intent(in) :: x307! complex(4), intent(in) :: y308! integer(8) :: f2309! end310! end interface311! interface operator(.foo.)312! procedure :: f1313! procedure :: f2314! end interface315!contains316! subroutine s1(x, y)317! complex(4) :: x318! real(4) :: y(1_8:f2(1._4, x))319! end320! subroutine s2(x, y)321! real(4) :: x322! real(4) :: y(1_8:f1(1._4, x))323! end324!end325