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->expr_type == EXPR_CONSTANT && 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;
70 source->ts.cl->length = gfc_int_expr (source->value.character.length);
75 /* Helper function for resolving the "mask" argument. */
78 resolve_mask_arg (gfc_expr *mask)
81 /* The mask can be any kind for an array.
82 For the scalar case, coerce it to kind=4 unconditionally
83 (because this is the only kind we have a library function
86 if (mask->rank == 0 && mask->ts.kind != 4)
92 gfc_convert_type (mask, &ts, 2);
96 /********************** Resolution functions **********************/
100 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
103 if (f->ts.type == BT_COMPLEX)
104 f->ts.type = BT_REAL;
106 f->value.function.name
107 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
112 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
113 gfc_expr *mode ATTRIBUTE_UNUSED)
115 f->ts.type = BT_INTEGER;
116 f->ts.kind = gfc_c_int_kind;
117 f->value.function.name = PREFIX ("access_func");
122 gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
124 f->ts.type = BT_CHARACTER;
125 f->ts.kind = (kind == NULL)
126 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
127 f->ts.cl = gfc_get_charlen ();
128 f->ts.cl->next = gfc_current_ns->cl_list;
129 gfc_current_ns->cl_list = f->ts.cl;
130 f->ts.cl->length = gfc_int_expr (1);
132 f->value.function.name = gfc_get_string ("__achar_%d_%c%d", f->ts.kind,
133 gfc_type_letter (x->ts.type),
139 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
142 f->value.function.name
143 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
148 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
151 f->value.function.name
152 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
158 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
160 f->ts.type = BT_REAL;
161 f->ts.kind = x->ts.kind;
162 f->value.function.name
163 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
169 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
171 f->ts.type = i->ts.type;
172 f->ts.kind = gfc_kind_max (i, j);
174 if (i->ts.kind != j->ts.kind)
176 if (i->ts.kind == gfc_kind_max (i, j))
177 gfc_convert_type (j, &i->ts, 2);
179 gfc_convert_type (i, &j->ts, 2);
182 f->value.function.name
183 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
188 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
192 f->ts.type = a->ts.type;
193 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
195 if (a->ts.kind != f->ts.kind)
197 ts.type = f->ts.type;
198 ts.kind = f->ts.kind;
199 gfc_convert_type (a, &ts, 2);
201 /* The resolved name is only used for specific intrinsics where
202 the return kind is the same as the arg kind. */
203 f->value.function.name
204 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
209 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
211 gfc_resolve_aint (f, a, NULL);
216 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
222 gfc_resolve_dim_arg (dim);
223 f->rank = mask->rank - 1;
224 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
227 f->value.function.name
228 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
234 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
238 f->ts.type = a->ts.type;
239 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
241 if (a->ts.kind != f->ts.kind)
243 ts.type = f->ts.type;
244 ts.kind = f->ts.kind;
245 gfc_convert_type (a, &ts, 2);
248 /* The resolved name is only used for specific intrinsics where
249 the return kind is the same as the arg kind. */
250 f->value.function.name
251 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
257 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
259 gfc_resolve_anint (f, a, NULL);
264 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
270 gfc_resolve_dim_arg (dim);
271 f->rank = mask->rank - 1;
272 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
275 f->value.function.name
276 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
282 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
285 f->value.function.name
286 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
290 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
293 f->value.function.name
294 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
299 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
302 f->value.function.name
303 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
307 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
310 f->value.function.name
311 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
316 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
319 f->value.function.name
320 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
325 /* Resolve the BESYN and BESJN intrinsics. */
328 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
333 if (n->ts.kind != gfc_c_int_kind)
335 ts.type = BT_INTEGER;
336 ts.kind = gfc_c_int_kind;
337 gfc_convert_type (n, &ts, 2);
339 f->value.function.name = gfc_get_string ("<intrinsic>");
344 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
346 f->ts.type = BT_LOGICAL;
347 f->ts.kind = gfc_default_logical_kind;
348 f->value.function.name
349 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
354 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
356 f->ts.type = BT_INTEGER;
357 f->ts.kind = (kind == NULL)
358 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
359 f->value.function.name
360 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
361 gfc_type_letter (a->ts.type), a->ts.kind);
366 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
368 f->ts.type = BT_CHARACTER;
369 f->ts.kind = (kind == NULL)
370 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
371 f->value.function.name
372 = gfc_get_string ("__char_%d_%c%d", f->ts.kind,
373 gfc_type_letter (a->ts.type), a->ts.kind);
378 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
380 f->ts.type = BT_INTEGER;
381 f->ts.kind = gfc_default_integer_kind;
382 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
387 gfc_resolve_chdir_sub (gfc_code *c)
392 if (c->ext.actual->next->expr != NULL)
393 kind = c->ext.actual->next->expr->ts.kind;
395 kind = gfc_default_integer_kind;
397 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
398 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
403 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
404 gfc_expr *mode ATTRIBUTE_UNUSED)
406 f->ts.type = BT_INTEGER;
407 f->ts.kind = gfc_c_int_kind;
408 f->value.function.name = PREFIX ("chmod_func");
413 gfc_resolve_chmod_sub (gfc_code *c)
418 if (c->ext.actual->next->next->expr != NULL)
419 kind = c->ext.actual->next->next->expr->ts.kind;
421 kind = gfc_default_integer_kind;
423 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
424 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
429 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
431 f->ts.type = BT_COMPLEX;
432 f->ts.kind = (kind == NULL)
433 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
436 f->value.function.name
437 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
438 gfc_type_letter (x->ts.type), x->ts.kind);
440 f->value.function.name
441 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
442 gfc_type_letter (x->ts.type), x->ts.kind,
443 gfc_type_letter (y->ts.type), y->ts.kind);
448 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
450 gfc_resolve_cmplx (f, x, y, gfc_int_expr (gfc_default_double_kind));
455 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
459 if (x->ts.type == BT_INTEGER)
461 if (y->ts.type == BT_INTEGER)
462 kind = gfc_default_real_kind;
468 if (y->ts.type == BT_REAL)
469 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
474 f->ts.type = BT_COMPLEX;
476 f->value.function.name
477 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
478 gfc_type_letter (x->ts.type), x->ts.kind,
479 gfc_type_letter (y->ts.type), y->ts.kind);
484 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
487 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
492 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
495 f->value.function.name
496 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
501 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
504 f->value.function.name
505 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
510 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
512 f->ts.type = BT_INTEGER;
514 f->ts.kind = mpz_get_si (kind->value.integer);
516 f->ts.kind = gfc_default_integer_kind;
520 f->rank = mask->rank - 1;
521 gfc_resolve_dim_arg (dim);
522 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
525 f->value.function.name
526 = gfc_get_string (PREFIX ("count_%d_%c%d"), f->ts.kind,
527 gfc_type_letter (mask->ts.type), mask->ts.kind);
532 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
537 if (array->ts.type == BT_CHARACTER && array->ref)
538 gfc_resolve_substring_charlen (array);
541 f->rank = array->rank;
542 f->shape = gfc_copy_shape (array->shape, array->rank);
549 /* Convert shift to at least gfc_default_integer_kind, so we don't need
550 kind=1 and kind=2 versions of the library functions. */
551 if (shift->ts.kind < gfc_default_integer_kind)
554 ts.type = BT_INTEGER;
555 ts.kind = gfc_default_integer_kind;
556 gfc_convert_type_warn (shift, &ts, 2, 0);
561 gfc_resolve_dim_arg (dim);
562 /* Convert dim to shift's kind, so we don't need so many variations. */
563 if (dim->ts.kind != shift->ts.kind)
564 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
566 f->value.function.name
567 = gfc_get_string (PREFIX ("cshift%d_%d%s"), n, shift->ts.kind,
568 array->ts.type == BT_CHARACTER ? "_char" : "");
573 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
577 f->ts.type = BT_CHARACTER;
578 f->ts.kind = gfc_default_character_kind;
580 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
581 if (time->ts.kind != 8)
583 ts.type = BT_INTEGER;
587 gfc_convert_type (time, &ts, 2);
590 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
595 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
597 f->ts.type = BT_REAL;
598 f->ts.kind = gfc_default_double_kind;
599 f->value.function.name
600 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
605 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
607 f->ts.type = a->ts.type;
609 f->ts.kind = gfc_kind_max (a,p);
611 f->ts.kind = a->ts.kind;
613 if (p != NULL && a->ts.kind != p->ts.kind)
615 if (a->ts.kind == gfc_kind_max (a,p))
616 gfc_convert_type (p, &a->ts, 2);
618 gfc_convert_type (a, &p->ts, 2);
621 f->value.function.name
622 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
627 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
631 temp.expr_type = EXPR_OP;
632 gfc_clear_ts (&temp.ts);
633 temp.value.op.operator = INTRINSIC_NONE;
634 temp.value.op.op1 = a;
635 temp.value.op.op2 = b;
636 gfc_type_convert_binary (&temp);
638 f->value.function.name
639 = gfc_get_string (PREFIX ("dot_product_%c%d"),
640 gfc_type_letter (f->ts.type), f->ts.kind);
645 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
646 gfc_expr *b ATTRIBUTE_UNUSED)
648 f->ts.kind = gfc_default_double_kind;
649 f->ts.type = BT_REAL;
650 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
655 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
656 gfc_expr *boundary, gfc_expr *dim)
660 if (array->ts.type == BT_CHARACTER && array->ref)
661 gfc_resolve_substring_charlen (array);
664 f->rank = array->rank;
665 f->shape = gfc_copy_shape (array->shape, array->rank);
670 if (boundary && boundary->rank > 0)
673 /* Convert shift to at least gfc_default_integer_kind, so we don't need
674 kind=1 and kind=2 versions of the library functions. */
675 if (shift->ts.kind < gfc_default_integer_kind)
678 ts.type = BT_INTEGER;
679 ts.kind = gfc_default_integer_kind;
680 gfc_convert_type_warn (shift, &ts, 2, 0);
685 gfc_resolve_dim_arg (dim);
686 /* Convert dim to shift's kind, so we don't need so many variations. */
687 if (dim->ts.kind != shift->ts.kind)
688 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
691 f->value.function.name
692 = gfc_get_string (PREFIX ("eoshift%d_%d%s"), n, shift->ts.kind,
693 array->ts.type == BT_CHARACTER ? "_char" : "");
698 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
701 f->value.function.name
702 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
707 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
709 f->ts.type = BT_INTEGER;
710 f->ts.kind = gfc_default_integer_kind;
711 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
716 gfc_resolve_fdate (gfc_expr *f)
718 f->ts.type = BT_CHARACTER;
719 f->ts.kind = gfc_default_character_kind;
720 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
725 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
727 f->ts.type = BT_INTEGER;
728 f->ts.kind = (kind == NULL)
729 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
730 f->value.function.name
731 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
732 gfc_type_letter (a->ts.type), a->ts.kind);
737 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
739 f->ts.type = BT_INTEGER;
740 f->ts.kind = gfc_default_integer_kind;
741 if (n->ts.kind != f->ts.kind)
742 gfc_convert_type (n, &f->ts, 2);
743 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
748 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
751 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
755 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
758 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
761 f->value.function.name = gfc_get_string ("<intrinsic>");
766 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
769 f->value.function.name
770 = gfc_get_string ("__gamma_%d", x->ts.kind);
775 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
777 f->ts.type = BT_INTEGER;
779 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
784 gfc_resolve_getgid (gfc_expr *f)
786 f->ts.type = BT_INTEGER;
788 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
793 gfc_resolve_getpid (gfc_expr *f)
795 f->ts.type = BT_INTEGER;
797 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
802 gfc_resolve_getuid (gfc_expr *f)
804 f->ts.type = BT_INTEGER;
806 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
811 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
813 f->ts.type = BT_INTEGER;
815 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
820 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
822 /* If the kind of i and j are different, then g77 cross-promoted the
823 kinds to the largest value. The Fortran 95 standard requires the
825 if (i->ts.kind != j->ts.kind)
827 if (i->ts.kind == gfc_kind_max (i, j))
828 gfc_convert_type (j, &i->ts, 2);
830 gfc_convert_type (i, &j->ts, 2);
834 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
839 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
842 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
847 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
848 gfc_expr *len ATTRIBUTE_UNUSED)
851 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
856 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
859 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
864 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
866 f->ts.type = BT_INTEGER;
868 f->ts.kind = mpz_get_si (kind->value.integer);
870 f->ts.kind = gfc_default_integer_kind;
871 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
876 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
878 f->ts.type = BT_INTEGER;
880 f->ts.kind = mpz_get_si (kind->value.integer);
882 f->ts.kind = gfc_default_integer_kind;
883 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
888 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
890 gfc_resolve_nint (f, a, NULL);
895 gfc_resolve_ierrno (gfc_expr *f)
897 f->ts.type = BT_INTEGER;
898 f->ts.kind = gfc_default_integer_kind;
899 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
904 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
906 /* If the kind of i and j are different, then g77 cross-promoted the
907 kinds to the largest value. The Fortran 95 standard requires the
909 if (i->ts.kind != j->ts.kind)
911 if (i->ts.kind == gfc_kind_max (i, j))
912 gfc_convert_type (j, &i->ts, 2);
914 gfc_convert_type (i, &j->ts, 2);
918 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
923 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
925 /* If the kind of i and j are different, then g77 cross-promoted the
926 kinds to the largest value. The Fortran 95 standard requires the
928 if (i->ts.kind != j->ts.kind)
930 if (i->ts.kind == gfc_kind_max (i, j))
931 gfc_convert_type (j, &i->ts, 2);
933 gfc_convert_type (i, &j->ts, 2);
937 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
942 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
943 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
948 f->ts.type = BT_INTEGER;
950 f->ts.kind = mpz_get_si (kind->value.integer);
952 f->ts.kind = gfc_default_integer_kind;
954 if (back && back->ts.kind != gfc_default_integer_kind)
956 ts.type = BT_LOGICAL;
957 ts.kind = gfc_default_integer_kind;
960 gfc_convert_type (back, &ts, 2);
963 f->value.function.name
964 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
969 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
971 f->ts.type = BT_INTEGER;
972 f->ts.kind = (kind == NULL)
973 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
974 f->value.function.name
975 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
976 gfc_type_letter (a->ts.type), a->ts.kind);
981 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
983 f->ts.type = BT_INTEGER;
985 f->value.function.name
986 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
987 gfc_type_letter (a->ts.type), a->ts.kind);
992 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
994 f->ts.type = BT_INTEGER;
996 f->value.function.name
997 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
998 gfc_type_letter (a->ts.type), a->ts.kind);
1003 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1005 f->ts.type = BT_INTEGER;
1007 f->value.function.name
1008 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1009 gfc_type_letter (a->ts.type), a->ts.kind);
1014 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1018 f->ts.type = BT_LOGICAL;
1019 f->ts.kind = gfc_default_integer_kind;
1020 if (u->ts.kind != gfc_c_int_kind)
1022 ts.type = BT_INTEGER;
1023 ts.kind = gfc_c_int_kind;
1026 gfc_convert_type (u, &ts, 2);
1029 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1034 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1037 f->value.function.name
1038 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1043 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1046 f->value.function.name
1047 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1052 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1055 f->value.function.name
1056 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1061 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1065 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1068 f->value.function.name
1069 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1074 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1075 gfc_expr *s ATTRIBUTE_UNUSED)
1077 f->ts.type = BT_INTEGER;
1078 f->ts.kind = gfc_default_integer_kind;
1079 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1084 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1086 static char lbound[] = "__lbound";
1088 f->ts.type = BT_INTEGER;
1090 f->ts.kind = mpz_get_si (kind->value.integer);
1092 f->ts.kind = gfc_default_integer_kind;
1097 f->shape = gfc_get_shape (1);
1098 mpz_init_set_ui (f->shape[0], array->rank);
1101 f->value.function.name = lbound;
1106 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1108 f->ts.type = BT_INTEGER;
1110 f->ts.kind = mpz_get_si (kind->value.integer);
1112 f->ts.kind = gfc_default_integer_kind;
1113 f->value.function.name
1114 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1115 gfc_default_integer_kind);
1120 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1122 f->ts.type = BT_INTEGER;
1124 f->ts.kind = mpz_get_si (kind->value.integer);
1126 f->ts.kind = gfc_default_integer_kind;
1127 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1132 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1135 f->value.function.name
1136 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1141 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1142 gfc_expr *p2 ATTRIBUTE_UNUSED)
1144 f->ts.type = BT_INTEGER;
1145 f->ts.kind = gfc_default_integer_kind;
1146 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1151 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1153 f->ts.type= BT_INTEGER;
1154 f->ts.kind = gfc_index_integer_kind;
1155 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1160 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1163 f->value.function.name
1164 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1169 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1172 f->value.function.name
1173 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1179 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1181 f->ts.type = BT_LOGICAL;
1182 f->ts.kind = (kind == NULL)
1183 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1186 f->value.function.name
1187 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1188 gfc_type_letter (a->ts.type), a->ts.kind);
1193 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1195 if (size->ts.kind < gfc_index_integer_kind)
1199 ts.type = BT_INTEGER;
1200 ts.kind = gfc_index_integer_kind;
1201 gfc_convert_type_warn (size, &ts, 2, 0);
1204 f->ts.type = BT_INTEGER;
1205 f->ts.kind = gfc_index_integer_kind;
1206 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1211 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1215 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1217 f->ts.type = BT_LOGICAL;
1218 f->ts.kind = gfc_default_logical_kind;
1222 temp.expr_type = EXPR_OP;
1223 gfc_clear_ts (&temp.ts);
1224 temp.value.op.operator = INTRINSIC_NONE;
1225 temp.value.op.op1 = a;
1226 temp.value.op.op2 = b;
1227 gfc_type_convert_binary (&temp);
1231 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1233 f->value.function.name
1234 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1240 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1242 gfc_actual_arglist *a;
1244 f->ts.type = args->expr->ts.type;
1245 f->ts.kind = args->expr->ts.kind;
1246 /* Find the largest type kind. */
1247 for (a = args->next; a; a = a->next)
1249 if (a->expr->ts.kind > f->ts.kind)
1250 f->ts.kind = a->expr->ts.kind;
1253 /* Convert all parameters to the required kind. */
1254 for (a = args; a; a = a->next)
1256 if (a->expr->ts.kind != f->ts.kind)
1257 gfc_convert_type (a->expr, &f->ts, 2);
1260 f->value.function.name
1261 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1266 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1268 gfc_resolve_minmax ("__max_%c%d", f, args);
1273 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1279 f->ts.type = BT_INTEGER;
1280 f->ts.kind = gfc_default_integer_kind;
1285 f->shape = gfc_get_shape (1);
1286 mpz_init_set_si (f->shape[0], array->rank);
1290 f->rank = array->rank - 1;
1291 gfc_resolve_dim_arg (dim);
1292 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1294 idim = (int) mpz_get_si (dim->value.integer);
1295 f->shape = gfc_get_shape (f->rank);
1296 for (i = 0, j = 0; i < f->rank; i++, j++)
1298 if (i == (idim - 1))
1300 mpz_init_set (f->shape[i], array->shape[j]);
1307 if (mask->rank == 0)
1312 resolve_mask_arg (mask);
1317 f->value.function.name
1318 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1319 gfc_type_letter (array->ts.type), array->ts.kind);
1324 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1334 f->rank = array->rank - 1;
1335 gfc_resolve_dim_arg (dim);
1337 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1339 idim = (int) mpz_get_si (dim->value.integer);
1340 f->shape = gfc_get_shape (f->rank);
1341 for (i = 0, j = 0; i < f->rank; i++, j++)
1343 if (i == (idim - 1))
1345 mpz_init_set (f->shape[i], array->shape[j]);
1352 if (mask->rank == 0)
1357 resolve_mask_arg (mask);
1362 f->value.function.name
1363 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1364 gfc_type_letter (array->ts.type), array->ts.kind);
1369 gfc_resolve_mclock (gfc_expr *f)
1371 f->ts.type = BT_INTEGER;
1373 f->value.function.name = PREFIX ("mclock");
1378 gfc_resolve_mclock8 (gfc_expr *f)
1380 f->ts.type = BT_INTEGER;
1382 f->value.function.name = PREFIX ("mclock8");
1387 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1388 gfc_expr *fsource ATTRIBUTE_UNUSED,
1389 gfc_expr *mask ATTRIBUTE_UNUSED)
1391 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1392 gfc_resolve_substring_charlen (tsource);
1394 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1395 gfc_resolve_substring_charlen (fsource);
1397 if (tsource->ts.type == BT_CHARACTER)
1398 check_charlen_present (tsource);
1400 f->ts = tsource->ts;
1401 f->value.function.name
1402 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1408 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1410 gfc_resolve_minmax ("__min_%c%d", f, args);
1415 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1421 f->ts.type = BT_INTEGER;
1422 f->ts.kind = gfc_default_integer_kind;
1427 f->shape = gfc_get_shape (1);
1428 mpz_init_set_si (f->shape[0], array->rank);
1432 f->rank = array->rank - 1;
1433 gfc_resolve_dim_arg (dim);
1434 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1436 idim = (int) mpz_get_si (dim->value.integer);
1437 f->shape = gfc_get_shape (f->rank);
1438 for (i = 0, j = 0; i < f->rank; i++, j++)
1440 if (i == (idim - 1))
1442 mpz_init_set (f->shape[i], array->shape[j]);
1449 if (mask->rank == 0)
1454 resolve_mask_arg (mask);
1459 f->value.function.name
1460 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1461 gfc_type_letter (array->ts.type), array->ts.kind);
1466 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1476 f->rank = array->rank - 1;
1477 gfc_resolve_dim_arg (dim);
1479 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1481 idim = (int) mpz_get_si (dim->value.integer);
1482 f->shape = gfc_get_shape (f->rank);
1483 for (i = 0, j = 0; i < f->rank; i++, j++)
1485 if (i == (idim - 1))
1487 mpz_init_set (f->shape[i], array->shape[j]);
1494 if (mask->rank == 0)
1499 resolve_mask_arg (mask);
1504 f->value.function.name
1505 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1506 gfc_type_letter (array->ts.type), array->ts.kind);
1511 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1513 f->ts.type = a->ts.type;
1515 f->ts.kind = gfc_kind_max (a,p);
1517 f->ts.kind = a->ts.kind;
1519 if (p != NULL && a->ts.kind != p->ts.kind)
1521 if (a->ts.kind == gfc_kind_max (a,p))
1522 gfc_convert_type (p, &a->ts, 2);
1524 gfc_convert_type (a, &p->ts, 2);
1527 f->value.function.name
1528 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1533 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1535 f->ts.type = a->ts.type;
1537 f->ts.kind = gfc_kind_max (a,p);
1539 f->ts.kind = a->ts.kind;
1541 if (p != NULL && a->ts.kind != p->ts.kind)
1543 if (a->ts.kind == gfc_kind_max (a,p))
1544 gfc_convert_type (p, &a->ts, 2);
1546 gfc_convert_type (a, &p->ts, 2);
1549 f->value.function.name
1550 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1555 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p ATTRIBUTE_UNUSED)
1558 f->value.function.name
1559 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1564 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1566 f->ts.type = BT_INTEGER;
1567 f->ts.kind = (kind == NULL)
1568 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1569 f->value.function.name
1570 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1575 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1578 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1583 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1585 f->ts.type = i->ts.type;
1586 f->ts.kind = gfc_kind_max (i, j);
1588 if (i->ts.kind != j->ts.kind)
1590 if (i->ts.kind == gfc_kind_max (i, j))
1591 gfc_convert_type (j, &i->ts, 2);
1593 gfc_convert_type (i, &j->ts, 2);
1596 f->value.function.name
1597 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1602 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1603 gfc_expr *vector ATTRIBUTE_UNUSED)
1605 if (array->ts.type == BT_CHARACTER && array->ref)
1606 gfc_resolve_substring_charlen (array);
1611 resolve_mask_arg (mask);
1613 if (mask->rank != 0)
1614 f->value.function.name = (array->ts.type == BT_CHARACTER
1615 ? PREFIX ("pack_char") : PREFIX ("pack"));
1617 f->value.function.name = (array->ts.type == BT_CHARACTER
1618 ? PREFIX ("pack_s_char") : PREFIX ("pack_s"));
1623 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1632 f->rank = array->rank - 1;
1633 gfc_resolve_dim_arg (dim);
1638 if (mask->rank == 0)
1643 resolve_mask_arg (mask);
1648 f->value.function.name
1649 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1650 gfc_type_letter (array->ts.type), array->ts.kind);
1655 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1657 f->ts.type = BT_REAL;
1660 f->ts.kind = mpz_get_si (kind->value.integer);
1662 f->ts.kind = (a->ts.type == BT_COMPLEX)
1663 ? a->ts.kind : gfc_default_real_kind;
1665 f->value.function.name
1666 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1667 gfc_type_letter (a->ts.type), a->ts.kind);
1672 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1674 f->ts.type = BT_REAL;
1675 f->ts.kind = a->ts.kind;
1676 f->value.function.name
1677 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1678 gfc_type_letter (a->ts.type), a->ts.kind);
1683 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1684 gfc_expr *p2 ATTRIBUTE_UNUSED)
1686 f->ts.type = BT_INTEGER;
1687 f->ts.kind = gfc_default_integer_kind;
1688 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1693 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
1694 gfc_expr *ncopies ATTRIBUTE_UNUSED)
1696 f->ts.type = BT_CHARACTER;
1697 f->ts.kind = string->ts.kind;
1698 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
1703 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
1704 gfc_expr *pad ATTRIBUTE_UNUSED,
1705 gfc_expr *order ATTRIBUTE_UNUSED)
1711 if (source->ts.type == BT_CHARACTER && source->ref)
1712 gfc_resolve_substring_charlen (source);
1716 gfc_array_size (shape, &rank);
1717 f->rank = mpz_get_si (rank);
1719 switch (source->ts.type)
1725 kind = source->ts.kind;
1739 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
1740 f->value.function.name
1741 = gfc_get_string (PREFIX ("reshape_%c%d"),
1742 gfc_type_letter (source->ts.type),
1745 f->value.function.name
1746 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
1751 f->value.function.name = (source->ts.type == BT_CHARACTER
1752 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1756 /* TODO: Make this work with a constant ORDER parameter. */
1757 if (shape->expr_type == EXPR_ARRAY
1758 && gfc_is_constant_expr (shape)
1762 f->shape = gfc_get_shape (f->rank);
1763 c = shape->value.constructor;
1764 for (i = 0; i < f->rank; i++)
1766 mpz_init_set (f->shape[i], c->expr->value.integer);
1771 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
1772 so many runtime variations. */
1773 if (shape->ts.kind != gfc_index_integer_kind)
1775 gfc_typespec ts = shape->ts;
1776 ts.kind = gfc_index_integer_kind;
1777 gfc_convert_type_warn (shape, &ts, 2, 0);
1779 if (order && order->ts.kind != gfc_index_integer_kind)
1780 gfc_convert_type_warn (order, &shape->ts, 2, 0);
1785 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
1788 gfc_actual_arglist *prec;
1791 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
1793 /* Create a hidden argument to the library routines for rrspacing. This
1794 hidden argument is the precision of x. */
1795 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1796 prec = gfc_get_actual_arglist ();
1798 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1799 /* The library routine expects INTEGER(4). */
1800 if (prec->expr->ts.kind != gfc_c_int_kind)
1803 ts.type = BT_INTEGER;
1804 ts.kind = gfc_c_int_kind;
1805 gfc_convert_type (prec->expr, &ts, 2);
1807 f->value.function.actual->next = prec;
1812 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1816 /* The implementation calls scalbn which takes an int as the
1818 if (i->ts.kind != gfc_c_int_kind)
1821 ts.type = BT_INTEGER;
1822 ts.kind = gfc_c_int_kind;
1823 gfc_convert_type_warn (i, &ts, 2, 0);
1826 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
1831 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
1832 gfc_expr *set ATTRIBUTE_UNUSED,
1833 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
1835 f->ts.type = BT_INTEGER;
1837 f->ts.kind = mpz_get_si (kind->value.integer);
1839 f->ts.kind = gfc_default_integer_kind;
1840 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
1845 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
1848 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
1853 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1857 /* The library implementation uses GFC_INTEGER_4 unconditionally,
1858 convert type so we don't have to implement all possible
1860 if (i->ts.kind != gfc_c_int_kind)
1863 ts.type = BT_INTEGER;
1864 ts.kind = gfc_c_int_kind;
1865 gfc_convert_type_warn (i, &ts, 2, 0);
1868 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
1873 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
1875 f->ts.type = BT_INTEGER;
1876 f->ts.kind = gfc_default_integer_kind;
1878 f->shape = gfc_get_shape (1);
1879 mpz_init_set_ui (f->shape[0], array->rank);
1880 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
1885 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
1888 f->value.function.name
1889 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
1894 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
1896 f->ts.type = BT_INTEGER;
1897 f->ts.kind = gfc_c_int_kind;
1899 /* handler can be either BT_INTEGER or BT_PROCEDURE */
1900 if (handler->ts.type == BT_INTEGER)
1902 if (handler->ts.kind != gfc_c_int_kind)
1903 gfc_convert_type (handler, &f->ts, 2);
1904 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
1907 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
1909 if (number->ts.kind != gfc_c_int_kind)
1910 gfc_convert_type (number, &f->ts, 2);
1915 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
1918 f->value.function.name
1919 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1924 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
1927 f->value.function.name
1928 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1933 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
1934 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
1936 f->ts.type = BT_INTEGER;
1938 f->ts.kind = mpz_get_si (kind->value.integer);
1940 f->ts.kind = gfc_default_integer_kind;
1945 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
1948 gfc_actual_arglist *prec, *tiny, *emin_1;
1951 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
1953 /* Create hidden arguments to the library routine for spacing. These
1954 hidden arguments are tiny(x), min_exponent - 1, and the precision
1957 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1959 tiny = gfc_get_actual_arglist ();
1960 tiny->name = "tiny";
1961 tiny->expr = gfc_get_expr ();
1962 tiny->expr->expr_type = EXPR_CONSTANT;
1963 tiny->expr->where = gfc_current_locus;
1964 tiny->expr->ts.type = x->ts.type;
1965 tiny->expr->ts.kind = x->ts.kind;
1966 mpfr_init (tiny->expr->value.real);
1967 mpfr_set (tiny->expr->value.real, gfc_real_kinds[k].tiny, GFC_RND_MODE);
1969 emin_1 = gfc_get_actual_arglist ();
1970 emin_1->name = "emin";
1971 emin_1->expr = gfc_int_expr (gfc_real_kinds[k].min_exponent - 1);
1973 /* The library routine expects INTEGER(4). */
1974 if (emin_1->expr->ts.kind != gfc_c_int_kind)
1977 ts.type = BT_INTEGER;
1978 ts.kind = gfc_c_int_kind;
1979 gfc_convert_type (emin_1->expr, &ts, 2);
1981 emin_1->next = tiny;
1983 prec = gfc_get_actual_arglist ();
1984 prec->name = "prec";
1985 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1987 /* The library routine expects INTEGER(4). */
1988 if (prec->expr->ts.kind != gfc_c_int_kind)
1991 ts.type = BT_INTEGER;
1992 ts.kind = gfc_c_int_kind;
1993 gfc_convert_type (prec->expr, &ts, 2);
1995 prec->next = emin_1;
1997 f->value.function.actual->next = prec;
2002 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2005 if (source->ts.type == BT_CHARACTER && source->ref)
2006 gfc_resolve_substring_charlen (source);
2008 if (source->ts.type == BT_CHARACTER)
2009 check_charlen_present (source);
2012 f->rank = source->rank + 1;
2013 if (source->rank == 0)
2014 f->value.function.name = (source->ts.type == BT_CHARACTER
2015 ? PREFIX ("spread_char_scalar")
2016 : PREFIX ("spread_scalar"));
2018 f->value.function.name = (source->ts.type == BT_CHARACTER
2019 ? PREFIX ("spread_char")
2020 : PREFIX ("spread"));
2022 if (dim && gfc_is_constant_expr (dim)
2023 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2026 idim = mpz_get_ui (dim->value.integer);
2027 f->shape = gfc_get_shape (f->rank);
2028 for (i = 0; i < (idim - 1); i++)
2029 mpz_init_set (f->shape[i], source->shape[i]);
2031 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2033 for (i = idim; i < f->rank ; i++)
2034 mpz_init_set (f->shape[i], source->shape[i-1]);
2038 gfc_resolve_dim_arg (dim);
2039 gfc_resolve_index (ncopies, 1);
2044 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2047 f->value.function.name
2048 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2052 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2055 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2056 gfc_expr *a ATTRIBUTE_UNUSED)
2058 f->ts.type = BT_INTEGER;
2059 f->ts.kind = gfc_default_integer_kind;
2060 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2065 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2066 gfc_expr *a ATTRIBUTE_UNUSED)
2068 f->ts.type = BT_INTEGER;
2069 f->ts.kind = gfc_default_integer_kind;
2070 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2075 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2077 f->ts.type = BT_INTEGER;
2078 f->ts.kind = gfc_default_integer_kind;
2079 if (n->ts.kind != f->ts.kind)
2080 gfc_convert_type (n, &f->ts, 2);
2082 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2087 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2091 f->ts.type = BT_INTEGER;
2092 f->ts.kind = gfc_c_int_kind;
2093 if (u->ts.kind != gfc_c_int_kind)
2095 ts.type = BT_INTEGER;
2096 ts.kind = gfc_c_int_kind;
2099 gfc_convert_type (u, &ts, 2);
2102 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2107 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2109 f->ts.type = BT_INTEGER;
2110 f->ts.kind = gfc_c_int_kind;
2111 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2116 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2120 f->ts.type = BT_INTEGER;
2121 f->ts.kind = gfc_c_int_kind;
2122 if (u->ts.kind != gfc_c_int_kind)
2124 ts.type = BT_INTEGER;
2125 ts.kind = gfc_c_int_kind;
2128 gfc_convert_type (u, &ts, 2);
2131 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2136 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2138 f->ts.type = BT_INTEGER;
2139 f->ts.kind = gfc_c_int_kind;
2140 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2145 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2149 f->ts.type = BT_INTEGER;
2150 f->ts.kind = gfc_index_integer_kind;
2151 if (u->ts.kind != gfc_c_int_kind)
2153 ts.type = BT_INTEGER;
2154 ts.kind = gfc_c_int_kind;
2157 gfc_convert_type (u, &ts, 2);
2160 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2165 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2173 if (mask->rank == 0)
2178 resolve_mask_arg (mask);
2185 f->rank = array->rank - 1;
2186 gfc_resolve_dim_arg (dim);
2189 f->value.function.name
2190 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2191 gfc_type_letter (array->ts.type), array->ts.kind);
2196 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2197 gfc_expr *p2 ATTRIBUTE_UNUSED)
2199 f->ts.type = BT_INTEGER;
2200 f->ts.kind = gfc_default_integer_kind;
2201 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2205 /* Resolve the g77 compatibility function SYSTEM. */
2208 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2210 f->ts.type = BT_INTEGER;
2212 f->value.function.name = gfc_get_string (PREFIX ("system"));
2217 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2220 f->value.function.name
2221 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2226 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2229 f->value.function.name
2230 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2235 gfc_resolve_time (gfc_expr *f)
2237 f->ts.type = BT_INTEGER;
2239 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2244 gfc_resolve_time8 (gfc_expr *f)
2246 f->ts.type = BT_INTEGER;
2248 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2253 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2254 gfc_expr *mold, gfc_expr *size)
2256 /* TODO: Make this do something meaningful. */
2257 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2261 if (size == NULL && mold->rank == 0)
2264 f->value.function.name = transfer0;
2269 f->value.function.name = transfer1;
2270 if (size && gfc_is_constant_expr (size))
2272 f->shape = gfc_get_shape (1);
2273 mpz_init_set (f->shape[0], size->value.integer);
2280 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2283 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2284 gfc_resolve_substring_charlen (matrix);
2290 f->shape = gfc_get_shape (2);
2291 mpz_init_set (f->shape[0], matrix->shape[1]);
2292 mpz_init_set (f->shape[1], matrix->shape[0]);
2295 switch (matrix->ts.kind)
2301 switch (matrix->ts.type)
2305 f->value.function.name
2306 = gfc_get_string (PREFIX ("transpose_%c%d"),
2307 gfc_type_letter (matrix->ts.type),
2313 /* Use the integer routines for real and logical cases. This
2314 assumes they all have the same alignment requirements. */
2315 f->value.function.name
2316 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2320 f->value.function.name = PREFIX ("transpose");
2326 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2327 ? PREFIX ("transpose_char")
2328 : PREFIX ("transpose"));
2335 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2337 f->ts.type = BT_CHARACTER;
2338 f->ts.kind = string->ts.kind;
2339 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2344 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2346 static char ubound[] = "__ubound";
2348 f->ts.type = BT_INTEGER;
2350 f->ts.kind = mpz_get_si (kind->value.integer);
2352 f->ts.kind = gfc_default_integer_kind;
2357 f->shape = gfc_get_shape (1);
2358 mpz_init_set_ui (f->shape[0], array->rank);
2361 f->value.function.name = ubound;
2365 /* Resolve the g77 compatibility function UMASK. */
2368 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2370 f->ts.type = BT_INTEGER;
2371 f->ts.kind = n->ts.kind;
2372 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2376 /* Resolve the g77 compatibility function UNLINK. */
2379 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2381 f->ts.type = BT_INTEGER;
2383 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2388 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2392 f->ts.type = BT_CHARACTER;
2393 f->ts.kind = gfc_default_character_kind;
2395 if (unit->ts.kind != gfc_c_int_kind)
2397 ts.type = BT_INTEGER;
2398 ts.kind = gfc_c_int_kind;
2401 gfc_convert_type (unit, &ts, 2);
2404 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2409 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2410 gfc_expr *field ATTRIBUTE_UNUSED)
2412 if (vector->ts.type == BT_CHARACTER && vector->ref)
2413 gfc_resolve_substring_charlen (vector);
2416 f->rank = mask->rank;
2417 resolve_mask_arg (mask);
2419 f->value.function.name
2420 = gfc_get_string (PREFIX ("unpack%d%s"), field->rank > 0 ? 1 : 0,
2421 vector->ts.type == BT_CHARACTER ? "_char" : "");
2426 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2427 gfc_expr *set ATTRIBUTE_UNUSED,
2428 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2430 f->ts.type = BT_INTEGER;
2432 f->ts.kind = mpz_get_si (kind->value.integer);
2434 f->ts.kind = gfc_default_integer_kind;
2435 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2440 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2442 f->ts.type = i->ts.type;
2443 f->ts.kind = gfc_kind_max (i, j);
2445 if (i->ts.kind != j->ts.kind)
2447 if (i->ts.kind == gfc_kind_max (i, j))
2448 gfc_convert_type (j, &i->ts, 2);
2450 gfc_convert_type (i, &j->ts, 2);
2453 f->value.function.name
2454 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2458 /* Intrinsic subroutine resolution. */
2461 gfc_resolve_alarm_sub (gfc_code *c)
2464 gfc_expr *seconds, *handler, *status;
2467 seconds = c->ext.actual->expr;
2468 handler = c->ext.actual->next->expr;
2469 status = c->ext.actual->next->next->expr;
2470 ts.type = BT_INTEGER;
2471 ts.kind = gfc_c_int_kind;
2473 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2474 In all cases, the status argument is of default integer kind
2475 (enforced in check.c) so that the function suffix is fixed. */
2476 if (handler->ts.type == BT_INTEGER)
2478 if (handler->ts.kind != gfc_c_int_kind)
2479 gfc_convert_type (handler, &ts, 2);
2480 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2481 gfc_default_integer_kind);
2484 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2485 gfc_default_integer_kind);
2487 if (seconds->ts.kind != gfc_c_int_kind)
2488 gfc_convert_type (seconds, &ts, 2);
2490 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2494 gfc_resolve_cpu_time (gfc_code *c)
2497 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2498 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2503 gfc_resolve_mvbits (gfc_code *c)
2508 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2509 they will be converted so that they fit into a C int. */
2510 ts.type = BT_INTEGER;
2511 ts.kind = gfc_c_int_kind;
2512 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2513 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2514 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2515 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2516 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2517 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2519 /* TO and FROM are guaranteed to have the same kind parameter. */
2520 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2521 c->ext.actual->expr->ts.kind);
2522 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2527 gfc_resolve_random_number (gfc_code *c)
2532 kind = c->ext.actual->expr->ts.kind;
2533 if (c->ext.actual->expr->rank == 0)
2534 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2536 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2538 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2543 gfc_resolve_random_seed (gfc_code *c)
2547 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2548 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2553 gfc_resolve_rename_sub (gfc_code *c)
2558 if (c->ext.actual->next->next->expr != NULL)
2559 kind = c->ext.actual->next->next->expr->ts.kind;
2561 kind = gfc_default_integer_kind;
2563 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2564 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2569 gfc_resolve_kill_sub (gfc_code *c)
2574 if (c->ext.actual->next->next->expr != NULL)
2575 kind = c->ext.actual->next->next->expr->ts.kind;
2577 kind = gfc_default_integer_kind;
2579 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2580 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2585 gfc_resolve_link_sub (gfc_code *c)
2590 if (c->ext.actual->next->next->expr != NULL)
2591 kind = c->ext.actual->next->next->expr->ts.kind;
2593 kind = gfc_default_integer_kind;
2595 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2596 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2601 gfc_resolve_symlnk_sub (gfc_code *c)
2606 if (c->ext.actual->next->next->expr != NULL)
2607 kind = c->ext.actual->next->next->expr->ts.kind;
2609 kind = gfc_default_integer_kind;
2611 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2612 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2616 /* G77 compatibility subroutines etime() and dtime(). */
2619 gfc_resolve_etime_sub (gfc_code *c)
2622 name = gfc_get_string (PREFIX ("etime_sub"));
2623 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2627 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2630 gfc_resolve_itime (gfc_code *c)
2633 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2634 gfc_default_integer_kind));
2638 gfc_resolve_idate (gfc_code *c)
2641 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2642 gfc_default_integer_kind));
2646 gfc_resolve_ltime (gfc_code *c)
2649 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2650 gfc_default_integer_kind));
2654 gfc_resolve_gmtime (gfc_code *c)
2657 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2658 gfc_default_integer_kind));
2662 /* G77 compatibility subroutine second(). */
2665 gfc_resolve_second_sub (gfc_code *c)
2668 name = gfc_get_string (PREFIX ("second_sub"));
2669 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2674 gfc_resolve_sleep_sub (gfc_code *c)
2679 if (c->ext.actual->expr != NULL)
2680 kind = c->ext.actual->expr->ts.kind;
2682 kind = gfc_default_integer_kind;
2684 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2685 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2689 /* G77 compatibility function srand(). */
2692 gfc_resolve_srand (gfc_code *c)
2695 name = gfc_get_string (PREFIX ("srand"));
2696 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2700 /* Resolve the getarg intrinsic subroutine. */
2703 gfc_resolve_getarg (gfc_code *c)
2707 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
2711 ts.type = BT_INTEGER;
2712 ts.kind = gfc_default_integer_kind;
2714 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2717 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
2718 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2722 /* Resolve the getcwd intrinsic subroutine. */
2725 gfc_resolve_getcwd_sub (gfc_code *c)
2730 if (c->ext.actual->next->expr != NULL)
2731 kind = c->ext.actual->next->expr->ts.kind;
2733 kind = gfc_default_integer_kind;
2735 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2736 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2740 /* Resolve the get_command intrinsic subroutine. */
2743 gfc_resolve_get_command (gfc_code *c)
2747 kind = gfc_default_integer_kind;
2748 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2749 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2753 /* Resolve the get_command_argument intrinsic subroutine. */
2756 gfc_resolve_get_command_argument (gfc_code *c)
2760 kind = gfc_default_integer_kind;
2761 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2762 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2766 /* Resolve the get_environment_variable intrinsic subroutine. */
2769 gfc_resolve_get_environment_variable (gfc_code *code)
2773 kind = gfc_default_integer_kind;
2774 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2775 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2780 gfc_resolve_signal_sub (gfc_code *c)
2783 gfc_expr *number, *handler, *status;
2786 number = c->ext.actual->expr;
2787 handler = c->ext.actual->next->expr;
2788 status = c->ext.actual->next->next->expr;
2789 ts.type = BT_INTEGER;
2790 ts.kind = gfc_c_int_kind;
2792 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2793 if (handler->ts.type == BT_INTEGER)
2795 if (handler->ts.kind != gfc_c_int_kind)
2796 gfc_convert_type (handler, &ts, 2);
2797 name = gfc_get_string (PREFIX ("signal_sub_int"));
2800 name = gfc_get_string (PREFIX ("signal_sub"));
2802 if (number->ts.kind != gfc_c_int_kind)
2803 gfc_convert_type (number, &ts, 2);
2804 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2805 gfc_convert_type (status, &ts, 2);
2807 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2811 /* Resolve the SYSTEM intrinsic subroutine. */
2814 gfc_resolve_system_sub (gfc_code *c)
2817 name = gfc_get_string (PREFIX ("system_sub"));
2818 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2822 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2825 gfc_resolve_system_clock (gfc_code *c)
2830 if (c->ext.actual->expr != NULL)
2831 kind = c->ext.actual->expr->ts.kind;
2832 else if (c->ext.actual->next->expr != NULL)
2833 kind = c->ext.actual->next->expr->ts.kind;
2834 else if (c->ext.actual->next->next->expr != NULL)
2835 kind = c->ext.actual->next->next->expr->ts.kind;
2837 kind = gfc_default_integer_kind;
2839 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
2840 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2844 /* Resolve the EXIT intrinsic subroutine. */
2847 gfc_resolve_exit (gfc_code *c)
2853 /* The STATUS argument has to be of default kind. If it is not,
2855 ts.type = BT_INTEGER;
2856 ts.kind = gfc_default_integer_kind;
2857 n = c->ext.actual->expr;
2858 if (n != NULL && n->ts.kind != ts.kind)
2859 gfc_convert_type (n, &ts, 2);
2861 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
2862 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2866 /* Resolve the FLUSH intrinsic subroutine. */
2869 gfc_resolve_flush (gfc_code *c)
2875 ts.type = BT_INTEGER;
2876 ts.kind = gfc_default_integer_kind;
2877 n = c->ext.actual->expr;
2878 if (n != NULL && n->ts.kind != ts.kind)
2879 gfc_convert_type (n, &ts, 2);
2881 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
2882 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2887 gfc_resolve_free (gfc_code *c)
2892 ts.type = BT_INTEGER;
2893 ts.kind = gfc_index_integer_kind;
2894 n = c->ext.actual->expr;
2895 if (n->ts.kind != ts.kind)
2896 gfc_convert_type (n, &ts, 2);
2898 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
2903 gfc_resolve_ctime_sub (gfc_code *c)
2907 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
2908 if (c->ext.actual->expr->ts.kind != 8)
2910 ts.type = BT_INTEGER;
2914 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2917 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
2922 gfc_resolve_fdate_sub (gfc_code *c)
2924 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
2929 gfc_resolve_gerror (gfc_code *c)
2931 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
2936 gfc_resolve_getlog (gfc_code *c)
2938 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
2943 gfc_resolve_hostnm_sub (gfc_code *c)
2948 if (c->ext.actual->next->expr != NULL)
2949 kind = c->ext.actual->next->expr->ts.kind;
2951 kind = gfc_default_integer_kind;
2953 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
2954 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2959 gfc_resolve_perror (gfc_code *c)
2961 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
2964 /* Resolve the STAT and FSTAT intrinsic subroutines. */
2967 gfc_resolve_stat_sub (gfc_code *c)
2970 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
2971 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2976 gfc_resolve_lstat_sub (gfc_code *c)
2979 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
2980 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2985 gfc_resolve_fstat_sub (gfc_code *c)
2991 u = c->ext.actual->expr;
2992 ts = &c->ext.actual->next->expr->ts;
2993 if (u->ts.kind != ts->kind)
2994 gfc_convert_type (u, ts, 2);
2995 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
2996 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3001 gfc_resolve_fgetc_sub (gfc_code *c)
3007 u = c->ext.actual->expr;
3008 st = c->ext.actual->next->next->expr;
3010 if (u->ts.kind != gfc_c_int_kind)
3012 ts.type = BT_INTEGER;
3013 ts.kind = gfc_c_int_kind;
3016 gfc_convert_type (u, &ts, 2);
3020 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3022 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3024 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3029 gfc_resolve_fget_sub (gfc_code *c)
3034 st = c->ext.actual->next->expr;
3036 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3038 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3040 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3045 gfc_resolve_fputc_sub (gfc_code *c)
3051 u = c->ext.actual->expr;
3052 st = c->ext.actual->next->next->expr;
3054 if (u->ts.kind != gfc_c_int_kind)
3056 ts.type = BT_INTEGER;
3057 ts.kind = gfc_c_int_kind;
3060 gfc_convert_type (u, &ts, 2);
3064 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3066 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3068 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3073 gfc_resolve_fput_sub (gfc_code *c)
3078 st = c->ext.actual->next->expr;
3080 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3082 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3084 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3089 gfc_resolve_fseek_sub (gfc_code *c)
3097 unit = c->ext.actual->expr;
3098 offset = c->ext.actual->next->expr;
3099 whence = c->ext.actual->next->next->expr;
3100 status = c->ext.actual->next->next->next->expr;
3102 if (unit->ts.kind != gfc_c_int_kind)
3104 ts.type = BT_INTEGER;
3105 ts.kind = gfc_c_int_kind;
3108 gfc_convert_type (unit, &ts, 2);
3111 if (offset->ts.kind != gfc_intio_kind)
3113 ts.type = BT_INTEGER;
3114 ts.kind = gfc_intio_kind;
3117 gfc_convert_type (offset, &ts, 2);
3120 if (whence->ts.kind != gfc_c_int_kind)
3122 ts.type = BT_INTEGER;
3123 ts.kind = gfc_c_int_kind;
3126 gfc_convert_type (whence, &ts, 2);
3129 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3133 gfc_resolve_ftell_sub (gfc_code *c)
3140 unit = c->ext.actual->expr;
3141 offset = c->ext.actual->next->expr;
3143 if (unit->ts.kind != gfc_c_int_kind)
3145 ts.type = BT_INTEGER;
3146 ts.kind = gfc_c_int_kind;
3149 gfc_convert_type (unit, &ts, 2);
3152 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3153 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3158 gfc_resolve_ttynam_sub (gfc_code *c)
3162 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3164 ts.type = BT_INTEGER;
3165 ts.kind = gfc_c_int_kind;
3168 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3171 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3175 /* Resolve the UMASK intrinsic subroutine. */
3178 gfc_resolve_umask_sub (gfc_code *c)
3183 if (c->ext.actual->next->expr != NULL)
3184 kind = c->ext.actual->next->expr->ts.kind;
3186 kind = gfc_default_integer_kind;
3188 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3189 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3192 /* Resolve the UNLINK intrinsic subroutine. */
3195 gfc_resolve_unlink_sub (gfc_code *c)
3200 if (c->ext.actual->next->expr != NULL)
3201 kind = c->ext.actual->next->expr->ts.kind;
3203 kind = gfc_default_integer_kind;
3205 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3206 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);