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 resolve_mask_arg (mask);
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)
272 f->ts.type = a->ts.type;
273 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
275 if (a->ts.kind != f->ts.kind)
277 ts.type = f->ts.type;
278 ts.kind = f->ts.kind;
279 gfc_convert_type (a, &ts, 2);
282 /* The resolved name is only used for specific intrinsics where
283 the return kind is the same as the arg kind. */
284 f->value.function.name
285 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
291 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
293 gfc_resolve_anint (f, a, NULL);
298 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
304 gfc_resolve_dim_arg (dim);
305 f->rank = mask->rank - 1;
306 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
309 resolve_mask_arg (mask);
311 f->value.function.name
312 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
318 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
321 f->value.function.name
322 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
326 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
329 f->value.function.name
330 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
335 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
338 f->value.function.name
339 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
343 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
346 f->value.function.name
347 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
352 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
355 f->value.function.name
356 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
361 /* Resolve the BESYN and BESJN intrinsics. */
364 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)
592 ts.type = BT_INTEGER;
594 gfc_convert_type_warn (shift, &ts, 2, 0);
599 if (dim->expr_type != EXPR_CONSTANT && dim->symtree->n.sym->attr.optional)
601 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
602 dim->representation.length = shift->ts.kind;
606 gfc_resolve_dim_arg (dim);
607 /* Convert dim to shift's kind to reduce variations. */
608 if (dim->ts.kind != shift->ts.kind)
609 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
613 f->value.function.name
614 = gfc_get_string (PREFIX ("cshift%d_%d%s"), n, shift->ts.kind,
615 array->ts.type == BT_CHARACTER ? "_char" : "");
620 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
624 f->ts.type = BT_CHARACTER;
625 f->ts.kind = gfc_default_character_kind;
627 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
628 if (time->ts.kind != 8)
630 ts.type = BT_INTEGER;
634 gfc_convert_type (time, &ts, 2);
637 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
642 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
644 f->ts.type = BT_REAL;
645 f->ts.kind = gfc_default_double_kind;
646 f->value.function.name
647 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
652 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
654 f->ts.type = a->ts.type;
656 f->ts.kind = gfc_kind_max (a,p);
658 f->ts.kind = a->ts.kind;
660 if (p != NULL && a->ts.kind != p->ts.kind)
662 if (a->ts.kind == gfc_kind_max (a,p))
663 gfc_convert_type (p, &a->ts, 2);
665 gfc_convert_type (a, &p->ts, 2);
668 f->value.function.name
669 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
674 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
678 temp.expr_type = EXPR_OP;
679 gfc_clear_ts (&temp.ts);
680 temp.value.op.operator = INTRINSIC_NONE;
681 temp.value.op.op1 = a;
682 temp.value.op.op2 = b;
683 gfc_type_convert_binary (&temp);
685 f->value.function.name
686 = gfc_get_string (PREFIX ("dot_product_%c%d"),
687 gfc_type_letter (f->ts.type), f->ts.kind);
692 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
693 gfc_expr *b ATTRIBUTE_UNUSED)
695 f->ts.kind = gfc_default_double_kind;
696 f->ts.type = BT_REAL;
697 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
702 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
703 gfc_expr *boundary, gfc_expr *dim)
707 if (array->ts.type == BT_CHARACTER && array->ref)
708 gfc_resolve_substring_charlen (array);
711 f->rank = array->rank;
712 f->shape = gfc_copy_shape (array->shape, array->rank);
717 if (boundary && boundary->rank > 0)
720 /* If dim kind is greater than default integer we need to use the larger. */
721 m = gfc_default_integer_kind;
723 m = m < dim->ts.kind ? dim->ts.kind : m;
725 /* Convert shift to at least m, so we don't need
726 kind=1 and kind=2 versions of the library functions. */
727 if (shift->ts.kind < m)
730 ts.type = BT_INTEGER;
732 gfc_convert_type_warn (shift, &ts, 2, 0);
737 if (dim->expr_type != EXPR_CONSTANT && dim->symtree->n.sym->attr.optional)
739 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
740 dim->representation.length = shift->ts.kind;
744 gfc_resolve_dim_arg (dim);
745 /* Convert dim to shift's kind to reduce variations. */
746 if (dim->ts.kind != shift->ts.kind)
747 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
751 f->value.function.name
752 = gfc_get_string (PREFIX ("eoshift%d_%d%s"), n, shift->ts.kind,
753 array->ts.type == BT_CHARACTER ? "_char" : "");
758 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
761 f->value.function.name
762 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
767 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
769 f->ts.type = BT_INTEGER;
770 f->ts.kind = gfc_default_integer_kind;
771 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
776 gfc_resolve_fdate (gfc_expr *f)
778 f->ts.type = BT_CHARACTER;
779 f->ts.kind = gfc_default_character_kind;
780 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
785 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
787 f->ts.type = BT_INTEGER;
788 f->ts.kind = (kind == NULL)
789 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
790 f->value.function.name
791 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
792 gfc_type_letter (a->ts.type), a->ts.kind);
797 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
799 f->ts.type = BT_INTEGER;
800 f->ts.kind = gfc_default_integer_kind;
801 if (n->ts.kind != f->ts.kind)
802 gfc_convert_type (n, &f->ts, 2);
803 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
808 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
811 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
815 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
818 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
821 f->value.function.name = gfc_get_string ("<intrinsic>");
826 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
829 f->value.function.name
830 = gfc_get_string ("__gamma_%d", x->ts.kind);
835 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
837 f->ts.type = BT_INTEGER;
839 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
844 gfc_resolve_getgid (gfc_expr *f)
846 f->ts.type = BT_INTEGER;
848 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
853 gfc_resolve_getpid (gfc_expr *f)
855 f->ts.type = BT_INTEGER;
857 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
862 gfc_resolve_getuid (gfc_expr *f)
864 f->ts.type = BT_INTEGER;
866 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
871 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
873 f->ts.type = BT_INTEGER;
875 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
880 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
882 /* If the kind of i and j are different, then g77 cross-promoted the
883 kinds to the largest value. The Fortran 95 standard requires the
885 if (i->ts.kind != j->ts.kind)
887 if (i->ts.kind == gfc_kind_max (i, j))
888 gfc_convert_type (j, &i->ts, 2);
890 gfc_convert_type (i, &j->ts, 2);
894 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
899 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
902 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
907 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
908 gfc_expr *len ATTRIBUTE_UNUSED)
911 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
916 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
919 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
924 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
926 f->ts.type = BT_INTEGER;
928 f->ts.kind = mpz_get_si (kind->value.integer);
930 f->ts.kind = gfc_default_integer_kind;
931 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
936 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
938 f->ts.type = BT_INTEGER;
940 f->ts.kind = mpz_get_si (kind->value.integer);
942 f->ts.kind = gfc_default_integer_kind;
943 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
948 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
950 gfc_resolve_nint (f, a, NULL);
955 gfc_resolve_ierrno (gfc_expr *f)
957 f->ts.type = BT_INTEGER;
958 f->ts.kind = gfc_default_integer_kind;
959 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
964 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
966 /* If the kind of i and j are different, then g77 cross-promoted the
967 kinds to the largest value. The Fortran 95 standard requires the
969 if (i->ts.kind != j->ts.kind)
971 if (i->ts.kind == gfc_kind_max (i, j))
972 gfc_convert_type (j, &i->ts, 2);
974 gfc_convert_type (i, &j->ts, 2);
978 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
983 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
985 /* If the kind of i and j are different, then g77 cross-promoted the
986 kinds to the largest value. The Fortran 95 standard requires the
988 if (i->ts.kind != j->ts.kind)
990 if (i->ts.kind == gfc_kind_max (i, j))
991 gfc_convert_type (j, &i->ts, 2);
993 gfc_convert_type (i, &j->ts, 2);
997 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
1002 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
1003 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
1008 f->ts.type = BT_INTEGER;
1010 f->ts.kind = mpz_get_si (kind->value.integer);
1012 f->ts.kind = gfc_default_integer_kind;
1014 if (back && back->ts.kind != gfc_default_integer_kind)
1016 ts.type = BT_LOGICAL;
1017 ts.kind = gfc_default_integer_kind;
1020 gfc_convert_type (back, &ts, 2);
1023 f->value.function.name
1024 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
1029 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1031 f->ts.type = BT_INTEGER;
1032 f->ts.kind = (kind == NULL)
1033 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1034 f->value.function.name
1035 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1036 gfc_type_letter (a->ts.type), a->ts.kind);
1041 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1043 f->ts.type = BT_INTEGER;
1045 f->value.function.name
1046 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1047 gfc_type_letter (a->ts.type), a->ts.kind);
1052 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
1054 f->ts.type = BT_INTEGER;
1056 f->value.function.name
1057 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1058 gfc_type_letter (a->ts.type), a->ts.kind);
1063 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1065 f->ts.type = BT_INTEGER;
1067 f->value.function.name
1068 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1069 gfc_type_letter (a->ts.type), a->ts.kind);
1074 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1078 f->ts.type = BT_LOGICAL;
1079 f->ts.kind = gfc_default_integer_kind;
1080 if (u->ts.kind != gfc_c_int_kind)
1082 ts.type = BT_INTEGER;
1083 ts.kind = gfc_c_int_kind;
1086 gfc_convert_type (u, &ts, 2);
1089 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1094 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1097 f->value.function.name
1098 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1103 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1106 f->value.function.name
1107 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1112 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1115 f->value.function.name
1116 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1121 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1125 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1128 f->value.function.name
1129 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1134 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1135 gfc_expr *s ATTRIBUTE_UNUSED)
1137 f->ts.type = BT_INTEGER;
1138 f->ts.kind = gfc_default_integer_kind;
1139 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1144 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1146 static char lbound[] = "__lbound";
1148 f->ts.type = BT_INTEGER;
1150 f->ts.kind = mpz_get_si (kind->value.integer);
1152 f->ts.kind = gfc_default_integer_kind;
1157 f->shape = gfc_get_shape (1);
1158 mpz_init_set_ui (f->shape[0], array->rank);
1161 f->value.function.name = lbound;
1166 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1168 f->ts.type = BT_INTEGER;
1170 f->ts.kind = mpz_get_si (kind->value.integer);
1172 f->ts.kind = gfc_default_integer_kind;
1173 f->value.function.name
1174 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1175 gfc_default_integer_kind);
1180 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1182 f->ts.type = BT_INTEGER;
1184 f->ts.kind = mpz_get_si (kind->value.integer);
1186 f->ts.kind = gfc_default_integer_kind;
1187 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1192 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1195 f->value.function.name
1196 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1201 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1202 gfc_expr *p2 ATTRIBUTE_UNUSED)
1204 f->ts.type = BT_INTEGER;
1205 f->ts.kind = gfc_default_integer_kind;
1206 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1211 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1213 f->ts.type= BT_INTEGER;
1214 f->ts.kind = gfc_index_integer_kind;
1215 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1220 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1223 f->value.function.name
1224 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1229 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1232 f->value.function.name
1233 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1239 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1241 f->ts.type = BT_LOGICAL;
1242 f->ts.kind = (kind == NULL)
1243 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1246 f->value.function.name
1247 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1248 gfc_type_letter (a->ts.type), a->ts.kind);
1253 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1255 if (size->ts.kind < gfc_index_integer_kind)
1259 ts.type = BT_INTEGER;
1260 ts.kind = gfc_index_integer_kind;
1261 gfc_convert_type_warn (size, &ts, 2, 0);
1264 f->ts.type = BT_INTEGER;
1265 f->ts.kind = gfc_index_integer_kind;
1266 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1271 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1275 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1277 f->ts.type = BT_LOGICAL;
1278 f->ts.kind = gfc_default_logical_kind;
1282 temp.expr_type = EXPR_OP;
1283 gfc_clear_ts (&temp.ts);
1284 temp.value.op.operator = INTRINSIC_NONE;
1285 temp.value.op.op1 = a;
1286 temp.value.op.op2 = b;
1287 gfc_type_convert_binary (&temp);
1291 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1293 f->value.function.name
1294 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1300 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1302 gfc_actual_arglist *a;
1304 f->ts.type = args->expr->ts.type;
1305 f->ts.kind = args->expr->ts.kind;
1306 /* Find the largest type kind. */
1307 for (a = args->next; a; a = a->next)
1309 if (a->expr->ts.kind > f->ts.kind)
1310 f->ts.kind = a->expr->ts.kind;
1313 /* Convert all parameters to the required kind. */
1314 for (a = args; a; a = a->next)
1316 if (a->expr->ts.kind != f->ts.kind)
1317 gfc_convert_type (a->expr, &f->ts, 2);
1320 f->value.function.name
1321 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1326 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1328 gfc_resolve_minmax ("__max_%c%d", f, args);
1333 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1339 f->ts.type = BT_INTEGER;
1340 f->ts.kind = gfc_default_integer_kind;
1345 f->shape = gfc_get_shape (1);
1346 mpz_init_set_si (f->shape[0], array->rank);
1350 f->rank = array->rank - 1;
1351 gfc_resolve_dim_arg (dim);
1352 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1354 idim = (int) mpz_get_si (dim->value.integer);
1355 f->shape = gfc_get_shape (f->rank);
1356 for (i = 0, j = 0; i < f->rank; i++, j++)
1358 if (i == (idim - 1))
1360 mpz_init_set (f->shape[i], array->shape[j]);
1367 if (mask->rank == 0)
1372 resolve_mask_arg (mask);
1377 f->value.function.name
1378 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1379 gfc_type_letter (array->ts.type), array->ts.kind);
1384 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1394 f->rank = array->rank - 1;
1395 gfc_resolve_dim_arg (dim);
1397 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1399 idim = (int) mpz_get_si (dim->value.integer);
1400 f->shape = gfc_get_shape (f->rank);
1401 for (i = 0, j = 0; i < f->rank; i++, j++)
1403 if (i == (idim - 1))
1405 mpz_init_set (f->shape[i], array->shape[j]);
1412 if (mask->rank == 0)
1417 resolve_mask_arg (mask);
1422 f->value.function.name
1423 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1424 gfc_type_letter (array->ts.type), array->ts.kind);
1429 gfc_resolve_mclock (gfc_expr *f)
1431 f->ts.type = BT_INTEGER;
1433 f->value.function.name = PREFIX ("mclock");
1438 gfc_resolve_mclock8 (gfc_expr *f)
1440 f->ts.type = BT_INTEGER;
1442 f->value.function.name = PREFIX ("mclock8");
1447 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1448 gfc_expr *fsource ATTRIBUTE_UNUSED,
1449 gfc_expr *mask ATTRIBUTE_UNUSED)
1451 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1452 gfc_resolve_substring_charlen (tsource);
1454 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1455 gfc_resolve_substring_charlen (fsource);
1457 if (tsource->ts.type == BT_CHARACTER)
1458 check_charlen_present (tsource);
1460 f->ts = tsource->ts;
1461 f->value.function.name
1462 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1468 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1470 gfc_resolve_minmax ("__min_%c%d", f, args);
1475 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1481 f->ts.type = BT_INTEGER;
1482 f->ts.kind = gfc_default_integer_kind;
1487 f->shape = gfc_get_shape (1);
1488 mpz_init_set_si (f->shape[0], array->rank);
1492 f->rank = array->rank - 1;
1493 gfc_resolve_dim_arg (dim);
1494 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1496 idim = (int) mpz_get_si (dim->value.integer);
1497 f->shape = gfc_get_shape (f->rank);
1498 for (i = 0, j = 0; i < f->rank; i++, j++)
1500 if (i == (idim - 1))
1502 mpz_init_set (f->shape[i], array->shape[j]);
1509 if (mask->rank == 0)
1514 resolve_mask_arg (mask);
1519 f->value.function.name
1520 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1521 gfc_type_letter (array->ts.type), array->ts.kind);
1526 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1536 f->rank = array->rank - 1;
1537 gfc_resolve_dim_arg (dim);
1539 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1541 idim = (int) mpz_get_si (dim->value.integer);
1542 f->shape = gfc_get_shape (f->rank);
1543 for (i = 0, j = 0; i < f->rank; i++, j++)
1545 if (i == (idim - 1))
1547 mpz_init_set (f->shape[i], array->shape[j]);
1554 if (mask->rank == 0)
1559 resolve_mask_arg (mask);
1564 f->value.function.name
1565 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1566 gfc_type_letter (array->ts.type), array->ts.kind);
1571 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1573 f->ts.type = a->ts.type;
1575 f->ts.kind = gfc_kind_max (a,p);
1577 f->ts.kind = a->ts.kind;
1579 if (p != NULL && a->ts.kind != p->ts.kind)
1581 if (a->ts.kind == gfc_kind_max (a,p))
1582 gfc_convert_type (p, &a->ts, 2);
1584 gfc_convert_type (a, &p->ts, 2);
1587 f->value.function.name
1588 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1593 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1595 f->ts.type = a->ts.type;
1597 f->ts.kind = gfc_kind_max (a,p);
1599 f->ts.kind = a->ts.kind;
1601 if (p != NULL && a->ts.kind != p->ts.kind)
1603 if (a->ts.kind == gfc_kind_max (a,p))
1604 gfc_convert_type (p, &a->ts, 2);
1606 gfc_convert_type (a, &p->ts, 2);
1609 f->value.function.name
1610 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1615 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1617 if (p->ts.kind != a->ts.kind)
1618 gfc_convert_type (p, &a->ts, 2);
1621 f->value.function.name
1622 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1627 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1629 f->ts.type = BT_INTEGER;
1630 f->ts.kind = (kind == NULL)
1631 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1632 f->value.function.name
1633 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1638 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1641 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1646 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1648 f->ts.type = i->ts.type;
1649 f->ts.kind = gfc_kind_max (i, j);
1651 if (i->ts.kind != j->ts.kind)
1653 if (i->ts.kind == gfc_kind_max (i, j))
1654 gfc_convert_type (j, &i->ts, 2);
1656 gfc_convert_type (i, &j->ts, 2);
1659 f->value.function.name
1660 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1665 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1666 gfc_expr *vector ATTRIBUTE_UNUSED)
1668 if (array->ts.type == BT_CHARACTER && array->ref)
1669 gfc_resolve_substring_charlen (array);
1674 resolve_mask_arg (mask);
1676 if (mask->rank != 0)
1677 f->value.function.name = (array->ts.type == BT_CHARACTER
1678 ? PREFIX ("pack_char") : PREFIX ("pack"));
1680 f->value.function.name = (array->ts.type == BT_CHARACTER
1681 ? PREFIX ("pack_s_char") : PREFIX ("pack_s"));
1686 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1695 f->rank = array->rank - 1;
1696 gfc_resolve_dim_arg (dim);
1701 if (mask->rank == 0)
1706 resolve_mask_arg (mask);
1711 f->value.function.name
1712 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1713 gfc_type_letter (array->ts.type), array->ts.kind);
1718 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1720 f->ts.type = BT_REAL;
1723 f->ts.kind = mpz_get_si (kind->value.integer);
1725 f->ts.kind = (a->ts.type == BT_COMPLEX)
1726 ? a->ts.kind : gfc_default_real_kind;
1728 f->value.function.name
1729 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1730 gfc_type_letter (a->ts.type), a->ts.kind);
1735 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1737 f->ts.type = BT_REAL;
1738 f->ts.kind = a->ts.kind;
1739 f->value.function.name
1740 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1741 gfc_type_letter (a->ts.type), a->ts.kind);
1746 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1747 gfc_expr *p2 ATTRIBUTE_UNUSED)
1749 f->ts.type = BT_INTEGER;
1750 f->ts.kind = gfc_default_integer_kind;
1751 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1756 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
1757 gfc_expr *ncopies ATTRIBUTE_UNUSED)
1759 f->ts.type = BT_CHARACTER;
1760 f->ts.kind = string->ts.kind;
1761 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
1766 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
1767 gfc_expr *pad ATTRIBUTE_UNUSED,
1768 gfc_expr *order ATTRIBUTE_UNUSED)
1774 if (source->ts.type == BT_CHARACTER && source->ref)
1775 gfc_resolve_substring_charlen (source);
1779 gfc_array_size (shape, &rank);
1780 f->rank = mpz_get_si (rank);
1782 switch (source->ts.type)
1788 kind = source->ts.kind;
1802 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
1803 f->value.function.name
1804 = gfc_get_string (PREFIX ("reshape_%c%d"),
1805 gfc_type_letter (source->ts.type),
1808 f->value.function.name
1809 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
1814 f->value.function.name = (source->ts.type == BT_CHARACTER
1815 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1819 /* TODO: Make this work with a constant ORDER parameter. */
1820 if (shape->expr_type == EXPR_ARRAY
1821 && gfc_is_constant_expr (shape)
1825 f->shape = gfc_get_shape (f->rank);
1826 c = shape->value.constructor;
1827 for (i = 0; i < f->rank; i++)
1829 mpz_init_set (f->shape[i], c->expr->value.integer);
1834 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
1835 so many runtime variations. */
1836 if (shape->ts.kind != gfc_index_integer_kind)
1838 gfc_typespec ts = shape->ts;
1839 ts.kind = gfc_index_integer_kind;
1840 gfc_convert_type_warn (shape, &ts, 2, 0);
1842 if (order && order->ts.kind != gfc_index_integer_kind)
1843 gfc_convert_type_warn (order, &shape->ts, 2, 0);
1848 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
1851 gfc_actual_arglist *prec;
1854 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
1856 /* Create a hidden argument to the library routines for rrspacing. This
1857 hidden argument is the precision of x. */
1858 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1859 prec = gfc_get_actual_arglist ();
1861 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1862 /* The library routine expects INTEGER(4). */
1863 if (prec->expr->ts.kind != gfc_c_int_kind)
1866 ts.type = BT_INTEGER;
1867 ts.kind = gfc_c_int_kind;
1868 gfc_convert_type (prec->expr, &ts, 2);
1870 f->value.function.actual->next = prec;
1875 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1879 /* The implementation calls scalbn which takes an int as the
1881 if (i->ts.kind != gfc_c_int_kind)
1884 ts.type = BT_INTEGER;
1885 ts.kind = gfc_c_int_kind;
1886 gfc_convert_type_warn (i, &ts, 2, 0);
1889 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
1894 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
1895 gfc_expr *set ATTRIBUTE_UNUSED,
1896 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
1898 f->ts.type = BT_INTEGER;
1900 f->ts.kind = mpz_get_si (kind->value.integer);
1902 f->ts.kind = gfc_default_integer_kind;
1903 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
1908 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
1911 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
1916 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1920 /* The library implementation uses GFC_INTEGER_4 unconditionally,
1921 convert type so we don't have to implement all possible
1923 if (i->ts.kind != gfc_c_int_kind)
1926 ts.type = BT_INTEGER;
1927 ts.kind = gfc_c_int_kind;
1928 gfc_convert_type_warn (i, &ts, 2, 0);
1931 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
1936 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
1938 f->ts.type = BT_INTEGER;
1939 f->ts.kind = gfc_default_integer_kind;
1941 f->shape = gfc_get_shape (1);
1942 mpz_init_set_ui (f->shape[0], array->rank);
1943 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
1948 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
1951 f->value.function.name
1952 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
1957 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
1959 f->ts.type = BT_INTEGER;
1960 f->ts.kind = gfc_c_int_kind;
1962 /* handler can be either BT_INTEGER or BT_PROCEDURE */
1963 if (handler->ts.type == BT_INTEGER)
1965 if (handler->ts.kind != gfc_c_int_kind)
1966 gfc_convert_type (handler, &f->ts, 2);
1967 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
1970 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
1972 if (number->ts.kind != gfc_c_int_kind)
1973 gfc_convert_type (number, &f->ts, 2);
1978 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
1981 f->value.function.name
1982 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1987 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
1990 f->value.function.name
1991 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1996 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
1997 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
1999 f->ts.type = BT_INTEGER;
2001 f->ts.kind = mpz_get_si (kind->value.integer);
2003 f->ts.kind = gfc_default_integer_kind;
2008 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
2011 gfc_actual_arglist *prec, *tiny, *emin_1;
2014 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
2016 /* Create hidden arguments to the library routine for spacing. These
2017 hidden arguments are tiny(x), min_exponent - 1, and the precision
2020 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
2022 tiny = gfc_get_actual_arglist ();
2023 tiny->name = "tiny";
2024 tiny->expr = gfc_get_expr ();
2025 tiny->expr->expr_type = EXPR_CONSTANT;
2026 tiny->expr->where = gfc_current_locus;
2027 tiny->expr->ts.type = x->ts.type;
2028 tiny->expr->ts.kind = x->ts.kind;
2029 mpfr_init (tiny->expr->value.real);
2030 mpfr_set (tiny->expr->value.real, gfc_real_kinds[k].tiny, GFC_RND_MODE);
2032 emin_1 = gfc_get_actual_arglist ();
2033 emin_1->name = "emin";
2034 emin_1->expr = gfc_int_expr (gfc_real_kinds[k].min_exponent - 1);
2036 /* The library routine expects INTEGER(4). */
2037 if (emin_1->expr->ts.kind != gfc_c_int_kind)
2040 ts.type = BT_INTEGER;
2041 ts.kind = gfc_c_int_kind;
2042 gfc_convert_type (emin_1->expr, &ts, 2);
2044 emin_1->next = tiny;
2046 prec = gfc_get_actual_arglist ();
2047 prec->name = "prec";
2048 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
2050 /* The library routine expects INTEGER(4). */
2051 if (prec->expr->ts.kind != gfc_c_int_kind)
2054 ts.type = BT_INTEGER;
2055 ts.kind = gfc_c_int_kind;
2056 gfc_convert_type (prec->expr, &ts, 2);
2058 prec->next = emin_1;
2060 f->value.function.actual->next = prec;
2065 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2068 if (source->ts.type == BT_CHARACTER && source->ref)
2069 gfc_resolve_substring_charlen (source);
2071 if (source->ts.type == BT_CHARACTER)
2072 check_charlen_present (source);
2075 f->rank = source->rank + 1;
2076 if (source->rank == 0)
2077 f->value.function.name = (source->ts.type == BT_CHARACTER
2078 ? PREFIX ("spread_char_scalar")
2079 : PREFIX ("spread_scalar"));
2081 f->value.function.name = (source->ts.type == BT_CHARACTER
2082 ? PREFIX ("spread_char")
2083 : PREFIX ("spread"));
2085 if (dim && gfc_is_constant_expr (dim)
2086 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2089 idim = mpz_get_ui (dim->value.integer);
2090 f->shape = gfc_get_shape (f->rank);
2091 for (i = 0; i < (idim - 1); i++)
2092 mpz_init_set (f->shape[i], source->shape[i]);
2094 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2096 for (i = idim; i < f->rank ; i++)
2097 mpz_init_set (f->shape[i], source->shape[i-1]);
2101 gfc_resolve_dim_arg (dim);
2102 gfc_resolve_index (ncopies, 1);
2107 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2110 f->value.function.name
2111 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2115 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2118 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2119 gfc_expr *a ATTRIBUTE_UNUSED)
2121 f->ts.type = BT_INTEGER;
2122 f->ts.kind = gfc_default_integer_kind;
2123 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2128 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2129 gfc_expr *a ATTRIBUTE_UNUSED)
2131 f->ts.type = BT_INTEGER;
2132 f->ts.kind = gfc_default_integer_kind;
2133 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2138 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2140 f->ts.type = BT_INTEGER;
2141 f->ts.kind = gfc_default_integer_kind;
2142 if (n->ts.kind != f->ts.kind)
2143 gfc_convert_type (n, &f->ts, 2);
2145 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2150 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2154 f->ts.type = BT_INTEGER;
2155 f->ts.kind = gfc_c_int_kind;
2156 if (u->ts.kind != gfc_c_int_kind)
2158 ts.type = BT_INTEGER;
2159 ts.kind = gfc_c_int_kind;
2162 gfc_convert_type (u, &ts, 2);
2165 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2170 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2172 f->ts.type = BT_INTEGER;
2173 f->ts.kind = gfc_c_int_kind;
2174 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2179 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2183 f->ts.type = BT_INTEGER;
2184 f->ts.kind = gfc_c_int_kind;
2185 if (u->ts.kind != gfc_c_int_kind)
2187 ts.type = BT_INTEGER;
2188 ts.kind = gfc_c_int_kind;
2191 gfc_convert_type (u, &ts, 2);
2194 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2199 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2201 f->ts.type = BT_INTEGER;
2202 f->ts.kind = gfc_c_int_kind;
2203 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2208 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2212 f->ts.type = BT_INTEGER;
2213 f->ts.kind = gfc_index_integer_kind;
2214 if (u->ts.kind != gfc_c_int_kind)
2216 ts.type = BT_INTEGER;
2217 ts.kind = gfc_c_int_kind;
2220 gfc_convert_type (u, &ts, 2);
2223 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2228 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2236 if (mask->rank == 0)
2241 resolve_mask_arg (mask);
2248 f->rank = array->rank - 1;
2249 gfc_resolve_dim_arg (dim);
2252 f->value.function.name
2253 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2254 gfc_type_letter (array->ts.type), array->ts.kind);
2259 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2260 gfc_expr *p2 ATTRIBUTE_UNUSED)
2262 f->ts.type = BT_INTEGER;
2263 f->ts.kind = gfc_default_integer_kind;
2264 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2268 /* Resolve the g77 compatibility function SYSTEM. */
2271 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2273 f->ts.type = BT_INTEGER;
2275 f->value.function.name = gfc_get_string (PREFIX ("system"));
2280 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2283 f->value.function.name
2284 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2289 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2292 f->value.function.name
2293 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2298 gfc_resolve_time (gfc_expr *f)
2300 f->ts.type = BT_INTEGER;
2302 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2307 gfc_resolve_time8 (gfc_expr *f)
2309 f->ts.type = BT_INTEGER;
2311 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2316 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2317 gfc_expr *mold, gfc_expr *size)
2319 /* TODO: Make this do something meaningful. */
2320 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2322 if (mold->ts.type == BT_CHARACTER && !mold->ts.cl->length
2323 && !(mold->expr_type == EXPR_VARIABLE && mold->symtree->n.sym->attr.dummy))
2324 mold->ts.cl->length = gfc_int_expr (mold->value.character.length);
2328 if (size == NULL && mold->rank == 0)
2331 f->value.function.name = transfer0;
2336 f->value.function.name = transfer1;
2337 if (size && gfc_is_constant_expr (size))
2339 f->shape = gfc_get_shape (1);
2340 mpz_init_set (f->shape[0], size->value.integer);
2347 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2350 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2351 gfc_resolve_substring_charlen (matrix);
2357 f->shape = gfc_get_shape (2);
2358 mpz_init_set (f->shape[0], matrix->shape[1]);
2359 mpz_init_set (f->shape[1], matrix->shape[0]);
2362 switch (matrix->ts.kind)
2368 switch (matrix->ts.type)
2372 f->value.function.name
2373 = gfc_get_string (PREFIX ("transpose_%c%d"),
2374 gfc_type_letter (matrix->ts.type),
2380 /* Use the integer routines for real and logical cases. This
2381 assumes they all have the same alignment requirements. */
2382 f->value.function.name
2383 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2387 f->value.function.name = PREFIX ("transpose");
2393 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2394 ? PREFIX ("transpose_char")
2395 : PREFIX ("transpose"));
2402 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2404 f->ts.type = BT_CHARACTER;
2405 f->ts.kind = string->ts.kind;
2406 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2411 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2413 static char ubound[] = "__ubound";
2415 f->ts.type = BT_INTEGER;
2417 f->ts.kind = mpz_get_si (kind->value.integer);
2419 f->ts.kind = gfc_default_integer_kind;
2424 f->shape = gfc_get_shape (1);
2425 mpz_init_set_ui (f->shape[0], array->rank);
2428 f->value.function.name = ubound;
2432 /* Resolve the g77 compatibility function UMASK. */
2435 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2437 f->ts.type = BT_INTEGER;
2438 f->ts.kind = n->ts.kind;
2439 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2443 /* Resolve the g77 compatibility function UNLINK. */
2446 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2448 f->ts.type = BT_INTEGER;
2450 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2455 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2459 f->ts.type = BT_CHARACTER;
2460 f->ts.kind = gfc_default_character_kind;
2462 if (unit->ts.kind != gfc_c_int_kind)
2464 ts.type = BT_INTEGER;
2465 ts.kind = gfc_c_int_kind;
2468 gfc_convert_type (unit, &ts, 2);
2471 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2476 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2477 gfc_expr *field ATTRIBUTE_UNUSED)
2479 if (vector->ts.type == BT_CHARACTER && vector->ref)
2480 gfc_resolve_substring_charlen (vector);
2483 f->rank = mask->rank;
2484 resolve_mask_arg (mask);
2486 f->value.function.name
2487 = gfc_get_string (PREFIX ("unpack%d%s"), field->rank > 0 ? 1 : 0,
2488 vector->ts.type == BT_CHARACTER ? "_char" : "");
2493 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2494 gfc_expr *set ATTRIBUTE_UNUSED,
2495 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2497 f->ts.type = BT_INTEGER;
2499 f->ts.kind = mpz_get_si (kind->value.integer);
2501 f->ts.kind = gfc_default_integer_kind;
2502 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2507 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2509 f->ts.type = i->ts.type;
2510 f->ts.kind = gfc_kind_max (i, j);
2512 if (i->ts.kind != j->ts.kind)
2514 if (i->ts.kind == gfc_kind_max (i, j))
2515 gfc_convert_type (j, &i->ts, 2);
2517 gfc_convert_type (i, &j->ts, 2);
2520 f->value.function.name
2521 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2525 /* Intrinsic subroutine resolution. */
2528 gfc_resolve_alarm_sub (gfc_code *c)
2531 gfc_expr *seconds, *handler, *status;
2534 seconds = c->ext.actual->expr;
2535 handler = c->ext.actual->next->expr;
2536 status = c->ext.actual->next->next->expr;
2537 ts.type = BT_INTEGER;
2538 ts.kind = gfc_c_int_kind;
2540 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2541 In all cases, the status argument is of default integer kind
2542 (enforced in check.c) so that the function suffix is fixed. */
2543 if (handler->ts.type == BT_INTEGER)
2545 if (handler->ts.kind != gfc_c_int_kind)
2546 gfc_convert_type (handler, &ts, 2);
2547 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2548 gfc_default_integer_kind);
2551 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2552 gfc_default_integer_kind);
2554 if (seconds->ts.kind != gfc_c_int_kind)
2555 gfc_convert_type (seconds, &ts, 2);
2557 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2561 gfc_resolve_cpu_time (gfc_code *c)
2564 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2565 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2570 gfc_resolve_mvbits (gfc_code *c)
2575 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2576 they will be converted so that they fit into a C int. */
2577 ts.type = BT_INTEGER;
2578 ts.kind = gfc_c_int_kind;
2579 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2580 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2581 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2582 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2583 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2584 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2586 /* TO and FROM are guaranteed to have the same kind parameter. */
2587 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2588 c->ext.actual->expr->ts.kind);
2589 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2590 /* Mark as elemental subroutine as this does not happen automatically. */
2591 c->resolved_sym->attr.elemental = 1;
2596 gfc_resolve_random_number (gfc_code *c)
2601 kind = c->ext.actual->expr->ts.kind;
2602 if (c->ext.actual->expr->rank == 0)
2603 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2605 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2607 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2612 gfc_resolve_random_seed (gfc_code *c)
2616 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2617 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2622 gfc_resolve_rename_sub (gfc_code *c)
2627 if (c->ext.actual->next->next->expr != NULL)
2628 kind = c->ext.actual->next->next->expr->ts.kind;
2630 kind = gfc_default_integer_kind;
2632 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2633 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2638 gfc_resolve_kill_sub (gfc_code *c)
2643 if (c->ext.actual->next->next->expr != NULL)
2644 kind = c->ext.actual->next->next->expr->ts.kind;
2646 kind = gfc_default_integer_kind;
2648 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2649 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2654 gfc_resolve_link_sub (gfc_code *c)
2659 if (c->ext.actual->next->next->expr != NULL)
2660 kind = c->ext.actual->next->next->expr->ts.kind;
2662 kind = gfc_default_integer_kind;
2664 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2665 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2670 gfc_resolve_symlnk_sub (gfc_code *c)
2675 if (c->ext.actual->next->next->expr != NULL)
2676 kind = c->ext.actual->next->next->expr->ts.kind;
2678 kind = gfc_default_integer_kind;
2680 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2681 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2685 /* G77 compatibility subroutines dtime() and etime(). */
2688 gfc_resolve_dtime_sub (gfc_code *c)
2691 name = gfc_get_string (PREFIX ("dtime_sub"));
2692 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2696 gfc_resolve_etime_sub (gfc_code *c)
2699 name = gfc_get_string (PREFIX ("etime_sub"));
2700 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2704 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2707 gfc_resolve_itime (gfc_code *c)
2710 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2711 gfc_default_integer_kind));
2715 gfc_resolve_idate (gfc_code *c)
2718 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2719 gfc_default_integer_kind));
2723 gfc_resolve_ltime (gfc_code *c)
2726 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2727 gfc_default_integer_kind));
2731 gfc_resolve_gmtime (gfc_code *c)
2734 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2735 gfc_default_integer_kind));
2739 /* G77 compatibility subroutine second(). */
2742 gfc_resolve_second_sub (gfc_code *c)
2745 name = gfc_get_string (PREFIX ("second_sub"));
2746 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2751 gfc_resolve_sleep_sub (gfc_code *c)
2756 if (c->ext.actual->expr != NULL)
2757 kind = c->ext.actual->expr->ts.kind;
2759 kind = gfc_default_integer_kind;
2761 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2762 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2766 /* G77 compatibility function srand(). */
2769 gfc_resolve_srand (gfc_code *c)
2772 name = gfc_get_string (PREFIX ("srand"));
2773 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2777 /* Resolve the getarg intrinsic subroutine. */
2780 gfc_resolve_getarg (gfc_code *c)
2784 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
2788 ts.type = BT_INTEGER;
2789 ts.kind = gfc_default_integer_kind;
2791 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2794 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
2795 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2799 /* Resolve the getcwd intrinsic subroutine. */
2802 gfc_resolve_getcwd_sub (gfc_code *c)
2807 if (c->ext.actual->next->expr != NULL)
2808 kind = c->ext.actual->next->expr->ts.kind;
2810 kind = gfc_default_integer_kind;
2812 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2813 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2817 /* Resolve the get_command intrinsic subroutine. */
2820 gfc_resolve_get_command (gfc_code *c)
2824 kind = gfc_default_integer_kind;
2825 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2826 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2830 /* Resolve the get_command_argument intrinsic subroutine. */
2833 gfc_resolve_get_command_argument (gfc_code *c)
2837 kind = gfc_default_integer_kind;
2838 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2839 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2843 /* Resolve the get_environment_variable intrinsic subroutine. */
2846 gfc_resolve_get_environment_variable (gfc_code *code)
2850 kind = gfc_default_integer_kind;
2851 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2852 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2857 gfc_resolve_signal_sub (gfc_code *c)
2860 gfc_expr *number, *handler, *status;
2863 number = c->ext.actual->expr;
2864 handler = c->ext.actual->next->expr;
2865 status = c->ext.actual->next->next->expr;
2866 ts.type = BT_INTEGER;
2867 ts.kind = gfc_c_int_kind;
2869 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2870 if (handler->ts.type == BT_INTEGER)
2872 if (handler->ts.kind != gfc_c_int_kind)
2873 gfc_convert_type (handler, &ts, 2);
2874 name = gfc_get_string (PREFIX ("signal_sub_int"));
2877 name = gfc_get_string (PREFIX ("signal_sub"));
2879 if (number->ts.kind != gfc_c_int_kind)
2880 gfc_convert_type (number, &ts, 2);
2881 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2882 gfc_convert_type (status, &ts, 2);
2884 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2888 /* Resolve the SYSTEM intrinsic subroutine. */
2891 gfc_resolve_system_sub (gfc_code *c)
2894 name = gfc_get_string (PREFIX ("system_sub"));
2895 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2899 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2902 gfc_resolve_system_clock (gfc_code *c)
2907 if (c->ext.actual->expr != NULL)
2908 kind = c->ext.actual->expr->ts.kind;
2909 else if (c->ext.actual->next->expr != NULL)
2910 kind = c->ext.actual->next->expr->ts.kind;
2911 else if (c->ext.actual->next->next->expr != NULL)
2912 kind = c->ext.actual->next->next->expr->ts.kind;
2914 kind = gfc_default_integer_kind;
2916 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
2917 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2921 /* Resolve the EXIT intrinsic subroutine. */
2924 gfc_resolve_exit (gfc_code *c)
2930 /* The STATUS argument has to be of default kind. If it is not,
2932 ts.type = BT_INTEGER;
2933 ts.kind = gfc_default_integer_kind;
2934 n = c->ext.actual->expr;
2935 if (n != NULL && n->ts.kind != ts.kind)
2936 gfc_convert_type (n, &ts, 2);
2938 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
2939 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2943 /* Resolve the FLUSH intrinsic subroutine. */
2946 gfc_resolve_flush (gfc_code *c)
2952 ts.type = BT_INTEGER;
2953 ts.kind = gfc_default_integer_kind;
2954 n = c->ext.actual->expr;
2955 if (n != NULL && n->ts.kind != ts.kind)
2956 gfc_convert_type (n, &ts, 2);
2958 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
2959 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2964 gfc_resolve_free (gfc_code *c)
2969 ts.type = BT_INTEGER;
2970 ts.kind = gfc_index_integer_kind;
2971 n = c->ext.actual->expr;
2972 if (n->ts.kind != ts.kind)
2973 gfc_convert_type (n, &ts, 2);
2975 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
2980 gfc_resolve_ctime_sub (gfc_code *c)
2984 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
2985 if (c->ext.actual->expr->ts.kind != 8)
2987 ts.type = BT_INTEGER;
2991 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2994 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
2999 gfc_resolve_fdate_sub (gfc_code *c)
3001 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3006 gfc_resolve_gerror (gfc_code *c)
3008 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3013 gfc_resolve_getlog (gfc_code *c)
3015 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3020 gfc_resolve_hostnm_sub (gfc_code *c)
3025 if (c->ext.actual->next->expr != NULL)
3026 kind = c->ext.actual->next->expr->ts.kind;
3028 kind = gfc_default_integer_kind;
3030 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3031 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3036 gfc_resolve_perror (gfc_code *c)
3038 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3041 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3044 gfc_resolve_stat_sub (gfc_code *c)
3047 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3048 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3053 gfc_resolve_lstat_sub (gfc_code *c)
3056 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3057 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3062 gfc_resolve_fstat_sub (gfc_code *c)
3068 u = c->ext.actual->expr;
3069 ts = &c->ext.actual->next->expr->ts;
3070 if (u->ts.kind != ts->kind)
3071 gfc_convert_type (u, ts, 2);
3072 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3073 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3078 gfc_resolve_fgetc_sub (gfc_code *c)
3084 u = c->ext.actual->expr;
3085 st = c->ext.actual->next->next->expr;
3087 if (u->ts.kind != gfc_c_int_kind)
3089 ts.type = BT_INTEGER;
3090 ts.kind = gfc_c_int_kind;
3093 gfc_convert_type (u, &ts, 2);
3097 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3099 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3101 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3106 gfc_resolve_fget_sub (gfc_code *c)
3111 st = c->ext.actual->next->expr;
3113 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3115 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3117 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3122 gfc_resolve_fputc_sub (gfc_code *c)
3128 u = c->ext.actual->expr;
3129 st = c->ext.actual->next->next->expr;
3131 if (u->ts.kind != gfc_c_int_kind)
3133 ts.type = BT_INTEGER;
3134 ts.kind = gfc_c_int_kind;
3137 gfc_convert_type (u, &ts, 2);
3141 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3143 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3145 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3150 gfc_resolve_fput_sub (gfc_code *c)
3155 st = c->ext.actual->next->expr;
3157 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3159 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3161 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3166 gfc_resolve_fseek_sub (gfc_code *c)
3174 unit = c->ext.actual->expr;
3175 offset = c->ext.actual->next->expr;
3176 whence = c->ext.actual->next->next->expr;
3177 status = c->ext.actual->next->next->next->expr;
3179 if (unit->ts.kind != gfc_c_int_kind)
3181 ts.type = BT_INTEGER;
3182 ts.kind = gfc_c_int_kind;
3185 gfc_convert_type (unit, &ts, 2);
3188 if (offset->ts.kind != gfc_intio_kind)
3190 ts.type = BT_INTEGER;
3191 ts.kind = gfc_intio_kind;
3194 gfc_convert_type (offset, &ts, 2);
3197 if (whence->ts.kind != gfc_c_int_kind)
3199 ts.type = BT_INTEGER;
3200 ts.kind = gfc_c_int_kind;
3203 gfc_convert_type (whence, &ts, 2);
3206 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3210 gfc_resolve_ftell_sub (gfc_code *c)
3217 unit = c->ext.actual->expr;
3218 offset = c->ext.actual->next->expr;
3220 if (unit->ts.kind != gfc_c_int_kind)
3222 ts.type = BT_INTEGER;
3223 ts.kind = gfc_c_int_kind;
3226 gfc_convert_type (unit, &ts, 2);
3229 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3230 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3235 gfc_resolve_ttynam_sub (gfc_code *c)
3239 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3241 ts.type = BT_INTEGER;
3242 ts.kind = gfc_c_int_kind;
3245 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3248 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3252 /* Resolve the UMASK intrinsic subroutine. */
3255 gfc_resolve_umask_sub (gfc_code *c)
3260 if (c->ext.actual->next->expr != NULL)
3261 kind = c->ext.actual->next->expr->ts.kind;
3263 kind = gfc_default_integer_kind;
3265 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3266 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3269 /* Resolve the UNLINK intrinsic subroutine. */
3272 gfc_resolve_unlink_sub (gfc_code *c)
3277 if (c->ext.actual->next->expr != NULL)
3278 kind = c->ext.actual->next->expr->ts.kind;
3280 kind = gfc_default_integer_kind;
3282 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3283 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);