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)
82 /* The mask can be kind 4 or 8 for the array case.
83 For the scalar case, coerce it to kind=4 unconditionally
84 (because this is the only kind we have a library function
91 if (mask->ts.kind != 4)
96 if (mask->ts.kind < 4)
97 newkind = gfc_default_logical_kind;
104 ts.type = BT_LOGICAL;
106 gfc_convert_type (mask, &ts, 2);
110 /********************** Resolution functions **********************/
114 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
117 if (f->ts.type == BT_COMPLEX)
118 f->ts.type = BT_REAL;
120 f->value.function.name
121 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
126 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
127 gfc_expr *mode ATTRIBUTE_UNUSED)
129 f->ts.type = BT_INTEGER;
130 f->ts.kind = gfc_c_int_kind;
131 f->value.function.name = PREFIX ("access_func");
136 gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
138 f->ts.type = BT_CHARACTER;
139 f->ts.kind = (kind == NULL)
140 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
141 f->ts.cl = gfc_get_charlen ();
142 f->ts.cl->next = gfc_current_ns->cl_list;
143 gfc_current_ns->cl_list = f->ts.cl;
144 f->ts.cl->length = gfc_int_expr (1);
146 f->value.function.name = gfc_get_string ("__achar_%d_%c%d", f->ts.kind,
147 gfc_type_letter (x->ts.type),
153 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
156 f->value.function.name
157 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
162 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
165 f->value.function.name
166 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
172 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
174 f->ts.type = BT_REAL;
175 f->ts.kind = x->ts.kind;
176 f->value.function.name
177 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
183 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
185 f->ts.type = i->ts.type;
186 f->ts.kind = gfc_kind_max (i, j);
188 if (i->ts.kind != j->ts.kind)
190 if (i->ts.kind == gfc_kind_max (i, j))
191 gfc_convert_type (j, &i->ts, 2);
193 gfc_convert_type (i, &j->ts, 2);
196 f->value.function.name
197 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
202 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
206 f->ts.type = a->ts.type;
207 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
209 if (a->ts.kind != f->ts.kind)
211 ts.type = f->ts.type;
212 ts.kind = f->ts.kind;
213 gfc_convert_type (a, &ts, 2);
215 /* The resolved name is only used for specific intrinsics where
216 the return kind is the same as the arg kind. */
217 f->value.function.name
218 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
223 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
225 gfc_resolve_aint (f, a, NULL);
230 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
236 gfc_resolve_dim_arg (dim);
237 f->rank = mask->rank - 1;
238 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
241 f->value.function.name
242 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
248 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
252 f->ts.type = a->ts.type;
253 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
255 if (a->ts.kind != f->ts.kind)
257 ts.type = f->ts.type;
258 ts.kind = f->ts.kind;
259 gfc_convert_type (a, &ts, 2);
262 /* The resolved name is only used for specific intrinsics where
263 the return kind is the same as the arg kind. */
264 f->value.function.name
265 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
271 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
273 gfc_resolve_anint (f, a, NULL);
278 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
284 gfc_resolve_dim_arg (dim);
285 f->rank = mask->rank - 1;
286 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
289 f->value.function.name
290 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
296 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
299 f->value.function.name
300 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
304 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
307 f->value.function.name
308 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
313 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
316 f->value.function.name
317 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
321 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
324 f->value.function.name
325 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
330 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
333 f->value.function.name
334 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
339 /* Resolve the BESYN and BESJN intrinsics. */
342 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
347 if (n->ts.kind != gfc_c_int_kind)
349 ts.type = BT_INTEGER;
350 ts.kind = gfc_c_int_kind;
351 gfc_convert_type (n, &ts, 2);
353 f->value.function.name = gfc_get_string ("<intrinsic>");
358 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
360 f->ts.type = BT_LOGICAL;
361 f->ts.kind = gfc_default_logical_kind;
362 f->value.function.name
363 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
368 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
370 f->ts.type = BT_INTEGER;
371 f->ts.kind = (kind == NULL)
372 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
373 f->value.function.name
374 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
375 gfc_type_letter (a->ts.type), a->ts.kind);
380 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
382 f->ts.type = BT_CHARACTER;
383 f->ts.kind = (kind == NULL)
384 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
385 f->value.function.name
386 = gfc_get_string ("__char_%d_%c%d", f->ts.kind,
387 gfc_type_letter (a->ts.type), a->ts.kind);
392 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
394 f->ts.type = BT_INTEGER;
395 f->ts.kind = gfc_default_integer_kind;
396 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
401 gfc_resolve_chdir_sub (gfc_code *c)
406 if (c->ext.actual->next->expr != NULL)
407 kind = c->ext.actual->next->expr->ts.kind;
409 kind = gfc_default_integer_kind;
411 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
412 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
417 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
418 gfc_expr *mode ATTRIBUTE_UNUSED)
420 f->ts.type = BT_INTEGER;
421 f->ts.kind = gfc_c_int_kind;
422 f->value.function.name = PREFIX ("chmod_func");
427 gfc_resolve_chmod_sub (gfc_code *c)
432 if (c->ext.actual->next->next->expr != NULL)
433 kind = c->ext.actual->next->next->expr->ts.kind;
435 kind = gfc_default_integer_kind;
437 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
438 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
443 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
445 f->ts.type = BT_COMPLEX;
446 f->ts.kind = (kind == NULL)
447 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
450 f->value.function.name
451 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
452 gfc_type_letter (x->ts.type), x->ts.kind);
454 f->value.function.name
455 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
456 gfc_type_letter (x->ts.type), x->ts.kind,
457 gfc_type_letter (y->ts.type), y->ts.kind);
462 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
464 gfc_resolve_cmplx (f, x, y, gfc_int_expr (gfc_default_double_kind));
469 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
473 if (x->ts.type == BT_INTEGER)
475 if (y->ts.type == BT_INTEGER)
476 kind = gfc_default_real_kind;
482 if (y->ts.type == BT_REAL)
483 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
488 f->ts.type = BT_COMPLEX;
490 f->value.function.name
491 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
492 gfc_type_letter (x->ts.type), x->ts.kind,
493 gfc_type_letter (y->ts.type), y->ts.kind);
498 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
501 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
506 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
509 f->value.function.name
510 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
515 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
518 f->value.function.name
519 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
524 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
526 f->ts.type = BT_INTEGER;
528 f->ts.kind = mpz_get_si (kind->value.integer);
530 f->ts.kind = gfc_default_integer_kind;
534 f->rank = mask->rank - 1;
535 gfc_resolve_dim_arg (dim);
536 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
539 f->value.function.name
540 = gfc_get_string (PREFIX ("count_%d_%c%d"), f->ts.kind,
541 gfc_type_letter (mask->ts.type), mask->ts.kind);
546 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
552 f->rank = array->rank;
553 f->shape = gfc_copy_shape (array->shape, array->rank);
560 /* Convert shift to at least gfc_default_integer_kind, so we don't need
561 kind=1 and kind=2 versions of the library functions. */
562 if (shift->ts.kind < gfc_default_integer_kind)
565 ts.type = BT_INTEGER;
566 ts.kind = gfc_default_integer_kind;
567 gfc_convert_type_warn (shift, &ts, 2, 0);
572 gfc_resolve_dim_arg (dim);
573 /* Convert dim to shift's kind, so we don't need so many variations. */
574 if (dim->ts.kind != shift->ts.kind)
575 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
577 f->value.function.name
578 = gfc_get_string (PREFIX ("cshift%d_%d%s"), n, shift->ts.kind,
579 array->ts.type == BT_CHARACTER ? "_char" : "");
584 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
588 f->ts.type = BT_CHARACTER;
589 f->ts.kind = gfc_default_character_kind;
591 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
592 if (time->ts.kind != 8)
594 ts.type = BT_INTEGER;
598 gfc_convert_type (time, &ts, 2);
601 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
606 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
608 f->ts.type = BT_REAL;
609 f->ts.kind = gfc_default_double_kind;
610 f->value.function.name
611 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
616 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
618 f->ts.type = a->ts.type;
620 f->ts.kind = gfc_kind_max (a,p);
622 f->ts.kind = a->ts.kind;
624 if (p != NULL && a->ts.kind != p->ts.kind)
626 if (a->ts.kind == gfc_kind_max (a,p))
627 gfc_convert_type (p, &a->ts, 2);
629 gfc_convert_type (a, &p->ts, 2);
632 f->value.function.name
633 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
638 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
642 temp.expr_type = EXPR_OP;
643 gfc_clear_ts (&temp.ts);
644 temp.value.op.operator = INTRINSIC_NONE;
645 temp.value.op.op1 = a;
646 temp.value.op.op2 = b;
647 gfc_type_convert_binary (&temp);
649 f->value.function.name
650 = gfc_get_string (PREFIX ("dot_product_%c%d"),
651 gfc_type_letter (f->ts.type), f->ts.kind);
656 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
657 gfc_expr *b ATTRIBUTE_UNUSED)
659 f->ts.kind = gfc_default_double_kind;
660 f->ts.type = BT_REAL;
661 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
666 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
667 gfc_expr *boundary, gfc_expr *dim)
672 f->rank = array->rank;
673 f->shape = gfc_copy_shape (array->shape, array->rank);
678 if (boundary && boundary->rank > 0)
681 /* Convert shift to at least gfc_default_integer_kind, so we don't need
682 kind=1 and kind=2 versions of the library functions. */
683 if (shift->ts.kind < gfc_default_integer_kind)
686 ts.type = BT_INTEGER;
687 ts.kind = gfc_default_integer_kind;
688 gfc_convert_type_warn (shift, &ts, 2, 0);
693 gfc_resolve_dim_arg (dim);
694 /* Convert dim to shift's kind, so we don't need so many variations. */
695 if (dim->ts.kind != shift->ts.kind)
696 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
699 f->value.function.name
700 = gfc_get_string (PREFIX ("eoshift%d_%d%s"), n, shift->ts.kind,
701 array->ts.type == BT_CHARACTER ? "_char" : "");
706 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
709 f->value.function.name
710 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
715 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
717 f->ts.type = BT_INTEGER;
718 f->ts.kind = gfc_default_integer_kind;
719 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
724 gfc_resolve_fdate (gfc_expr *f)
726 f->ts.type = BT_CHARACTER;
727 f->ts.kind = gfc_default_character_kind;
728 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
733 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
735 f->ts.type = BT_INTEGER;
736 f->ts.kind = (kind == NULL)
737 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
738 f->value.function.name
739 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
740 gfc_type_letter (a->ts.type), a->ts.kind);
745 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
747 f->ts.type = BT_INTEGER;
748 f->ts.kind = gfc_default_integer_kind;
749 if (n->ts.kind != f->ts.kind)
750 gfc_convert_type (n, &f->ts, 2);
751 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
756 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
759 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
763 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
766 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
769 f->value.function.name = gfc_get_string ("<intrinsic>");
774 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
776 f->ts.type = BT_INTEGER;
778 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
783 gfc_resolve_getgid (gfc_expr *f)
785 f->ts.type = BT_INTEGER;
787 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
792 gfc_resolve_getpid (gfc_expr *f)
794 f->ts.type = BT_INTEGER;
796 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
801 gfc_resolve_getuid (gfc_expr *f)
803 f->ts.type = BT_INTEGER;
805 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
810 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
812 f->ts.type = BT_INTEGER;
814 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
819 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
821 /* If the kind of i and j are different, then g77 cross-promoted the
822 kinds to the largest value. The Fortran 95 standard requires the
824 if (i->ts.kind != j->ts.kind)
826 if (i->ts.kind == gfc_kind_max (i, j))
827 gfc_convert_type (j, &i->ts, 2);
829 gfc_convert_type (i, &j->ts, 2);
833 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
838 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
841 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
846 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
847 gfc_expr *len ATTRIBUTE_UNUSED)
850 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
855 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
858 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
863 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
865 f->ts.type = BT_INTEGER;
867 f->ts.kind = mpz_get_si (kind->value.integer);
869 f->ts.kind = gfc_default_integer_kind;
870 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
875 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
877 f->ts.type = BT_INTEGER;
879 f->ts.kind = mpz_get_si (kind->value.integer);
881 f->ts.kind = gfc_default_integer_kind;
882 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
887 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
889 gfc_resolve_nint (f, a, NULL);
894 gfc_resolve_ierrno (gfc_expr *f)
896 f->ts.type = BT_INTEGER;
897 f->ts.kind = gfc_default_integer_kind;
898 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
903 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
905 /* If the kind of i and j are different, then g77 cross-promoted the
906 kinds to the largest value. The Fortran 95 standard requires the
908 if (i->ts.kind != j->ts.kind)
910 if (i->ts.kind == gfc_kind_max (i, j))
911 gfc_convert_type (j, &i->ts, 2);
913 gfc_convert_type (i, &j->ts, 2);
917 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
922 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
924 /* If the kind of i and j are different, then g77 cross-promoted the
925 kinds to the largest value. The Fortran 95 standard requires the
927 if (i->ts.kind != j->ts.kind)
929 if (i->ts.kind == gfc_kind_max (i, j))
930 gfc_convert_type (j, &i->ts, 2);
932 gfc_convert_type (i, &j->ts, 2);
936 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
941 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
942 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
947 f->ts.type = BT_INTEGER;
949 f->ts.kind = mpz_get_si (kind->value.integer);
951 f->ts.kind = gfc_default_integer_kind;
953 if (back && back->ts.kind != gfc_default_integer_kind)
955 ts.type = BT_LOGICAL;
956 ts.kind = gfc_default_integer_kind;
959 gfc_convert_type (back, &ts, 2);
962 f->value.function.name
963 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
968 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
970 f->ts.type = BT_INTEGER;
971 f->ts.kind = (kind == NULL)
972 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
973 f->value.function.name
974 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
975 gfc_type_letter (a->ts.type), a->ts.kind);
980 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
982 f->ts.type = BT_INTEGER;
984 f->value.function.name
985 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
986 gfc_type_letter (a->ts.type), a->ts.kind);
991 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
993 f->ts.type = BT_INTEGER;
995 f->value.function.name
996 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
997 gfc_type_letter (a->ts.type), a->ts.kind);
1002 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1004 f->ts.type = BT_INTEGER;
1006 f->value.function.name
1007 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1008 gfc_type_letter (a->ts.type), a->ts.kind);
1013 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1017 f->ts.type = BT_LOGICAL;
1018 f->ts.kind = gfc_default_integer_kind;
1019 if (u->ts.kind != gfc_c_int_kind)
1021 ts.type = BT_INTEGER;
1022 ts.kind = gfc_c_int_kind;
1025 gfc_convert_type (u, &ts, 2);
1028 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1033 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1036 f->value.function.name
1037 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1042 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1045 f->value.function.name
1046 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1051 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1054 f->value.function.name
1055 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1060 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1064 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1067 f->value.function.name
1068 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1073 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1074 gfc_expr *s ATTRIBUTE_UNUSED)
1076 f->ts.type = BT_INTEGER;
1077 f->ts.kind = gfc_default_integer_kind;
1078 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1083 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1085 static char lbound[] = "__lbound";
1087 f->ts.type = BT_INTEGER;
1089 f->ts.kind = mpz_get_si (kind->value.integer);
1091 f->ts.kind = gfc_default_integer_kind;
1096 f->shape = gfc_get_shape (1);
1097 mpz_init_set_ui (f->shape[0], array->rank);
1100 f->value.function.name = lbound;
1105 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1107 f->ts.type = BT_INTEGER;
1109 f->ts.kind = mpz_get_si (kind->value.integer);
1111 f->ts.kind = gfc_default_integer_kind;
1112 f->value.function.name
1113 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1114 gfc_default_integer_kind);
1119 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1121 f->ts.type = BT_INTEGER;
1123 f->ts.kind = mpz_get_si (kind->value.integer);
1125 f->ts.kind = gfc_default_integer_kind;
1126 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1131 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1132 gfc_expr *p2 ATTRIBUTE_UNUSED)
1134 f->ts.type = BT_INTEGER;
1135 f->ts.kind = gfc_default_integer_kind;
1136 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1141 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1143 f->ts.type= BT_INTEGER;
1144 f->ts.kind = gfc_index_integer_kind;
1145 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1150 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1153 f->value.function.name
1154 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1159 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1162 f->value.function.name
1163 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1169 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1171 f->ts.type = BT_LOGICAL;
1172 f->ts.kind = (kind == NULL)
1173 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1176 f->value.function.name
1177 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1178 gfc_type_letter (a->ts.type), a->ts.kind);
1183 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1185 if (size->ts.kind < gfc_index_integer_kind)
1189 ts.type = BT_INTEGER;
1190 ts.kind = gfc_index_integer_kind;
1191 gfc_convert_type_warn (size, &ts, 2, 0);
1194 f->ts.type = BT_INTEGER;
1195 f->ts.kind = gfc_index_integer_kind;
1196 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1201 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1205 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1207 f->ts.type = BT_LOGICAL;
1208 f->ts.kind = gfc_default_logical_kind;
1212 temp.expr_type = EXPR_OP;
1213 gfc_clear_ts (&temp.ts);
1214 temp.value.op.operator = INTRINSIC_NONE;
1215 temp.value.op.op1 = a;
1216 temp.value.op.op2 = b;
1217 gfc_type_convert_binary (&temp);
1221 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1223 f->value.function.name
1224 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1230 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1232 gfc_actual_arglist *a;
1234 f->ts.type = args->expr->ts.type;
1235 f->ts.kind = args->expr->ts.kind;
1236 /* Find the largest type kind. */
1237 for (a = args->next; a; a = a->next)
1239 if (a->expr->ts.kind > f->ts.kind)
1240 f->ts.kind = a->expr->ts.kind;
1243 /* Convert all parameters to the required kind. */
1244 for (a = args; a; a = a->next)
1246 if (a->expr->ts.kind != f->ts.kind)
1247 gfc_convert_type (a->expr, &f->ts, 2);
1250 f->value.function.name
1251 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1256 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1258 gfc_resolve_minmax ("__max_%c%d", f, args);
1263 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1269 f->ts.type = BT_INTEGER;
1270 f->ts.kind = gfc_default_integer_kind;
1275 f->shape = gfc_get_shape (1);
1276 mpz_init_set_si (f->shape[0], array->rank);
1280 f->rank = array->rank - 1;
1281 gfc_resolve_dim_arg (dim);
1282 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1284 idim = (int) mpz_get_si (dim->value.integer);
1285 f->shape = gfc_get_shape (f->rank);
1286 for (i = 0, j = 0; i < f->rank; i++, j++)
1288 if (i == (idim - 1))
1290 mpz_init_set (f->shape[i], array->shape[j]);
1297 if (mask->rank == 0)
1302 resolve_mask_arg (mask);
1307 f->value.function.name
1308 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1309 gfc_type_letter (array->ts.type), array->ts.kind);
1314 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1324 f->rank = array->rank - 1;
1325 gfc_resolve_dim_arg (dim);
1327 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1329 idim = (int) mpz_get_si (dim->value.integer);
1330 f->shape = gfc_get_shape (f->rank);
1331 for (i = 0, j = 0; i < f->rank; i++, j++)
1333 if (i == (idim - 1))
1335 mpz_init_set (f->shape[i], array->shape[j]);
1342 if (mask->rank == 0)
1347 resolve_mask_arg (mask);
1352 f->value.function.name
1353 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1354 gfc_type_letter (array->ts.type), array->ts.kind);
1359 gfc_resolve_mclock (gfc_expr *f)
1361 f->ts.type = BT_INTEGER;
1363 f->value.function.name = PREFIX ("mclock");
1368 gfc_resolve_mclock8 (gfc_expr *f)
1370 f->ts.type = BT_INTEGER;
1372 f->value.function.name = PREFIX ("mclock8");
1377 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1378 gfc_expr *fsource ATTRIBUTE_UNUSED,
1379 gfc_expr *mask ATTRIBUTE_UNUSED)
1381 if (tsource->ts.type == BT_CHARACTER)
1382 check_charlen_present (tsource);
1384 f->ts = tsource->ts;
1385 f->value.function.name
1386 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1392 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1394 gfc_resolve_minmax ("__min_%c%d", f, args);
1399 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1405 f->ts.type = BT_INTEGER;
1406 f->ts.kind = gfc_default_integer_kind;
1411 f->shape = gfc_get_shape (1);
1412 mpz_init_set_si (f->shape[0], array->rank);
1416 f->rank = array->rank - 1;
1417 gfc_resolve_dim_arg (dim);
1418 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1420 idim = (int) mpz_get_si (dim->value.integer);
1421 f->shape = gfc_get_shape (f->rank);
1422 for (i = 0, j = 0; i < f->rank; i++, j++)
1424 if (i == (idim - 1))
1426 mpz_init_set (f->shape[i], array->shape[j]);
1433 if (mask->rank == 0)
1438 resolve_mask_arg (mask);
1443 f->value.function.name
1444 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1445 gfc_type_letter (array->ts.type), array->ts.kind);
1450 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1460 f->rank = array->rank - 1;
1461 gfc_resolve_dim_arg (dim);
1463 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1465 idim = (int) mpz_get_si (dim->value.integer);
1466 f->shape = gfc_get_shape (f->rank);
1467 for (i = 0, j = 0; i < f->rank; i++, j++)
1469 if (i == (idim - 1))
1471 mpz_init_set (f->shape[i], array->shape[j]);
1478 if (mask->rank == 0)
1483 resolve_mask_arg (mask);
1488 f->value.function.name
1489 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1490 gfc_type_letter (array->ts.type), array->ts.kind);
1495 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1497 f->ts.type = a->ts.type;
1499 f->ts.kind = gfc_kind_max (a,p);
1501 f->ts.kind = a->ts.kind;
1503 if (p != NULL && a->ts.kind != p->ts.kind)
1505 if (a->ts.kind == gfc_kind_max (a,p))
1506 gfc_convert_type (p, &a->ts, 2);
1508 gfc_convert_type (a, &p->ts, 2);
1511 f->value.function.name
1512 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1517 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1519 f->ts.type = a->ts.type;
1521 f->ts.kind = gfc_kind_max (a,p);
1523 f->ts.kind = a->ts.kind;
1525 if (p != NULL && a->ts.kind != p->ts.kind)
1527 if (a->ts.kind == gfc_kind_max (a,p))
1528 gfc_convert_type (p, &a->ts, 2);
1530 gfc_convert_type (a, &p->ts, 2);
1533 f->value.function.name
1534 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1539 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p ATTRIBUTE_UNUSED)
1542 f->value.function.name
1543 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1548 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1550 f->ts.type = BT_INTEGER;
1551 f->ts.kind = (kind == NULL)
1552 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1553 f->value.function.name
1554 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1559 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1562 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1567 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1569 f->ts.type = i->ts.type;
1570 f->ts.kind = gfc_kind_max (i, j);
1572 if (i->ts.kind != j->ts.kind)
1574 if (i->ts.kind == gfc_kind_max (i, j))
1575 gfc_convert_type (j, &i->ts, 2);
1577 gfc_convert_type (i, &j->ts, 2);
1580 f->value.function.name
1581 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1586 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1587 gfc_expr *vector ATTRIBUTE_UNUSED)
1592 resolve_mask_arg (mask);
1594 if (mask->rank != 0)
1595 f->value.function.name = (array->ts.type == BT_CHARACTER
1596 ? PREFIX ("pack_char") : PREFIX ("pack"));
1598 f->value.function.name = (array->ts.type == BT_CHARACTER
1599 ? PREFIX ("pack_s_char") : PREFIX ("pack_s"));
1604 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1613 f->rank = array->rank - 1;
1614 gfc_resolve_dim_arg (dim);
1619 if (mask->rank == 0)
1624 resolve_mask_arg (mask);
1629 f->value.function.name
1630 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1631 gfc_type_letter (array->ts.type), array->ts.kind);
1636 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1638 f->ts.type = BT_REAL;
1641 f->ts.kind = mpz_get_si (kind->value.integer);
1643 f->ts.kind = (a->ts.type == BT_COMPLEX)
1644 ? a->ts.kind : gfc_default_real_kind;
1646 f->value.function.name
1647 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1648 gfc_type_letter (a->ts.type), a->ts.kind);
1653 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1655 f->ts.type = BT_REAL;
1656 f->ts.kind = a->ts.kind;
1657 f->value.function.name
1658 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1659 gfc_type_letter (a->ts.type), a->ts.kind);
1664 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1665 gfc_expr *p2 ATTRIBUTE_UNUSED)
1667 f->ts.type = BT_INTEGER;
1668 f->ts.kind = gfc_default_integer_kind;
1669 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1674 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
1675 gfc_expr *ncopies ATTRIBUTE_UNUSED)
1677 f->ts.type = BT_CHARACTER;
1678 f->ts.kind = string->ts.kind;
1679 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
1684 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
1685 gfc_expr *pad ATTRIBUTE_UNUSED,
1686 gfc_expr *order ATTRIBUTE_UNUSED)
1694 gfc_array_size (shape, &rank);
1695 f->rank = mpz_get_si (rank);
1697 switch (source->ts.type)
1703 kind = source->ts.kind;
1717 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
1718 f->value.function.name
1719 = gfc_get_string (PREFIX ("reshape_%c%d"),
1720 gfc_type_letter (source->ts.type),
1723 f->value.function.name
1724 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
1729 f->value.function.name = (source->ts.type == BT_CHARACTER
1730 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1734 /* TODO: Make this work with a constant ORDER parameter. */
1735 if (shape->expr_type == EXPR_ARRAY
1736 && gfc_is_constant_expr (shape)
1740 f->shape = gfc_get_shape (f->rank);
1741 c = shape->value.constructor;
1742 for (i = 0; i < f->rank; i++)
1744 mpz_init_set (f->shape[i], c->expr->value.integer);
1749 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
1750 so many runtime variations. */
1751 if (shape->ts.kind != gfc_index_integer_kind)
1753 gfc_typespec ts = shape->ts;
1754 ts.kind = gfc_index_integer_kind;
1755 gfc_convert_type_warn (shape, &ts, 2, 0);
1757 if (order && order->ts.kind != gfc_index_integer_kind)
1758 gfc_convert_type_warn (order, &shape->ts, 2, 0);
1763 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
1766 gfc_actual_arglist *prec;
1769 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
1771 /* Create a hidden argument to the library routines for rrspacing. This
1772 hidden argument is the precision of x. */
1773 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1774 prec = gfc_get_actual_arglist ();
1776 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1777 /* The library routine expects INTEGER(4). */
1778 if (prec->expr->ts.kind != gfc_c_int_kind)
1781 ts.type = BT_INTEGER;
1782 ts.kind = gfc_c_int_kind;
1783 gfc_convert_type (prec->expr, &ts, 2);
1785 f->value.function.actual->next = prec;
1790 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1794 /* The implementation calls scalbn which takes an int as the
1796 if (i->ts.kind != gfc_c_int_kind)
1799 ts.type = BT_INTEGER;
1800 ts.kind = gfc_c_int_kind;
1801 gfc_convert_type_warn (i, &ts, 2, 0);
1804 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
1809 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
1810 gfc_expr *set ATTRIBUTE_UNUSED,
1811 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
1813 f->ts.type = BT_INTEGER;
1815 f->ts.kind = mpz_get_si (kind->value.integer);
1817 f->ts.kind = gfc_default_integer_kind;
1818 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
1823 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
1826 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
1831 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1835 /* The library implementation uses GFC_INTEGER_4 unconditionally,
1836 convert type so we don't have to implement all possible
1838 if (i->ts.kind != gfc_c_int_kind)
1841 ts.type = BT_INTEGER;
1842 ts.kind = gfc_c_int_kind;
1843 gfc_convert_type_warn (i, &ts, 2, 0);
1846 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
1851 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
1853 f->ts.type = BT_INTEGER;
1854 f->ts.kind = gfc_default_integer_kind;
1856 f->shape = gfc_get_shape (1);
1857 mpz_init_set_ui (f->shape[0], array->rank);
1858 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
1863 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
1866 f->value.function.name
1867 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
1872 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
1874 f->ts.type = BT_INTEGER;
1875 f->ts.kind = gfc_c_int_kind;
1877 /* handler can be either BT_INTEGER or BT_PROCEDURE */
1878 if (handler->ts.type == BT_INTEGER)
1880 if (handler->ts.kind != gfc_c_int_kind)
1881 gfc_convert_type (handler, &f->ts, 2);
1882 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
1885 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
1887 if (number->ts.kind != gfc_c_int_kind)
1888 gfc_convert_type (number, &f->ts, 2);
1893 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
1896 f->value.function.name
1897 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1902 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
1905 f->value.function.name
1906 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1911 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
1912 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
1914 f->ts.type = BT_INTEGER;
1916 f->ts.kind = mpz_get_si (kind->value.integer);
1918 f->ts.kind = gfc_default_integer_kind;
1923 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
1926 gfc_actual_arglist *prec, *tiny, *emin_1;
1929 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
1931 /* Create hidden arguments to the library routine for spacing. These
1932 hidden arguments are tiny(x), min_exponent - 1, and the precision
1935 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1937 tiny = gfc_get_actual_arglist ();
1938 tiny->name = "tiny";
1939 tiny->expr = gfc_get_expr ();
1940 tiny->expr->expr_type = EXPR_CONSTANT;
1941 tiny->expr->where = gfc_current_locus;
1942 tiny->expr->ts.type = x->ts.type;
1943 tiny->expr->ts.kind = x->ts.kind;
1944 mpfr_init (tiny->expr->value.real);
1945 mpfr_set (tiny->expr->value.real, gfc_real_kinds[k].tiny, GFC_RND_MODE);
1947 emin_1 = gfc_get_actual_arglist ();
1948 emin_1->name = "emin";
1949 emin_1->expr = gfc_int_expr (gfc_real_kinds[k].min_exponent - 1);
1951 /* The library routine expects INTEGER(4). */
1952 if (emin_1->expr->ts.kind != gfc_c_int_kind)
1955 ts.type = BT_INTEGER;
1956 ts.kind = gfc_c_int_kind;
1957 gfc_convert_type (emin_1->expr, &ts, 2);
1959 emin_1->next = tiny;
1961 prec = gfc_get_actual_arglist ();
1962 prec->name = "prec";
1963 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1965 /* The library routine expects INTEGER(4). */
1966 if (prec->expr->ts.kind != gfc_c_int_kind)
1969 ts.type = BT_INTEGER;
1970 ts.kind = gfc_c_int_kind;
1971 gfc_convert_type (prec->expr, &ts, 2);
1973 prec->next = emin_1;
1975 f->value.function.actual->next = prec;
1980 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
1983 if (source->ts.type == BT_CHARACTER)
1984 check_charlen_present (source);
1987 f->rank = source->rank + 1;
1988 if (source->rank == 0)
1989 f->value.function.name = (source->ts.type == BT_CHARACTER
1990 ? PREFIX ("spread_char_scalar")
1991 : PREFIX ("spread_scalar"));
1993 f->value.function.name = (source->ts.type == BT_CHARACTER
1994 ? PREFIX ("spread_char")
1995 : PREFIX ("spread"));
1997 if (dim && gfc_is_constant_expr (dim)
1998 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2001 idim = mpz_get_ui (dim->value.integer);
2002 f->shape = gfc_get_shape (f->rank);
2003 for (i = 0; i < (idim - 1); i++)
2004 mpz_init_set (f->shape[i], source->shape[i]);
2006 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2008 for (i = idim; i < f->rank ; i++)
2009 mpz_init_set (f->shape[i], source->shape[i-1]);
2013 gfc_resolve_dim_arg (dim);
2014 gfc_resolve_index (ncopies, 1);
2019 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2022 f->value.function.name
2023 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2027 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2030 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2031 gfc_expr *a ATTRIBUTE_UNUSED)
2033 f->ts.type = BT_INTEGER;
2034 f->ts.kind = gfc_default_integer_kind;
2035 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2040 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2041 gfc_expr *a ATTRIBUTE_UNUSED)
2043 f->ts.type = BT_INTEGER;
2044 f->ts.kind = gfc_default_integer_kind;
2045 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2050 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2052 f->ts.type = BT_INTEGER;
2053 f->ts.kind = gfc_default_integer_kind;
2054 if (n->ts.kind != f->ts.kind)
2055 gfc_convert_type (n, &f->ts, 2);
2057 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2062 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2066 f->ts.type = BT_INTEGER;
2067 f->ts.kind = gfc_c_int_kind;
2068 if (u->ts.kind != gfc_c_int_kind)
2070 ts.type = BT_INTEGER;
2071 ts.kind = gfc_c_int_kind;
2074 gfc_convert_type (u, &ts, 2);
2077 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2082 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2084 f->ts.type = BT_INTEGER;
2085 f->ts.kind = gfc_c_int_kind;
2086 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2091 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2095 f->ts.type = BT_INTEGER;
2096 f->ts.kind = gfc_c_int_kind;
2097 if (u->ts.kind != gfc_c_int_kind)
2099 ts.type = BT_INTEGER;
2100 ts.kind = gfc_c_int_kind;
2103 gfc_convert_type (u, &ts, 2);
2106 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2111 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2113 f->ts.type = BT_INTEGER;
2114 f->ts.kind = gfc_c_int_kind;
2115 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2120 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2124 f->ts.type = BT_INTEGER;
2125 f->ts.kind = gfc_index_integer_kind;
2126 if (u->ts.kind != gfc_c_int_kind)
2128 ts.type = BT_INTEGER;
2129 ts.kind = gfc_c_int_kind;
2132 gfc_convert_type (u, &ts, 2);
2135 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2140 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2148 if (mask->rank == 0)
2153 resolve_mask_arg (mask);
2160 f->rank = array->rank - 1;
2161 gfc_resolve_dim_arg (dim);
2164 f->value.function.name
2165 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2166 gfc_type_letter (array->ts.type), array->ts.kind);
2171 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2172 gfc_expr *p2 ATTRIBUTE_UNUSED)
2174 f->ts.type = BT_INTEGER;
2175 f->ts.kind = gfc_default_integer_kind;
2176 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2180 /* Resolve the g77 compatibility function SYSTEM. */
2183 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2185 f->ts.type = BT_INTEGER;
2187 f->value.function.name = gfc_get_string (PREFIX ("system"));
2192 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2195 f->value.function.name
2196 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2201 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2204 f->value.function.name
2205 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2210 gfc_resolve_time (gfc_expr *f)
2212 f->ts.type = BT_INTEGER;
2214 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2219 gfc_resolve_time8 (gfc_expr *f)
2221 f->ts.type = BT_INTEGER;
2223 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2228 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2229 gfc_expr *mold, gfc_expr *size)
2231 /* TODO: Make this do something meaningful. */
2232 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2236 if (size == NULL && mold->rank == 0)
2239 f->value.function.name = transfer0;
2244 f->value.function.name = transfer1;
2245 if (size && gfc_is_constant_expr (size))
2247 f->shape = gfc_get_shape (1);
2248 mpz_init_set (f->shape[0], size->value.integer);
2255 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2261 f->shape = gfc_get_shape (2);
2262 mpz_init_set (f->shape[0], matrix->shape[1]);
2263 mpz_init_set (f->shape[1], matrix->shape[0]);
2266 switch (matrix->ts.kind)
2272 switch (matrix->ts.type)
2276 f->value.function.name
2277 = gfc_get_string (PREFIX ("transpose_%c%d"),
2278 gfc_type_letter (matrix->ts.type),
2284 /* Use the integer routines for real and logical cases. This
2285 assumes they all have the same alignment requirements. */
2286 f->value.function.name
2287 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2291 f->value.function.name = PREFIX ("transpose");
2297 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2298 ? PREFIX ("transpose_char")
2299 : PREFIX ("transpose"));
2306 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2308 f->ts.type = BT_CHARACTER;
2309 f->ts.kind = string->ts.kind;
2310 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2315 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2317 static char ubound[] = "__ubound";
2319 f->ts.type = BT_INTEGER;
2321 f->ts.kind = mpz_get_si (kind->value.integer);
2323 f->ts.kind = gfc_default_integer_kind;
2328 f->shape = gfc_get_shape (1);
2329 mpz_init_set_ui (f->shape[0], array->rank);
2332 f->value.function.name = ubound;
2336 /* Resolve the g77 compatibility function UMASK. */
2339 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2341 f->ts.type = BT_INTEGER;
2342 f->ts.kind = n->ts.kind;
2343 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2347 /* Resolve the g77 compatibility function UNLINK. */
2350 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2352 f->ts.type = BT_INTEGER;
2354 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2359 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2363 f->ts.type = BT_CHARACTER;
2364 f->ts.kind = gfc_default_character_kind;
2366 if (unit->ts.kind != gfc_c_int_kind)
2368 ts.type = BT_INTEGER;
2369 ts.kind = gfc_c_int_kind;
2372 gfc_convert_type (unit, &ts, 2);
2375 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2380 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2381 gfc_expr *field ATTRIBUTE_UNUSED)
2384 f->rank = mask->rank;
2385 resolve_mask_arg (mask);
2387 f->value.function.name
2388 = gfc_get_string (PREFIX ("unpack%d%s"), field->rank > 0 ? 1 : 0,
2389 vector->ts.type == BT_CHARACTER ? "_char" : "");
2394 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2395 gfc_expr *set ATTRIBUTE_UNUSED,
2396 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2398 f->ts.type = BT_INTEGER;
2400 f->ts.kind = mpz_get_si (kind->value.integer);
2402 f->ts.kind = gfc_default_integer_kind;
2403 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2408 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2410 f->ts.type = i->ts.type;
2411 f->ts.kind = gfc_kind_max (i, j);
2413 if (i->ts.kind != j->ts.kind)
2415 if (i->ts.kind == gfc_kind_max (i, j))
2416 gfc_convert_type (j, &i->ts, 2);
2418 gfc_convert_type (i, &j->ts, 2);
2421 f->value.function.name
2422 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2426 /* Intrinsic subroutine resolution. */
2429 gfc_resolve_alarm_sub (gfc_code *c)
2432 gfc_expr *seconds, *handler, *status;
2435 seconds = c->ext.actual->expr;
2436 handler = c->ext.actual->next->expr;
2437 status = c->ext.actual->next->next->expr;
2438 ts.type = BT_INTEGER;
2439 ts.kind = gfc_c_int_kind;
2441 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2442 In all cases, the status argument is of default integer kind
2443 (enforced in check.c) so that the function suffix is fixed. */
2444 if (handler->ts.type == BT_INTEGER)
2446 if (handler->ts.kind != gfc_c_int_kind)
2447 gfc_convert_type (handler, &ts, 2);
2448 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2449 gfc_default_integer_kind);
2452 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2453 gfc_default_integer_kind);
2455 if (seconds->ts.kind != gfc_c_int_kind)
2456 gfc_convert_type (seconds, &ts, 2);
2458 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2462 gfc_resolve_cpu_time (gfc_code *c)
2465 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2466 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2471 gfc_resolve_mvbits (gfc_code *c)
2476 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2477 they will be converted so that they fit into a C int. */
2478 ts.type = BT_INTEGER;
2479 ts.kind = gfc_c_int_kind;
2480 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2481 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2482 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2483 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2484 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2485 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2487 /* TO and FROM are guaranteed to have the same kind parameter. */
2488 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2489 c->ext.actual->expr->ts.kind);
2490 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2495 gfc_resolve_random_number (gfc_code *c)
2500 kind = c->ext.actual->expr->ts.kind;
2501 if (c->ext.actual->expr->rank == 0)
2502 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2504 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2506 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2511 gfc_resolve_random_seed (gfc_code *c)
2515 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2516 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2521 gfc_resolve_rename_sub (gfc_code *c)
2526 if (c->ext.actual->next->next->expr != NULL)
2527 kind = c->ext.actual->next->next->expr->ts.kind;
2529 kind = gfc_default_integer_kind;
2531 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2532 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2537 gfc_resolve_kill_sub (gfc_code *c)
2542 if (c->ext.actual->next->next->expr != NULL)
2543 kind = c->ext.actual->next->next->expr->ts.kind;
2545 kind = gfc_default_integer_kind;
2547 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2548 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2553 gfc_resolve_link_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 ("link_i%d_sub"), kind);
2564 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2569 gfc_resolve_symlnk_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 ("symlnk_i%d_sub"), kind);
2580 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2584 /* G77 compatibility subroutines etime() and dtime(). */
2587 gfc_resolve_etime_sub (gfc_code *c)
2590 name = gfc_get_string (PREFIX ("etime_sub"));
2591 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2595 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2598 gfc_resolve_itime (gfc_code *c)
2601 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2602 gfc_default_integer_kind));
2606 gfc_resolve_idate (gfc_code *c)
2609 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2610 gfc_default_integer_kind));
2614 gfc_resolve_ltime (gfc_code *c)
2617 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2618 gfc_default_integer_kind));
2622 gfc_resolve_gmtime (gfc_code *c)
2625 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2626 gfc_default_integer_kind));
2630 /* G77 compatibility subroutine second(). */
2633 gfc_resolve_second_sub (gfc_code *c)
2636 name = gfc_get_string (PREFIX ("second_sub"));
2637 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2642 gfc_resolve_sleep_sub (gfc_code *c)
2647 if (c->ext.actual->expr != NULL)
2648 kind = c->ext.actual->expr->ts.kind;
2650 kind = gfc_default_integer_kind;
2652 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2653 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2657 /* G77 compatibility function srand(). */
2660 gfc_resolve_srand (gfc_code *c)
2663 name = gfc_get_string (PREFIX ("srand"));
2664 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2668 /* Resolve the getarg intrinsic subroutine. */
2671 gfc_resolve_getarg (gfc_code *c)
2675 kind = gfc_default_integer_kind;
2676 name = gfc_get_string (PREFIX ("getarg_i%d"), kind);
2677 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2681 /* Resolve the getcwd intrinsic subroutine. */
2684 gfc_resolve_getcwd_sub (gfc_code *c)
2689 if (c->ext.actual->next->expr != NULL)
2690 kind = c->ext.actual->next->expr->ts.kind;
2692 kind = gfc_default_integer_kind;
2694 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2695 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2699 /* Resolve the get_command intrinsic subroutine. */
2702 gfc_resolve_get_command (gfc_code *c)
2706 kind = gfc_default_integer_kind;
2707 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2708 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2712 /* Resolve the get_command_argument intrinsic subroutine. */
2715 gfc_resolve_get_command_argument (gfc_code *c)
2719 kind = gfc_default_integer_kind;
2720 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2721 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2725 /* Resolve the get_environment_variable intrinsic subroutine. */
2728 gfc_resolve_get_environment_variable (gfc_code *code)
2732 kind = gfc_default_integer_kind;
2733 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2734 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2739 gfc_resolve_signal_sub (gfc_code *c)
2742 gfc_expr *number, *handler, *status;
2745 number = c->ext.actual->expr;
2746 handler = c->ext.actual->next->expr;
2747 status = c->ext.actual->next->next->expr;
2748 ts.type = BT_INTEGER;
2749 ts.kind = gfc_c_int_kind;
2751 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2752 if (handler->ts.type == BT_INTEGER)
2754 if (handler->ts.kind != gfc_c_int_kind)
2755 gfc_convert_type (handler, &ts, 2);
2756 name = gfc_get_string (PREFIX ("signal_sub_int"));
2759 name = gfc_get_string (PREFIX ("signal_sub"));
2761 if (number->ts.kind != gfc_c_int_kind)
2762 gfc_convert_type (number, &ts, 2);
2763 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2764 gfc_convert_type (status, &ts, 2);
2766 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2770 /* Resolve the SYSTEM intrinsic subroutine. */
2773 gfc_resolve_system_sub (gfc_code *c)
2776 name = gfc_get_string (PREFIX ("system_sub"));
2777 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2781 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2784 gfc_resolve_system_clock (gfc_code *c)
2789 if (c->ext.actual->expr != NULL)
2790 kind = c->ext.actual->expr->ts.kind;
2791 else if (c->ext.actual->next->expr != NULL)
2792 kind = c->ext.actual->next->expr->ts.kind;
2793 else if (c->ext.actual->next->next->expr != NULL)
2794 kind = c->ext.actual->next->next->expr->ts.kind;
2796 kind = gfc_default_integer_kind;
2798 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
2799 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2803 /* Resolve the EXIT intrinsic subroutine. */
2806 gfc_resolve_exit (gfc_code *c)
2812 /* The STATUS argument has to be of default kind. If it is not,
2814 ts.type = BT_INTEGER;
2815 ts.kind = gfc_default_integer_kind;
2816 n = c->ext.actual->expr;
2817 if (n != NULL && n->ts.kind != ts.kind)
2818 gfc_convert_type (n, &ts, 2);
2820 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
2821 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2825 /* Resolve the FLUSH intrinsic subroutine. */
2828 gfc_resolve_flush (gfc_code *c)
2834 ts.type = BT_INTEGER;
2835 ts.kind = gfc_default_integer_kind;
2836 n = c->ext.actual->expr;
2837 if (n != NULL && n->ts.kind != ts.kind)
2838 gfc_convert_type (n, &ts, 2);
2840 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
2841 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2846 gfc_resolve_free (gfc_code *c)
2851 ts.type = BT_INTEGER;
2852 ts.kind = gfc_index_integer_kind;
2853 n = c->ext.actual->expr;
2854 if (n->ts.kind != ts.kind)
2855 gfc_convert_type (n, &ts, 2);
2857 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
2862 gfc_resolve_ctime_sub (gfc_code *c)
2866 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
2867 if (c->ext.actual->expr->ts.kind != 8)
2869 ts.type = BT_INTEGER;
2873 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2876 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
2881 gfc_resolve_fdate_sub (gfc_code *c)
2883 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
2888 gfc_resolve_gerror (gfc_code *c)
2890 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
2895 gfc_resolve_getlog (gfc_code *c)
2897 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
2902 gfc_resolve_hostnm_sub (gfc_code *c)
2907 if (c->ext.actual->next->expr != NULL)
2908 kind = c->ext.actual->next->expr->ts.kind;
2910 kind = gfc_default_integer_kind;
2912 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
2913 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2918 gfc_resolve_perror (gfc_code *c)
2920 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
2923 /* Resolve the STAT and FSTAT intrinsic subroutines. */
2926 gfc_resolve_stat_sub (gfc_code *c)
2929 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
2930 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2935 gfc_resolve_lstat_sub (gfc_code *c)
2938 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
2939 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2944 gfc_resolve_fstat_sub (gfc_code *c)
2950 u = c->ext.actual->expr;
2951 ts = &c->ext.actual->next->expr->ts;
2952 if (u->ts.kind != ts->kind)
2953 gfc_convert_type (u, ts, 2);
2954 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
2955 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2960 gfc_resolve_fgetc_sub (gfc_code *c)
2966 u = c->ext.actual->expr;
2967 st = c->ext.actual->next->next->expr;
2969 if (u->ts.kind != gfc_c_int_kind)
2971 ts.type = BT_INTEGER;
2972 ts.kind = gfc_c_int_kind;
2975 gfc_convert_type (u, &ts, 2);
2979 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
2981 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
2983 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2988 gfc_resolve_fget_sub (gfc_code *c)
2993 st = c->ext.actual->next->expr;
2995 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
2997 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
2999 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3004 gfc_resolve_fputc_sub (gfc_code *c)
3010 u = c->ext.actual->expr;
3011 st = c->ext.actual->next->next->expr;
3013 if (u->ts.kind != gfc_c_int_kind)
3015 ts.type = BT_INTEGER;
3016 ts.kind = gfc_c_int_kind;
3019 gfc_convert_type (u, &ts, 2);
3023 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3025 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3027 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3032 gfc_resolve_fput_sub (gfc_code *c)
3037 st = c->ext.actual->next->expr;
3039 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3041 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3043 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3048 gfc_resolve_fseek_sub (gfc_code *c)
3056 unit = c->ext.actual->expr;
3057 offset = c->ext.actual->next->expr;
3058 whence = c->ext.actual->next->next->expr;
3059 status = c->ext.actual->next->next->next->expr;
3061 if (unit->ts.kind != gfc_c_int_kind)
3063 ts.type = BT_INTEGER;
3064 ts.kind = gfc_c_int_kind;
3067 gfc_convert_type (unit, &ts, 2);
3070 if (offset->ts.kind != gfc_intio_kind)
3072 ts.type = BT_INTEGER;
3073 ts.kind = gfc_intio_kind;
3076 gfc_convert_type (offset, &ts, 2);
3079 if (whence->ts.kind != gfc_c_int_kind)
3081 ts.type = BT_INTEGER;
3082 ts.kind = gfc_c_int_kind;
3085 gfc_convert_type (whence, &ts, 2);
3088 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3092 gfc_resolve_ftell_sub (gfc_code *c)
3099 unit = c->ext.actual->expr;
3100 offset = c->ext.actual->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 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3112 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3117 gfc_resolve_ttynam_sub (gfc_code *c)
3121 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3123 ts.type = BT_INTEGER;
3124 ts.kind = gfc_c_int_kind;
3127 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3130 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3134 /* Resolve the UMASK intrinsic subroutine. */
3137 gfc_resolve_umask_sub (gfc_code *c)
3142 if (c->ext.actual->next->expr != NULL)
3143 kind = c->ext.actual->next->expr->ts.kind;
3145 kind = gfc_default_integer_kind;
3147 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3148 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3151 /* Resolve the UNLINK intrinsic subroutine. */
3154 gfc_resolve_unlink_sub (gfc_code *c)
3159 if (c->ext.actual->next->expr != NULL)
3160 kind = c->ext.actual->next->expr->ts.kind;
3162 kind = gfc_default_integer_kind;
3164 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3165 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);