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 /* Helper function for resolving the "mask" argument. */
78 resolve_mask_arg (gfc_expr *mask)
82 /* The mask can be kind 4 or 8 for the array case.
83 For the scalar case, coerce it to kind=4 unconditionally
84 (because this is the only kind we have a library function
91 if (mask->ts.kind != 4)
96 if (mask->ts.kind < 4)
97 newkind = gfc_default_logical_kind;
104 ts.type = BT_LOGICAL;
106 gfc_convert_type (mask, &ts, 2);
110 /********************** Resolution functions **********************/
114 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
117 if (f->ts.type == BT_COMPLEX)
118 f->ts.type = BT_REAL;
120 f->value.function.name
121 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
126 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
127 gfc_expr *mode ATTRIBUTE_UNUSED)
129 f->ts.type = BT_INTEGER;
130 f->ts.kind = gfc_c_int_kind;
131 f->value.function.name = PREFIX ("access_func");
136 gfc_resolve_achar (gfc_expr *f, gfc_expr *x)
139 f->ts.type = BT_CHARACTER;
140 f->ts.kind = gfc_default_character_kind;
141 f->ts.cl = gfc_get_charlen ();
142 f->ts.cl->next = gfc_current_ns->cl_list;
143 gfc_current_ns->cl_list = f->ts.cl;
144 f->ts.cl->length = gfc_int_expr (1);
146 f->value.function.name
147 = gfc_get_string ("__achar_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
152 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
155 f->value.function.name
156 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
161 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
164 f->value.function.name
165 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
171 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
173 f->ts.type = BT_REAL;
174 f->ts.kind = x->ts.kind;
175 f->value.function.name
176 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
182 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
184 f->ts.type = i->ts.type;
185 f->ts.kind = gfc_kind_max (i, j);
187 if (i->ts.kind != j->ts.kind)
189 if (i->ts.kind == gfc_kind_max (i, j))
190 gfc_convert_type (j, &i->ts, 2);
192 gfc_convert_type (i, &j->ts, 2);
195 f->value.function.name
196 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
201 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
205 f->ts.type = a->ts.type;
206 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
208 if (a->ts.kind != f->ts.kind)
210 ts.type = f->ts.type;
211 ts.kind = f->ts.kind;
212 gfc_convert_type (a, &ts, 2);
214 /* The resolved name is only used for specific intrinsics where
215 the return kind is the same as the arg kind. */
216 f->value.function.name
217 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
222 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
224 gfc_resolve_aint (f, a, NULL);
229 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
235 gfc_resolve_dim_arg (dim);
236 f->rank = mask->rank - 1;
237 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
240 f->value.function.name
241 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
247 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
251 f->ts.type = a->ts.type;
252 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
254 if (a->ts.kind != f->ts.kind)
256 ts.type = f->ts.type;
257 ts.kind = f->ts.kind;
258 gfc_convert_type (a, &ts, 2);
261 /* The resolved name is only used for specific intrinsics where
262 the return kind is the same as the arg kind. */
263 f->value.function.name
264 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
270 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
272 gfc_resolve_anint (f, a, NULL);
277 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
283 gfc_resolve_dim_arg (dim);
284 f->rank = mask->rank - 1;
285 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
288 f->value.function.name
289 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
295 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
298 f->value.function.name
299 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
303 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
306 f->value.function.name
307 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
312 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
315 f->value.function.name
316 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
320 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
323 f->value.function.name
324 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
329 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
332 f->value.function.name
333 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
338 /* Resolve the BESYN and BESJN intrinsics. */
341 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
346 if (n->ts.kind != gfc_c_int_kind)
348 ts.type = BT_INTEGER;
349 ts.kind = gfc_c_int_kind;
350 gfc_convert_type (n, &ts, 2);
352 f->value.function.name = gfc_get_string ("<intrinsic>");
357 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
359 f->ts.type = BT_LOGICAL;
360 f->ts.kind = gfc_default_logical_kind;
361 f->value.function.name
362 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
367 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
369 f->ts.type = BT_INTEGER;
370 f->ts.kind = (kind == NULL)
371 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
372 f->value.function.name
373 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
374 gfc_type_letter (a->ts.type), a->ts.kind);
379 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
381 f->ts.type = BT_CHARACTER;
382 f->ts.kind = (kind == NULL)
383 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
384 f->value.function.name
385 = gfc_get_string ("__char_%d_%c%d", f->ts.kind,
386 gfc_type_letter (a->ts.type), a->ts.kind);
391 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
393 f->ts.type = BT_INTEGER;
394 f->ts.kind = gfc_default_integer_kind;
395 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
400 gfc_resolve_chdir_sub (gfc_code *c)
405 if (c->ext.actual->next->expr != NULL)
406 kind = c->ext.actual->next->expr->ts.kind;
408 kind = gfc_default_integer_kind;
410 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
411 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
416 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
417 gfc_expr *mode ATTRIBUTE_UNUSED)
419 f->ts.type = BT_INTEGER;
420 f->ts.kind = gfc_c_int_kind;
421 f->value.function.name = PREFIX ("chmod_func");
426 gfc_resolve_chmod_sub (gfc_code *c)
431 if (c->ext.actual->next->next->expr != NULL)
432 kind = c->ext.actual->next->next->expr->ts.kind;
434 kind = gfc_default_integer_kind;
436 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
437 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
442 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
444 f->ts.type = BT_COMPLEX;
445 f->ts.kind = (kind == NULL)
446 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
449 f->value.function.name
450 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
451 gfc_type_letter (x->ts.type), x->ts.kind);
453 f->value.function.name
454 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
455 gfc_type_letter (x->ts.type), x->ts.kind,
456 gfc_type_letter (y->ts.type), y->ts.kind);
461 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
463 gfc_resolve_cmplx (f, x, y, gfc_int_expr (gfc_default_double_kind));
468 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
472 if (x->ts.type == BT_INTEGER)
474 if (y->ts.type == BT_INTEGER)
475 kind = gfc_default_real_kind;
481 if (y->ts.type == BT_REAL)
482 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
487 f->ts.type = BT_COMPLEX;
489 f->value.function.name
490 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
491 gfc_type_letter (x->ts.type), x->ts.kind,
492 gfc_type_letter (y->ts.type), y->ts.kind);
497 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
500 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
505 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
508 f->value.function.name
509 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
514 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
517 f->value.function.name
518 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
523 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
525 f->ts.type = BT_INTEGER;
526 f->ts.kind = gfc_default_integer_kind;
530 f->rank = mask->rank - 1;
531 gfc_resolve_dim_arg (dim);
532 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
535 f->value.function.name
536 = gfc_get_string (PREFIX ("count_%d_%c%d"), f->ts.kind,
537 gfc_type_letter (mask->ts.type), mask->ts.kind);
542 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
548 f->rank = array->rank;
549 f->shape = gfc_copy_shape (array->shape, array->rank);
556 /* Convert shift to at least gfc_default_integer_kind, so we don't need
557 kind=1 and kind=2 versions of the library functions. */
558 if (shift->ts.kind < gfc_default_integer_kind)
561 ts.type = BT_INTEGER;
562 ts.kind = gfc_default_integer_kind;
563 gfc_convert_type_warn (shift, &ts, 2, 0);
568 gfc_resolve_dim_arg (dim);
569 /* Convert dim to shift's kind, so we don't need so many variations. */
570 if (dim->ts.kind != shift->ts.kind)
571 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
573 f->value.function.name
574 = gfc_get_string (PREFIX ("cshift%d_%d%s"), n, shift->ts.kind,
575 array->ts.type == BT_CHARACTER ? "_char" : "");
580 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
584 f->ts.type = BT_CHARACTER;
585 f->ts.kind = gfc_default_character_kind;
587 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
588 if (time->ts.kind != 8)
590 ts.type = BT_INTEGER;
594 gfc_convert_type (time, &ts, 2);
597 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
602 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
604 f->ts.type = BT_REAL;
605 f->ts.kind = gfc_default_double_kind;
606 f->value.function.name
607 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
612 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
614 f->ts.type = a->ts.type;
616 f->ts.kind = gfc_kind_max (a,p);
618 f->ts.kind = a->ts.kind;
620 if (p != NULL && a->ts.kind != p->ts.kind)
622 if (a->ts.kind == gfc_kind_max (a,p))
623 gfc_convert_type (p, &a->ts, 2);
625 gfc_convert_type (a, &p->ts, 2);
628 f->value.function.name
629 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
634 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
638 temp.expr_type = EXPR_OP;
639 gfc_clear_ts (&temp.ts);
640 temp.value.op.operator = INTRINSIC_NONE;
641 temp.value.op.op1 = a;
642 temp.value.op.op2 = b;
643 gfc_type_convert_binary (&temp);
645 f->value.function.name
646 = gfc_get_string (PREFIX ("dot_product_%c%d"),
647 gfc_type_letter (f->ts.type), f->ts.kind);
652 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
653 gfc_expr *b ATTRIBUTE_UNUSED)
655 f->ts.kind = gfc_default_double_kind;
656 f->ts.type = BT_REAL;
657 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
662 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
663 gfc_expr *boundary, gfc_expr *dim)
668 f->rank = array->rank;
669 f->shape = gfc_copy_shape (array->shape, array->rank);
674 if (boundary && boundary->rank > 0)
677 /* Convert shift to at least gfc_default_integer_kind, so we don't need
678 kind=1 and kind=2 versions of the library functions. */
679 if (shift->ts.kind < gfc_default_integer_kind)
682 ts.type = BT_INTEGER;
683 ts.kind = gfc_default_integer_kind;
684 gfc_convert_type_warn (shift, &ts, 2, 0);
689 gfc_resolve_dim_arg (dim);
690 /* Convert dim to shift's kind, so we don't need so many variations. */
691 if (dim->ts.kind != shift->ts.kind)
692 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
695 f->value.function.name
696 = gfc_get_string (PREFIX ("eoshift%d_%d%s"), n, shift->ts.kind,
697 array->ts.type == BT_CHARACTER ? "_char" : "");
702 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
705 f->value.function.name
706 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
711 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
713 f->ts.type = BT_INTEGER;
714 f->ts.kind = gfc_default_integer_kind;
715 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
720 gfc_resolve_fdate (gfc_expr *f)
722 f->ts.type = BT_CHARACTER;
723 f->ts.kind = gfc_default_character_kind;
724 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
729 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
731 f->ts.type = BT_INTEGER;
732 f->ts.kind = (kind == NULL)
733 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
734 f->value.function.name
735 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
736 gfc_type_letter (a->ts.type), a->ts.kind);
741 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
743 f->ts.type = BT_INTEGER;
744 f->ts.kind = gfc_default_integer_kind;
745 if (n->ts.kind != f->ts.kind)
746 gfc_convert_type (n, &f->ts, 2);
747 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
752 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
755 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
759 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
762 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
765 f->value.function.name = gfc_get_string ("<intrinsic>");
770 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
772 f->ts.type = BT_INTEGER;
774 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
779 gfc_resolve_getgid (gfc_expr *f)
781 f->ts.type = BT_INTEGER;
783 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
788 gfc_resolve_getpid (gfc_expr *f)
790 f->ts.type = BT_INTEGER;
792 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
797 gfc_resolve_getuid (gfc_expr *f)
799 f->ts.type = BT_INTEGER;
801 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
806 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
808 f->ts.type = BT_INTEGER;
810 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
815 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
817 /* If the kind of i and j are different, then g77 cross-promoted the
818 kinds to the largest value. The Fortran 95 standard requires the
820 if (i->ts.kind != j->ts.kind)
822 if (i->ts.kind == gfc_kind_max (i, j))
823 gfc_convert_type (j, &i->ts, 2);
825 gfc_convert_type (i, &j->ts, 2);
829 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
834 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
837 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
842 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
843 gfc_expr *len ATTRIBUTE_UNUSED)
846 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
851 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
854 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
859 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c)
861 f->ts.type = BT_INTEGER;
862 f->ts.kind = gfc_default_integer_kind;
863 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
868 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
870 gfc_resolve_nint (f, a, NULL);
875 gfc_resolve_ierrno (gfc_expr *f)
877 f->ts.type = BT_INTEGER;
878 f->ts.kind = gfc_default_integer_kind;
879 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
884 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
886 /* If the kind of i and j are different, then g77 cross-promoted the
887 kinds to the largest value. The Fortran 95 standard requires the
889 if (i->ts.kind != j->ts.kind)
891 if (i->ts.kind == gfc_kind_max (i, j))
892 gfc_convert_type (j, &i->ts, 2);
894 gfc_convert_type (i, &j->ts, 2);
898 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
903 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
905 /* If the kind of i and j are different, then g77 cross-promoted the
906 kinds to the largest value. The Fortran 95 standard requires the
908 if (i->ts.kind != j->ts.kind)
910 if (i->ts.kind == gfc_kind_max (i, j))
911 gfc_convert_type (j, &i->ts, 2);
913 gfc_convert_type (i, &j->ts, 2);
917 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
922 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
923 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back)
927 f->ts.type = BT_INTEGER;
928 f->ts.kind = gfc_default_integer_kind;
930 if (back && back->ts.kind != gfc_default_integer_kind)
932 ts.type = BT_LOGICAL;
933 ts.kind = gfc_default_integer_kind;
936 gfc_convert_type (back, &ts, 2);
939 f->value.function.name
940 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
945 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
947 f->ts.type = BT_INTEGER;
948 f->ts.kind = (kind == NULL)
949 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
950 f->value.function.name
951 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
952 gfc_type_letter (a->ts.type), a->ts.kind);
957 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
959 f->ts.type = BT_INTEGER;
961 f->value.function.name
962 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
963 gfc_type_letter (a->ts.type), a->ts.kind);
968 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
970 f->ts.type = BT_INTEGER;
972 f->value.function.name
973 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
974 gfc_type_letter (a->ts.type), a->ts.kind);
979 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
981 f->ts.type = BT_INTEGER;
983 f->value.function.name
984 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
985 gfc_type_letter (a->ts.type), a->ts.kind);
990 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
994 f->ts.type = BT_LOGICAL;
995 f->ts.kind = gfc_default_integer_kind;
996 if (u->ts.kind != gfc_c_int_kind)
998 ts.type = BT_INTEGER;
999 ts.kind = gfc_c_int_kind;
1002 gfc_convert_type (u, &ts, 2);
1005 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1010 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1013 f->value.function.name
1014 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1019 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1022 f->value.function.name
1023 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1028 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1031 f->value.function.name
1032 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1037 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1041 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1044 f->value.function.name
1045 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1050 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1051 gfc_expr *s ATTRIBUTE_UNUSED)
1053 f->ts.type = BT_INTEGER;
1054 f->ts.kind = gfc_default_integer_kind;
1055 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1060 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1062 static char lbound[] = "__lbound";
1064 f->ts.type = BT_INTEGER;
1065 f->ts.kind = gfc_default_integer_kind;
1070 f->shape = gfc_get_shape (1);
1071 mpz_init_set_ui (f->shape[0], array->rank);
1074 f->value.function.name = lbound;
1079 gfc_resolve_len (gfc_expr *f, gfc_expr *string)
1081 f->ts.type = BT_INTEGER;
1082 f->ts.kind = gfc_default_integer_kind;
1083 f->value.function.name
1084 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1085 gfc_default_integer_kind);
1090 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string)
1092 f->ts.type = BT_INTEGER;
1093 f->ts.kind = gfc_default_integer_kind;
1094 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1099 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1100 gfc_expr *p2 ATTRIBUTE_UNUSED)
1102 f->ts.type = BT_INTEGER;
1103 f->ts.kind = gfc_default_integer_kind;
1104 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1109 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1111 f->ts.type= BT_INTEGER;
1112 f->ts.kind = gfc_index_integer_kind;
1113 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1118 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1121 f->value.function.name
1122 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1127 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1130 f->value.function.name
1131 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1137 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1139 f->ts.type = BT_LOGICAL;
1140 f->ts.kind = (kind == NULL)
1141 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1144 f->value.function.name
1145 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1146 gfc_type_letter (a->ts.type), a->ts.kind);
1151 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1153 if (size->ts.kind < gfc_index_integer_kind)
1157 ts.type = BT_INTEGER;
1158 ts.kind = gfc_index_integer_kind;
1159 gfc_convert_type_warn (size, &ts, 2, 0);
1162 f->ts.type = BT_INTEGER;
1163 f->ts.kind = gfc_index_integer_kind;
1164 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1169 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1173 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1175 f->ts.type = BT_LOGICAL;
1176 f->ts.kind = gfc_default_logical_kind;
1180 temp.expr_type = EXPR_OP;
1181 gfc_clear_ts (&temp.ts);
1182 temp.value.op.operator = INTRINSIC_NONE;
1183 temp.value.op.op1 = a;
1184 temp.value.op.op2 = b;
1185 gfc_type_convert_binary (&temp);
1189 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1191 f->value.function.name
1192 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1198 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1200 gfc_actual_arglist *a;
1202 f->ts.type = args->expr->ts.type;
1203 f->ts.kind = args->expr->ts.kind;
1204 /* Find the largest type kind. */
1205 for (a = args->next; a; a = a->next)
1207 if (a->expr->ts.kind > f->ts.kind)
1208 f->ts.kind = a->expr->ts.kind;
1211 /* Convert all parameters to the required kind. */
1212 for (a = args; a; a = a->next)
1214 if (a->expr->ts.kind != f->ts.kind)
1215 gfc_convert_type (a->expr, &f->ts, 2);
1218 f->value.function.name
1219 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1224 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1226 gfc_resolve_minmax ("__max_%c%d", f, args);
1231 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1237 f->ts.type = BT_INTEGER;
1238 f->ts.kind = gfc_default_integer_kind;
1243 f->shape = gfc_get_shape (1);
1244 mpz_init_set_si (f->shape[0], array->rank);
1248 f->rank = array->rank - 1;
1249 gfc_resolve_dim_arg (dim);
1250 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1252 idim = (int) mpz_get_si (dim->value.integer);
1253 f->shape = gfc_get_shape (f->rank);
1254 for (i = 0, j = 0; i < f->rank; i++, j++)
1256 if (i == (idim - 1))
1258 mpz_init_set (f->shape[i], array->shape[j]);
1265 if (mask->rank == 0)
1270 resolve_mask_arg (mask);
1275 f->value.function.name
1276 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1277 gfc_type_letter (array->ts.type), array->ts.kind);
1282 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1292 f->rank = array->rank - 1;
1293 gfc_resolve_dim_arg (dim);
1295 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1297 idim = (int) mpz_get_si (dim->value.integer);
1298 f->shape = gfc_get_shape (f->rank);
1299 for (i = 0, j = 0; i < f->rank; i++, j++)
1301 if (i == (idim - 1))
1303 mpz_init_set (f->shape[i], array->shape[j]);
1310 if (mask->rank == 0)
1315 resolve_mask_arg (mask);
1320 f->value.function.name
1321 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1322 gfc_type_letter (array->ts.type), array->ts.kind);
1327 gfc_resolve_mclock (gfc_expr *f)
1329 f->ts.type = BT_INTEGER;
1331 f->value.function.name = PREFIX ("mclock");
1336 gfc_resolve_mclock8 (gfc_expr *f)
1338 f->ts.type = BT_INTEGER;
1340 f->value.function.name = PREFIX ("mclock8");
1345 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1346 gfc_expr *fsource ATTRIBUTE_UNUSED,
1347 gfc_expr *mask ATTRIBUTE_UNUSED)
1349 if (tsource->ts.type == BT_CHARACTER)
1350 check_charlen_present (tsource);
1352 f->ts = tsource->ts;
1353 f->value.function.name
1354 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1360 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1362 gfc_resolve_minmax ("__min_%c%d", f, args);
1367 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1373 f->ts.type = BT_INTEGER;
1374 f->ts.kind = gfc_default_integer_kind;
1379 f->shape = gfc_get_shape (1);
1380 mpz_init_set_si (f->shape[0], array->rank);
1384 f->rank = array->rank - 1;
1385 gfc_resolve_dim_arg (dim);
1386 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1388 idim = (int) mpz_get_si (dim->value.integer);
1389 f->shape = gfc_get_shape (f->rank);
1390 for (i = 0, j = 0; i < f->rank; i++, j++)
1392 if (i == (idim - 1))
1394 mpz_init_set (f->shape[i], array->shape[j]);
1401 if (mask->rank == 0)
1406 resolve_mask_arg (mask);
1411 f->value.function.name
1412 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1413 gfc_type_letter (array->ts.type), array->ts.kind);
1418 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1428 f->rank = array->rank - 1;
1429 gfc_resolve_dim_arg (dim);
1431 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1433 idim = (int) mpz_get_si (dim->value.integer);
1434 f->shape = gfc_get_shape (f->rank);
1435 for (i = 0, j = 0; i < f->rank; i++, j++)
1437 if (i == (idim - 1))
1439 mpz_init_set (f->shape[i], array->shape[j]);
1446 if (mask->rank == 0)
1451 resolve_mask_arg (mask);
1456 f->value.function.name
1457 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1458 gfc_type_letter (array->ts.type), array->ts.kind);
1463 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1465 f->ts.type = a->ts.type;
1467 f->ts.kind = gfc_kind_max (a,p);
1469 f->ts.kind = a->ts.kind;
1471 if (p != NULL && a->ts.kind != p->ts.kind)
1473 if (a->ts.kind == gfc_kind_max (a,p))
1474 gfc_convert_type (p, &a->ts, 2);
1476 gfc_convert_type (a, &p->ts, 2);
1479 f->value.function.name
1480 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1485 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1487 f->ts.type = a->ts.type;
1489 f->ts.kind = gfc_kind_max (a,p);
1491 f->ts.kind = a->ts.kind;
1493 if (p != NULL && a->ts.kind != p->ts.kind)
1495 if (a->ts.kind == gfc_kind_max (a,p))
1496 gfc_convert_type (p, &a->ts, 2);
1498 gfc_convert_type (a, &p->ts, 2);
1501 f->value.function.name
1502 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1507 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p ATTRIBUTE_UNUSED)
1510 f->value.function.name
1511 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1516 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1518 f->ts.type = BT_INTEGER;
1519 f->ts.kind = (kind == NULL)
1520 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1521 f->value.function.name
1522 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1527 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1530 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1535 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1537 f->ts.type = i->ts.type;
1538 f->ts.kind = gfc_kind_max (i, j);
1540 if (i->ts.kind != j->ts.kind)
1542 if (i->ts.kind == gfc_kind_max (i, j))
1543 gfc_convert_type (j, &i->ts, 2);
1545 gfc_convert_type (i, &j->ts, 2);
1548 f->value.function.name
1549 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1554 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1555 gfc_expr *vector ATTRIBUTE_UNUSED)
1560 resolve_mask_arg (mask);
1562 if (mask->rank != 0)
1563 f->value.function.name = (array->ts.type == BT_CHARACTER
1564 ? PREFIX ("pack_char") : PREFIX ("pack"));
1566 f->value.function.name = (array->ts.type == BT_CHARACTER
1567 ? PREFIX ("pack_s_char") : PREFIX ("pack_s"));
1572 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1581 f->rank = array->rank - 1;
1582 gfc_resolve_dim_arg (dim);
1587 if (mask->rank == 0)
1592 resolve_mask_arg (mask);
1597 f->value.function.name
1598 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1599 gfc_type_letter (array->ts.type), array->ts.kind);
1604 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1606 f->ts.type = BT_REAL;
1609 f->ts.kind = mpz_get_si (kind->value.integer);
1611 f->ts.kind = (a->ts.type == BT_COMPLEX)
1612 ? a->ts.kind : gfc_default_real_kind;
1614 f->value.function.name
1615 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1616 gfc_type_letter (a->ts.type), a->ts.kind);
1621 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1623 f->ts.type = BT_REAL;
1624 f->ts.kind = a->ts.kind;
1625 f->value.function.name
1626 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1627 gfc_type_letter (a->ts.type), a->ts.kind);
1632 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1633 gfc_expr *p2 ATTRIBUTE_UNUSED)
1635 f->ts.type = BT_INTEGER;
1636 f->ts.kind = gfc_default_integer_kind;
1637 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1642 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
1643 gfc_expr *ncopies ATTRIBUTE_UNUSED)
1645 f->ts.type = BT_CHARACTER;
1646 f->ts.kind = string->ts.kind;
1647 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
1652 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
1653 gfc_expr *pad ATTRIBUTE_UNUSED,
1654 gfc_expr *order ATTRIBUTE_UNUSED)
1662 gfc_array_size (shape, &rank);
1663 f->rank = mpz_get_si (rank);
1665 switch (source->ts.type)
1671 kind = source->ts.kind;
1685 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
1686 f->value.function.name
1687 = gfc_get_string (PREFIX ("reshape_%c%d"),
1688 gfc_type_letter (source->ts.type),
1691 f->value.function.name
1692 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
1697 f->value.function.name = (source->ts.type == BT_CHARACTER
1698 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1702 /* TODO: Make this work with a constant ORDER parameter. */
1703 if (shape->expr_type == EXPR_ARRAY
1704 && gfc_is_constant_expr (shape)
1708 f->shape = gfc_get_shape (f->rank);
1709 c = shape->value.constructor;
1710 for (i = 0; i < f->rank; i++)
1712 mpz_init_set (f->shape[i], c->expr->value.integer);
1717 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
1718 so many runtime variations. */
1719 if (shape->ts.kind != gfc_index_integer_kind)
1721 gfc_typespec ts = shape->ts;
1722 ts.kind = gfc_index_integer_kind;
1723 gfc_convert_type_warn (shape, &ts, 2, 0);
1725 if (order && order->ts.kind != gfc_index_integer_kind)
1726 gfc_convert_type_warn (order, &shape->ts, 2, 0);
1731 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
1734 gfc_actual_arglist *prec;
1737 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
1739 /* Create a hidden argument to the library routines for rrspacing. This
1740 hidden argument is the precision of x. */
1741 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1742 prec = gfc_get_actual_arglist ();
1744 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1745 /* The library routine expects INTEGER(4). */
1746 if (prec->expr->ts.kind != gfc_c_int_kind)
1749 ts.type = BT_INTEGER;
1750 ts.kind = gfc_c_int_kind;
1751 gfc_convert_type (prec->expr, &ts, 2);
1753 f->value.function.actual->next = prec;
1758 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1762 /* The implementation calls scalbn which takes an int as the
1764 if (i->ts.kind != gfc_c_int_kind)
1767 ts.type = BT_INTEGER;
1768 ts.kind = gfc_c_int_kind;
1769 gfc_convert_type_warn (i, &ts, 2, 0);
1772 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
1777 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
1778 gfc_expr *set ATTRIBUTE_UNUSED,
1779 gfc_expr *back ATTRIBUTE_UNUSED)
1781 f->ts.type = BT_INTEGER;
1782 f->ts.kind = gfc_default_integer_kind;
1783 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
1788 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
1791 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
1796 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1800 /* The library implementation uses GFC_INTEGER_4 unconditionally,
1801 convert type so we don't have to implement all possible
1803 if (i->ts.kind != gfc_c_int_kind)
1806 ts.type = BT_INTEGER;
1807 ts.kind = gfc_c_int_kind;
1808 gfc_convert_type_warn (i, &ts, 2, 0);
1811 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
1816 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
1818 f->ts.type = BT_INTEGER;
1819 f->ts.kind = gfc_default_integer_kind;
1821 f->shape = gfc_get_shape (1);
1822 mpz_init_set_ui (f->shape[0], array->rank);
1823 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
1828 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
1831 f->value.function.name
1832 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
1837 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
1839 f->ts.type = BT_INTEGER;
1840 f->ts.kind = gfc_c_int_kind;
1842 /* handler can be either BT_INTEGER or BT_PROCEDURE */
1843 if (handler->ts.type == BT_INTEGER)
1845 if (handler->ts.kind != gfc_c_int_kind)
1846 gfc_convert_type (handler, &f->ts, 2);
1847 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
1850 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
1852 if (number->ts.kind != gfc_c_int_kind)
1853 gfc_convert_type (number, &f->ts, 2);
1858 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
1861 f->value.function.name
1862 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1867 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
1870 f->value.function.name
1871 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1876 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
1879 gfc_actual_arglist *prec, *tiny, *emin_1;
1882 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
1884 /* Create hidden arguments to the library routine for spacing. These
1885 hidden arguments are tiny(x), min_exponent - 1, and the precision
1888 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1890 tiny = gfc_get_actual_arglist ();
1891 tiny->name = "tiny";
1892 tiny->expr = gfc_get_expr ();
1893 tiny->expr->expr_type = EXPR_CONSTANT;
1894 tiny->expr->where = gfc_current_locus;
1895 tiny->expr->ts.type = x->ts.type;
1896 tiny->expr->ts.kind = x->ts.kind;
1897 mpfr_init (tiny->expr->value.real);
1898 mpfr_set (tiny->expr->value.real, gfc_real_kinds[k].tiny, GFC_RND_MODE);
1900 emin_1 = gfc_get_actual_arglist ();
1901 emin_1->name = "emin";
1902 emin_1->expr = gfc_int_expr (gfc_real_kinds[k].min_exponent - 1);
1904 /* The library routine expects INTEGER(4). */
1905 if (emin_1->expr->ts.kind != gfc_c_int_kind)
1908 ts.type = BT_INTEGER;
1909 ts.kind = gfc_c_int_kind;
1910 gfc_convert_type (emin_1->expr, &ts, 2);
1912 emin_1->next = tiny;
1914 prec = gfc_get_actual_arglist ();
1915 prec->name = "prec";
1916 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1918 /* The library routine expects INTEGER(4). */
1919 if (prec->expr->ts.kind != gfc_c_int_kind)
1922 ts.type = BT_INTEGER;
1923 ts.kind = gfc_c_int_kind;
1924 gfc_convert_type (prec->expr, &ts, 2);
1926 prec->next = emin_1;
1928 f->value.function.actual->next = prec;
1933 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
1936 if (source->ts.type == BT_CHARACTER)
1937 check_charlen_present (source);
1940 f->rank = source->rank + 1;
1941 if (source->rank == 0)
1942 f->value.function.name = (source->ts.type == BT_CHARACTER
1943 ? PREFIX ("spread_char_scalar")
1944 : PREFIX ("spread_scalar"));
1946 f->value.function.name = (source->ts.type == BT_CHARACTER
1947 ? PREFIX ("spread_char")
1948 : PREFIX ("spread"));
1950 if (dim && gfc_is_constant_expr (dim)
1951 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
1954 idim = mpz_get_ui (dim->value.integer);
1955 f->shape = gfc_get_shape (f->rank);
1956 for (i = 0; i < (idim - 1); i++)
1957 mpz_init_set (f->shape[i], source->shape[i]);
1959 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
1961 for (i = idim; i < f->rank ; i++)
1962 mpz_init_set (f->shape[i], source->shape[i-1]);
1966 gfc_resolve_dim_arg (dim);
1967 gfc_resolve_index (ncopies, 1);
1972 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
1975 f->value.function.name
1976 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1980 /* Resolve the g77 compatibility function STAT AND FSTAT. */
1983 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
1984 gfc_expr *a ATTRIBUTE_UNUSED)
1986 f->ts.type = BT_INTEGER;
1987 f->ts.kind = gfc_default_integer_kind;
1988 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
1993 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
1994 gfc_expr *a ATTRIBUTE_UNUSED)
1996 f->ts.type = BT_INTEGER;
1997 f->ts.kind = gfc_default_integer_kind;
1998 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2003 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2005 f->ts.type = BT_INTEGER;
2006 f->ts.kind = gfc_default_integer_kind;
2007 if (n->ts.kind != f->ts.kind)
2008 gfc_convert_type (n, &f->ts, 2);
2010 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2015 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2019 f->ts.type = BT_INTEGER;
2020 f->ts.kind = gfc_c_int_kind;
2021 if (u->ts.kind != gfc_c_int_kind)
2023 ts.type = BT_INTEGER;
2024 ts.kind = gfc_c_int_kind;
2027 gfc_convert_type (u, &ts, 2);
2030 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2035 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2037 f->ts.type = BT_INTEGER;
2038 f->ts.kind = gfc_c_int_kind;
2039 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2044 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2048 f->ts.type = BT_INTEGER;
2049 f->ts.kind = gfc_c_int_kind;
2050 if (u->ts.kind != gfc_c_int_kind)
2052 ts.type = BT_INTEGER;
2053 ts.kind = gfc_c_int_kind;
2056 gfc_convert_type (u, &ts, 2);
2059 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2064 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2066 f->ts.type = BT_INTEGER;
2067 f->ts.kind = gfc_c_int_kind;
2068 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2073 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2077 f->ts.type = BT_INTEGER;
2078 f->ts.kind = gfc_index_integer_kind;
2079 if (u->ts.kind != gfc_c_int_kind)
2081 ts.type = BT_INTEGER;
2082 ts.kind = gfc_c_int_kind;
2085 gfc_convert_type (u, &ts, 2);
2088 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2093 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2101 if (mask->rank == 0)
2106 resolve_mask_arg (mask);
2113 f->rank = array->rank - 1;
2114 gfc_resolve_dim_arg (dim);
2117 f->value.function.name
2118 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2119 gfc_type_letter (array->ts.type), array->ts.kind);
2124 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2125 gfc_expr *p2 ATTRIBUTE_UNUSED)
2127 f->ts.type = BT_INTEGER;
2128 f->ts.kind = gfc_default_integer_kind;
2129 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2133 /* Resolve the g77 compatibility function SYSTEM. */
2136 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2138 f->ts.type = BT_INTEGER;
2140 f->value.function.name = gfc_get_string (PREFIX ("system"));
2145 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2148 f->value.function.name
2149 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2154 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2157 f->value.function.name
2158 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2163 gfc_resolve_time (gfc_expr *f)
2165 f->ts.type = BT_INTEGER;
2167 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2172 gfc_resolve_time8 (gfc_expr *f)
2174 f->ts.type = BT_INTEGER;
2176 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2181 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2182 gfc_expr *mold, gfc_expr *size)
2184 /* TODO: Make this do something meaningful. */
2185 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2189 if (size == NULL && mold->rank == 0)
2192 f->value.function.name = transfer0;
2197 f->value.function.name = transfer1;
2198 if (size && gfc_is_constant_expr (size))
2200 f->shape = gfc_get_shape (1);
2201 mpz_init_set (f->shape[0], size->value.integer);
2208 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2214 f->shape = gfc_get_shape (2);
2215 mpz_init_set (f->shape[0], matrix->shape[1]);
2216 mpz_init_set (f->shape[1], matrix->shape[0]);
2219 switch (matrix->ts.kind)
2225 switch (matrix->ts.type)
2229 f->value.function.name
2230 = gfc_get_string (PREFIX ("transpose_%c%d"),
2231 gfc_type_letter (matrix->ts.type),
2237 /* Use the integer routines for real and logical cases. This
2238 assumes they all have the same alignment requirements. */
2239 f->value.function.name
2240 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2244 f->value.function.name = PREFIX ("transpose");
2250 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2251 ? PREFIX ("transpose_char")
2252 : PREFIX ("transpose"));
2259 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2261 f->ts.type = BT_CHARACTER;
2262 f->ts.kind = string->ts.kind;
2263 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2268 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
2270 static char ubound[] = "__ubound";
2272 f->ts.type = BT_INTEGER;
2273 f->ts.kind = gfc_default_integer_kind;
2278 f->shape = gfc_get_shape (1);
2279 mpz_init_set_ui (f->shape[0], array->rank);
2282 f->value.function.name = ubound;
2286 /* Resolve the g77 compatibility function UMASK. */
2289 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2291 f->ts.type = BT_INTEGER;
2292 f->ts.kind = n->ts.kind;
2293 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2297 /* Resolve the g77 compatibility function UNLINK. */
2300 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2302 f->ts.type = BT_INTEGER;
2304 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2309 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2313 f->ts.type = BT_CHARACTER;
2314 f->ts.kind = gfc_default_character_kind;
2316 if (unit->ts.kind != gfc_c_int_kind)
2318 ts.type = BT_INTEGER;
2319 ts.kind = gfc_c_int_kind;
2322 gfc_convert_type (unit, &ts, 2);
2325 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2330 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2331 gfc_expr *field ATTRIBUTE_UNUSED)
2334 f->rank = mask->rank;
2335 resolve_mask_arg (mask);
2337 f->value.function.name
2338 = gfc_get_string (PREFIX ("unpack%d%s"), field->rank > 0 ? 1 : 0,
2339 vector->ts.type == BT_CHARACTER ? "_char" : "");
2344 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2345 gfc_expr *set ATTRIBUTE_UNUSED,
2346 gfc_expr *back ATTRIBUTE_UNUSED)
2348 f->ts.type = BT_INTEGER;
2349 f->ts.kind = gfc_default_integer_kind;
2350 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2355 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2357 f->ts.type = i->ts.type;
2358 f->ts.kind = gfc_kind_max (i, j);
2360 if (i->ts.kind != j->ts.kind)
2362 if (i->ts.kind == gfc_kind_max (i, j))
2363 gfc_convert_type (j, &i->ts, 2);
2365 gfc_convert_type (i, &j->ts, 2);
2368 f->value.function.name
2369 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2373 /* Intrinsic subroutine resolution. */
2376 gfc_resolve_alarm_sub (gfc_code *c)
2379 gfc_expr *seconds, *handler, *status;
2382 seconds = c->ext.actual->expr;
2383 handler = c->ext.actual->next->expr;
2384 status = c->ext.actual->next->next->expr;
2385 ts.type = BT_INTEGER;
2386 ts.kind = gfc_c_int_kind;
2388 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2389 In all cases, the status argument is of default integer kind
2390 (enforced in check.c) so that the function suffix is fixed. */
2391 if (handler->ts.type == BT_INTEGER)
2393 if (handler->ts.kind != gfc_c_int_kind)
2394 gfc_convert_type (handler, &ts, 2);
2395 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2396 gfc_default_integer_kind);
2399 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2400 gfc_default_integer_kind);
2402 if (seconds->ts.kind != gfc_c_int_kind)
2403 gfc_convert_type (seconds, &ts, 2);
2405 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2409 gfc_resolve_cpu_time (gfc_code *c)
2412 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2413 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2418 gfc_resolve_mvbits (gfc_code *c)
2423 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2424 they will be converted so that they fit into a C int. */
2425 ts.type = BT_INTEGER;
2426 ts.kind = gfc_c_int_kind;
2427 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2428 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2429 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2430 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2431 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2432 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2434 /* TO and FROM are guaranteed to have the same kind parameter. */
2435 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2436 c->ext.actual->expr->ts.kind);
2437 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2442 gfc_resolve_random_number (gfc_code *c)
2447 kind = c->ext.actual->expr->ts.kind;
2448 if (c->ext.actual->expr->rank == 0)
2449 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2451 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2453 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2458 gfc_resolve_rename_sub (gfc_code *c)
2463 if (c->ext.actual->next->next->expr != NULL)
2464 kind = c->ext.actual->next->next->expr->ts.kind;
2466 kind = gfc_default_integer_kind;
2468 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2469 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2474 gfc_resolve_kill_sub (gfc_code *c)
2479 if (c->ext.actual->next->next->expr != NULL)
2480 kind = c->ext.actual->next->next->expr->ts.kind;
2482 kind = gfc_default_integer_kind;
2484 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2485 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2490 gfc_resolve_link_sub (gfc_code *c)
2495 if (c->ext.actual->next->next->expr != NULL)
2496 kind = c->ext.actual->next->next->expr->ts.kind;
2498 kind = gfc_default_integer_kind;
2500 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2501 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2506 gfc_resolve_symlnk_sub (gfc_code *c)
2511 if (c->ext.actual->next->next->expr != NULL)
2512 kind = c->ext.actual->next->next->expr->ts.kind;
2514 kind = gfc_default_integer_kind;
2516 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2517 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2521 /* G77 compatibility subroutines etime() and dtime(). */
2524 gfc_resolve_etime_sub (gfc_code *c)
2527 name = gfc_get_string (PREFIX ("etime_sub"));
2528 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2532 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2535 gfc_resolve_itime (gfc_code *c)
2538 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2539 gfc_default_integer_kind));
2543 gfc_resolve_idate (gfc_code *c)
2546 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2547 gfc_default_integer_kind));
2551 gfc_resolve_ltime (gfc_code *c)
2554 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2555 gfc_default_integer_kind));
2559 gfc_resolve_gmtime (gfc_code *c)
2562 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2563 gfc_default_integer_kind));
2567 /* G77 compatibility subroutine second(). */
2570 gfc_resolve_second_sub (gfc_code *c)
2573 name = gfc_get_string (PREFIX ("second_sub"));
2574 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2579 gfc_resolve_sleep_sub (gfc_code *c)
2584 if (c->ext.actual->expr != NULL)
2585 kind = c->ext.actual->expr->ts.kind;
2587 kind = gfc_default_integer_kind;
2589 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2590 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2594 /* G77 compatibility function srand(). */
2597 gfc_resolve_srand (gfc_code *c)
2600 name = gfc_get_string (PREFIX ("srand"));
2601 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2605 /* Resolve the getarg intrinsic subroutine. */
2608 gfc_resolve_getarg (gfc_code *c)
2612 kind = gfc_default_integer_kind;
2613 name = gfc_get_string (PREFIX ("getarg_i%d"), kind);
2614 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2618 /* Resolve the getcwd intrinsic subroutine. */
2621 gfc_resolve_getcwd_sub (gfc_code *c)
2626 if (c->ext.actual->next->expr != NULL)
2627 kind = c->ext.actual->next->expr->ts.kind;
2629 kind = gfc_default_integer_kind;
2631 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2632 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2636 /* Resolve the get_command intrinsic subroutine. */
2639 gfc_resolve_get_command (gfc_code *c)
2643 kind = gfc_default_integer_kind;
2644 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2645 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2649 /* Resolve the get_command_argument intrinsic subroutine. */
2652 gfc_resolve_get_command_argument (gfc_code *c)
2656 kind = gfc_default_integer_kind;
2657 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2658 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2662 /* Resolve the get_environment_variable intrinsic subroutine. */
2665 gfc_resolve_get_environment_variable (gfc_code *code)
2669 kind = gfc_default_integer_kind;
2670 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2671 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2676 gfc_resolve_signal_sub (gfc_code *c)
2679 gfc_expr *number, *handler, *status;
2682 number = c->ext.actual->expr;
2683 handler = c->ext.actual->next->expr;
2684 status = c->ext.actual->next->next->expr;
2685 ts.type = BT_INTEGER;
2686 ts.kind = gfc_c_int_kind;
2688 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2689 if (handler->ts.type == BT_INTEGER)
2691 if (handler->ts.kind != gfc_c_int_kind)
2692 gfc_convert_type (handler, &ts, 2);
2693 name = gfc_get_string (PREFIX ("signal_sub_int"));
2696 name = gfc_get_string (PREFIX ("signal_sub"));
2698 if (number->ts.kind != gfc_c_int_kind)
2699 gfc_convert_type (number, &ts, 2);
2700 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2701 gfc_convert_type (status, &ts, 2);
2703 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2707 /* Resolve the SYSTEM intrinsic subroutine. */
2710 gfc_resolve_system_sub (gfc_code *c)
2713 name = gfc_get_string (PREFIX ("system_sub"));
2714 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2718 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2721 gfc_resolve_system_clock (gfc_code *c)
2726 if (c->ext.actual->expr != NULL)
2727 kind = c->ext.actual->expr->ts.kind;
2728 else if (c->ext.actual->next->expr != NULL)
2729 kind = c->ext.actual->next->expr->ts.kind;
2730 else if (c->ext.actual->next->next->expr != NULL)
2731 kind = c->ext.actual->next->next->expr->ts.kind;
2733 kind = gfc_default_integer_kind;
2735 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
2736 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2740 /* Resolve the EXIT intrinsic subroutine. */
2743 gfc_resolve_exit (gfc_code *c)
2749 /* The STATUS argument has to be of default kind. If it is not,
2751 ts.type = BT_INTEGER;
2752 ts.kind = gfc_default_integer_kind;
2753 n = c->ext.actual->expr;
2754 if (n != NULL && n->ts.kind != ts.kind)
2755 gfc_convert_type (n, &ts, 2);
2757 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
2758 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2762 /* Resolve the FLUSH intrinsic subroutine. */
2765 gfc_resolve_flush (gfc_code *c)
2771 ts.type = BT_INTEGER;
2772 ts.kind = gfc_default_integer_kind;
2773 n = c->ext.actual->expr;
2774 if (n != NULL && n->ts.kind != ts.kind)
2775 gfc_convert_type (n, &ts, 2);
2777 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
2778 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2783 gfc_resolve_free (gfc_code *c)
2788 ts.type = BT_INTEGER;
2789 ts.kind = gfc_index_integer_kind;
2790 n = c->ext.actual->expr;
2791 if (n->ts.kind != ts.kind)
2792 gfc_convert_type (n, &ts, 2);
2794 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
2799 gfc_resolve_ctime_sub (gfc_code *c)
2803 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
2804 if (c->ext.actual->expr->ts.kind != 8)
2806 ts.type = BT_INTEGER;
2810 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2813 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
2818 gfc_resolve_fdate_sub (gfc_code *c)
2820 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
2825 gfc_resolve_gerror (gfc_code *c)
2827 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
2832 gfc_resolve_getlog (gfc_code *c)
2834 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
2839 gfc_resolve_hostnm_sub (gfc_code *c)
2844 if (c->ext.actual->next->expr != NULL)
2845 kind = c->ext.actual->next->expr->ts.kind;
2847 kind = gfc_default_integer_kind;
2849 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
2850 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2855 gfc_resolve_perror (gfc_code *c)
2857 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
2860 /* Resolve the STAT and FSTAT intrinsic subroutines. */
2863 gfc_resolve_stat_sub (gfc_code *c)
2866 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
2867 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2872 gfc_resolve_lstat_sub (gfc_code *c)
2875 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
2876 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2881 gfc_resolve_fstat_sub (gfc_code *c)
2887 u = c->ext.actual->expr;
2888 ts = &c->ext.actual->next->expr->ts;
2889 if (u->ts.kind != ts->kind)
2890 gfc_convert_type (u, ts, 2);
2891 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
2892 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2897 gfc_resolve_fgetc_sub (gfc_code *c)
2903 u = c->ext.actual->expr;
2904 st = c->ext.actual->next->next->expr;
2906 if (u->ts.kind != gfc_c_int_kind)
2908 ts.type = BT_INTEGER;
2909 ts.kind = gfc_c_int_kind;
2912 gfc_convert_type (u, &ts, 2);
2916 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
2918 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
2920 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2925 gfc_resolve_fget_sub (gfc_code *c)
2930 st = c->ext.actual->next->expr;
2932 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
2934 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
2936 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2941 gfc_resolve_fputc_sub (gfc_code *c)
2947 u = c->ext.actual->expr;
2948 st = c->ext.actual->next->next->expr;
2950 if (u->ts.kind != gfc_c_int_kind)
2952 ts.type = BT_INTEGER;
2953 ts.kind = gfc_c_int_kind;
2956 gfc_convert_type (u, &ts, 2);
2960 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
2962 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
2964 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2969 gfc_resolve_fput_sub (gfc_code *c)
2974 st = c->ext.actual->next->expr;
2976 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
2978 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
2980 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2985 gfc_resolve_fseek_sub (gfc_code *c)
2993 unit = c->ext.actual->expr;
2994 offset = c->ext.actual->next->expr;
2995 whence = c->ext.actual->next->next->expr;
2996 status = c->ext.actual->next->next->next->expr;
2998 if (unit->ts.kind != gfc_c_int_kind)
3000 ts.type = BT_INTEGER;
3001 ts.kind = gfc_c_int_kind;
3004 gfc_convert_type (unit, &ts, 2);
3007 if (offset->ts.kind != gfc_intio_kind)
3009 ts.type = BT_INTEGER;
3010 ts.kind = gfc_intio_kind;
3013 gfc_convert_type (offset, &ts, 2);
3016 if (whence->ts.kind != gfc_c_int_kind)
3018 ts.type = BT_INTEGER;
3019 ts.kind = gfc_c_int_kind;
3022 gfc_convert_type (whence, &ts, 2);
3025 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3029 gfc_resolve_ftell_sub (gfc_code *c)
3036 unit = c->ext.actual->expr;
3037 offset = c->ext.actual->next->expr;
3039 if (unit->ts.kind != gfc_c_int_kind)
3041 ts.type = BT_INTEGER;
3042 ts.kind = gfc_c_int_kind;
3045 gfc_convert_type (unit, &ts, 2);
3048 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3049 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3054 gfc_resolve_ttynam_sub (gfc_code *c)
3058 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3060 ts.type = BT_INTEGER;
3061 ts.kind = gfc_c_int_kind;
3064 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3067 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3071 /* Resolve the UMASK intrinsic subroutine. */
3074 gfc_resolve_umask_sub (gfc_code *c)
3079 if (c->ext.actual->next->expr != NULL)
3080 kind = c->ext.actual->next->expr->ts.kind;
3082 kind = gfc_default_integer_kind;
3084 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3085 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3088 /* Resolve the UNLINK intrinsic subroutine. */
3091 gfc_resolve_unlink_sub (gfc_code *c)
3096 if (c->ext.actual->next->expr != NULL)
3097 kind = c->ext.actual->next->expr->ts.kind;
3099 kind = gfc_default_integer_kind;
3101 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3102 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);