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 /* If dim kind is greater than default integer we need to use the larger. */
577 m = gfc_default_integer_kind;
579 m = m < dim->ts.kind ? dim->ts.kind : m;
581 /* Convert shift to at least m, so we don't need
582 kind=1 and kind=2 versions of the library functions. */
583 if (shift->ts.kind < m)
586 ts.type = BT_INTEGER;
588 gfc_convert_type_warn (shift, &ts, 2, 0);
593 if (dim->expr_type != EXPR_CONSTANT && dim->symtree->n.sym->attr.optional)
595 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
596 dim->representation.length = shift->ts.kind;
600 gfc_resolve_dim_arg (dim);
601 /* Convert dim to shift's kind to reduce variations. */
602 if (dim->ts.kind != shift->ts.kind)
603 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
607 f->value.function.name
608 = gfc_get_string (PREFIX ("cshift%d_%d%s"), n, shift->ts.kind,
609 array->ts.type == BT_CHARACTER ? "_char" : "");
614 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
618 f->ts.type = BT_CHARACTER;
619 f->ts.kind = gfc_default_character_kind;
621 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
622 if (time->ts.kind != 8)
624 ts.type = BT_INTEGER;
628 gfc_convert_type (time, &ts, 2);
631 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
636 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
638 f->ts.type = BT_REAL;
639 f->ts.kind = gfc_default_double_kind;
640 f->value.function.name
641 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
646 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
648 f->ts.type = a->ts.type;
650 f->ts.kind = gfc_kind_max (a,p);
652 f->ts.kind = a->ts.kind;
654 if (p != NULL && a->ts.kind != p->ts.kind)
656 if (a->ts.kind == gfc_kind_max (a,p))
657 gfc_convert_type (p, &a->ts, 2);
659 gfc_convert_type (a, &p->ts, 2);
662 f->value.function.name
663 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
668 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
672 temp.expr_type = EXPR_OP;
673 gfc_clear_ts (&temp.ts);
674 temp.value.op.operator = INTRINSIC_NONE;
675 temp.value.op.op1 = a;
676 temp.value.op.op2 = b;
677 gfc_type_convert_binary (&temp);
679 f->value.function.name
680 = gfc_get_string (PREFIX ("dot_product_%c%d"),
681 gfc_type_letter (f->ts.type), f->ts.kind);
686 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
687 gfc_expr *b ATTRIBUTE_UNUSED)
689 f->ts.kind = gfc_default_double_kind;
690 f->ts.type = BT_REAL;
691 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
696 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
697 gfc_expr *boundary, gfc_expr *dim)
701 if (array->ts.type == BT_CHARACTER && array->ref)
702 gfc_resolve_substring_charlen (array);
705 f->rank = array->rank;
706 f->shape = gfc_copy_shape (array->shape, array->rank);
711 if (boundary && boundary->rank > 0)
714 /* If dim kind is greater than default integer we need to use the larger. */
715 m = gfc_default_integer_kind;
717 m = m < dim->ts.kind ? dim->ts.kind : m;
719 /* Convert shift to at least m, so we don't need
720 kind=1 and kind=2 versions of the library functions. */
721 if (shift->ts.kind < m)
724 ts.type = BT_INTEGER;
726 gfc_convert_type_warn (shift, &ts, 2, 0);
731 if (dim->expr_type != EXPR_CONSTANT && dim->symtree->n.sym->attr.optional)
733 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
734 dim->representation.length = shift->ts.kind;
738 gfc_resolve_dim_arg (dim);
739 /* Convert dim to shift's kind to reduce variations. */
740 if (dim->ts.kind != shift->ts.kind)
741 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
745 f->value.function.name
746 = gfc_get_string (PREFIX ("eoshift%d_%d%s"), n, shift->ts.kind,
747 array->ts.type == BT_CHARACTER ? "_char" : "");
752 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
755 f->value.function.name
756 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
761 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
763 f->ts.type = BT_INTEGER;
764 f->ts.kind = gfc_default_integer_kind;
765 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
770 gfc_resolve_fdate (gfc_expr *f)
772 f->ts.type = BT_CHARACTER;
773 f->ts.kind = gfc_default_character_kind;
774 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
779 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
781 f->ts.type = BT_INTEGER;
782 f->ts.kind = (kind == NULL)
783 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
784 f->value.function.name
785 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
786 gfc_type_letter (a->ts.type), a->ts.kind);
791 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
793 f->ts.type = BT_INTEGER;
794 f->ts.kind = gfc_default_integer_kind;
795 if (n->ts.kind != f->ts.kind)
796 gfc_convert_type (n, &f->ts, 2);
797 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
802 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
805 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
809 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
812 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
815 f->value.function.name = gfc_get_string ("<intrinsic>");
820 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
823 f->value.function.name
824 = gfc_get_string ("__gamma_%d", x->ts.kind);
829 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
831 f->ts.type = BT_INTEGER;
833 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
838 gfc_resolve_getgid (gfc_expr *f)
840 f->ts.type = BT_INTEGER;
842 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
847 gfc_resolve_getpid (gfc_expr *f)
849 f->ts.type = BT_INTEGER;
851 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
856 gfc_resolve_getuid (gfc_expr *f)
858 f->ts.type = BT_INTEGER;
860 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
865 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
867 f->ts.type = BT_INTEGER;
869 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
874 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
876 /* If the kind of i and j are different, then g77 cross-promoted the
877 kinds to the largest value. The Fortran 95 standard requires the
879 if (i->ts.kind != j->ts.kind)
881 if (i->ts.kind == gfc_kind_max (i, j))
882 gfc_convert_type (j, &i->ts, 2);
884 gfc_convert_type (i, &j->ts, 2);
888 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
893 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
896 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
901 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
902 gfc_expr *len ATTRIBUTE_UNUSED)
905 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
910 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
913 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
918 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
920 f->ts.type = BT_INTEGER;
922 f->ts.kind = mpz_get_si (kind->value.integer);
924 f->ts.kind = gfc_default_integer_kind;
925 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
930 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
932 f->ts.type = BT_INTEGER;
934 f->ts.kind = mpz_get_si (kind->value.integer);
936 f->ts.kind = gfc_default_integer_kind;
937 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
942 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
944 gfc_resolve_nint (f, a, NULL);
949 gfc_resolve_ierrno (gfc_expr *f)
951 f->ts.type = BT_INTEGER;
952 f->ts.kind = gfc_default_integer_kind;
953 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
958 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
960 /* If the kind of i and j are different, then g77 cross-promoted the
961 kinds to the largest value. The Fortran 95 standard requires the
963 if (i->ts.kind != j->ts.kind)
965 if (i->ts.kind == gfc_kind_max (i, j))
966 gfc_convert_type (j, &i->ts, 2);
968 gfc_convert_type (i, &j->ts, 2);
972 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
977 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
979 /* If the kind of i and j are different, then g77 cross-promoted the
980 kinds to the largest value. The Fortran 95 standard requires the
982 if (i->ts.kind != j->ts.kind)
984 if (i->ts.kind == gfc_kind_max (i, j))
985 gfc_convert_type (j, &i->ts, 2);
987 gfc_convert_type (i, &j->ts, 2);
991 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
996 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
997 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
1002 f->ts.type = BT_INTEGER;
1004 f->ts.kind = mpz_get_si (kind->value.integer);
1006 f->ts.kind = gfc_default_integer_kind;
1008 if (back && back->ts.kind != gfc_default_integer_kind)
1010 ts.type = BT_LOGICAL;
1011 ts.kind = gfc_default_integer_kind;
1014 gfc_convert_type (back, &ts, 2);
1017 f->value.function.name
1018 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
1023 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1025 f->ts.type = BT_INTEGER;
1026 f->ts.kind = (kind == NULL)
1027 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1028 f->value.function.name
1029 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1030 gfc_type_letter (a->ts.type), a->ts.kind);
1035 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1037 f->ts.type = BT_INTEGER;
1039 f->value.function.name
1040 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1041 gfc_type_letter (a->ts.type), a->ts.kind);
1046 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
1048 f->ts.type = BT_INTEGER;
1050 f->value.function.name
1051 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1052 gfc_type_letter (a->ts.type), a->ts.kind);
1057 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1059 f->ts.type = BT_INTEGER;
1061 f->value.function.name
1062 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1063 gfc_type_letter (a->ts.type), a->ts.kind);
1068 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1072 f->ts.type = BT_LOGICAL;
1073 f->ts.kind = gfc_default_integer_kind;
1074 if (u->ts.kind != gfc_c_int_kind)
1076 ts.type = BT_INTEGER;
1077 ts.kind = gfc_c_int_kind;
1080 gfc_convert_type (u, &ts, 2);
1083 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1088 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1091 f->value.function.name
1092 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1097 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1100 f->value.function.name
1101 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1106 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1109 f->value.function.name
1110 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1115 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1119 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1122 f->value.function.name
1123 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1128 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1129 gfc_expr *s ATTRIBUTE_UNUSED)
1131 f->ts.type = BT_INTEGER;
1132 f->ts.kind = gfc_default_integer_kind;
1133 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1138 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1140 static char lbound[] = "__lbound";
1142 f->ts.type = BT_INTEGER;
1144 f->ts.kind = mpz_get_si (kind->value.integer);
1146 f->ts.kind = gfc_default_integer_kind;
1151 f->shape = gfc_get_shape (1);
1152 mpz_init_set_ui (f->shape[0], array->rank);
1155 f->value.function.name = lbound;
1160 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1162 f->ts.type = BT_INTEGER;
1164 f->ts.kind = mpz_get_si (kind->value.integer);
1166 f->ts.kind = gfc_default_integer_kind;
1167 f->value.function.name
1168 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1169 gfc_default_integer_kind);
1174 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1176 f->ts.type = BT_INTEGER;
1178 f->ts.kind = mpz_get_si (kind->value.integer);
1180 f->ts.kind = gfc_default_integer_kind;
1181 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1186 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1189 f->value.function.name
1190 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1195 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1196 gfc_expr *p2 ATTRIBUTE_UNUSED)
1198 f->ts.type = BT_INTEGER;
1199 f->ts.kind = gfc_default_integer_kind;
1200 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1205 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1207 f->ts.type= BT_INTEGER;
1208 f->ts.kind = gfc_index_integer_kind;
1209 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1214 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1217 f->value.function.name
1218 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1223 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1226 f->value.function.name
1227 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1233 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1235 f->ts.type = BT_LOGICAL;
1236 f->ts.kind = (kind == NULL)
1237 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1240 f->value.function.name
1241 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1242 gfc_type_letter (a->ts.type), a->ts.kind);
1247 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1249 if (size->ts.kind < gfc_index_integer_kind)
1253 ts.type = BT_INTEGER;
1254 ts.kind = gfc_index_integer_kind;
1255 gfc_convert_type_warn (size, &ts, 2, 0);
1258 f->ts.type = BT_INTEGER;
1259 f->ts.kind = gfc_index_integer_kind;
1260 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1265 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1269 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1271 f->ts.type = BT_LOGICAL;
1272 f->ts.kind = gfc_default_logical_kind;
1276 temp.expr_type = EXPR_OP;
1277 gfc_clear_ts (&temp.ts);
1278 temp.value.op.operator = INTRINSIC_NONE;
1279 temp.value.op.op1 = a;
1280 temp.value.op.op2 = b;
1281 gfc_type_convert_binary (&temp);
1285 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1287 f->value.function.name
1288 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1294 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1296 gfc_actual_arglist *a;
1298 f->ts.type = args->expr->ts.type;
1299 f->ts.kind = args->expr->ts.kind;
1300 /* Find the largest type kind. */
1301 for (a = args->next; a; a = a->next)
1303 if (a->expr->ts.kind > f->ts.kind)
1304 f->ts.kind = a->expr->ts.kind;
1307 /* Convert all parameters to the required kind. */
1308 for (a = args; a; a = a->next)
1310 if (a->expr->ts.kind != f->ts.kind)
1311 gfc_convert_type (a->expr, &f->ts, 2);
1314 f->value.function.name
1315 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1320 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1322 gfc_resolve_minmax ("__max_%c%d", f, args);
1327 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1333 f->ts.type = BT_INTEGER;
1334 f->ts.kind = gfc_default_integer_kind;
1339 f->shape = gfc_get_shape (1);
1340 mpz_init_set_si (f->shape[0], array->rank);
1344 f->rank = array->rank - 1;
1345 gfc_resolve_dim_arg (dim);
1346 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1348 idim = (int) mpz_get_si (dim->value.integer);
1349 f->shape = gfc_get_shape (f->rank);
1350 for (i = 0, j = 0; i < f->rank; i++, j++)
1352 if (i == (idim - 1))
1354 mpz_init_set (f->shape[i], array->shape[j]);
1361 if (mask->rank == 0)
1366 resolve_mask_arg (mask);
1371 f->value.function.name
1372 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1373 gfc_type_letter (array->ts.type), array->ts.kind);
1378 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1388 f->rank = array->rank - 1;
1389 gfc_resolve_dim_arg (dim);
1391 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1393 idim = (int) mpz_get_si (dim->value.integer);
1394 f->shape = gfc_get_shape (f->rank);
1395 for (i = 0, j = 0; i < f->rank; i++, j++)
1397 if (i == (idim - 1))
1399 mpz_init_set (f->shape[i], array->shape[j]);
1406 if (mask->rank == 0)
1411 resolve_mask_arg (mask);
1416 f->value.function.name
1417 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1418 gfc_type_letter (array->ts.type), array->ts.kind);
1423 gfc_resolve_mclock (gfc_expr *f)
1425 f->ts.type = BT_INTEGER;
1427 f->value.function.name = PREFIX ("mclock");
1432 gfc_resolve_mclock8 (gfc_expr *f)
1434 f->ts.type = BT_INTEGER;
1436 f->value.function.name = PREFIX ("mclock8");
1441 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1442 gfc_expr *fsource ATTRIBUTE_UNUSED,
1443 gfc_expr *mask ATTRIBUTE_UNUSED)
1445 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1446 gfc_resolve_substring_charlen (tsource);
1448 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1449 gfc_resolve_substring_charlen (fsource);
1451 if (tsource->ts.type == BT_CHARACTER)
1452 check_charlen_present (tsource);
1454 f->ts = tsource->ts;
1455 f->value.function.name
1456 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1462 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1464 gfc_resolve_minmax ("__min_%c%d", f, args);
1469 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1475 f->ts.type = BT_INTEGER;
1476 f->ts.kind = gfc_default_integer_kind;
1481 f->shape = gfc_get_shape (1);
1482 mpz_init_set_si (f->shape[0], array->rank);
1486 f->rank = array->rank - 1;
1487 gfc_resolve_dim_arg (dim);
1488 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1490 idim = (int) mpz_get_si (dim->value.integer);
1491 f->shape = gfc_get_shape (f->rank);
1492 for (i = 0, j = 0; i < f->rank; i++, j++)
1494 if (i == (idim - 1))
1496 mpz_init_set (f->shape[i], array->shape[j]);
1503 if (mask->rank == 0)
1508 resolve_mask_arg (mask);
1513 f->value.function.name
1514 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1515 gfc_type_letter (array->ts.type), array->ts.kind);
1520 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1530 f->rank = array->rank - 1;
1531 gfc_resolve_dim_arg (dim);
1533 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1535 idim = (int) mpz_get_si (dim->value.integer);
1536 f->shape = gfc_get_shape (f->rank);
1537 for (i = 0, j = 0; i < f->rank; i++, j++)
1539 if (i == (idim - 1))
1541 mpz_init_set (f->shape[i], array->shape[j]);
1548 if (mask->rank == 0)
1553 resolve_mask_arg (mask);
1558 f->value.function.name
1559 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1560 gfc_type_letter (array->ts.type), array->ts.kind);
1565 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1567 f->ts.type = a->ts.type;
1569 f->ts.kind = gfc_kind_max (a,p);
1571 f->ts.kind = a->ts.kind;
1573 if (p != NULL && a->ts.kind != p->ts.kind)
1575 if (a->ts.kind == gfc_kind_max (a,p))
1576 gfc_convert_type (p, &a->ts, 2);
1578 gfc_convert_type (a, &p->ts, 2);
1581 f->value.function.name
1582 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1587 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1589 f->ts.type = a->ts.type;
1591 f->ts.kind = gfc_kind_max (a,p);
1593 f->ts.kind = a->ts.kind;
1595 if (p != NULL && a->ts.kind != p->ts.kind)
1597 if (a->ts.kind == gfc_kind_max (a,p))
1598 gfc_convert_type (p, &a->ts, 2);
1600 gfc_convert_type (a, &p->ts, 2);
1603 f->value.function.name
1604 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1609 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1611 if (p->ts.kind != a->ts.kind)
1612 gfc_convert_type (p, &a->ts, 2);
1615 f->value.function.name
1616 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1621 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1623 f->ts.type = BT_INTEGER;
1624 f->ts.kind = (kind == NULL)
1625 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1626 f->value.function.name
1627 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1632 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1635 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1640 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1642 f->ts.type = i->ts.type;
1643 f->ts.kind = gfc_kind_max (i, j);
1645 if (i->ts.kind != j->ts.kind)
1647 if (i->ts.kind == gfc_kind_max (i, j))
1648 gfc_convert_type (j, &i->ts, 2);
1650 gfc_convert_type (i, &j->ts, 2);
1653 f->value.function.name
1654 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1659 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1660 gfc_expr *vector ATTRIBUTE_UNUSED)
1662 if (array->ts.type == BT_CHARACTER && array->ref)
1663 gfc_resolve_substring_charlen (array);
1668 resolve_mask_arg (mask);
1670 if (mask->rank != 0)
1671 f->value.function.name = (array->ts.type == BT_CHARACTER
1672 ? PREFIX ("pack_char") : PREFIX ("pack"));
1674 f->value.function.name = (array->ts.type == BT_CHARACTER
1675 ? PREFIX ("pack_s_char") : PREFIX ("pack_s"));
1680 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1689 f->rank = array->rank - 1;
1690 gfc_resolve_dim_arg (dim);
1695 if (mask->rank == 0)
1700 resolve_mask_arg (mask);
1705 f->value.function.name
1706 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1707 gfc_type_letter (array->ts.type), array->ts.kind);
1712 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1714 f->ts.type = BT_REAL;
1717 f->ts.kind = mpz_get_si (kind->value.integer);
1719 f->ts.kind = (a->ts.type == BT_COMPLEX)
1720 ? a->ts.kind : gfc_default_real_kind;
1722 f->value.function.name
1723 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1724 gfc_type_letter (a->ts.type), a->ts.kind);
1729 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1731 f->ts.type = BT_REAL;
1732 f->ts.kind = a->ts.kind;
1733 f->value.function.name
1734 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1735 gfc_type_letter (a->ts.type), a->ts.kind);
1740 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1741 gfc_expr *p2 ATTRIBUTE_UNUSED)
1743 f->ts.type = BT_INTEGER;
1744 f->ts.kind = gfc_default_integer_kind;
1745 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1750 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
1751 gfc_expr *ncopies ATTRIBUTE_UNUSED)
1753 f->ts.type = BT_CHARACTER;
1754 f->ts.kind = string->ts.kind;
1755 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
1760 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
1761 gfc_expr *pad ATTRIBUTE_UNUSED,
1762 gfc_expr *order ATTRIBUTE_UNUSED)
1768 if (source->ts.type == BT_CHARACTER && source->ref)
1769 gfc_resolve_substring_charlen (source);
1773 gfc_array_size (shape, &rank);
1774 f->rank = mpz_get_si (rank);
1776 switch (source->ts.type)
1782 kind = source->ts.kind;
1796 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
1797 f->value.function.name
1798 = gfc_get_string (PREFIX ("reshape_%c%d"),
1799 gfc_type_letter (source->ts.type),
1802 f->value.function.name
1803 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
1808 f->value.function.name = (source->ts.type == BT_CHARACTER
1809 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1813 /* TODO: Make this work with a constant ORDER parameter. */
1814 if (shape->expr_type == EXPR_ARRAY
1815 && gfc_is_constant_expr (shape)
1819 f->shape = gfc_get_shape (f->rank);
1820 c = shape->value.constructor;
1821 for (i = 0; i < f->rank; i++)
1823 mpz_init_set (f->shape[i], c->expr->value.integer);
1828 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
1829 so many runtime variations. */
1830 if (shape->ts.kind != gfc_index_integer_kind)
1832 gfc_typespec ts = shape->ts;
1833 ts.kind = gfc_index_integer_kind;
1834 gfc_convert_type_warn (shape, &ts, 2, 0);
1836 if (order && order->ts.kind != gfc_index_integer_kind)
1837 gfc_convert_type_warn (order, &shape->ts, 2, 0);
1842 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
1845 gfc_actual_arglist *prec;
1848 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
1850 /* Create a hidden argument to the library routines for rrspacing. This
1851 hidden argument is the precision of x. */
1852 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1853 prec = gfc_get_actual_arglist ();
1855 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1856 /* The library routine expects INTEGER(4). */
1857 if (prec->expr->ts.kind != gfc_c_int_kind)
1860 ts.type = BT_INTEGER;
1861 ts.kind = gfc_c_int_kind;
1862 gfc_convert_type (prec->expr, &ts, 2);
1864 f->value.function.actual->next = prec;
1869 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1873 /* The implementation calls scalbn which takes an int as the
1875 if (i->ts.kind != gfc_c_int_kind)
1878 ts.type = BT_INTEGER;
1879 ts.kind = gfc_c_int_kind;
1880 gfc_convert_type_warn (i, &ts, 2, 0);
1883 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
1888 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
1889 gfc_expr *set ATTRIBUTE_UNUSED,
1890 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
1892 f->ts.type = BT_INTEGER;
1894 f->ts.kind = mpz_get_si (kind->value.integer);
1896 f->ts.kind = gfc_default_integer_kind;
1897 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
1902 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
1905 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
1910 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1914 /* The library implementation uses GFC_INTEGER_4 unconditionally,
1915 convert type so we don't have to implement all possible
1917 if (i->ts.kind != gfc_c_int_kind)
1920 ts.type = BT_INTEGER;
1921 ts.kind = gfc_c_int_kind;
1922 gfc_convert_type_warn (i, &ts, 2, 0);
1925 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
1930 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
1932 f->ts.type = BT_INTEGER;
1933 f->ts.kind = gfc_default_integer_kind;
1935 f->shape = gfc_get_shape (1);
1936 mpz_init_set_ui (f->shape[0], array->rank);
1937 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
1942 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
1945 f->value.function.name
1946 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
1951 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
1953 f->ts.type = BT_INTEGER;
1954 f->ts.kind = gfc_c_int_kind;
1956 /* handler can be either BT_INTEGER or BT_PROCEDURE */
1957 if (handler->ts.type == BT_INTEGER)
1959 if (handler->ts.kind != gfc_c_int_kind)
1960 gfc_convert_type (handler, &f->ts, 2);
1961 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
1964 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
1966 if (number->ts.kind != gfc_c_int_kind)
1967 gfc_convert_type (number, &f->ts, 2);
1972 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
1975 f->value.function.name
1976 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1981 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
1984 f->value.function.name
1985 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1990 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
1991 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
1993 f->ts.type = BT_INTEGER;
1995 f->ts.kind = mpz_get_si (kind->value.integer);
1997 f->ts.kind = gfc_default_integer_kind;
2002 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
2005 gfc_actual_arglist *prec, *tiny, *emin_1;
2008 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
2010 /* Create hidden arguments to the library routine for spacing. These
2011 hidden arguments are tiny(x), min_exponent - 1, and the precision
2014 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
2016 tiny = gfc_get_actual_arglist ();
2017 tiny->name = "tiny";
2018 tiny->expr = gfc_get_expr ();
2019 tiny->expr->expr_type = EXPR_CONSTANT;
2020 tiny->expr->where = gfc_current_locus;
2021 tiny->expr->ts.type = x->ts.type;
2022 tiny->expr->ts.kind = x->ts.kind;
2023 mpfr_init (tiny->expr->value.real);
2024 mpfr_set (tiny->expr->value.real, gfc_real_kinds[k].tiny, GFC_RND_MODE);
2026 emin_1 = gfc_get_actual_arglist ();
2027 emin_1->name = "emin";
2028 emin_1->expr = gfc_int_expr (gfc_real_kinds[k].min_exponent - 1);
2030 /* The library routine expects INTEGER(4). */
2031 if (emin_1->expr->ts.kind != gfc_c_int_kind)
2034 ts.type = BT_INTEGER;
2035 ts.kind = gfc_c_int_kind;
2036 gfc_convert_type (emin_1->expr, &ts, 2);
2038 emin_1->next = tiny;
2040 prec = gfc_get_actual_arglist ();
2041 prec->name = "prec";
2042 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
2044 /* The library routine expects INTEGER(4). */
2045 if (prec->expr->ts.kind != gfc_c_int_kind)
2048 ts.type = BT_INTEGER;
2049 ts.kind = gfc_c_int_kind;
2050 gfc_convert_type (prec->expr, &ts, 2);
2052 prec->next = emin_1;
2054 f->value.function.actual->next = prec;
2059 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2062 if (source->ts.type == BT_CHARACTER && source->ref)
2063 gfc_resolve_substring_charlen (source);
2065 if (source->ts.type == BT_CHARACTER)
2066 check_charlen_present (source);
2069 f->rank = source->rank + 1;
2070 if (source->rank == 0)
2071 f->value.function.name = (source->ts.type == BT_CHARACTER
2072 ? PREFIX ("spread_char_scalar")
2073 : PREFIX ("spread_scalar"));
2075 f->value.function.name = (source->ts.type == BT_CHARACTER
2076 ? PREFIX ("spread_char")
2077 : PREFIX ("spread"));
2079 if (dim && gfc_is_constant_expr (dim)
2080 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2083 idim = mpz_get_ui (dim->value.integer);
2084 f->shape = gfc_get_shape (f->rank);
2085 for (i = 0; i < (idim - 1); i++)
2086 mpz_init_set (f->shape[i], source->shape[i]);
2088 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2090 for (i = idim; i < f->rank ; i++)
2091 mpz_init_set (f->shape[i], source->shape[i-1]);
2095 gfc_resolve_dim_arg (dim);
2096 gfc_resolve_index (ncopies, 1);
2101 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2104 f->value.function.name
2105 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2109 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2112 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2113 gfc_expr *a ATTRIBUTE_UNUSED)
2115 f->ts.type = BT_INTEGER;
2116 f->ts.kind = gfc_default_integer_kind;
2117 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2122 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2123 gfc_expr *a ATTRIBUTE_UNUSED)
2125 f->ts.type = BT_INTEGER;
2126 f->ts.kind = gfc_default_integer_kind;
2127 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2132 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2134 f->ts.type = BT_INTEGER;
2135 f->ts.kind = gfc_default_integer_kind;
2136 if (n->ts.kind != f->ts.kind)
2137 gfc_convert_type (n, &f->ts, 2);
2139 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2144 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2148 f->ts.type = BT_INTEGER;
2149 f->ts.kind = gfc_c_int_kind;
2150 if (u->ts.kind != gfc_c_int_kind)
2152 ts.type = BT_INTEGER;
2153 ts.kind = gfc_c_int_kind;
2156 gfc_convert_type (u, &ts, 2);
2159 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2164 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2166 f->ts.type = BT_INTEGER;
2167 f->ts.kind = gfc_c_int_kind;
2168 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2173 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2177 f->ts.type = BT_INTEGER;
2178 f->ts.kind = gfc_c_int_kind;
2179 if (u->ts.kind != gfc_c_int_kind)
2181 ts.type = BT_INTEGER;
2182 ts.kind = gfc_c_int_kind;
2185 gfc_convert_type (u, &ts, 2);
2188 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2193 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2195 f->ts.type = BT_INTEGER;
2196 f->ts.kind = gfc_c_int_kind;
2197 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2202 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2206 f->ts.type = BT_INTEGER;
2207 f->ts.kind = gfc_index_integer_kind;
2208 if (u->ts.kind != gfc_c_int_kind)
2210 ts.type = BT_INTEGER;
2211 ts.kind = gfc_c_int_kind;
2214 gfc_convert_type (u, &ts, 2);
2217 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2222 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2230 if (mask->rank == 0)
2235 resolve_mask_arg (mask);
2242 f->rank = array->rank - 1;
2243 gfc_resolve_dim_arg (dim);
2246 f->value.function.name
2247 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2248 gfc_type_letter (array->ts.type), array->ts.kind);
2253 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2254 gfc_expr *p2 ATTRIBUTE_UNUSED)
2256 f->ts.type = BT_INTEGER;
2257 f->ts.kind = gfc_default_integer_kind;
2258 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2262 /* Resolve the g77 compatibility function SYSTEM. */
2265 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2267 f->ts.type = BT_INTEGER;
2269 f->value.function.name = gfc_get_string (PREFIX ("system"));
2274 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2277 f->value.function.name
2278 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2283 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2286 f->value.function.name
2287 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2292 gfc_resolve_time (gfc_expr *f)
2294 f->ts.type = BT_INTEGER;
2296 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2301 gfc_resolve_time8 (gfc_expr *f)
2303 f->ts.type = BT_INTEGER;
2305 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2310 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2311 gfc_expr *mold, gfc_expr *size)
2313 /* TODO: Make this do something meaningful. */
2314 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2316 if (mold->ts.type == BT_CHARACTER && !mold->ts.cl->length
2317 && !(mold->expr_type == EXPR_VARIABLE && mold->symtree->n.sym->attr.dummy))
2318 mold->ts.cl->length = gfc_int_expr (mold->value.character.length);
2322 if (size == NULL && mold->rank == 0)
2325 f->value.function.name = transfer0;
2330 f->value.function.name = transfer1;
2331 if (size && gfc_is_constant_expr (size))
2333 f->shape = gfc_get_shape (1);
2334 mpz_init_set (f->shape[0], size->value.integer);
2341 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2344 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2345 gfc_resolve_substring_charlen (matrix);
2351 f->shape = gfc_get_shape (2);
2352 mpz_init_set (f->shape[0], matrix->shape[1]);
2353 mpz_init_set (f->shape[1], matrix->shape[0]);
2356 switch (matrix->ts.kind)
2362 switch (matrix->ts.type)
2366 f->value.function.name
2367 = gfc_get_string (PREFIX ("transpose_%c%d"),
2368 gfc_type_letter (matrix->ts.type),
2374 /* Use the integer routines for real and logical cases. This
2375 assumes they all have the same alignment requirements. */
2376 f->value.function.name
2377 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2381 f->value.function.name = PREFIX ("transpose");
2387 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2388 ? PREFIX ("transpose_char")
2389 : PREFIX ("transpose"));
2396 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2398 f->ts.type = BT_CHARACTER;
2399 f->ts.kind = string->ts.kind;
2400 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2405 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2407 static char ubound[] = "__ubound";
2409 f->ts.type = BT_INTEGER;
2411 f->ts.kind = mpz_get_si (kind->value.integer);
2413 f->ts.kind = gfc_default_integer_kind;
2418 f->shape = gfc_get_shape (1);
2419 mpz_init_set_ui (f->shape[0], array->rank);
2422 f->value.function.name = ubound;
2426 /* Resolve the g77 compatibility function UMASK. */
2429 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2431 f->ts.type = BT_INTEGER;
2432 f->ts.kind = n->ts.kind;
2433 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2437 /* Resolve the g77 compatibility function UNLINK. */
2440 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2442 f->ts.type = BT_INTEGER;
2444 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2449 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2453 f->ts.type = BT_CHARACTER;
2454 f->ts.kind = gfc_default_character_kind;
2456 if (unit->ts.kind != gfc_c_int_kind)
2458 ts.type = BT_INTEGER;
2459 ts.kind = gfc_c_int_kind;
2462 gfc_convert_type (unit, &ts, 2);
2465 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2470 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2471 gfc_expr *field ATTRIBUTE_UNUSED)
2473 if (vector->ts.type == BT_CHARACTER && vector->ref)
2474 gfc_resolve_substring_charlen (vector);
2477 f->rank = mask->rank;
2478 resolve_mask_arg (mask);
2480 f->value.function.name
2481 = gfc_get_string (PREFIX ("unpack%d%s"), field->rank > 0 ? 1 : 0,
2482 vector->ts.type == BT_CHARACTER ? "_char" : "");
2487 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2488 gfc_expr *set ATTRIBUTE_UNUSED,
2489 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2491 f->ts.type = BT_INTEGER;
2493 f->ts.kind = mpz_get_si (kind->value.integer);
2495 f->ts.kind = gfc_default_integer_kind;
2496 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2501 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2503 f->ts.type = i->ts.type;
2504 f->ts.kind = gfc_kind_max (i, j);
2506 if (i->ts.kind != j->ts.kind)
2508 if (i->ts.kind == gfc_kind_max (i, j))
2509 gfc_convert_type (j, &i->ts, 2);
2511 gfc_convert_type (i, &j->ts, 2);
2514 f->value.function.name
2515 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2519 /* Intrinsic subroutine resolution. */
2522 gfc_resolve_alarm_sub (gfc_code *c)
2525 gfc_expr *seconds, *handler, *status;
2528 seconds = c->ext.actual->expr;
2529 handler = c->ext.actual->next->expr;
2530 status = c->ext.actual->next->next->expr;
2531 ts.type = BT_INTEGER;
2532 ts.kind = gfc_c_int_kind;
2534 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2535 In all cases, the status argument is of default integer kind
2536 (enforced in check.c) so that the function suffix is fixed. */
2537 if (handler->ts.type == BT_INTEGER)
2539 if (handler->ts.kind != gfc_c_int_kind)
2540 gfc_convert_type (handler, &ts, 2);
2541 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2542 gfc_default_integer_kind);
2545 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2546 gfc_default_integer_kind);
2548 if (seconds->ts.kind != gfc_c_int_kind)
2549 gfc_convert_type (seconds, &ts, 2);
2551 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2555 gfc_resolve_cpu_time (gfc_code *c)
2558 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2559 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2564 gfc_resolve_mvbits (gfc_code *c)
2569 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2570 they will be converted so that they fit into a C int. */
2571 ts.type = BT_INTEGER;
2572 ts.kind = gfc_c_int_kind;
2573 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2574 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2575 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2576 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2577 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2578 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2580 /* TO and FROM are guaranteed to have the same kind parameter. */
2581 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2582 c->ext.actual->expr->ts.kind);
2583 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2584 /* Mark as elemental subroutine as this does not happen automatically. */
2585 c->resolved_sym->attr.elemental = 1;
2590 gfc_resolve_random_number (gfc_code *c)
2595 kind = c->ext.actual->expr->ts.kind;
2596 if (c->ext.actual->expr->rank == 0)
2597 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2599 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2601 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2606 gfc_resolve_random_seed (gfc_code *c)
2610 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2611 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2616 gfc_resolve_rename_sub (gfc_code *c)
2621 if (c->ext.actual->next->next->expr != NULL)
2622 kind = c->ext.actual->next->next->expr->ts.kind;
2624 kind = gfc_default_integer_kind;
2626 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2627 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2632 gfc_resolve_kill_sub (gfc_code *c)
2637 if (c->ext.actual->next->next->expr != NULL)
2638 kind = c->ext.actual->next->next->expr->ts.kind;
2640 kind = gfc_default_integer_kind;
2642 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2643 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2648 gfc_resolve_link_sub (gfc_code *c)
2653 if (c->ext.actual->next->next->expr != NULL)
2654 kind = c->ext.actual->next->next->expr->ts.kind;
2656 kind = gfc_default_integer_kind;
2658 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2659 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2664 gfc_resolve_symlnk_sub (gfc_code *c)
2669 if (c->ext.actual->next->next->expr != NULL)
2670 kind = c->ext.actual->next->next->expr->ts.kind;
2672 kind = gfc_default_integer_kind;
2674 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2675 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2679 /* G77 compatibility subroutines etime() and dtime(). */
2682 gfc_resolve_etime_sub (gfc_code *c)
2685 name = gfc_get_string (PREFIX ("etime_sub"));
2686 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2690 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2693 gfc_resolve_itime (gfc_code *c)
2696 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2697 gfc_default_integer_kind));
2701 gfc_resolve_idate (gfc_code *c)
2704 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2705 gfc_default_integer_kind));
2709 gfc_resolve_ltime (gfc_code *c)
2712 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2713 gfc_default_integer_kind));
2717 gfc_resolve_gmtime (gfc_code *c)
2720 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2721 gfc_default_integer_kind));
2725 /* G77 compatibility subroutine second(). */
2728 gfc_resolve_second_sub (gfc_code *c)
2731 name = gfc_get_string (PREFIX ("second_sub"));
2732 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2737 gfc_resolve_sleep_sub (gfc_code *c)
2742 if (c->ext.actual->expr != NULL)
2743 kind = c->ext.actual->expr->ts.kind;
2745 kind = gfc_default_integer_kind;
2747 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2748 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2752 /* G77 compatibility function srand(). */
2755 gfc_resolve_srand (gfc_code *c)
2758 name = gfc_get_string (PREFIX ("srand"));
2759 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2763 /* Resolve the getarg intrinsic subroutine. */
2766 gfc_resolve_getarg (gfc_code *c)
2770 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
2774 ts.type = BT_INTEGER;
2775 ts.kind = gfc_default_integer_kind;
2777 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2780 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
2781 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2785 /* Resolve the getcwd intrinsic subroutine. */
2788 gfc_resolve_getcwd_sub (gfc_code *c)
2793 if (c->ext.actual->next->expr != NULL)
2794 kind = c->ext.actual->next->expr->ts.kind;
2796 kind = gfc_default_integer_kind;
2798 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2799 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2803 /* Resolve the get_command intrinsic subroutine. */
2806 gfc_resolve_get_command (gfc_code *c)
2810 kind = gfc_default_integer_kind;
2811 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2812 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2816 /* Resolve the get_command_argument intrinsic subroutine. */
2819 gfc_resolve_get_command_argument (gfc_code *c)
2823 kind = gfc_default_integer_kind;
2824 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2825 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2829 /* Resolve the get_environment_variable intrinsic subroutine. */
2832 gfc_resolve_get_environment_variable (gfc_code *code)
2836 kind = gfc_default_integer_kind;
2837 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2838 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2843 gfc_resolve_signal_sub (gfc_code *c)
2846 gfc_expr *number, *handler, *status;
2849 number = c->ext.actual->expr;
2850 handler = c->ext.actual->next->expr;
2851 status = c->ext.actual->next->next->expr;
2852 ts.type = BT_INTEGER;
2853 ts.kind = gfc_c_int_kind;
2855 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2856 if (handler->ts.type == BT_INTEGER)
2858 if (handler->ts.kind != gfc_c_int_kind)
2859 gfc_convert_type (handler, &ts, 2);
2860 name = gfc_get_string (PREFIX ("signal_sub_int"));
2863 name = gfc_get_string (PREFIX ("signal_sub"));
2865 if (number->ts.kind != gfc_c_int_kind)
2866 gfc_convert_type (number, &ts, 2);
2867 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2868 gfc_convert_type (status, &ts, 2);
2870 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2874 /* Resolve the SYSTEM intrinsic subroutine. */
2877 gfc_resolve_system_sub (gfc_code *c)
2880 name = gfc_get_string (PREFIX ("system_sub"));
2881 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2885 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2888 gfc_resolve_system_clock (gfc_code *c)
2893 if (c->ext.actual->expr != NULL)
2894 kind = c->ext.actual->expr->ts.kind;
2895 else if (c->ext.actual->next->expr != NULL)
2896 kind = c->ext.actual->next->expr->ts.kind;
2897 else if (c->ext.actual->next->next->expr != NULL)
2898 kind = c->ext.actual->next->next->expr->ts.kind;
2900 kind = gfc_default_integer_kind;
2902 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
2903 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2907 /* Resolve the EXIT intrinsic subroutine. */
2910 gfc_resolve_exit (gfc_code *c)
2916 /* The STATUS argument has to be of default kind. If it is not,
2918 ts.type = BT_INTEGER;
2919 ts.kind = gfc_default_integer_kind;
2920 n = c->ext.actual->expr;
2921 if (n != NULL && n->ts.kind != ts.kind)
2922 gfc_convert_type (n, &ts, 2);
2924 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
2925 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2929 /* Resolve the FLUSH intrinsic subroutine. */
2932 gfc_resolve_flush (gfc_code *c)
2938 ts.type = BT_INTEGER;
2939 ts.kind = gfc_default_integer_kind;
2940 n = c->ext.actual->expr;
2941 if (n != NULL && n->ts.kind != ts.kind)
2942 gfc_convert_type (n, &ts, 2);
2944 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
2945 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2950 gfc_resolve_free (gfc_code *c)
2955 ts.type = BT_INTEGER;
2956 ts.kind = gfc_index_integer_kind;
2957 n = c->ext.actual->expr;
2958 if (n->ts.kind != ts.kind)
2959 gfc_convert_type (n, &ts, 2);
2961 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
2966 gfc_resolve_ctime_sub (gfc_code *c)
2970 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
2971 if (c->ext.actual->expr->ts.kind != 8)
2973 ts.type = BT_INTEGER;
2977 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2980 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
2985 gfc_resolve_fdate_sub (gfc_code *c)
2987 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
2992 gfc_resolve_gerror (gfc_code *c)
2994 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
2999 gfc_resolve_getlog (gfc_code *c)
3001 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3006 gfc_resolve_hostnm_sub (gfc_code *c)
3011 if (c->ext.actual->next->expr != NULL)
3012 kind = c->ext.actual->next->expr->ts.kind;
3014 kind = gfc_default_integer_kind;
3016 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3017 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3022 gfc_resolve_perror (gfc_code *c)
3024 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3027 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3030 gfc_resolve_stat_sub (gfc_code *c)
3033 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3034 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3039 gfc_resolve_lstat_sub (gfc_code *c)
3042 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3043 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3048 gfc_resolve_fstat_sub (gfc_code *c)
3054 u = c->ext.actual->expr;
3055 ts = &c->ext.actual->next->expr->ts;
3056 if (u->ts.kind != ts->kind)
3057 gfc_convert_type (u, ts, 2);
3058 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3059 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3064 gfc_resolve_fgetc_sub (gfc_code *c)
3070 u = c->ext.actual->expr;
3071 st = c->ext.actual->next->next->expr;
3073 if (u->ts.kind != gfc_c_int_kind)
3075 ts.type = BT_INTEGER;
3076 ts.kind = gfc_c_int_kind;
3079 gfc_convert_type (u, &ts, 2);
3083 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3085 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3087 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3092 gfc_resolve_fget_sub (gfc_code *c)
3097 st = c->ext.actual->next->expr;
3099 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3101 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3103 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3108 gfc_resolve_fputc_sub (gfc_code *c)
3114 u = c->ext.actual->expr;
3115 st = c->ext.actual->next->next->expr;
3117 if (u->ts.kind != gfc_c_int_kind)
3119 ts.type = BT_INTEGER;
3120 ts.kind = gfc_c_int_kind;
3123 gfc_convert_type (u, &ts, 2);
3127 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3129 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3131 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3136 gfc_resolve_fput_sub (gfc_code *c)
3141 st = c->ext.actual->next->expr;
3143 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3145 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3147 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3152 gfc_resolve_fseek_sub (gfc_code *c)
3160 unit = c->ext.actual->expr;
3161 offset = c->ext.actual->next->expr;
3162 whence = c->ext.actual->next->next->expr;
3163 status = c->ext.actual->next->next->next->expr;
3165 if (unit->ts.kind != gfc_c_int_kind)
3167 ts.type = BT_INTEGER;
3168 ts.kind = gfc_c_int_kind;
3171 gfc_convert_type (unit, &ts, 2);
3174 if (offset->ts.kind != gfc_intio_kind)
3176 ts.type = BT_INTEGER;
3177 ts.kind = gfc_intio_kind;
3180 gfc_convert_type (offset, &ts, 2);
3183 if (whence->ts.kind != gfc_c_int_kind)
3185 ts.type = BT_INTEGER;
3186 ts.kind = gfc_c_int_kind;
3189 gfc_convert_type (whence, &ts, 2);
3192 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3196 gfc_resolve_ftell_sub (gfc_code *c)
3203 unit = c->ext.actual->expr;
3204 offset = c->ext.actual->next->expr;
3206 if (unit->ts.kind != gfc_c_int_kind)
3208 ts.type = BT_INTEGER;
3209 ts.kind = gfc_c_int_kind;
3212 gfc_convert_type (unit, &ts, 2);
3215 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3216 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3221 gfc_resolve_ttynam_sub (gfc_code *c)
3225 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3227 ts.type = BT_INTEGER;
3228 ts.kind = gfc_c_int_kind;
3231 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3234 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3238 /* Resolve the UMASK intrinsic subroutine. */
3241 gfc_resolve_umask_sub (gfc_code *c)
3246 if (c->ext.actual->next->expr != NULL)
3247 kind = c->ext.actual->next->expr->ts.kind;
3249 kind = gfc_default_integer_kind;
3251 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3252 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3255 /* Resolve the UNLINK intrinsic subroutine. */
3258 gfc_resolve_unlink_sub (gfc_code *c)
3263 if (c->ext.actual->next->expr != NULL)
3264 kind = c->ext.actual->next->expr->ts.kind;
3266 kind = gfc_default_integer_kind;
3268 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3269 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);