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 f->value.function.actual->next = prec;
1750 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1754 /* The implementation calls scalbn which takes an int as the
1756 if (i->ts.kind != gfc_c_int_kind)
1759 ts.type = BT_INTEGER;
1760 ts.kind = gfc_default_integer_kind;
1761 gfc_convert_type_warn (i, &ts, 2, 0);
1764 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
1769 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
1770 gfc_expr *set ATTRIBUTE_UNUSED,
1771 gfc_expr *back ATTRIBUTE_UNUSED)
1773 f->ts.type = BT_INTEGER;
1774 f->ts.kind = gfc_default_integer_kind;
1775 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
1780 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
1783 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
1788 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1792 /* The library implementation uses GFC_INTEGER_4 unconditionally,
1793 convert type so we don't have to implement all possible
1795 if (i->ts.kind != 4)
1798 ts.type = BT_INTEGER;
1799 ts.kind = gfc_default_integer_kind;
1800 gfc_convert_type_warn (i, &ts, 2, 0);
1803 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
1808 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
1810 f->ts.type = BT_INTEGER;
1811 f->ts.kind = gfc_default_integer_kind;
1813 f->shape = gfc_get_shape (1);
1814 mpz_init_set_ui (f->shape[0], array->rank);
1815 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
1820 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
1823 f->value.function.name
1824 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
1829 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
1831 f->ts.type = BT_INTEGER;
1832 f->ts.kind = gfc_c_int_kind;
1834 /* handler can be either BT_INTEGER or BT_PROCEDURE */
1835 if (handler->ts.type == BT_INTEGER)
1837 if (handler->ts.kind != gfc_c_int_kind)
1838 gfc_convert_type (handler, &f->ts, 2);
1839 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
1842 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
1844 if (number->ts.kind != gfc_c_int_kind)
1845 gfc_convert_type (number, &f->ts, 2);
1850 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
1853 f->value.function.name
1854 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1859 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
1862 f->value.function.name
1863 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1868 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
1871 gfc_actual_arglist *prec, *tiny, *emin_1;
1874 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
1876 /* Create hidden arguments to the library routine for spacing. These
1877 hidden arguments are tiny(x), min_exponent - 1, and the precision
1880 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1882 tiny = gfc_get_actual_arglist ();
1883 tiny->name = "tiny";
1884 tiny->expr = gfc_get_expr ();
1885 tiny->expr->expr_type = EXPR_CONSTANT;
1886 tiny->expr->where = gfc_current_locus;
1887 tiny->expr->ts.type = x->ts.type;
1888 tiny->expr->ts.kind = x->ts.kind;
1889 mpfr_init (tiny->expr->value.real);
1890 mpfr_set (tiny->expr->value.real, gfc_real_kinds[k].tiny, GFC_RND_MODE);
1892 emin_1 = gfc_get_actual_arglist ();
1893 emin_1->name = "emin";
1894 emin_1->expr = gfc_int_expr (gfc_real_kinds[k].min_exponent - 1);
1895 emin_1->next = tiny;
1897 prec = gfc_get_actual_arglist ();
1898 prec->name = "prec";
1899 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1900 prec->next = emin_1;
1902 f->value.function.actual->next = prec;
1907 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
1910 if (source->ts.type == BT_CHARACTER)
1911 check_charlen_present (source);
1914 f->rank = source->rank + 1;
1915 if (source->rank == 0)
1916 f->value.function.name = (source->ts.type == BT_CHARACTER
1917 ? PREFIX ("spread_char_scalar")
1918 : PREFIX ("spread_scalar"));
1920 f->value.function.name = (source->ts.type == BT_CHARACTER
1921 ? PREFIX ("spread_char")
1922 : PREFIX ("spread"));
1924 if (dim && gfc_is_constant_expr (dim)
1925 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
1928 idim = mpz_get_ui (dim->value.integer);
1929 f->shape = gfc_get_shape (f->rank);
1930 for (i = 0; i < (idim - 1); i++)
1931 mpz_init_set (f->shape[i], source->shape[i]);
1933 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
1935 for (i = idim; i < f->rank ; i++)
1936 mpz_init_set (f->shape[i], source->shape[i-1]);
1940 gfc_resolve_dim_arg (dim);
1941 gfc_resolve_index (ncopies, 1);
1946 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
1949 f->value.function.name
1950 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1954 /* Resolve the g77 compatibility function STAT AND FSTAT. */
1957 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
1958 gfc_expr *a ATTRIBUTE_UNUSED)
1960 f->ts.type = BT_INTEGER;
1961 f->ts.kind = gfc_default_integer_kind;
1962 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
1967 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
1968 gfc_expr *a ATTRIBUTE_UNUSED)
1970 f->ts.type = BT_INTEGER;
1971 f->ts.kind = gfc_default_integer_kind;
1972 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
1977 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
1979 f->ts.type = BT_INTEGER;
1980 f->ts.kind = gfc_default_integer_kind;
1981 if (n->ts.kind != f->ts.kind)
1982 gfc_convert_type (n, &f->ts, 2);
1984 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
1989 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
1993 f->ts.type = BT_INTEGER;
1994 f->ts.kind = gfc_c_int_kind;
1995 if (u->ts.kind != gfc_c_int_kind)
1997 ts.type = BT_INTEGER;
1998 ts.kind = gfc_c_int_kind;
2001 gfc_convert_type (u, &ts, 2);
2004 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2009 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2011 f->ts.type = BT_INTEGER;
2012 f->ts.kind = gfc_c_int_kind;
2013 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2018 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2022 f->ts.type = BT_INTEGER;
2023 f->ts.kind = gfc_c_int_kind;
2024 if (u->ts.kind != gfc_c_int_kind)
2026 ts.type = BT_INTEGER;
2027 ts.kind = gfc_c_int_kind;
2030 gfc_convert_type (u, &ts, 2);
2033 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2038 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2040 f->ts.type = BT_INTEGER;
2041 f->ts.kind = gfc_c_int_kind;
2042 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2047 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2051 f->ts.type = BT_INTEGER;
2052 f->ts.kind = gfc_index_integer_kind;
2053 if (u->ts.kind != gfc_c_int_kind)
2055 ts.type = BT_INTEGER;
2056 ts.kind = gfc_c_int_kind;
2059 gfc_convert_type (u, &ts, 2);
2062 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2067 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2075 if (mask->rank == 0)
2080 resolve_mask_arg (mask);
2087 f->rank = array->rank - 1;
2088 gfc_resolve_dim_arg (dim);
2091 f->value.function.name
2092 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2093 gfc_type_letter (array->ts.type), array->ts.kind);
2098 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2099 gfc_expr *p2 ATTRIBUTE_UNUSED)
2101 f->ts.type = BT_INTEGER;
2102 f->ts.kind = gfc_default_integer_kind;
2103 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2107 /* Resolve the g77 compatibility function SYSTEM. */
2110 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2112 f->ts.type = BT_INTEGER;
2114 f->value.function.name = gfc_get_string (PREFIX ("system"));
2119 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2122 f->value.function.name
2123 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2128 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2131 f->value.function.name
2132 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2137 gfc_resolve_time (gfc_expr *f)
2139 f->ts.type = BT_INTEGER;
2141 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2146 gfc_resolve_time8 (gfc_expr *f)
2148 f->ts.type = BT_INTEGER;
2150 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2155 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2156 gfc_expr *mold, gfc_expr *size)
2158 /* TODO: Make this do something meaningful. */
2159 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2163 if (size == NULL && mold->rank == 0)
2166 f->value.function.name = transfer0;
2171 f->value.function.name = transfer1;
2172 if (size && gfc_is_constant_expr (size))
2174 f->shape = gfc_get_shape (1);
2175 mpz_init_set (f->shape[0], size->value.integer);
2182 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2188 f->shape = gfc_get_shape (2);
2189 mpz_init_set (f->shape[0], matrix->shape[1]);
2190 mpz_init_set (f->shape[1], matrix->shape[0]);
2193 switch (matrix->ts.kind)
2199 switch (matrix->ts.type)
2203 f->value.function.name
2204 = gfc_get_string (PREFIX ("transpose_%c%d"),
2205 gfc_type_letter (matrix->ts.type),
2211 /* Use the integer routines for real and logical cases. This
2212 assumes they all have the same alignment requirements. */
2213 f->value.function.name
2214 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2218 f->value.function.name = PREFIX ("transpose");
2224 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2225 ? PREFIX ("transpose_char")
2226 : PREFIX ("transpose"));
2233 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2235 f->ts.type = BT_CHARACTER;
2236 f->ts.kind = string->ts.kind;
2237 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2242 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
2244 static char ubound[] = "__ubound";
2246 f->ts.type = BT_INTEGER;
2247 f->ts.kind = gfc_default_integer_kind;
2252 f->shape = gfc_get_shape (1);
2253 mpz_init_set_ui (f->shape[0], array->rank);
2256 f->value.function.name = ubound;
2260 /* Resolve the g77 compatibility function UMASK. */
2263 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2265 f->ts.type = BT_INTEGER;
2266 f->ts.kind = n->ts.kind;
2267 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2271 /* Resolve the g77 compatibility function UNLINK. */
2274 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2276 f->ts.type = BT_INTEGER;
2278 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2283 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2287 f->ts.type = BT_CHARACTER;
2288 f->ts.kind = gfc_default_character_kind;
2290 if (unit->ts.kind != gfc_c_int_kind)
2292 ts.type = BT_INTEGER;
2293 ts.kind = gfc_c_int_kind;
2296 gfc_convert_type (unit, &ts, 2);
2299 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2304 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2305 gfc_expr *field ATTRIBUTE_UNUSED)
2308 f->rank = mask->rank;
2309 resolve_mask_arg (mask);
2311 f->value.function.name
2312 = gfc_get_string (PREFIX ("unpack%d%s"), field->rank > 0 ? 1 : 0,
2313 vector->ts.type == BT_CHARACTER ? "_char" : "");
2318 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2319 gfc_expr *set ATTRIBUTE_UNUSED,
2320 gfc_expr *back ATTRIBUTE_UNUSED)
2322 f->ts.type = BT_INTEGER;
2323 f->ts.kind = gfc_default_integer_kind;
2324 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2329 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2331 f->ts.type = i->ts.type;
2332 f->ts.kind = gfc_kind_max (i, j);
2334 if (i->ts.kind != j->ts.kind)
2336 if (i->ts.kind == gfc_kind_max (i, j))
2337 gfc_convert_type (j, &i->ts, 2);
2339 gfc_convert_type (i, &j->ts, 2);
2342 f->value.function.name
2343 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2347 /* Intrinsic subroutine resolution. */
2350 gfc_resolve_alarm_sub (gfc_code *c)
2353 gfc_expr *seconds, *handler, *status;
2356 seconds = c->ext.actual->expr;
2357 handler = c->ext.actual->next->expr;
2358 status = c->ext.actual->next->next->expr;
2359 ts.type = BT_INTEGER;
2360 ts.kind = gfc_c_int_kind;
2362 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2363 if (handler->ts.type == BT_INTEGER)
2365 if (handler->ts.kind != gfc_c_int_kind)
2366 gfc_convert_type (handler, &ts, 2);
2367 name = gfc_get_string (PREFIX ("alarm_sub_int"));
2370 name = gfc_get_string (PREFIX ("alarm_sub"));
2372 if (seconds->ts.kind != gfc_c_int_kind)
2373 gfc_convert_type (seconds, &ts, 2);
2375 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2379 gfc_resolve_cpu_time (gfc_code *c)
2382 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2383 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2388 gfc_resolve_mvbits (gfc_code *c)
2393 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2394 they will be converted so that they fit into a C int. */
2395 ts.type = BT_INTEGER;
2396 ts.kind = gfc_c_int_kind;
2397 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2398 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2399 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2400 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2401 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2402 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2404 /* TO and FROM are guaranteed to have the same kind parameter. */
2405 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2406 c->ext.actual->expr->ts.kind);
2407 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2412 gfc_resolve_random_number (gfc_code *c)
2417 kind = c->ext.actual->expr->ts.kind;
2418 if (c->ext.actual->expr->rank == 0)
2419 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2421 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2423 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2428 gfc_resolve_rename_sub (gfc_code *c)
2433 if (c->ext.actual->next->next->expr != NULL)
2434 kind = c->ext.actual->next->next->expr->ts.kind;
2436 kind = gfc_default_integer_kind;
2438 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2439 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2444 gfc_resolve_kill_sub (gfc_code *c)
2449 if (c->ext.actual->next->next->expr != NULL)
2450 kind = c->ext.actual->next->next->expr->ts.kind;
2452 kind = gfc_default_integer_kind;
2454 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2455 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2460 gfc_resolve_link_sub (gfc_code *c)
2465 if (c->ext.actual->next->next->expr != NULL)
2466 kind = c->ext.actual->next->next->expr->ts.kind;
2468 kind = gfc_default_integer_kind;
2470 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2471 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2476 gfc_resolve_symlnk_sub (gfc_code *c)
2481 if (c->ext.actual->next->next->expr != NULL)
2482 kind = c->ext.actual->next->next->expr->ts.kind;
2484 kind = gfc_default_integer_kind;
2486 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2487 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2491 /* G77 compatibility subroutines etime() and dtime(). */
2494 gfc_resolve_etime_sub (gfc_code *c)
2497 name = gfc_get_string (PREFIX ("etime_sub"));
2498 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2502 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2505 gfc_resolve_itime (gfc_code *c)
2508 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2509 gfc_default_integer_kind));
2513 gfc_resolve_idate (gfc_code *c)
2516 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2517 gfc_default_integer_kind));
2521 gfc_resolve_ltime (gfc_code *c)
2524 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2525 gfc_default_integer_kind));
2529 gfc_resolve_gmtime (gfc_code *c)
2532 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2533 gfc_default_integer_kind));
2537 /* G77 compatibility subroutine second(). */
2540 gfc_resolve_second_sub (gfc_code *c)
2543 name = gfc_get_string (PREFIX ("second_sub"));
2544 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2549 gfc_resolve_sleep_sub (gfc_code *c)
2554 if (c->ext.actual->expr != NULL)
2555 kind = c->ext.actual->expr->ts.kind;
2557 kind = gfc_default_integer_kind;
2559 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2560 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2564 /* G77 compatibility function srand(). */
2567 gfc_resolve_srand (gfc_code *c)
2570 name = gfc_get_string (PREFIX ("srand"));
2571 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2575 /* Resolve the getarg intrinsic subroutine. */
2578 gfc_resolve_getarg (gfc_code *c)
2582 kind = gfc_default_integer_kind;
2583 name = gfc_get_string (PREFIX ("getarg_i%d"), kind);
2584 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2588 /* Resolve the getcwd intrinsic subroutine. */
2591 gfc_resolve_getcwd_sub (gfc_code *c)
2596 if (c->ext.actual->next->expr != NULL)
2597 kind = c->ext.actual->next->expr->ts.kind;
2599 kind = gfc_default_integer_kind;
2601 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2602 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2606 /* Resolve the get_command intrinsic subroutine. */
2609 gfc_resolve_get_command (gfc_code *c)
2613 kind = gfc_default_integer_kind;
2614 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2615 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2619 /* Resolve the get_command_argument intrinsic subroutine. */
2622 gfc_resolve_get_command_argument (gfc_code *c)
2626 kind = gfc_default_integer_kind;
2627 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2628 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2632 /* Resolve the get_environment_variable intrinsic subroutine. */
2635 gfc_resolve_get_environment_variable (gfc_code *code)
2639 kind = gfc_default_integer_kind;
2640 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2641 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2646 gfc_resolve_signal_sub (gfc_code *c)
2649 gfc_expr *number, *handler, *status;
2652 number = c->ext.actual->expr;
2653 handler = c->ext.actual->next->expr;
2654 status = c->ext.actual->next->next->expr;
2655 ts.type = BT_INTEGER;
2656 ts.kind = gfc_c_int_kind;
2658 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2659 if (handler->ts.type == BT_INTEGER)
2661 if (handler->ts.kind != gfc_c_int_kind)
2662 gfc_convert_type (handler, &ts, 2);
2663 name = gfc_get_string (PREFIX ("signal_sub_int"));
2666 name = gfc_get_string (PREFIX ("signal_sub"));
2668 if (number->ts.kind != gfc_c_int_kind)
2669 gfc_convert_type (number, &ts, 2);
2670 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2671 gfc_convert_type (status, &ts, 2);
2673 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2677 /* Resolve the SYSTEM intrinsic subroutine. */
2680 gfc_resolve_system_sub (gfc_code *c)
2683 name = gfc_get_string (PREFIX ("system_sub"));
2684 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2688 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2691 gfc_resolve_system_clock (gfc_code *c)
2696 if (c->ext.actual->expr != NULL)
2697 kind = c->ext.actual->expr->ts.kind;
2698 else if (c->ext.actual->next->expr != NULL)
2699 kind = c->ext.actual->next->expr->ts.kind;
2700 else if (c->ext.actual->next->next->expr != NULL)
2701 kind = c->ext.actual->next->next->expr->ts.kind;
2703 kind = gfc_default_integer_kind;
2705 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
2706 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2710 /* Resolve the EXIT intrinsic subroutine. */
2713 gfc_resolve_exit (gfc_code *c)
2718 if (c->ext.actual->expr != NULL)
2719 kind = c->ext.actual->expr->ts.kind;
2721 kind = gfc_default_integer_kind;
2723 name = gfc_get_string (PREFIX ("exit_i%d"), kind);
2724 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2728 /* Resolve the FLUSH intrinsic subroutine. */
2731 gfc_resolve_flush (gfc_code *c)
2737 ts.type = BT_INTEGER;
2738 ts.kind = gfc_default_integer_kind;
2739 n = c->ext.actual->expr;
2740 if (n != NULL && n->ts.kind != ts.kind)
2741 gfc_convert_type (n, &ts, 2);
2743 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
2744 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2749 gfc_resolve_free (gfc_code *c)
2754 ts.type = BT_INTEGER;
2755 ts.kind = gfc_index_integer_kind;
2756 n = c->ext.actual->expr;
2757 if (n->ts.kind != ts.kind)
2758 gfc_convert_type (n, &ts, 2);
2760 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
2765 gfc_resolve_ctime_sub (gfc_code *c)
2769 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
2770 if (c->ext.actual->expr->ts.kind != 8)
2772 ts.type = BT_INTEGER;
2776 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2779 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
2784 gfc_resolve_fdate_sub (gfc_code *c)
2786 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
2791 gfc_resolve_gerror (gfc_code *c)
2793 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
2798 gfc_resolve_getlog (gfc_code *c)
2800 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
2805 gfc_resolve_hostnm_sub (gfc_code *c)
2810 if (c->ext.actual->next->expr != NULL)
2811 kind = c->ext.actual->next->expr->ts.kind;
2813 kind = gfc_default_integer_kind;
2815 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
2816 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2821 gfc_resolve_perror (gfc_code *c)
2823 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
2826 /* Resolve the STAT and FSTAT intrinsic subroutines. */
2829 gfc_resolve_stat_sub (gfc_code *c)
2832 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
2833 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2838 gfc_resolve_lstat_sub (gfc_code *c)
2841 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
2842 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2847 gfc_resolve_fstat_sub (gfc_code *c)
2853 u = c->ext.actual->expr;
2854 ts = &c->ext.actual->next->expr->ts;
2855 if (u->ts.kind != ts->kind)
2856 gfc_convert_type (u, ts, 2);
2857 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
2858 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2863 gfc_resolve_fgetc_sub (gfc_code *c)
2869 u = c->ext.actual->expr;
2870 st = c->ext.actual->next->next->expr;
2872 if (u->ts.kind != gfc_c_int_kind)
2874 ts.type = BT_INTEGER;
2875 ts.kind = gfc_c_int_kind;
2878 gfc_convert_type (u, &ts, 2);
2882 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
2884 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
2886 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2891 gfc_resolve_fget_sub (gfc_code *c)
2896 st = c->ext.actual->next->expr;
2898 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
2900 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
2902 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2907 gfc_resolve_fputc_sub (gfc_code *c)
2913 u = c->ext.actual->expr;
2914 st = c->ext.actual->next->next->expr;
2916 if (u->ts.kind != gfc_c_int_kind)
2918 ts.type = BT_INTEGER;
2919 ts.kind = gfc_c_int_kind;
2922 gfc_convert_type (u, &ts, 2);
2926 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
2928 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
2930 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2935 gfc_resolve_fput_sub (gfc_code *c)
2940 st = c->ext.actual->next->expr;
2942 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
2944 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
2946 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2951 gfc_resolve_fseek_sub (gfc_code *c)
2959 unit = c->ext.actual->expr;
2960 offset = c->ext.actual->next->expr;
2961 whence = c->ext.actual->next->next->expr;
2962 status = c->ext.actual->next->next->next->expr;
2964 if (unit->ts.kind != gfc_c_int_kind)
2966 ts.type = BT_INTEGER;
2967 ts.kind = gfc_c_int_kind;
2970 gfc_convert_type (unit, &ts, 2);
2973 if (offset->ts.kind != gfc_intio_kind)
2975 ts.type = BT_INTEGER;
2976 ts.kind = gfc_intio_kind;
2979 gfc_convert_type (offset, &ts, 2);
2982 if (whence->ts.kind != gfc_c_int_kind)
2984 ts.type = BT_INTEGER;
2985 ts.kind = gfc_c_int_kind;
2988 gfc_convert_type (whence, &ts, 2);
2991 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
2995 gfc_resolve_ftell_sub (gfc_code *c)
3002 unit = c->ext.actual->expr;
3003 offset = c->ext.actual->next->expr;
3005 if (unit->ts.kind != gfc_c_int_kind)
3007 ts.type = BT_INTEGER;
3008 ts.kind = gfc_c_int_kind;
3011 gfc_convert_type (unit, &ts, 2);
3014 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3015 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3020 gfc_resolve_ttynam_sub (gfc_code *c)
3024 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3026 ts.type = BT_INTEGER;
3027 ts.kind = gfc_c_int_kind;
3030 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3033 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3037 /* Resolve the UMASK intrinsic subroutine. */
3040 gfc_resolve_umask_sub (gfc_code *c)
3045 if (c->ext.actual->next->expr != NULL)
3046 kind = c->ext.actual->next->expr->ts.kind;
3048 kind = gfc_default_integer_kind;
3050 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3051 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3054 /* Resolve the UNLINK intrinsic subroutine. */
3057 gfc_resolve_unlink_sub (gfc_code *c)
3062 if (c->ext.actual->next->expr != NULL)
3063 kind = c->ext.actual->next->expr->ts.kind;
3065 kind = gfc_default_integer_kind;
3067 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3068 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);