1 /* Intrinsic function resolution.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught & Katherine Holcomb
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* Assign name and types to intrinsic procedures. For functions, the
24 first argument to a resolution function is an expression pointer to
25 the original function node and the rest are pointers to the
26 arguments of the function call. For subroutines, a pointer to the
27 code node is passed. The result type and library subroutine name
28 are generally set according to the function arguments. */
32 #include "coretypes.h"
35 #include "intrinsic.h"
37 /* Given printf-like arguments, return a stable version of the result string.
39 We already have a working, optimized string hashing table in the form of
40 the identifier table. Reusing this table is likely not to be wasted,
41 since if the function name makes it to the gimple output of the frontend,
42 we'll have to create the identifier anyway. */
45 gfc_get_string (const char *format, ...)
51 va_start (ap, format);
52 vsnprintf (temp_name, sizeof (temp_name), format, ap);
54 temp_name[sizeof (temp_name) - 1] = 0;
56 ident = get_identifier (temp_name);
57 return IDENTIFIER_POINTER (ident);
60 /* MERGE and SPREAD need to have source charlen's present for passing
61 to the result expression. */
63 check_charlen_present (gfc_expr *source)
65 if (source->ts.cl == NULL)
67 source->ts.cl = gfc_get_charlen ();
68 source->ts.cl->next = gfc_current_ns->cl_list;
69 gfc_current_ns->cl_list = source->ts.cl;
72 if (source->expr_type == EXPR_CONSTANT)
74 source->ts.cl->length = gfc_int_expr (source->value.character.length);
77 else if (source->expr_type == EXPR_ARRAY)
79 source->ts.cl->length =
80 gfc_int_expr (source->value.constructor->expr->value.character.length);
85 /* Helper function for resolving the "mask" argument. */
88 resolve_mask_arg (gfc_expr *mask)
95 /* For the scalar case, coerce the mask to kind=4 unconditionally
96 (because this is the only kind we have a library function
99 if (mask->ts.kind != 4)
101 ts.type = BT_LOGICAL;
103 gfc_convert_type (mask, &ts, 2);
108 /* In the library, we access the mask with a GFC_LOGICAL_1
109 argument. No need to waste memory if we are about to create
110 a temporary array. */
111 if (mask->expr_type == EXPR_OP)
113 ts.type = BT_LOGICAL;
115 gfc_convert_type (mask, &ts, 2);
120 /********************** Resolution functions **********************/
124 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
127 if (f->ts.type == BT_COMPLEX)
128 f->ts.type = BT_REAL;
130 f->value.function.name
131 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
136 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
137 gfc_expr *mode ATTRIBUTE_UNUSED)
139 f->ts.type = BT_INTEGER;
140 f->ts.kind = gfc_c_int_kind;
141 f->value.function.name = PREFIX ("access_func");
146 gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind,
149 f->ts.type = BT_CHARACTER;
150 f->ts.kind = (kind == NULL)
151 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
152 f->ts.cl = gfc_get_charlen ();
153 f->ts.cl->next = gfc_current_ns->cl_list;
154 gfc_current_ns->cl_list = f->ts.cl;
155 f->ts.cl->length = gfc_int_expr (1);
157 f->value.function.name = gfc_get_string (name, f->ts.kind,
158 gfc_type_letter (x->ts.type),
164 gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
166 gfc_resolve_char_achar (f, x, kind, "__achar_%d_%c%d");
171 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
174 f->value.function.name
175 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
180 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
183 f->value.function.name
184 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
190 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
192 f->ts.type = BT_REAL;
193 f->ts.kind = x->ts.kind;
194 f->value.function.name
195 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
201 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
203 f->ts.type = i->ts.type;
204 f->ts.kind = gfc_kind_max (i, j);
206 if (i->ts.kind != j->ts.kind)
208 if (i->ts.kind == gfc_kind_max (i, j))
209 gfc_convert_type (j, &i->ts, 2);
211 gfc_convert_type (i, &j->ts, 2);
214 f->value.function.name
215 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
220 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
224 f->ts.type = a->ts.type;
225 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
227 if (a->ts.kind != f->ts.kind)
229 ts.type = f->ts.type;
230 ts.kind = f->ts.kind;
231 gfc_convert_type (a, &ts, 2);
233 /* The resolved name is only used for specific intrinsics where
234 the return kind is the same as the arg kind. */
235 f->value.function.name
236 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
241 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
243 gfc_resolve_aint (f, a, NULL);
248 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
254 gfc_resolve_dim_arg (dim);
255 f->rank = mask->rank - 1;
256 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
259 f->value.function.name
260 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
266 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
270 f->ts.type = a->ts.type;
271 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
273 if (a->ts.kind != f->ts.kind)
275 ts.type = f->ts.type;
276 ts.kind = f->ts.kind;
277 gfc_convert_type (a, &ts, 2);
280 /* The resolved name is only used for specific intrinsics where
281 the return kind is the same as the arg kind. */
282 f->value.function.name
283 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
289 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
291 gfc_resolve_anint (f, a, NULL);
296 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
302 gfc_resolve_dim_arg (dim);
303 f->rank = mask->rank - 1;
304 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
307 f->value.function.name
308 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
314 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
317 f->value.function.name
318 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
322 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
325 f->value.function.name
326 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
331 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
334 f->value.function.name
335 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
339 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
342 f->value.function.name
343 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
348 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
351 f->value.function.name
352 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
357 /* Resolve the BESYN and BESJN intrinsics. */
360 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
365 if (n->ts.kind != gfc_c_int_kind)
367 ts.type = BT_INTEGER;
368 ts.kind = gfc_c_int_kind;
369 gfc_convert_type (n, &ts, 2);
371 f->value.function.name = gfc_get_string ("<intrinsic>");
376 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
378 f->ts.type = BT_LOGICAL;
379 f->ts.kind = gfc_default_logical_kind;
380 f->value.function.name
381 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
386 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
388 f->ts.type = BT_INTEGER;
389 f->ts.kind = (kind == NULL)
390 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
391 f->value.function.name
392 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
393 gfc_type_letter (a->ts.type), a->ts.kind);
398 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
400 gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d");
405 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
407 f->ts.type = BT_INTEGER;
408 f->ts.kind = gfc_default_integer_kind;
409 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
414 gfc_resolve_chdir_sub (gfc_code *c)
419 if (c->ext.actual->next->expr != NULL)
420 kind = c->ext.actual->next->expr->ts.kind;
422 kind = gfc_default_integer_kind;
424 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
425 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
430 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
431 gfc_expr *mode ATTRIBUTE_UNUSED)
433 f->ts.type = BT_INTEGER;
434 f->ts.kind = gfc_c_int_kind;
435 f->value.function.name = PREFIX ("chmod_func");
440 gfc_resolve_chmod_sub (gfc_code *c)
445 if (c->ext.actual->next->next->expr != NULL)
446 kind = c->ext.actual->next->next->expr->ts.kind;
448 kind = gfc_default_integer_kind;
450 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
451 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
456 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
458 f->ts.type = BT_COMPLEX;
459 f->ts.kind = (kind == NULL)
460 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
463 f->value.function.name
464 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
465 gfc_type_letter (x->ts.type), x->ts.kind);
467 f->value.function.name
468 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
469 gfc_type_letter (x->ts.type), x->ts.kind,
470 gfc_type_letter (y->ts.type), y->ts.kind);
475 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
477 gfc_resolve_cmplx (f, x, y, gfc_int_expr (gfc_default_double_kind));
482 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
486 if (x->ts.type == BT_INTEGER)
488 if (y->ts.type == BT_INTEGER)
489 kind = gfc_default_real_kind;
495 if (y->ts.type == BT_REAL)
496 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
501 f->ts.type = BT_COMPLEX;
503 f->value.function.name
504 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
505 gfc_type_letter (x->ts.type), x->ts.kind,
506 gfc_type_letter (y->ts.type), y->ts.kind);
511 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
514 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
519 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
522 f->value.function.name
523 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
528 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
531 f->value.function.name
532 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
537 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
539 f->ts.type = BT_INTEGER;
541 f->ts.kind = mpz_get_si (kind->value.integer);
543 f->ts.kind = gfc_default_integer_kind;
547 f->rank = mask->rank - 1;
548 gfc_resolve_dim_arg (dim);
549 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
552 f->value.function.name
553 = gfc_get_string (PREFIX ("count_%d_%c%d"), f->ts.kind,
554 gfc_type_letter (mask->ts.type), mask->ts.kind);
559 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
564 if (array->ts.type == BT_CHARACTER && array->ref)
565 gfc_resolve_substring_charlen (array);
568 f->rank = array->rank;
569 f->shape = gfc_copy_shape (array->shape, array->rank);
576 /* Convert shift to at least gfc_default_integer_kind, so we don't need
577 kind=1 and kind=2 versions of the library functions. */
578 if (shift->ts.kind < gfc_default_integer_kind)
581 ts.type = BT_INTEGER;
582 ts.kind = gfc_default_integer_kind;
583 gfc_convert_type_warn (shift, &ts, 2, 0);
588 gfc_resolve_dim_arg (dim);
589 /* Convert dim to shift's kind, so we don't need so many variations. */
590 if (dim->ts.kind != shift->ts.kind)
591 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
593 f->value.function.name
594 = gfc_get_string (PREFIX ("cshift%d_%d%s"), n, shift->ts.kind,
595 array->ts.type == BT_CHARACTER ? "_char" : "");
600 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
604 f->ts.type = BT_CHARACTER;
605 f->ts.kind = gfc_default_character_kind;
607 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
608 if (time->ts.kind != 8)
610 ts.type = BT_INTEGER;
614 gfc_convert_type (time, &ts, 2);
617 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
622 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
624 f->ts.type = BT_REAL;
625 f->ts.kind = gfc_default_double_kind;
626 f->value.function.name
627 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
632 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
634 f->ts.type = a->ts.type;
636 f->ts.kind = gfc_kind_max (a,p);
638 f->ts.kind = a->ts.kind;
640 if (p != NULL && a->ts.kind != p->ts.kind)
642 if (a->ts.kind == gfc_kind_max (a,p))
643 gfc_convert_type (p, &a->ts, 2);
645 gfc_convert_type (a, &p->ts, 2);
648 f->value.function.name
649 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
654 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
658 temp.expr_type = EXPR_OP;
659 gfc_clear_ts (&temp.ts);
660 temp.value.op.operator = INTRINSIC_NONE;
661 temp.value.op.op1 = a;
662 temp.value.op.op2 = b;
663 gfc_type_convert_binary (&temp);
665 f->value.function.name
666 = gfc_get_string (PREFIX ("dot_product_%c%d"),
667 gfc_type_letter (f->ts.type), f->ts.kind);
672 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
673 gfc_expr *b ATTRIBUTE_UNUSED)
675 f->ts.kind = gfc_default_double_kind;
676 f->ts.type = BT_REAL;
677 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
682 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
683 gfc_expr *boundary, gfc_expr *dim)
687 if (array->ts.type == BT_CHARACTER && array->ref)
688 gfc_resolve_substring_charlen (array);
691 f->rank = array->rank;
692 f->shape = gfc_copy_shape (array->shape, array->rank);
697 if (boundary && boundary->rank > 0)
700 /* Convert shift to at least gfc_default_integer_kind, so we don't need
701 kind=1 and kind=2 versions of the library functions. */
702 if (shift->ts.kind < gfc_default_integer_kind)
705 ts.type = BT_INTEGER;
706 ts.kind = gfc_default_integer_kind;
707 gfc_convert_type_warn (shift, &ts, 2, 0);
712 gfc_resolve_dim_arg (dim);
713 /* Convert dim to shift's kind, so we don't need so many variations. */
714 if (dim->ts.kind != shift->ts.kind)
715 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
718 f->value.function.name
719 = gfc_get_string (PREFIX ("eoshift%d_%d%s"), n, shift->ts.kind,
720 array->ts.type == BT_CHARACTER ? "_char" : "");
725 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
728 f->value.function.name
729 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
734 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
736 f->ts.type = BT_INTEGER;
737 f->ts.kind = gfc_default_integer_kind;
738 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
743 gfc_resolve_fdate (gfc_expr *f)
745 f->ts.type = BT_CHARACTER;
746 f->ts.kind = gfc_default_character_kind;
747 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
752 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
754 f->ts.type = BT_INTEGER;
755 f->ts.kind = (kind == NULL)
756 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
757 f->value.function.name
758 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
759 gfc_type_letter (a->ts.type), a->ts.kind);
764 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
766 f->ts.type = BT_INTEGER;
767 f->ts.kind = gfc_default_integer_kind;
768 if (n->ts.kind != f->ts.kind)
769 gfc_convert_type (n, &f->ts, 2);
770 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
775 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
778 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
782 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
785 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
788 f->value.function.name = gfc_get_string ("<intrinsic>");
793 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
796 f->value.function.name
797 = gfc_get_string ("__gamma_%d", x->ts.kind);
802 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
804 f->ts.type = BT_INTEGER;
806 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
811 gfc_resolve_getgid (gfc_expr *f)
813 f->ts.type = BT_INTEGER;
815 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
820 gfc_resolve_getpid (gfc_expr *f)
822 f->ts.type = BT_INTEGER;
824 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
829 gfc_resolve_getuid (gfc_expr *f)
831 f->ts.type = BT_INTEGER;
833 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
838 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
840 f->ts.type = BT_INTEGER;
842 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
847 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
849 /* If the kind of i and j are different, then g77 cross-promoted the
850 kinds to the largest value. The Fortran 95 standard requires the
852 if (i->ts.kind != j->ts.kind)
854 if (i->ts.kind == gfc_kind_max (i, j))
855 gfc_convert_type (j, &i->ts, 2);
857 gfc_convert_type (i, &j->ts, 2);
861 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
866 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
869 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
874 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
875 gfc_expr *len ATTRIBUTE_UNUSED)
878 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
883 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
886 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
891 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
893 f->ts.type = BT_INTEGER;
895 f->ts.kind = mpz_get_si (kind->value.integer);
897 f->ts.kind = gfc_default_integer_kind;
898 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
903 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
905 f->ts.type = BT_INTEGER;
907 f->ts.kind = mpz_get_si (kind->value.integer);
909 f->ts.kind = gfc_default_integer_kind;
910 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
915 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
917 gfc_resolve_nint (f, a, NULL);
922 gfc_resolve_ierrno (gfc_expr *f)
924 f->ts.type = BT_INTEGER;
925 f->ts.kind = gfc_default_integer_kind;
926 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
931 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
933 /* If the kind of i and j are different, then g77 cross-promoted the
934 kinds to the largest value. The Fortran 95 standard requires the
936 if (i->ts.kind != j->ts.kind)
938 if (i->ts.kind == gfc_kind_max (i, j))
939 gfc_convert_type (j, &i->ts, 2);
941 gfc_convert_type (i, &j->ts, 2);
945 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
950 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
952 /* If the kind of i and j are different, then g77 cross-promoted the
953 kinds to the largest value. The Fortran 95 standard requires the
955 if (i->ts.kind != j->ts.kind)
957 if (i->ts.kind == gfc_kind_max (i, j))
958 gfc_convert_type (j, &i->ts, 2);
960 gfc_convert_type (i, &j->ts, 2);
964 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
969 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
970 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
975 f->ts.type = BT_INTEGER;
977 f->ts.kind = mpz_get_si (kind->value.integer);
979 f->ts.kind = gfc_default_integer_kind;
981 if (back && back->ts.kind != gfc_default_integer_kind)
983 ts.type = BT_LOGICAL;
984 ts.kind = gfc_default_integer_kind;
987 gfc_convert_type (back, &ts, 2);
990 f->value.function.name
991 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
996 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
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 ("__int_%d_%c%d", f->ts.kind,
1003 gfc_type_letter (a->ts.type), a->ts.kind);
1008 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1010 f->ts.type = BT_INTEGER;
1012 f->value.function.name
1013 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1014 gfc_type_letter (a->ts.type), a->ts.kind);
1019 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
1021 f->ts.type = BT_INTEGER;
1023 f->value.function.name
1024 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1025 gfc_type_letter (a->ts.type), a->ts.kind);
1030 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1032 f->ts.type = BT_INTEGER;
1034 f->value.function.name
1035 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1036 gfc_type_letter (a->ts.type), a->ts.kind);
1041 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1045 f->ts.type = BT_LOGICAL;
1046 f->ts.kind = gfc_default_integer_kind;
1047 if (u->ts.kind != gfc_c_int_kind)
1049 ts.type = BT_INTEGER;
1050 ts.kind = gfc_c_int_kind;
1053 gfc_convert_type (u, &ts, 2);
1056 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1061 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1064 f->value.function.name
1065 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1070 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1073 f->value.function.name
1074 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1079 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1082 f->value.function.name
1083 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1088 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1092 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1095 f->value.function.name
1096 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1101 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1102 gfc_expr *s ATTRIBUTE_UNUSED)
1104 f->ts.type = BT_INTEGER;
1105 f->ts.kind = gfc_default_integer_kind;
1106 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1111 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1113 static char lbound[] = "__lbound";
1115 f->ts.type = BT_INTEGER;
1117 f->ts.kind = mpz_get_si (kind->value.integer);
1119 f->ts.kind = gfc_default_integer_kind;
1124 f->shape = gfc_get_shape (1);
1125 mpz_init_set_ui (f->shape[0], array->rank);
1128 f->value.function.name = lbound;
1133 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1135 f->ts.type = BT_INTEGER;
1137 f->ts.kind = mpz_get_si (kind->value.integer);
1139 f->ts.kind = gfc_default_integer_kind;
1140 f->value.function.name
1141 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1142 gfc_default_integer_kind);
1147 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1149 f->ts.type = BT_INTEGER;
1151 f->ts.kind = mpz_get_si (kind->value.integer);
1153 f->ts.kind = gfc_default_integer_kind;
1154 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1159 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1162 f->value.function.name
1163 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1168 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1169 gfc_expr *p2 ATTRIBUTE_UNUSED)
1171 f->ts.type = BT_INTEGER;
1172 f->ts.kind = gfc_default_integer_kind;
1173 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1178 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1180 f->ts.type= BT_INTEGER;
1181 f->ts.kind = gfc_index_integer_kind;
1182 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1187 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1190 f->value.function.name
1191 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1196 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1199 f->value.function.name
1200 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1206 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1208 f->ts.type = BT_LOGICAL;
1209 f->ts.kind = (kind == NULL)
1210 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1213 f->value.function.name
1214 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1215 gfc_type_letter (a->ts.type), a->ts.kind);
1220 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1222 if (size->ts.kind < gfc_index_integer_kind)
1226 ts.type = BT_INTEGER;
1227 ts.kind = gfc_index_integer_kind;
1228 gfc_convert_type_warn (size, &ts, 2, 0);
1231 f->ts.type = BT_INTEGER;
1232 f->ts.kind = gfc_index_integer_kind;
1233 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1238 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1242 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1244 f->ts.type = BT_LOGICAL;
1245 f->ts.kind = gfc_default_logical_kind;
1249 temp.expr_type = EXPR_OP;
1250 gfc_clear_ts (&temp.ts);
1251 temp.value.op.operator = INTRINSIC_NONE;
1252 temp.value.op.op1 = a;
1253 temp.value.op.op2 = b;
1254 gfc_type_convert_binary (&temp);
1258 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1260 f->value.function.name
1261 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1267 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1269 gfc_actual_arglist *a;
1271 f->ts.type = args->expr->ts.type;
1272 f->ts.kind = args->expr->ts.kind;
1273 /* Find the largest type kind. */
1274 for (a = args->next; a; a = a->next)
1276 if (a->expr->ts.kind > f->ts.kind)
1277 f->ts.kind = a->expr->ts.kind;
1280 /* Convert all parameters to the required kind. */
1281 for (a = args; a; a = a->next)
1283 if (a->expr->ts.kind != f->ts.kind)
1284 gfc_convert_type (a->expr, &f->ts, 2);
1287 f->value.function.name
1288 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1293 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1295 gfc_resolve_minmax ("__max_%c%d", f, args);
1300 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1306 f->ts.type = BT_INTEGER;
1307 f->ts.kind = gfc_default_integer_kind;
1312 f->shape = gfc_get_shape (1);
1313 mpz_init_set_si (f->shape[0], array->rank);
1317 f->rank = array->rank - 1;
1318 gfc_resolve_dim_arg (dim);
1319 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1321 idim = (int) mpz_get_si (dim->value.integer);
1322 f->shape = gfc_get_shape (f->rank);
1323 for (i = 0, j = 0; i < f->rank; i++, j++)
1325 if (i == (idim - 1))
1327 mpz_init_set (f->shape[i], array->shape[j]);
1334 if (mask->rank == 0)
1339 resolve_mask_arg (mask);
1344 f->value.function.name
1345 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1346 gfc_type_letter (array->ts.type), array->ts.kind);
1351 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1361 f->rank = array->rank - 1;
1362 gfc_resolve_dim_arg (dim);
1364 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1366 idim = (int) mpz_get_si (dim->value.integer);
1367 f->shape = gfc_get_shape (f->rank);
1368 for (i = 0, j = 0; i < f->rank; i++, j++)
1370 if (i == (idim - 1))
1372 mpz_init_set (f->shape[i], array->shape[j]);
1379 if (mask->rank == 0)
1384 resolve_mask_arg (mask);
1389 f->value.function.name
1390 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1391 gfc_type_letter (array->ts.type), array->ts.kind);
1396 gfc_resolve_mclock (gfc_expr *f)
1398 f->ts.type = BT_INTEGER;
1400 f->value.function.name = PREFIX ("mclock");
1405 gfc_resolve_mclock8 (gfc_expr *f)
1407 f->ts.type = BT_INTEGER;
1409 f->value.function.name = PREFIX ("mclock8");
1414 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1415 gfc_expr *fsource ATTRIBUTE_UNUSED,
1416 gfc_expr *mask ATTRIBUTE_UNUSED)
1418 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1419 gfc_resolve_substring_charlen (tsource);
1421 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1422 gfc_resolve_substring_charlen (fsource);
1424 if (tsource->ts.type == BT_CHARACTER)
1425 check_charlen_present (tsource);
1427 f->ts = tsource->ts;
1428 f->value.function.name
1429 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1435 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1437 gfc_resolve_minmax ("__min_%c%d", f, args);
1442 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1448 f->ts.type = BT_INTEGER;
1449 f->ts.kind = gfc_default_integer_kind;
1454 f->shape = gfc_get_shape (1);
1455 mpz_init_set_si (f->shape[0], array->rank);
1459 f->rank = array->rank - 1;
1460 gfc_resolve_dim_arg (dim);
1461 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1463 idim = (int) mpz_get_si (dim->value.integer);
1464 f->shape = gfc_get_shape (f->rank);
1465 for (i = 0, j = 0; i < f->rank; i++, j++)
1467 if (i == (idim - 1))
1469 mpz_init_set (f->shape[i], array->shape[j]);
1476 if (mask->rank == 0)
1481 resolve_mask_arg (mask);
1486 f->value.function.name
1487 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1488 gfc_type_letter (array->ts.type), array->ts.kind);
1493 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1503 f->rank = array->rank - 1;
1504 gfc_resolve_dim_arg (dim);
1506 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1508 idim = (int) mpz_get_si (dim->value.integer);
1509 f->shape = gfc_get_shape (f->rank);
1510 for (i = 0, j = 0; i < f->rank; i++, j++)
1512 if (i == (idim - 1))
1514 mpz_init_set (f->shape[i], array->shape[j]);
1521 if (mask->rank == 0)
1526 resolve_mask_arg (mask);
1531 f->value.function.name
1532 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1533 gfc_type_letter (array->ts.type), array->ts.kind);
1538 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1540 f->ts.type = a->ts.type;
1542 f->ts.kind = gfc_kind_max (a,p);
1544 f->ts.kind = a->ts.kind;
1546 if (p != NULL && a->ts.kind != p->ts.kind)
1548 if (a->ts.kind == gfc_kind_max (a,p))
1549 gfc_convert_type (p, &a->ts, 2);
1551 gfc_convert_type (a, &p->ts, 2);
1554 f->value.function.name
1555 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1560 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1562 f->ts.type = a->ts.type;
1564 f->ts.kind = gfc_kind_max (a,p);
1566 f->ts.kind = a->ts.kind;
1568 if (p != NULL && a->ts.kind != p->ts.kind)
1570 if (a->ts.kind == gfc_kind_max (a,p))
1571 gfc_convert_type (p, &a->ts, 2);
1573 gfc_convert_type (a, &p->ts, 2);
1576 f->value.function.name
1577 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1582 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p ATTRIBUTE_UNUSED)
1585 f->value.function.name
1586 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1591 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1593 f->ts.type = BT_INTEGER;
1594 f->ts.kind = (kind == NULL)
1595 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1596 f->value.function.name
1597 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1602 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1605 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1610 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1612 f->ts.type = i->ts.type;
1613 f->ts.kind = gfc_kind_max (i, j);
1615 if (i->ts.kind != j->ts.kind)
1617 if (i->ts.kind == gfc_kind_max (i, j))
1618 gfc_convert_type (j, &i->ts, 2);
1620 gfc_convert_type (i, &j->ts, 2);
1623 f->value.function.name
1624 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1629 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1630 gfc_expr *vector ATTRIBUTE_UNUSED)
1632 if (array->ts.type == BT_CHARACTER && array->ref)
1633 gfc_resolve_substring_charlen (array);
1638 resolve_mask_arg (mask);
1640 if (mask->rank != 0)
1641 f->value.function.name = (array->ts.type == BT_CHARACTER
1642 ? PREFIX ("pack_char") : PREFIX ("pack"));
1644 f->value.function.name = (array->ts.type == BT_CHARACTER
1645 ? PREFIX ("pack_s_char") : PREFIX ("pack_s"));
1650 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1659 f->rank = array->rank - 1;
1660 gfc_resolve_dim_arg (dim);
1665 if (mask->rank == 0)
1670 resolve_mask_arg (mask);
1675 f->value.function.name
1676 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1677 gfc_type_letter (array->ts.type), array->ts.kind);
1682 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1684 f->ts.type = BT_REAL;
1687 f->ts.kind = mpz_get_si (kind->value.integer);
1689 f->ts.kind = (a->ts.type == BT_COMPLEX)
1690 ? a->ts.kind : gfc_default_real_kind;
1692 f->value.function.name
1693 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1694 gfc_type_letter (a->ts.type), a->ts.kind);
1699 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1701 f->ts.type = BT_REAL;
1702 f->ts.kind = a->ts.kind;
1703 f->value.function.name
1704 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1705 gfc_type_letter (a->ts.type), a->ts.kind);
1710 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1711 gfc_expr *p2 ATTRIBUTE_UNUSED)
1713 f->ts.type = BT_INTEGER;
1714 f->ts.kind = gfc_default_integer_kind;
1715 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1720 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
1721 gfc_expr *ncopies ATTRIBUTE_UNUSED)
1723 f->ts.type = BT_CHARACTER;
1724 f->ts.kind = string->ts.kind;
1725 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
1730 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
1731 gfc_expr *pad ATTRIBUTE_UNUSED,
1732 gfc_expr *order ATTRIBUTE_UNUSED)
1738 if (source->ts.type == BT_CHARACTER && source->ref)
1739 gfc_resolve_substring_charlen (source);
1743 gfc_array_size (shape, &rank);
1744 f->rank = mpz_get_si (rank);
1746 switch (source->ts.type)
1752 kind = source->ts.kind;
1766 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
1767 f->value.function.name
1768 = gfc_get_string (PREFIX ("reshape_%c%d"),
1769 gfc_type_letter (source->ts.type),
1772 f->value.function.name
1773 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
1778 f->value.function.name = (source->ts.type == BT_CHARACTER
1779 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1783 /* TODO: Make this work with a constant ORDER parameter. */
1784 if (shape->expr_type == EXPR_ARRAY
1785 && gfc_is_constant_expr (shape)
1789 f->shape = gfc_get_shape (f->rank);
1790 c = shape->value.constructor;
1791 for (i = 0; i < f->rank; i++)
1793 mpz_init_set (f->shape[i], c->expr->value.integer);
1798 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
1799 so many runtime variations. */
1800 if (shape->ts.kind != gfc_index_integer_kind)
1802 gfc_typespec ts = shape->ts;
1803 ts.kind = gfc_index_integer_kind;
1804 gfc_convert_type_warn (shape, &ts, 2, 0);
1806 if (order && order->ts.kind != gfc_index_integer_kind)
1807 gfc_convert_type_warn (order, &shape->ts, 2, 0);
1812 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
1815 gfc_actual_arglist *prec;
1818 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
1820 /* Create a hidden argument to the library routines for rrspacing. This
1821 hidden argument is the precision of x. */
1822 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1823 prec = gfc_get_actual_arglist ();
1825 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1826 /* The library routine expects INTEGER(4). */
1827 if (prec->expr->ts.kind != gfc_c_int_kind)
1830 ts.type = BT_INTEGER;
1831 ts.kind = gfc_c_int_kind;
1832 gfc_convert_type (prec->expr, &ts, 2);
1834 f->value.function.actual->next = prec;
1839 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1843 /* The implementation calls scalbn which takes an int as the
1845 if (i->ts.kind != gfc_c_int_kind)
1848 ts.type = BT_INTEGER;
1849 ts.kind = gfc_c_int_kind;
1850 gfc_convert_type_warn (i, &ts, 2, 0);
1853 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
1858 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
1859 gfc_expr *set ATTRIBUTE_UNUSED,
1860 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
1862 f->ts.type = BT_INTEGER;
1864 f->ts.kind = mpz_get_si (kind->value.integer);
1866 f->ts.kind = gfc_default_integer_kind;
1867 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
1872 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
1875 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
1880 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1884 /* The library implementation uses GFC_INTEGER_4 unconditionally,
1885 convert type so we don't have to implement all possible
1887 if (i->ts.kind != gfc_c_int_kind)
1890 ts.type = BT_INTEGER;
1891 ts.kind = gfc_c_int_kind;
1892 gfc_convert_type_warn (i, &ts, 2, 0);
1895 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
1900 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
1902 f->ts.type = BT_INTEGER;
1903 f->ts.kind = gfc_default_integer_kind;
1905 f->shape = gfc_get_shape (1);
1906 mpz_init_set_ui (f->shape[0], array->rank);
1907 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
1912 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
1915 f->value.function.name
1916 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
1921 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
1923 f->ts.type = BT_INTEGER;
1924 f->ts.kind = gfc_c_int_kind;
1926 /* handler can be either BT_INTEGER or BT_PROCEDURE */
1927 if (handler->ts.type == BT_INTEGER)
1929 if (handler->ts.kind != gfc_c_int_kind)
1930 gfc_convert_type (handler, &f->ts, 2);
1931 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
1934 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
1936 if (number->ts.kind != gfc_c_int_kind)
1937 gfc_convert_type (number, &f->ts, 2);
1942 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
1945 f->value.function.name
1946 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1951 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
1954 f->value.function.name
1955 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1960 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
1961 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
1963 f->ts.type = BT_INTEGER;
1965 f->ts.kind = mpz_get_si (kind->value.integer);
1967 f->ts.kind = gfc_default_integer_kind;
1972 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
1975 gfc_actual_arglist *prec, *tiny, *emin_1;
1978 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
1980 /* Create hidden arguments to the library routine for spacing. These
1981 hidden arguments are tiny(x), min_exponent - 1, and the precision
1984 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1986 tiny = gfc_get_actual_arglist ();
1987 tiny->name = "tiny";
1988 tiny->expr = gfc_get_expr ();
1989 tiny->expr->expr_type = EXPR_CONSTANT;
1990 tiny->expr->where = gfc_current_locus;
1991 tiny->expr->ts.type = x->ts.type;
1992 tiny->expr->ts.kind = x->ts.kind;
1993 mpfr_init (tiny->expr->value.real);
1994 mpfr_set (tiny->expr->value.real, gfc_real_kinds[k].tiny, GFC_RND_MODE);
1996 emin_1 = gfc_get_actual_arglist ();
1997 emin_1->name = "emin";
1998 emin_1->expr = gfc_int_expr (gfc_real_kinds[k].min_exponent - 1);
2000 /* The library routine expects INTEGER(4). */
2001 if (emin_1->expr->ts.kind != gfc_c_int_kind)
2004 ts.type = BT_INTEGER;
2005 ts.kind = gfc_c_int_kind;
2006 gfc_convert_type (emin_1->expr, &ts, 2);
2008 emin_1->next = tiny;
2010 prec = gfc_get_actual_arglist ();
2011 prec->name = "prec";
2012 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
2014 /* The library routine expects INTEGER(4). */
2015 if (prec->expr->ts.kind != gfc_c_int_kind)
2018 ts.type = BT_INTEGER;
2019 ts.kind = gfc_c_int_kind;
2020 gfc_convert_type (prec->expr, &ts, 2);
2022 prec->next = emin_1;
2024 f->value.function.actual->next = prec;
2029 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2032 if (source->ts.type == BT_CHARACTER && source->ref)
2033 gfc_resolve_substring_charlen (source);
2035 if (source->ts.type == BT_CHARACTER)
2036 check_charlen_present (source);
2039 f->rank = source->rank + 1;
2040 if (source->rank == 0)
2041 f->value.function.name = (source->ts.type == BT_CHARACTER
2042 ? PREFIX ("spread_char_scalar")
2043 : PREFIX ("spread_scalar"));
2045 f->value.function.name = (source->ts.type == BT_CHARACTER
2046 ? PREFIX ("spread_char")
2047 : PREFIX ("spread"));
2049 if (dim && gfc_is_constant_expr (dim)
2050 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2053 idim = mpz_get_ui (dim->value.integer);
2054 f->shape = gfc_get_shape (f->rank);
2055 for (i = 0; i < (idim - 1); i++)
2056 mpz_init_set (f->shape[i], source->shape[i]);
2058 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2060 for (i = idim; i < f->rank ; i++)
2061 mpz_init_set (f->shape[i], source->shape[i-1]);
2065 gfc_resolve_dim_arg (dim);
2066 gfc_resolve_index (ncopies, 1);
2071 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2074 f->value.function.name
2075 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2079 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2082 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2083 gfc_expr *a ATTRIBUTE_UNUSED)
2085 f->ts.type = BT_INTEGER;
2086 f->ts.kind = gfc_default_integer_kind;
2087 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2092 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2093 gfc_expr *a ATTRIBUTE_UNUSED)
2095 f->ts.type = BT_INTEGER;
2096 f->ts.kind = gfc_default_integer_kind;
2097 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2102 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2104 f->ts.type = BT_INTEGER;
2105 f->ts.kind = gfc_default_integer_kind;
2106 if (n->ts.kind != f->ts.kind)
2107 gfc_convert_type (n, &f->ts, 2);
2109 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2114 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2118 f->ts.type = BT_INTEGER;
2119 f->ts.kind = gfc_c_int_kind;
2120 if (u->ts.kind != gfc_c_int_kind)
2122 ts.type = BT_INTEGER;
2123 ts.kind = gfc_c_int_kind;
2126 gfc_convert_type (u, &ts, 2);
2129 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2134 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2136 f->ts.type = BT_INTEGER;
2137 f->ts.kind = gfc_c_int_kind;
2138 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2143 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2147 f->ts.type = BT_INTEGER;
2148 f->ts.kind = gfc_c_int_kind;
2149 if (u->ts.kind != gfc_c_int_kind)
2151 ts.type = BT_INTEGER;
2152 ts.kind = gfc_c_int_kind;
2155 gfc_convert_type (u, &ts, 2);
2158 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2163 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2165 f->ts.type = BT_INTEGER;
2166 f->ts.kind = gfc_c_int_kind;
2167 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2172 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2176 f->ts.type = BT_INTEGER;
2177 f->ts.kind = gfc_index_integer_kind;
2178 if (u->ts.kind != gfc_c_int_kind)
2180 ts.type = BT_INTEGER;
2181 ts.kind = gfc_c_int_kind;
2184 gfc_convert_type (u, &ts, 2);
2187 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2192 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2200 if (mask->rank == 0)
2205 resolve_mask_arg (mask);
2212 f->rank = array->rank - 1;
2213 gfc_resolve_dim_arg (dim);
2216 f->value.function.name
2217 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2218 gfc_type_letter (array->ts.type), array->ts.kind);
2223 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2224 gfc_expr *p2 ATTRIBUTE_UNUSED)
2226 f->ts.type = BT_INTEGER;
2227 f->ts.kind = gfc_default_integer_kind;
2228 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2232 /* Resolve the g77 compatibility function SYSTEM. */
2235 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2237 f->ts.type = BT_INTEGER;
2239 f->value.function.name = gfc_get_string (PREFIX ("system"));
2244 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2247 f->value.function.name
2248 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2253 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2256 f->value.function.name
2257 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2262 gfc_resolve_time (gfc_expr *f)
2264 f->ts.type = BT_INTEGER;
2266 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2271 gfc_resolve_time8 (gfc_expr *f)
2273 f->ts.type = BT_INTEGER;
2275 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2280 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2281 gfc_expr *mold, gfc_expr *size)
2283 /* TODO: Make this do something meaningful. */
2284 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2286 if (mold->ts.type == BT_CHARACTER && !mold->ts.cl->length)
2287 mold->ts.cl->length = gfc_int_expr (mold->value.character.length);
2291 if (size == NULL && mold->rank == 0)
2294 f->value.function.name = transfer0;
2299 f->value.function.name = transfer1;
2300 if (size && gfc_is_constant_expr (size))
2302 f->shape = gfc_get_shape (1);
2303 mpz_init_set (f->shape[0], size->value.integer);
2310 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2313 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2314 gfc_resolve_substring_charlen (matrix);
2320 f->shape = gfc_get_shape (2);
2321 mpz_init_set (f->shape[0], matrix->shape[1]);
2322 mpz_init_set (f->shape[1], matrix->shape[0]);
2325 switch (matrix->ts.kind)
2331 switch (matrix->ts.type)
2335 f->value.function.name
2336 = gfc_get_string (PREFIX ("transpose_%c%d"),
2337 gfc_type_letter (matrix->ts.type),
2343 /* Use the integer routines for real and logical cases. This
2344 assumes they all have the same alignment requirements. */
2345 f->value.function.name
2346 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2350 f->value.function.name = PREFIX ("transpose");
2356 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2357 ? PREFIX ("transpose_char")
2358 : PREFIX ("transpose"));
2365 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2367 f->ts.type = BT_CHARACTER;
2368 f->ts.kind = string->ts.kind;
2369 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2374 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2376 static char ubound[] = "__ubound";
2378 f->ts.type = BT_INTEGER;
2380 f->ts.kind = mpz_get_si (kind->value.integer);
2382 f->ts.kind = gfc_default_integer_kind;
2387 f->shape = gfc_get_shape (1);
2388 mpz_init_set_ui (f->shape[0], array->rank);
2391 f->value.function.name = ubound;
2395 /* Resolve the g77 compatibility function UMASK. */
2398 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2400 f->ts.type = BT_INTEGER;
2401 f->ts.kind = n->ts.kind;
2402 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2406 /* Resolve the g77 compatibility function UNLINK. */
2409 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2411 f->ts.type = BT_INTEGER;
2413 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2418 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2422 f->ts.type = BT_CHARACTER;
2423 f->ts.kind = gfc_default_character_kind;
2425 if (unit->ts.kind != gfc_c_int_kind)
2427 ts.type = BT_INTEGER;
2428 ts.kind = gfc_c_int_kind;
2431 gfc_convert_type (unit, &ts, 2);
2434 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2439 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2440 gfc_expr *field ATTRIBUTE_UNUSED)
2442 if (vector->ts.type == BT_CHARACTER && vector->ref)
2443 gfc_resolve_substring_charlen (vector);
2446 f->rank = mask->rank;
2447 resolve_mask_arg (mask);
2449 f->value.function.name
2450 = gfc_get_string (PREFIX ("unpack%d%s"), field->rank > 0 ? 1 : 0,
2451 vector->ts.type == BT_CHARACTER ? "_char" : "");
2456 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2457 gfc_expr *set ATTRIBUTE_UNUSED,
2458 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2460 f->ts.type = BT_INTEGER;
2462 f->ts.kind = mpz_get_si (kind->value.integer);
2464 f->ts.kind = gfc_default_integer_kind;
2465 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2470 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2472 f->ts.type = i->ts.type;
2473 f->ts.kind = gfc_kind_max (i, j);
2475 if (i->ts.kind != j->ts.kind)
2477 if (i->ts.kind == gfc_kind_max (i, j))
2478 gfc_convert_type (j, &i->ts, 2);
2480 gfc_convert_type (i, &j->ts, 2);
2483 f->value.function.name
2484 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2488 /* Intrinsic subroutine resolution. */
2491 gfc_resolve_alarm_sub (gfc_code *c)
2494 gfc_expr *seconds, *handler, *status;
2497 seconds = c->ext.actual->expr;
2498 handler = c->ext.actual->next->expr;
2499 status = c->ext.actual->next->next->expr;
2500 ts.type = BT_INTEGER;
2501 ts.kind = gfc_c_int_kind;
2503 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2504 In all cases, the status argument is of default integer kind
2505 (enforced in check.c) so that the function suffix is fixed. */
2506 if (handler->ts.type == BT_INTEGER)
2508 if (handler->ts.kind != gfc_c_int_kind)
2509 gfc_convert_type (handler, &ts, 2);
2510 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2511 gfc_default_integer_kind);
2514 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2515 gfc_default_integer_kind);
2517 if (seconds->ts.kind != gfc_c_int_kind)
2518 gfc_convert_type (seconds, &ts, 2);
2520 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2524 gfc_resolve_cpu_time (gfc_code *c)
2527 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2528 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2533 gfc_resolve_mvbits (gfc_code *c)
2538 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2539 they will be converted so that they fit into a C int. */
2540 ts.type = BT_INTEGER;
2541 ts.kind = gfc_c_int_kind;
2542 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2543 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2544 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2545 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2546 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2547 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2549 /* TO and FROM are guaranteed to have the same kind parameter. */
2550 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2551 c->ext.actual->expr->ts.kind);
2552 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2557 gfc_resolve_random_number (gfc_code *c)
2562 kind = c->ext.actual->expr->ts.kind;
2563 if (c->ext.actual->expr->rank == 0)
2564 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2566 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2568 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2573 gfc_resolve_random_seed (gfc_code *c)
2577 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2578 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2583 gfc_resolve_rename_sub (gfc_code *c)
2588 if (c->ext.actual->next->next->expr != NULL)
2589 kind = c->ext.actual->next->next->expr->ts.kind;
2591 kind = gfc_default_integer_kind;
2593 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2594 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2599 gfc_resolve_kill_sub (gfc_code *c)
2604 if (c->ext.actual->next->next->expr != NULL)
2605 kind = c->ext.actual->next->next->expr->ts.kind;
2607 kind = gfc_default_integer_kind;
2609 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2610 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2615 gfc_resolve_link_sub (gfc_code *c)
2620 if (c->ext.actual->next->next->expr != NULL)
2621 kind = c->ext.actual->next->next->expr->ts.kind;
2623 kind = gfc_default_integer_kind;
2625 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2626 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2631 gfc_resolve_symlnk_sub (gfc_code *c)
2636 if (c->ext.actual->next->next->expr != NULL)
2637 kind = c->ext.actual->next->next->expr->ts.kind;
2639 kind = gfc_default_integer_kind;
2641 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2642 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2646 /* G77 compatibility subroutines etime() and dtime(). */
2649 gfc_resolve_etime_sub (gfc_code *c)
2652 name = gfc_get_string (PREFIX ("etime_sub"));
2653 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2657 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2660 gfc_resolve_itime (gfc_code *c)
2663 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2664 gfc_default_integer_kind));
2668 gfc_resolve_idate (gfc_code *c)
2671 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2672 gfc_default_integer_kind));
2676 gfc_resolve_ltime (gfc_code *c)
2679 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2680 gfc_default_integer_kind));
2684 gfc_resolve_gmtime (gfc_code *c)
2687 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2688 gfc_default_integer_kind));
2692 /* G77 compatibility subroutine second(). */
2695 gfc_resolve_second_sub (gfc_code *c)
2698 name = gfc_get_string (PREFIX ("second_sub"));
2699 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2704 gfc_resolve_sleep_sub (gfc_code *c)
2709 if (c->ext.actual->expr != NULL)
2710 kind = c->ext.actual->expr->ts.kind;
2712 kind = gfc_default_integer_kind;
2714 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2715 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2719 /* G77 compatibility function srand(). */
2722 gfc_resolve_srand (gfc_code *c)
2725 name = gfc_get_string (PREFIX ("srand"));
2726 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2730 /* Resolve the getarg intrinsic subroutine. */
2733 gfc_resolve_getarg (gfc_code *c)
2737 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
2741 ts.type = BT_INTEGER;
2742 ts.kind = gfc_default_integer_kind;
2744 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2747 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
2748 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2752 /* Resolve the getcwd intrinsic subroutine. */
2755 gfc_resolve_getcwd_sub (gfc_code *c)
2760 if (c->ext.actual->next->expr != NULL)
2761 kind = c->ext.actual->next->expr->ts.kind;
2763 kind = gfc_default_integer_kind;
2765 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2766 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2770 /* Resolve the get_command intrinsic subroutine. */
2773 gfc_resolve_get_command (gfc_code *c)
2777 kind = gfc_default_integer_kind;
2778 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2779 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2783 /* Resolve the get_command_argument intrinsic subroutine. */
2786 gfc_resolve_get_command_argument (gfc_code *c)
2790 kind = gfc_default_integer_kind;
2791 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2792 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2796 /* Resolve the get_environment_variable intrinsic subroutine. */
2799 gfc_resolve_get_environment_variable (gfc_code *code)
2803 kind = gfc_default_integer_kind;
2804 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2805 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2810 gfc_resolve_signal_sub (gfc_code *c)
2813 gfc_expr *number, *handler, *status;
2816 number = c->ext.actual->expr;
2817 handler = c->ext.actual->next->expr;
2818 status = c->ext.actual->next->next->expr;
2819 ts.type = BT_INTEGER;
2820 ts.kind = gfc_c_int_kind;
2822 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2823 if (handler->ts.type == BT_INTEGER)
2825 if (handler->ts.kind != gfc_c_int_kind)
2826 gfc_convert_type (handler, &ts, 2);
2827 name = gfc_get_string (PREFIX ("signal_sub_int"));
2830 name = gfc_get_string (PREFIX ("signal_sub"));
2832 if (number->ts.kind != gfc_c_int_kind)
2833 gfc_convert_type (number, &ts, 2);
2834 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2835 gfc_convert_type (status, &ts, 2);
2837 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2841 /* Resolve the SYSTEM intrinsic subroutine. */
2844 gfc_resolve_system_sub (gfc_code *c)
2847 name = gfc_get_string (PREFIX ("system_sub"));
2848 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2852 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2855 gfc_resolve_system_clock (gfc_code *c)
2860 if (c->ext.actual->expr != NULL)
2861 kind = c->ext.actual->expr->ts.kind;
2862 else if (c->ext.actual->next->expr != NULL)
2863 kind = c->ext.actual->next->expr->ts.kind;
2864 else if (c->ext.actual->next->next->expr != NULL)
2865 kind = c->ext.actual->next->next->expr->ts.kind;
2867 kind = gfc_default_integer_kind;
2869 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
2870 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2874 /* Resolve the EXIT intrinsic subroutine. */
2877 gfc_resolve_exit (gfc_code *c)
2883 /* The STATUS argument has to be of default kind. If it is not,
2885 ts.type = BT_INTEGER;
2886 ts.kind = gfc_default_integer_kind;
2887 n = c->ext.actual->expr;
2888 if (n != NULL && n->ts.kind != ts.kind)
2889 gfc_convert_type (n, &ts, 2);
2891 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
2892 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2896 /* Resolve the FLUSH intrinsic subroutine. */
2899 gfc_resolve_flush (gfc_code *c)
2905 ts.type = BT_INTEGER;
2906 ts.kind = gfc_default_integer_kind;
2907 n = c->ext.actual->expr;
2908 if (n != NULL && n->ts.kind != ts.kind)
2909 gfc_convert_type (n, &ts, 2);
2911 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
2912 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2917 gfc_resolve_free (gfc_code *c)
2922 ts.type = BT_INTEGER;
2923 ts.kind = gfc_index_integer_kind;
2924 n = c->ext.actual->expr;
2925 if (n->ts.kind != ts.kind)
2926 gfc_convert_type (n, &ts, 2);
2928 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
2933 gfc_resolve_ctime_sub (gfc_code *c)
2937 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
2938 if (c->ext.actual->expr->ts.kind != 8)
2940 ts.type = BT_INTEGER;
2944 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2947 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
2952 gfc_resolve_fdate_sub (gfc_code *c)
2954 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
2959 gfc_resolve_gerror (gfc_code *c)
2961 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
2966 gfc_resolve_getlog (gfc_code *c)
2968 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
2973 gfc_resolve_hostnm_sub (gfc_code *c)
2978 if (c->ext.actual->next->expr != NULL)
2979 kind = c->ext.actual->next->expr->ts.kind;
2981 kind = gfc_default_integer_kind;
2983 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
2984 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2989 gfc_resolve_perror (gfc_code *c)
2991 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
2994 /* Resolve the STAT and FSTAT intrinsic subroutines. */
2997 gfc_resolve_stat_sub (gfc_code *c)
3000 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3001 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3006 gfc_resolve_lstat_sub (gfc_code *c)
3009 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3010 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3015 gfc_resolve_fstat_sub (gfc_code *c)
3021 u = c->ext.actual->expr;
3022 ts = &c->ext.actual->next->expr->ts;
3023 if (u->ts.kind != ts->kind)
3024 gfc_convert_type (u, ts, 2);
3025 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3026 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3031 gfc_resolve_fgetc_sub (gfc_code *c)
3037 u = c->ext.actual->expr;
3038 st = c->ext.actual->next->next->expr;
3040 if (u->ts.kind != gfc_c_int_kind)
3042 ts.type = BT_INTEGER;
3043 ts.kind = gfc_c_int_kind;
3046 gfc_convert_type (u, &ts, 2);
3050 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3052 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3054 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3059 gfc_resolve_fget_sub (gfc_code *c)
3064 st = c->ext.actual->next->expr;
3066 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3068 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3070 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3075 gfc_resolve_fputc_sub (gfc_code *c)
3081 u = c->ext.actual->expr;
3082 st = c->ext.actual->next->next->expr;
3084 if (u->ts.kind != gfc_c_int_kind)
3086 ts.type = BT_INTEGER;
3087 ts.kind = gfc_c_int_kind;
3090 gfc_convert_type (u, &ts, 2);
3094 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3096 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3098 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3103 gfc_resolve_fput_sub (gfc_code *c)
3108 st = c->ext.actual->next->expr;
3110 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3112 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3114 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3119 gfc_resolve_fseek_sub (gfc_code *c)
3127 unit = c->ext.actual->expr;
3128 offset = c->ext.actual->next->expr;
3129 whence = c->ext.actual->next->next->expr;
3130 status = c->ext.actual->next->next->next->expr;
3132 if (unit->ts.kind != gfc_c_int_kind)
3134 ts.type = BT_INTEGER;
3135 ts.kind = gfc_c_int_kind;
3138 gfc_convert_type (unit, &ts, 2);
3141 if (offset->ts.kind != gfc_intio_kind)
3143 ts.type = BT_INTEGER;
3144 ts.kind = gfc_intio_kind;
3147 gfc_convert_type (offset, &ts, 2);
3150 if (whence->ts.kind != gfc_c_int_kind)
3152 ts.type = BT_INTEGER;
3153 ts.kind = gfc_c_int_kind;
3156 gfc_convert_type (whence, &ts, 2);
3159 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3163 gfc_resolve_ftell_sub (gfc_code *c)
3170 unit = c->ext.actual->expr;
3171 offset = c->ext.actual->next->expr;
3173 if (unit->ts.kind != gfc_c_int_kind)
3175 ts.type = BT_INTEGER;
3176 ts.kind = gfc_c_int_kind;
3179 gfc_convert_type (unit, &ts, 2);
3182 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3183 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3188 gfc_resolve_ttynam_sub (gfc_code *c)
3192 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3194 ts.type = BT_INTEGER;
3195 ts.kind = gfc_c_int_kind;
3198 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3201 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3205 /* Resolve the UMASK intrinsic subroutine. */
3208 gfc_resolve_umask_sub (gfc_code *c)
3213 if (c->ext.actual->next->expr != NULL)
3214 kind = c->ext.actual->next->expr->ts.kind;
3216 kind = gfc_default_integer_kind;
3218 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3219 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3222 /* Resolve the UNLINK intrinsic subroutine. */
3225 gfc_resolve_unlink_sub (gfc_code *c)
3230 if (c->ext.actual->next->expr != NULL)
3231 kind = c->ext.actual->next->expr->ts.kind;
3233 kind = gfc_default_integer_kind;
3235 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3236 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);