1 /* Intrinsic function resolution.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught & Katherine Holcomb
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* Assign name and types to intrinsic procedures. For functions, the
24 first argument to a resolution function is an expression pointer to
25 the original function node and the rest are pointers to the
26 arguments of the function call. For subroutines, a pointer to the
27 code node is passed. The result type and library subroutine name
28 are generally set according to the function arguments. */
32 #include "coretypes.h"
35 #include "intrinsic.h"
37 /* Given printf-like arguments, return a stable version of the result string.
39 We already have a working, optimized string hashing table in the form of
40 the identifier table. Reusing this table is likely not to be wasted,
41 since if the function name makes it to the gimple output of the frontend,
42 we'll have to create the identifier anyway. */
45 gfc_get_string (const char *format, ...)
51 va_start (ap, format);
52 vsnprintf (temp_name, sizeof (temp_name), format, ap);
54 temp_name[sizeof (temp_name) - 1] = 0;
56 ident = get_identifier (temp_name);
57 return IDENTIFIER_POINTER (ident);
60 /* MERGE and SPREAD need to have source charlen's present for passing
61 to the result expression. */
63 check_charlen_present (gfc_expr *source)
65 if (source->ts.u.cl == NULL)
66 source->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
68 if (source->expr_type == EXPR_CONSTANT)
70 source->ts.u.cl->length = gfc_int_expr (source->value.character.length);
73 else if (source->expr_type == EXPR_ARRAY)
74 source->ts.u.cl->length =
75 gfc_int_expr (source->value.constructor->expr->value.character.length);
78 /* Helper function for resolving the "mask" argument. */
81 resolve_mask_arg (gfc_expr *mask)
89 /* For the scalar case, coerce the mask to kind=4 unconditionally
90 (because this is the only kind we have a library function
93 if (mask->ts.kind != 4)
97 gfc_convert_type (mask, &ts, 2);
102 /* In the library, we access the mask with a GFC_LOGICAL_1
103 argument. No need to waste memory if we are about to create
104 a temporary array. */
105 if (mask->expr_type == EXPR_OP && mask->ts.kind != 1)
107 ts.type = BT_LOGICAL;
109 gfc_convert_type (mask, &ts, 2);
114 /********************** Resolution functions **********************/
118 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
121 if (f->ts.type == BT_COMPLEX)
122 f->ts.type = BT_REAL;
124 f->value.function.name
125 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
130 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
131 gfc_expr *mode ATTRIBUTE_UNUSED)
133 f->ts.type = BT_INTEGER;
134 f->ts.kind = gfc_c_int_kind;
135 f->value.function.name = PREFIX ("access_func");
140 gfc_resolve_adjustl (gfc_expr *f, gfc_expr *string)
142 f->ts.type = BT_CHARACTER;
143 f->ts.kind = string->ts.kind;
144 f->value.function.name = gfc_get_string ("__adjustl_s%d", f->ts.kind);
149 gfc_resolve_adjustr (gfc_expr *f, gfc_expr *string)
151 f->ts.type = BT_CHARACTER;
152 f->ts.kind = string->ts.kind;
153 f->value.function.name = gfc_get_string ("__adjustr_s%d", f->ts.kind);
158 gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind,
161 f->ts.type = BT_CHARACTER;
162 f->ts.kind = (kind == NULL)
163 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
164 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
165 f->ts.u.cl->length = gfc_int_expr (1);
167 f->value.function.name = gfc_get_string (name, f->ts.kind,
168 gfc_type_letter (x->ts.type),
174 gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
176 gfc_resolve_char_achar (f, x, kind, "__achar_%d_%c%d");
181 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
184 f->value.function.name
185 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
190 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
193 f->value.function.name
194 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
200 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
202 f->ts.type = BT_REAL;
203 f->ts.kind = x->ts.kind;
204 f->value.function.name
205 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
211 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
213 f->ts.type = i->ts.type;
214 f->ts.kind = gfc_kind_max (i, j);
216 if (i->ts.kind != j->ts.kind)
218 if (i->ts.kind == gfc_kind_max (i, j))
219 gfc_convert_type (j, &i->ts, 2);
221 gfc_convert_type (i, &j->ts, 2);
224 f->value.function.name
225 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
230 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
235 f->ts.type = a->ts.type;
236 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
238 if (a->ts.kind != f->ts.kind)
240 ts.type = f->ts.type;
241 ts.kind = f->ts.kind;
242 gfc_convert_type (a, &ts, 2);
244 /* The resolved name is only used for specific intrinsics where
245 the return kind is the same as the arg kind. */
246 f->value.function.name
247 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
252 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
254 gfc_resolve_aint (f, a, NULL);
259 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
265 gfc_resolve_dim_arg (dim);
266 f->rank = mask->rank - 1;
267 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
270 f->value.function.name
271 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
277 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
282 f->ts.type = a->ts.type;
283 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
285 if (a->ts.kind != f->ts.kind)
287 ts.type = f->ts.type;
288 ts.kind = f->ts.kind;
289 gfc_convert_type (a, &ts, 2);
292 /* The resolved name is only used for specific intrinsics where
293 the return kind is the same as the arg kind. */
294 f->value.function.name
295 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
301 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
303 gfc_resolve_anint (f, a, NULL);
308 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
314 gfc_resolve_dim_arg (dim);
315 f->rank = mask->rank - 1;
316 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
319 f->value.function.name
320 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
326 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
329 f->value.function.name
330 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
334 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
337 f->value.function.name
338 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
343 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
346 f->value.function.name
347 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
351 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
354 f->value.function.name
355 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
360 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
363 f->value.function.name
364 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
369 /* Resolve the BESYN and BESJN intrinsics. */
372 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
378 if (n->ts.kind != gfc_c_int_kind)
380 ts.type = BT_INTEGER;
381 ts.kind = gfc_c_int_kind;
382 gfc_convert_type (n, &ts, 2);
384 f->value.function.name = gfc_get_string ("<intrinsic>");
389 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
391 f->ts.type = BT_LOGICAL;
392 f->ts.kind = gfc_default_logical_kind;
393 f->value.function.name
394 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
399 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
401 f->ts.type = BT_INTEGER;
402 f->ts.kind = (kind == NULL)
403 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
404 f->value.function.name
405 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
406 gfc_type_letter (a->ts.type), a->ts.kind);
411 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
413 gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d");
418 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
420 f->ts.type = BT_INTEGER;
421 f->ts.kind = gfc_default_integer_kind;
422 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
427 gfc_resolve_chdir_sub (gfc_code *c)
432 if (c->ext.actual->next->expr != NULL)
433 kind = c->ext.actual->next->expr->ts.kind;
435 kind = gfc_default_integer_kind;
437 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
438 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
443 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
444 gfc_expr *mode ATTRIBUTE_UNUSED)
446 f->ts.type = BT_INTEGER;
447 f->ts.kind = gfc_c_int_kind;
448 f->value.function.name = PREFIX ("chmod_func");
453 gfc_resolve_chmod_sub (gfc_code *c)
458 if (c->ext.actual->next->next->expr != NULL)
459 kind = c->ext.actual->next->next->expr->ts.kind;
461 kind = gfc_default_integer_kind;
463 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
464 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
469 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
471 f->ts.type = BT_COMPLEX;
472 f->ts.kind = (kind == NULL)
473 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
476 f->value.function.name
477 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
478 gfc_type_letter (x->ts.type), x->ts.kind);
480 f->value.function.name
481 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
482 gfc_type_letter (x->ts.type), x->ts.kind,
483 gfc_type_letter (y->ts.type), y->ts.kind);
488 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
490 gfc_resolve_cmplx (f, x, y, gfc_int_expr (gfc_default_double_kind));
495 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
499 if (x->ts.type == BT_INTEGER)
501 if (y->ts.type == BT_INTEGER)
502 kind = gfc_default_real_kind;
508 if (y->ts.type == BT_REAL)
509 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
514 f->ts.type = BT_COMPLEX;
516 f->value.function.name
517 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
518 gfc_type_letter (x->ts.type), x->ts.kind,
519 gfc_type_letter (y->ts.type), y->ts.kind);
524 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
527 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
532 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
535 f->value.function.name
536 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
541 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
544 f->value.function.name
545 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
550 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
552 f->ts.type = BT_INTEGER;
554 f->ts.kind = mpz_get_si (kind->value.integer);
556 f->ts.kind = gfc_default_integer_kind;
560 f->rank = mask->rank - 1;
561 gfc_resolve_dim_arg (dim);
562 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
565 resolve_mask_arg (mask);
567 f->value.function.name
568 = gfc_get_string (PREFIX ("count_%d_%c"), f->ts.kind,
569 gfc_type_letter (mask->ts.type));
574 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
579 if (array->ts.type == BT_CHARACTER && array->ref)
580 gfc_resolve_substring_charlen (array);
583 f->rank = array->rank;
584 f->shape = gfc_copy_shape (array->shape, array->rank);
591 /* If dim kind is greater than default integer we need to use the larger. */
592 m = gfc_default_integer_kind;
594 m = m < dim->ts.kind ? dim->ts.kind : m;
596 /* Convert shift to at least m, so we don't need
597 kind=1 and kind=2 versions of the library functions. */
598 if (shift->ts.kind < m)
602 ts.type = BT_INTEGER;
604 gfc_convert_type_warn (shift, &ts, 2, 0);
609 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
610 && dim->symtree->n.sym->attr.optional)
612 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
613 dim->representation.length = shift->ts.kind;
617 gfc_resolve_dim_arg (dim);
618 /* Convert dim to shift's kind to reduce variations. */
619 if (dim->ts.kind != shift->ts.kind)
620 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
624 if (array->ts.type == BT_CHARACTER)
626 if (array->ts.kind == gfc_default_character_kind)
627 f->value.function.name
628 = gfc_get_string (PREFIX ("cshift%d_%d_char"), n, shift->ts.kind);
630 f->value.function.name
631 = gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n, shift->ts.kind,
635 f->value.function.name
636 = gfc_get_string (PREFIX ("cshift%d_%d"), n, shift->ts.kind);
641 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
646 f->ts.type = BT_CHARACTER;
647 f->ts.kind = gfc_default_character_kind;
649 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
650 if (time->ts.kind != 8)
652 ts.type = BT_INTEGER;
656 gfc_convert_type (time, &ts, 2);
659 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
664 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
666 f->ts.type = BT_REAL;
667 f->ts.kind = gfc_default_double_kind;
668 f->value.function.name
669 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
674 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
676 f->ts.type = a->ts.type;
678 f->ts.kind = gfc_kind_max (a,p);
680 f->ts.kind = a->ts.kind;
682 if (p != NULL && a->ts.kind != p->ts.kind)
684 if (a->ts.kind == gfc_kind_max (a,p))
685 gfc_convert_type (p, &a->ts, 2);
687 gfc_convert_type (a, &p->ts, 2);
690 f->value.function.name
691 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
696 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
700 temp.expr_type = EXPR_OP;
701 gfc_clear_ts (&temp.ts);
702 temp.value.op.op = INTRINSIC_NONE;
703 temp.value.op.op1 = a;
704 temp.value.op.op2 = b;
705 gfc_type_convert_binary (&temp);
707 f->value.function.name
708 = gfc_get_string (PREFIX ("dot_product_%c%d"),
709 gfc_type_letter (f->ts.type), f->ts.kind);
714 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
715 gfc_expr *b ATTRIBUTE_UNUSED)
717 f->ts.kind = gfc_default_double_kind;
718 f->ts.type = BT_REAL;
719 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
724 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
725 gfc_expr *boundary, gfc_expr *dim)
729 if (array->ts.type == BT_CHARACTER && array->ref)
730 gfc_resolve_substring_charlen (array);
733 f->rank = array->rank;
734 f->shape = gfc_copy_shape (array->shape, array->rank);
739 if (boundary && boundary->rank > 0)
742 /* If dim kind is greater than default integer we need to use the larger. */
743 m = gfc_default_integer_kind;
745 m = m < dim->ts.kind ? dim->ts.kind : m;
747 /* Convert shift to at least m, so we don't need
748 kind=1 and kind=2 versions of the library functions. */
749 if (shift->ts.kind < m)
753 ts.type = BT_INTEGER;
755 gfc_convert_type_warn (shift, &ts, 2, 0);
760 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
761 && dim->symtree->n.sym->attr.optional)
763 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
764 dim->representation.length = shift->ts.kind;
768 gfc_resolve_dim_arg (dim);
769 /* Convert dim to shift's kind to reduce variations. */
770 if (dim->ts.kind != shift->ts.kind)
771 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
775 if (array->ts.type == BT_CHARACTER)
777 if (array->ts.kind == gfc_default_character_kind)
778 f->value.function.name
779 = gfc_get_string (PREFIX ("eoshift%d_%d_char"), n, shift->ts.kind);
781 f->value.function.name
782 = gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n, shift->ts.kind,
786 f->value.function.name
787 = gfc_get_string (PREFIX ("eoshift%d_%d"), n, shift->ts.kind);
792 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
795 f->value.function.name
796 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
801 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
803 f->ts.type = BT_INTEGER;
804 f->ts.kind = gfc_default_integer_kind;
805 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
810 gfc_resolve_fdate (gfc_expr *f)
812 f->ts.type = BT_CHARACTER;
813 f->ts.kind = gfc_default_character_kind;
814 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
819 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
821 f->ts.type = BT_INTEGER;
822 f->ts.kind = (kind == NULL)
823 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
824 f->value.function.name
825 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
826 gfc_type_letter (a->ts.type), a->ts.kind);
831 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
833 f->ts.type = BT_INTEGER;
834 f->ts.kind = gfc_default_integer_kind;
835 if (n->ts.kind != f->ts.kind)
836 gfc_convert_type (n, &f->ts, 2);
837 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
842 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
845 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
849 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
852 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
855 f->value.function.name = gfc_get_string ("<intrinsic>");
860 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
863 f->value.function.name
864 = gfc_get_string ("__gamma_%d", x->ts.kind);
869 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
871 f->ts.type = BT_INTEGER;
873 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
878 gfc_resolve_getgid (gfc_expr *f)
880 f->ts.type = BT_INTEGER;
882 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
887 gfc_resolve_getpid (gfc_expr *f)
889 f->ts.type = BT_INTEGER;
891 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
896 gfc_resolve_getuid (gfc_expr *f)
898 f->ts.type = BT_INTEGER;
900 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
905 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
907 f->ts.type = BT_INTEGER;
909 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
914 gfc_resolve_hypot (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
917 f->value.function.name = gfc_get_string ("__hypot_r%d", x->ts.kind);
922 gfc_resolve_iand (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 ("__iand_%d", i->ts.kind);
941 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
944 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
949 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
950 gfc_expr *len ATTRIBUTE_UNUSED)
953 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
958 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
961 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
966 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
968 f->ts.type = BT_INTEGER;
970 f->ts.kind = mpz_get_si (kind->value.integer);
972 f->ts.kind = gfc_default_integer_kind;
973 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
978 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
980 f->ts.type = BT_INTEGER;
982 f->ts.kind = mpz_get_si (kind->value.integer);
984 f->ts.kind = gfc_default_integer_kind;
985 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
990 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
992 gfc_resolve_nint (f, a, NULL);
997 gfc_resolve_ierrno (gfc_expr *f)
999 f->ts.type = BT_INTEGER;
1000 f->ts.kind = gfc_default_integer_kind;
1001 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
1006 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1008 /* If the kind of i and j are different, then g77 cross-promoted the
1009 kinds to the largest value. The Fortran 95 standard requires the
1011 if (i->ts.kind != j->ts.kind)
1013 if (i->ts.kind == gfc_kind_max (i, j))
1014 gfc_convert_type (j, &i->ts, 2);
1016 gfc_convert_type (i, &j->ts, 2);
1020 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
1025 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1027 /* If the kind of i and j are different, then g77 cross-promoted the
1028 kinds to the largest value. The Fortran 95 standard requires the
1030 if (i->ts.kind != j->ts.kind)
1032 if (i->ts.kind == gfc_kind_max (i, j))
1033 gfc_convert_type (j, &i->ts, 2);
1035 gfc_convert_type (i, &j->ts, 2);
1039 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
1044 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
1045 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
1051 f->ts.type = BT_INTEGER;
1053 f->ts.kind = mpz_get_si (kind->value.integer);
1055 f->ts.kind = gfc_default_integer_kind;
1057 if (back && back->ts.kind != gfc_default_integer_kind)
1059 ts.type = BT_LOGICAL;
1060 ts.kind = gfc_default_integer_kind;
1061 ts.u.derived = NULL;
1063 gfc_convert_type (back, &ts, 2);
1066 f->value.function.name
1067 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
1072 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1074 f->ts.type = BT_INTEGER;
1075 f->ts.kind = (kind == NULL)
1076 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1077 f->value.function.name
1078 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1079 gfc_type_letter (a->ts.type), a->ts.kind);
1084 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1086 f->ts.type = BT_INTEGER;
1088 f->value.function.name
1089 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1090 gfc_type_letter (a->ts.type), a->ts.kind);
1095 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
1097 f->ts.type = BT_INTEGER;
1099 f->value.function.name
1100 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1101 gfc_type_letter (a->ts.type), a->ts.kind);
1106 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1108 f->ts.type = BT_INTEGER;
1110 f->value.function.name
1111 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1112 gfc_type_letter (a->ts.type), a->ts.kind);
1117 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1122 f->ts.type = BT_LOGICAL;
1123 f->ts.kind = gfc_default_integer_kind;
1124 if (u->ts.kind != gfc_c_int_kind)
1126 ts.type = BT_INTEGER;
1127 ts.kind = gfc_c_int_kind;
1128 ts.u.derived = NULL;
1130 gfc_convert_type (u, &ts, 2);
1133 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1138 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1141 f->value.function.name
1142 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1147 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1150 f->value.function.name
1151 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1156 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1159 f->value.function.name
1160 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1165 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1169 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1172 f->value.function.name
1173 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1178 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1179 gfc_expr *s ATTRIBUTE_UNUSED)
1181 f->ts.type = BT_INTEGER;
1182 f->ts.kind = gfc_default_integer_kind;
1183 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1188 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1190 static char lbound[] = "__lbound";
1192 f->ts.type = BT_INTEGER;
1194 f->ts.kind = mpz_get_si (kind->value.integer);
1196 f->ts.kind = gfc_default_integer_kind;
1201 f->shape = gfc_get_shape (1);
1202 mpz_init_set_ui (f->shape[0], array->rank);
1205 f->value.function.name = lbound;
1210 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1212 f->ts.type = BT_INTEGER;
1214 f->ts.kind = mpz_get_si (kind->value.integer);
1216 f->ts.kind = gfc_default_integer_kind;
1217 f->value.function.name
1218 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1219 gfc_default_integer_kind);
1224 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1226 f->ts.type = BT_INTEGER;
1228 f->ts.kind = mpz_get_si (kind->value.integer);
1230 f->ts.kind = gfc_default_integer_kind;
1231 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1236 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1239 f->value.function.name
1240 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1245 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1246 gfc_expr *p2 ATTRIBUTE_UNUSED)
1248 f->ts.type = BT_INTEGER;
1249 f->ts.kind = gfc_default_integer_kind;
1250 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1255 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1257 f->ts.type= BT_INTEGER;
1258 f->ts.kind = gfc_index_integer_kind;
1259 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1264 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1267 f->value.function.name
1268 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1273 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1276 f->value.function.name
1277 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1283 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1285 f->ts.type = BT_LOGICAL;
1286 f->ts.kind = (kind == NULL)
1287 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1290 f->value.function.name
1291 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1292 gfc_type_letter (a->ts.type), a->ts.kind);
1297 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1299 if (size->ts.kind < gfc_index_integer_kind)
1304 ts.type = BT_INTEGER;
1305 ts.kind = gfc_index_integer_kind;
1306 gfc_convert_type_warn (size, &ts, 2, 0);
1309 f->ts.type = BT_INTEGER;
1310 f->ts.kind = gfc_index_integer_kind;
1311 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1316 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1320 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1322 f->ts.type = BT_LOGICAL;
1323 f->ts.kind = gfc_default_logical_kind;
1327 temp.expr_type = EXPR_OP;
1328 gfc_clear_ts (&temp.ts);
1329 temp.value.op.op = INTRINSIC_NONE;
1330 temp.value.op.op1 = a;
1331 temp.value.op.op2 = b;
1332 gfc_type_convert_binary (&temp);
1336 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1338 if (a->rank == 2 && b->rank == 2)
1340 if (a->shape && b->shape)
1342 f->shape = gfc_get_shape (f->rank);
1343 mpz_init_set (f->shape[0], a->shape[0]);
1344 mpz_init_set (f->shape[1], b->shape[1]);
1347 else if (a->rank == 1)
1351 f->shape = gfc_get_shape (f->rank);
1352 mpz_init_set (f->shape[0], b->shape[1]);
1357 /* b->rank == 1 and a->rank == 2 here, all other cases have
1358 been caught in check.c. */
1361 f->shape = gfc_get_shape (f->rank);
1362 mpz_init_set (f->shape[0], a->shape[0]);
1366 f->value.function.name
1367 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1373 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1375 gfc_actual_arglist *a;
1377 f->ts.type = args->expr->ts.type;
1378 f->ts.kind = args->expr->ts.kind;
1379 /* Find the largest type kind. */
1380 for (a = args->next; a; a = a->next)
1382 if (a->expr->ts.kind > f->ts.kind)
1383 f->ts.kind = a->expr->ts.kind;
1386 /* Convert all parameters to the required kind. */
1387 for (a = args; a; a = a->next)
1389 if (a->expr->ts.kind != f->ts.kind)
1390 gfc_convert_type (a->expr, &f->ts, 2);
1393 f->value.function.name
1394 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1399 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1401 gfc_resolve_minmax ("__max_%c%d", f, args);
1406 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1412 f->ts.type = BT_INTEGER;
1413 f->ts.kind = gfc_default_integer_kind;
1418 f->shape = gfc_get_shape (1);
1419 mpz_init_set_si (f->shape[0], array->rank);
1423 f->rank = array->rank - 1;
1424 gfc_resolve_dim_arg (dim);
1425 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1427 idim = (int) mpz_get_si (dim->value.integer);
1428 f->shape = gfc_get_shape (f->rank);
1429 for (i = 0, j = 0; i < f->rank; i++, j++)
1431 if (i == (idim - 1))
1433 mpz_init_set (f->shape[i], array->shape[j]);
1440 if (mask->rank == 0)
1445 resolve_mask_arg (mask);
1450 f->value.function.name
1451 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1452 gfc_type_letter (array->ts.type), array->ts.kind);
1457 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1467 f->rank = array->rank - 1;
1468 gfc_resolve_dim_arg (dim);
1470 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1472 idim = (int) mpz_get_si (dim->value.integer);
1473 f->shape = gfc_get_shape (f->rank);
1474 for (i = 0, j = 0; i < f->rank; i++, j++)
1476 if (i == (idim - 1))
1478 mpz_init_set (f->shape[i], array->shape[j]);
1485 if (mask->rank == 0)
1490 resolve_mask_arg (mask);
1495 f->value.function.name
1496 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1497 gfc_type_letter (array->ts.type), array->ts.kind);
1502 gfc_resolve_mclock (gfc_expr *f)
1504 f->ts.type = BT_INTEGER;
1506 f->value.function.name = PREFIX ("mclock");
1511 gfc_resolve_mclock8 (gfc_expr *f)
1513 f->ts.type = BT_INTEGER;
1515 f->value.function.name = PREFIX ("mclock8");
1520 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1521 gfc_expr *fsource ATTRIBUTE_UNUSED,
1522 gfc_expr *mask ATTRIBUTE_UNUSED)
1524 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1525 gfc_resolve_substring_charlen (tsource);
1527 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1528 gfc_resolve_substring_charlen (fsource);
1530 if (tsource->ts.type == BT_CHARACTER)
1531 check_charlen_present (tsource);
1533 f->ts = tsource->ts;
1534 f->value.function.name
1535 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1541 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1543 gfc_resolve_minmax ("__min_%c%d", f, args);
1548 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1554 f->ts.type = BT_INTEGER;
1555 f->ts.kind = gfc_default_integer_kind;
1560 f->shape = gfc_get_shape (1);
1561 mpz_init_set_si (f->shape[0], array->rank);
1565 f->rank = array->rank - 1;
1566 gfc_resolve_dim_arg (dim);
1567 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1569 idim = (int) mpz_get_si (dim->value.integer);
1570 f->shape = gfc_get_shape (f->rank);
1571 for (i = 0, j = 0; i < f->rank; i++, j++)
1573 if (i == (idim - 1))
1575 mpz_init_set (f->shape[i], array->shape[j]);
1582 if (mask->rank == 0)
1587 resolve_mask_arg (mask);
1592 f->value.function.name
1593 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1594 gfc_type_letter (array->ts.type), array->ts.kind);
1599 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1609 f->rank = array->rank - 1;
1610 gfc_resolve_dim_arg (dim);
1612 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1614 idim = (int) mpz_get_si (dim->value.integer);
1615 f->shape = gfc_get_shape (f->rank);
1616 for (i = 0, j = 0; i < f->rank; i++, j++)
1618 if (i == (idim - 1))
1620 mpz_init_set (f->shape[i], array->shape[j]);
1627 if (mask->rank == 0)
1632 resolve_mask_arg (mask);
1637 f->value.function.name
1638 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1639 gfc_type_letter (array->ts.type), array->ts.kind);
1644 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1646 f->ts.type = a->ts.type;
1648 f->ts.kind = gfc_kind_max (a,p);
1650 f->ts.kind = a->ts.kind;
1652 if (p != NULL && a->ts.kind != p->ts.kind)
1654 if (a->ts.kind == gfc_kind_max (a,p))
1655 gfc_convert_type (p, &a->ts, 2);
1657 gfc_convert_type (a, &p->ts, 2);
1660 f->value.function.name
1661 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1666 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1668 f->ts.type = a->ts.type;
1670 f->ts.kind = gfc_kind_max (a,p);
1672 f->ts.kind = a->ts.kind;
1674 if (p != NULL && a->ts.kind != p->ts.kind)
1676 if (a->ts.kind == gfc_kind_max (a,p))
1677 gfc_convert_type (p, &a->ts, 2);
1679 gfc_convert_type (a, &p->ts, 2);
1682 f->value.function.name
1683 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1688 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1690 if (p->ts.kind != a->ts.kind)
1691 gfc_convert_type (p, &a->ts, 2);
1694 f->value.function.name
1695 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1700 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1702 f->ts.type = BT_INTEGER;
1703 f->ts.kind = (kind == NULL)
1704 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1705 f->value.function.name
1706 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1711 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1714 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1719 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1721 f->ts.type = i->ts.type;
1722 f->ts.kind = gfc_kind_max (i, j);
1724 if (i->ts.kind != j->ts.kind)
1726 if (i->ts.kind == gfc_kind_max (i, j))
1727 gfc_convert_type (j, &i->ts, 2);
1729 gfc_convert_type (i, &j->ts, 2);
1732 f->value.function.name
1733 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1738 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1739 gfc_expr *vector ATTRIBUTE_UNUSED)
1741 if (array->ts.type == BT_CHARACTER && array->ref)
1742 gfc_resolve_substring_charlen (array);
1747 resolve_mask_arg (mask);
1749 if (mask->rank != 0)
1751 if (array->ts.type == BT_CHARACTER)
1752 f->value.function.name
1753 = array->ts.kind == 1 ? PREFIX ("pack_char")
1755 (PREFIX ("pack_char%d"),
1758 f->value.function.name = PREFIX ("pack");
1762 if (array->ts.type == BT_CHARACTER)
1763 f->value.function.name
1764 = array->ts.kind == 1 ? PREFIX ("pack_s_char")
1766 (PREFIX ("pack_s_char%d"),
1769 f->value.function.name = PREFIX ("pack_s");
1775 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1784 f->rank = array->rank - 1;
1785 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
1786 gfc_resolve_dim_arg (dim);
1791 if (mask->rank == 0)
1796 resolve_mask_arg (mask);
1801 f->value.function.name
1802 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1803 gfc_type_letter (array->ts.type), array->ts.kind);
1808 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1810 f->ts.type = BT_REAL;
1813 f->ts.kind = mpz_get_si (kind->value.integer);
1815 f->ts.kind = (a->ts.type == BT_COMPLEX)
1816 ? a->ts.kind : gfc_default_real_kind;
1818 f->value.function.name
1819 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1820 gfc_type_letter (a->ts.type), a->ts.kind);
1825 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1827 f->ts.type = BT_REAL;
1828 f->ts.kind = a->ts.kind;
1829 f->value.function.name
1830 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1831 gfc_type_letter (a->ts.type), a->ts.kind);
1836 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1837 gfc_expr *p2 ATTRIBUTE_UNUSED)
1839 f->ts.type = BT_INTEGER;
1840 f->ts.kind = gfc_default_integer_kind;
1841 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1846 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
1847 gfc_expr *ncopies ATTRIBUTE_UNUSED)
1849 f->ts.type = BT_CHARACTER;
1850 f->ts.kind = string->ts.kind;
1851 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
1856 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
1857 gfc_expr *pad ATTRIBUTE_UNUSED,
1858 gfc_expr *order ATTRIBUTE_UNUSED)
1864 if (source->ts.type == BT_CHARACTER && source->ref)
1865 gfc_resolve_substring_charlen (source);
1869 gfc_array_size (shape, &rank);
1870 f->rank = mpz_get_si (rank);
1872 switch (source->ts.type)
1879 kind = source->ts.kind;
1893 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
1894 f->value.function.name
1895 = gfc_get_string (PREFIX ("reshape_%c%d"),
1896 gfc_type_letter (source->ts.type),
1898 else if (source->ts.type == BT_CHARACTER)
1899 f->value.function.name = gfc_get_string (PREFIX ("reshape_char%d"),
1902 f->value.function.name
1903 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
1907 f->value.function.name = (source->ts.type == BT_CHARACTER
1908 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1912 /* TODO: Make this work with a constant ORDER parameter. */
1913 if (shape->expr_type == EXPR_ARRAY
1914 && gfc_is_constant_expr (shape)
1918 f->shape = gfc_get_shape (f->rank);
1919 c = shape->value.constructor;
1920 for (i = 0; i < f->rank; i++)
1922 mpz_init_set (f->shape[i], c->expr->value.integer);
1927 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
1928 so many runtime variations. */
1929 if (shape->ts.kind != gfc_index_integer_kind)
1931 gfc_typespec ts = shape->ts;
1932 ts.kind = gfc_index_integer_kind;
1933 gfc_convert_type_warn (shape, &ts, 2, 0);
1935 if (order && order->ts.kind != gfc_index_integer_kind)
1936 gfc_convert_type_warn (order, &shape->ts, 2, 0);
1941 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
1944 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
1949 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED)
1952 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
1957 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
1958 gfc_expr *set ATTRIBUTE_UNUSED,
1959 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
1961 f->ts.type = BT_INTEGER;
1963 f->ts.kind = mpz_get_si (kind->value.integer);
1965 f->ts.kind = gfc_default_integer_kind;
1966 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
1971 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
1974 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
1979 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x,
1980 gfc_expr *i ATTRIBUTE_UNUSED)
1983 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
1988 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
1990 f->ts.type = BT_INTEGER;
1991 f->ts.kind = gfc_default_integer_kind;
1993 f->shape = gfc_get_shape (1);
1994 mpz_init_set_ui (f->shape[0], array->rank);
1995 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
2000 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
2003 f->value.function.name
2004 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
2009 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
2011 f->ts.type = BT_INTEGER;
2012 f->ts.kind = gfc_c_int_kind;
2014 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2015 if (handler->ts.type == BT_INTEGER)
2017 if (handler->ts.kind != gfc_c_int_kind)
2018 gfc_convert_type (handler, &f->ts, 2);
2019 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
2022 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
2024 if (number->ts.kind != gfc_c_int_kind)
2025 gfc_convert_type (number, &f->ts, 2);
2030 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
2033 f->value.function.name
2034 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2039 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
2042 f->value.function.name
2043 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2048 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2049 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
2051 f->ts.type = BT_INTEGER;
2053 f->ts.kind = mpz_get_si (kind->value.integer);
2055 f->ts.kind = gfc_default_integer_kind;
2060 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
2063 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
2068 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2071 if (source->ts.type == BT_CHARACTER && source->ref)
2072 gfc_resolve_substring_charlen (source);
2074 if (source->ts.type == BT_CHARACTER)
2075 check_charlen_present (source);
2078 f->rank = source->rank + 1;
2079 if (source->rank == 0)
2081 if (source->ts.type == BT_CHARACTER)
2082 f->value.function.name
2083 = source->ts.kind == 1 ? PREFIX ("spread_char_scalar")
2085 (PREFIX ("spread_char%d_scalar"),
2088 f->value.function.name = PREFIX ("spread_scalar");
2092 if (source->ts.type == BT_CHARACTER)
2093 f->value.function.name
2094 = source->ts.kind == 1 ? PREFIX ("spread_char")
2096 (PREFIX ("spread_char%d"),
2099 f->value.function.name = PREFIX ("spread");
2102 if (dim && gfc_is_constant_expr (dim)
2103 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2106 idim = mpz_get_ui (dim->value.integer);
2107 f->shape = gfc_get_shape (f->rank);
2108 for (i = 0; i < (idim - 1); i++)
2109 mpz_init_set (f->shape[i], source->shape[i]);
2111 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2113 for (i = idim; i < f->rank ; i++)
2114 mpz_init_set (f->shape[i], source->shape[i-1]);
2118 gfc_resolve_dim_arg (dim);
2119 gfc_resolve_index (ncopies, 1);
2124 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2127 f->value.function.name
2128 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2132 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2135 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2136 gfc_expr *a ATTRIBUTE_UNUSED)
2138 f->ts.type = BT_INTEGER;
2139 f->ts.kind = gfc_default_integer_kind;
2140 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2145 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2146 gfc_expr *a ATTRIBUTE_UNUSED)
2148 f->ts.type = BT_INTEGER;
2149 f->ts.kind = gfc_default_integer_kind;
2150 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2155 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2157 f->ts.type = BT_INTEGER;
2158 f->ts.kind = gfc_default_integer_kind;
2159 if (n->ts.kind != f->ts.kind)
2160 gfc_convert_type (n, &f->ts, 2);
2162 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2167 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2172 f->ts.type = BT_INTEGER;
2173 f->ts.kind = gfc_c_int_kind;
2174 if (u->ts.kind != gfc_c_int_kind)
2176 ts.type = BT_INTEGER;
2177 ts.kind = gfc_c_int_kind;
2178 ts.u.derived = NULL;
2180 gfc_convert_type (u, &ts, 2);
2183 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2188 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2190 f->ts.type = BT_INTEGER;
2191 f->ts.kind = gfc_c_int_kind;
2192 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2197 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2202 f->ts.type = BT_INTEGER;
2203 f->ts.kind = gfc_c_int_kind;
2204 if (u->ts.kind != gfc_c_int_kind)
2206 ts.type = BT_INTEGER;
2207 ts.kind = gfc_c_int_kind;
2208 ts.u.derived = NULL;
2210 gfc_convert_type (u, &ts, 2);
2213 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2218 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2220 f->ts.type = BT_INTEGER;
2221 f->ts.kind = gfc_c_int_kind;
2222 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2227 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2232 f->ts.type = BT_INTEGER;
2233 f->ts.kind = gfc_index_integer_kind;
2234 if (u->ts.kind != gfc_c_int_kind)
2236 ts.type = BT_INTEGER;
2237 ts.kind = gfc_c_int_kind;
2238 ts.u.derived = NULL;
2240 gfc_convert_type (u, &ts, 2);
2243 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2248 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2256 if (mask->rank == 0)
2261 resolve_mask_arg (mask);
2268 f->rank = array->rank - 1;
2269 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
2270 gfc_resolve_dim_arg (dim);
2273 f->value.function.name
2274 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2275 gfc_type_letter (array->ts.type), array->ts.kind);
2280 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2281 gfc_expr *p2 ATTRIBUTE_UNUSED)
2283 f->ts.type = BT_INTEGER;
2284 f->ts.kind = gfc_default_integer_kind;
2285 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2289 /* Resolve the g77 compatibility function SYSTEM. */
2292 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2294 f->ts.type = BT_INTEGER;
2296 f->value.function.name = gfc_get_string (PREFIX ("system"));
2301 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2304 f->value.function.name
2305 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2310 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2313 f->value.function.name
2314 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2319 gfc_resolve_time (gfc_expr *f)
2321 f->ts.type = BT_INTEGER;
2323 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2328 gfc_resolve_time8 (gfc_expr *f)
2330 f->ts.type = BT_INTEGER;
2332 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2337 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2338 gfc_expr *mold, gfc_expr *size)
2340 /* TODO: Make this do something meaningful. */
2341 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2343 if (mold->ts.type == BT_CHARACTER
2344 && !mold->ts.u.cl->length
2345 && gfc_is_constant_expr (mold))
2348 if (mold->expr_type == EXPR_CONSTANT)
2349 mold->ts.u.cl->length = gfc_int_expr (mold->value.character.length);
2352 len = mold->value.constructor->expr->value.character.length;
2353 mold->ts.u.cl->length = gfc_int_expr (len);
2359 if (size == NULL && mold->rank == 0)
2362 f->value.function.name = transfer0;
2367 f->value.function.name = transfer1;
2368 if (size && gfc_is_constant_expr (size))
2370 f->shape = gfc_get_shape (1);
2371 mpz_init_set (f->shape[0], size->value.integer);
2378 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2381 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2382 gfc_resolve_substring_charlen (matrix);
2388 f->shape = gfc_get_shape (2);
2389 mpz_init_set (f->shape[0], matrix->shape[1]);
2390 mpz_init_set (f->shape[1], matrix->shape[0]);
2393 switch (matrix->ts.kind)
2399 switch (matrix->ts.type)
2403 f->value.function.name
2404 = gfc_get_string (PREFIX ("transpose_%c%d"),
2405 gfc_type_letter (matrix->ts.type),
2411 /* Use the integer routines for real and logical cases. This
2412 assumes they all have the same alignment requirements. */
2413 f->value.function.name
2414 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2418 if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4)
2419 f->value.function.name = PREFIX ("transpose_char4");
2421 f->value.function.name = PREFIX ("transpose");
2427 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2428 ? PREFIX ("transpose_char")
2429 : PREFIX ("transpose"));
2436 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2438 f->ts.type = BT_CHARACTER;
2439 f->ts.kind = string->ts.kind;
2440 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2445 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2447 static char ubound[] = "__ubound";
2449 f->ts.type = BT_INTEGER;
2451 f->ts.kind = mpz_get_si (kind->value.integer);
2453 f->ts.kind = gfc_default_integer_kind;
2458 f->shape = gfc_get_shape (1);
2459 mpz_init_set_ui (f->shape[0], array->rank);
2462 f->value.function.name = ubound;
2466 /* Resolve the g77 compatibility function UMASK. */
2469 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2471 f->ts.type = BT_INTEGER;
2472 f->ts.kind = n->ts.kind;
2473 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2477 /* Resolve the g77 compatibility function UNLINK. */
2480 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2482 f->ts.type = BT_INTEGER;
2484 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2489 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2494 f->ts.type = BT_CHARACTER;
2495 f->ts.kind = gfc_default_character_kind;
2497 if (unit->ts.kind != gfc_c_int_kind)
2499 ts.type = BT_INTEGER;
2500 ts.kind = gfc_c_int_kind;
2501 ts.u.derived = NULL;
2503 gfc_convert_type (unit, &ts, 2);
2506 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2511 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2512 gfc_expr *field ATTRIBUTE_UNUSED)
2514 if (vector->ts.type == BT_CHARACTER && vector->ref)
2515 gfc_resolve_substring_charlen (vector);
2518 f->rank = mask->rank;
2519 resolve_mask_arg (mask);
2521 if (vector->ts.type == BT_CHARACTER)
2523 if (vector->ts.kind == 1)
2524 f->value.function.name
2525 = gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0);
2527 f->value.function.name
2528 = gfc_get_string (PREFIX ("unpack%d_char%d"),
2529 field->rank > 0 ? 1 : 0, vector->ts.kind);
2532 f->value.function.name
2533 = gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0);
2538 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2539 gfc_expr *set ATTRIBUTE_UNUSED,
2540 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2542 f->ts.type = BT_INTEGER;
2544 f->ts.kind = mpz_get_si (kind->value.integer);
2546 f->ts.kind = gfc_default_integer_kind;
2547 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2552 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2554 f->ts.type = i->ts.type;
2555 f->ts.kind = gfc_kind_max (i, j);
2557 if (i->ts.kind != j->ts.kind)
2559 if (i->ts.kind == gfc_kind_max (i, j))
2560 gfc_convert_type (j, &i->ts, 2);
2562 gfc_convert_type (i, &j->ts, 2);
2565 f->value.function.name
2566 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2570 /* Intrinsic subroutine resolution. */
2573 gfc_resolve_alarm_sub (gfc_code *c)
2576 gfc_expr *seconds, *handler, *status;
2580 seconds = c->ext.actual->expr;
2581 handler = c->ext.actual->next->expr;
2582 status = c->ext.actual->next->next->expr;
2583 ts.type = BT_INTEGER;
2584 ts.kind = gfc_c_int_kind;
2586 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2587 In all cases, the status argument is of default integer kind
2588 (enforced in check.c) so that the function suffix is fixed. */
2589 if (handler->ts.type == BT_INTEGER)
2591 if (handler->ts.kind != gfc_c_int_kind)
2592 gfc_convert_type (handler, &ts, 2);
2593 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2594 gfc_default_integer_kind);
2597 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2598 gfc_default_integer_kind);
2600 if (seconds->ts.kind != gfc_c_int_kind)
2601 gfc_convert_type (seconds, &ts, 2);
2603 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2607 gfc_resolve_cpu_time (gfc_code *c)
2610 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2611 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2615 /* Create a formal arglist based on an actual one and set the INTENTs given. */
2617 static gfc_formal_arglist*
2618 create_formal_for_intents (gfc_actual_arglist* actual, const sym_intent* ints)
2620 gfc_formal_arglist* head;
2621 gfc_formal_arglist* tail;
2627 head = tail = gfc_get_formal_arglist ();
2628 for (i = 0; actual; actual = actual->next, tail = tail->next, ++i)
2632 sym = gfc_new_symbol ("dummyarg", NULL);
2633 sym->ts = actual->expr->ts;
2635 sym->attr.intent = ints[i];
2639 tail->next = gfc_get_formal_arglist ();
2647 gfc_resolve_mvbits (gfc_code *c)
2649 static const sym_intent INTENTS[] = {INTENT_IN, INTENT_IN, INTENT_IN,
2650 INTENT_INOUT, INTENT_IN};
2656 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2657 they will be converted so that they fit into a C int. */
2658 ts.type = BT_INTEGER;
2659 ts.kind = gfc_c_int_kind;
2660 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2661 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2662 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2663 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2664 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2665 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2667 /* TO and FROM are guaranteed to have the same kind parameter. */
2668 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2669 c->ext.actual->expr->ts.kind);
2670 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2671 /* Mark as elemental subroutine as this does not happen automatically. */
2672 c->resolved_sym->attr.elemental = 1;
2674 /* Create a dummy formal arglist so the INTENTs are known later for purpose
2675 of creating temporaries. */
2676 c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS);
2681 gfc_resolve_random_number (gfc_code *c)
2686 kind = c->ext.actual->expr->ts.kind;
2687 if (c->ext.actual->expr->rank == 0)
2688 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2690 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2692 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2697 gfc_resolve_random_seed (gfc_code *c)
2701 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2702 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2707 gfc_resolve_rename_sub (gfc_code *c)
2712 if (c->ext.actual->next->next->expr != NULL)
2713 kind = c->ext.actual->next->next->expr->ts.kind;
2715 kind = gfc_default_integer_kind;
2717 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2718 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2723 gfc_resolve_kill_sub (gfc_code *c)
2728 if (c->ext.actual->next->next->expr != NULL)
2729 kind = c->ext.actual->next->next->expr->ts.kind;
2731 kind = gfc_default_integer_kind;
2733 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2734 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2739 gfc_resolve_link_sub (gfc_code *c)
2744 if (c->ext.actual->next->next->expr != NULL)
2745 kind = c->ext.actual->next->next->expr->ts.kind;
2747 kind = gfc_default_integer_kind;
2749 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2750 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2755 gfc_resolve_symlnk_sub (gfc_code *c)
2760 if (c->ext.actual->next->next->expr != NULL)
2761 kind = c->ext.actual->next->next->expr->ts.kind;
2763 kind = gfc_default_integer_kind;
2765 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2766 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2770 /* G77 compatibility subroutines dtime() and etime(). */
2773 gfc_resolve_dtime_sub (gfc_code *c)
2776 name = gfc_get_string (PREFIX ("dtime_sub"));
2777 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2781 gfc_resolve_etime_sub (gfc_code *c)
2784 name = gfc_get_string (PREFIX ("etime_sub"));
2785 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2789 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2792 gfc_resolve_itime (gfc_code *c)
2795 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2796 gfc_default_integer_kind));
2800 gfc_resolve_idate (gfc_code *c)
2803 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2804 gfc_default_integer_kind));
2808 gfc_resolve_ltime (gfc_code *c)
2811 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2812 gfc_default_integer_kind));
2816 gfc_resolve_gmtime (gfc_code *c)
2819 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2820 gfc_default_integer_kind));
2824 /* G77 compatibility subroutine second(). */
2827 gfc_resolve_second_sub (gfc_code *c)
2830 name = gfc_get_string (PREFIX ("second_sub"));
2831 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2836 gfc_resolve_sleep_sub (gfc_code *c)
2841 if (c->ext.actual->expr != NULL)
2842 kind = c->ext.actual->expr->ts.kind;
2844 kind = gfc_default_integer_kind;
2846 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2847 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2851 /* G77 compatibility function srand(). */
2854 gfc_resolve_srand (gfc_code *c)
2857 name = gfc_get_string (PREFIX ("srand"));
2858 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2862 /* Resolve the getarg intrinsic subroutine. */
2865 gfc_resolve_getarg (gfc_code *c)
2869 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
2874 ts.type = BT_INTEGER;
2875 ts.kind = gfc_default_integer_kind;
2877 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2880 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
2881 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2885 /* Resolve the getcwd intrinsic subroutine. */
2888 gfc_resolve_getcwd_sub (gfc_code *c)
2893 if (c->ext.actual->next->expr != NULL)
2894 kind = c->ext.actual->next->expr->ts.kind;
2896 kind = gfc_default_integer_kind;
2898 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2899 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2903 /* Resolve the get_command intrinsic subroutine. */
2906 gfc_resolve_get_command (gfc_code *c)
2910 kind = gfc_default_integer_kind;
2911 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2912 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2916 /* Resolve the get_command_argument intrinsic subroutine. */
2919 gfc_resolve_get_command_argument (gfc_code *c)
2923 kind = gfc_default_integer_kind;
2924 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2925 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2929 /* Resolve the get_environment_variable intrinsic subroutine. */
2932 gfc_resolve_get_environment_variable (gfc_code *code)
2936 kind = gfc_default_integer_kind;
2937 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2938 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2943 gfc_resolve_signal_sub (gfc_code *c)
2946 gfc_expr *number, *handler, *status;
2950 number = c->ext.actual->expr;
2951 handler = c->ext.actual->next->expr;
2952 status = c->ext.actual->next->next->expr;
2953 ts.type = BT_INTEGER;
2954 ts.kind = gfc_c_int_kind;
2956 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2957 if (handler->ts.type == BT_INTEGER)
2959 if (handler->ts.kind != gfc_c_int_kind)
2960 gfc_convert_type (handler, &ts, 2);
2961 name = gfc_get_string (PREFIX ("signal_sub_int"));
2964 name = gfc_get_string (PREFIX ("signal_sub"));
2966 if (number->ts.kind != gfc_c_int_kind)
2967 gfc_convert_type (number, &ts, 2);
2968 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2969 gfc_convert_type (status, &ts, 2);
2971 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2975 /* Resolve the SYSTEM intrinsic subroutine. */
2978 gfc_resolve_system_sub (gfc_code *c)
2981 name = gfc_get_string (PREFIX ("system_sub"));
2982 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2986 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2989 gfc_resolve_system_clock (gfc_code *c)
2994 if (c->ext.actual->expr != NULL)
2995 kind = c->ext.actual->expr->ts.kind;
2996 else if (c->ext.actual->next->expr != NULL)
2997 kind = c->ext.actual->next->expr->ts.kind;
2998 else if (c->ext.actual->next->next->expr != NULL)
2999 kind = c->ext.actual->next->next->expr->ts.kind;
3001 kind = gfc_default_integer_kind;
3003 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
3004 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3008 /* Resolve the EXIT intrinsic subroutine. */
3011 gfc_resolve_exit (gfc_code *c)
3018 /* The STATUS argument has to be of default kind. If it is not,
3020 ts.type = BT_INTEGER;
3021 ts.kind = gfc_default_integer_kind;
3022 n = c->ext.actual->expr;
3023 if (n != NULL && n->ts.kind != ts.kind)
3024 gfc_convert_type (n, &ts, 2);
3026 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
3027 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3031 /* Resolve the FLUSH intrinsic subroutine. */
3034 gfc_resolve_flush (gfc_code *c)
3041 ts.type = BT_INTEGER;
3042 ts.kind = gfc_default_integer_kind;
3043 n = c->ext.actual->expr;
3044 if (n != NULL && n->ts.kind != ts.kind)
3045 gfc_convert_type (n, &ts, 2);
3047 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
3048 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3053 gfc_resolve_free (gfc_code *c)
3059 ts.type = BT_INTEGER;
3060 ts.kind = gfc_index_integer_kind;
3061 n = c->ext.actual->expr;
3062 if (n->ts.kind != ts.kind)
3063 gfc_convert_type (n, &ts, 2);
3065 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
3070 gfc_resolve_ctime_sub (gfc_code *c)
3075 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3076 if (c->ext.actual->expr->ts.kind != 8)
3078 ts.type = BT_INTEGER;
3080 ts.u.derived = NULL;
3082 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3085 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3090 gfc_resolve_fdate_sub (gfc_code *c)
3092 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3097 gfc_resolve_gerror (gfc_code *c)
3099 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3104 gfc_resolve_getlog (gfc_code *c)
3106 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3111 gfc_resolve_hostnm_sub (gfc_code *c)
3116 if (c->ext.actual->next->expr != NULL)
3117 kind = c->ext.actual->next->expr->ts.kind;
3119 kind = gfc_default_integer_kind;
3121 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3122 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3127 gfc_resolve_perror (gfc_code *c)
3129 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3132 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3135 gfc_resolve_stat_sub (gfc_code *c)
3138 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3139 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3144 gfc_resolve_lstat_sub (gfc_code *c)
3147 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3148 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3153 gfc_resolve_fstat_sub (gfc_code *c)
3159 u = c->ext.actual->expr;
3160 ts = &c->ext.actual->next->expr->ts;
3161 if (u->ts.kind != ts->kind)
3162 gfc_convert_type (u, ts, 2);
3163 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3164 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3169 gfc_resolve_fgetc_sub (gfc_code *c)
3176 u = c->ext.actual->expr;
3177 st = c->ext.actual->next->next->expr;
3179 if (u->ts.kind != gfc_c_int_kind)
3181 ts.type = BT_INTEGER;
3182 ts.kind = gfc_c_int_kind;
3183 ts.u.derived = NULL;
3185 gfc_convert_type (u, &ts, 2);
3189 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3191 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3193 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3198 gfc_resolve_fget_sub (gfc_code *c)
3203 st = c->ext.actual->next->expr;
3205 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3207 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3209 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3214 gfc_resolve_fputc_sub (gfc_code *c)
3221 u = c->ext.actual->expr;
3222 st = c->ext.actual->next->next->expr;
3224 if (u->ts.kind != gfc_c_int_kind)
3226 ts.type = BT_INTEGER;
3227 ts.kind = gfc_c_int_kind;
3228 ts.u.derived = NULL;
3230 gfc_convert_type (u, &ts, 2);
3234 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3236 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3238 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3243 gfc_resolve_fput_sub (gfc_code *c)
3248 st = c->ext.actual->next->expr;
3250 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3252 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3254 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3259 gfc_resolve_fseek_sub (gfc_code *c)
3268 unit = c->ext.actual->expr;
3269 offset = c->ext.actual->next->expr;
3270 whence = c->ext.actual->next->next->expr;
3271 status = c->ext.actual->next->next->next->expr;
3273 if (unit->ts.kind != gfc_c_int_kind)
3275 ts.type = BT_INTEGER;
3276 ts.kind = gfc_c_int_kind;
3277 ts.u.derived = NULL;
3279 gfc_convert_type (unit, &ts, 2);
3282 if (offset->ts.kind != gfc_intio_kind)
3284 ts.type = BT_INTEGER;
3285 ts.kind = gfc_intio_kind;
3286 ts.u.derived = NULL;
3288 gfc_convert_type (offset, &ts, 2);
3291 if (whence->ts.kind != gfc_c_int_kind)
3293 ts.type = BT_INTEGER;
3294 ts.kind = gfc_c_int_kind;
3295 ts.u.derived = NULL;
3297 gfc_convert_type (whence, &ts, 2);
3300 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3304 gfc_resolve_ftell_sub (gfc_code *c)
3312 unit = c->ext.actual->expr;
3313 offset = c->ext.actual->next->expr;
3315 if (unit->ts.kind != gfc_c_int_kind)
3317 ts.type = BT_INTEGER;
3318 ts.kind = gfc_c_int_kind;
3319 ts.u.derived = NULL;
3321 gfc_convert_type (unit, &ts, 2);
3324 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3325 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3330 gfc_resolve_ttynam_sub (gfc_code *c)
3335 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3337 ts.type = BT_INTEGER;
3338 ts.kind = gfc_c_int_kind;
3339 ts.u.derived = NULL;
3341 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3344 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3348 /* Resolve the UMASK intrinsic subroutine. */
3351 gfc_resolve_umask_sub (gfc_code *c)
3356 if (c->ext.actual->next->expr != NULL)
3357 kind = c->ext.actual->next->expr->ts.kind;
3359 kind = gfc_default_integer_kind;
3361 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3362 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3365 /* Resolve the UNLINK intrinsic subroutine. */
3368 gfc_resolve_unlink_sub (gfc_code *c)
3373 if (c->ext.actual->next->expr != NULL)
3374 kind = c->ext.actual->next->expr->ts.kind;
3376 kind = gfc_default_integer_kind;
3378 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3379 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);