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 2, 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 COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
24 /* Assign name and types to intrinsic procedures. For functions, the
25 first argument to a resolution function is an expression pointer to
26 the original function node and the rest are pointers to the
27 arguments of the function call. For subroutines, a pointer to the
28 code node is passed. The result type and library subroutine name
29 are generally set according to the function arguments. */
33 #include "coretypes.h"
36 #include "intrinsic.h"
38 /* Given printf-like arguments, return a stable version of the result string.
40 We already have a working, optimized string hashing table in the form of
41 the identifier table. Reusing this table is likely not to be wasted,
42 since if the function name makes it to the gimple output of the frontend,
43 we'll have to create the identifier anyway. */
46 gfc_get_string (const char *format, ...)
52 va_start (ap, format);
53 vsnprintf (temp_name, sizeof (temp_name), format, ap);
55 temp_name[sizeof (temp_name) - 1] = 0;
57 ident = get_identifier (temp_name);
58 return IDENTIFIER_POINTER (ident);
61 /* MERGE and SPREAD need to have source charlen's present for passing
62 to the result expression. */
64 check_charlen_present (gfc_expr *source)
66 if (source->expr_type == EXPR_CONSTANT && source->ts.cl == NULL)
68 source->ts.cl = gfc_get_charlen ();
69 source->ts.cl->next = gfc_current_ns->cl_list;
70 gfc_current_ns->cl_list = source->ts.cl;
71 source->ts.cl->length = gfc_int_expr (source->value.character.length);
76 /********************** Resolution functions **********************/
80 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
83 if (f->ts.type == BT_COMPLEX)
86 f->value.function.name
87 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
92 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
93 gfc_expr *mode ATTRIBUTE_UNUSED)
95 f->ts.type = BT_INTEGER;
96 f->ts.kind = gfc_c_int_kind;
97 f->value.function.name = PREFIX ("access_func");
102 gfc_resolve_achar (gfc_expr *f, gfc_expr *x)
105 f->ts.type = BT_CHARACTER;
106 f->ts.kind = gfc_default_character_kind;
107 f->ts.cl = gfc_get_charlen ();
108 f->ts.cl->next = gfc_current_ns->cl_list;
109 gfc_current_ns->cl_list = f->ts.cl;
110 f->ts.cl->length = gfc_int_expr (1);
112 f->value.function.name
113 = gfc_get_string ("__achar_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
118 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
121 f->value.function.name
122 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
127 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
130 f->value.function.name
131 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
137 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
139 f->ts.type = BT_REAL;
140 f->ts.kind = x->ts.kind;
141 f->value.function.name
142 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
148 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
150 f->ts.type = i->ts.type;
151 f->ts.kind = gfc_kind_max (i, j);
153 if (i->ts.kind != j->ts.kind)
155 if (i->ts.kind == gfc_kind_max (i, j))
156 gfc_convert_type (j, &i->ts, 2);
158 gfc_convert_type (i, &j->ts, 2);
161 f->value.function.name
162 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
167 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
171 f->ts.type = a->ts.type;
172 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
174 if (a->ts.kind != f->ts.kind)
176 ts.type = f->ts.type;
177 ts.kind = f->ts.kind;
178 gfc_convert_type (a, &ts, 2);
180 /* The resolved name is only used for specific intrinsics where
181 the return kind is the same as the arg kind. */
182 f->value.function.name
183 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
188 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
190 gfc_resolve_aint (f, a, NULL);
195 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
201 gfc_resolve_dim_arg (dim);
202 f->rank = mask->rank - 1;
203 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
206 f->value.function.name
207 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
213 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
217 f->ts.type = a->ts.type;
218 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
220 if (a->ts.kind != f->ts.kind)
222 ts.type = f->ts.type;
223 ts.kind = f->ts.kind;
224 gfc_convert_type (a, &ts, 2);
227 /* The resolved name is only used for specific intrinsics where
228 the return kind is the same as the arg kind. */
229 f->value.function.name
230 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
236 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
238 gfc_resolve_anint (f, a, NULL);
243 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
249 gfc_resolve_dim_arg (dim);
250 f->rank = mask->rank - 1;
251 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
254 f->value.function.name
255 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
261 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
264 f->value.function.name
265 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
269 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
272 f->value.function.name
273 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
278 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
281 f->value.function.name
282 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
286 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
289 f->value.function.name
290 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
295 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
298 f->value.function.name
299 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
304 /* Resolve the BESYN and BESJN intrinsics. */
307 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
312 if (n->ts.kind != gfc_c_int_kind)
314 ts.type = BT_INTEGER;
315 ts.kind = gfc_c_int_kind;
316 gfc_convert_type (n, &ts, 2);
318 f->value.function.name = gfc_get_string ("<intrinsic>");
323 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
325 f->ts.type = BT_LOGICAL;
326 f->ts.kind = gfc_default_logical_kind;
327 f->value.function.name
328 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
333 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
335 f->ts.type = BT_INTEGER;
336 f->ts.kind = (kind == NULL)
337 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
338 f->value.function.name
339 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
340 gfc_type_letter (a->ts.type), a->ts.kind);
345 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
347 f->ts.type = BT_CHARACTER;
348 f->ts.kind = (kind == NULL)
349 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
350 f->value.function.name
351 = gfc_get_string ("__char_%d_%c%d", f->ts.kind,
352 gfc_type_letter (a->ts.type), a->ts.kind);
357 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
359 f->ts.type = BT_INTEGER;
360 f->ts.kind = gfc_default_integer_kind;
361 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
366 gfc_resolve_chdir_sub (gfc_code *c)
371 if (c->ext.actual->next->expr != NULL)
372 kind = c->ext.actual->next->expr->ts.kind;
374 kind = gfc_default_integer_kind;
376 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
377 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
382 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
383 gfc_expr *mode ATTRIBUTE_UNUSED)
385 f->ts.type = BT_INTEGER;
386 f->ts.kind = gfc_c_int_kind;
387 f->value.function.name = PREFIX ("chmod_func");
392 gfc_resolve_chmod_sub (gfc_code *c)
397 if (c->ext.actual->next->next->expr != NULL)
398 kind = c->ext.actual->next->next->expr->ts.kind;
400 kind = gfc_default_integer_kind;
402 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
403 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
408 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
410 f->ts.type = BT_COMPLEX;
411 f->ts.kind = (kind == NULL)
412 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
415 f->value.function.name
416 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
417 gfc_type_letter (x->ts.type), x->ts.kind);
419 f->value.function.name
420 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
421 gfc_type_letter (x->ts.type), x->ts.kind,
422 gfc_type_letter (y->ts.type), y->ts.kind);
427 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
429 gfc_resolve_cmplx (f, x, y, gfc_int_expr (gfc_default_double_kind));
434 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
438 if (x->ts.type == BT_INTEGER)
440 if (y->ts.type == BT_INTEGER)
441 kind = gfc_default_real_kind;
447 if (y->ts.type == BT_REAL)
448 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
453 f->ts.type = BT_COMPLEX;
455 f->value.function.name
456 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
457 gfc_type_letter (x->ts.type), x->ts.kind,
458 gfc_type_letter (y->ts.type), y->ts.kind);
463 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
466 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
471 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
474 f->value.function.name
475 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
480 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
483 f->value.function.name
484 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
489 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
491 f->ts.type = BT_INTEGER;
492 f->ts.kind = gfc_default_integer_kind;
496 f->rank = mask->rank - 1;
497 gfc_resolve_dim_arg (dim);
498 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
501 f->value.function.name
502 = gfc_get_string (PREFIX ("count_%d_%c%d"), f->ts.kind,
503 gfc_type_letter (mask->ts.type), mask->ts.kind);
508 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
514 f->rank = array->rank;
515 f->shape = gfc_copy_shape (array->shape, array->rank);
522 /* Convert shift to at least gfc_default_integer_kind, so we don't need
523 kind=1 and kind=2 versions of the library functions. */
524 if (shift->ts.kind < gfc_default_integer_kind)
527 ts.type = BT_INTEGER;
528 ts.kind = gfc_default_integer_kind;
529 gfc_convert_type_warn (shift, &ts, 2, 0);
534 gfc_resolve_dim_arg (dim);
535 /* Convert dim to shift's kind, so we don't need so many variations. */
536 if (dim->ts.kind != shift->ts.kind)
537 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
539 f->value.function.name
540 = gfc_get_string (PREFIX ("cshift%d_%d%s"), n, shift->ts.kind,
541 array->ts.type == BT_CHARACTER ? "_char" : "");
546 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
550 f->ts.type = BT_CHARACTER;
551 f->ts.kind = gfc_default_character_kind;
553 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
554 if (time->ts.kind != 8)
556 ts.type = BT_INTEGER;
560 gfc_convert_type (time, &ts, 2);
563 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
568 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
570 f->ts.type = BT_REAL;
571 f->ts.kind = gfc_default_double_kind;
572 f->value.function.name
573 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
578 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
580 f->ts.type = a->ts.type;
582 f->ts.kind = gfc_kind_max (a,p);
584 f->ts.kind = a->ts.kind;
586 if (p != NULL && a->ts.kind != p->ts.kind)
588 if (a->ts.kind == gfc_kind_max (a,p))
589 gfc_convert_type (p, &a->ts, 2);
591 gfc_convert_type (a, &p->ts, 2);
594 f->value.function.name
595 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
600 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
604 temp.expr_type = EXPR_OP;
605 gfc_clear_ts (&temp.ts);
606 temp.value.op.operator = INTRINSIC_NONE;
607 temp.value.op.op1 = a;
608 temp.value.op.op2 = b;
609 gfc_type_convert_binary (&temp);
611 f->value.function.name
612 = gfc_get_string (PREFIX ("dot_product_%c%d"),
613 gfc_type_letter (f->ts.type), f->ts.kind);
618 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
619 gfc_expr *b ATTRIBUTE_UNUSED)
621 f->ts.kind = gfc_default_double_kind;
622 f->ts.type = BT_REAL;
623 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
628 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
629 gfc_expr *boundary, gfc_expr *dim)
634 f->rank = array->rank;
635 f->shape = gfc_copy_shape (array->shape, array->rank);
640 if (boundary && boundary->rank > 0)
643 /* Convert shift to at least gfc_default_integer_kind, so we don't need
644 kind=1 and kind=2 versions of the library functions. */
645 if (shift->ts.kind < gfc_default_integer_kind)
648 ts.type = BT_INTEGER;
649 ts.kind = gfc_default_integer_kind;
650 gfc_convert_type_warn (shift, &ts, 2, 0);
655 gfc_resolve_dim_arg (dim);
656 /* Convert dim to shift's kind, so we don't need so many variations. */
657 if (dim->ts.kind != shift->ts.kind)
658 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
661 f->value.function.name
662 = gfc_get_string (PREFIX ("eoshift%d_%d%s"), n, shift->ts.kind,
663 array->ts.type == BT_CHARACTER ? "_char" : "");
668 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
671 f->value.function.name
672 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
677 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
679 f->ts.type = BT_INTEGER;
680 f->ts.kind = gfc_default_integer_kind;
681 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
686 gfc_resolve_fdate (gfc_expr *f)
688 f->ts.type = BT_CHARACTER;
689 f->ts.kind = gfc_default_character_kind;
690 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
695 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
697 f->ts.type = BT_INTEGER;
698 f->ts.kind = (kind == NULL)
699 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
700 f->value.function.name
701 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
702 gfc_type_letter (a->ts.type), a->ts.kind);
707 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
709 f->ts.type = BT_INTEGER;
710 f->ts.kind = gfc_default_integer_kind;
711 if (n->ts.kind != f->ts.kind)
712 gfc_convert_type (n, &f->ts, 2);
713 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
718 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
721 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
725 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
728 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
731 f->value.function.name = gfc_get_string ("<intrinsic>");
736 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
738 f->ts.type = BT_INTEGER;
740 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
745 gfc_resolve_getgid (gfc_expr *f)
747 f->ts.type = BT_INTEGER;
749 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
754 gfc_resolve_getpid (gfc_expr *f)
756 f->ts.type = BT_INTEGER;
758 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
763 gfc_resolve_getuid (gfc_expr *f)
765 f->ts.type = BT_INTEGER;
767 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
772 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
774 f->ts.type = BT_INTEGER;
776 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
781 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
783 /* If the kind of i and j are different, then g77 cross-promoted the
784 kinds to the largest value. The Fortran 95 standard requires the
786 if (i->ts.kind != j->ts.kind)
788 if (i->ts.kind == gfc_kind_max (i, j))
789 gfc_convert_type (j, &i->ts, 2);
791 gfc_convert_type (i, &j->ts, 2);
795 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
800 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
803 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
808 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
809 gfc_expr *len ATTRIBUTE_UNUSED)
812 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
817 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
820 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
825 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c)
827 f->ts.type = BT_INTEGER;
828 f->ts.kind = gfc_default_integer_kind;
829 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
834 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
836 gfc_resolve_nint (f, a, NULL);
841 gfc_resolve_ierrno (gfc_expr *f)
843 f->ts.type = BT_INTEGER;
844 f->ts.kind = gfc_default_integer_kind;
845 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
850 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
852 /* If the kind of i and j are different, then g77 cross-promoted the
853 kinds to the largest value. The Fortran 95 standard requires the
855 if (i->ts.kind != j->ts.kind)
857 if (i->ts.kind == gfc_kind_max (i, j))
858 gfc_convert_type (j, &i->ts, 2);
860 gfc_convert_type (i, &j->ts, 2);
864 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
869 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
871 /* If the kind of i and j are different, then g77 cross-promoted the
872 kinds to the largest value. The Fortran 95 standard requires the
874 if (i->ts.kind != j->ts.kind)
876 if (i->ts.kind == gfc_kind_max (i, j))
877 gfc_convert_type (j, &i->ts, 2);
879 gfc_convert_type (i, &j->ts, 2);
883 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
888 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
889 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back)
893 f->ts.type = BT_INTEGER;
894 f->ts.kind = gfc_default_integer_kind;
896 if (back && back->ts.kind != gfc_default_integer_kind)
898 ts.type = BT_LOGICAL;
899 ts.kind = gfc_default_integer_kind;
902 gfc_convert_type (back, &ts, 2);
905 f->value.function.name
906 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
911 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
913 f->ts.type = BT_INTEGER;
914 f->ts.kind = (kind == NULL)
915 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
916 f->value.function.name
917 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
918 gfc_type_letter (a->ts.type), a->ts.kind);
923 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
925 f->ts.type = BT_INTEGER;
927 f->value.function.name
928 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
929 gfc_type_letter (a->ts.type), a->ts.kind);
934 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
936 f->ts.type = BT_INTEGER;
938 f->value.function.name
939 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
940 gfc_type_letter (a->ts.type), a->ts.kind);
945 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
947 f->ts.type = BT_INTEGER;
949 f->value.function.name
950 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
951 gfc_type_letter (a->ts.type), a->ts.kind);
956 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
960 f->ts.type = BT_LOGICAL;
961 f->ts.kind = gfc_default_integer_kind;
962 if (u->ts.kind != gfc_c_int_kind)
964 ts.type = BT_INTEGER;
965 ts.kind = gfc_c_int_kind;
968 gfc_convert_type (u, &ts, 2);
971 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
976 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
979 f->value.function.name
980 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
985 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
988 f->value.function.name
989 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
994 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
997 f->value.function.name
998 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1003 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1007 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1010 f->value.function.name
1011 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1016 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1017 gfc_expr *s ATTRIBUTE_UNUSED)
1019 f->ts.type = BT_INTEGER;
1020 f->ts.kind = gfc_default_integer_kind;
1021 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1026 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1028 static char lbound[] = "__lbound";
1030 f->ts.type = BT_INTEGER;
1031 f->ts.kind = gfc_default_integer_kind;
1036 f->shape = gfc_get_shape (1);
1037 mpz_init_set_ui (f->shape[0], array->rank);
1040 f->value.function.name = lbound;
1045 gfc_resolve_len (gfc_expr *f, gfc_expr *string)
1047 f->ts.type = BT_INTEGER;
1048 f->ts.kind = gfc_default_integer_kind;
1049 f->value.function.name
1050 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1051 gfc_default_integer_kind);
1056 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string)
1058 f->ts.type = BT_INTEGER;
1059 f->ts.kind = gfc_default_integer_kind;
1060 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1065 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1066 gfc_expr *p2 ATTRIBUTE_UNUSED)
1068 f->ts.type = BT_INTEGER;
1069 f->ts.kind = gfc_default_integer_kind;
1070 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1075 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1077 f->ts.type= BT_INTEGER;
1078 f->ts.kind = gfc_index_integer_kind;
1079 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1084 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1087 f->value.function.name
1088 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1093 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1096 f->value.function.name
1097 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1103 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1105 f->ts.type = BT_LOGICAL;
1106 f->ts.kind = (kind == NULL)
1107 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1110 f->value.function.name
1111 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1112 gfc_type_letter (a->ts.type), a->ts.kind);
1117 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1119 if (size->ts.kind < gfc_index_integer_kind)
1123 ts.type = BT_INTEGER;
1124 ts.kind = gfc_index_integer_kind;
1125 gfc_convert_type_warn (size, &ts, 2, 0);
1128 f->ts.type = BT_INTEGER;
1129 f->ts.kind = gfc_index_integer_kind;
1130 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1135 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1139 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1141 f->ts.type = BT_LOGICAL;
1142 f->ts.kind = gfc_default_logical_kind;
1146 temp.expr_type = EXPR_OP;
1147 gfc_clear_ts (&temp.ts);
1148 temp.value.op.operator = INTRINSIC_NONE;
1149 temp.value.op.op1 = a;
1150 temp.value.op.op2 = b;
1151 gfc_type_convert_binary (&temp);
1155 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1157 f->value.function.name
1158 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1164 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1166 gfc_actual_arglist *a;
1168 f->ts.type = args->expr->ts.type;
1169 f->ts.kind = args->expr->ts.kind;
1170 /* Find the largest type kind. */
1171 for (a = args->next; a; a = a->next)
1173 if (a->expr->ts.kind > f->ts.kind)
1174 f->ts.kind = a->expr->ts.kind;
1177 /* Convert all parameters to the required kind. */
1178 for (a = args; a; a = a->next)
1180 if (a->expr->ts.kind != f->ts.kind)
1181 gfc_convert_type (a->expr, &f->ts, 2);
1184 f->value.function.name
1185 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1190 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1192 gfc_resolve_minmax ("__max_%c%d", f, args);
1197 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1203 f->ts.type = BT_INTEGER;
1204 f->ts.kind = gfc_default_integer_kind;
1209 f->shape = gfc_get_shape (1);
1210 mpz_init_set_si (f->shape[0], array->rank);
1214 f->rank = array->rank - 1;
1215 gfc_resolve_dim_arg (dim);
1216 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1218 idim = (int) mpz_get_si (dim->value.integer);
1219 f->shape = gfc_get_shape (f->rank);
1220 for (i = 0, j = 0; i < f->rank; i++, j++)
1222 if (i == (idim - 1))
1224 mpz_init_set (f->shape[i], array->shape[j]);
1231 if (mask->rank == 0)
1236 /* The mask can be kind 4 or 8 for the array case. For the
1237 scalar case, coerce it to default kind unconditionally. */
1238 if ((mask->ts.kind < gfc_default_logical_kind)
1239 || (mask->rank == 0 && mask->ts.kind != gfc_default_logical_kind))
1242 ts.type = BT_LOGICAL;
1243 ts.kind = gfc_default_logical_kind;
1244 gfc_convert_type_warn (mask, &ts, 2, 0);
1250 f->value.function.name
1251 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1252 gfc_type_letter (array->ts.type), array->ts.kind);
1257 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1267 f->rank = array->rank - 1;
1268 gfc_resolve_dim_arg (dim);
1270 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1272 idim = (int) mpz_get_si (dim->value.integer);
1273 f->shape = gfc_get_shape (f->rank);
1274 for (i = 0, j = 0; i < f->rank; i++, j++)
1276 if (i == (idim - 1))
1278 mpz_init_set (f->shape[i], array->shape[j]);
1285 if (mask->rank == 0)
1290 /* The mask can be kind 4 or 8 for the array case. For the
1291 scalar case, coerce it to default kind unconditionally. */
1292 if ((mask->ts.kind < gfc_default_logical_kind)
1293 || (mask->rank == 0 && mask->ts.kind != gfc_default_logical_kind))
1296 ts.type = BT_LOGICAL;
1297 ts.kind = gfc_default_logical_kind;
1298 gfc_convert_type_warn (mask, &ts, 2, 0);
1304 f->value.function.name
1305 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1306 gfc_type_letter (array->ts.type), array->ts.kind);
1311 gfc_resolve_mclock (gfc_expr *f)
1313 f->ts.type = BT_INTEGER;
1315 f->value.function.name = PREFIX ("mclock");
1320 gfc_resolve_mclock8 (gfc_expr *f)
1322 f->ts.type = BT_INTEGER;
1324 f->value.function.name = PREFIX ("mclock8");
1329 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1330 gfc_expr *fsource ATTRIBUTE_UNUSED,
1331 gfc_expr *mask ATTRIBUTE_UNUSED)
1333 if (tsource->ts.type == BT_CHARACTER)
1334 check_charlen_present (tsource);
1336 f->ts = tsource->ts;
1337 f->value.function.name
1338 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1344 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1346 gfc_resolve_minmax ("__min_%c%d", f, args);
1351 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1357 f->ts.type = BT_INTEGER;
1358 f->ts.kind = gfc_default_integer_kind;
1363 f->shape = gfc_get_shape (1);
1364 mpz_init_set_si (f->shape[0], array->rank);
1368 f->rank = array->rank - 1;
1369 gfc_resolve_dim_arg (dim);
1370 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1372 idim = (int) mpz_get_si (dim->value.integer);
1373 f->shape = gfc_get_shape (f->rank);
1374 for (i = 0, j = 0; i < f->rank; i++, j++)
1376 if (i == (idim - 1))
1378 mpz_init_set (f->shape[i], array->shape[j]);
1385 if (mask->rank == 0)
1390 /* The mask can be kind 4 or 8 for the array case. For the
1391 scalar case, coerce it to default kind unconditionally. */
1392 if ((mask->ts.kind < gfc_default_logical_kind)
1393 || (mask->rank == 0 && mask->ts.kind != gfc_default_logical_kind))
1396 ts.type = BT_LOGICAL;
1397 ts.kind = gfc_default_logical_kind;
1398 gfc_convert_type_warn (mask, &ts, 2, 0);
1404 f->value.function.name
1405 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1406 gfc_type_letter (array->ts.type), array->ts.kind);
1411 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1421 f->rank = array->rank - 1;
1422 gfc_resolve_dim_arg (dim);
1424 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1426 idim = (int) mpz_get_si (dim->value.integer);
1427 f->shape = gfc_get_shape (f->rank);
1428 for (i = 0, j = 0; i < f->rank; i++, j++)
1430 if (i == (idim - 1))
1432 mpz_init_set (f->shape[i], array->shape[j]);
1439 if (mask->rank == 0)
1444 /* The mask can be kind 4 or 8 for the array case. For the
1445 scalar case, coerce it to default kind unconditionally. */
1446 if ((mask->ts.kind < gfc_default_logical_kind)
1447 || (mask->rank == 0 && mask->ts.kind != gfc_default_logical_kind))
1450 ts.type = BT_LOGICAL;
1451 ts.kind = gfc_default_logical_kind;
1452 gfc_convert_type_warn (mask, &ts, 2, 0);
1458 f->value.function.name
1459 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1460 gfc_type_letter (array->ts.type), array->ts.kind);
1465 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1467 f->ts.type = a->ts.type;
1469 f->ts.kind = gfc_kind_max (a,p);
1471 f->ts.kind = a->ts.kind;
1473 if (p != NULL && a->ts.kind != p->ts.kind)
1475 if (a->ts.kind == gfc_kind_max (a,p))
1476 gfc_convert_type (p, &a->ts, 2);
1478 gfc_convert_type (a, &p->ts, 2);
1481 f->value.function.name
1482 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1487 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1489 f->ts.type = a->ts.type;
1491 f->ts.kind = gfc_kind_max (a,p);
1493 f->ts.kind = a->ts.kind;
1495 if (p != NULL && a->ts.kind != p->ts.kind)
1497 if (a->ts.kind == gfc_kind_max (a,p))
1498 gfc_convert_type (p, &a->ts, 2);
1500 gfc_convert_type (a, &p->ts, 2);
1503 f->value.function.name
1504 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1509 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p ATTRIBUTE_UNUSED)
1512 f->value.function.name
1513 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1518 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1520 f->ts.type = BT_INTEGER;
1521 f->ts.kind = (kind == NULL)
1522 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1523 f->value.function.name
1524 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1529 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1532 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1537 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1539 f->ts.type = i->ts.type;
1540 f->ts.kind = gfc_kind_max (i, j);
1542 if (i->ts.kind != j->ts.kind)
1544 if (i->ts.kind == gfc_kind_max (i, j))
1545 gfc_convert_type (j, &i->ts, 2);
1547 gfc_convert_type (i, &j->ts, 2);
1550 f->value.function.name
1551 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1556 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1557 gfc_expr *vector ATTRIBUTE_UNUSED)
1562 if (mask->rank != 0)
1563 f->value.function.name = (array->ts.type == BT_CHARACTER
1564 ? PREFIX ("pack_char") : PREFIX ("pack"));
1567 /* We convert mask to default logical only in the scalar case.
1568 In the array case we can simply read the array as if it were
1569 of type default logical. */
1570 if (mask->ts.kind != gfc_default_logical_kind)
1574 ts.type = BT_LOGICAL;
1575 ts.kind = gfc_default_logical_kind;
1576 gfc_convert_type (mask, &ts, 2);
1579 f->value.function.name = (array->ts.type == BT_CHARACTER
1580 ? PREFIX ("pack_s_char") : PREFIX ("pack_s"));
1586 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1595 f->rank = array->rank - 1;
1596 gfc_resolve_dim_arg (dim);
1601 if (mask->rank == 0)
1606 /* The mask can be kind 4 or 8 for the array case. For the
1607 scalar case, coerce it to default kind unconditionally. */
1608 if ((mask->ts.kind < gfc_default_logical_kind)
1609 || (mask->rank == 0 && mask->ts.kind != gfc_default_logical_kind))
1612 ts.type = BT_LOGICAL;
1613 ts.kind = gfc_default_logical_kind;
1614 gfc_convert_type_warn (mask, &ts, 2, 0);
1620 f->value.function.name
1621 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1622 gfc_type_letter (array->ts.type), array->ts.kind);
1627 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1629 f->ts.type = BT_REAL;
1632 f->ts.kind = mpz_get_si (kind->value.integer);
1634 f->ts.kind = (a->ts.type == BT_COMPLEX)
1635 ? a->ts.kind : gfc_default_real_kind;
1637 f->value.function.name
1638 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1639 gfc_type_letter (a->ts.type), a->ts.kind);
1644 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1646 f->ts.type = BT_REAL;
1647 f->ts.kind = a->ts.kind;
1648 f->value.function.name
1649 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1650 gfc_type_letter (a->ts.type), a->ts.kind);
1655 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1656 gfc_expr *p2 ATTRIBUTE_UNUSED)
1658 f->ts.type = BT_INTEGER;
1659 f->ts.kind = gfc_default_integer_kind;
1660 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1665 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
1666 gfc_expr *ncopies ATTRIBUTE_UNUSED)
1668 f->ts.type = BT_CHARACTER;
1669 f->ts.kind = string->ts.kind;
1670 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
1675 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
1676 gfc_expr *pad ATTRIBUTE_UNUSED,
1677 gfc_expr *order ATTRIBUTE_UNUSED)
1685 gfc_array_size (shape, &rank);
1686 f->rank = mpz_get_si (rank);
1688 switch (source->ts.type)
1694 kind = source->ts.kind;
1708 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
1709 f->value.function.name
1710 = gfc_get_string (PREFIX ("reshape_%c%d"),
1711 gfc_type_letter (source->ts.type),
1714 f->value.function.name
1715 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
1720 f->value.function.name = (source->ts.type == BT_CHARACTER
1721 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1725 /* TODO: Make this work with a constant ORDER parameter. */
1726 if (shape->expr_type == EXPR_ARRAY
1727 && gfc_is_constant_expr (shape)
1731 f->shape = gfc_get_shape (f->rank);
1732 c = shape->value.constructor;
1733 for (i = 0; i < f->rank; i++)
1735 mpz_init_set (f->shape[i], c->expr->value.integer);
1740 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
1741 so many runtime variations. */
1742 if (shape->ts.kind != gfc_index_integer_kind)
1744 gfc_typespec ts = shape->ts;
1745 ts.kind = gfc_index_integer_kind;
1746 gfc_convert_type_warn (shape, &ts, 2, 0);
1748 if (order && order->ts.kind != gfc_index_integer_kind)
1749 gfc_convert_type_warn (order, &shape->ts, 2, 0);
1754 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
1757 gfc_actual_arglist *prec;
1760 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
1762 /* Create a hidden argument to the library routines for rrspacing. This
1763 hidden argument is the precision of x. */
1764 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1765 prec = gfc_get_actual_arglist ();
1767 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1768 f->value.function.actual->next = prec;
1773 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1777 /* The implementation calls scalbn which takes an int as the
1779 if (i->ts.kind != gfc_c_int_kind)
1782 ts.type = BT_INTEGER;
1783 ts.kind = gfc_default_integer_kind;
1784 gfc_convert_type_warn (i, &ts, 2, 0);
1787 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
1792 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
1793 gfc_expr *set ATTRIBUTE_UNUSED,
1794 gfc_expr *back ATTRIBUTE_UNUSED)
1796 f->ts.type = BT_INTEGER;
1797 f->ts.kind = gfc_default_integer_kind;
1798 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
1803 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
1806 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
1811 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1815 /* The library implementation uses GFC_INTEGER_4 unconditionally,
1816 convert type so we don't have to implement all possible
1818 if (i->ts.kind != 4)
1821 ts.type = BT_INTEGER;
1822 ts.kind = gfc_default_integer_kind;
1823 gfc_convert_type_warn (i, &ts, 2, 0);
1826 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
1831 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
1833 f->ts.type = BT_INTEGER;
1834 f->ts.kind = gfc_default_integer_kind;
1836 f->shape = gfc_get_shape (1);
1837 mpz_init_set_ui (f->shape[0], array->rank);
1838 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
1843 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
1846 f->value.function.name
1847 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
1852 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
1854 f->ts.type = BT_INTEGER;
1855 f->ts.kind = gfc_c_int_kind;
1857 /* handler can be either BT_INTEGER or BT_PROCEDURE */
1858 if (handler->ts.type == BT_INTEGER)
1860 if (handler->ts.kind != gfc_c_int_kind)
1861 gfc_convert_type (handler, &f->ts, 2);
1862 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
1865 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
1867 if (number->ts.kind != gfc_c_int_kind)
1868 gfc_convert_type (number, &f->ts, 2);
1873 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
1876 f->value.function.name
1877 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1882 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
1885 f->value.function.name
1886 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1891 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
1894 gfc_actual_arglist *prec, *tiny, *emin_1;
1897 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
1899 /* Create hidden arguments to the library routine for spacing. These
1900 hidden arguments are tiny(x), min_exponent - 1, and the precision
1903 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1905 tiny = gfc_get_actual_arglist ();
1906 tiny->name = "tiny";
1907 tiny->expr = gfc_get_expr ();
1908 tiny->expr->expr_type = EXPR_CONSTANT;
1909 tiny->expr->where = gfc_current_locus;
1910 tiny->expr->ts.type = x->ts.type;
1911 tiny->expr->ts.kind = x->ts.kind;
1912 mpfr_init (tiny->expr->value.real);
1913 mpfr_set (tiny->expr->value.real, gfc_real_kinds[k].tiny, GFC_RND_MODE);
1915 emin_1 = gfc_get_actual_arglist ();
1916 emin_1->name = "emin";
1917 emin_1->expr = gfc_int_expr (gfc_real_kinds[k].min_exponent - 1);
1918 emin_1->next = tiny;
1920 prec = gfc_get_actual_arglist ();
1921 prec->name = "prec";
1922 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1923 prec->next = emin_1;
1925 f->value.function.actual->next = prec;
1930 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
1933 if (source->ts.type == BT_CHARACTER)
1934 check_charlen_present (source);
1937 f->rank = source->rank + 1;
1938 if (source->rank == 0)
1939 f->value.function.name = (source->ts.type == BT_CHARACTER
1940 ? PREFIX ("spread_char_scalar")
1941 : PREFIX ("spread_scalar"));
1943 f->value.function.name = (source->ts.type == BT_CHARACTER
1944 ? PREFIX ("spread_char")
1945 : PREFIX ("spread"));
1947 if (dim && gfc_is_constant_expr (dim)
1948 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
1951 idim = mpz_get_ui (dim->value.integer);
1952 f->shape = gfc_get_shape (f->rank);
1953 for (i = 0; i < (idim - 1); i++)
1954 mpz_init_set (f->shape[i], source->shape[i]);
1956 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
1958 for (i = idim; i < f->rank ; i++)
1959 mpz_init_set (f->shape[i], source->shape[i-1]);
1963 gfc_resolve_dim_arg (dim);
1964 gfc_resolve_index (ncopies, 1);
1969 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
1972 f->value.function.name
1973 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1977 /* Resolve the g77 compatibility function STAT AND FSTAT. */
1980 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
1981 gfc_expr *a ATTRIBUTE_UNUSED)
1983 f->ts.type = BT_INTEGER;
1984 f->ts.kind = gfc_default_integer_kind;
1985 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
1990 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
1991 gfc_expr *a ATTRIBUTE_UNUSED)
1993 f->ts.type = BT_INTEGER;
1994 f->ts.kind = gfc_default_integer_kind;
1995 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2000 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2002 f->ts.type = BT_INTEGER;
2003 f->ts.kind = gfc_default_integer_kind;
2004 if (n->ts.kind != f->ts.kind)
2005 gfc_convert_type (n, &f->ts, 2);
2007 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2012 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2016 f->ts.type = BT_INTEGER;
2017 f->ts.kind = gfc_c_int_kind;
2018 if (u->ts.kind != gfc_c_int_kind)
2020 ts.type = BT_INTEGER;
2021 ts.kind = gfc_c_int_kind;
2024 gfc_convert_type (u, &ts, 2);
2027 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2032 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2034 f->ts.type = BT_INTEGER;
2035 f->ts.kind = gfc_c_int_kind;
2036 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2041 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2045 f->ts.type = BT_INTEGER;
2046 f->ts.kind = gfc_c_int_kind;
2047 if (u->ts.kind != gfc_c_int_kind)
2049 ts.type = BT_INTEGER;
2050 ts.kind = gfc_c_int_kind;
2053 gfc_convert_type (u, &ts, 2);
2056 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2061 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2063 f->ts.type = BT_INTEGER;
2064 f->ts.kind = gfc_c_int_kind;
2065 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2070 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2074 f->ts.type = BT_INTEGER;
2075 f->ts.kind = gfc_index_integer_kind;
2076 if (u->ts.kind != gfc_c_int_kind)
2078 ts.type = BT_INTEGER;
2079 ts.kind = gfc_c_int_kind;
2082 gfc_convert_type (u, &ts, 2);
2085 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2090 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2098 if (mask->rank == 0)
2103 /* The mask can be kind 4 or 8 for the array case. For the
2104 scalar case, coerce it to default kind unconditionally. */
2105 if ((mask->ts.kind < gfc_default_logical_kind)
2106 || (mask->rank == 0 && mask->ts.kind != gfc_default_logical_kind))
2109 ts.type = BT_LOGICAL;
2110 ts.kind = gfc_default_logical_kind;
2111 gfc_convert_type_warn (mask, &ts, 2, 0);
2119 f->rank = array->rank - 1;
2120 gfc_resolve_dim_arg (dim);
2123 f->value.function.name
2124 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2125 gfc_type_letter (array->ts.type), array->ts.kind);
2130 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2131 gfc_expr *p2 ATTRIBUTE_UNUSED)
2133 f->ts.type = BT_INTEGER;
2134 f->ts.kind = gfc_default_integer_kind;
2135 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2139 /* Resolve the g77 compatibility function SYSTEM. */
2142 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2144 f->ts.type = BT_INTEGER;
2146 f->value.function.name = gfc_get_string (PREFIX ("system"));
2151 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2154 f->value.function.name
2155 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2160 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2163 f->value.function.name
2164 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2169 gfc_resolve_time (gfc_expr *f)
2171 f->ts.type = BT_INTEGER;
2173 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2178 gfc_resolve_time8 (gfc_expr *f)
2180 f->ts.type = BT_INTEGER;
2182 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2187 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2188 gfc_expr *mold, gfc_expr *size)
2190 /* TODO: Make this do something meaningful. */
2191 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2195 if (size == NULL && mold->rank == 0)
2198 f->value.function.name = transfer0;
2203 f->value.function.name = transfer1;
2204 if (size && gfc_is_constant_expr (size))
2206 f->shape = gfc_get_shape (1);
2207 mpz_init_set (f->shape[0], size->value.integer);
2214 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2220 f->shape = gfc_get_shape (2);
2221 mpz_init_set (f->shape[0], matrix->shape[1]);
2222 mpz_init_set (f->shape[1], matrix->shape[0]);
2225 switch (matrix->ts.kind)
2231 switch (matrix->ts.type)
2235 f->value.function.name
2236 = gfc_get_string (PREFIX ("transpose_%c%d"),
2237 gfc_type_letter (matrix->ts.type),
2243 /* Use the integer routines for real and logical cases. This
2244 assumes they all have the same alignment requirements. */
2245 f->value.function.name
2246 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2250 f->value.function.name = PREFIX ("transpose");
2256 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2257 ? PREFIX ("transpose_char")
2258 : PREFIX ("transpose"));
2265 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2267 f->ts.type = BT_CHARACTER;
2268 f->ts.kind = string->ts.kind;
2269 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2274 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
2276 static char ubound[] = "__ubound";
2278 f->ts.type = BT_INTEGER;
2279 f->ts.kind = gfc_default_integer_kind;
2284 f->shape = gfc_get_shape (1);
2285 mpz_init_set_ui (f->shape[0], array->rank);
2288 f->value.function.name = ubound;
2292 /* Resolve the g77 compatibility function UMASK. */
2295 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2297 f->ts.type = BT_INTEGER;
2298 f->ts.kind = n->ts.kind;
2299 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2303 /* Resolve the g77 compatibility function UNLINK. */
2306 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2308 f->ts.type = BT_INTEGER;
2310 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2315 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2319 f->ts.type = BT_CHARACTER;
2320 f->ts.kind = gfc_default_character_kind;
2322 if (unit->ts.kind != gfc_c_int_kind)
2324 ts.type = BT_INTEGER;
2325 ts.kind = gfc_c_int_kind;
2328 gfc_convert_type (unit, &ts, 2);
2331 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2336 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2337 gfc_expr *field ATTRIBUTE_UNUSED)
2340 f->rank = mask->rank;
2342 f->value.function.name
2343 = gfc_get_string (PREFIX ("unpack%d%s"), field->rank > 0 ? 1 : 0,
2344 vector->ts.type == BT_CHARACTER ? "_char" : "");
2349 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2350 gfc_expr *set ATTRIBUTE_UNUSED,
2351 gfc_expr *back ATTRIBUTE_UNUSED)
2353 f->ts.type = BT_INTEGER;
2354 f->ts.kind = gfc_default_integer_kind;
2355 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2360 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2362 f->ts.type = i->ts.type;
2363 f->ts.kind = gfc_kind_max (i, j);
2365 if (i->ts.kind != j->ts.kind)
2367 if (i->ts.kind == gfc_kind_max (i, j))
2368 gfc_convert_type (j, &i->ts, 2);
2370 gfc_convert_type (i, &j->ts, 2);
2373 f->value.function.name
2374 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2378 /* Intrinsic subroutine resolution. */
2381 gfc_resolve_alarm_sub (gfc_code *c)
2384 gfc_expr *seconds, *handler, *status;
2387 seconds = c->ext.actual->expr;
2388 handler = c->ext.actual->next->expr;
2389 status = c->ext.actual->next->next->expr;
2390 ts.type = BT_INTEGER;
2391 ts.kind = gfc_c_int_kind;
2393 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2394 if (handler->ts.type == BT_INTEGER)
2396 if (handler->ts.kind != gfc_c_int_kind)
2397 gfc_convert_type (handler, &ts, 2);
2398 name = gfc_get_string (PREFIX ("alarm_sub_int"));
2401 name = gfc_get_string (PREFIX ("alarm_sub"));
2403 if (seconds->ts.kind != gfc_c_int_kind)
2404 gfc_convert_type (seconds, &ts, 2);
2406 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2410 gfc_resolve_cpu_time (gfc_code *c)
2413 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2414 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2419 gfc_resolve_mvbits (gfc_code *c)
2423 kind = c->ext.actual->expr->ts.kind;
2424 name = gfc_get_string (PREFIX ("mvbits_i%d"), kind);
2425 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2430 gfc_resolve_random_number (gfc_code *c)
2435 kind = c->ext.actual->expr->ts.kind;
2436 if (c->ext.actual->expr->rank == 0)
2437 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2439 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2441 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2446 gfc_resolve_rename_sub (gfc_code *c)
2451 if (c->ext.actual->next->next->expr != NULL)
2452 kind = c->ext.actual->next->next->expr->ts.kind;
2454 kind = gfc_default_integer_kind;
2456 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2457 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2462 gfc_resolve_kill_sub (gfc_code *c)
2467 if (c->ext.actual->next->next->expr != NULL)
2468 kind = c->ext.actual->next->next->expr->ts.kind;
2470 kind = gfc_default_integer_kind;
2472 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2473 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2478 gfc_resolve_link_sub (gfc_code *c)
2483 if (c->ext.actual->next->next->expr != NULL)
2484 kind = c->ext.actual->next->next->expr->ts.kind;
2486 kind = gfc_default_integer_kind;
2488 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2489 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2494 gfc_resolve_symlnk_sub (gfc_code *c)
2499 if (c->ext.actual->next->next->expr != NULL)
2500 kind = c->ext.actual->next->next->expr->ts.kind;
2502 kind = gfc_default_integer_kind;
2504 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2505 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2509 /* G77 compatibility subroutines etime() and dtime(). */
2512 gfc_resolve_etime_sub (gfc_code *c)
2515 name = gfc_get_string (PREFIX ("etime_sub"));
2516 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2520 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2523 gfc_resolve_itime (gfc_code *c)
2526 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2527 gfc_default_integer_kind));
2531 gfc_resolve_idate (gfc_code *c)
2534 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2535 gfc_default_integer_kind));
2539 gfc_resolve_ltime (gfc_code *c)
2542 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2543 gfc_default_integer_kind));
2547 gfc_resolve_gmtime (gfc_code *c)
2550 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2551 gfc_default_integer_kind));
2555 /* G77 compatibility subroutine second(). */
2558 gfc_resolve_second_sub (gfc_code *c)
2561 name = gfc_get_string (PREFIX ("second_sub"));
2562 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2567 gfc_resolve_sleep_sub (gfc_code *c)
2572 if (c->ext.actual->expr != NULL)
2573 kind = c->ext.actual->expr->ts.kind;
2575 kind = gfc_default_integer_kind;
2577 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2578 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2582 /* G77 compatibility function srand(). */
2585 gfc_resolve_srand (gfc_code *c)
2588 name = gfc_get_string (PREFIX ("srand"));
2589 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2593 /* Resolve the getarg intrinsic subroutine. */
2596 gfc_resolve_getarg (gfc_code *c)
2600 kind = gfc_default_integer_kind;
2601 name = gfc_get_string (PREFIX ("getarg_i%d"), kind);
2602 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2606 /* Resolve the getcwd intrinsic subroutine. */
2609 gfc_resolve_getcwd_sub (gfc_code *c)
2614 if (c->ext.actual->next->expr != NULL)
2615 kind = c->ext.actual->next->expr->ts.kind;
2617 kind = gfc_default_integer_kind;
2619 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2620 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2624 /* Resolve the get_command intrinsic subroutine. */
2627 gfc_resolve_get_command (gfc_code *c)
2631 kind = gfc_default_integer_kind;
2632 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2633 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2637 /* Resolve the get_command_argument intrinsic subroutine. */
2640 gfc_resolve_get_command_argument (gfc_code *c)
2644 kind = gfc_default_integer_kind;
2645 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2646 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2650 /* Resolve the get_environment_variable intrinsic subroutine. */
2653 gfc_resolve_get_environment_variable (gfc_code *code)
2657 kind = gfc_default_integer_kind;
2658 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2659 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2664 gfc_resolve_signal_sub (gfc_code *c)
2667 gfc_expr *number, *handler, *status;
2670 number = c->ext.actual->expr;
2671 handler = c->ext.actual->next->expr;
2672 status = c->ext.actual->next->next->expr;
2673 ts.type = BT_INTEGER;
2674 ts.kind = gfc_c_int_kind;
2676 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2677 if (handler->ts.type == BT_INTEGER)
2679 if (handler->ts.kind != gfc_c_int_kind)
2680 gfc_convert_type (handler, &ts, 2);
2681 name = gfc_get_string (PREFIX ("signal_sub_int"));
2684 name = gfc_get_string (PREFIX ("signal_sub"));
2686 if (number->ts.kind != gfc_c_int_kind)
2687 gfc_convert_type (number, &ts, 2);
2688 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2689 gfc_convert_type (status, &ts, 2);
2691 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2695 /* Resolve the SYSTEM intrinsic subroutine. */
2698 gfc_resolve_system_sub (gfc_code *c)
2701 name = gfc_get_string (PREFIX ("system_sub"));
2702 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2706 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2709 gfc_resolve_system_clock (gfc_code *c)
2714 if (c->ext.actual->expr != NULL)
2715 kind = c->ext.actual->expr->ts.kind;
2716 else if (c->ext.actual->next->expr != NULL)
2717 kind = c->ext.actual->next->expr->ts.kind;
2718 else if (c->ext.actual->next->next->expr != NULL)
2719 kind = c->ext.actual->next->next->expr->ts.kind;
2721 kind = gfc_default_integer_kind;
2723 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
2724 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2728 /* Resolve the EXIT intrinsic subroutine. */
2731 gfc_resolve_exit (gfc_code *c)
2736 if (c->ext.actual->expr != NULL)
2737 kind = c->ext.actual->expr->ts.kind;
2739 kind = gfc_default_integer_kind;
2741 name = gfc_get_string (PREFIX ("exit_i%d"), kind);
2742 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2746 /* Resolve the FLUSH intrinsic subroutine. */
2749 gfc_resolve_flush (gfc_code *c)
2755 ts.type = BT_INTEGER;
2756 ts.kind = gfc_default_integer_kind;
2757 n = c->ext.actual->expr;
2758 if (n != NULL && n->ts.kind != ts.kind)
2759 gfc_convert_type (n, &ts, 2);
2761 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
2762 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2767 gfc_resolve_free (gfc_code *c)
2772 ts.type = BT_INTEGER;
2773 ts.kind = gfc_index_integer_kind;
2774 n = c->ext.actual->expr;
2775 if (n->ts.kind != ts.kind)
2776 gfc_convert_type (n, &ts, 2);
2778 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
2783 gfc_resolve_ctime_sub (gfc_code *c)
2787 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
2788 if (c->ext.actual->expr->ts.kind != 8)
2790 ts.type = BT_INTEGER;
2794 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2797 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
2802 gfc_resolve_fdate_sub (gfc_code *c)
2804 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
2809 gfc_resolve_gerror (gfc_code *c)
2811 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
2816 gfc_resolve_getlog (gfc_code *c)
2818 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
2823 gfc_resolve_hostnm_sub (gfc_code *c)
2828 if (c->ext.actual->next->expr != NULL)
2829 kind = c->ext.actual->next->expr->ts.kind;
2831 kind = gfc_default_integer_kind;
2833 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
2834 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2839 gfc_resolve_perror (gfc_code *c)
2841 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
2844 /* Resolve the STAT and FSTAT intrinsic subroutines. */
2847 gfc_resolve_stat_sub (gfc_code *c)
2850 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
2851 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2856 gfc_resolve_lstat_sub (gfc_code *c)
2859 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
2860 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2865 gfc_resolve_fstat_sub (gfc_code *c)
2871 u = c->ext.actual->expr;
2872 ts = &c->ext.actual->next->expr->ts;
2873 if (u->ts.kind != ts->kind)
2874 gfc_convert_type (u, ts, 2);
2875 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
2876 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2881 gfc_resolve_fgetc_sub (gfc_code *c)
2887 u = c->ext.actual->expr;
2888 st = c->ext.actual->next->next->expr;
2890 if (u->ts.kind != gfc_c_int_kind)
2892 ts.type = BT_INTEGER;
2893 ts.kind = gfc_c_int_kind;
2896 gfc_convert_type (u, &ts, 2);
2900 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
2902 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
2904 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2909 gfc_resolve_fget_sub (gfc_code *c)
2914 st = c->ext.actual->next->expr;
2916 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
2918 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
2920 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2925 gfc_resolve_fputc_sub (gfc_code *c)
2931 u = c->ext.actual->expr;
2932 st = c->ext.actual->next->next->expr;
2934 if (u->ts.kind != gfc_c_int_kind)
2936 ts.type = BT_INTEGER;
2937 ts.kind = gfc_c_int_kind;
2940 gfc_convert_type (u, &ts, 2);
2944 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
2946 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
2948 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2953 gfc_resolve_fput_sub (gfc_code *c)
2958 st = c->ext.actual->next->expr;
2960 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
2962 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
2964 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2969 gfc_resolve_fseek_sub (gfc_code *c)
2977 unit = c->ext.actual->expr;
2978 offset = c->ext.actual->next->expr;
2979 whence = c->ext.actual->next->next->expr;
2980 status = c->ext.actual->next->next->next->expr;
2982 if (unit->ts.kind != gfc_c_int_kind)
2984 ts.type = BT_INTEGER;
2985 ts.kind = gfc_c_int_kind;
2988 gfc_convert_type (unit, &ts, 2);
2991 if (offset->ts.kind != gfc_intio_kind)
2993 ts.type = BT_INTEGER;
2994 ts.kind = gfc_intio_kind;
2997 gfc_convert_type (offset, &ts, 2);
3000 if (whence->ts.kind != gfc_c_int_kind)
3002 ts.type = BT_INTEGER;
3003 ts.kind = gfc_c_int_kind;
3006 gfc_convert_type (whence, &ts, 2);
3009 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3013 gfc_resolve_ftell_sub (gfc_code *c)
3020 unit = c->ext.actual->expr;
3021 offset = c->ext.actual->next->expr;
3023 if (unit->ts.kind != gfc_c_int_kind)
3025 ts.type = BT_INTEGER;
3026 ts.kind = gfc_c_int_kind;
3029 gfc_convert_type (unit, &ts, 2);
3032 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3033 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3038 gfc_resolve_ttynam_sub (gfc_code *c)
3042 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3044 ts.type = BT_INTEGER;
3045 ts.kind = gfc_c_int_kind;
3048 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3051 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3055 /* Resolve the UMASK intrinsic subroutine. */
3058 gfc_resolve_umask_sub (gfc_code *c)
3063 if (c->ext.actual->next->expr != NULL)
3064 kind = c->ext.actual->next->expr->ts.kind;
3066 kind = gfc_default_integer_kind;
3068 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3069 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3072 /* Resolve the UNLINK intrinsic subroutine. */
3075 gfc_resolve_unlink_sub (gfc_code *c)
3080 if (c->ext.actual->next->expr != NULL)
3081 kind = c->ext.actual->next->expr->ts.kind;
3083 kind = gfc_default_integer_kind;
3085 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3086 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);