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
= xstrdup (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_ceiling (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
506 f
->ts
.type
= BT_INTEGER
;
507 f
->ts
.kind
= (kind
== NULL
)
508 ? gfc_default_integer_kind
: mpz_get_si (kind
->value
.integer
);
509 f
->value
.function
.name
510 = gfc_get_string ("__ceiling_%d_%c%d", f
->ts
.kind
,
511 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
516 gfc_resolve_char (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
518 gfc_resolve_char_achar (f
, a
, kind
, "__char_%d_%c%d");
523 gfc_resolve_chdir (gfc_expr
*f
, gfc_expr
*d ATTRIBUTE_UNUSED
)
525 f
->ts
.type
= BT_INTEGER
;
526 f
->ts
.kind
= gfc_default_integer_kind
;
527 f
->value
.function
.name
= gfc_get_string (PREFIX ("chdir_i%d"), f
->ts
.kind
);
532 gfc_resolve_chdir_sub (gfc_code
*c
)
537 if (c
->ext
.actual
->next
->expr
!= NULL
)
538 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
540 kind
= gfc_default_integer_kind
;
542 name
= gfc_get_string (PREFIX ("chdir_i%d_sub"), kind
);
543 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
548 gfc_resolve_chmod (gfc_expr
*f
, gfc_expr
*name ATTRIBUTE_UNUSED
,
549 gfc_expr
*mode ATTRIBUTE_UNUSED
)
551 f
->ts
.type
= BT_INTEGER
;
552 f
->ts
.kind
= gfc_c_int_kind
;
553 f
->value
.function
.name
= PREFIX ("chmod_func");
558 gfc_resolve_chmod_sub (gfc_code
*c
)
563 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
564 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
566 kind
= gfc_default_integer_kind
;
568 name
= gfc_get_string (PREFIX ("chmod_i%d_sub"), kind
);
569 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
574 gfc_resolve_cmplx (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*kind
)
576 f
->ts
.type
= BT_COMPLEX
;
577 f
->ts
.kind
= (kind
== NULL
)
578 ? gfc_default_real_kind
: mpz_get_si (kind
->value
.integer
);
581 f
->value
.function
.name
582 = gfc_get_string ("__cmplx0_%d_%c%d", f
->ts
.kind
,
583 gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
585 f
->value
.function
.name
586 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f
->ts
.kind
,
587 gfc_type_letter (x
->ts
.type
), x
->ts
.kind
,
588 gfc_type_letter (y
->ts
.type
), y
->ts
.kind
);
593 gfc_resolve_dcmplx (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*y
)
595 gfc_resolve_cmplx (f
, x
, y
, gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
596 gfc_default_double_kind
));
601 gfc_resolve_complex (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*y
)
605 if (x
->ts
.type
== BT_INTEGER
)
607 if (y
->ts
.type
== BT_INTEGER
)
608 kind
= gfc_default_real_kind
;
614 if (y
->ts
.type
== BT_REAL
)
615 kind
= (x
->ts
.kind
> y
->ts
.kind
) ? x
->ts
.kind
: y
->ts
.kind
;
620 f
->ts
.type
= BT_COMPLEX
;
622 f
->value
.function
.name
623 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f
->ts
.kind
,
624 gfc_type_letter (x
->ts
.type
), x
->ts
.kind
,
625 gfc_type_letter (y
->ts
.type
), y
->ts
.kind
);
630 gfc_resolve_conjg (gfc_expr
*f
, gfc_expr
*x
)
633 f
->value
.function
.name
= gfc_get_string ("__conjg_%d", x
->ts
.kind
);
638 gfc_resolve_cos (gfc_expr
*f
, gfc_expr
*x
)
641 f
->value
.function
.name
642 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
647 gfc_resolve_cosh (gfc_expr
*f
, gfc_expr
*x
)
650 f
->value
.function
.name
651 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
656 gfc_resolve_count (gfc_expr
*f
, gfc_expr
*mask
, gfc_expr
*dim
, gfc_expr
*kind
)
658 f
->ts
.type
= BT_INTEGER
;
660 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
662 f
->ts
.kind
= gfc_default_integer_kind
;
666 f
->rank
= mask
->rank
- 1;
667 gfc_resolve_dim_arg (dim
);
668 f
->shape
= gfc_copy_shape_excluding (mask
->shape
, mask
->rank
, dim
);
671 resolve_mask_arg (mask
);
673 f
->value
.function
.name
674 = gfc_get_string (PREFIX ("count_%d_%c"), f
->ts
.kind
,
675 gfc_type_letter (mask
->ts
.type
));
680 gfc_resolve_cshift (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*shift
,
685 if (array
->ts
.type
== BT_CHARACTER
&& array
->ref
)
686 gfc_resolve_substring_charlen (array
);
689 f
->rank
= array
->rank
;
690 f
->shape
= gfc_copy_shape (array
->shape
, array
->rank
);
697 /* If dim kind is greater than default integer we need to use the larger. */
698 m
= gfc_default_integer_kind
;
700 m
= m
< dim
->ts
.kind
? dim
->ts
.kind
: m
;
702 /* Convert shift to at least m, so we don't need
703 kind=1 and kind=2 versions of the library functions. */
704 if (shift
->ts
.kind
< m
)
708 ts
.type
= BT_INTEGER
;
710 gfc_convert_type_warn (shift
, &ts
, 2, 0);
715 if (dim
->expr_type
!= EXPR_CONSTANT
&& dim
->symtree
!= NULL
716 && dim
->symtree
->n
.sym
->attr
.optional
)
718 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
719 dim
->representation
.length
= shift
->ts
.kind
;
723 gfc_resolve_dim_arg (dim
);
724 /* Convert dim to shift's kind to reduce variations. */
725 if (dim
->ts
.kind
!= shift
->ts
.kind
)
726 gfc_convert_type_warn (dim
, &shift
->ts
, 2, 0);
730 if (array
->ts
.type
== BT_CHARACTER
)
732 if (array
->ts
.kind
== gfc_default_character_kind
)
733 f
->value
.function
.name
734 = gfc_get_string (PREFIX ("cshift%d_%d_char"), n
, shift
->ts
.kind
);
736 f
->value
.function
.name
737 = gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n
, shift
->ts
.kind
,
741 f
->value
.function
.name
742 = gfc_get_string (PREFIX ("cshift%d_%d"), n
, shift
->ts
.kind
);
747 gfc_resolve_ctime (gfc_expr
*f
, gfc_expr
*time
)
752 f
->ts
.type
= BT_CHARACTER
;
753 f
->ts
.kind
= gfc_default_character_kind
;
755 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
756 if (time
->ts
.kind
!= 8)
758 ts
.type
= BT_INTEGER
;
762 gfc_convert_type (time
, &ts
, 2);
765 f
->value
.function
.name
= gfc_get_string (PREFIX ("ctime"));
770 gfc_resolve_dble (gfc_expr
*f
, gfc_expr
*a
)
772 f
->ts
.type
= BT_REAL
;
773 f
->ts
.kind
= gfc_default_double_kind
;
774 f
->value
.function
.name
775 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
780 gfc_resolve_dim (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*p
)
782 f
->ts
.type
= a
->ts
.type
;
784 f
->ts
.kind
= gfc_kind_max (a
,p
);
786 f
->ts
.kind
= a
->ts
.kind
;
788 if (p
!= NULL
&& a
->ts
.kind
!= p
->ts
.kind
)
790 if (a
->ts
.kind
== gfc_kind_max (a
,p
))
791 gfc_convert_type (p
, &a
->ts
, 2);
793 gfc_convert_type (a
, &p
->ts
, 2);
796 f
->value
.function
.name
797 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f
->ts
.type
), f
->ts
.kind
);
802 gfc_resolve_dot_product (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*b
)
806 temp
.expr_type
= EXPR_OP
;
807 gfc_clear_ts (&temp
.ts
);
808 temp
.value
.op
.op
= INTRINSIC_NONE
;
809 temp
.value
.op
.op1
= a
;
810 temp
.value
.op
.op2
= b
;
811 gfc_type_convert_binary (&temp
, 1);
813 f
->value
.function
.name
814 = gfc_get_string (PREFIX ("dot_product_%c%d"),
815 gfc_type_letter (f
->ts
.type
), f
->ts
.kind
);
820 gfc_resolve_dprod (gfc_expr
*f
, gfc_expr
*a ATTRIBUTE_UNUSED
,
821 gfc_expr
*b ATTRIBUTE_UNUSED
)
823 f
->ts
.kind
= gfc_default_double_kind
;
824 f
->ts
.type
= BT_REAL
;
825 f
->value
.function
.name
= gfc_get_string ("__dprod_r%d", f
->ts
.kind
);
830 gfc_resolve_dshift (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j ATTRIBUTE_UNUSED
,
831 gfc_expr
*shift ATTRIBUTE_UNUSED
)
834 if (f
->value
.function
.isym
->id
== GFC_ISYM_DSHIFTL
)
835 f
->value
.function
.name
= gfc_get_string ("dshiftl_i%d", f
->ts
.kind
);
836 else if (f
->value
.function
.isym
->id
== GFC_ISYM_DSHIFTR
)
837 f
->value
.function
.name
= gfc_get_string ("dshiftr_i%d", f
->ts
.kind
);
844 gfc_resolve_eoshift (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*shift
,
845 gfc_expr
*boundary
, gfc_expr
*dim
)
849 if (array
->ts
.type
== BT_CHARACTER
&& array
->ref
)
850 gfc_resolve_substring_charlen (array
);
853 f
->rank
= array
->rank
;
854 f
->shape
= gfc_copy_shape (array
->shape
, array
->rank
);
859 if (boundary
&& boundary
->rank
> 0)
862 /* If dim kind is greater than default integer we need to use the larger. */
863 m
= gfc_default_integer_kind
;
865 m
= m
< dim
->ts
.kind
? dim
->ts
.kind
: m
;
867 /* Convert shift to at least m, so we don't need
868 kind=1 and kind=2 versions of the library functions. */
869 if (shift
->ts
.kind
< m
)
873 ts
.type
= BT_INTEGER
;
875 gfc_convert_type_warn (shift
, &ts
, 2, 0);
880 if (dim
->expr_type
!= EXPR_CONSTANT
&& dim
->symtree
!= NULL
881 && dim
->symtree
->n
.sym
->attr
.optional
)
883 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
884 dim
->representation
.length
= shift
->ts
.kind
;
888 gfc_resolve_dim_arg (dim
);
889 /* Convert dim to shift's kind to reduce variations. */
890 if (dim
->ts
.kind
!= shift
->ts
.kind
)
891 gfc_convert_type_warn (dim
, &shift
->ts
, 2, 0);
895 if (array
->ts
.type
== BT_CHARACTER
)
897 if (array
->ts
.kind
== gfc_default_character_kind
)
898 f
->value
.function
.name
899 = gfc_get_string (PREFIX ("eoshift%d_%d_char"), n
, shift
->ts
.kind
);
901 f
->value
.function
.name
902 = gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n
, shift
->ts
.kind
,
906 f
->value
.function
.name
907 = gfc_get_string (PREFIX ("eoshift%d_%d"), n
, shift
->ts
.kind
);
912 gfc_resolve_exp (gfc_expr
*f
, gfc_expr
*x
)
915 f
->value
.function
.name
916 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
921 gfc_resolve_exponent (gfc_expr
*f
, gfc_expr
*x
)
923 f
->ts
.type
= BT_INTEGER
;
924 f
->ts
.kind
= gfc_default_integer_kind
;
925 f
->value
.function
.name
= gfc_get_string ("__exponent_%d", x
->ts
.kind
);
929 /* Resolve the EXTENDS_TYPE_OF intrinsic function. */
932 gfc_resolve_extends_type_of (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*mo
)
937 /* Prevent double resolution. */
938 if (f
->ts
.type
== BT_LOGICAL
)
941 /* Replace the first argument with the corresponding vtab. */
942 if (a
->ts
.type
== BT_CLASS
)
943 gfc_add_vptr_component (a
);
944 else if (a
->ts
.type
== BT_DERIVED
)
946 vtab
= gfc_find_derived_vtab (a
->ts
.u
.derived
);
947 /* Clear the old expr. */
948 gfc_free_ref_list (a
->ref
);
949 memset (a
, '\0', sizeof (gfc_expr
));
950 /* Construct a new one. */
951 a
->expr_type
= EXPR_VARIABLE
;
952 st
= gfc_find_symtree (vtab
->ns
->sym_root
, vtab
->name
);
957 /* Replace the second argument with the corresponding vtab. */
958 if (mo
->ts
.type
== BT_CLASS
)
959 gfc_add_vptr_component (mo
);
960 else if (mo
->ts
.type
== BT_DERIVED
)
962 vtab
= gfc_find_derived_vtab (mo
->ts
.u
.derived
);
963 /* Clear the old expr. */
964 gfc_free_ref_list (mo
->ref
);
965 memset (mo
, '\0', sizeof (gfc_expr
));
966 /* Construct a new one. */
967 mo
->expr_type
= EXPR_VARIABLE
;
968 st
= gfc_find_symtree (vtab
->ns
->sym_root
, vtab
->name
);
973 f
->ts
.type
= BT_LOGICAL
;
976 f
->value
.function
.isym
->formal
->ts
= a
->ts
;
977 f
->value
.function
.isym
->formal
->next
->ts
= mo
->ts
;
979 /* Call library function. */
980 f
->value
.function
.name
= gfc_get_string (PREFIX ("is_extension_of"));
985 gfc_resolve_fdate (gfc_expr
*f
)
987 f
->ts
.type
= BT_CHARACTER
;
988 f
->ts
.kind
= gfc_default_character_kind
;
989 f
->value
.function
.name
= gfc_get_string (PREFIX ("fdate"));
994 gfc_resolve_floor (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
996 f
->ts
.type
= BT_INTEGER
;
997 f
->ts
.kind
= (kind
== NULL
)
998 ? gfc_default_integer_kind
: mpz_get_si (kind
->value
.integer
);
999 f
->value
.function
.name
1000 = gfc_get_string ("__floor%d_%c%d", f
->ts
.kind
,
1001 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1006 gfc_resolve_fnum (gfc_expr
*f
, gfc_expr
*n
)
1008 f
->ts
.type
= BT_INTEGER
;
1009 f
->ts
.kind
= gfc_default_integer_kind
;
1010 if (n
->ts
.kind
!= f
->ts
.kind
)
1011 gfc_convert_type (n
, &f
->ts
, 2);
1012 f
->value
.function
.name
= gfc_get_string (PREFIX ("fnum_i%d"), f
->ts
.kind
);
1017 gfc_resolve_fraction (gfc_expr
*f
, gfc_expr
*x
)
1020 f
->value
.function
.name
= gfc_get_string ("__fraction_%d", x
->ts
.kind
);
1024 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
1027 gfc_resolve_g77_math1 (gfc_expr
*f
, gfc_expr
*x
)
1030 f
->value
.function
.name
= gfc_get_string ("<intrinsic>");
1035 gfc_resolve_gamma (gfc_expr
*f
, gfc_expr
*x
)
1038 f
->value
.function
.name
1039 = gfc_get_string ("__tgamma_%d", x
->ts
.kind
);
1044 gfc_resolve_getcwd (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
)
1046 f
->ts
.type
= BT_INTEGER
;
1048 f
->value
.function
.name
= gfc_get_string (PREFIX ("getcwd"));
1053 gfc_resolve_getgid (gfc_expr
*f
)
1055 f
->ts
.type
= BT_INTEGER
;
1057 f
->value
.function
.name
= gfc_get_string (PREFIX ("getgid"));
1062 gfc_resolve_getpid (gfc_expr
*f
)
1064 f
->ts
.type
= BT_INTEGER
;
1066 f
->value
.function
.name
= gfc_get_string (PREFIX ("getpid"));
1071 gfc_resolve_getuid (gfc_expr
*f
)
1073 f
->ts
.type
= BT_INTEGER
;
1075 f
->value
.function
.name
= gfc_get_string (PREFIX ("getuid"));
1080 gfc_resolve_hostnm (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
)
1082 f
->ts
.type
= BT_INTEGER
;
1084 f
->value
.function
.name
= gfc_get_string (PREFIX ("hostnm"));
1089 gfc_resolve_hypot (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*y ATTRIBUTE_UNUSED
)
1092 f
->value
.function
.name
= gfc_get_string ("__hypot_r%d", x
->ts
.kind
);
1097 gfc_resolve_iall (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*mask
)
1099 resolve_transformational ("iall", f
, array
, dim
, mask
);
1104 gfc_resolve_iand (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
1106 /* If the kind of i and j are different, then g77 cross-promoted the
1107 kinds to the largest value. The Fortran 95 standard requires the
1109 if (i
->ts
.kind
!= j
->ts
.kind
)
1111 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
1112 gfc_convert_type (j
, &i
->ts
, 2);
1114 gfc_convert_type (i
, &j
->ts
, 2);
1118 f
->value
.function
.name
= gfc_get_string ("__iand_%d", i
->ts
.kind
);
1123 gfc_resolve_iany (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*mask
)
1125 resolve_transformational ("iany", f
, array
, dim
, mask
);
1130 gfc_resolve_ibclr (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*pos ATTRIBUTE_UNUSED
)
1133 f
->value
.function
.name
= gfc_get_string ("__ibclr_%d", i
->ts
.kind
);
1138 gfc_resolve_ibits (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*pos ATTRIBUTE_UNUSED
,
1139 gfc_expr
*len ATTRIBUTE_UNUSED
)
1142 f
->value
.function
.name
= gfc_get_string ("__ibits_%d", i
->ts
.kind
);
1147 gfc_resolve_ibset (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*pos ATTRIBUTE_UNUSED
)
1150 f
->value
.function
.name
= gfc_get_string ("__ibset_%d", i
->ts
.kind
);
1155 gfc_resolve_iachar (gfc_expr
*f
, gfc_expr
*c
, gfc_expr
*kind
)
1157 f
->ts
.type
= BT_INTEGER
;
1159 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1161 f
->ts
.kind
= gfc_default_integer_kind
;
1162 f
->value
.function
.name
= gfc_get_string ("__ichar_%d", c
->ts
.kind
);
1167 gfc_resolve_ichar (gfc_expr
*f
, gfc_expr
*c
, gfc_expr
*kind
)
1169 f
->ts
.type
= BT_INTEGER
;
1171 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1173 f
->ts
.kind
= gfc_default_integer_kind
;
1174 f
->value
.function
.name
= gfc_get_string ("__ichar_%d", c
->ts
.kind
);
1179 gfc_resolve_idnint (gfc_expr
*f
, gfc_expr
*a
)
1181 gfc_resolve_nint (f
, a
, NULL
);
1186 gfc_resolve_ierrno (gfc_expr
*f
)
1188 f
->ts
.type
= BT_INTEGER
;
1189 f
->ts
.kind
= gfc_default_integer_kind
;
1190 f
->value
.function
.name
= gfc_get_string (PREFIX ("ierrno_i%d"), f
->ts
.kind
);
1195 gfc_resolve_ieor (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
1197 /* If the kind of i and j are different, then g77 cross-promoted the
1198 kinds to the largest value. The Fortran 95 standard requires the
1200 if (i
->ts
.kind
!= j
->ts
.kind
)
1202 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
1203 gfc_convert_type (j
, &i
->ts
, 2);
1205 gfc_convert_type (i
, &j
->ts
, 2);
1209 f
->value
.function
.name
= gfc_get_string ("__ieor_%d", i
->ts
.kind
);
1214 gfc_resolve_ior (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
1216 /* If the kind of i and j are different, then g77 cross-promoted the
1217 kinds to the largest value. The Fortran 95 standard requires the
1219 if (i
->ts
.kind
!= j
->ts
.kind
)
1221 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
1222 gfc_convert_type (j
, &i
->ts
, 2);
1224 gfc_convert_type (i
, &j
->ts
, 2);
1228 f
->value
.function
.name
= gfc_get_string ("__ior_%d", i
->ts
.kind
);
1233 gfc_resolve_index_func (gfc_expr
*f
, gfc_expr
*str
,
1234 gfc_expr
*sub_str ATTRIBUTE_UNUSED
, gfc_expr
*back
,
1240 f
->ts
.type
= BT_INTEGER
;
1242 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1244 f
->ts
.kind
= gfc_default_integer_kind
;
1246 if (back
&& back
->ts
.kind
!= gfc_default_integer_kind
)
1248 ts
.type
= BT_LOGICAL
;
1249 ts
.kind
= gfc_default_integer_kind
;
1250 ts
.u
.derived
= NULL
;
1252 gfc_convert_type (back
, &ts
, 2);
1255 f
->value
.function
.name
1256 = gfc_get_string ("__index_%d_i%d", str
->ts
.kind
, f
->ts
.kind
);
1261 gfc_resolve_int (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
1263 f
->ts
.type
= BT_INTEGER
;
1264 f
->ts
.kind
= (kind
== NULL
)
1265 ? gfc_default_integer_kind
: mpz_get_si (kind
->value
.integer
);
1266 f
->value
.function
.name
1267 = gfc_get_string ("__int_%d_%c%d", f
->ts
.kind
,
1268 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1273 gfc_resolve_int2 (gfc_expr
*f
, gfc_expr
*a
)
1275 f
->ts
.type
= BT_INTEGER
;
1277 f
->value
.function
.name
1278 = gfc_get_string ("__int_%d_%c%d", f
->ts
.kind
,
1279 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1284 gfc_resolve_int8 (gfc_expr
*f
, gfc_expr
*a
)
1286 f
->ts
.type
= BT_INTEGER
;
1288 f
->value
.function
.name
1289 = gfc_get_string ("__int_%d_%c%d", f
->ts
.kind
,
1290 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1295 gfc_resolve_long (gfc_expr
*f
, gfc_expr
*a
)
1297 f
->ts
.type
= BT_INTEGER
;
1299 f
->value
.function
.name
1300 = gfc_get_string ("__int_%d_%c%d", f
->ts
.kind
,
1301 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1306 gfc_resolve_iparity (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*mask
)
1308 resolve_transformational ("iparity", f
, array
, dim
, mask
);
1313 gfc_resolve_isatty (gfc_expr
*f
, gfc_expr
*u
)
1318 f
->ts
.type
= BT_LOGICAL
;
1319 f
->ts
.kind
= gfc_default_integer_kind
;
1320 if (u
->ts
.kind
!= gfc_c_int_kind
)
1322 ts
.type
= BT_INTEGER
;
1323 ts
.kind
= gfc_c_int_kind
;
1324 ts
.u
.derived
= NULL
;
1326 gfc_convert_type (u
, &ts
, 2);
1329 f
->value
.function
.name
= gfc_get_string (PREFIX ("isatty_l%d"), f
->ts
.kind
);
1334 gfc_resolve_ishft (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift
)
1337 f
->value
.function
.name
1338 = gfc_get_string ("__ishft_%d_%d", i
->ts
.kind
, shift
->ts
.kind
);
1343 gfc_resolve_rshift (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift
)
1346 f
->value
.function
.name
1347 = gfc_get_string ("__rshift_%d_%d", i
->ts
.kind
, shift
->ts
.kind
);
1352 gfc_resolve_lshift (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift
)
1355 f
->value
.function
.name
1356 = gfc_get_string ("__lshift_%d_%d", i
->ts
.kind
, shift
->ts
.kind
);
1361 gfc_resolve_ishftc (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift
, gfc_expr
*size
)
1365 s_kind
= (size
== NULL
) ? gfc_default_integer_kind
: size
->ts
.kind
;
1368 f
->value
.function
.name
1369 = gfc_get_string ("__ishftc_%d_%d_%d", i
->ts
.kind
, shift
->ts
.kind
, s_kind
);
1374 gfc_resolve_kill (gfc_expr
*f
, gfc_expr
*p ATTRIBUTE_UNUSED
,
1375 gfc_expr
*s ATTRIBUTE_UNUSED
)
1377 f
->ts
.type
= BT_INTEGER
;
1378 f
->ts
.kind
= gfc_default_integer_kind
;
1379 f
->value
.function
.name
= gfc_get_string (PREFIX ("kill_i%d"), f
->ts
.kind
);
1384 gfc_resolve_lbound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
1386 resolve_bound (f
, array
, dim
, kind
, "__lbound", false);
1391 gfc_resolve_lcobound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
1393 resolve_bound (f
, array
, dim
, kind
, "__lcobound", true);
1398 gfc_resolve_len (gfc_expr
*f
, gfc_expr
*string
, gfc_expr
*kind
)
1400 f
->ts
.type
= BT_INTEGER
;
1402 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
1404 f
->ts
.kind
= gfc_default_integer_kind
;
1405 f
->value
.function
.name
1406 = gfc_get_string ("__len_%d_i%d", string
->ts
.kind
,
1407 gfc_default_integer_kind
);
1412 gfc_resolve_len_trim (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
= gfc_get_string ("__len_trim%d", string
->ts
.kind
);
1424 gfc_resolve_lgamma (gfc_expr
*f
, gfc_expr
*x
)
1427 f
->value
.function
.name
1428 = gfc_get_string ("__lgamma_%d", x
->ts
.kind
);
1433 gfc_resolve_link (gfc_expr
*f
, gfc_expr
*p1 ATTRIBUTE_UNUSED
,
1434 gfc_expr
*p2 ATTRIBUTE_UNUSED
)
1436 f
->ts
.type
= BT_INTEGER
;
1437 f
->ts
.kind
= gfc_default_integer_kind
;
1438 f
->value
.function
.name
= gfc_get_string (PREFIX ("link_i%d"), f
->ts
.kind
);
1443 gfc_resolve_loc (gfc_expr
*f
, gfc_expr
*x
)
1445 f
->ts
.type
= BT_INTEGER
;
1446 f
->ts
.kind
= gfc_index_integer_kind
;
1447 f
->value
.function
.name
= gfc_get_string ("__loc_%d", x
->ts
.kind
);
1452 gfc_resolve_log (gfc_expr
*f
, gfc_expr
*x
)
1455 f
->value
.function
.name
1456 = gfc_get_string ("__log_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
1461 gfc_resolve_log10 (gfc_expr
*f
, gfc_expr
*x
)
1464 f
->value
.function
.name
1465 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x
->ts
.type
),
1471 gfc_resolve_logical (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
1473 f
->ts
.type
= BT_LOGICAL
;
1474 f
->ts
.kind
= (kind
== NULL
)
1475 ? gfc_default_logical_kind
: mpz_get_si (kind
->value
.integer
);
1478 f
->value
.function
.name
1479 = gfc_get_string ("__logical_%d_%c%d", f
->ts
.kind
,
1480 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
1485 gfc_resolve_malloc (gfc_expr
*f
, gfc_expr
*size
)
1487 if (size
->ts
.kind
< gfc_index_integer_kind
)
1492 ts
.type
= BT_INTEGER
;
1493 ts
.kind
= gfc_index_integer_kind
;
1494 gfc_convert_type_warn (size
, &ts
, 2, 0);
1497 f
->ts
.type
= BT_INTEGER
;
1498 f
->ts
.kind
= gfc_index_integer_kind
;
1499 f
->value
.function
.name
= gfc_get_string (PREFIX ("malloc"));
1504 gfc_resolve_matmul (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*b
)
1508 if (a
->ts
.type
== BT_LOGICAL
&& b
->ts
.type
== BT_LOGICAL
)
1510 f
->ts
.type
= BT_LOGICAL
;
1511 f
->ts
.kind
= gfc_default_logical_kind
;
1515 temp
.expr_type
= EXPR_OP
;
1516 gfc_clear_ts (&temp
.ts
);
1517 temp
.value
.op
.op
= INTRINSIC_NONE
;
1518 temp
.value
.op
.op1
= a
;
1519 temp
.value
.op
.op2
= b
;
1520 gfc_type_convert_binary (&temp
, 1);
1524 f
->rank
= (a
->rank
== 2 && b
->rank
== 2) ? 2 : 1;
1526 if (a
->rank
== 2 && b
->rank
== 2)
1528 if (a
->shape
&& b
->shape
)
1530 f
->shape
= gfc_get_shape (f
->rank
);
1531 mpz_init_set (f
->shape
[0], a
->shape
[0]);
1532 mpz_init_set (f
->shape
[1], b
->shape
[1]);
1535 else if (a
->rank
== 1)
1539 f
->shape
= gfc_get_shape (f
->rank
);
1540 mpz_init_set (f
->shape
[0], b
->shape
[1]);
1545 /* b->rank == 1 and a->rank == 2 here, all other cases have
1546 been caught in check.c. */
1549 f
->shape
= gfc_get_shape (f
->rank
);
1550 mpz_init_set (f
->shape
[0], a
->shape
[0]);
1554 f
->value
.function
.name
1555 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f
->ts
.type
),
1561 gfc_resolve_minmax (const char *name
, gfc_expr
*f
, gfc_actual_arglist
*args
)
1563 gfc_actual_arglist
*a
;
1565 f
->ts
.type
= args
->expr
->ts
.type
;
1566 f
->ts
.kind
= args
->expr
->ts
.kind
;
1567 /* Find the largest type kind. */
1568 for (a
= args
->next
; a
; a
= a
->next
)
1570 if (a
->expr
->ts
.kind
> f
->ts
.kind
)
1571 f
->ts
.kind
= a
->expr
->ts
.kind
;
1574 /* Convert all parameters to the required kind. */
1575 for (a
= args
; a
; a
= a
->next
)
1577 if (a
->expr
->ts
.kind
!= f
->ts
.kind
)
1578 gfc_convert_type (a
->expr
, &f
->ts
, 2);
1581 f
->value
.function
.name
1582 = gfc_get_string (name
, gfc_type_letter (f
->ts
.type
), f
->ts
.kind
);
1587 gfc_resolve_max (gfc_expr
*f
, gfc_actual_arglist
*args
)
1589 gfc_resolve_minmax ("__max_%c%d", f
, args
);
1594 gfc_resolve_maxloc (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
1600 f
->ts
.type
= BT_INTEGER
;
1601 f
->ts
.kind
= gfc_default_integer_kind
;
1606 f
->shape
= gfc_get_shape (1);
1607 mpz_init_set_si (f
->shape
[0], array
->rank
);
1611 f
->rank
= array
->rank
- 1;
1612 gfc_resolve_dim_arg (dim
);
1613 if (array
->shape
&& dim
->expr_type
== EXPR_CONSTANT
)
1615 idim
= (int) mpz_get_si (dim
->value
.integer
);
1616 f
->shape
= gfc_get_shape (f
->rank
);
1617 for (i
= 0, j
= 0; i
< f
->rank
; i
++, j
++)
1619 if (i
== (idim
- 1))
1621 mpz_init_set (f
->shape
[i
], array
->shape
[j
]);
1628 if (mask
->rank
== 0)
1633 resolve_mask_arg (mask
);
1638 f
->value
.function
.name
1639 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name
, dim
!= NULL
, f
->ts
.kind
,
1640 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
1645 gfc_resolve_maxval (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
1655 f
->rank
= array
->rank
- 1;
1656 gfc_resolve_dim_arg (dim
);
1658 if (f
->rank
&& array
->shape
&& dim
->expr_type
== EXPR_CONSTANT
)
1660 idim
= (int) mpz_get_si (dim
->value
.integer
);
1661 f
->shape
= gfc_get_shape (f
->rank
);
1662 for (i
= 0, j
= 0; i
< f
->rank
; i
++, j
++)
1664 if (i
== (idim
- 1))
1666 mpz_init_set (f
->shape
[i
], array
->shape
[j
]);
1673 if (mask
->rank
== 0)
1678 resolve_mask_arg (mask
);
1683 f
->value
.function
.name
1684 = gfc_get_string (PREFIX ("%s_%c%d"), name
,
1685 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
1690 gfc_resolve_mclock (gfc_expr
*f
)
1692 f
->ts
.type
= BT_INTEGER
;
1694 f
->value
.function
.name
= PREFIX ("mclock");
1699 gfc_resolve_mclock8 (gfc_expr
*f
)
1701 f
->ts
.type
= BT_INTEGER
;
1703 f
->value
.function
.name
= PREFIX ("mclock8");
1708 gfc_resolve_mask (gfc_expr
*f
, gfc_expr
*i ATTRIBUTE_UNUSED
,
1711 f
->ts
.type
= BT_INTEGER
;
1712 f
->ts
.kind
= kind
? mpz_get_si (kind
->value
.integer
)
1713 : gfc_default_integer_kind
;
1715 if (f
->value
.function
.isym
->id
== GFC_ISYM_MASKL
)
1716 f
->value
.function
.name
= gfc_get_string ("__maskl_i%d", f
->ts
.kind
);
1718 f
->value
.function
.name
= gfc_get_string ("__maskr_i%d", f
->ts
.kind
);
1723 gfc_resolve_merge (gfc_expr
*f
, gfc_expr
*tsource
,
1724 gfc_expr
*fsource ATTRIBUTE_UNUSED
,
1725 gfc_expr
*mask ATTRIBUTE_UNUSED
)
1727 if (tsource
->ts
.type
== BT_CHARACTER
&& tsource
->ref
)
1728 gfc_resolve_substring_charlen (tsource
);
1730 if (fsource
->ts
.type
== BT_CHARACTER
&& fsource
->ref
)
1731 gfc_resolve_substring_charlen (fsource
);
1733 if (tsource
->ts
.type
== BT_CHARACTER
)
1734 check_charlen_present (tsource
);
1736 f
->ts
= tsource
->ts
;
1737 f
->value
.function
.name
1738 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource
->ts
.type
),
1744 gfc_resolve_merge_bits (gfc_expr
*f
, gfc_expr
*i
,
1745 gfc_expr
*j ATTRIBUTE_UNUSED
,
1746 gfc_expr
*mask ATTRIBUTE_UNUSED
)
1749 f
->value
.function
.name
= gfc_get_string ("__merge_bits_i%d", i
->ts
.kind
);
1754 gfc_resolve_min (gfc_expr
*f
, gfc_actual_arglist
*args
)
1756 gfc_resolve_minmax ("__min_%c%d", f
, args
);
1761 gfc_resolve_minloc (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
1767 f
->ts
.type
= BT_INTEGER
;
1768 f
->ts
.kind
= gfc_default_integer_kind
;
1773 f
->shape
= gfc_get_shape (1);
1774 mpz_init_set_si (f
->shape
[0], array
->rank
);
1778 f
->rank
= array
->rank
- 1;
1779 gfc_resolve_dim_arg (dim
);
1780 if (array
->shape
&& dim
->expr_type
== EXPR_CONSTANT
)
1782 idim
= (int) mpz_get_si (dim
->value
.integer
);
1783 f
->shape
= gfc_get_shape (f
->rank
);
1784 for (i
= 0, j
= 0; i
< f
->rank
; i
++, j
++)
1786 if (i
== (idim
- 1))
1788 mpz_init_set (f
->shape
[i
], array
->shape
[j
]);
1795 if (mask
->rank
== 0)
1800 resolve_mask_arg (mask
);
1805 f
->value
.function
.name
1806 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name
, dim
!= NULL
, f
->ts
.kind
,
1807 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
1812 gfc_resolve_minval (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
1822 f
->rank
= array
->rank
- 1;
1823 gfc_resolve_dim_arg (dim
);
1825 if (f
->rank
&& array
->shape
&& dim
->expr_type
== EXPR_CONSTANT
)
1827 idim
= (int) mpz_get_si (dim
->value
.integer
);
1828 f
->shape
= gfc_get_shape (f
->rank
);
1829 for (i
= 0, j
= 0; i
< f
->rank
; i
++, j
++)
1831 if (i
== (idim
- 1))
1833 mpz_init_set (f
->shape
[i
], array
->shape
[j
]);
1840 if (mask
->rank
== 0)
1845 resolve_mask_arg (mask
);
1850 f
->value
.function
.name
1851 = gfc_get_string (PREFIX ("%s_%c%d"), name
,
1852 gfc_type_letter (array
->ts
.type
), array
->ts
.kind
);
1857 gfc_resolve_mod (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*p
)
1859 f
->ts
.type
= a
->ts
.type
;
1861 f
->ts
.kind
= gfc_kind_max (a
,p
);
1863 f
->ts
.kind
= a
->ts
.kind
;
1865 if (p
!= NULL
&& a
->ts
.kind
!= p
->ts
.kind
)
1867 if (a
->ts
.kind
== gfc_kind_max (a
,p
))
1868 gfc_convert_type (p
, &a
->ts
, 2);
1870 gfc_convert_type (a
, &p
->ts
, 2);
1873 f
->value
.function
.name
1874 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f
->ts
.type
), f
->ts
.kind
);
1879 gfc_resolve_modulo (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*p
)
1881 f
->ts
.type
= a
->ts
.type
;
1883 f
->ts
.kind
= gfc_kind_max (a
,p
);
1885 f
->ts
.kind
= a
->ts
.kind
;
1887 if (p
!= NULL
&& a
->ts
.kind
!= p
->ts
.kind
)
1889 if (a
->ts
.kind
== gfc_kind_max (a
,p
))
1890 gfc_convert_type (p
, &a
->ts
, 2);
1892 gfc_convert_type (a
, &p
->ts
, 2);
1895 f
->value
.function
.name
1896 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f
->ts
.type
),
1901 gfc_resolve_nearest (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*p
)
1903 if (p
->ts
.kind
!= a
->ts
.kind
)
1904 gfc_convert_type (p
, &a
->ts
, 2);
1907 f
->value
.function
.name
1908 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a
->ts
.type
),
1913 gfc_resolve_nint (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
1915 f
->ts
.type
= BT_INTEGER
;
1916 f
->ts
.kind
= (kind
== NULL
)
1917 ? gfc_default_integer_kind
: mpz_get_si (kind
->value
.integer
);
1918 f
->value
.function
.name
1919 = gfc_get_string ("__nint_%d_%d", f
->ts
.kind
, a
->ts
.kind
);
1924 gfc_resolve_norm2 (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
)
1926 resolve_transformational ("norm2", f
, array
, dim
, NULL
);
1931 gfc_resolve_not (gfc_expr
*f
, gfc_expr
*i
)
1934 f
->value
.function
.name
= gfc_get_string ("__not_%d", i
->ts
.kind
);
1939 gfc_resolve_or (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
1941 f
->ts
.type
= i
->ts
.type
;
1942 f
->ts
.kind
= gfc_kind_max (i
, j
);
1944 if (i
->ts
.kind
!= j
->ts
.kind
)
1946 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
1947 gfc_convert_type (j
, &i
->ts
, 2);
1949 gfc_convert_type (i
, &j
->ts
, 2);
1952 f
->value
.function
.name
1953 = gfc_get_string ("__or_%c%d", gfc_type_letter (i
->ts
.type
), f
->ts
.kind
);
1958 gfc_resolve_pack (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*mask
,
1959 gfc_expr
*vector ATTRIBUTE_UNUSED
)
1961 if (array
->ts
.type
== BT_CHARACTER
&& array
->ref
)
1962 gfc_resolve_substring_charlen (array
);
1967 resolve_mask_arg (mask
);
1969 if (mask
->rank
!= 0)
1971 if (array
->ts
.type
== BT_CHARACTER
)
1972 f
->value
.function
.name
1973 = array
->ts
.kind
== 1 ? PREFIX ("pack_char")
1975 (PREFIX ("pack_char%d"),
1978 f
->value
.function
.name
= PREFIX ("pack");
1982 if (array
->ts
.type
== BT_CHARACTER
)
1983 f
->value
.function
.name
1984 = array
->ts
.kind
== 1 ? PREFIX ("pack_s_char")
1986 (PREFIX ("pack_s_char%d"),
1989 f
->value
.function
.name
= PREFIX ("pack_s");
1995 gfc_resolve_parity (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
)
1997 resolve_transformational ("parity", f
, array
, dim
, NULL
);
2002 gfc_resolve_product (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
,
2005 resolve_transformational ("product", f
, array
, dim
, mask
);
2010 gfc_resolve_rank (gfc_expr
*f
, gfc_expr
*array ATTRIBUTE_UNUSED
)
2012 f
->ts
.type
= BT_INTEGER
;
2013 f
->ts
.kind
= gfc_default_integer_kind
;
2014 f
->value
.function
.name
= gfc_get_string ("__rank");
2019 gfc_resolve_real (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*kind
)
2021 f
->ts
.type
= BT_REAL
;
2024 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2026 f
->ts
.kind
= (a
->ts
.type
== BT_COMPLEX
)
2027 ? a
->ts
.kind
: gfc_default_real_kind
;
2029 f
->value
.function
.name
2030 = gfc_get_string ("__real_%d_%c%d", f
->ts
.kind
,
2031 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
2036 gfc_resolve_realpart (gfc_expr
*f
, gfc_expr
*a
)
2038 f
->ts
.type
= BT_REAL
;
2039 f
->ts
.kind
= a
->ts
.kind
;
2040 f
->value
.function
.name
2041 = gfc_get_string ("__real_%d_%c%d", f
->ts
.kind
,
2042 gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
2047 gfc_resolve_rename (gfc_expr
*f
, gfc_expr
*p1 ATTRIBUTE_UNUSED
,
2048 gfc_expr
*p2 ATTRIBUTE_UNUSED
)
2050 f
->ts
.type
= BT_INTEGER
;
2051 f
->ts
.kind
= gfc_default_integer_kind
;
2052 f
->value
.function
.name
= gfc_get_string (PREFIX ("rename_i%d"), f
->ts
.kind
);
2057 gfc_resolve_repeat (gfc_expr
*f
, gfc_expr
*string
,
2062 f
->ts
.type
= BT_CHARACTER
;
2063 f
->ts
.kind
= string
->ts
.kind
;
2064 f
->value
.function
.name
= gfc_get_string ("__repeat_%d", string
->ts
.kind
);
2066 /* If possible, generate a character length. */
2067 if (f
->ts
.u
.cl
== NULL
)
2068 f
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
2071 if (string
->expr_type
== EXPR_CONSTANT
)
2073 len
= string
->value
.character
.length
;
2074 tmp
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, len
);
2076 else if (string
->ts
.u
.cl
&& string
->ts
.u
.cl
->length
)
2078 tmp
= gfc_copy_expr (string
->ts
.u
.cl
->length
);
2082 f
->ts
.u
.cl
->length
= gfc_multiply (tmp
, gfc_copy_expr (ncopies
));
2087 gfc_resolve_reshape (gfc_expr
*f
, gfc_expr
*source
, gfc_expr
*shape
,
2088 gfc_expr
*pad ATTRIBUTE_UNUSED
,
2089 gfc_expr
*order ATTRIBUTE_UNUSED
)
2095 if (source
->ts
.type
== BT_CHARACTER
&& source
->ref
)
2096 gfc_resolve_substring_charlen (source
);
2100 gfc_array_size (shape
, &rank
);
2101 f
->rank
= mpz_get_si (rank
);
2103 switch (source
->ts
.type
)
2110 kind
= source
->ts
.kind
;
2124 if (source
->ts
.type
== BT_COMPLEX
|| source
->ts
.type
== BT_REAL
)
2125 f
->value
.function
.name
2126 = gfc_get_string (PREFIX ("reshape_%c%d"),
2127 gfc_type_letter (source
->ts
.type
),
2129 else if (source
->ts
.type
== BT_CHARACTER
)
2130 f
->value
.function
.name
= gfc_get_string (PREFIX ("reshape_char%d"),
2133 f
->value
.function
.name
2134 = gfc_get_string (PREFIX ("reshape_%d"), source
->ts
.kind
);
2138 f
->value
.function
.name
= (source
->ts
.type
== BT_CHARACTER
2139 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
2143 /* TODO: Make this work with a constant ORDER parameter. */
2144 if (shape
->expr_type
== EXPR_ARRAY
2145 && gfc_is_constant_expr (shape
)
2149 f
->shape
= gfc_get_shape (f
->rank
);
2150 c
= gfc_constructor_first (shape
->value
.constructor
);
2151 for (i
= 0; i
< f
->rank
; i
++)
2153 mpz_init_set (f
->shape
[i
], c
->expr
->value
.integer
);
2154 c
= gfc_constructor_next (c
);
2158 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
2159 so many runtime variations. */
2160 if (shape
->ts
.kind
!= gfc_index_integer_kind
)
2162 gfc_typespec ts
= shape
->ts
;
2163 ts
.kind
= gfc_index_integer_kind
;
2164 gfc_convert_type_warn (shape
, &ts
, 2, 0);
2166 if (order
&& order
->ts
.kind
!= gfc_index_integer_kind
)
2167 gfc_convert_type_warn (order
, &shape
->ts
, 2, 0);
2172 gfc_resolve_rrspacing (gfc_expr
*f
, gfc_expr
*x
)
2175 f
->value
.function
.name
= gfc_get_string ("__rrspacing_%d", x
->ts
.kind
);
2180 gfc_resolve_scale (gfc_expr
*f
, gfc_expr
*x
, gfc_expr
*i ATTRIBUTE_UNUSED
)
2183 f
->value
.function
.name
= gfc_get_string ("__scale_%d", x
->ts
.kind
);
2188 gfc_resolve_scan (gfc_expr
*f
, gfc_expr
*string
,
2189 gfc_expr
*set ATTRIBUTE_UNUSED
,
2190 gfc_expr
*back ATTRIBUTE_UNUSED
, gfc_expr
*kind
)
2192 f
->ts
.type
= BT_INTEGER
;
2194 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2196 f
->ts
.kind
= gfc_default_integer_kind
;
2197 f
->value
.function
.name
= gfc_get_string ("__scan_%d", string
->ts
.kind
);
2202 gfc_resolve_secnds (gfc_expr
*t1
, gfc_expr
*t0
)
2205 t1
->value
.function
.name
= gfc_get_string (PREFIX ("secnds"));
2210 gfc_resolve_set_exponent (gfc_expr
*f
, gfc_expr
*x
,
2211 gfc_expr
*i ATTRIBUTE_UNUSED
)
2214 f
->value
.function
.name
= gfc_get_string ("__set_exponent_%d", x
->ts
.kind
);
2219 gfc_resolve_shape (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*kind
)
2221 f
->ts
.type
= BT_INTEGER
;
2224 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2226 f
->ts
.kind
= gfc_default_integer_kind
;
2229 if (array
->rank
!= -1)
2231 f
->shape
= gfc_get_shape (1);
2232 mpz_init_set_ui (f
->shape
[0], array
->rank
);
2235 f
->value
.function
.name
= gfc_get_string (PREFIX ("shape_%d"), f
->ts
.kind
);
2240 gfc_resolve_shift (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*shift ATTRIBUTE_UNUSED
)
2243 if (f
->value
.function
.isym
->id
== GFC_ISYM_SHIFTA
)
2244 f
->value
.function
.name
= gfc_get_string ("shifta_i%d", f
->ts
.kind
);
2245 else if (f
->value
.function
.isym
->id
== GFC_ISYM_SHIFTL
)
2246 f
->value
.function
.name
= gfc_get_string ("shiftl_i%d", f
->ts
.kind
);
2247 else if (f
->value
.function
.isym
->id
== GFC_ISYM_SHIFTR
)
2248 f
->value
.function
.name
= gfc_get_string ("shiftr_i%d", f
->ts
.kind
);
2255 gfc_resolve_sign (gfc_expr
*f
, gfc_expr
*a
, gfc_expr
*b ATTRIBUTE_UNUSED
)
2258 f
->value
.function
.name
2259 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a
->ts
.type
), a
->ts
.kind
);
2264 gfc_resolve_signal (gfc_expr
*f
, gfc_expr
*number
, gfc_expr
*handler
)
2266 f
->ts
.type
= BT_INTEGER
;
2267 f
->ts
.kind
= gfc_c_int_kind
;
2269 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2270 if (handler
->ts
.type
== BT_INTEGER
)
2272 if (handler
->ts
.kind
!= gfc_c_int_kind
)
2273 gfc_convert_type (handler
, &f
->ts
, 2);
2274 f
->value
.function
.name
= gfc_get_string (PREFIX ("signal_func_int"));
2277 f
->value
.function
.name
= gfc_get_string (PREFIX ("signal_func"));
2279 if (number
->ts
.kind
!= gfc_c_int_kind
)
2280 gfc_convert_type (number
, &f
->ts
, 2);
2285 gfc_resolve_sin (gfc_expr
*f
, gfc_expr
*x
)
2288 f
->value
.function
.name
2289 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2294 gfc_resolve_sinh (gfc_expr
*f
, gfc_expr
*x
)
2297 f
->value
.function
.name
2298 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2303 gfc_resolve_size (gfc_expr
*f
, gfc_expr
*array ATTRIBUTE_UNUSED
,
2304 gfc_expr
*dim ATTRIBUTE_UNUSED
, gfc_expr
*kind
)
2306 f
->ts
.type
= BT_INTEGER
;
2308 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2310 f
->ts
.kind
= gfc_default_integer_kind
;
2315 gfc_resolve_stride (gfc_expr
*f
, gfc_expr
*array ATTRIBUTE_UNUSED
,
2316 gfc_expr
*dim ATTRIBUTE_UNUSED
)
2318 f
->ts
.type
= BT_INTEGER
;
2319 f
->ts
.kind
= gfc_index_integer_kind
;
2324 gfc_resolve_spacing (gfc_expr
*f
, gfc_expr
*x
)
2327 f
->value
.function
.name
= gfc_get_string ("__spacing_%d", x
->ts
.kind
);
2332 gfc_resolve_spread (gfc_expr
*f
, gfc_expr
*source
, gfc_expr
*dim
,
2335 if (source
->ts
.type
== BT_CHARACTER
&& source
->ref
)
2336 gfc_resolve_substring_charlen (source
);
2338 if (source
->ts
.type
== BT_CHARACTER
)
2339 check_charlen_present (source
);
2342 f
->rank
= source
->rank
+ 1;
2343 if (source
->rank
== 0)
2345 if (source
->ts
.type
== BT_CHARACTER
)
2346 f
->value
.function
.name
2347 = source
->ts
.kind
== 1 ? PREFIX ("spread_char_scalar")
2349 (PREFIX ("spread_char%d_scalar"),
2352 f
->value
.function
.name
= PREFIX ("spread_scalar");
2356 if (source
->ts
.type
== BT_CHARACTER
)
2357 f
->value
.function
.name
2358 = source
->ts
.kind
== 1 ? PREFIX ("spread_char")
2360 (PREFIX ("spread_char%d"),
2363 f
->value
.function
.name
= PREFIX ("spread");
2366 if (dim
&& gfc_is_constant_expr (dim
)
2367 && ncopies
&& gfc_is_constant_expr (ncopies
) && source
->shape
[0])
2370 idim
= mpz_get_ui (dim
->value
.integer
);
2371 f
->shape
= gfc_get_shape (f
->rank
);
2372 for (i
= 0; i
< (idim
- 1); i
++)
2373 mpz_init_set (f
->shape
[i
], source
->shape
[i
]);
2375 mpz_init_set (f
->shape
[idim
- 1], ncopies
->value
.integer
);
2377 for (i
= idim
; i
< f
->rank
; i
++)
2378 mpz_init_set (f
->shape
[i
], source
->shape
[i
-1]);
2382 gfc_resolve_dim_arg (dim
);
2383 gfc_resolve_index (ncopies
, 1);
2388 gfc_resolve_sqrt (gfc_expr
*f
, gfc_expr
*x
)
2391 f
->value
.function
.name
2392 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2396 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2399 gfc_resolve_stat (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
,
2400 gfc_expr
*a ATTRIBUTE_UNUSED
)
2402 f
->ts
.type
= BT_INTEGER
;
2403 f
->ts
.kind
= gfc_default_integer_kind
;
2404 f
->value
.function
.name
= gfc_get_string (PREFIX ("stat_i%d"), f
->ts
.kind
);
2409 gfc_resolve_lstat (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
,
2410 gfc_expr
*a ATTRIBUTE_UNUSED
)
2412 f
->ts
.type
= BT_INTEGER
;
2413 f
->ts
.kind
= gfc_default_integer_kind
;
2414 f
->value
.function
.name
= gfc_get_string (PREFIX ("lstat_i%d"), f
->ts
.kind
);
2419 gfc_resolve_fstat (gfc_expr
*f
, gfc_expr
*n
, gfc_expr
*a ATTRIBUTE_UNUSED
)
2421 f
->ts
.type
= BT_INTEGER
;
2422 f
->ts
.kind
= gfc_default_integer_kind
;
2423 if (n
->ts
.kind
!= f
->ts
.kind
)
2424 gfc_convert_type (n
, &f
->ts
, 2);
2426 f
->value
.function
.name
= gfc_get_string (PREFIX ("fstat_i%d"), f
->ts
.kind
);
2431 gfc_resolve_fgetc (gfc_expr
*f
, gfc_expr
*u
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2436 f
->ts
.type
= BT_INTEGER
;
2437 f
->ts
.kind
= gfc_c_int_kind
;
2438 if (u
->ts
.kind
!= gfc_c_int_kind
)
2440 ts
.type
= BT_INTEGER
;
2441 ts
.kind
= gfc_c_int_kind
;
2442 ts
.u
.derived
= NULL
;
2444 gfc_convert_type (u
, &ts
, 2);
2447 f
->value
.function
.name
= gfc_get_string (PREFIX ("fgetc"));
2452 gfc_resolve_fget (gfc_expr
*f
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2454 f
->ts
.type
= BT_INTEGER
;
2455 f
->ts
.kind
= gfc_c_int_kind
;
2456 f
->value
.function
.name
= gfc_get_string (PREFIX ("fget"));
2461 gfc_resolve_fputc (gfc_expr
*f
, gfc_expr
*u
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2466 f
->ts
.type
= BT_INTEGER
;
2467 f
->ts
.kind
= gfc_c_int_kind
;
2468 if (u
->ts
.kind
!= gfc_c_int_kind
)
2470 ts
.type
= BT_INTEGER
;
2471 ts
.kind
= gfc_c_int_kind
;
2472 ts
.u
.derived
= NULL
;
2474 gfc_convert_type (u
, &ts
, 2);
2477 f
->value
.function
.name
= gfc_get_string (PREFIX ("fputc"));
2482 gfc_resolve_fput (gfc_expr
*f
, gfc_expr
*c ATTRIBUTE_UNUSED
)
2484 f
->ts
.type
= BT_INTEGER
;
2485 f
->ts
.kind
= gfc_c_int_kind
;
2486 f
->value
.function
.name
= gfc_get_string (PREFIX ("fput"));
2491 gfc_resolve_ftell (gfc_expr
*f
, gfc_expr
*u
)
2496 f
->ts
.type
= BT_INTEGER
;
2497 f
->ts
.kind
= gfc_intio_kind
;
2498 if (u
->ts
.kind
!= gfc_c_int_kind
)
2500 ts
.type
= BT_INTEGER
;
2501 ts
.kind
= gfc_c_int_kind
;
2502 ts
.u
.derived
= NULL
;
2504 gfc_convert_type (u
, &ts
, 2);
2507 f
->value
.function
.name
= gfc_get_string (PREFIX ("ftell2"));
2512 gfc_resolve_storage_size (gfc_expr
*f
, gfc_expr
*a ATTRIBUTE_UNUSED
,
2515 f
->ts
.type
= BT_INTEGER
;
2517 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2519 f
->ts
.kind
= gfc_default_integer_kind
;
2524 gfc_resolve_sum (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*mask
)
2526 resolve_transformational ("sum", f
, array
, dim
, mask
);
2531 gfc_resolve_symlnk (gfc_expr
*f
, gfc_expr
*p1 ATTRIBUTE_UNUSED
,
2532 gfc_expr
*p2 ATTRIBUTE_UNUSED
)
2534 f
->ts
.type
= BT_INTEGER
;
2535 f
->ts
.kind
= gfc_default_integer_kind
;
2536 f
->value
.function
.name
= gfc_get_string (PREFIX ("symlnk_i%d"), f
->ts
.kind
);
2540 /* Resolve the g77 compatibility function SYSTEM. */
2543 gfc_resolve_system (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
)
2545 f
->ts
.type
= BT_INTEGER
;
2547 f
->value
.function
.name
= gfc_get_string (PREFIX ("system"));
2552 gfc_resolve_tan (gfc_expr
*f
, gfc_expr
*x
)
2555 f
->value
.function
.name
2556 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2561 gfc_resolve_tanh (gfc_expr
*f
, gfc_expr
*x
)
2564 f
->value
.function
.name
2565 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x
->ts
.type
), x
->ts
.kind
);
2570 gfc_resolve_image_index (gfc_expr
*f
, gfc_expr
*array ATTRIBUTE_UNUSED
,
2571 gfc_expr
*sub ATTRIBUTE_UNUSED
)
2573 static char image_index
[] = "__image_index";
2574 f
->ts
.type
= BT_INTEGER
;
2575 f
->ts
.kind
= gfc_default_integer_kind
;
2576 f
->value
.function
.name
= image_index
;
2581 gfc_resolve_this_image (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
)
2583 static char this_image
[] = "__this_image";
2585 resolve_bound (f
, array
, dim
, NULL
, "__this_image", true);
2588 f
->ts
.type
= BT_INTEGER
;
2589 f
->ts
.kind
= gfc_default_integer_kind
;
2590 f
->value
.function
.name
= this_image
;
2596 gfc_resolve_time (gfc_expr
*f
)
2598 f
->ts
.type
= BT_INTEGER
;
2600 f
->value
.function
.name
= gfc_get_string (PREFIX ("time_func"));
2605 gfc_resolve_time8 (gfc_expr
*f
)
2607 f
->ts
.type
= BT_INTEGER
;
2609 f
->value
.function
.name
= gfc_get_string (PREFIX ("time8_func"));
2614 gfc_resolve_transfer (gfc_expr
*f
, gfc_expr
*source ATTRIBUTE_UNUSED
,
2615 gfc_expr
*mold
, gfc_expr
*size
)
2617 /* TODO: Make this do something meaningful. */
2618 static char transfer0
[] = "__transfer0", transfer1
[] = "__transfer1";
2620 if (mold
->ts
.type
== BT_CHARACTER
2621 && !mold
->ts
.u
.cl
->length
2622 && gfc_is_constant_expr (mold
))
2625 if (mold
->expr_type
== EXPR_CONSTANT
)
2627 len
= mold
->value
.character
.length
;
2628 mold
->ts
.u
.cl
->length
= gfc_get_int_expr (gfc_default_integer_kind
,
2633 gfc_constructor
*c
= gfc_constructor_first (mold
->value
.constructor
);
2634 len
= c
->expr
->value
.character
.length
;
2635 mold
->ts
.u
.cl
->length
= gfc_get_int_expr (gfc_default_integer_kind
,
2642 if (size
== NULL
&& mold
->rank
== 0)
2645 f
->value
.function
.name
= transfer0
;
2650 f
->value
.function
.name
= transfer1
;
2651 if (size
&& gfc_is_constant_expr (size
))
2653 f
->shape
= gfc_get_shape (1);
2654 mpz_init_set (f
->shape
[0], size
->value
.integer
);
2661 gfc_resolve_transpose (gfc_expr
*f
, gfc_expr
*matrix
)
2664 if (matrix
->ts
.type
== BT_CHARACTER
&& matrix
->ref
)
2665 gfc_resolve_substring_charlen (matrix
);
2671 f
->shape
= gfc_get_shape (2);
2672 mpz_init_set (f
->shape
[0], matrix
->shape
[1]);
2673 mpz_init_set (f
->shape
[1], matrix
->shape
[0]);
2676 switch (matrix
->ts
.kind
)
2682 switch (matrix
->ts
.type
)
2686 f
->value
.function
.name
2687 = gfc_get_string (PREFIX ("transpose_%c%d"),
2688 gfc_type_letter (matrix
->ts
.type
),
2694 /* Use the integer routines for real and logical cases. This
2695 assumes they all have the same alignment requirements. */
2696 f
->value
.function
.name
2697 = gfc_get_string (PREFIX ("transpose_i%d"), matrix
->ts
.kind
);
2701 if (matrix
->ts
.type
== BT_CHARACTER
&& matrix
->ts
.kind
== 4)
2702 f
->value
.function
.name
= PREFIX ("transpose_char4");
2704 f
->value
.function
.name
= PREFIX ("transpose");
2710 f
->value
.function
.name
= (matrix
->ts
.type
== BT_CHARACTER
2711 ? PREFIX ("transpose_char")
2712 : PREFIX ("transpose"));
2719 gfc_resolve_trim (gfc_expr
*f
, gfc_expr
*string
)
2721 f
->ts
.type
= BT_CHARACTER
;
2722 f
->ts
.kind
= string
->ts
.kind
;
2723 f
->value
.function
.name
= gfc_get_string ("__trim_%d", string
->ts
.kind
);
2728 gfc_resolve_ubound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
2730 resolve_bound (f
, array
, dim
, kind
, "__ubound", false);
2735 gfc_resolve_ucobound (gfc_expr
*f
, gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
2737 resolve_bound (f
, array
, dim
, kind
, "__ucobound", true);
2741 /* Resolve the g77 compatibility function UMASK. */
2744 gfc_resolve_umask (gfc_expr
*f
, gfc_expr
*n
)
2746 f
->ts
.type
= BT_INTEGER
;
2747 f
->ts
.kind
= n
->ts
.kind
;
2748 f
->value
.function
.name
= gfc_get_string (PREFIX ("umask_i%d"), n
->ts
.kind
);
2752 /* Resolve the g77 compatibility function UNLINK. */
2755 gfc_resolve_unlink (gfc_expr
*f
, gfc_expr
*n ATTRIBUTE_UNUSED
)
2757 f
->ts
.type
= BT_INTEGER
;
2759 f
->value
.function
.name
= gfc_get_string (PREFIX ("unlink"));
2764 gfc_resolve_ttynam (gfc_expr
*f
, gfc_expr
*unit
)
2769 f
->ts
.type
= BT_CHARACTER
;
2770 f
->ts
.kind
= gfc_default_character_kind
;
2772 if (unit
->ts
.kind
!= gfc_c_int_kind
)
2774 ts
.type
= BT_INTEGER
;
2775 ts
.kind
= gfc_c_int_kind
;
2776 ts
.u
.derived
= NULL
;
2778 gfc_convert_type (unit
, &ts
, 2);
2781 f
->value
.function
.name
= gfc_get_string (PREFIX ("ttynam"));
2786 gfc_resolve_unpack (gfc_expr
*f
, gfc_expr
*vector
, gfc_expr
*mask
,
2787 gfc_expr
*field ATTRIBUTE_UNUSED
)
2789 if (vector
->ts
.type
== BT_CHARACTER
&& vector
->ref
)
2790 gfc_resolve_substring_charlen (vector
);
2793 f
->rank
= mask
->rank
;
2794 resolve_mask_arg (mask
);
2796 if (vector
->ts
.type
== BT_CHARACTER
)
2798 if (vector
->ts
.kind
== 1)
2799 f
->value
.function
.name
2800 = gfc_get_string (PREFIX ("unpack%d_char"), field
->rank
> 0 ? 1 : 0);
2802 f
->value
.function
.name
2803 = gfc_get_string (PREFIX ("unpack%d_char%d"),
2804 field
->rank
> 0 ? 1 : 0, vector
->ts
.kind
);
2807 f
->value
.function
.name
2808 = gfc_get_string (PREFIX ("unpack%d"), field
->rank
> 0 ? 1 : 0);
2813 gfc_resolve_verify (gfc_expr
*f
, gfc_expr
*string
,
2814 gfc_expr
*set ATTRIBUTE_UNUSED
,
2815 gfc_expr
*back ATTRIBUTE_UNUSED
, gfc_expr
*kind
)
2817 f
->ts
.type
= BT_INTEGER
;
2819 f
->ts
.kind
= mpz_get_si (kind
->value
.integer
);
2821 f
->ts
.kind
= gfc_default_integer_kind
;
2822 f
->value
.function
.name
= gfc_get_string ("__verify_%d", string
->ts
.kind
);
2827 gfc_resolve_xor (gfc_expr
*f
, gfc_expr
*i
, gfc_expr
*j
)
2829 f
->ts
.type
= i
->ts
.type
;
2830 f
->ts
.kind
= gfc_kind_max (i
, j
);
2832 if (i
->ts
.kind
!= j
->ts
.kind
)
2834 if (i
->ts
.kind
== gfc_kind_max (i
, j
))
2835 gfc_convert_type (j
, &i
->ts
, 2);
2837 gfc_convert_type (i
, &j
->ts
, 2);
2840 f
->value
.function
.name
2841 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i
->ts
.type
), f
->ts
.kind
);
2845 /* Intrinsic subroutine resolution. */
2848 gfc_resolve_alarm_sub (gfc_code
*c
)
2851 gfc_expr
*seconds
, *handler
;
2855 seconds
= c
->ext
.actual
->expr
;
2856 handler
= c
->ext
.actual
->next
->expr
;
2857 ts
.type
= BT_INTEGER
;
2858 ts
.kind
= gfc_c_int_kind
;
2860 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2861 In all cases, the status argument is of default integer kind
2862 (enforced in check.c) so that the function suffix is fixed. */
2863 if (handler
->ts
.type
== BT_INTEGER
)
2865 if (handler
->ts
.kind
!= gfc_c_int_kind
)
2866 gfc_convert_type (handler
, &ts
, 2);
2867 name
= gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2868 gfc_default_integer_kind
);
2871 name
= gfc_get_string (PREFIX ("alarm_sub_i%d"),
2872 gfc_default_integer_kind
);
2874 if (seconds
->ts
.kind
!= gfc_c_int_kind
)
2875 gfc_convert_type (seconds
, &ts
, 2);
2877 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2881 gfc_resolve_cpu_time (gfc_code
*c
)
2884 name
= gfc_get_string (PREFIX ("cpu_time_%d"), c
->ext
.actual
->expr
->ts
.kind
);
2885 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2889 /* Create a formal arglist based on an actual one and set the INTENTs given. */
2891 static gfc_formal_arglist
*
2892 create_formal_for_intents (gfc_actual_arglist
* actual
, const sym_intent
* ints
)
2894 gfc_formal_arglist
* head
;
2895 gfc_formal_arglist
* tail
;
2901 head
= tail
= gfc_get_formal_arglist ();
2902 for (i
= 0; actual
; actual
= actual
->next
, tail
= tail
->next
, ++i
)
2906 sym
= gfc_new_symbol ("dummyarg", NULL
);
2907 sym
->ts
= actual
->expr
->ts
;
2909 sym
->attr
.intent
= ints
[i
];
2913 tail
->next
= gfc_get_formal_arglist ();
2921 gfc_resolve_atomic_def (gfc_code
*c
)
2923 const char *name
= "atomic_define";
2924 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2929 gfc_resolve_atomic_ref (gfc_code
*c
)
2931 const char *name
= "atomic_ref";
2932 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2937 gfc_resolve_mvbits (gfc_code
*c
)
2939 static const sym_intent INTENTS
[] = {INTENT_IN
, INTENT_IN
, INTENT_IN
,
2940 INTENT_INOUT
, INTENT_IN
};
2946 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2947 they will be converted so that they fit into a C int. */
2948 ts
.type
= BT_INTEGER
;
2949 ts
.kind
= gfc_c_int_kind
;
2950 if (c
->ext
.actual
->next
->expr
->ts
.kind
!= gfc_c_int_kind
)
2951 gfc_convert_type (c
->ext
.actual
->next
->expr
, &ts
, 2);
2952 if (c
->ext
.actual
->next
->next
->expr
->ts
.kind
!= gfc_c_int_kind
)
2953 gfc_convert_type (c
->ext
.actual
->next
->next
->expr
, &ts
, 2);
2954 if (c
->ext
.actual
->next
->next
->next
->next
->expr
->ts
.kind
!= gfc_c_int_kind
)
2955 gfc_convert_type (c
->ext
.actual
->next
->next
->next
->next
->expr
, &ts
, 2);
2957 /* TO and FROM are guaranteed to have the same kind parameter. */
2958 name
= gfc_get_string (PREFIX ("mvbits_i%d"),
2959 c
->ext
.actual
->expr
->ts
.kind
);
2960 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2961 /* Mark as elemental subroutine as this does not happen automatically. */
2962 c
->resolved_sym
->attr
.elemental
= 1;
2964 /* Create a dummy formal arglist so the INTENTs are known later for purpose
2965 of creating temporaries. */
2966 c
->resolved_sym
->formal
= create_formal_for_intents (c
->ext
.actual
, INTENTS
);
2971 gfc_resolve_random_number (gfc_code
*c
)
2976 kind
= c
->ext
.actual
->expr
->ts
.kind
;
2977 if (c
->ext
.actual
->expr
->rank
== 0)
2978 name
= gfc_get_string (PREFIX ("random_r%d"), kind
);
2980 name
= gfc_get_string (PREFIX ("arandom_r%d"), kind
);
2982 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2987 gfc_resolve_random_seed (gfc_code
*c
)
2991 name
= gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind
);
2992 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
2997 gfc_resolve_rename_sub (gfc_code
*c
)
3002 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
3003 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
3005 kind
= gfc_default_integer_kind
;
3007 name
= gfc_get_string (PREFIX ("rename_i%d_sub"), kind
);
3008 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3013 gfc_resolve_kill_sub (gfc_code
*c
)
3018 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
3019 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
3021 kind
= gfc_default_integer_kind
;
3023 name
= gfc_get_string (PREFIX ("kill_i%d_sub"), kind
);
3024 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3029 gfc_resolve_link_sub (gfc_code
*c
)
3034 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
3035 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
3037 kind
= gfc_default_integer_kind
;
3039 name
= gfc_get_string (PREFIX ("link_i%d_sub"), kind
);
3040 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3045 gfc_resolve_symlnk_sub (gfc_code
*c
)
3050 if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
3051 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
3053 kind
= gfc_default_integer_kind
;
3055 name
= gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind
);
3056 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3060 /* G77 compatibility subroutines dtime() and etime(). */
3063 gfc_resolve_dtime_sub (gfc_code
*c
)
3066 name
= gfc_get_string (PREFIX ("dtime_sub"));
3067 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3071 gfc_resolve_etime_sub (gfc_code
*c
)
3074 name
= gfc_get_string (PREFIX ("etime_sub"));
3075 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3079 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
3082 gfc_resolve_itime (gfc_code
*c
)
3085 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
3086 gfc_default_integer_kind
));
3090 gfc_resolve_idate (gfc_code
*c
)
3093 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
3094 gfc_default_integer_kind
));
3098 gfc_resolve_ltime (gfc_code
*c
)
3101 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
3102 gfc_default_integer_kind
));
3106 gfc_resolve_gmtime (gfc_code
*c
)
3109 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
3110 gfc_default_integer_kind
));
3114 /* G77 compatibility subroutine second(). */
3117 gfc_resolve_second_sub (gfc_code
*c
)
3120 name
= gfc_get_string (PREFIX ("second_sub"));
3121 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3126 gfc_resolve_sleep_sub (gfc_code
*c
)
3131 if (c
->ext
.actual
->expr
!= NULL
)
3132 kind
= c
->ext
.actual
->expr
->ts
.kind
;
3134 kind
= gfc_default_integer_kind
;
3136 name
= gfc_get_string (PREFIX ("sleep_i%d_sub"), kind
);
3137 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3141 /* G77 compatibility function srand(). */
3144 gfc_resolve_srand (gfc_code
*c
)
3147 name
= gfc_get_string (PREFIX ("srand"));
3148 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3152 /* Resolve the getarg intrinsic subroutine. */
3155 gfc_resolve_getarg (gfc_code
*c
)
3159 if (c
->ext
.actual
->expr
->ts
.kind
!= gfc_default_integer_kind
)
3164 ts
.type
= BT_INTEGER
;
3165 ts
.kind
= gfc_default_integer_kind
;
3167 gfc_convert_type (c
->ext
.actual
->expr
, &ts
, 2);
3170 name
= gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind
);
3171 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3175 /* Resolve the getcwd intrinsic subroutine. */
3178 gfc_resolve_getcwd_sub (gfc_code
*c
)
3183 if (c
->ext
.actual
->next
->expr
!= NULL
)
3184 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3186 kind
= gfc_default_integer_kind
;
3188 name
= gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind
);
3189 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3193 /* Resolve the get_command intrinsic subroutine. */
3196 gfc_resolve_get_command (gfc_code
*c
)
3200 kind
= gfc_default_integer_kind
;
3201 name
= gfc_get_string (PREFIX ("get_command_i%d"), kind
);
3202 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3206 /* Resolve the get_command_argument intrinsic subroutine. */
3209 gfc_resolve_get_command_argument (gfc_code
*c
)
3213 kind
= gfc_default_integer_kind
;
3214 name
= gfc_get_string (PREFIX ("get_command_argument_i%d"), kind
);
3215 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3219 /* Resolve the get_environment_variable intrinsic subroutine. */
3222 gfc_resolve_get_environment_variable (gfc_code
*code
)
3226 kind
= gfc_default_integer_kind
;
3227 name
= gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind
);
3228 code
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3233 gfc_resolve_signal_sub (gfc_code
*c
)
3236 gfc_expr
*number
, *handler
, *status
;
3240 number
= c
->ext
.actual
->expr
;
3241 handler
= c
->ext
.actual
->next
->expr
;
3242 status
= c
->ext
.actual
->next
->next
->expr
;
3243 ts
.type
= BT_INTEGER
;
3244 ts
.kind
= gfc_c_int_kind
;
3246 /* handler can be either BT_INTEGER or BT_PROCEDURE */
3247 if (handler
->ts
.type
== BT_INTEGER
)
3249 if (handler
->ts
.kind
!= gfc_c_int_kind
)
3250 gfc_convert_type (handler
, &ts
, 2);
3251 name
= gfc_get_string (PREFIX ("signal_sub_int"));
3254 name
= gfc_get_string (PREFIX ("signal_sub"));
3256 if (number
->ts
.kind
!= gfc_c_int_kind
)
3257 gfc_convert_type (number
, &ts
, 2);
3258 if (status
!= NULL
&& status
->ts
.kind
!= gfc_c_int_kind
)
3259 gfc_convert_type (status
, &ts
, 2);
3261 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3265 /* Resolve the SYSTEM intrinsic subroutine. */
3268 gfc_resolve_system_sub (gfc_code
*c
)
3271 name
= gfc_get_string (PREFIX ("system_sub"));
3272 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3276 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
3279 gfc_resolve_system_clock (gfc_code
*c
)
3284 if (c
->ext
.actual
->expr
!= NULL
)
3285 kind
= c
->ext
.actual
->expr
->ts
.kind
;
3286 else if (c
->ext
.actual
->next
->expr
!= NULL
)
3287 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3288 else if (c
->ext
.actual
->next
->next
->expr
!= NULL
)
3289 kind
= c
->ext
.actual
->next
->next
->expr
->ts
.kind
;
3291 kind
= gfc_default_integer_kind
;
3293 name
= gfc_get_string (PREFIX ("system_clock_%d"), kind
);
3294 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3298 /* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine. */
3300 gfc_resolve_execute_command_line (gfc_code
*c
)
3303 name
= gfc_get_string (PREFIX ("execute_command_line_i%d"),
3304 gfc_default_integer_kind
);
3305 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3309 /* Resolve the EXIT intrinsic subroutine. */
3312 gfc_resolve_exit (gfc_code
*c
)
3319 /* The STATUS argument has to be of default kind. If it is not,
3321 ts
.type
= BT_INTEGER
;
3322 ts
.kind
= gfc_default_integer_kind
;
3323 n
= c
->ext
.actual
->expr
;
3324 if (n
!= NULL
&& n
->ts
.kind
!= ts
.kind
)
3325 gfc_convert_type (n
, &ts
, 2);
3327 name
= gfc_get_string (PREFIX ("exit_i%d"), ts
.kind
);
3328 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3332 /* Resolve the FLUSH intrinsic subroutine. */
3335 gfc_resolve_flush (gfc_code
*c
)
3342 ts
.type
= BT_INTEGER
;
3343 ts
.kind
= gfc_default_integer_kind
;
3344 n
= c
->ext
.actual
->expr
;
3345 if (n
!= NULL
&& n
->ts
.kind
!= ts
.kind
)
3346 gfc_convert_type (n
, &ts
, 2);
3348 name
= gfc_get_string (PREFIX ("flush_i%d"), ts
.kind
);
3349 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3354 gfc_resolve_free (gfc_code
*c
)
3360 ts
.type
= BT_INTEGER
;
3361 ts
.kind
= gfc_index_integer_kind
;
3362 n
= c
->ext
.actual
->expr
;
3363 if (n
->ts
.kind
!= ts
.kind
)
3364 gfc_convert_type (n
, &ts
, 2);
3366 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
3371 gfc_resolve_ctime_sub (gfc_code
*c
)
3376 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3377 if (c
->ext
.actual
->expr
->ts
.kind
!= 8)
3379 ts
.type
= BT_INTEGER
;
3381 ts
.u
.derived
= NULL
;
3383 gfc_convert_type (c
->ext
.actual
->expr
, &ts
, 2);
3386 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3391 gfc_resolve_fdate_sub (gfc_code
*c
)
3393 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3398 gfc_resolve_gerror (gfc_code
*c
)
3400 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3405 gfc_resolve_getlog (gfc_code
*c
)
3407 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3412 gfc_resolve_hostnm_sub (gfc_code
*c
)
3417 if (c
->ext
.actual
->next
->expr
!= NULL
)
3418 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3420 kind
= gfc_default_integer_kind
;
3422 name
= gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind
);
3423 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3428 gfc_resolve_perror (gfc_code
*c
)
3430 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3433 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3436 gfc_resolve_stat_sub (gfc_code
*c
)
3439 name
= gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind
);
3440 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3445 gfc_resolve_lstat_sub (gfc_code
*c
)
3448 name
= gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind
);
3449 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3454 gfc_resolve_fstat_sub (gfc_code
*c
)
3460 u
= c
->ext
.actual
->expr
;
3461 ts
= &c
->ext
.actual
->next
->expr
->ts
;
3462 if (u
->ts
.kind
!= ts
->kind
)
3463 gfc_convert_type (u
, ts
, 2);
3464 name
= gfc_get_string (PREFIX ("fstat_i%d_sub"), ts
->kind
);
3465 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3470 gfc_resolve_fgetc_sub (gfc_code
*c
)
3477 u
= c
->ext
.actual
->expr
;
3478 st
= c
->ext
.actual
->next
->next
->expr
;
3480 if (u
->ts
.kind
!= gfc_c_int_kind
)
3482 ts
.type
= BT_INTEGER
;
3483 ts
.kind
= gfc_c_int_kind
;
3484 ts
.u
.derived
= NULL
;
3486 gfc_convert_type (u
, &ts
, 2);
3490 name
= gfc_get_string (PREFIX ("fgetc_i%d_sub"), st
->ts
.kind
);
3492 name
= gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind
);
3494 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3499 gfc_resolve_fget_sub (gfc_code
*c
)
3504 st
= c
->ext
.actual
->next
->expr
;
3506 name
= gfc_get_string (PREFIX ("fget_i%d_sub"), st
->ts
.kind
);
3508 name
= gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind
);
3510 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3515 gfc_resolve_fputc_sub (gfc_code
*c
)
3522 u
= c
->ext
.actual
->expr
;
3523 st
= c
->ext
.actual
->next
->next
->expr
;
3525 if (u
->ts
.kind
!= gfc_c_int_kind
)
3527 ts
.type
= BT_INTEGER
;
3528 ts
.kind
= gfc_c_int_kind
;
3529 ts
.u
.derived
= NULL
;
3531 gfc_convert_type (u
, &ts
, 2);
3535 name
= gfc_get_string (PREFIX ("fputc_i%d_sub"), st
->ts
.kind
);
3537 name
= gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind
);
3539 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3544 gfc_resolve_fput_sub (gfc_code
*c
)
3549 st
= c
->ext
.actual
->next
->expr
;
3551 name
= gfc_get_string (PREFIX ("fput_i%d_sub"), st
->ts
.kind
);
3553 name
= gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind
);
3555 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3560 gfc_resolve_fseek_sub (gfc_code
*c
)
3568 unit
= c
->ext
.actual
->expr
;
3569 offset
= c
->ext
.actual
->next
->expr
;
3570 whence
= c
->ext
.actual
->next
->next
->expr
;
3572 if (unit
->ts
.kind
!= gfc_c_int_kind
)
3574 ts
.type
= BT_INTEGER
;
3575 ts
.kind
= gfc_c_int_kind
;
3576 ts
.u
.derived
= NULL
;
3578 gfc_convert_type (unit
, &ts
, 2);
3581 if (offset
->ts
.kind
!= gfc_intio_kind
)
3583 ts
.type
= BT_INTEGER
;
3584 ts
.kind
= gfc_intio_kind
;
3585 ts
.u
.derived
= NULL
;
3587 gfc_convert_type (offset
, &ts
, 2);
3590 if (whence
->ts
.kind
!= gfc_c_int_kind
)
3592 ts
.type
= BT_INTEGER
;
3593 ts
.kind
= gfc_c_int_kind
;
3594 ts
.u
.derived
= NULL
;
3596 gfc_convert_type (whence
, &ts
, 2);
3599 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3603 gfc_resolve_ftell_sub (gfc_code
*c
)
3611 unit
= c
->ext
.actual
->expr
;
3612 offset
= c
->ext
.actual
->next
->expr
;
3614 if (unit
->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 (unit
, &ts
, 2);
3623 name
= gfc_get_string (PREFIX ("ftell_i%d_sub"), offset
->ts
.kind
);
3624 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3629 gfc_resolve_ttynam_sub (gfc_code
*c
)
3634 if (c
->ext
.actual
->expr
->ts
.kind
!= gfc_c_int_kind
)
3636 ts
.type
= BT_INTEGER
;
3637 ts
.kind
= gfc_c_int_kind
;
3638 ts
.u
.derived
= NULL
;
3640 gfc_convert_type (c
->ext
.actual
->expr
, &ts
, 2);
3643 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3647 /* Resolve the UMASK intrinsic subroutine. */
3650 gfc_resolve_umask_sub (gfc_code
*c
)
3655 if (c
->ext
.actual
->next
->expr
!= NULL
)
3656 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3658 kind
= gfc_default_integer_kind
;
3660 name
= gfc_get_string (PREFIX ("umask_i%d_sub"), kind
);
3661 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);
3664 /* Resolve the UNLINK intrinsic subroutine. */
3667 gfc_resolve_unlink_sub (gfc_code
*c
)
3672 if (c
->ext
.actual
->next
->expr
!= NULL
)
3673 kind
= c
->ext
.actual
->next
->expr
->ts
.kind
;
3675 kind
= gfc_default_integer_kind
;
3677 name
= gfc_get_string (PREFIX ("unlink_i%d_sub"), kind
);
3678 c
->resolved_sym
= gfc_get_intrinsic_sub_symbol (name
);