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.cl == NULL)
66 source->ts.cl = gfc_new_charlen (gfc_current_ns);
68 if (source->expr_type == EXPR_CONSTANT)
70 source->ts.cl->length = gfc_int_expr (source->value.character.length);
73 else if (source->expr_type == EXPR_ARRAY)
74 source->ts.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.cl = gfc_new_charlen (gfc_current_ns);
165 f->ts.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;
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;
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;
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;
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;
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 && !mold->ts.cl->length
2344 && !(mold->expr_type == EXPR_VARIABLE && mold->symtree->n.sym->attr.dummy))
2345 mold->ts.cl->length = gfc_int_expr (mold->value.character.length);
2349 if (size == NULL && mold->rank == 0)
2352 f->value.function.name = transfer0;
2357 f->value.function.name = transfer1;
2358 if (size && gfc_is_constant_expr (size))
2360 f->shape = gfc_get_shape (1);
2361 mpz_init_set (f->shape[0], size->value.integer);
2368 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2371 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2372 gfc_resolve_substring_charlen (matrix);
2378 f->shape = gfc_get_shape (2);
2379 mpz_init_set (f->shape[0], matrix->shape[1]);
2380 mpz_init_set (f->shape[1], matrix->shape[0]);
2383 switch (matrix->ts.kind)
2389 switch (matrix->ts.type)
2393 f->value.function.name
2394 = gfc_get_string (PREFIX ("transpose_%c%d"),
2395 gfc_type_letter (matrix->ts.type),
2401 /* Use the integer routines for real and logical cases. This
2402 assumes they all have the same alignment requirements. */
2403 f->value.function.name
2404 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2408 if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4)
2409 f->value.function.name = PREFIX ("transpose_char4");
2411 f->value.function.name = PREFIX ("transpose");
2417 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2418 ? PREFIX ("transpose_char")
2419 : PREFIX ("transpose"));
2426 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2428 f->ts.type = BT_CHARACTER;
2429 f->ts.kind = string->ts.kind;
2430 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2435 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2437 static char ubound[] = "__ubound";
2439 f->ts.type = BT_INTEGER;
2441 f->ts.kind = mpz_get_si (kind->value.integer);
2443 f->ts.kind = gfc_default_integer_kind;
2448 f->shape = gfc_get_shape (1);
2449 mpz_init_set_ui (f->shape[0], array->rank);
2452 f->value.function.name = ubound;
2456 /* Resolve the g77 compatibility function UMASK. */
2459 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2461 f->ts.type = BT_INTEGER;
2462 f->ts.kind = n->ts.kind;
2463 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2467 /* Resolve the g77 compatibility function UNLINK. */
2470 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2472 f->ts.type = BT_INTEGER;
2474 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2479 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2484 f->ts.type = BT_CHARACTER;
2485 f->ts.kind = gfc_default_character_kind;
2487 if (unit->ts.kind != gfc_c_int_kind)
2489 ts.type = BT_INTEGER;
2490 ts.kind = gfc_c_int_kind;
2493 gfc_convert_type (unit, &ts, 2);
2496 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2501 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2502 gfc_expr *field ATTRIBUTE_UNUSED)
2504 if (vector->ts.type == BT_CHARACTER && vector->ref)
2505 gfc_resolve_substring_charlen (vector);
2508 f->rank = mask->rank;
2509 resolve_mask_arg (mask);
2511 if (vector->ts.type == BT_CHARACTER)
2513 if (vector->ts.kind == 1)
2514 f->value.function.name
2515 = gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0);
2517 f->value.function.name
2518 = gfc_get_string (PREFIX ("unpack%d_char%d"),
2519 field->rank > 0 ? 1 : 0, vector->ts.kind);
2522 f->value.function.name
2523 = gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0);
2528 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2529 gfc_expr *set ATTRIBUTE_UNUSED,
2530 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2532 f->ts.type = BT_INTEGER;
2534 f->ts.kind = mpz_get_si (kind->value.integer);
2536 f->ts.kind = gfc_default_integer_kind;
2537 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2542 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2544 f->ts.type = i->ts.type;
2545 f->ts.kind = gfc_kind_max (i, j);
2547 if (i->ts.kind != j->ts.kind)
2549 if (i->ts.kind == gfc_kind_max (i, j))
2550 gfc_convert_type (j, &i->ts, 2);
2552 gfc_convert_type (i, &j->ts, 2);
2555 f->value.function.name
2556 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2560 /* Intrinsic subroutine resolution. */
2563 gfc_resolve_alarm_sub (gfc_code *c)
2566 gfc_expr *seconds, *handler, *status;
2570 seconds = c->ext.actual->expr;
2571 handler = c->ext.actual->next->expr;
2572 status = c->ext.actual->next->next->expr;
2573 ts.type = BT_INTEGER;
2574 ts.kind = gfc_c_int_kind;
2576 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2577 In all cases, the status argument is of default integer kind
2578 (enforced in check.c) so that the function suffix is fixed. */
2579 if (handler->ts.type == BT_INTEGER)
2581 if (handler->ts.kind != gfc_c_int_kind)
2582 gfc_convert_type (handler, &ts, 2);
2583 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2584 gfc_default_integer_kind);
2587 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2588 gfc_default_integer_kind);
2590 if (seconds->ts.kind != gfc_c_int_kind)
2591 gfc_convert_type (seconds, &ts, 2);
2593 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2597 gfc_resolve_cpu_time (gfc_code *c)
2600 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2601 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2605 /* Create a formal arglist based on an actual one and set the INTENTs given. */
2607 static gfc_formal_arglist*
2608 create_formal_for_intents (gfc_actual_arglist* actual, const sym_intent* ints)
2610 gfc_formal_arglist* head;
2611 gfc_formal_arglist* tail;
2617 head = tail = gfc_get_formal_arglist ();
2618 for (i = 0; actual; actual = actual->next, tail = tail->next, ++i)
2622 sym = gfc_new_symbol ("dummyarg", NULL);
2623 sym->ts = actual->expr->ts;
2625 sym->attr.intent = ints[i];
2629 tail->next = gfc_get_formal_arglist ();
2637 gfc_resolve_mvbits (gfc_code *c)
2639 static const sym_intent INTENTS[] = {INTENT_IN, INTENT_IN, INTENT_IN,
2640 INTENT_INOUT, INTENT_IN};
2646 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2647 they will be converted so that they fit into a C int. */
2648 ts.type = BT_INTEGER;
2649 ts.kind = gfc_c_int_kind;
2650 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2651 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2652 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2653 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2654 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2655 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2657 /* TO and FROM are guaranteed to have the same kind parameter. */
2658 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2659 c->ext.actual->expr->ts.kind);
2660 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2661 /* Mark as elemental subroutine as this does not happen automatically. */
2662 c->resolved_sym->attr.elemental = 1;
2664 /* Create a dummy formal arglist so the INTENTs are known later for purpose
2665 of creating temporaries. */
2666 c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS);
2671 gfc_resolve_random_number (gfc_code *c)
2676 kind = c->ext.actual->expr->ts.kind;
2677 if (c->ext.actual->expr->rank == 0)
2678 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2680 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2682 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2687 gfc_resolve_random_seed (gfc_code *c)
2691 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2692 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2697 gfc_resolve_rename_sub (gfc_code *c)
2702 if (c->ext.actual->next->next->expr != NULL)
2703 kind = c->ext.actual->next->next->expr->ts.kind;
2705 kind = gfc_default_integer_kind;
2707 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2708 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2713 gfc_resolve_kill_sub (gfc_code *c)
2718 if (c->ext.actual->next->next->expr != NULL)
2719 kind = c->ext.actual->next->next->expr->ts.kind;
2721 kind = gfc_default_integer_kind;
2723 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2724 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2729 gfc_resolve_link_sub (gfc_code *c)
2734 if (c->ext.actual->next->next->expr != NULL)
2735 kind = c->ext.actual->next->next->expr->ts.kind;
2737 kind = gfc_default_integer_kind;
2739 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2740 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2745 gfc_resolve_symlnk_sub (gfc_code *c)
2750 if (c->ext.actual->next->next->expr != NULL)
2751 kind = c->ext.actual->next->next->expr->ts.kind;
2753 kind = gfc_default_integer_kind;
2755 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2756 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2760 /* G77 compatibility subroutines dtime() and etime(). */
2763 gfc_resolve_dtime_sub (gfc_code *c)
2766 name = gfc_get_string (PREFIX ("dtime_sub"));
2767 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2771 gfc_resolve_etime_sub (gfc_code *c)
2774 name = gfc_get_string (PREFIX ("etime_sub"));
2775 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2779 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2782 gfc_resolve_itime (gfc_code *c)
2785 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2786 gfc_default_integer_kind));
2790 gfc_resolve_idate (gfc_code *c)
2793 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2794 gfc_default_integer_kind));
2798 gfc_resolve_ltime (gfc_code *c)
2801 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2802 gfc_default_integer_kind));
2806 gfc_resolve_gmtime (gfc_code *c)
2809 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2810 gfc_default_integer_kind));
2814 /* G77 compatibility subroutine second(). */
2817 gfc_resolve_second_sub (gfc_code *c)
2820 name = gfc_get_string (PREFIX ("second_sub"));
2821 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2826 gfc_resolve_sleep_sub (gfc_code *c)
2831 if (c->ext.actual->expr != NULL)
2832 kind = c->ext.actual->expr->ts.kind;
2834 kind = gfc_default_integer_kind;
2836 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2837 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2841 /* G77 compatibility function srand(). */
2844 gfc_resolve_srand (gfc_code *c)
2847 name = gfc_get_string (PREFIX ("srand"));
2848 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2852 /* Resolve the getarg intrinsic subroutine. */
2855 gfc_resolve_getarg (gfc_code *c)
2859 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
2864 ts.type = BT_INTEGER;
2865 ts.kind = gfc_default_integer_kind;
2867 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2870 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
2871 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2875 /* Resolve the getcwd intrinsic subroutine. */
2878 gfc_resolve_getcwd_sub (gfc_code *c)
2883 if (c->ext.actual->next->expr != NULL)
2884 kind = c->ext.actual->next->expr->ts.kind;
2886 kind = gfc_default_integer_kind;
2888 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2889 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2893 /* Resolve the get_command intrinsic subroutine. */
2896 gfc_resolve_get_command (gfc_code *c)
2900 kind = gfc_default_integer_kind;
2901 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2902 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2906 /* Resolve the get_command_argument intrinsic subroutine. */
2909 gfc_resolve_get_command_argument (gfc_code *c)
2913 kind = gfc_default_integer_kind;
2914 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2915 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2919 /* Resolve the get_environment_variable intrinsic subroutine. */
2922 gfc_resolve_get_environment_variable (gfc_code *code)
2926 kind = gfc_default_integer_kind;
2927 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2928 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2933 gfc_resolve_signal_sub (gfc_code *c)
2936 gfc_expr *number, *handler, *status;
2940 number = c->ext.actual->expr;
2941 handler = c->ext.actual->next->expr;
2942 status = c->ext.actual->next->next->expr;
2943 ts.type = BT_INTEGER;
2944 ts.kind = gfc_c_int_kind;
2946 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2947 if (handler->ts.type == BT_INTEGER)
2949 if (handler->ts.kind != gfc_c_int_kind)
2950 gfc_convert_type (handler, &ts, 2);
2951 name = gfc_get_string (PREFIX ("signal_sub_int"));
2954 name = gfc_get_string (PREFIX ("signal_sub"));
2956 if (number->ts.kind != gfc_c_int_kind)
2957 gfc_convert_type (number, &ts, 2);
2958 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2959 gfc_convert_type (status, &ts, 2);
2961 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2965 /* Resolve the SYSTEM intrinsic subroutine. */
2968 gfc_resolve_system_sub (gfc_code *c)
2971 name = gfc_get_string (PREFIX ("system_sub"));
2972 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2976 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2979 gfc_resolve_system_clock (gfc_code *c)
2984 if (c->ext.actual->expr != NULL)
2985 kind = c->ext.actual->expr->ts.kind;
2986 else if (c->ext.actual->next->expr != NULL)
2987 kind = c->ext.actual->next->expr->ts.kind;
2988 else if (c->ext.actual->next->next->expr != NULL)
2989 kind = c->ext.actual->next->next->expr->ts.kind;
2991 kind = gfc_default_integer_kind;
2993 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
2994 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2998 /* Resolve the EXIT intrinsic subroutine. */
3001 gfc_resolve_exit (gfc_code *c)
3008 /* The STATUS argument has to be of default kind. If it is not,
3010 ts.type = BT_INTEGER;
3011 ts.kind = gfc_default_integer_kind;
3012 n = c->ext.actual->expr;
3013 if (n != NULL && n->ts.kind != ts.kind)
3014 gfc_convert_type (n, &ts, 2);
3016 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
3017 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3021 /* Resolve the FLUSH intrinsic subroutine. */
3024 gfc_resolve_flush (gfc_code *c)
3031 ts.type = BT_INTEGER;
3032 ts.kind = gfc_default_integer_kind;
3033 n = c->ext.actual->expr;
3034 if (n != NULL && n->ts.kind != ts.kind)
3035 gfc_convert_type (n, &ts, 2);
3037 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
3038 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3043 gfc_resolve_free (gfc_code *c)
3049 ts.type = BT_INTEGER;
3050 ts.kind = gfc_index_integer_kind;
3051 n = c->ext.actual->expr;
3052 if (n->ts.kind != ts.kind)
3053 gfc_convert_type (n, &ts, 2);
3055 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
3060 gfc_resolve_ctime_sub (gfc_code *c)
3065 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3066 if (c->ext.actual->expr->ts.kind != 8)
3068 ts.type = BT_INTEGER;
3072 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3075 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3080 gfc_resolve_fdate_sub (gfc_code *c)
3082 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3087 gfc_resolve_gerror (gfc_code *c)
3089 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3094 gfc_resolve_getlog (gfc_code *c)
3096 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3101 gfc_resolve_hostnm_sub (gfc_code *c)
3106 if (c->ext.actual->next->expr != NULL)
3107 kind = c->ext.actual->next->expr->ts.kind;
3109 kind = gfc_default_integer_kind;
3111 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3112 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3117 gfc_resolve_perror (gfc_code *c)
3119 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3122 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3125 gfc_resolve_stat_sub (gfc_code *c)
3128 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3129 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3134 gfc_resolve_lstat_sub (gfc_code *c)
3137 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3138 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3143 gfc_resolve_fstat_sub (gfc_code *c)
3149 u = c->ext.actual->expr;
3150 ts = &c->ext.actual->next->expr->ts;
3151 if (u->ts.kind != ts->kind)
3152 gfc_convert_type (u, ts, 2);
3153 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3154 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3159 gfc_resolve_fgetc_sub (gfc_code *c)
3166 u = c->ext.actual->expr;
3167 st = c->ext.actual->next->next->expr;
3169 if (u->ts.kind != gfc_c_int_kind)
3171 ts.type = BT_INTEGER;
3172 ts.kind = gfc_c_int_kind;
3175 gfc_convert_type (u, &ts, 2);
3179 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3181 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3183 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3188 gfc_resolve_fget_sub (gfc_code *c)
3193 st = c->ext.actual->next->expr;
3195 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3197 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3199 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3204 gfc_resolve_fputc_sub (gfc_code *c)
3211 u = c->ext.actual->expr;
3212 st = c->ext.actual->next->next->expr;
3214 if (u->ts.kind != gfc_c_int_kind)
3216 ts.type = BT_INTEGER;
3217 ts.kind = gfc_c_int_kind;
3220 gfc_convert_type (u, &ts, 2);
3224 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3226 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3228 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3233 gfc_resolve_fput_sub (gfc_code *c)
3238 st = c->ext.actual->next->expr;
3240 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3242 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3244 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3249 gfc_resolve_fseek_sub (gfc_code *c)
3258 unit = c->ext.actual->expr;
3259 offset = c->ext.actual->next->expr;
3260 whence = c->ext.actual->next->next->expr;
3261 status = c->ext.actual->next->next->next->expr;
3263 if (unit->ts.kind != gfc_c_int_kind)
3265 ts.type = BT_INTEGER;
3266 ts.kind = gfc_c_int_kind;
3269 gfc_convert_type (unit, &ts, 2);
3272 if (offset->ts.kind != gfc_intio_kind)
3274 ts.type = BT_INTEGER;
3275 ts.kind = gfc_intio_kind;
3278 gfc_convert_type (offset, &ts, 2);
3281 if (whence->ts.kind != gfc_c_int_kind)
3283 ts.type = BT_INTEGER;
3284 ts.kind = gfc_c_int_kind;
3287 gfc_convert_type (whence, &ts, 2);
3290 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3294 gfc_resolve_ftell_sub (gfc_code *c)
3302 unit = c->ext.actual->expr;
3303 offset = c->ext.actual->next->expr;
3305 if (unit->ts.kind != gfc_c_int_kind)
3307 ts.type = BT_INTEGER;
3308 ts.kind = gfc_c_int_kind;
3311 gfc_convert_type (unit, &ts, 2);
3314 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3315 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3320 gfc_resolve_ttynam_sub (gfc_code *c)
3325 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3327 ts.type = BT_INTEGER;
3328 ts.kind = gfc_c_int_kind;
3331 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3334 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3338 /* Resolve the UMASK intrinsic subroutine. */
3341 gfc_resolve_umask_sub (gfc_code *c)
3346 if (c->ext.actual->next->expr != NULL)
3347 kind = c->ext.actual->next->expr->ts.kind;
3349 kind = gfc_default_integer_kind;
3351 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3352 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3355 /* Resolve the UNLINK intrinsic subroutine. */
3358 gfc_resolve_unlink_sub (gfc_code *c)
3363 if (c->ext.actual->next->expr != NULL)
3364 kind = c->ext.actual->next->expr->ts.kind;
3366 kind = gfc_default_integer_kind;
3368 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3369 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);