1 /* Intrinsic function resolution.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 Free Software Foundation, Inc.
5 Contributed by Andy Vaught & Katherine Holcomb
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
24 /* Assign name and types to intrinsic procedures. For functions, the
25 first argument to a resolution function is an expression pointer to
26 the original function node and the rest are pointers to the
27 arguments of the function call. For subroutines, a pointer to the
28 code node is passed. The result type and library subroutine name
29 are generally set according to the function arguments. */
33 #include "coretypes.h"
36 #include "intrinsic.h"
37 #include "constructor.h"
39 /* Given printf-like arguments, return a stable version of the result string.
41 We already have a working, optimized string hashing table in the form of
42 the identifier table. Reusing this table is likely not to be wasted,
43 since if the function name makes it to the gimple output of the frontend,
44 we'll have to create the identifier anyway. */
47 gfc_get_string (const char *format, ...)
53 va_start (ap, format);
54 vsnprintf (temp_name, sizeof (temp_name), format, ap);
56 temp_name[sizeof (temp_name) - 1] = 0;
58 ident = get_identifier (temp_name);
59 return IDENTIFIER_POINTER (ident);
62 /* MERGE and SPREAD need to have source charlen's present for passing
63 to the result expression. */
65 check_charlen_present (gfc_expr *source)
67 if (source->ts.u.cl == NULL)
68 source->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
70 if (source->expr_type == EXPR_CONSTANT)
72 source->ts.u.cl->length
73 = gfc_get_int_expr (gfc_default_integer_kind, NULL,
74 source->value.character.length);
77 else if (source->expr_type == EXPR_ARRAY)
79 gfc_constructor *c = gfc_constructor_first (source->value.constructor);
80 source->ts.u.cl->length
81 = gfc_get_int_expr (gfc_default_integer_kind, NULL,
82 c->expr->value.character.length);
86 /* Helper function for resolving the "mask" argument. */
89 resolve_mask_arg (gfc_expr *mask)
97 /* For the scalar case, coerce the mask to kind=4 unconditionally
98 (because this is the only kind we have a library function
101 if (mask->ts.kind != 4)
103 ts.type = BT_LOGICAL;
105 gfc_convert_type (mask, &ts, 2);
110 /* In the library, we access the mask with a GFC_LOGICAL_1
111 argument. No need to waste memory if we are about to create
112 a temporary array. */
113 if (mask->expr_type == EXPR_OP && mask->ts.kind != 1)
115 ts.type = BT_LOGICAL;
117 gfc_convert_type_warn (mask, &ts, 2, 0);
124 resolve_bound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind,
127 f->ts.type = BT_INTEGER;
129 f->ts.kind = mpz_get_si (kind->value.integer);
131 f->ts.kind = gfc_default_integer_kind;
136 f->shape = gfc_get_shape (1);
137 mpz_init_set_ui (f->shape[0], array->rank);
140 f->value.function.name = xstrdup (name);
143 /********************** Resolution functions **********************/
147 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
150 if (f->ts.type == BT_COMPLEX)
151 f->ts.type = BT_REAL;
153 f->value.function.name
154 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
159 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
160 gfc_expr *mode ATTRIBUTE_UNUSED)
162 f->ts.type = BT_INTEGER;
163 f->ts.kind = gfc_c_int_kind;
164 f->value.function.name = PREFIX ("access_func");
169 gfc_resolve_adjustl (gfc_expr *f, gfc_expr *string)
171 f->ts.type = BT_CHARACTER;
172 f->ts.kind = string->ts.kind;
173 f->value.function.name = gfc_get_string ("__adjustl_s%d", f->ts.kind);
178 gfc_resolve_adjustr (gfc_expr *f, gfc_expr *string)
180 f->ts.type = BT_CHARACTER;
181 f->ts.kind = string->ts.kind;
182 f->value.function.name = gfc_get_string ("__adjustr_s%d", f->ts.kind);
187 gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind,
190 f->ts.type = BT_CHARACTER;
191 f->ts.kind = (kind == NULL)
192 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
193 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
194 f->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
196 f->value.function.name = gfc_get_string (name, f->ts.kind,
197 gfc_type_letter (x->ts.type),
203 gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
205 gfc_resolve_char_achar (f, x, kind, "__achar_%d_%c%d");
210 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
213 f->value.function.name
214 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
219 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
222 f->value.function.name
223 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
229 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
231 f->ts.type = BT_REAL;
232 f->ts.kind = x->ts.kind;
233 f->value.function.name
234 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
240 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
242 f->ts.type = i->ts.type;
243 f->ts.kind = gfc_kind_max (i, j);
245 if (i->ts.kind != j->ts.kind)
247 if (i->ts.kind == gfc_kind_max (i, j))
248 gfc_convert_type (j, &i->ts, 2);
250 gfc_convert_type (i, &j->ts, 2);
253 f->value.function.name
254 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
259 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
264 f->ts.type = a->ts.type;
265 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
267 if (a->ts.kind != f->ts.kind)
269 ts.type = f->ts.type;
270 ts.kind = f->ts.kind;
271 gfc_convert_type (a, &ts, 2);
273 /* The resolved name is only used for specific intrinsics where
274 the return kind is the same as the arg kind. */
275 f->value.function.name
276 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
281 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
283 gfc_resolve_aint (f, a, NULL);
288 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
294 gfc_resolve_dim_arg (dim);
295 f->rank = mask->rank - 1;
296 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
299 f->value.function.name
300 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
306 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
311 f->ts.type = a->ts.type;
312 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
314 if (a->ts.kind != f->ts.kind)
316 ts.type = f->ts.type;
317 ts.kind = f->ts.kind;
318 gfc_convert_type (a, &ts, 2);
321 /* The resolved name is only used for specific intrinsics where
322 the return kind is the same as the arg kind. */
323 f->value.function.name
324 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
330 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
332 gfc_resolve_anint (f, a, NULL);
337 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
343 gfc_resolve_dim_arg (dim);
344 f->rank = mask->rank - 1;
345 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
348 f->value.function.name
349 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
355 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
358 f->value.function.name
359 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
363 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
366 f->value.function.name
367 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
372 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
375 f->value.function.name
376 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
380 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
383 f->value.function.name
384 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
389 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
392 f->value.function.name
393 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
398 /* Resolve the BESYN and BESJN intrinsics. */
401 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
407 if (n->ts.kind != gfc_c_int_kind)
409 ts.type = BT_INTEGER;
410 ts.kind = gfc_c_int_kind;
411 gfc_convert_type (n, &ts, 2);
413 f->value.function.name = gfc_get_string ("<intrinsic>");
418 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
420 f->ts.type = BT_LOGICAL;
421 f->ts.kind = gfc_default_logical_kind;
422 f->value.function.name
423 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
428 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
430 f->ts.type = BT_INTEGER;
431 f->ts.kind = (kind == NULL)
432 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
433 f->value.function.name
434 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
435 gfc_type_letter (a->ts.type), a->ts.kind);
440 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
442 gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d");
447 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
449 f->ts.type = BT_INTEGER;
450 f->ts.kind = gfc_default_integer_kind;
451 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
456 gfc_resolve_chdir_sub (gfc_code *c)
461 if (c->ext.actual->next->expr != NULL)
462 kind = c->ext.actual->next->expr->ts.kind;
464 kind = gfc_default_integer_kind;
466 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
467 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
472 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
473 gfc_expr *mode ATTRIBUTE_UNUSED)
475 f->ts.type = BT_INTEGER;
476 f->ts.kind = gfc_c_int_kind;
477 f->value.function.name = PREFIX ("chmod_func");
482 gfc_resolve_chmod_sub (gfc_code *c)
487 if (c->ext.actual->next->next->expr != NULL)
488 kind = c->ext.actual->next->next->expr->ts.kind;
490 kind = gfc_default_integer_kind;
492 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
493 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
498 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
500 f->ts.type = BT_COMPLEX;
501 f->ts.kind = (kind == NULL)
502 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
505 f->value.function.name
506 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
507 gfc_type_letter (x->ts.type), x->ts.kind);
509 f->value.function.name
510 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
511 gfc_type_letter (x->ts.type), x->ts.kind,
512 gfc_type_letter (y->ts.type), y->ts.kind);
517 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
519 gfc_resolve_cmplx (f, x, y, gfc_get_int_expr (gfc_default_integer_kind, NULL,
520 gfc_default_double_kind));
525 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
529 if (x->ts.type == BT_INTEGER)
531 if (y->ts.type == BT_INTEGER)
532 kind = gfc_default_real_kind;
538 if (y->ts.type == BT_REAL)
539 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
544 f->ts.type = BT_COMPLEX;
546 f->value.function.name
547 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
548 gfc_type_letter (x->ts.type), x->ts.kind,
549 gfc_type_letter (y->ts.type), y->ts.kind);
554 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
557 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
562 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
565 f->value.function.name
566 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
571 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
574 f->value.function.name
575 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
580 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
582 f->ts.type = BT_INTEGER;
584 f->ts.kind = mpz_get_si (kind->value.integer);
586 f->ts.kind = gfc_default_integer_kind;
590 f->rank = mask->rank - 1;
591 gfc_resolve_dim_arg (dim);
592 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
595 resolve_mask_arg (mask);
597 f->value.function.name
598 = gfc_get_string (PREFIX ("count_%d_%c"), f->ts.kind,
599 gfc_type_letter (mask->ts.type));
604 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
609 if (array->ts.type == BT_CHARACTER && array->ref)
610 gfc_resolve_substring_charlen (array);
613 f->rank = array->rank;
614 f->shape = gfc_copy_shape (array->shape, array->rank);
621 /* If dim kind is greater than default integer we need to use the larger. */
622 m = gfc_default_integer_kind;
624 m = m < dim->ts.kind ? dim->ts.kind : m;
626 /* Convert shift to at least m, so we don't need
627 kind=1 and kind=2 versions of the library functions. */
628 if (shift->ts.kind < m)
632 ts.type = BT_INTEGER;
634 gfc_convert_type_warn (shift, &ts, 2, 0);
639 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
640 && dim->symtree->n.sym->attr.optional)
642 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
643 dim->representation.length = shift->ts.kind;
647 gfc_resolve_dim_arg (dim);
648 /* Convert dim to shift's kind to reduce variations. */
649 if (dim->ts.kind != shift->ts.kind)
650 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
654 if (array->ts.type == BT_CHARACTER)
656 if (array->ts.kind == gfc_default_character_kind)
657 f->value.function.name
658 = gfc_get_string (PREFIX ("cshift%d_%d_char"), n, shift->ts.kind);
660 f->value.function.name
661 = gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n, shift->ts.kind,
665 f->value.function.name
666 = gfc_get_string (PREFIX ("cshift%d_%d"), n, shift->ts.kind);
671 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
676 f->ts.type = BT_CHARACTER;
677 f->ts.kind = gfc_default_character_kind;
679 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
680 if (time->ts.kind != 8)
682 ts.type = BT_INTEGER;
686 gfc_convert_type (time, &ts, 2);
689 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
694 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
696 f->ts.type = BT_REAL;
697 f->ts.kind = gfc_default_double_kind;
698 f->value.function.name
699 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
704 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
706 f->ts.type = a->ts.type;
708 f->ts.kind = gfc_kind_max (a,p);
710 f->ts.kind = a->ts.kind;
712 if (p != NULL && a->ts.kind != p->ts.kind)
714 if (a->ts.kind == gfc_kind_max (a,p))
715 gfc_convert_type (p, &a->ts, 2);
717 gfc_convert_type (a, &p->ts, 2);
720 f->value.function.name
721 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
726 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
730 temp.expr_type = EXPR_OP;
731 gfc_clear_ts (&temp.ts);
732 temp.value.op.op = INTRINSIC_NONE;
733 temp.value.op.op1 = a;
734 temp.value.op.op2 = b;
735 gfc_type_convert_binary (&temp, 1);
737 f->value.function.name
738 = gfc_get_string (PREFIX ("dot_product_%c%d"),
739 gfc_type_letter (f->ts.type), f->ts.kind);
744 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
745 gfc_expr *b ATTRIBUTE_UNUSED)
747 f->ts.kind = gfc_default_double_kind;
748 f->ts.type = BT_REAL;
749 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
754 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
755 gfc_expr *boundary, gfc_expr *dim)
759 if (array->ts.type == BT_CHARACTER && array->ref)
760 gfc_resolve_substring_charlen (array);
763 f->rank = array->rank;
764 f->shape = gfc_copy_shape (array->shape, array->rank);
769 if (boundary && boundary->rank > 0)
772 /* If dim kind is greater than default integer we need to use the larger. */
773 m = gfc_default_integer_kind;
775 m = m < dim->ts.kind ? dim->ts.kind : m;
777 /* Convert shift to at least m, so we don't need
778 kind=1 and kind=2 versions of the library functions. */
779 if (shift->ts.kind < m)
783 ts.type = BT_INTEGER;
785 gfc_convert_type_warn (shift, &ts, 2, 0);
790 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
791 && dim->symtree->n.sym->attr.optional)
793 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
794 dim->representation.length = shift->ts.kind;
798 gfc_resolve_dim_arg (dim);
799 /* Convert dim to shift's kind to reduce variations. */
800 if (dim->ts.kind != shift->ts.kind)
801 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
805 if (array->ts.type == BT_CHARACTER)
807 if (array->ts.kind == gfc_default_character_kind)
808 f->value.function.name
809 = gfc_get_string (PREFIX ("eoshift%d_%d_char"), n, shift->ts.kind);
811 f->value.function.name
812 = gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n, shift->ts.kind,
816 f->value.function.name
817 = gfc_get_string (PREFIX ("eoshift%d_%d"), n, shift->ts.kind);
822 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
825 f->value.function.name
826 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
831 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
833 f->ts.type = BT_INTEGER;
834 f->ts.kind = gfc_default_integer_kind;
835 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
839 /* Resolve the EXTENDS_TYPE_OF intrinsic function. */
842 gfc_resolve_extends_type_of (gfc_expr *f, gfc_expr *a, gfc_expr *mo)
847 /* Prevent double resolution. */
848 if (f->ts.type == BT_LOGICAL)
851 /* Replace the first argument with the corresponding vtab. */
852 if (a->ts.type == BT_CLASS)
853 gfc_add_component_ref (a, "$vptr");
854 else if (a->ts.type == BT_DERIVED)
856 vtab = gfc_find_derived_vtab (a->ts.u.derived, false);
857 /* Clear the old expr. */
858 gfc_free_ref_list (a->ref);
859 memset (a, '\0', sizeof (gfc_expr));
860 /* Construct a new one. */
861 a->expr_type = EXPR_VARIABLE;
862 st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
867 /* Replace the second argument with the corresponding vtab. */
868 if (mo->ts.type == BT_CLASS)
869 gfc_add_component_ref (mo, "$vptr");
870 else if (mo->ts.type == BT_DERIVED)
872 vtab = gfc_find_derived_vtab (mo->ts.u.derived, false);
873 /* Clear the old expr. */
874 gfc_free_ref_list (mo->ref);
875 memset (mo, '\0', sizeof (gfc_expr));
876 /* Construct a new one. */
877 mo->expr_type = EXPR_VARIABLE;
878 st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
883 f->ts.type = BT_LOGICAL;
885 /* Call library function. */
886 f->value.function.name = gfc_get_string (PREFIX ("is_extension_of"));
891 gfc_resolve_fdate (gfc_expr *f)
893 f->ts.type = BT_CHARACTER;
894 f->ts.kind = gfc_default_character_kind;
895 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
900 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
902 f->ts.type = BT_INTEGER;
903 f->ts.kind = (kind == NULL)
904 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
905 f->value.function.name
906 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
907 gfc_type_letter (a->ts.type), a->ts.kind);
912 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
914 f->ts.type = BT_INTEGER;
915 f->ts.kind = gfc_default_integer_kind;
916 if (n->ts.kind != f->ts.kind)
917 gfc_convert_type (n, &f->ts, 2);
918 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
923 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
926 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
930 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
933 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
936 f->value.function.name = gfc_get_string ("<intrinsic>");
941 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
944 f->value.function.name
945 = gfc_get_string ("__tgamma_%d", x->ts.kind);
950 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
952 f->ts.type = BT_INTEGER;
954 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
959 gfc_resolve_getgid (gfc_expr *f)
961 f->ts.type = BT_INTEGER;
963 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
968 gfc_resolve_getpid (gfc_expr *f)
970 f->ts.type = BT_INTEGER;
972 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
977 gfc_resolve_getuid (gfc_expr *f)
979 f->ts.type = BT_INTEGER;
981 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
986 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
988 f->ts.type = BT_INTEGER;
990 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
995 gfc_resolve_hypot (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
998 f->value.function.name = gfc_get_string ("__hypot_r%d", x->ts.kind);
1003 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1005 /* If the kind of i and j are different, then g77 cross-promoted the
1006 kinds to the largest value. The Fortran 95 standard requires the
1008 if (i->ts.kind != j->ts.kind)
1010 if (i->ts.kind == gfc_kind_max (i, j))
1011 gfc_convert_type (j, &i->ts, 2);
1013 gfc_convert_type (i, &j->ts, 2);
1017 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
1022 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1025 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
1030 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
1031 gfc_expr *len ATTRIBUTE_UNUSED)
1034 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
1039 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1042 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
1047 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1049 f->ts.type = BT_INTEGER;
1051 f->ts.kind = mpz_get_si (kind->value.integer);
1053 f->ts.kind = gfc_default_integer_kind;
1054 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1059 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1061 f->ts.type = BT_INTEGER;
1063 f->ts.kind = mpz_get_si (kind->value.integer);
1065 f->ts.kind = gfc_default_integer_kind;
1066 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1071 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
1073 gfc_resolve_nint (f, a, NULL);
1078 gfc_resolve_ierrno (gfc_expr *f)
1080 f->ts.type = BT_INTEGER;
1081 f->ts.kind = gfc_default_integer_kind;
1082 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
1087 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1089 /* If the kind of i and j are different, then g77 cross-promoted the
1090 kinds to the largest value. The Fortran 95 standard requires the
1092 if (i->ts.kind != j->ts.kind)
1094 if (i->ts.kind == gfc_kind_max (i, j))
1095 gfc_convert_type (j, &i->ts, 2);
1097 gfc_convert_type (i, &j->ts, 2);
1101 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
1106 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1108 /* If the kind of i and j are different, then g77 cross-promoted the
1109 kinds to the largest value. The Fortran 95 standard requires the
1111 if (i->ts.kind != j->ts.kind)
1113 if (i->ts.kind == gfc_kind_max (i, j))
1114 gfc_convert_type (j, &i->ts, 2);
1116 gfc_convert_type (i, &j->ts, 2);
1120 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
1125 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
1126 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
1132 f->ts.type = BT_INTEGER;
1134 f->ts.kind = mpz_get_si (kind->value.integer);
1136 f->ts.kind = gfc_default_integer_kind;
1138 if (back && back->ts.kind != gfc_default_integer_kind)
1140 ts.type = BT_LOGICAL;
1141 ts.kind = gfc_default_integer_kind;
1142 ts.u.derived = NULL;
1144 gfc_convert_type (back, &ts, 2);
1147 f->value.function.name
1148 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
1153 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1155 f->ts.type = BT_INTEGER;
1156 f->ts.kind = (kind == NULL)
1157 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1158 f->value.function.name
1159 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1160 gfc_type_letter (a->ts.type), a->ts.kind);
1165 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1167 f->ts.type = BT_INTEGER;
1169 f->value.function.name
1170 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1171 gfc_type_letter (a->ts.type), a->ts.kind);
1176 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
1178 f->ts.type = BT_INTEGER;
1180 f->value.function.name
1181 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1182 gfc_type_letter (a->ts.type), a->ts.kind);
1187 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1189 f->ts.type = BT_INTEGER;
1191 f->value.function.name
1192 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1193 gfc_type_letter (a->ts.type), a->ts.kind);
1198 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1203 f->ts.type = BT_LOGICAL;
1204 f->ts.kind = gfc_default_integer_kind;
1205 if (u->ts.kind != gfc_c_int_kind)
1207 ts.type = BT_INTEGER;
1208 ts.kind = gfc_c_int_kind;
1209 ts.u.derived = NULL;
1211 gfc_convert_type (u, &ts, 2);
1214 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1219 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1222 f->value.function.name
1223 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1228 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1231 f->value.function.name
1232 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1237 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1240 f->value.function.name
1241 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1246 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1250 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1253 f->value.function.name
1254 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1259 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1260 gfc_expr *s ATTRIBUTE_UNUSED)
1262 f->ts.type = BT_INTEGER;
1263 f->ts.kind = gfc_default_integer_kind;
1264 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1269 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1271 resolve_bound (f, array, dim, kind, "__lbound");
1276 gfc_resolve_lcobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1278 resolve_bound (f, array, dim, kind, "__lcobound");
1283 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1285 f->ts.type = BT_INTEGER;
1287 f->ts.kind = mpz_get_si (kind->value.integer);
1289 f->ts.kind = gfc_default_integer_kind;
1290 f->value.function.name
1291 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1292 gfc_default_integer_kind);
1297 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1299 f->ts.type = BT_INTEGER;
1301 f->ts.kind = mpz_get_si (kind->value.integer);
1303 f->ts.kind = gfc_default_integer_kind;
1304 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1309 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1312 f->value.function.name
1313 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1318 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1319 gfc_expr *p2 ATTRIBUTE_UNUSED)
1321 f->ts.type = BT_INTEGER;
1322 f->ts.kind = gfc_default_integer_kind;
1323 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1328 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1330 f->ts.type= BT_INTEGER;
1331 f->ts.kind = gfc_index_integer_kind;
1332 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1337 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1340 f->value.function.name
1341 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1346 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1349 f->value.function.name
1350 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1356 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1358 f->ts.type = BT_LOGICAL;
1359 f->ts.kind = (kind == NULL)
1360 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1363 f->value.function.name
1364 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1365 gfc_type_letter (a->ts.type), a->ts.kind);
1370 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1372 if (size->ts.kind < gfc_index_integer_kind)
1377 ts.type = BT_INTEGER;
1378 ts.kind = gfc_index_integer_kind;
1379 gfc_convert_type_warn (size, &ts, 2, 0);
1382 f->ts.type = BT_INTEGER;
1383 f->ts.kind = gfc_index_integer_kind;
1384 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1389 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1393 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1395 f->ts.type = BT_LOGICAL;
1396 f->ts.kind = gfc_default_logical_kind;
1400 temp.expr_type = EXPR_OP;
1401 gfc_clear_ts (&temp.ts);
1402 temp.value.op.op = INTRINSIC_NONE;
1403 temp.value.op.op1 = a;
1404 temp.value.op.op2 = b;
1405 gfc_type_convert_binary (&temp, 1);
1409 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1411 if (a->rank == 2 && b->rank == 2)
1413 if (a->shape && b->shape)
1415 f->shape = gfc_get_shape (f->rank);
1416 mpz_init_set (f->shape[0], a->shape[0]);
1417 mpz_init_set (f->shape[1], b->shape[1]);
1420 else if (a->rank == 1)
1424 f->shape = gfc_get_shape (f->rank);
1425 mpz_init_set (f->shape[0], b->shape[1]);
1430 /* b->rank == 1 and a->rank == 2 here, all other cases have
1431 been caught in check.c. */
1434 f->shape = gfc_get_shape (f->rank);
1435 mpz_init_set (f->shape[0], a->shape[0]);
1439 f->value.function.name
1440 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1446 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1448 gfc_actual_arglist *a;
1450 f->ts.type = args->expr->ts.type;
1451 f->ts.kind = args->expr->ts.kind;
1452 /* Find the largest type kind. */
1453 for (a = args->next; a; a = a->next)
1455 if (a->expr->ts.kind > f->ts.kind)
1456 f->ts.kind = a->expr->ts.kind;
1459 /* Convert all parameters to the required kind. */
1460 for (a = args; a; a = a->next)
1462 if (a->expr->ts.kind != f->ts.kind)
1463 gfc_convert_type (a->expr, &f->ts, 2);
1466 f->value.function.name
1467 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1472 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1474 gfc_resolve_minmax ("__max_%c%d", f, args);
1479 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1485 f->ts.type = BT_INTEGER;
1486 f->ts.kind = gfc_default_integer_kind;
1491 f->shape = gfc_get_shape (1);
1492 mpz_init_set_si (f->shape[0], array->rank);
1496 f->rank = array->rank - 1;
1497 gfc_resolve_dim_arg (dim);
1498 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1500 idim = (int) mpz_get_si (dim->value.integer);
1501 f->shape = gfc_get_shape (f->rank);
1502 for (i = 0, j = 0; i < f->rank; i++, j++)
1504 if (i == (idim - 1))
1506 mpz_init_set (f->shape[i], array->shape[j]);
1513 if (mask->rank == 0)
1518 resolve_mask_arg (mask);
1523 f->value.function.name
1524 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1525 gfc_type_letter (array->ts.type), array->ts.kind);
1530 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1540 f->rank = array->rank - 1;
1541 gfc_resolve_dim_arg (dim);
1543 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1545 idim = (int) mpz_get_si (dim->value.integer);
1546 f->shape = gfc_get_shape (f->rank);
1547 for (i = 0, j = 0; i < f->rank; i++, j++)
1549 if (i == (idim - 1))
1551 mpz_init_set (f->shape[i], array->shape[j]);
1558 if (mask->rank == 0)
1563 resolve_mask_arg (mask);
1568 f->value.function.name
1569 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1570 gfc_type_letter (array->ts.type), array->ts.kind);
1575 gfc_resolve_mclock (gfc_expr *f)
1577 f->ts.type = BT_INTEGER;
1579 f->value.function.name = PREFIX ("mclock");
1584 gfc_resolve_mclock8 (gfc_expr *f)
1586 f->ts.type = BT_INTEGER;
1588 f->value.function.name = PREFIX ("mclock8");
1593 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1594 gfc_expr *fsource ATTRIBUTE_UNUSED,
1595 gfc_expr *mask ATTRIBUTE_UNUSED)
1597 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1598 gfc_resolve_substring_charlen (tsource);
1600 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1601 gfc_resolve_substring_charlen (fsource);
1603 if (tsource->ts.type == BT_CHARACTER)
1604 check_charlen_present (tsource);
1606 f->ts = tsource->ts;
1607 f->value.function.name
1608 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1614 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1616 gfc_resolve_minmax ("__min_%c%d", f, args);
1621 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1627 f->ts.type = BT_INTEGER;
1628 f->ts.kind = gfc_default_integer_kind;
1633 f->shape = gfc_get_shape (1);
1634 mpz_init_set_si (f->shape[0], array->rank);
1638 f->rank = array->rank - 1;
1639 gfc_resolve_dim_arg (dim);
1640 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1642 idim = (int) mpz_get_si (dim->value.integer);
1643 f->shape = gfc_get_shape (f->rank);
1644 for (i = 0, j = 0; i < f->rank; i++, j++)
1646 if (i == (idim - 1))
1648 mpz_init_set (f->shape[i], array->shape[j]);
1655 if (mask->rank == 0)
1660 resolve_mask_arg (mask);
1665 f->value.function.name
1666 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1667 gfc_type_letter (array->ts.type), array->ts.kind);
1672 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1682 f->rank = array->rank - 1;
1683 gfc_resolve_dim_arg (dim);
1685 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1687 idim = (int) mpz_get_si (dim->value.integer);
1688 f->shape = gfc_get_shape (f->rank);
1689 for (i = 0, j = 0; i < f->rank; i++, j++)
1691 if (i == (idim - 1))
1693 mpz_init_set (f->shape[i], array->shape[j]);
1700 if (mask->rank == 0)
1705 resolve_mask_arg (mask);
1710 f->value.function.name
1711 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1712 gfc_type_letter (array->ts.type), array->ts.kind);
1717 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1719 f->ts.type = a->ts.type;
1721 f->ts.kind = gfc_kind_max (a,p);
1723 f->ts.kind = a->ts.kind;
1725 if (p != NULL && a->ts.kind != p->ts.kind)
1727 if (a->ts.kind == gfc_kind_max (a,p))
1728 gfc_convert_type (p, &a->ts, 2);
1730 gfc_convert_type (a, &p->ts, 2);
1733 f->value.function.name
1734 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1739 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1741 f->ts.type = a->ts.type;
1743 f->ts.kind = gfc_kind_max (a,p);
1745 f->ts.kind = a->ts.kind;
1747 if (p != NULL && a->ts.kind != p->ts.kind)
1749 if (a->ts.kind == gfc_kind_max (a,p))
1750 gfc_convert_type (p, &a->ts, 2);
1752 gfc_convert_type (a, &p->ts, 2);
1755 f->value.function.name
1756 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1761 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1763 if (p->ts.kind != a->ts.kind)
1764 gfc_convert_type (p, &a->ts, 2);
1767 f->value.function.name
1768 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1773 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1775 f->ts.type = BT_INTEGER;
1776 f->ts.kind = (kind == NULL)
1777 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1778 f->value.function.name
1779 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1784 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1787 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1792 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1794 f->ts.type = i->ts.type;
1795 f->ts.kind = gfc_kind_max (i, j);
1797 if (i->ts.kind != j->ts.kind)
1799 if (i->ts.kind == gfc_kind_max (i, j))
1800 gfc_convert_type (j, &i->ts, 2);
1802 gfc_convert_type (i, &j->ts, 2);
1805 f->value.function.name
1806 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1811 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1812 gfc_expr *vector ATTRIBUTE_UNUSED)
1814 if (array->ts.type == BT_CHARACTER && array->ref)
1815 gfc_resolve_substring_charlen (array);
1820 resolve_mask_arg (mask);
1822 if (mask->rank != 0)
1824 if (array->ts.type == BT_CHARACTER)
1825 f->value.function.name
1826 = array->ts.kind == 1 ? PREFIX ("pack_char")
1828 (PREFIX ("pack_char%d"),
1831 f->value.function.name = PREFIX ("pack");
1835 if (array->ts.type == BT_CHARACTER)
1836 f->value.function.name
1837 = array->ts.kind == 1 ? PREFIX ("pack_s_char")
1839 (PREFIX ("pack_s_char%d"),
1842 f->value.function.name = PREFIX ("pack_s");
1848 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1857 f->rank = array->rank - 1;
1858 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
1859 gfc_resolve_dim_arg (dim);
1864 if (mask->rank == 0)
1869 resolve_mask_arg (mask);
1874 f->value.function.name
1875 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1876 gfc_type_letter (array->ts.type), array->ts.kind);
1881 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1883 f->ts.type = BT_REAL;
1886 f->ts.kind = mpz_get_si (kind->value.integer);
1888 f->ts.kind = (a->ts.type == BT_COMPLEX)
1889 ? a->ts.kind : gfc_default_real_kind;
1891 f->value.function.name
1892 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1893 gfc_type_letter (a->ts.type), a->ts.kind);
1898 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1900 f->ts.type = BT_REAL;
1901 f->ts.kind = a->ts.kind;
1902 f->value.function.name
1903 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1904 gfc_type_letter (a->ts.type), a->ts.kind);
1909 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1910 gfc_expr *p2 ATTRIBUTE_UNUSED)
1912 f->ts.type = BT_INTEGER;
1913 f->ts.kind = gfc_default_integer_kind;
1914 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1919 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
1920 gfc_expr *ncopies ATTRIBUTE_UNUSED)
1922 f->ts.type = BT_CHARACTER;
1923 f->ts.kind = string->ts.kind;
1924 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
1929 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
1930 gfc_expr *pad ATTRIBUTE_UNUSED,
1931 gfc_expr *order ATTRIBUTE_UNUSED)
1937 if (source->ts.type == BT_CHARACTER && source->ref)
1938 gfc_resolve_substring_charlen (source);
1942 gfc_array_size (shape, &rank);
1943 f->rank = mpz_get_si (rank);
1945 switch (source->ts.type)
1952 kind = source->ts.kind;
1966 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
1967 f->value.function.name
1968 = gfc_get_string (PREFIX ("reshape_%c%d"),
1969 gfc_type_letter (source->ts.type),
1971 else if (source->ts.type == BT_CHARACTER)
1972 f->value.function.name = gfc_get_string (PREFIX ("reshape_char%d"),
1975 f->value.function.name
1976 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
1980 f->value.function.name = (source->ts.type == BT_CHARACTER
1981 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1985 /* TODO: Make this work with a constant ORDER parameter. */
1986 if (shape->expr_type == EXPR_ARRAY
1987 && gfc_is_constant_expr (shape)
1991 f->shape = gfc_get_shape (f->rank);
1992 c = gfc_constructor_first (shape->value.constructor);
1993 for (i = 0; i < f->rank; i++)
1995 mpz_init_set (f->shape[i], c->expr->value.integer);
1996 c = gfc_constructor_next (c);
2000 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
2001 so many runtime variations. */
2002 if (shape->ts.kind != gfc_index_integer_kind)
2004 gfc_typespec ts = shape->ts;
2005 ts.kind = gfc_index_integer_kind;
2006 gfc_convert_type_warn (shape, &ts, 2, 0);
2008 if (order && order->ts.kind != gfc_index_integer_kind)
2009 gfc_convert_type_warn (order, &shape->ts, 2, 0);
2014 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
2017 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
2022 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED)
2025 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
2030 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
2031 gfc_expr *set ATTRIBUTE_UNUSED,
2032 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2034 f->ts.type = BT_INTEGER;
2036 f->ts.kind = mpz_get_si (kind->value.integer);
2038 f->ts.kind = gfc_default_integer_kind;
2039 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
2044 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
2047 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
2052 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x,
2053 gfc_expr *i ATTRIBUTE_UNUSED)
2056 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
2061 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
2063 f->ts.type = BT_INTEGER;
2064 f->ts.kind = gfc_default_integer_kind;
2066 f->shape = gfc_get_shape (1);
2067 mpz_init_set_ui (f->shape[0], array->rank);
2068 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
2073 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
2076 f->value.function.name
2077 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
2082 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
2084 f->ts.type = BT_INTEGER;
2085 f->ts.kind = gfc_c_int_kind;
2087 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2088 if (handler->ts.type == BT_INTEGER)
2090 if (handler->ts.kind != gfc_c_int_kind)
2091 gfc_convert_type (handler, &f->ts, 2);
2092 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
2095 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
2097 if (number->ts.kind != gfc_c_int_kind)
2098 gfc_convert_type (number, &f->ts, 2);
2103 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
2106 f->value.function.name
2107 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2112 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
2115 f->value.function.name
2116 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2121 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2122 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
2124 f->ts.type = BT_INTEGER;
2126 f->ts.kind = mpz_get_si (kind->value.integer);
2128 f->ts.kind = gfc_default_integer_kind;
2133 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
2136 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
2141 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2144 if (source->ts.type == BT_CHARACTER && source->ref)
2145 gfc_resolve_substring_charlen (source);
2147 if (source->ts.type == BT_CHARACTER)
2148 check_charlen_present (source);
2151 f->rank = source->rank + 1;
2152 if (source->rank == 0)
2154 if (source->ts.type == BT_CHARACTER)
2155 f->value.function.name
2156 = source->ts.kind == 1 ? PREFIX ("spread_char_scalar")
2158 (PREFIX ("spread_char%d_scalar"),
2161 f->value.function.name = PREFIX ("spread_scalar");
2165 if (source->ts.type == BT_CHARACTER)
2166 f->value.function.name
2167 = source->ts.kind == 1 ? PREFIX ("spread_char")
2169 (PREFIX ("spread_char%d"),
2172 f->value.function.name = PREFIX ("spread");
2175 if (dim && gfc_is_constant_expr (dim)
2176 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2179 idim = mpz_get_ui (dim->value.integer);
2180 f->shape = gfc_get_shape (f->rank);
2181 for (i = 0; i < (idim - 1); i++)
2182 mpz_init_set (f->shape[i], source->shape[i]);
2184 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2186 for (i = idim; i < f->rank ; i++)
2187 mpz_init_set (f->shape[i], source->shape[i-1]);
2191 gfc_resolve_dim_arg (dim);
2192 gfc_resolve_index (ncopies, 1);
2197 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2200 f->value.function.name
2201 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2205 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2208 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2209 gfc_expr *a ATTRIBUTE_UNUSED)
2211 f->ts.type = BT_INTEGER;
2212 f->ts.kind = gfc_default_integer_kind;
2213 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2218 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2219 gfc_expr *a ATTRIBUTE_UNUSED)
2221 f->ts.type = BT_INTEGER;
2222 f->ts.kind = gfc_default_integer_kind;
2223 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2228 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2230 f->ts.type = BT_INTEGER;
2231 f->ts.kind = gfc_default_integer_kind;
2232 if (n->ts.kind != f->ts.kind)
2233 gfc_convert_type (n, &f->ts, 2);
2235 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2240 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2245 f->ts.type = BT_INTEGER;
2246 f->ts.kind = gfc_c_int_kind;
2247 if (u->ts.kind != gfc_c_int_kind)
2249 ts.type = BT_INTEGER;
2250 ts.kind = gfc_c_int_kind;
2251 ts.u.derived = NULL;
2253 gfc_convert_type (u, &ts, 2);
2256 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2261 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2263 f->ts.type = BT_INTEGER;
2264 f->ts.kind = gfc_c_int_kind;
2265 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2270 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2275 f->ts.type = BT_INTEGER;
2276 f->ts.kind = gfc_c_int_kind;
2277 if (u->ts.kind != gfc_c_int_kind)
2279 ts.type = BT_INTEGER;
2280 ts.kind = gfc_c_int_kind;
2281 ts.u.derived = NULL;
2283 gfc_convert_type (u, &ts, 2);
2286 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2291 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2293 f->ts.type = BT_INTEGER;
2294 f->ts.kind = gfc_c_int_kind;
2295 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2300 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2305 f->ts.type = BT_INTEGER;
2306 f->ts.kind = gfc_index_integer_kind;
2307 if (u->ts.kind != gfc_c_int_kind)
2309 ts.type = BT_INTEGER;
2310 ts.kind = gfc_c_int_kind;
2311 ts.u.derived = NULL;
2313 gfc_convert_type (u, &ts, 2);
2316 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2321 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2329 if (mask->rank == 0)
2334 resolve_mask_arg (mask);
2341 f->rank = array->rank - 1;
2342 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
2343 gfc_resolve_dim_arg (dim);
2346 f->value.function.name
2347 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2348 gfc_type_letter (array->ts.type), array->ts.kind);
2353 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2354 gfc_expr *p2 ATTRIBUTE_UNUSED)
2356 f->ts.type = BT_INTEGER;
2357 f->ts.kind = gfc_default_integer_kind;
2358 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2362 /* Resolve the g77 compatibility function SYSTEM. */
2365 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2367 f->ts.type = BT_INTEGER;
2369 f->value.function.name = gfc_get_string (PREFIX ("system"));
2374 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2377 f->value.function.name
2378 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2383 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2386 f->value.function.name
2387 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2392 gfc_resolve_image_index (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2393 gfc_expr *sub ATTRIBUTE_UNUSED)
2395 static char this_image[] = "__image_index";
2396 f->ts.kind = gfc_default_integer_kind;
2397 f->value.function.name = this_image;
2402 gfc_resolve_this_image (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
2404 resolve_bound (f, array, dim, NULL, "__this_image");
2409 gfc_resolve_time (gfc_expr *f)
2411 f->ts.type = BT_INTEGER;
2413 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2418 gfc_resolve_time8 (gfc_expr *f)
2420 f->ts.type = BT_INTEGER;
2422 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2427 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2428 gfc_expr *mold, gfc_expr *size)
2430 /* TODO: Make this do something meaningful. */
2431 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2433 if (mold->ts.type == BT_CHARACTER
2434 && !mold->ts.u.cl->length
2435 && gfc_is_constant_expr (mold))
2438 if (mold->expr_type == EXPR_CONSTANT)
2440 len = mold->value.character.length;
2441 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2446 gfc_constructor *c = gfc_constructor_first (mold->value.constructor);
2447 len = c->expr->value.character.length;
2448 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2455 if (size == NULL && mold->rank == 0)
2458 f->value.function.name = transfer0;
2463 f->value.function.name = transfer1;
2464 if (size && gfc_is_constant_expr (size))
2466 f->shape = gfc_get_shape (1);
2467 mpz_init_set (f->shape[0], size->value.integer);
2474 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2477 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2478 gfc_resolve_substring_charlen (matrix);
2484 f->shape = gfc_get_shape (2);
2485 mpz_init_set (f->shape[0], matrix->shape[1]);
2486 mpz_init_set (f->shape[1], matrix->shape[0]);
2489 switch (matrix->ts.kind)
2495 switch (matrix->ts.type)
2499 f->value.function.name
2500 = gfc_get_string (PREFIX ("transpose_%c%d"),
2501 gfc_type_letter (matrix->ts.type),
2507 /* Use the integer routines for real and logical cases. This
2508 assumes they all have the same alignment requirements. */
2509 f->value.function.name
2510 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2514 if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4)
2515 f->value.function.name = PREFIX ("transpose_char4");
2517 f->value.function.name = PREFIX ("transpose");
2523 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2524 ? PREFIX ("transpose_char")
2525 : PREFIX ("transpose"));
2532 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2534 f->ts.type = BT_CHARACTER;
2535 f->ts.kind = string->ts.kind;
2536 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2541 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2543 resolve_bound (f, array, dim, kind, "__ubound");
2548 gfc_resolve_ucobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2550 resolve_bound (f, array, dim, kind, "__ucobound");
2554 /* Resolve the g77 compatibility function UMASK. */
2557 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2559 f->ts.type = BT_INTEGER;
2560 f->ts.kind = n->ts.kind;
2561 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2565 /* Resolve the g77 compatibility function UNLINK. */
2568 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2570 f->ts.type = BT_INTEGER;
2572 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2577 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2582 f->ts.type = BT_CHARACTER;
2583 f->ts.kind = gfc_default_character_kind;
2585 if (unit->ts.kind != gfc_c_int_kind)
2587 ts.type = BT_INTEGER;
2588 ts.kind = gfc_c_int_kind;
2589 ts.u.derived = NULL;
2591 gfc_convert_type (unit, &ts, 2);
2594 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2599 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2600 gfc_expr *field ATTRIBUTE_UNUSED)
2602 if (vector->ts.type == BT_CHARACTER && vector->ref)
2603 gfc_resolve_substring_charlen (vector);
2606 f->rank = mask->rank;
2607 resolve_mask_arg (mask);
2609 if (vector->ts.type == BT_CHARACTER)
2611 if (vector->ts.kind == 1)
2612 f->value.function.name
2613 = gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0);
2615 f->value.function.name
2616 = gfc_get_string (PREFIX ("unpack%d_char%d"),
2617 field->rank > 0 ? 1 : 0, vector->ts.kind);
2620 f->value.function.name
2621 = gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0);
2626 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2627 gfc_expr *set ATTRIBUTE_UNUSED,
2628 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2630 f->ts.type = BT_INTEGER;
2632 f->ts.kind = mpz_get_si (kind->value.integer);
2634 f->ts.kind = gfc_default_integer_kind;
2635 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2640 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2642 f->ts.type = i->ts.type;
2643 f->ts.kind = gfc_kind_max (i, j);
2645 if (i->ts.kind != j->ts.kind)
2647 if (i->ts.kind == gfc_kind_max (i, j))
2648 gfc_convert_type (j, &i->ts, 2);
2650 gfc_convert_type (i, &j->ts, 2);
2653 f->value.function.name
2654 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2658 /* Intrinsic subroutine resolution. */
2661 gfc_resolve_alarm_sub (gfc_code *c)
2664 gfc_expr *seconds, *handler;
2668 seconds = c->ext.actual->expr;
2669 handler = c->ext.actual->next->expr;
2670 ts.type = BT_INTEGER;
2671 ts.kind = gfc_c_int_kind;
2673 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2674 In all cases, the status argument is of default integer kind
2675 (enforced in check.c) so that the function suffix is fixed. */
2676 if (handler->ts.type == BT_INTEGER)
2678 if (handler->ts.kind != gfc_c_int_kind)
2679 gfc_convert_type (handler, &ts, 2);
2680 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2681 gfc_default_integer_kind);
2684 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2685 gfc_default_integer_kind);
2687 if (seconds->ts.kind != gfc_c_int_kind)
2688 gfc_convert_type (seconds, &ts, 2);
2690 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2694 gfc_resolve_cpu_time (gfc_code *c)
2697 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2698 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2702 /* Create a formal arglist based on an actual one and set the INTENTs given. */
2704 static gfc_formal_arglist*
2705 create_formal_for_intents (gfc_actual_arglist* actual, const sym_intent* ints)
2707 gfc_formal_arglist* head;
2708 gfc_formal_arglist* tail;
2714 head = tail = gfc_get_formal_arglist ();
2715 for (i = 0; actual; actual = actual->next, tail = tail->next, ++i)
2719 sym = gfc_new_symbol ("dummyarg", NULL);
2720 sym->ts = actual->expr->ts;
2722 sym->attr.intent = ints[i];
2726 tail->next = gfc_get_formal_arglist ();
2734 gfc_resolve_mvbits (gfc_code *c)
2736 static const sym_intent INTENTS[] = {INTENT_IN, INTENT_IN, INTENT_IN,
2737 INTENT_INOUT, INTENT_IN};
2743 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2744 they will be converted so that they fit into a C int. */
2745 ts.type = BT_INTEGER;
2746 ts.kind = gfc_c_int_kind;
2747 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2748 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2749 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2750 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2751 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2752 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2754 /* TO and FROM are guaranteed to have the same kind parameter. */
2755 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2756 c->ext.actual->expr->ts.kind);
2757 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2758 /* Mark as elemental subroutine as this does not happen automatically. */
2759 c->resolved_sym->attr.elemental = 1;
2761 /* Create a dummy formal arglist so the INTENTs are known later for purpose
2762 of creating temporaries. */
2763 c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS);
2768 gfc_resolve_random_number (gfc_code *c)
2773 kind = c->ext.actual->expr->ts.kind;
2774 if (c->ext.actual->expr->rank == 0)
2775 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2777 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2779 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2784 gfc_resolve_random_seed (gfc_code *c)
2788 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2789 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2794 gfc_resolve_rename_sub (gfc_code *c)
2799 if (c->ext.actual->next->next->expr != NULL)
2800 kind = c->ext.actual->next->next->expr->ts.kind;
2802 kind = gfc_default_integer_kind;
2804 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2805 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2810 gfc_resolve_kill_sub (gfc_code *c)
2815 if (c->ext.actual->next->next->expr != NULL)
2816 kind = c->ext.actual->next->next->expr->ts.kind;
2818 kind = gfc_default_integer_kind;
2820 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2821 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2826 gfc_resolve_link_sub (gfc_code *c)
2831 if (c->ext.actual->next->next->expr != NULL)
2832 kind = c->ext.actual->next->next->expr->ts.kind;
2834 kind = gfc_default_integer_kind;
2836 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2837 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2842 gfc_resolve_symlnk_sub (gfc_code *c)
2847 if (c->ext.actual->next->next->expr != NULL)
2848 kind = c->ext.actual->next->next->expr->ts.kind;
2850 kind = gfc_default_integer_kind;
2852 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2853 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2857 /* G77 compatibility subroutines dtime() and etime(). */
2860 gfc_resolve_dtime_sub (gfc_code *c)
2863 name = gfc_get_string (PREFIX ("dtime_sub"));
2864 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2868 gfc_resolve_etime_sub (gfc_code *c)
2871 name = gfc_get_string (PREFIX ("etime_sub"));
2872 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2876 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2879 gfc_resolve_itime (gfc_code *c)
2882 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2883 gfc_default_integer_kind));
2887 gfc_resolve_idate (gfc_code *c)
2890 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2891 gfc_default_integer_kind));
2895 gfc_resolve_ltime (gfc_code *c)
2898 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2899 gfc_default_integer_kind));
2903 gfc_resolve_gmtime (gfc_code *c)
2906 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2907 gfc_default_integer_kind));
2911 /* G77 compatibility subroutine second(). */
2914 gfc_resolve_second_sub (gfc_code *c)
2917 name = gfc_get_string (PREFIX ("second_sub"));
2918 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2923 gfc_resolve_sleep_sub (gfc_code *c)
2928 if (c->ext.actual->expr != NULL)
2929 kind = c->ext.actual->expr->ts.kind;
2931 kind = gfc_default_integer_kind;
2933 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2934 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2938 /* G77 compatibility function srand(). */
2941 gfc_resolve_srand (gfc_code *c)
2944 name = gfc_get_string (PREFIX ("srand"));
2945 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2949 /* Resolve the getarg intrinsic subroutine. */
2952 gfc_resolve_getarg (gfc_code *c)
2956 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
2961 ts.type = BT_INTEGER;
2962 ts.kind = gfc_default_integer_kind;
2964 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2967 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
2968 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2972 /* Resolve the getcwd intrinsic subroutine. */
2975 gfc_resolve_getcwd_sub (gfc_code *c)
2980 if (c->ext.actual->next->expr != NULL)
2981 kind = c->ext.actual->next->expr->ts.kind;
2983 kind = gfc_default_integer_kind;
2985 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2986 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2990 /* Resolve the get_command intrinsic subroutine. */
2993 gfc_resolve_get_command (gfc_code *c)
2997 kind = gfc_default_integer_kind;
2998 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2999 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3003 /* Resolve the get_command_argument intrinsic subroutine. */
3006 gfc_resolve_get_command_argument (gfc_code *c)
3010 kind = gfc_default_integer_kind;
3011 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
3012 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3016 /* Resolve the get_environment_variable intrinsic subroutine. */
3019 gfc_resolve_get_environment_variable (gfc_code *code)
3023 kind = gfc_default_integer_kind;
3024 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
3025 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3030 gfc_resolve_signal_sub (gfc_code *c)
3033 gfc_expr *number, *handler, *status;
3037 number = c->ext.actual->expr;
3038 handler = c->ext.actual->next->expr;
3039 status = c->ext.actual->next->next->expr;
3040 ts.type = BT_INTEGER;
3041 ts.kind = gfc_c_int_kind;
3043 /* handler can be either BT_INTEGER or BT_PROCEDURE */
3044 if (handler->ts.type == BT_INTEGER)
3046 if (handler->ts.kind != gfc_c_int_kind)
3047 gfc_convert_type (handler, &ts, 2);
3048 name = gfc_get_string (PREFIX ("signal_sub_int"));
3051 name = gfc_get_string (PREFIX ("signal_sub"));
3053 if (number->ts.kind != gfc_c_int_kind)
3054 gfc_convert_type (number, &ts, 2);
3055 if (status != NULL && status->ts.kind != gfc_c_int_kind)
3056 gfc_convert_type (status, &ts, 2);
3058 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3062 /* Resolve the SYSTEM intrinsic subroutine. */
3065 gfc_resolve_system_sub (gfc_code *c)
3068 name = gfc_get_string (PREFIX ("system_sub"));
3069 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3073 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
3076 gfc_resolve_system_clock (gfc_code *c)
3081 if (c->ext.actual->expr != NULL)
3082 kind = c->ext.actual->expr->ts.kind;
3083 else if (c->ext.actual->next->expr != NULL)
3084 kind = c->ext.actual->next->expr->ts.kind;
3085 else if (c->ext.actual->next->next->expr != NULL)
3086 kind = c->ext.actual->next->next->expr->ts.kind;
3088 kind = gfc_default_integer_kind;
3090 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
3091 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3095 /* Resolve the EXIT intrinsic subroutine. */
3098 gfc_resolve_exit (gfc_code *c)
3105 /* The STATUS argument has to be of default kind. If it is not,
3107 ts.type = BT_INTEGER;
3108 ts.kind = gfc_default_integer_kind;
3109 n = c->ext.actual->expr;
3110 if (n != NULL && n->ts.kind != ts.kind)
3111 gfc_convert_type (n, &ts, 2);
3113 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
3114 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3118 /* Resolve the FLUSH intrinsic subroutine. */
3121 gfc_resolve_flush (gfc_code *c)
3128 ts.type = BT_INTEGER;
3129 ts.kind = gfc_default_integer_kind;
3130 n = c->ext.actual->expr;
3131 if (n != NULL && n->ts.kind != ts.kind)
3132 gfc_convert_type (n, &ts, 2);
3134 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
3135 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3140 gfc_resolve_free (gfc_code *c)
3146 ts.type = BT_INTEGER;
3147 ts.kind = gfc_index_integer_kind;
3148 n = c->ext.actual->expr;
3149 if (n->ts.kind != ts.kind)
3150 gfc_convert_type (n, &ts, 2);
3152 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
3157 gfc_resolve_ctime_sub (gfc_code *c)
3162 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3163 if (c->ext.actual->expr->ts.kind != 8)
3165 ts.type = BT_INTEGER;
3167 ts.u.derived = NULL;
3169 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3172 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3177 gfc_resolve_fdate_sub (gfc_code *c)
3179 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3184 gfc_resolve_gerror (gfc_code *c)
3186 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3191 gfc_resolve_getlog (gfc_code *c)
3193 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3198 gfc_resolve_hostnm_sub (gfc_code *c)
3203 if (c->ext.actual->next->expr != NULL)
3204 kind = c->ext.actual->next->expr->ts.kind;
3206 kind = gfc_default_integer_kind;
3208 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3209 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3214 gfc_resolve_perror (gfc_code *c)
3216 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3219 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3222 gfc_resolve_stat_sub (gfc_code *c)
3225 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3226 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3231 gfc_resolve_lstat_sub (gfc_code *c)
3234 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3235 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3240 gfc_resolve_fstat_sub (gfc_code *c)
3246 u = c->ext.actual->expr;
3247 ts = &c->ext.actual->next->expr->ts;
3248 if (u->ts.kind != ts->kind)
3249 gfc_convert_type (u, ts, 2);
3250 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3251 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3256 gfc_resolve_fgetc_sub (gfc_code *c)
3263 u = c->ext.actual->expr;
3264 st = c->ext.actual->next->next->expr;
3266 if (u->ts.kind != gfc_c_int_kind)
3268 ts.type = BT_INTEGER;
3269 ts.kind = gfc_c_int_kind;
3270 ts.u.derived = NULL;
3272 gfc_convert_type (u, &ts, 2);
3276 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3278 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3280 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3285 gfc_resolve_fget_sub (gfc_code *c)
3290 st = c->ext.actual->next->expr;
3292 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3294 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3296 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3301 gfc_resolve_fputc_sub (gfc_code *c)
3308 u = c->ext.actual->expr;
3309 st = c->ext.actual->next->next->expr;
3311 if (u->ts.kind != gfc_c_int_kind)
3313 ts.type = BT_INTEGER;
3314 ts.kind = gfc_c_int_kind;
3315 ts.u.derived = NULL;
3317 gfc_convert_type (u, &ts, 2);
3321 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3323 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3325 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3330 gfc_resolve_fput_sub (gfc_code *c)
3335 st = c->ext.actual->next->expr;
3337 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3339 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3341 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3346 gfc_resolve_fseek_sub (gfc_code *c)
3354 unit = c->ext.actual->expr;
3355 offset = c->ext.actual->next->expr;
3356 whence = c->ext.actual->next->next->expr;
3358 if (unit->ts.kind != gfc_c_int_kind)
3360 ts.type = BT_INTEGER;
3361 ts.kind = gfc_c_int_kind;
3362 ts.u.derived = NULL;
3364 gfc_convert_type (unit, &ts, 2);
3367 if (offset->ts.kind != gfc_intio_kind)
3369 ts.type = BT_INTEGER;
3370 ts.kind = gfc_intio_kind;
3371 ts.u.derived = NULL;
3373 gfc_convert_type (offset, &ts, 2);
3376 if (whence->ts.kind != gfc_c_int_kind)
3378 ts.type = BT_INTEGER;
3379 ts.kind = gfc_c_int_kind;
3380 ts.u.derived = NULL;
3382 gfc_convert_type (whence, &ts, 2);
3385 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3389 gfc_resolve_ftell_sub (gfc_code *c)
3397 unit = c->ext.actual->expr;
3398 offset = c->ext.actual->next->expr;
3400 if (unit->ts.kind != gfc_c_int_kind)
3402 ts.type = BT_INTEGER;
3403 ts.kind = gfc_c_int_kind;
3404 ts.u.derived = NULL;
3406 gfc_convert_type (unit, &ts, 2);
3409 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3410 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3415 gfc_resolve_ttynam_sub (gfc_code *c)
3420 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3422 ts.type = BT_INTEGER;
3423 ts.kind = gfc_c_int_kind;
3424 ts.u.derived = NULL;
3426 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3429 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3433 /* Resolve the UMASK intrinsic subroutine. */
3436 gfc_resolve_umask_sub (gfc_code *c)
3441 if (c->ext.actual->next->expr != NULL)
3442 kind = c->ext.actual->next->expr->ts.kind;
3444 kind = gfc_default_integer_kind;
3446 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3447 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3450 /* Resolve the UNLINK intrinsic subroutine. */
3453 gfc_resolve_unlink_sub (gfc_code *c)
3458 if (c->ext.actual->next->expr != NULL)
3459 kind = c->ext.actual->next->expr->ts.kind;
3461 kind = gfc_default_integer_kind;
3463 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3464 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);