modfile33.f90
13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
! RUN: %S/test_modfile.sh %s %t %f18 -flogical-abbreviations -fxor-operator
! Resolution of user-defined operators in expressions.
! Test by using generic function in a specification expression that needs
! to be written to a .mod file.
! Numeric operators
module m1
type :: t
sequence
logical :: x
end type
interface operator(+)
pure integer(8) function add_ll(x, y)
logical, intent(in) :: x, y
end
pure integer(8) function add_li(x, y)
logical, intent(in) :: x
integer, intent(in) :: y
end
pure integer(8) function add_tt(x, y)
import :: t
type(t), intent(in) :: x, y
end
end interface
interface operator(/)
pure integer(8) function div_tz(x, y)
import :: t
type(t), intent(in) :: x
complex, intent(in) :: y
end
pure integer(8) function div_ct(x, y)
import :: t
character(10), intent(in) :: x
type(t), intent(in) :: y
end
end interface
contains
subroutine s1(x, y, z)
logical :: x, y
real :: z(x + y) ! resolves to add_ll
end
subroutine s2(x, y, z)
logical :: x
integer :: y
real :: z(x + y) ! resolves to add_li
end
subroutine s3(x, y, z)
type(t) :: x
complex :: y
real :: z(x / y) ! resolves to div_tz
end
subroutine s4(x, y, z)
character(10) :: x
type(t) :: y
real :: z(x / y) ! resolves to div_ct
end
end
!Expect: m1.mod
!module m1
! type :: t
! sequence
! logical(4) :: x
! end type
! interface operator(+)
! procedure :: add_ll
! procedure :: add_li
! procedure :: add_tt
! end interface
! interface
! pure function add_ll(x, y)
! logical(4), intent(in) :: x
! logical(4), intent(in) :: y
! integer(8) :: add_ll
! end
! end interface
! interface
! pure function add_li(x, y)
! logical(4), intent(in) :: x
! integer(4), intent(in) :: y
! integer(8) :: add_li
! end
! end interface
! interface
! pure function add_tt(x, y)
! import :: t
! type(t), intent(in) :: x
! type(t), intent(in) :: y
! integer(8) :: add_tt
! end
! end interface
! interface operator(/)
! procedure :: div_tz
! procedure :: div_ct
! end interface
! interface
! pure function div_tz(x, y)
! import :: t
! type(t), intent(in) :: x
! complex(4), intent(in) :: y
! integer(8) :: div_tz
! end
! end interface
! interface
! pure function div_ct(x, y)
! import :: t
! character(10_4, 1), intent(in) :: x
! type(t), intent(in) :: y
! integer(8) :: div_ct
! end
! end interface
!contains
! subroutine s1(x, y, z)
! logical(4) :: x
! logical(4) :: y
! real(4) :: z(1_8:add_ll(x, y))
! end
! subroutine s2(x, y, z)
! logical(4) :: x
! integer(4) :: y
! real(4) :: z(1_8:add_li(x, y))
! end
! subroutine s3(x, y, z)
! type(t) :: x
! complex(4) :: y
! real(4) :: z(1_8:div_tz(x, y))
! end
! subroutine s4(x, y, z)
! character(10_4, 1) :: x
! type(t) :: y
! real(4) :: z(1_8:div_ct(x, y))
! end
!end
! Logical operators
module m2
type :: t
sequence
logical :: x
end type
interface operator(.And.)
pure integer(8) function and_ti(x, y)
import :: t
type(t), intent(in) :: x
integer, intent(in) :: y
end
pure integer(8) function and_li(x, y)
logical, intent(in) :: x
integer, intent(in) :: y
end
end interface
! Alternative spelling of .AND.
interface operator(.a.)
pure integer(8) function and_tt(x, y)
import :: t
type(t), intent(in) :: x, y
end
end interface
interface operator(.x.)
pure integer(8) function neqv_tt(x, y)
import :: t
type(t), intent(in) :: x, y
end
end interface
interface operator(.neqv.)
pure integer(8) function neqv_rr(x, y)
real, intent(in) :: x, y
end
end interface
contains
subroutine s1(x, y, z)
type(t) :: x
integer :: y
real :: z(x .and. y) ! resolves to and_ti
end
subroutine s2(x, y, z)
logical :: x
integer :: y
real :: z(x .a. y) ! resolves to and_li
end
subroutine s3(x, y, z)
type(t) :: x, y
real :: z(x .and. y) ! resolves to and_tt
end
subroutine s4(x, y, z)
type(t) :: x, y
real :: z(x .neqv. y) ! resolves to neqv_tt
end
subroutine s5(x, y, z)
real :: x, y
real :: z(x .xor. y) ! resolves to neqv_rr
end
end
!Expect: m2.mod
!module m2
! type :: t
! sequence
! logical(4) :: x
! end type
! interface operator( .and.)
! procedure :: and_ti
! procedure :: and_li
! procedure :: and_tt
! end interface
! interface
! pure function and_ti(x, y)
! import :: t
! type(t), intent(in) :: x
! integer(4), intent(in) :: y
! integer(8) :: and_ti
! end
! end interface
! interface
! pure function and_li(x, y)
! logical(4), intent(in) :: x
! integer(4), intent(in) :: y
! integer(8) :: and_li
! end
! end interface
! interface
! pure function and_tt(x, y)
! import :: t
! type(t), intent(in) :: x
! type(t), intent(in) :: y
! integer(8) :: and_tt
! end
! end interface
! interface operator(.x.)
! procedure :: neqv_tt
! procedure :: neqv_rr
! end interface
! interface
! pure function neqv_tt(x, y)
! import :: t
! type(t), intent(in) :: x
! type(t), intent(in) :: y
! integer(8) :: neqv_tt
! end
! end interface
! interface
! pure function neqv_rr(x, y)
! real(4), intent(in) :: x
! real(4), intent(in) :: y
! integer(8) :: neqv_rr
! end
! end interface
!contains
! subroutine s1(x, y, z)
! type(t) :: x
! integer(4) :: y
! real(4) :: z(1_8:and_ti(x, y))
! end
! subroutine s2(x, y, z)
! logical(4) :: x
! integer(4) :: y
! real(4) :: z(1_8:and_li(x, y))
! end
! subroutine s3(x, y, z)
! type(t) :: x
! type(t) :: y
! real(4) :: z(1_8:and_tt(x, y))
! end
! subroutine s4(x, y, z)
! type(t) :: x
! type(t) :: y
! real(4) :: z(1_8:neqv_tt(x, y))
! end
! subroutine s5(x, y, z)
! real(4) :: x
! real(4) :: y
! real(4) :: z(1_8:neqv_rr(x, y))
! end
!end
! Relational operators
module m3
type :: t
sequence
logical :: x
end type
interface operator(<>)
pure integer(8) function ne_it(x, y)
import :: t
integer, intent(in) :: x
type(t), intent(in) :: y
end
end interface
interface operator(/=)
pure integer(8) function ne_tt(x, y)
import :: t
type(t), intent(in) :: x, y
end
end interface
interface operator(.ne.)
pure integer(8) function ne_ci(x, y)
character(len=*), intent(in) :: x
integer, intent(in) :: y
end
end interface
contains
subroutine s1(x, y, z)
integer :: x
type(t) :: y
real :: z(x /= y) ! resolves to ne_it
end
subroutine s2(x, y, z)
type(t) :: x
type(t) :: y
real :: z(x .ne. y) ! resolves to ne_tt
end
subroutine s3(x, y, z)
character(len=*) :: x
integer :: y
real :: z(x <> y) ! resolves to ne_ci
end
end
!Expect: m3.mod
!module m3
! type :: t
! sequence
! logical(4) :: x
! end type
! interface operator(<>)
! procedure :: ne_it
! procedure :: ne_tt
! procedure :: ne_ci
! end interface
! interface
! pure function ne_it(x, y)
! import :: t
! integer(4), intent(in) :: x
! type(t), intent(in) :: y
! integer(8) :: ne_it
! end
! end interface
! interface
! pure function ne_tt(x, y)
! import :: t
! type(t), intent(in) :: x
! type(t), intent(in) :: y
! integer(8) :: ne_tt
! end
! end interface
! interface
! pure function ne_ci(x, y)
! character(*, 1), intent(in) :: x
! integer(4), intent(in) :: y
! integer(8) :: ne_ci
! end
! end interface
!contains
! subroutine s1(x, y, z)
! integer(4) :: x
! type(t) :: y
! real(4) :: z(1_8:ne_it(x, y))
! end
! subroutine s2(x, y, z)
! type(t) :: x
! type(t) :: y
! real(4) :: z(1_8:ne_tt(x, y))
! end
! subroutine s3(x, y, z)
! character(*, 1) :: x
! integer(4) :: y
! real(4) :: z(1_8:ne_ci(x, y))
! end
!end
! Concatenation
module m4
type :: t
sequence
logical :: x
end type
interface operator(//)
pure integer(8) function concat_12(x, y)
character(len=*,kind=1), intent(in) :: x
character(len=*,kind=2), intent(in) :: y
end
pure integer(8) function concat_int_real(x, y)
integer, intent(in) :: x
real, intent(in) :: y
end
end interface
contains
subroutine s1(x, y, z)
character(len=*,kind=1) :: x
character(len=*,kind=2) :: y
real :: z(x // y) ! resolves to concat_12
end
subroutine s2(x, y, z)
integer :: x
real :: y
real :: z(x // y) ! resolves to concat_int_real
end
end
!Expect: m4.mod
!module m4
! type :: t
! sequence
! logical(4) :: x
! end type
! interface operator(//)
! procedure :: concat_12
! procedure :: concat_int_real
! end interface
! interface
! pure function concat_12(x, y)
! character(*, 1), intent(in) :: x
! character(*, 2), intent(in) :: y
! integer(8) :: concat_12
! end
! end interface
! interface
! pure function concat_int_real(x, y)
! integer(4), intent(in) :: x
! real(4), intent(in) :: y
! integer(8) :: concat_int_real
! end
! end interface
!contains
! subroutine s1(x, y, z)
! character(*, 1) :: x
! character(*, 2) :: y
! real(4) :: z(1_8:concat_12(x, y))
! end
! subroutine s2(x, y, z)
! integer(4) :: x
! real(4) :: y
! real(4) :: z(1_8:concat_int_real(x, y))
! end
!end
! Unary operators
module m5
type :: t
end type
interface operator(+)
pure integer(8) function plus_l(x)
logical, intent(in) :: x
end
end interface
interface operator(-)
pure integer(8) function minus_t(x)
import :: t
type(t), intent(in) :: x
end
end interface
interface operator(.not.)
pure integer(8) function not_t(x)
import :: t
type(t), intent(in) :: x
end
pure integer(8) function not_real(x)
real, intent(in) :: x
end
end interface
contains
subroutine s1(x, y)
logical :: x
real :: y(+x) ! resolves_to plus_l
end
subroutine s2(x, y)
type(t) :: x
real :: y(-x) ! resolves_to minus_t
end
subroutine s3(x, y)
type(t) :: x
real :: y(.not. x) ! resolves to not_t
end
subroutine s4(x, y)
real :: y(.not. x) ! resolves to not_real
end
end
!Expect: m5.mod
!module m5
! type :: t
! end type
! interface operator(+)
! procedure :: plus_l
! end interface
! interface
! pure function plus_l(x)
! logical(4), intent(in) :: x
! integer(8) :: plus_l
! end
! end interface
! interface operator(-)
! procedure :: minus_t
! end interface
! interface
! pure function minus_t(x)
! import :: t
! type(t), intent(in) :: x
! integer(8) :: minus_t
! end
! end interface
! interface operator( .not.)
! procedure :: not_t
! procedure :: not_real
! end interface
! interface
! pure function not_t(x)
! import :: t
! type(t), intent(in) :: x
! integer(8) :: not_t
! end
! end interface
! interface
! pure function not_real(x)
! real(4), intent(in) :: x
! integer(8) :: not_real
! end
! end interface
!contains
! subroutine s1(x, y)
! logical(4) :: x
! real(4) :: y(1_8:plus_l(x))
! end
! subroutine s2(x, y)
! type(t) :: x
! real(4) :: y(1_8:minus_t(x))
! end
! subroutine s3(x, y)
! type(t) :: x
! real(4) :: y(1_8:not_t(x))
! end
! subroutine s4(x, y)
! real(4) :: x
! real(4) :: y(1_8:not_real(x))
! end
!end
! Resolved based on shape
module m6
interface operator(+)
pure integer(8) function add(x, y)
real, intent(in) :: x(:, :)
real, intent(in) :: y(:, :, :)
end
end interface
contains
subroutine s1(n, x, y, z, a, b)
integer(8) :: n
real :: x
real :: y(4, n)
real :: z(2, 2, 2)
real :: a(size(x+y)) ! intrinsic +
real :: b(y+z) ! resolves to add
end
end
!Expect: m6.mod
!module m6
! interface operator(+)
! procedure :: add
! end interface
! interface
! pure function add(x, y)
! real(4), intent(in) :: x(:, :)
! real(4), intent(in) :: y(:, :, :)
! integer(8) :: add
! end
! end interface
!contains
! subroutine s1(n, x, y, z, a, b)
! integer(8) :: n
! real(4) :: x
! real(4) :: y(1_8:4_8, 1_8:n)
! real(4) :: z(1_8:2_8, 1_8:2_8, 1_8:2_8)
! real(4) :: a(1_8:int(int(4_8*(n-1_8+1_8),kind=4),kind=8))
! real(4) :: b(1_8:add(y, z))
! end
!end
! Parameterized derived type
module m7
type :: t(k)
integer, kind :: k
real(k) :: a
end type
interface operator(+)
pure integer(8) function f1(x, y)
import :: t
type(t(4)), intent(in) :: x, y
end
pure integer(8) function f2(x, y)
import :: t
type(t(8)), intent(in) :: x, y
end
end interface
contains
subroutine s1(x, y, z)
type(t(4)) :: x, y
real :: z(x + y) ! resolves to f1
end
subroutine s2(x, y, z)
type(t(8)) :: x, y
real :: z(x + y) ! resolves to f2
end
end
!Expect: m7.mod
!module m7
! type :: t(k)
! integer(4), kind :: k
! real(int(k, kind=8)) :: a
! end type
! interface operator(+)
! procedure :: f1
! procedure :: f2
! end interface
! interface
! pure function f1(x, y)
! import :: t
! type(t(k=4_4)), intent(in) :: x
! type(t(k=4_4)), intent(in) :: y
! integer(8) :: f1
! end
! end interface
! interface
! pure function f2(x, y)
! import :: t
! type(t(k=8_4)), intent(in) :: x
! type(t(k=8_4)), intent(in) :: y
! integer(8) :: f2
! end
! end interface
!contains
! subroutine s1(x, y, z)
! type(t(k=4_4)) :: x
! type(t(k=4_4)) :: y
! real(4) :: z(1_8:f1(x, y))
! end
! subroutine s2(x, y, z)
! type(t(k=8_4)) :: x
! type(t(k=8_4)) :: y
! real(4) :: z(1_8:f2(x, y))
! end
!end