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
38 ! real(4), intent(in) :: x
43 ! pure function f2(x, y)
44 ! real(4), intent(in) :: x
45 ! real(4), intent(in) :: y
50 ! pure function f3(x, y, z, w)
51 ! real(4), intent(in) :: x
52 ! real(4), intent(in) :: y
53 ! real(4), intent(in) :: z
54 ! 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 ! pure function f_real4(x)
119 ! real(4), intent(in) :: x
120 ! integer(8) :: f_real4
124 ! pure function f_real8(x)
125 ! real(8), intent(in) :: x
126 ! integer(8) :: f_real8
130 ! pure function f_integer(x)
131 ! integer(4), intent(in) :: x
132 ! integer(8) :: f_integer
136 ! procedure :: f_real4
137 ! procedure :: f_real8
138 ! procedure :: 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
247 ! pure function f_real(x)
248 ! real(4), intent(in) :: x
249 ! integer(8) :: f_real
253 ! pure function f_integer(x)
254 ! integer(4), intent(in) :: x
255 ! integer(8) :: f_integer
258 ! interface operator(.foo.)
259 ! procedure :: f_real
260 ! procedure :: 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
298 ! pure function f1(x, y)
299 ! real(4), intent(in) :: x
300 ! real(4), intent(in) :: y
305 ! pure function f2(x, y)
306 ! real(4), intent(in) :: x
307 ! complex(4), intent(in) :: y
311 ! interface operator(.foo.)
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))