1 /* Intrinsic function resolution.
2 Copyright (C) 2000-2015 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"
35 #include "double-int.h"
43 #include "stringpool.h"
45 #include "intrinsic.h"
46 #include "constructor.h"
49 /* Given printf-like arguments, return a stable version of the result string.
51 We already have a working, optimized string hashing table in the form of
52 the identifier table. Reusing this table is likely not to be wasted,
53 since if the function name makes it to the gimple output of the frontend,
54 we'll have to create the identifier anyway. */
57 gfc_get_string (const char *format
, ...)
63 va_start (ap
, format
);
64 vsnprintf (temp_name
, sizeof (temp_name
), format
, ap
);
66 temp_name
[sizeof (temp_name
) - 1] = 0;
68 ident
= get_identifier (temp_name
);
69 return IDENTIFIER_POINTER (ident
);
72 /* MERGE and SPREAD need to have source charlen's present for passing
73 to the result expression. */
75 check_charlen_present (gfc_expr
*source
)
77 if (source
->ts
.u
.cl
== NULL
)
78 source
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
80 if (source
->expr_type
== EXPR_CONSTANT
)
82 source
->ts
.u
.cl
->length
83 = gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
84 source
->value
.character
.length
);
87 else if (source
->expr_type
== EXPR_ARRAY
)
89 gfc_constructor
*c
= gfc_constructor_first (source
->value
.constructor
);
90 source
->ts
.u
.cl
->length
91 = gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
92 c
->expr
->value
.character
.length
);
96 /* Helper function for resolving the "mask" argument. */
99 resolve_mask_arg (gfc_expr
*mask
)
107 /* For the scalar case, coerce the mask to kind=4 unconditionally
108 (because this is the only kind we have a library function
111 if (mask
->ts
.kind
!= 4)
113 ts
.type
= BT_LOGICAL
;
115 gfc_convert_type (mask
, &ts
, 2);
120 /* In the library, we access the mask with a GFC_LOGICAL_1
121 argument. No need to waste memory if we are about to create
122 a temporary array. */
123 if (mask
->expr_type
== EXPR_OP
&& mask
->ts
.kind
!= 1)
125 ts
.type
= BT_LOGICAL
;
127 gfc_convert_type_warn (mask
, &ts
, 2, 0);
134 resolve_bound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
,
135 const char *name
, bool coarray
)
137 f
->ts
.type
= BT_INTEGER
;
139 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
141 f
->ts
.kind
= gfc_default_integer_kind
;
146 if (array
->rank
!= -1)
148 f
->shape
= gfc_get_shape (1);
149 mpz_init_set_ui (f
->shape
[0], coarray
? gfc_get_corank (array
)
154 f
->value
.function
.name
= gfc_get_string (name
);
159 resolve_transformational (const char *name
, gfc_expr
*f
, gfc_expr
*array
,
160 gfc_expr
*dim
, gfc_expr
*mask
)
173 resolve_mask_arg (mask
);
180 f
->rank
= array
->rank
- 1;
181 f
->shape
= gfc_copy_shape_excluding (array
->shape
, array
->rank
, dim
);
182 gfc_resolve_dim_arg (dim
);
185 f
->value
.function
.name
186 = gfc_get_string (PREFIX ("%s%s_%c%d"), prefix
, name
,
187 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
191 /********************** Resolution functions **********************/
195 gfc_resolve_abs (gfc_expr
*f
, gfc_expr
*a
)
198 if (f
->ts
.type
== BT_COMPLEX
)
199 f
->ts
.type
= BT_REAL
;
201 f
->value
.function
.name
202 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
207 gfc_resolve_access (gfc_expr
*f
, gfc_expr
*name ATTRIBUTE_UNUSED
,
208 gfc_expr
*mode ATTRIBUTE_UNUSED
)
210 f
->ts
.type
= BT_INTEGER
;
211 f
->ts
.kind
= gfc_c_int_kind
;
212 f
->value
.function
.name
= PREFIX ("access_func");
217 gfc_resolve_adjustl (gfc_expr
*f
, gfc_expr
*string
)
219 f
->ts
.type
= BT_CHARACTER
;
220 f
->ts
.kind
= string
->ts
.kind
;
221 f
->value
.function
.name
= gfc_get_string ("__adjustl_s%d", f
->ts
.kind
);
226 gfc_resolve_adjustr (gfc_expr
*f
, gfc_expr
*string
)
228 f
->ts
.type
= BT_CHARACTER
;
229 f
->ts
.kind
= string
->ts
.kind
;
230 f
->value
.function
.name
= gfc_get_string ("__adjustr_s%d", f
->ts
.kind
);
235 gfc_resolve_char_achar (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*kind
,
238 f
->ts
.type
= BT_CHARACTER
;
239 f
->ts
.kind
= (kind
== NULL
)
240 ? gfc_default_character_kind
: mpz_get_si (kind
->value
.integer
);
241 f
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
242 f
->ts
.u
.cl
->length
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
244 f
->value
.function
.name
= gfc_get_string (name
, f
->ts
.kind
,
245 gfc_type_letter (x
->ts
.type
),
251 gfc_resolve_achar (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*kind
)
253 gfc_resolve_char_achar (f
, x
, kind
, "__achar_%d_%c%d");
258 gfc_resolve_acos (gfc_expr
*f
, gfc_expr
*x
)
261 f
->value
.function
.name
262 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
267 gfc_resolve_acosh (gfc_expr
*f
, gfc_expr
*x
)
270 f
->value
.function
.name
271 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x
->ts
.type
),
277 gfc_resolve_aimag (gfc_expr
*f
, gfc_expr
*x
)
279 f
->ts
.type
= BT_REAL
;
280 f
->ts
.kind
= x
->ts
.kind
;
281 f
->value
.function
.name
282 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x
->ts
.type
),
288 gfc_resolve_and (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
290 f
->ts
.type
= i
->ts
.type
;
291 f
->ts
.kind
= gfc_kind_max (i
, j
);
293 if (i
->ts
.kind
!= j
->ts
.kind
)
295 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
296 gfc_convert_type (j
, &i
->ts
, 2);
298 gfc_convert_type (i
, &j
->ts
, 2);
301 f
->value
.function
.name
302 = gfc_get_string ("__and_%c%d", gfc_type_letter (i
->ts
.type
), f
->ts
.kind
);
307 gfc_resolve_aint (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
312 f
->ts
.type
= a
->ts
.type
;
313 f
->ts
.kind
= (kind
== NULL
) ? a
->ts
.kind
: mpz_get_si (kind
->value
.integer
);
315 if (a
->ts
.kind
!= f
->ts
.kind
)
317 ts
.type
= f
->ts
.type
;
318 ts
.kind
= f
->ts
.kind
;
319 gfc_convert_type (a
, &ts
, 2);
321 /* The resolved name is only used for specific intrinsics where
322 the return kind is the same as the arg kind. */
323 f
->value
.function
.name
324 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
329 gfc_resolve_dint (gfc_expr
*f
, gfc_expr
*a
)
331 gfc_resolve_aint (f
, a
, NULL
);
336 gfc_resolve_all (gfc_expr
*f
, gfc_expr
*mask
, gfc_expr
*dim
)
342 gfc_resolve_dim_arg (dim
);
343 f
->rank
= mask
->rank
- 1;
344 f
->shape
= gfc_copy_shape_excluding (mask
->shape
, mask
->rank
, dim
);
347 f
->value
.function
.name
348 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask
->ts
.type
),
354 gfc_resolve_anint (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
359 f
->ts
.type
= a
->ts
.type
;
360 f
->ts
.kind
= (kind
== NULL
) ? a
->ts
.kind
: mpz_get_si (kind
->value
.integer
);
362 if (a
->ts
.kind
!= f
->ts
.kind
)
364 ts
.type
= f
->ts
.type
;
365 ts
.kind
= f
->ts
.kind
;
366 gfc_convert_type (a
, &ts
, 2);
369 /* The resolved name is only used for specific intrinsics where
370 the return kind is the same as the arg kind. */
371 f
->value
.function
.name
372 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a
->ts
.type
),
378 gfc_resolve_dnint (gfc_expr
*f
, gfc_expr
*a
)
380 gfc_resolve_anint (f
, a
, NULL
);
385 gfc_resolve_any (gfc_expr
*f
, gfc_expr
*mask
, gfc_expr
*dim
)
391 gfc_resolve_dim_arg (dim
);
392 f
->rank
= mask
->rank
- 1;
393 f
->shape
= gfc_copy_shape_excluding (mask
->shape
, mask
->rank
, dim
);
396 f
->value
.function
.name
397 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask
->ts
.type
),
403 gfc_resolve_asin (gfc_expr
*f
, gfc_expr
*x
)
406 f
->value
.function
.name
407 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
411 gfc_resolve_asinh (gfc_expr
*f
, gfc_expr
*x
)
414 f
->value
.function
.name
415 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x
->ts
.type
),
420 gfc_resolve_atan (gfc_expr
*f
, gfc_expr
*x
)
423 f
->value
.function
.name
424 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
428 gfc_resolve_atanh (gfc_expr
*f
, gfc_expr
*x
)
431 f
->value
.function
.name
432 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x
->ts
.type
),
437 gfc_resolve_atan2 (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*y ATTRIBUTE_UNUSED
)
440 f
->value
.function
.name
441 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x
->ts
.type
),
446 /* Resolve the BESYN and BESJN intrinsics. */
449 gfc_resolve_besn (gfc_expr
*f
, gfc_expr
*n
, gfc_expr
*x
)
455 if (n
->ts
.kind
!= gfc_c_int_kind
)
457 ts
.type
= BT_INTEGER
;
458 ts
.kind
= gfc_c_int_kind
;
459 gfc_convert_type (n
, &ts
, 2);
461 f
->value
.function
.name
= gfc_get_string ("<intrinsic>");
466 gfc_resolve_bessel_n2 (gfc_expr
*f
, gfc_expr
*n1
, gfc_expr
*n2
, gfc_expr
*x
)
473 if (n1
->expr_type
== EXPR_CONSTANT
&& n2
->expr_type
== EXPR_CONSTANT
)
475 f
->shape
= gfc_get_shape (1);
476 mpz_init (f
->shape
[0]);
477 mpz_sub (f
->shape
[0], n2
->value
.integer
, n1
->value
.integer
);
478 mpz_add_ui (f
->shape
[0], f
->shape
[0], 1);
481 if (n1
->ts
.kind
!= gfc_c_int_kind
)
483 ts
.type
= BT_INTEGER
;
484 ts
.kind
= gfc_c_int_kind
;
485 gfc_convert_type (n1
, &ts
, 2);
488 if (n2
->ts
.kind
!= gfc_c_int_kind
)
490 ts
.type
= BT_INTEGER
;
491 ts
.kind
= gfc_c_int_kind
;
492 gfc_convert_type (n2
, &ts
, 2);
495 if (f
->value
.function
.isym
->id
== GFC_ISYM_JN2
)
496 f
->value
.function
.name
= gfc_get_string (PREFIX ("bessel_jn_r%d"),
499 f
->value
.function
.name
= gfc_get_string (PREFIX ("bessel_yn_r%d"),
505 gfc_resolve_btest (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*pos
)
507 f
->ts
.type
= BT_LOGICAL
;
508 f
->ts
.kind
= gfc_default_logical_kind
;
509 f
->value
.function
.name
510 = gfc_get_string ("__btest_%d_%d", i
->ts
.kind
, pos
->ts
.kind
);
515 gfc_resolve_c_loc (gfc_expr
*f
, gfc_expr
*x ATTRIBUTE_UNUSED
)
517 f
->ts
= f
->value
.function
.isym
->ts
;
522 gfc_resolve_c_funloc (gfc_expr
*f
, gfc_expr
*x ATTRIBUTE_UNUSED
)
524 f
->ts
= f
->value
.function
.isym
->ts
;
529 gfc_resolve_ceiling (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
531 f
->ts
.type
= BT_INTEGER
;
532 f
->ts
.kind
= (kind
== NULL
)
533 ? gfc_default_integer_kind
: mpz_get_si (kind
->value
.integer
);
534 f
->value
.function
.name
535 = gfc_get_string ("__ceiling_%d_%c%d", f
->ts
.kind
,
536 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
541 gfc_resolve_char (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
543 gfc_resolve_char_achar (f
, a
, kind
, "__char_%d_%c%d");
548 gfc_resolve_chdir (gfc_expr
*f
, gfc_expr
*d ATTRIBUTE_UNUSED
)
550 f
->ts
.type
= BT_INTEGER
;
551 f
->ts
.kind
= gfc_default_integer_kind
;
552 f
->value
.function
.name
= gfc_get_string (PREFIX ("chdir_i%d"), f
->ts
.kind
);
557 gfc_resolve_chdir_sub (gfc_code
*c
)
562 if (c
->ext
.actual
->next
->expr
!= NULL
)
563 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
565 kind
= gfc_default_integer_kind
;
567 name
= gfc_get_string (PREFIX ("chdir_i%d_sub"), kind
);
568 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
573 gfc_resolve_chmod (gfc_expr
*f
, gfc_expr
*name ATTRIBUTE_UNUSED
,
574 gfc_expr
*mode ATTRIBUTE_UNUSED
)
576 f
->ts
.type
= BT_INTEGER
;
577 f
->ts
.kind
= gfc_c_int_kind
;
578 f
->value
.function
.name
= PREFIX ("chmod_func");
583 gfc_resolve_chmod_sub (gfc_code
*c
)
588 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
589 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
591 kind
= gfc_default_integer_kind
;
593 name
= gfc_get_string (PREFIX ("chmod_i%d_sub"), kind
);
594 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
599 gfc_resolve_cmplx (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*kind
)
601 f
->ts
.type
= BT_COMPLEX
;
602 f
->ts
.kind
= (kind
== NULL
)
603 ? gfc_default_real_kind
: mpz_get_si (kind
->value
.integer
);
606 f
->value
.function
.name
607 = gfc_get_string ("__cmplx0_%d_%c%d", f
->ts
.kind
,
608 gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
610 f
->value
.function
.name
611 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f
->ts
.kind
,
612 gfc_type_letter (x
->ts
.type
), x
->ts
.kind
,
613 gfc_type_letter (y
->ts
.type
), y
->ts
.kind
);
618 gfc_resolve_dcmplx (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*y
)
620 gfc_resolve_cmplx (f
, x
, y
, gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
621 gfc_default_double_kind
));
626 gfc_resolve_complex (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*y
)
630 if (x
->ts
.type
== BT_INTEGER
)
632 if (y
->ts
.type
== BT_INTEGER
)
633 kind
= gfc_default_real_kind
;
639 if (y
->ts
.type
== BT_REAL
)
640 kind
= (x
->ts
.kind
> y
->ts
.kind
) ? x
->ts
.kind
: y
->ts
.kind
;
645 f
->ts
.type
= BT_COMPLEX
;
647 f
->value
.function
.name
648 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f
->ts
.kind
,
649 gfc_type_letter (x
->ts
.type
), x
->ts
.kind
,
650 gfc_type_letter (y
->ts
.type
), y
->ts
.kind
);
655 gfc_resolve_conjg (gfc_expr
*f
, gfc_expr
*x
)
658 f
->value
.function
.name
= gfc_get_string ("__conjg_%d", x
->ts
.kind
);
663 gfc_resolve_cos (gfc_expr
*f
, gfc_expr
*x
)
666 f
->value
.function
.name
667 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
672 gfc_resolve_cosh (gfc_expr
*f
, gfc_expr
*x
)
675 f
->value
.function
.name
676 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
681 gfc_resolve_count (gfc_expr
*f
, gfc_expr
*mask
, gfc_expr
*dim
, gfc_expr
*kind
)
683 f
->ts
.type
= BT_INTEGER
;
685 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
687 f
->ts
.kind
= gfc_default_integer_kind
;
691 f
->rank
= mask
->rank
- 1;
692 gfc_resolve_dim_arg (dim
);
693 f
->shape
= gfc_copy_shape_excluding (mask
->shape
, mask
->rank
, dim
);
696 resolve_mask_arg (mask
);
698 f
->value
.function
.name
699 = gfc_get_string (PREFIX ("count_%d_%c"), f
->ts
.kind
,
700 gfc_type_letter (mask
->ts
.type
));
705 gfc_resolve_cshift (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*shift
,
710 if (array
->ts
.type
== BT_CHARACTER
&& array
->ref
)
711 gfc_resolve_substring_charlen (array
);
714 f
->rank
= array
->rank
;
715 f
->shape
= gfc_copy_shape (array
->shape
, array
->rank
);
722 /* If dim kind is greater than default integer we need to use the larger. */
723 m
= gfc_default_integer_kind
;
725 m
= m
< dim
->ts
.kind
? dim
->ts
.kind
: m
;
727 /* Convert shift to at least m, so we don't need
728 kind=1 and kind=2 versions of the library functions. */
729 if (shift
->ts
.kind
< m
)
733 ts
.type
= BT_INTEGER
;
735 gfc_convert_type_warn (shift
, &ts
, 2, 0);
740 if (dim
->expr_type
!= EXPR_CONSTANT
&& dim
->symtree
!= NULL
741 && dim
->symtree
->n
.sym
->attr
.optional
)
743 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
744 dim
->representation
.length
= shift
->ts
.kind
;
748 gfc_resolve_dim_arg (dim
);
749 /* Convert dim to shift's kind to reduce variations. */
750 if (dim
->ts
.kind
!= shift
->ts
.kind
)
751 gfc_convert_type_warn (dim
, &shift
->ts
, 2, 0);
755 if (array
->ts
.type
== BT_CHARACTER
)
757 if (array
->ts
.kind
== gfc_default_character_kind
)
758 f
->value
.function
.name
759 = gfc_get_string (PREFIX ("cshift%d_%d_char"), n
, shift
->ts
.kind
);
761 f
->value
.function
.name
762 = gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n
, shift
->ts
.kind
,
766 f
->value
.function
.name
767 = gfc_get_string (PREFIX ("cshift%d_%d"), n
, shift
->ts
.kind
);
772 gfc_resolve_ctime (gfc_expr
*f
, gfc_expr
*time
)
777 f
->ts
.type
= BT_CHARACTER
;
778 f
->ts
.kind
= gfc_default_character_kind
;
780 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
781 if (time
->ts
.kind
!= 8)
783 ts
.type
= BT_INTEGER
;
787 gfc_convert_type (time
, &ts
, 2);
790 f
->value
.function
.name
= gfc_get_string (PREFIX ("ctime"));
795 gfc_resolve_dble (gfc_expr
*f
, gfc_expr
*a
)
797 f
->ts
.type
= BT_REAL
;
798 f
->ts
.kind
= gfc_default_double_kind
;
799 f
->value
.function
.name
800 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
805 gfc_resolve_dim (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*p
)
807 f
->ts
.type
= a
->ts
.type
;
809 f
->ts
.kind
= gfc_kind_max (a
,p
);
811 f
->ts
.kind
= a
->ts
.kind
;
813 if (p
!= NULL
&& a
->ts
.kind
!= p
->ts
.kind
)
815 if (a
->ts
.kind
== gfc_kind_max (a
,p
))
816 gfc_convert_type (p
, &a
->ts
, 2);
818 gfc_convert_type (a
, &p
->ts
, 2);
821 f
->value
.function
.name
822 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f
->ts
.type
), f
->ts
.kind
);
827 gfc_resolve_dot_product (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*b
)
831 temp
.expr_type
= EXPR_OP
;
832 gfc_clear_ts (&temp
.ts
);
833 temp
.value
.op
.op
= INTRINSIC_NONE
;
834 temp
.value
.op
.op1
= a
;
835 temp
.value
.op
.op2
= b
;
836 gfc_type_convert_binary (&temp
, 1);
838 f
->value
.function
.name
839 = gfc_get_string (PREFIX ("dot_product_%c%d"),
840 gfc_type_letter (f
->ts
.type
), f
->ts
.kind
);
845 gfc_resolve_dprod (gfc_expr
*f
, gfc_expr
*a ATTRIBUTE_UNUSED
,
846 gfc_expr
*b ATTRIBUTE_UNUSED
)
848 f
->ts
.kind
= gfc_default_double_kind
;
849 f
->ts
.type
= BT_REAL
;
850 f
->value
.function
.name
= gfc_get_string ("__dprod_r%d", f
->ts
.kind
);
855 gfc_resolve_dshift (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j ATTRIBUTE_UNUSED
,
856 gfc_expr
*shift ATTRIBUTE_UNUSED
)
859 if (f
->value
.function
.isym
->id
== GFC_ISYM_DSHIFTL
)
860 f
->value
.function
.name
= gfc_get_string ("dshiftl_i%d", f
->ts
.kind
);
861 else if (f
->value
.function
.isym
->id
== GFC_ISYM_DSHIFTR
)
862 f
->value
.function
.name
= gfc_get_string ("dshiftr_i%d", f
->ts
.kind
);
869 gfc_resolve_eoshift (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*shift
,
870 gfc_expr
*boundary
, gfc_expr
*dim
)
874 if (array
->ts
.type
== BT_CHARACTER
&& array
->ref
)
875 gfc_resolve_substring_charlen (array
);
878 f
->rank
= array
->rank
;
879 f
->shape
= gfc_copy_shape (array
->shape
, array
->rank
);
884 if (boundary
&& boundary
->rank
> 0)
887 /* If dim kind is greater than default integer we need to use the larger. */
888 m
= gfc_default_integer_kind
;
890 m
= m
< dim
->ts
.kind
? dim
->ts
.kind
: m
;
892 /* Convert shift to at least m, so we don't need
893 kind=1 and kind=2 versions of the library functions. */
894 if (shift
->ts
.kind
< m
)
898 ts
.type
= BT_INTEGER
;
900 gfc_convert_type_warn (shift
, &ts
, 2, 0);
905 if (dim
->expr_type
!= EXPR_CONSTANT
&& dim
->symtree
!= NULL
906 && dim
->symtree
->n
.sym
->attr
.optional
)
908 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
909 dim
->representation
.length
= shift
->ts
.kind
;
913 gfc_resolve_dim_arg (dim
);
914 /* Convert dim to shift's kind to reduce variations. */
915 if (dim
->ts
.kind
!= shift
->ts
.kind
)
916 gfc_convert_type_warn (dim
, &shift
->ts
, 2, 0);
920 if (array
->ts
.type
== BT_CHARACTER
)
922 if (array
->ts
.kind
== gfc_default_character_kind
)
923 f
->value
.function
.name
924 = gfc_get_string (PREFIX ("eoshift%d_%d_char"), n
, shift
->ts
.kind
);
926 f
->value
.function
.name
927 = gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n
, shift
->ts
.kind
,
931 f
->value
.function
.name
932 = gfc_get_string (PREFIX ("eoshift%d_%d"), n
, shift
->ts
.kind
);
937 gfc_resolve_exp (gfc_expr
*f
, gfc_expr
*x
)
940 f
->value
.function
.name
941 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
946 gfc_resolve_exponent (gfc_expr
*f
, gfc_expr
*x
)
948 f
->ts
.type
= BT_INTEGER
;
949 f
->ts
.kind
= gfc_default_integer_kind
;
950 f
->value
.function
.name
= gfc_get_string ("__exponent_%d", x
->ts
.kind
);
954 /* Resolve the EXTENDS_TYPE_OF intrinsic function. */
957 gfc_resolve_extends_type_of (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*mo
)
962 /* Prevent double resolution. */
963 if (f
->ts
.type
== BT_LOGICAL
)
966 /* Replace the first argument with the corresponding vtab. */
967 if (a
->ts
.type
== BT_CLASS
)
968 gfc_add_vptr_component (a
);
969 else if (a
->ts
.type
== BT_DERIVED
)
971 vtab
= gfc_find_derived_vtab (a
->ts
.u
.derived
);
972 /* Clear the old expr. */
973 gfc_free_ref_list (a
->ref
);
974 memset (a
, '\0', sizeof (gfc_expr
));
975 /* Construct a new one. */
976 a
->expr_type
= EXPR_VARIABLE
;
977 st
= gfc_find_symtree (vtab
->ns
->sym_root
, vtab
->name
);
982 /* Replace the second argument with the corresponding vtab. */
983 if (mo
->ts
.type
== BT_CLASS
)
984 gfc_add_vptr_component (mo
);
985 else if (mo
->ts
.type
== BT_DERIVED
)
987 vtab
= gfc_find_derived_vtab (mo
->ts
.u
.derived
);
988 /* Clear the old expr. */
989 gfc_free_ref_list (mo
->ref
);
990 memset (mo
, '\0', sizeof (gfc_expr
));
991 /* Construct a new one. */
992 mo
->expr_type
= EXPR_VARIABLE
;
993 st
= gfc_find_symtree (vtab
->ns
->sym_root
, vtab
->name
);
998 f
->ts
.type
= BT_LOGICAL
;
1001 f
->value
.function
.isym
->formal
->ts
= a
->ts
;
1002 f
->value
.function
.isym
->formal
->next
->ts
= mo
->ts
;
1004 /* Call library function. */
1005 f
->value
.function
.name
= gfc_get_string (PREFIX ("is_extension_of"));
1010 gfc_resolve_fdate (gfc_expr
*f
)
1012 f
->ts
.type
= BT_CHARACTER
;
1013 f
->ts
.kind
= gfc_default_character_kind
;
1014 f
->value
.function
.name
= gfc_get_string (PREFIX ("fdate"));
1019 gfc_resolve_floor (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
1021 f
->ts
.type
= BT_INTEGER
;
1022 f
->ts
.kind
= (kind
== NULL
)
1023 ? gfc_default_integer_kind
: mpz_get_si (kind
->value
.integer
);
1024 f
->value
.function
.name
1025 = gfc_get_string ("__floor%d_%c%d", f
->ts
.kind
,
1026 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1031 gfc_resolve_fnum (gfc_expr
*f
, gfc_expr
*n
)
1033 f
->ts
.type
= BT_INTEGER
;
1034 f
->ts
.kind
= gfc_default_integer_kind
;
1035 if (n
->ts
.kind
!= f
->ts
.kind
)
1036 gfc_convert_type (n
, &f
->ts
, 2);
1037 f
->value
.function
.name
= gfc_get_string (PREFIX ("fnum_i%d"), f
->ts
.kind
);
1042 gfc_resolve_fraction (gfc_expr
*f
, gfc_expr
*x
)
1045 f
->value
.function
.name
= gfc_get_string ("__fraction_%d", x
->ts
.kind
);
1049 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
1052 gfc_resolve_g77_math1 (gfc_expr
*f
, gfc_expr
*x
)
1055 f
->value
.function
.name
= gfc_get_string ("<intrinsic>");
1060 gfc_resolve_gamma (gfc_expr
*f
, gfc_expr
*x
)
1063 f
->value
.function
.name
1064 = gfc_get_string ("__tgamma_%d", x
->ts
.kind
);
1069 gfc_resolve_getcwd (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
)
1071 f
->ts
.type
= BT_INTEGER
;
1073 f
->value
.function
.name
= gfc_get_string (PREFIX ("getcwd"));
1078 gfc_resolve_getgid (gfc_expr
*f
)
1080 f
->ts
.type
= BT_INTEGER
;
1082 f
->value
.function
.name
= gfc_get_string (PREFIX ("getgid"));
1087 gfc_resolve_getpid (gfc_expr
*f
)
1089 f
->ts
.type
= BT_INTEGER
;
1091 f
->value
.function
.name
= gfc_get_string (PREFIX ("getpid"));
1096 gfc_resolve_getuid (gfc_expr
*f
)
1098 f
->ts
.type
= BT_INTEGER
;
1100 f
->value
.function
.name
= gfc_get_string (PREFIX ("getuid"));
1105 gfc_resolve_hostnm (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
)
1107 f
->ts
.type
= BT_INTEGER
;
1109 f
->value
.function
.name
= gfc_get_string (PREFIX ("hostnm"));
1114 gfc_resolve_hypot (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*y ATTRIBUTE_UNUSED
)
1117 f
->value
.function
.name
= gfc_get_string ("__hypot_r%d", x
->ts
.kind
);
1122 gfc_resolve_iall (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*mask
)
1124 resolve_transformational ("iall", f
, array
, dim
, mask
);
1129 gfc_resolve_iand (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
1131 /* If the kind of i and j are different, then g77 cross-promoted the
1132 kinds to the largest value. The Fortran 95 standard requires the
1134 if (i
->ts
.kind
!= j
->ts
.kind
)
1136 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
1137 gfc_convert_type (j
, &i
->ts
, 2);
1139 gfc_convert_type (i
, &j
->ts
, 2);
1143 f
->value
.function
.name
= gfc_get_string ("__iand_%d", i
->ts
.kind
);
1148 gfc_resolve_iany (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*mask
)
1150 resolve_transformational ("iany", f
, array
, dim
, mask
);
1155 gfc_resolve_ibclr (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*pos ATTRIBUTE_UNUSED
)
1158 f
->value
.function
.name
= gfc_get_string ("__ibclr_%d", i
->ts
.kind
);
1163 gfc_resolve_ibits (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*pos ATTRIBUTE_UNUSED
,
1164 gfc_expr
*len ATTRIBUTE_UNUSED
)
1167 f
->value
.function
.name
= gfc_get_string ("__ibits_%d", i
->ts
.kind
);
1172 gfc_resolve_ibset (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*pos ATTRIBUTE_UNUSED
)
1175 f
->value
.function
.name
= gfc_get_string ("__ibset_%d", i
->ts
.kind
);
1180 gfc_resolve_iachar (gfc_expr
*f
, gfc_expr
*c
, gfc_expr
*kind
)
1182 f
->ts
.type
= BT_INTEGER
;
1184 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1186 f
->ts
.kind
= gfc_default_integer_kind
;
1187 f
->value
.function
.name
= gfc_get_string ("__ichar_%d", c
->ts
.kind
);
1192 gfc_resolve_ichar (gfc_expr
*f
, gfc_expr
*c
, gfc_expr
*kind
)
1194 f
->ts
.type
= BT_INTEGER
;
1196 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1198 f
->ts
.kind
= gfc_default_integer_kind
;
1199 f
->value
.function
.name
= gfc_get_string ("__ichar_%d", c
->ts
.kind
);
1204 gfc_resolve_idnint (gfc_expr
*f
, gfc_expr
*a
)
1206 gfc_resolve_nint (f
, a
, NULL
);
1211 gfc_resolve_ierrno (gfc_expr
*f
)
1213 f
->ts
.type
= BT_INTEGER
;
1214 f
->ts
.kind
= gfc_default_integer_kind
;
1215 f
->value
.function
.name
= gfc_get_string (PREFIX ("ierrno_i%d"), f
->ts
.kind
);
1220 gfc_resolve_ieor (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
1222 /* If the kind of i and j are different, then g77 cross-promoted the
1223 kinds to the largest value. The Fortran 95 standard requires the
1225 if (i
->ts
.kind
!= j
->ts
.kind
)
1227 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
1228 gfc_convert_type (j
, &i
->ts
, 2);
1230 gfc_convert_type (i
, &j
->ts
, 2);
1234 f
->value
.function
.name
= gfc_get_string ("__ieor_%d", i
->ts
.kind
);
1239 gfc_resolve_ior (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
1241 /* If the kind of i and j are different, then g77 cross-promoted the
1242 kinds to the largest value. The Fortran 95 standard requires the
1244 if (i
->ts
.kind
!= j
->ts
.kind
)
1246 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
1247 gfc_convert_type (j
, &i
->ts
, 2);
1249 gfc_convert_type (i
, &j
->ts
, 2);
1253 f
->value
.function
.name
= gfc_get_string ("__ior_%d", i
->ts
.kind
);
1258 gfc_resolve_index_func (gfc_expr
*f
, gfc_expr
*str
,
1259 gfc_expr
*sub_str ATTRIBUTE_UNUSED
, gfc_expr
*back
,
1265 f
->ts
.type
= BT_INTEGER
;
1267 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1269 f
->ts
.kind
= gfc_default_integer_kind
;
1271 if (back
&& back
->ts
.kind
!= gfc_default_integer_kind
)
1273 ts
.type
= BT_LOGICAL
;
1274 ts
.kind
= gfc_default_integer_kind
;
1275 ts
.u
.derived
= NULL
;
1277 gfc_convert_type (back
, &ts
, 2);
1280 f
->value
.function
.name
1281 = gfc_get_string ("__index_%d_i%d", str
->ts
.kind
, f
->ts
.kind
);
1286 gfc_resolve_int (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
1288 f
->ts
.type
= BT_INTEGER
;
1289 f
->ts
.kind
= (kind
== NULL
)
1290 ? gfc_default_integer_kind
: mpz_get_si (kind
->value
.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_int2 (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_int8 (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_long (gfc_expr
*f
, gfc_expr
*a
)
1322 f
->ts
.type
= BT_INTEGER
;
1324 f
->value
.function
.name
1325 = gfc_get_string ("__int_%d_%c%d", f
->ts
.kind
,
1326 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1331 gfc_resolve_iparity (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*mask
)
1333 resolve_transformational ("iparity", f
, array
, dim
, mask
);
1338 gfc_resolve_isatty (gfc_expr
*f
, gfc_expr
*u
)
1343 f
->ts
.type
= BT_LOGICAL
;
1344 f
->ts
.kind
= gfc_default_integer_kind
;
1345 if (u
->ts
.kind
!= gfc_c_int_kind
)
1347 ts
.type
= BT_INTEGER
;
1348 ts
.kind
= gfc_c_int_kind
;
1349 ts
.u
.derived
= NULL
;
1351 gfc_convert_type (u
, &ts
, 2);
1354 f
->value
.function
.name
= gfc_get_string (PREFIX ("isatty_l%d"), f
->ts
.kind
);
1359 gfc_resolve_ishft (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift
)
1362 f
->value
.function
.name
1363 = gfc_get_string ("__ishft_%d_%d", i
->ts
.kind
, shift
->ts
.kind
);
1368 gfc_resolve_rshift (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift
)
1371 f
->value
.function
.name
1372 = gfc_get_string ("__rshift_%d_%d", i
->ts
.kind
, shift
->ts
.kind
);
1377 gfc_resolve_lshift (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift
)
1380 f
->value
.function
.name
1381 = gfc_get_string ("__lshift_%d_%d", i
->ts
.kind
, shift
->ts
.kind
);
1386 gfc_resolve_ishftc (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift
, gfc_expr
*size
)
1390 s_kind
= (size
== NULL
) ? gfc_default_integer_kind
: size
->ts
.kind
;
1393 f
->value
.function
.name
1394 = gfc_get_string ("__ishftc_%d_%d_%d", i
->ts
.kind
, shift
->ts
.kind
, s_kind
);
1399 gfc_resolve_kill (gfc_expr
*f
, gfc_expr
*p ATTRIBUTE_UNUSED
,
1400 gfc_expr
*s ATTRIBUTE_UNUSED
)
1402 f
->ts
.type
= BT_INTEGER
;
1403 f
->ts
.kind
= gfc_default_integer_kind
;
1404 f
->value
.function
.name
= gfc_get_string (PREFIX ("kill_i%d"), f
->ts
.kind
);
1409 gfc_resolve_lbound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
1411 resolve_bound (f
, array
, dim
, kind
, "__lbound", false);
1416 gfc_resolve_lcobound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
1418 resolve_bound (f
, array
, dim
, kind
, "__lcobound", true);
1423 gfc_resolve_len (gfc_expr
*f
, gfc_expr
*string
, gfc_expr
*kind
)
1425 f
->ts
.type
= BT_INTEGER
;
1427 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1429 f
->ts
.kind
= gfc_default_integer_kind
;
1430 f
->value
.function
.name
1431 = gfc_get_string ("__len_%d_i%d", string
->ts
.kind
,
1432 gfc_default_integer_kind
);
1437 gfc_resolve_len_trim (gfc_expr
*f
, gfc_expr
*string
, gfc_expr
*kind
)
1439 f
->ts
.type
= BT_INTEGER
;
1441 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1443 f
->ts
.kind
= gfc_default_integer_kind
;
1444 f
->value
.function
.name
= gfc_get_string ("__len_trim%d", string
->ts
.kind
);
1449 gfc_resolve_lgamma (gfc_expr
*f
, gfc_expr
*x
)
1452 f
->value
.function
.name
1453 = gfc_get_string ("__lgamma_%d", x
->ts
.kind
);
1458 gfc_resolve_link (gfc_expr
*f
, gfc_expr
*p1 ATTRIBUTE_UNUSED
,
1459 gfc_expr
*p2 ATTRIBUTE_UNUSED
)
1461 f
->ts
.type
= BT_INTEGER
;
1462 f
->ts
.kind
= gfc_default_integer_kind
;
1463 f
->value
.function
.name
= gfc_get_string (PREFIX ("link_i%d"), f
->ts
.kind
);
1468 gfc_resolve_loc (gfc_expr
*f
, gfc_expr
*x
)
1470 f
->ts
.type
= BT_INTEGER
;
1471 f
->ts
.kind
= gfc_index_integer_kind
;
1472 f
->value
.function
.name
= gfc_get_string ("__loc_%d", x
->ts
.kind
);
1477 gfc_resolve_log (gfc_expr
*f
, gfc_expr
*x
)
1480 f
->value
.function
.name
1481 = gfc_get_string ("__log_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
1486 gfc_resolve_log10 (gfc_expr
*f
, gfc_expr
*x
)
1489 f
->value
.function
.name
1490 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x
->ts
.type
),
1496 gfc_resolve_logical (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
1498 f
->ts
.type
= BT_LOGICAL
;
1499 f
->ts
.kind
= (kind
== NULL
)
1500 ? gfc_default_logical_kind
: mpz_get_si (kind
->value
.integer
);
1503 f
->value
.function
.name
1504 = gfc_get_string ("__logical_%d_%c%d", f
->ts
.kind
,
1505 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1510 gfc_resolve_malloc (gfc_expr
*f
, gfc_expr
*size
)
1512 if (size
->ts
.kind
< gfc_index_integer_kind
)
1517 ts
.type
= BT_INTEGER
;
1518 ts
.kind
= gfc_index_integer_kind
;
1519 gfc_convert_type_warn (size
, &ts
, 2, 0);
1522 f
->ts
.type
= BT_INTEGER
;
1523 f
->ts
.kind
= gfc_index_integer_kind
;
1524 f
->value
.function
.name
= gfc_get_string (PREFIX ("malloc"));
1529 gfc_resolve_matmul (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*b
)
1533 if (a
->ts
.type
== BT_LOGICAL
&& b
->ts
.type
== BT_LOGICAL
)
1535 f
->ts
.type
= BT_LOGICAL
;
1536 f
->ts
.kind
= gfc_default_logical_kind
;
1540 temp
.expr_type
= EXPR_OP
;
1541 gfc_clear_ts (&temp
.ts
);
1542 temp
.value
.op
.op
= INTRINSIC_NONE
;
1543 temp
.value
.op
.op1
= a
;
1544 temp
.value
.op
.op2
= b
;
1545 gfc_type_convert_binary (&temp
, 1);
1549 f
->rank
= (a
->rank
== 2 && b
->rank
== 2) ? 2 : 1;
1551 if (a
->rank
== 2 && b
->rank
== 2)
1553 if (a
->shape
&& b
->shape
)
1555 f
->shape
= gfc_get_shape (f
->rank
);
1556 mpz_init_set (f
->shape
[0], a
->shape
[0]);
1557 mpz_init_set (f
->shape
[1], b
->shape
[1]);
1560 else if (a
->rank
== 1)
1564 f
->shape
= gfc_get_shape (f
->rank
);
1565 mpz_init_set (f
->shape
[0], b
->shape
[1]);
1570 /* b->rank == 1 and a->rank == 2 here, all other cases have
1571 been caught in check.c. */
1574 f
->shape
= gfc_get_shape (f
->rank
);
1575 mpz_init_set (f
->shape
[0], a
->shape
[0]);
1579 f
->value
.function
.name
1580 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f
->ts
.type
),
1586 gfc_resolve_minmax (const char *name
, gfc_expr
*f
, gfc_actual_arglist
*args
)
1588 gfc_actual_arglist
*a
;
1590 f
->ts
.type
= args
->expr
->ts
.type
;
1591 f
->ts
.kind
= args
->expr
->ts
.kind
;
1592 /* Find the largest type kind. */
1593 for (a
= args
->next
; a
; a
= a
->next
)
1595 if (a
->expr
->ts
.kind
> f
->ts
.kind
)
1596 f
->ts
.kind
= a
->expr
->ts
.kind
;
1599 /* Convert all parameters to the required kind. */
1600 for (a
= args
; a
; a
= a
->next
)
1602 if (a
->expr
->ts
.kind
!= f
->ts
.kind
)
1603 gfc_convert_type (a
->expr
, &f
->ts
, 2);
1606 f
->value
.function
.name
1607 = gfc_get_string (name
, gfc_type_letter (f
->ts
.type
), f
->ts
.kind
);
1612 gfc_resolve_max (gfc_expr
*f
, gfc_actual_arglist
*args
)
1614 gfc_resolve_minmax ("__max_%c%d", f
, args
);
1619 gfc_resolve_maxloc (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
1625 f
->ts
.type
= BT_INTEGER
;
1626 f
->ts
.kind
= gfc_default_integer_kind
;
1631 f
->shape
= gfc_get_shape (1);
1632 mpz_init_set_si (f
->shape
[0], array
->rank
);
1636 f
->rank
= array
->rank
- 1;
1637 gfc_resolve_dim_arg (dim
);
1638 if (array
->shape
&& dim
->expr_type
== EXPR_CONSTANT
)
1640 idim
= (int) mpz_get_si (dim
->value
.integer
);
1641 f
->shape
= gfc_get_shape (f
->rank
);
1642 for (i
= 0, j
= 0; i
< f
->rank
; i
++, j
++)
1644 if (i
== (idim
- 1))
1646 mpz_init_set (f
->shape
[i
], array
->shape
[j
]);
1653 if (mask
->rank
== 0)
1658 resolve_mask_arg (mask
);
1663 f
->value
.function
.name
1664 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name
, dim
!= NULL
, f
->ts
.kind
,
1665 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
1670 gfc_resolve_maxval (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
1680 f
->rank
= array
->rank
- 1;
1681 gfc_resolve_dim_arg (dim
);
1683 if (f
->rank
&& array
->shape
&& dim
->expr_type
== EXPR_CONSTANT
)
1685 idim
= (int) mpz_get_si (dim
->value
.integer
);
1686 f
->shape
= gfc_get_shape (f
->rank
);
1687 for (i
= 0, j
= 0; i
< f
->rank
; i
++, j
++)
1689 if (i
== (idim
- 1))
1691 mpz_init_set (f
->shape
[i
], array
->shape
[j
]);
1698 if (mask
->rank
== 0)
1703 resolve_mask_arg (mask
);
1708 f
->value
.function
.name
1709 = gfc_get_string (PREFIX ("%s_%c%d"), name
,
1710 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
1715 gfc_resolve_mclock (gfc_expr
*f
)
1717 f
->ts
.type
= BT_INTEGER
;
1719 f
->value
.function
.name
= PREFIX ("mclock");
1724 gfc_resolve_mclock8 (gfc_expr
*f
)
1726 f
->ts
.type
= BT_INTEGER
;
1728 f
->value
.function
.name
= PREFIX ("mclock8");
1733 gfc_resolve_mask (gfc_expr
*f
, gfc_expr
*i ATTRIBUTE_UNUSED
,
1736 f
->ts
.type
= BT_INTEGER
;
1737 f
->ts
.kind
= kind
? mpz_get_si (kind
->value
.integer
)
1738 : gfc_default_integer_kind
;
1740 if (f
->value
.function
.isym
->id
== GFC_ISYM_MASKL
)
1741 f
->value
.function
.name
= gfc_get_string ("__maskl_i%d", f
->ts
.kind
);
1743 f
->value
.function
.name
= gfc_get_string ("__maskr_i%d", f
->ts
.kind
);
1748 gfc_resolve_merge (gfc_expr
*f
, gfc_expr
*tsource
,
1749 gfc_expr
*fsource ATTRIBUTE_UNUSED
,
1750 gfc_expr
*mask ATTRIBUTE_UNUSED
)
1752 if (tsource
->ts
.type
== BT_CHARACTER
&& tsource
->ref
)
1753 gfc_resolve_substring_charlen (tsource
);
1755 if (fsource
->ts
.type
== BT_CHARACTER
&& fsource
->ref
)
1756 gfc_resolve_substring_charlen (fsource
);
1758 if (tsource
->ts
.type
== BT_CHARACTER
)
1759 check_charlen_present (tsource
);
1761 f
->ts
= tsource
->ts
;
1762 f
->value
.function
.name
1763 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource
->ts
.type
),
1769 gfc_resolve_merge_bits (gfc_expr
*f
, gfc_expr
*i
,
1770 gfc_expr
*j ATTRIBUTE_UNUSED
,
1771 gfc_expr
*mask ATTRIBUTE_UNUSED
)
1774 f
->value
.function
.name
= gfc_get_string ("__merge_bits_i%d", i
->ts
.kind
);
1779 gfc_resolve_min (gfc_expr
*f
, gfc_actual_arglist
*args
)
1781 gfc_resolve_minmax ("__min_%c%d", f
, args
);
1786 gfc_resolve_minloc (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
1792 f
->ts
.type
= BT_INTEGER
;
1793 f
->ts
.kind
= gfc_default_integer_kind
;
1798 f
->shape
= gfc_get_shape (1);
1799 mpz_init_set_si (f
->shape
[0], array
->rank
);
1803 f
->rank
= array
->rank
- 1;
1804 gfc_resolve_dim_arg (dim
);
1805 if (array
->shape
&& dim
->expr_type
== EXPR_CONSTANT
)
1807 idim
= (int) mpz_get_si (dim
->value
.integer
);
1808 f
->shape
= gfc_get_shape (f
->rank
);
1809 for (i
= 0, j
= 0; i
< f
->rank
; i
++, j
++)
1811 if (i
== (idim
- 1))
1813 mpz_init_set (f
->shape
[i
], array
->shape
[j
]);
1820 if (mask
->rank
== 0)
1825 resolve_mask_arg (mask
);
1830 f
->value
.function
.name
1831 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name
, dim
!= NULL
, f
->ts
.kind
,
1832 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
1837 gfc_resolve_minval (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
1847 f
->rank
= array
->rank
- 1;
1848 gfc_resolve_dim_arg (dim
);
1850 if (f
->rank
&& array
->shape
&& dim
->expr_type
== EXPR_CONSTANT
)
1852 idim
= (int) mpz_get_si (dim
->value
.integer
);
1853 f
->shape
= gfc_get_shape (f
->rank
);
1854 for (i
= 0, j
= 0; i
< f
->rank
; i
++, j
++)
1856 if (i
== (idim
- 1))
1858 mpz_init_set (f
->shape
[i
], array
->shape
[j
]);
1865 if (mask
->rank
== 0)
1870 resolve_mask_arg (mask
);
1875 f
->value
.function
.name
1876 = gfc_get_string (PREFIX ("%s_%c%d"), name
,
1877 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
1882 gfc_resolve_mod (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*p
)
1884 f
->ts
.type
= a
->ts
.type
;
1886 f
->ts
.kind
= gfc_kind_max (a
,p
);
1888 f
->ts
.kind
= a
->ts
.kind
;
1890 if (p
!= NULL
&& a
->ts
.kind
!= p
->ts
.kind
)
1892 if (a
->ts
.kind
== gfc_kind_max (a
,p
))
1893 gfc_convert_type (p
, &a
->ts
, 2);
1895 gfc_convert_type (a
, &p
->ts
, 2);
1898 f
->value
.function
.name
1899 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f
->ts
.type
), f
->ts
.kind
);
1904 gfc_resolve_modulo (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*p
)
1906 f
->ts
.type
= a
->ts
.type
;
1908 f
->ts
.kind
= gfc_kind_max (a
,p
);
1910 f
->ts
.kind
= a
->ts
.kind
;
1912 if (p
!= NULL
&& a
->ts
.kind
!= p
->ts
.kind
)
1914 if (a
->ts
.kind
== gfc_kind_max (a
,p
))
1915 gfc_convert_type (p
, &a
->ts
, 2);
1917 gfc_convert_type (a
, &p
->ts
, 2);
1920 f
->value
.function
.name
1921 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f
->ts
.type
),
1926 gfc_resolve_nearest (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*p
)
1928 if (p
->ts
.kind
!= a
->ts
.kind
)
1929 gfc_convert_type (p
, &a
->ts
, 2);
1932 f
->value
.function
.name
1933 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a
->ts
.type
),
1938 gfc_resolve_nint (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
1940 f
->ts
.type
= BT_INTEGER
;
1941 f
->ts
.kind
= (kind
== NULL
)
1942 ? gfc_default_integer_kind
: mpz_get_si (kind
->value
.integer
);
1943 f
->value
.function
.name
1944 = gfc_get_string ("__nint_%d_%d", f
->ts
.kind
, a
->ts
.kind
);
1949 gfc_resolve_norm2 (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
)
1951 resolve_transformational ("norm2", f
, array
, dim
, NULL
);
1956 gfc_resolve_not (gfc_expr
*f
, gfc_expr
*i
)
1959 f
->value
.function
.name
= gfc_get_string ("__not_%d", i
->ts
.kind
);
1964 gfc_resolve_or (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
1966 f
->ts
.type
= i
->ts
.type
;
1967 f
->ts
.kind
= gfc_kind_max (i
, j
);
1969 if (i
->ts
.kind
!= j
->ts
.kind
)
1971 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
1972 gfc_convert_type (j
, &i
->ts
, 2);
1974 gfc_convert_type (i
, &j
->ts
, 2);
1977 f
->value
.function
.name
1978 = gfc_get_string ("__or_%c%d", gfc_type_letter (i
->ts
.type
), f
->ts
.kind
);
1983 gfc_resolve_pack (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*mask
,
1984 gfc_expr
*vector ATTRIBUTE_UNUSED
)
1986 if (array
->ts
.type
== BT_CHARACTER
&& array
->ref
)
1987 gfc_resolve_substring_charlen (array
);
1992 resolve_mask_arg (mask
);
1994 if (mask
->rank
!= 0)
1996 if (array
->ts
.type
== BT_CHARACTER
)
1997 f
->value
.function
.name
1998 = array
->ts
.kind
== 1 ? PREFIX ("pack_char")
2000 (PREFIX ("pack_char%d"),
2003 f
->value
.function
.name
= PREFIX ("pack");
2007 if (array
->ts
.type
== BT_CHARACTER
)
2008 f
->value
.function
.name
2009 = array
->ts
.kind
== 1 ? PREFIX ("pack_s_char")
2011 (PREFIX ("pack_s_char%d"),
2014 f
->value
.function
.name
= PREFIX ("pack_s");
2020 gfc_resolve_parity (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
)
2022 resolve_transformational ("parity", f
, array
, dim
, NULL
);
2027 gfc_resolve_product (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
2030 resolve_transformational ("product", f
, array
, dim
, mask
);
2035 gfc_resolve_rank (gfc_expr
*f
, gfc_expr
*array ATTRIBUTE_UNUSED
)
2037 f
->ts
.type
= BT_INTEGER
;
2038 f
->ts
.kind
= gfc_default_integer_kind
;
2039 f
->value
.function
.name
= gfc_get_string ("__rank");
2044 gfc_resolve_real (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
2046 f
->ts
.type
= BT_REAL
;
2049 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2051 f
->ts
.kind
= (a
->ts
.type
== BT_COMPLEX
)
2052 ? a
->ts
.kind
: gfc_default_real_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_realpart (gfc_expr
*f
, gfc_expr
*a
)
2063 f
->ts
.type
= BT_REAL
;
2064 f
->ts
.kind
= a
->ts
.kind
;
2065 f
->value
.function
.name
2066 = gfc_get_string ("__real_%d_%c%d", f
->ts
.kind
,
2067 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
2072 gfc_resolve_rename (gfc_expr
*f
, gfc_expr
*p1 ATTRIBUTE_UNUSED
,
2073 gfc_expr
*p2 ATTRIBUTE_UNUSED
)
2075 f
->ts
.type
= BT_INTEGER
;
2076 f
->ts
.kind
= gfc_default_integer_kind
;
2077 f
->value
.function
.name
= gfc_get_string (PREFIX ("rename_i%d"), f
->ts
.kind
);
2082 gfc_resolve_repeat (gfc_expr
*f
, gfc_expr
*string
,
2087 f
->ts
.type
= BT_CHARACTER
;
2088 f
->ts
.kind
= string
->ts
.kind
;
2089 f
->value
.function
.name
= gfc_get_string ("__repeat_%d", string
->ts
.kind
);
2091 /* If possible, generate a character length. */
2092 if (f
->ts
.u
.cl
== NULL
)
2093 f
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
2096 if (string
->expr_type
== EXPR_CONSTANT
)
2098 len
= string
->value
.character
.length
;
2099 tmp
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, len
);
2101 else if (string
->ts
.u
.cl
&& string
->ts
.u
.cl
->length
)
2103 tmp
= gfc_copy_expr (string
->ts
.u
.cl
->length
);
2107 f
->ts
.u
.cl
->length
= gfc_multiply (tmp
, gfc_copy_expr (ncopies
));
2112 gfc_resolve_reshape (gfc_expr
*f
, gfc_expr
*source
, gfc_expr
*shape
,
2113 gfc_expr
*pad ATTRIBUTE_UNUSED
,
2114 gfc_expr
*order ATTRIBUTE_UNUSED
)
2120 if (source
->ts
.type
== BT_CHARACTER
&& source
->ref
)
2121 gfc_resolve_substring_charlen (source
);
2125 gfc_array_size (shape
, &rank
);
2126 f
->rank
= mpz_get_si (rank
);
2128 switch (source
->ts
.type
)
2135 kind
= source
->ts
.kind
;
2149 if (source
->ts
.type
== BT_COMPLEX
|| source
->ts
.type
== BT_REAL
)
2150 f
->value
.function
.name
2151 = gfc_get_string (PREFIX ("reshape_%c%d"),
2152 gfc_type_letter (source
->ts
.type
),
2154 else if (source
->ts
.type
== BT_CHARACTER
)
2155 f
->value
.function
.name
= gfc_get_string (PREFIX ("reshape_char%d"),
2158 f
->value
.function
.name
2159 = gfc_get_string (PREFIX ("reshape_%d"), source
->ts
.kind
);
2163 f
->value
.function
.name
= (source
->ts
.type
== BT_CHARACTER
2164 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
2168 if (shape
->expr_type
== EXPR_ARRAY
&& gfc_is_constant_expr (shape
))
2171 f
->shape
= gfc_get_shape (f
->rank
);
2172 c
= gfc_constructor_first (shape
->value
.constructor
);
2173 for (i
= 0; i
< f
->rank
; i
++)
2175 mpz_init_set (f
->shape
[i
], c
->expr
->value
.integer
);
2176 c
= gfc_constructor_next (c
);
2180 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
2181 so many runtime variations. */
2182 if (shape
->ts
.kind
!= gfc_index_integer_kind
)
2184 gfc_typespec ts
= shape
->ts
;
2185 ts
.kind
= gfc_index_integer_kind
;
2186 gfc_convert_type_warn (shape
, &ts
, 2, 0);
2188 if (order
&& order
->ts
.kind
!= gfc_index_integer_kind
)
2189 gfc_convert_type_warn (order
, &shape
->ts
, 2, 0);
2194 gfc_resolve_rrspacing (gfc_expr
*f
, gfc_expr
*x
)
2197 f
->value
.function
.name
= gfc_get_string ("__rrspacing_%d", x
->ts
.kind
);
2202 gfc_resolve_scale (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*i ATTRIBUTE_UNUSED
)
2205 f
->value
.function
.name
= gfc_get_string ("__scale_%d", x
->ts
.kind
);
2210 gfc_resolve_scan (gfc_expr
*f
, gfc_expr
*string
,
2211 gfc_expr
*set ATTRIBUTE_UNUSED
,
2212 gfc_expr
*back ATTRIBUTE_UNUSED
, gfc_expr
*kind
)
2214 f
->ts
.type
= BT_INTEGER
;
2216 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2218 f
->ts
.kind
= gfc_default_integer_kind
;
2219 f
->value
.function
.name
= gfc_get_string ("__scan_%d", string
->ts
.kind
);
2224 gfc_resolve_secnds (gfc_expr
*t1
, gfc_expr
*t0
)
2227 t1
->value
.function
.name
= gfc_get_string (PREFIX ("secnds"));
2232 gfc_resolve_set_exponent (gfc_expr
*f
, gfc_expr
*x
,
2233 gfc_expr
*i ATTRIBUTE_UNUSED
)
2236 f
->value
.function
.name
= gfc_get_string ("__set_exponent_%d", x
->ts
.kind
);
2241 gfc_resolve_shape (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*kind
)
2243 f
->ts
.type
= BT_INTEGER
;
2246 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2248 f
->ts
.kind
= gfc_default_integer_kind
;
2251 if (array
->rank
!= -1)
2253 f
->shape
= gfc_get_shape (1);
2254 mpz_init_set_ui (f
->shape
[0], array
->rank
);
2257 f
->value
.function
.name
= gfc_get_string (PREFIX ("shape_%d"), f
->ts
.kind
);
2262 gfc_resolve_shift (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift ATTRIBUTE_UNUSED
)
2265 if (f
->value
.function
.isym
->id
== GFC_ISYM_SHIFTA
)
2266 f
->value
.function
.name
= gfc_get_string ("shifta_i%d", f
->ts
.kind
);
2267 else if (f
->value
.function
.isym
->id
== GFC_ISYM_SHIFTL
)
2268 f
->value
.function
.name
= gfc_get_string ("shiftl_i%d", f
->ts
.kind
);
2269 else if (f
->value
.function
.isym
->id
== GFC_ISYM_SHIFTR
)
2270 f
->value
.function
.name
= gfc_get_string ("shiftr_i%d", f
->ts
.kind
);
2277 gfc_resolve_sign (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*b ATTRIBUTE_UNUSED
)
2280 f
->value
.function
.name
2281 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
2286 gfc_resolve_signal (gfc_expr
*f
, gfc_expr
*number
, gfc_expr
*handler
)
2288 f
->ts
.type
= BT_INTEGER
;
2289 f
->ts
.kind
= gfc_c_int_kind
;
2291 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2292 if (handler
->ts
.type
== BT_INTEGER
)
2294 if (handler
->ts
.kind
!= gfc_c_int_kind
)
2295 gfc_convert_type (handler
, &f
->ts
, 2);
2296 f
->value
.function
.name
= gfc_get_string (PREFIX ("signal_func_int"));
2299 f
->value
.function
.name
= gfc_get_string (PREFIX ("signal_func"));
2301 if (number
->ts
.kind
!= gfc_c_int_kind
)
2302 gfc_convert_type (number
, &f
->ts
, 2);
2307 gfc_resolve_sin (gfc_expr
*f
, gfc_expr
*x
)
2310 f
->value
.function
.name
2311 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2316 gfc_resolve_sinh (gfc_expr
*f
, gfc_expr
*x
)
2319 f
->value
.function
.name
2320 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2325 gfc_resolve_size (gfc_expr
*f
, gfc_expr
*array ATTRIBUTE_UNUSED
,
2326 gfc_expr
*dim ATTRIBUTE_UNUSED
, gfc_expr
*kind
)
2328 f
->ts
.type
= BT_INTEGER
;
2330 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2332 f
->ts
.kind
= gfc_default_integer_kind
;
2337 gfc_resolve_stride (gfc_expr
*f
, gfc_expr
*array ATTRIBUTE_UNUSED
,
2338 gfc_expr
*dim ATTRIBUTE_UNUSED
)
2340 f
->ts
.type
= BT_INTEGER
;
2341 f
->ts
.kind
= gfc_index_integer_kind
;
2346 gfc_resolve_spacing (gfc_expr
*f
, gfc_expr
*x
)
2349 f
->value
.function
.name
= gfc_get_string ("__spacing_%d", x
->ts
.kind
);
2354 gfc_resolve_spread (gfc_expr
*f
, gfc_expr
*source
, gfc_expr
*dim
,
2357 if (source
->ts
.type
== BT_CHARACTER
&& source
->ref
)
2358 gfc_resolve_substring_charlen (source
);
2360 if (source
->ts
.type
== BT_CHARACTER
)
2361 check_charlen_present (source
);
2364 f
->rank
= source
->rank
+ 1;
2365 if (source
->rank
== 0)
2367 if (source
->ts
.type
== BT_CHARACTER
)
2368 f
->value
.function
.name
2369 = source
->ts
.kind
== 1 ? PREFIX ("spread_char_scalar")
2371 (PREFIX ("spread_char%d_scalar"),
2374 f
->value
.function
.name
= PREFIX ("spread_scalar");
2378 if (source
->ts
.type
== BT_CHARACTER
)
2379 f
->value
.function
.name
2380 = source
->ts
.kind
== 1 ? PREFIX ("spread_char")
2382 (PREFIX ("spread_char%d"),
2385 f
->value
.function
.name
= PREFIX ("spread");
2388 if (dim
&& gfc_is_constant_expr (dim
)
2389 && ncopies
&& gfc_is_constant_expr (ncopies
) && source
->shape
[0])
2392 idim
= mpz_get_ui (dim
->value
.integer
);
2393 f
->shape
= gfc_get_shape (f
->rank
);
2394 for (i
= 0; i
< (idim
- 1); i
++)
2395 mpz_init_set (f
->shape
[i
], source
->shape
[i
]);
2397 mpz_init_set (f
->shape
[idim
- 1], ncopies
->value
.integer
);
2399 for (i
= idim
; i
< f
->rank
; i
++)
2400 mpz_init_set (f
->shape
[i
], source
->shape
[i
-1]);
2404 gfc_resolve_dim_arg (dim
);
2405 gfc_resolve_index (ncopies
, 1);
2410 gfc_resolve_sqrt (gfc_expr
*f
, gfc_expr
*x
)
2413 f
->value
.function
.name
2414 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2418 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2421 gfc_resolve_stat (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
,
2422 gfc_expr
*a ATTRIBUTE_UNUSED
)
2424 f
->ts
.type
= BT_INTEGER
;
2425 f
->ts
.kind
= gfc_default_integer_kind
;
2426 f
->value
.function
.name
= gfc_get_string (PREFIX ("stat_i%d"), f
->ts
.kind
);
2431 gfc_resolve_lstat (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
,
2432 gfc_expr
*a ATTRIBUTE_UNUSED
)
2434 f
->ts
.type
= BT_INTEGER
;
2435 f
->ts
.kind
= gfc_default_integer_kind
;
2436 f
->value
.function
.name
= gfc_get_string (PREFIX ("lstat_i%d"), f
->ts
.kind
);
2441 gfc_resolve_fstat (gfc_expr
*f
, gfc_expr
*n
, gfc_expr
*a ATTRIBUTE_UNUSED
)
2443 f
->ts
.type
= BT_INTEGER
;
2444 f
->ts
.kind
= gfc_default_integer_kind
;
2445 if (n
->ts
.kind
!= f
->ts
.kind
)
2446 gfc_convert_type (n
, &f
->ts
, 2);
2448 f
->value
.function
.name
= gfc_get_string (PREFIX ("fstat_i%d"), f
->ts
.kind
);
2453 gfc_resolve_fgetc (gfc_expr
*f
, gfc_expr
*u
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2458 f
->ts
.type
= BT_INTEGER
;
2459 f
->ts
.kind
= gfc_c_int_kind
;
2460 if (u
->ts
.kind
!= gfc_c_int_kind
)
2462 ts
.type
= BT_INTEGER
;
2463 ts
.kind
= gfc_c_int_kind
;
2464 ts
.u
.derived
= NULL
;
2466 gfc_convert_type (u
, &ts
, 2);
2469 f
->value
.function
.name
= gfc_get_string (PREFIX ("fgetc"));
2474 gfc_resolve_fget (gfc_expr
*f
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2476 f
->ts
.type
= BT_INTEGER
;
2477 f
->ts
.kind
= gfc_c_int_kind
;
2478 f
->value
.function
.name
= gfc_get_string (PREFIX ("fget"));
2483 gfc_resolve_fputc (gfc_expr
*f
, gfc_expr
*u
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2488 f
->ts
.type
= BT_INTEGER
;
2489 f
->ts
.kind
= gfc_c_int_kind
;
2490 if (u
->ts
.kind
!= gfc_c_int_kind
)
2492 ts
.type
= BT_INTEGER
;
2493 ts
.kind
= gfc_c_int_kind
;
2494 ts
.u
.derived
= NULL
;
2496 gfc_convert_type (u
, &ts
, 2);
2499 f
->value
.function
.name
= gfc_get_string (PREFIX ("fputc"));
2504 gfc_resolve_fput (gfc_expr
*f
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2506 f
->ts
.type
= BT_INTEGER
;
2507 f
->ts
.kind
= gfc_c_int_kind
;
2508 f
->value
.function
.name
= gfc_get_string (PREFIX ("fput"));
2513 gfc_resolve_ftell (gfc_expr
*f
, gfc_expr
*u
)
2518 f
->ts
.type
= BT_INTEGER
;
2519 f
->ts
.kind
= gfc_intio_kind
;
2520 if (u
->ts
.kind
!= gfc_c_int_kind
)
2522 ts
.type
= BT_INTEGER
;
2523 ts
.kind
= gfc_c_int_kind
;
2524 ts
.u
.derived
= NULL
;
2526 gfc_convert_type (u
, &ts
, 2);
2529 f
->value
.function
.name
= gfc_get_string (PREFIX ("ftell2"));
2534 gfc_resolve_storage_size (gfc_expr
*f
, gfc_expr
*a ATTRIBUTE_UNUSED
,
2537 f
->ts
.type
= BT_INTEGER
;
2539 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2541 f
->ts
.kind
= gfc_default_integer_kind
;
2546 gfc_resolve_sum (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*mask
)
2548 resolve_transformational ("sum", f
, array
, dim
, mask
);
2553 gfc_resolve_symlnk (gfc_expr
*f
, gfc_expr
*p1 ATTRIBUTE_UNUSED
,
2554 gfc_expr
*p2 ATTRIBUTE_UNUSED
)
2556 f
->ts
.type
= BT_INTEGER
;
2557 f
->ts
.kind
= gfc_default_integer_kind
;
2558 f
->value
.function
.name
= gfc_get_string (PREFIX ("symlnk_i%d"), f
->ts
.kind
);
2562 /* Resolve the g77 compatibility function SYSTEM. */
2565 gfc_resolve_system (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
)
2567 f
->ts
.type
= BT_INTEGER
;
2569 f
->value
.function
.name
= gfc_get_string (PREFIX ("system"));
2574 gfc_resolve_tan (gfc_expr
*f
, gfc_expr
*x
)
2577 f
->value
.function
.name
2578 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2583 gfc_resolve_tanh (gfc_expr
*f
, gfc_expr
*x
)
2586 f
->value
.function
.name
2587 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2592 gfc_resolve_image_index (gfc_expr
*f
, gfc_expr
*array ATTRIBUTE_UNUSED
,
2593 gfc_expr
*sub ATTRIBUTE_UNUSED
)
2595 static char image_index
[] = "__image_index";
2596 f
->ts
.type
= BT_INTEGER
;
2597 f
->ts
.kind
= gfc_default_integer_kind
;
2598 f
->value
.function
.name
= image_index
;
2603 gfc_resolve_this_image (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
2604 gfc_expr
*distance ATTRIBUTE_UNUSED
)
2606 static char this_image
[] = "__this_image";
2607 if (array
&& gfc_is_coarray (array
))
2608 resolve_bound (f
, array
, dim
, NULL
, "__this_image", true);
2611 f
->ts
.type
= BT_INTEGER
;
2612 f
->ts
.kind
= gfc_default_integer_kind
;
2613 f
->value
.function
.name
= this_image
;
2619 gfc_resolve_time (gfc_expr
*f
)
2621 f
->ts
.type
= BT_INTEGER
;
2623 f
->value
.function
.name
= gfc_get_string (PREFIX ("time_func"));
2628 gfc_resolve_time8 (gfc_expr
*f
)
2630 f
->ts
.type
= BT_INTEGER
;
2632 f
->value
.function
.name
= gfc_get_string (PREFIX ("time8_func"));
2637 gfc_resolve_transfer (gfc_expr
*f
, gfc_expr
*source ATTRIBUTE_UNUSED
,
2638 gfc_expr
*mold
, gfc_expr
*size
)
2640 /* TODO: Make this do something meaningful. */
2641 static char transfer0
[] = "__transfer0", transfer1
[] = "__transfer1";
2643 if (mold
->ts
.type
== BT_CHARACTER
2644 && !mold
->ts
.u
.cl
->length
2645 && gfc_is_constant_expr (mold
))
2648 if (mold
->expr_type
== EXPR_CONSTANT
)
2650 len
= mold
->value
.character
.length
;
2651 mold
->ts
.u
.cl
->length
= gfc_get_int_expr (gfc_default_integer_kind
,
2656 gfc_constructor
*c
= gfc_constructor_first (mold
->value
.constructor
);
2657 len
= c
->expr
->value
.character
.length
;
2658 mold
->ts
.u
.cl
->length
= gfc_get_int_expr (gfc_default_integer_kind
,
2665 if (size
== NULL
&& mold
->rank
== 0)
2668 f
->value
.function
.name
= transfer0
;
2673 f
->value
.function
.name
= transfer1
;
2674 if (size
&& gfc_is_constant_expr (size
))
2676 f
->shape
= gfc_get_shape (1);
2677 mpz_init_set (f
->shape
[0], size
->value
.integer
);
2684 gfc_resolve_transpose (gfc_expr
*f
, gfc_expr
*matrix
)
2687 if (matrix
->ts
.type
== BT_CHARACTER
&& matrix
->ref
)
2688 gfc_resolve_substring_charlen (matrix
);
2694 f
->shape
= gfc_get_shape (2);
2695 mpz_init_set (f
->shape
[0], matrix
->shape
[1]);
2696 mpz_init_set (f
->shape
[1], matrix
->shape
[0]);
2699 switch (matrix
->ts
.kind
)
2705 switch (matrix
->ts
.type
)
2709 f
->value
.function
.name
2710 = gfc_get_string (PREFIX ("transpose_%c%d"),
2711 gfc_type_letter (matrix
->ts
.type
),
2717 /* Use the integer routines for real and logical cases. This
2718 assumes they all have the same alignment requirements. */
2719 f
->value
.function
.name
2720 = gfc_get_string (PREFIX ("transpose_i%d"), matrix
->ts
.kind
);
2724 if (matrix
->ts
.type
== BT_CHARACTER
&& matrix
->ts
.kind
== 4)
2725 f
->value
.function
.name
= PREFIX ("transpose_char4");
2727 f
->value
.function
.name
= PREFIX ("transpose");
2733 f
->value
.function
.name
= (matrix
->ts
.type
== BT_CHARACTER
2734 ? PREFIX ("transpose_char")
2735 : PREFIX ("transpose"));
2742 gfc_resolve_trim (gfc_expr
*f
, gfc_expr
*string
)
2744 f
->ts
.type
= BT_CHARACTER
;
2745 f
->ts
.kind
= string
->ts
.kind
;
2746 f
->value
.function
.name
= gfc_get_string ("__trim_%d", string
->ts
.kind
);
2751 gfc_resolve_ubound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
2753 resolve_bound (f
, array
, dim
, kind
, "__ubound", false);
2758 gfc_resolve_ucobound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
2760 resolve_bound (f
, array
, dim
, kind
, "__ucobound", true);
2764 /* Resolve the g77 compatibility function UMASK. */
2767 gfc_resolve_umask (gfc_expr
*f
, gfc_expr
*n
)
2769 f
->ts
.type
= BT_INTEGER
;
2770 f
->ts
.kind
= n
->ts
.kind
;
2771 f
->value
.function
.name
= gfc_get_string (PREFIX ("umask_i%d"), n
->ts
.kind
);
2775 /* Resolve the g77 compatibility function UNLINK. */
2778 gfc_resolve_unlink (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
)
2780 f
->ts
.type
= BT_INTEGER
;
2782 f
->value
.function
.name
= gfc_get_string (PREFIX ("unlink"));
2787 gfc_resolve_ttynam (gfc_expr
*f
, gfc_expr
*unit
)
2792 f
->ts
.type
= BT_CHARACTER
;
2793 f
->ts
.kind
= gfc_default_character_kind
;
2795 if (unit
->ts
.kind
!= gfc_c_int_kind
)
2797 ts
.type
= BT_INTEGER
;
2798 ts
.kind
= gfc_c_int_kind
;
2799 ts
.u
.derived
= NULL
;
2801 gfc_convert_type (unit
, &ts
, 2);
2804 f
->value
.function
.name
= gfc_get_string (PREFIX ("ttynam"));
2809 gfc_resolve_unpack (gfc_expr
*f
, gfc_expr
*vector
, gfc_expr
*mask
,
2810 gfc_expr
*field ATTRIBUTE_UNUSED
)
2812 if (vector
->ts
.type
== BT_CHARACTER
&& vector
->ref
)
2813 gfc_resolve_substring_charlen (vector
);
2816 f
->rank
= mask
->rank
;
2817 resolve_mask_arg (mask
);
2819 if (vector
->ts
.type
== BT_CHARACTER
)
2821 if (vector
->ts
.kind
== 1)
2822 f
->value
.function
.name
2823 = gfc_get_string (PREFIX ("unpack%d_char"), field
->rank
> 0 ? 1 : 0);
2825 f
->value
.function
.name
2826 = gfc_get_string (PREFIX ("unpack%d_char%d"),
2827 field
->rank
> 0 ? 1 : 0, vector
->ts
.kind
);
2830 f
->value
.function
.name
2831 = gfc_get_string (PREFIX ("unpack%d"), field
->rank
> 0 ? 1 : 0);
2836 gfc_resolve_verify (gfc_expr
*f
, gfc_expr
*string
,
2837 gfc_expr
*set ATTRIBUTE_UNUSED
,
2838 gfc_expr
*back ATTRIBUTE_UNUSED
, gfc_expr
*kind
)
2840 f
->ts
.type
= BT_INTEGER
;
2842 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2844 f
->ts
.kind
= gfc_default_integer_kind
;
2845 f
->value
.function
.name
= gfc_get_string ("__verify_%d", string
->ts
.kind
);
2850 gfc_resolve_xor (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
2852 f
->ts
.type
= i
->ts
.type
;
2853 f
->ts
.kind
= gfc_kind_max (i
, j
);
2855 if (i
->ts
.kind
!= j
->ts
.kind
)
2857 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
2858 gfc_convert_type (j
, &i
->ts
, 2);
2860 gfc_convert_type (i
, &j
->ts
, 2);
2863 f
->value
.function
.name
2864 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i
->ts
.type
), f
->ts
.kind
);
2868 /* Intrinsic subroutine resolution. */
2871 gfc_resolve_alarm_sub (gfc_code
*c
)
2874 gfc_expr
*seconds
, *handler
;
2878 seconds
= c
->ext
.actual
->expr
;
2879 handler
= c
->ext
.actual
->next
->expr
;
2880 ts
.type
= BT_INTEGER
;
2881 ts
.kind
= gfc_c_int_kind
;
2883 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2884 In all cases, the status argument is of default integer kind
2885 (enforced in check.c) so that the function suffix is fixed. */
2886 if (handler
->ts
.type
== BT_INTEGER
)
2888 if (handler
->ts
.kind
!= gfc_c_int_kind
)
2889 gfc_convert_type (handler
, &ts
, 2);
2890 name
= gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2891 gfc_default_integer_kind
);
2894 name
= gfc_get_string (PREFIX ("alarm_sub_i%d"),
2895 gfc_default_integer_kind
);
2897 if (seconds
->ts
.kind
!= gfc_c_int_kind
)
2898 gfc_convert_type (seconds
, &ts
, 2);
2900 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2904 gfc_resolve_cpu_time (gfc_code
*c
)
2907 name
= gfc_get_string (PREFIX ("cpu_time_%d"), c
->ext
.actual
->expr
->ts
.kind
);
2908 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2912 /* Create a formal arglist based on an actual one and set the INTENTs given. */
2914 static gfc_formal_arglist
*
2915 create_formal_for_intents (gfc_actual_arglist
* actual
, const sym_intent
* ints
)
2917 gfc_formal_arglist
* head
;
2918 gfc_formal_arglist
* tail
;
2924 head
= tail
= gfc_get_formal_arglist ();
2925 for (i
= 0; actual
; actual
= actual
->next
, tail
= tail
->next
, ++i
)
2929 sym
= gfc_new_symbol ("dummyarg", NULL
);
2930 sym
->ts
= actual
->expr
->ts
;
2932 sym
->attr
.intent
= ints
[i
];
2936 tail
->next
= gfc_get_formal_arglist ();
2944 gfc_resolve_atomic_def (gfc_code
*c
)
2946 const char *name
= "atomic_define";
2947 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2952 gfc_resolve_atomic_ref (gfc_code
*c
)
2954 const char *name
= "atomic_ref";
2955 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2960 gfc_resolve_mvbits (gfc_code
*c
)
2962 static const sym_intent INTENTS
[] = {INTENT_IN
, INTENT_IN
, INTENT_IN
,
2963 INTENT_INOUT
, INTENT_IN
};
2969 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2970 they will be converted so that they fit into a C int. */
2971 ts
.type
= BT_INTEGER
;
2972 ts
.kind
= gfc_c_int_kind
;
2973 if (c
->ext
.actual
->next
->expr
->ts
.kind
!= gfc_c_int_kind
)
2974 gfc_convert_type (c
->ext
.actual
->next
->expr
, &ts
, 2);
2975 if (c
->ext
.actual
->next
->next
->expr
->ts
.kind
!= gfc_c_int_kind
)
2976 gfc_convert_type (c
->ext
.actual
->next
->next
->expr
, &ts
, 2);
2977 if (c
->ext
.actual
->next
->next
->next
->next
->expr
->ts
.kind
!= gfc_c_int_kind
)
2978 gfc_convert_type (c
->ext
.actual
->next
->next
->next
->next
->expr
, &ts
, 2);
2980 /* TO and FROM are guaranteed to have the same kind parameter. */
2981 name
= gfc_get_string (PREFIX ("mvbits_i%d"),
2982 c
->ext
.actual
->expr
->ts
.kind
);
2983 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2984 /* Mark as elemental subroutine as this does not happen automatically. */
2985 c
->resolved_sym
->attr
.elemental
= 1;
2987 /* Create a dummy formal arglist so the INTENTs are known later for purpose
2988 of creating temporaries. */
2989 c
->resolved_sym
->formal
= create_formal_for_intents (c
->ext
.actual
, INTENTS
);
2994 gfc_resolve_random_number (gfc_code
*c
)
2999 kind
= c
->ext
.actual
->expr
->ts
.kind
;
3000 if (c
->ext
.actual
->expr
->rank
== 0)
3001 name
= gfc_get_string (PREFIX ("random_r%d"), kind
);
3003 name
= gfc_get_string (PREFIX ("arandom_r%d"), kind
);
3005 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3010 gfc_resolve_random_seed (gfc_code
*c
)
3014 name
= gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind
);
3015 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3020 gfc_resolve_rename_sub (gfc_code
*c
)
3025 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
3026 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
3028 kind
= gfc_default_integer_kind
;
3030 name
= gfc_get_string (PREFIX ("rename_i%d_sub"), kind
);
3031 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3036 gfc_resolve_kill_sub (gfc_code
*c
)
3041 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
3042 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
3044 kind
= gfc_default_integer_kind
;
3046 name
= gfc_get_string (PREFIX ("kill_i%d_sub"), kind
);
3047 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3052 gfc_resolve_link_sub (gfc_code
*c
)
3057 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
3058 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
3060 kind
= gfc_default_integer_kind
;
3062 name
= gfc_get_string (PREFIX ("link_i%d_sub"), kind
);
3063 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3068 gfc_resolve_symlnk_sub (gfc_code
*c
)
3073 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
3074 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
3076 kind
= gfc_default_integer_kind
;
3078 name
= gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind
);
3079 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3083 /* G77 compatibility subroutines dtime() and etime(). */
3086 gfc_resolve_dtime_sub (gfc_code
*c
)
3089 name
= gfc_get_string (PREFIX ("dtime_sub"));
3090 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3094 gfc_resolve_etime_sub (gfc_code
*c
)
3097 name
= gfc_get_string (PREFIX ("etime_sub"));
3098 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3102 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
3105 gfc_resolve_itime (gfc_code
*c
)
3108 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
3109 gfc_default_integer_kind
));
3113 gfc_resolve_idate (gfc_code
*c
)
3116 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
3117 gfc_default_integer_kind
));
3121 gfc_resolve_ltime (gfc_code
*c
)
3124 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
3125 gfc_default_integer_kind
));
3129 gfc_resolve_gmtime (gfc_code
*c
)
3132 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
3133 gfc_default_integer_kind
));
3137 /* G77 compatibility subroutine second(). */
3140 gfc_resolve_second_sub (gfc_code
*c
)
3143 name
= gfc_get_string (PREFIX ("second_sub"));
3144 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3149 gfc_resolve_sleep_sub (gfc_code
*c
)
3154 if (c
->ext
.actual
->expr
!= NULL
)
3155 kind
= c
->ext
.actual
->expr
->ts
.kind
;
3157 kind
= gfc_default_integer_kind
;
3159 name
= gfc_get_string (PREFIX ("sleep_i%d_sub"), kind
);
3160 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3164 /* G77 compatibility function srand(). */
3167 gfc_resolve_srand (gfc_code
*c
)
3170 name
= gfc_get_string (PREFIX ("srand"));
3171 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3175 /* Resolve the getarg intrinsic subroutine. */
3178 gfc_resolve_getarg (gfc_code
*c
)
3182 if (c
->ext
.actual
->expr
->ts
.kind
!= gfc_default_integer_kind
)
3187 ts
.type
= BT_INTEGER
;
3188 ts
.kind
= gfc_default_integer_kind
;
3190 gfc_convert_type (c
->ext
.actual
->expr
, &ts
, 2);
3193 name
= gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind
);
3194 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3198 /* Resolve the getcwd intrinsic subroutine. */
3201 gfc_resolve_getcwd_sub (gfc_code
*c
)
3206 if (c
->ext
.actual
->next
->expr
!= NULL
)
3207 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3209 kind
= gfc_default_integer_kind
;
3211 name
= gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind
);
3212 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3216 /* Resolve the get_command intrinsic subroutine. */
3219 gfc_resolve_get_command (gfc_code
*c
)
3223 kind
= gfc_default_integer_kind
;
3224 name
= gfc_get_string (PREFIX ("get_command_i%d"), kind
);
3225 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3229 /* Resolve the get_command_argument intrinsic subroutine. */
3232 gfc_resolve_get_command_argument (gfc_code
*c
)
3236 kind
= gfc_default_integer_kind
;
3237 name
= gfc_get_string (PREFIX ("get_command_argument_i%d"), kind
);
3238 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3242 /* Resolve the get_environment_variable intrinsic subroutine. */
3245 gfc_resolve_get_environment_variable (gfc_code
*code
)
3249 kind
= gfc_default_integer_kind
;
3250 name
= gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind
);
3251 code
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3256 gfc_resolve_signal_sub (gfc_code
*c
)
3259 gfc_expr
*number
, *handler
, *status
;
3263 number
= c
->ext
.actual
->expr
;
3264 handler
= c
->ext
.actual
->next
->expr
;
3265 status
= c
->ext
.actual
->next
->next
->expr
;
3266 ts
.type
= BT_INTEGER
;
3267 ts
.kind
= gfc_c_int_kind
;
3269 /* handler can be either BT_INTEGER or BT_PROCEDURE */
3270 if (handler
->ts
.type
== BT_INTEGER
)
3272 if (handler
->ts
.kind
!= gfc_c_int_kind
)
3273 gfc_convert_type (handler
, &ts
, 2);
3274 name
= gfc_get_string (PREFIX ("signal_sub_int"));
3277 name
= gfc_get_string (PREFIX ("signal_sub"));
3279 if (number
->ts
.kind
!= gfc_c_int_kind
)
3280 gfc_convert_type (number
, &ts
, 2);
3281 if (status
!= NULL
&& status
->ts
.kind
!= gfc_c_int_kind
)
3282 gfc_convert_type (status
, &ts
, 2);
3284 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3288 /* Resolve the SYSTEM intrinsic subroutine. */
3291 gfc_resolve_system_sub (gfc_code
*c
)
3294 name
= gfc_get_string (PREFIX ("system_sub"));
3295 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3299 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
3302 gfc_resolve_system_clock (gfc_code
*c
)
3306 gfc_expr
*count
= c
->ext
.actual
->expr
;
3307 gfc_expr
*count_max
= c
->ext
.actual
->next
->next
->expr
;
3309 /* The INTEGER(8) version has higher precision, it is used if both COUNT
3310 and COUNT_MAX can hold 64-bit values, or are absent. */
3311 if ((!count
|| count
->ts
.kind
>= 8)
3312 && (!count_max
|| count_max
->ts
.kind
>= 8))
3315 kind
= gfc_default_integer_kind
;
3317 name
= gfc_get_string (PREFIX ("system_clock_%d"), kind
);
3318 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3322 /* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine. */
3324 gfc_resolve_execute_command_line (gfc_code
*c
)
3327 name
= gfc_get_string (PREFIX ("execute_command_line_i%d"),
3328 gfc_default_integer_kind
);
3329 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3333 /* Resolve the EXIT intrinsic subroutine. */
3336 gfc_resolve_exit (gfc_code
*c
)
3343 /* The STATUS argument has to be of default kind. If it is not,
3345 ts
.type
= BT_INTEGER
;
3346 ts
.kind
= gfc_default_integer_kind
;
3347 n
= c
->ext
.actual
->expr
;
3348 if (n
!= NULL
&& n
->ts
.kind
!= ts
.kind
)
3349 gfc_convert_type (n
, &ts
, 2);
3351 name
= gfc_get_string (PREFIX ("exit_i%d"), ts
.kind
);
3352 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3356 /* Resolve the FLUSH intrinsic subroutine. */
3359 gfc_resolve_flush (gfc_code
*c
)
3366 ts
.type
= BT_INTEGER
;
3367 ts
.kind
= gfc_default_integer_kind
;
3368 n
= c
->ext
.actual
->expr
;
3369 if (n
!= NULL
&& n
->ts
.kind
!= ts
.kind
)
3370 gfc_convert_type (n
, &ts
, 2);
3372 name
= gfc_get_string (PREFIX ("flush_i%d"), ts
.kind
);
3373 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3378 gfc_resolve_free (gfc_code
*c
)
3384 ts
.type
= BT_INTEGER
;
3385 ts
.kind
= gfc_index_integer_kind
;
3386 n
= c
->ext
.actual
->expr
;
3387 if (n
->ts
.kind
!= ts
.kind
)
3388 gfc_convert_type (n
, &ts
, 2);
3390 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
3395 gfc_resolve_ctime_sub (gfc_code
*c
)
3400 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3401 if (c
->ext
.actual
->expr
->ts
.kind
!= 8)
3403 ts
.type
= BT_INTEGER
;
3405 ts
.u
.derived
= NULL
;
3407 gfc_convert_type (c
->ext
.actual
->expr
, &ts
, 2);
3410 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3415 gfc_resolve_fdate_sub (gfc_code
*c
)
3417 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3422 gfc_resolve_gerror (gfc_code
*c
)
3424 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3429 gfc_resolve_getlog (gfc_code
*c
)
3431 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3436 gfc_resolve_hostnm_sub (gfc_code
*c
)
3441 if (c
->ext
.actual
->next
->expr
!= NULL
)
3442 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3444 kind
= gfc_default_integer_kind
;
3446 name
= gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind
);
3447 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3452 gfc_resolve_perror (gfc_code
*c
)
3454 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3457 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3460 gfc_resolve_stat_sub (gfc_code
*c
)
3463 name
= gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind
);
3464 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3469 gfc_resolve_lstat_sub (gfc_code
*c
)
3472 name
= gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind
);
3473 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3478 gfc_resolve_fstat_sub (gfc_code
*c
)
3484 u
= c
->ext
.actual
->expr
;
3485 ts
= &c
->ext
.actual
->next
->expr
->ts
;
3486 if (u
->ts
.kind
!= ts
->kind
)
3487 gfc_convert_type (u
, ts
, 2);
3488 name
= gfc_get_string (PREFIX ("fstat_i%d_sub"), ts
->kind
);
3489 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3494 gfc_resolve_fgetc_sub (gfc_code
*c
)
3501 u
= c
->ext
.actual
->expr
;
3502 st
= c
->ext
.actual
->next
->next
->expr
;
3504 if (u
->ts
.kind
!= gfc_c_int_kind
)
3506 ts
.type
= BT_INTEGER
;
3507 ts
.kind
= gfc_c_int_kind
;
3508 ts
.u
.derived
= NULL
;
3510 gfc_convert_type (u
, &ts
, 2);
3514 name
= gfc_get_string (PREFIX ("fgetc_i%d_sub"), st
->ts
.kind
);
3516 name
= gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind
);
3518 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3523 gfc_resolve_fget_sub (gfc_code
*c
)
3528 st
= c
->ext
.actual
->next
->expr
;
3530 name
= gfc_get_string (PREFIX ("fget_i%d_sub"), st
->ts
.kind
);
3532 name
= gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind
);
3534 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3539 gfc_resolve_fputc_sub (gfc_code
*c
)
3546 u
= c
->ext
.actual
->expr
;
3547 st
= c
->ext
.actual
->next
->next
->expr
;
3549 if (u
->ts
.kind
!= gfc_c_int_kind
)
3551 ts
.type
= BT_INTEGER
;
3552 ts
.kind
= gfc_c_int_kind
;
3553 ts
.u
.derived
= NULL
;
3555 gfc_convert_type (u
, &ts
, 2);
3559 name
= gfc_get_string (PREFIX ("fputc_i%d_sub"), st
->ts
.kind
);
3561 name
= gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind
);
3563 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3568 gfc_resolve_fput_sub (gfc_code
*c
)
3573 st
= c
->ext
.actual
->next
->expr
;
3575 name
= gfc_get_string (PREFIX ("fput_i%d_sub"), st
->ts
.kind
);
3577 name
= gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind
);
3579 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3584 gfc_resolve_fseek_sub (gfc_code
*c
)
3592 unit
= c
->ext
.actual
->expr
;
3593 offset
= c
->ext
.actual
->next
->expr
;
3594 whence
= c
->ext
.actual
->next
->next
->expr
;
3596 if (unit
->ts
.kind
!= gfc_c_int_kind
)
3598 ts
.type
= BT_INTEGER
;
3599 ts
.kind
= gfc_c_int_kind
;
3600 ts
.u
.derived
= NULL
;
3602 gfc_convert_type (unit
, &ts
, 2);
3605 if (offset
->ts
.kind
!= gfc_intio_kind
)
3607 ts
.type
= BT_INTEGER
;
3608 ts
.kind
= gfc_intio_kind
;
3609 ts
.u
.derived
= NULL
;
3611 gfc_convert_type (offset
, &ts
, 2);
3614 if (whence
->ts
.kind
!= gfc_c_int_kind
)
3616 ts
.type
= BT_INTEGER
;
3617 ts
.kind
= gfc_c_int_kind
;
3618 ts
.u
.derived
= NULL
;
3620 gfc_convert_type (whence
, &ts
, 2);
3623 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3627 gfc_resolve_ftell_sub (gfc_code
*c
)
3635 unit
= c
->ext
.actual
->expr
;
3636 offset
= c
->ext
.actual
->next
->expr
;
3638 if (unit
->ts
.kind
!= gfc_c_int_kind
)
3640 ts
.type
= BT_INTEGER
;
3641 ts
.kind
= gfc_c_int_kind
;
3642 ts
.u
.derived
= NULL
;
3644 gfc_convert_type (unit
, &ts
, 2);
3647 name
= gfc_get_string (PREFIX ("ftell_i%d_sub"), offset
->ts
.kind
);
3648 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3653 gfc_resolve_ttynam_sub (gfc_code
*c
)
3658 if (c
->ext
.actual
->expr
->ts
.kind
!= gfc_c_int_kind
)
3660 ts
.type
= BT_INTEGER
;
3661 ts
.kind
= gfc_c_int_kind
;
3662 ts
.u
.derived
= NULL
;
3664 gfc_convert_type (c
->ext
.actual
->expr
, &ts
, 2);
3667 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3671 /* Resolve the UMASK intrinsic subroutine. */
3674 gfc_resolve_umask_sub (gfc_code
*c
)
3679 if (c
->ext
.actual
->next
->expr
!= NULL
)
3680 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3682 kind
= gfc_default_integer_kind
;
3684 name
= gfc_get_string (PREFIX ("umask_i%d_sub"), kind
);
3685 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3688 /* Resolve the UNLINK intrinsic subroutine. */
3691 gfc_resolve_unlink_sub (gfc_code
*c
)
3696 if (c
->ext
.actual
->next
->expr
!= NULL
)
3697 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3699 kind
= gfc_default_integer_kind
;
3701 name
= gfc_get_string (PREFIX ("unlink_i%d_sub"), kind
);
3702 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);