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)
67 source->ts.cl = gfc_get_charlen ();
68 source->ts.cl->next = gfc_current_ns->cl_list;
69 gfc_current_ns->cl_list = source->ts.cl;
72 if (source->expr_type == EXPR_CONSTANT)
74 source->ts.cl->length = gfc_int_expr (source->value.character.length);
77 else if (source->expr_type == EXPR_ARRAY)
79 source->ts.cl->length =
80 gfc_int_expr (source->value.constructor->expr->value.character.length);
85 /* Helper function for resolving the "mask" argument. */
88 resolve_mask_arg (gfc_expr *mask)
96 /* For the scalar case, coerce the mask to kind=4 unconditionally
97 (because this is the only kind we have a library function
100 if (mask->ts.kind != 4)
102 ts.type = BT_LOGICAL;
104 gfc_convert_type (mask, &ts, 2);
109 /* In the library, we access the mask with a GFC_LOGICAL_1
110 argument. No need to waste memory if we are about to create
111 a temporary array. */
112 if (mask->expr_type == EXPR_OP)
114 ts.type = BT_LOGICAL;
116 gfc_convert_type (mask, &ts, 2);
121 /********************** Resolution functions **********************/
125 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
128 if (f->ts.type == BT_COMPLEX)
129 f->ts.type = BT_REAL;
131 f->value.function.name
132 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
137 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
138 gfc_expr *mode ATTRIBUTE_UNUSED)
140 f->ts.type = BT_INTEGER;
141 f->ts.kind = gfc_c_int_kind;
142 f->value.function.name = PREFIX ("access_func");
147 gfc_resolve_adjustl (gfc_expr *f, gfc_expr *string)
149 f->ts.type = BT_CHARACTER;
150 f->ts.kind = string->ts.kind;
151 f->value.function.name = gfc_get_string ("__adjustl_s%d", f->ts.kind);
156 gfc_resolve_adjustr (gfc_expr *f, gfc_expr *string)
158 f->ts.type = BT_CHARACTER;
159 f->ts.kind = string->ts.kind;
160 f->value.function.name = gfc_get_string ("__adjustr_s%d", f->ts.kind);
165 gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind,
168 f->ts.type = BT_CHARACTER;
169 f->ts.kind = (kind == NULL)
170 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
171 f->ts.cl = gfc_get_charlen ();
172 f->ts.cl->next = gfc_current_ns->cl_list;
173 gfc_current_ns->cl_list = f->ts.cl;
174 f->ts.cl->length = gfc_int_expr (1);
176 f->value.function.name = gfc_get_string (name, f->ts.kind,
177 gfc_type_letter (x->ts.type),
183 gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
185 gfc_resolve_char_achar (f, x, kind, "__achar_%d_%c%d");
190 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
193 f->value.function.name
194 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
199 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
202 f->value.function.name
203 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
209 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
211 f->ts.type = BT_REAL;
212 f->ts.kind = x->ts.kind;
213 f->value.function.name
214 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
220 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
222 f->ts.type = i->ts.type;
223 f->ts.kind = gfc_kind_max (i, j);
225 if (i->ts.kind != j->ts.kind)
227 if (i->ts.kind == gfc_kind_max (i, j))
228 gfc_convert_type (j, &i->ts, 2);
230 gfc_convert_type (i, &j->ts, 2);
233 f->value.function.name
234 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
239 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
244 f->ts.type = a->ts.type;
245 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
247 if (a->ts.kind != f->ts.kind)
249 ts.type = f->ts.type;
250 ts.kind = f->ts.kind;
251 gfc_convert_type (a, &ts, 2);
253 /* The resolved name is only used for specific intrinsics where
254 the return kind is the same as the arg kind. */
255 f->value.function.name
256 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
261 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
263 gfc_resolve_aint (f, a, NULL);
268 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
274 gfc_resolve_dim_arg (dim);
275 f->rank = mask->rank - 1;
276 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
279 f->value.function.name
280 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
286 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
291 f->ts.type = a->ts.type;
292 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
294 if (a->ts.kind != f->ts.kind)
296 ts.type = f->ts.type;
297 ts.kind = f->ts.kind;
298 gfc_convert_type (a, &ts, 2);
301 /* The resolved name is only used for specific intrinsics where
302 the return kind is the same as the arg kind. */
303 f->value.function.name
304 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
310 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
312 gfc_resolve_anint (f, a, NULL);
317 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
323 gfc_resolve_dim_arg (dim);
324 f->rank = mask->rank - 1;
325 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
328 f->value.function.name
329 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
335 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
338 f->value.function.name
339 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
343 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
346 f->value.function.name
347 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
352 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
355 f->value.function.name
356 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
360 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
363 f->value.function.name
364 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
369 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
372 f->value.function.name
373 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
378 /* Resolve the BESYN and BESJN intrinsics. */
381 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
387 if (n->ts.kind != gfc_c_int_kind)
389 ts.type = BT_INTEGER;
390 ts.kind = gfc_c_int_kind;
391 gfc_convert_type (n, &ts, 2);
393 f->value.function.name = gfc_get_string ("<intrinsic>");
398 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
400 f->ts.type = BT_LOGICAL;
401 f->ts.kind = gfc_default_logical_kind;
402 f->value.function.name
403 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
408 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
410 f->ts.type = BT_INTEGER;
411 f->ts.kind = (kind == NULL)
412 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
413 f->value.function.name
414 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
415 gfc_type_letter (a->ts.type), a->ts.kind);
420 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
422 gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d");
427 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
429 f->ts.type = BT_INTEGER;
430 f->ts.kind = gfc_default_integer_kind;
431 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
436 gfc_resolve_chdir_sub (gfc_code *c)
441 if (c->ext.actual->next->expr != NULL)
442 kind = c->ext.actual->next->expr->ts.kind;
444 kind = gfc_default_integer_kind;
446 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
447 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
452 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
453 gfc_expr *mode ATTRIBUTE_UNUSED)
455 f->ts.type = BT_INTEGER;
456 f->ts.kind = gfc_c_int_kind;
457 f->value.function.name = PREFIX ("chmod_func");
462 gfc_resolve_chmod_sub (gfc_code *c)
467 if (c->ext.actual->next->next->expr != NULL)
468 kind = c->ext.actual->next->next->expr->ts.kind;
470 kind = gfc_default_integer_kind;
472 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
473 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
478 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
480 f->ts.type = BT_COMPLEX;
481 f->ts.kind = (kind == NULL)
482 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
485 f->value.function.name
486 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
487 gfc_type_letter (x->ts.type), x->ts.kind);
489 f->value.function.name
490 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
491 gfc_type_letter (x->ts.type), x->ts.kind,
492 gfc_type_letter (y->ts.type), y->ts.kind);
497 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
499 gfc_resolve_cmplx (f, x, y, gfc_int_expr (gfc_default_double_kind));
504 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
508 if (x->ts.type == BT_INTEGER)
510 if (y->ts.type == BT_INTEGER)
511 kind = gfc_default_real_kind;
517 if (y->ts.type == BT_REAL)
518 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
523 f->ts.type = BT_COMPLEX;
525 f->value.function.name
526 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
527 gfc_type_letter (x->ts.type), x->ts.kind,
528 gfc_type_letter (y->ts.type), y->ts.kind);
533 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
536 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
541 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
544 f->value.function.name
545 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
550 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
553 f->value.function.name
554 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
559 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
561 f->ts.type = BT_INTEGER;
563 f->ts.kind = mpz_get_si (kind->value.integer);
565 f->ts.kind = gfc_default_integer_kind;
569 f->rank = mask->rank - 1;
570 gfc_resolve_dim_arg (dim);
571 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
574 resolve_mask_arg (mask);
576 f->value.function.name
577 = gfc_get_string (PREFIX ("count_%d_%c"), f->ts.kind,
578 gfc_type_letter (mask->ts.type));
583 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
588 if (array->ts.type == BT_CHARACTER && array->ref)
589 gfc_resolve_substring_charlen (array);
592 f->rank = array->rank;
593 f->shape = gfc_copy_shape (array->shape, array->rank);
600 /* If dim kind is greater than default integer we need to use the larger. */
601 m = gfc_default_integer_kind;
603 m = m < dim->ts.kind ? dim->ts.kind : m;
605 /* Convert shift to at least m, so we don't need
606 kind=1 and kind=2 versions of the library functions. */
607 if (shift->ts.kind < m)
611 ts.type = BT_INTEGER;
613 gfc_convert_type_warn (shift, &ts, 2, 0);
618 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
619 && dim->symtree->n.sym->attr.optional)
621 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
622 dim->representation.length = shift->ts.kind;
626 gfc_resolve_dim_arg (dim);
627 /* Convert dim to shift's kind to reduce variations. */
628 if (dim->ts.kind != shift->ts.kind)
629 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
633 f->value.function.name
634 = gfc_get_string (PREFIX ("cshift%d_%d%s"), n, shift->ts.kind,
635 array->ts.type == BT_CHARACTER ? "_char" : "");
640 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
645 f->ts.type = BT_CHARACTER;
646 f->ts.kind = gfc_default_character_kind;
648 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
649 if (time->ts.kind != 8)
651 ts.type = BT_INTEGER;
655 gfc_convert_type (time, &ts, 2);
658 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
663 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
665 f->ts.type = BT_REAL;
666 f->ts.kind = gfc_default_double_kind;
667 f->value.function.name
668 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
673 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
675 f->ts.type = a->ts.type;
677 f->ts.kind = gfc_kind_max (a,p);
679 f->ts.kind = a->ts.kind;
681 if (p != NULL && a->ts.kind != p->ts.kind)
683 if (a->ts.kind == gfc_kind_max (a,p))
684 gfc_convert_type (p, &a->ts, 2);
686 gfc_convert_type (a, &p->ts, 2);
689 f->value.function.name
690 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
695 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
699 temp.expr_type = EXPR_OP;
700 gfc_clear_ts (&temp.ts);
701 temp.value.op.operator = INTRINSIC_NONE;
702 temp.value.op.op1 = a;
703 temp.value.op.op2 = b;
704 gfc_type_convert_binary (&temp);
706 f->value.function.name
707 = gfc_get_string (PREFIX ("dot_product_%c%d"),
708 gfc_type_letter (f->ts.type), f->ts.kind);
713 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
714 gfc_expr *b ATTRIBUTE_UNUSED)
716 f->ts.kind = gfc_default_double_kind;
717 f->ts.type = BT_REAL;
718 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
723 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
724 gfc_expr *boundary, gfc_expr *dim)
728 if (array->ts.type == BT_CHARACTER && array->ref)
729 gfc_resolve_substring_charlen (array);
732 f->rank = array->rank;
733 f->shape = gfc_copy_shape (array->shape, array->rank);
738 if (boundary && boundary->rank > 0)
741 /* If dim kind is greater than default integer we need to use the larger. */
742 m = gfc_default_integer_kind;
744 m = m < dim->ts.kind ? dim->ts.kind : m;
746 /* Convert shift to at least m, so we don't need
747 kind=1 and kind=2 versions of the library functions. */
748 if (shift->ts.kind < m)
752 ts.type = BT_INTEGER;
754 gfc_convert_type_warn (shift, &ts, 2, 0);
759 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
760 && dim->symtree->n.sym->attr.optional)
762 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
763 dim->representation.length = shift->ts.kind;
767 gfc_resolve_dim_arg (dim);
768 /* Convert dim to shift's kind to reduce variations. */
769 if (dim->ts.kind != shift->ts.kind)
770 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
774 f->value.function.name
775 = gfc_get_string (PREFIX ("eoshift%d_%d%s"), n, shift->ts.kind,
776 array->ts.type == BT_CHARACTER ? "_char" : "");
781 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
784 f->value.function.name
785 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
790 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
792 f->ts.type = BT_INTEGER;
793 f->ts.kind = gfc_default_integer_kind;
794 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
799 gfc_resolve_fdate (gfc_expr *f)
801 f->ts.type = BT_CHARACTER;
802 f->ts.kind = gfc_default_character_kind;
803 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
808 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
810 f->ts.type = BT_INTEGER;
811 f->ts.kind = (kind == NULL)
812 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
813 f->value.function.name
814 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
815 gfc_type_letter (a->ts.type), a->ts.kind);
820 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
822 f->ts.type = BT_INTEGER;
823 f->ts.kind = gfc_default_integer_kind;
824 if (n->ts.kind != f->ts.kind)
825 gfc_convert_type (n, &f->ts, 2);
826 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
831 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
834 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
838 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
841 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
844 f->value.function.name = gfc_get_string ("<intrinsic>");
849 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
852 f->value.function.name
853 = gfc_get_string ("__gamma_%d", x->ts.kind);
858 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
860 f->ts.type = BT_INTEGER;
862 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
867 gfc_resolve_getgid (gfc_expr *f)
869 f->ts.type = BT_INTEGER;
871 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
876 gfc_resolve_getpid (gfc_expr *f)
878 f->ts.type = BT_INTEGER;
880 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
885 gfc_resolve_getuid (gfc_expr *f)
887 f->ts.type = BT_INTEGER;
889 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
894 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
896 f->ts.type = BT_INTEGER;
898 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
903 gfc_resolve_hypot (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
906 f->value.function.name = gfc_get_string ("__hypot_r%d", x->ts.kind);
911 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
913 /* If the kind of i and j are different, then g77 cross-promoted the
914 kinds to the largest value. The Fortran 95 standard requires the
916 if (i->ts.kind != j->ts.kind)
918 if (i->ts.kind == gfc_kind_max (i, j))
919 gfc_convert_type (j, &i->ts, 2);
921 gfc_convert_type (i, &j->ts, 2);
925 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
930 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
933 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
938 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
939 gfc_expr *len ATTRIBUTE_UNUSED)
942 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
947 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
950 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
955 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
957 f->ts.type = BT_INTEGER;
959 f->ts.kind = mpz_get_si (kind->value.integer);
961 f->ts.kind = gfc_default_integer_kind;
962 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
967 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
969 f->ts.type = BT_INTEGER;
971 f->ts.kind = mpz_get_si (kind->value.integer);
973 f->ts.kind = gfc_default_integer_kind;
974 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
979 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
981 gfc_resolve_nint (f, a, NULL);
986 gfc_resolve_ierrno (gfc_expr *f)
988 f->ts.type = BT_INTEGER;
989 f->ts.kind = gfc_default_integer_kind;
990 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
995 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
997 /* If the kind of i and j are different, then g77 cross-promoted the
998 kinds to the largest value. The Fortran 95 standard requires the
1000 if (i->ts.kind != j->ts.kind)
1002 if (i->ts.kind == gfc_kind_max (i, j))
1003 gfc_convert_type (j, &i->ts, 2);
1005 gfc_convert_type (i, &j->ts, 2);
1009 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
1014 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1016 /* If the kind of i and j are different, then g77 cross-promoted the
1017 kinds to the largest value. The Fortran 95 standard requires the
1019 if (i->ts.kind != j->ts.kind)
1021 if (i->ts.kind == gfc_kind_max (i, j))
1022 gfc_convert_type (j, &i->ts, 2);
1024 gfc_convert_type (i, &j->ts, 2);
1028 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
1033 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
1034 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
1040 f->ts.type = BT_INTEGER;
1042 f->ts.kind = mpz_get_si (kind->value.integer);
1044 f->ts.kind = gfc_default_integer_kind;
1046 if (back && back->ts.kind != gfc_default_integer_kind)
1048 ts.type = BT_LOGICAL;
1049 ts.kind = gfc_default_integer_kind;
1052 gfc_convert_type (back, &ts, 2);
1055 f->value.function.name
1056 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
1061 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1063 f->ts.type = BT_INTEGER;
1064 f->ts.kind = (kind == NULL)
1065 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1066 f->value.function.name
1067 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1068 gfc_type_letter (a->ts.type), a->ts.kind);
1073 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1075 f->ts.type = BT_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_int8 (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_long (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_isatty (gfc_expr *f, gfc_expr *u)
1111 f->ts.type = BT_LOGICAL;
1112 f->ts.kind = gfc_default_integer_kind;
1113 if (u->ts.kind != gfc_c_int_kind)
1115 ts.type = BT_INTEGER;
1116 ts.kind = gfc_c_int_kind;
1119 gfc_convert_type (u, &ts, 2);
1122 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1127 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1130 f->value.function.name
1131 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1136 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1139 f->value.function.name
1140 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1145 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1148 f->value.function.name
1149 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1154 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1158 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1161 f->value.function.name
1162 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1167 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1168 gfc_expr *s ATTRIBUTE_UNUSED)
1170 f->ts.type = BT_INTEGER;
1171 f->ts.kind = gfc_default_integer_kind;
1172 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1177 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1179 static char lbound[] = "__lbound";
1181 f->ts.type = BT_INTEGER;
1183 f->ts.kind = mpz_get_si (kind->value.integer);
1185 f->ts.kind = gfc_default_integer_kind;
1190 f->shape = gfc_get_shape (1);
1191 mpz_init_set_ui (f->shape[0], array->rank);
1194 f->value.function.name = lbound;
1199 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1201 f->ts.type = BT_INTEGER;
1203 f->ts.kind = mpz_get_si (kind->value.integer);
1205 f->ts.kind = gfc_default_integer_kind;
1206 f->value.function.name
1207 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1208 gfc_default_integer_kind);
1213 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1215 f->ts.type = BT_INTEGER;
1217 f->ts.kind = mpz_get_si (kind->value.integer);
1219 f->ts.kind = gfc_default_integer_kind;
1220 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1225 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1228 f->value.function.name
1229 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1234 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1235 gfc_expr *p2 ATTRIBUTE_UNUSED)
1237 f->ts.type = BT_INTEGER;
1238 f->ts.kind = gfc_default_integer_kind;
1239 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1244 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1246 f->ts.type= BT_INTEGER;
1247 f->ts.kind = gfc_index_integer_kind;
1248 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1253 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1256 f->value.function.name
1257 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1262 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1265 f->value.function.name
1266 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1272 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1274 f->ts.type = BT_LOGICAL;
1275 f->ts.kind = (kind == NULL)
1276 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1279 f->value.function.name
1280 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1281 gfc_type_letter (a->ts.type), a->ts.kind);
1286 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1288 if (size->ts.kind < gfc_index_integer_kind)
1293 ts.type = BT_INTEGER;
1294 ts.kind = gfc_index_integer_kind;
1295 gfc_convert_type_warn (size, &ts, 2, 0);
1298 f->ts.type = BT_INTEGER;
1299 f->ts.kind = gfc_index_integer_kind;
1300 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1305 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1309 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1311 f->ts.type = BT_LOGICAL;
1312 f->ts.kind = gfc_default_logical_kind;
1316 temp.expr_type = EXPR_OP;
1317 gfc_clear_ts (&temp.ts);
1318 temp.value.op.operator = INTRINSIC_NONE;
1319 temp.value.op.op1 = a;
1320 temp.value.op.op2 = b;
1321 gfc_type_convert_binary (&temp);
1325 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1327 f->value.function.name
1328 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1334 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1336 gfc_actual_arglist *a;
1338 f->ts.type = args->expr->ts.type;
1339 f->ts.kind = args->expr->ts.kind;
1340 /* Find the largest type kind. */
1341 for (a = args->next; a; a = a->next)
1343 if (a->expr->ts.kind > f->ts.kind)
1344 f->ts.kind = a->expr->ts.kind;
1347 /* Convert all parameters to the required kind. */
1348 for (a = args; a; a = a->next)
1350 if (a->expr->ts.kind != f->ts.kind)
1351 gfc_convert_type (a->expr, &f->ts, 2);
1354 f->value.function.name
1355 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1360 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1362 gfc_resolve_minmax ("__max_%c%d", f, args);
1367 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1373 f->ts.type = BT_INTEGER;
1374 f->ts.kind = gfc_default_integer_kind;
1379 f->shape = gfc_get_shape (1);
1380 mpz_init_set_si (f->shape[0], array->rank);
1384 f->rank = array->rank - 1;
1385 gfc_resolve_dim_arg (dim);
1386 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1388 idim = (int) mpz_get_si (dim->value.integer);
1389 f->shape = gfc_get_shape (f->rank);
1390 for (i = 0, j = 0; i < f->rank; i++, j++)
1392 if (i == (idim - 1))
1394 mpz_init_set (f->shape[i], array->shape[j]);
1401 if (mask->rank == 0)
1406 resolve_mask_arg (mask);
1411 f->value.function.name
1412 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1413 gfc_type_letter (array->ts.type), array->ts.kind);
1418 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1428 f->rank = array->rank - 1;
1429 gfc_resolve_dim_arg (dim);
1431 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1433 idim = (int) mpz_get_si (dim->value.integer);
1434 f->shape = gfc_get_shape (f->rank);
1435 for (i = 0, j = 0; i < f->rank; i++, j++)
1437 if (i == (idim - 1))
1439 mpz_init_set (f->shape[i], array->shape[j]);
1446 if (mask->rank == 0)
1451 resolve_mask_arg (mask);
1456 f->value.function.name
1457 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1458 gfc_type_letter (array->ts.type), array->ts.kind);
1463 gfc_resolve_mclock (gfc_expr *f)
1465 f->ts.type = BT_INTEGER;
1467 f->value.function.name = PREFIX ("mclock");
1472 gfc_resolve_mclock8 (gfc_expr *f)
1474 f->ts.type = BT_INTEGER;
1476 f->value.function.name = PREFIX ("mclock8");
1481 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1482 gfc_expr *fsource ATTRIBUTE_UNUSED,
1483 gfc_expr *mask ATTRIBUTE_UNUSED)
1485 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1486 gfc_resolve_substring_charlen (tsource);
1488 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1489 gfc_resolve_substring_charlen (fsource);
1491 if (tsource->ts.type == BT_CHARACTER)
1492 check_charlen_present (tsource);
1494 f->ts = tsource->ts;
1495 f->value.function.name
1496 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1502 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1504 gfc_resolve_minmax ("__min_%c%d", f, args);
1509 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1515 f->ts.type = BT_INTEGER;
1516 f->ts.kind = gfc_default_integer_kind;
1521 f->shape = gfc_get_shape (1);
1522 mpz_init_set_si (f->shape[0], array->rank);
1526 f->rank = array->rank - 1;
1527 gfc_resolve_dim_arg (dim);
1528 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1530 idim = (int) mpz_get_si (dim->value.integer);
1531 f->shape = gfc_get_shape (f->rank);
1532 for (i = 0, j = 0; i < f->rank; i++, j++)
1534 if (i == (idim - 1))
1536 mpz_init_set (f->shape[i], array->shape[j]);
1543 if (mask->rank == 0)
1548 resolve_mask_arg (mask);
1553 f->value.function.name
1554 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1555 gfc_type_letter (array->ts.type), array->ts.kind);
1560 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1570 f->rank = array->rank - 1;
1571 gfc_resolve_dim_arg (dim);
1573 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1575 idim = (int) mpz_get_si (dim->value.integer);
1576 f->shape = gfc_get_shape (f->rank);
1577 for (i = 0, j = 0; i < f->rank; i++, j++)
1579 if (i == (idim - 1))
1581 mpz_init_set (f->shape[i], array->shape[j]);
1588 if (mask->rank == 0)
1593 resolve_mask_arg (mask);
1598 f->value.function.name
1599 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1600 gfc_type_letter (array->ts.type), array->ts.kind);
1605 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1607 f->ts.type = a->ts.type;
1609 f->ts.kind = gfc_kind_max (a,p);
1611 f->ts.kind = a->ts.kind;
1613 if (p != NULL && a->ts.kind != p->ts.kind)
1615 if (a->ts.kind == gfc_kind_max (a,p))
1616 gfc_convert_type (p, &a->ts, 2);
1618 gfc_convert_type (a, &p->ts, 2);
1621 f->value.function.name
1622 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1627 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1629 f->ts.type = a->ts.type;
1631 f->ts.kind = gfc_kind_max (a,p);
1633 f->ts.kind = a->ts.kind;
1635 if (p != NULL && a->ts.kind != p->ts.kind)
1637 if (a->ts.kind == gfc_kind_max (a,p))
1638 gfc_convert_type (p, &a->ts, 2);
1640 gfc_convert_type (a, &p->ts, 2);
1643 f->value.function.name
1644 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1649 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1651 if (p->ts.kind != a->ts.kind)
1652 gfc_convert_type (p, &a->ts, 2);
1655 f->value.function.name
1656 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1661 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1663 f->ts.type = BT_INTEGER;
1664 f->ts.kind = (kind == NULL)
1665 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1666 f->value.function.name
1667 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1672 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1675 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1680 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1682 f->ts.type = i->ts.type;
1683 f->ts.kind = gfc_kind_max (i, j);
1685 if (i->ts.kind != j->ts.kind)
1687 if (i->ts.kind == gfc_kind_max (i, j))
1688 gfc_convert_type (j, &i->ts, 2);
1690 gfc_convert_type (i, &j->ts, 2);
1693 f->value.function.name
1694 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1699 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1700 gfc_expr *vector ATTRIBUTE_UNUSED)
1702 if (array->ts.type == BT_CHARACTER && array->ref)
1703 gfc_resolve_substring_charlen (array);
1708 resolve_mask_arg (mask);
1710 if (mask->rank != 0)
1712 if (array->ts.type == BT_CHARACTER)
1713 f->value.function.name
1714 = array->ts.kind == 1 ? PREFIX ("pack_char")
1716 (PREFIX ("pack_char%d"),
1719 f->value.function.name = PREFIX ("pack");
1723 if (array->ts.type == BT_CHARACTER)
1724 f->value.function.name
1725 = array->ts.kind == 1 ? PREFIX ("pack_s_char")
1727 (PREFIX ("pack_s_char%d"),
1730 f->value.function.name = PREFIX ("pack_s");
1736 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1745 f->rank = array->rank - 1;
1746 gfc_resolve_dim_arg (dim);
1751 if (mask->rank == 0)
1756 resolve_mask_arg (mask);
1761 f->value.function.name
1762 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1763 gfc_type_letter (array->ts.type), array->ts.kind);
1768 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1770 f->ts.type = BT_REAL;
1773 f->ts.kind = mpz_get_si (kind->value.integer);
1775 f->ts.kind = (a->ts.type == BT_COMPLEX)
1776 ? a->ts.kind : gfc_default_real_kind;
1778 f->value.function.name
1779 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1780 gfc_type_letter (a->ts.type), a->ts.kind);
1785 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1787 f->ts.type = BT_REAL;
1788 f->ts.kind = a->ts.kind;
1789 f->value.function.name
1790 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1791 gfc_type_letter (a->ts.type), a->ts.kind);
1796 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1797 gfc_expr *p2 ATTRIBUTE_UNUSED)
1799 f->ts.type = BT_INTEGER;
1800 f->ts.kind = gfc_default_integer_kind;
1801 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1806 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
1807 gfc_expr *ncopies ATTRIBUTE_UNUSED)
1809 f->ts.type = BT_CHARACTER;
1810 f->ts.kind = string->ts.kind;
1811 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
1816 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
1817 gfc_expr *pad ATTRIBUTE_UNUSED,
1818 gfc_expr *order ATTRIBUTE_UNUSED)
1824 if (source->ts.type == BT_CHARACTER && source->ref)
1825 gfc_resolve_substring_charlen (source);
1829 gfc_array_size (shape, &rank);
1830 f->rank = mpz_get_si (rank);
1832 switch (source->ts.type)
1839 kind = source->ts.kind;
1853 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
1854 f->value.function.name
1855 = gfc_get_string (PREFIX ("reshape_%c%d"),
1856 gfc_type_letter (source->ts.type),
1858 else if (source->ts.type == BT_CHARACTER)
1859 f->value.function.name = gfc_get_string (PREFIX ("reshape_char%d"),
1862 f->value.function.name
1863 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
1867 f->value.function.name = (source->ts.type == BT_CHARACTER
1868 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1872 /* TODO: Make this work with a constant ORDER parameter. */
1873 if (shape->expr_type == EXPR_ARRAY
1874 && gfc_is_constant_expr (shape)
1878 f->shape = gfc_get_shape (f->rank);
1879 c = shape->value.constructor;
1880 for (i = 0; i < f->rank; i++)
1882 mpz_init_set (f->shape[i], c->expr->value.integer);
1887 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
1888 so many runtime variations. */
1889 if (shape->ts.kind != gfc_index_integer_kind)
1891 gfc_typespec ts = shape->ts;
1892 ts.kind = gfc_index_integer_kind;
1893 gfc_convert_type_warn (shape, &ts, 2, 0);
1895 if (order && order->ts.kind != gfc_index_integer_kind)
1896 gfc_convert_type_warn (order, &shape->ts, 2, 0);
1901 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
1904 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
1909 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED)
1912 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
1917 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
1918 gfc_expr *set ATTRIBUTE_UNUSED,
1919 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
1921 f->ts.type = BT_INTEGER;
1923 f->ts.kind = mpz_get_si (kind->value.integer);
1925 f->ts.kind = gfc_default_integer_kind;
1926 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
1931 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
1934 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
1939 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x,
1940 gfc_expr *i ATTRIBUTE_UNUSED)
1943 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
1948 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
1950 f->ts.type = BT_INTEGER;
1951 f->ts.kind = gfc_default_integer_kind;
1953 f->shape = gfc_get_shape (1);
1954 mpz_init_set_ui (f->shape[0], array->rank);
1955 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
1960 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
1963 f->value.function.name
1964 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
1969 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
1971 f->ts.type = BT_INTEGER;
1972 f->ts.kind = gfc_c_int_kind;
1974 /* handler can be either BT_INTEGER or BT_PROCEDURE */
1975 if (handler->ts.type == BT_INTEGER)
1977 if (handler->ts.kind != gfc_c_int_kind)
1978 gfc_convert_type (handler, &f->ts, 2);
1979 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
1982 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
1984 if (number->ts.kind != gfc_c_int_kind)
1985 gfc_convert_type (number, &f->ts, 2);
1990 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
1993 f->value.function.name
1994 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1999 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
2002 f->value.function.name
2003 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2008 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2009 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
2011 f->ts.type = BT_INTEGER;
2013 f->ts.kind = mpz_get_si (kind->value.integer);
2015 f->ts.kind = gfc_default_integer_kind;
2020 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
2023 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
2028 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2031 if (source->ts.type == BT_CHARACTER && source->ref)
2032 gfc_resolve_substring_charlen (source);
2034 if (source->ts.type == BT_CHARACTER)
2035 check_charlen_present (source);
2038 f->rank = source->rank + 1;
2039 if (source->rank == 0)
2041 if (source->ts.type == BT_CHARACTER)
2042 f->value.function.name
2043 = source->ts.kind == 1 ? PREFIX ("spread_char_scalar")
2045 (PREFIX ("spread_char%d_scalar"),
2048 f->value.function.name = PREFIX ("spread_scalar");
2052 if (source->ts.type == BT_CHARACTER)
2053 f->value.function.name
2054 = source->ts.kind == 1 ? PREFIX ("spread_char")
2056 (PREFIX ("spread_char%d"),
2059 f->value.function.name = PREFIX ("spread");
2062 if (dim && gfc_is_constant_expr (dim)
2063 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2066 idim = mpz_get_ui (dim->value.integer);
2067 f->shape = gfc_get_shape (f->rank);
2068 for (i = 0; i < (idim - 1); i++)
2069 mpz_init_set (f->shape[i], source->shape[i]);
2071 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2073 for (i = idim; i < f->rank ; i++)
2074 mpz_init_set (f->shape[i], source->shape[i-1]);
2078 gfc_resolve_dim_arg (dim);
2079 gfc_resolve_index (ncopies, 1);
2084 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2087 f->value.function.name
2088 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2092 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2095 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2096 gfc_expr *a ATTRIBUTE_UNUSED)
2098 f->ts.type = BT_INTEGER;
2099 f->ts.kind = gfc_default_integer_kind;
2100 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2105 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2106 gfc_expr *a ATTRIBUTE_UNUSED)
2108 f->ts.type = BT_INTEGER;
2109 f->ts.kind = gfc_default_integer_kind;
2110 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2115 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2117 f->ts.type = BT_INTEGER;
2118 f->ts.kind = gfc_default_integer_kind;
2119 if (n->ts.kind != f->ts.kind)
2120 gfc_convert_type (n, &f->ts, 2);
2122 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2127 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2132 f->ts.type = BT_INTEGER;
2133 f->ts.kind = gfc_c_int_kind;
2134 if (u->ts.kind != gfc_c_int_kind)
2136 ts.type = BT_INTEGER;
2137 ts.kind = gfc_c_int_kind;
2140 gfc_convert_type (u, &ts, 2);
2143 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2148 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2150 f->ts.type = BT_INTEGER;
2151 f->ts.kind = gfc_c_int_kind;
2152 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2157 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2162 f->ts.type = BT_INTEGER;
2163 f->ts.kind = gfc_c_int_kind;
2164 if (u->ts.kind != gfc_c_int_kind)
2166 ts.type = BT_INTEGER;
2167 ts.kind = gfc_c_int_kind;
2170 gfc_convert_type (u, &ts, 2);
2173 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2178 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2180 f->ts.type = BT_INTEGER;
2181 f->ts.kind = gfc_c_int_kind;
2182 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2187 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2192 f->ts.type = BT_INTEGER;
2193 f->ts.kind = gfc_index_integer_kind;
2194 if (u->ts.kind != gfc_c_int_kind)
2196 ts.type = BT_INTEGER;
2197 ts.kind = gfc_c_int_kind;
2200 gfc_convert_type (u, &ts, 2);
2203 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2208 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2216 if (mask->rank == 0)
2221 resolve_mask_arg (mask);
2228 f->rank = array->rank - 1;
2229 gfc_resolve_dim_arg (dim);
2232 f->value.function.name
2233 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2234 gfc_type_letter (array->ts.type), array->ts.kind);
2239 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2240 gfc_expr *p2 ATTRIBUTE_UNUSED)
2242 f->ts.type = BT_INTEGER;
2243 f->ts.kind = gfc_default_integer_kind;
2244 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2248 /* Resolve the g77 compatibility function SYSTEM. */
2251 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2253 f->ts.type = BT_INTEGER;
2255 f->value.function.name = gfc_get_string (PREFIX ("system"));
2260 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2263 f->value.function.name
2264 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2269 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2272 f->value.function.name
2273 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2278 gfc_resolve_time (gfc_expr *f)
2280 f->ts.type = BT_INTEGER;
2282 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2287 gfc_resolve_time8 (gfc_expr *f)
2289 f->ts.type = BT_INTEGER;
2291 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2296 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2297 gfc_expr *mold, gfc_expr *size)
2299 /* TODO: Make this do something meaningful. */
2300 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2302 if (mold->ts.type == BT_CHARACTER && !mold->ts.cl->length
2303 && !(mold->expr_type == EXPR_VARIABLE && mold->symtree->n.sym->attr.dummy))
2304 mold->ts.cl->length = gfc_int_expr (mold->value.character.length);
2308 if (size == NULL && mold->rank == 0)
2311 f->value.function.name = transfer0;
2316 f->value.function.name = transfer1;
2317 if (size && gfc_is_constant_expr (size))
2319 f->shape = gfc_get_shape (1);
2320 mpz_init_set (f->shape[0], size->value.integer);
2327 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2330 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2331 gfc_resolve_substring_charlen (matrix);
2337 f->shape = gfc_get_shape (2);
2338 mpz_init_set (f->shape[0], matrix->shape[1]);
2339 mpz_init_set (f->shape[1], matrix->shape[0]);
2342 switch (matrix->ts.kind)
2348 switch (matrix->ts.type)
2352 f->value.function.name
2353 = gfc_get_string (PREFIX ("transpose_%c%d"),
2354 gfc_type_letter (matrix->ts.type),
2360 /* Use the integer routines for real and logical cases. This
2361 assumes they all have the same alignment requirements. */
2362 f->value.function.name
2363 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2367 if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4)
2368 f->value.function.name = PREFIX ("transpose_char4");
2370 f->value.function.name = PREFIX ("transpose");
2376 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2377 ? PREFIX ("transpose_char")
2378 : PREFIX ("transpose"));
2385 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2387 f->ts.type = BT_CHARACTER;
2388 f->ts.kind = string->ts.kind;
2389 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2394 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2396 static char ubound[] = "__ubound";
2398 f->ts.type = BT_INTEGER;
2400 f->ts.kind = mpz_get_si (kind->value.integer);
2402 f->ts.kind = gfc_default_integer_kind;
2407 f->shape = gfc_get_shape (1);
2408 mpz_init_set_ui (f->shape[0], array->rank);
2411 f->value.function.name = ubound;
2415 /* Resolve the g77 compatibility function UMASK. */
2418 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2420 f->ts.type = BT_INTEGER;
2421 f->ts.kind = n->ts.kind;
2422 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2426 /* Resolve the g77 compatibility function UNLINK. */
2429 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2431 f->ts.type = BT_INTEGER;
2433 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2438 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2443 f->ts.type = BT_CHARACTER;
2444 f->ts.kind = gfc_default_character_kind;
2446 if (unit->ts.kind != gfc_c_int_kind)
2448 ts.type = BT_INTEGER;
2449 ts.kind = gfc_c_int_kind;
2452 gfc_convert_type (unit, &ts, 2);
2455 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2460 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2461 gfc_expr *field ATTRIBUTE_UNUSED)
2463 if (vector->ts.type == BT_CHARACTER && vector->ref)
2464 gfc_resolve_substring_charlen (vector);
2467 f->rank = mask->rank;
2468 resolve_mask_arg (mask);
2470 if (vector->ts.type == BT_CHARACTER)
2472 if (vector->ts.kind == 1)
2473 f->value.function.name
2474 = gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0);
2476 f->value.function.name
2477 = gfc_get_string (PREFIX ("unpack%d_char%d"),
2478 field->rank > 0 ? 1 : 0, vector->ts.kind);
2481 f->value.function.name
2482 = gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0);
2487 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2488 gfc_expr *set ATTRIBUTE_UNUSED,
2489 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2491 f->ts.type = BT_INTEGER;
2493 f->ts.kind = mpz_get_si (kind->value.integer);
2495 f->ts.kind = gfc_default_integer_kind;
2496 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2501 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2503 f->ts.type = i->ts.type;
2504 f->ts.kind = gfc_kind_max (i, j);
2506 if (i->ts.kind != j->ts.kind)
2508 if (i->ts.kind == gfc_kind_max (i, j))
2509 gfc_convert_type (j, &i->ts, 2);
2511 gfc_convert_type (i, &j->ts, 2);
2514 f->value.function.name
2515 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2519 /* Intrinsic subroutine resolution. */
2522 gfc_resolve_alarm_sub (gfc_code *c)
2525 gfc_expr *seconds, *handler, *status;
2529 seconds = c->ext.actual->expr;
2530 handler = c->ext.actual->next->expr;
2531 status = c->ext.actual->next->next->expr;
2532 ts.type = BT_INTEGER;
2533 ts.kind = gfc_c_int_kind;
2535 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2536 In all cases, the status argument is of default integer kind
2537 (enforced in check.c) so that the function suffix is fixed. */
2538 if (handler->ts.type == BT_INTEGER)
2540 if (handler->ts.kind != gfc_c_int_kind)
2541 gfc_convert_type (handler, &ts, 2);
2542 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2543 gfc_default_integer_kind);
2546 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2547 gfc_default_integer_kind);
2549 if (seconds->ts.kind != gfc_c_int_kind)
2550 gfc_convert_type (seconds, &ts, 2);
2552 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2556 gfc_resolve_cpu_time (gfc_code *c)
2559 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2560 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2565 gfc_resolve_mvbits (gfc_code *c)
2571 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2572 they will be converted so that they fit into a C int. */
2573 ts.type = BT_INTEGER;
2574 ts.kind = gfc_c_int_kind;
2575 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2576 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2577 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2578 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2579 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2580 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2582 /* TO and FROM are guaranteed to have the same kind parameter. */
2583 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2584 c->ext.actual->expr->ts.kind);
2585 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2586 /* Mark as elemental subroutine as this does not happen automatically. */
2587 c->resolved_sym->attr.elemental = 1;
2592 gfc_resolve_random_number (gfc_code *c)
2597 kind = c->ext.actual->expr->ts.kind;
2598 if (c->ext.actual->expr->rank == 0)
2599 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2601 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2603 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2608 gfc_resolve_random_seed (gfc_code *c)
2612 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2613 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2618 gfc_resolve_rename_sub (gfc_code *c)
2623 if (c->ext.actual->next->next->expr != NULL)
2624 kind = c->ext.actual->next->next->expr->ts.kind;
2626 kind = gfc_default_integer_kind;
2628 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2629 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2634 gfc_resolve_kill_sub (gfc_code *c)
2639 if (c->ext.actual->next->next->expr != NULL)
2640 kind = c->ext.actual->next->next->expr->ts.kind;
2642 kind = gfc_default_integer_kind;
2644 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2645 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2650 gfc_resolve_link_sub (gfc_code *c)
2655 if (c->ext.actual->next->next->expr != NULL)
2656 kind = c->ext.actual->next->next->expr->ts.kind;
2658 kind = gfc_default_integer_kind;
2660 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2661 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2666 gfc_resolve_symlnk_sub (gfc_code *c)
2671 if (c->ext.actual->next->next->expr != NULL)
2672 kind = c->ext.actual->next->next->expr->ts.kind;
2674 kind = gfc_default_integer_kind;
2676 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2677 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2681 /* G77 compatibility subroutines dtime() and etime(). */
2684 gfc_resolve_dtime_sub (gfc_code *c)
2687 name = gfc_get_string (PREFIX ("dtime_sub"));
2688 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2692 gfc_resolve_etime_sub (gfc_code *c)
2695 name = gfc_get_string (PREFIX ("etime_sub"));
2696 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2700 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2703 gfc_resolve_itime (gfc_code *c)
2706 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2707 gfc_default_integer_kind));
2711 gfc_resolve_idate (gfc_code *c)
2714 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2715 gfc_default_integer_kind));
2719 gfc_resolve_ltime (gfc_code *c)
2722 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2723 gfc_default_integer_kind));
2727 gfc_resolve_gmtime (gfc_code *c)
2730 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2731 gfc_default_integer_kind));
2735 /* G77 compatibility subroutine second(). */
2738 gfc_resolve_second_sub (gfc_code *c)
2741 name = gfc_get_string (PREFIX ("second_sub"));
2742 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2747 gfc_resolve_sleep_sub (gfc_code *c)
2752 if (c->ext.actual->expr != NULL)
2753 kind = c->ext.actual->expr->ts.kind;
2755 kind = gfc_default_integer_kind;
2757 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2758 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2762 /* G77 compatibility function srand(). */
2765 gfc_resolve_srand (gfc_code *c)
2768 name = gfc_get_string (PREFIX ("srand"));
2769 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2773 /* Resolve the getarg intrinsic subroutine. */
2776 gfc_resolve_getarg (gfc_code *c)
2780 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
2785 ts.type = BT_INTEGER;
2786 ts.kind = gfc_default_integer_kind;
2788 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2791 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
2792 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2796 /* Resolve the getcwd intrinsic subroutine. */
2799 gfc_resolve_getcwd_sub (gfc_code *c)
2804 if (c->ext.actual->next->expr != NULL)
2805 kind = c->ext.actual->next->expr->ts.kind;
2807 kind = gfc_default_integer_kind;
2809 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2810 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2814 /* Resolve the get_command intrinsic subroutine. */
2817 gfc_resolve_get_command (gfc_code *c)
2821 kind = gfc_default_integer_kind;
2822 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2823 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2827 /* Resolve the get_command_argument intrinsic subroutine. */
2830 gfc_resolve_get_command_argument (gfc_code *c)
2834 kind = gfc_default_integer_kind;
2835 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2836 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2840 /* Resolve the get_environment_variable intrinsic subroutine. */
2843 gfc_resolve_get_environment_variable (gfc_code *code)
2847 kind = gfc_default_integer_kind;
2848 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2849 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2854 gfc_resolve_signal_sub (gfc_code *c)
2857 gfc_expr *number, *handler, *status;
2861 number = c->ext.actual->expr;
2862 handler = c->ext.actual->next->expr;
2863 status = c->ext.actual->next->next->expr;
2864 ts.type = BT_INTEGER;
2865 ts.kind = gfc_c_int_kind;
2867 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2868 if (handler->ts.type == BT_INTEGER)
2870 if (handler->ts.kind != gfc_c_int_kind)
2871 gfc_convert_type (handler, &ts, 2);
2872 name = gfc_get_string (PREFIX ("signal_sub_int"));
2875 name = gfc_get_string (PREFIX ("signal_sub"));
2877 if (number->ts.kind != gfc_c_int_kind)
2878 gfc_convert_type (number, &ts, 2);
2879 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2880 gfc_convert_type (status, &ts, 2);
2882 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2886 /* Resolve the SYSTEM intrinsic subroutine. */
2889 gfc_resolve_system_sub (gfc_code *c)
2892 name = gfc_get_string (PREFIX ("system_sub"));
2893 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2897 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2900 gfc_resolve_system_clock (gfc_code *c)
2905 if (c->ext.actual->expr != NULL)
2906 kind = c->ext.actual->expr->ts.kind;
2907 else if (c->ext.actual->next->expr != NULL)
2908 kind = c->ext.actual->next->expr->ts.kind;
2909 else if (c->ext.actual->next->next->expr != NULL)
2910 kind = c->ext.actual->next->next->expr->ts.kind;
2912 kind = gfc_default_integer_kind;
2914 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
2915 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2919 /* Resolve the EXIT intrinsic subroutine. */
2922 gfc_resolve_exit (gfc_code *c)
2929 /* The STATUS argument has to be of default kind. If it is not,
2931 ts.type = BT_INTEGER;
2932 ts.kind = gfc_default_integer_kind;
2933 n = c->ext.actual->expr;
2934 if (n != NULL && n->ts.kind != ts.kind)
2935 gfc_convert_type (n, &ts, 2);
2937 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
2938 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2942 /* Resolve the FLUSH intrinsic subroutine. */
2945 gfc_resolve_flush (gfc_code *c)
2952 ts.type = BT_INTEGER;
2953 ts.kind = gfc_default_integer_kind;
2954 n = c->ext.actual->expr;
2955 if (n != NULL && n->ts.kind != ts.kind)
2956 gfc_convert_type (n, &ts, 2);
2958 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
2959 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2964 gfc_resolve_free (gfc_code *c)
2970 ts.type = BT_INTEGER;
2971 ts.kind = gfc_index_integer_kind;
2972 n = c->ext.actual->expr;
2973 if (n->ts.kind != ts.kind)
2974 gfc_convert_type (n, &ts, 2);
2976 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
2981 gfc_resolve_ctime_sub (gfc_code *c)
2986 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
2987 if (c->ext.actual->expr->ts.kind != 8)
2989 ts.type = BT_INTEGER;
2993 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2996 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3001 gfc_resolve_fdate_sub (gfc_code *c)
3003 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3008 gfc_resolve_gerror (gfc_code *c)
3010 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3015 gfc_resolve_getlog (gfc_code *c)
3017 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3022 gfc_resolve_hostnm_sub (gfc_code *c)
3027 if (c->ext.actual->next->expr != NULL)
3028 kind = c->ext.actual->next->expr->ts.kind;
3030 kind = gfc_default_integer_kind;
3032 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3033 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3038 gfc_resolve_perror (gfc_code *c)
3040 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3043 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3046 gfc_resolve_stat_sub (gfc_code *c)
3049 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3050 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3055 gfc_resolve_lstat_sub (gfc_code *c)
3058 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3059 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3064 gfc_resolve_fstat_sub (gfc_code *c)
3070 u = c->ext.actual->expr;
3071 ts = &c->ext.actual->next->expr->ts;
3072 if (u->ts.kind != ts->kind)
3073 gfc_convert_type (u, ts, 2);
3074 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3075 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3080 gfc_resolve_fgetc_sub (gfc_code *c)
3087 u = c->ext.actual->expr;
3088 st = c->ext.actual->next->next->expr;
3090 if (u->ts.kind != gfc_c_int_kind)
3092 ts.type = BT_INTEGER;
3093 ts.kind = gfc_c_int_kind;
3096 gfc_convert_type (u, &ts, 2);
3100 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3102 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3104 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3109 gfc_resolve_fget_sub (gfc_code *c)
3114 st = c->ext.actual->next->expr;
3116 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3118 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3120 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3125 gfc_resolve_fputc_sub (gfc_code *c)
3132 u = c->ext.actual->expr;
3133 st = c->ext.actual->next->next->expr;
3135 if (u->ts.kind != gfc_c_int_kind)
3137 ts.type = BT_INTEGER;
3138 ts.kind = gfc_c_int_kind;
3141 gfc_convert_type (u, &ts, 2);
3145 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3147 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3149 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3154 gfc_resolve_fput_sub (gfc_code *c)
3159 st = c->ext.actual->next->expr;
3161 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3163 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3165 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3170 gfc_resolve_fseek_sub (gfc_code *c)
3179 unit = c->ext.actual->expr;
3180 offset = c->ext.actual->next->expr;
3181 whence = c->ext.actual->next->next->expr;
3182 status = c->ext.actual->next->next->next->expr;
3184 if (unit->ts.kind != gfc_c_int_kind)
3186 ts.type = BT_INTEGER;
3187 ts.kind = gfc_c_int_kind;
3190 gfc_convert_type (unit, &ts, 2);
3193 if (offset->ts.kind != gfc_intio_kind)
3195 ts.type = BT_INTEGER;
3196 ts.kind = gfc_intio_kind;
3199 gfc_convert_type (offset, &ts, 2);
3202 if (whence->ts.kind != gfc_c_int_kind)
3204 ts.type = BT_INTEGER;
3205 ts.kind = gfc_c_int_kind;
3208 gfc_convert_type (whence, &ts, 2);
3211 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3215 gfc_resolve_ftell_sub (gfc_code *c)
3223 unit = c->ext.actual->expr;
3224 offset = c->ext.actual->next->expr;
3226 if (unit->ts.kind != gfc_c_int_kind)
3228 ts.type = BT_INTEGER;
3229 ts.kind = gfc_c_int_kind;
3232 gfc_convert_type (unit, &ts, 2);
3235 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3236 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3241 gfc_resolve_ttynam_sub (gfc_code *c)
3246 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3248 ts.type = BT_INTEGER;
3249 ts.kind = gfc_c_int_kind;
3252 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3255 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3259 /* Resolve the UMASK intrinsic subroutine. */
3262 gfc_resolve_umask_sub (gfc_code *c)
3267 if (c->ext.actual->next->expr != NULL)
3268 kind = c->ext.actual->next->expr->ts.kind;
3270 kind = gfc_default_integer_kind;
3272 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3273 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3276 /* Resolve the UNLINK intrinsic subroutine. */
3279 gfc_resolve_unlink_sub (gfc_code *c)
3284 if (c->ext.actual->next->expr != NULL)
3285 kind = c->ext.actual->next->expr->ts.kind;
3287 kind = gfc_default_integer_kind;
3289 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3290 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);