1 /* Intrinsic function resolution.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
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)
95 /* For the scalar case, coerce the mask to kind=4 unconditionally
96 (because this is the only kind we have a library function
99 if (mask->ts.kind != 4)
101 ts.type = BT_LOGICAL;
103 gfc_convert_type (mask, &ts, 2);
108 /* In the library, we access the mask with a GFC_LOGICAL_1
109 argument. No need to waste memory if we are about to create
110 a temporary array. */
111 if (mask->expr_type == EXPR_OP)
113 ts.type = BT_LOGICAL;
115 gfc_convert_type (mask, &ts, 2);
120 /********************** Resolution functions **********************/
124 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
127 if (f->ts.type == BT_COMPLEX)
128 f->ts.type = BT_REAL;
130 f->value.function.name
131 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
136 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
137 gfc_expr *mode ATTRIBUTE_UNUSED)
139 f->ts.type = BT_INTEGER;
140 f->ts.kind = gfc_c_int_kind;
141 f->value.function.name = PREFIX ("access_func");
146 gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind,
149 f->ts.type = BT_CHARACTER;
150 f->ts.kind = (kind == NULL)
151 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
152 f->ts.cl = gfc_get_charlen ();
153 f->ts.cl->next = gfc_current_ns->cl_list;
154 gfc_current_ns->cl_list = f->ts.cl;
155 f->ts.cl->length = gfc_int_expr (1);
157 f->value.function.name = gfc_get_string (name, f->ts.kind,
158 gfc_type_letter (x->ts.type),
164 gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
166 gfc_resolve_char_achar (f, x, kind, "__achar_%d_%c%d");
171 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
174 f->value.function.name
175 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
180 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
183 f->value.function.name
184 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
190 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
192 f->ts.type = BT_REAL;
193 f->ts.kind = x->ts.kind;
194 f->value.function.name
195 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
201 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
203 f->ts.type = i->ts.type;
204 f->ts.kind = gfc_kind_max (i, j);
206 if (i->ts.kind != j->ts.kind)
208 if (i->ts.kind == gfc_kind_max (i, j))
209 gfc_convert_type (j, &i->ts, 2);
211 gfc_convert_type (i, &j->ts, 2);
214 f->value.function.name
215 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
220 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
224 f->ts.type = a->ts.type;
225 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
227 if (a->ts.kind != f->ts.kind)
229 ts.type = f->ts.type;
230 ts.kind = f->ts.kind;
231 gfc_convert_type (a, &ts, 2);
233 /* The resolved name is only used for specific intrinsics where
234 the return kind is the same as the arg kind. */
235 f->value.function.name
236 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
241 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
243 gfc_resolve_aint (f, a, NULL);
248 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
254 gfc_resolve_dim_arg (dim);
255 f->rank = mask->rank - 1;
256 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
259 f->value.function.name
260 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
266 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
270 f->ts.type = a->ts.type;
271 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
273 if (a->ts.kind != f->ts.kind)
275 ts.type = f->ts.type;
276 ts.kind = f->ts.kind;
277 gfc_convert_type (a, &ts, 2);
280 /* The resolved name is only used for specific intrinsics where
281 the return kind is the same as the arg kind. */
282 f->value.function.name
283 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
289 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
291 gfc_resolve_anint (f, a, NULL);
296 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
302 gfc_resolve_dim_arg (dim);
303 f->rank = mask->rank - 1;
304 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
307 f->value.function.name
308 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
314 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
317 f->value.function.name
318 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
322 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
325 f->value.function.name
326 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
331 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
334 f->value.function.name
335 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
339 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
342 f->value.function.name
343 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
348 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
351 f->value.function.name
352 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
357 /* Resolve the BESYN and BESJN intrinsics. */
360 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
365 if (n->ts.kind != gfc_c_int_kind)
367 ts.type = BT_INTEGER;
368 ts.kind = gfc_c_int_kind;
369 gfc_convert_type (n, &ts, 2);
371 f->value.function.name = gfc_get_string ("<intrinsic>");
376 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
378 f->ts.type = BT_LOGICAL;
379 f->ts.kind = gfc_default_logical_kind;
380 f->value.function.name
381 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
386 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
388 f->ts.type = BT_INTEGER;
389 f->ts.kind = (kind == NULL)
390 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
391 f->value.function.name
392 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
393 gfc_type_letter (a->ts.type), a->ts.kind);
398 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
400 gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d");
405 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
407 f->ts.type = BT_INTEGER;
408 f->ts.kind = gfc_default_integer_kind;
409 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
414 gfc_resolve_chdir_sub (gfc_code *c)
419 if (c->ext.actual->next->expr != NULL)
420 kind = c->ext.actual->next->expr->ts.kind;
422 kind = gfc_default_integer_kind;
424 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
425 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
430 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
431 gfc_expr *mode ATTRIBUTE_UNUSED)
433 f->ts.type = BT_INTEGER;
434 f->ts.kind = gfc_c_int_kind;
435 f->value.function.name = PREFIX ("chmod_func");
440 gfc_resolve_chmod_sub (gfc_code *c)
445 if (c->ext.actual->next->next->expr != NULL)
446 kind = c->ext.actual->next->next->expr->ts.kind;
448 kind = gfc_default_integer_kind;
450 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
451 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
456 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
458 f->ts.type = BT_COMPLEX;
459 f->ts.kind = (kind == NULL)
460 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
463 f->value.function.name
464 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
465 gfc_type_letter (x->ts.type), x->ts.kind);
467 f->value.function.name
468 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
469 gfc_type_letter (x->ts.type), x->ts.kind,
470 gfc_type_letter (y->ts.type), y->ts.kind);
475 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
477 gfc_resolve_cmplx (f, x, y, gfc_int_expr (gfc_default_double_kind));
482 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
486 if (x->ts.type == BT_INTEGER)
488 if (y->ts.type == BT_INTEGER)
489 kind = gfc_default_real_kind;
495 if (y->ts.type == BT_REAL)
496 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
501 f->ts.type = BT_COMPLEX;
503 f->value.function.name
504 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
505 gfc_type_letter (x->ts.type), x->ts.kind,
506 gfc_type_letter (y->ts.type), y->ts.kind);
511 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
514 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
519 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
522 f->value.function.name
523 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
528 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
531 f->value.function.name
532 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
537 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
539 f->ts.type = BT_INTEGER;
541 f->ts.kind = mpz_get_si (kind->value.integer);
543 f->ts.kind = gfc_default_integer_kind;
547 f->rank = mask->rank - 1;
548 gfc_resolve_dim_arg (dim);
549 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
552 resolve_mask_arg (mask);
554 f->value.function.name
555 = gfc_get_string (PREFIX ("count_%d_%c"), f->ts.kind,
556 gfc_type_letter (mask->ts.type));
561 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
566 if (array->ts.type == BT_CHARACTER && array->ref)
567 gfc_resolve_substring_charlen (array);
570 f->rank = array->rank;
571 f->shape = gfc_copy_shape (array->shape, array->rank);
578 /* If dim kind is greater than default integer we need to use the larger. */
579 m = gfc_default_integer_kind;
581 m = m < dim->ts.kind ? dim->ts.kind : m;
583 /* Convert shift to at least m, so we don't need
584 kind=1 and kind=2 versions of the library functions. */
585 if (shift->ts.kind < m)
588 ts.type = BT_INTEGER;
590 gfc_convert_type_warn (shift, &ts, 2, 0);
595 if (dim->expr_type != EXPR_CONSTANT && dim->symtree->n.sym->attr.optional)
597 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
598 dim->representation.length = shift->ts.kind;
602 gfc_resolve_dim_arg (dim);
603 /* Convert dim to shift's kind to reduce variations. */
604 if (dim->ts.kind != shift->ts.kind)
605 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
609 f->value.function.name
610 = gfc_get_string (PREFIX ("cshift%d_%d%s"), n, shift->ts.kind,
611 array->ts.type == BT_CHARACTER ? "_char" : "");
616 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
620 f->ts.type = BT_CHARACTER;
621 f->ts.kind = gfc_default_character_kind;
623 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
624 if (time->ts.kind != 8)
626 ts.type = BT_INTEGER;
630 gfc_convert_type (time, &ts, 2);
633 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
638 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
640 f->ts.type = BT_REAL;
641 f->ts.kind = gfc_default_double_kind;
642 f->value.function.name
643 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
648 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
650 f->ts.type = a->ts.type;
652 f->ts.kind = gfc_kind_max (a,p);
654 f->ts.kind = a->ts.kind;
656 if (p != NULL && a->ts.kind != p->ts.kind)
658 if (a->ts.kind == gfc_kind_max (a,p))
659 gfc_convert_type (p, &a->ts, 2);
661 gfc_convert_type (a, &p->ts, 2);
664 f->value.function.name
665 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
670 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
674 temp.expr_type = EXPR_OP;
675 gfc_clear_ts (&temp.ts);
676 temp.value.op.operator = INTRINSIC_NONE;
677 temp.value.op.op1 = a;
678 temp.value.op.op2 = b;
679 gfc_type_convert_binary (&temp);
681 f->value.function.name
682 = gfc_get_string (PREFIX ("dot_product_%c%d"),
683 gfc_type_letter (f->ts.type), f->ts.kind);
688 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
689 gfc_expr *b ATTRIBUTE_UNUSED)
691 f->ts.kind = gfc_default_double_kind;
692 f->ts.type = BT_REAL;
693 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
698 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
699 gfc_expr *boundary, gfc_expr *dim)
703 if (array->ts.type == BT_CHARACTER && array->ref)
704 gfc_resolve_substring_charlen (array);
707 f->rank = array->rank;
708 f->shape = gfc_copy_shape (array->shape, array->rank);
713 if (boundary && boundary->rank > 0)
716 /* If dim kind is greater than default integer we need to use the larger. */
717 m = gfc_default_integer_kind;
719 m = m < dim->ts.kind ? dim->ts.kind : m;
721 /* Convert shift to at least m, so we don't need
722 kind=1 and kind=2 versions of the library functions. */
723 if (shift->ts.kind < m)
726 ts.type = BT_INTEGER;
728 gfc_convert_type_warn (shift, &ts, 2, 0);
733 if (dim->expr_type != EXPR_CONSTANT && dim->symtree->n.sym->attr.optional)
735 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
736 dim->representation.length = shift->ts.kind;
740 gfc_resolve_dim_arg (dim);
741 /* Convert dim to shift's kind to reduce variations. */
742 if (dim->ts.kind != shift->ts.kind)
743 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
747 f->value.function.name
748 = gfc_get_string (PREFIX ("eoshift%d_%d%s"), n, shift->ts.kind,
749 array->ts.type == BT_CHARACTER ? "_char" : "");
754 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
757 f->value.function.name
758 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
763 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
765 f->ts.type = BT_INTEGER;
766 f->ts.kind = gfc_default_integer_kind;
767 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
772 gfc_resolve_fdate (gfc_expr *f)
774 f->ts.type = BT_CHARACTER;
775 f->ts.kind = gfc_default_character_kind;
776 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
781 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
783 f->ts.type = BT_INTEGER;
784 f->ts.kind = (kind == NULL)
785 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
786 f->value.function.name
787 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
788 gfc_type_letter (a->ts.type), a->ts.kind);
793 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
795 f->ts.type = BT_INTEGER;
796 f->ts.kind = gfc_default_integer_kind;
797 if (n->ts.kind != f->ts.kind)
798 gfc_convert_type (n, &f->ts, 2);
799 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
804 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
807 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
811 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
814 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
817 f->value.function.name = gfc_get_string ("<intrinsic>");
822 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
825 f->value.function.name
826 = gfc_get_string ("__gamma_%d", x->ts.kind);
831 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
833 f->ts.type = BT_INTEGER;
835 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
840 gfc_resolve_getgid (gfc_expr *f)
842 f->ts.type = BT_INTEGER;
844 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
849 gfc_resolve_getpid (gfc_expr *f)
851 f->ts.type = BT_INTEGER;
853 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
858 gfc_resolve_getuid (gfc_expr *f)
860 f->ts.type = BT_INTEGER;
862 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
867 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
869 f->ts.type = BT_INTEGER;
871 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
876 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
878 /* If the kind of i and j are different, then g77 cross-promoted the
879 kinds to the largest value. The Fortran 95 standard requires the
881 if (i->ts.kind != j->ts.kind)
883 if (i->ts.kind == gfc_kind_max (i, j))
884 gfc_convert_type (j, &i->ts, 2);
886 gfc_convert_type (i, &j->ts, 2);
890 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
895 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
898 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
903 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
904 gfc_expr *len ATTRIBUTE_UNUSED)
907 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
912 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
915 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
920 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
922 f->ts.type = BT_INTEGER;
924 f->ts.kind = mpz_get_si (kind->value.integer);
926 f->ts.kind = gfc_default_integer_kind;
927 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
932 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
934 f->ts.type = BT_INTEGER;
936 f->ts.kind = mpz_get_si (kind->value.integer);
938 f->ts.kind = gfc_default_integer_kind;
939 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
944 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
946 gfc_resolve_nint (f, a, NULL);
951 gfc_resolve_ierrno (gfc_expr *f)
953 f->ts.type = BT_INTEGER;
954 f->ts.kind = gfc_default_integer_kind;
955 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
960 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
962 /* If the kind of i and j are different, then g77 cross-promoted the
963 kinds to the largest value. The Fortran 95 standard requires the
965 if (i->ts.kind != j->ts.kind)
967 if (i->ts.kind == gfc_kind_max (i, j))
968 gfc_convert_type (j, &i->ts, 2);
970 gfc_convert_type (i, &j->ts, 2);
974 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
979 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
981 /* If the kind of i and j are different, then g77 cross-promoted the
982 kinds to the largest value. The Fortran 95 standard requires the
984 if (i->ts.kind != j->ts.kind)
986 if (i->ts.kind == gfc_kind_max (i, j))
987 gfc_convert_type (j, &i->ts, 2);
989 gfc_convert_type (i, &j->ts, 2);
993 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
998 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
999 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
1004 f->ts.type = BT_INTEGER;
1006 f->ts.kind = mpz_get_si (kind->value.integer);
1008 f->ts.kind = gfc_default_integer_kind;
1010 if (back && back->ts.kind != gfc_default_integer_kind)
1012 ts.type = BT_LOGICAL;
1013 ts.kind = gfc_default_integer_kind;
1016 gfc_convert_type (back, &ts, 2);
1019 f->value.function.name
1020 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
1025 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1027 f->ts.type = BT_INTEGER;
1028 f->ts.kind = (kind == NULL)
1029 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1030 f->value.function.name
1031 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1032 gfc_type_letter (a->ts.type), a->ts.kind);
1037 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1039 f->ts.type = BT_INTEGER;
1041 f->value.function.name
1042 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1043 gfc_type_letter (a->ts.type), a->ts.kind);
1048 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
1050 f->ts.type = BT_INTEGER;
1052 f->value.function.name
1053 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1054 gfc_type_letter (a->ts.type), a->ts.kind);
1059 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1061 f->ts.type = BT_INTEGER;
1063 f->value.function.name
1064 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1065 gfc_type_letter (a->ts.type), a->ts.kind);
1070 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1074 f->ts.type = BT_LOGICAL;
1075 f->ts.kind = gfc_default_integer_kind;
1076 if (u->ts.kind != gfc_c_int_kind)
1078 ts.type = BT_INTEGER;
1079 ts.kind = gfc_c_int_kind;
1082 gfc_convert_type (u, &ts, 2);
1085 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1090 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1093 f->value.function.name
1094 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1099 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1102 f->value.function.name
1103 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1108 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1111 f->value.function.name
1112 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1117 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1121 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1124 f->value.function.name
1125 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1130 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1131 gfc_expr *s ATTRIBUTE_UNUSED)
1133 f->ts.type = BT_INTEGER;
1134 f->ts.kind = gfc_default_integer_kind;
1135 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1140 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1142 static char lbound[] = "__lbound";
1144 f->ts.type = BT_INTEGER;
1146 f->ts.kind = mpz_get_si (kind->value.integer);
1148 f->ts.kind = gfc_default_integer_kind;
1153 f->shape = gfc_get_shape (1);
1154 mpz_init_set_ui (f->shape[0], array->rank);
1157 f->value.function.name = lbound;
1162 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1164 f->ts.type = BT_INTEGER;
1166 f->ts.kind = mpz_get_si (kind->value.integer);
1168 f->ts.kind = gfc_default_integer_kind;
1169 f->value.function.name
1170 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1171 gfc_default_integer_kind);
1176 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1178 f->ts.type = BT_INTEGER;
1180 f->ts.kind = mpz_get_si (kind->value.integer);
1182 f->ts.kind = gfc_default_integer_kind;
1183 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1188 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1191 f->value.function.name
1192 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1197 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1198 gfc_expr *p2 ATTRIBUTE_UNUSED)
1200 f->ts.type = BT_INTEGER;
1201 f->ts.kind = gfc_default_integer_kind;
1202 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1207 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1209 f->ts.type= BT_INTEGER;
1210 f->ts.kind = gfc_index_integer_kind;
1211 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1216 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1219 f->value.function.name
1220 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1225 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1228 f->value.function.name
1229 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1235 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1237 f->ts.type = BT_LOGICAL;
1238 f->ts.kind = (kind == NULL)
1239 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1242 f->value.function.name
1243 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1244 gfc_type_letter (a->ts.type), a->ts.kind);
1249 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1251 if (size->ts.kind < gfc_index_integer_kind)
1255 ts.type = BT_INTEGER;
1256 ts.kind = gfc_index_integer_kind;
1257 gfc_convert_type_warn (size, &ts, 2, 0);
1260 f->ts.type = BT_INTEGER;
1261 f->ts.kind = gfc_index_integer_kind;
1262 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1267 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1271 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1273 f->ts.type = BT_LOGICAL;
1274 f->ts.kind = gfc_default_logical_kind;
1278 temp.expr_type = EXPR_OP;
1279 gfc_clear_ts (&temp.ts);
1280 temp.value.op.operator = INTRINSIC_NONE;
1281 temp.value.op.op1 = a;
1282 temp.value.op.op2 = b;
1283 gfc_type_convert_binary (&temp);
1287 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1289 f->value.function.name
1290 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1296 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1298 gfc_actual_arglist *a;
1300 f->ts.type = args->expr->ts.type;
1301 f->ts.kind = args->expr->ts.kind;
1302 /* Find the largest type kind. */
1303 for (a = args->next; a; a = a->next)
1305 if (a->expr->ts.kind > f->ts.kind)
1306 f->ts.kind = a->expr->ts.kind;
1309 /* Convert all parameters to the required kind. */
1310 for (a = args; a; a = a->next)
1312 if (a->expr->ts.kind != f->ts.kind)
1313 gfc_convert_type (a->expr, &f->ts, 2);
1316 f->value.function.name
1317 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1322 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1324 gfc_resolve_minmax ("__max_%c%d", f, args);
1329 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1335 f->ts.type = BT_INTEGER;
1336 f->ts.kind = gfc_default_integer_kind;
1341 f->shape = gfc_get_shape (1);
1342 mpz_init_set_si (f->shape[0], array->rank);
1346 f->rank = array->rank - 1;
1347 gfc_resolve_dim_arg (dim);
1348 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1350 idim = (int) mpz_get_si (dim->value.integer);
1351 f->shape = gfc_get_shape (f->rank);
1352 for (i = 0, j = 0; i < f->rank; i++, j++)
1354 if (i == (idim - 1))
1356 mpz_init_set (f->shape[i], array->shape[j]);
1363 if (mask->rank == 0)
1368 resolve_mask_arg (mask);
1373 f->value.function.name
1374 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1375 gfc_type_letter (array->ts.type), array->ts.kind);
1380 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1390 f->rank = array->rank - 1;
1391 gfc_resolve_dim_arg (dim);
1393 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1395 idim = (int) mpz_get_si (dim->value.integer);
1396 f->shape = gfc_get_shape (f->rank);
1397 for (i = 0, j = 0; i < f->rank; i++, j++)
1399 if (i == (idim - 1))
1401 mpz_init_set (f->shape[i], array->shape[j]);
1408 if (mask->rank == 0)
1413 resolve_mask_arg (mask);
1418 f->value.function.name
1419 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1420 gfc_type_letter (array->ts.type), array->ts.kind);
1425 gfc_resolve_mclock (gfc_expr *f)
1427 f->ts.type = BT_INTEGER;
1429 f->value.function.name = PREFIX ("mclock");
1434 gfc_resolve_mclock8 (gfc_expr *f)
1436 f->ts.type = BT_INTEGER;
1438 f->value.function.name = PREFIX ("mclock8");
1443 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1444 gfc_expr *fsource ATTRIBUTE_UNUSED,
1445 gfc_expr *mask ATTRIBUTE_UNUSED)
1447 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1448 gfc_resolve_substring_charlen (tsource);
1450 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1451 gfc_resolve_substring_charlen (fsource);
1453 if (tsource->ts.type == BT_CHARACTER)
1454 check_charlen_present (tsource);
1456 f->ts = tsource->ts;
1457 f->value.function.name
1458 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1464 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1466 gfc_resolve_minmax ("__min_%c%d", f, args);
1471 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1477 f->ts.type = BT_INTEGER;
1478 f->ts.kind = gfc_default_integer_kind;
1483 f->shape = gfc_get_shape (1);
1484 mpz_init_set_si (f->shape[0], array->rank);
1488 f->rank = array->rank - 1;
1489 gfc_resolve_dim_arg (dim);
1490 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1492 idim = (int) mpz_get_si (dim->value.integer);
1493 f->shape = gfc_get_shape (f->rank);
1494 for (i = 0, j = 0; i < f->rank; i++, j++)
1496 if (i == (idim - 1))
1498 mpz_init_set (f->shape[i], array->shape[j]);
1505 if (mask->rank == 0)
1510 resolve_mask_arg (mask);
1515 f->value.function.name
1516 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1517 gfc_type_letter (array->ts.type), array->ts.kind);
1522 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1532 f->rank = array->rank - 1;
1533 gfc_resolve_dim_arg (dim);
1535 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1537 idim = (int) mpz_get_si (dim->value.integer);
1538 f->shape = gfc_get_shape (f->rank);
1539 for (i = 0, j = 0; i < f->rank; i++, j++)
1541 if (i == (idim - 1))
1543 mpz_init_set (f->shape[i], array->shape[j]);
1550 if (mask->rank == 0)
1555 resolve_mask_arg (mask);
1560 f->value.function.name
1561 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1562 gfc_type_letter (array->ts.type), array->ts.kind);
1567 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1569 f->ts.type = a->ts.type;
1571 f->ts.kind = gfc_kind_max (a,p);
1573 f->ts.kind = a->ts.kind;
1575 if (p != NULL && a->ts.kind != p->ts.kind)
1577 if (a->ts.kind == gfc_kind_max (a,p))
1578 gfc_convert_type (p, &a->ts, 2);
1580 gfc_convert_type (a, &p->ts, 2);
1583 f->value.function.name
1584 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1589 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1591 f->ts.type = a->ts.type;
1593 f->ts.kind = gfc_kind_max (a,p);
1595 f->ts.kind = a->ts.kind;
1597 if (p != NULL && a->ts.kind != p->ts.kind)
1599 if (a->ts.kind == gfc_kind_max (a,p))
1600 gfc_convert_type (p, &a->ts, 2);
1602 gfc_convert_type (a, &p->ts, 2);
1605 f->value.function.name
1606 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1611 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1613 if (p->ts.kind != a->ts.kind)
1614 gfc_convert_type (p, &a->ts, 2);
1617 f->value.function.name
1618 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1623 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1625 f->ts.type = BT_INTEGER;
1626 f->ts.kind = (kind == NULL)
1627 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1628 f->value.function.name
1629 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1634 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1637 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1642 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1644 f->ts.type = i->ts.type;
1645 f->ts.kind = gfc_kind_max (i, j);
1647 if (i->ts.kind != j->ts.kind)
1649 if (i->ts.kind == gfc_kind_max (i, j))
1650 gfc_convert_type (j, &i->ts, 2);
1652 gfc_convert_type (i, &j->ts, 2);
1655 f->value.function.name
1656 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1661 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1662 gfc_expr *vector ATTRIBUTE_UNUSED)
1664 if (array->ts.type == BT_CHARACTER && array->ref)
1665 gfc_resolve_substring_charlen (array);
1670 resolve_mask_arg (mask);
1672 if (mask->rank != 0)
1673 f->value.function.name = (array->ts.type == BT_CHARACTER
1674 ? PREFIX ("pack_char") : PREFIX ("pack"));
1676 f->value.function.name = (array->ts.type == BT_CHARACTER
1677 ? PREFIX ("pack_s_char") : PREFIX ("pack_s"));
1682 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1691 f->rank = array->rank - 1;
1692 gfc_resolve_dim_arg (dim);
1697 if (mask->rank == 0)
1702 resolve_mask_arg (mask);
1707 f->value.function.name
1708 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1709 gfc_type_letter (array->ts.type), array->ts.kind);
1714 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1716 f->ts.type = BT_REAL;
1719 f->ts.kind = mpz_get_si (kind->value.integer);
1721 f->ts.kind = (a->ts.type == BT_COMPLEX)
1722 ? a->ts.kind : gfc_default_real_kind;
1724 f->value.function.name
1725 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1726 gfc_type_letter (a->ts.type), a->ts.kind);
1731 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1733 f->ts.type = BT_REAL;
1734 f->ts.kind = a->ts.kind;
1735 f->value.function.name
1736 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1737 gfc_type_letter (a->ts.type), a->ts.kind);
1742 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1743 gfc_expr *p2 ATTRIBUTE_UNUSED)
1745 f->ts.type = BT_INTEGER;
1746 f->ts.kind = gfc_default_integer_kind;
1747 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1752 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
1753 gfc_expr *ncopies ATTRIBUTE_UNUSED)
1755 f->ts.type = BT_CHARACTER;
1756 f->ts.kind = string->ts.kind;
1757 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
1762 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
1763 gfc_expr *pad ATTRIBUTE_UNUSED,
1764 gfc_expr *order ATTRIBUTE_UNUSED)
1770 if (source->ts.type == BT_CHARACTER && source->ref)
1771 gfc_resolve_substring_charlen (source);
1775 gfc_array_size (shape, &rank);
1776 f->rank = mpz_get_si (rank);
1778 switch (source->ts.type)
1784 kind = source->ts.kind;
1798 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
1799 f->value.function.name
1800 = gfc_get_string (PREFIX ("reshape_%c%d"),
1801 gfc_type_letter (source->ts.type),
1804 f->value.function.name
1805 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
1810 f->value.function.name = (source->ts.type == BT_CHARACTER
1811 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1815 /* TODO: Make this work with a constant ORDER parameter. */
1816 if (shape->expr_type == EXPR_ARRAY
1817 && gfc_is_constant_expr (shape)
1821 f->shape = gfc_get_shape (f->rank);
1822 c = shape->value.constructor;
1823 for (i = 0; i < f->rank; i++)
1825 mpz_init_set (f->shape[i], c->expr->value.integer);
1830 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
1831 so many runtime variations. */
1832 if (shape->ts.kind != gfc_index_integer_kind)
1834 gfc_typespec ts = shape->ts;
1835 ts.kind = gfc_index_integer_kind;
1836 gfc_convert_type_warn (shape, &ts, 2, 0);
1838 if (order && order->ts.kind != gfc_index_integer_kind)
1839 gfc_convert_type_warn (order, &shape->ts, 2, 0);
1844 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
1847 gfc_actual_arglist *prec;
1850 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
1852 /* Create a hidden argument to the library routines for rrspacing. This
1853 hidden argument is the precision of x. */
1854 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1855 prec = gfc_get_actual_arglist ();
1857 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1858 /* The library routine expects INTEGER(4). */
1859 if (prec->expr->ts.kind != gfc_c_int_kind)
1862 ts.type = BT_INTEGER;
1863 ts.kind = gfc_c_int_kind;
1864 gfc_convert_type (prec->expr, &ts, 2);
1866 f->value.function.actual->next = prec;
1871 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1875 /* The implementation calls scalbn which takes an int as the
1877 if (i->ts.kind != gfc_c_int_kind)
1880 ts.type = BT_INTEGER;
1881 ts.kind = gfc_c_int_kind;
1882 gfc_convert_type_warn (i, &ts, 2, 0);
1885 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
1890 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
1891 gfc_expr *set ATTRIBUTE_UNUSED,
1892 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
1894 f->ts.type = BT_INTEGER;
1896 f->ts.kind = mpz_get_si (kind->value.integer);
1898 f->ts.kind = gfc_default_integer_kind;
1899 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
1904 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
1907 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
1912 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1916 /* The library implementation uses GFC_INTEGER_4 unconditionally,
1917 convert type so we don't have to implement all possible
1919 if (i->ts.kind != gfc_c_int_kind)
1922 ts.type = BT_INTEGER;
1923 ts.kind = gfc_c_int_kind;
1924 gfc_convert_type_warn (i, &ts, 2, 0);
1927 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
1932 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
1934 f->ts.type = BT_INTEGER;
1935 f->ts.kind = gfc_default_integer_kind;
1937 f->shape = gfc_get_shape (1);
1938 mpz_init_set_ui (f->shape[0], array->rank);
1939 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
1944 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
1947 f->value.function.name
1948 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
1953 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
1955 f->ts.type = BT_INTEGER;
1956 f->ts.kind = gfc_c_int_kind;
1958 /* handler can be either BT_INTEGER or BT_PROCEDURE */
1959 if (handler->ts.type == BT_INTEGER)
1961 if (handler->ts.kind != gfc_c_int_kind)
1962 gfc_convert_type (handler, &f->ts, 2);
1963 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
1966 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
1968 if (number->ts.kind != gfc_c_int_kind)
1969 gfc_convert_type (number, &f->ts, 2);
1974 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
1977 f->value.function.name
1978 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1983 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
1986 f->value.function.name
1987 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1992 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
1993 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
1995 f->ts.type = BT_INTEGER;
1997 f->ts.kind = mpz_get_si (kind->value.integer);
1999 f->ts.kind = gfc_default_integer_kind;
2004 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
2007 gfc_actual_arglist *prec, *tiny, *emin_1;
2010 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
2012 /* Create hidden arguments to the library routine for spacing. These
2013 hidden arguments are tiny(x), min_exponent - 1, and the precision
2016 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
2018 tiny = gfc_get_actual_arglist ();
2019 tiny->name = "tiny";
2020 tiny->expr = gfc_get_expr ();
2021 tiny->expr->expr_type = EXPR_CONSTANT;
2022 tiny->expr->where = gfc_current_locus;
2023 tiny->expr->ts.type = x->ts.type;
2024 tiny->expr->ts.kind = x->ts.kind;
2025 mpfr_init (tiny->expr->value.real);
2026 mpfr_set (tiny->expr->value.real, gfc_real_kinds[k].tiny, GFC_RND_MODE);
2028 emin_1 = gfc_get_actual_arglist ();
2029 emin_1->name = "emin";
2030 emin_1->expr = gfc_int_expr (gfc_real_kinds[k].min_exponent - 1);
2032 /* The library routine expects INTEGER(4). */
2033 if (emin_1->expr->ts.kind != gfc_c_int_kind)
2036 ts.type = BT_INTEGER;
2037 ts.kind = gfc_c_int_kind;
2038 gfc_convert_type (emin_1->expr, &ts, 2);
2040 emin_1->next = tiny;
2042 prec = gfc_get_actual_arglist ();
2043 prec->name = "prec";
2044 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
2046 /* The library routine expects INTEGER(4). */
2047 if (prec->expr->ts.kind != gfc_c_int_kind)
2050 ts.type = BT_INTEGER;
2051 ts.kind = gfc_c_int_kind;
2052 gfc_convert_type (prec->expr, &ts, 2);
2054 prec->next = emin_1;
2056 f->value.function.actual->next = prec;
2061 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2064 if (source->ts.type == BT_CHARACTER && source->ref)
2065 gfc_resolve_substring_charlen (source);
2067 if (source->ts.type == BT_CHARACTER)
2068 check_charlen_present (source);
2071 f->rank = source->rank + 1;
2072 if (source->rank == 0)
2073 f->value.function.name = (source->ts.type == BT_CHARACTER
2074 ? PREFIX ("spread_char_scalar")
2075 : PREFIX ("spread_scalar"));
2077 f->value.function.name = (source->ts.type == BT_CHARACTER
2078 ? PREFIX ("spread_char")
2079 : PREFIX ("spread"));
2081 if (dim && gfc_is_constant_expr (dim)
2082 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2085 idim = mpz_get_ui (dim->value.integer);
2086 f->shape = gfc_get_shape (f->rank);
2087 for (i = 0; i < (idim - 1); i++)
2088 mpz_init_set (f->shape[i], source->shape[i]);
2090 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2092 for (i = idim; i < f->rank ; i++)
2093 mpz_init_set (f->shape[i], source->shape[i-1]);
2097 gfc_resolve_dim_arg (dim);
2098 gfc_resolve_index (ncopies, 1);
2103 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2106 f->value.function.name
2107 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2111 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2114 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2115 gfc_expr *a ATTRIBUTE_UNUSED)
2117 f->ts.type = BT_INTEGER;
2118 f->ts.kind = gfc_default_integer_kind;
2119 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2124 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2125 gfc_expr *a ATTRIBUTE_UNUSED)
2127 f->ts.type = BT_INTEGER;
2128 f->ts.kind = gfc_default_integer_kind;
2129 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2134 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2136 f->ts.type = BT_INTEGER;
2137 f->ts.kind = gfc_default_integer_kind;
2138 if (n->ts.kind != f->ts.kind)
2139 gfc_convert_type (n, &f->ts, 2);
2141 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2146 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2150 f->ts.type = BT_INTEGER;
2151 f->ts.kind = gfc_c_int_kind;
2152 if (u->ts.kind != gfc_c_int_kind)
2154 ts.type = BT_INTEGER;
2155 ts.kind = gfc_c_int_kind;
2158 gfc_convert_type (u, &ts, 2);
2161 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2166 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2168 f->ts.type = BT_INTEGER;
2169 f->ts.kind = gfc_c_int_kind;
2170 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2175 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2179 f->ts.type = BT_INTEGER;
2180 f->ts.kind = gfc_c_int_kind;
2181 if (u->ts.kind != gfc_c_int_kind)
2183 ts.type = BT_INTEGER;
2184 ts.kind = gfc_c_int_kind;
2187 gfc_convert_type (u, &ts, 2);
2190 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2195 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2197 f->ts.type = BT_INTEGER;
2198 f->ts.kind = gfc_c_int_kind;
2199 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2204 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2208 f->ts.type = BT_INTEGER;
2209 f->ts.kind = gfc_index_integer_kind;
2210 if (u->ts.kind != gfc_c_int_kind)
2212 ts.type = BT_INTEGER;
2213 ts.kind = gfc_c_int_kind;
2216 gfc_convert_type (u, &ts, 2);
2219 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2224 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2232 if (mask->rank == 0)
2237 resolve_mask_arg (mask);
2244 f->rank = array->rank - 1;
2245 gfc_resolve_dim_arg (dim);
2248 f->value.function.name
2249 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2250 gfc_type_letter (array->ts.type), array->ts.kind);
2255 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2256 gfc_expr *p2 ATTRIBUTE_UNUSED)
2258 f->ts.type = BT_INTEGER;
2259 f->ts.kind = gfc_default_integer_kind;
2260 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2264 /* Resolve the g77 compatibility function SYSTEM. */
2267 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2269 f->ts.type = BT_INTEGER;
2271 f->value.function.name = gfc_get_string (PREFIX ("system"));
2276 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2279 f->value.function.name
2280 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2285 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2288 f->value.function.name
2289 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2294 gfc_resolve_time (gfc_expr *f)
2296 f->ts.type = BT_INTEGER;
2298 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2303 gfc_resolve_time8 (gfc_expr *f)
2305 f->ts.type = BT_INTEGER;
2307 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2312 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2313 gfc_expr *mold, gfc_expr *size)
2315 /* TODO: Make this do something meaningful. */
2316 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2318 if (mold->ts.type == BT_CHARACTER && !mold->ts.cl->length
2319 && !(mold->expr_type == EXPR_VARIABLE && mold->symtree->n.sym->attr.dummy))
2320 mold->ts.cl->length = gfc_int_expr (mold->value.character.length);
2324 if (size == NULL && mold->rank == 0)
2327 f->value.function.name = transfer0;
2332 f->value.function.name = transfer1;
2333 if (size && gfc_is_constant_expr (size))
2335 f->shape = gfc_get_shape (1);
2336 mpz_init_set (f->shape[0], size->value.integer);
2343 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2346 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2347 gfc_resolve_substring_charlen (matrix);
2353 f->shape = gfc_get_shape (2);
2354 mpz_init_set (f->shape[0], matrix->shape[1]);
2355 mpz_init_set (f->shape[1], matrix->shape[0]);
2358 switch (matrix->ts.kind)
2364 switch (matrix->ts.type)
2368 f->value.function.name
2369 = gfc_get_string (PREFIX ("transpose_%c%d"),
2370 gfc_type_letter (matrix->ts.type),
2376 /* Use the integer routines for real and logical cases. This
2377 assumes they all have the same alignment requirements. */
2378 f->value.function.name
2379 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2383 f->value.function.name = PREFIX ("transpose");
2389 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2390 ? PREFIX ("transpose_char")
2391 : PREFIX ("transpose"));
2398 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2400 f->ts.type = BT_CHARACTER;
2401 f->ts.kind = string->ts.kind;
2402 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2407 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2409 static char ubound[] = "__ubound";
2411 f->ts.type = BT_INTEGER;
2413 f->ts.kind = mpz_get_si (kind->value.integer);
2415 f->ts.kind = gfc_default_integer_kind;
2420 f->shape = gfc_get_shape (1);
2421 mpz_init_set_ui (f->shape[0], array->rank);
2424 f->value.function.name = ubound;
2428 /* Resolve the g77 compatibility function UMASK. */
2431 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2433 f->ts.type = BT_INTEGER;
2434 f->ts.kind = n->ts.kind;
2435 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2439 /* Resolve the g77 compatibility function UNLINK. */
2442 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2444 f->ts.type = BT_INTEGER;
2446 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2451 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2455 f->ts.type = BT_CHARACTER;
2456 f->ts.kind = gfc_default_character_kind;
2458 if (unit->ts.kind != gfc_c_int_kind)
2460 ts.type = BT_INTEGER;
2461 ts.kind = gfc_c_int_kind;
2464 gfc_convert_type (unit, &ts, 2);
2467 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2472 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2473 gfc_expr *field ATTRIBUTE_UNUSED)
2475 if (vector->ts.type == BT_CHARACTER && vector->ref)
2476 gfc_resolve_substring_charlen (vector);
2479 f->rank = mask->rank;
2480 resolve_mask_arg (mask);
2482 f->value.function.name
2483 = gfc_get_string (PREFIX ("unpack%d%s"), field->rank > 0 ? 1 : 0,
2484 vector->ts.type == BT_CHARACTER ? "_char" : "");
2489 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2490 gfc_expr *set ATTRIBUTE_UNUSED,
2491 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2493 f->ts.type = BT_INTEGER;
2495 f->ts.kind = mpz_get_si (kind->value.integer);
2497 f->ts.kind = gfc_default_integer_kind;
2498 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2503 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2505 f->ts.type = i->ts.type;
2506 f->ts.kind = gfc_kind_max (i, j);
2508 if (i->ts.kind != j->ts.kind)
2510 if (i->ts.kind == gfc_kind_max (i, j))
2511 gfc_convert_type (j, &i->ts, 2);
2513 gfc_convert_type (i, &j->ts, 2);
2516 f->value.function.name
2517 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2521 /* Intrinsic subroutine resolution. */
2524 gfc_resolve_alarm_sub (gfc_code *c)
2527 gfc_expr *seconds, *handler, *status;
2530 seconds = c->ext.actual->expr;
2531 handler = c->ext.actual->next->expr;
2532 status = c->ext.actual->next->next->expr;
2533 ts.type = BT_INTEGER;
2534 ts.kind = gfc_c_int_kind;
2536 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2537 In all cases, the status argument is of default integer kind
2538 (enforced in check.c) so that the function suffix is fixed. */
2539 if (handler->ts.type == BT_INTEGER)
2541 if (handler->ts.kind != gfc_c_int_kind)
2542 gfc_convert_type (handler, &ts, 2);
2543 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2544 gfc_default_integer_kind);
2547 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2548 gfc_default_integer_kind);
2550 if (seconds->ts.kind != gfc_c_int_kind)
2551 gfc_convert_type (seconds, &ts, 2);
2553 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2557 gfc_resolve_cpu_time (gfc_code *c)
2560 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2561 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2566 gfc_resolve_mvbits (gfc_code *c)
2571 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2572 they will be converted so that they fit into a C int. */
2573 ts.type = BT_INTEGER;
2574 ts.kind = gfc_c_int_kind;
2575 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2576 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2577 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2578 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2579 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2580 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2582 /* TO and FROM are guaranteed to have the same kind parameter. */
2583 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2584 c->ext.actual->expr->ts.kind);
2585 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2586 /* Mark as elemental subroutine as this does not happen automatically. */
2587 c->resolved_sym->attr.elemental = 1;
2592 gfc_resolve_random_number (gfc_code *c)
2597 kind = c->ext.actual->expr->ts.kind;
2598 if (c->ext.actual->expr->rank == 0)
2599 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2601 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2603 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2608 gfc_resolve_random_seed (gfc_code *c)
2612 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2613 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2618 gfc_resolve_rename_sub (gfc_code *c)
2623 if (c->ext.actual->next->next->expr != NULL)
2624 kind = c->ext.actual->next->next->expr->ts.kind;
2626 kind = gfc_default_integer_kind;
2628 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2629 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2634 gfc_resolve_kill_sub (gfc_code *c)
2639 if (c->ext.actual->next->next->expr != NULL)
2640 kind = c->ext.actual->next->next->expr->ts.kind;
2642 kind = gfc_default_integer_kind;
2644 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2645 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2650 gfc_resolve_link_sub (gfc_code *c)
2655 if (c->ext.actual->next->next->expr != NULL)
2656 kind = c->ext.actual->next->next->expr->ts.kind;
2658 kind = gfc_default_integer_kind;
2660 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2661 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2666 gfc_resolve_symlnk_sub (gfc_code *c)
2671 if (c->ext.actual->next->next->expr != NULL)
2672 kind = c->ext.actual->next->next->expr->ts.kind;
2674 kind = gfc_default_integer_kind;
2676 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2677 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2681 /* G77 compatibility subroutines dtime() and etime(). */
2684 gfc_resolve_dtime_sub (gfc_code *c)
2687 name = gfc_get_string (PREFIX ("dtime_sub"));
2688 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2692 gfc_resolve_etime_sub (gfc_code *c)
2695 name = gfc_get_string (PREFIX ("etime_sub"));
2696 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2700 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2703 gfc_resolve_itime (gfc_code *c)
2706 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2707 gfc_default_integer_kind));
2711 gfc_resolve_idate (gfc_code *c)
2714 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2715 gfc_default_integer_kind));
2719 gfc_resolve_ltime (gfc_code *c)
2722 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2723 gfc_default_integer_kind));
2727 gfc_resolve_gmtime (gfc_code *c)
2730 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2731 gfc_default_integer_kind));
2735 /* G77 compatibility subroutine second(). */
2738 gfc_resolve_second_sub (gfc_code *c)
2741 name = gfc_get_string (PREFIX ("second_sub"));
2742 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2747 gfc_resolve_sleep_sub (gfc_code *c)
2752 if (c->ext.actual->expr != NULL)
2753 kind = c->ext.actual->expr->ts.kind;
2755 kind = gfc_default_integer_kind;
2757 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2758 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2762 /* G77 compatibility function srand(). */
2765 gfc_resolve_srand (gfc_code *c)
2768 name = gfc_get_string (PREFIX ("srand"));
2769 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2773 /* Resolve the getarg intrinsic subroutine. */
2776 gfc_resolve_getarg (gfc_code *c)
2780 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
2784 ts.type = BT_INTEGER;
2785 ts.kind = gfc_default_integer_kind;
2787 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2790 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
2791 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2795 /* Resolve the getcwd intrinsic subroutine. */
2798 gfc_resolve_getcwd_sub (gfc_code *c)
2803 if (c->ext.actual->next->expr != NULL)
2804 kind = c->ext.actual->next->expr->ts.kind;
2806 kind = gfc_default_integer_kind;
2808 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2809 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2813 /* Resolve the get_command intrinsic subroutine. */
2816 gfc_resolve_get_command (gfc_code *c)
2820 kind = gfc_default_integer_kind;
2821 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2822 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2826 /* Resolve the get_command_argument intrinsic subroutine. */
2829 gfc_resolve_get_command_argument (gfc_code *c)
2833 kind = gfc_default_integer_kind;
2834 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2835 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2839 /* Resolve the get_environment_variable intrinsic subroutine. */
2842 gfc_resolve_get_environment_variable (gfc_code *code)
2846 kind = gfc_default_integer_kind;
2847 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2848 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2853 gfc_resolve_signal_sub (gfc_code *c)
2856 gfc_expr *number, *handler, *status;
2859 number = c->ext.actual->expr;
2860 handler = c->ext.actual->next->expr;
2861 status = c->ext.actual->next->next->expr;
2862 ts.type = BT_INTEGER;
2863 ts.kind = gfc_c_int_kind;
2865 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2866 if (handler->ts.type == BT_INTEGER)
2868 if (handler->ts.kind != gfc_c_int_kind)
2869 gfc_convert_type (handler, &ts, 2);
2870 name = gfc_get_string (PREFIX ("signal_sub_int"));
2873 name = gfc_get_string (PREFIX ("signal_sub"));
2875 if (number->ts.kind != gfc_c_int_kind)
2876 gfc_convert_type (number, &ts, 2);
2877 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2878 gfc_convert_type (status, &ts, 2);
2880 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2884 /* Resolve the SYSTEM intrinsic subroutine. */
2887 gfc_resolve_system_sub (gfc_code *c)
2890 name = gfc_get_string (PREFIX ("system_sub"));
2891 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2895 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2898 gfc_resolve_system_clock (gfc_code *c)
2903 if (c->ext.actual->expr != NULL)
2904 kind = c->ext.actual->expr->ts.kind;
2905 else if (c->ext.actual->next->expr != NULL)
2906 kind = c->ext.actual->next->expr->ts.kind;
2907 else 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 ("system_clock_%d"), kind);
2913 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2917 /* Resolve the EXIT intrinsic subroutine. */
2920 gfc_resolve_exit (gfc_code *c)
2926 /* The STATUS argument has to be of default kind. If it is not,
2928 ts.type = BT_INTEGER;
2929 ts.kind = gfc_default_integer_kind;
2930 n = c->ext.actual->expr;
2931 if (n != NULL && n->ts.kind != ts.kind)
2932 gfc_convert_type (n, &ts, 2);
2934 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
2935 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2939 /* Resolve the FLUSH intrinsic subroutine. */
2942 gfc_resolve_flush (gfc_code *c)
2948 ts.type = BT_INTEGER;
2949 ts.kind = gfc_default_integer_kind;
2950 n = c->ext.actual->expr;
2951 if (n != NULL && n->ts.kind != ts.kind)
2952 gfc_convert_type (n, &ts, 2);
2954 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
2955 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2960 gfc_resolve_free (gfc_code *c)
2965 ts.type = BT_INTEGER;
2966 ts.kind = gfc_index_integer_kind;
2967 n = c->ext.actual->expr;
2968 if (n->ts.kind != ts.kind)
2969 gfc_convert_type (n, &ts, 2);
2971 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
2976 gfc_resolve_ctime_sub (gfc_code *c)
2980 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
2981 if (c->ext.actual->expr->ts.kind != 8)
2983 ts.type = BT_INTEGER;
2987 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2990 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
2995 gfc_resolve_fdate_sub (gfc_code *c)
2997 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3002 gfc_resolve_gerror (gfc_code *c)
3004 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3009 gfc_resolve_getlog (gfc_code *c)
3011 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3016 gfc_resolve_hostnm_sub (gfc_code *c)
3021 if (c->ext.actual->next->expr != NULL)
3022 kind = c->ext.actual->next->expr->ts.kind;
3024 kind = gfc_default_integer_kind;
3026 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3027 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3032 gfc_resolve_perror (gfc_code *c)
3034 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3037 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3040 gfc_resolve_stat_sub (gfc_code *c)
3043 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3044 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3049 gfc_resolve_lstat_sub (gfc_code *c)
3052 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3053 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3058 gfc_resolve_fstat_sub (gfc_code *c)
3064 u = c->ext.actual->expr;
3065 ts = &c->ext.actual->next->expr->ts;
3066 if (u->ts.kind != ts->kind)
3067 gfc_convert_type (u, ts, 2);
3068 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3069 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3074 gfc_resolve_fgetc_sub (gfc_code *c)
3080 u = c->ext.actual->expr;
3081 st = c->ext.actual->next->next->expr;
3083 if (u->ts.kind != gfc_c_int_kind)
3085 ts.type = BT_INTEGER;
3086 ts.kind = gfc_c_int_kind;
3089 gfc_convert_type (u, &ts, 2);
3093 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3095 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3097 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3102 gfc_resolve_fget_sub (gfc_code *c)
3107 st = c->ext.actual->next->expr;
3109 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3111 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3113 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3118 gfc_resolve_fputc_sub (gfc_code *c)
3124 u = c->ext.actual->expr;
3125 st = c->ext.actual->next->next->expr;
3127 if (u->ts.kind != gfc_c_int_kind)
3129 ts.type = BT_INTEGER;
3130 ts.kind = gfc_c_int_kind;
3133 gfc_convert_type (u, &ts, 2);
3137 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3139 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3141 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3146 gfc_resolve_fput_sub (gfc_code *c)
3151 st = c->ext.actual->next->expr;
3153 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3155 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3157 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3162 gfc_resolve_fseek_sub (gfc_code *c)
3170 unit = c->ext.actual->expr;
3171 offset = c->ext.actual->next->expr;
3172 whence = c->ext.actual->next->next->expr;
3173 status = c->ext.actual->next->next->next->expr;
3175 if (unit->ts.kind != gfc_c_int_kind)
3177 ts.type = BT_INTEGER;
3178 ts.kind = gfc_c_int_kind;
3181 gfc_convert_type (unit, &ts, 2);
3184 if (offset->ts.kind != gfc_intio_kind)
3186 ts.type = BT_INTEGER;
3187 ts.kind = gfc_intio_kind;
3190 gfc_convert_type (offset, &ts, 2);
3193 if (whence->ts.kind != gfc_c_int_kind)
3195 ts.type = BT_INTEGER;
3196 ts.kind = gfc_c_int_kind;
3199 gfc_convert_type (whence, &ts, 2);
3202 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3206 gfc_resolve_ftell_sub (gfc_code *c)
3213 unit = c->ext.actual->expr;
3214 offset = c->ext.actual->next->expr;
3216 if (unit->ts.kind != gfc_c_int_kind)
3218 ts.type = BT_INTEGER;
3219 ts.kind = gfc_c_int_kind;
3222 gfc_convert_type (unit, &ts, 2);
3225 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3226 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3231 gfc_resolve_ttynam_sub (gfc_code *c)
3235 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3237 ts.type = BT_INTEGER;
3238 ts.kind = gfc_c_int_kind;
3241 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3244 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3248 /* Resolve the UMASK intrinsic subroutine. */
3251 gfc_resolve_umask_sub (gfc_code *c)
3256 if (c->ext.actual->next->expr != NULL)
3257 kind = c->ext.actual->next->expr->ts.kind;
3259 kind = gfc_default_integer_kind;
3261 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3262 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3265 /* Resolve the UNLINK intrinsic subroutine. */
3268 gfc_resolve_unlink_sub (gfc_code *c)
3273 if (c->ext.actual->next->expr != NULL)
3274 kind = c->ext.actual->next->expr->ts.kind;
3276 kind = gfc_default_integer_kind;
3278 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3279 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);