aboutsummaryrefslogtreecommitdiff
blob: f7aaecfeaf500a9c6ba4af22433e52eff22744eb (plain)
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
! RUN: %S/test_modfile.sh %s %t %f18
! Resolution of generic names in expressions.
! Test by using generic function in a specification expression that needs
! to be written to a .mod file.

! Resolve based on number of arguments
module m1
  interface f
    pure integer(8) function f1(x)
      real, intent(in) :: x
    end
    pure integer(8) function f2(x, y)
      real, intent(in) :: x, y
    end
    pure integer(8) function f3(x, y, z, w)
      real, intent(in) :: x, y, z, w
      optional :: w
    end
  end interface
contains
  subroutine s1(x, z)
    real :: z(f(x))  ! resolves to f1
  end
  subroutine s2(x, y, z)
    real :: z(f(x, y))  ! resolves to f2
  end
  subroutine s3(x, y, z, w)
    real :: w(f(x, y, z))  ! resolves to f3
  end
  subroutine s4(x, y, z, w, u)
    real :: u(f(x, y, z, w))  ! resolves to f3
  end
end
!Expect: m1.mod
!module m1
! interface f
!  procedure :: f1
!  procedure :: f2
!  procedure :: f3
! end interface
! interface
!  pure function f1(x)
!   real(4), intent(in) :: x
!   integer(8) :: f1
!  end
! end interface
! interface
!  pure function f2(x, y)
!   real(4), intent(in) :: x
!   real(4), intent(in) :: y
!   integer(8) :: f2
!  end
! end interface
! interface
!  pure function f3(x, y, z, w)
!   real(4), intent(in) :: x
!   real(4), intent(in) :: y
!   real(4), intent(in) :: z
!   real(4), intent(in), optional :: w
!   integer(8) :: f3
!  end
! end interface
!contains
! subroutine s1(x, z)
!  real(4) :: x
!  real(4) :: z(1_8:f1(x))
! end
! subroutine s2(x, y, z)
!  real(4) :: x
!  real(4) :: y
!  real(4) :: z(1_8:f2(x, y))
! end
! subroutine s3(x, y, z, w)
!  real(4) :: x
!  real(4) :: y
!  real(4) :: z
!  real(4) :: w(1_8:f3(x, y, z))
! end
! subroutine s4(x, y, z, w, u)
!  real(4) :: x
!  real(4) :: y
!  real(4) :: z
!  real(4) :: w
!  real(4) :: u(1_8:f3(x, y, z, w))
! end
!end

! Resolve based on type or kind
module m2
  interface f
    pure integer(8) function f_real4(x)
      real(4), intent(in) :: x
    end
    pure integer(8) function f_real8(x)
      real(8), intent(in) :: x
    end
    pure integer(8) function f_integer(x)
      integer, intent(in) :: x
    end
  end interface
contains
  subroutine s1(x, y)
    real(4) :: x
    real :: y(f(x))  ! resolves to f_real4
  end
  subroutine s2(x, y)
    real(8) :: x
    real :: y(f(x))  ! resolves to f_real8
  end
  subroutine s3(x, y)
    integer :: x
    real :: y(f(x))  ! resolves to f_integer
  end
end
!Expect: m2.mod
!module m2
! interface f
!  procedure :: f_real4
!  procedure :: f_real8
!  procedure :: f_integer
! end interface
! interface
!  pure function f_real4(x)
!   real(4), intent(in) :: x
!   integer(8) :: f_real4
!  end
! end interface
! interface
!  pure function f_real8(x)
!   real(8), intent(in) :: x
!   integer(8) :: f_real8
!  end
! end interface
! interface
!  pure function f_integer(x)
!   integer(4), intent(in) :: x
!   integer(8) :: f_integer
!  end
! end interface
!contains
! subroutine s1(x, y)
!  real(4) :: x
!  real(4) :: y(1_8:f_real4(x))
! end
! subroutine s2(x, y)
!  real(8) :: x
!  real(4) :: y(1_8:f_real8(x))
! end
! subroutine s3(x, y)
!  integer(4) :: x
!  real(4) :: y(1_8:f_integer(x))
! end
!end

! Resolve based on rank
module m3a
  interface f
    procedure :: f_elem
    procedure :: f_vector
  end interface
contains
  pure integer(8) elemental function f_elem(x) result(result)
    real, intent(in) :: x
    result = 1_8
  end
  pure integer(8) function f_vector(x) result(result)
    real, intent(in) :: x(:)
    result = 2_8
  end
end
!Expect: m3a.mod
!module m3a
! interface f
!  procedure :: f_elem
!  procedure :: f_vector
! end interface
!contains
! elemental pure function f_elem(x) result(result)
!  real(4), intent(in) :: x
!  integer(8) :: result
! end
! pure function f_vector(x) result(result)
!  real(4), intent(in) :: x(:)
!  integer(8) :: result
! end
!end

module m3b
use m3a
contains
  subroutine s1(x, y)
    real :: x
    real :: y(f(x))  ! resolves to f_elem
  end
  subroutine s2(x, y)
    real :: x(10)
    real :: y(f(x))  ! resolves to f_vector (preferred over elemental one)
  end
  subroutine s3(x, y)
    real :: x(10, 10)
    real :: y(ubound(f(x), 1))  ! resolves to f_elem
  end
end
!Expect: m3b.mod
!module m3b
! use m3a, only: f
! use m3a, only: f_elem
! use m3a, only: f_vector
!contains
! subroutine s1(x, y)
!  real(4) :: x
!  real(4) :: y(1_8:f_elem(x))
! end
! subroutine s2(x, y)
!  real(4) :: x(1_8:10_8)
!  real(4) :: y(1_8:f_vector(x))
! end
! subroutine s3(x, y)
!  real(4) :: x(1_8:10_8, 1_8:10_8)
!  real(4) :: y(1_8:10_8)
! end
!end

! Resolve defined unary operator based on type
module m4
  interface operator(.foo.)
    pure integer(8) function f_real(x)
      real, intent(in) :: x
    end
    pure integer(8) function f_integer(x)
      integer, intent(in) :: x
    end
  end interface
contains
  subroutine s1(x, y)
    real :: x
    real :: y(.foo. x)  ! resolves to f_real
  end
  subroutine s2(x, y)
    integer :: x
    real :: y(.foo. x)  ! resolves to f_integer
  end
end
!Expect: m4.mod
!module m4
! interface operator(.foo.)
!  procedure :: f_real
!  procedure :: f_integer
! end interface
! interface
!  pure function f_real(x)
!   real(4), intent(in) :: x
!   integer(8) :: f_real
!  end
! end interface
! interface
!  pure function f_integer(x)
!   integer(4), intent(in) :: x
!   integer(8) :: f_integer
!  end
! end interface
!contains
! subroutine s1(x, y)
!  real(4) :: x
!  real(4) :: y(1_8:f_real(x))
! end
! subroutine s2(x, y)
!  integer(4) :: x
!  real(4) :: y(1_8:f_integer(x))
! end
!end

! Resolve defined binary operator based on type
module m5
  interface operator(.foo.)
    pure integer(8) function f1(x, y)
      real, intent(in) :: x
      real, intent(in) :: y
    end
    pure integer(8) function f2(x, y)
      real, intent(in) :: x
      complex, intent(in) :: y
    end
  end interface
contains
  subroutine s1(x, y)
    complex :: x
    real :: y(1.0 .foo. x)  ! resolves to f2
  end
  subroutine s2(x, y)
    real :: x
    real :: y(1.0 .foo. x)  ! resolves to f1
  end
end
!Expect: m5.mod
!module m5
! interface operator(.foo.)
!  procedure :: f1
!  procedure :: f2
! end interface
! interface
!  pure function f1(x, y)
!   real(4), intent(in) :: x
!   real(4), intent(in) :: y
!   integer(8) :: f1
!  end
! end interface
! interface
!  pure function f2(x, y)
!   real(4), intent(in) :: x
!   complex(4), intent(in) :: y
!   integer(8) :: f2
!  end
! end interface
!contains
! subroutine s1(x, y)
!  complex(4) :: x
!  real(4) :: y(1_8:f2(1._4, x))
! end
! subroutine s2(x, y)
!  real(4) :: x
!  real(4) :: y(1_8:f1(1._4, x))
! end
!end