1 ! RUN: %python %S/test_modfile.py %s %flang_fc1
2 ! Resolution of generic names in expressions.
3 ! Test by using generic function in a specification expression that needs
4 ! to be written to a .mod file.
6 ! Resolve based on number of arguments
9 pure
integer(8) function f1(x
)
12 pure
integer(8) function f2(x
, y
)
13 real, intent(in
) :: x
, y
15 pure
integer(8) function f3(x
, y
, z
, w
)
16 real, intent(in
) :: x
, y
, z
, w
22 real :: z(f(x
)) ! resolves to f1
24 subroutine s2(x
, y
, z
)
25 real :: z(f(x
, y
)) ! resolves to f2
27 subroutine s3(x
, y
, z
, w
)
28 real :: w(f(x
, y
, z
)) ! resolves to f3
30 subroutine s4(x
, y
, z
, w
, u
)
31 real :: u(f(x
, y
, z
, w
)) ! resolves to f3
43 ! real(4), intent(in) :: x
48 ! pure function f2(x, y)
49 ! real(4), intent(in) :: x
50 ! real(4), intent(in) :: y
55 ! pure function f3(x, y, z, w)
56 ! real(4), intent(in) :: x
57 ! real(4), intent(in) :: y
58 ! real(4), intent(in) :: z
59 ! real(4), intent(in), optional :: w
66 ! real(4) :: z(1_8:f1(x))
68 ! subroutine s2(x, y, z)
71 ! real(4) :: z(1_8:f2(x, y))
73 ! subroutine s3(x, y, z, w)
77 ! real(4) :: w(1_8:f3(x, y, z))
79 ! subroutine s4(x, y, z, w, u)
84 ! real(4) :: u(1_8:f3(x, y, z, w))
88 ! Resolve based on type or kind
91 pure
integer(8) function f_real4(x
)
92 real(4), intent(in
) :: x
94 pure
integer(8) function f_real8(x
)
95 real(8), intent(in
) :: x
97 pure
integer(8) function f_integer(x
)
98 integer, intent(in
) :: x
104 real :: y(f(x
)) ! resolves to f_real4
108 real :: y(f(x
)) ! resolves to f_real8
112 real :: y(f(x
)) ! resolves to f_integer
118 ! procedure :: f_real4
119 ! procedure :: f_real8
120 ! procedure :: f_integer
123 ! pure function f_real4(x)
124 ! real(4), intent(in) :: x
125 ! integer(8) :: f_real4
129 ! pure function f_real8(x)
130 ! real(8), intent(in) :: x
131 ! integer(8) :: f_real8
135 ! pure function f_integer(x)
136 ! integer(4), intent(in) :: x
137 ! integer(8) :: f_integer
141 ! subroutine s1(x, y)
143 ! real(4) :: y(1_8:f_real4(x))
145 ! subroutine s2(x, y)
147 ! real(4) :: y(1_8:f_real8(x))
149 ! subroutine s3(x, y)
151 ! real(4) :: y(1_8:f_integer(x))
155 ! Resolve based on rank
159 procedure
:: f_vector
162 pure
integer(8) elemental
function f_elem(x
) result(result
)
163 real, intent(in
) :: x
166 pure
integer(8) function f_vector(x
) result(result
)
167 real, intent(in
) :: x(:)
174 ! procedure :: f_elem
175 ! procedure :: f_vector
178 ! elemental pure function f_elem(x) result(result)
179 ! real(4), intent(in) :: x
180 ! integer(8) :: result
182 ! pure function f_vector(x) result(result)
183 ! real(4), intent(in) :: x(:)
184 ! integer(8) :: result
193 real :: y(f(x
)) ! resolves to f_elem
197 real :: y(f(x
)) ! resolves to f_vector (preferred over elemental one)
201 real :: y(ubound(f(x
), 1)) ! resolves to f_elem
207 ! use m3a, only: f_elem
208 ! use m3a, only: f_vector
210 ! subroutine s1(x, y)
212 ! real(4) :: y(1_8:f_elem(x))
214 ! subroutine s2(x, y)
215 ! real(4) :: x(1_8:10_8)
216 ! real(4) :: y(1_8:f_vector(x))
218 ! subroutine s3(x, y)
219 ! real(4) :: x(1_8:10_8, 1_8:10_8)
220 ! real(4) :: y(1_8:10_8)
224 ! Resolve defined unary operator based on type
226 interface operator(.foo
.)
227 pure
integer(8) function f_real(x
)
228 real, intent(in
) :: x
230 pure
integer(8) function f_integer(x
)
231 integer, intent(in
) :: x
237 real :: y(.foo
. x
) ! resolves to f_real
241 real :: y(.foo
. x
) ! resolves to f_integer
246 ! interface operator(.foo.)
247 ! procedure :: f_real
248 ! procedure :: f_integer
251 ! pure function f_real(x)
252 ! real(4), intent(in) :: x
253 ! integer(8) :: f_real
257 ! pure function f_integer(x)
258 ! integer(4), intent(in) :: x
259 ! integer(8) :: f_integer
263 ! subroutine s1(x, y)
265 ! real(4) :: y(1_8:f_real(x))
267 ! subroutine s2(x, y)
269 ! real(4) :: y(1_8:f_integer(x))
273 ! Resolve defined binary operator based on type
275 interface operator(.foo
.)
276 pure
integer(8) function f1(x
, y
)
277 real, intent(in
) :: x
278 real, intent(in
) :: y
280 pure
integer(8) function f2(x
, y
)
281 real, intent(in
) :: x
282 complex, intent(in
) :: y
288 real :: y(1.0 .foo
. x
) ! resolves to f2
292 real :: y(1.0 .foo
. x
) ! resolves to f1
297 ! interface operator(.foo.)
302 ! pure function f1(x, y)
303 ! real(4), intent(in) :: x
304 ! real(4), intent(in) :: y
309 ! pure function f2(x, y)
310 ! real(4), intent(in) :: x
311 ! complex(4), intent(in) :: y
316 ! subroutine s1(x, y)
318 ! real(4) :: y(1_8:f2(1._4, x))
320 ! subroutine s2(x, y)
322 ! real(4) :: y(1_8:f1(1._4, x))