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