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
66 ! interface operator(+)
72 ! pure function add_ll(x, y)
73 ! logical(4), intent(in) :: x
74 ! logical(4), intent(in) :: y
75 ! integer(8) :: add_ll
79 ! pure function add_li(x, y)
80 ! logical(4), intent(in) :: x
81 ! integer(4), intent(in) :: y
82 ! integer(8) :: add_li
86 ! pure function add_tt(x, y)
88 ! type(t), intent(in) :: x
89 ! type(t), intent(in) :: y
90 ! integer(8) :: add_tt
93 ! interface operator(/)
98 ! pure function div_tz(x, y)
100 ! type(t), intent(in) :: x
101 ! complex(4), intent(in) :: y
102 ! integer(8) :: div_tz
106 ! pure function div_ct(x, y)
108 ! character(10_4, 1), intent(in) :: x
109 ! type(t), intent(in) :: y
110 ! integer(8) :: 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
202 ! interface operator( .and.)
203 ! procedure :: and_ti
204 ! procedure :: and_li
205 ! procedure :: and_tt
208 ! pure function and_ti(x, y)
210 ! type(t), intent(in) :: x
211 ! integer(4), intent(in) :: y
212 ! integer(8) :: and_ti
216 ! pure function and_li(x, y)
217 ! logical(4), intent(in) :: x
218 ! integer(4), intent(in) :: y
219 ! integer(8) :: and_li
223 ! pure function and_tt(x, y)
225 ! type(t), intent(in) :: x
226 ! type(t), intent(in) :: y
227 ! integer(8) :: and_tt
230 ! interface operator(.x.)
231 ! procedure :: neqv_tt
232 ! procedure :: neqv_rr
235 ! pure function neqv_tt(x, y)
237 ! type(t), intent(in) :: x
238 ! type(t), intent(in) :: y
239 ! integer(8) :: neqv_tt
243 ! pure function neqv_rr(x, y)
244 ! real(4), intent(in) :: x
245 ! real(4), intent(in) :: y
246 ! integer(8) :: 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
326 ! interface operator(<>)
332 ! pure function ne_it(x, y)
334 ! integer(4), intent(in) :: x
335 ! type(t), intent(in) :: y
336 ! integer(8) :: ne_it
340 ! pure function ne_tt(x, y)
342 ! type(t), intent(in) :: x
343 ! type(t), intent(in) :: y
344 ! integer(8) :: ne_tt
348 ! pure function ne_ci(x, y)
349 ! character(*, 1), intent(in) :: x
350 ! integer(4), intent(in) :: y
351 ! integer(8) :: ne_ci
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
406 ! interface operator(//)
407 ! procedure :: concat_12
408 ! procedure :: concat_int_real
411 ! pure function concat_12(x, y)
412 ! character(*, 1), intent(in) :: x
413 ! character(*, 2), intent(in) :: y
414 ! integer(8) :: concat_12
418 ! pure function concat_int_real(x, y)
419 ! integer(4), intent(in) :: x
420 ! real(4), intent(in) :: y
421 ! integer(8) :: 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
483 ! interface operator(+)
484 ! procedure :: plus_l
487 ! pure function plus_l(x)
488 ! logical(4), intent(in) :: x
489 ! integer(8) :: plus_l
492 ! interface operator(-)
493 ! procedure :: minus_t
496 ! pure function minus_t(x)
498 ! type(t), intent(in) :: x
499 ! integer(8) :: minus_t
502 ! interface operator( .not.)
504 ! procedure :: not_real
507 ! pure function not_t(x)
509 ! type(t), intent(in) :: x
510 ! integer(8) :: not_t
514 ! pure function not_real(x)
515 ! real(4), intent(in) :: x
516 ! integer(8) :: 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
559 ! interface operator(+)
563 ! pure function add(x, y)
564 ! real(4), intent(in) :: x(:, :)
565 ! real(4), intent(in) :: y(:, :, :)
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
613 ! interface operator(+)
618 ! pure function f1(x, y)
620 ! type(t(k=4_4)), intent(in) :: x
621 ! type(t(k=4_4)), intent(in) :: y
626 ! pure function f2(x, y)
628 ! type(t(k=8_4)), intent(in) :: x
629 ! type(t(k=8_4)), intent(in) :: y
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))