]>
Commit | Line | Data |
---|---|---|
6de9cd9a | 1 | /* Intrinsic function resolution. |
23a5b65a | 2 | Copyright (C) 2000-2014 Free Software Foundation, Inc. |
6de9cd9a DN |
3 | Contributed by Andy Vaught & Katherine Holcomb |
4 | ||
9fc4d79b | 5 | This file is part of GCC. |
6de9cd9a | 6 | |
9fc4d79b TS |
7 | GCC is free software; you can redistribute it and/or modify it under |
8 | the terms of the GNU General Public License as published by the Free | |
d234d788 | 9 | Software Foundation; either version 3, or (at your option) any later |
9fc4d79b | 10 | version. |
6de9cd9a | 11 | |
9fc4d79b TS |
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
6de9cd9a DN |
16 | |
17 | You should have received a copy of the GNU General Public License | |
d234d788 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
6de9cd9a DN |
20 | |
21 | ||
22 | /* Assign name and types to intrinsic procedures. For functions, the | |
23 | first argument to a resolution function is an expression pointer to | |
24 | the original function node and the rest are pointers to the | |
25 | arguments of the function call. For subroutines, a pointer to the | |
26 | code node is passed. The result type and library subroutine name | |
27 | are generally set according to the function arguments. */ | |
28 | ||
29 | #include "config.h" | |
6b25a558 RH |
30 | #include "system.h" |
31 | #include "coretypes.h" | |
32 | #include "tree.h" | |
d8a2d370 | 33 | #include "stringpool.h" |
6de9cd9a DN |
34 | #include "gfortran.h" |
35 | #include "intrinsic.h" | |
b7e75771 | 36 | #include "constructor.h" |
fabb6f8e | 37 | #include "arith.h" |
6de9cd9a | 38 | |
6b25a558 | 39 | /* Given printf-like arguments, return a stable version of the result string. |
6de9cd9a | 40 | |
6b25a558 RH |
41 | We already have a working, optimized string hashing table in the form of |
42 | the identifier table. Reusing this table is likely not to be wasted, | |
43 | since if the function name makes it to the gimple output of the frontend, | |
44 | we'll have to create the identifier anyway. */ | |
6de9cd9a | 45 | |
6b25a558 | 46 | const char * |
6de9cd9a DN |
47 | gfc_get_string (const char *format, ...) |
48 | { | |
6b25a558 | 49 | char temp_name[128]; |
6de9cd9a | 50 | va_list ap; |
6b25a558 | 51 | tree ident; |
6de9cd9a DN |
52 | |
53 | va_start (ap, format); | |
b251af97 | 54 | vsnprintf (temp_name, sizeof (temp_name), format, ap); |
6de9cd9a | 55 | va_end (ap); |
b251af97 | 56 | temp_name[sizeof (temp_name) - 1] = 0; |
6de9cd9a | 57 | |
6b25a558 RH |
58 | ident = get_identifier (temp_name); |
59 | return IDENTIFIER_POINTER (ident); | |
6de9cd9a DN |
60 | } |
61 | ||
2853e512 PT |
62 | /* MERGE and SPREAD need to have source charlen's present for passing |
63 | to the result expression. */ | |
64 | static void | |
65 | check_charlen_present (gfc_expr *source) | |
66 | { | |
bc21d315 | 67 | if (source->ts.u.cl == NULL) |
b76e28c6 | 68 | source->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); |
6f535271 PT |
69 | |
70 | if (source->expr_type == EXPR_CONSTANT) | |
71 | { | |
b7e75771 JD |
72 | source->ts.u.cl->length |
73 | = gfc_get_int_expr (gfc_default_integer_kind, NULL, | |
74 | source->value.character.length); | |
2853e512 PT |
75 | source->rank = 0; |
76 | } | |
6f535271 | 77 | else if (source->expr_type == EXPR_ARRAY) |
b7e75771 JD |
78 | { |
79 | gfc_constructor *c = gfc_constructor_first (source->value.constructor); | |
80 | source->ts.u.cl->length | |
81 | = gfc_get_int_expr (gfc_default_integer_kind, NULL, | |
82 | c->expr->value.character.length); | |
83 | } | |
2853e512 PT |
84 | } |
85 | ||
870c06b9 TK |
86 | /* Helper function for resolving the "mask" argument. */ |
87 | ||
88 | static void | |
89 | resolve_mask_arg (gfc_expr *mask) | |
90 | { | |
870c06b9 | 91 | |
76896993 | 92 | gfc_typespec ts; |
4af63337 | 93 | gfc_clear_ts (&ts); |
870c06b9 | 94 | |
76896993 | 95 | if (mask->rank == 0) |
870c06b9 | 96 | { |
76896993 TK |
97 | /* For the scalar case, coerce the mask to kind=4 unconditionally |
98 | (because this is the only kind we have a library function | |
99 | for). */ | |
100 | ||
101 | if (mask->ts.kind != 4) | |
102 | { | |
103 | ts.type = BT_LOGICAL; | |
104 | ts.kind = 4; | |
105 | gfc_convert_type (mask, &ts, 2); | |
106 | } | |
107 | } | |
108 | else | |
109 | { | |
110 | /* In the library, we access the mask with a GFC_LOGICAL_1 | |
111 | argument. No need to waste memory if we are about to create | |
112 | a temporary array. */ | |
04f2b606 | 113 | if (mask->expr_type == EXPR_OP && mask->ts.kind != 1) |
76896993 TK |
114 | { |
115 | ts.type = BT_LOGICAL; | |
116 | ts.kind = 1; | |
63bcb71f | 117 | gfc_convert_type_warn (mask, &ts, 2, 0); |
76896993 | 118 | } |
870c06b9 TK |
119 | } |
120 | } | |
121 | ||
0d6d8e00 TB |
122 | |
123 | static void | |
124 | resolve_bound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind, | |
7aa0849a | 125 | const char *name, bool coarray) |
0d6d8e00 TB |
126 | { |
127 | f->ts.type = BT_INTEGER; | |
128 | if (kind) | |
129 | f->ts.kind = mpz_get_si (kind->value.integer); | |
130 | else | |
131 | f->ts.kind = gfc_default_integer_kind; | |
132 | ||
133 | if (dim == NULL) | |
134 | { | |
135 | f->rank = 1; | |
d357d991 MM |
136 | if (array->rank != -1) |
137 | { | |
138 | f->shape = gfc_get_shape (1); | |
139 | mpz_init_set_ui (f->shape[0], coarray ? gfc_get_corank (array) | |
140 | : array->rank); | |
141 | } | |
0d6d8e00 TB |
142 | } |
143 | ||
2b62c97f | 144 | f->value.function.name = gfc_get_string (name); |
0d6d8e00 TB |
145 | } |
146 | ||
195a95c4 TB |
147 | |
148 | static void | |
149 | resolve_transformational (const char *name, gfc_expr *f, gfc_expr *array, | |
150 | gfc_expr *dim, gfc_expr *mask) | |
151 | { | |
152 | const char *prefix; | |
153 | ||
154 | f->ts = array->ts; | |
155 | ||
156 | if (mask) | |
157 | { | |
158 | if (mask->rank == 0) | |
159 | prefix = "s"; | |
160 | else | |
161 | prefix = "m"; | |
162 | ||
163 | resolve_mask_arg (mask); | |
164 | } | |
165 | else | |
166 | prefix = ""; | |
167 | ||
168 | if (dim != NULL) | |
169 | { | |
170 | f->rank = array->rank - 1; | |
171 | f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim); | |
172 | gfc_resolve_dim_arg (dim); | |
173 | } | |
174 | ||
175 | f->value.function.name | |
176 | = gfc_get_string (PREFIX ("%s%s_%c%d"), prefix, name, | |
177 | gfc_type_letter (array->ts.type), array->ts.kind); | |
178 | } | |
179 | ||
180 | ||
6de9cd9a DN |
181 | /********************** Resolution functions **********************/ |
182 | ||
183 | ||
184 | void | |
b251af97 | 185 | gfc_resolve_abs (gfc_expr *f, gfc_expr *a) |
6de9cd9a | 186 | { |
6de9cd9a DN |
187 | f->ts = a->ts; |
188 | if (f->ts.type == BT_COMPLEX) | |
189 | f->ts.type = BT_REAL; | |
190 | ||
b251af97 SK |
191 | f->value.function.name |
192 | = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind); | |
6de9cd9a DN |
193 | } |
194 | ||
195 | ||
a119fc1c | 196 | void |
b251af97 SK |
197 | gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED, |
198 | gfc_expr *mode ATTRIBUTE_UNUSED) | |
a119fc1c FXC |
199 | { |
200 | f->ts.type = BT_INTEGER; | |
201 | f->ts.kind = gfc_c_int_kind; | |
b251af97 | 202 | f->value.function.name = PREFIX ("access_func"); |
3c19e5e1 PT |
203 | } |
204 | ||
205 | ||
d393bbd7 FXC |
206 | void |
207 | gfc_resolve_adjustl (gfc_expr *f, gfc_expr *string) | |
208 | { | |
209 | f->ts.type = BT_CHARACTER; | |
210 | f->ts.kind = string->ts.kind; | |
211 | f->value.function.name = gfc_get_string ("__adjustl_s%d", f->ts.kind); | |
212 | } | |
213 | ||
214 | ||
215 | void | |
216 | gfc_resolve_adjustr (gfc_expr *f, gfc_expr *string) | |
217 | { | |
218 | f->ts.type = BT_CHARACTER; | |
219 | f->ts.kind = string->ts.kind; | |
220 | f->value.function.name = gfc_get_string ("__adjustr_s%d", f->ts.kind); | |
221 | } | |
222 | ||
223 | ||
6f535271 PT |
224 | static void |
225 | gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind, | |
226 | const char *name) | |
3c19e5e1 | 227 | { |
3c19e5e1 | 228 | f->ts.type = BT_CHARACTER; |
719e72fb FXC |
229 | f->ts.kind = (kind == NULL) |
230 | ? gfc_default_character_kind : mpz_get_si (kind->value.integer); | |
b76e28c6 | 231 | f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); |
b7e75771 | 232 | f->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1); |
3c19e5e1 | 233 | |
6f535271 | 234 | f->value.function.name = gfc_get_string (name, f->ts.kind, |
719e72fb FXC |
235 | gfc_type_letter (x->ts.type), |
236 | x->ts.kind); | |
a119fc1c FXC |
237 | } |
238 | ||
239 | ||
6f535271 PT |
240 | void |
241 | gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind) | |
242 | { | |
243 | gfc_resolve_char_achar (f, x, kind, "__achar_%d_%c%d"); | |
244 | } | |
245 | ||
246 | ||
6de9cd9a | 247 | void |
b251af97 | 248 | gfc_resolve_acos (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 249 | { |
6de9cd9a | 250 | f->ts = x->ts; |
b251af97 SK |
251 | f->value.function.name |
252 | = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind); | |
6de9cd9a DN |
253 | } |
254 | ||
255 | ||
1e399e23 | 256 | void |
b251af97 | 257 | gfc_resolve_acosh (gfc_expr *f, gfc_expr *x) |
1e399e23 JD |
258 | { |
259 | f->ts = x->ts; | |
b251af97 SK |
260 | f->value.function.name |
261 | = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type), | |
262 | x->ts.kind); | |
1e399e23 JD |
263 | } |
264 | ||
265 | ||
6de9cd9a | 266 | void |
b251af97 | 267 | gfc_resolve_aimag (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 268 | { |
6de9cd9a DN |
269 | f->ts.type = BT_REAL; |
270 | f->ts.kind = x->ts.kind; | |
b251af97 SK |
271 | f->value.function.name |
272 | = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type), | |
273 | x->ts.kind); | |
6de9cd9a DN |
274 | } |
275 | ||
276 | ||
5d723e54 | 277 | void |
b251af97 | 278 | gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j) |
5d723e54 FXC |
279 | { |
280 | f->ts.type = i->ts.type; | |
b251af97 | 281 | f->ts.kind = gfc_kind_max (i, j); |
5d723e54 FXC |
282 | |
283 | if (i->ts.kind != j->ts.kind) | |
284 | { | |
b251af97 SK |
285 | if (i->ts.kind == gfc_kind_max (i, j)) |
286 | gfc_convert_type (j, &i->ts, 2); | |
5d723e54 | 287 | else |
b251af97 | 288 | gfc_convert_type (i, &j->ts, 2); |
5d723e54 FXC |
289 | } |
290 | ||
b251af97 SK |
291 | f->value.function.name |
292 | = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind); | |
5d723e54 FXC |
293 | } |
294 | ||
295 | ||
6de9cd9a | 296 | void |
b251af97 | 297 | gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
6de9cd9a | 298 | { |
5dd17af5 | 299 | gfc_typespec ts; |
4af63337 | 300 | gfc_clear_ts (&ts); |
5dd17af5 | 301 | |
6de9cd9a DN |
302 | f->ts.type = a->ts.type; |
303 | f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer); | |
304 | ||
5dd17af5 SK |
305 | if (a->ts.kind != f->ts.kind) |
306 | { | |
307 | ts.type = f->ts.type; | |
308 | ts.kind = f->ts.kind; | |
309 | gfc_convert_type (a, &ts, 2); | |
310 | } | |
6de9cd9a DN |
311 | /* The resolved name is only used for specific intrinsics where |
312 | the return kind is the same as the arg kind. */ | |
b251af97 SK |
313 | f->value.function.name |
314 | = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind); | |
6de9cd9a DN |
315 | } |
316 | ||
317 | ||
318 | void | |
b251af97 | 319 | gfc_resolve_dint (gfc_expr *f, gfc_expr *a) |
6de9cd9a DN |
320 | { |
321 | gfc_resolve_aint (f, a, NULL); | |
322 | } | |
323 | ||
324 | ||
325 | void | |
b251af97 | 326 | gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim) |
6de9cd9a | 327 | { |
6de9cd9a DN |
328 | f->ts = mask->ts; |
329 | ||
330 | if (dim != NULL) | |
331 | { | |
bf302220 | 332 | gfc_resolve_dim_arg (dim); |
6de9cd9a | 333 | f->rank = mask->rank - 1; |
94538bd1 | 334 | f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim); |
6de9cd9a DN |
335 | } |
336 | ||
b251af97 SK |
337 | f->value.function.name |
338 | = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type), | |
339 | mask->ts.kind); | |
6de9cd9a DN |
340 | } |
341 | ||
342 | ||
343 | void | |
b251af97 | 344 | gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
6de9cd9a | 345 | { |
5dd17af5 | 346 | gfc_typespec ts; |
4af63337 | 347 | gfc_clear_ts (&ts); |
5dd17af5 | 348 | |
6de9cd9a DN |
349 | f->ts.type = a->ts.type; |
350 | f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer); | |
351 | ||
5dd17af5 SK |
352 | if (a->ts.kind != f->ts.kind) |
353 | { | |
354 | ts.type = f->ts.type; | |
355 | ts.kind = f->ts.kind; | |
356 | gfc_convert_type (a, &ts, 2); | |
357 | } | |
358 | ||
6de9cd9a DN |
359 | /* The resolved name is only used for specific intrinsics where |
360 | the return kind is the same as the arg kind. */ | |
b251af97 SK |
361 | f->value.function.name |
362 | = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type), | |
363 | a->ts.kind); | |
6de9cd9a DN |
364 | } |
365 | ||
366 | ||
367 | void | |
b251af97 | 368 | gfc_resolve_dnint (gfc_expr *f, gfc_expr *a) |
6de9cd9a DN |
369 | { |
370 | gfc_resolve_anint (f, a, NULL); | |
371 | } | |
372 | ||
373 | ||
374 | void | |
b251af97 | 375 | gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim) |
6de9cd9a | 376 | { |
6de9cd9a DN |
377 | f->ts = mask->ts; |
378 | ||
379 | if (dim != NULL) | |
380 | { | |
bf302220 | 381 | gfc_resolve_dim_arg (dim); |
6de9cd9a | 382 | f->rank = mask->rank - 1; |
94538bd1 | 383 | f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim); |
6de9cd9a DN |
384 | } |
385 | ||
b251af97 SK |
386 | f->value.function.name |
387 | = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type), | |
388 | mask->ts.kind); | |
6de9cd9a DN |
389 | } |
390 | ||
391 | ||
392 | void | |
b251af97 | 393 | gfc_resolve_asin (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 394 | { |
6de9cd9a | 395 | f->ts = x->ts; |
b251af97 SK |
396 | f->value.function.name |
397 | = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind); | |
6de9cd9a DN |
398 | } |
399 | ||
1e399e23 | 400 | void |
b251af97 | 401 | gfc_resolve_asinh (gfc_expr *f, gfc_expr *x) |
1e399e23 JD |
402 | { |
403 | f->ts = x->ts; | |
b251af97 SK |
404 | f->value.function.name |
405 | = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type), | |
406 | x->ts.kind); | |
1e399e23 | 407 | } |
6de9cd9a DN |
408 | |
409 | void | |
b251af97 | 410 | gfc_resolve_atan (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 411 | { |
6de9cd9a | 412 | f->ts = x->ts; |
b251af97 SK |
413 | f->value.function.name |
414 | = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind); | |
6de9cd9a DN |
415 | } |
416 | ||
1e399e23 | 417 | void |
b251af97 | 418 | gfc_resolve_atanh (gfc_expr *f, gfc_expr *x) |
1e399e23 JD |
419 | { |
420 | f->ts = x->ts; | |
b251af97 SK |
421 | f->value.function.name |
422 | = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type), | |
423 | x->ts.kind); | |
1e399e23 | 424 | } |
6de9cd9a DN |
425 | |
426 | void | |
b251af97 | 427 | gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED) |
6de9cd9a | 428 | { |
6de9cd9a | 429 | f->ts = x->ts; |
b251af97 SK |
430 | f->value.function.name |
431 | = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type), | |
432 | x->ts.kind); | |
6de9cd9a DN |
433 | } |
434 | ||
435 | ||
e8525382 SK |
436 | /* Resolve the BESYN and BESJN intrinsics. */ |
437 | ||
438 | void | |
b251af97 | 439 | gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x) |
e8525382 SK |
440 | { |
441 | gfc_typespec ts; | |
4af63337 | 442 | gfc_clear_ts (&ts); |
e8525382 SK |
443 | |
444 | f->ts = x->ts; | |
445 | if (n->ts.kind != gfc_c_int_kind) | |
446 | { | |
447 | ts.type = BT_INTEGER; | |
448 | ts.kind = gfc_c_int_kind; | |
449 | gfc_convert_type (n, &ts, 2); | |
450 | } | |
451 | f->value.function.name = gfc_get_string ("<intrinsic>"); | |
452 | } | |
453 | ||
454 | ||
47b99694 TB |
455 | void |
456 | gfc_resolve_bessel_n2 (gfc_expr *f, gfc_expr *n1, gfc_expr *n2, gfc_expr *x) | |
457 | { | |
458 | gfc_typespec ts; | |
459 | gfc_clear_ts (&ts); | |
460 | ||
461 | f->ts = x->ts; | |
462 | f->rank = 1; | |
463 | if (n1->expr_type == EXPR_CONSTANT && n2->expr_type == EXPR_CONSTANT) | |
464 | { | |
465 | f->shape = gfc_get_shape (1); | |
466 | mpz_init (f->shape[0]); | |
467 | mpz_sub (f->shape[0], n2->value.integer, n1->value.integer); | |
468 | mpz_add_ui (f->shape[0], f->shape[0], 1); | |
469 | } | |
470 | ||
471 | if (n1->ts.kind != gfc_c_int_kind) | |
472 | { | |
473 | ts.type = BT_INTEGER; | |
474 | ts.kind = gfc_c_int_kind; | |
475 | gfc_convert_type (n1, &ts, 2); | |
476 | } | |
477 | ||
478 | if (n2->ts.kind != gfc_c_int_kind) | |
479 | { | |
480 | ts.type = BT_INTEGER; | |
481 | ts.kind = gfc_c_int_kind; | |
482 | gfc_convert_type (n2, &ts, 2); | |
483 | } | |
484 | ||
485 | if (f->value.function.isym->id == GFC_ISYM_JN2) | |
486 | f->value.function.name = gfc_get_string (PREFIX ("bessel_jn_r%d"), | |
487 | f->ts.kind); | |
488 | else | |
489 | f->value.function.name = gfc_get_string (PREFIX ("bessel_yn_r%d"), | |
490 | f->ts.kind); | |
491 | } | |
492 | ||
493 | ||
6de9cd9a | 494 | void |
b251af97 | 495 | gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos) |
6de9cd9a | 496 | { |
6de9cd9a | 497 | f->ts.type = BT_LOGICAL; |
9d64df18 | 498 | f->ts.kind = gfc_default_logical_kind; |
b251af97 SK |
499 | f->value.function.name |
500 | = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind); | |
6de9cd9a DN |
501 | } |
502 | ||
503 | ||
cadddfdd TB |
504 | void |
505 | gfc_resolve_c_loc (gfc_expr *f, gfc_expr *x ATTRIBUTE_UNUSED) | |
506 | { | |
507 | f->ts = f->value.function.isym->ts; | |
508 | } | |
509 | ||
510 | ||
511 | void | |
512 | gfc_resolve_c_funloc (gfc_expr *f, gfc_expr *x ATTRIBUTE_UNUSED) | |
513 | { | |
514 | f->ts = f->value.function.isym->ts; | |
515 | } | |
516 | ||
517 | ||
6de9cd9a | 518 | void |
b251af97 | 519 | gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
6de9cd9a | 520 | { |
6de9cd9a | 521 | f->ts.type = BT_INTEGER; |
b251af97 SK |
522 | f->ts.kind = (kind == NULL) |
523 | ? gfc_default_integer_kind : mpz_get_si (kind->value.integer); | |
524 | f->value.function.name | |
525 | = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind, | |
526 | gfc_type_letter (a->ts.type), a->ts.kind); | |
6de9cd9a DN |
527 | } |
528 | ||
529 | ||
530 | void | |
b251af97 | 531 | gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
6de9cd9a | 532 | { |
6f535271 | 533 | gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d"); |
6de9cd9a DN |
534 | } |
535 | ||
536 | ||
f77b6ca3 | 537 | void |
b251af97 | 538 | gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED) |
f77b6ca3 FXC |
539 | { |
540 | f->ts.type = BT_INTEGER; | |
541 | f->ts.kind = gfc_default_integer_kind; | |
b251af97 | 542 | f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind); |
f77b6ca3 FXC |
543 | } |
544 | ||
545 | ||
546 | void | |
b251af97 | 547 | gfc_resolve_chdir_sub (gfc_code *c) |
f77b6ca3 FXC |
548 | { |
549 | const char *name; | |
550 | int kind; | |
551 | ||
552 | if (c->ext.actual->next->expr != NULL) | |
553 | kind = c->ext.actual->next->expr->ts.kind; | |
554 | else | |
555 | kind = gfc_default_integer_kind; | |
556 | ||
b251af97 | 557 | name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind); |
f77b6ca3 FXC |
558 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
559 | } | |
560 | ||
561 | ||
a119fc1c | 562 | void |
b251af97 SK |
563 | gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED, |
564 | gfc_expr *mode ATTRIBUTE_UNUSED) | |
a119fc1c FXC |
565 | { |
566 | f->ts.type = BT_INTEGER; | |
567 | f->ts.kind = gfc_c_int_kind; | |
b251af97 | 568 | f->value.function.name = PREFIX ("chmod_func"); |
a119fc1c FXC |
569 | } |
570 | ||
571 | ||
572 | void | |
b251af97 | 573 | gfc_resolve_chmod_sub (gfc_code *c) |
a119fc1c FXC |
574 | { |
575 | const char *name; | |
576 | int kind; | |
577 | ||
578 | if (c->ext.actual->next->next->expr != NULL) | |
579 | kind = c->ext.actual->next->next->expr->ts.kind; | |
580 | else | |
581 | kind = gfc_default_integer_kind; | |
582 | ||
b251af97 | 583 | name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind); |
a119fc1c FXC |
584 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
585 | } | |
586 | ||
587 | ||
6de9cd9a | 588 | void |
b251af97 | 589 | gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind) |
6de9cd9a | 590 | { |
6de9cd9a | 591 | f->ts.type = BT_COMPLEX; |
b251af97 SK |
592 | f->ts.kind = (kind == NULL) |
593 | ? gfc_default_real_kind : mpz_get_si (kind->value.integer); | |
6de9cd9a DN |
594 | |
595 | if (y == NULL) | |
b251af97 SK |
596 | f->value.function.name |
597 | = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind, | |
598 | gfc_type_letter (x->ts.type), x->ts.kind); | |
6de9cd9a | 599 | else |
b251af97 SK |
600 | f->value.function.name |
601 | = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind, | |
602 | gfc_type_letter (x->ts.type), x->ts.kind, | |
603 | gfc_type_letter (y->ts.type), y->ts.kind); | |
6de9cd9a DN |
604 | } |
605 | ||
b251af97 | 606 | |
6de9cd9a | 607 | void |
b251af97 | 608 | gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y) |
6de9cd9a | 609 | { |
b7e75771 JD |
610 | gfc_resolve_cmplx (f, x, y, gfc_get_int_expr (gfc_default_integer_kind, NULL, |
611 | gfc_default_double_kind)); | |
6de9cd9a DN |
612 | } |
613 | ||
b251af97 | 614 | |
5d723e54 | 615 | void |
b251af97 | 616 | gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y) |
5d723e54 FXC |
617 | { |
618 | int kind; | |
619 | ||
620 | if (x->ts.type == BT_INTEGER) | |
621 | { | |
622 | if (y->ts.type == BT_INTEGER) | |
623 | kind = gfc_default_real_kind; | |
624 | else | |
625 | kind = y->ts.kind; | |
626 | } | |
627 | else | |
628 | { | |
629 | if (y->ts.type == BT_REAL) | |
630 | kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind; | |
631 | else | |
632 | kind = x->ts.kind; | |
633 | } | |
634 | ||
635 | f->ts.type = BT_COMPLEX; | |
636 | f->ts.kind = kind; | |
b251af97 SK |
637 | f->value.function.name |
638 | = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind, | |
639 | gfc_type_letter (x->ts.type), x->ts.kind, | |
640 | gfc_type_letter (y->ts.type), y->ts.kind); | |
5d723e54 FXC |
641 | } |
642 | ||
643 | ||
6de9cd9a | 644 | void |
b251af97 | 645 | gfc_resolve_conjg (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 646 | { |
6de9cd9a DN |
647 | f->ts = x->ts; |
648 | f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind); | |
649 | } | |
650 | ||
651 | ||
652 | void | |
b251af97 | 653 | gfc_resolve_cos (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 654 | { |
6de9cd9a | 655 | f->ts = x->ts; |
b251af97 SK |
656 | f->value.function.name |
657 | = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind); | |
6de9cd9a DN |
658 | } |
659 | ||
660 | ||
661 | void | |
b251af97 | 662 | gfc_resolve_cosh (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 663 | { |
6de9cd9a | 664 | f->ts = x->ts; |
b251af97 SK |
665 | f->value.function.name |
666 | = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind); | |
6de9cd9a DN |
667 | } |
668 | ||
669 | ||
670 | void | |
5cda5098 | 671 | gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind) |
6de9cd9a | 672 | { |
6de9cd9a | 673 | f->ts.type = BT_INTEGER; |
5cda5098 FXC |
674 | if (kind) |
675 | f->ts.kind = mpz_get_si (kind->value.integer); | |
676 | else | |
677 | f->ts.kind = gfc_default_integer_kind; | |
6de9cd9a DN |
678 | |
679 | if (dim != NULL) | |
680 | { | |
681 | f->rank = mask->rank - 1; | |
bf302220 | 682 | gfc_resolve_dim_arg (dim); |
94538bd1 | 683 | f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim); |
6de9cd9a DN |
684 | } |
685 | ||
90469382 TK |
686 | resolve_mask_arg (mask); |
687 | ||
b251af97 | 688 | f->value.function.name |
90469382 TK |
689 | = gfc_get_string (PREFIX ("count_%d_%c"), f->ts.kind, |
690 | gfc_type_letter (mask->ts.type)); | |
6de9cd9a DN |
691 | } |
692 | ||
693 | ||
694 | void | |
b251af97 SK |
695 | gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift, |
696 | gfc_expr *dim) | |
6de9cd9a | 697 | { |
be9c3c6e | 698 | int n, m; |
6de9cd9a | 699 | |
07368af0 PT |
700 | if (array->ts.type == BT_CHARACTER && array->ref) |
701 | gfc_resolve_substring_charlen (array); | |
702 | ||
6de9cd9a DN |
703 | f->ts = array->ts; |
704 | f->rank = array->rank; | |
94538bd1 | 705 | f->shape = gfc_copy_shape (array->shape, array->rank); |
6de9cd9a DN |
706 | |
707 | if (shift->rank > 0) | |
708 | n = 1; | |
709 | else | |
710 | n = 0; | |
711 | ||
be9c3c6e JD |
712 | /* If dim kind is greater than default integer we need to use the larger. */ |
713 | m = gfc_default_integer_kind; | |
714 | if (dim != NULL) | |
715 | m = m < dim->ts.kind ? dim->ts.kind : m; | |
716 | ||
717 | /* Convert shift to at least m, so we don't need | |
718 | kind=1 and kind=2 versions of the library functions. */ | |
719 | if (shift->ts.kind < m) | |
bf302220 TK |
720 | { |
721 | gfc_typespec ts; | |
4af63337 | 722 | gfc_clear_ts (&ts); |
bf302220 | 723 | ts.type = BT_INTEGER; |
be9c3c6e | 724 | ts.kind = m; |
bf302220 TK |
725 | gfc_convert_type_warn (shift, &ts, 2, 0); |
726 | } | |
be9c3c6e | 727 | |
e76e6ce3 JD |
728 | if (dim != NULL) |
729 | { | |
97d650cc JD |
730 | if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL |
731 | && dim->symtree->n.sym->attr.optional) | |
be9c3c6e JD |
732 | { |
733 | /* Mark this for later setting the type in gfc_conv_missing_dummy. */ | |
734 | dim->representation.length = shift->ts.kind; | |
735 | } | |
736 | else | |
737 | { | |
738 | gfc_resolve_dim_arg (dim); | |
739 | /* Convert dim to shift's kind to reduce variations. */ | |
740 | if (dim->ts.kind != shift->ts.kind) | |
741 | gfc_convert_type_warn (dim, &shift->ts, 2, 0); | |
742 | } | |
e76e6ce3 | 743 | } |
33717d59 | 744 | |
691da334 FXC |
745 | if (array->ts.type == BT_CHARACTER) |
746 | { | |
747 | if (array->ts.kind == gfc_default_character_kind) | |
748 | f->value.function.name | |
749 | = gfc_get_string (PREFIX ("cshift%d_%d_char"), n, shift->ts.kind); | |
750 | else | |
751 | f->value.function.name | |
752 | = gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n, shift->ts.kind, | |
753 | array->ts.kind); | |
754 | } | |
755 | else | |
756 | f->value.function.name | |
757 | = gfc_get_string (PREFIX ("cshift%d_%d"), n, shift->ts.kind); | |
6de9cd9a DN |
758 | } |
759 | ||
760 | ||
35059811 | 761 | void |
b251af97 | 762 | gfc_resolve_ctime (gfc_expr *f, gfc_expr *time) |
35059811 FXC |
763 | { |
764 | gfc_typespec ts; | |
4af63337 | 765 | gfc_clear_ts (&ts); |
35059811 FXC |
766 | |
767 | f->ts.type = BT_CHARACTER; | |
768 | f->ts.kind = gfc_default_character_kind; | |
769 | ||
770 | /* ctime TIME argument is a INTEGER(KIND=8), says the doc */ | |
771 | if (time->ts.kind != 8) | |
772 | { | |
773 | ts.type = BT_INTEGER; | |
774 | ts.kind = 8; | |
bc21d315 JW |
775 | ts.u.derived = NULL; |
776 | ts.u.cl = NULL; | |
35059811 FXC |
777 | gfc_convert_type (time, &ts, 2); |
778 | } | |
779 | ||
b251af97 | 780 | f->value.function.name = gfc_get_string (PREFIX ("ctime")); |
35059811 FXC |
781 | } |
782 | ||
783 | ||
6de9cd9a | 784 | void |
b251af97 | 785 | gfc_resolve_dble (gfc_expr *f, gfc_expr *a) |
6de9cd9a | 786 | { |
6de9cd9a | 787 | f->ts.type = BT_REAL; |
9d64df18 | 788 | f->ts.kind = gfc_default_double_kind; |
b251af97 SK |
789 | f->value.function.name |
790 | = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind); | |
6de9cd9a DN |
791 | } |
792 | ||
793 | ||
794 | void | |
b251af97 | 795 | gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p) |
6de9cd9a | 796 | { |
991bb832 FXC |
797 | f->ts.type = a->ts.type; |
798 | if (p != NULL) | |
799 | f->ts.kind = gfc_kind_max (a,p); | |
800 | else | |
801 | f->ts.kind = a->ts.kind; | |
802 | ||
803 | if (p != NULL && a->ts.kind != p->ts.kind) | |
804 | { | |
805 | if (a->ts.kind == gfc_kind_max (a,p)) | |
b251af97 | 806 | gfc_convert_type (p, &a->ts, 2); |
991bb832 | 807 | else |
b251af97 | 808 | gfc_convert_type (a, &p->ts, 2); |
991bb832 FXC |
809 | } |
810 | ||
b251af97 SK |
811 | f->value.function.name |
812 | = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind); | |
6de9cd9a DN |
813 | } |
814 | ||
815 | ||
816 | void | |
b251af97 | 817 | gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b) |
6de9cd9a DN |
818 | { |
819 | gfc_expr temp; | |
820 | ||
61321991 PT |
821 | temp.expr_type = EXPR_OP; |
822 | gfc_clear_ts (&temp.ts); | |
a1ee985f | 823 | temp.value.op.op = INTRINSIC_NONE; |
61321991 PT |
824 | temp.value.op.op1 = a; |
825 | temp.value.op.op2 = b; | |
dcea1b2f | 826 | gfc_type_convert_binary (&temp, 1); |
61321991 | 827 | f->ts = temp.ts; |
b251af97 SK |
828 | f->value.function.name |
829 | = gfc_get_string (PREFIX ("dot_product_%c%d"), | |
830 | gfc_type_letter (f->ts.type), f->ts.kind); | |
6de9cd9a DN |
831 | } |
832 | ||
833 | ||
834 | void | |
b251af97 SK |
835 | gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED, |
836 | gfc_expr *b ATTRIBUTE_UNUSED) | |
6de9cd9a | 837 | { |
9d64df18 | 838 | f->ts.kind = gfc_default_double_kind; |
6de9cd9a | 839 | f->ts.type = BT_REAL; |
6de9cd9a DN |
840 | f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind); |
841 | } | |
842 | ||
843 | ||
88a95a11 FXC |
844 | void |
845 | gfc_resolve_dshift (gfc_expr *f, gfc_expr *i, gfc_expr *j ATTRIBUTE_UNUSED, | |
846 | gfc_expr *shift ATTRIBUTE_UNUSED) | |
847 | { | |
848 | f->ts = i->ts; | |
849 | if (f->value.function.isym->id == GFC_ISYM_DSHIFTL) | |
850 | f->value.function.name = gfc_get_string ("dshiftl_i%d", f->ts.kind); | |
851 | else if (f->value.function.isym->id == GFC_ISYM_DSHIFTR) | |
852 | f->value.function.name = gfc_get_string ("dshiftr_i%d", f->ts.kind); | |
853 | else | |
854 | gcc_unreachable (); | |
855 | } | |
856 | ||
857 | ||
6de9cd9a | 858 | void |
b251af97 SK |
859 | gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift, |
860 | gfc_expr *boundary, gfc_expr *dim) | |
6de9cd9a | 861 | { |
be9c3c6e | 862 | int n, m; |
6de9cd9a | 863 | |
07368af0 PT |
864 | if (array->ts.type == BT_CHARACTER && array->ref) |
865 | gfc_resolve_substring_charlen (array); | |
866 | ||
6de9cd9a DN |
867 | f->ts = array->ts; |
868 | f->rank = array->rank; | |
94538bd1 | 869 | f->shape = gfc_copy_shape (array->shape, array->rank); |
6de9cd9a DN |
870 | |
871 | n = 0; | |
872 | if (shift->rank > 0) | |
873 | n = n | 1; | |
874 | if (boundary && boundary->rank > 0) | |
875 | n = n | 2; | |
876 | ||
be9c3c6e JD |
877 | /* If dim kind is greater than default integer we need to use the larger. */ |
878 | m = gfc_default_integer_kind; | |
879 | if (dim != NULL) | |
880 | m = m < dim->ts.kind ? dim->ts.kind : m; | |
881 | ||
882 | /* Convert shift to at least m, so we don't need | |
883 | kind=1 and kind=2 versions of the library functions. */ | |
884 | if (shift->ts.kind < m) | |
bf302220 TK |
885 | { |
886 | gfc_typespec ts; | |
4af63337 | 887 | gfc_clear_ts (&ts); |
bf302220 | 888 | ts.type = BT_INTEGER; |
be9c3c6e | 889 | ts.kind = m; |
bf302220 TK |
890 | gfc_convert_type_warn (shift, &ts, 2, 0); |
891 | } | |
be9c3c6e | 892 | |
e76e6ce3 JD |
893 | if (dim != NULL) |
894 | { | |
554ef027 JD |
895 | if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL |
896 | && dim->symtree->n.sym->attr.optional) | |
be9c3c6e JD |
897 | { |
898 | /* Mark this for later setting the type in gfc_conv_missing_dummy. */ | |
899 | dim->representation.length = shift->ts.kind; | |
900 | } | |
901 | else | |
902 | { | |
903 | gfc_resolve_dim_arg (dim); | |
904 | /* Convert dim to shift's kind to reduce variations. */ | |
905 | if (dim->ts.kind != shift->ts.kind) | |
906 | gfc_convert_type_warn (dim, &shift->ts, 2, 0); | |
907 | } | |
e76e6ce3 | 908 | } |
6de9cd9a | 909 | |
691da334 FXC |
910 | if (array->ts.type == BT_CHARACTER) |
911 | { | |
912 | if (array->ts.kind == gfc_default_character_kind) | |
913 | f->value.function.name | |
914 | = gfc_get_string (PREFIX ("eoshift%d_%d_char"), n, shift->ts.kind); | |
915 | else | |
916 | f->value.function.name | |
917 | = gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n, shift->ts.kind, | |
918 | array->ts.kind); | |
919 | } | |
920 | else | |
921 | f->value.function.name | |
922 | = gfc_get_string (PREFIX ("eoshift%d_%d"), n, shift->ts.kind); | |
6de9cd9a DN |
923 | } |
924 | ||
925 | ||
926 | void | |
b251af97 | 927 | gfc_resolve_exp (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 928 | { |
6de9cd9a | 929 | f->ts = x->ts; |
b251af97 SK |
930 | f->value.function.name |
931 | = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind); | |
6de9cd9a DN |
932 | } |
933 | ||
934 | ||
935 | void | |
b251af97 | 936 | gfc_resolve_exponent (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 937 | { |
6de9cd9a | 938 | f->ts.type = BT_INTEGER; |
9d64df18 | 939 | f->ts.kind = gfc_default_integer_kind; |
6de9cd9a DN |
940 | f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind); |
941 | } | |
942 | ||
943 | ||
7c1dab0d JW |
944 | /* Resolve the EXTENDS_TYPE_OF intrinsic function. */ |
945 | ||
946 | void | |
947 | gfc_resolve_extends_type_of (gfc_expr *f, gfc_expr *a, gfc_expr *mo) | |
948 | { | |
949 | gfc_symbol *vtab; | |
950 | gfc_symtree *st; | |
951 | ||
952 | /* Prevent double resolution. */ | |
953 | if (f->ts.type == BT_LOGICAL) | |
954 | return; | |
955 | ||
956 | /* Replace the first argument with the corresponding vtab. */ | |
957 | if (a->ts.type == BT_CLASS) | |
b04533af | 958 | gfc_add_vptr_component (a); |
7c1dab0d JW |
959 | else if (a->ts.type == BT_DERIVED) |
960 | { | |
88ce8031 | 961 | vtab = gfc_find_derived_vtab (a->ts.u.derived); |
7c1dab0d JW |
962 | /* Clear the old expr. */ |
963 | gfc_free_ref_list (a->ref); | |
964 | memset (a, '\0', sizeof (gfc_expr)); | |
965 | /* Construct a new one. */ | |
966 | a->expr_type = EXPR_VARIABLE; | |
967 | st = gfc_find_symtree (vtab->ns->sym_root, vtab->name); | |
968 | a->symtree = st; | |
969 | a->ts = vtab->ts; | |
970 | } | |
971 | ||
972 | /* Replace the second argument with the corresponding vtab. */ | |
973 | if (mo->ts.type == BT_CLASS) | |
b04533af | 974 | gfc_add_vptr_component (mo); |
7c1dab0d JW |
975 | else if (mo->ts.type == BT_DERIVED) |
976 | { | |
88ce8031 | 977 | vtab = gfc_find_derived_vtab (mo->ts.u.derived); |
7c1dab0d JW |
978 | /* Clear the old expr. */ |
979 | gfc_free_ref_list (mo->ref); | |
980 | memset (mo, '\0', sizeof (gfc_expr)); | |
981 | /* Construct a new one. */ | |
982 | mo->expr_type = EXPR_VARIABLE; | |
983 | st = gfc_find_symtree (vtab->ns->sym_root, vtab->name); | |
984 | mo->symtree = st; | |
985 | mo->ts = vtab->ts; | |
986 | } | |
987 | ||
988 | f->ts.type = BT_LOGICAL; | |
989 | f->ts.kind = 4; | |
47b99694 TB |
990 | |
991 | f->value.function.isym->formal->ts = a->ts; | |
992 | f->value.function.isym->formal->next->ts = mo->ts; | |
993 | ||
7c1dab0d JW |
994 | /* Call library function. */ |
995 | f->value.function.name = gfc_get_string (PREFIX ("is_extension_of")); | |
996 | } | |
997 | ||
998 | ||
35059811 | 999 | void |
b251af97 | 1000 | gfc_resolve_fdate (gfc_expr *f) |
35059811 FXC |
1001 | { |
1002 | f->ts.type = BT_CHARACTER; | |
1003 | f->ts.kind = gfc_default_character_kind; | |
b251af97 | 1004 | f->value.function.name = gfc_get_string (PREFIX ("fdate")); |
35059811 FXC |
1005 | } |
1006 | ||
1007 | ||
6de9cd9a | 1008 | void |
b251af97 | 1009 | gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
6de9cd9a | 1010 | { |
6de9cd9a | 1011 | f->ts.type = BT_INTEGER; |
b251af97 SK |
1012 | f->ts.kind = (kind == NULL) |
1013 | ? gfc_default_integer_kind : mpz_get_si (kind->value.integer); | |
1014 | f->value.function.name | |
1015 | = gfc_get_string ("__floor%d_%c%d", f->ts.kind, | |
1016 | gfc_type_letter (a->ts.type), a->ts.kind); | |
6de9cd9a DN |
1017 | } |
1018 | ||
1019 | ||
df65f093 | 1020 | void |
b251af97 | 1021 | gfc_resolve_fnum (gfc_expr *f, gfc_expr *n) |
df65f093 | 1022 | { |
df65f093 SK |
1023 | f->ts.type = BT_INTEGER; |
1024 | f->ts.kind = gfc_default_integer_kind; | |
1025 | if (n->ts.kind != f->ts.kind) | |
1026 | gfc_convert_type (n, &f->ts, 2); | |
b251af97 | 1027 | f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind); |
df65f093 SK |
1028 | } |
1029 | ||
1030 | ||
6de9cd9a | 1031 | void |
b251af97 | 1032 | gfc_resolve_fraction (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 1033 | { |
6de9cd9a DN |
1034 | f->ts = x->ts; |
1035 | f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind); | |
1036 | } | |
1037 | ||
1038 | ||
e8525382 SK |
1039 | /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */ |
1040 | ||
1041 | void | |
b251af97 | 1042 | gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x) |
e8525382 SK |
1043 | { |
1044 | f->ts = x->ts; | |
1045 | f->value.function.name = gfc_get_string ("<intrinsic>"); | |
1046 | } | |
1047 | ||
1048 | ||
75be5dc0 TB |
1049 | void |
1050 | gfc_resolve_gamma (gfc_expr *f, gfc_expr *x) | |
1051 | { | |
1052 | f->ts = x->ts; | |
1053 | f->value.function.name | |
7bc19392 | 1054 | = gfc_get_string ("__tgamma_%d", x->ts.kind); |
75be5dc0 TB |
1055 | } |
1056 | ||
1057 | ||
a8c60d7f | 1058 | void |
b251af97 | 1059 | gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED) |
a8c60d7f SK |
1060 | { |
1061 | f->ts.type = BT_INTEGER; | |
1062 | f->ts.kind = 4; | |
b251af97 | 1063 | f->value.function.name = gfc_get_string (PREFIX ("getcwd")); |
a8c60d7f SK |
1064 | } |
1065 | ||
1066 | ||
4c0c6b9f | 1067 | void |
b251af97 | 1068 | gfc_resolve_getgid (gfc_expr *f) |
4c0c6b9f SK |
1069 | { |
1070 | f->ts.type = BT_INTEGER; | |
1071 | f->ts.kind = 4; | |
b251af97 | 1072 | f->value.function.name = gfc_get_string (PREFIX ("getgid")); |
4c0c6b9f SK |
1073 | } |
1074 | ||
1075 | ||
1076 | void | |
b251af97 | 1077 | gfc_resolve_getpid (gfc_expr *f) |
4c0c6b9f SK |
1078 | { |
1079 | f->ts.type = BT_INTEGER; | |
1080 | f->ts.kind = 4; | |
b251af97 | 1081 | f->value.function.name = gfc_get_string (PREFIX ("getpid")); |
4c0c6b9f SK |
1082 | } |
1083 | ||
1084 | ||
1085 | void | |
b251af97 | 1086 | gfc_resolve_getuid (gfc_expr *f) |
4c0c6b9f SK |
1087 | { |
1088 | f->ts.type = BT_INTEGER; | |
1089 | f->ts.kind = 4; | |
b251af97 | 1090 | f->value.function.name = gfc_get_string (PREFIX ("getuid")); |
4c0c6b9f SK |
1091 | } |
1092 | ||
b251af97 | 1093 | |
f77b6ca3 | 1094 | void |
b251af97 | 1095 | gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED) |
f77b6ca3 FXC |
1096 | { |
1097 | f->ts.type = BT_INTEGER; | |
1098 | f->ts.kind = 4; | |
1099 | f->value.function.name = gfc_get_string (PREFIX ("hostnm")); | |
1100 | } | |
1101 | ||
b251af97 | 1102 | |
f489fba1 FXC |
1103 | void |
1104 | gfc_resolve_hypot (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED) | |
1105 | { | |
1106 | f->ts = x->ts; | |
1107 | f->value.function.name = gfc_get_string ("__hypot_r%d", x->ts.kind); | |
1108 | } | |
1109 | ||
1110 | ||
195a95c4 TB |
1111 | void |
1112 | gfc_resolve_iall (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask) | |
1113 | { | |
1114 | resolve_transformational ("iall", f, array, dim, mask); | |
1115 | } | |
1116 | ||
1117 | ||
6de9cd9a | 1118 | void |
b251af97 | 1119 | gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j) |
6de9cd9a | 1120 | { |
c3d003d2 SK |
1121 | /* If the kind of i and j are different, then g77 cross-promoted the |
1122 | kinds to the largest value. The Fortran 95 standard requires the | |
1123 | kinds to match. */ | |
1124 | if (i->ts.kind != j->ts.kind) | |
1125 | { | |
b251af97 SK |
1126 | if (i->ts.kind == gfc_kind_max (i, j)) |
1127 | gfc_convert_type (j, &i->ts, 2); | |
c3d003d2 | 1128 | else |
b251af97 | 1129 | gfc_convert_type (i, &j->ts, 2); |
c3d003d2 | 1130 | } |
6de9cd9a DN |
1131 | |
1132 | f->ts = i->ts; | |
1133 | f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind); | |
1134 | } | |
1135 | ||
1136 | ||
195a95c4 TB |
1137 | void |
1138 | gfc_resolve_iany (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask) | |
1139 | { | |
1140 | resolve_transformational ("iany", f, array, dim, mask); | |
1141 | } | |
1142 | ||
1143 | ||
6de9cd9a | 1144 | void |
b251af97 | 1145 | gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED) |
6de9cd9a | 1146 | { |
6de9cd9a DN |
1147 | f->ts = i->ts; |
1148 | f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind); | |
1149 | } | |
1150 | ||
1151 | ||
1152 | void | |
b251af97 SK |
1153 | gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED, |
1154 | gfc_expr *len ATTRIBUTE_UNUSED) | |
6de9cd9a | 1155 | { |
6de9cd9a DN |
1156 | f->ts = i->ts; |
1157 | f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind); | |
1158 | } | |
1159 | ||
1160 | ||
1161 | void | |
b251af97 | 1162 | gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED) |
6de9cd9a | 1163 | { |
6de9cd9a DN |
1164 | f->ts = i->ts; |
1165 | f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind); | |
1166 | } | |
1167 | ||
1168 | ||
1169 | void | |
5cda5098 | 1170 | gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind) |
6de9cd9a | 1171 | { |
6de9cd9a | 1172 | f->ts.type = BT_INTEGER; |
5cda5098 FXC |
1173 | if (kind) |
1174 | f->ts.kind = mpz_get_si (kind->value.integer); | |
1175 | else | |
1176 | f->ts.kind = gfc_default_integer_kind; | |
1177 | f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind); | |
1178 | } | |
1179 | ||
1180 | ||
1181 | void | |
1182 | gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind) | |
1183 | { | |
1184 | f->ts.type = BT_INTEGER; | |
1185 | if (kind) | |
1186 | f->ts.kind = mpz_get_si (kind->value.integer); | |
1187 | else | |
1188 | f->ts.kind = gfc_default_integer_kind; | |
6de9cd9a DN |
1189 | f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind); |
1190 | } | |
1191 | ||
1192 | ||
1193 | void | |
b251af97 | 1194 | gfc_resolve_idnint (gfc_expr *f, gfc_expr *a) |
6de9cd9a DN |
1195 | { |
1196 | gfc_resolve_nint (f, a, NULL); | |
1197 | } | |
1198 | ||
1199 | ||
f77b6ca3 | 1200 | void |
b251af97 | 1201 | gfc_resolve_ierrno (gfc_expr *f) |
f77b6ca3 FXC |
1202 | { |
1203 | f->ts.type = BT_INTEGER; | |
1204 | f->ts.kind = gfc_default_integer_kind; | |
b251af97 | 1205 | f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind); |
f77b6ca3 FXC |
1206 | } |
1207 | ||
1208 | ||
6de9cd9a | 1209 | void |
b251af97 | 1210 | gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j) |
6de9cd9a | 1211 | { |
c3d003d2 SK |
1212 | /* If the kind of i and j are different, then g77 cross-promoted the |
1213 | kinds to the largest value. The Fortran 95 standard requires the | |
1214 | kinds to match. */ | |
1215 | if (i->ts.kind != j->ts.kind) | |
1216 | { | |
b251af97 SK |
1217 | if (i->ts.kind == gfc_kind_max (i, j)) |
1218 | gfc_convert_type (j, &i->ts, 2); | |
c3d003d2 | 1219 | else |
b251af97 | 1220 | gfc_convert_type (i, &j->ts, 2); |
c3d003d2 | 1221 | } |
6de9cd9a DN |
1222 | |
1223 | f->ts = i->ts; | |
1224 | f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind); | |
1225 | } | |
1226 | ||
1227 | ||
1228 | void | |
b251af97 | 1229 | gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j) |
6de9cd9a | 1230 | { |
c3d003d2 SK |
1231 | /* If the kind of i and j are different, then g77 cross-promoted the |
1232 | kinds to the largest value. The Fortran 95 standard requires the | |
1233 | kinds to match. */ | |
1234 | if (i->ts.kind != j->ts.kind) | |
1235 | { | |
b251af97 SK |
1236 | if (i->ts.kind == gfc_kind_max (i, j)) |
1237 | gfc_convert_type (j, &i->ts, 2); | |
c3d003d2 | 1238 | else |
b251af97 | 1239 | gfc_convert_type (i, &j->ts, 2); |
c3d003d2 | 1240 | } |
6de9cd9a DN |
1241 | |
1242 | f->ts = i->ts; | |
1243 | f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind); | |
1244 | } | |
1245 | ||
1246 | ||
0e7e7e6e | 1247 | void |
b251af97 | 1248 | gfc_resolve_index_func (gfc_expr *f, gfc_expr *str, |
5cda5098 FXC |
1249 | gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back, |
1250 | gfc_expr *kind) | |
0e7e7e6e FXC |
1251 | { |
1252 | gfc_typespec ts; | |
4af63337 | 1253 | gfc_clear_ts (&ts); |
0e7e7e6e FXC |
1254 | |
1255 | f->ts.type = BT_INTEGER; | |
5cda5098 FXC |
1256 | if (kind) |
1257 | f->ts.kind = mpz_get_si (kind->value.integer); | |
1258 | else | |
1259 | f->ts.kind = gfc_default_integer_kind; | |
0e7e7e6e FXC |
1260 | |
1261 | if (back && back->ts.kind != gfc_default_integer_kind) | |
1262 | { | |
1263 | ts.type = BT_LOGICAL; | |
1264 | ts.kind = gfc_default_integer_kind; | |
bc21d315 JW |
1265 | ts.u.derived = NULL; |
1266 | ts.u.cl = NULL; | |
0e7e7e6e FXC |
1267 | gfc_convert_type (back, &ts, 2); |
1268 | } | |
1269 | ||
b251af97 SK |
1270 | f->value.function.name |
1271 | = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind); | |
0e7e7e6e FXC |
1272 | } |
1273 | ||
1274 | ||
6de9cd9a | 1275 | void |
b251af97 | 1276 | gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
6de9cd9a | 1277 | { |
6de9cd9a | 1278 | f->ts.type = BT_INTEGER; |
b251af97 SK |
1279 | f->ts.kind = (kind == NULL) |
1280 | ? gfc_default_integer_kind : mpz_get_si (kind->value.integer); | |
1281 | f->value.function.name | |
1282 | = gfc_get_string ("__int_%d_%c%d", f->ts.kind, | |
1283 | gfc_type_letter (a->ts.type), a->ts.kind); | |
6de9cd9a DN |
1284 | } |
1285 | ||
1286 | ||
bf3fb7e4 | 1287 | void |
b251af97 | 1288 | gfc_resolve_int2 (gfc_expr *f, gfc_expr *a) |
bf3fb7e4 FXC |
1289 | { |
1290 | f->ts.type = BT_INTEGER; | |
1291 | f->ts.kind = 2; | |
b251af97 SK |
1292 | f->value.function.name |
1293 | = gfc_get_string ("__int_%d_%c%d", f->ts.kind, | |
1294 | gfc_type_letter (a->ts.type), a->ts.kind); | |
bf3fb7e4 FXC |
1295 | } |
1296 | ||
1297 | ||
1298 | void | |
b251af97 | 1299 | gfc_resolve_int8 (gfc_expr *f, gfc_expr *a) |
bf3fb7e4 FXC |
1300 | { |
1301 | f->ts.type = BT_INTEGER; | |
1302 | f->ts.kind = 8; | |
b251af97 SK |
1303 | f->value.function.name |
1304 | = gfc_get_string ("__int_%d_%c%d", f->ts.kind, | |
1305 | gfc_type_letter (a->ts.type), a->ts.kind); | |
bf3fb7e4 FXC |
1306 | } |
1307 | ||
1308 | ||
1309 | void | |
b251af97 | 1310 | gfc_resolve_long (gfc_expr *f, gfc_expr *a) |
bf3fb7e4 FXC |
1311 | { |
1312 | f->ts.type = BT_INTEGER; | |
1313 | f->ts.kind = 4; | |
b251af97 SK |
1314 | f->value.function.name |
1315 | = gfc_get_string ("__int_%d_%c%d", f->ts.kind, | |
1316 | gfc_type_letter (a->ts.type), a->ts.kind); | |
bf3fb7e4 FXC |
1317 | } |
1318 | ||
1319 | ||
195a95c4 TB |
1320 | void |
1321 | gfc_resolve_iparity (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask) | |
1322 | { | |
1323 | resolve_transformational ("iparity", f, array, dim, mask); | |
1324 | } | |
1325 | ||
1326 | ||
ae8b8789 | 1327 | void |
b251af97 | 1328 | gfc_resolve_isatty (gfc_expr *f, gfc_expr *u) |
ae8b8789 FXC |
1329 | { |
1330 | gfc_typespec ts; | |
4af63337 | 1331 | gfc_clear_ts (&ts); |
ae8b8789 FXC |
1332 | |
1333 | f->ts.type = BT_LOGICAL; | |
1334 | f->ts.kind = gfc_default_integer_kind; | |
1335 | if (u->ts.kind != gfc_c_int_kind) | |
1336 | { | |
1337 | ts.type = BT_INTEGER; | |
1338 | ts.kind = gfc_c_int_kind; | |
bc21d315 JW |
1339 | ts.u.derived = NULL; |
1340 | ts.u.cl = NULL; | |
ae8b8789 FXC |
1341 | gfc_convert_type (u, &ts, 2); |
1342 | } | |
1343 | ||
b251af97 | 1344 | f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind); |
ae8b8789 FXC |
1345 | } |
1346 | ||
1347 | ||
6de9cd9a | 1348 | void |
b251af97 | 1349 | gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift) |
6de9cd9a | 1350 | { |
6de9cd9a | 1351 | f->ts = i->ts; |
b251af97 SK |
1352 | f->value.function.name |
1353 | = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind); | |
6de9cd9a DN |
1354 | } |
1355 | ||
1356 | ||
a119fc1c | 1357 | void |
b251af97 | 1358 | gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift) |
a119fc1c FXC |
1359 | { |
1360 | f->ts = i->ts; | |
b251af97 SK |
1361 | f->value.function.name |
1362 | = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind); | |
a119fc1c FXC |
1363 | } |
1364 | ||
1365 | ||
1366 | void | |
b251af97 | 1367 | gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift) |
a119fc1c FXC |
1368 | { |
1369 | f->ts = i->ts; | |
b251af97 SK |
1370 | f->value.function.name |
1371 | = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind); | |
a119fc1c FXC |
1372 | } |
1373 | ||
1374 | ||
6de9cd9a | 1375 | void |
b251af97 | 1376 | gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size) |
6de9cd9a DN |
1377 | { |
1378 | int s_kind; | |
1379 | ||
a24ff43f | 1380 | s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind; |
6de9cd9a DN |
1381 | |
1382 | f->ts = i->ts; | |
b251af97 SK |
1383 | f->value.function.name |
1384 | = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind); | |
6de9cd9a DN |
1385 | } |
1386 | ||
1387 | ||
f77b6ca3 | 1388 | void |
b251af97 SK |
1389 | gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED, |
1390 | gfc_expr *s ATTRIBUTE_UNUSED) | |
f77b6ca3 FXC |
1391 | { |
1392 | f->ts.type = BT_INTEGER; | |
1393 | f->ts.kind = gfc_default_integer_kind; | |
b251af97 | 1394 | f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind); |
f77b6ca3 FXC |
1395 | } |
1396 | ||
1397 | ||
6de9cd9a | 1398 | void |
5cda5098 | 1399 | gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind) |
6de9cd9a | 1400 | { |
7aa0849a | 1401 | resolve_bound (f, array, dim, kind, "__lbound", false); |
0d6d8e00 | 1402 | } |
6de9cd9a | 1403 | |
6de9cd9a | 1404 | |
0d6d8e00 TB |
1405 | void |
1406 | gfc_resolve_lcobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind) | |
1407 | { | |
7aa0849a | 1408 | resolve_bound (f, array, dim, kind, "__lcobound", true); |
6de9cd9a DN |
1409 | } |
1410 | ||
1411 | ||
1412 | void | |
5cda5098 | 1413 | gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind) |
6de9cd9a | 1414 | { |
6de9cd9a | 1415 | f->ts.type = BT_INTEGER; |
5cda5098 FXC |
1416 | if (kind) |
1417 | f->ts.kind = mpz_get_si (kind->value.integer); | |
1418 | else | |
1419 | f->ts.kind = gfc_default_integer_kind; | |
b251af97 SK |
1420 | f->value.function.name |
1421 | = gfc_get_string ("__len_%d_i%d", string->ts.kind, | |
1422 | gfc_default_integer_kind); | |
6de9cd9a DN |
1423 | } |
1424 | ||
1425 | ||
1426 | void | |
5cda5098 | 1427 | gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind) |
6de9cd9a | 1428 | { |
6de9cd9a | 1429 | f->ts.type = BT_INTEGER; |
5cda5098 FXC |
1430 | if (kind) |
1431 | f->ts.kind = mpz_get_si (kind->value.integer); | |
1432 | else | |
1433 | f->ts.kind = gfc_default_integer_kind; | |
6de9cd9a DN |
1434 | f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind); |
1435 | } | |
1436 | ||
1437 | ||
75be5dc0 TB |
1438 | void |
1439 | gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x) | |
1440 | { | |
1441 | f->ts = x->ts; | |
1442 | f->value.function.name | |
1443 | = gfc_get_string ("__lgamma_%d", x->ts.kind); | |
1444 | } | |
1445 | ||
1446 | ||
f77b6ca3 | 1447 | void |
b251af97 SK |
1448 | gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED, |
1449 | gfc_expr *p2 ATTRIBUTE_UNUSED) | |
f77b6ca3 FXC |
1450 | { |
1451 | f->ts.type = BT_INTEGER; | |
1452 | f->ts.kind = gfc_default_integer_kind; | |
b251af97 | 1453 | f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind); |
f77b6ca3 FXC |
1454 | } |
1455 | ||
1456 | ||
83d890b9 AL |
1457 | void |
1458 | gfc_resolve_loc (gfc_expr *f, gfc_expr *x) | |
1459 | { | |
1460 | f->ts.type= BT_INTEGER; | |
1461 | f->ts.kind = gfc_index_integer_kind; | |
1462 | f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind); | |
1463 | } | |
1464 | ||
1465 | ||
6de9cd9a | 1466 | void |
b251af97 | 1467 | gfc_resolve_log (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 1468 | { |
6de9cd9a | 1469 | f->ts = x->ts; |
b251af97 SK |
1470 | f->value.function.name |
1471 | = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind); | |
6de9cd9a DN |
1472 | } |
1473 | ||
1474 | ||
1475 | void | |
b251af97 | 1476 | gfc_resolve_log10 (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 1477 | { |
6de9cd9a | 1478 | f->ts = x->ts; |
b251af97 SK |
1479 | f->value.function.name |
1480 | = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type), | |
1481 | x->ts.kind); | |
6de9cd9a DN |
1482 | } |
1483 | ||
1484 | ||
1485 | void | |
b251af97 | 1486 | gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
6de9cd9a | 1487 | { |
6de9cd9a | 1488 | f->ts.type = BT_LOGICAL; |
b251af97 SK |
1489 | f->ts.kind = (kind == NULL) |
1490 | ? gfc_default_logical_kind : mpz_get_si (kind->value.integer); | |
6de9cd9a DN |
1491 | f->rank = a->rank; |
1492 | ||
b251af97 SK |
1493 | f->value.function.name |
1494 | = gfc_get_string ("__logical_%d_%c%d", f->ts.kind, | |
1495 | gfc_type_letter (a->ts.type), a->ts.kind); | |
6de9cd9a DN |
1496 | } |
1497 | ||
1498 | ||
0d519038 | 1499 | void |
b251af97 | 1500 | gfc_resolve_malloc (gfc_expr *f, gfc_expr *size) |
0d519038 FXC |
1501 | { |
1502 | if (size->ts.kind < gfc_index_integer_kind) | |
1503 | { | |
1504 | gfc_typespec ts; | |
4af63337 | 1505 | gfc_clear_ts (&ts); |
0d519038 FXC |
1506 | |
1507 | ts.type = BT_INTEGER; | |
1508 | ts.kind = gfc_index_integer_kind; | |
1509 | gfc_convert_type_warn (size, &ts, 2, 0); | |
1510 | } | |
1511 | ||
1512 | f->ts.type = BT_INTEGER; | |
1513 | f->ts.kind = gfc_index_integer_kind; | |
b251af97 | 1514 | f->value.function.name = gfc_get_string (PREFIX ("malloc")); |
0d519038 FXC |
1515 | } |
1516 | ||
1517 | ||
6de9cd9a | 1518 | void |
b251af97 | 1519 | gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b) |
6de9cd9a DN |
1520 | { |
1521 | gfc_expr temp; | |
1522 | ||
1523 | if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL) | |
1524 | { | |
1525 | f->ts.type = BT_LOGICAL; | |
9d64df18 | 1526 | f->ts.kind = gfc_default_logical_kind; |
6de9cd9a DN |
1527 | } |
1528 | else | |
1529 | { | |
1530 | temp.expr_type = EXPR_OP; | |
1531 | gfc_clear_ts (&temp.ts); | |
a1ee985f | 1532 | temp.value.op.op = INTRINSIC_NONE; |
58b03ab2 TS |
1533 | temp.value.op.op1 = a; |
1534 | temp.value.op.op2 = b; | |
dcea1b2f | 1535 | gfc_type_convert_binary (&temp, 1); |
6de9cd9a DN |
1536 | f->ts = temp.ts; |
1537 | } | |
1538 | ||
1539 | f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1; | |
1540 | ||
986a8d11 TK |
1541 | if (a->rank == 2 && b->rank == 2) |
1542 | { | |
1543 | if (a->shape && b->shape) | |
1544 | { | |
1545 | f->shape = gfc_get_shape (f->rank); | |
1546 | mpz_init_set (f->shape[0], a->shape[0]); | |
1547 | mpz_init_set (f->shape[1], b->shape[1]); | |
1548 | } | |
1549 | } | |
1550 | else if (a->rank == 1) | |
1551 | { | |
1552 | if (b->shape) | |
1553 | { | |
1554 | f->shape = gfc_get_shape (f->rank); | |
1555 | mpz_init_set (f->shape[0], b->shape[1]); | |
1556 | } | |
1557 | } | |
1558 | else | |
1559 | { | |
1560 | /* b->rank == 1 and a->rank == 2 here, all other cases have | |
1561 | been caught in check.c. */ | |
1562 | if (a->shape) | |
1563 | { | |
1564 | f->shape = gfc_get_shape (f->rank); | |
1565 | mpz_init_set (f->shape[0], a->shape[0]); | |
1566 | } | |
1567 | } | |
1568 | ||
b251af97 SK |
1569 | f->value.function.name |
1570 | = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type), | |
1571 | f->ts.kind); | |
6de9cd9a DN |
1572 | } |
1573 | ||
1574 | ||
1575 | static void | |
b251af97 | 1576 | gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args) |
6de9cd9a DN |
1577 | { |
1578 | gfc_actual_arglist *a; | |
1579 | ||
1580 | f->ts.type = args->expr->ts.type; | |
1581 | f->ts.kind = args->expr->ts.kind; | |
1582 | /* Find the largest type kind. */ | |
1583 | for (a = args->next; a; a = a->next) | |
1584 | { | |
1585 | if (a->expr->ts.kind > f->ts.kind) | |
b251af97 | 1586 | f->ts.kind = a->expr->ts.kind; |
6de9cd9a DN |
1587 | } |
1588 | ||
1589 | /* Convert all parameters to the required kind. */ | |
1590 | for (a = args; a; a = a->next) | |
1591 | { | |
1592 | if (a->expr->ts.kind != f->ts.kind) | |
b251af97 | 1593 | gfc_convert_type (a->expr, &f->ts, 2); |
6de9cd9a DN |
1594 | } |
1595 | ||
b251af97 SK |
1596 | f->value.function.name |
1597 | = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind); | |
6de9cd9a DN |
1598 | } |
1599 | ||
1600 | ||
1601 | void | |
b251af97 | 1602 | gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args) |
6de9cd9a DN |
1603 | { |
1604 | gfc_resolve_minmax ("__max_%c%d", f, args); | |
1605 | } | |
1606 | ||
1607 | ||
1608 | void | |
b251af97 SK |
1609 | gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim, |
1610 | gfc_expr *mask) | |
6de9cd9a DN |
1611 | { |
1612 | const char *name; | |
476220e7 | 1613 | int i, j, idim; |
6de9cd9a DN |
1614 | |
1615 | f->ts.type = BT_INTEGER; | |
9d64df18 | 1616 | f->ts.kind = gfc_default_integer_kind; |
6de9cd9a DN |
1617 | |
1618 | if (dim == NULL) | |
476220e7 PT |
1619 | { |
1620 | f->rank = 1; | |
1621 | f->shape = gfc_get_shape (1); | |
1622 | mpz_init_set_si (f->shape[0], array->rank); | |
1623 | } | |
6de9cd9a DN |
1624 | else |
1625 | { | |
1626 | f->rank = array->rank - 1; | |
bf302220 | 1627 | gfc_resolve_dim_arg (dim); |
476220e7 PT |
1628 | if (array->shape && dim->expr_type == EXPR_CONSTANT) |
1629 | { | |
1630 | idim = (int) mpz_get_si (dim->value.integer); | |
1631 | f->shape = gfc_get_shape (f->rank); | |
1632 | for (i = 0, j = 0; i < f->rank; i++, j++) | |
1633 | { | |
1634 | if (i == (idim - 1)) | |
b251af97 | 1635 | j++; |
476220e7 PT |
1636 | mpz_init_set (f->shape[i], array->shape[j]); |
1637 | } | |
1638 | } | |
6de9cd9a DN |
1639 | } |
1640 | ||
97a62038 TK |
1641 | if (mask) |
1642 | { | |
1643 | if (mask->rank == 0) | |
1644 | name = "smaxloc"; | |
1645 | else | |
1646 | name = "mmaxloc"; | |
1647 | ||
870c06b9 | 1648 | resolve_mask_arg (mask); |
97a62038 TK |
1649 | } |
1650 | else | |
1651 | name = "maxloc"; | |
1652 | ||
b251af97 SK |
1653 | f->value.function.name |
1654 | = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind, | |
1655 | gfc_type_letter (array->ts.type), array->ts.kind); | |
6de9cd9a DN |
1656 | } |
1657 | ||
1658 | ||
1659 | void | |
b251af97 SK |
1660 | gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim, |
1661 | gfc_expr *mask) | |
6de9cd9a | 1662 | { |
97a62038 | 1663 | const char *name; |
476220e7 | 1664 | int i, j, idim; |
97a62038 | 1665 | |
6de9cd9a DN |
1666 | f->ts = array->ts; |
1667 | ||
1668 | if (dim != NULL) | |
1669 | { | |
1670 | f->rank = array->rank - 1; | |
bf302220 | 1671 | gfc_resolve_dim_arg (dim); |
476220e7 PT |
1672 | |
1673 | if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT) | |
1674 | { | |
1675 | idim = (int) mpz_get_si (dim->value.integer); | |
1676 | f->shape = gfc_get_shape (f->rank); | |
1677 | for (i = 0, j = 0; i < f->rank; i++, j++) | |
1678 | { | |
1679 | if (i == (idim - 1)) | |
b251af97 | 1680 | j++; |
476220e7 PT |
1681 | mpz_init_set (f->shape[i], array->shape[j]); |
1682 | } | |
1683 | } | |
6de9cd9a DN |
1684 | } |
1685 | ||
97a62038 TK |
1686 | if (mask) |
1687 | { | |
1688 | if (mask->rank == 0) | |
1689 | name = "smaxval"; | |
1690 | else | |
1691 | name = "mmaxval"; | |
1692 | ||
870c06b9 | 1693 | resolve_mask_arg (mask); |
97a62038 TK |
1694 | } |
1695 | else | |
1696 | name = "maxval"; | |
1697 | ||
b251af97 SK |
1698 | f->value.function.name |
1699 | = gfc_get_string (PREFIX ("%s_%c%d"), name, | |
1700 | gfc_type_letter (array->ts.type), array->ts.kind); | |
6de9cd9a DN |
1701 | } |
1702 | ||
1703 | ||
bf3fb7e4 | 1704 | void |
b251af97 | 1705 | gfc_resolve_mclock (gfc_expr *f) |
bf3fb7e4 FXC |
1706 | { |
1707 | f->ts.type = BT_INTEGER; | |
1708 | f->ts.kind = 4; | |
b251af97 | 1709 | f->value.function.name = PREFIX ("mclock"); |
bf3fb7e4 FXC |
1710 | } |
1711 | ||
1712 | ||
1713 | void | |
b251af97 | 1714 | gfc_resolve_mclock8 (gfc_expr *f) |
bf3fb7e4 FXC |
1715 | { |
1716 | f->ts.type = BT_INTEGER; | |
1717 | f->ts.kind = 8; | |
b251af97 | 1718 | f->value.function.name = PREFIX ("mclock8"); |
bf3fb7e4 FXC |
1719 | } |
1720 | ||
1721 | ||
88a95a11 FXC |
1722 | void |
1723 | gfc_resolve_mask (gfc_expr *f, gfc_expr *i ATTRIBUTE_UNUSED, | |
1724 | gfc_expr *kind) | |
1725 | { | |
1726 | f->ts.type = BT_INTEGER; | |
1727 | f->ts.kind = kind ? mpz_get_si (kind->value.integer) | |
1728 | : gfc_default_integer_kind; | |
1729 | ||
1730 | if (f->value.function.isym->id == GFC_ISYM_MASKL) | |
1731 | f->value.function.name = gfc_get_string ("__maskl_i%d", f->ts.kind); | |
1732 | else | |
1733 | f->value.function.name = gfc_get_string ("__maskr_i%d", f->ts.kind); | |
1734 | } | |
1735 | ||
1736 | ||
6de9cd9a | 1737 | void |
b251af97 SK |
1738 | gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource, |
1739 | gfc_expr *fsource ATTRIBUTE_UNUSED, | |
1740 | gfc_expr *mask ATTRIBUTE_UNUSED) | |
6de9cd9a | 1741 | { |
07368af0 PT |
1742 | if (tsource->ts.type == BT_CHARACTER && tsource->ref) |
1743 | gfc_resolve_substring_charlen (tsource); | |
1744 | ||
1745 | if (fsource->ts.type == BT_CHARACTER && fsource->ref) | |
1746 | gfc_resolve_substring_charlen (fsource); | |
1747 | ||
2853e512 PT |
1748 | if (tsource->ts.type == BT_CHARACTER) |
1749 | check_charlen_present (tsource); | |
1750 | ||
6de9cd9a | 1751 | f->ts = tsource->ts; |
b251af97 SK |
1752 | f->value.function.name |
1753 | = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type), | |
1754 | tsource->ts.kind); | |
6de9cd9a DN |
1755 | } |
1756 | ||
1757 | ||
88a95a11 FXC |
1758 | void |
1759 | gfc_resolve_merge_bits (gfc_expr *f, gfc_expr *i, | |
1760 | gfc_expr *j ATTRIBUTE_UNUSED, | |
1761 | gfc_expr *mask ATTRIBUTE_UNUSED) | |
1762 | { | |
1763 | f->ts = i->ts; | |
1764 | f->value.function.name = gfc_get_string ("__merge_bits_i%d", i->ts.kind); | |
1765 | } | |
1766 | ||
1767 | ||
6de9cd9a | 1768 | void |
b251af97 | 1769 | gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args) |
6de9cd9a DN |
1770 | { |
1771 | gfc_resolve_minmax ("__min_%c%d", f, args); | |
1772 | } | |
1773 | ||
1774 | ||
1775 | void | |
b251af97 SK |
1776 | gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim, |
1777 | gfc_expr *mask) | |
6de9cd9a DN |
1778 | { |
1779 | const char *name; | |
476220e7 | 1780 | int i, j, idim; |
6de9cd9a DN |
1781 | |
1782 | f->ts.type = BT_INTEGER; | |
9d64df18 | 1783 | f->ts.kind = gfc_default_integer_kind; |
6de9cd9a DN |
1784 | |
1785 | if (dim == NULL) | |
476220e7 PT |
1786 | { |
1787 | f->rank = 1; | |
1788 | f->shape = gfc_get_shape (1); | |
1789 | mpz_init_set_si (f->shape[0], array->rank); | |
1790 | } | |
6de9cd9a DN |
1791 | else |
1792 | { | |
1793 | f->rank = array->rank - 1; | |
bf302220 | 1794 | gfc_resolve_dim_arg (dim); |
476220e7 PT |
1795 | if (array->shape && dim->expr_type == EXPR_CONSTANT) |
1796 | { | |
1797 | idim = (int) mpz_get_si (dim->value.integer); | |
1798 | f->shape = gfc_get_shape (f->rank); | |
1799 | for (i = 0, j = 0; i < f->rank; i++, j++) | |
1800 | { | |
1801 | if (i == (idim - 1)) | |
b251af97 | 1802 | j++; |
476220e7 PT |
1803 | mpz_init_set (f->shape[i], array->shape[j]); |
1804 | } | |
1805 | } | |
6de9cd9a DN |
1806 | } |
1807 | ||
97a62038 TK |
1808 | if (mask) |
1809 | { | |
1810 | if (mask->rank == 0) | |
1811 | name = "sminloc"; | |
1812 | else | |
1813 | name = "mminloc"; | |
1814 | ||
870c06b9 | 1815 | resolve_mask_arg (mask); |
97a62038 TK |
1816 | } |
1817 | else | |
1818 | name = "minloc"; | |
1819 | ||
b251af97 SK |
1820 | f->value.function.name |
1821 | = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind, | |
1822 | gfc_type_letter (array->ts.type), array->ts.kind); | |
6de9cd9a DN |
1823 | } |
1824 | ||
7551270e | 1825 | |
6de9cd9a | 1826 | void |
b251af97 SK |
1827 | gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim, |
1828 | gfc_expr *mask) | |
6de9cd9a | 1829 | { |
97a62038 | 1830 | const char *name; |
476220e7 | 1831 | int i, j, idim; |
97a62038 | 1832 | |
6de9cd9a DN |
1833 | f->ts = array->ts; |
1834 | ||
1835 | if (dim != NULL) | |
1836 | { | |
1837 | f->rank = array->rank - 1; | |
bf302220 | 1838 | gfc_resolve_dim_arg (dim); |
476220e7 PT |
1839 | |
1840 | if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT) | |
1841 | { | |
1842 | idim = (int) mpz_get_si (dim->value.integer); | |
1843 | f->shape = gfc_get_shape (f->rank); | |
1844 | for (i = 0, j = 0; i < f->rank; i++, j++) | |
1845 | { | |
1846 | if (i == (idim - 1)) | |
b251af97 | 1847 | j++; |
476220e7 PT |
1848 | mpz_init_set (f->shape[i], array->shape[j]); |
1849 | } | |
1850 | } | |
6de9cd9a DN |
1851 | } |
1852 | ||
97a62038 TK |
1853 | if (mask) |
1854 | { | |
1855 | if (mask->rank == 0) | |
1856 | name = "sminval"; | |
1857 | else | |
1858 | name = "mminval"; | |
1859 | ||
870c06b9 | 1860 | resolve_mask_arg (mask); |
97a62038 TK |
1861 | } |
1862 | else | |
1863 | name = "minval"; | |
1864 | ||
b251af97 SK |
1865 | f->value.function.name |
1866 | = gfc_get_string (PREFIX ("%s_%c%d"), name, | |
1867 | gfc_type_letter (array->ts.type), array->ts.kind); | |
6de9cd9a DN |
1868 | } |
1869 | ||
1870 | ||
1871 | void | |
b251af97 | 1872 | gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p) |
6de9cd9a | 1873 | { |
991bb832 FXC |
1874 | f->ts.type = a->ts.type; |
1875 | if (p != NULL) | |
1876 | f->ts.kind = gfc_kind_max (a,p); | |
1877 | else | |
1878 | f->ts.kind = a->ts.kind; | |
1879 | ||
1880 | if (p != NULL && a->ts.kind != p->ts.kind) | |
1881 | { | |
1882 | if (a->ts.kind == gfc_kind_max (a,p)) | |
b251af97 | 1883 | gfc_convert_type (p, &a->ts, 2); |
991bb832 | 1884 | else |
b251af97 | 1885 | gfc_convert_type (a, &p->ts, 2); |
991bb832 FXC |
1886 | } |
1887 | ||
b251af97 SK |
1888 | f->value.function.name |
1889 | = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind); | |
6de9cd9a DN |
1890 | } |
1891 | ||
1892 | ||
1893 | void | |
b251af97 | 1894 | gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p) |
6de9cd9a | 1895 | { |
991bb832 FXC |
1896 | f->ts.type = a->ts.type; |
1897 | if (p != NULL) | |
1898 | f->ts.kind = gfc_kind_max (a,p); | |
1899 | else | |
1900 | f->ts.kind = a->ts.kind; | |
1901 | ||
1902 | if (p != NULL && a->ts.kind != p->ts.kind) | |
1903 | { | |
1904 | if (a->ts.kind == gfc_kind_max (a,p)) | |
b251af97 | 1905 | gfc_convert_type (p, &a->ts, 2); |
991bb832 | 1906 | else |
b251af97 | 1907 | gfc_convert_type (a, &p->ts, 2); |
991bb832 FXC |
1908 | } |
1909 | ||
b251af97 SK |
1910 | f->value.function.name |
1911 | = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type), | |
1912 | f->ts.kind); | |
6de9cd9a DN |
1913 | } |
1914 | ||
8765339d | 1915 | void |
be9c3c6e | 1916 | gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p) |
8765339d | 1917 | { |
be9c3c6e JD |
1918 | if (p->ts.kind != a->ts.kind) |
1919 | gfc_convert_type (p, &a->ts, 2); | |
1920 | ||
8765339d | 1921 | f->ts = a->ts; |
b251af97 SK |
1922 | f->value.function.name |
1923 | = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type), | |
1924 | a->ts.kind); | |
8765339d | 1925 | } |
6de9cd9a DN |
1926 | |
1927 | void | |
b251af97 | 1928 | gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
6de9cd9a | 1929 | { |
6de9cd9a | 1930 | f->ts.type = BT_INTEGER; |
b251af97 SK |
1931 | f->ts.kind = (kind == NULL) |
1932 | ? gfc_default_integer_kind : mpz_get_si (kind->value.integer); | |
1933 | f->value.function.name | |
1934 | = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind); | |
6de9cd9a DN |
1935 | } |
1936 | ||
1937 | ||
0cd0559e TB |
1938 | void |
1939 | gfc_resolve_norm2 (gfc_expr *f, gfc_expr *array, gfc_expr *dim) | |
1940 | { | |
195a95c4 | 1941 | resolve_transformational ("norm2", f, array, dim, NULL); |
0cd0559e TB |
1942 | } |
1943 | ||
1944 | ||
6de9cd9a | 1945 | void |
b251af97 | 1946 | gfc_resolve_not (gfc_expr *f, gfc_expr *i) |
6de9cd9a | 1947 | { |
6de9cd9a DN |
1948 | f->ts = i->ts; |
1949 | f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind); | |
1950 | } | |
1951 | ||
1952 | ||
5d723e54 | 1953 | void |
b251af97 | 1954 | gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j) |
5d723e54 FXC |
1955 | { |
1956 | f->ts.type = i->ts.type; | |
b251af97 | 1957 | f->ts.kind = gfc_kind_max (i, j); |
5d723e54 FXC |
1958 | |
1959 | if (i->ts.kind != j->ts.kind) | |
1960 | { | |
b251af97 SK |
1961 | if (i->ts.kind == gfc_kind_max (i, j)) |
1962 | gfc_convert_type (j, &i->ts, 2); | |
5d723e54 | 1963 | else |
b251af97 | 1964 | gfc_convert_type (i, &j->ts, 2); |
5d723e54 FXC |
1965 | } |
1966 | ||
b251af97 SK |
1967 | f->value.function.name |
1968 | = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind); | |
5d723e54 FXC |
1969 | } |
1970 | ||
1971 | ||
6de9cd9a | 1972 | void |
b251af97 SK |
1973 | gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask, |
1974 | gfc_expr *vector ATTRIBUTE_UNUSED) | |
6de9cd9a | 1975 | { |
07368af0 PT |
1976 | if (array->ts.type == BT_CHARACTER && array->ref) |
1977 | gfc_resolve_substring_charlen (array); | |
1978 | ||
6de9cd9a DN |
1979 | f->ts = array->ts; |
1980 | f->rank = 1; | |
1981 | ||
870c06b9 | 1982 | resolve_mask_arg (mask); |
3b3620db TK |
1983 | |
1984 | if (mask->rank != 0) | |
d393bbd7 FXC |
1985 | { |
1986 | if (array->ts.type == BT_CHARACTER) | |
1987 | f->value.function.name | |
1988 | = array->ts.kind == 1 ? PREFIX ("pack_char") | |
1989 | : gfc_get_string | |
1990 | (PREFIX ("pack_char%d"), | |
1991 | array->ts.kind); | |
1992 | else | |
1993 | f->value.function.name = PREFIX ("pack"); | |
1994 | } | |
3b3620db | 1995 | else |
d393bbd7 FXC |
1996 | { |
1997 | if (array->ts.type == BT_CHARACTER) | |
1998 | f->value.function.name | |
1999 | = array->ts.kind == 1 ? PREFIX ("pack_s_char") | |
2000 | : gfc_get_string | |
2001 | (PREFIX ("pack_s_char%d"), | |
2002 | array->ts.kind); | |
2003 | else | |
2004 | f->value.function.name = PREFIX ("pack_s"); | |
2005 | } | |
6de9cd9a DN |
2006 | } |
2007 | ||
2008 | ||
0cd0559e TB |
2009 | void |
2010 | gfc_resolve_parity (gfc_expr *f, gfc_expr *array, gfc_expr *dim) | |
2011 | { | |
195a95c4 | 2012 | resolve_transformational ("parity", f, array, dim, NULL); |
0cd0559e TB |
2013 | } |
2014 | ||
2015 | ||
6de9cd9a | 2016 | void |
b251af97 SK |
2017 | gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim, |
2018 | gfc_expr *mask) | |
6de9cd9a | 2019 | { |
195a95c4 | 2020 | resolve_transformational ("product", f, array, dim, mask); |
6de9cd9a DN |
2021 | } |
2022 | ||
2023 | ||
32e7b05d TB |
2024 | void |
2025 | gfc_resolve_rank (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED) | |
2026 | { | |
2027 | f->ts.type = BT_INTEGER; | |
2028 | f->ts.kind = gfc_default_integer_kind; | |
2029 | f->value.function.name = gfc_get_string ("__rank"); | |
2030 | } | |
2031 | ||
2032 | ||
6de9cd9a | 2033 | void |
b251af97 | 2034 | gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind) |
6de9cd9a | 2035 | { |
6de9cd9a DN |
2036 | f->ts.type = BT_REAL; |
2037 | ||
2038 | if (kind != NULL) | |
2039 | f->ts.kind = mpz_get_si (kind->value.integer); | |
2040 | else | |
b251af97 SK |
2041 | f->ts.kind = (a->ts.type == BT_COMPLEX) |
2042 | ? a->ts.kind : gfc_default_real_kind; | |
6de9cd9a | 2043 | |
b251af97 SK |
2044 | f->value.function.name |
2045 | = gfc_get_string ("__real_%d_%c%d", f->ts.kind, | |
2046 | gfc_type_letter (a->ts.type), a->ts.kind); | |
6de9cd9a DN |
2047 | } |
2048 | ||
2049 | ||
6970fcc8 | 2050 | void |
b251af97 | 2051 | gfc_resolve_realpart (gfc_expr *f, gfc_expr *a) |
6970fcc8 SK |
2052 | { |
2053 | f->ts.type = BT_REAL; | |
2054 | f->ts.kind = a->ts.kind; | |
b251af97 SK |
2055 | f->value.function.name |
2056 | = gfc_get_string ("__real_%d_%c%d", f->ts.kind, | |
2057 | gfc_type_letter (a->ts.type), a->ts.kind); | |
6970fcc8 SK |
2058 | } |
2059 | ||
2060 | ||
f77b6ca3 | 2061 | void |
b251af97 SK |
2062 | gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED, |
2063 | gfc_expr *p2 ATTRIBUTE_UNUSED) | |
f77b6ca3 FXC |
2064 | { |
2065 | f->ts.type = BT_INTEGER; | |
2066 | f->ts.kind = gfc_default_integer_kind; | |
b251af97 | 2067 | f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind); |
f77b6ca3 FXC |
2068 | } |
2069 | ||
2070 | ||
6de9cd9a | 2071 | void |
b251af97 | 2072 | gfc_resolve_repeat (gfc_expr *f, gfc_expr *string, |
fabb6f8e | 2073 | gfc_expr *ncopies) |
6de9cd9a | 2074 | { |
fabb6f8e PT |
2075 | int len; |
2076 | gfc_expr *tmp; | |
6de9cd9a DN |
2077 | f->ts.type = BT_CHARACTER; |
2078 | f->ts.kind = string->ts.kind; | |
2079 | f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind); | |
fabb6f8e PT |
2080 | |
2081 | /* If possible, generate a character length. */ | |
2082 | if (f->ts.u.cl == NULL) | |
2083 | f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); | |
2084 | ||
2085 | tmp = NULL; | |
2086 | if (string->expr_type == EXPR_CONSTANT) | |
2087 | { | |
2088 | len = string->value.character.length; | |
2089 | tmp = gfc_get_int_expr (gfc_default_integer_kind, NULL , len); | |
2090 | } | |
2091 | else if (string->ts.u.cl && string->ts.u.cl->length) | |
2092 | { | |
2093 | tmp = gfc_copy_expr (string->ts.u.cl->length); | |
2094 | } | |
2095 | ||
2096 | if (tmp) | |
2097 | f->ts.u.cl->length = gfc_multiply (tmp, gfc_copy_expr (ncopies)); | |
6de9cd9a DN |
2098 | } |
2099 | ||
2100 | ||
2101 | void | |
b251af97 SK |
2102 | gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape, |
2103 | gfc_expr *pad ATTRIBUTE_UNUSED, | |
2104 | gfc_expr *order ATTRIBUTE_UNUSED) | |
6de9cd9a | 2105 | { |
6de9cd9a DN |
2106 | mpz_t rank; |
2107 | int kind; | |
2108 | int i; | |
2109 | ||
07368af0 PT |
2110 | if (source->ts.type == BT_CHARACTER && source->ref) |
2111 | gfc_resolve_substring_charlen (source); | |
2112 | ||
6de9cd9a DN |
2113 | f->ts = source->ts; |
2114 | ||
2115 | gfc_array_size (shape, &rank); | |
2116 | f->rank = mpz_get_si (rank); | |
2117 | mpz_clear (rank); | |
2118 | switch (source->ts.type) | |
2119 | { | |
2120 | case BT_COMPLEX: | |
6de9cd9a DN |
2121 | case BT_REAL: |
2122 | case BT_INTEGER: | |
2123 | case BT_LOGICAL: | |
d393bbd7 | 2124 | case BT_CHARACTER: |
6de9cd9a DN |
2125 | kind = source->ts.kind; |
2126 | break; | |
2127 | ||
2128 | default: | |
2129 | kind = 0; | |
2130 | break; | |
2131 | } | |
2132 | ||
2133 | switch (kind) | |
2134 | { | |
2135 | case 4: | |
2136 | case 8: | |
644cb69f FXC |
2137 | case 10: |
2138 | case 16: | |
ecebfb8b | 2139 | if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL) |
b251af97 SK |
2140 | f->value.function.name |
2141 | = gfc_get_string (PREFIX ("reshape_%c%d"), | |
2142 | gfc_type_letter (source->ts.type), | |
2143 | source->ts.kind); | |
d393bbd7 FXC |
2144 | else if (source->ts.type == BT_CHARACTER) |
2145 | f->value.function.name = gfc_get_string (PREFIX ("reshape_char%d"), | |
2146 | kind); | |
8f4dc7af | 2147 | else |
b251af97 SK |
2148 | f->value.function.name |
2149 | = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind); | |
6de9cd9a DN |
2150 | break; |
2151 | ||
2152 | default: | |
7823229b | 2153 | f->value.function.name = (source->ts.type == BT_CHARACTER |
d393bbd7 | 2154 | ? PREFIX ("reshape_char") : PREFIX ("reshape")); |
6de9cd9a DN |
2155 | break; |
2156 | } | |
2157 | ||
7c42966e | 2158 | if (shape->expr_type == EXPR_ARRAY && gfc_is_constant_expr (shape)) |
6de9cd9a DN |
2159 | { |
2160 | gfc_constructor *c; | |
2161 | f->shape = gfc_get_shape (f->rank); | |
b7e75771 | 2162 | c = gfc_constructor_first (shape->value.constructor); |
6de9cd9a DN |
2163 | for (i = 0; i < f->rank; i++) |
2164 | { | |
2165 | mpz_init_set (f->shape[i], c->expr->value.integer); | |
b7e75771 | 2166 | c = gfc_constructor_next (c); |
6de9cd9a DN |
2167 | } |
2168 | } | |
323c74da RH |
2169 | |
2170 | /* Force-convert both SHAPE and ORDER to index_kind so that we don't need | |
2171 | so many runtime variations. */ | |
2172 | if (shape->ts.kind != gfc_index_integer_kind) | |
2173 | { | |
2174 | gfc_typespec ts = shape->ts; | |
2175 | ts.kind = gfc_index_integer_kind; | |
2176 | gfc_convert_type_warn (shape, &ts, 2, 0); | |
2177 | } | |
2178 | if (order && order->ts.kind != gfc_index_integer_kind) | |
2179 | gfc_convert_type_warn (order, &shape->ts, 2, 0); | |
6de9cd9a DN |
2180 | } |
2181 | ||
2182 | ||
2183 | void | |
b251af97 | 2184 | gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 2185 | { |
6de9cd9a DN |
2186 | f->ts = x->ts; |
2187 | f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind); | |
2188 | } | |
2189 | ||
2190 | ||
2191 | void | |
b5a4419c | 2192 | gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED) |
6de9cd9a | 2193 | { |
6de9cd9a | 2194 | f->ts = x->ts; |
49e4d580 | 2195 | f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind); |
6de9cd9a DN |
2196 | } |
2197 | ||
2198 | ||
2199 | void | |
b251af97 SK |
2200 | gfc_resolve_scan (gfc_expr *f, gfc_expr *string, |
2201 | gfc_expr *set ATTRIBUTE_UNUSED, | |
5cda5098 | 2202 | gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind) |
6de9cd9a | 2203 | { |
6de9cd9a | 2204 | f->ts.type = BT_INTEGER; |
5cda5098 FXC |
2205 | if (kind) |
2206 | f->ts.kind = mpz_get_si (kind->value.integer); | |
2207 | else | |
2208 | f->ts.kind = gfc_default_integer_kind; | |
6de9cd9a DN |
2209 | f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind); |
2210 | } | |
2211 | ||
2212 | ||
53096259 | 2213 | void |
b251af97 | 2214 | gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0) |
53096259 PT |
2215 | { |
2216 | t1->ts = t0->ts; | |
b251af97 | 2217 | t1->value.function.name = gfc_get_string (PREFIX ("secnds")); |
53096259 PT |
2218 | } |
2219 | ||
2220 | ||
6de9cd9a | 2221 | void |
b5a4419c FXC |
2222 | gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x, |
2223 | gfc_expr *i ATTRIBUTE_UNUSED) | |
6de9cd9a | 2224 | { |
6de9cd9a | 2225 | f->ts = x->ts; |
49e4d580 | 2226 | f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind); |
6de9cd9a DN |
2227 | } |
2228 | ||
2229 | ||
2230 | void | |
7320cf09 | 2231 | gfc_resolve_shape (gfc_expr *f, gfc_expr *array, gfc_expr *kind) |
6de9cd9a | 2232 | { |
6de9cd9a | 2233 | f->ts.type = BT_INTEGER; |
7320cf09 TB |
2234 | |
2235 | if (kind) | |
2236 | f->ts.kind = mpz_get_si (kind->value.integer); | |
2237 | else | |
2238 | f->ts.kind = gfc_default_integer_kind; | |
2239 | ||
6de9cd9a | 2240 | f->rank = 1; |
d357d991 MM |
2241 | if (array->rank != -1) |
2242 | { | |
2243 | f->shape = gfc_get_shape (1); | |
2244 | mpz_init_set_ui (f->shape[0], array->rank); | |
2245 | } | |
2246 | ||
b251af97 | 2247 | f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind); |
6de9cd9a DN |
2248 | } |
2249 | ||
2250 | ||
88a95a11 FXC |
2251 | void |
2252 | gfc_resolve_shift (gfc_expr *f, gfc_expr *i, gfc_expr *shift ATTRIBUTE_UNUSED) | |
2253 | { | |
2254 | f->ts = i->ts; | |
2255 | if (f->value.function.isym->id == GFC_ISYM_SHIFTA) | |
2256 | f->value.function.name = gfc_get_string ("shifta_i%d", f->ts.kind); | |
2257 | else if (f->value.function.isym->id == GFC_ISYM_SHIFTL) | |
2258 | f->value.function.name = gfc_get_string ("shiftl_i%d", f->ts.kind); | |
2259 | else if (f->value.function.isym->id == GFC_ISYM_SHIFTR) | |
2260 | f->value.function.name = gfc_get_string ("shiftr_i%d", f->ts.kind); | |
2261 | else | |
2262 | gcc_unreachable (); | |
2263 | } | |
2264 | ||
2265 | ||
6de9cd9a | 2266 | void |
b251af97 | 2267 | gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED) |
6de9cd9a | 2268 | { |
6de9cd9a | 2269 | f->ts = a->ts; |
b251af97 SK |
2270 | f->value.function.name |
2271 | = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind); | |
6de9cd9a DN |
2272 | } |
2273 | ||
2274 | ||
185d7d97 | 2275 | void |
b251af97 | 2276 | gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler) |
185d7d97 FXC |
2277 | { |
2278 | f->ts.type = BT_INTEGER; | |
2279 | f->ts.kind = gfc_c_int_kind; | |
2280 | ||
2281 | /* handler can be either BT_INTEGER or BT_PROCEDURE */ | |
2282 | if (handler->ts.type == BT_INTEGER) | |
2283 | { | |
2284 | if (handler->ts.kind != gfc_c_int_kind) | |
2285 | gfc_convert_type (handler, &f->ts, 2); | |
b251af97 | 2286 | f->value.function.name = gfc_get_string (PREFIX ("signal_func_int")); |
185d7d97 FXC |
2287 | } |
2288 | else | |
b251af97 | 2289 | f->value.function.name = gfc_get_string (PREFIX ("signal_func")); |
185d7d97 FXC |
2290 | |
2291 | if (number->ts.kind != gfc_c_int_kind) | |
2292 | gfc_convert_type (number, &f->ts, 2); | |
2293 | } | |
2294 | ||
2295 | ||
6de9cd9a | 2296 | void |
b251af97 | 2297 | gfc_resolve_sin (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 2298 | { |
6de9cd9a | 2299 | f->ts = x->ts; |
b251af97 SK |
2300 | f->value.function.name |
2301 | = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind); | |
6de9cd9a DN |
2302 | } |
2303 | ||
2304 | ||
2305 | void | |
b251af97 | 2306 | gfc_resolve_sinh (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 2307 | { |
6de9cd9a | 2308 | f->ts = x->ts; |
b251af97 SK |
2309 | f->value.function.name |
2310 | = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind); | |
6de9cd9a DN |
2311 | } |
2312 | ||
2313 | ||
5cda5098 FXC |
2314 | void |
2315 | gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED, | |
2316 | gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind) | |
2317 | { | |
2318 | f->ts.type = BT_INTEGER; | |
2319 | if (kind) | |
2320 | f->ts.kind = mpz_get_si (kind->value.integer); | |
2321 | else | |
2322 | f->ts.kind = gfc_default_integer_kind; | |
2323 | } | |
2324 | ||
2325 | ||
0881224e TB |
2326 | void |
2327 | gfc_resolve_stride (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED, | |
2328 | gfc_expr *dim ATTRIBUTE_UNUSED) | |
2329 | { | |
2330 | f->ts.type = BT_INTEGER; | |
2331 | f->ts.kind = gfc_index_integer_kind; | |
2332 | } | |
2333 | ||
2334 | ||
6de9cd9a | 2335 | void |
b251af97 | 2336 | gfc_resolve_spacing (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 2337 | { |
6de9cd9a DN |
2338 | f->ts = x->ts; |
2339 | f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind); | |
2340 | } | |
2341 | ||
2342 | ||
2343 | void | |
b251af97 SK |
2344 | gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim, |
2345 | gfc_expr *ncopies) | |
6de9cd9a | 2346 | { |
07368af0 PT |
2347 | if (source->ts.type == BT_CHARACTER && source->ref) |
2348 | gfc_resolve_substring_charlen (source); | |
2349 | ||
2853e512 PT |
2350 | if (source->ts.type == BT_CHARACTER) |
2351 | check_charlen_present (source); | |
2352 | ||
6de9cd9a DN |
2353 | f->ts = source->ts; |
2354 | f->rank = source->rank + 1; | |
2853e512 | 2355 | if (source->rank == 0) |
d393bbd7 FXC |
2356 | { |
2357 | if (source->ts.type == BT_CHARACTER) | |
2358 | f->value.function.name | |
2359 | = source->ts.kind == 1 ? PREFIX ("spread_char_scalar") | |
2360 | : gfc_get_string | |
2361 | (PREFIX ("spread_char%d_scalar"), | |
2362 | source->ts.kind); | |
2363 | else | |
2364 | f->value.function.name = PREFIX ("spread_scalar"); | |
2365 | } | |
2853e512 | 2366 | else |
d393bbd7 FXC |
2367 | { |
2368 | if (source->ts.type == BT_CHARACTER) | |
2369 | f->value.function.name | |
2370 | = source->ts.kind == 1 ? PREFIX ("spread_char") | |
2371 | : gfc_get_string | |
2372 | (PREFIX ("spread_char%d"), | |
2373 | source->ts.kind); | |
2374 | else | |
2375 | f->value.function.name = PREFIX ("spread"); | |
2376 | } | |
6de9cd9a | 2377 | |
80f2bb6e | 2378 | if (dim && gfc_is_constant_expr (dim) |
b251af97 | 2379 | && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0]) |
80f2bb6e PT |
2380 | { |
2381 | int i, idim; | |
2382 | idim = mpz_get_ui (dim->value.integer); | |
2383 | f->shape = gfc_get_shape (f->rank); | |
2384 | for (i = 0; i < (idim - 1); i++) | |
2385 | mpz_init_set (f->shape[i], source->shape[i]); | |
2386 | ||
2387 | mpz_init_set (f->shape[idim - 1], ncopies->value.integer); | |
2388 | ||
2389 | for (i = idim; i < f->rank ; i++) | |
2390 | mpz_init_set (f->shape[i], source->shape[i-1]); | |
2391 | } | |
2392 | ||
2393 | ||
bf302220 | 2394 | gfc_resolve_dim_arg (dim); |
6de9cd9a DN |
2395 | gfc_resolve_index (ncopies, 1); |
2396 | } | |
2397 | ||
2398 | ||
2399 | void | |
b251af97 | 2400 | gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 2401 | { |
6de9cd9a | 2402 | f->ts = x->ts; |
b251af97 SK |
2403 | f->value.function.name |
2404 | = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind); | |
6de9cd9a DN |
2405 | } |
2406 | ||
2407 | ||
df65f093 SK |
2408 | /* Resolve the g77 compatibility function STAT AND FSTAT. */ |
2409 | ||
2410 | void | |
b251af97 SK |
2411 | gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED, |
2412 | gfc_expr *a ATTRIBUTE_UNUSED) | |
df65f093 | 2413 | { |
df65f093 SK |
2414 | f->ts.type = BT_INTEGER; |
2415 | f->ts.kind = gfc_default_integer_kind; | |
b251af97 | 2416 | f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind); |
df65f093 SK |
2417 | } |
2418 | ||
2419 | ||
bf3fb7e4 | 2420 | void |
b251af97 SK |
2421 | gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED, |
2422 | gfc_expr *a ATTRIBUTE_UNUSED) | |
bf3fb7e4 FXC |
2423 | { |
2424 | f->ts.type = BT_INTEGER; | |
2425 | f->ts.kind = gfc_default_integer_kind; | |
b251af97 | 2426 | f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind); |
bf3fb7e4 FXC |
2427 | } |
2428 | ||
2429 | ||
df65f093 | 2430 | void |
b251af97 | 2431 | gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED) |
df65f093 | 2432 | { |
df65f093 SK |
2433 | f->ts.type = BT_INTEGER; |
2434 | f->ts.kind = gfc_default_integer_kind; | |
2435 | if (n->ts.kind != f->ts.kind) | |
2436 | gfc_convert_type (n, &f->ts, 2); | |
2437 | ||
b251af97 | 2438 | f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind); |
df65f093 SK |
2439 | } |
2440 | ||
2441 | ||
5d723e54 | 2442 | void |
b251af97 | 2443 | gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED) |
5d723e54 FXC |
2444 | { |
2445 | gfc_typespec ts; | |
4af63337 | 2446 | gfc_clear_ts (&ts); |
5d723e54 FXC |
2447 | |
2448 | f->ts.type = BT_INTEGER; | |
2449 | f->ts.kind = gfc_c_int_kind; | |
2450 | if (u->ts.kind != gfc_c_int_kind) | |
2451 | { | |
2452 | ts.type = BT_INTEGER; | |
2453 | ts.kind = gfc_c_int_kind; | |
bc21d315 JW |
2454 | ts.u.derived = NULL; |
2455 | ts.u.cl = NULL; | |
5d723e54 FXC |
2456 | gfc_convert_type (u, &ts, 2); |
2457 | } | |
2458 | ||
b251af97 | 2459 | f->value.function.name = gfc_get_string (PREFIX ("fgetc")); |
5d723e54 FXC |
2460 | } |
2461 | ||
2462 | ||
2463 | void | |
b251af97 | 2464 | gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED) |
5d723e54 FXC |
2465 | { |
2466 | f->ts.type = BT_INTEGER; | |
2467 | f->ts.kind = gfc_c_int_kind; | |
b251af97 | 2468 | f->value.function.name = gfc_get_string (PREFIX ("fget")); |
5d723e54 FXC |
2469 | } |
2470 | ||
2471 | ||
2472 | void | |
b251af97 | 2473 | gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED) |
5d723e54 FXC |
2474 | { |
2475 | gfc_typespec ts; | |
4af63337 | 2476 | gfc_clear_ts (&ts); |
5d723e54 FXC |
2477 | |
2478 | f->ts.type = BT_INTEGER; | |
2479 | f->ts.kind = gfc_c_int_kind; | |
2480 | if (u->ts.kind != gfc_c_int_kind) | |
2481 | { | |
2482 | ts.type = BT_INTEGER; | |
2483 | ts.kind = gfc_c_int_kind; | |
bc21d315 JW |
2484 | ts.u.derived = NULL; |
2485 | ts.u.cl = NULL; | |
5d723e54 FXC |
2486 | gfc_convert_type (u, &ts, 2); |
2487 | } | |
2488 | ||
b251af97 | 2489 | f->value.function.name = gfc_get_string (PREFIX ("fputc")); |
5d723e54 FXC |
2490 | } |
2491 | ||
2492 | ||
2493 | void | |
b251af97 | 2494 | gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED) |
5d723e54 FXC |
2495 | { |
2496 | f->ts.type = BT_INTEGER; | |
2497 | f->ts.kind = gfc_c_int_kind; | |
b251af97 | 2498 | f->value.function.name = gfc_get_string (PREFIX ("fput")); |
5d723e54 FXC |
2499 | } |
2500 | ||
2501 | ||
2502 | void | |
b251af97 | 2503 | gfc_resolve_ftell (gfc_expr *f, gfc_expr *u) |
5d723e54 FXC |
2504 | { |
2505 | gfc_typespec ts; | |
4af63337 | 2506 | gfc_clear_ts (&ts); |
5d723e54 FXC |
2507 | |
2508 | f->ts.type = BT_INTEGER; | |
67eb28c8 | 2509 | f->ts.kind = gfc_intio_kind; |
5d723e54 FXC |
2510 | if (u->ts.kind != gfc_c_int_kind) |
2511 | { | |
2512 | ts.type = BT_INTEGER; | |
2513 | ts.kind = gfc_c_int_kind; | |
bc21d315 JW |
2514 | ts.u.derived = NULL; |
2515 | ts.u.cl = NULL; | |
5d723e54 FXC |
2516 | gfc_convert_type (u, &ts, 2); |
2517 | } | |
2518 | ||
67eb28c8 | 2519 | f->value.function.name = gfc_get_string (PREFIX ("ftell2")); |
5d723e54 FXC |
2520 | } |
2521 | ||
2522 | ||
048510c8 JW |
2523 | void |
2524 | gfc_resolve_storage_size (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED, | |
2525 | gfc_expr *kind) | |
2526 | { | |
2527 | f->ts.type = BT_INTEGER; | |
2528 | if (kind) | |
2529 | f->ts.kind = mpz_get_si (kind->value.integer); | |
2530 | else | |
2531 | f->ts.kind = gfc_default_integer_kind; | |
2532 | } | |
2533 | ||
2534 | ||
6de9cd9a | 2535 | void |
b251af97 | 2536 | gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask) |
6de9cd9a | 2537 | { |
195a95c4 | 2538 | resolve_transformational ("sum", f, array, dim, mask); |
6de9cd9a DN |
2539 | } |
2540 | ||
2541 | ||
f77b6ca3 | 2542 | void |
b251af97 SK |
2543 | gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED, |
2544 | gfc_expr *p2 ATTRIBUTE_UNUSED) | |
f77b6ca3 FXC |
2545 | { |
2546 | f->ts.type = BT_INTEGER; | |
2547 | f->ts.kind = gfc_default_integer_kind; | |
b251af97 | 2548 | f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind); |
f77b6ca3 FXC |
2549 | } |
2550 | ||
2551 | ||
5b1374e9 TS |
2552 | /* Resolve the g77 compatibility function SYSTEM. */ |
2553 | ||
2554 | void | |
b251af97 | 2555 | gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED) |
5b1374e9 TS |
2556 | { |
2557 | f->ts.type = BT_INTEGER; | |
2558 | f->ts.kind = 4; | |
b251af97 | 2559 | f->value.function.name = gfc_get_string (PREFIX ("system")); |
5b1374e9 TS |
2560 | } |
2561 | ||
2562 | ||
6de9cd9a | 2563 | void |
b251af97 | 2564 | gfc_resolve_tan (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 2565 | { |
6de9cd9a | 2566 | f->ts = x->ts; |
b251af97 SK |
2567 | f->value.function.name |
2568 | = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind); | |
6de9cd9a DN |
2569 | } |
2570 | ||
2571 | ||
2572 | void | |
b251af97 | 2573 | gfc_resolve_tanh (gfc_expr *f, gfc_expr *x) |
6de9cd9a | 2574 | { |
6de9cd9a | 2575 | f->ts = x->ts; |
b251af97 SK |
2576 | f->value.function.name |
2577 | = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind); | |
6de9cd9a DN |
2578 | } |
2579 | ||
2580 | ||
0d6d8e00 TB |
2581 | void |
2582 | gfc_resolve_image_index (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED, | |
2583 | gfc_expr *sub ATTRIBUTE_UNUSED) | |
2584 | { | |
5af07930 TB |
2585 | static char image_index[] = "__image_index"; |
2586 | f->ts.type = BT_INTEGER; | |
0d6d8e00 | 2587 | f->ts.kind = gfc_default_integer_kind; |
5af07930 | 2588 | f->value.function.name = image_index; |
0d6d8e00 TB |
2589 | } |
2590 | ||
2591 | ||
2592 | void | |
2593 | gfc_resolve_this_image (gfc_expr *f, gfc_expr *array, gfc_expr *dim) | |
2594 | { | |
60386f50 TB |
2595 | static char this_image[] = "__this_image"; |
2596 | if (array) | |
2597 | resolve_bound (f, array, dim, NULL, "__this_image", true); | |
2598 | else | |
2599 | { | |
2600 | f->ts.type = BT_INTEGER; | |
2601 | f->ts.kind = gfc_default_integer_kind; | |
2602 | f->value.function.name = this_image; | |
2603 | } | |
0d6d8e00 TB |
2604 | } |
2605 | ||
2606 | ||
f77b6ca3 | 2607 | void |
b251af97 | 2608 | gfc_resolve_time (gfc_expr *f) |
f77b6ca3 FXC |
2609 | { |
2610 | f->ts.type = BT_INTEGER; | |
2611 | f->ts.kind = 4; | |
b251af97 | 2612 | f->value.function.name = gfc_get_string (PREFIX ("time_func")); |
f77b6ca3 FXC |
2613 | } |
2614 | ||
2615 | ||
2616 | void | |
b251af97 | 2617 | gfc_resolve_time8 (gfc_expr *f) |
f77b6ca3 FXC |
2618 | { |
2619 | f->ts.type = BT_INTEGER; | |
2620 | f->ts.kind = 8; | |
b251af97 | 2621 | f->value.function.name = gfc_get_string (PREFIX ("time8_func")); |
f77b6ca3 FXC |
2622 | } |
2623 | ||
2624 | ||
6de9cd9a | 2625 | void |
b251af97 SK |
2626 | gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED, |
2627 | gfc_expr *mold, gfc_expr *size) | |
6de9cd9a DN |
2628 | { |
2629 | /* TODO: Make this do something meaningful. */ | |
2630 | static char transfer0[] = "__transfer0", transfer1[] = "__transfer1"; | |
2631 | ||
fd1e840d | 2632 | if (mold->ts.type == BT_CHARACTER |
bc21d315 | 2633 | && !mold->ts.u.cl->length |
fd1e840d PT |
2634 | && gfc_is_constant_expr (mold)) |
2635 | { | |
2636 | int len; | |
2637 | if (mold->expr_type == EXPR_CONSTANT) | |
b7e75771 JD |
2638 | { |
2639 | len = mold->value.character.length; | |
2640 | mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, | |
2641 | NULL, len); | |
2642 | } | |
fd1e840d PT |
2643 | else |
2644 | { | |
b7e75771 JD |
2645 | gfc_constructor *c = gfc_constructor_first (mold->value.constructor); |
2646 | len = c->expr->value.character.length; | |
2647 | mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, | |
2648 | NULL, len); | |
fd1e840d PT |
2649 | } |
2650 | } | |
6f535271 | 2651 | |
6de9cd9a DN |
2652 | f->ts = mold->ts; |
2653 | ||
2654 | if (size == NULL && mold->rank == 0) | |
2655 | { | |
2656 | f->rank = 0; | |
2657 | f->value.function.name = transfer0; | |
2658 | } | |
2659 | else | |
2660 | { | |
2661 | f->rank = 1; | |
2662 | f->value.function.name = transfer1; | |
e15e9be3 PT |
2663 | if (size && gfc_is_constant_expr (size)) |
2664 | { | |
2665 | f->shape = gfc_get_shape (1); | |
2666 | mpz_init_set (f->shape[0], size->value.integer); | |
2667 | } | |
6de9cd9a DN |
2668 | } |
2669 | } | |
2670 | ||
2671 | ||
2672 | void | |
b251af97 | 2673 | gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix) |
6de9cd9a | 2674 | { |
07368af0 PT |
2675 | |
2676 | if (matrix->ts.type == BT_CHARACTER && matrix->ref) | |
2677 | gfc_resolve_substring_charlen (matrix); | |
2678 | ||
6de9cd9a DN |
2679 | f->ts = matrix->ts; |
2680 | f->rank = 2; | |
94538bd1 VL |
2681 | if (matrix->shape) |
2682 | { | |
2683 | f->shape = gfc_get_shape (2); | |
2684 | mpz_init_set (f->shape[0], matrix->shape[1]); | |
2685 | mpz_init_set (f->shape[1], matrix->shape[0]); | |
2686 | } | |
6de9cd9a | 2687 | |
ecebfb8b | 2688 | switch (matrix->ts.kind) |
6de9cd9a DN |
2689 | { |
2690 | case 4: | |
2691 | case 8: | |
644cb69f FXC |
2692 | case 10: |
2693 | case 16: | |
58757957 | 2694 | switch (matrix->ts.type) |
b251af97 SK |
2695 | { |
2696 | case BT_REAL: | |
2697 | case BT_COMPLEX: | |
2698 | f->value.function.name | |
2699 | = gfc_get_string (PREFIX ("transpose_%c%d"), | |
2700 | gfc_type_letter (matrix->ts.type), | |
2701 | matrix->ts.kind); | |
2702 | break; | |
2703 | ||
2704 | case BT_INTEGER: | |
2705 | case BT_LOGICAL: | |
58757957 JM |
2706 | /* Use the integer routines for real and logical cases. This |
2707 | assumes they all have the same alignment requirements. */ | |
b251af97 SK |
2708 | f->value.function.name |
2709 | = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind); | |
2710 | break; | |
2711 | ||
2712 | default: | |
d393bbd7 FXC |
2713 | if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4) |
2714 | f->value.function.name = PREFIX ("transpose_char4"); | |
2715 | else | |
2716 | f->value.function.name = PREFIX ("transpose"); | |
b251af97 SK |
2717 | break; |
2718 | } | |
6de9cd9a DN |
2719 | break; |
2720 | ||
2721 | default: | |
7823229b | 2722 | f->value.function.name = (matrix->ts.type == BT_CHARACTER |
b251af97 SK |
2723 | ? PREFIX ("transpose_char") |
2724 | : PREFIX ("transpose")); | |
7823229b | 2725 | break; |
6de9cd9a DN |
2726 | } |
2727 | } | |
2728 | ||
2729 | ||
2730 | void | |
b251af97 | 2731 | gfc_resolve_trim (gfc_expr *f, gfc_expr *string) |
6de9cd9a | 2732 | { |
6de9cd9a DN |
2733 | f->ts.type = BT_CHARACTER; |
2734 | f->ts.kind = string->ts.kind; | |
2735 | f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind); | |
2736 | } | |
2737 | ||
2738 | ||
2739 | void | |
5cda5098 | 2740 | gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind) |
6de9cd9a | 2741 | { |
7aa0849a | 2742 | resolve_bound (f, array, dim, kind, "__ubound", false); |
0d6d8e00 | 2743 | } |
6de9cd9a | 2744 | |
94538bd1 | 2745 | |
0d6d8e00 TB |
2746 | void |
2747 | gfc_resolve_ucobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind) | |
2748 | { | |
7aa0849a | 2749 | resolve_bound (f, array, dim, kind, "__ucobound", true); |
6de9cd9a DN |
2750 | } |
2751 | ||
2752 | ||
d8fe26b2 SK |
2753 | /* Resolve the g77 compatibility function UMASK. */ |
2754 | ||
2755 | void | |
b251af97 | 2756 | gfc_resolve_umask (gfc_expr *f, gfc_expr *n) |
d8fe26b2 | 2757 | { |
d8fe26b2 SK |
2758 | f->ts.type = BT_INTEGER; |
2759 | f->ts.kind = n->ts.kind; | |
b251af97 | 2760 | f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind); |
d8fe26b2 SK |
2761 | } |
2762 | ||
2763 | ||
2764 | /* Resolve the g77 compatibility function UNLINK. */ | |
2765 | ||
2766 | void | |
b251af97 | 2767 | gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED) |
d8fe26b2 | 2768 | { |
d8fe26b2 SK |
2769 | f->ts.type = BT_INTEGER; |
2770 | f->ts.kind = 4; | |
b251af97 | 2771 | f->value.function.name = gfc_get_string (PREFIX ("unlink")); |
d8fe26b2 SK |
2772 | } |
2773 | ||
25fc05eb FXC |
2774 | |
2775 | void | |
b251af97 | 2776 | gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit) |
25fc05eb FXC |
2777 | { |
2778 | gfc_typespec ts; | |
4af63337 | 2779 | gfc_clear_ts (&ts); |
25fc05eb FXC |
2780 | |
2781 | f->ts.type = BT_CHARACTER; | |
2782 | f->ts.kind = gfc_default_character_kind; | |
2783 | ||
2784 | if (unit->ts.kind != gfc_c_int_kind) | |
2785 | { | |
2786 | ts.type = BT_INTEGER; | |
2787 | ts.kind = gfc_c_int_kind; | |
bc21d315 JW |
2788 | ts.u.derived = NULL; |
2789 | ts.u.cl = NULL; | |
25fc05eb FXC |
2790 | gfc_convert_type (unit, &ts, 2); |
2791 | } | |
2792 | ||
b251af97 | 2793 | f->value.function.name = gfc_get_string (PREFIX ("ttynam")); |
25fc05eb FXC |
2794 | } |
2795 | ||
2796 | ||
6de9cd9a | 2797 | void |
b251af97 SK |
2798 | gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask, |
2799 | gfc_expr *field ATTRIBUTE_UNUSED) | |
6de9cd9a | 2800 | { |
07368af0 PT |
2801 | if (vector->ts.type == BT_CHARACTER && vector->ref) |
2802 | gfc_resolve_substring_charlen (vector); | |
2803 | ||
7823229b | 2804 | f->ts = vector->ts; |
6de9cd9a | 2805 | f->rank = mask->rank; |
870c06b9 | 2806 | resolve_mask_arg (mask); |
3b3620db | 2807 | |
d393bbd7 FXC |
2808 | if (vector->ts.type == BT_CHARACTER) |
2809 | { | |
2810 | if (vector->ts.kind == 1) | |
2811 | f->value.function.name | |
2812 | = gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0); | |
2813 | else | |
2814 | f->value.function.name | |
2815 | = gfc_get_string (PREFIX ("unpack%d_char%d"), | |
2816 | field->rank > 0 ? 1 : 0, vector->ts.kind); | |
2817 | } | |
2818 | else | |
2819 | f->value.function.name | |
2820 | = gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0); | |
6de9cd9a DN |
2821 | } |
2822 | ||
2823 | ||
2824 | void | |
b251af97 SK |
2825 | gfc_resolve_verify (gfc_expr *f, gfc_expr *string, |
2826 | gfc_expr *set ATTRIBUTE_UNUSED, | |
5cda5098 | 2827 | gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind) |
6de9cd9a | 2828 | { |
6de9cd9a | 2829 | f->ts.type = BT_INTEGER; |
5cda5098 FXC |
2830 | if (kind) |
2831 | f->ts.kind = mpz_get_si (kind->value.integer); | |
2832 | else | |
2833 | f->ts.kind = gfc_default_integer_kind; | |
6de9cd9a DN |
2834 | f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind); |
2835 | } | |
2836 | ||
2837 | ||
5d723e54 | 2838 | void |
b251af97 | 2839 | gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j) |
5d723e54 FXC |
2840 | { |
2841 | f->ts.type = i->ts.type; | |
b251af97 | 2842 | f->ts.kind = gfc_kind_max (i, j); |
5d723e54 FXC |
2843 | |
2844 | if (i->ts.kind != j->ts.kind) | |
2845 | { | |
b251af97 SK |
2846 | if (i->ts.kind == gfc_kind_max (i, j)) |
2847 | gfc_convert_type (j, &i->ts, 2); | |
5d723e54 | 2848 | else |
b251af97 | 2849 | gfc_convert_type (i, &j->ts, 2); |
5d723e54 FXC |
2850 | } |
2851 | ||
b251af97 SK |
2852 | f->value.function.name |
2853 | = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind); | |
5d723e54 FXC |
2854 | } |
2855 | ||
2856 | ||
6de9cd9a DN |
2857 | /* Intrinsic subroutine resolution. */ |
2858 | ||
185d7d97 | 2859 | void |
b251af97 | 2860 | gfc_resolve_alarm_sub (gfc_code *c) |
185d7d97 FXC |
2861 | { |
2862 | const char *name; | |
c4fae39e | 2863 | gfc_expr *seconds, *handler; |
185d7d97 | 2864 | gfc_typespec ts; |
4af63337 | 2865 | gfc_clear_ts (&ts); |
185d7d97 FXC |
2866 | |
2867 | seconds = c->ext.actual->expr; | |
2868 | handler = c->ext.actual->next->expr; | |
185d7d97 FXC |
2869 | ts.type = BT_INTEGER; |
2870 | ts.kind = gfc_c_int_kind; | |
2871 | ||
19c222f8 FXC |
2872 | /* handler can be either BT_INTEGER or BT_PROCEDURE. |
2873 | In all cases, the status argument is of default integer kind | |
2874 | (enforced in check.c) so that the function suffix is fixed. */ | |
185d7d97 FXC |
2875 | if (handler->ts.type == BT_INTEGER) |
2876 | { | |
2877 | if (handler->ts.kind != gfc_c_int_kind) | |
2878 | gfc_convert_type (handler, &ts, 2); | |
19c222f8 FXC |
2879 | name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"), |
2880 | gfc_default_integer_kind); | |
185d7d97 FXC |
2881 | } |
2882 | else | |
19c222f8 FXC |
2883 | name = gfc_get_string (PREFIX ("alarm_sub_i%d"), |
2884 | gfc_default_integer_kind); | |
185d7d97 FXC |
2885 | |
2886 | if (seconds->ts.kind != gfc_c_int_kind) | |
2887 | gfc_convert_type (seconds, &ts, 2); | |
185d7d97 FXC |
2888 | |
2889 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); | |
2890 | } | |
2891 | ||
6de9cd9a | 2892 | void |
b251af97 | 2893 | gfc_resolve_cpu_time (gfc_code *c) |
6de9cd9a DN |
2894 | { |
2895 | const char *name; | |
b251af97 | 2896 | name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind); |
6de9cd9a DN |
2897 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
2898 | } | |
2899 | ||
2900 | ||
12f681a0 DK |
2901 | /* Create a formal arglist based on an actual one and set the INTENTs given. */ |
2902 | ||
2903 | static gfc_formal_arglist* | |
2904 | create_formal_for_intents (gfc_actual_arglist* actual, const sym_intent* ints) | |
2905 | { | |
2906 | gfc_formal_arglist* head; | |
2907 | gfc_formal_arglist* tail; | |
2908 | int i; | |
2909 | ||
2910 | if (!actual) | |
2911 | return NULL; | |
2912 | ||
2913 | head = tail = gfc_get_formal_arglist (); | |
2914 | for (i = 0; actual; actual = actual->next, tail = tail->next, ++i) | |
2915 | { | |
2916 | gfc_symbol* sym; | |
2917 | ||
2918 | sym = gfc_new_symbol ("dummyarg", NULL); | |
2919 | sym->ts = actual->expr->ts; | |
2920 | ||
2921 | sym->attr.intent = ints[i]; | |
2922 | tail->sym = sym; | |
2923 | ||
2924 | if (actual->next) | |
2925 | tail->next = gfc_get_formal_arglist (); | |
2926 | } | |
2927 | ||
2928 | return head; | |
2929 | } | |
2930 | ||
2931 | ||
da661a58 TB |
2932 | void |
2933 | gfc_resolve_atomic_def (gfc_code *c) | |
2934 | { | |
2935 | const char *name = "atomic_define"; | |
2936 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); | |
2937 | } | |
2938 | ||
2939 | ||
2940 | void | |
2941 | gfc_resolve_atomic_ref (gfc_code *c) | |
2942 | { | |
2943 | const char *name = "atomic_ref"; | |
2944 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); | |
2945 | } | |
2946 | ||
2947 | ||
ee569894 | 2948 | void |
b251af97 | 2949 | gfc_resolve_mvbits (gfc_code *c) |
ee569894 | 2950 | { |
12f681a0 DK |
2951 | static const sym_intent INTENTS[] = {INTENT_IN, INTENT_IN, INTENT_IN, |
2952 | INTENT_INOUT, INTENT_IN}; | |
2953 | ||
ee569894 | 2954 | const char *name; |
37058415 | 2955 | gfc_typespec ts; |
4af63337 | 2956 | gfc_clear_ts (&ts); |
37058415 FXC |
2957 | |
2958 | /* FROMPOS, LEN and TOPOS are restricted to small values. As such, | |
2959 | they will be converted so that they fit into a C int. */ | |
2960 | ts.type = BT_INTEGER; | |
2961 | ts.kind = gfc_c_int_kind; | |
2962 | if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind) | |
2963 | gfc_convert_type (c->ext.actual->next->expr, &ts, 2); | |
2964 | if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind) | |
2965 | gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2); | |
2966 | if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind) | |
2967 | gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2); | |
2968 | ||
2969 | /* TO and FROM are guaranteed to have the same kind parameter. */ | |
2970 | name = gfc_get_string (PREFIX ("mvbits_i%d"), | |
2971 | c->ext.actual->expr->ts.kind); | |
ee569894 | 2972 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
42a8c358 TB |
2973 | /* Mark as elemental subroutine as this does not happen automatically. */ |
2974 | c->resolved_sym->attr.elemental = 1; | |
12f681a0 DK |
2975 | |
2976 | /* Create a dummy formal arglist so the INTENTs are known later for purpose | |
2977 | of creating temporaries. */ | |
2978 | c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS); | |
ee569894 TS |
2979 | } |
2980 | ||
2981 | ||
6de9cd9a | 2982 | void |
b251af97 | 2983 | gfc_resolve_random_number (gfc_code *c) |
6de9cd9a DN |
2984 | { |
2985 | const char *name; | |
2986 | int kind; | |
2987 | ||
2988 | kind = c->ext.actual->expr->ts.kind; | |
5f251c26 | 2989 | if (c->ext.actual->expr->rank == 0) |
b251af97 | 2990 | name = gfc_get_string (PREFIX ("random_r%d"), kind); |
5f251c26 | 2991 | else |
b251af97 | 2992 | name = gfc_get_string (PREFIX ("arandom_r%d"), kind); |
5f251c26 | 2993 | |
6de9cd9a | 2994 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
2bd74949 SK |
2995 | } |
2996 | ||
2997 | ||
34b4bc5c FXC |
2998 | void |
2999 | gfc_resolve_random_seed (gfc_code *c) | |
3000 | { | |
3001 | const char *name; | |
3002 | ||
3003 | name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind); | |
3004 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); | |
3005 | } | |
3006 | ||
3007 | ||
f77b6ca3 | 3008 | void |
b251af97 | 3009 | gfc_resolve_rename_sub (gfc_code *c) |
f77b6ca3 FXC |
3010 | { |
3011 | const char *name; | |
3012 | int kind; | |
3013 | ||
3014 | if (c->ext.actual->next->next->expr != NULL) | |
3015 | kind = c->ext.actual->next->next->expr->ts.kind; | |
3016 | else | |
3017 | kind = gfc_default_integer_kind; | |
3018 | ||
b251af97 | 3019 | name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind); |
f77b6ca3 FXC |
3020 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3021 | } | |
3022 | ||
3023 | ||
3024 | void | |
b251af97 | 3025 | gfc_resolve_kill_sub (gfc_code *c) |
f77b6ca3 FXC |
3026 | { |
3027 | const char *name; | |
3028 | int kind; | |
3029 | ||
3030 | if (c->ext.actual->next->next->expr != NULL) | |
3031 | kind = c->ext.actual->next->next->expr->ts.kind; | |
3032 | else | |
3033 | kind = gfc_default_integer_kind; | |
3034 | ||
b251af97 | 3035 | name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind); |
f77b6ca3 FXC |
3036 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3037 | } | |
3038 | ||
3039 | ||
3040 | void | |
b251af97 | 3041 | gfc_resolve_link_sub (gfc_code *c) |
f77b6ca3 FXC |
3042 | { |
3043 | const char *name; | |
3044 | int kind; | |
3045 | ||
3046 | if (c->ext.actual->next->next->expr != NULL) | |
3047 | kind = c->ext.actual->next->next->expr->ts.kind; | |
3048 | else | |
3049 | kind = gfc_default_integer_kind; | |
3050 | ||
b251af97 | 3051 | name = gfc_get_string (PREFIX ("link_i%d_sub"), kind); |
f77b6ca3 FXC |
3052 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3053 | } | |
3054 | ||
3055 | ||
3056 | void | |
b251af97 | 3057 | gfc_resolve_symlnk_sub (gfc_code *c) |
f77b6ca3 FXC |
3058 | { |
3059 | const char *name; | |
3060 | int kind; | |
3061 | ||
3062 | if (c->ext.actual->next->next->expr != NULL) | |
3063 | kind = c->ext.actual->next->next->expr->ts.kind; | |
3064 | else | |
3065 | kind = gfc_default_integer_kind; | |
3066 | ||
b251af97 | 3067 | name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind); |
f77b6ca3 FXC |
3068 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3069 | } | |
3070 | ||
3071 | ||
a1ba31ce DF |
3072 | /* G77 compatibility subroutines dtime() and etime(). */ |
3073 | ||
3074 | void | |
3075 | gfc_resolve_dtime_sub (gfc_code *c) | |
3076 | { | |
3077 | const char *name; | |
3078 | name = gfc_get_string (PREFIX ("dtime_sub")); | |
3079 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); | |
3080 | } | |
2bd74949 SK |
3081 | |
3082 | void | |
b251af97 | 3083 | gfc_resolve_etime_sub (gfc_code *c) |
2bd74949 SK |
3084 | { |
3085 | const char *name; | |
b251af97 | 3086 | name = gfc_get_string (PREFIX ("etime_sub")); |
2bd74949 SK |
3087 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3088 | } | |
3089 | ||
3090 | ||
a119fc1c | 3091 | /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */ |
12197210 FXC |
3092 | |
3093 | void | |
b251af97 | 3094 | gfc_resolve_itime (gfc_code *c) |
12197210 | 3095 | { |
b251af97 SK |
3096 | c->resolved_sym |
3097 | = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"), | |
3098 | gfc_default_integer_kind)); | |
12197210 FXC |
3099 | } |
3100 | ||
12197210 | 3101 | void |
b251af97 | 3102 | gfc_resolve_idate (gfc_code *c) |
12197210 | 3103 | { |
b251af97 SK |
3104 | c->resolved_sym |
3105 | = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"), | |
3106 | gfc_default_integer_kind)); | |
12197210 FXC |
3107 | } |
3108 | ||
a119fc1c | 3109 | void |
b251af97 | 3110 | gfc_resolve_ltime (gfc_code *c) |
a119fc1c | 3111 | { |
b251af97 SK |
3112 | c->resolved_sym |
3113 | = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"), | |
3114 | gfc_default_integer_kind)); | |
a119fc1c FXC |
3115 | } |
3116 | ||
3117 | void | |
b251af97 | 3118 | gfc_resolve_gmtime (gfc_code *c) |
a119fc1c | 3119 | { |
b251af97 SK |
3120 | c->resolved_sym |
3121 | = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"), | |
3122 | gfc_default_integer_kind)); | |
a119fc1c FXC |
3123 | } |
3124 | ||
12197210 | 3125 | |
2bd74949 SK |
3126 | /* G77 compatibility subroutine second(). */ |
3127 | ||
3128 | void | |
b251af97 | 3129 | gfc_resolve_second_sub (gfc_code *c) |
2bd74949 SK |
3130 | { |
3131 | const char *name; | |
b251af97 | 3132 | name = gfc_get_string (PREFIX ("second_sub")); |
2bd74949 SK |
3133 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3134 | } | |
3135 | ||
3136 | ||
f77b6ca3 | 3137 | void |
b251af97 | 3138 | gfc_resolve_sleep_sub (gfc_code *c) |
f77b6ca3 FXC |
3139 | { |
3140 | const char *name; | |
3141 | int kind; | |
3142 | ||
3143 | if (c->ext.actual->expr != NULL) | |
3144 | kind = c->ext.actual->expr->ts.kind; | |
3145 | else | |
3146 | kind = gfc_default_integer_kind; | |
3147 | ||
b251af97 | 3148 | name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind); |
f77b6ca3 FXC |
3149 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3150 | } | |
3151 | ||
3152 | ||
2bd74949 SK |
3153 | /* G77 compatibility function srand(). */ |
3154 | ||
3155 | void | |
b251af97 | 3156 | gfc_resolve_srand (gfc_code *c) |
2bd74949 SK |
3157 | { |
3158 | const char *name; | |
b251af97 | 3159 | name = gfc_get_string (PREFIX ("srand")); |
2bd74949 | 3160 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
6de9cd9a DN |
3161 | } |
3162 | ||
5f251c26 | 3163 | |
b41b2534 JB |
3164 | /* Resolve the getarg intrinsic subroutine. */ |
3165 | ||
3166 | void | |
b251af97 | 3167 | gfc_resolve_getarg (gfc_code *c) |
b41b2534 JB |
3168 | { |
3169 | const char *name; | |
ed8315d5 FXC |
3170 | |
3171 | if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind) | |
3172 | { | |
3173 | gfc_typespec ts; | |
4af63337 | 3174 | gfc_clear_ts (&ts); |
ed8315d5 FXC |
3175 | |
3176 | ts.type = BT_INTEGER; | |
3177 | ts.kind = gfc_default_integer_kind; | |
3178 | ||
3179 | gfc_convert_type (c->ext.actual->expr, &ts, 2); | |
3180 | } | |
3181 | ||
3182 | name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind); | |
b41b2534 JB |
3183 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3184 | } | |
3185 | ||
b251af97 | 3186 | |
a8c60d7f SK |
3187 | /* Resolve the getcwd intrinsic subroutine. */ |
3188 | ||
3189 | void | |
b251af97 | 3190 | gfc_resolve_getcwd_sub (gfc_code *c) |
a8c60d7f SK |
3191 | { |
3192 | const char *name; | |
3193 | int kind; | |
3194 | ||
3195 | if (c->ext.actual->next->expr != NULL) | |
3196 | kind = c->ext.actual->next->expr->ts.kind; | |
3197 | else | |
3198 | kind = gfc_default_integer_kind; | |
3199 | ||
b251af97 | 3200 | name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind); |
a8c60d7f SK |
3201 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3202 | } | |
3203 | ||
b41b2534 JB |
3204 | |
3205 | /* Resolve the get_command intrinsic subroutine. */ | |
3206 | ||
3207 | void | |
b251af97 | 3208 | gfc_resolve_get_command (gfc_code *c) |
b41b2534 JB |
3209 | { |
3210 | const char *name; | |
3211 | int kind; | |
9d64df18 | 3212 | kind = gfc_default_integer_kind; |
b251af97 | 3213 | name = gfc_get_string (PREFIX ("get_command_i%d"), kind); |
b41b2534 JB |
3214 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3215 | } | |
3216 | ||
3217 | ||
3218 | /* Resolve the get_command_argument intrinsic subroutine. */ | |
3219 | ||
3220 | void | |
b251af97 | 3221 | gfc_resolve_get_command_argument (gfc_code *c) |
b41b2534 JB |
3222 | { |
3223 | const char *name; | |
3224 | int kind; | |
9d64df18 | 3225 | kind = gfc_default_integer_kind; |
b251af97 | 3226 | name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind); |
b41b2534 JB |
3227 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3228 | } | |
3229 | ||
b251af97 | 3230 | |
f7b529fa | 3231 | /* Resolve the get_environment_variable intrinsic subroutine. */ |
aa6fc635 JB |
3232 | |
3233 | void | |
b251af97 | 3234 | gfc_resolve_get_environment_variable (gfc_code *code) |
aa6fc635 JB |
3235 | { |
3236 | const char *name; | |
3237 | int kind; | |
9d64df18 | 3238 | kind = gfc_default_integer_kind; |
b251af97 | 3239 | name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind); |
aa6fc635 JB |
3240 | code->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3241 | } | |
3242 | ||
b251af97 | 3243 | |
185d7d97 | 3244 | void |
b251af97 | 3245 | gfc_resolve_signal_sub (gfc_code *c) |
185d7d97 FXC |
3246 | { |
3247 | const char *name; | |
3248 | gfc_expr *number, *handler, *status; | |
3249 | gfc_typespec ts; | |
4af63337 | 3250 | gfc_clear_ts (&ts); |
185d7d97 FXC |
3251 | |
3252 | number = c->ext.actual->expr; | |
3253 | handler = c->ext.actual->next->expr; | |
3254 | status = c->ext.actual->next->next->expr; | |
3255 | ts.type = BT_INTEGER; | |
3256 | ts.kind = gfc_c_int_kind; | |
3257 | ||
3258 | /* handler can be either BT_INTEGER or BT_PROCEDURE */ | |
3259 | if (handler->ts.type == BT_INTEGER) | |
3260 | { | |
3261 | if (handler->ts.kind != gfc_c_int_kind) | |
3262 | gfc_convert_type (handler, &ts, 2); | |
b251af97 | 3263 | name = gfc_get_string (PREFIX ("signal_sub_int")); |
185d7d97 FXC |
3264 | } |
3265 | else | |
b251af97 | 3266 | name = gfc_get_string (PREFIX ("signal_sub")); |
185d7d97 FXC |
3267 | |
3268 | if (number->ts.kind != gfc_c_int_kind) | |
3269 | gfc_convert_type (number, &ts, 2); | |
3270 | if (status != NULL && status->ts.kind != gfc_c_int_kind) | |
3271 | gfc_convert_type (status, &ts, 2); | |
3272 | ||
3273 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); | |
3274 | } | |
3275 | ||
b251af97 | 3276 | |
5b1374e9 TS |
3277 | /* Resolve the SYSTEM intrinsic subroutine. */ |
3278 | ||
3279 | void | |
b251af97 | 3280 | gfc_resolve_system_sub (gfc_code *c) |
5b1374e9 TS |
3281 | { |
3282 | const char *name; | |
b251af97 | 3283 | name = gfc_get_string (PREFIX ("system_sub")); |
5b1374e9 TS |
3284 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3285 | } | |
b41b2534 | 3286 | |
b251af97 | 3287 | |
21fdfcc1 SK |
3288 | /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */ |
3289 | ||
3290 | void | |
b251af97 | 3291 | gfc_resolve_system_clock (gfc_code *c) |
21fdfcc1 SK |
3292 | { |
3293 | const char *name; | |
3294 | int kind; | |
3295 | ||
3296 | if (c->ext.actual->expr != NULL) | |
3297 | kind = c->ext.actual->expr->ts.kind; | |
3298 | else if (c->ext.actual->next->expr != NULL) | |
3299 | kind = c->ext.actual->next->expr->ts.kind; | |
3300 | else if (c->ext.actual->next->next->expr != NULL) | |
3301 | kind = c->ext.actual->next->next->expr->ts.kind; | |
3302 | else | |
9d64df18 | 3303 | kind = gfc_default_integer_kind; |
21fdfcc1 | 3304 | |
b251af97 | 3305 | name = gfc_get_string (PREFIX ("system_clock_%d"), kind); |
21fdfcc1 SK |
3306 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3307 | } | |
3308 | ||
b251af97 | 3309 | |
c14c8155 FXC |
3310 | /* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine. */ |
3311 | void | |
3312 | gfc_resolve_execute_command_line (gfc_code *c) | |
3313 | { | |
3314 | const char *name; | |
3315 | name = gfc_get_string (PREFIX ("execute_command_line_i%d"), | |
3316 | gfc_default_integer_kind); | |
3317 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); | |
3318 | } | |
3319 | ||
3320 | ||
d8fe26b2 SK |
3321 | /* Resolve the EXIT intrinsic subroutine. */ |
3322 | ||
3323 | void | |
b251af97 | 3324 | gfc_resolve_exit (gfc_code *c) |
d8fe26b2 SK |
3325 | { |
3326 | const char *name; | |
fe569d8f FXC |
3327 | gfc_typespec ts; |
3328 | gfc_expr *n; | |
4af63337 | 3329 | gfc_clear_ts (&ts); |
d8fe26b2 | 3330 | |
fe569d8f FXC |
3331 | /* The STATUS argument has to be of default kind. If it is not, |
3332 | we convert it. */ | |
3333 | ts.type = BT_INTEGER; | |
3334 | ts.kind = gfc_default_integer_kind; | |
3335 | n = c->ext.actual->expr; | |
3336 | if (n != NULL && n->ts.kind != ts.kind) | |
3337 | gfc_convert_type (n, &ts, 2); | |
d8fe26b2 | 3338 | |
fe569d8f | 3339 | name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind); |
d8fe26b2 SK |
3340 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3341 | } | |
3342 | ||
b251af97 | 3343 | |
df65f093 SK |
3344 | /* Resolve the FLUSH intrinsic subroutine. */ |
3345 | ||
3346 | void | |
b251af97 | 3347 | gfc_resolve_flush (gfc_code *c) |
df65f093 SK |
3348 | { |
3349 | const char *name; | |
3350 | gfc_typespec ts; | |
3351 | gfc_expr *n; | |
4af63337 | 3352 | gfc_clear_ts (&ts); |
df65f093 SK |
3353 | |
3354 | ts.type = BT_INTEGER; | |
3355 | ts.kind = gfc_default_integer_kind; | |
3356 | n = c->ext.actual->expr; | |
b251af97 | 3357 | if (n != NULL && n->ts.kind != ts.kind) |
df65f093 SK |
3358 | gfc_convert_type (n, &ts, 2); |
3359 | ||
b251af97 | 3360 | name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind); |
df65f093 SK |
3361 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3362 | } | |
3363 | ||
f77b6ca3 | 3364 | |
0d519038 | 3365 | void |
b251af97 | 3366 | gfc_resolve_free (gfc_code *c) |
0d519038 FXC |
3367 | { |
3368 | gfc_typespec ts; | |
3369 | gfc_expr *n; | |
4af63337 | 3370 | gfc_clear_ts (&ts); |
0d519038 FXC |
3371 | |
3372 | ts.type = BT_INTEGER; | |
3373 | ts.kind = gfc_index_integer_kind; | |
3374 | n = c->ext.actual->expr; | |
3375 | if (n->ts.kind != ts.kind) | |
3376 | gfc_convert_type (n, &ts, 2); | |
3377 | ||
b251af97 | 3378 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free")); |
0d519038 FXC |
3379 | } |
3380 | ||
3381 | ||
35059811 | 3382 | void |
b251af97 | 3383 | gfc_resolve_ctime_sub (gfc_code *c) |
35059811 FXC |
3384 | { |
3385 | gfc_typespec ts; | |
4af63337 | 3386 | gfc_clear_ts (&ts); |
35059811 FXC |
3387 | |
3388 | /* ctime TIME argument is a INTEGER(KIND=8), says the doc */ | |
3389 | if (c->ext.actual->expr->ts.kind != 8) | |
3390 | { | |
3391 | ts.type = BT_INTEGER; | |
3392 | ts.kind = 8; | |
bc21d315 JW |
3393 | ts.u.derived = NULL; |
3394 | ts.u.cl = NULL; | |
35059811 FXC |
3395 | gfc_convert_type (c->ext.actual->expr, &ts, 2); |
3396 | } | |
3397 | ||
b251af97 | 3398 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub")); |
35059811 FXC |
3399 | } |
3400 | ||
3401 | ||
3402 | void | |
b251af97 | 3403 | gfc_resolve_fdate_sub (gfc_code *c) |
35059811 FXC |
3404 | { |
3405 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub")); | |
3406 | } | |
3407 | ||
3408 | ||
f77b6ca3 | 3409 | void |
b251af97 | 3410 | gfc_resolve_gerror (gfc_code *c) |
f77b6ca3 FXC |
3411 | { |
3412 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror")); | |
3413 | } | |
3414 | ||
3415 | ||
3416 | void | |
b251af97 | 3417 | gfc_resolve_getlog (gfc_code *c) |
f77b6ca3 FXC |
3418 | { |
3419 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog")); | |
3420 | } | |
3421 | ||
3422 | ||
3423 | void | |
b251af97 | 3424 | gfc_resolve_hostnm_sub (gfc_code *c) |
f77b6ca3 FXC |
3425 | { |
3426 | const char *name; | |
3427 | int kind; | |
3428 | ||
3429 | if (c->ext.actual->next->expr != NULL) | |
3430 | kind = c->ext.actual->next->expr->ts.kind; | |
3431 | else | |
3432 | kind = gfc_default_integer_kind; | |
3433 | ||
b251af97 | 3434 | name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind); |
f77b6ca3 FXC |
3435 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3436 | } | |
3437 | ||
3438 | ||
3439 | void | |
b251af97 | 3440 | gfc_resolve_perror (gfc_code *c) |
f77b6ca3 FXC |
3441 | { |
3442 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub")); | |
3443 | } | |
3444 | ||
df65f093 SK |
3445 | /* Resolve the STAT and FSTAT intrinsic subroutines. */ |
3446 | ||
3447 | void | |
b251af97 | 3448 | gfc_resolve_stat_sub (gfc_code *c) |
df65f093 SK |
3449 | { |
3450 | const char *name; | |
b251af97 | 3451 | name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind); |
df65f093 SK |
3452 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3453 | } | |
3454 | ||
3455 | ||
bf3fb7e4 | 3456 | void |
b251af97 | 3457 | gfc_resolve_lstat_sub (gfc_code *c) |
bf3fb7e4 FXC |
3458 | { |
3459 | const char *name; | |
b251af97 | 3460 | name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind); |
bf3fb7e4 FXC |
3461 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3462 | } | |
3463 | ||
3464 | ||
df65f093 | 3465 | void |
b251af97 | 3466 | gfc_resolve_fstat_sub (gfc_code *c) |
df65f093 SK |
3467 | { |
3468 | const char *name; | |
3469 | gfc_expr *u; | |
3470 | gfc_typespec *ts; | |
3471 | ||
3472 | u = c->ext.actual->expr; | |
3473 | ts = &c->ext.actual->next->expr->ts; | |
3474 | if (u->ts.kind != ts->kind) | |
3475 | gfc_convert_type (u, ts, 2); | |
b251af97 | 3476 | name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind); |
df65f093 SK |
3477 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3478 | } | |
3479 | ||
ae8b8789 | 3480 | |
5d723e54 | 3481 | void |
b251af97 | 3482 | gfc_resolve_fgetc_sub (gfc_code *c) |
5d723e54 FXC |
3483 | { |
3484 | const char *name; | |
3485 | gfc_typespec ts; | |
3486 | gfc_expr *u, *st; | |
4af63337 | 3487 | gfc_clear_ts (&ts); |
5d723e54 FXC |
3488 | |
3489 | u = c->ext.actual->expr; | |
3490 | st = c->ext.actual->next->next->expr; | |
3491 | ||
3492 | if (u->ts.kind != gfc_c_int_kind) | |
3493 | { | |
3494 | ts.type = BT_INTEGER; | |
3495 | ts.kind = gfc_c_int_kind; | |
bc21d315 JW |
3496 | ts.u.derived = NULL; |
3497 | ts.u.cl = NULL; | |
5d723e54 FXC |
3498 | gfc_convert_type (u, &ts, 2); |
3499 | } | |
3500 | ||
3501 | if (st != NULL) | |
b251af97 | 3502 | name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind); |
5d723e54 | 3503 | else |
b251af97 | 3504 | name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind); |
5d723e54 FXC |
3505 | |
3506 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); | |
3507 | } | |
3508 | ||
3509 | ||
3510 | void | |
b251af97 | 3511 | gfc_resolve_fget_sub (gfc_code *c) |
5d723e54 FXC |
3512 | { |
3513 | const char *name; | |
3514 | gfc_expr *st; | |
3515 | ||
3516 | st = c->ext.actual->next->expr; | |
3517 | if (st != NULL) | |
b251af97 | 3518 | name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind); |
5d723e54 | 3519 | else |
b251af97 | 3520 | name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind); |
5d723e54 FXC |
3521 | |
3522 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); | |
3523 | } | |
3524 | ||
3525 | ||
3526 | void | |
b251af97 | 3527 | gfc_resolve_fputc_sub (gfc_code *c) |
5d723e54 FXC |
3528 | { |
3529 | const char *name; | |
3530 | gfc_typespec ts; | |
3531 | gfc_expr *u, *st; | |
4af63337 | 3532 | gfc_clear_ts (&ts); |
5d723e54 FXC |
3533 | |
3534 | u = c->ext.actual->expr; | |
3535 | st = c->ext.actual->next->next->expr; | |
3536 | ||
3537 | if (u->ts.kind != gfc_c_int_kind) | |
3538 | { | |
3539 | ts.type = BT_INTEGER; | |
3540 | ts.kind = gfc_c_int_kind; | |
bc21d315 JW |
3541 | ts.u.derived = NULL; |
3542 | ts.u.cl = NULL; | |
5d723e54 FXC |
3543 | gfc_convert_type (u, &ts, 2); |
3544 | } | |
3545 | ||
3546 | if (st != NULL) | |
b251af97 | 3547 | name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind); |
5d723e54 | 3548 | else |
b251af97 | 3549 | name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind); |
5d723e54 FXC |
3550 | |
3551 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); | |
3552 | } | |
3553 | ||
3554 | ||
3555 | void | |
b251af97 | 3556 | gfc_resolve_fput_sub (gfc_code *c) |
5d723e54 FXC |
3557 | { |
3558 | const char *name; | |
3559 | gfc_expr *st; | |
3560 | ||
3561 | st = c->ext.actual->next->expr; | |
3562 | if (st != NULL) | |
b251af97 | 3563 | name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind); |
5d723e54 | 3564 | else |
b251af97 | 3565 | name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind); |
5d723e54 FXC |
3566 | |
3567 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); | |
3568 | } | |
3569 | ||
3570 | ||
dcdc26df DF |
3571 | void |
3572 | gfc_resolve_fseek_sub (gfc_code *c) | |
3573 | { | |
3574 | gfc_expr *unit; | |
3575 | gfc_expr *offset; | |
3576 | gfc_expr *whence; | |
dcdc26df | 3577 | gfc_typespec ts; |
4af63337 | 3578 | gfc_clear_ts (&ts); |
dcdc26df DF |
3579 | |
3580 | unit = c->ext.actual->expr; | |
3581 | offset = c->ext.actual->next->expr; | |
3582 | whence = c->ext.actual->next->next->expr; | |
dcdc26df DF |
3583 | |
3584 | if (unit->ts.kind != gfc_c_int_kind) | |
3585 | { | |
3586 | ts.type = BT_INTEGER; | |
3587 | ts.kind = gfc_c_int_kind; | |
bc21d315 JW |
3588 | ts.u.derived = NULL; |
3589 | ts.u.cl = NULL; | |
dcdc26df DF |
3590 | gfc_convert_type (unit, &ts, 2); |
3591 | } | |
3592 | ||
3593 | if (offset->ts.kind != gfc_intio_kind) | |
3594 | { | |
3595 | ts.type = BT_INTEGER; | |
3596 | ts.kind = gfc_intio_kind; | |
bc21d315 JW |
3597 | ts.u.derived = NULL; |
3598 | ts.u.cl = NULL; | |
dcdc26df DF |
3599 | gfc_convert_type (offset, &ts, 2); |
3600 | } | |
3601 | ||
3602 | if (whence->ts.kind != gfc_c_int_kind) | |
3603 | { | |
3604 | ts.type = BT_INTEGER; | |
3605 | ts.kind = gfc_c_int_kind; | |
bc21d315 JW |
3606 | ts.u.derived = NULL; |
3607 | ts.u.cl = NULL; | |
dcdc26df DF |
3608 | gfc_convert_type (whence, &ts, 2); |
3609 | } | |
3610 | ||
3611 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub")); | |
3612 | } | |
3613 | ||
5d723e54 | 3614 | void |
b251af97 | 3615 | gfc_resolve_ftell_sub (gfc_code *c) |
5d723e54 FXC |
3616 | { |
3617 | const char *name; | |
3618 | gfc_expr *unit; | |
3619 | gfc_expr *offset; | |
3620 | gfc_typespec ts; | |
4af63337 | 3621 | gfc_clear_ts (&ts); |
5d723e54 FXC |
3622 | |
3623 | unit = c->ext.actual->expr; | |
3624 | offset = c->ext.actual->next->expr; | |
3625 | ||
3626 | if (unit->ts.kind != gfc_c_int_kind) | |
3627 | { | |
3628 | ts.type = BT_INTEGER; | |
3629 | ts.kind = gfc_c_int_kind; | |
bc21d315 JW |
3630 | ts.u.derived = NULL; |
3631 | ts.u.cl = NULL; | |
5d723e54 FXC |
3632 | gfc_convert_type (unit, &ts, 2); |
3633 | } | |
3634 | ||
b251af97 | 3635 | name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind); |
5d723e54 FXC |
3636 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3637 | } | |
3638 | ||
3639 | ||
ae8b8789 | 3640 | void |
b251af97 | 3641 | gfc_resolve_ttynam_sub (gfc_code *c) |
ae8b8789 FXC |
3642 | { |
3643 | gfc_typespec ts; | |
4af63337 | 3644 | gfc_clear_ts (&ts); |
ae8b8789 FXC |
3645 | |
3646 | if (c->ext.actual->expr->ts.kind != gfc_c_int_kind) | |
3647 | { | |
3648 | ts.type = BT_INTEGER; | |
3649 | ts.kind = gfc_c_int_kind; | |
bc21d315 JW |
3650 | ts.u.derived = NULL; |
3651 | ts.u.cl = NULL; | |
ae8b8789 FXC |
3652 | gfc_convert_type (c->ext.actual->expr, &ts, 2); |
3653 | } | |
3654 | ||
b251af97 | 3655 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub")); |
ae8b8789 FXC |
3656 | } |
3657 | ||
3658 | ||
d8fe26b2 SK |
3659 | /* Resolve the UMASK intrinsic subroutine. */ |
3660 | ||
3661 | void | |
b251af97 | 3662 | gfc_resolve_umask_sub (gfc_code *c) |
d8fe26b2 SK |
3663 | { |
3664 | const char *name; | |
3665 | int kind; | |
3666 | ||
3667 | if (c->ext.actual->next->expr != NULL) | |
3668 | kind = c->ext.actual->next->expr->ts.kind; | |
3669 | else | |
3670 | kind = gfc_default_integer_kind; | |
3671 | ||
b251af97 | 3672 | name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind); |
d8fe26b2 SK |
3673 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3674 | } | |
3675 | ||
3676 | /* Resolve the UNLINK intrinsic subroutine. */ | |
3677 | ||
3678 | void | |
b251af97 | 3679 | gfc_resolve_unlink_sub (gfc_code *c) |
d8fe26b2 SK |
3680 | { |
3681 | const char *name; | |
3682 | int kind; | |
3683 | ||
3684 | if (c->ext.actual->next->expr != NULL) | |
3685 | kind = c->ext.actual->next->expr->ts.kind; | |
3686 | else | |
3687 | kind = gfc_default_integer_kind; | |
3688 | ||
b251af97 | 3689 | name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind); |
d8fe26b2 SK |
3690 | c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); |
3691 | } |