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
)
1564 /* The mask can be kind 4 or 8 for the array case. For the scalar
1565 case, coerce it to kind=4 unconditionally (because this is the only
1566 kind we have a library function for). */
1569 if (mask
->rank
== 0)
1571 if (mask
->ts
.kind
!= 4)
1576 if (mask
->ts
.kind
< 4)
1577 newkind
= gfc_default_logical_kind
;
1584 ts
.type
= BT_LOGICAL
;
1585 ts
.kind
= gfc_default_logical_kind
;
1586 gfc_convert_type (mask
, &ts
, 2);
1589 if (mask
->rank
!= 0)
1590 f
->value
.function
.name
= (array
->ts
.type
== BT_CHARACTER
1591 ? PREFIX ("pack_char") : PREFIX ("pack"));
1593 f
->value
.function
.name
= (array
->ts
.type
== BT_CHARACTER
1594 ? PREFIX ("pack_s_char") : PREFIX ("pack_s"));
1599 gfc_resolve_product (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
1608 f
->rank
= array
->rank
- 1;
1609 gfc_resolve_dim_arg (dim
);
1614 if (mask
->rank
== 0)
1619 /* The mask can be kind 4 or 8 for the array case. For the
1620 scalar case, coerce it to default kind unconditionally. */
1621 if ((mask
->ts
.kind
< gfc_default_logical_kind
)
1622 || (mask
->rank
== 0 && mask
->ts
.kind
!= gfc_default_logical_kind
))
1625 ts
.type
= BT_LOGICAL
;
1626 ts
.kind
= gfc_default_logical_kind
;
1627 gfc_convert_type_warn (mask
, &ts
, 2, 0);
1633 f
->value
.function
.name
1634 = gfc_get_string (PREFIX ("%s_%c%d"), name
,
1635 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
1640 gfc_resolve_real (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
1642 f
->ts
.type
= BT_REAL
;
1645 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1647 f
->ts
.kind
= (a
->ts
.type
== BT_COMPLEX
)
1648 ? a
->ts
.kind
: gfc_default_real_kind
;
1650 f
->value
.function
.name
1651 = gfc_get_string ("__real_%d_%c%d", f
->ts
.kind
,
1652 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1657 gfc_resolve_realpart (gfc_expr
*f
, gfc_expr
*a
)
1659 f
->ts
.type
= BT_REAL
;
1660 f
->ts
.kind
= a
->ts
.kind
;
1661 f
->value
.function
.name
1662 = gfc_get_string ("__real_%d_%c%d", f
->ts
.kind
,
1663 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1668 gfc_resolve_rename (gfc_expr
*f
, gfc_expr
*p1 ATTRIBUTE_UNUSED
,
1669 gfc_expr
*p2 ATTRIBUTE_UNUSED
)
1671 f
->ts
.type
= BT_INTEGER
;
1672 f
->ts
.kind
= gfc_default_integer_kind
;
1673 f
->value
.function
.name
= gfc_get_string (PREFIX ("rename_i%d"), f
->ts
.kind
);
1678 gfc_resolve_repeat (gfc_expr
*f
, gfc_expr
*string
,
1679 gfc_expr
*ncopies ATTRIBUTE_UNUSED
)
1681 f
->ts
.type
= BT_CHARACTER
;
1682 f
->ts
.kind
= string
->ts
.kind
;
1683 f
->value
.function
.name
= gfc_get_string ("__repeat_%d", string
->ts
.kind
);
1688 gfc_resolve_reshape (gfc_expr
*f
, gfc_expr
*source
, gfc_expr
*shape
,
1689 gfc_expr
*pad ATTRIBUTE_UNUSED
,
1690 gfc_expr
*order ATTRIBUTE_UNUSED
)
1698 gfc_array_size (shape
, &rank
);
1699 f
->rank
= mpz_get_si (rank
);
1701 switch (source
->ts
.type
)
1707 kind
= source
->ts
.kind
;
1721 if (source
->ts
.type
== BT_COMPLEX
|| source
->ts
.type
== BT_REAL
)
1722 f
->value
.function
.name
1723 = gfc_get_string (PREFIX ("reshape_%c%d"),
1724 gfc_type_letter (source
->ts
.type
),
1727 f
->value
.function
.name
1728 = gfc_get_string (PREFIX ("reshape_%d"), source
->ts
.kind
);
1733 f
->value
.function
.name
= (source
->ts
.type
== BT_CHARACTER
1734 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
1738 /* TODO: Make this work with a constant ORDER parameter. */
1739 if (shape
->expr_type
== EXPR_ARRAY
1740 && gfc_is_constant_expr (shape
)
1744 f
->shape
= gfc_get_shape (f
->rank
);
1745 c
= shape
->value
.constructor
;
1746 for (i
= 0; i
< f
->rank
; i
++)
1748 mpz_init_set (f
->shape
[i
], c
->expr
->value
.integer
);
1753 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
1754 so many runtime variations. */
1755 if (shape
->ts
.kind
!= gfc_index_integer_kind
)
1757 gfc_typespec ts
= shape
->ts
;
1758 ts
.kind
= gfc_index_integer_kind
;
1759 gfc_convert_type_warn (shape
, &ts
, 2, 0);
1761 if (order
&& order
->ts
.kind
!= gfc_index_integer_kind
)
1762 gfc_convert_type_warn (order
, &shape
->ts
, 2, 0);
1767 gfc_resolve_rrspacing (gfc_expr
*f
, gfc_expr
*x
)
1770 gfc_actual_arglist
*prec
;
1773 f
->value
.function
.name
= gfc_get_string ("__rrspacing_%d", x
->ts
.kind
);
1775 /* Create a hidden argument to the library routines for rrspacing. This
1776 hidden argument is the precision of x. */
1777 k
= gfc_validate_kind (BT_REAL
, x
->ts
.kind
, false);
1778 prec
= gfc_get_actual_arglist ();
1780 prec
->expr
= gfc_int_expr (gfc_real_kinds
[k
].digits
);
1781 f
->value
.function
.actual
->next
= prec
;
1786 gfc_resolve_scale (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*i
)
1790 /* The implementation calls scalbn which takes an int as the
1792 if (i
->ts
.kind
!= gfc_c_int_kind
)
1795 ts
.type
= BT_INTEGER
;
1796 ts
.kind
= gfc_default_integer_kind
;
1797 gfc_convert_type_warn (i
, &ts
, 2, 0);
1800 f
->value
.function
.name
= gfc_get_string ("__scale_%d", x
->ts
.kind
);
1805 gfc_resolve_scan (gfc_expr
*f
, gfc_expr
*string
,
1806 gfc_expr
*set ATTRIBUTE_UNUSED
,
1807 gfc_expr
*back ATTRIBUTE_UNUSED
)
1809 f
->ts
.type
= BT_INTEGER
;
1810 f
->ts
.kind
= gfc_default_integer_kind
;
1811 f
->value
.function
.name
= gfc_get_string ("__scan_%d", string
->ts
.kind
);
1816 gfc_resolve_secnds (gfc_expr
*t1
, gfc_expr
*t0
)
1819 t1
->value
.function
.name
= gfc_get_string (PREFIX ("secnds"));
1824 gfc_resolve_set_exponent (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*i
)
1828 /* The library implementation uses GFC_INTEGER_4 unconditionally,
1829 convert type so we don't have to implement all possible
1831 if (i
->ts
.kind
!= 4)
1834 ts
.type
= BT_INTEGER
;
1835 ts
.kind
= gfc_default_integer_kind
;
1836 gfc_convert_type_warn (i
, &ts
, 2, 0);
1839 f
->value
.function
.name
= gfc_get_string ("__set_exponent_%d", x
->ts
.kind
);
1844 gfc_resolve_shape (gfc_expr
*f
, gfc_expr
*array
)
1846 f
->ts
.type
= BT_INTEGER
;
1847 f
->ts
.kind
= gfc_default_integer_kind
;
1849 f
->shape
= gfc_get_shape (1);
1850 mpz_init_set_ui (f
->shape
[0], array
->rank
);
1851 f
->value
.function
.name
= gfc_get_string (PREFIX ("shape_%d"), f
->ts
.kind
);
1856 gfc_resolve_sign (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*b ATTRIBUTE_UNUSED
)
1859 f
->value
.function
.name
1860 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1865 gfc_resolve_signal (gfc_expr
*f
, gfc_expr
*number
, gfc_expr
*handler
)
1867 f
->ts
.type
= BT_INTEGER
;
1868 f
->ts
.kind
= gfc_c_int_kind
;
1870 /* handler can be either BT_INTEGER or BT_PROCEDURE */
1871 if (handler
->ts
.type
== BT_INTEGER
)
1873 if (handler
->ts
.kind
!= gfc_c_int_kind
)
1874 gfc_convert_type (handler
, &f
->ts
, 2);
1875 f
->value
.function
.name
= gfc_get_string (PREFIX ("signal_func_int"));
1878 f
->value
.function
.name
= gfc_get_string (PREFIX ("signal_func"));
1880 if (number
->ts
.kind
!= gfc_c_int_kind
)
1881 gfc_convert_type (number
, &f
->ts
, 2);
1886 gfc_resolve_sin (gfc_expr
*f
, gfc_expr
*x
)
1889 f
->value
.function
.name
1890 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
1895 gfc_resolve_sinh (gfc_expr
*f
, gfc_expr
*x
)
1898 f
->value
.function
.name
1899 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
1904 gfc_resolve_spacing (gfc_expr
*f
, gfc_expr
*x
)
1907 gfc_actual_arglist
*prec
, *tiny
, *emin_1
;
1910 f
->value
.function
.name
= gfc_get_string ("__spacing_%d", x
->ts
.kind
);
1912 /* Create hidden arguments to the library routine for spacing. These
1913 hidden arguments are tiny(x), min_exponent - 1, and the precision
1916 k
= gfc_validate_kind (BT_REAL
, x
->ts
.kind
, false);
1918 tiny
= gfc_get_actual_arglist ();
1919 tiny
->name
= "tiny";
1920 tiny
->expr
= gfc_get_expr ();
1921 tiny
->expr
->expr_type
= EXPR_CONSTANT
;
1922 tiny
->expr
->where
= gfc_current_locus
;
1923 tiny
->expr
->ts
.type
= x
->ts
.type
;
1924 tiny
->expr
->ts
.kind
= x
->ts
.kind
;
1925 mpfr_init (tiny
->expr
->value
.real
);
1926 mpfr_set (tiny
->expr
->value
.real
, gfc_real_kinds
[k
].tiny
, GFC_RND_MODE
);
1928 emin_1
= gfc_get_actual_arglist ();
1929 emin_1
->name
= "emin";
1930 emin_1
->expr
= gfc_int_expr (gfc_real_kinds
[k
].min_exponent
- 1);
1931 emin_1
->next
= tiny
;
1933 prec
= gfc_get_actual_arglist ();
1934 prec
->name
= "prec";
1935 prec
->expr
= gfc_int_expr (gfc_real_kinds
[k
].digits
);
1936 prec
->next
= emin_1
;
1938 f
->value
.function
.actual
->next
= prec
;
1943 gfc_resolve_spread (gfc_expr
*f
, gfc_expr
*source
, gfc_expr
*dim
,
1946 if (source
->ts
.type
== BT_CHARACTER
)
1947 check_charlen_present (source
);
1950 f
->rank
= source
->rank
+ 1;
1951 if (source
->rank
== 0)
1952 f
->value
.function
.name
= (source
->ts
.type
== BT_CHARACTER
1953 ? PREFIX ("spread_char_scalar")
1954 : PREFIX ("spread_scalar"));
1956 f
->value
.function
.name
= (source
->ts
.type
== BT_CHARACTER
1957 ? PREFIX ("spread_char")
1958 : PREFIX ("spread"));
1960 if (dim
&& gfc_is_constant_expr (dim
)
1961 && ncopies
&& gfc_is_constant_expr (ncopies
) && source
->shape
[0])
1964 idim
= mpz_get_ui (dim
->value
.integer
);
1965 f
->shape
= gfc_get_shape (f
->rank
);
1966 for (i
= 0; i
< (idim
- 1); i
++)
1967 mpz_init_set (f
->shape
[i
], source
->shape
[i
]);
1969 mpz_init_set (f
->shape
[idim
- 1], ncopies
->value
.integer
);
1971 for (i
= idim
; i
< f
->rank
; i
++)
1972 mpz_init_set (f
->shape
[i
], source
->shape
[i
-1]);
1976 gfc_resolve_dim_arg (dim
);
1977 gfc_resolve_index (ncopies
, 1);
1982 gfc_resolve_sqrt (gfc_expr
*f
, gfc_expr
*x
)
1985 f
->value
.function
.name
1986 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
1990 /* Resolve the g77 compatibility function STAT AND FSTAT. */
1993 gfc_resolve_stat (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
,
1994 gfc_expr
*a ATTRIBUTE_UNUSED
)
1996 f
->ts
.type
= BT_INTEGER
;
1997 f
->ts
.kind
= gfc_default_integer_kind
;
1998 f
->value
.function
.name
= gfc_get_string (PREFIX ("stat_i%d"), f
->ts
.kind
);
2003 gfc_resolve_lstat (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
,
2004 gfc_expr
*a ATTRIBUTE_UNUSED
)
2006 f
->ts
.type
= BT_INTEGER
;
2007 f
->ts
.kind
= gfc_default_integer_kind
;
2008 f
->value
.function
.name
= gfc_get_string (PREFIX ("lstat_i%d"), f
->ts
.kind
);
2013 gfc_resolve_fstat (gfc_expr
*f
, gfc_expr
*n
, gfc_expr
*a ATTRIBUTE_UNUSED
)
2015 f
->ts
.type
= BT_INTEGER
;
2016 f
->ts
.kind
= gfc_default_integer_kind
;
2017 if (n
->ts
.kind
!= f
->ts
.kind
)
2018 gfc_convert_type (n
, &f
->ts
, 2);
2020 f
->value
.function
.name
= gfc_get_string (PREFIX ("fstat_i%d"), f
->ts
.kind
);
2025 gfc_resolve_fgetc (gfc_expr
*f
, gfc_expr
*u
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2029 f
->ts
.type
= BT_INTEGER
;
2030 f
->ts
.kind
= gfc_c_int_kind
;
2031 if (u
->ts
.kind
!= gfc_c_int_kind
)
2033 ts
.type
= BT_INTEGER
;
2034 ts
.kind
= gfc_c_int_kind
;
2037 gfc_convert_type (u
, &ts
, 2);
2040 f
->value
.function
.name
= gfc_get_string (PREFIX ("fgetc"));
2045 gfc_resolve_fget (gfc_expr
*f
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2047 f
->ts
.type
= BT_INTEGER
;
2048 f
->ts
.kind
= gfc_c_int_kind
;
2049 f
->value
.function
.name
= gfc_get_string (PREFIX ("fget"));
2054 gfc_resolve_fputc (gfc_expr
*f
, gfc_expr
*u
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2058 f
->ts
.type
= BT_INTEGER
;
2059 f
->ts
.kind
= gfc_c_int_kind
;
2060 if (u
->ts
.kind
!= gfc_c_int_kind
)
2062 ts
.type
= BT_INTEGER
;
2063 ts
.kind
= gfc_c_int_kind
;
2066 gfc_convert_type (u
, &ts
, 2);
2069 f
->value
.function
.name
= gfc_get_string (PREFIX ("fputc"));
2074 gfc_resolve_fput (gfc_expr
*f
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2076 f
->ts
.type
= BT_INTEGER
;
2077 f
->ts
.kind
= gfc_c_int_kind
;
2078 f
->value
.function
.name
= gfc_get_string (PREFIX ("fput"));
2083 gfc_resolve_ftell (gfc_expr
*f
, gfc_expr
*u
)
2087 f
->ts
.type
= BT_INTEGER
;
2088 f
->ts
.kind
= gfc_index_integer_kind
;
2089 if (u
->ts
.kind
!= gfc_c_int_kind
)
2091 ts
.type
= BT_INTEGER
;
2092 ts
.kind
= gfc_c_int_kind
;
2095 gfc_convert_type (u
, &ts
, 2);
2098 f
->value
.function
.name
= gfc_get_string (PREFIX ("ftell"));
2103 gfc_resolve_sum (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*mask
)
2111 if (mask
->rank
== 0)
2116 /* The mask can be kind 4 or 8 for the array case. For the
2117 scalar case, coerce it to default kind unconditionally. */
2118 if ((mask
->ts
.kind
< gfc_default_logical_kind
)
2119 || (mask
->rank
== 0 && mask
->ts
.kind
!= gfc_default_logical_kind
))
2122 ts
.type
= BT_LOGICAL
;
2123 ts
.kind
= gfc_default_logical_kind
;
2124 gfc_convert_type_warn (mask
, &ts
, 2, 0);
2132 f
->rank
= array
->rank
- 1;
2133 gfc_resolve_dim_arg (dim
);
2136 f
->value
.function
.name
2137 = gfc_get_string (PREFIX ("%s_%c%d"), name
,
2138 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
2143 gfc_resolve_symlnk (gfc_expr
*f
, gfc_expr
*p1 ATTRIBUTE_UNUSED
,
2144 gfc_expr
*p2 ATTRIBUTE_UNUSED
)
2146 f
->ts
.type
= BT_INTEGER
;
2147 f
->ts
.kind
= gfc_default_integer_kind
;
2148 f
->value
.function
.name
= gfc_get_string (PREFIX ("symlnk_i%d"), f
->ts
.kind
);
2152 /* Resolve the g77 compatibility function SYSTEM. */
2155 gfc_resolve_system (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
)
2157 f
->ts
.type
= BT_INTEGER
;
2159 f
->value
.function
.name
= gfc_get_string (PREFIX ("system"));
2164 gfc_resolve_tan (gfc_expr
*f
, gfc_expr
*x
)
2167 f
->value
.function
.name
2168 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2173 gfc_resolve_tanh (gfc_expr
*f
, gfc_expr
*x
)
2176 f
->value
.function
.name
2177 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2182 gfc_resolve_time (gfc_expr
*f
)
2184 f
->ts
.type
= BT_INTEGER
;
2186 f
->value
.function
.name
= gfc_get_string (PREFIX ("time_func"));
2191 gfc_resolve_time8 (gfc_expr
*f
)
2193 f
->ts
.type
= BT_INTEGER
;
2195 f
->value
.function
.name
= gfc_get_string (PREFIX ("time8_func"));
2200 gfc_resolve_transfer (gfc_expr
*f
, gfc_expr
*source ATTRIBUTE_UNUSED
,
2201 gfc_expr
*mold
, gfc_expr
*size
)
2203 /* TODO: Make this do something meaningful. */
2204 static char transfer0
[] = "__transfer0", transfer1
[] = "__transfer1";
2208 if (size
== NULL
&& mold
->rank
== 0)
2211 f
->value
.function
.name
= transfer0
;
2216 f
->value
.function
.name
= transfer1
;
2217 if (size
&& gfc_is_constant_expr (size
))
2219 f
->shape
= gfc_get_shape (1);
2220 mpz_init_set (f
->shape
[0], size
->value
.integer
);
2227 gfc_resolve_transpose (gfc_expr
*f
, gfc_expr
*matrix
)
2233 f
->shape
= gfc_get_shape (2);
2234 mpz_init_set (f
->shape
[0], matrix
->shape
[1]);
2235 mpz_init_set (f
->shape
[1], matrix
->shape
[0]);
2238 switch (matrix
->ts
.kind
)
2244 switch (matrix
->ts
.type
)
2248 f
->value
.function
.name
2249 = gfc_get_string (PREFIX ("transpose_%c%d"),
2250 gfc_type_letter (matrix
->ts
.type
),
2256 /* Use the integer routines for real and logical cases. This
2257 assumes they all have the same alignment requirements. */
2258 f
->value
.function
.name
2259 = gfc_get_string (PREFIX ("transpose_i%d"), matrix
->ts
.kind
);
2263 f
->value
.function
.name
= PREFIX ("transpose");
2269 f
->value
.function
.name
= (matrix
->ts
.type
== BT_CHARACTER
2270 ? PREFIX ("transpose_char")
2271 : PREFIX ("transpose"));
2278 gfc_resolve_trim (gfc_expr
*f
, gfc_expr
*string
)
2280 f
->ts
.type
= BT_CHARACTER
;
2281 f
->ts
.kind
= string
->ts
.kind
;
2282 f
->value
.function
.name
= gfc_get_string ("__trim_%d", string
->ts
.kind
);
2287 gfc_resolve_ubound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
)
2289 static char ubound
[] = "__ubound";
2291 f
->ts
.type
= BT_INTEGER
;
2292 f
->ts
.kind
= gfc_default_integer_kind
;
2297 f
->shape
= gfc_get_shape (1);
2298 mpz_init_set_ui (f
->shape
[0], array
->rank
);
2301 f
->value
.function
.name
= ubound
;
2305 /* Resolve the g77 compatibility function UMASK. */
2308 gfc_resolve_umask (gfc_expr
*f
, gfc_expr
*n
)
2310 f
->ts
.type
= BT_INTEGER
;
2311 f
->ts
.kind
= n
->ts
.kind
;
2312 f
->value
.function
.name
= gfc_get_string (PREFIX ("umask_i%d"), n
->ts
.kind
);
2316 /* Resolve the g77 compatibility function UNLINK. */
2319 gfc_resolve_unlink (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
)
2321 f
->ts
.type
= BT_INTEGER
;
2323 f
->value
.function
.name
= gfc_get_string (PREFIX ("unlink"));
2328 gfc_resolve_ttynam (gfc_expr
*f
, gfc_expr
*unit
)
2332 f
->ts
.type
= BT_CHARACTER
;
2333 f
->ts
.kind
= gfc_default_character_kind
;
2335 if (unit
->ts
.kind
!= gfc_c_int_kind
)
2337 ts
.type
= BT_INTEGER
;
2338 ts
.kind
= gfc_c_int_kind
;
2341 gfc_convert_type (unit
, &ts
, 2);
2344 f
->value
.function
.name
= gfc_get_string (PREFIX ("ttynam"));
2349 gfc_resolve_unpack (gfc_expr
*f
, gfc_expr
*vector
, gfc_expr
*mask
,
2350 gfc_expr
*field ATTRIBUTE_UNUSED
)
2353 f
->rank
= mask
->rank
;
2355 /* Coerce the mask to default logical kind if it has kind < 4. */
2357 if (mask
->ts
.kind
< 4)
2361 ts
.type
= BT_LOGICAL
;
2362 ts
.kind
= gfc_default_logical_kind
;
2363 gfc_convert_type (mask
, &ts
, 2);
2366 f
->value
.function
.name
2367 = gfc_get_string (PREFIX ("unpack%d%s"), field
->rank
> 0 ? 1 : 0,
2368 vector
->ts
.type
== BT_CHARACTER
? "_char" : "");
2373 gfc_resolve_verify (gfc_expr
*f
, gfc_expr
*string
,
2374 gfc_expr
*set ATTRIBUTE_UNUSED
,
2375 gfc_expr
*back ATTRIBUTE_UNUSED
)
2377 f
->ts
.type
= BT_INTEGER
;
2378 f
->ts
.kind
= gfc_default_integer_kind
;
2379 f
->value
.function
.name
= gfc_get_string ("__verify_%d", string
->ts
.kind
);
2384 gfc_resolve_xor (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
2386 f
->ts
.type
= i
->ts
.type
;
2387 f
->ts
.kind
= gfc_kind_max (i
, j
);
2389 if (i
->ts
.kind
!= j
->ts
.kind
)
2391 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
2392 gfc_convert_type (j
, &i
->ts
, 2);
2394 gfc_convert_type (i
, &j
->ts
, 2);
2397 f
->value
.function
.name
2398 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i
->ts
.type
), f
->ts
.kind
);
2402 /* Intrinsic subroutine resolution. */
2405 gfc_resolve_alarm_sub (gfc_code
*c
)
2408 gfc_expr
*seconds
, *handler
, *status
;
2411 seconds
= c
->ext
.actual
->expr
;
2412 handler
= c
->ext
.actual
->next
->expr
;
2413 status
= c
->ext
.actual
->next
->next
->expr
;
2414 ts
.type
= BT_INTEGER
;
2415 ts
.kind
= gfc_c_int_kind
;
2417 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2418 if (handler
->ts
.type
== BT_INTEGER
)
2420 if (handler
->ts
.kind
!= gfc_c_int_kind
)
2421 gfc_convert_type (handler
, &ts
, 2);
2422 name
= gfc_get_string (PREFIX ("alarm_sub_int"));
2425 name
= gfc_get_string (PREFIX ("alarm_sub"));
2427 if (seconds
->ts
.kind
!= gfc_c_int_kind
)
2428 gfc_convert_type (seconds
, &ts
, 2);
2430 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2434 gfc_resolve_cpu_time (gfc_code
*c
)
2437 name
= gfc_get_string (PREFIX ("cpu_time_%d"), c
->ext
.actual
->expr
->ts
.kind
);
2438 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2443 gfc_resolve_mvbits (gfc_code
*c
)
2448 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2449 they will be converted so that they fit into a C int. */
2450 ts
.type
= BT_INTEGER
;
2451 ts
.kind
= gfc_c_int_kind
;
2452 if (c
->ext
.actual
->next
->expr
->ts
.kind
!= gfc_c_int_kind
)
2453 gfc_convert_type (c
->ext
.actual
->next
->expr
, &ts
, 2);
2454 if (c
->ext
.actual
->next
->next
->expr
->ts
.kind
!= gfc_c_int_kind
)
2455 gfc_convert_type (c
->ext
.actual
->next
->next
->expr
, &ts
, 2);
2456 if (c
->ext
.actual
->next
->next
->next
->next
->expr
->ts
.kind
!= gfc_c_int_kind
)
2457 gfc_convert_type (c
->ext
.actual
->next
->next
->next
->next
->expr
, &ts
, 2);
2459 /* TO and FROM are guaranteed to have the same kind parameter. */
2460 name
= gfc_get_string (PREFIX ("mvbits_i%d"),
2461 c
->ext
.actual
->expr
->ts
.kind
);
2462 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2467 gfc_resolve_random_number (gfc_code
*c
)
2472 kind
= c
->ext
.actual
->expr
->ts
.kind
;
2473 if (c
->ext
.actual
->expr
->rank
== 0)
2474 name
= gfc_get_string (PREFIX ("random_r%d"), kind
);
2476 name
= gfc_get_string (PREFIX ("arandom_r%d"), kind
);
2478 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2483 gfc_resolve_rename_sub (gfc_code
*c
)
2488 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
2489 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
2491 kind
= gfc_default_integer_kind
;
2493 name
= gfc_get_string (PREFIX ("rename_i%d_sub"), kind
);
2494 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2499 gfc_resolve_kill_sub (gfc_code
*c
)
2504 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
2505 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
2507 kind
= gfc_default_integer_kind
;
2509 name
= gfc_get_string (PREFIX ("kill_i%d_sub"), kind
);
2510 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2515 gfc_resolve_link_sub (gfc_code
*c
)
2520 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
2521 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
2523 kind
= gfc_default_integer_kind
;
2525 name
= gfc_get_string (PREFIX ("link_i%d_sub"), kind
);
2526 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2531 gfc_resolve_symlnk_sub (gfc_code
*c
)
2536 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
2537 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
2539 kind
= gfc_default_integer_kind
;
2541 name
= gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind
);
2542 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2546 /* G77 compatibility subroutines etime() and dtime(). */
2549 gfc_resolve_etime_sub (gfc_code
*c
)
2552 name
= gfc_get_string (PREFIX ("etime_sub"));
2553 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2557 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2560 gfc_resolve_itime (gfc_code
*c
)
2563 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2564 gfc_default_integer_kind
));
2568 gfc_resolve_idate (gfc_code
*c
)
2571 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2572 gfc_default_integer_kind
));
2576 gfc_resolve_ltime (gfc_code
*c
)
2579 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2580 gfc_default_integer_kind
));
2584 gfc_resolve_gmtime (gfc_code
*c
)
2587 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2588 gfc_default_integer_kind
));
2592 /* G77 compatibility subroutine second(). */
2595 gfc_resolve_second_sub (gfc_code
*c
)
2598 name
= gfc_get_string (PREFIX ("second_sub"));
2599 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2604 gfc_resolve_sleep_sub (gfc_code
*c
)
2609 if (c
->ext
.actual
->expr
!= NULL
)
2610 kind
= c
->ext
.actual
->expr
->ts
.kind
;
2612 kind
= gfc_default_integer_kind
;
2614 name
= gfc_get_string (PREFIX ("sleep_i%d_sub"), kind
);
2615 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2619 /* G77 compatibility function srand(). */
2622 gfc_resolve_srand (gfc_code
*c
)
2625 name
= gfc_get_string (PREFIX ("srand"));
2626 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2630 /* Resolve the getarg intrinsic subroutine. */
2633 gfc_resolve_getarg (gfc_code
*c
)
2637 kind
= gfc_default_integer_kind
;
2638 name
= gfc_get_string (PREFIX ("getarg_i%d"), kind
);
2639 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2643 /* Resolve the getcwd intrinsic subroutine. */
2646 gfc_resolve_getcwd_sub (gfc_code
*c
)
2651 if (c
->ext
.actual
->next
->expr
!= NULL
)
2652 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
2654 kind
= gfc_default_integer_kind
;
2656 name
= gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind
);
2657 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2661 /* Resolve the get_command intrinsic subroutine. */
2664 gfc_resolve_get_command (gfc_code
*c
)
2668 kind
= gfc_default_integer_kind
;
2669 name
= gfc_get_string (PREFIX ("get_command_i%d"), kind
);
2670 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2674 /* Resolve the get_command_argument intrinsic subroutine. */
2677 gfc_resolve_get_command_argument (gfc_code
*c
)
2681 kind
= gfc_default_integer_kind
;
2682 name
= gfc_get_string (PREFIX ("get_command_argument_i%d"), kind
);
2683 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2687 /* Resolve the get_environment_variable intrinsic subroutine. */
2690 gfc_resolve_get_environment_variable (gfc_code
*code
)
2694 kind
= gfc_default_integer_kind
;
2695 name
= gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind
);
2696 code
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2701 gfc_resolve_signal_sub (gfc_code
*c
)
2704 gfc_expr
*number
, *handler
, *status
;
2707 number
= c
->ext
.actual
->expr
;
2708 handler
= c
->ext
.actual
->next
->expr
;
2709 status
= c
->ext
.actual
->next
->next
->expr
;
2710 ts
.type
= BT_INTEGER
;
2711 ts
.kind
= gfc_c_int_kind
;
2713 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2714 if (handler
->ts
.type
== BT_INTEGER
)
2716 if (handler
->ts
.kind
!= gfc_c_int_kind
)
2717 gfc_convert_type (handler
, &ts
, 2);
2718 name
= gfc_get_string (PREFIX ("signal_sub_int"));
2721 name
= gfc_get_string (PREFIX ("signal_sub"));
2723 if (number
->ts
.kind
!= gfc_c_int_kind
)
2724 gfc_convert_type (number
, &ts
, 2);
2725 if (status
!= NULL
&& status
->ts
.kind
!= gfc_c_int_kind
)
2726 gfc_convert_type (status
, &ts
, 2);
2728 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2732 /* Resolve the SYSTEM intrinsic subroutine. */
2735 gfc_resolve_system_sub (gfc_code
*c
)
2738 name
= gfc_get_string (PREFIX ("system_sub"));
2739 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2743 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
2746 gfc_resolve_system_clock (gfc_code
*c
)
2751 if (c
->ext
.actual
->expr
!= NULL
)
2752 kind
= c
->ext
.actual
->expr
->ts
.kind
;
2753 else if (c
->ext
.actual
->next
->expr
!= NULL
)
2754 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
2755 else if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
2756 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
2758 kind
= gfc_default_integer_kind
;
2760 name
= gfc_get_string (PREFIX ("system_clock_%d"), kind
);
2761 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2765 /* Resolve the EXIT intrinsic subroutine. */
2768 gfc_resolve_exit (gfc_code
*c
)
2773 if (c
->ext
.actual
->expr
!= NULL
)
2774 kind
= c
->ext
.actual
->expr
->ts
.kind
;
2776 kind
= gfc_default_integer_kind
;
2778 name
= gfc_get_string (PREFIX ("exit_i%d"), kind
);
2779 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2783 /* Resolve the FLUSH intrinsic subroutine. */
2786 gfc_resolve_flush (gfc_code
*c
)
2792 ts
.type
= BT_INTEGER
;
2793 ts
.kind
= gfc_default_integer_kind
;
2794 n
= c
->ext
.actual
->expr
;
2795 if (n
!= NULL
&& n
->ts
.kind
!= ts
.kind
)
2796 gfc_convert_type (n
, &ts
, 2);
2798 name
= gfc_get_string (PREFIX ("flush_i%d"), ts
.kind
);
2799 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2804 gfc_resolve_free (gfc_code
*c
)
2809 ts
.type
= BT_INTEGER
;
2810 ts
.kind
= gfc_index_integer_kind
;
2811 n
= c
->ext
.actual
->expr
;
2812 if (n
->ts
.kind
!= ts
.kind
)
2813 gfc_convert_type (n
, &ts
, 2);
2815 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
2820 gfc_resolve_ctime_sub (gfc_code
*c
)
2824 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
2825 if (c
->ext
.actual
->expr
->ts
.kind
!= 8)
2827 ts
.type
= BT_INTEGER
;
2831 gfc_convert_type (c
->ext
.actual
->expr
, &ts
, 2);
2834 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
2839 gfc_resolve_fdate_sub (gfc_code
*c
)
2841 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
2846 gfc_resolve_gerror (gfc_code
*c
)
2848 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
2853 gfc_resolve_getlog (gfc_code
*c
)
2855 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
2860 gfc_resolve_hostnm_sub (gfc_code
*c
)
2865 if (c
->ext
.actual
->next
->expr
!= NULL
)
2866 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
2868 kind
= gfc_default_integer_kind
;
2870 name
= gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind
);
2871 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2876 gfc_resolve_perror (gfc_code
*c
)
2878 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
2881 /* Resolve the STAT and FSTAT intrinsic subroutines. */
2884 gfc_resolve_stat_sub (gfc_code
*c
)
2887 name
= gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind
);
2888 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2893 gfc_resolve_lstat_sub (gfc_code
*c
)
2896 name
= gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind
);
2897 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2902 gfc_resolve_fstat_sub (gfc_code
*c
)
2908 u
= c
->ext
.actual
->expr
;
2909 ts
= &c
->ext
.actual
->next
->expr
->ts
;
2910 if (u
->ts
.kind
!= ts
->kind
)
2911 gfc_convert_type (u
, ts
, 2);
2912 name
= gfc_get_string (PREFIX ("fstat_i%d_sub"), ts
->kind
);
2913 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2918 gfc_resolve_fgetc_sub (gfc_code
*c
)
2924 u
= c
->ext
.actual
->expr
;
2925 st
= c
->ext
.actual
->next
->next
->expr
;
2927 if (u
->ts
.kind
!= gfc_c_int_kind
)
2929 ts
.type
= BT_INTEGER
;
2930 ts
.kind
= gfc_c_int_kind
;
2933 gfc_convert_type (u
, &ts
, 2);
2937 name
= gfc_get_string (PREFIX ("fgetc_i%d_sub"), st
->ts
.kind
);
2939 name
= gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind
);
2941 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2946 gfc_resolve_fget_sub (gfc_code
*c
)
2951 st
= c
->ext
.actual
->next
->expr
;
2953 name
= gfc_get_string (PREFIX ("fget_i%d_sub"), st
->ts
.kind
);
2955 name
= gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind
);
2957 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2962 gfc_resolve_fputc_sub (gfc_code
*c
)
2968 u
= c
->ext
.actual
->expr
;
2969 st
= c
->ext
.actual
->next
->next
->expr
;
2971 if (u
->ts
.kind
!= gfc_c_int_kind
)
2973 ts
.type
= BT_INTEGER
;
2974 ts
.kind
= gfc_c_int_kind
;
2977 gfc_convert_type (u
, &ts
, 2);
2981 name
= gfc_get_string (PREFIX ("fputc_i%d_sub"), st
->ts
.kind
);
2983 name
= gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind
);
2985 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2990 gfc_resolve_fput_sub (gfc_code
*c
)
2995 st
= c
->ext
.actual
->next
->expr
;
2997 name
= gfc_get_string (PREFIX ("fput_i%d_sub"), st
->ts
.kind
);
2999 name
= gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind
);
3001 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3006 gfc_resolve_fseek_sub (gfc_code
*c
)
3014 unit
= c
->ext
.actual
->expr
;
3015 offset
= c
->ext
.actual
->next
->expr
;
3016 whence
= c
->ext
.actual
->next
->next
->expr
;
3017 status
= c
->ext
.actual
->next
->next
->next
->expr
;
3019 if (unit
->ts
.kind
!= gfc_c_int_kind
)
3021 ts
.type
= BT_INTEGER
;
3022 ts
.kind
= gfc_c_int_kind
;
3025 gfc_convert_type (unit
, &ts
, 2);
3028 if (offset
->ts
.kind
!= gfc_intio_kind
)
3030 ts
.type
= BT_INTEGER
;
3031 ts
.kind
= gfc_intio_kind
;
3034 gfc_convert_type (offset
, &ts
, 2);
3037 if (whence
->ts
.kind
!= gfc_c_int_kind
)
3039 ts
.type
= BT_INTEGER
;
3040 ts
.kind
= gfc_c_int_kind
;
3043 gfc_convert_type (whence
, &ts
, 2);
3046 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3050 gfc_resolve_ftell_sub (gfc_code
*c
)
3057 unit
= c
->ext
.actual
->expr
;
3058 offset
= c
->ext
.actual
->next
->expr
;
3060 if (unit
->ts
.kind
!= gfc_c_int_kind
)
3062 ts
.type
= BT_INTEGER
;
3063 ts
.kind
= gfc_c_int_kind
;
3066 gfc_convert_type (unit
, &ts
, 2);
3069 name
= gfc_get_string (PREFIX ("ftell_i%d_sub"), offset
->ts
.kind
);
3070 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3075 gfc_resolve_ttynam_sub (gfc_code
*c
)
3079 if (c
->ext
.actual
->expr
->ts
.kind
!= gfc_c_int_kind
)
3081 ts
.type
= BT_INTEGER
;
3082 ts
.kind
= gfc_c_int_kind
;
3085 gfc_convert_type (c
->ext
.actual
->expr
, &ts
, 2);
3088 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3092 /* Resolve the UMASK intrinsic subroutine. */
3095 gfc_resolve_umask_sub (gfc_code
*c
)
3100 if (c
->ext
.actual
->next
->expr
!= NULL
)
3101 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3103 kind
= gfc_default_integer_kind
;
3105 name
= gfc_get_string (PREFIX ("umask_i%d_sub"), kind
);
3106 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3109 /* Resolve the UNLINK intrinsic subroutine. */
3112 gfc_resolve_unlink_sub (gfc_code
*c
)
3117 if (c
->ext
.actual
->next
->expr
!= NULL
)
3118 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3120 kind
= gfc_default_integer_kind
;
3122 name
= gfc_get_string (PREFIX ("unlink_i%d_sub"), kind
);
3123 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);