1 /* Intrinsic function resolution.
2 Copyright (C) 2000-2013 Free Software Foundation, Inc.
3 Contributed by Andy Vaught & Katherine Holcomb
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 /* Assign name and types to intrinsic procedures. For functions, the
23 first argument to a resolution function is an expression pointer to
24 the original function node and the rest are pointers to the
25 arguments of the function call. For subroutines, a pointer to the
26 code node is passed. The result type and library subroutine name
27 are generally set according to the function arguments. */
31 #include "coretypes.h"
34 #include "intrinsic.h"
35 #include "constructor.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
->ts
.u
.cl
== NULL
)
67 source
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
69 if (source
->expr_type
== EXPR_CONSTANT
)
71 source
->ts
.u
.cl
->length
72 = gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
73 source
->value
.character
.length
);
76 else if (source
->expr_type
== EXPR_ARRAY
)
78 gfc_constructor
*c
= gfc_constructor_first (source
->value
.constructor
);
79 source
->ts
.u
.cl
->length
80 = gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
81 c
->expr
->value
.character
.length
);
85 /* Helper function for resolving the "mask" argument. */
88 resolve_mask_arg (gfc_expr
*mask
)
96 /* For the scalar case, coerce the mask to kind=4 unconditionally
97 (because this is the only kind we have a library function
100 if (mask
->ts
.kind
!= 4)
102 ts
.type
= BT_LOGICAL
;
104 gfc_convert_type (mask
, &ts
, 2);
109 /* In the library, we access the mask with a GFC_LOGICAL_1
110 argument. No need to waste memory if we are about to create
111 a temporary array. */
112 if (mask
->expr_type
== EXPR_OP
&& mask
->ts
.kind
!= 1)
114 ts
.type
= BT_LOGICAL
;
116 gfc_convert_type_warn (mask
, &ts
, 2, 0);
123 resolve_bound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
,
124 const char *name
, bool coarray
)
126 f
->ts
.type
= BT_INTEGER
;
128 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
130 f
->ts
.kind
= gfc_default_integer_kind
;
135 if (array
->rank
!= -1)
137 f
->shape
= gfc_get_shape (1);
138 mpz_init_set_ui (f
->shape
[0], coarray
? gfc_get_corank (array
)
143 f
->value
.function
.name
= gfc_get_string (name
);
148 resolve_transformational (const char *name
, gfc_expr
*f
, gfc_expr
*array
,
149 gfc_expr
*dim
, gfc_expr
*mask
)
162 resolve_mask_arg (mask
);
169 f
->rank
= array
->rank
- 1;
170 f
->shape
= gfc_copy_shape_excluding (array
->shape
, array
->rank
, dim
);
171 gfc_resolve_dim_arg (dim
);
174 f
->value
.function
.name
175 = gfc_get_string (PREFIX ("%s%s_%c%d"), prefix
, name
,
176 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
180 /********************** Resolution functions **********************/
184 gfc_resolve_abs (gfc_expr
*f
, gfc_expr
*a
)
187 if (f
->ts
.type
== BT_COMPLEX
)
188 f
->ts
.type
= BT_REAL
;
190 f
->value
.function
.name
191 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
196 gfc_resolve_access (gfc_expr
*f
, gfc_expr
*name ATTRIBUTE_UNUSED
,
197 gfc_expr
*mode ATTRIBUTE_UNUSED
)
199 f
->ts
.type
= BT_INTEGER
;
200 f
->ts
.kind
= gfc_c_int_kind
;
201 f
->value
.function
.name
= PREFIX ("access_func");
206 gfc_resolve_adjustl (gfc_expr
*f
, gfc_expr
*string
)
208 f
->ts
.type
= BT_CHARACTER
;
209 f
->ts
.kind
= string
->ts
.kind
;
210 f
->value
.function
.name
= gfc_get_string ("__adjustl_s%d", f
->ts
.kind
);
215 gfc_resolve_adjustr (gfc_expr
*f
, gfc_expr
*string
)
217 f
->ts
.type
= BT_CHARACTER
;
218 f
->ts
.kind
= string
->ts
.kind
;
219 f
->value
.function
.name
= gfc_get_string ("__adjustr_s%d", f
->ts
.kind
);
224 gfc_resolve_char_achar (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*kind
,
227 f
->ts
.type
= BT_CHARACTER
;
228 f
->ts
.kind
= (kind
== NULL
)
229 ? gfc_default_character_kind
: mpz_get_si (kind
->value
.integer
);
230 f
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
231 f
->ts
.u
.cl
->length
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
233 f
->value
.function
.name
= gfc_get_string (name
, f
->ts
.kind
,
234 gfc_type_letter (x
->ts
.type
),
240 gfc_resolve_achar (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*kind
)
242 gfc_resolve_char_achar (f
, x
, kind
, "__achar_%d_%c%d");
247 gfc_resolve_acos (gfc_expr
*f
, gfc_expr
*x
)
250 f
->value
.function
.name
251 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
256 gfc_resolve_acosh (gfc_expr
*f
, gfc_expr
*x
)
259 f
->value
.function
.name
260 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x
->ts
.type
),
266 gfc_resolve_aimag (gfc_expr
*f
, gfc_expr
*x
)
268 f
->ts
.type
= BT_REAL
;
269 f
->ts
.kind
= x
->ts
.kind
;
270 f
->value
.function
.name
271 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x
->ts
.type
),
277 gfc_resolve_and (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
279 f
->ts
.type
= i
->ts
.type
;
280 f
->ts
.kind
= gfc_kind_max (i
, j
);
282 if (i
->ts
.kind
!= j
->ts
.kind
)
284 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
285 gfc_convert_type (j
, &i
->ts
, 2);
287 gfc_convert_type (i
, &j
->ts
, 2);
290 f
->value
.function
.name
291 = gfc_get_string ("__and_%c%d", gfc_type_letter (i
->ts
.type
), f
->ts
.kind
);
296 gfc_resolve_aint (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
301 f
->ts
.type
= a
->ts
.type
;
302 f
->ts
.kind
= (kind
== NULL
) ? a
->ts
.kind
: mpz_get_si (kind
->value
.integer
);
304 if (a
->ts
.kind
!= f
->ts
.kind
)
306 ts
.type
= f
->ts
.type
;
307 ts
.kind
= f
->ts
.kind
;
308 gfc_convert_type (a
, &ts
, 2);
310 /* The resolved name is only used for specific intrinsics where
311 the return kind is the same as the arg kind. */
312 f
->value
.function
.name
313 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
318 gfc_resolve_dint (gfc_expr
*f
, gfc_expr
*a
)
320 gfc_resolve_aint (f
, a
, NULL
);
325 gfc_resolve_all (gfc_expr
*f
, gfc_expr
*mask
, gfc_expr
*dim
)
331 gfc_resolve_dim_arg (dim
);
332 f
->rank
= mask
->rank
- 1;
333 f
->shape
= gfc_copy_shape_excluding (mask
->shape
, mask
->rank
, dim
);
336 f
->value
.function
.name
337 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask
->ts
.type
),
343 gfc_resolve_anint (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
348 f
->ts
.type
= a
->ts
.type
;
349 f
->ts
.kind
= (kind
== NULL
) ? a
->ts
.kind
: mpz_get_si (kind
->value
.integer
);
351 if (a
->ts
.kind
!= f
->ts
.kind
)
353 ts
.type
= f
->ts
.type
;
354 ts
.kind
= f
->ts
.kind
;
355 gfc_convert_type (a
, &ts
, 2);
358 /* The resolved name is only used for specific intrinsics where
359 the return kind is the same as the arg kind. */
360 f
->value
.function
.name
361 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a
->ts
.type
),
367 gfc_resolve_dnint (gfc_expr
*f
, gfc_expr
*a
)
369 gfc_resolve_anint (f
, a
, NULL
);
374 gfc_resolve_any (gfc_expr
*f
, gfc_expr
*mask
, gfc_expr
*dim
)
380 gfc_resolve_dim_arg (dim
);
381 f
->rank
= mask
->rank
- 1;
382 f
->shape
= gfc_copy_shape_excluding (mask
->shape
, mask
->rank
, dim
);
385 f
->value
.function
.name
386 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask
->ts
.type
),
392 gfc_resolve_asin (gfc_expr
*f
, gfc_expr
*x
)
395 f
->value
.function
.name
396 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
400 gfc_resolve_asinh (gfc_expr
*f
, gfc_expr
*x
)
403 f
->value
.function
.name
404 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x
->ts
.type
),
409 gfc_resolve_atan (gfc_expr
*f
, gfc_expr
*x
)
412 f
->value
.function
.name
413 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
417 gfc_resolve_atanh (gfc_expr
*f
, gfc_expr
*x
)
420 f
->value
.function
.name
421 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x
->ts
.type
),
426 gfc_resolve_atan2 (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*y ATTRIBUTE_UNUSED
)
429 f
->value
.function
.name
430 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x
->ts
.type
),
435 /* Resolve the BESYN and BESJN intrinsics. */
438 gfc_resolve_besn (gfc_expr
*f
, gfc_expr
*n
, gfc_expr
*x
)
444 if (n
->ts
.kind
!= gfc_c_int_kind
)
446 ts
.type
= BT_INTEGER
;
447 ts
.kind
= gfc_c_int_kind
;
448 gfc_convert_type (n
, &ts
, 2);
450 f
->value
.function
.name
= gfc_get_string ("<intrinsic>");
455 gfc_resolve_bessel_n2 (gfc_expr
*f
, gfc_expr
*n1
, gfc_expr
*n2
, gfc_expr
*x
)
462 if (n1
->expr_type
== EXPR_CONSTANT
&& n2
->expr_type
== EXPR_CONSTANT
)
464 f
->shape
= gfc_get_shape (1);
465 mpz_init (f
->shape
[0]);
466 mpz_sub (f
->shape
[0], n2
->value
.integer
, n1
->value
.integer
);
467 mpz_add_ui (f
->shape
[0], f
->shape
[0], 1);
470 if (n1
->ts
.kind
!= gfc_c_int_kind
)
472 ts
.type
= BT_INTEGER
;
473 ts
.kind
= gfc_c_int_kind
;
474 gfc_convert_type (n1
, &ts
, 2);
477 if (n2
->ts
.kind
!= gfc_c_int_kind
)
479 ts
.type
= BT_INTEGER
;
480 ts
.kind
= gfc_c_int_kind
;
481 gfc_convert_type (n2
, &ts
, 2);
484 if (f
->value
.function
.isym
->id
== GFC_ISYM_JN2
)
485 f
->value
.function
.name
= gfc_get_string (PREFIX ("bessel_jn_r%d"),
488 f
->value
.function
.name
= gfc_get_string (PREFIX ("bessel_yn_r%d"),
494 gfc_resolve_btest (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*pos
)
496 f
->ts
.type
= BT_LOGICAL
;
497 f
->ts
.kind
= gfc_default_logical_kind
;
498 f
->value
.function
.name
499 = gfc_get_string ("__btest_%d_%d", i
->ts
.kind
, pos
->ts
.kind
);
504 gfc_resolve_c_loc (gfc_expr
*f
, gfc_expr
*x ATTRIBUTE_UNUSED
)
506 f
->ts
= f
->value
.function
.isym
->ts
;
511 gfc_resolve_c_funloc (gfc_expr
*f
, gfc_expr
*x ATTRIBUTE_UNUSED
)
513 f
->ts
= f
->value
.function
.isym
->ts
;
518 gfc_resolve_ceiling (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
520 f
->ts
.type
= BT_INTEGER
;
521 f
->ts
.kind
= (kind
== NULL
)
522 ? gfc_default_integer_kind
: mpz_get_si (kind
->value
.integer
);
523 f
->value
.function
.name
524 = gfc_get_string ("__ceiling_%d_%c%d", f
->ts
.kind
,
525 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
530 gfc_resolve_char (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
532 gfc_resolve_char_achar (f
, a
, kind
, "__char_%d_%c%d");
537 gfc_resolve_chdir (gfc_expr
*f
, gfc_expr
*d ATTRIBUTE_UNUSED
)
539 f
->ts
.type
= BT_INTEGER
;
540 f
->ts
.kind
= gfc_default_integer_kind
;
541 f
->value
.function
.name
= gfc_get_string (PREFIX ("chdir_i%d"), f
->ts
.kind
);
546 gfc_resolve_chdir_sub (gfc_code
*c
)
551 if (c
->ext
.actual
->next
->expr
!= NULL
)
552 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
554 kind
= gfc_default_integer_kind
;
556 name
= gfc_get_string (PREFIX ("chdir_i%d_sub"), kind
);
557 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
562 gfc_resolve_chmod (gfc_expr
*f
, gfc_expr
*name ATTRIBUTE_UNUSED
,
563 gfc_expr
*mode ATTRIBUTE_UNUSED
)
565 f
->ts
.type
= BT_INTEGER
;
566 f
->ts
.kind
= gfc_c_int_kind
;
567 f
->value
.function
.name
= PREFIX ("chmod_func");
572 gfc_resolve_chmod_sub (gfc_code
*c
)
577 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
578 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
580 kind
= gfc_default_integer_kind
;
582 name
= gfc_get_string (PREFIX ("chmod_i%d_sub"), kind
);
583 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
588 gfc_resolve_cmplx (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*kind
)
590 f
->ts
.type
= BT_COMPLEX
;
591 f
->ts
.kind
= (kind
== NULL
)
592 ? gfc_default_real_kind
: mpz_get_si (kind
->value
.integer
);
595 f
->value
.function
.name
596 = gfc_get_string ("__cmplx0_%d_%c%d", f
->ts
.kind
,
597 gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
599 f
->value
.function
.name
600 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f
->ts
.kind
,
601 gfc_type_letter (x
->ts
.type
), x
->ts
.kind
,
602 gfc_type_letter (y
->ts
.type
), y
->ts
.kind
);
607 gfc_resolve_dcmplx (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*y
)
609 gfc_resolve_cmplx (f
, x
, y
, gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
610 gfc_default_double_kind
));
615 gfc_resolve_complex (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*y
)
619 if (x
->ts
.type
== BT_INTEGER
)
621 if (y
->ts
.type
== BT_INTEGER
)
622 kind
= gfc_default_real_kind
;
628 if (y
->ts
.type
== BT_REAL
)
629 kind
= (x
->ts
.kind
> y
->ts
.kind
) ? x
->ts
.kind
: y
->ts
.kind
;
634 f
->ts
.type
= BT_COMPLEX
;
636 f
->value
.function
.name
637 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f
->ts
.kind
,
638 gfc_type_letter (x
->ts
.type
), x
->ts
.kind
,
639 gfc_type_letter (y
->ts
.type
), y
->ts
.kind
);
644 gfc_resolve_conjg (gfc_expr
*f
, gfc_expr
*x
)
647 f
->value
.function
.name
= gfc_get_string ("__conjg_%d", x
->ts
.kind
);
652 gfc_resolve_cos (gfc_expr
*f
, gfc_expr
*x
)
655 f
->value
.function
.name
656 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
661 gfc_resolve_cosh (gfc_expr
*f
, gfc_expr
*x
)
664 f
->value
.function
.name
665 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
670 gfc_resolve_count (gfc_expr
*f
, gfc_expr
*mask
, gfc_expr
*dim
, gfc_expr
*kind
)
672 f
->ts
.type
= BT_INTEGER
;
674 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
676 f
->ts
.kind
= gfc_default_integer_kind
;
680 f
->rank
= mask
->rank
- 1;
681 gfc_resolve_dim_arg (dim
);
682 f
->shape
= gfc_copy_shape_excluding (mask
->shape
, mask
->rank
, dim
);
685 resolve_mask_arg (mask
);
687 f
->value
.function
.name
688 = gfc_get_string (PREFIX ("count_%d_%c"), f
->ts
.kind
,
689 gfc_type_letter (mask
->ts
.type
));
694 gfc_resolve_cshift (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*shift
,
699 if (array
->ts
.type
== BT_CHARACTER
&& array
->ref
)
700 gfc_resolve_substring_charlen (array
);
703 f
->rank
= array
->rank
;
704 f
->shape
= gfc_copy_shape (array
->shape
, array
->rank
);
711 /* If dim kind is greater than default integer we need to use the larger. */
712 m
= gfc_default_integer_kind
;
714 m
= m
< dim
->ts
.kind
? dim
->ts
.kind
: m
;
716 /* Convert shift to at least m, so we don't need
717 kind=1 and kind=2 versions of the library functions. */
718 if (shift
->ts
.kind
< m
)
722 ts
.type
= BT_INTEGER
;
724 gfc_convert_type_warn (shift
, &ts
, 2, 0);
729 if (dim
->expr_type
!= EXPR_CONSTANT
&& dim
->symtree
!= NULL
730 && dim
->symtree
->n
.sym
->attr
.optional
)
732 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
733 dim
->representation
.length
= shift
->ts
.kind
;
737 gfc_resolve_dim_arg (dim
);
738 /* Convert dim to shift's kind to reduce variations. */
739 if (dim
->ts
.kind
!= shift
->ts
.kind
)
740 gfc_convert_type_warn (dim
, &shift
->ts
, 2, 0);
744 if (array
->ts
.type
== BT_CHARACTER
)
746 if (array
->ts
.kind
== gfc_default_character_kind
)
747 f
->value
.function
.name
748 = gfc_get_string (PREFIX ("cshift%d_%d_char"), n
, shift
->ts
.kind
);
750 f
->value
.function
.name
751 = gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n
, shift
->ts
.kind
,
755 f
->value
.function
.name
756 = gfc_get_string (PREFIX ("cshift%d_%d"), n
, shift
->ts
.kind
);
761 gfc_resolve_ctime (gfc_expr
*f
, gfc_expr
*time
)
766 f
->ts
.type
= BT_CHARACTER
;
767 f
->ts
.kind
= gfc_default_character_kind
;
769 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
770 if (time
->ts
.kind
!= 8)
772 ts
.type
= BT_INTEGER
;
776 gfc_convert_type (time
, &ts
, 2);
779 f
->value
.function
.name
= gfc_get_string (PREFIX ("ctime"));
784 gfc_resolve_dble (gfc_expr
*f
, gfc_expr
*a
)
786 f
->ts
.type
= BT_REAL
;
787 f
->ts
.kind
= gfc_default_double_kind
;
788 f
->value
.function
.name
789 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
794 gfc_resolve_dim (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*p
)
796 f
->ts
.type
= a
->ts
.type
;
798 f
->ts
.kind
= gfc_kind_max (a
,p
);
800 f
->ts
.kind
= a
->ts
.kind
;
802 if (p
!= NULL
&& a
->ts
.kind
!= p
->ts
.kind
)
804 if (a
->ts
.kind
== gfc_kind_max (a
,p
))
805 gfc_convert_type (p
, &a
->ts
, 2);
807 gfc_convert_type (a
, &p
->ts
, 2);
810 f
->value
.function
.name
811 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f
->ts
.type
), f
->ts
.kind
);
816 gfc_resolve_dot_product (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*b
)
820 temp
.expr_type
= EXPR_OP
;
821 gfc_clear_ts (&temp
.ts
);
822 temp
.value
.op
.op
= INTRINSIC_NONE
;
823 temp
.value
.op
.op1
= a
;
824 temp
.value
.op
.op2
= b
;
825 gfc_type_convert_binary (&temp
, 1);
827 f
->value
.function
.name
828 = gfc_get_string (PREFIX ("dot_product_%c%d"),
829 gfc_type_letter (f
->ts
.type
), f
->ts
.kind
);
834 gfc_resolve_dprod (gfc_expr
*f
, gfc_expr
*a ATTRIBUTE_UNUSED
,
835 gfc_expr
*b ATTRIBUTE_UNUSED
)
837 f
->ts
.kind
= gfc_default_double_kind
;
838 f
->ts
.type
= BT_REAL
;
839 f
->value
.function
.name
= gfc_get_string ("__dprod_r%d", f
->ts
.kind
);
844 gfc_resolve_dshift (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j ATTRIBUTE_UNUSED
,
845 gfc_expr
*shift ATTRIBUTE_UNUSED
)
848 if (f
->value
.function
.isym
->id
== GFC_ISYM_DSHIFTL
)
849 f
->value
.function
.name
= gfc_get_string ("dshiftl_i%d", f
->ts
.kind
);
850 else if (f
->value
.function
.isym
->id
== GFC_ISYM_DSHIFTR
)
851 f
->value
.function
.name
= gfc_get_string ("dshiftr_i%d", f
->ts
.kind
);
858 gfc_resolve_eoshift (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*shift
,
859 gfc_expr
*boundary
, gfc_expr
*dim
)
863 if (array
->ts
.type
== BT_CHARACTER
&& array
->ref
)
864 gfc_resolve_substring_charlen (array
);
867 f
->rank
= array
->rank
;
868 f
->shape
= gfc_copy_shape (array
->shape
, array
->rank
);
873 if (boundary
&& boundary
->rank
> 0)
876 /* If dim kind is greater than default integer we need to use the larger. */
877 m
= gfc_default_integer_kind
;
879 m
= m
< dim
->ts
.kind
? dim
->ts
.kind
: m
;
881 /* Convert shift to at least m, so we don't need
882 kind=1 and kind=2 versions of the library functions. */
883 if (shift
->ts
.kind
< m
)
887 ts
.type
= BT_INTEGER
;
889 gfc_convert_type_warn (shift
, &ts
, 2, 0);
894 if (dim
->expr_type
!= EXPR_CONSTANT
&& dim
->symtree
!= NULL
895 && dim
->symtree
->n
.sym
->attr
.optional
)
897 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
898 dim
->representation
.length
= shift
->ts
.kind
;
902 gfc_resolve_dim_arg (dim
);
903 /* Convert dim to shift's kind to reduce variations. */
904 if (dim
->ts
.kind
!= shift
->ts
.kind
)
905 gfc_convert_type_warn (dim
, &shift
->ts
, 2, 0);
909 if (array
->ts
.type
== BT_CHARACTER
)
911 if (array
->ts
.kind
== gfc_default_character_kind
)
912 f
->value
.function
.name
913 = gfc_get_string (PREFIX ("eoshift%d_%d_char"), n
, shift
->ts
.kind
);
915 f
->value
.function
.name
916 = gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n
, shift
->ts
.kind
,
920 f
->value
.function
.name
921 = gfc_get_string (PREFIX ("eoshift%d_%d"), n
, shift
->ts
.kind
);
926 gfc_resolve_exp (gfc_expr
*f
, gfc_expr
*x
)
929 f
->value
.function
.name
930 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
935 gfc_resolve_exponent (gfc_expr
*f
, gfc_expr
*x
)
937 f
->ts
.type
= BT_INTEGER
;
938 f
->ts
.kind
= gfc_default_integer_kind
;
939 f
->value
.function
.name
= gfc_get_string ("__exponent_%d", x
->ts
.kind
);
943 /* Resolve the EXTENDS_TYPE_OF intrinsic function. */
946 gfc_resolve_extends_type_of (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*mo
)
951 /* Prevent double resolution. */
952 if (f
->ts
.type
== BT_LOGICAL
)
955 /* Replace the first argument with the corresponding vtab. */
956 if (a
->ts
.type
== BT_CLASS
)
957 gfc_add_vptr_component (a
);
958 else if (a
->ts
.type
== BT_DERIVED
)
960 vtab
= gfc_find_derived_vtab (a
->ts
.u
.derived
);
961 /* Clear the old expr. */
962 gfc_free_ref_list (a
->ref
);
963 memset (a
, '\0', sizeof (gfc_expr
));
964 /* Construct a new one. */
965 a
->expr_type
= EXPR_VARIABLE
;
966 st
= gfc_find_symtree (vtab
->ns
->sym_root
, vtab
->name
);
971 /* Replace the second argument with the corresponding vtab. */
972 if (mo
->ts
.type
== BT_CLASS
)
973 gfc_add_vptr_component (mo
);
974 else if (mo
->ts
.type
== BT_DERIVED
)
976 vtab
= gfc_find_derived_vtab (mo
->ts
.u
.derived
);
977 /* Clear the old expr. */
978 gfc_free_ref_list (mo
->ref
);
979 memset (mo
, '\0', sizeof (gfc_expr
));
980 /* Construct a new one. */
981 mo
->expr_type
= EXPR_VARIABLE
;
982 st
= gfc_find_symtree (vtab
->ns
->sym_root
, vtab
->name
);
987 f
->ts
.type
= BT_LOGICAL
;
990 f
->value
.function
.isym
->formal
->ts
= a
->ts
;
991 f
->value
.function
.isym
->formal
->next
->ts
= mo
->ts
;
993 /* Call library function. */
994 f
->value
.function
.name
= gfc_get_string (PREFIX ("is_extension_of"));
999 gfc_resolve_fdate (gfc_expr
*f
)
1001 f
->ts
.type
= BT_CHARACTER
;
1002 f
->ts
.kind
= gfc_default_character_kind
;
1003 f
->value
.function
.name
= gfc_get_string (PREFIX ("fdate"));
1008 gfc_resolve_floor (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
1010 f
->ts
.type
= BT_INTEGER
;
1011 f
->ts
.kind
= (kind
== NULL
)
1012 ? gfc_default_integer_kind
: mpz_get_si (kind
->value
.integer
);
1013 f
->value
.function
.name
1014 = gfc_get_string ("__floor%d_%c%d", f
->ts
.kind
,
1015 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1020 gfc_resolve_fnum (gfc_expr
*f
, gfc_expr
*n
)
1022 f
->ts
.type
= BT_INTEGER
;
1023 f
->ts
.kind
= gfc_default_integer_kind
;
1024 if (n
->ts
.kind
!= f
->ts
.kind
)
1025 gfc_convert_type (n
, &f
->ts
, 2);
1026 f
->value
.function
.name
= gfc_get_string (PREFIX ("fnum_i%d"), f
->ts
.kind
);
1031 gfc_resolve_fraction (gfc_expr
*f
, gfc_expr
*x
)
1034 f
->value
.function
.name
= gfc_get_string ("__fraction_%d", x
->ts
.kind
);
1038 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
1041 gfc_resolve_g77_math1 (gfc_expr
*f
, gfc_expr
*x
)
1044 f
->value
.function
.name
= gfc_get_string ("<intrinsic>");
1049 gfc_resolve_gamma (gfc_expr
*f
, gfc_expr
*x
)
1052 f
->value
.function
.name
1053 = gfc_get_string ("__tgamma_%d", x
->ts
.kind
);
1058 gfc_resolve_getcwd (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
)
1060 f
->ts
.type
= BT_INTEGER
;
1062 f
->value
.function
.name
= gfc_get_string (PREFIX ("getcwd"));
1067 gfc_resolve_getgid (gfc_expr
*f
)
1069 f
->ts
.type
= BT_INTEGER
;
1071 f
->value
.function
.name
= gfc_get_string (PREFIX ("getgid"));
1076 gfc_resolve_getpid (gfc_expr
*f
)
1078 f
->ts
.type
= BT_INTEGER
;
1080 f
->value
.function
.name
= gfc_get_string (PREFIX ("getpid"));
1085 gfc_resolve_getuid (gfc_expr
*f
)
1087 f
->ts
.type
= BT_INTEGER
;
1089 f
->value
.function
.name
= gfc_get_string (PREFIX ("getuid"));
1094 gfc_resolve_hostnm (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
)
1096 f
->ts
.type
= BT_INTEGER
;
1098 f
->value
.function
.name
= gfc_get_string (PREFIX ("hostnm"));
1103 gfc_resolve_hypot (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*y ATTRIBUTE_UNUSED
)
1106 f
->value
.function
.name
= gfc_get_string ("__hypot_r%d", x
->ts
.kind
);
1111 gfc_resolve_iall (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*mask
)
1113 resolve_transformational ("iall", f
, array
, dim
, mask
);
1118 gfc_resolve_iand (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
1120 /* If the kind of i and j are different, then g77 cross-promoted the
1121 kinds to the largest value. The Fortran 95 standard requires the
1123 if (i
->ts
.kind
!= j
->ts
.kind
)
1125 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
1126 gfc_convert_type (j
, &i
->ts
, 2);
1128 gfc_convert_type (i
, &j
->ts
, 2);
1132 f
->value
.function
.name
= gfc_get_string ("__iand_%d", i
->ts
.kind
);
1137 gfc_resolve_iany (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*mask
)
1139 resolve_transformational ("iany", f
, array
, dim
, mask
);
1144 gfc_resolve_ibclr (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*pos ATTRIBUTE_UNUSED
)
1147 f
->value
.function
.name
= gfc_get_string ("__ibclr_%d", i
->ts
.kind
);
1152 gfc_resolve_ibits (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*pos ATTRIBUTE_UNUSED
,
1153 gfc_expr
*len ATTRIBUTE_UNUSED
)
1156 f
->value
.function
.name
= gfc_get_string ("__ibits_%d", i
->ts
.kind
);
1161 gfc_resolve_ibset (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*pos ATTRIBUTE_UNUSED
)
1164 f
->value
.function
.name
= gfc_get_string ("__ibset_%d", i
->ts
.kind
);
1169 gfc_resolve_iachar (gfc_expr
*f
, gfc_expr
*c
, gfc_expr
*kind
)
1171 f
->ts
.type
= BT_INTEGER
;
1173 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1175 f
->ts
.kind
= gfc_default_integer_kind
;
1176 f
->value
.function
.name
= gfc_get_string ("__ichar_%d", c
->ts
.kind
);
1181 gfc_resolve_ichar (gfc_expr
*f
, gfc_expr
*c
, gfc_expr
*kind
)
1183 f
->ts
.type
= BT_INTEGER
;
1185 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1187 f
->ts
.kind
= gfc_default_integer_kind
;
1188 f
->value
.function
.name
= gfc_get_string ("__ichar_%d", c
->ts
.kind
);
1193 gfc_resolve_idnint (gfc_expr
*f
, gfc_expr
*a
)
1195 gfc_resolve_nint (f
, a
, NULL
);
1200 gfc_resolve_ierrno (gfc_expr
*f
)
1202 f
->ts
.type
= BT_INTEGER
;
1203 f
->ts
.kind
= gfc_default_integer_kind
;
1204 f
->value
.function
.name
= gfc_get_string (PREFIX ("ierrno_i%d"), f
->ts
.kind
);
1209 gfc_resolve_ieor (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
1211 /* If the kind of i and j are different, then g77 cross-promoted the
1212 kinds to the largest value. The Fortran 95 standard requires the
1214 if (i
->ts
.kind
!= j
->ts
.kind
)
1216 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
1217 gfc_convert_type (j
, &i
->ts
, 2);
1219 gfc_convert_type (i
, &j
->ts
, 2);
1223 f
->value
.function
.name
= gfc_get_string ("__ieor_%d", i
->ts
.kind
);
1228 gfc_resolve_ior (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
1230 /* If the kind of i and j are different, then g77 cross-promoted the
1231 kinds to the largest value. The Fortran 95 standard requires the
1233 if (i
->ts
.kind
!= j
->ts
.kind
)
1235 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
1236 gfc_convert_type (j
, &i
->ts
, 2);
1238 gfc_convert_type (i
, &j
->ts
, 2);
1242 f
->value
.function
.name
= gfc_get_string ("__ior_%d", i
->ts
.kind
);
1247 gfc_resolve_index_func (gfc_expr
*f
, gfc_expr
*str
,
1248 gfc_expr
*sub_str ATTRIBUTE_UNUSED
, gfc_expr
*back
,
1254 f
->ts
.type
= BT_INTEGER
;
1256 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1258 f
->ts
.kind
= gfc_default_integer_kind
;
1260 if (back
&& back
->ts
.kind
!= gfc_default_integer_kind
)
1262 ts
.type
= BT_LOGICAL
;
1263 ts
.kind
= gfc_default_integer_kind
;
1264 ts
.u
.derived
= NULL
;
1266 gfc_convert_type (back
, &ts
, 2);
1269 f
->value
.function
.name
1270 = gfc_get_string ("__index_%d_i%d", str
->ts
.kind
, f
->ts
.kind
);
1275 gfc_resolve_int (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
1277 f
->ts
.type
= BT_INTEGER
;
1278 f
->ts
.kind
= (kind
== NULL
)
1279 ? gfc_default_integer_kind
: mpz_get_si (kind
->value
.integer
);
1280 f
->value
.function
.name
1281 = gfc_get_string ("__int_%d_%c%d", f
->ts
.kind
,
1282 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1287 gfc_resolve_int2 (gfc_expr
*f
, gfc_expr
*a
)
1289 f
->ts
.type
= BT_INTEGER
;
1291 f
->value
.function
.name
1292 = gfc_get_string ("__int_%d_%c%d", f
->ts
.kind
,
1293 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1298 gfc_resolve_int8 (gfc_expr
*f
, gfc_expr
*a
)
1300 f
->ts
.type
= BT_INTEGER
;
1302 f
->value
.function
.name
1303 = gfc_get_string ("__int_%d_%c%d", f
->ts
.kind
,
1304 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1309 gfc_resolve_long (gfc_expr
*f
, gfc_expr
*a
)
1311 f
->ts
.type
= BT_INTEGER
;
1313 f
->value
.function
.name
1314 = gfc_get_string ("__int_%d_%c%d", f
->ts
.kind
,
1315 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1320 gfc_resolve_iparity (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*mask
)
1322 resolve_transformational ("iparity", f
, array
, dim
, mask
);
1327 gfc_resolve_isatty (gfc_expr
*f
, gfc_expr
*u
)
1332 f
->ts
.type
= BT_LOGICAL
;
1333 f
->ts
.kind
= gfc_default_integer_kind
;
1334 if (u
->ts
.kind
!= gfc_c_int_kind
)
1336 ts
.type
= BT_INTEGER
;
1337 ts
.kind
= gfc_c_int_kind
;
1338 ts
.u
.derived
= NULL
;
1340 gfc_convert_type (u
, &ts
, 2);
1343 f
->value
.function
.name
= gfc_get_string (PREFIX ("isatty_l%d"), f
->ts
.kind
);
1348 gfc_resolve_ishft (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift
)
1351 f
->value
.function
.name
1352 = gfc_get_string ("__ishft_%d_%d", i
->ts
.kind
, shift
->ts
.kind
);
1357 gfc_resolve_rshift (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift
)
1360 f
->value
.function
.name
1361 = gfc_get_string ("__rshift_%d_%d", i
->ts
.kind
, shift
->ts
.kind
);
1366 gfc_resolve_lshift (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift
)
1369 f
->value
.function
.name
1370 = gfc_get_string ("__lshift_%d_%d", i
->ts
.kind
, shift
->ts
.kind
);
1375 gfc_resolve_ishftc (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift
, gfc_expr
*size
)
1379 s_kind
= (size
== NULL
) ? gfc_default_integer_kind
: size
->ts
.kind
;
1382 f
->value
.function
.name
1383 = gfc_get_string ("__ishftc_%d_%d_%d", i
->ts
.kind
, shift
->ts
.kind
, s_kind
);
1388 gfc_resolve_kill (gfc_expr
*f
, gfc_expr
*p ATTRIBUTE_UNUSED
,
1389 gfc_expr
*s ATTRIBUTE_UNUSED
)
1391 f
->ts
.type
= BT_INTEGER
;
1392 f
->ts
.kind
= gfc_default_integer_kind
;
1393 f
->value
.function
.name
= gfc_get_string (PREFIX ("kill_i%d"), f
->ts
.kind
);
1398 gfc_resolve_lbound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
1400 resolve_bound (f
, array
, dim
, kind
, "__lbound", false);
1405 gfc_resolve_lcobound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
1407 resolve_bound (f
, array
, dim
, kind
, "__lcobound", true);
1412 gfc_resolve_len (gfc_expr
*f
, gfc_expr
*string
, gfc_expr
*kind
)
1414 f
->ts
.type
= BT_INTEGER
;
1416 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1418 f
->ts
.kind
= gfc_default_integer_kind
;
1419 f
->value
.function
.name
1420 = gfc_get_string ("__len_%d_i%d", string
->ts
.kind
,
1421 gfc_default_integer_kind
);
1426 gfc_resolve_len_trim (gfc_expr
*f
, gfc_expr
*string
, gfc_expr
*kind
)
1428 f
->ts
.type
= BT_INTEGER
;
1430 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1432 f
->ts
.kind
= gfc_default_integer_kind
;
1433 f
->value
.function
.name
= gfc_get_string ("__len_trim%d", string
->ts
.kind
);
1438 gfc_resolve_lgamma (gfc_expr
*f
, gfc_expr
*x
)
1441 f
->value
.function
.name
1442 = gfc_get_string ("__lgamma_%d", x
->ts
.kind
);
1447 gfc_resolve_link (gfc_expr
*f
, gfc_expr
*p1 ATTRIBUTE_UNUSED
,
1448 gfc_expr
*p2 ATTRIBUTE_UNUSED
)
1450 f
->ts
.type
= BT_INTEGER
;
1451 f
->ts
.kind
= gfc_default_integer_kind
;
1452 f
->value
.function
.name
= gfc_get_string (PREFIX ("link_i%d"), f
->ts
.kind
);
1457 gfc_resolve_loc (gfc_expr
*f
, gfc_expr
*x
)
1459 f
->ts
.type
= BT_INTEGER
;
1460 f
->ts
.kind
= gfc_index_integer_kind
;
1461 f
->value
.function
.name
= gfc_get_string ("__loc_%d", x
->ts
.kind
);
1466 gfc_resolve_log (gfc_expr
*f
, gfc_expr
*x
)
1469 f
->value
.function
.name
1470 = gfc_get_string ("__log_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
1475 gfc_resolve_log10 (gfc_expr
*f
, gfc_expr
*x
)
1478 f
->value
.function
.name
1479 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x
->ts
.type
),
1485 gfc_resolve_logical (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
1487 f
->ts
.type
= BT_LOGICAL
;
1488 f
->ts
.kind
= (kind
== NULL
)
1489 ? gfc_default_logical_kind
: mpz_get_si (kind
->value
.integer
);
1492 f
->value
.function
.name
1493 = gfc_get_string ("__logical_%d_%c%d", f
->ts
.kind
,
1494 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1499 gfc_resolve_malloc (gfc_expr
*f
, gfc_expr
*size
)
1501 if (size
->ts
.kind
< gfc_index_integer_kind
)
1506 ts
.type
= BT_INTEGER
;
1507 ts
.kind
= gfc_index_integer_kind
;
1508 gfc_convert_type_warn (size
, &ts
, 2, 0);
1511 f
->ts
.type
= BT_INTEGER
;
1512 f
->ts
.kind
= gfc_index_integer_kind
;
1513 f
->value
.function
.name
= gfc_get_string (PREFIX ("malloc"));
1518 gfc_resolve_matmul (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*b
)
1522 if (a
->ts
.type
== BT_LOGICAL
&& b
->ts
.type
== BT_LOGICAL
)
1524 f
->ts
.type
= BT_LOGICAL
;
1525 f
->ts
.kind
= gfc_default_logical_kind
;
1529 temp
.expr_type
= EXPR_OP
;
1530 gfc_clear_ts (&temp
.ts
);
1531 temp
.value
.op
.op
= INTRINSIC_NONE
;
1532 temp
.value
.op
.op1
= a
;
1533 temp
.value
.op
.op2
= b
;
1534 gfc_type_convert_binary (&temp
, 1);
1538 f
->rank
= (a
->rank
== 2 && b
->rank
== 2) ? 2 : 1;
1540 if (a
->rank
== 2 && b
->rank
== 2)
1542 if (a
->shape
&& b
->shape
)
1544 f
->shape
= gfc_get_shape (f
->rank
);
1545 mpz_init_set (f
->shape
[0], a
->shape
[0]);
1546 mpz_init_set (f
->shape
[1], b
->shape
[1]);
1549 else if (a
->rank
== 1)
1553 f
->shape
= gfc_get_shape (f
->rank
);
1554 mpz_init_set (f
->shape
[0], b
->shape
[1]);
1559 /* b->rank == 1 and a->rank == 2 here, all other cases have
1560 been caught in check.c. */
1563 f
->shape
= gfc_get_shape (f
->rank
);
1564 mpz_init_set (f
->shape
[0], a
->shape
[0]);
1568 f
->value
.function
.name
1569 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f
->ts
.type
),
1575 gfc_resolve_minmax (const char *name
, gfc_expr
*f
, gfc_actual_arglist
*args
)
1577 gfc_actual_arglist
*a
;
1579 f
->ts
.type
= args
->expr
->ts
.type
;
1580 f
->ts
.kind
= args
->expr
->ts
.kind
;
1581 /* Find the largest type kind. */
1582 for (a
= args
->next
; a
; a
= a
->next
)
1584 if (a
->expr
->ts
.kind
> f
->ts
.kind
)
1585 f
->ts
.kind
= a
->expr
->ts
.kind
;
1588 /* Convert all parameters to the required kind. */
1589 for (a
= args
; a
; a
= a
->next
)
1591 if (a
->expr
->ts
.kind
!= f
->ts
.kind
)
1592 gfc_convert_type (a
->expr
, &f
->ts
, 2);
1595 f
->value
.function
.name
1596 = gfc_get_string (name
, gfc_type_letter (f
->ts
.type
), f
->ts
.kind
);
1601 gfc_resolve_max (gfc_expr
*f
, gfc_actual_arglist
*args
)
1603 gfc_resolve_minmax ("__max_%c%d", f
, args
);
1608 gfc_resolve_maxloc (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
1614 f
->ts
.type
= BT_INTEGER
;
1615 f
->ts
.kind
= gfc_default_integer_kind
;
1620 f
->shape
= gfc_get_shape (1);
1621 mpz_init_set_si (f
->shape
[0], array
->rank
);
1625 f
->rank
= array
->rank
- 1;
1626 gfc_resolve_dim_arg (dim
);
1627 if (array
->shape
&& dim
->expr_type
== EXPR_CONSTANT
)
1629 idim
= (int) mpz_get_si (dim
->value
.integer
);
1630 f
->shape
= gfc_get_shape (f
->rank
);
1631 for (i
= 0, j
= 0; i
< f
->rank
; i
++, j
++)
1633 if (i
== (idim
- 1))
1635 mpz_init_set (f
->shape
[i
], array
->shape
[j
]);
1642 if (mask
->rank
== 0)
1647 resolve_mask_arg (mask
);
1652 f
->value
.function
.name
1653 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name
, dim
!= NULL
, f
->ts
.kind
,
1654 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
1659 gfc_resolve_maxval (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
1669 f
->rank
= array
->rank
- 1;
1670 gfc_resolve_dim_arg (dim
);
1672 if (f
->rank
&& array
->shape
&& dim
->expr_type
== EXPR_CONSTANT
)
1674 idim
= (int) mpz_get_si (dim
->value
.integer
);
1675 f
->shape
= gfc_get_shape (f
->rank
);
1676 for (i
= 0, j
= 0; i
< f
->rank
; i
++, j
++)
1678 if (i
== (idim
- 1))
1680 mpz_init_set (f
->shape
[i
], array
->shape
[j
]);
1687 if (mask
->rank
== 0)
1692 resolve_mask_arg (mask
);
1697 f
->value
.function
.name
1698 = gfc_get_string (PREFIX ("%s_%c%d"), name
,
1699 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
1704 gfc_resolve_mclock (gfc_expr
*f
)
1706 f
->ts
.type
= BT_INTEGER
;
1708 f
->value
.function
.name
= PREFIX ("mclock");
1713 gfc_resolve_mclock8 (gfc_expr
*f
)
1715 f
->ts
.type
= BT_INTEGER
;
1717 f
->value
.function
.name
= PREFIX ("mclock8");
1722 gfc_resolve_mask (gfc_expr
*f
, gfc_expr
*i ATTRIBUTE_UNUSED
,
1725 f
->ts
.type
= BT_INTEGER
;
1726 f
->ts
.kind
= kind
? mpz_get_si (kind
->value
.integer
)
1727 : gfc_default_integer_kind
;
1729 if (f
->value
.function
.isym
->id
== GFC_ISYM_MASKL
)
1730 f
->value
.function
.name
= gfc_get_string ("__maskl_i%d", f
->ts
.kind
);
1732 f
->value
.function
.name
= gfc_get_string ("__maskr_i%d", f
->ts
.kind
);
1737 gfc_resolve_merge (gfc_expr
*f
, gfc_expr
*tsource
,
1738 gfc_expr
*fsource ATTRIBUTE_UNUSED
,
1739 gfc_expr
*mask ATTRIBUTE_UNUSED
)
1741 if (tsource
->ts
.type
== BT_CHARACTER
&& tsource
->ref
)
1742 gfc_resolve_substring_charlen (tsource
);
1744 if (fsource
->ts
.type
== BT_CHARACTER
&& fsource
->ref
)
1745 gfc_resolve_substring_charlen (fsource
);
1747 if (tsource
->ts
.type
== BT_CHARACTER
)
1748 check_charlen_present (tsource
);
1750 f
->ts
= tsource
->ts
;
1751 f
->value
.function
.name
1752 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource
->ts
.type
),
1758 gfc_resolve_merge_bits (gfc_expr
*f
, gfc_expr
*i
,
1759 gfc_expr
*j ATTRIBUTE_UNUSED
,
1760 gfc_expr
*mask ATTRIBUTE_UNUSED
)
1763 f
->value
.function
.name
= gfc_get_string ("__merge_bits_i%d", i
->ts
.kind
);
1768 gfc_resolve_min (gfc_expr
*f
, gfc_actual_arglist
*args
)
1770 gfc_resolve_minmax ("__min_%c%d", f
, args
);
1775 gfc_resolve_minloc (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
1781 f
->ts
.type
= BT_INTEGER
;
1782 f
->ts
.kind
= gfc_default_integer_kind
;
1787 f
->shape
= gfc_get_shape (1);
1788 mpz_init_set_si (f
->shape
[0], array
->rank
);
1792 f
->rank
= array
->rank
- 1;
1793 gfc_resolve_dim_arg (dim
);
1794 if (array
->shape
&& dim
->expr_type
== EXPR_CONSTANT
)
1796 idim
= (int) mpz_get_si (dim
->value
.integer
);
1797 f
->shape
= gfc_get_shape (f
->rank
);
1798 for (i
= 0, j
= 0; i
< f
->rank
; i
++, j
++)
1800 if (i
== (idim
- 1))
1802 mpz_init_set (f
->shape
[i
], array
->shape
[j
]);
1809 if (mask
->rank
== 0)
1814 resolve_mask_arg (mask
);
1819 f
->value
.function
.name
1820 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name
, dim
!= NULL
, f
->ts
.kind
,
1821 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
1826 gfc_resolve_minval (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
1836 f
->rank
= array
->rank
- 1;
1837 gfc_resolve_dim_arg (dim
);
1839 if (f
->rank
&& array
->shape
&& dim
->expr_type
== EXPR_CONSTANT
)
1841 idim
= (int) mpz_get_si (dim
->value
.integer
);
1842 f
->shape
= gfc_get_shape (f
->rank
);
1843 for (i
= 0, j
= 0; i
< f
->rank
; i
++, j
++)
1845 if (i
== (idim
- 1))
1847 mpz_init_set (f
->shape
[i
], array
->shape
[j
]);
1854 if (mask
->rank
== 0)
1859 resolve_mask_arg (mask
);
1864 f
->value
.function
.name
1865 = gfc_get_string (PREFIX ("%s_%c%d"), name
,
1866 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
1871 gfc_resolve_mod (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*p
)
1873 f
->ts
.type
= a
->ts
.type
;
1875 f
->ts
.kind
= gfc_kind_max (a
,p
);
1877 f
->ts
.kind
= a
->ts
.kind
;
1879 if (p
!= NULL
&& a
->ts
.kind
!= p
->ts
.kind
)
1881 if (a
->ts
.kind
== gfc_kind_max (a
,p
))
1882 gfc_convert_type (p
, &a
->ts
, 2);
1884 gfc_convert_type (a
, &p
->ts
, 2);
1887 f
->value
.function
.name
1888 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f
->ts
.type
), f
->ts
.kind
);
1893 gfc_resolve_modulo (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*p
)
1895 f
->ts
.type
= a
->ts
.type
;
1897 f
->ts
.kind
= gfc_kind_max (a
,p
);
1899 f
->ts
.kind
= a
->ts
.kind
;
1901 if (p
!= NULL
&& a
->ts
.kind
!= p
->ts
.kind
)
1903 if (a
->ts
.kind
== gfc_kind_max (a
,p
))
1904 gfc_convert_type (p
, &a
->ts
, 2);
1906 gfc_convert_type (a
, &p
->ts
, 2);
1909 f
->value
.function
.name
1910 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f
->ts
.type
),
1915 gfc_resolve_nearest (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*p
)
1917 if (p
->ts
.kind
!= a
->ts
.kind
)
1918 gfc_convert_type (p
, &a
->ts
, 2);
1921 f
->value
.function
.name
1922 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a
->ts
.type
),
1927 gfc_resolve_nint (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
1929 f
->ts
.type
= BT_INTEGER
;
1930 f
->ts
.kind
= (kind
== NULL
)
1931 ? gfc_default_integer_kind
: mpz_get_si (kind
->value
.integer
);
1932 f
->value
.function
.name
1933 = gfc_get_string ("__nint_%d_%d", f
->ts
.kind
, a
->ts
.kind
);
1938 gfc_resolve_norm2 (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
)
1940 resolve_transformational ("norm2", f
, array
, dim
, NULL
);
1945 gfc_resolve_not (gfc_expr
*f
, gfc_expr
*i
)
1948 f
->value
.function
.name
= gfc_get_string ("__not_%d", i
->ts
.kind
);
1953 gfc_resolve_or (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
1955 f
->ts
.type
= i
->ts
.type
;
1956 f
->ts
.kind
= gfc_kind_max (i
, j
);
1958 if (i
->ts
.kind
!= j
->ts
.kind
)
1960 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
1961 gfc_convert_type (j
, &i
->ts
, 2);
1963 gfc_convert_type (i
, &j
->ts
, 2);
1966 f
->value
.function
.name
1967 = gfc_get_string ("__or_%c%d", gfc_type_letter (i
->ts
.type
), f
->ts
.kind
);
1972 gfc_resolve_pack (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*mask
,
1973 gfc_expr
*vector ATTRIBUTE_UNUSED
)
1975 if (array
->ts
.type
== BT_CHARACTER
&& array
->ref
)
1976 gfc_resolve_substring_charlen (array
);
1981 resolve_mask_arg (mask
);
1983 if (mask
->rank
!= 0)
1985 if (array
->ts
.type
== BT_CHARACTER
)
1986 f
->value
.function
.name
1987 = array
->ts
.kind
== 1 ? PREFIX ("pack_char")
1989 (PREFIX ("pack_char%d"),
1992 f
->value
.function
.name
= PREFIX ("pack");
1996 if (array
->ts
.type
== BT_CHARACTER
)
1997 f
->value
.function
.name
1998 = array
->ts
.kind
== 1 ? PREFIX ("pack_s_char")
2000 (PREFIX ("pack_s_char%d"),
2003 f
->value
.function
.name
= PREFIX ("pack_s");
2009 gfc_resolve_parity (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
)
2011 resolve_transformational ("parity", f
, array
, dim
, NULL
);
2016 gfc_resolve_product (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
2019 resolve_transformational ("product", f
, array
, dim
, mask
);
2024 gfc_resolve_rank (gfc_expr
*f
, gfc_expr
*array ATTRIBUTE_UNUSED
)
2026 f
->ts
.type
= BT_INTEGER
;
2027 f
->ts
.kind
= gfc_default_integer_kind
;
2028 f
->value
.function
.name
= gfc_get_string ("__rank");
2033 gfc_resolve_real (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
2035 f
->ts
.type
= BT_REAL
;
2038 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2040 f
->ts
.kind
= (a
->ts
.type
== BT_COMPLEX
)
2041 ? a
->ts
.kind
: gfc_default_real_kind
;
2043 f
->value
.function
.name
2044 = gfc_get_string ("__real_%d_%c%d", f
->ts
.kind
,
2045 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
2050 gfc_resolve_realpart (gfc_expr
*f
, gfc_expr
*a
)
2052 f
->ts
.type
= BT_REAL
;
2053 f
->ts
.kind
= a
->ts
.kind
;
2054 f
->value
.function
.name
2055 = gfc_get_string ("__real_%d_%c%d", f
->ts
.kind
,
2056 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
2061 gfc_resolve_rename (gfc_expr
*f
, gfc_expr
*p1 ATTRIBUTE_UNUSED
,
2062 gfc_expr
*p2 ATTRIBUTE_UNUSED
)
2064 f
->ts
.type
= BT_INTEGER
;
2065 f
->ts
.kind
= gfc_default_integer_kind
;
2066 f
->value
.function
.name
= gfc_get_string (PREFIX ("rename_i%d"), f
->ts
.kind
);
2071 gfc_resolve_repeat (gfc_expr
*f
, gfc_expr
*string
,
2076 f
->ts
.type
= BT_CHARACTER
;
2077 f
->ts
.kind
= string
->ts
.kind
;
2078 f
->value
.function
.name
= gfc_get_string ("__repeat_%d", string
->ts
.kind
);
2080 /* If possible, generate a character length. */
2081 if (f
->ts
.u
.cl
== NULL
)
2082 f
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
2085 if (string
->expr_type
== EXPR_CONSTANT
)
2087 len
= string
->value
.character
.length
;
2088 tmp
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, len
);
2090 else if (string
->ts
.u
.cl
&& string
->ts
.u
.cl
->length
)
2092 tmp
= gfc_copy_expr (string
->ts
.u
.cl
->length
);
2096 f
->ts
.u
.cl
->length
= gfc_multiply (tmp
, gfc_copy_expr (ncopies
));
2101 gfc_resolve_reshape (gfc_expr
*f
, gfc_expr
*source
, gfc_expr
*shape
,
2102 gfc_expr
*pad ATTRIBUTE_UNUSED
,
2103 gfc_expr
*order ATTRIBUTE_UNUSED
)
2109 if (source
->ts
.type
== BT_CHARACTER
&& source
->ref
)
2110 gfc_resolve_substring_charlen (source
);
2114 gfc_array_size (shape
, &rank
);
2115 f
->rank
= mpz_get_si (rank
);
2117 switch (source
->ts
.type
)
2124 kind
= source
->ts
.kind
;
2138 if (source
->ts
.type
== BT_COMPLEX
|| source
->ts
.type
== BT_REAL
)
2139 f
->value
.function
.name
2140 = gfc_get_string (PREFIX ("reshape_%c%d"),
2141 gfc_type_letter (source
->ts
.type
),
2143 else if (source
->ts
.type
== BT_CHARACTER
)
2144 f
->value
.function
.name
= gfc_get_string (PREFIX ("reshape_char%d"),
2147 f
->value
.function
.name
2148 = gfc_get_string (PREFIX ("reshape_%d"), source
->ts
.kind
);
2152 f
->value
.function
.name
= (source
->ts
.type
== BT_CHARACTER
2153 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
2157 if (shape
->expr_type
== EXPR_ARRAY
&& gfc_is_constant_expr (shape
))
2160 f
->shape
= gfc_get_shape (f
->rank
);
2161 c
= gfc_constructor_first (shape
->value
.constructor
);
2162 for (i
= 0; i
< f
->rank
; i
++)
2164 mpz_init_set (f
->shape
[i
], c
->expr
->value
.integer
);
2165 c
= gfc_constructor_next (c
);
2169 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
2170 so many runtime variations. */
2171 if (shape
->ts
.kind
!= gfc_index_integer_kind
)
2173 gfc_typespec ts
= shape
->ts
;
2174 ts
.kind
= gfc_index_integer_kind
;
2175 gfc_convert_type_warn (shape
, &ts
, 2, 0);
2177 if (order
&& order
->ts
.kind
!= gfc_index_integer_kind
)
2178 gfc_convert_type_warn (order
, &shape
->ts
, 2, 0);
2183 gfc_resolve_rrspacing (gfc_expr
*f
, gfc_expr
*x
)
2186 f
->value
.function
.name
= gfc_get_string ("__rrspacing_%d", x
->ts
.kind
);
2191 gfc_resolve_scale (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*i ATTRIBUTE_UNUSED
)
2194 f
->value
.function
.name
= gfc_get_string ("__scale_%d", x
->ts
.kind
);
2199 gfc_resolve_scan (gfc_expr
*f
, gfc_expr
*string
,
2200 gfc_expr
*set ATTRIBUTE_UNUSED
,
2201 gfc_expr
*back ATTRIBUTE_UNUSED
, gfc_expr
*kind
)
2203 f
->ts
.type
= BT_INTEGER
;
2205 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2207 f
->ts
.kind
= gfc_default_integer_kind
;
2208 f
->value
.function
.name
= gfc_get_string ("__scan_%d", string
->ts
.kind
);
2213 gfc_resolve_secnds (gfc_expr
*t1
, gfc_expr
*t0
)
2216 t1
->value
.function
.name
= gfc_get_string (PREFIX ("secnds"));
2221 gfc_resolve_set_exponent (gfc_expr
*f
, gfc_expr
*x
,
2222 gfc_expr
*i ATTRIBUTE_UNUSED
)
2225 f
->value
.function
.name
= gfc_get_string ("__set_exponent_%d", x
->ts
.kind
);
2230 gfc_resolve_shape (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*kind
)
2232 f
->ts
.type
= BT_INTEGER
;
2235 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2237 f
->ts
.kind
= gfc_default_integer_kind
;
2240 if (array
->rank
!= -1)
2242 f
->shape
= gfc_get_shape (1);
2243 mpz_init_set_ui (f
->shape
[0], array
->rank
);
2246 f
->value
.function
.name
= gfc_get_string (PREFIX ("shape_%d"), f
->ts
.kind
);
2251 gfc_resolve_shift (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift ATTRIBUTE_UNUSED
)
2254 if (f
->value
.function
.isym
->id
== GFC_ISYM_SHIFTA
)
2255 f
->value
.function
.name
= gfc_get_string ("shifta_i%d", f
->ts
.kind
);
2256 else if (f
->value
.function
.isym
->id
== GFC_ISYM_SHIFTL
)
2257 f
->value
.function
.name
= gfc_get_string ("shiftl_i%d", f
->ts
.kind
);
2258 else if (f
->value
.function
.isym
->id
== GFC_ISYM_SHIFTR
)
2259 f
->value
.function
.name
= gfc_get_string ("shiftr_i%d", f
->ts
.kind
);
2266 gfc_resolve_sign (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*b ATTRIBUTE_UNUSED
)
2269 f
->value
.function
.name
2270 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
2275 gfc_resolve_signal (gfc_expr
*f
, gfc_expr
*number
, gfc_expr
*handler
)
2277 f
->ts
.type
= BT_INTEGER
;
2278 f
->ts
.kind
= gfc_c_int_kind
;
2280 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2281 if (handler
->ts
.type
== BT_INTEGER
)
2283 if (handler
->ts
.kind
!= gfc_c_int_kind
)
2284 gfc_convert_type (handler
, &f
->ts
, 2);
2285 f
->value
.function
.name
= gfc_get_string (PREFIX ("signal_func_int"));
2288 f
->value
.function
.name
= gfc_get_string (PREFIX ("signal_func"));
2290 if (number
->ts
.kind
!= gfc_c_int_kind
)
2291 gfc_convert_type (number
, &f
->ts
, 2);
2296 gfc_resolve_sin (gfc_expr
*f
, gfc_expr
*x
)
2299 f
->value
.function
.name
2300 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2305 gfc_resolve_sinh (gfc_expr
*f
, gfc_expr
*x
)
2308 f
->value
.function
.name
2309 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2314 gfc_resolve_size (gfc_expr
*f
, gfc_expr
*array ATTRIBUTE_UNUSED
,
2315 gfc_expr
*dim ATTRIBUTE_UNUSED
, gfc_expr
*kind
)
2317 f
->ts
.type
= BT_INTEGER
;
2319 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2321 f
->ts
.kind
= gfc_default_integer_kind
;
2326 gfc_resolve_stride (gfc_expr
*f
, gfc_expr
*array ATTRIBUTE_UNUSED
,
2327 gfc_expr
*dim ATTRIBUTE_UNUSED
)
2329 f
->ts
.type
= BT_INTEGER
;
2330 f
->ts
.kind
= gfc_index_integer_kind
;
2335 gfc_resolve_spacing (gfc_expr
*f
, gfc_expr
*x
)
2338 f
->value
.function
.name
= gfc_get_string ("__spacing_%d", x
->ts
.kind
);
2343 gfc_resolve_spread (gfc_expr
*f
, gfc_expr
*source
, gfc_expr
*dim
,
2346 if (source
->ts
.type
== BT_CHARACTER
&& source
->ref
)
2347 gfc_resolve_substring_charlen (source
);
2349 if (source
->ts
.type
== BT_CHARACTER
)
2350 check_charlen_present (source
);
2353 f
->rank
= source
->rank
+ 1;
2354 if (source
->rank
== 0)
2356 if (source
->ts
.type
== BT_CHARACTER
)
2357 f
->value
.function
.name
2358 = source
->ts
.kind
== 1 ? PREFIX ("spread_char_scalar")
2360 (PREFIX ("spread_char%d_scalar"),
2363 f
->value
.function
.name
= PREFIX ("spread_scalar");
2367 if (source
->ts
.type
== BT_CHARACTER
)
2368 f
->value
.function
.name
2369 = source
->ts
.kind
== 1 ? PREFIX ("spread_char")
2371 (PREFIX ("spread_char%d"),
2374 f
->value
.function
.name
= PREFIX ("spread");
2377 if (dim
&& gfc_is_constant_expr (dim
)
2378 && ncopies
&& gfc_is_constant_expr (ncopies
) && source
->shape
[0])
2381 idim
= mpz_get_ui (dim
->value
.integer
);
2382 f
->shape
= gfc_get_shape (f
->rank
);
2383 for (i
= 0; i
< (idim
- 1); i
++)
2384 mpz_init_set (f
->shape
[i
], source
->shape
[i
]);
2386 mpz_init_set (f
->shape
[idim
- 1], ncopies
->value
.integer
);
2388 for (i
= idim
; i
< f
->rank
; i
++)
2389 mpz_init_set (f
->shape
[i
], source
->shape
[i
-1]);
2393 gfc_resolve_dim_arg (dim
);
2394 gfc_resolve_index (ncopies
, 1);
2399 gfc_resolve_sqrt (gfc_expr
*f
, gfc_expr
*x
)
2402 f
->value
.function
.name
2403 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2407 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2410 gfc_resolve_stat (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
,
2411 gfc_expr
*a ATTRIBUTE_UNUSED
)
2413 f
->ts
.type
= BT_INTEGER
;
2414 f
->ts
.kind
= gfc_default_integer_kind
;
2415 f
->value
.function
.name
= gfc_get_string (PREFIX ("stat_i%d"), f
->ts
.kind
);
2420 gfc_resolve_lstat (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
,
2421 gfc_expr
*a ATTRIBUTE_UNUSED
)
2423 f
->ts
.type
= BT_INTEGER
;
2424 f
->ts
.kind
= gfc_default_integer_kind
;
2425 f
->value
.function
.name
= gfc_get_string (PREFIX ("lstat_i%d"), f
->ts
.kind
);
2430 gfc_resolve_fstat (gfc_expr
*f
, gfc_expr
*n
, gfc_expr
*a ATTRIBUTE_UNUSED
)
2432 f
->ts
.type
= BT_INTEGER
;
2433 f
->ts
.kind
= gfc_default_integer_kind
;
2434 if (n
->ts
.kind
!= f
->ts
.kind
)
2435 gfc_convert_type (n
, &f
->ts
, 2);
2437 f
->value
.function
.name
= gfc_get_string (PREFIX ("fstat_i%d"), f
->ts
.kind
);
2442 gfc_resolve_fgetc (gfc_expr
*f
, gfc_expr
*u
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2447 f
->ts
.type
= BT_INTEGER
;
2448 f
->ts
.kind
= gfc_c_int_kind
;
2449 if (u
->ts
.kind
!= gfc_c_int_kind
)
2451 ts
.type
= BT_INTEGER
;
2452 ts
.kind
= gfc_c_int_kind
;
2453 ts
.u
.derived
= NULL
;
2455 gfc_convert_type (u
, &ts
, 2);
2458 f
->value
.function
.name
= gfc_get_string (PREFIX ("fgetc"));
2463 gfc_resolve_fget (gfc_expr
*f
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2465 f
->ts
.type
= BT_INTEGER
;
2466 f
->ts
.kind
= gfc_c_int_kind
;
2467 f
->value
.function
.name
= gfc_get_string (PREFIX ("fget"));
2472 gfc_resolve_fputc (gfc_expr
*f
, gfc_expr
*u
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2477 f
->ts
.type
= BT_INTEGER
;
2478 f
->ts
.kind
= gfc_c_int_kind
;
2479 if (u
->ts
.kind
!= gfc_c_int_kind
)
2481 ts
.type
= BT_INTEGER
;
2482 ts
.kind
= gfc_c_int_kind
;
2483 ts
.u
.derived
= NULL
;
2485 gfc_convert_type (u
, &ts
, 2);
2488 f
->value
.function
.name
= gfc_get_string (PREFIX ("fputc"));
2493 gfc_resolve_fput (gfc_expr
*f
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2495 f
->ts
.type
= BT_INTEGER
;
2496 f
->ts
.kind
= gfc_c_int_kind
;
2497 f
->value
.function
.name
= gfc_get_string (PREFIX ("fput"));
2502 gfc_resolve_ftell (gfc_expr
*f
, gfc_expr
*u
)
2507 f
->ts
.type
= BT_INTEGER
;
2508 f
->ts
.kind
= gfc_intio_kind
;
2509 if (u
->ts
.kind
!= gfc_c_int_kind
)
2511 ts
.type
= BT_INTEGER
;
2512 ts
.kind
= gfc_c_int_kind
;
2513 ts
.u
.derived
= NULL
;
2515 gfc_convert_type (u
, &ts
, 2);
2518 f
->value
.function
.name
= gfc_get_string (PREFIX ("ftell2"));
2523 gfc_resolve_storage_size (gfc_expr
*f
, gfc_expr
*a ATTRIBUTE_UNUSED
,
2526 f
->ts
.type
= BT_INTEGER
;
2528 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2530 f
->ts
.kind
= gfc_default_integer_kind
;
2535 gfc_resolve_sum (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*mask
)
2537 resolve_transformational ("sum", f
, array
, dim
, mask
);
2542 gfc_resolve_symlnk (gfc_expr
*f
, gfc_expr
*p1 ATTRIBUTE_UNUSED
,
2543 gfc_expr
*p2 ATTRIBUTE_UNUSED
)
2545 f
->ts
.type
= BT_INTEGER
;
2546 f
->ts
.kind
= gfc_default_integer_kind
;
2547 f
->value
.function
.name
= gfc_get_string (PREFIX ("symlnk_i%d"), f
->ts
.kind
);
2551 /* Resolve the g77 compatibility function SYSTEM. */
2554 gfc_resolve_system (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
)
2556 f
->ts
.type
= BT_INTEGER
;
2558 f
->value
.function
.name
= gfc_get_string (PREFIX ("system"));
2563 gfc_resolve_tan (gfc_expr
*f
, gfc_expr
*x
)
2566 f
->value
.function
.name
2567 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2572 gfc_resolve_tanh (gfc_expr
*f
, gfc_expr
*x
)
2575 f
->value
.function
.name
2576 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2581 gfc_resolve_image_index (gfc_expr
*f
, gfc_expr
*array ATTRIBUTE_UNUSED
,
2582 gfc_expr
*sub ATTRIBUTE_UNUSED
)
2584 static char image_index
[] = "__image_index";
2585 f
->ts
.type
= BT_INTEGER
;
2586 f
->ts
.kind
= gfc_default_integer_kind
;
2587 f
->value
.function
.name
= image_index
;
2592 gfc_resolve_this_image (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
)
2594 static char this_image
[] = "__this_image";
2596 resolve_bound (f
, array
, dim
, NULL
, "__this_image", true);
2599 f
->ts
.type
= BT_INTEGER
;
2600 f
->ts
.kind
= gfc_default_integer_kind
;
2601 f
->value
.function
.name
= this_image
;
2607 gfc_resolve_time (gfc_expr
*f
)
2609 f
->ts
.type
= BT_INTEGER
;
2611 f
->value
.function
.name
= gfc_get_string (PREFIX ("time_func"));
2616 gfc_resolve_time8 (gfc_expr
*f
)
2618 f
->ts
.type
= BT_INTEGER
;
2620 f
->value
.function
.name
= gfc_get_string (PREFIX ("time8_func"));
2625 gfc_resolve_transfer (gfc_expr
*f
, gfc_expr
*source ATTRIBUTE_UNUSED
,
2626 gfc_expr
*mold
, gfc_expr
*size
)
2628 /* TODO: Make this do something meaningful. */
2629 static char transfer0
[] = "__transfer0", transfer1
[] = "__transfer1";
2631 if (mold
->ts
.type
== BT_CHARACTER
2632 && !mold
->ts
.u
.cl
->length
2633 && gfc_is_constant_expr (mold
))
2636 if (mold
->expr_type
== EXPR_CONSTANT
)
2638 len
= mold
->value
.character
.length
;
2639 mold
->ts
.u
.cl
->length
= gfc_get_int_expr (gfc_default_integer_kind
,
2644 gfc_constructor
*c
= gfc_constructor_first (mold
->value
.constructor
);
2645 len
= c
->expr
->value
.character
.length
;
2646 mold
->ts
.u
.cl
->length
= gfc_get_int_expr (gfc_default_integer_kind
,
2653 if (size
== NULL
&& mold
->rank
== 0)
2656 f
->value
.function
.name
= transfer0
;
2661 f
->value
.function
.name
= transfer1
;
2662 if (size
&& gfc_is_constant_expr (size
))
2664 f
->shape
= gfc_get_shape (1);
2665 mpz_init_set (f
->shape
[0], size
->value
.integer
);
2672 gfc_resolve_transpose (gfc_expr
*f
, gfc_expr
*matrix
)
2675 if (matrix
->ts
.type
== BT_CHARACTER
&& matrix
->ref
)
2676 gfc_resolve_substring_charlen (matrix
);
2682 f
->shape
= gfc_get_shape (2);
2683 mpz_init_set (f
->shape
[0], matrix
->shape
[1]);
2684 mpz_init_set (f
->shape
[1], matrix
->shape
[0]);
2687 switch (matrix
->ts
.kind
)
2693 switch (matrix
->ts
.type
)
2697 f
->value
.function
.name
2698 = gfc_get_string (PREFIX ("transpose_%c%d"),
2699 gfc_type_letter (matrix
->ts
.type
),
2705 /* Use the integer routines for real and logical cases. This
2706 assumes they all have the same alignment requirements. */
2707 f
->value
.function
.name
2708 = gfc_get_string (PREFIX ("transpose_i%d"), matrix
->ts
.kind
);
2712 if (matrix
->ts
.type
== BT_CHARACTER
&& matrix
->ts
.kind
== 4)
2713 f
->value
.function
.name
= PREFIX ("transpose_char4");
2715 f
->value
.function
.name
= PREFIX ("transpose");
2721 f
->value
.function
.name
= (matrix
->ts
.type
== BT_CHARACTER
2722 ? PREFIX ("transpose_char")
2723 : PREFIX ("transpose"));
2730 gfc_resolve_trim (gfc_expr
*f
, gfc_expr
*string
)
2732 f
->ts
.type
= BT_CHARACTER
;
2733 f
->ts
.kind
= string
->ts
.kind
;
2734 f
->value
.function
.name
= gfc_get_string ("__trim_%d", string
->ts
.kind
);
2739 gfc_resolve_ubound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
2741 resolve_bound (f
, array
, dim
, kind
, "__ubound", false);
2746 gfc_resolve_ucobound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
2748 resolve_bound (f
, array
, dim
, kind
, "__ucobound", true);
2752 /* Resolve the g77 compatibility function UMASK. */
2755 gfc_resolve_umask (gfc_expr
*f
, gfc_expr
*n
)
2757 f
->ts
.type
= BT_INTEGER
;
2758 f
->ts
.kind
= n
->ts
.kind
;
2759 f
->value
.function
.name
= gfc_get_string (PREFIX ("umask_i%d"), n
->ts
.kind
);
2763 /* Resolve the g77 compatibility function UNLINK. */
2766 gfc_resolve_unlink (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
)
2768 f
->ts
.type
= BT_INTEGER
;
2770 f
->value
.function
.name
= gfc_get_string (PREFIX ("unlink"));
2775 gfc_resolve_ttynam (gfc_expr
*f
, gfc_expr
*unit
)
2780 f
->ts
.type
= BT_CHARACTER
;
2781 f
->ts
.kind
= gfc_default_character_kind
;
2783 if (unit
->ts
.kind
!= gfc_c_int_kind
)
2785 ts
.type
= BT_INTEGER
;
2786 ts
.kind
= gfc_c_int_kind
;
2787 ts
.u
.derived
= NULL
;
2789 gfc_convert_type (unit
, &ts
, 2);
2792 f
->value
.function
.name
= gfc_get_string (PREFIX ("ttynam"));
2797 gfc_resolve_unpack (gfc_expr
*f
, gfc_expr
*vector
, gfc_expr
*mask
,
2798 gfc_expr
*field ATTRIBUTE_UNUSED
)
2800 if (vector
->ts
.type
== BT_CHARACTER
&& vector
->ref
)
2801 gfc_resolve_substring_charlen (vector
);
2804 f
->rank
= mask
->rank
;
2805 resolve_mask_arg (mask
);
2807 if (vector
->ts
.type
== BT_CHARACTER
)
2809 if (vector
->ts
.kind
== 1)
2810 f
->value
.function
.name
2811 = gfc_get_string (PREFIX ("unpack%d_char"), field
->rank
> 0 ? 1 : 0);
2813 f
->value
.function
.name
2814 = gfc_get_string (PREFIX ("unpack%d_char%d"),
2815 field
->rank
> 0 ? 1 : 0, vector
->ts
.kind
);
2818 f
->value
.function
.name
2819 = gfc_get_string (PREFIX ("unpack%d"), field
->rank
> 0 ? 1 : 0);
2824 gfc_resolve_verify (gfc_expr
*f
, gfc_expr
*string
,
2825 gfc_expr
*set ATTRIBUTE_UNUSED
,
2826 gfc_expr
*back ATTRIBUTE_UNUSED
, gfc_expr
*kind
)
2828 f
->ts
.type
= BT_INTEGER
;
2830 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2832 f
->ts
.kind
= gfc_default_integer_kind
;
2833 f
->value
.function
.name
= gfc_get_string ("__verify_%d", string
->ts
.kind
);
2838 gfc_resolve_xor (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
2840 f
->ts
.type
= i
->ts
.type
;
2841 f
->ts
.kind
= gfc_kind_max (i
, j
);
2843 if (i
->ts
.kind
!= j
->ts
.kind
)
2845 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
2846 gfc_convert_type (j
, &i
->ts
, 2);
2848 gfc_convert_type (i
, &j
->ts
, 2);
2851 f
->value
.function
.name
2852 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i
->ts
.type
), f
->ts
.kind
);
2856 /* Intrinsic subroutine resolution. */
2859 gfc_resolve_alarm_sub (gfc_code
*c
)
2862 gfc_expr
*seconds
, *handler
;
2866 seconds
= c
->ext
.actual
->expr
;
2867 handler
= c
->ext
.actual
->next
->expr
;
2868 ts
.type
= BT_INTEGER
;
2869 ts
.kind
= gfc_c_int_kind
;
2871 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2872 In all cases, the status argument is of default integer kind
2873 (enforced in check.c) so that the function suffix is fixed. */
2874 if (handler
->ts
.type
== BT_INTEGER
)
2876 if (handler
->ts
.kind
!= gfc_c_int_kind
)
2877 gfc_convert_type (handler
, &ts
, 2);
2878 name
= gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2879 gfc_default_integer_kind
);
2882 name
= gfc_get_string (PREFIX ("alarm_sub_i%d"),
2883 gfc_default_integer_kind
);
2885 if (seconds
->ts
.kind
!= gfc_c_int_kind
)
2886 gfc_convert_type (seconds
, &ts
, 2);
2888 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2892 gfc_resolve_cpu_time (gfc_code
*c
)
2895 name
= gfc_get_string (PREFIX ("cpu_time_%d"), c
->ext
.actual
->expr
->ts
.kind
);
2896 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2900 /* Create a formal arglist based on an actual one and set the INTENTs given. */
2902 static gfc_formal_arglist
*
2903 create_formal_for_intents (gfc_actual_arglist
* actual
, const sym_intent
* ints
)
2905 gfc_formal_arglist
* head
;
2906 gfc_formal_arglist
* tail
;
2912 head
= tail
= gfc_get_formal_arglist ();
2913 for (i
= 0; actual
; actual
= actual
->next
, tail
= tail
->next
, ++i
)
2917 sym
= gfc_new_symbol ("dummyarg", NULL
);
2918 sym
->ts
= actual
->expr
->ts
;
2920 sym
->attr
.intent
= ints
[i
];
2924 tail
->next
= gfc_get_formal_arglist ();
2932 gfc_resolve_atomic_def (gfc_code
*c
)
2934 const char *name
= "atomic_define";
2935 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2940 gfc_resolve_atomic_ref (gfc_code
*c
)
2942 const char *name
= "atomic_ref";
2943 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2948 gfc_resolve_mvbits (gfc_code
*c
)
2950 static const sym_intent INTENTS
[] = {INTENT_IN
, INTENT_IN
, INTENT_IN
,
2951 INTENT_INOUT
, INTENT_IN
};
2957 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2958 they will be converted so that they fit into a C int. */
2959 ts
.type
= BT_INTEGER
;
2960 ts
.kind
= gfc_c_int_kind
;
2961 if (c
->ext
.actual
->next
->expr
->ts
.kind
!= gfc_c_int_kind
)
2962 gfc_convert_type (c
->ext
.actual
->next
->expr
, &ts
, 2);
2963 if (c
->ext
.actual
->next
->next
->expr
->ts
.kind
!= gfc_c_int_kind
)
2964 gfc_convert_type (c
->ext
.actual
->next
->next
->expr
, &ts
, 2);
2965 if (c
->ext
.actual
->next
->next
->next
->next
->expr
->ts
.kind
!= gfc_c_int_kind
)
2966 gfc_convert_type (c
->ext
.actual
->next
->next
->next
->next
->expr
, &ts
, 2);
2968 /* TO and FROM are guaranteed to have the same kind parameter. */
2969 name
= gfc_get_string (PREFIX ("mvbits_i%d"),
2970 c
->ext
.actual
->expr
->ts
.kind
);
2971 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2972 /* Mark as elemental subroutine as this does not happen automatically. */
2973 c
->resolved_sym
->attr
.elemental
= 1;
2975 /* Create a dummy formal arglist so the INTENTs are known later for purpose
2976 of creating temporaries. */
2977 c
->resolved_sym
->formal
= create_formal_for_intents (c
->ext
.actual
, INTENTS
);
2982 gfc_resolve_random_number (gfc_code
*c
)
2987 kind
= c
->ext
.actual
->expr
->ts
.kind
;
2988 if (c
->ext
.actual
->expr
->rank
== 0)
2989 name
= gfc_get_string (PREFIX ("random_r%d"), kind
);
2991 name
= gfc_get_string (PREFIX ("arandom_r%d"), kind
);
2993 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2998 gfc_resolve_random_seed (gfc_code
*c
)
3002 name
= gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind
);
3003 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3008 gfc_resolve_rename_sub (gfc_code
*c
)
3013 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
3014 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
3016 kind
= gfc_default_integer_kind
;
3018 name
= gfc_get_string (PREFIX ("rename_i%d_sub"), kind
);
3019 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3024 gfc_resolve_kill_sub (gfc_code
*c
)
3029 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
3030 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
3032 kind
= gfc_default_integer_kind
;
3034 name
= gfc_get_string (PREFIX ("kill_i%d_sub"), kind
);
3035 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3040 gfc_resolve_link_sub (gfc_code
*c
)
3045 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
3046 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
3048 kind
= gfc_default_integer_kind
;
3050 name
= gfc_get_string (PREFIX ("link_i%d_sub"), kind
);
3051 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3056 gfc_resolve_symlnk_sub (gfc_code
*c
)
3061 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
3062 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
3064 kind
= gfc_default_integer_kind
;
3066 name
= gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind
);
3067 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3071 /* G77 compatibility subroutines dtime() and etime(). */
3074 gfc_resolve_dtime_sub (gfc_code
*c
)
3077 name
= gfc_get_string (PREFIX ("dtime_sub"));
3078 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3082 gfc_resolve_etime_sub (gfc_code
*c
)
3085 name
= gfc_get_string (PREFIX ("etime_sub"));
3086 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3090 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
3093 gfc_resolve_itime (gfc_code
*c
)
3096 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
3097 gfc_default_integer_kind
));
3101 gfc_resolve_idate (gfc_code
*c
)
3104 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
3105 gfc_default_integer_kind
));
3109 gfc_resolve_ltime (gfc_code
*c
)
3112 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
3113 gfc_default_integer_kind
));
3117 gfc_resolve_gmtime (gfc_code
*c
)
3120 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
3121 gfc_default_integer_kind
));
3125 /* G77 compatibility subroutine second(). */
3128 gfc_resolve_second_sub (gfc_code
*c
)
3131 name
= gfc_get_string (PREFIX ("second_sub"));
3132 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3137 gfc_resolve_sleep_sub (gfc_code
*c
)
3142 if (c
->ext
.actual
->expr
!= NULL
)
3143 kind
= c
->ext
.actual
->expr
->ts
.kind
;
3145 kind
= gfc_default_integer_kind
;
3147 name
= gfc_get_string (PREFIX ("sleep_i%d_sub"), kind
);
3148 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3152 /* G77 compatibility function srand(). */
3155 gfc_resolve_srand (gfc_code
*c
)
3158 name
= gfc_get_string (PREFIX ("srand"));
3159 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3163 /* Resolve the getarg intrinsic subroutine. */
3166 gfc_resolve_getarg (gfc_code
*c
)
3170 if (c
->ext
.actual
->expr
->ts
.kind
!= gfc_default_integer_kind
)
3175 ts
.type
= BT_INTEGER
;
3176 ts
.kind
= gfc_default_integer_kind
;
3178 gfc_convert_type (c
->ext
.actual
->expr
, &ts
, 2);
3181 name
= gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind
);
3182 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3186 /* Resolve the getcwd intrinsic subroutine. */
3189 gfc_resolve_getcwd_sub (gfc_code
*c
)
3194 if (c
->ext
.actual
->next
->expr
!= NULL
)
3195 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3197 kind
= gfc_default_integer_kind
;
3199 name
= gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind
);
3200 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3204 /* Resolve the get_command intrinsic subroutine. */
3207 gfc_resolve_get_command (gfc_code
*c
)
3211 kind
= gfc_default_integer_kind
;
3212 name
= gfc_get_string (PREFIX ("get_command_i%d"), kind
);
3213 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3217 /* Resolve the get_command_argument intrinsic subroutine. */
3220 gfc_resolve_get_command_argument (gfc_code
*c
)
3224 kind
= gfc_default_integer_kind
;
3225 name
= gfc_get_string (PREFIX ("get_command_argument_i%d"), kind
);
3226 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3230 /* Resolve the get_environment_variable intrinsic subroutine. */
3233 gfc_resolve_get_environment_variable (gfc_code
*code
)
3237 kind
= gfc_default_integer_kind
;
3238 name
= gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind
);
3239 code
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3244 gfc_resolve_signal_sub (gfc_code
*c
)
3247 gfc_expr
*number
, *handler
, *status
;
3251 number
= c
->ext
.actual
->expr
;
3252 handler
= c
->ext
.actual
->next
->expr
;
3253 status
= c
->ext
.actual
->next
->next
->expr
;
3254 ts
.type
= BT_INTEGER
;
3255 ts
.kind
= gfc_c_int_kind
;
3257 /* handler can be either BT_INTEGER or BT_PROCEDURE */
3258 if (handler
->ts
.type
== BT_INTEGER
)
3260 if (handler
->ts
.kind
!= gfc_c_int_kind
)
3261 gfc_convert_type (handler
, &ts
, 2);
3262 name
= gfc_get_string (PREFIX ("signal_sub_int"));
3265 name
= gfc_get_string (PREFIX ("signal_sub"));
3267 if (number
->ts
.kind
!= gfc_c_int_kind
)
3268 gfc_convert_type (number
, &ts
, 2);
3269 if (status
!= NULL
&& status
->ts
.kind
!= gfc_c_int_kind
)
3270 gfc_convert_type (status
, &ts
, 2);
3272 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3276 /* Resolve the SYSTEM intrinsic subroutine. */
3279 gfc_resolve_system_sub (gfc_code
*c
)
3282 name
= gfc_get_string (PREFIX ("system_sub"));
3283 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3287 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
3290 gfc_resolve_system_clock (gfc_code
*c
)
3295 if (c
->ext
.actual
->expr
!= NULL
)
3296 kind
= c
->ext
.actual
->expr
->ts
.kind
;
3297 else if (c
->ext
.actual
->next
->expr
!= NULL
)
3298 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3299 else if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
3300 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
3302 kind
= gfc_default_integer_kind
;
3304 name
= gfc_get_string (PREFIX ("system_clock_%d"), kind
);
3305 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3309 /* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine. */
3311 gfc_resolve_execute_command_line (gfc_code
*c
)
3314 name
= gfc_get_string (PREFIX ("execute_command_line_i%d"),
3315 gfc_default_integer_kind
);
3316 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3320 /* Resolve the EXIT intrinsic subroutine. */
3323 gfc_resolve_exit (gfc_code
*c
)
3330 /* The STATUS argument has to be of default kind. If it is not,
3332 ts
.type
= BT_INTEGER
;
3333 ts
.kind
= gfc_default_integer_kind
;
3334 n
= c
->ext
.actual
->expr
;
3335 if (n
!= NULL
&& n
->ts
.kind
!= ts
.kind
)
3336 gfc_convert_type (n
, &ts
, 2);
3338 name
= gfc_get_string (PREFIX ("exit_i%d"), ts
.kind
);
3339 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3343 /* Resolve the FLUSH intrinsic subroutine. */
3346 gfc_resolve_flush (gfc_code
*c
)
3353 ts
.type
= BT_INTEGER
;
3354 ts
.kind
= gfc_default_integer_kind
;
3355 n
= c
->ext
.actual
->expr
;
3356 if (n
!= NULL
&& n
->ts
.kind
!= ts
.kind
)
3357 gfc_convert_type (n
, &ts
, 2);
3359 name
= gfc_get_string (PREFIX ("flush_i%d"), ts
.kind
);
3360 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3365 gfc_resolve_free (gfc_code
*c
)
3371 ts
.type
= BT_INTEGER
;
3372 ts
.kind
= gfc_index_integer_kind
;
3373 n
= c
->ext
.actual
->expr
;
3374 if (n
->ts
.kind
!= ts
.kind
)
3375 gfc_convert_type (n
, &ts
, 2);
3377 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
3382 gfc_resolve_ctime_sub (gfc_code
*c
)
3387 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3388 if (c
->ext
.actual
->expr
->ts
.kind
!= 8)
3390 ts
.type
= BT_INTEGER
;
3392 ts
.u
.derived
= NULL
;
3394 gfc_convert_type (c
->ext
.actual
->expr
, &ts
, 2);
3397 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3402 gfc_resolve_fdate_sub (gfc_code
*c
)
3404 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3409 gfc_resolve_gerror (gfc_code
*c
)
3411 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3416 gfc_resolve_getlog (gfc_code
*c
)
3418 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3423 gfc_resolve_hostnm_sub (gfc_code
*c
)
3428 if (c
->ext
.actual
->next
->expr
!= NULL
)
3429 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3431 kind
= gfc_default_integer_kind
;
3433 name
= gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind
);
3434 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3439 gfc_resolve_perror (gfc_code
*c
)
3441 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3444 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3447 gfc_resolve_stat_sub (gfc_code
*c
)
3450 name
= gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind
);
3451 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3456 gfc_resolve_lstat_sub (gfc_code
*c
)
3459 name
= gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind
);
3460 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3465 gfc_resolve_fstat_sub (gfc_code
*c
)
3471 u
= c
->ext
.actual
->expr
;
3472 ts
= &c
->ext
.actual
->next
->expr
->ts
;
3473 if (u
->ts
.kind
!= ts
->kind
)
3474 gfc_convert_type (u
, ts
, 2);
3475 name
= gfc_get_string (PREFIX ("fstat_i%d_sub"), ts
->kind
);
3476 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3481 gfc_resolve_fgetc_sub (gfc_code
*c
)
3488 u
= c
->ext
.actual
->expr
;
3489 st
= c
->ext
.actual
->next
->next
->expr
;
3491 if (u
->ts
.kind
!= gfc_c_int_kind
)
3493 ts
.type
= BT_INTEGER
;
3494 ts
.kind
= gfc_c_int_kind
;
3495 ts
.u
.derived
= NULL
;
3497 gfc_convert_type (u
, &ts
, 2);
3501 name
= gfc_get_string (PREFIX ("fgetc_i%d_sub"), st
->ts
.kind
);
3503 name
= gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind
);
3505 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3510 gfc_resolve_fget_sub (gfc_code
*c
)
3515 st
= c
->ext
.actual
->next
->expr
;
3517 name
= gfc_get_string (PREFIX ("fget_i%d_sub"), st
->ts
.kind
);
3519 name
= gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind
);
3521 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3526 gfc_resolve_fputc_sub (gfc_code
*c
)
3533 u
= c
->ext
.actual
->expr
;
3534 st
= c
->ext
.actual
->next
->next
->expr
;
3536 if (u
->ts
.kind
!= gfc_c_int_kind
)
3538 ts
.type
= BT_INTEGER
;
3539 ts
.kind
= gfc_c_int_kind
;
3540 ts
.u
.derived
= NULL
;
3542 gfc_convert_type (u
, &ts
, 2);
3546 name
= gfc_get_string (PREFIX ("fputc_i%d_sub"), st
->ts
.kind
);
3548 name
= gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind
);
3550 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3555 gfc_resolve_fput_sub (gfc_code
*c
)
3560 st
= c
->ext
.actual
->next
->expr
;
3562 name
= gfc_get_string (PREFIX ("fput_i%d_sub"), st
->ts
.kind
);
3564 name
= gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind
);
3566 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3571 gfc_resolve_fseek_sub (gfc_code
*c
)
3579 unit
= c
->ext
.actual
->expr
;
3580 offset
= c
->ext
.actual
->next
->expr
;
3581 whence
= c
->ext
.actual
->next
->next
->expr
;
3583 if (unit
->ts
.kind
!= gfc_c_int_kind
)
3585 ts
.type
= BT_INTEGER
;
3586 ts
.kind
= gfc_c_int_kind
;
3587 ts
.u
.derived
= NULL
;
3589 gfc_convert_type (unit
, &ts
, 2);
3592 if (offset
->ts
.kind
!= gfc_intio_kind
)
3594 ts
.type
= BT_INTEGER
;
3595 ts
.kind
= gfc_intio_kind
;
3596 ts
.u
.derived
= NULL
;
3598 gfc_convert_type (offset
, &ts
, 2);
3601 if (whence
->ts
.kind
!= gfc_c_int_kind
)
3603 ts
.type
= BT_INTEGER
;
3604 ts
.kind
= gfc_c_int_kind
;
3605 ts
.u
.derived
= NULL
;
3607 gfc_convert_type (whence
, &ts
, 2);
3610 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3614 gfc_resolve_ftell_sub (gfc_code
*c
)
3622 unit
= c
->ext
.actual
->expr
;
3623 offset
= c
->ext
.actual
->next
->expr
;
3625 if (unit
->ts
.kind
!= gfc_c_int_kind
)
3627 ts
.type
= BT_INTEGER
;
3628 ts
.kind
= gfc_c_int_kind
;
3629 ts
.u
.derived
= NULL
;
3631 gfc_convert_type (unit
, &ts
, 2);
3634 name
= gfc_get_string (PREFIX ("ftell_i%d_sub"), offset
->ts
.kind
);
3635 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3640 gfc_resolve_ttynam_sub (gfc_code
*c
)
3645 if (c
->ext
.actual
->expr
->ts
.kind
!= gfc_c_int_kind
)
3647 ts
.type
= BT_INTEGER
;
3648 ts
.kind
= gfc_c_int_kind
;
3649 ts
.u
.derived
= NULL
;
3651 gfc_convert_type (c
->ext
.actual
->expr
, &ts
, 2);
3654 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3658 /* Resolve the UMASK intrinsic subroutine. */
3661 gfc_resolve_umask_sub (gfc_code
*c
)
3666 if (c
->ext
.actual
->next
->expr
!= NULL
)
3667 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3669 kind
= gfc_default_integer_kind
;
3671 name
= gfc_get_string (PREFIX ("umask_i%d_sub"), kind
);
3672 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3675 /* Resolve the UNLINK intrinsic subroutine. */
3678 gfc_resolve_unlink_sub (gfc_code
*c
)
3683 if (c
->ext
.actual
->next
->expr
!= NULL
)
3684 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3686 kind
= gfc_default_integer_kind
;
3688 name
= gfc_get_string (PREFIX ("unlink_i%d_sub"), kind
);
3689 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);