1 /* Intrinsic function resolution.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught & Katherine Holcomb
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* Assign name and types to intrinsic procedures. For functions, the
24 first argument to a resolution function is an expression pointer to
25 the original function node and the rest are pointers to the
26 arguments of the function call. For subroutines, a pointer to the
27 code node is passed. The result type and library subroutine name
28 are generally set according to the function arguments. */
32 #include "coretypes.h"
35 #include "intrinsic.h"
37 /* Given printf-like arguments, return a stable version of the result string.
39 We already have a working, optimized string hashing table in the form of
40 the identifier table. Reusing this table is likely not to be wasted,
41 since if the function name makes it to the gimple output of the frontend,
42 we'll have to create the identifier anyway. */
45 gfc_get_string (const char *format, ...)
51 va_start (ap, format);
52 vsnprintf (temp_name, sizeof (temp_name), format, ap);
54 temp_name[sizeof (temp_name) - 1] = 0;
56 ident = get_identifier (temp_name);
57 return IDENTIFIER_POINTER (ident);
60 /* MERGE and SPREAD need to have source charlen's present for passing
61 to the result expression. */
63 check_charlen_present (gfc_expr *source)
65 if (source->ts.cl == NULL)
67 source->ts.cl = gfc_get_charlen ();
68 source->ts.cl->next = gfc_current_ns->cl_list;
69 gfc_current_ns->cl_list = source->ts.cl;
72 if (source->expr_type == EXPR_CONSTANT)
74 source->ts.cl->length = gfc_int_expr (source->value.character.length);
77 else if (source->expr_type == EXPR_ARRAY)
79 source->ts.cl->length =
80 gfc_int_expr (source->value.constructor->expr->value.character.length);
85 /* Helper function for resolving the "mask" argument. */
88 resolve_mask_arg (gfc_expr *mask)
96 /* For the scalar case, coerce the mask to kind=4 unconditionally
97 (because this is the only kind we have a library function
100 if (mask->ts.kind != 4)
102 ts.type = BT_LOGICAL;
104 gfc_convert_type (mask, &ts, 2);
109 /* In the library, we access the mask with a GFC_LOGICAL_1
110 argument. No need to waste memory if we are about to create
111 a temporary array. */
112 if (mask->expr_type == EXPR_OP)
114 ts.type = BT_LOGICAL;
116 gfc_convert_type (mask, &ts, 2);
121 /********************** Resolution functions **********************/
125 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
128 if (f->ts.type == BT_COMPLEX)
129 f->ts.type = BT_REAL;
131 f->value.function.name
132 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
137 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
138 gfc_expr *mode ATTRIBUTE_UNUSED)
140 f->ts.type = BT_INTEGER;
141 f->ts.kind = gfc_c_int_kind;
142 f->value.function.name = PREFIX ("access_func");
147 gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind,
150 f->ts.type = BT_CHARACTER;
151 f->ts.kind = (kind == NULL)
152 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
153 f->ts.cl = gfc_get_charlen ();
154 f->ts.cl->next = gfc_current_ns->cl_list;
155 gfc_current_ns->cl_list = f->ts.cl;
156 f->ts.cl->length = gfc_int_expr (1);
158 f->value.function.name = gfc_get_string (name, f->ts.kind,
159 gfc_type_letter (x->ts.type),
165 gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
167 gfc_resolve_char_achar (f, x, kind, "__achar_%d_%c%d");
172 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
175 f->value.function.name
176 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
181 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
184 f->value.function.name
185 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
191 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
193 f->ts.type = BT_REAL;
194 f->ts.kind = x->ts.kind;
195 f->value.function.name
196 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
202 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
204 f->ts.type = i->ts.type;
205 f->ts.kind = gfc_kind_max (i, j);
207 if (i->ts.kind != j->ts.kind)
209 if (i->ts.kind == gfc_kind_max (i, j))
210 gfc_convert_type (j, &i->ts, 2);
212 gfc_convert_type (i, &j->ts, 2);
215 f->value.function.name
216 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
221 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
226 f->ts.type = a->ts.type;
227 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
229 if (a->ts.kind != f->ts.kind)
231 ts.type = f->ts.type;
232 ts.kind = f->ts.kind;
233 gfc_convert_type (a, &ts, 2);
235 /* The resolved name is only used for specific intrinsics where
236 the return kind is the same as the arg kind. */
237 f->value.function.name
238 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
243 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
245 gfc_resolve_aint (f, a, NULL);
250 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
256 gfc_resolve_dim_arg (dim);
257 f->rank = mask->rank - 1;
258 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
261 f->value.function.name
262 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
268 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
273 f->ts.type = a->ts.type;
274 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
276 if (a->ts.kind != f->ts.kind)
278 ts.type = f->ts.type;
279 ts.kind = f->ts.kind;
280 gfc_convert_type (a, &ts, 2);
283 /* The resolved name is only used for specific intrinsics where
284 the return kind is the same as the arg kind. */
285 f->value.function.name
286 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
292 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
294 gfc_resolve_anint (f, a, NULL);
299 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
305 gfc_resolve_dim_arg (dim);
306 f->rank = mask->rank - 1;
307 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
310 f->value.function.name
311 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
317 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
320 f->value.function.name
321 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
325 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
328 f->value.function.name
329 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
334 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
337 f->value.function.name
338 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
342 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
345 f->value.function.name
346 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
351 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
354 f->value.function.name
355 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
360 /* Resolve the BESYN and BESJN intrinsics. */
363 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
369 if (n->ts.kind != gfc_c_int_kind)
371 ts.type = BT_INTEGER;
372 ts.kind = gfc_c_int_kind;
373 gfc_convert_type (n, &ts, 2);
375 f->value.function.name = gfc_get_string ("<intrinsic>");
380 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
382 f->ts.type = BT_LOGICAL;
383 f->ts.kind = gfc_default_logical_kind;
384 f->value.function.name
385 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
390 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
392 f->ts.type = BT_INTEGER;
393 f->ts.kind = (kind == NULL)
394 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
395 f->value.function.name
396 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
397 gfc_type_letter (a->ts.type), a->ts.kind);
402 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
404 gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d");
409 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
411 f->ts.type = BT_INTEGER;
412 f->ts.kind = gfc_default_integer_kind;
413 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
418 gfc_resolve_chdir_sub (gfc_code *c)
423 if (c->ext.actual->next->expr != NULL)
424 kind = c->ext.actual->next->expr->ts.kind;
426 kind = gfc_default_integer_kind;
428 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
429 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
434 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
435 gfc_expr *mode ATTRIBUTE_UNUSED)
437 f->ts.type = BT_INTEGER;
438 f->ts.kind = gfc_c_int_kind;
439 f->value.function.name = PREFIX ("chmod_func");
444 gfc_resolve_chmod_sub (gfc_code *c)
449 if (c->ext.actual->next->next->expr != NULL)
450 kind = c->ext.actual->next->next->expr->ts.kind;
452 kind = gfc_default_integer_kind;
454 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
455 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
460 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
462 f->ts.type = BT_COMPLEX;
463 f->ts.kind = (kind == NULL)
464 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
467 f->value.function.name
468 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
469 gfc_type_letter (x->ts.type), x->ts.kind);
471 f->value.function.name
472 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
473 gfc_type_letter (x->ts.type), x->ts.kind,
474 gfc_type_letter (y->ts.type), y->ts.kind);
479 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
481 gfc_resolve_cmplx (f, x, y, gfc_int_expr (gfc_default_double_kind));
486 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
490 if (x->ts.type == BT_INTEGER)
492 if (y->ts.type == BT_INTEGER)
493 kind = gfc_default_real_kind;
499 if (y->ts.type == BT_REAL)
500 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
505 f->ts.type = BT_COMPLEX;
507 f->value.function.name
508 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
509 gfc_type_letter (x->ts.type), x->ts.kind,
510 gfc_type_letter (y->ts.type), y->ts.kind);
515 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
518 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
523 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
526 f->value.function.name
527 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
532 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
535 f->value.function.name
536 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
541 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
543 f->ts.type = BT_INTEGER;
545 f->ts.kind = mpz_get_si (kind->value.integer);
547 f->ts.kind = gfc_default_integer_kind;
551 f->rank = mask->rank - 1;
552 gfc_resolve_dim_arg (dim);
553 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
556 resolve_mask_arg (mask);
558 f->value.function.name
559 = gfc_get_string (PREFIX ("count_%d_%c"), f->ts.kind,
560 gfc_type_letter (mask->ts.type));
565 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
570 if (array->ts.type == BT_CHARACTER && array->ref)
571 gfc_resolve_substring_charlen (array);
574 f->rank = array->rank;
575 f->shape = gfc_copy_shape (array->shape, array->rank);
582 /* If dim kind is greater than default integer we need to use the larger. */
583 m = gfc_default_integer_kind;
585 m = m < dim->ts.kind ? dim->ts.kind : m;
587 /* Convert shift to at least m, so we don't need
588 kind=1 and kind=2 versions of the library functions. */
589 if (shift->ts.kind < m)
593 ts.type = BT_INTEGER;
595 gfc_convert_type_warn (shift, &ts, 2, 0);
600 if (dim->expr_type != EXPR_CONSTANT && dim->symtree->n.sym->attr.optional)
602 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
603 dim->representation.length = shift->ts.kind;
607 gfc_resolve_dim_arg (dim);
608 /* Convert dim to shift's kind to reduce variations. */
609 if (dim->ts.kind != shift->ts.kind)
610 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
614 f->value.function.name
615 = gfc_get_string (PREFIX ("cshift%d_%d%s"), n, shift->ts.kind,
616 array->ts.type == BT_CHARACTER ? "_char" : "");
621 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
626 f->ts.type = BT_CHARACTER;
627 f->ts.kind = gfc_default_character_kind;
629 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
630 if (time->ts.kind != 8)
632 ts.type = BT_INTEGER;
636 gfc_convert_type (time, &ts, 2);
639 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
644 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
646 f->ts.type = BT_REAL;
647 f->ts.kind = gfc_default_double_kind;
648 f->value.function.name
649 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
654 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
656 f->ts.type = a->ts.type;
658 f->ts.kind = gfc_kind_max (a,p);
660 f->ts.kind = a->ts.kind;
662 if (p != NULL && a->ts.kind != p->ts.kind)
664 if (a->ts.kind == gfc_kind_max (a,p))
665 gfc_convert_type (p, &a->ts, 2);
667 gfc_convert_type (a, &p->ts, 2);
670 f->value.function.name
671 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
676 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
680 temp.expr_type = EXPR_OP;
681 gfc_clear_ts (&temp.ts);
682 temp.value.op.operator = INTRINSIC_NONE;
683 temp.value.op.op1 = a;
684 temp.value.op.op2 = b;
685 gfc_type_convert_binary (&temp);
687 f->value.function.name
688 = gfc_get_string (PREFIX ("dot_product_%c%d"),
689 gfc_type_letter (f->ts.type), f->ts.kind);
694 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
695 gfc_expr *b ATTRIBUTE_UNUSED)
697 f->ts.kind = gfc_default_double_kind;
698 f->ts.type = BT_REAL;
699 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
704 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
705 gfc_expr *boundary, gfc_expr *dim)
709 if (array->ts.type == BT_CHARACTER && array->ref)
710 gfc_resolve_substring_charlen (array);
713 f->rank = array->rank;
714 f->shape = gfc_copy_shape (array->shape, array->rank);
719 if (boundary && boundary->rank > 0)
722 /* If dim kind is greater than default integer we need to use the larger. */
723 m = gfc_default_integer_kind;
725 m = m < dim->ts.kind ? dim->ts.kind : m;
727 /* Convert shift to at least m, so we don't need
728 kind=1 and kind=2 versions of the library functions. */
729 if (shift->ts.kind < m)
733 ts.type = BT_INTEGER;
735 gfc_convert_type_warn (shift, &ts, 2, 0);
740 if (dim->expr_type != EXPR_CONSTANT && dim->symtree->n.sym->attr.optional)
742 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
743 dim->representation.length = shift->ts.kind;
747 gfc_resolve_dim_arg (dim);
748 /* Convert dim to shift's kind to reduce variations. */
749 if (dim->ts.kind != shift->ts.kind)
750 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
754 f->value.function.name
755 = gfc_get_string (PREFIX ("eoshift%d_%d%s"), n, shift->ts.kind,
756 array->ts.type == BT_CHARACTER ? "_char" : "");
761 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
764 f->value.function.name
765 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
770 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
772 f->ts.type = BT_INTEGER;
773 f->ts.kind = gfc_default_integer_kind;
774 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
779 gfc_resolve_fdate (gfc_expr *f)
781 f->ts.type = BT_CHARACTER;
782 f->ts.kind = gfc_default_character_kind;
783 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
788 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
790 f->ts.type = BT_INTEGER;
791 f->ts.kind = (kind == NULL)
792 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
793 f->value.function.name
794 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
795 gfc_type_letter (a->ts.type), a->ts.kind);
800 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
802 f->ts.type = BT_INTEGER;
803 f->ts.kind = gfc_default_integer_kind;
804 if (n->ts.kind != f->ts.kind)
805 gfc_convert_type (n, &f->ts, 2);
806 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
811 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
814 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
818 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
821 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
824 f->value.function.name = gfc_get_string ("<intrinsic>");
829 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
832 f->value.function.name
833 = gfc_get_string ("__gamma_%d", x->ts.kind);
838 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
840 f->ts.type = BT_INTEGER;
842 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
847 gfc_resolve_getgid (gfc_expr *f)
849 f->ts.type = BT_INTEGER;
851 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
856 gfc_resolve_getpid (gfc_expr *f)
858 f->ts.type = BT_INTEGER;
860 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
865 gfc_resolve_getuid (gfc_expr *f)
867 f->ts.type = BT_INTEGER;
869 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
874 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
876 f->ts.type = BT_INTEGER;
878 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
883 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
885 /* If the kind of i and j are different, then g77 cross-promoted the
886 kinds to the largest value. The Fortran 95 standard requires the
888 if (i->ts.kind != j->ts.kind)
890 if (i->ts.kind == gfc_kind_max (i, j))
891 gfc_convert_type (j, &i->ts, 2);
893 gfc_convert_type (i, &j->ts, 2);
897 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
902 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
905 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
910 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
911 gfc_expr *len ATTRIBUTE_UNUSED)
914 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
919 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
922 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
927 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
929 f->ts.type = BT_INTEGER;
931 f->ts.kind = mpz_get_si (kind->value.integer);
933 f->ts.kind = gfc_default_integer_kind;
934 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
939 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
941 f->ts.type = BT_INTEGER;
943 f->ts.kind = mpz_get_si (kind->value.integer);
945 f->ts.kind = gfc_default_integer_kind;
946 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
951 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
953 gfc_resolve_nint (f, a, NULL);
958 gfc_resolve_ierrno (gfc_expr *f)
960 f->ts.type = BT_INTEGER;
961 f->ts.kind = gfc_default_integer_kind;
962 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
967 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
969 /* If the kind of i and j are different, then g77 cross-promoted the
970 kinds to the largest value. The Fortran 95 standard requires the
972 if (i->ts.kind != j->ts.kind)
974 if (i->ts.kind == gfc_kind_max (i, j))
975 gfc_convert_type (j, &i->ts, 2);
977 gfc_convert_type (i, &j->ts, 2);
981 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
986 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
988 /* If the kind of i and j are different, then g77 cross-promoted the
989 kinds to the largest value. The Fortran 95 standard requires the
991 if (i->ts.kind != j->ts.kind)
993 if (i->ts.kind == gfc_kind_max (i, j))
994 gfc_convert_type (j, &i->ts, 2);
996 gfc_convert_type (i, &j->ts, 2);
1000 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
1005 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
1006 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
1012 f->ts.type = BT_INTEGER;
1014 f->ts.kind = mpz_get_si (kind->value.integer);
1016 f->ts.kind = gfc_default_integer_kind;
1018 if (back && back->ts.kind != gfc_default_integer_kind)
1020 ts.type = BT_LOGICAL;
1021 ts.kind = gfc_default_integer_kind;
1024 gfc_convert_type (back, &ts, 2);
1027 f->value.function.name
1028 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
1033 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1035 f->ts.type = BT_INTEGER;
1036 f->ts.kind = (kind == NULL)
1037 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1038 f->value.function.name
1039 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1040 gfc_type_letter (a->ts.type), a->ts.kind);
1045 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1047 f->ts.type = BT_INTEGER;
1049 f->value.function.name
1050 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1051 gfc_type_letter (a->ts.type), a->ts.kind);
1056 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
1058 f->ts.type = BT_INTEGER;
1060 f->value.function.name
1061 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1062 gfc_type_letter (a->ts.type), a->ts.kind);
1067 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1069 f->ts.type = BT_INTEGER;
1071 f->value.function.name
1072 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1073 gfc_type_letter (a->ts.type), a->ts.kind);
1078 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1083 f->ts.type = BT_LOGICAL;
1084 f->ts.kind = gfc_default_integer_kind;
1085 if (u->ts.kind != gfc_c_int_kind)
1087 ts.type = BT_INTEGER;
1088 ts.kind = gfc_c_int_kind;
1091 gfc_convert_type (u, &ts, 2);
1094 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1099 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1102 f->value.function.name
1103 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1108 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1111 f->value.function.name
1112 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1117 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1120 f->value.function.name
1121 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1126 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1130 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1133 f->value.function.name
1134 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1139 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1140 gfc_expr *s ATTRIBUTE_UNUSED)
1142 f->ts.type = BT_INTEGER;
1143 f->ts.kind = gfc_default_integer_kind;
1144 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1149 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1151 static char lbound[] = "__lbound";
1153 f->ts.type = BT_INTEGER;
1155 f->ts.kind = mpz_get_si (kind->value.integer);
1157 f->ts.kind = gfc_default_integer_kind;
1162 f->shape = gfc_get_shape (1);
1163 mpz_init_set_ui (f->shape[0], array->rank);
1166 f->value.function.name = lbound;
1171 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1173 f->ts.type = BT_INTEGER;
1175 f->ts.kind = mpz_get_si (kind->value.integer);
1177 f->ts.kind = gfc_default_integer_kind;
1178 f->value.function.name
1179 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1180 gfc_default_integer_kind);
1185 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1187 f->ts.type = BT_INTEGER;
1189 f->ts.kind = mpz_get_si (kind->value.integer);
1191 f->ts.kind = gfc_default_integer_kind;
1192 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1197 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1200 f->value.function.name
1201 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1206 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1207 gfc_expr *p2 ATTRIBUTE_UNUSED)
1209 f->ts.type = BT_INTEGER;
1210 f->ts.kind = gfc_default_integer_kind;
1211 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1216 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1218 f->ts.type= BT_INTEGER;
1219 f->ts.kind = gfc_index_integer_kind;
1220 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1225 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1228 f->value.function.name
1229 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1234 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1237 f->value.function.name
1238 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1244 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1246 f->ts.type = BT_LOGICAL;
1247 f->ts.kind = (kind == NULL)
1248 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1251 f->value.function.name
1252 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1253 gfc_type_letter (a->ts.type), a->ts.kind);
1258 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1260 if (size->ts.kind < gfc_index_integer_kind)
1265 ts.type = BT_INTEGER;
1266 ts.kind = gfc_index_integer_kind;
1267 gfc_convert_type_warn (size, &ts, 2, 0);
1270 f->ts.type = BT_INTEGER;
1271 f->ts.kind = gfc_index_integer_kind;
1272 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1277 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1281 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1283 f->ts.type = BT_LOGICAL;
1284 f->ts.kind = gfc_default_logical_kind;
1288 temp.expr_type = EXPR_OP;
1289 gfc_clear_ts (&temp.ts);
1290 temp.value.op.operator = INTRINSIC_NONE;
1291 temp.value.op.op1 = a;
1292 temp.value.op.op2 = b;
1293 gfc_type_convert_binary (&temp);
1297 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1299 f->value.function.name
1300 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1306 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1308 gfc_actual_arglist *a;
1310 f->ts.type = args->expr->ts.type;
1311 f->ts.kind = args->expr->ts.kind;
1312 /* Find the largest type kind. */
1313 for (a = args->next; a; a = a->next)
1315 if (a->expr->ts.kind > f->ts.kind)
1316 f->ts.kind = a->expr->ts.kind;
1319 /* Convert all parameters to the required kind. */
1320 for (a = args; a; a = a->next)
1322 if (a->expr->ts.kind != f->ts.kind)
1323 gfc_convert_type (a->expr, &f->ts, 2);
1326 f->value.function.name
1327 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1332 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1334 gfc_resolve_minmax ("__max_%c%d", f, args);
1339 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1345 f->ts.type = BT_INTEGER;
1346 f->ts.kind = gfc_default_integer_kind;
1351 f->shape = gfc_get_shape (1);
1352 mpz_init_set_si (f->shape[0], array->rank);
1356 f->rank = array->rank - 1;
1357 gfc_resolve_dim_arg (dim);
1358 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1360 idim = (int) mpz_get_si (dim->value.integer);
1361 f->shape = gfc_get_shape (f->rank);
1362 for (i = 0, j = 0; i < f->rank; i++, j++)
1364 if (i == (idim - 1))
1366 mpz_init_set (f->shape[i], array->shape[j]);
1373 if (mask->rank == 0)
1378 resolve_mask_arg (mask);
1383 f->value.function.name
1384 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1385 gfc_type_letter (array->ts.type), array->ts.kind);
1390 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1400 f->rank = array->rank - 1;
1401 gfc_resolve_dim_arg (dim);
1403 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1405 idim = (int) mpz_get_si (dim->value.integer);
1406 f->shape = gfc_get_shape (f->rank);
1407 for (i = 0, j = 0; i < f->rank; i++, j++)
1409 if (i == (idim - 1))
1411 mpz_init_set (f->shape[i], array->shape[j]);
1418 if (mask->rank == 0)
1423 resolve_mask_arg (mask);
1428 f->value.function.name
1429 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1430 gfc_type_letter (array->ts.type), array->ts.kind);
1435 gfc_resolve_mclock (gfc_expr *f)
1437 f->ts.type = BT_INTEGER;
1439 f->value.function.name = PREFIX ("mclock");
1444 gfc_resolve_mclock8 (gfc_expr *f)
1446 f->ts.type = BT_INTEGER;
1448 f->value.function.name = PREFIX ("mclock8");
1453 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1454 gfc_expr *fsource ATTRIBUTE_UNUSED,
1455 gfc_expr *mask ATTRIBUTE_UNUSED)
1457 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1458 gfc_resolve_substring_charlen (tsource);
1460 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1461 gfc_resolve_substring_charlen (fsource);
1463 if (tsource->ts.type == BT_CHARACTER)
1464 check_charlen_present (tsource);
1466 f->ts = tsource->ts;
1467 f->value.function.name
1468 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1474 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1476 gfc_resolve_minmax ("__min_%c%d", f, args);
1481 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1487 f->ts.type = BT_INTEGER;
1488 f->ts.kind = gfc_default_integer_kind;
1493 f->shape = gfc_get_shape (1);
1494 mpz_init_set_si (f->shape[0], array->rank);
1498 f->rank = array->rank - 1;
1499 gfc_resolve_dim_arg (dim);
1500 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1502 idim = (int) mpz_get_si (dim->value.integer);
1503 f->shape = gfc_get_shape (f->rank);
1504 for (i = 0, j = 0; i < f->rank; i++, j++)
1506 if (i == (idim - 1))
1508 mpz_init_set (f->shape[i], array->shape[j]);
1515 if (mask->rank == 0)
1520 resolve_mask_arg (mask);
1525 f->value.function.name
1526 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1527 gfc_type_letter (array->ts.type), array->ts.kind);
1532 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1542 f->rank = array->rank - 1;
1543 gfc_resolve_dim_arg (dim);
1545 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1547 idim = (int) mpz_get_si (dim->value.integer);
1548 f->shape = gfc_get_shape (f->rank);
1549 for (i = 0, j = 0; i < f->rank; i++, j++)
1551 if (i == (idim - 1))
1553 mpz_init_set (f->shape[i], array->shape[j]);
1560 if (mask->rank == 0)
1565 resolve_mask_arg (mask);
1570 f->value.function.name
1571 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1572 gfc_type_letter (array->ts.type), array->ts.kind);
1577 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1579 f->ts.type = a->ts.type;
1581 f->ts.kind = gfc_kind_max (a,p);
1583 f->ts.kind = a->ts.kind;
1585 if (p != NULL && a->ts.kind != p->ts.kind)
1587 if (a->ts.kind == gfc_kind_max (a,p))
1588 gfc_convert_type (p, &a->ts, 2);
1590 gfc_convert_type (a, &p->ts, 2);
1593 f->value.function.name
1594 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1599 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1601 f->ts.type = a->ts.type;
1603 f->ts.kind = gfc_kind_max (a,p);
1605 f->ts.kind = a->ts.kind;
1607 if (p != NULL && a->ts.kind != p->ts.kind)
1609 if (a->ts.kind == gfc_kind_max (a,p))
1610 gfc_convert_type (p, &a->ts, 2);
1612 gfc_convert_type (a, &p->ts, 2);
1615 f->value.function.name
1616 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1621 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1623 if (p->ts.kind != a->ts.kind)
1624 gfc_convert_type (p, &a->ts, 2);
1627 f->value.function.name
1628 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1633 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1635 f->ts.type = BT_INTEGER;
1636 f->ts.kind = (kind == NULL)
1637 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1638 f->value.function.name
1639 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1644 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1647 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1652 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1654 f->ts.type = i->ts.type;
1655 f->ts.kind = gfc_kind_max (i, j);
1657 if (i->ts.kind != j->ts.kind)
1659 if (i->ts.kind == gfc_kind_max (i, j))
1660 gfc_convert_type (j, &i->ts, 2);
1662 gfc_convert_type (i, &j->ts, 2);
1665 f->value.function.name
1666 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1671 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1672 gfc_expr *vector ATTRIBUTE_UNUSED)
1674 if (array->ts.type == BT_CHARACTER && array->ref)
1675 gfc_resolve_substring_charlen (array);
1680 resolve_mask_arg (mask);
1682 if (mask->rank != 0)
1683 f->value.function.name = (array->ts.type == BT_CHARACTER
1684 ? PREFIX ("pack_char") : PREFIX ("pack"));
1686 f->value.function.name = (array->ts.type == BT_CHARACTER
1687 ? PREFIX ("pack_s_char") : PREFIX ("pack_s"));
1692 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1701 f->rank = array->rank - 1;
1702 gfc_resolve_dim_arg (dim);
1707 if (mask->rank == 0)
1712 resolve_mask_arg (mask);
1717 f->value.function.name
1718 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1719 gfc_type_letter (array->ts.type), array->ts.kind);
1724 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1726 f->ts.type = BT_REAL;
1729 f->ts.kind = mpz_get_si (kind->value.integer);
1731 f->ts.kind = (a->ts.type == BT_COMPLEX)
1732 ? a->ts.kind : gfc_default_real_kind;
1734 f->value.function.name
1735 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1736 gfc_type_letter (a->ts.type), a->ts.kind);
1741 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1743 f->ts.type = BT_REAL;
1744 f->ts.kind = a->ts.kind;
1745 f->value.function.name
1746 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1747 gfc_type_letter (a->ts.type), a->ts.kind);
1752 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1753 gfc_expr *p2 ATTRIBUTE_UNUSED)
1755 f->ts.type = BT_INTEGER;
1756 f->ts.kind = gfc_default_integer_kind;
1757 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1762 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
1763 gfc_expr *ncopies ATTRIBUTE_UNUSED)
1765 f->ts.type = BT_CHARACTER;
1766 f->ts.kind = string->ts.kind;
1767 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
1772 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
1773 gfc_expr *pad ATTRIBUTE_UNUSED,
1774 gfc_expr *order ATTRIBUTE_UNUSED)
1780 if (source->ts.type == BT_CHARACTER && source->ref)
1781 gfc_resolve_substring_charlen (source);
1785 gfc_array_size (shape, &rank);
1786 f->rank = mpz_get_si (rank);
1788 switch (source->ts.type)
1794 kind = source->ts.kind;
1808 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
1809 f->value.function.name
1810 = gfc_get_string (PREFIX ("reshape_%c%d"),
1811 gfc_type_letter (source->ts.type),
1814 f->value.function.name
1815 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
1820 f->value.function.name = (source->ts.type == BT_CHARACTER
1821 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1825 /* TODO: Make this work with a constant ORDER parameter. */
1826 if (shape->expr_type == EXPR_ARRAY
1827 && gfc_is_constant_expr (shape)
1831 f->shape = gfc_get_shape (f->rank);
1832 c = shape->value.constructor;
1833 for (i = 0; i < f->rank; i++)
1835 mpz_init_set (f->shape[i], c->expr->value.integer);
1840 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
1841 so many runtime variations. */
1842 if (shape->ts.kind != gfc_index_integer_kind)
1844 gfc_typespec ts = shape->ts;
1845 ts.kind = gfc_index_integer_kind;
1846 gfc_convert_type_warn (shape, &ts, 2, 0);
1848 if (order && order->ts.kind != gfc_index_integer_kind)
1849 gfc_convert_type_warn (order, &shape->ts, 2, 0);
1854 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
1857 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
1862 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED)
1865 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
1870 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
1871 gfc_expr *set ATTRIBUTE_UNUSED,
1872 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
1874 f->ts.type = BT_INTEGER;
1876 f->ts.kind = mpz_get_si (kind->value.integer);
1878 f->ts.kind = gfc_default_integer_kind;
1879 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
1884 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
1887 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
1892 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x,
1893 gfc_expr *i ATTRIBUTE_UNUSED)
1896 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
1901 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
1903 f->ts.type = BT_INTEGER;
1904 f->ts.kind = gfc_default_integer_kind;
1906 f->shape = gfc_get_shape (1);
1907 mpz_init_set_ui (f->shape[0], array->rank);
1908 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
1913 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
1916 f->value.function.name
1917 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
1922 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
1924 f->ts.type = BT_INTEGER;
1925 f->ts.kind = gfc_c_int_kind;
1927 /* handler can be either BT_INTEGER or BT_PROCEDURE */
1928 if (handler->ts.type == BT_INTEGER)
1930 if (handler->ts.kind != gfc_c_int_kind)
1931 gfc_convert_type (handler, &f->ts, 2);
1932 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
1935 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
1937 if (number->ts.kind != gfc_c_int_kind)
1938 gfc_convert_type (number, &f->ts, 2);
1943 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
1946 f->value.function.name
1947 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1952 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
1955 f->value.function.name
1956 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1961 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
1962 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
1964 f->ts.type = BT_INTEGER;
1966 f->ts.kind = mpz_get_si (kind->value.integer);
1968 f->ts.kind = gfc_default_integer_kind;
1973 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
1976 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
1981 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
1984 if (source->ts.type == BT_CHARACTER && source->ref)
1985 gfc_resolve_substring_charlen (source);
1987 if (source->ts.type == BT_CHARACTER)
1988 check_charlen_present (source);
1991 f->rank = source->rank + 1;
1992 if (source->rank == 0)
1993 f->value.function.name = (source->ts.type == BT_CHARACTER
1994 ? PREFIX ("spread_char_scalar")
1995 : PREFIX ("spread_scalar"));
1997 f->value.function.name = (source->ts.type == BT_CHARACTER
1998 ? PREFIX ("spread_char")
1999 : PREFIX ("spread"));
2001 if (dim && gfc_is_constant_expr (dim)
2002 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2005 idim = mpz_get_ui (dim->value.integer);
2006 f->shape = gfc_get_shape (f->rank);
2007 for (i = 0; i < (idim - 1); i++)
2008 mpz_init_set (f->shape[i], source->shape[i]);
2010 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2012 for (i = idim; i < f->rank ; i++)
2013 mpz_init_set (f->shape[i], source->shape[i-1]);
2017 gfc_resolve_dim_arg (dim);
2018 gfc_resolve_index (ncopies, 1);
2023 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2026 f->value.function.name
2027 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2031 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2034 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2035 gfc_expr *a ATTRIBUTE_UNUSED)
2037 f->ts.type = BT_INTEGER;
2038 f->ts.kind = gfc_default_integer_kind;
2039 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2044 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2045 gfc_expr *a ATTRIBUTE_UNUSED)
2047 f->ts.type = BT_INTEGER;
2048 f->ts.kind = gfc_default_integer_kind;
2049 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2054 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2056 f->ts.type = BT_INTEGER;
2057 f->ts.kind = gfc_default_integer_kind;
2058 if (n->ts.kind != f->ts.kind)
2059 gfc_convert_type (n, &f->ts, 2);
2061 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2066 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2071 f->ts.type = BT_INTEGER;
2072 f->ts.kind = gfc_c_int_kind;
2073 if (u->ts.kind != gfc_c_int_kind)
2075 ts.type = BT_INTEGER;
2076 ts.kind = gfc_c_int_kind;
2079 gfc_convert_type (u, &ts, 2);
2082 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2087 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2089 f->ts.type = BT_INTEGER;
2090 f->ts.kind = gfc_c_int_kind;
2091 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2096 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2101 f->ts.type = BT_INTEGER;
2102 f->ts.kind = gfc_c_int_kind;
2103 if (u->ts.kind != gfc_c_int_kind)
2105 ts.type = BT_INTEGER;
2106 ts.kind = gfc_c_int_kind;
2109 gfc_convert_type (u, &ts, 2);
2112 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2117 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2119 f->ts.type = BT_INTEGER;
2120 f->ts.kind = gfc_c_int_kind;
2121 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2126 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2131 f->ts.type = BT_INTEGER;
2132 f->ts.kind = gfc_index_integer_kind;
2133 if (u->ts.kind != gfc_c_int_kind)
2135 ts.type = BT_INTEGER;
2136 ts.kind = gfc_c_int_kind;
2139 gfc_convert_type (u, &ts, 2);
2142 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2147 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2155 if (mask->rank == 0)
2160 resolve_mask_arg (mask);
2167 f->rank = array->rank - 1;
2168 gfc_resolve_dim_arg (dim);
2171 f->value.function.name
2172 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2173 gfc_type_letter (array->ts.type), array->ts.kind);
2178 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2179 gfc_expr *p2 ATTRIBUTE_UNUSED)
2181 f->ts.type = BT_INTEGER;
2182 f->ts.kind = gfc_default_integer_kind;
2183 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2187 /* Resolve the g77 compatibility function SYSTEM. */
2190 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2192 f->ts.type = BT_INTEGER;
2194 f->value.function.name = gfc_get_string (PREFIX ("system"));
2199 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2202 f->value.function.name
2203 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2208 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2211 f->value.function.name
2212 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2217 gfc_resolve_time (gfc_expr *f)
2219 f->ts.type = BT_INTEGER;
2221 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2226 gfc_resolve_time8 (gfc_expr *f)
2228 f->ts.type = BT_INTEGER;
2230 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2235 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2236 gfc_expr *mold, gfc_expr *size)
2238 /* TODO: Make this do something meaningful. */
2239 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2241 if (mold->ts.type == BT_CHARACTER && !mold->ts.cl->length
2242 && !(mold->expr_type == EXPR_VARIABLE && mold->symtree->n.sym->attr.dummy))
2243 mold->ts.cl->length = gfc_int_expr (mold->value.character.length);
2247 if (size == NULL && mold->rank == 0)
2250 f->value.function.name = transfer0;
2255 f->value.function.name = transfer1;
2256 if (size && gfc_is_constant_expr (size))
2258 f->shape = gfc_get_shape (1);
2259 mpz_init_set (f->shape[0], size->value.integer);
2266 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2269 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2270 gfc_resolve_substring_charlen (matrix);
2276 f->shape = gfc_get_shape (2);
2277 mpz_init_set (f->shape[0], matrix->shape[1]);
2278 mpz_init_set (f->shape[1], matrix->shape[0]);
2281 switch (matrix->ts.kind)
2287 switch (matrix->ts.type)
2291 f->value.function.name
2292 = gfc_get_string (PREFIX ("transpose_%c%d"),
2293 gfc_type_letter (matrix->ts.type),
2299 /* Use the integer routines for real and logical cases. This
2300 assumes they all have the same alignment requirements. */
2301 f->value.function.name
2302 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2306 f->value.function.name = PREFIX ("transpose");
2312 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2313 ? PREFIX ("transpose_char")
2314 : PREFIX ("transpose"));
2321 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2323 f->ts.type = BT_CHARACTER;
2324 f->ts.kind = string->ts.kind;
2325 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2330 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2332 static char ubound[] = "__ubound";
2334 f->ts.type = BT_INTEGER;
2336 f->ts.kind = mpz_get_si (kind->value.integer);
2338 f->ts.kind = gfc_default_integer_kind;
2343 f->shape = gfc_get_shape (1);
2344 mpz_init_set_ui (f->shape[0], array->rank);
2347 f->value.function.name = ubound;
2351 /* Resolve the g77 compatibility function UMASK. */
2354 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2356 f->ts.type = BT_INTEGER;
2357 f->ts.kind = n->ts.kind;
2358 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2362 /* Resolve the g77 compatibility function UNLINK. */
2365 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2367 f->ts.type = BT_INTEGER;
2369 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2374 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2379 f->ts.type = BT_CHARACTER;
2380 f->ts.kind = gfc_default_character_kind;
2382 if (unit->ts.kind != gfc_c_int_kind)
2384 ts.type = BT_INTEGER;
2385 ts.kind = gfc_c_int_kind;
2388 gfc_convert_type (unit, &ts, 2);
2391 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2396 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2397 gfc_expr *field ATTRIBUTE_UNUSED)
2399 if (vector->ts.type == BT_CHARACTER && vector->ref)
2400 gfc_resolve_substring_charlen (vector);
2403 f->rank = mask->rank;
2404 resolve_mask_arg (mask);
2406 f->value.function.name
2407 = gfc_get_string (PREFIX ("unpack%d%s"), field->rank > 0 ? 1 : 0,
2408 vector->ts.type == BT_CHARACTER ? "_char" : "");
2413 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2414 gfc_expr *set ATTRIBUTE_UNUSED,
2415 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2417 f->ts.type = BT_INTEGER;
2419 f->ts.kind = mpz_get_si (kind->value.integer);
2421 f->ts.kind = gfc_default_integer_kind;
2422 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2427 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2429 f->ts.type = i->ts.type;
2430 f->ts.kind = gfc_kind_max (i, j);
2432 if (i->ts.kind != j->ts.kind)
2434 if (i->ts.kind == gfc_kind_max (i, j))
2435 gfc_convert_type (j, &i->ts, 2);
2437 gfc_convert_type (i, &j->ts, 2);
2440 f->value.function.name
2441 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2445 /* Intrinsic subroutine resolution. */
2448 gfc_resolve_alarm_sub (gfc_code *c)
2451 gfc_expr *seconds, *handler, *status;
2455 seconds = c->ext.actual->expr;
2456 handler = c->ext.actual->next->expr;
2457 status = c->ext.actual->next->next->expr;
2458 ts.type = BT_INTEGER;
2459 ts.kind = gfc_c_int_kind;
2461 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2462 In all cases, the status argument is of default integer kind
2463 (enforced in check.c) so that the function suffix is fixed. */
2464 if (handler->ts.type == BT_INTEGER)
2466 if (handler->ts.kind != gfc_c_int_kind)
2467 gfc_convert_type (handler, &ts, 2);
2468 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2469 gfc_default_integer_kind);
2472 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2473 gfc_default_integer_kind);
2475 if (seconds->ts.kind != gfc_c_int_kind)
2476 gfc_convert_type (seconds, &ts, 2);
2478 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2482 gfc_resolve_cpu_time (gfc_code *c)
2485 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2486 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2491 gfc_resolve_mvbits (gfc_code *c)
2497 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2498 they will be converted so that they fit into a C int. */
2499 ts.type = BT_INTEGER;
2500 ts.kind = gfc_c_int_kind;
2501 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2502 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2503 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2504 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2505 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2506 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2508 /* TO and FROM are guaranteed to have the same kind parameter. */
2509 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2510 c->ext.actual->expr->ts.kind);
2511 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2512 /* Mark as elemental subroutine as this does not happen automatically. */
2513 c->resolved_sym->attr.elemental = 1;
2518 gfc_resolve_random_number (gfc_code *c)
2523 kind = c->ext.actual->expr->ts.kind;
2524 if (c->ext.actual->expr->rank == 0)
2525 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2527 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2529 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2534 gfc_resolve_random_seed (gfc_code *c)
2538 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2539 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2544 gfc_resolve_rename_sub (gfc_code *c)
2549 if (c->ext.actual->next->next->expr != NULL)
2550 kind = c->ext.actual->next->next->expr->ts.kind;
2552 kind = gfc_default_integer_kind;
2554 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2555 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2560 gfc_resolve_kill_sub (gfc_code *c)
2565 if (c->ext.actual->next->next->expr != NULL)
2566 kind = c->ext.actual->next->next->expr->ts.kind;
2568 kind = gfc_default_integer_kind;
2570 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2571 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2576 gfc_resolve_link_sub (gfc_code *c)
2581 if (c->ext.actual->next->next->expr != NULL)
2582 kind = c->ext.actual->next->next->expr->ts.kind;
2584 kind = gfc_default_integer_kind;
2586 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2587 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2592 gfc_resolve_symlnk_sub (gfc_code *c)
2597 if (c->ext.actual->next->next->expr != NULL)
2598 kind = c->ext.actual->next->next->expr->ts.kind;
2600 kind = gfc_default_integer_kind;
2602 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2603 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2607 /* G77 compatibility subroutines dtime() and etime(). */
2610 gfc_resolve_dtime_sub (gfc_code *c)
2613 name = gfc_get_string (PREFIX ("dtime_sub"));
2614 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2618 gfc_resolve_etime_sub (gfc_code *c)
2621 name = gfc_get_string (PREFIX ("etime_sub"));
2622 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2626 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2629 gfc_resolve_itime (gfc_code *c)
2632 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2633 gfc_default_integer_kind));
2637 gfc_resolve_idate (gfc_code *c)
2640 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2641 gfc_default_integer_kind));
2645 gfc_resolve_ltime (gfc_code *c)
2648 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2649 gfc_default_integer_kind));
2653 gfc_resolve_gmtime (gfc_code *c)
2656 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2657 gfc_default_integer_kind));
2661 /* G77 compatibility subroutine second(). */
2664 gfc_resolve_second_sub (gfc_code *c)
2667 name = gfc_get_string (PREFIX ("second_sub"));
2668 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2673 gfc_resolve_sleep_sub (gfc_code *c)
2678 if (c->ext.actual->expr != NULL)
2679 kind = c->ext.actual->expr->ts.kind;
2681 kind = gfc_default_integer_kind;
2683 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2684 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2688 /* G77 compatibility function srand(). */
2691 gfc_resolve_srand (gfc_code *c)
2694 name = gfc_get_string (PREFIX ("srand"));
2695 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2699 /* Resolve the getarg intrinsic subroutine. */
2702 gfc_resolve_getarg (gfc_code *c)
2706 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
2711 ts.type = BT_INTEGER;
2712 ts.kind = gfc_default_integer_kind;
2714 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2717 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
2718 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2722 /* Resolve the getcwd intrinsic subroutine. */
2725 gfc_resolve_getcwd_sub (gfc_code *c)
2730 if (c->ext.actual->next->expr != NULL)
2731 kind = c->ext.actual->next->expr->ts.kind;
2733 kind = gfc_default_integer_kind;
2735 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2736 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2740 /* Resolve the get_command intrinsic subroutine. */
2743 gfc_resolve_get_command (gfc_code *c)
2747 kind = gfc_default_integer_kind;
2748 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2749 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2753 /* Resolve the get_command_argument intrinsic subroutine. */
2756 gfc_resolve_get_command_argument (gfc_code *c)
2760 kind = gfc_default_integer_kind;
2761 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2762 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2766 /* Resolve the get_environment_variable intrinsic subroutine. */
2769 gfc_resolve_get_environment_variable (gfc_code *code)
2773 kind = gfc_default_integer_kind;
2774 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2775 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2780 gfc_resolve_signal_sub (gfc_code *c)
2783 gfc_expr *number, *handler, *status;
2787 number = c->ext.actual->expr;
2788 handler = c->ext.actual->next->expr;
2789 status = c->ext.actual->next->next->expr;
2790 ts.type = BT_INTEGER;
2791 ts.kind = gfc_c_int_kind;
2793 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2794 if (handler->ts.type == BT_INTEGER)
2796 if (handler->ts.kind != gfc_c_int_kind)
2797 gfc_convert_type (handler, &ts, 2);
2798 name = gfc_get_string (PREFIX ("signal_sub_int"));
2801 name = gfc_get_string (PREFIX ("signal_sub"));
2803 if (number->ts.kind != gfc_c_int_kind)
2804 gfc_convert_type (number, &ts, 2);
2805 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2806 gfc_convert_type (status, &ts, 2);
2808 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2812 /* Resolve the SYSTEM intrinsic subroutine. */
2815 gfc_resolve_system_sub (gfc_code *c)
2818 name = gfc_get_string (PREFIX ("system_sub"));
2819 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2823 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2826 gfc_resolve_system_clock (gfc_code *c)
2831 if (c->ext.actual->expr != NULL)
2832 kind = c->ext.actual->expr->ts.kind;
2833 else if (c->ext.actual->next->expr != NULL)
2834 kind = c->ext.actual->next->expr->ts.kind;
2835 else if (c->ext.actual->next->next->expr != NULL)
2836 kind = c->ext.actual->next->next->expr->ts.kind;
2838 kind = gfc_default_integer_kind;
2840 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
2841 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2845 /* Resolve the EXIT intrinsic subroutine. */
2848 gfc_resolve_exit (gfc_code *c)
2855 /* The STATUS argument has to be of default kind. If it is not,
2857 ts.type = BT_INTEGER;
2858 ts.kind = gfc_default_integer_kind;
2859 n = c->ext.actual->expr;
2860 if (n != NULL && n->ts.kind != ts.kind)
2861 gfc_convert_type (n, &ts, 2);
2863 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
2864 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2868 /* Resolve the FLUSH intrinsic subroutine. */
2871 gfc_resolve_flush (gfc_code *c)
2878 ts.type = BT_INTEGER;
2879 ts.kind = gfc_default_integer_kind;
2880 n = c->ext.actual->expr;
2881 if (n != NULL && n->ts.kind != ts.kind)
2882 gfc_convert_type (n, &ts, 2);
2884 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
2885 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2890 gfc_resolve_free (gfc_code *c)
2896 ts.type = BT_INTEGER;
2897 ts.kind = gfc_index_integer_kind;
2898 n = c->ext.actual->expr;
2899 if (n->ts.kind != ts.kind)
2900 gfc_convert_type (n, &ts, 2);
2902 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
2907 gfc_resolve_ctime_sub (gfc_code *c)
2912 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
2913 if (c->ext.actual->expr->ts.kind != 8)
2915 ts.type = BT_INTEGER;
2919 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2922 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
2927 gfc_resolve_fdate_sub (gfc_code *c)
2929 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
2934 gfc_resolve_gerror (gfc_code *c)
2936 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
2941 gfc_resolve_getlog (gfc_code *c)
2943 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
2948 gfc_resolve_hostnm_sub (gfc_code *c)
2953 if (c->ext.actual->next->expr != NULL)
2954 kind = c->ext.actual->next->expr->ts.kind;
2956 kind = gfc_default_integer_kind;
2958 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
2959 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2964 gfc_resolve_perror (gfc_code *c)
2966 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
2969 /* Resolve the STAT and FSTAT intrinsic subroutines. */
2972 gfc_resolve_stat_sub (gfc_code *c)
2975 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
2976 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2981 gfc_resolve_lstat_sub (gfc_code *c)
2984 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
2985 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2990 gfc_resolve_fstat_sub (gfc_code *c)
2996 u = c->ext.actual->expr;
2997 ts = &c->ext.actual->next->expr->ts;
2998 if (u->ts.kind != ts->kind)
2999 gfc_convert_type (u, ts, 2);
3000 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3001 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3006 gfc_resolve_fgetc_sub (gfc_code *c)
3013 u = c->ext.actual->expr;
3014 st = c->ext.actual->next->next->expr;
3016 if (u->ts.kind != gfc_c_int_kind)
3018 ts.type = BT_INTEGER;
3019 ts.kind = gfc_c_int_kind;
3022 gfc_convert_type (u, &ts, 2);
3026 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3028 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3030 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3035 gfc_resolve_fget_sub (gfc_code *c)
3040 st = c->ext.actual->next->expr;
3042 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3044 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3046 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3051 gfc_resolve_fputc_sub (gfc_code *c)
3058 u = c->ext.actual->expr;
3059 st = c->ext.actual->next->next->expr;
3061 if (u->ts.kind != gfc_c_int_kind)
3063 ts.type = BT_INTEGER;
3064 ts.kind = gfc_c_int_kind;
3067 gfc_convert_type (u, &ts, 2);
3071 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3073 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3075 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3080 gfc_resolve_fput_sub (gfc_code *c)
3085 st = c->ext.actual->next->expr;
3087 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3089 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3091 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3096 gfc_resolve_fseek_sub (gfc_code *c)
3105 unit = c->ext.actual->expr;
3106 offset = c->ext.actual->next->expr;
3107 whence = c->ext.actual->next->next->expr;
3108 status = c->ext.actual->next->next->next->expr;
3110 if (unit->ts.kind != gfc_c_int_kind)
3112 ts.type = BT_INTEGER;
3113 ts.kind = gfc_c_int_kind;
3116 gfc_convert_type (unit, &ts, 2);
3119 if (offset->ts.kind != gfc_intio_kind)
3121 ts.type = BT_INTEGER;
3122 ts.kind = gfc_intio_kind;
3125 gfc_convert_type (offset, &ts, 2);
3128 if (whence->ts.kind != gfc_c_int_kind)
3130 ts.type = BT_INTEGER;
3131 ts.kind = gfc_c_int_kind;
3134 gfc_convert_type (whence, &ts, 2);
3137 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3141 gfc_resolve_ftell_sub (gfc_code *c)
3149 unit = c->ext.actual->expr;
3150 offset = c->ext.actual->next->expr;
3152 if (unit->ts.kind != gfc_c_int_kind)
3154 ts.type = BT_INTEGER;
3155 ts.kind = gfc_c_int_kind;
3158 gfc_convert_type (unit, &ts, 2);
3161 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3162 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3167 gfc_resolve_ttynam_sub (gfc_code *c)
3172 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3174 ts.type = BT_INTEGER;
3175 ts.kind = gfc_c_int_kind;
3178 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3181 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3185 /* Resolve the UMASK intrinsic subroutine. */
3188 gfc_resolve_umask_sub (gfc_code *c)
3193 if (c->ext.actual->next->expr != NULL)
3194 kind = c->ext.actual->next->expr->ts.kind;
3196 kind = gfc_default_integer_kind;
3198 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3199 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3202 /* Resolve the UNLINK intrinsic subroutine. */
3205 gfc_resolve_unlink_sub (gfc_code *c)
3210 if (c->ext.actual->next->expr != NULL)
3211 kind = c->ext.actual->next->expr->ts.kind;
3213 kind = gfc_default_integer_kind;
3215 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3216 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);