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, gfc_expr *kind)
525 f->ts.type = BT_INTEGER;
527 f->ts.kind = mpz_get_si (kind->value.integer);
529 f->ts.kind = gfc_default_integer_kind;
533 f->rank = mask->rank - 1;
534 gfc_resolve_dim_arg (dim);
535 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
538 f->value.function.name
539 = gfc_get_string (PREFIX ("count_%d_%c%d"), f->ts.kind,
540 gfc_type_letter (mask->ts.type), mask->ts.kind);
545 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
551 f->rank = array->rank;
552 f->shape = gfc_copy_shape (array->shape, array->rank);
559 /* Convert shift to at least gfc_default_integer_kind, so we don't need
560 kind=1 and kind=2 versions of the library functions. */
561 if (shift->ts.kind < gfc_default_integer_kind)
564 ts.type = BT_INTEGER;
565 ts.kind = gfc_default_integer_kind;
566 gfc_convert_type_warn (shift, &ts, 2, 0);
571 gfc_resolve_dim_arg (dim);
572 /* Convert dim to shift's kind, so we don't need so many variations. */
573 if (dim->ts.kind != shift->ts.kind)
574 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
576 f->value.function.name
577 = gfc_get_string (PREFIX ("cshift%d_%d%s"), n, shift->ts.kind,
578 array->ts.type == BT_CHARACTER ? "_char" : "");
583 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
587 f->ts.type = BT_CHARACTER;
588 f->ts.kind = gfc_default_character_kind;
590 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
591 if (time->ts.kind != 8)
593 ts.type = BT_INTEGER;
597 gfc_convert_type (time, &ts, 2);
600 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
605 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
607 f->ts.type = BT_REAL;
608 f->ts.kind = gfc_default_double_kind;
609 f->value.function.name
610 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
615 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
617 f->ts.type = a->ts.type;
619 f->ts.kind = gfc_kind_max (a,p);
621 f->ts.kind = a->ts.kind;
623 if (p != NULL && a->ts.kind != p->ts.kind)
625 if (a->ts.kind == gfc_kind_max (a,p))
626 gfc_convert_type (p, &a->ts, 2);
628 gfc_convert_type (a, &p->ts, 2);
631 f->value.function.name
632 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
637 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
641 temp.expr_type = EXPR_OP;
642 gfc_clear_ts (&temp.ts);
643 temp.value.op.operator = INTRINSIC_NONE;
644 temp.value.op.op1 = a;
645 temp.value.op.op2 = b;
646 gfc_type_convert_binary (&temp);
648 f->value.function.name
649 = gfc_get_string (PREFIX ("dot_product_%c%d"),
650 gfc_type_letter (f->ts.type), f->ts.kind);
655 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
656 gfc_expr *b ATTRIBUTE_UNUSED)
658 f->ts.kind = gfc_default_double_kind;
659 f->ts.type = BT_REAL;
660 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
665 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
666 gfc_expr *boundary, gfc_expr *dim)
671 f->rank = array->rank;
672 f->shape = gfc_copy_shape (array->shape, array->rank);
677 if (boundary && boundary->rank > 0)
680 /* Convert shift to at least gfc_default_integer_kind, so we don't need
681 kind=1 and kind=2 versions of the library functions. */
682 if (shift->ts.kind < gfc_default_integer_kind)
685 ts.type = BT_INTEGER;
686 ts.kind = gfc_default_integer_kind;
687 gfc_convert_type_warn (shift, &ts, 2, 0);
692 gfc_resolve_dim_arg (dim);
693 /* Convert dim to shift's kind, so we don't need so many variations. */
694 if (dim->ts.kind != shift->ts.kind)
695 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
698 f->value.function.name
699 = gfc_get_string (PREFIX ("eoshift%d_%d%s"), n, shift->ts.kind,
700 array->ts.type == BT_CHARACTER ? "_char" : "");
705 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
708 f->value.function.name
709 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
714 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
716 f->ts.type = BT_INTEGER;
717 f->ts.kind = gfc_default_integer_kind;
718 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
723 gfc_resolve_fdate (gfc_expr *f)
725 f->ts.type = BT_CHARACTER;
726 f->ts.kind = gfc_default_character_kind;
727 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
732 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
734 f->ts.type = BT_INTEGER;
735 f->ts.kind = (kind == NULL)
736 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
737 f->value.function.name
738 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
739 gfc_type_letter (a->ts.type), a->ts.kind);
744 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
746 f->ts.type = BT_INTEGER;
747 f->ts.kind = gfc_default_integer_kind;
748 if (n->ts.kind != f->ts.kind)
749 gfc_convert_type (n, &f->ts, 2);
750 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
755 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
758 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
762 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
765 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
768 f->value.function.name = gfc_get_string ("<intrinsic>");
773 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
775 f->ts.type = BT_INTEGER;
777 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
782 gfc_resolve_getgid (gfc_expr *f)
784 f->ts.type = BT_INTEGER;
786 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
791 gfc_resolve_getpid (gfc_expr *f)
793 f->ts.type = BT_INTEGER;
795 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
800 gfc_resolve_getuid (gfc_expr *f)
802 f->ts.type = BT_INTEGER;
804 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
809 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
811 f->ts.type = BT_INTEGER;
813 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
818 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
820 /* If the kind of i and j are different, then g77 cross-promoted the
821 kinds to the largest value. The Fortran 95 standard requires the
823 if (i->ts.kind != j->ts.kind)
825 if (i->ts.kind == gfc_kind_max (i, j))
826 gfc_convert_type (j, &i->ts, 2);
828 gfc_convert_type (i, &j->ts, 2);
832 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
837 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
840 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
845 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
846 gfc_expr *len ATTRIBUTE_UNUSED)
849 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
854 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
857 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
862 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
864 f->ts.type = BT_INTEGER;
866 f->ts.kind = mpz_get_si (kind->value.integer);
868 f->ts.kind = gfc_default_integer_kind;
869 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
874 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
876 f->ts.type = BT_INTEGER;
878 f->ts.kind = mpz_get_si (kind->value.integer);
880 f->ts.kind = gfc_default_integer_kind;
881 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
886 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
888 gfc_resolve_nint (f, a, NULL);
893 gfc_resolve_ierrno (gfc_expr *f)
895 f->ts.type = BT_INTEGER;
896 f->ts.kind = gfc_default_integer_kind;
897 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
902 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
904 /* If the kind of i and j are different, then g77 cross-promoted the
905 kinds to the largest value. The Fortran 95 standard requires the
907 if (i->ts.kind != j->ts.kind)
909 if (i->ts.kind == gfc_kind_max (i, j))
910 gfc_convert_type (j, &i->ts, 2);
912 gfc_convert_type (i, &j->ts, 2);
916 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
921 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
923 /* If the kind of i and j are different, then g77 cross-promoted the
924 kinds to the largest value. The Fortran 95 standard requires the
926 if (i->ts.kind != j->ts.kind)
928 if (i->ts.kind == gfc_kind_max (i, j))
929 gfc_convert_type (j, &i->ts, 2);
931 gfc_convert_type (i, &j->ts, 2);
935 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
940 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
941 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
946 f->ts.type = BT_INTEGER;
948 f->ts.kind = mpz_get_si (kind->value.integer);
950 f->ts.kind = gfc_default_integer_kind;
952 if (back && back->ts.kind != gfc_default_integer_kind)
954 ts.type = BT_LOGICAL;
955 ts.kind = gfc_default_integer_kind;
958 gfc_convert_type (back, &ts, 2);
961 f->value.function.name
962 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
967 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
969 f->ts.type = BT_INTEGER;
970 f->ts.kind = (kind == NULL)
971 ? gfc_default_integer_kind : mpz_get_si (kind->value.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_int2 (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_int8 (gfc_expr *f, gfc_expr *a)
992 f->ts.type = BT_INTEGER;
994 f->value.function.name
995 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
996 gfc_type_letter (a->ts.type), a->ts.kind);
1001 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1003 f->ts.type = BT_INTEGER;
1005 f->value.function.name
1006 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1007 gfc_type_letter (a->ts.type), a->ts.kind);
1012 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1016 f->ts.type = BT_LOGICAL;
1017 f->ts.kind = gfc_default_integer_kind;
1018 if (u->ts.kind != gfc_c_int_kind)
1020 ts.type = BT_INTEGER;
1021 ts.kind = gfc_c_int_kind;
1024 gfc_convert_type (u, &ts, 2);
1027 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1032 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1035 f->value.function.name
1036 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1041 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1044 f->value.function.name
1045 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1050 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1053 f->value.function.name
1054 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1059 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1063 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1066 f->value.function.name
1067 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1072 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1073 gfc_expr *s ATTRIBUTE_UNUSED)
1075 f->ts.type = BT_INTEGER;
1076 f->ts.kind = gfc_default_integer_kind;
1077 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1082 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1084 static char lbound[] = "__lbound";
1086 f->ts.type = BT_INTEGER;
1088 f->ts.kind = mpz_get_si (kind->value.integer);
1090 f->ts.kind = gfc_default_integer_kind;
1095 f->shape = gfc_get_shape (1);
1096 mpz_init_set_ui (f->shape[0], array->rank);
1099 f->value.function.name = lbound;
1104 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1106 f->ts.type = BT_INTEGER;
1108 f->ts.kind = mpz_get_si (kind->value.integer);
1110 f->ts.kind = gfc_default_integer_kind;
1111 f->value.function.name
1112 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1113 gfc_default_integer_kind);
1118 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1120 f->ts.type = BT_INTEGER;
1122 f->ts.kind = mpz_get_si (kind->value.integer);
1124 f->ts.kind = gfc_default_integer_kind;
1125 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1130 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1131 gfc_expr *p2 ATTRIBUTE_UNUSED)
1133 f->ts.type = BT_INTEGER;
1134 f->ts.kind = gfc_default_integer_kind;
1135 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1140 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1142 f->ts.type= BT_INTEGER;
1143 f->ts.kind = gfc_index_integer_kind;
1144 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1149 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1152 f->value.function.name
1153 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1158 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1161 f->value.function.name
1162 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1168 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1170 f->ts.type = BT_LOGICAL;
1171 f->ts.kind = (kind == NULL)
1172 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1175 f->value.function.name
1176 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1177 gfc_type_letter (a->ts.type), a->ts.kind);
1182 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1184 if (size->ts.kind < gfc_index_integer_kind)
1188 ts.type = BT_INTEGER;
1189 ts.kind = gfc_index_integer_kind;
1190 gfc_convert_type_warn (size, &ts, 2, 0);
1193 f->ts.type = BT_INTEGER;
1194 f->ts.kind = gfc_index_integer_kind;
1195 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1200 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1204 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1206 f->ts.type = BT_LOGICAL;
1207 f->ts.kind = gfc_default_logical_kind;
1211 temp.expr_type = EXPR_OP;
1212 gfc_clear_ts (&temp.ts);
1213 temp.value.op.operator = INTRINSIC_NONE;
1214 temp.value.op.op1 = a;
1215 temp.value.op.op2 = b;
1216 gfc_type_convert_binary (&temp);
1220 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1222 f->value.function.name
1223 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1229 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1231 gfc_actual_arglist *a;
1233 f->ts.type = args->expr->ts.type;
1234 f->ts.kind = args->expr->ts.kind;
1235 /* Find the largest type kind. */
1236 for (a = args->next; a; a = a->next)
1238 if (a->expr->ts.kind > f->ts.kind)
1239 f->ts.kind = a->expr->ts.kind;
1242 /* Convert all parameters to the required kind. */
1243 for (a = args; a; a = a->next)
1245 if (a->expr->ts.kind != f->ts.kind)
1246 gfc_convert_type (a->expr, &f->ts, 2);
1249 f->value.function.name
1250 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1255 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1257 gfc_resolve_minmax ("__max_%c%d", f, args);
1262 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1268 f->ts.type = BT_INTEGER;
1269 f->ts.kind = gfc_default_integer_kind;
1274 f->shape = gfc_get_shape (1);
1275 mpz_init_set_si (f->shape[0], array->rank);
1279 f->rank = array->rank - 1;
1280 gfc_resolve_dim_arg (dim);
1281 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1283 idim = (int) mpz_get_si (dim->value.integer);
1284 f->shape = gfc_get_shape (f->rank);
1285 for (i = 0, j = 0; i < f->rank; i++, j++)
1287 if (i == (idim - 1))
1289 mpz_init_set (f->shape[i], array->shape[j]);
1296 if (mask->rank == 0)
1301 resolve_mask_arg (mask);
1306 f->value.function.name
1307 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1308 gfc_type_letter (array->ts.type), array->ts.kind);
1313 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1323 f->rank = array->rank - 1;
1324 gfc_resolve_dim_arg (dim);
1326 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1328 idim = (int) mpz_get_si (dim->value.integer);
1329 f->shape = gfc_get_shape (f->rank);
1330 for (i = 0, j = 0; i < f->rank; i++, j++)
1332 if (i == (idim - 1))
1334 mpz_init_set (f->shape[i], array->shape[j]);
1341 if (mask->rank == 0)
1346 resolve_mask_arg (mask);
1351 f->value.function.name
1352 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1353 gfc_type_letter (array->ts.type), array->ts.kind);
1358 gfc_resolve_mclock (gfc_expr *f)
1360 f->ts.type = BT_INTEGER;
1362 f->value.function.name = PREFIX ("mclock");
1367 gfc_resolve_mclock8 (gfc_expr *f)
1369 f->ts.type = BT_INTEGER;
1371 f->value.function.name = PREFIX ("mclock8");
1376 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1377 gfc_expr *fsource ATTRIBUTE_UNUSED,
1378 gfc_expr *mask ATTRIBUTE_UNUSED)
1380 if (tsource->ts.type == BT_CHARACTER)
1381 check_charlen_present (tsource);
1383 f->ts = tsource->ts;
1384 f->value.function.name
1385 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1391 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1393 gfc_resolve_minmax ("__min_%c%d", f, args);
1398 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1404 f->ts.type = BT_INTEGER;
1405 f->ts.kind = gfc_default_integer_kind;
1410 f->shape = gfc_get_shape (1);
1411 mpz_init_set_si (f->shape[0], array->rank);
1415 f->rank = array->rank - 1;
1416 gfc_resolve_dim_arg (dim);
1417 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1419 idim = (int) mpz_get_si (dim->value.integer);
1420 f->shape = gfc_get_shape (f->rank);
1421 for (i = 0, j = 0; i < f->rank; i++, j++)
1423 if (i == (idim - 1))
1425 mpz_init_set (f->shape[i], array->shape[j]);
1432 if (mask->rank == 0)
1437 resolve_mask_arg (mask);
1442 f->value.function.name
1443 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1444 gfc_type_letter (array->ts.type), array->ts.kind);
1449 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1459 f->rank = array->rank - 1;
1460 gfc_resolve_dim_arg (dim);
1462 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1464 idim = (int) mpz_get_si (dim->value.integer);
1465 f->shape = gfc_get_shape (f->rank);
1466 for (i = 0, j = 0; i < f->rank; i++, j++)
1468 if (i == (idim - 1))
1470 mpz_init_set (f->shape[i], array->shape[j]);
1477 if (mask->rank == 0)
1482 resolve_mask_arg (mask);
1487 f->value.function.name
1488 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1489 gfc_type_letter (array->ts.type), array->ts.kind);
1494 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1496 f->ts.type = a->ts.type;
1498 f->ts.kind = gfc_kind_max (a,p);
1500 f->ts.kind = a->ts.kind;
1502 if (p != NULL && a->ts.kind != p->ts.kind)
1504 if (a->ts.kind == gfc_kind_max (a,p))
1505 gfc_convert_type (p, &a->ts, 2);
1507 gfc_convert_type (a, &p->ts, 2);
1510 f->value.function.name
1511 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1516 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1518 f->ts.type = a->ts.type;
1520 f->ts.kind = gfc_kind_max (a,p);
1522 f->ts.kind = a->ts.kind;
1524 if (p != NULL && a->ts.kind != p->ts.kind)
1526 if (a->ts.kind == gfc_kind_max (a,p))
1527 gfc_convert_type (p, &a->ts, 2);
1529 gfc_convert_type (a, &p->ts, 2);
1532 f->value.function.name
1533 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1538 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p ATTRIBUTE_UNUSED)
1541 f->value.function.name
1542 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1547 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1549 f->ts.type = BT_INTEGER;
1550 f->ts.kind = (kind == NULL)
1551 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1552 f->value.function.name
1553 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1558 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1561 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1566 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1568 f->ts.type = i->ts.type;
1569 f->ts.kind = gfc_kind_max (i, j);
1571 if (i->ts.kind != j->ts.kind)
1573 if (i->ts.kind == gfc_kind_max (i, j))
1574 gfc_convert_type (j, &i->ts, 2);
1576 gfc_convert_type (i, &j->ts, 2);
1579 f->value.function.name
1580 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1585 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1586 gfc_expr *vector ATTRIBUTE_UNUSED)
1591 resolve_mask_arg (mask);
1593 if (mask->rank != 0)
1594 f->value.function.name = (array->ts.type == BT_CHARACTER
1595 ? PREFIX ("pack_char") : PREFIX ("pack"));
1597 f->value.function.name = (array->ts.type == BT_CHARACTER
1598 ? PREFIX ("pack_s_char") : PREFIX ("pack_s"));
1603 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1612 f->rank = array->rank - 1;
1613 gfc_resolve_dim_arg (dim);
1618 if (mask->rank == 0)
1623 resolve_mask_arg (mask);
1628 f->value.function.name
1629 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1630 gfc_type_letter (array->ts.type), array->ts.kind);
1635 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1637 f->ts.type = BT_REAL;
1640 f->ts.kind = mpz_get_si (kind->value.integer);
1642 f->ts.kind = (a->ts.type == BT_COMPLEX)
1643 ? a->ts.kind : gfc_default_real_kind;
1645 f->value.function.name
1646 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1647 gfc_type_letter (a->ts.type), a->ts.kind);
1652 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1654 f->ts.type = BT_REAL;
1655 f->ts.kind = a->ts.kind;
1656 f->value.function.name
1657 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1658 gfc_type_letter (a->ts.type), a->ts.kind);
1663 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1664 gfc_expr *p2 ATTRIBUTE_UNUSED)
1666 f->ts.type = BT_INTEGER;
1667 f->ts.kind = gfc_default_integer_kind;
1668 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1673 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
1674 gfc_expr *ncopies ATTRIBUTE_UNUSED)
1676 f->ts.type = BT_CHARACTER;
1677 f->ts.kind = string->ts.kind;
1678 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
1683 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
1684 gfc_expr *pad ATTRIBUTE_UNUSED,
1685 gfc_expr *order ATTRIBUTE_UNUSED)
1693 gfc_array_size (shape, &rank);
1694 f->rank = mpz_get_si (rank);
1696 switch (source->ts.type)
1702 kind = source->ts.kind;
1716 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
1717 f->value.function.name
1718 = gfc_get_string (PREFIX ("reshape_%c%d"),
1719 gfc_type_letter (source->ts.type),
1722 f->value.function.name
1723 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
1728 f->value.function.name = (source->ts.type == BT_CHARACTER
1729 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1733 /* TODO: Make this work with a constant ORDER parameter. */
1734 if (shape->expr_type == EXPR_ARRAY
1735 && gfc_is_constant_expr (shape)
1739 f->shape = gfc_get_shape (f->rank);
1740 c = shape->value.constructor;
1741 for (i = 0; i < f->rank; i++)
1743 mpz_init_set (f->shape[i], c->expr->value.integer);
1748 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
1749 so many runtime variations. */
1750 if (shape->ts.kind != gfc_index_integer_kind)
1752 gfc_typespec ts = shape->ts;
1753 ts.kind = gfc_index_integer_kind;
1754 gfc_convert_type_warn (shape, &ts, 2, 0);
1756 if (order && order->ts.kind != gfc_index_integer_kind)
1757 gfc_convert_type_warn (order, &shape->ts, 2, 0);
1762 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
1765 gfc_actual_arglist *prec;
1768 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
1770 /* Create a hidden argument to the library routines for rrspacing. This
1771 hidden argument is the precision of x. */
1772 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1773 prec = gfc_get_actual_arglist ();
1775 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1776 /* The library routine expects INTEGER(4). */
1777 if (prec->expr->ts.kind != gfc_c_int_kind)
1780 ts.type = BT_INTEGER;
1781 ts.kind = gfc_c_int_kind;
1782 gfc_convert_type (prec->expr, &ts, 2);
1784 f->value.function.actual->next = prec;
1789 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1793 /* The implementation calls scalbn which takes an int as the
1795 if (i->ts.kind != gfc_c_int_kind)
1798 ts.type = BT_INTEGER;
1799 ts.kind = gfc_c_int_kind;
1800 gfc_convert_type_warn (i, &ts, 2, 0);
1803 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
1808 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
1809 gfc_expr *set ATTRIBUTE_UNUSED,
1810 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
1812 f->ts.type = BT_INTEGER;
1814 f->ts.kind = mpz_get_si (kind->value.integer);
1816 f->ts.kind = gfc_default_integer_kind;
1817 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
1822 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
1825 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
1830 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x, gfc_expr *i)
1834 /* The library implementation uses GFC_INTEGER_4 unconditionally,
1835 convert type so we don't have to implement all possible
1837 if (i->ts.kind != gfc_c_int_kind)
1840 ts.type = BT_INTEGER;
1841 ts.kind = gfc_c_int_kind;
1842 gfc_convert_type_warn (i, &ts, 2, 0);
1845 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
1850 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
1852 f->ts.type = BT_INTEGER;
1853 f->ts.kind = gfc_default_integer_kind;
1855 f->shape = gfc_get_shape (1);
1856 mpz_init_set_ui (f->shape[0], array->rank);
1857 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
1862 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
1865 f->value.function.name
1866 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
1871 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
1873 f->ts.type = BT_INTEGER;
1874 f->ts.kind = gfc_c_int_kind;
1876 /* handler can be either BT_INTEGER or BT_PROCEDURE */
1877 if (handler->ts.type == BT_INTEGER)
1879 if (handler->ts.kind != gfc_c_int_kind)
1880 gfc_convert_type (handler, &f->ts, 2);
1881 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
1884 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
1886 if (number->ts.kind != gfc_c_int_kind)
1887 gfc_convert_type (number, &f->ts, 2);
1892 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
1895 f->value.function.name
1896 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1901 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
1904 f->value.function.name
1905 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1910 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
1911 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
1913 f->ts.type = BT_INTEGER;
1915 f->ts.kind = mpz_get_si (kind->value.integer);
1917 f->ts.kind = gfc_default_integer_kind;
1922 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
1925 gfc_actual_arglist *prec, *tiny, *emin_1;
1928 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
1930 /* Create hidden arguments to the library routine for spacing. These
1931 hidden arguments are tiny(x), min_exponent - 1, and the precision
1934 k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
1936 tiny = gfc_get_actual_arglist ();
1937 tiny->name = "tiny";
1938 tiny->expr = gfc_get_expr ();
1939 tiny->expr->expr_type = EXPR_CONSTANT;
1940 tiny->expr->where = gfc_current_locus;
1941 tiny->expr->ts.type = x->ts.type;
1942 tiny->expr->ts.kind = x->ts.kind;
1943 mpfr_init (tiny->expr->value.real);
1944 mpfr_set (tiny->expr->value.real, gfc_real_kinds[k].tiny, GFC_RND_MODE);
1946 emin_1 = gfc_get_actual_arglist ();
1947 emin_1->name = "emin";
1948 emin_1->expr = gfc_int_expr (gfc_real_kinds[k].min_exponent - 1);
1950 /* The library routine expects INTEGER(4). */
1951 if (emin_1->expr->ts.kind != gfc_c_int_kind)
1954 ts.type = BT_INTEGER;
1955 ts.kind = gfc_c_int_kind;
1956 gfc_convert_type (emin_1->expr, &ts, 2);
1958 emin_1->next = tiny;
1960 prec = gfc_get_actual_arglist ();
1961 prec->name = "prec";
1962 prec->expr = gfc_int_expr (gfc_real_kinds[k].digits);
1964 /* The library routine expects INTEGER(4). */
1965 if (prec->expr->ts.kind != gfc_c_int_kind)
1968 ts.type = BT_INTEGER;
1969 ts.kind = gfc_c_int_kind;
1970 gfc_convert_type (prec->expr, &ts, 2);
1972 prec->next = emin_1;
1974 f->value.function.actual->next = prec;
1979 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
1982 if (source->ts.type == BT_CHARACTER)
1983 check_charlen_present (source);
1986 f->rank = source->rank + 1;
1987 if (source->rank == 0)
1988 f->value.function.name = (source->ts.type == BT_CHARACTER
1989 ? PREFIX ("spread_char_scalar")
1990 : PREFIX ("spread_scalar"));
1992 f->value.function.name = (source->ts.type == BT_CHARACTER
1993 ? PREFIX ("spread_char")
1994 : PREFIX ("spread"));
1996 if (dim && gfc_is_constant_expr (dim)
1997 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2000 idim = mpz_get_ui (dim->value.integer);
2001 f->shape = gfc_get_shape (f->rank);
2002 for (i = 0; i < (idim - 1); i++)
2003 mpz_init_set (f->shape[i], source->shape[i]);
2005 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2007 for (i = idim; i < f->rank ; i++)
2008 mpz_init_set (f->shape[i], source->shape[i-1]);
2012 gfc_resolve_dim_arg (dim);
2013 gfc_resolve_index (ncopies, 1);
2018 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2021 f->value.function.name
2022 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2026 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2029 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2030 gfc_expr *a ATTRIBUTE_UNUSED)
2032 f->ts.type = BT_INTEGER;
2033 f->ts.kind = gfc_default_integer_kind;
2034 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2039 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2040 gfc_expr *a ATTRIBUTE_UNUSED)
2042 f->ts.type = BT_INTEGER;
2043 f->ts.kind = gfc_default_integer_kind;
2044 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2049 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2051 f->ts.type = BT_INTEGER;
2052 f->ts.kind = gfc_default_integer_kind;
2053 if (n->ts.kind != f->ts.kind)
2054 gfc_convert_type (n, &f->ts, 2);
2056 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2061 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2065 f->ts.type = BT_INTEGER;
2066 f->ts.kind = gfc_c_int_kind;
2067 if (u->ts.kind != gfc_c_int_kind)
2069 ts.type = BT_INTEGER;
2070 ts.kind = gfc_c_int_kind;
2073 gfc_convert_type (u, &ts, 2);
2076 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2081 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2083 f->ts.type = BT_INTEGER;
2084 f->ts.kind = gfc_c_int_kind;
2085 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2090 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2094 f->ts.type = BT_INTEGER;
2095 f->ts.kind = gfc_c_int_kind;
2096 if (u->ts.kind != gfc_c_int_kind)
2098 ts.type = BT_INTEGER;
2099 ts.kind = gfc_c_int_kind;
2102 gfc_convert_type (u, &ts, 2);
2105 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2110 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2112 f->ts.type = BT_INTEGER;
2113 f->ts.kind = gfc_c_int_kind;
2114 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2119 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2123 f->ts.type = BT_INTEGER;
2124 f->ts.kind = gfc_index_integer_kind;
2125 if (u->ts.kind != gfc_c_int_kind)
2127 ts.type = BT_INTEGER;
2128 ts.kind = gfc_c_int_kind;
2131 gfc_convert_type (u, &ts, 2);
2134 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2139 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2147 if (mask->rank == 0)
2152 resolve_mask_arg (mask);
2159 f->rank = array->rank - 1;
2160 gfc_resolve_dim_arg (dim);
2163 f->value.function.name
2164 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2165 gfc_type_letter (array->ts.type), array->ts.kind);
2170 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2171 gfc_expr *p2 ATTRIBUTE_UNUSED)
2173 f->ts.type = BT_INTEGER;
2174 f->ts.kind = gfc_default_integer_kind;
2175 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2179 /* Resolve the g77 compatibility function SYSTEM. */
2182 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2184 f->ts.type = BT_INTEGER;
2186 f->value.function.name = gfc_get_string (PREFIX ("system"));
2191 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2194 f->value.function.name
2195 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2200 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2203 f->value.function.name
2204 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2209 gfc_resolve_time (gfc_expr *f)
2211 f->ts.type = BT_INTEGER;
2213 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2218 gfc_resolve_time8 (gfc_expr *f)
2220 f->ts.type = BT_INTEGER;
2222 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2227 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2228 gfc_expr *mold, gfc_expr *size)
2230 /* TODO: Make this do something meaningful. */
2231 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2235 if (size == NULL && mold->rank == 0)
2238 f->value.function.name = transfer0;
2243 f->value.function.name = transfer1;
2244 if (size && gfc_is_constant_expr (size))
2246 f->shape = gfc_get_shape (1);
2247 mpz_init_set (f->shape[0], size->value.integer);
2254 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2260 f->shape = gfc_get_shape (2);
2261 mpz_init_set (f->shape[0], matrix->shape[1]);
2262 mpz_init_set (f->shape[1], matrix->shape[0]);
2265 switch (matrix->ts.kind)
2271 switch (matrix->ts.type)
2275 f->value.function.name
2276 = gfc_get_string (PREFIX ("transpose_%c%d"),
2277 gfc_type_letter (matrix->ts.type),
2283 /* Use the integer routines for real and logical cases. This
2284 assumes they all have the same alignment requirements. */
2285 f->value.function.name
2286 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2290 f->value.function.name = PREFIX ("transpose");
2296 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2297 ? PREFIX ("transpose_char")
2298 : PREFIX ("transpose"));
2305 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2307 f->ts.type = BT_CHARACTER;
2308 f->ts.kind = string->ts.kind;
2309 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2314 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2316 static char ubound[] = "__ubound";
2318 f->ts.type = BT_INTEGER;
2320 f->ts.kind = mpz_get_si (kind->value.integer);
2322 f->ts.kind = gfc_default_integer_kind;
2327 f->shape = gfc_get_shape (1);
2328 mpz_init_set_ui (f->shape[0], array->rank);
2331 f->value.function.name = ubound;
2335 /* Resolve the g77 compatibility function UMASK. */
2338 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2340 f->ts.type = BT_INTEGER;
2341 f->ts.kind = n->ts.kind;
2342 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2346 /* Resolve the g77 compatibility function UNLINK. */
2349 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2351 f->ts.type = BT_INTEGER;
2353 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2358 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2362 f->ts.type = BT_CHARACTER;
2363 f->ts.kind = gfc_default_character_kind;
2365 if (unit->ts.kind != gfc_c_int_kind)
2367 ts.type = BT_INTEGER;
2368 ts.kind = gfc_c_int_kind;
2371 gfc_convert_type (unit, &ts, 2);
2374 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2379 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2380 gfc_expr *field ATTRIBUTE_UNUSED)
2383 f->rank = mask->rank;
2384 resolve_mask_arg (mask);
2386 f->value.function.name
2387 = gfc_get_string (PREFIX ("unpack%d%s"), field->rank > 0 ? 1 : 0,
2388 vector->ts.type == BT_CHARACTER ? "_char" : "");
2393 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2394 gfc_expr *set ATTRIBUTE_UNUSED,
2395 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2397 f->ts.type = BT_INTEGER;
2399 f->ts.kind = mpz_get_si (kind->value.integer);
2401 f->ts.kind = gfc_default_integer_kind;
2402 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2407 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2409 f->ts.type = i->ts.type;
2410 f->ts.kind = gfc_kind_max (i, j);
2412 if (i->ts.kind != j->ts.kind)
2414 if (i->ts.kind == gfc_kind_max (i, j))
2415 gfc_convert_type (j, &i->ts, 2);
2417 gfc_convert_type (i, &j->ts, 2);
2420 f->value.function.name
2421 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2425 /* Intrinsic subroutine resolution. */
2428 gfc_resolve_alarm_sub (gfc_code *c)
2431 gfc_expr *seconds, *handler, *status;
2434 seconds = c->ext.actual->expr;
2435 handler = c->ext.actual->next->expr;
2436 status = c->ext.actual->next->next->expr;
2437 ts.type = BT_INTEGER;
2438 ts.kind = gfc_c_int_kind;
2440 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2441 In all cases, the status argument is of default integer kind
2442 (enforced in check.c) so that the function suffix is fixed. */
2443 if (handler->ts.type == BT_INTEGER)
2445 if (handler->ts.kind != gfc_c_int_kind)
2446 gfc_convert_type (handler, &ts, 2);
2447 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2448 gfc_default_integer_kind);
2451 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2452 gfc_default_integer_kind);
2454 if (seconds->ts.kind != gfc_c_int_kind)
2455 gfc_convert_type (seconds, &ts, 2);
2457 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2461 gfc_resolve_cpu_time (gfc_code *c)
2464 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2465 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2470 gfc_resolve_mvbits (gfc_code *c)
2475 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2476 they will be converted so that they fit into a C int. */
2477 ts.type = BT_INTEGER;
2478 ts.kind = gfc_c_int_kind;
2479 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2480 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2481 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2482 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2483 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2484 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2486 /* TO and FROM are guaranteed to have the same kind parameter. */
2487 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2488 c->ext.actual->expr->ts.kind);
2489 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2494 gfc_resolve_random_number (gfc_code *c)
2499 kind = c->ext.actual->expr->ts.kind;
2500 if (c->ext.actual->expr->rank == 0)
2501 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2503 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2505 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2510 gfc_resolve_rename_sub (gfc_code *c)
2515 if (c->ext.actual->next->next->expr != NULL)
2516 kind = c->ext.actual->next->next->expr->ts.kind;
2518 kind = gfc_default_integer_kind;
2520 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2521 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2526 gfc_resolve_kill_sub (gfc_code *c)
2531 if (c->ext.actual->next->next->expr != NULL)
2532 kind = c->ext.actual->next->next->expr->ts.kind;
2534 kind = gfc_default_integer_kind;
2536 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2537 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2542 gfc_resolve_link_sub (gfc_code *c)
2547 if (c->ext.actual->next->next->expr != NULL)
2548 kind = c->ext.actual->next->next->expr->ts.kind;
2550 kind = gfc_default_integer_kind;
2552 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2553 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2558 gfc_resolve_symlnk_sub (gfc_code *c)
2563 if (c->ext.actual->next->next->expr != NULL)
2564 kind = c->ext.actual->next->next->expr->ts.kind;
2566 kind = gfc_default_integer_kind;
2568 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2569 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2573 /* G77 compatibility subroutines etime() and dtime(). */
2576 gfc_resolve_etime_sub (gfc_code *c)
2579 name = gfc_get_string (PREFIX ("etime_sub"));
2580 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2584 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2587 gfc_resolve_itime (gfc_code *c)
2590 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2591 gfc_default_integer_kind));
2595 gfc_resolve_idate (gfc_code *c)
2598 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2599 gfc_default_integer_kind));
2603 gfc_resolve_ltime (gfc_code *c)
2606 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2607 gfc_default_integer_kind));
2611 gfc_resolve_gmtime (gfc_code *c)
2614 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2615 gfc_default_integer_kind));
2619 /* G77 compatibility subroutine second(). */
2622 gfc_resolve_second_sub (gfc_code *c)
2625 name = gfc_get_string (PREFIX ("second_sub"));
2626 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2631 gfc_resolve_sleep_sub (gfc_code *c)
2636 if (c->ext.actual->expr != NULL)
2637 kind = c->ext.actual->expr->ts.kind;
2639 kind = gfc_default_integer_kind;
2641 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
2642 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2646 /* G77 compatibility function srand(). */
2649 gfc_resolve_srand (gfc_code *c)
2652 name = gfc_get_string (PREFIX ("srand"));
2653 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2657 /* Resolve the getarg intrinsic subroutine. */
2660 gfc_resolve_getarg (gfc_code *c)
2664 kind = gfc_default_integer_kind;
2665 name = gfc_get_string (PREFIX ("getarg_i%d"), kind);
2666 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2670 /* Resolve the getcwd intrinsic subroutine. */
2673 gfc_resolve_getcwd_sub (gfc_code *c)
2678 if (c->ext.actual->next->expr != NULL)
2679 kind = c->ext.actual->next->expr->ts.kind;
2681 kind = gfc_default_integer_kind;
2683 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
2684 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2688 /* Resolve the get_command intrinsic subroutine. */
2691 gfc_resolve_get_command (gfc_code *c)
2695 kind = gfc_default_integer_kind;
2696 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
2697 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2701 /* Resolve the get_command_argument intrinsic subroutine. */
2704 gfc_resolve_get_command_argument (gfc_code *c)
2708 kind = gfc_default_integer_kind;
2709 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
2710 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2714 /* Resolve the get_environment_variable intrinsic subroutine. */
2717 gfc_resolve_get_environment_variable (gfc_code *code)
2721 kind = gfc_default_integer_kind;
2722 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
2723 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2728 gfc_resolve_signal_sub (gfc_code *c)
2731 gfc_expr *number, *handler, *status;
2734 number = c->ext.actual->expr;
2735 handler = c->ext.actual->next->expr;
2736 status = c->ext.actual->next->next->expr;
2737 ts.type = BT_INTEGER;
2738 ts.kind = gfc_c_int_kind;
2740 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2741 if (handler->ts.type == BT_INTEGER)
2743 if (handler->ts.kind != gfc_c_int_kind)
2744 gfc_convert_type (handler, &ts, 2);
2745 name = gfc_get_string (PREFIX ("signal_sub_int"));
2748 name = gfc_get_string (PREFIX ("signal_sub"));
2750 if (number->ts.kind != gfc_c_int_kind)
2751 gfc_convert_type (number, &ts, 2);
2752 if (status != NULL && status->ts.kind != gfc_c_int_kind)
2753 gfc_convert_type (status, &ts, 2);
2755 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2759 /* Resolve the SYSTEM intrinsic subroutine. */
2762 gfc_resolve_system_sub (gfc_code *c)
2765 name = gfc_get_string (PREFIX ("system_sub"));
2766 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2770 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2773 gfc_resolve_system_clock (gfc_code *c)
2778 if (c->ext.actual->expr != NULL)
2779 kind = c->ext.actual->expr->ts.kind;
2780 else if (c->ext.actual->next->expr != NULL)
2781 kind = c->ext.actual->next->expr->ts.kind;
2782 else if (c->ext.actual->next->next->expr != NULL)
2783 kind = c->ext.actual->next->next->expr->ts.kind;
2785 kind = gfc_default_integer_kind;
2787 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
2788 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2792 /* Resolve the EXIT intrinsic subroutine. */
2795 gfc_resolve_exit (gfc_code *c)
2801 /* The STATUS argument has to be of default kind. If it is not,
2803 ts.type = BT_INTEGER;
2804 ts.kind = gfc_default_integer_kind;
2805 n = c->ext.actual->expr;
2806 if (n != NULL && n->ts.kind != ts.kind)
2807 gfc_convert_type (n, &ts, 2);
2809 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
2810 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2814 /* Resolve the FLUSH intrinsic subroutine. */
2817 gfc_resolve_flush (gfc_code *c)
2823 ts.type = BT_INTEGER;
2824 ts.kind = gfc_default_integer_kind;
2825 n = c->ext.actual->expr;
2826 if (n != NULL && n->ts.kind != ts.kind)
2827 gfc_convert_type (n, &ts, 2);
2829 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
2830 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2835 gfc_resolve_free (gfc_code *c)
2840 ts.type = BT_INTEGER;
2841 ts.kind = gfc_index_integer_kind;
2842 n = c->ext.actual->expr;
2843 if (n->ts.kind != ts.kind)
2844 gfc_convert_type (n, &ts, 2);
2846 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
2851 gfc_resolve_ctime_sub (gfc_code *c)
2855 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
2856 if (c->ext.actual->expr->ts.kind != 8)
2858 ts.type = BT_INTEGER;
2862 gfc_convert_type (c->ext.actual->expr, &ts, 2);
2865 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
2870 gfc_resolve_fdate_sub (gfc_code *c)
2872 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
2877 gfc_resolve_gerror (gfc_code *c)
2879 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
2884 gfc_resolve_getlog (gfc_code *c)
2886 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
2891 gfc_resolve_hostnm_sub (gfc_code *c)
2896 if (c->ext.actual->next->expr != NULL)
2897 kind = c->ext.actual->next->expr->ts.kind;
2899 kind = gfc_default_integer_kind;
2901 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
2902 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2907 gfc_resolve_perror (gfc_code *c)
2909 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
2912 /* Resolve the STAT and FSTAT intrinsic subroutines. */
2915 gfc_resolve_stat_sub (gfc_code *c)
2918 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
2919 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2924 gfc_resolve_lstat_sub (gfc_code *c)
2927 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
2928 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2933 gfc_resolve_fstat_sub (gfc_code *c)
2939 u = c->ext.actual->expr;
2940 ts = &c->ext.actual->next->expr->ts;
2941 if (u->ts.kind != ts->kind)
2942 gfc_convert_type (u, ts, 2);
2943 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
2944 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2949 gfc_resolve_fgetc_sub (gfc_code *c)
2955 u = c->ext.actual->expr;
2956 st = c->ext.actual->next->next->expr;
2958 if (u->ts.kind != gfc_c_int_kind)
2960 ts.type = BT_INTEGER;
2961 ts.kind = gfc_c_int_kind;
2964 gfc_convert_type (u, &ts, 2);
2968 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
2970 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
2972 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2977 gfc_resolve_fget_sub (gfc_code *c)
2982 st = c->ext.actual->next->expr;
2984 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
2986 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
2988 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2993 gfc_resolve_fputc_sub (gfc_code *c)
2999 u = c->ext.actual->expr;
3000 st = c->ext.actual->next->next->expr;
3002 if (u->ts.kind != gfc_c_int_kind)
3004 ts.type = BT_INTEGER;
3005 ts.kind = gfc_c_int_kind;
3008 gfc_convert_type (u, &ts, 2);
3012 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3014 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3016 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3021 gfc_resolve_fput_sub (gfc_code *c)
3026 st = c->ext.actual->next->expr;
3028 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3030 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3032 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3037 gfc_resolve_fseek_sub (gfc_code *c)
3045 unit = c->ext.actual->expr;
3046 offset = c->ext.actual->next->expr;
3047 whence = c->ext.actual->next->next->expr;
3048 status = c->ext.actual->next->next->next->expr;
3050 if (unit->ts.kind != gfc_c_int_kind)
3052 ts.type = BT_INTEGER;
3053 ts.kind = gfc_c_int_kind;
3056 gfc_convert_type (unit, &ts, 2);
3059 if (offset->ts.kind != gfc_intio_kind)
3061 ts.type = BT_INTEGER;
3062 ts.kind = gfc_intio_kind;
3065 gfc_convert_type (offset, &ts, 2);
3068 if (whence->ts.kind != gfc_c_int_kind)
3070 ts.type = BT_INTEGER;
3071 ts.kind = gfc_c_int_kind;
3074 gfc_convert_type (whence, &ts, 2);
3077 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3081 gfc_resolve_ftell_sub (gfc_code *c)
3088 unit = c->ext.actual->expr;
3089 offset = c->ext.actual->next->expr;
3091 if (unit->ts.kind != gfc_c_int_kind)
3093 ts.type = BT_INTEGER;
3094 ts.kind = gfc_c_int_kind;
3097 gfc_convert_type (unit, &ts, 2);
3100 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3101 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3106 gfc_resolve_ttynam_sub (gfc_code *c)
3110 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3112 ts.type = BT_INTEGER;
3113 ts.kind = gfc_c_int_kind;
3116 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3119 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3123 /* Resolve the UMASK intrinsic subroutine. */
3126 gfc_resolve_umask_sub (gfc_code *c)
3131 if (c->ext.actual->next->expr != NULL)
3132 kind = c->ext.actual->next->expr->ts.kind;
3134 kind = gfc_default_integer_kind;
3136 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3137 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3140 /* Resolve the UNLINK intrinsic subroutine. */
3143 gfc_resolve_unlink_sub (gfc_code *c)
3148 if (c->ext.actual->next->expr != NULL)
3149 kind = c->ext.actual->next->expr->ts.kind;
3151 kind = gfc_default_integer_kind;
3153 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3154 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);