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->expr_type == EXPR_CONSTANT && 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;
70 source->ts.cl->length = gfc_int_expr (source->value.character.length);
75 /********************** Resolution functions **********************/
79 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
82 if (f->ts.type == BT_COMPLEX)
85 f->value.function.name
86 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
91 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
92 gfc_expr *mode ATTRIBUTE_UNUSED)
94 f->ts.type = BT_INTEGER;
95 f->ts.kind = gfc_c_int_kind;
96 f->value.function.name = PREFIX ("access_func");
101 gfc_resolve_achar (gfc_expr *f, gfc_expr *x)
104 f->ts.type = BT_CHARACTER;
105 f->ts.kind = gfc_default_character_kind;
106 f->ts.cl = gfc_get_charlen ();
107 f->ts.cl->next = gfc_current_ns->cl_list;
108 gfc_current_ns->cl_list = f->ts.cl;
109 f->ts.cl->length = gfc_int_expr (1);
111 f->value.function.name
112 = gfc_get_string ("__achar_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
117 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
120 f->value.function.name
121 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
126 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
129 f->value.function.name
130 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
136 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
138 f->ts.type = BT_REAL;
139 f->ts.kind = x->ts.kind;
140 f->value.function.name
141 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
147 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
149 f->ts.type = i->ts.type;
150 f->ts.kind = gfc_kind_max (i, j);
152 if (i->ts.kind != j->ts.kind)
154 if (i->ts.kind == gfc_kind_max (i, j))
155 gfc_convert_type (j, &i->ts, 2);
157 gfc_convert_type (i, &j->ts, 2);
160 f->value.function.name
161 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
166 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
170 f->ts.type = a->ts.type;
171 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
173 if (a->ts.kind != f->ts.kind)
175 ts.type = f->ts.type;
176 ts.kind = f->ts.kind;
177 gfc_convert_type (a, &ts, 2);
179 /* The resolved name is only used for specific intrinsics where
180 the return kind is the same as the arg kind. */
181 f->value.function.name
182 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
187 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
189 gfc_resolve_aint (f, a, NULL);
194 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
200 gfc_resolve_dim_arg (dim);
201 f->rank = mask->rank - 1;
202 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
205 f->value.function.name
206 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
212 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
216 f->ts.type = a->ts.type;
217 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
219 if (a->ts.kind != f->ts.kind)
221 ts.type = f->ts.type;
222 ts.kind = f->ts.kind;
223 gfc_convert_type (a, &ts, 2);
226 /* The resolved name is only used for specific intrinsics where
227 the return kind is the same as the arg kind. */
228 f->value.function.name
229 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
235 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
237 gfc_resolve_anint (f, a, NULL);
242 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
248 gfc_resolve_dim_arg (dim);
249 f->rank = mask->rank - 1;
250 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
253 f->value.function.name
254 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
260 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
263 f->value.function.name
264 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
268 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
271 f->value.function.name
272 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
277 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
280 f->value.function.name
281 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
285 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
288 f->value.function.name
289 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
294 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
297 f->value.function.name
298 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
303 /* Resolve the BESYN and BESJN intrinsics. */
306 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
311 if (n->ts.kind != gfc_c_int_kind)
313 ts.type = BT_INTEGER;
314 ts.kind = gfc_c_int_kind;
315 gfc_convert_type (n, &ts, 2);
317 f->value.function.name = gfc_get_string ("<intrinsic>");
322 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
324 f->ts.type = BT_LOGICAL;
325 f->ts.kind = gfc_default_logical_kind;
326 f->value.function.name
327 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
332 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
334 f->ts.type = BT_INTEGER;
335 f->ts.kind = (kind == NULL)
336 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
337 f->value.function.name
338 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
339 gfc_type_letter (a->ts.type), a->ts.kind);
344 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
346 f->ts.type = BT_CHARACTER;
347 f->ts.kind = (kind == NULL)
348 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
349 f->value.function.name
350 = gfc_get_string ("__char_%d_%c%d", f->ts.kind,
351 gfc_type_letter (a->ts.type), a->ts.kind);
356 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
358 f->ts.type = BT_INTEGER;
359 f->ts.kind = gfc_default_integer_kind;
360 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
365 gfc_resolve_chdir_sub (gfc_code *c)
370 if (c->ext.actual->next->expr != NULL)
371 kind = c->ext.actual->next->expr->ts.kind;
373 kind = gfc_default_integer_kind;
375 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
376 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
381 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
382 gfc_expr *mode ATTRIBUTE_UNUSED)
384 f->ts.type = BT_INTEGER;
385 f->ts.kind = gfc_c_int_kind;
386 f->value.function.name = PREFIX ("chmod_func");
391 gfc_resolve_chmod_sub (gfc_code *c)
396 if (c->ext.actual->next->next->expr != NULL)
397 kind = c->ext.actual->next->next->expr->ts.kind;
399 kind = gfc_default_integer_kind;
401 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
402 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
407 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
409 f->ts.type = BT_COMPLEX;
410 f->ts.kind = (kind == NULL)
411 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
414 f->value.function.name
415 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
416 gfc_type_letter (x->ts.type), x->ts.kind);
418 f->value.function.name
419 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
420 gfc_type_letter (x->ts.type), x->ts.kind,
421 gfc_type_letter (y->ts.type), y->ts.kind);
426 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
428 gfc_resolve_cmplx (f, x, y, gfc_int_expr (gfc_default_double_kind));
433 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
437 if (x->ts.type == BT_INTEGER)
439 if (y->ts.type == BT_INTEGER)
440 kind = gfc_default_real_kind;
446 if (y->ts.type == BT_REAL)
447 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
452 f->ts.type = BT_COMPLEX;
454 f->value.function.name
455 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
456 gfc_type_letter (x->ts.type), x->ts.kind,
457 gfc_type_letter (y->ts.type), y->ts.kind);
462 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
465 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
470 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
473 f->value.function.name
474 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
479 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
482 f->value.function.name
483 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
488 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
490 f->ts.type = BT_INTEGER;
491 f->ts.kind = gfc_default_integer_kind;
495 f->rank = mask->rank - 1;
496 gfc_resolve_dim_arg (dim);
497 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
500 f->value.function.name
501 = gfc_get_string (PREFIX ("count_%d_%c%d"), f->ts.kind,
502 gfc_type_letter (mask->ts.type), mask->ts.kind);
507 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
513 f->rank = array->rank;
514 f->shape = gfc_copy_shape (array->shape, array->rank);
521 /* Convert shift to at least gfc_default_integer_kind, so we don't need
522 kind=1 and kind=2 versions of the library functions. */
523 if (shift->ts.kind < gfc_default_integer_kind)
526 ts.type = BT_INTEGER;
527 ts.kind = gfc_default_integer_kind;
528 gfc_convert_type_warn (shift, &ts, 2, 0);
533 gfc_resolve_dim_arg (dim);
534 /* Convert dim to shift's kind, so we don't need so many variations. */
535 if (dim->ts.kind != shift->ts.kind)
536 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
538 f->value.function.name
539 = gfc_get_string (PREFIX ("cshift%d_%d%s"), n, shift->ts.kind,
540 array->ts.type == BT_CHARACTER ? "_char" : "");
545 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
549 f->ts.type = BT_CHARACTER;
550 f->ts.kind = gfc_default_character_kind;
552 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
553 if (time->ts.kind != 8)
555 ts.type = BT_INTEGER;
559 gfc_convert_type (time, &ts, 2);
562 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
567 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
569 f->ts.type = BT_REAL;
570 f->ts.kind = gfc_default_double_kind;
571 f->value.function.name
572 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
577 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
579 f->ts.type = a->ts.type;
581 f->ts.kind = gfc_kind_max (a,p);
583 f->ts.kind = a->ts.kind;
585 if (p != NULL && a->ts.kind != p->ts.kind)
587 if (a->ts.kind == gfc_kind_max (a,p))
588 gfc_convert_type (p, &a->ts, 2);
590 gfc_convert_type (a, &p->ts, 2);
593 f->value.function.name
594 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
599 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
603 temp.expr_type = EXPR_OP;
604 gfc_clear_ts (&temp.ts);
605 temp.value.op.operator = INTRINSIC_NONE;
606 temp.value.op.op1 = a;
607 temp.value.op.op2 = b;
608 gfc_type_convert_binary (&temp);
610 f->value.function.name
611 = gfc_get_string (PREFIX ("dot_product_%c%d"),
612 gfc_type_letter (f->ts.type), f->ts.kind);
617 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
618 gfc_expr *b ATTRIBUTE_UNUSED)
620 f->ts.kind = gfc_default_double_kind;
621 f->ts.type = BT_REAL;
622 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
627 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
628 gfc_expr *boundary, gfc_expr *dim)
633 f->rank = array->rank;
634 f->shape = gfc_copy_shape (array->shape, array->rank);
639 if (boundary && boundary->rank > 0)
642 /* Convert shift to at least gfc_default_integer_kind, so we don't need
643 kind=1 and kind=2 versions of the library functions. */
644 if (shift->ts.kind < gfc_default_integer_kind)
647 ts.type = BT_INTEGER;
648 ts.kind = gfc_default_integer_kind;
649 gfc_convert_type_warn (shift, &ts, 2, 0);
654 gfc_resolve_dim_arg (dim);
655 /* Convert dim to shift's kind, so we don't need so many variations. */
656 if (dim->ts.kind != shift->ts.kind)
657 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
660 f->value.function.name
661 = gfc_get_string (PREFIX ("eoshift%d_%d%s"), n, shift->ts.kind,
662 array->ts.type == BT_CHARACTER ? "_char" : "");
667 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
670 f->value.function.name
671 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
676 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
678 f->ts.type = BT_INTEGER;
679 f->ts.kind = gfc_default_integer_kind;
680 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
685 gfc_resolve_fdate (gfc_expr *f)
687 f->ts.type = BT_CHARACTER;
688 f->ts.kind = gfc_default_character_kind;
689 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
694 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
696 f->ts.type = BT_INTEGER;
697 f->ts.kind = (kind == NULL)
698 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
699 f->value.function.name
700 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
701 gfc_type_letter (a->ts.type), a->ts.kind);
706 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
708 f->ts.type = BT_INTEGER;
709 f->ts.kind = gfc_default_integer_kind;
710 if (n->ts.kind != f->ts.kind)
711 gfc_convert_type (n, &f->ts, 2);
712 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
717 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
720 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
724 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
727 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
730 f->value.function.name = gfc_get_string ("<intrinsic>");
735 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
737 f->ts.type = BT_INTEGER;
739 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
744 gfc_resolve_getgid (gfc_expr *f)
746 f->ts.type = BT_INTEGER;
748 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
753 gfc_resolve_getpid (gfc_expr *f)
755 f->ts.type = BT_INTEGER;
757 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
762 gfc_resolve_getuid (gfc_expr *f)
764 f->ts.type = BT_INTEGER;
766 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
771 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
773 f->ts.type = BT_INTEGER;
775 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
780 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
782 /* If the kind of i and j are different, then g77 cross-promoted the
783 kinds to the largest value. The Fortran 95 standard requires the
785 if (i->ts.kind != j->ts.kind)
787 if (i->ts.kind == gfc_kind_max (i, j))
788 gfc_convert_type (j, &i->ts, 2);
790 gfc_convert_type (i, &j->ts, 2);
794 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
799 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
802 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
807 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
808 gfc_expr *len ATTRIBUTE_UNUSED)
811 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
816 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
819 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
824 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c)
826 f->ts.type = BT_INTEGER;
827 f->ts.kind = gfc_default_integer_kind;
828 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
833 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
835 gfc_resolve_nint (f, a, NULL);
840 gfc_resolve_ierrno (gfc_expr *f)
842 f->ts.type = BT_INTEGER;
843 f->ts.kind = gfc_default_integer_kind;
844 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
849 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
851 /* If the kind of i and j are different, then g77 cross-promoted the
852 kinds to the largest value. The Fortran 95 standard requires the
854 if (i->ts.kind != j->ts.kind)
856 if (i->ts.kind == gfc_kind_max (i, j))
857 gfc_convert_type (j, &i->ts, 2);
859 gfc_convert_type (i, &j->ts, 2);
863 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
868 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
870 /* If the kind of i and j are different, then g77 cross-promoted the
871 kinds to the largest value. The Fortran 95 standard requires the
873 if (i->ts.kind != j->ts.kind)
875 if (i->ts.kind == gfc_kind_max (i, j))
876 gfc_convert_type (j, &i->ts, 2);
878 gfc_convert_type (i, &j->ts, 2);
882 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
887 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
888 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back)
892 f->ts.type = BT_INTEGER;
893 f->ts.kind = gfc_default_integer_kind;
895 if (back && back->ts.kind != gfc_default_integer_kind)
897 ts.type = BT_LOGICAL;
898 ts.kind = gfc_default_integer_kind;
901 gfc_convert_type (back, &ts, 2);
904 f->value.function.name
905 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
910 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
912 f->ts.type = BT_INTEGER;
913 f->ts.kind = (kind == NULL)
914 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
915 f->value.function.name
916 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
917 gfc_type_letter (a->ts.type), a->ts.kind);
922 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
924 f->ts.type = BT_INTEGER;
926 f->value.function.name
927 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
928 gfc_type_letter (a->ts.type), a->ts.kind);
933 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
935 f->ts.type = BT_INTEGER;
937 f->value.function.name
938 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
939 gfc_type_letter (a->ts.type), a->ts.kind);
944 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
946 f->ts.type = BT_INTEGER;
948 f->value.function.name
949 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
950 gfc_type_letter (a->ts.type), a->ts.kind);
955 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
959 f->ts.type = BT_LOGICAL;
960 f->ts.kind = gfc_default_integer_kind;
961 if (u->ts.kind != gfc_c_int_kind)
963 ts.type = BT_INTEGER;
964 ts.kind = gfc_c_int_kind;
967 gfc_convert_type (u, &ts, 2);
970 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
975 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
978 f->value.function.name
979 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
984 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
987 f->value.function.name
988 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
993 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
996 f->value.function.name
997 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1002 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1006 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1009 f->value.function.name
1010 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1015 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1016 gfc_expr *s ATTRIBUTE_UNUSED)
1018 f->ts.type = BT_INTEGER;
1019 f->ts.kind = gfc_default_integer_kind;
1020 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1025 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1027 static char lbound[] = "__lbound";
1029 f->ts.type = BT_INTEGER;
1030 f->ts.kind = gfc_default_integer_kind;
1035 f->shape = gfc_get_shape (1);
1036 mpz_init_set_ui (f->shape[0], array->rank);
1039 f->value.function.name = lbound;
1044 gfc_resolve_len (gfc_expr *f, gfc_expr *string)
1046 f->ts.type = BT_INTEGER;
1047 f->ts.kind = gfc_default_integer_kind;
1048 f->value.function.name
1049 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1050 gfc_default_integer_kind);
1055 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string)
1057 f->ts.type = BT_INTEGER;
1058 f->ts.kind = gfc_default_integer_kind;
1059 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1064 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1065 gfc_expr *p2 ATTRIBUTE_UNUSED)
1067 f->ts.type = BT_INTEGER;
1068 f->ts.kind = gfc_default_integer_kind;
1069 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1074 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1076 f->ts.type= BT_INTEGER;
1077 f->ts.kind = gfc_index_integer_kind;
1078 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1083 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1086 f->value.function.name
1087 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1092 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1095 f->value.function.name
1096 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1102 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1104 f->ts.type = BT_LOGICAL;
1105 f->ts.kind = (kind == NULL)
1106 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1109 f->value.function.name
1110 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1111 gfc_type_letter (a->ts.type), a->ts.kind);
1116 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1118 if (size->ts.kind < gfc_index_integer_kind)
1122 ts.type = BT_INTEGER;
1123 ts.kind = gfc_index_integer_kind;
1124 gfc_convert_type_warn (size, &ts, 2, 0);
1127 f->ts.type = BT_INTEGER;
1128 f->ts.kind = gfc_index_integer_kind;
1129 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1134 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1138 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1140 f->ts.type = BT_LOGICAL;
1141 f->ts.kind = gfc_default_logical_kind;
1145 temp.expr_type = EXPR_OP;
1146 gfc_clear_ts (&temp.ts);
1147 temp.value.op.operator = INTRINSIC_NONE;
1148 temp.value.op.op1 = a;
1149 temp.value.op.op2 = b;
1150 gfc_type_convert_binary (&temp);
1154 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1156 f->value.function.name
1157 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1163 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1165 gfc_actual_arglist *a;
1167 f->ts.type = args->expr->ts.type;
1168 f->ts.kind = args->expr->ts.kind;
1169 /* Find the largest type kind. */
1170 for (a = args->next; a; a = a->next)
1172 if (a->expr->ts.kind > f->ts.kind)
1173 f->ts.kind = a->expr->ts.kind;
1176 /* Convert all parameters to the required kind. */
1177 for (a = args; a; a = a->next)
1179 if (a->expr->ts.kind != f->ts.kind)
1180 gfc_convert_type (a->expr, &f->ts, 2);
1183 f->value.function.name
1184 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1189 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1191 gfc_resolve_minmax ("__max_%c%d", f, args);
1196 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1202 f->ts.type = BT_INTEGER;
1203 f->ts.kind = gfc_default_integer_kind;
1208 f->shape = gfc_get_shape (1);
1209 mpz_init_set_si (f->shape[0], array->rank);
1213 f->rank = array->rank - 1;
1214 gfc_resolve_dim_arg (dim);
1215 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1217 idim = (int) mpz_get_si (dim->value.integer);
1218 f->shape = gfc_get_shape (f->rank);
1219 for (i = 0, j = 0; i < f->rank; i++, j++)
1221 if (i == (idim - 1))
1223 mpz_init_set (f->shape[i], array->shape[j]);
1230 if (mask->rank == 0)
1235 /* The mask can be kind 4 or 8 for the array case. For the
1236 scalar case, coerce it to default kind unconditionally. */
1237 if ((mask->ts.kind < gfc_default_logical_kind)
1238 || (mask->rank == 0 && mask->ts.kind != gfc_default_logical_kind))
1241 ts.type = BT_LOGICAL;
1242 ts.kind = gfc_default_logical_kind;
1243 gfc_convert_type_warn (mask, &ts, 2, 0);
1249 f->value.function.name
1250 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1251 gfc_type_letter (array->ts.type), array->ts.kind);
1256 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1266 f->rank = array->rank - 1;
1267 gfc_resolve_dim_arg (dim);
1269 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1271 idim = (int) mpz_get_si (dim->value.integer);
1272 f->shape = gfc_get_shape (f->rank);
1273 for (i = 0, j = 0; i < f->rank; i++, j++)
1275 if (i == (idim - 1))
1277 mpz_init_set (f->shape[i], array->shape[j]);
1284 if (mask->rank == 0)
1289 /* The mask can be kind 4 or 8 for the array case. For the
1290 scalar case, coerce it to default kind unconditionally. */
1291 if ((mask->ts.kind < gfc_default_logical_kind)
1292 || (mask->rank == 0 && mask->ts.kind != gfc_default_logical_kind))
1295 ts.type = BT_LOGICAL;
1296 ts.kind = gfc_default_logical_kind;
1297 gfc_convert_type_warn (mask, &ts, 2, 0);
1303 f->value.function.name
1304 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1305 gfc_type_letter (array->ts.type), array->ts.kind);
1310 gfc_resolve_mclock (gfc_expr *f)
1312 f->ts.type = BT_INTEGER;
1314 f->value.function.name = PREFIX ("mclock");
1319 gfc_resolve_mclock8 (gfc_expr *f)
1321 f->ts.type = BT_INTEGER;
1323 f->value.function.name = PREFIX ("mclock8");
1328 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1329 gfc_expr *fsource ATTRIBUTE_UNUSED,
1330 gfc_expr *mask ATTRIBUTE_UNUSED)
1332 if (tsource->ts.type == BT_CHARACTER)
1333 check_charlen_present (tsource);
1335 f->ts = tsource->ts;
1336 f->value.function.name
1337 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1343 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1345 gfc_resolve_minmax ("__min_%c%d", f, args);
1350 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1356 f->ts.type = BT_INTEGER;
1357 f->ts.kind = gfc_default_integer_kind;
1362 f->shape = gfc_get_shape (1);
1363 mpz_init_set_si (f->shape[0], array->rank);
1367 f->rank = array->rank - 1;
1368 gfc_resolve_dim_arg (dim);
1369 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1371 idim = (int) mpz_get_si (dim->value.integer);
1372 f->shape = gfc_get_shape (f->rank);
1373 for (i = 0, j = 0; i < f->rank; i++, j++)
1375 if (i == (idim - 1))
1377 mpz_init_set (f->shape[i], array->shape[j]);
1384 if (mask->rank == 0)
1389 /* The mask can be kind 4 or 8 for the array case. For the
1390 scalar case, coerce it to default kind unconditionally. */
1391 if ((mask->ts.kind < gfc_default_logical_kind)
1392 || (mask->rank == 0 && mask->ts.kind != gfc_default_logical_kind))
1395 ts.type = BT_LOGICAL;
1396 ts.kind = gfc_default_logical_kind;
1397 gfc_convert_type_warn (mask, &ts, 2, 0);
1403 f->value.function.name
1404 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1405 gfc_type_letter (array->ts.type), array->ts.kind);
1410 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1420 f->rank = array->rank - 1;
1421 gfc_resolve_dim_arg (dim);
1423 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1425 idim = (int) mpz_get_si (dim->value.integer);
1426 f->shape = gfc_get_shape (f->rank);
1427 for (i = 0, j = 0; i < f->rank; i++, j++)
1429 if (i == (idim - 1))
1431 mpz_init_set (f->shape[i], array->shape[j]);
1438 if (mask->rank == 0)
1443 /* The mask can be kind 4 or 8 for the array case. For the
1444 scalar case, coerce it to default kind unconditionally. */
1445 if ((mask->ts.kind < gfc_default_logical_kind)
1446 || (mask->rank == 0 && mask->ts.kind != gfc_default_logical_kind))
1449 ts.type = BT_LOGICAL;
1450 ts.kind = gfc_default_logical_kind;
1451 gfc_convert_type_warn (mask, &ts, 2, 0);
1457 f->value.function.name
1458 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1459 gfc_type_letter (array->ts.type), array->ts.kind);
1464 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1466 f->ts.type = a->ts.type;
1468 f->ts.kind = gfc_kind_max (a,p);
1470 f->ts.kind = a->ts.kind;
1472 if (p != NULL && a->ts.kind != p->ts.kind)
1474 if (a->ts.kind == gfc_kind_max (a,p))
1475 gfc_convert_type (p, &a->ts, 2);
1477 gfc_convert_type (a, &p->ts, 2);
1480 f->value.function.name
1481 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1486 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1488 f->ts.type = a->ts.type;
1490 f->ts.kind = gfc_kind_max (a,p);
1492 f->ts.kind = a->ts.kind;
1494 if (p != NULL && a->ts.kind != p->ts.kind)
1496 if (a->ts.kind == gfc_kind_max (a,p))
1497 gfc_convert_type (p, &a->ts, 2);
1499 gfc_convert_type (a, &p->ts, 2);
1502 f->value.function.name
1503 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1508 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p ATTRIBUTE_UNUSED)
1511 f->value.function.name
1512 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1517 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1519 f->ts.type = BT_INTEGER;
1520 f->ts.kind = (kind == NULL)
1521 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1522 f->value.function.name
1523 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1528 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1531 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1536 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1538 f->ts.type = i->ts.type;
1539 f->ts.kind = gfc_kind_max (i, j);
1541 if (i->ts.kind != j->ts.kind)
1543 if (i->ts.kind == gfc_kind_max (i, j))
1544 gfc_convert_type (j, &i->ts, 2);
1546 gfc_convert_type (i, &j->ts, 2);
1549 f->value.function.name
1550 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1555 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1556 gfc_expr *vector ATTRIBUTE_UNUSED)
1563 /* The mask can be kind 4 or 8 for the array case. For the scalar
1564 case, coerce it to kind=4 unconditionally (because this is the only
1565 kind we have a library function for). */
1568 if (mask->rank == 0)
1570 if (mask->ts.kind != 4)
1575 if (mask->ts.kind < 4)
1576 newkind = gfc_default_logical_kind;
1583 ts.type = BT_LOGICAL;
1584 ts.kind = gfc_default_logical_kind;
1585 gfc_convert_type (mask, &ts, 2);
1588 if (mask->rank != 0)
1589 f->value.function.name = (array->ts.type == BT_CHARACTER
1590 ? PREFIX ("pack_char") : PREFIX ("pack"));
1592 f->value.function.name = (array->ts.type == BT_CHARACTER
1593 ? PREFIX ("pack_s_char") : PREFIX ("pack_s"));
1598 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1607 f->rank = array->rank - 1;
1608 gfc_resolve_dim_arg (dim);
1613 if (mask->rank == 0)
1618 /* The mask can be kind 4 or 8 for the array case. For the
1619 scalar case, coerce it to default kind unconditionally. */
1620 if ((mask->ts.kind < gfc_default_logical_kind)
1621 || (mask->rank == 0 && mask->ts.kind != gfc_default_logical_kind))
1624 ts.type = BT_LOGICAL;
1625 ts.kind = gfc_default_logical_kind;
1626 gfc_convert_type_warn (mask, &ts, 2, 0);
1632 f->value.function.name
1633 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1634 gfc_type_letter (array->ts.type), array->ts.kind);
1639 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1641 f->ts.type = BT_REAL;
1644 f->ts.kind = mpz_get_si (kind->value.integer);
1646 f->ts.kind = (a->ts.type == BT_COMPLEX)
1647 ? a->ts.kind : gfc_default_real_kind;
1649 f->value.function.name
1650 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1651 gfc_type_letter (a->ts.type), a->ts.kind);
1656 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1658 f->ts.type = BT_REAL;
1659 f->ts.kind = a->ts.kind;
1660 f->value.function.name
1661 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1662 gfc_type_letter (a->ts.type), a->ts.kind);
1667 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1668 gfc_expr *p2 ATTRIBUTE_UNUSED)
1670 f->ts.type = BT_INTEGER;
1671 f->ts.kind = gfc_default_integer_kind;
1672 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1677 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
1678 gfc_expr *ncopies ATTRIBUTE_UNUSED)
1680 f->ts.type = BT_CHARACTER;
1681 f->ts.kind = string->ts.kind;
1682 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
1687 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
1688 gfc_expr *pad ATTRIBUTE_UNUSED,
1689 gfc_expr *order ATTRIBUTE_UNUSED)
1697 gfc_array_size (shape, &rank);
1698 f->rank = mpz_get_si (rank);
1700 switch (source->ts.type)
1706 kind = source->ts.kind;
1720 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
1721 f->value.function.name
1722 = gfc_get_string (PREFIX ("reshape_%c%d"),
1723 gfc_type_letter (source->ts.type),
1726 f->value.function.name
1727 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
1732 f->value.function.name = (source->ts.type == BT_CHARACTER
1733 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1737 /* TODO: Make this work with a constant ORDER parameter. */
1738 if (shape->expr_type == EXPR_ARRAY
1739 && gfc_is_constant_expr (shape)
1743 f->shape = gfc_get_shape (f->rank);
1744 c = shape->value.constructor;
1745 for (i = 0; i < f->rank; i++)
1747 mpz_init_set (f->shape[i], c->expr->value.integer);
1752 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
1753 so many runtime variations. */
1754 if (shape->ts.kind != gfc_index_integer_kind)
1756 gfc_typespec ts = shape->ts;
1757 ts.kind = gfc_index_integer_kind;
1758 gfc_convert_type_warn (shape, &ts, 2, 0);
1760 if (order && order->ts.kind != gfc_index_integer_kind)
1761 gfc_convert_type_warn (order, &shape->ts, 2, 0);
1766 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
1769 gfc_actual_arglist *prec;
1772 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
1774 /* Create a hidden argument to the library routines for rrspacing. This
1775 hidden argument is the precision of x. */
1776 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1777 prec = gfc_get_actual_arglist ();
1779 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1780 f->value.function.actual->next = prec;
1785 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1789 /* The implementation calls scalbn which takes an int as the
1791 if (i->ts.kind != gfc_c_int_kind)
1794 ts.type = BT_INTEGER;
1795 ts.kind = gfc_default_integer_kind;
1796 gfc_convert_type_warn (i, &ts, 2, 0);
1799 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
1804 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
1805 gfc_expr *set ATTRIBUTE_UNUSED,
1806 gfc_expr *back ATTRIBUTE_UNUSED)
1808 f->ts.type = BT_INTEGER;
1809 f->ts.kind = gfc_default_integer_kind;
1810 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
1815 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
1818 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
1823 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1827 /* The library implementation uses GFC_INTEGER_4 unconditionally,
1828 convert type so we don't have to implement all possible
1830 if (i->ts.kind != 4)
1833 ts.type = BT_INTEGER;
1834 ts.kind = gfc_default_integer_kind;
1835 gfc_convert_type_warn (i, &ts, 2, 0);
1838 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
1843 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
1845 f->ts.type = BT_INTEGER;
1846 f->ts.kind = gfc_default_integer_kind;
1848 f->shape = gfc_get_shape (1);
1849 mpz_init_set_ui (f->shape[0], array->rank);
1850 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
1855 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
1858 f->value.function.name
1859 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
1864 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
1866 f->ts.type = BT_INTEGER;
1867 f->ts.kind = gfc_c_int_kind;
1869 /* handler can be either BT_INTEGER or BT_PROCEDURE */
1870 if (handler->ts.type == BT_INTEGER)
1872 if (handler->ts.kind != gfc_c_int_kind)
1873 gfc_convert_type (handler, &f->ts, 2);
1874 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
1877 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
1879 if (number->ts.kind != gfc_c_int_kind)
1880 gfc_convert_type (number, &f->ts, 2);
1885 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
1888 f->value.function.name
1889 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1894 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
1897 f->value.function.name
1898 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1903 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
1906 gfc_actual_arglist *prec, *tiny, *emin_1;
1909 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
1911 /* Create hidden arguments to the library routine for spacing. These
1912 hidden arguments are tiny(x), min_exponent - 1, and the precision
1915 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1917 tiny = gfc_get_actual_arglist ();
1918 tiny->name = "tiny";
1919 tiny->expr = gfc_get_expr ();
1920 tiny->expr->expr_type = EXPR_CONSTANT;
1921 tiny->expr->where = gfc_current_locus;
1922 tiny->expr->ts.type = x->ts.type;
1923 tiny->expr->ts.kind = x->ts.kind;
1924 mpfr_init (tiny->expr->value.real);
1925 mpfr_set (tiny->expr->value.real, gfc_real_kinds[k].tiny, GFC_RND_MODE);
1927 emin_1 = gfc_get_actual_arglist ();
1928 emin_1->name = "emin";
1929 emin_1->expr = gfc_int_expr (gfc_real_kinds[k].min_exponent - 1);
1930 emin_1->next = tiny;
1932 prec = gfc_get_actual_arglist ();
1933 prec->name = "prec";
1934 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1935 prec->next = emin_1;
1937 f->value.function.actual->next = prec;
1942 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
1945 if (source->ts.type == BT_CHARACTER)
1946 check_charlen_present (source);
1949 f->rank = source->rank + 1;
1950 if (source->rank == 0)
1951 f->value.function.name = (source->ts.type == BT_CHARACTER
1952 ? PREFIX ("spread_char_scalar")
1953 : PREFIX ("spread_scalar"));
1955 f->value.function.name = (source->ts.type == BT_CHARACTER
1956 ? PREFIX ("spread_char")
1957 : PREFIX ("spread"));
1959 if (dim && gfc_is_constant_expr (dim)
1960 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
1963 idim = mpz_get_ui (dim->value.integer);
1964 f->shape = gfc_get_shape (f->rank);
1965 for (i = 0; i < (idim - 1); i++)
1966 mpz_init_set (f->shape[i], source->shape[i]);
1968 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
1970 for (i = idim; i < f->rank ; i++)
1971 mpz_init_set (f->shape[i], source->shape[i-1]);
1975 gfc_resolve_dim_arg (dim);
1976 gfc_resolve_index (ncopies, 1);
1981 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
1984 f->value.function.name
1985 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1989 /* Resolve the g77 compatibility function STAT AND FSTAT. */
1992 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
1993 gfc_expr *a ATTRIBUTE_UNUSED)
1995 f->ts.type = BT_INTEGER;
1996 f->ts.kind = gfc_default_integer_kind;
1997 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2002 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2003 gfc_expr *a ATTRIBUTE_UNUSED)
2005 f->ts.type = BT_INTEGER;
2006 f->ts.kind = gfc_default_integer_kind;
2007 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2012 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2014 f->ts.type = BT_INTEGER;
2015 f->ts.kind = gfc_default_integer_kind;
2016 if (n->ts.kind != f->ts.kind)
2017 gfc_convert_type (n, &f->ts, 2);
2019 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2024 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2028 f->ts.type = BT_INTEGER;
2029 f->ts.kind = gfc_c_int_kind;
2030 if (u->ts.kind != gfc_c_int_kind)
2032 ts.type = BT_INTEGER;
2033 ts.kind = gfc_c_int_kind;
2036 gfc_convert_type (u, &ts, 2);
2039 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2044 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2046 f->ts.type = BT_INTEGER;
2047 f->ts.kind = gfc_c_int_kind;
2048 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2053 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2057 f->ts.type = BT_INTEGER;
2058 f->ts.kind = gfc_c_int_kind;
2059 if (u->ts.kind != gfc_c_int_kind)
2061 ts.type = BT_INTEGER;
2062 ts.kind = gfc_c_int_kind;
2065 gfc_convert_type (u, &ts, 2);
2068 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2073 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2075 f->ts.type = BT_INTEGER;
2076 f->ts.kind = gfc_c_int_kind;
2077 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2082 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2086 f->ts.type = BT_INTEGER;
2087 f->ts.kind = gfc_index_integer_kind;
2088 if (u->ts.kind != gfc_c_int_kind)
2090 ts.type = BT_INTEGER;
2091 ts.kind = gfc_c_int_kind;
2094 gfc_convert_type (u, &ts, 2);
2097 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2102 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2110 if (mask->rank == 0)
2115 /* The mask can be kind 4 or 8 for the array case. For the
2116 scalar case, coerce it to default kind unconditionally. */
2117 if ((mask->ts.kind < gfc_default_logical_kind)
2118 || (mask->rank == 0 && mask->ts.kind != gfc_default_logical_kind))
2121 ts.type = BT_LOGICAL;
2122 ts.kind = gfc_default_logical_kind;
2123 gfc_convert_type_warn (mask, &ts, 2, 0);
2131 f->rank = array->rank - 1;
2132 gfc_resolve_dim_arg (dim);
2135 f->value.function.name
2136 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2137 gfc_type_letter (array->ts.type), array->ts.kind);
2142 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2143 gfc_expr *p2 ATTRIBUTE_UNUSED)
2145 f->ts.type = BT_INTEGER;
2146 f->ts.kind = gfc_default_integer_kind;
2147 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2151 /* Resolve the g77 compatibility function SYSTEM. */
2154 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2156 f->ts.type = BT_INTEGER;
2158 f->value.function.name = gfc_get_string (PREFIX ("system"));
2163 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2166 f->value.function.name
2167 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2172 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2175 f->value.function.name
2176 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2181 gfc_resolve_time (gfc_expr *f)
2183 f->ts.type = BT_INTEGER;
2185 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2190 gfc_resolve_time8 (gfc_expr *f)
2192 f->ts.type = BT_INTEGER;
2194 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2199 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2200 gfc_expr *mold, gfc_expr *size)
2202 /* TODO: Make this do something meaningful. */
2203 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2207 if (size == NULL && mold->rank == 0)
2210 f->value.function.name = transfer0;
2215 f->value.function.name = transfer1;
2216 if (size && gfc_is_constant_expr (size))
2218 f->shape = gfc_get_shape (1);
2219 mpz_init_set (f->shape[0], size->value.integer);
2226 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2232 f->shape = gfc_get_shape (2);
2233 mpz_init_set (f->shape[0], matrix->shape[1]);
2234 mpz_init_set (f->shape[1], matrix->shape[0]);
2237 switch (matrix->ts.kind)
2243 switch (matrix->ts.type)
2247 f->value.function.name
2248 = gfc_get_string (PREFIX ("transpose_%c%d"),
2249 gfc_type_letter (matrix->ts.type),
2255 /* Use the integer routines for real and logical cases. This
2256 assumes they all have the same alignment requirements. */
2257 f->value.function.name
2258 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2262 f->value.function.name = PREFIX ("transpose");
2268 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2269 ? PREFIX ("transpose_char")
2270 : PREFIX ("transpose"));
2277 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2279 f->ts.type = BT_CHARACTER;
2280 f->ts.kind = string->ts.kind;
2281 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2286 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
2288 static char ubound[] = "__ubound";
2290 f->ts.type = BT_INTEGER;
2291 f->ts.kind = gfc_default_integer_kind;
2296 f->shape = gfc_get_shape (1);
2297 mpz_init_set_ui (f->shape[0], array->rank);
2300 f->value.function.name = ubound;
2304 /* Resolve the g77 compatibility function UMASK. */
2307 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2309 f->ts.type = BT_INTEGER;
2310 f->ts.kind = n->ts.kind;
2311 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2315 /* Resolve the g77 compatibility function UNLINK. */
2318 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2320 f->ts.type = BT_INTEGER;
2322 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2327 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2331 f->ts.type = BT_CHARACTER;
2332 f->ts.kind = gfc_default_character_kind;
2334 if (unit->ts.kind != gfc_c_int_kind)
2336 ts.type = BT_INTEGER;
2337 ts.kind = gfc_c_int_kind;
2340 gfc_convert_type (unit, &ts, 2);
2343 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2348 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2349 gfc_expr *field ATTRIBUTE_UNUSED)
2352 f->rank = mask->rank;
2354 /* Coerce the mask to default logical kind if it has kind < 4. */
2356 if (mask->ts.kind < 4)
2360 ts.type = BT_LOGICAL;
2361 ts.kind = gfc_default_logical_kind;
2362 gfc_convert_type (mask, &ts, 2);
2365 f->value.function.name
2366 = gfc_get_string (PREFIX ("unpack%d%s"), field->rank > 0 ? 1 : 0,
2367 vector->ts.type == BT_CHARACTER ? "_char" : "");
2372 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2373 gfc_expr *set ATTRIBUTE_UNUSED,
2374 gfc_expr *back ATTRIBUTE_UNUSED)
2376 f->ts.type = BT_INTEGER;
2377 f->ts.kind = gfc_default_integer_kind;
2378 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2383 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2385 f->ts.type = i->ts.type;
2386 f->ts.kind = gfc_kind_max (i, j);
2388 if (i->ts.kind != j->ts.kind)
2390 if (i->ts.kind == gfc_kind_max (i, j))
2391 gfc_convert_type (j, &i->ts, 2);
2393 gfc_convert_type (i, &j->ts, 2);
2396 f->value.function.name
2397 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2401 /* Intrinsic subroutine resolution. */
2404 gfc_resolve_alarm_sub (gfc_code *c)
2407 gfc_expr *seconds, *handler, *status;
2410 seconds = c->ext.actual->expr;
2411 handler = c->ext.actual->next->expr;
2412 status = c->ext.actual->next->next->expr;
2413 ts.type = BT_INTEGER;
2414 ts.kind = gfc_c_int_kind;
2416 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2417 if (handler->ts.type == BT_INTEGER)
2419 if (handler->ts.kind != gfc_c_int_kind)
2420 gfc_convert_type (handler, &ts, 2);
2421 name = gfc_get_string (PREFIX ("alarm_sub_int"));
2424 name = gfc_get_string (PREFIX ("alarm_sub"));
2426 if (seconds->ts.kind != gfc_c_int_kind)
2427 gfc_convert_type (seconds, &ts, 2);
2429 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2433 gfc_resolve_cpu_time (gfc_code *c)
2436 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2437 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2442 gfc_resolve_mvbits (gfc_code *c)
2447 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2448 they will be converted so that they fit into a C int. */
2449 ts.type = BT_INTEGER;
2450 ts.kind = gfc_c_int_kind;
2451 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2452 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2453 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2454 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2455 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2456 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2458 /* TO and FROM are guaranteed to have the same kind parameter. */
2459 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2460 c->ext.actual->expr->ts.kind);
2461 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2466 gfc_resolve_random_number (gfc_code *c)
2471 kind = c->ext.actual->expr->ts.kind;
2472 if (c->ext.actual->expr->rank == 0)
2473 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2475 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2477 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2482 gfc_resolve_rename_sub (gfc_code *c)
2487 if (c->ext.actual->next->next->expr != NULL)
2488 kind = c->ext.actual->next->next->expr->ts.kind;
2490 kind = gfc_default_integer_kind;
2492 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2493 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2498 gfc_resolve_kill_sub (gfc_code *c)
2503 if (c->ext.actual->next->next->expr != NULL)
2504 kind = c->ext.actual->next->next->expr->ts.kind;
2506 kind = gfc_default_integer_kind;
2508 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2509 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2514 gfc_resolve_link_sub (gfc_code *c)
2519 if (c->ext.actual->next->next->expr != NULL)
2520 kind = c->ext.actual->next->next->expr->ts.kind;
2522 kind = gfc_default_integer_kind;
2524 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2525 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2530 gfc_resolve_symlnk_sub (gfc_code *c)
2535 if (c->ext.actual->next->next->expr != NULL)
2536 kind = c->ext.actual->next->next->expr->ts.kind;
2538 kind = gfc_default_integer_kind;
2540 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2541 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2545 /* G77 compatibility subroutines etime() and dtime(). */
2548 gfc_resolve_etime_sub (gfc_code *c)
2551 name = gfc_get_string (PREFIX ("etime_sub"));
2552 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2556 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2559 gfc_resolve_itime (gfc_code *c)
2562 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2563 gfc_default_integer_kind));
2567 gfc_resolve_idate (gfc_code *c)
2570 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2571 gfc_default_integer_kind));
2575 gfc_resolve_ltime (gfc_code *c)
2578 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2579 gfc_default_integer_kind));
2583 gfc_resolve_gmtime (gfc_code *c)
2586 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2587 gfc_default_integer_kind));
2591 /* G77 compatibility subroutine second(). */
2594 gfc_resolve_second_sub (gfc_code *c)
2597 name = gfc_get_string (PREFIX ("second_sub"));
2598 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2603 gfc_resolve_sleep_sub (gfc_code *c)
2608 if (c->ext.actual->expr != NULL)
2609 kind = c->ext.actual->expr->ts.kind;
2611 kind = gfc_default_integer_kind;
2613 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2614 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2618 /* G77 compatibility function srand(). */
2621 gfc_resolve_srand (gfc_code *c)
2624 name = gfc_get_string (PREFIX ("srand"));
2625 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2629 /* Resolve the getarg intrinsic subroutine. */
2632 gfc_resolve_getarg (gfc_code *c)
2636 kind = gfc_default_integer_kind;
2637 name = gfc_get_string (PREFIX ("getarg_i%d"), kind);
2638 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2642 /* Resolve the getcwd intrinsic subroutine. */
2645 gfc_resolve_getcwd_sub (gfc_code *c)
2650 if (c->ext.actual->next->expr != NULL)
2651 kind = c->ext.actual->next->expr->ts.kind;
2653 kind = gfc_default_integer_kind;
2655 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2656 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2660 /* Resolve the get_command intrinsic subroutine. */
2663 gfc_resolve_get_command (gfc_code *c)
2667 kind = gfc_default_integer_kind;
2668 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2669 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2673 /* Resolve the get_command_argument intrinsic subroutine. */
2676 gfc_resolve_get_command_argument (gfc_code *c)
2680 kind = gfc_default_integer_kind;
2681 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2682 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2686 /* Resolve the get_environment_variable intrinsic subroutine. */
2689 gfc_resolve_get_environment_variable (gfc_code *code)
2693 kind = gfc_default_integer_kind;
2694 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2695 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2700 gfc_resolve_signal_sub (gfc_code *c)
2703 gfc_expr *number, *handler, *status;
2706 number = c->ext.actual->expr;
2707 handler = c->ext.actual->next->expr;
2708 status = c->ext.actual->next->next->expr;
2709 ts.type = BT_INTEGER;
2710 ts.kind = gfc_c_int_kind;
2712 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2713 if (handler->ts.type == BT_INTEGER)
2715 if (handler->ts.kind != gfc_c_int_kind)
2716 gfc_convert_type (handler, &ts, 2);
2717 name = gfc_get_string (PREFIX ("signal_sub_int"));
2720 name = gfc_get_string (PREFIX ("signal_sub"));
2722 if (number->ts.kind != gfc_c_int_kind)
2723 gfc_convert_type (number, &ts, 2);
2724 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2725 gfc_convert_type (status, &ts, 2);
2727 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2731 /* Resolve the SYSTEM intrinsic subroutine. */
2734 gfc_resolve_system_sub (gfc_code *c)
2737 name = gfc_get_string (PREFIX ("system_sub"));
2738 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2742 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2745 gfc_resolve_system_clock (gfc_code *c)
2750 if (c->ext.actual->expr != NULL)
2751 kind = c->ext.actual->expr->ts.kind;
2752 else if (c->ext.actual->next->expr != NULL)
2753 kind = c->ext.actual->next->expr->ts.kind;
2754 else if (c->ext.actual->next->next->expr != NULL)
2755 kind = c->ext.actual->next->next->expr->ts.kind;
2757 kind = gfc_default_integer_kind;
2759 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
2760 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2764 /* Resolve the EXIT intrinsic subroutine. */
2767 gfc_resolve_exit (gfc_code *c)
2772 if (c->ext.actual->expr != NULL)
2773 kind = c->ext.actual->expr->ts.kind;
2775 kind = gfc_default_integer_kind;
2777 name = gfc_get_string (PREFIX ("exit_i%d"), kind);
2778 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2782 /* Resolve the FLUSH intrinsic subroutine. */
2785 gfc_resolve_flush (gfc_code *c)
2791 ts.type = BT_INTEGER;
2792 ts.kind = gfc_default_integer_kind;
2793 n = c->ext.actual->expr;
2794 if (n != NULL && n->ts.kind != ts.kind)
2795 gfc_convert_type (n, &ts, 2);
2797 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
2798 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2803 gfc_resolve_free (gfc_code *c)
2808 ts.type = BT_INTEGER;
2809 ts.kind = gfc_index_integer_kind;
2810 n = c->ext.actual->expr;
2811 if (n->ts.kind != ts.kind)
2812 gfc_convert_type (n, &ts, 2);
2814 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
2819 gfc_resolve_ctime_sub (gfc_code *c)
2823 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
2824 if (c->ext.actual->expr->ts.kind != 8)
2826 ts.type = BT_INTEGER;
2830 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2833 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
2838 gfc_resolve_fdate_sub (gfc_code *c)
2840 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
2845 gfc_resolve_gerror (gfc_code *c)
2847 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
2852 gfc_resolve_getlog (gfc_code *c)
2854 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
2859 gfc_resolve_hostnm_sub (gfc_code *c)
2864 if (c->ext.actual->next->expr != NULL)
2865 kind = c->ext.actual->next->expr->ts.kind;
2867 kind = gfc_default_integer_kind;
2869 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
2870 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2875 gfc_resolve_perror (gfc_code *c)
2877 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
2880 /* Resolve the STAT and FSTAT intrinsic subroutines. */
2883 gfc_resolve_stat_sub (gfc_code *c)
2886 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
2887 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2892 gfc_resolve_lstat_sub (gfc_code *c)
2895 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
2896 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2901 gfc_resolve_fstat_sub (gfc_code *c)
2907 u = c->ext.actual->expr;
2908 ts = &c->ext.actual->next->expr->ts;
2909 if (u->ts.kind != ts->kind)
2910 gfc_convert_type (u, ts, 2);
2911 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
2912 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2917 gfc_resolve_fgetc_sub (gfc_code *c)
2923 u = c->ext.actual->expr;
2924 st = c->ext.actual->next->next->expr;
2926 if (u->ts.kind != gfc_c_int_kind)
2928 ts.type = BT_INTEGER;
2929 ts.kind = gfc_c_int_kind;
2932 gfc_convert_type (u, &ts, 2);
2936 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
2938 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
2940 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2945 gfc_resolve_fget_sub (gfc_code *c)
2950 st = c->ext.actual->next->expr;
2952 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
2954 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
2956 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2961 gfc_resolve_fputc_sub (gfc_code *c)
2967 u = c->ext.actual->expr;
2968 st = c->ext.actual->next->next->expr;
2970 if (u->ts.kind != gfc_c_int_kind)
2972 ts.type = BT_INTEGER;
2973 ts.kind = gfc_c_int_kind;
2976 gfc_convert_type (u, &ts, 2);
2980 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
2982 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
2984 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2989 gfc_resolve_fput_sub (gfc_code *c)
2994 st = c->ext.actual->next->expr;
2996 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
2998 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3000 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3005 gfc_resolve_fseek_sub (gfc_code *c)
3013 unit = c->ext.actual->expr;
3014 offset = c->ext.actual->next->expr;
3015 whence = c->ext.actual->next->next->expr;
3016 status = c->ext.actual->next->next->next->expr;
3018 if (unit->ts.kind != gfc_c_int_kind)
3020 ts.type = BT_INTEGER;
3021 ts.kind = gfc_c_int_kind;
3024 gfc_convert_type (unit, &ts, 2);
3027 if (offset->ts.kind != gfc_intio_kind)
3029 ts.type = BT_INTEGER;
3030 ts.kind = gfc_intio_kind;
3033 gfc_convert_type (offset, &ts, 2);
3036 if (whence->ts.kind != gfc_c_int_kind)
3038 ts.type = BT_INTEGER;
3039 ts.kind = gfc_c_int_kind;
3042 gfc_convert_type (whence, &ts, 2);
3045 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3049 gfc_resolve_ftell_sub (gfc_code *c)
3056 unit = c->ext.actual->expr;
3057 offset = c->ext.actual->next->expr;
3059 if (unit->ts.kind != gfc_c_int_kind)
3061 ts.type = BT_INTEGER;
3062 ts.kind = gfc_c_int_kind;
3065 gfc_convert_type (unit, &ts, 2);
3068 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3069 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3074 gfc_resolve_ttynam_sub (gfc_code *c)
3078 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3080 ts.type = BT_INTEGER;
3081 ts.kind = gfc_c_int_kind;
3084 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3087 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3091 /* Resolve the UMASK intrinsic subroutine. */
3094 gfc_resolve_umask_sub (gfc_code *c)
3099 if (c->ext.actual->next->expr != NULL)
3100 kind = c->ext.actual->next->expr->ts.kind;
3102 kind = gfc_default_integer_kind;
3104 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3105 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3108 /* Resolve the UNLINK intrinsic subroutine. */
3111 gfc_resolve_unlink_sub (gfc_code *c)
3116 if (c->ext.actual->next->expr != NULL)
3117 kind = c->ext.actual->next->expr->ts.kind;
3119 kind = gfc_default_integer_kind;
3121 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3122 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);