1 ! RUN: %python %S/test_modfile.py %s %flang_fc1 -flogical-abbreviations -fxor-operator
3 ! Resolution of user-defined operators in expressions.
4 ! Test by using generic function in a specification expression that needs
5 ! to be written to a .mod file.
14 pure
integer(8) function add_ll(x
, y
)
15 logical, intent(in
) :: x
, y
17 pure
integer(8) function add_li(x
, y
)
18 logical, intent(in
) :: x
19 integer, intent(in
) :: y
21 pure
integer(8) function add_tt(x
, y
)
23 type(t
), intent(in
) :: x
, y
27 pure
integer(8) function div_tz(x
, y
)
29 type(t
), intent(in
) :: x
30 complex, intent(in
) :: y
32 pure
integer(8) function div_ct(x
, y
)
34 character(10), intent(in
) :: x
35 type(t
), intent(in
) :: y
39 subroutine s1(x
, y
, z
)
41 real :: z(x
+ y
) ! resolves to add_ll
43 subroutine s2(x
, y
, z
)
46 real :: z(x
+ y
) ! resolves to add_li
48 subroutine s3(x
, y
, z
)
51 real :: z(x
/ y
) ! resolves to div_tz
53 subroutine s4(x
, y
, z
)
56 real :: z(x
/ y
) ! resolves to div_ct
67 ! pure function add_ll(x, y)
68 ! logical(4), intent(in) :: x
69 ! logical(4), intent(in) :: y
70 ! integer(8) :: add_ll
74 ! pure function add_li(x, y)
75 ! logical(4), intent(in) :: x
76 ! integer(4), intent(in) :: y
77 ! integer(8) :: add_li
81 ! pure function add_tt(x, y)
83 ! type(t), intent(in) :: x
84 ! type(t), intent(in) :: y
85 ! integer(8) :: add_tt
89 ! pure function div_tz(x, y)
91 ! type(t), intent(in) :: x
92 ! complex(4), intent(in) :: y
93 ! integer(8) :: div_tz
97 ! pure function div_ct(x, y)
99 ! character(10_4, 1), intent(in) :: x
100 ! type(t), intent(in) :: y
101 ! integer(8) :: div_ct
104 ! interface operator(+)
105 ! procedure :: add_ll
106 ! procedure :: add_li
107 ! procedure :: add_tt
109 ! interface operator(/)
110 ! procedure :: div_tz
111 ! procedure :: div_ct
114 ! subroutine s1(x, y, z)
117 ! real(4) :: z(1_8:add_ll(x, y))
119 ! subroutine s2(x, y, z)
122 ! real(4) :: z(1_8:add_li(x, y))
124 ! subroutine s3(x, y, z)
127 ! real(4) :: z(1_8:div_tz(x, y))
129 ! subroutine s4(x, y, z)
130 ! character(10_4, 1) :: x
132 ! real(4) :: z(1_8:div_ct(x, y))
142 interface operator(.And
.)
143 pure
integer(8) function and_ti(x
, y
)
145 type(t
), intent(in
) :: x
146 integer, intent(in
) :: y
148 pure
integer(8) function and_li(x
, y
)
149 logical, intent(in
) :: x
150 integer, intent(in
) :: y
153 ! Alternative spelling of .AND.
154 interface operator(.a
.)
155 pure
integer(8) function and_tt(x
, y
)
157 type(t
), intent(in
) :: x
, y
160 interface operator(.x
.)
161 pure
integer(8) function neqv_tt(x
, y
)
163 type(t
), intent(in
) :: x
, y
166 interface operator(.neqv
.)
167 pure
integer(8) function neqv_rr(x
, y
)
168 real, intent(in
) :: x
, y
172 subroutine s1(x
, y
, z
)
175 real :: z(x
.and
. y
) ! resolves to and_ti
177 subroutine s2(x
, y
, z
)
180 real :: z(x
.a
. y
) ! resolves to and_li
182 subroutine s3(x
, y
, z
)
184 real :: z(x
.and
. y
) ! resolves to and_tt
186 subroutine s4(x
, y
, z
)
188 real :: z(x
.neqv
. y
) ! resolves to neqv_tt
190 subroutine s5(x
, y
, z
)
192 real :: z(x
.xor
. y
) ! resolves to neqv_rr
203 ! pure function and_ti(x, y)
205 ! type(t), intent(in) :: x
206 ! integer(4), intent(in) :: y
207 ! integer(8) :: and_ti
211 ! pure function and_li(x, y)
212 ! logical(4), intent(in) :: x
213 ! integer(4), intent(in) :: y
214 ! integer(8) :: and_li
218 ! pure function and_tt(x, y)
220 ! type(t), intent(in) :: x
221 ! type(t), intent(in) :: y
222 ! integer(8) :: and_tt
226 ! pure function neqv_tt(x, y)
228 ! type(t), intent(in) :: x
229 ! type(t), intent(in) :: y
230 ! integer(8) :: neqv_tt
234 ! pure function neqv_rr(x, y)
235 ! real(4), intent(in) :: x
236 ! real(4), intent(in) :: y
237 ! integer(8) :: neqv_rr
240 ! interface operator( .and.)
241 ! procedure :: and_ti
242 ! procedure :: and_li
243 ! procedure :: and_tt
245 ! interface operator(.x.)
246 ! procedure :: neqv_tt
247 ! procedure :: neqv_rr
250 ! subroutine s1(x, y, z)
253 ! real(4) :: z(1_8:and_ti(x, y))
255 ! subroutine s2(x, y, z)
258 ! real(4) :: z(1_8:and_li(x, y))
260 ! subroutine s3(x, y, z)
263 ! real(4) :: z(1_8:and_tt(x, y))
265 ! subroutine s4(x, y, z)
268 ! real(4) :: z(1_8:neqv_tt(x, y))
270 ! subroutine s5(x, y, z)
273 ! real(4) :: z(1_8:neqv_rr(x, y))
277 ! Relational operators
283 interface operator(<>)
284 pure
integer(8) function ne_it(x
, y
)
286 integer, intent(in
) :: x
287 type(t
), intent(in
) :: y
290 interface operator(/=)
291 pure
integer(8) function ne_tt(x
, y
)
293 type(t
), intent(in
) :: x
, y
296 interface operator(.ne
.)
297 pure
integer(8) function ne_ci(x
, y
)
298 character(len
=*), intent(in
) :: x
299 integer, intent(in
) :: y
303 subroutine s1(x
, y
, z
)
306 real :: z(x
/= y
) ! resolves to ne_it
308 subroutine s2(x
, y
, z
)
311 real :: z(x
.ne
. y
) ! resolves to ne_tt
313 subroutine s3(x
, y
, z
)
314 character(len
=*) :: x
316 real :: z(x
<> y
) ! resolves to ne_ci
327 ! pure function ne_it(x, y)
329 ! integer(4), intent(in) :: x
330 ! type(t), intent(in) :: y
331 ! integer(8) :: ne_it
335 ! pure function ne_tt(x, y)
337 ! type(t), intent(in) :: x
338 ! type(t), intent(in) :: y
339 ! integer(8) :: ne_tt
343 ! pure function ne_ci(x, y)
344 ! character(*, 1), intent(in) :: x
345 ! integer(4), intent(in) :: y
346 ! integer(8) :: ne_ci
349 ! interface operator(<>)
355 ! subroutine s1(x, y, z)
358 ! real(4) :: z(1_8:ne_it(x, y))
360 ! subroutine s2(x, y, z)
363 ! real(4) :: z(1_8:ne_tt(x, y))
365 ! subroutine s3(x, y, z)
366 ! character(*, 1) :: x
368 ! real(4) :: z(1_8:ne_ci(x, y))
378 interface operator(//)
379 pure
integer(8) function concat_12(x
, y
)
380 character(len
=*,kind
=1), intent(in
) :: x
381 character(len
=*,kind
=2), intent(in
) :: y
383 pure
integer(8) function concat_int_real(x
, y
)
384 integer, intent(in
) :: x
385 real, intent(in
) :: y
389 subroutine s1(x
, y
, z
)
390 character(len
=*,kind
=1) :: x
391 character(len
=*,kind
=2) :: y
392 real :: z(x
// y
) ! resolves to concat_12
394 subroutine s2(x
, y
, z
)
397 real :: z(x
// y
) ! resolves to concat_int_real
407 ! pure function concat_12(x, y)
408 ! character(*, 1), intent(in) :: x
409 ! character(*, 2), intent(in) :: y
410 ! integer(8) :: concat_12
414 ! pure function concat_int_real(x, y)
415 ! integer(4), intent(in) :: x
416 ! real(4), intent(in) :: y
417 ! integer(8) :: concat_int_real
420 ! interface operator(//)
421 ! procedure :: concat_12
422 ! procedure :: concat_int_real
425 ! subroutine s1(x, y, z)
426 ! character(*, 1) :: x
427 ! character(*, 2) :: y
428 ! real(4) :: z(1_8:concat_12(x, y))
430 ! subroutine s2(x, y, z)
433 ! real(4) :: z(1_8:concat_int_real(x, y))
441 interface operator(+)
442 pure
integer(8) function plus_l(x
)
443 logical, intent(in
) :: x
446 interface operator(-)
447 pure
integer(8) function minus_t(x
)
449 type(t
), intent(in
) :: x
452 interface operator(.not
.)
453 pure
integer(8) function not_t(x
)
455 type(t
), intent(in
) :: x
457 pure
integer(8) function not_real(x
)
458 real, intent(in
) :: x
464 real :: y(+x
) ! resolves_to plus_l
468 real :: y(-x
) ! resolves_to minus_t
472 real :: y(.not
. x
) ! resolves to not_t
475 real :: y(.not
. x
) ! resolves to not_real
484 ! pure function plus_l(x)
485 ! logical(4), intent(in) :: x
486 ! integer(8) :: plus_l
490 ! pure function minus_t(x)
492 ! type(t), intent(in) :: x
493 ! integer(8) :: minus_t
497 ! pure function not_t(x)
499 ! type(t), intent(in) :: x
500 ! integer(8) :: not_t
504 ! pure function not_real(x)
505 ! real(4), intent(in) :: x
506 ! integer(8) :: not_real
509 ! interface operator(+)
510 ! procedure :: plus_l
512 ! interface operator(-)
513 ! procedure :: minus_t
515 ! interface operator( .not.)
517 ! procedure :: not_real
520 ! subroutine s1(x, y)
522 ! real(4) :: y(1_8:plus_l(x))
524 ! subroutine s2(x, y)
526 ! real(4) :: y(1_8:minus_t(x))
528 ! subroutine s3(x, y)
530 ! real(4) :: y(1_8:not_t(x))
532 ! subroutine s4(x, y)
534 ! real(4) :: y(1_8:not_real(x))
538 ! Resolved based on shape
540 interface operator(+)
541 pure
integer(8) function add(x
, y
)
542 real, intent(in
) :: x(:, :)
543 real, intent(in
) :: y(:, :, :)
547 subroutine s1(n
, x
, y
, z
, a
, b
)
552 real :: a(size(x
+y
)) ! intrinsic +
553 real :: b(y
+z
) ! resolves to add
560 ! pure function add(x, y)
561 ! real(4), intent(in) :: x(:, :)
562 ! real(4), intent(in) :: y(:, :, :)
566 ! interface operator(+)
570 ! subroutine s1(n, x, y, z, a, b)
573 ! real(4) :: y(1_8:4_8, 1_8:n)
574 ! real(4) :: z(1_8:2_8, 1_8:2_8, 1_8:2_8)
575 ! real(4) :: a(1_8:int(int(4_8*size(y,dim=2,kind=8),kind=4),kind=8))
576 ! real(4) :: b(1_8:add(y, z))
580 ! Parameterized derived type
586 interface operator(+)
587 pure
integer(8) function f1(x
, y
)
589 type(t(4)), intent(in
) :: x
, y
591 pure
integer(8) function f2(x
, y
)
593 type(t(8)), intent(in
) :: x
, y
597 subroutine s1(x
, y
, z
)
599 real :: z(x
+ y
) ! resolves to f1
601 subroutine s2(x
, y
, z
)
603 real :: z(x
+ y
) ! resolves to f2
610 ! integer(4), kind :: k
611 ! real(int(int(k,kind=4),kind=8))::a
614 ! pure function f1(x, y)
616 ! type(t(k=4_4)), intent(in) :: x
617 ! type(t(k=4_4)), intent(in) :: y
622 ! pure function f2(x, y)
624 ! type(t(k=8_4)), intent(in) :: x
625 ! type(t(k=8_4)), intent(in) :: y
629 ! interface operator(+)
634 ! subroutine s1(x, y, z)
635 ! type(t(k=4_4)) :: x
636 ! type(t(k=4_4)) :: y
637 ! real(4) :: z(1_8:f1(x, y))
639 ! subroutine s2(x, y, z)
640 ! type(t(k=8_4)) :: x
641 ! type(t(k=8_4)) :: y
642 ! real(4) :: z(1_8:f2(x, y))