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,
125 const char *name, bool coarray)
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], coarray ? gfc_get_corank (array)
141 f->value.function.name = xstrdup (name);
144 /********************** Resolution functions **********************/
148 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
151 if (f->ts.type == BT_COMPLEX)
152 f->ts.type = BT_REAL;
154 f->value.function.name
155 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
160 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
161 gfc_expr *mode ATTRIBUTE_UNUSED)
163 f->ts.type = BT_INTEGER;
164 f->ts.kind = gfc_c_int_kind;
165 f->value.function.name = PREFIX ("access_func");
170 gfc_resolve_adjustl (gfc_expr *f, gfc_expr *string)
172 f->ts.type = BT_CHARACTER;
173 f->ts.kind = string->ts.kind;
174 f->value.function.name = gfc_get_string ("__adjustl_s%d", f->ts.kind);
179 gfc_resolve_adjustr (gfc_expr *f, gfc_expr *string)
181 f->ts.type = BT_CHARACTER;
182 f->ts.kind = string->ts.kind;
183 f->value.function.name = gfc_get_string ("__adjustr_s%d", f->ts.kind);
188 gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind,
191 f->ts.type = BT_CHARACTER;
192 f->ts.kind = (kind == NULL)
193 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
194 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
195 f->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
197 f->value.function.name = gfc_get_string (name, f->ts.kind,
198 gfc_type_letter (x->ts.type),
204 gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
206 gfc_resolve_char_achar (f, x, kind, "__achar_%d_%c%d");
211 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
214 f->value.function.name
215 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
220 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
223 f->value.function.name
224 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
230 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
232 f->ts.type = BT_REAL;
233 f->ts.kind = x->ts.kind;
234 f->value.function.name
235 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
241 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
243 f->ts.type = i->ts.type;
244 f->ts.kind = gfc_kind_max (i, j);
246 if (i->ts.kind != j->ts.kind)
248 if (i->ts.kind == gfc_kind_max (i, j))
249 gfc_convert_type (j, &i->ts, 2);
251 gfc_convert_type (i, &j->ts, 2);
254 f->value.function.name
255 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
260 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
265 f->ts.type = a->ts.type;
266 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
268 if (a->ts.kind != f->ts.kind)
270 ts.type = f->ts.type;
271 ts.kind = f->ts.kind;
272 gfc_convert_type (a, &ts, 2);
274 /* The resolved name is only used for specific intrinsics where
275 the return kind is the same as the arg kind. */
276 f->value.function.name
277 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
282 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
284 gfc_resolve_aint (f, a, NULL);
289 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
295 gfc_resolve_dim_arg (dim);
296 f->rank = mask->rank - 1;
297 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
300 f->value.function.name
301 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
307 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
312 f->ts.type = a->ts.type;
313 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
315 if (a->ts.kind != f->ts.kind)
317 ts.type = f->ts.type;
318 ts.kind = f->ts.kind;
319 gfc_convert_type (a, &ts, 2);
322 /* The resolved name is only used for specific intrinsics where
323 the return kind is the same as the arg kind. */
324 f->value.function.name
325 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
331 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
333 gfc_resolve_anint (f, a, NULL);
338 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
344 gfc_resolve_dim_arg (dim);
345 f->rank = mask->rank - 1;
346 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
349 f->value.function.name
350 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
356 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
359 f->value.function.name
360 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
364 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
367 f->value.function.name
368 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
373 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
376 f->value.function.name
377 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
381 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
384 f->value.function.name
385 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
390 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
393 f->value.function.name
394 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
399 /* Resolve the BESYN and BESJN intrinsics. */
402 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
408 if (n->ts.kind != gfc_c_int_kind)
410 ts.type = BT_INTEGER;
411 ts.kind = gfc_c_int_kind;
412 gfc_convert_type (n, &ts, 2);
414 f->value.function.name = gfc_get_string ("<intrinsic>");
419 gfc_resolve_bessel_n2 (gfc_expr *f, gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
426 if (n1->expr_type == EXPR_CONSTANT && n2->expr_type == EXPR_CONSTANT)
428 f->shape = gfc_get_shape (1);
429 mpz_init (f->shape[0]);
430 mpz_sub (f->shape[0], n2->value.integer, n1->value.integer);
431 mpz_add_ui (f->shape[0], f->shape[0], 1);
434 if (n1->ts.kind != gfc_c_int_kind)
436 ts.type = BT_INTEGER;
437 ts.kind = gfc_c_int_kind;
438 gfc_convert_type (n1, &ts, 2);
441 if (n2->ts.kind != gfc_c_int_kind)
443 ts.type = BT_INTEGER;
444 ts.kind = gfc_c_int_kind;
445 gfc_convert_type (n2, &ts, 2);
448 if (f->value.function.isym->id == GFC_ISYM_JN2)
449 f->value.function.name = gfc_get_string (PREFIX ("bessel_jn_r%d"),
452 f->value.function.name = gfc_get_string (PREFIX ("bessel_yn_r%d"),
458 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
460 f->ts.type = BT_LOGICAL;
461 f->ts.kind = gfc_default_logical_kind;
462 f->value.function.name
463 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
468 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
470 f->ts.type = BT_INTEGER;
471 f->ts.kind = (kind == NULL)
472 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
473 f->value.function.name
474 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
475 gfc_type_letter (a->ts.type), a->ts.kind);
480 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
482 gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d");
487 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
489 f->ts.type = BT_INTEGER;
490 f->ts.kind = gfc_default_integer_kind;
491 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
496 gfc_resolve_chdir_sub (gfc_code *c)
501 if (c->ext.actual->next->expr != NULL)
502 kind = c->ext.actual->next->expr->ts.kind;
504 kind = gfc_default_integer_kind;
506 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
507 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
512 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
513 gfc_expr *mode ATTRIBUTE_UNUSED)
515 f->ts.type = BT_INTEGER;
516 f->ts.kind = gfc_c_int_kind;
517 f->value.function.name = PREFIX ("chmod_func");
522 gfc_resolve_chmod_sub (gfc_code *c)
527 if (c->ext.actual->next->next->expr != NULL)
528 kind = c->ext.actual->next->next->expr->ts.kind;
530 kind = gfc_default_integer_kind;
532 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
533 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
538 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
540 f->ts.type = BT_COMPLEX;
541 f->ts.kind = (kind == NULL)
542 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
545 f->value.function.name
546 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
547 gfc_type_letter (x->ts.type), x->ts.kind);
549 f->value.function.name
550 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
551 gfc_type_letter (x->ts.type), x->ts.kind,
552 gfc_type_letter (y->ts.type), y->ts.kind);
557 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
559 gfc_resolve_cmplx (f, x, y, gfc_get_int_expr (gfc_default_integer_kind, NULL,
560 gfc_default_double_kind));
565 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
569 if (x->ts.type == BT_INTEGER)
571 if (y->ts.type == BT_INTEGER)
572 kind = gfc_default_real_kind;
578 if (y->ts.type == BT_REAL)
579 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
584 f->ts.type = BT_COMPLEX;
586 f->value.function.name
587 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
588 gfc_type_letter (x->ts.type), x->ts.kind,
589 gfc_type_letter (y->ts.type), y->ts.kind);
594 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
597 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
602 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
605 f->value.function.name
606 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
611 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
614 f->value.function.name
615 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
620 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
622 f->ts.type = BT_INTEGER;
624 f->ts.kind = mpz_get_si (kind->value.integer);
626 f->ts.kind = gfc_default_integer_kind;
630 f->rank = mask->rank - 1;
631 gfc_resolve_dim_arg (dim);
632 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
635 resolve_mask_arg (mask);
637 f->value.function.name
638 = gfc_get_string (PREFIX ("count_%d_%c"), f->ts.kind,
639 gfc_type_letter (mask->ts.type));
644 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
649 if (array->ts.type == BT_CHARACTER && array->ref)
650 gfc_resolve_substring_charlen (array);
653 f->rank = array->rank;
654 f->shape = gfc_copy_shape (array->shape, array->rank);
661 /* If dim kind is greater than default integer we need to use the larger. */
662 m = gfc_default_integer_kind;
664 m = m < dim->ts.kind ? dim->ts.kind : m;
666 /* Convert shift to at least m, so we don't need
667 kind=1 and kind=2 versions of the library functions. */
668 if (shift->ts.kind < m)
672 ts.type = BT_INTEGER;
674 gfc_convert_type_warn (shift, &ts, 2, 0);
679 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
680 && dim->symtree->n.sym->attr.optional)
682 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
683 dim->representation.length = shift->ts.kind;
687 gfc_resolve_dim_arg (dim);
688 /* Convert dim to shift's kind to reduce variations. */
689 if (dim->ts.kind != shift->ts.kind)
690 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
694 if (array->ts.type == BT_CHARACTER)
696 if (array->ts.kind == gfc_default_character_kind)
697 f->value.function.name
698 = gfc_get_string (PREFIX ("cshift%d_%d_char"), n, shift->ts.kind);
700 f->value.function.name
701 = gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n, shift->ts.kind,
705 f->value.function.name
706 = gfc_get_string (PREFIX ("cshift%d_%d"), n, shift->ts.kind);
711 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
716 f->ts.type = BT_CHARACTER;
717 f->ts.kind = gfc_default_character_kind;
719 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
720 if (time->ts.kind != 8)
722 ts.type = BT_INTEGER;
726 gfc_convert_type (time, &ts, 2);
729 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
734 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
736 f->ts.type = BT_REAL;
737 f->ts.kind = gfc_default_double_kind;
738 f->value.function.name
739 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
744 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
746 f->ts.type = a->ts.type;
748 f->ts.kind = gfc_kind_max (a,p);
750 f->ts.kind = a->ts.kind;
752 if (p != NULL && a->ts.kind != p->ts.kind)
754 if (a->ts.kind == gfc_kind_max (a,p))
755 gfc_convert_type (p, &a->ts, 2);
757 gfc_convert_type (a, &p->ts, 2);
760 f->value.function.name
761 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
766 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
770 temp.expr_type = EXPR_OP;
771 gfc_clear_ts (&temp.ts);
772 temp.value.op.op = INTRINSIC_NONE;
773 temp.value.op.op1 = a;
774 temp.value.op.op2 = b;
775 gfc_type_convert_binary (&temp, 1);
777 f->value.function.name
778 = gfc_get_string (PREFIX ("dot_product_%c%d"),
779 gfc_type_letter (f->ts.type), f->ts.kind);
784 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
785 gfc_expr *b ATTRIBUTE_UNUSED)
787 f->ts.kind = gfc_default_double_kind;
788 f->ts.type = BT_REAL;
789 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
794 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
795 gfc_expr *boundary, gfc_expr *dim)
799 if (array->ts.type == BT_CHARACTER && array->ref)
800 gfc_resolve_substring_charlen (array);
803 f->rank = array->rank;
804 f->shape = gfc_copy_shape (array->shape, array->rank);
809 if (boundary && boundary->rank > 0)
812 /* If dim kind is greater than default integer we need to use the larger. */
813 m = gfc_default_integer_kind;
815 m = m < dim->ts.kind ? dim->ts.kind : m;
817 /* Convert shift to at least m, so we don't need
818 kind=1 and kind=2 versions of the library functions. */
819 if (shift->ts.kind < m)
823 ts.type = BT_INTEGER;
825 gfc_convert_type_warn (shift, &ts, 2, 0);
830 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
831 && dim->symtree->n.sym->attr.optional)
833 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
834 dim->representation.length = shift->ts.kind;
838 gfc_resolve_dim_arg (dim);
839 /* Convert dim to shift's kind to reduce variations. */
840 if (dim->ts.kind != shift->ts.kind)
841 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
845 if (array->ts.type == BT_CHARACTER)
847 if (array->ts.kind == gfc_default_character_kind)
848 f->value.function.name
849 = gfc_get_string (PREFIX ("eoshift%d_%d_char"), n, shift->ts.kind);
851 f->value.function.name
852 = gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n, shift->ts.kind,
856 f->value.function.name
857 = gfc_get_string (PREFIX ("eoshift%d_%d"), n, shift->ts.kind);
862 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
865 f->value.function.name
866 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
871 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
873 f->ts.type = BT_INTEGER;
874 f->ts.kind = gfc_default_integer_kind;
875 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
879 /* Resolve the EXTENDS_TYPE_OF intrinsic function. */
882 gfc_resolve_extends_type_of (gfc_expr *f, gfc_expr *a, gfc_expr *mo)
887 /* Prevent double resolution. */
888 if (f->ts.type == BT_LOGICAL)
891 /* Replace the first argument with the corresponding vtab. */
892 if (a->ts.type == BT_CLASS)
893 gfc_add_component_ref (a, "$vptr");
894 else if (a->ts.type == BT_DERIVED)
896 vtab = gfc_find_derived_vtab (a->ts.u.derived);
897 /* Clear the old expr. */
898 gfc_free_ref_list (a->ref);
899 memset (a, '\0', sizeof (gfc_expr));
900 /* Construct a new one. */
901 a->expr_type = EXPR_VARIABLE;
902 st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
907 /* Replace the second argument with the corresponding vtab. */
908 if (mo->ts.type == BT_CLASS)
909 gfc_add_component_ref (mo, "$vptr");
910 else if (mo->ts.type == BT_DERIVED)
912 vtab = gfc_find_derived_vtab (mo->ts.u.derived);
913 /* Clear the old expr. */
914 gfc_free_ref_list (mo->ref);
915 memset (mo, '\0', sizeof (gfc_expr));
916 /* Construct a new one. */
917 mo->expr_type = EXPR_VARIABLE;
918 st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
923 f->ts.type = BT_LOGICAL;
926 f->value.function.isym->formal->ts = a->ts;
927 f->value.function.isym->formal->next->ts = mo->ts;
929 /* Call library function. */
930 f->value.function.name = gfc_get_string (PREFIX ("is_extension_of"));
935 gfc_resolve_fdate (gfc_expr *f)
937 f->ts.type = BT_CHARACTER;
938 f->ts.kind = gfc_default_character_kind;
939 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
944 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
946 f->ts.type = BT_INTEGER;
947 f->ts.kind = (kind == NULL)
948 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
949 f->value.function.name
950 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
951 gfc_type_letter (a->ts.type), a->ts.kind);
956 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
958 f->ts.type = BT_INTEGER;
959 f->ts.kind = gfc_default_integer_kind;
960 if (n->ts.kind != f->ts.kind)
961 gfc_convert_type (n, &f->ts, 2);
962 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
967 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
970 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
974 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
977 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
980 f->value.function.name = gfc_get_string ("<intrinsic>");
985 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
988 f->value.function.name
989 = gfc_get_string ("__tgamma_%d", x->ts.kind);
994 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
996 f->ts.type = BT_INTEGER;
998 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
1003 gfc_resolve_getgid (gfc_expr *f)
1005 f->ts.type = BT_INTEGER;
1007 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
1012 gfc_resolve_getpid (gfc_expr *f)
1014 f->ts.type = BT_INTEGER;
1016 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
1021 gfc_resolve_getuid (gfc_expr *f)
1023 f->ts.type = BT_INTEGER;
1025 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
1030 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
1032 f->ts.type = BT_INTEGER;
1034 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
1039 gfc_resolve_hypot (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
1042 f->value.function.name = gfc_get_string ("__hypot_r%d", x->ts.kind);
1047 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1049 /* If the kind of i and j are different, then g77 cross-promoted the
1050 kinds to the largest value. The Fortran 95 standard requires the
1052 if (i->ts.kind != j->ts.kind)
1054 if (i->ts.kind == gfc_kind_max (i, j))
1055 gfc_convert_type (j, &i->ts, 2);
1057 gfc_convert_type (i, &j->ts, 2);
1061 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
1066 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1069 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
1074 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
1075 gfc_expr *len ATTRIBUTE_UNUSED)
1078 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
1083 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1086 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
1091 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1093 f->ts.type = BT_INTEGER;
1095 f->ts.kind = mpz_get_si (kind->value.integer);
1097 f->ts.kind = gfc_default_integer_kind;
1098 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1103 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1105 f->ts.type = BT_INTEGER;
1107 f->ts.kind = mpz_get_si (kind->value.integer);
1109 f->ts.kind = gfc_default_integer_kind;
1110 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1115 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
1117 gfc_resolve_nint (f, a, NULL);
1122 gfc_resolve_ierrno (gfc_expr *f)
1124 f->ts.type = BT_INTEGER;
1125 f->ts.kind = gfc_default_integer_kind;
1126 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
1131 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1133 /* If the kind of i and j are different, then g77 cross-promoted the
1134 kinds to the largest value. The Fortran 95 standard requires the
1136 if (i->ts.kind != j->ts.kind)
1138 if (i->ts.kind == gfc_kind_max (i, j))
1139 gfc_convert_type (j, &i->ts, 2);
1141 gfc_convert_type (i, &j->ts, 2);
1145 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
1150 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1152 /* If the kind of i and j are different, then g77 cross-promoted the
1153 kinds to the largest value. The Fortran 95 standard requires the
1155 if (i->ts.kind != j->ts.kind)
1157 if (i->ts.kind == gfc_kind_max (i, j))
1158 gfc_convert_type (j, &i->ts, 2);
1160 gfc_convert_type (i, &j->ts, 2);
1164 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
1169 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
1170 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
1176 f->ts.type = BT_INTEGER;
1178 f->ts.kind = mpz_get_si (kind->value.integer);
1180 f->ts.kind = gfc_default_integer_kind;
1182 if (back && back->ts.kind != gfc_default_integer_kind)
1184 ts.type = BT_LOGICAL;
1185 ts.kind = gfc_default_integer_kind;
1186 ts.u.derived = NULL;
1188 gfc_convert_type (back, &ts, 2);
1191 f->value.function.name
1192 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
1197 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1199 f->ts.type = BT_INTEGER;
1200 f->ts.kind = (kind == NULL)
1201 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1202 f->value.function.name
1203 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1204 gfc_type_letter (a->ts.type), a->ts.kind);
1209 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1211 f->ts.type = BT_INTEGER;
1213 f->value.function.name
1214 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1215 gfc_type_letter (a->ts.type), a->ts.kind);
1220 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
1222 f->ts.type = BT_INTEGER;
1224 f->value.function.name
1225 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1226 gfc_type_letter (a->ts.type), a->ts.kind);
1231 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1233 f->ts.type = BT_INTEGER;
1235 f->value.function.name
1236 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1237 gfc_type_letter (a->ts.type), a->ts.kind);
1242 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1247 f->ts.type = BT_LOGICAL;
1248 f->ts.kind = gfc_default_integer_kind;
1249 if (u->ts.kind != gfc_c_int_kind)
1251 ts.type = BT_INTEGER;
1252 ts.kind = gfc_c_int_kind;
1253 ts.u.derived = NULL;
1255 gfc_convert_type (u, &ts, 2);
1258 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1263 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1266 f->value.function.name
1267 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1272 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1275 f->value.function.name
1276 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1281 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1284 f->value.function.name
1285 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1290 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1294 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1297 f->value.function.name
1298 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1303 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1304 gfc_expr *s ATTRIBUTE_UNUSED)
1306 f->ts.type = BT_INTEGER;
1307 f->ts.kind = gfc_default_integer_kind;
1308 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1313 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1315 resolve_bound (f, array, dim, kind, "__lbound", false);
1320 gfc_resolve_lcobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1322 resolve_bound (f, array, dim, kind, "__lcobound", true);
1327 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1329 f->ts.type = BT_INTEGER;
1331 f->ts.kind = mpz_get_si (kind->value.integer);
1333 f->ts.kind = gfc_default_integer_kind;
1334 f->value.function.name
1335 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1336 gfc_default_integer_kind);
1341 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1343 f->ts.type = BT_INTEGER;
1345 f->ts.kind = mpz_get_si (kind->value.integer);
1347 f->ts.kind = gfc_default_integer_kind;
1348 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1353 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1356 f->value.function.name
1357 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1362 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1363 gfc_expr *p2 ATTRIBUTE_UNUSED)
1365 f->ts.type = BT_INTEGER;
1366 f->ts.kind = gfc_default_integer_kind;
1367 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1372 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1374 f->ts.type= BT_INTEGER;
1375 f->ts.kind = gfc_index_integer_kind;
1376 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1381 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1384 f->value.function.name
1385 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1390 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1393 f->value.function.name
1394 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1400 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1402 f->ts.type = BT_LOGICAL;
1403 f->ts.kind = (kind == NULL)
1404 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1407 f->value.function.name
1408 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1409 gfc_type_letter (a->ts.type), a->ts.kind);
1414 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1416 if (size->ts.kind < gfc_index_integer_kind)
1421 ts.type = BT_INTEGER;
1422 ts.kind = gfc_index_integer_kind;
1423 gfc_convert_type_warn (size, &ts, 2, 0);
1426 f->ts.type = BT_INTEGER;
1427 f->ts.kind = gfc_index_integer_kind;
1428 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1433 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1437 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1439 f->ts.type = BT_LOGICAL;
1440 f->ts.kind = gfc_default_logical_kind;
1444 temp.expr_type = EXPR_OP;
1445 gfc_clear_ts (&temp.ts);
1446 temp.value.op.op = INTRINSIC_NONE;
1447 temp.value.op.op1 = a;
1448 temp.value.op.op2 = b;
1449 gfc_type_convert_binary (&temp, 1);
1453 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1455 if (a->rank == 2 && b->rank == 2)
1457 if (a->shape && b->shape)
1459 f->shape = gfc_get_shape (f->rank);
1460 mpz_init_set (f->shape[0], a->shape[0]);
1461 mpz_init_set (f->shape[1], b->shape[1]);
1464 else if (a->rank == 1)
1468 f->shape = gfc_get_shape (f->rank);
1469 mpz_init_set (f->shape[0], b->shape[1]);
1474 /* b->rank == 1 and a->rank == 2 here, all other cases have
1475 been caught in check.c. */
1478 f->shape = gfc_get_shape (f->rank);
1479 mpz_init_set (f->shape[0], a->shape[0]);
1483 f->value.function.name
1484 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1490 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1492 gfc_actual_arglist *a;
1494 f->ts.type = args->expr->ts.type;
1495 f->ts.kind = args->expr->ts.kind;
1496 /* Find the largest type kind. */
1497 for (a = args->next; a; a = a->next)
1499 if (a->expr->ts.kind > f->ts.kind)
1500 f->ts.kind = a->expr->ts.kind;
1503 /* Convert all parameters to the required kind. */
1504 for (a = args; a; a = a->next)
1506 if (a->expr->ts.kind != f->ts.kind)
1507 gfc_convert_type (a->expr, &f->ts, 2);
1510 f->value.function.name
1511 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1516 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1518 gfc_resolve_minmax ("__max_%c%d", f, args);
1523 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1529 f->ts.type = BT_INTEGER;
1530 f->ts.kind = gfc_default_integer_kind;
1535 f->shape = gfc_get_shape (1);
1536 mpz_init_set_si (f->shape[0], array->rank);
1540 f->rank = array->rank - 1;
1541 gfc_resolve_dim_arg (dim);
1542 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1544 idim = (int) mpz_get_si (dim->value.integer);
1545 f->shape = gfc_get_shape (f->rank);
1546 for (i = 0, j = 0; i < f->rank; i++, j++)
1548 if (i == (idim - 1))
1550 mpz_init_set (f->shape[i], array->shape[j]);
1557 if (mask->rank == 0)
1562 resolve_mask_arg (mask);
1567 f->value.function.name
1568 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1569 gfc_type_letter (array->ts.type), array->ts.kind);
1574 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1584 f->rank = array->rank - 1;
1585 gfc_resolve_dim_arg (dim);
1587 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1589 idim = (int) mpz_get_si (dim->value.integer);
1590 f->shape = gfc_get_shape (f->rank);
1591 for (i = 0, j = 0; i < f->rank; i++, j++)
1593 if (i == (idim - 1))
1595 mpz_init_set (f->shape[i], array->shape[j]);
1602 if (mask->rank == 0)
1607 resolve_mask_arg (mask);
1612 f->value.function.name
1613 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1614 gfc_type_letter (array->ts.type), array->ts.kind);
1619 gfc_resolve_mclock (gfc_expr *f)
1621 f->ts.type = BT_INTEGER;
1623 f->value.function.name = PREFIX ("mclock");
1628 gfc_resolve_mclock8 (gfc_expr *f)
1630 f->ts.type = BT_INTEGER;
1632 f->value.function.name = PREFIX ("mclock8");
1637 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1638 gfc_expr *fsource ATTRIBUTE_UNUSED,
1639 gfc_expr *mask ATTRIBUTE_UNUSED)
1641 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1642 gfc_resolve_substring_charlen (tsource);
1644 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1645 gfc_resolve_substring_charlen (fsource);
1647 if (tsource->ts.type == BT_CHARACTER)
1648 check_charlen_present (tsource);
1650 f->ts = tsource->ts;
1651 f->value.function.name
1652 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1658 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1660 gfc_resolve_minmax ("__min_%c%d", f, args);
1665 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1671 f->ts.type = BT_INTEGER;
1672 f->ts.kind = gfc_default_integer_kind;
1677 f->shape = gfc_get_shape (1);
1678 mpz_init_set_si (f->shape[0], array->rank);
1682 f->rank = array->rank - 1;
1683 gfc_resolve_dim_arg (dim);
1684 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1686 idim = (int) mpz_get_si (dim->value.integer);
1687 f->shape = gfc_get_shape (f->rank);
1688 for (i = 0, j = 0; i < f->rank; i++, j++)
1690 if (i == (idim - 1))
1692 mpz_init_set (f->shape[i], array->shape[j]);
1699 if (mask->rank == 0)
1704 resolve_mask_arg (mask);
1709 f->value.function.name
1710 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1711 gfc_type_letter (array->ts.type), array->ts.kind);
1716 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1726 f->rank = array->rank - 1;
1727 gfc_resolve_dim_arg (dim);
1729 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1731 idim = (int) mpz_get_si (dim->value.integer);
1732 f->shape = gfc_get_shape (f->rank);
1733 for (i = 0, j = 0; i < f->rank; i++, j++)
1735 if (i == (idim - 1))
1737 mpz_init_set (f->shape[i], array->shape[j]);
1744 if (mask->rank == 0)
1749 resolve_mask_arg (mask);
1754 f->value.function.name
1755 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1756 gfc_type_letter (array->ts.type), array->ts.kind);
1761 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1763 f->ts.type = a->ts.type;
1765 f->ts.kind = gfc_kind_max (a,p);
1767 f->ts.kind = a->ts.kind;
1769 if (p != NULL && a->ts.kind != p->ts.kind)
1771 if (a->ts.kind == gfc_kind_max (a,p))
1772 gfc_convert_type (p, &a->ts, 2);
1774 gfc_convert_type (a, &p->ts, 2);
1777 f->value.function.name
1778 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1783 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1785 f->ts.type = a->ts.type;
1787 f->ts.kind = gfc_kind_max (a,p);
1789 f->ts.kind = a->ts.kind;
1791 if (p != NULL && a->ts.kind != p->ts.kind)
1793 if (a->ts.kind == gfc_kind_max (a,p))
1794 gfc_convert_type (p, &a->ts, 2);
1796 gfc_convert_type (a, &p->ts, 2);
1799 f->value.function.name
1800 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1805 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1807 if (p->ts.kind != a->ts.kind)
1808 gfc_convert_type (p, &a->ts, 2);
1811 f->value.function.name
1812 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1817 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1819 f->ts.type = BT_INTEGER;
1820 f->ts.kind = (kind == NULL)
1821 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1822 f->value.function.name
1823 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1828 gfc_resolve_norm2 (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1834 f->rank = array->rank - 1;
1835 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
1836 gfc_resolve_dim_arg (dim);
1839 f->value.function.name
1840 = gfc_get_string (PREFIX ("norm2_r%d"), array->ts.kind);
1845 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1848 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1853 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1855 f->ts.type = i->ts.type;
1856 f->ts.kind = gfc_kind_max (i, j);
1858 if (i->ts.kind != j->ts.kind)
1860 if (i->ts.kind == gfc_kind_max (i, j))
1861 gfc_convert_type (j, &i->ts, 2);
1863 gfc_convert_type (i, &j->ts, 2);
1866 f->value.function.name
1867 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1872 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1873 gfc_expr *vector ATTRIBUTE_UNUSED)
1875 if (array->ts.type == BT_CHARACTER && array->ref)
1876 gfc_resolve_substring_charlen (array);
1881 resolve_mask_arg (mask);
1883 if (mask->rank != 0)
1885 if (array->ts.type == BT_CHARACTER)
1886 f->value.function.name
1887 = array->ts.kind == 1 ? PREFIX ("pack_char")
1889 (PREFIX ("pack_char%d"),
1892 f->value.function.name = PREFIX ("pack");
1896 if (array->ts.type == BT_CHARACTER)
1897 f->value.function.name
1898 = array->ts.kind == 1 ? PREFIX ("pack_s_char")
1900 (PREFIX ("pack_s_char%d"),
1903 f->value.function.name = PREFIX ("pack_s");
1909 gfc_resolve_parity (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1915 f->rank = array->rank - 1;
1916 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
1917 gfc_resolve_dim_arg (dim);
1920 resolve_mask_arg (array);
1922 f->value.function.name
1923 = gfc_get_string (PREFIX ("parity_l%d"), array->ts.kind);
1928 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1937 f->rank = array->rank - 1;
1938 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
1939 gfc_resolve_dim_arg (dim);
1944 if (mask->rank == 0)
1949 resolve_mask_arg (mask);
1954 f->value.function.name
1955 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1956 gfc_type_letter (array->ts.type), array->ts.kind);
1961 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1963 f->ts.type = BT_REAL;
1966 f->ts.kind = mpz_get_si (kind->value.integer);
1968 f->ts.kind = (a->ts.type == BT_COMPLEX)
1969 ? a->ts.kind : gfc_default_real_kind;
1971 f->value.function.name
1972 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1973 gfc_type_letter (a->ts.type), a->ts.kind);
1978 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1980 f->ts.type = BT_REAL;
1981 f->ts.kind = a->ts.kind;
1982 f->value.function.name
1983 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1984 gfc_type_letter (a->ts.type), a->ts.kind);
1989 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1990 gfc_expr *p2 ATTRIBUTE_UNUSED)
1992 f->ts.type = BT_INTEGER;
1993 f->ts.kind = gfc_default_integer_kind;
1994 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1999 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
2000 gfc_expr *ncopies ATTRIBUTE_UNUSED)
2002 f->ts.type = BT_CHARACTER;
2003 f->ts.kind = string->ts.kind;
2004 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
2009 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
2010 gfc_expr *pad ATTRIBUTE_UNUSED,
2011 gfc_expr *order ATTRIBUTE_UNUSED)
2017 if (source->ts.type == BT_CHARACTER && source->ref)
2018 gfc_resolve_substring_charlen (source);
2022 gfc_array_size (shape, &rank);
2023 f->rank = mpz_get_si (rank);
2025 switch (source->ts.type)
2032 kind = source->ts.kind;
2046 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
2047 f->value.function.name
2048 = gfc_get_string (PREFIX ("reshape_%c%d"),
2049 gfc_type_letter (source->ts.type),
2051 else if (source->ts.type == BT_CHARACTER)
2052 f->value.function.name = gfc_get_string (PREFIX ("reshape_char%d"),
2055 f->value.function.name
2056 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
2060 f->value.function.name = (source->ts.type == BT_CHARACTER
2061 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
2065 /* TODO: Make this work with a constant ORDER parameter. */
2066 if (shape->expr_type == EXPR_ARRAY
2067 && gfc_is_constant_expr (shape)
2071 f->shape = gfc_get_shape (f->rank);
2072 c = gfc_constructor_first (shape->value.constructor);
2073 for (i = 0; i < f->rank; i++)
2075 mpz_init_set (f->shape[i], c->expr->value.integer);
2076 c = gfc_constructor_next (c);
2080 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
2081 so many runtime variations. */
2082 if (shape->ts.kind != gfc_index_integer_kind)
2084 gfc_typespec ts = shape->ts;
2085 ts.kind = gfc_index_integer_kind;
2086 gfc_convert_type_warn (shape, &ts, 2, 0);
2088 if (order && order->ts.kind != gfc_index_integer_kind)
2089 gfc_convert_type_warn (order, &shape->ts, 2, 0);
2094 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
2097 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
2102 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED)
2105 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
2110 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
2111 gfc_expr *set ATTRIBUTE_UNUSED,
2112 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2114 f->ts.type = BT_INTEGER;
2116 f->ts.kind = mpz_get_si (kind->value.integer);
2118 f->ts.kind = gfc_default_integer_kind;
2119 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
2124 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
2127 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
2132 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x,
2133 gfc_expr *i ATTRIBUTE_UNUSED)
2136 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
2141 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
2143 f->ts.type = BT_INTEGER;
2144 f->ts.kind = gfc_default_integer_kind;
2146 f->shape = gfc_get_shape (1);
2147 mpz_init_set_ui (f->shape[0], array->rank);
2148 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
2153 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
2156 f->value.function.name
2157 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
2162 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
2164 f->ts.type = BT_INTEGER;
2165 f->ts.kind = gfc_c_int_kind;
2167 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2168 if (handler->ts.type == BT_INTEGER)
2170 if (handler->ts.kind != gfc_c_int_kind)
2171 gfc_convert_type (handler, &f->ts, 2);
2172 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
2175 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
2177 if (number->ts.kind != gfc_c_int_kind)
2178 gfc_convert_type (number, &f->ts, 2);
2183 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
2186 f->value.function.name
2187 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2192 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
2195 f->value.function.name
2196 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2201 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2202 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
2204 f->ts.type = BT_INTEGER;
2206 f->ts.kind = mpz_get_si (kind->value.integer);
2208 f->ts.kind = gfc_default_integer_kind;
2213 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
2216 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
2221 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2224 if (source->ts.type == BT_CHARACTER && source->ref)
2225 gfc_resolve_substring_charlen (source);
2227 if (source->ts.type == BT_CHARACTER)
2228 check_charlen_present (source);
2231 f->rank = source->rank + 1;
2232 if (source->rank == 0)
2234 if (source->ts.type == BT_CHARACTER)
2235 f->value.function.name
2236 = source->ts.kind == 1 ? PREFIX ("spread_char_scalar")
2238 (PREFIX ("spread_char%d_scalar"),
2241 f->value.function.name = PREFIX ("spread_scalar");
2245 if (source->ts.type == BT_CHARACTER)
2246 f->value.function.name
2247 = source->ts.kind == 1 ? PREFIX ("spread_char")
2249 (PREFIX ("spread_char%d"),
2252 f->value.function.name = PREFIX ("spread");
2255 if (dim && gfc_is_constant_expr (dim)
2256 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2259 idim = mpz_get_ui (dim->value.integer);
2260 f->shape = gfc_get_shape (f->rank);
2261 for (i = 0; i < (idim - 1); i++)
2262 mpz_init_set (f->shape[i], source->shape[i]);
2264 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2266 for (i = idim; i < f->rank ; i++)
2267 mpz_init_set (f->shape[i], source->shape[i-1]);
2271 gfc_resolve_dim_arg (dim);
2272 gfc_resolve_index (ncopies, 1);
2277 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2280 f->value.function.name
2281 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2285 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2288 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2289 gfc_expr *a ATTRIBUTE_UNUSED)
2291 f->ts.type = BT_INTEGER;
2292 f->ts.kind = gfc_default_integer_kind;
2293 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2298 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2299 gfc_expr *a ATTRIBUTE_UNUSED)
2301 f->ts.type = BT_INTEGER;
2302 f->ts.kind = gfc_default_integer_kind;
2303 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2308 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2310 f->ts.type = BT_INTEGER;
2311 f->ts.kind = gfc_default_integer_kind;
2312 if (n->ts.kind != f->ts.kind)
2313 gfc_convert_type (n, &f->ts, 2);
2315 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2320 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2325 f->ts.type = BT_INTEGER;
2326 f->ts.kind = gfc_c_int_kind;
2327 if (u->ts.kind != gfc_c_int_kind)
2329 ts.type = BT_INTEGER;
2330 ts.kind = gfc_c_int_kind;
2331 ts.u.derived = NULL;
2333 gfc_convert_type (u, &ts, 2);
2336 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2341 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2343 f->ts.type = BT_INTEGER;
2344 f->ts.kind = gfc_c_int_kind;
2345 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2350 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2355 f->ts.type = BT_INTEGER;
2356 f->ts.kind = gfc_c_int_kind;
2357 if (u->ts.kind != gfc_c_int_kind)
2359 ts.type = BT_INTEGER;
2360 ts.kind = gfc_c_int_kind;
2361 ts.u.derived = NULL;
2363 gfc_convert_type (u, &ts, 2);
2366 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2371 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2373 f->ts.type = BT_INTEGER;
2374 f->ts.kind = gfc_c_int_kind;
2375 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2380 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2385 f->ts.type = BT_INTEGER;
2386 f->ts.kind = gfc_index_integer_kind;
2387 if (u->ts.kind != gfc_c_int_kind)
2389 ts.type = BT_INTEGER;
2390 ts.kind = gfc_c_int_kind;
2391 ts.u.derived = NULL;
2393 gfc_convert_type (u, &ts, 2);
2396 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2401 gfc_resolve_storage_size (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
2404 f->ts.type = BT_INTEGER;
2406 f->ts.kind = mpz_get_si (kind->value.integer);
2408 f->ts.kind = gfc_default_integer_kind;
2413 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2421 if (mask->rank == 0)
2426 resolve_mask_arg (mask);
2433 f->rank = array->rank - 1;
2434 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
2435 gfc_resolve_dim_arg (dim);
2438 f->value.function.name
2439 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2440 gfc_type_letter (array->ts.type), array->ts.kind);
2445 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2446 gfc_expr *p2 ATTRIBUTE_UNUSED)
2448 f->ts.type = BT_INTEGER;
2449 f->ts.kind = gfc_default_integer_kind;
2450 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2454 /* Resolve the g77 compatibility function SYSTEM. */
2457 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2459 f->ts.type = BT_INTEGER;
2461 f->value.function.name = gfc_get_string (PREFIX ("system"));
2466 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2469 f->value.function.name
2470 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2475 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2478 f->value.function.name
2479 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2484 gfc_resolve_image_index (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2485 gfc_expr *sub ATTRIBUTE_UNUSED)
2487 static char this_image[] = "__image_index";
2488 f->ts.kind = gfc_default_integer_kind;
2489 f->value.function.name = this_image;
2494 gfc_resolve_this_image (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
2496 resolve_bound (f, array, dim, NULL, "__this_image", true);
2501 gfc_resolve_time (gfc_expr *f)
2503 f->ts.type = BT_INTEGER;
2505 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2510 gfc_resolve_time8 (gfc_expr *f)
2512 f->ts.type = BT_INTEGER;
2514 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2519 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2520 gfc_expr *mold, gfc_expr *size)
2522 /* TODO: Make this do something meaningful. */
2523 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2525 if (mold->ts.type == BT_CHARACTER
2526 && !mold->ts.u.cl->length
2527 && gfc_is_constant_expr (mold))
2530 if (mold->expr_type == EXPR_CONSTANT)
2532 len = mold->value.character.length;
2533 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2538 gfc_constructor *c = gfc_constructor_first (mold->value.constructor);
2539 len = c->expr->value.character.length;
2540 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2547 if (size == NULL && mold->rank == 0)
2550 f->value.function.name = transfer0;
2555 f->value.function.name = transfer1;
2556 if (size && gfc_is_constant_expr (size))
2558 f->shape = gfc_get_shape (1);
2559 mpz_init_set (f->shape[0], size->value.integer);
2566 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2569 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2570 gfc_resolve_substring_charlen (matrix);
2576 f->shape = gfc_get_shape (2);
2577 mpz_init_set (f->shape[0], matrix->shape[1]);
2578 mpz_init_set (f->shape[1], matrix->shape[0]);
2581 switch (matrix->ts.kind)
2587 switch (matrix->ts.type)
2591 f->value.function.name
2592 = gfc_get_string (PREFIX ("transpose_%c%d"),
2593 gfc_type_letter (matrix->ts.type),
2599 /* Use the integer routines for real and logical cases. This
2600 assumes they all have the same alignment requirements. */
2601 f->value.function.name
2602 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2606 if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4)
2607 f->value.function.name = PREFIX ("transpose_char4");
2609 f->value.function.name = PREFIX ("transpose");
2615 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2616 ? PREFIX ("transpose_char")
2617 : PREFIX ("transpose"));
2624 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2626 f->ts.type = BT_CHARACTER;
2627 f->ts.kind = string->ts.kind;
2628 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2633 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2635 resolve_bound (f, array, dim, kind, "__ubound", false);
2640 gfc_resolve_ucobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2642 resolve_bound (f, array, dim, kind, "__ucobound", true);
2646 /* Resolve the g77 compatibility function UMASK. */
2649 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2651 f->ts.type = BT_INTEGER;
2652 f->ts.kind = n->ts.kind;
2653 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2657 /* Resolve the g77 compatibility function UNLINK. */
2660 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2662 f->ts.type = BT_INTEGER;
2664 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2669 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2674 f->ts.type = BT_CHARACTER;
2675 f->ts.kind = gfc_default_character_kind;
2677 if (unit->ts.kind != gfc_c_int_kind)
2679 ts.type = BT_INTEGER;
2680 ts.kind = gfc_c_int_kind;
2681 ts.u.derived = NULL;
2683 gfc_convert_type (unit, &ts, 2);
2686 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2691 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2692 gfc_expr *field ATTRIBUTE_UNUSED)
2694 if (vector->ts.type == BT_CHARACTER && vector->ref)
2695 gfc_resolve_substring_charlen (vector);
2698 f->rank = mask->rank;
2699 resolve_mask_arg (mask);
2701 if (vector->ts.type == BT_CHARACTER)
2703 if (vector->ts.kind == 1)
2704 f->value.function.name
2705 = gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0);
2707 f->value.function.name
2708 = gfc_get_string (PREFIX ("unpack%d_char%d"),
2709 field->rank > 0 ? 1 : 0, vector->ts.kind);
2712 f->value.function.name
2713 = gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0);
2718 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2719 gfc_expr *set ATTRIBUTE_UNUSED,
2720 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2722 f->ts.type = BT_INTEGER;
2724 f->ts.kind = mpz_get_si (kind->value.integer);
2726 f->ts.kind = gfc_default_integer_kind;
2727 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2732 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2734 f->ts.type = i->ts.type;
2735 f->ts.kind = gfc_kind_max (i, j);
2737 if (i->ts.kind != j->ts.kind)
2739 if (i->ts.kind == gfc_kind_max (i, j))
2740 gfc_convert_type (j, &i->ts, 2);
2742 gfc_convert_type (i, &j->ts, 2);
2745 f->value.function.name
2746 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2750 /* Intrinsic subroutine resolution. */
2753 gfc_resolve_alarm_sub (gfc_code *c)
2756 gfc_expr *seconds, *handler;
2760 seconds = c->ext.actual->expr;
2761 handler = c->ext.actual->next->expr;
2762 ts.type = BT_INTEGER;
2763 ts.kind = gfc_c_int_kind;
2765 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2766 In all cases, the status argument is of default integer kind
2767 (enforced in check.c) so that the function suffix is fixed. */
2768 if (handler->ts.type == BT_INTEGER)
2770 if (handler->ts.kind != gfc_c_int_kind)
2771 gfc_convert_type (handler, &ts, 2);
2772 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2773 gfc_default_integer_kind);
2776 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2777 gfc_default_integer_kind);
2779 if (seconds->ts.kind != gfc_c_int_kind)
2780 gfc_convert_type (seconds, &ts, 2);
2782 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2786 gfc_resolve_cpu_time (gfc_code *c)
2789 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2790 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2794 /* Create a formal arglist based on an actual one and set the INTENTs given. */
2796 static gfc_formal_arglist*
2797 create_formal_for_intents (gfc_actual_arglist* actual, const sym_intent* ints)
2799 gfc_formal_arglist* head;
2800 gfc_formal_arglist* tail;
2806 head = tail = gfc_get_formal_arglist ();
2807 for (i = 0; actual; actual = actual->next, tail = tail->next, ++i)
2811 sym = gfc_new_symbol ("dummyarg", NULL);
2812 sym->ts = actual->expr->ts;
2814 sym->attr.intent = ints[i];
2818 tail->next = gfc_get_formal_arglist ();
2826 gfc_resolve_mvbits (gfc_code *c)
2828 static const sym_intent INTENTS[] = {INTENT_IN, INTENT_IN, INTENT_IN,
2829 INTENT_INOUT, INTENT_IN};
2835 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2836 they will be converted so that they fit into a C int. */
2837 ts.type = BT_INTEGER;
2838 ts.kind = gfc_c_int_kind;
2839 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2840 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2841 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2842 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2843 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2844 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2846 /* TO and FROM are guaranteed to have the same kind parameter. */
2847 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2848 c->ext.actual->expr->ts.kind);
2849 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2850 /* Mark as elemental subroutine as this does not happen automatically. */
2851 c->resolved_sym->attr.elemental = 1;
2853 /* Create a dummy formal arglist so the INTENTs are known later for purpose
2854 of creating temporaries. */
2855 c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS);
2860 gfc_resolve_random_number (gfc_code *c)
2865 kind = c->ext.actual->expr->ts.kind;
2866 if (c->ext.actual->expr->rank == 0)
2867 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2869 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2871 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2876 gfc_resolve_random_seed (gfc_code *c)
2880 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2881 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2886 gfc_resolve_rename_sub (gfc_code *c)
2891 if (c->ext.actual->next->next->expr != NULL)
2892 kind = c->ext.actual->next->next->expr->ts.kind;
2894 kind = gfc_default_integer_kind;
2896 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2897 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2902 gfc_resolve_kill_sub (gfc_code *c)
2907 if (c->ext.actual->next->next->expr != NULL)
2908 kind = c->ext.actual->next->next->expr->ts.kind;
2910 kind = gfc_default_integer_kind;
2912 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2913 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2918 gfc_resolve_link_sub (gfc_code *c)
2923 if (c->ext.actual->next->next->expr != NULL)
2924 kind = c->ext.actual->next->next->expr->ts.kind;
2926 kind = gfc_default_integer_kind;
2928 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2929 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2934 gfc_resolve_symlnk_sub (gfc_code *c)
2939 if (c->ext.actual->next->next->expr != NULL)
2940 kind = c->ext.actual->next->next->expr->ts.kind;
2942 kind = gfc_default_integer_kind;
2944 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2945 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2949 /* G77 compatibility subroutines dtime() and etime(). */
2952 gfc_resolve_dtime_sub (gfc_code *c)
2955 name = gfc_get_string (PREFIX ("dtime_sub"));
2956 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2960 gfc_resolve_etime_sub (gfc_code *c)
2963 name = gfc_get_string (PREFIX ("etime_sub"));
2964 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2968 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2971 gfc_resolve_itime (gfc_code *c)
2974 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2975 gfc_default_integer_kind));
2979 gfc_resolve_idate (gfc_code *c)
2982 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2983 gfc_default_integer_kind));
2987 gfc_resolve_ltime (gfc_code *c)
2990 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2991 gfc_default_integer_kind));
2995 gfc_resolve_gmtime (gfc_code *c)
2998 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2999 gfc_default_integer_kind));
3003 /* G77 compatibility subroutine second(). */
3006 gfc_resolve_second_sub (gfc_code *c)
3009 name = gfc_get_string (PREFIX ("second_sub"));
3010 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3015 gfc_resolve_sleep_sub (gfc_code *c)
3020 if (c->ext.actual->expr != NULL)
3021 kind = c->ext.actual->expr->ts.kind;
3023 kind = gfc_default_integer_kind;
3025 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
3026 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3030 /* G77 compatibility function srand(). */
3033 gfc_resolve_srand (gfc_code *c)
3036 name = gfc_get_string (PREFIX ("srand"));
3037 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3041 /* Resolve the getarg intrinsic subroutine. */
3044 gfc_resolve_getarg (gfc_code *c)
3048 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
3053 ts.type = BT_INTEGER;
3054 ts.kind = gfc_default_integer_kind;
3056 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3059 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
3060 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3064 /* Resolve the getcwd intrinsic subroutine. */
3067 gfc_resolve_getcwd_sub (gfc_code *c)
3072 if (c->ext.actual->next->expr != NULL)
3073 kind = c->ext.actual->next->expr->ts.kind;
3075 kind = gfc_default_integer_kind;
3077 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
3078 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3082 /* Resolve the get_command intrinsic subroutine. */
3085 gfc_resolve_get_command (gfc_code *c)
3089 kind = gfc_default_integer_kind;
3090 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
3091 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3095 /* Resolve the get_command_argument intrinsic subroutine. */
3098 gfc_resolve_get_command_argument (gfc_code *c)
3102 kind = gfc_default_integer_kind;
3103 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
3104 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3108 /* Resolve the get_environment_variable intrinsic subroutine. */
3111 gfc_resolve_get_environment_variable (gfc_code *code)
3115 kind = gfc_default_integer_kind;
3116 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
3117 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3122 gfc_resolve_signal_sub (gfc_code *c)
3125 gfc_expr *number, *handler, *status;
3129 number = c->ext.actual->expr;
3130 handler = c->ext.actual->next->expr;
3131 status = c->ext.actual->next->next->expr;
3132 ts.type = BT_INTEGER;
3133 ts.kind = gfc_c_int_kind;
3135 /* handler can be either BT_INTEGER or BT_PROCEDURE */
3136 if (handler->ts.type == BT_INTEGER)
3138 if (handler->ts.kind != gfc_c_int_kind)
3139 gfc_convert_type (handler, &ts, 2);
3140 name = gfc_get_string (PREFIX ("signal_sub_int"));
3143 name = gfc_get_string (PREFIX ("signal_sub"));
3145 if (number->ts.kind != gfc_c_int_kind)
3146 gfc_convert_type (number, &ts, 2);
3147 if (status != NULL && status->ts.kind != gfc_c_int_kind)
3148 gfc_convert_type (status, &ts, 2);
3150 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3154 /* Resolve the SYSTEM intrinsic subroutine. */
3157 gfc_resolve_system_sub (gfc_code *c)
3160 name = gfc_get_string (PREFIX ("system_sub"));
3161 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3165 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
3168 gfc_resolve_system_clock (gfc_code *c)
3173 if (c->ext.actual->expr != NULL)
3174 kind = c->ext.actual->expr->ts.kind;
3175 else if (c->ext.actual->next->expr != NULL)
3176 kind = c->ext.actual->next->expr->ts.kind;
3177 else if (c->ext.actual->next->next->expr != NULL)
3178 kind = c->ext.actual->next->next->expr->ts.kind;
3180 kind = gfc_default_integer_kind;
3182 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
3183 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3187 /* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine. */
3189 gfc_resolve_execute_command_line (gfc_code *c)
3192 name = gfc_get_string (PREFIX ("execute_command_line_i%d"),
3193 gfc_default_integer_kind);
3194 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3198 /* Resolve the EXIT intrinsic subroutine. */
3201 gfc_resolve_exit (gfc_code *c)
3208 /* The STATUS argument has to be of default kind. If it is not,
3210 ts.type = BT_INTEGER;
3211 ts.kind = gfc_default_integer_kind;
3212 n = c->ext.actual->expr;
3213 if (n != NULL && n->ts.kind != ts.kind)
3214 gfc_convert_type (n, &ts, 2);
3216 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
3217 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3221 /* Resolve the FLUSH intrinsic subroutine. */
3224 gfc_resolve_flush (gfc_code *c)
3231 ts.type = BT_INTEGER;
3232 ts.kind = gfc_default_integer_kind;
3233 n = c->ext.actual->expr;
3234 if (n != NULL && n->ts.kind != ts.kind)
3235 gfc_convert_type (n, &ts, 2);
3237 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
3238 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3243 gfc_resolve_free (gfc_code *c)
3249 ts.type = BT_INTEGER;
3250 ts.kind = gfc_index_integer_kind;
3251 n = c->ext.actual->expr;
3252 if (n->ts.kind != ts.kind)
3253 gfc_convert_type (n, &ts, 2);
3255 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
3260 gfc_resolve_ctime_sub (gfc_code *c)
3265 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3266 if (c->ext.actual->expr->ts.kind != 8)
3268 ts.type = BT_INTEGER;
3270 ts.u.derived = NULL;
3272 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3275 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3280 gfc_resolve_fdate_sub (gfc_code *c)
3282 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3287 gfc_resolve_gerror (gfc_code *c)
3289 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3294 gfc_resolve_getlog (gfc_code *c)
3296 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3301 gfc_resolve_hostnm_sub (gfc_code *c)
3306 if (c->ext.actual->next->expr != NULL)
3307 kind = c->ext.actual->next->expr->ts.kind;
3309 kind = gfc_default_integer_kind;
3311 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3312 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3317 gfc_resolve_perror (gfc_code *c)
3319 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3322 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3325 gfc_resolve_stat_sub (gfc_code *c)
3328 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3329 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3334 gfc_resolve_lstat_sub (gfc_code *c)
3337 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3338 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3343 gfc_resolve_fstat_sub (gfc_code *c)
3349 u = c->ext.actual->expr;
3350 ts = &c->ext.actual->next->expr->ts;
3351 if (u->ts.kind != ts->kind)
3352 gfc_convert_type (u, ts, 2);
3353 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3354 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3359 gfc_resolve_fgetc_sub (gfc_code *c)
3366 u = c->ext.actual->expr;
3367 st = c->ext.actual->next->next->expr;
3369 if (u->ts.kind != gfc_c_int_kind)
3371 ts.type = BT_INTEGER;
3372 ts.kind = gfc_c_int_kind;
3373 ts.u.derived = NULL;
3375 gfc_convert_type (u, &ts, 2);
3379 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3381 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3383 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3388 gfc_resolve_fget_sub (gfc_code *c)
3393 st = c->ext.actual->next->expr;
3395 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3397 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3399 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3404 gfc_resolve_fputc_sub (gfc_code *c)
3411 u = c->ext.actual->expr;
3412 st = c->ext.actual->next->next->expr;
3414 if (u->ts.kind != gfc_c_int_kind)
3416 ts.type = BT_INTEGER;
3417 ts.kind = gfc_c_int_kind;
3418 ts.u.derived = NULL;
3420 gfc_convert_type (u, &ts, 2);
3424 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3426 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3428 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3433 gfc_resolve_fput_sub (gfc_code *c)
3438 st = c->ext.actual->next->expr;
3440 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3442 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3444 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3449 gfc_resolve_fseek_sub (gfc_code *c)
3457 unit = c->ext.actual->expr;
3458 offset = c->ext.actual->next->expr;
3459 whence = c->ext.actual->next->next->expr;
3461 if (unit->ts.kind != gfc_c_int_kind)
3463 ts.type = BT_INTEGER;
3464 ts.kind = gfc_c_int_kind;
3465 ts.u.derived = NULL;
3467 gfc_convert_type (unit, &ts, 2);
3470 if (offset->ts.kind != gfc_intio_kind)
3472 ts.type = BT_INTEGER;
3473 ts.kind = gfc_intio_kind;
3474 ts.u.derived = NULL;
3476 gfc_convert_type (offset, &ts, 2);
3479 if (whence->ts.kind != gfc_c_int_kind)
3481 ts.type = BT_INTEGER;
3482 ts.kind = gfc_c_int_kind;
3483 ts.u.derived = NULL;
3485 gfc_convert_type (whence, &ts, 2);
3488 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3492 gfc_resolve_ftell_sub (gfc_code *c)
3500 unit = c->ext.actual->expr;
3501 offset = c->ext.actual->next->expr;
3503 if (unit->ts.kind != gfc_c_int_kind)
3505 ts.type = BT_INTEGER;
3506 ts.kind = gfc_c_int_kind;
3507 ts.u.derived = NULL;
3509 gfc_convert_type (unit, &ts, 2);
3512 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3513 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3518 gfc_resolve_ttynam_sub (gfc_code *c)
3523 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3525 ts.type = BT_INTEGER;
3526 ts.kind = gfc_c_int_kind;
3527 ts.u.derived = NULL;
3529 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3532 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3536 /* Resolve the UMASK intrinsic subroutine. */
3539 gfc_resolve_umask_sub (gfc_code *c)
3544 if (c->ext.actual->next->expr != NULL)
3545 kind = c->ext.actual->next->expr->ts.kind;
3547 kind = gfc_default_integer_kind;
3549 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3550 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3553 /* Resolve the UNLINK intrinsic subroutine. */
3556 gfc_resolve_unlink_sub (gfc_code *c)
3561 if (c->ext.actual->next->expr != NULL)
3562 kind = c->ext.actual->next->expr->ts.kind;
3564 kind = gfc_default_integer_kind;
3566 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3567 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);