re PR target/57865 (Broken _save64gpr and _rest64gpr usage)
[official-gcc.git] / gcc / fortran / iresolve.c
blobaf452b3288874260eb9b12a3a8ddc28a943dafa5
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
10 version.
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
15 for more details.
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. */
29 #include "config.h"
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tree.h"
33 #include "gfortran.h"
34 #include "intrinsic.h"
35 #include "constructor.h"
36 #include "arith.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. */
45 const char *
46 gfc_get_string (const char *format, ...)
48 char temp_name[128];
49 va_list ap;
50 tree ident;
52 va_start (ap, format);
53 vsnprintf (temp_name, sizeof (temp_name), format, ap);
54 va_end (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. */
63 static void
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);
74 source->rank = 0;
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. */
87 static void
88 resolve_mask_arg (gfc_expr *mask)
91 gfc_typespec ts;
92 gfc_clear_ts (&ts);
94 if (mask->rank == 0)
96 /* For the scalar case, coerce the mask to kind=4 unconditionally
97 (because this is the only kind we have a library function
98 for). */
100 if (mask->ts.kind != 4)
102 ts.type = BT_LOGICAL;
103 ts.kind = 4;
104 gfc_convert_type (mask, &ts, 2);
107 else
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;
115 ts.kind = 1;
116 gfc_convert_type_warn (mask, &ts, 2, 0);
122 static void
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;
127 if (kind)
128 f->ts.kind = mpz_get_si (kind->value.integer);
129 else
130 f->ts.kind = gfc_default_integer_kind;
132 if (dim == NULL)
134 f->rank = 1;
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)
139 : array->rank);
143 f->value.function.name = gfc_get_string (name);
147 static void
148 resolve_transformational (const char *name, gfc_expr *f, gfc_expr *array,
149 gfc_expr *dim, gfc_expr *mask)
151 const char *prefix;
153 f->ts = array->ts;
155 if (mask)
157 if (mask->rank == 0)
158 prefix = "s";
159 else
160 prefix = "m";
162 resolve_mask_arg (mask);
164 else
165 prefix = "";
167 if (dim != NULL)
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 **********************/
183 void
184 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
186 f->ts = a->ts;
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);
195 void
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");
205 void
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);
214 void
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);
223 static void
224 gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind,
225 const char *name)
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),
235 x->ts.kind);
239 void
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");
246 void
247 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
249 f->ts = x->ts;
250 f->value.function.name
251 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
255 void
256 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
258 f->ts = x->ts;
259 f->value.function.name
260 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
261 x->ts.kind);
265 void
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),
272 x->ts.kind);
276 void
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);
286 else
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);
295 void
296 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
298 gfc_typespec ts;
299 gfc_clear_ts (&ts);
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);
317 void
318 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
320 gfc_resolve_aint (f, a, NULL);
324 void
325 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
327 f->ts = mask->ts;
329 if (dim != NULL)
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),
338 mask->ts.kind);
342 void
343 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
345 gfc_typespec ts;
346 gfc_clear_ts (&ts);
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),
362 a->ts.kind);
366 void
367 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
369 gfc_resolve_anint (f, a, NULL);
373 void
374 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
376 f->ts = mask->ts;
378 if (dim != NULL)
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),
387 mask->ts.kind);
391 void
392 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
394 f->ts = x->ts;
395 f->value.function.name
396 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
399 void
400 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
402 f->ts = x->ts;
403 f->value.function.name
404 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
405 x->ts.kind);
408 void
409 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
411 f->ts = x->ts;
412 f->value.function.name
413 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
416 void
417 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
419 f->ts = x->ts;
420 f->value.function.name
421 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
422 x->ts.kind);
425 void
426 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
428 f->ts = x->ts;
429 f->value.function.name
430 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
431 x->ts.kind);
435 /* Resolve the BESYN and BESJN intrinsics. */
437 void
438 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
440 gfc_typespec ts;
441 gfc_clear_ts (&ts);
443 f->ts = x->ts;
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>");
454 void
455 gfc_resolve_bessel_n2 (gfc_expr *f, gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
457 gfc_typespec ts;
458 gfc_clear_ts (&ts);
460 f->ts = x->ts;
461 f->rank = 1;
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"),
486 f->ts.kind);
487 else
488 f->value.function.name = gfc_get_string (PREFIX ("bessel_yn_r%d"),
489 f->ts.kind);
493 void
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);
503 void
504 gfc_resolve_c_loc (gfc_expr *f, gfc_expr *x ATTRIBUTE_UNUSED)
506 f->ts = f->value.function.isym->ts;
510 void
511 gfc_resolve_c_funloc (gfc_expr *f, gfc_expr *x ATTRIBUTE_UNUSED)
513 f->ts = f->value.function.isym->ts;
517 void
518 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
520 f->ts.type = BT_INTEGER;
521 f->ts.kind = (kind == NULL)
522 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
523 f->value.function.name
524 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
525 gfc_type_letter (a->ts.type), a->ts.kind);
529 void
530 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
532 gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d");
536 void
537 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
539 f->ts.type = BT_INTEGER;
540 f->ts.kind = gfc_default_integer_kind;
541 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
545 void
546 gfc_resolve_chdir_sub (gfc_code *c)
548 const char *name;
549 int kind;
551 if (c->ext.actual->next->expr != NULL)
552 kind = c->ext.actual->next->expr->ts.kind;
553 else
554 kind = gfc_default_integer_kind;
556 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
557 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
561 void
562 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
563 gfc_expr *mode ATTRIBUTE_UNUSED)
565 f->ts.type = BT_INTEGER;
566 f->ts.kind = gfc_c_int_kind;
567 f->value.function.name = PREFIX ("chmod_func");
571 void
572 gfc_resolve_chmod_sub (gfc_code *c)
574 const char *name;
575 int kind;
577 if (c->ext.actual->next->next->expr != NULL)
578 kind = c->ext.actual->next->next->expr->ts.kind;
579 else
580 kind = gfc_default_integer_kind;
582 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
583 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
587 void
588 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
590 f->ts.type = BT_COMPLEX;
591 f->ts.kind = (kind == NULL)
592 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
594 if (y == NULL)
595 f->value.function.name
596 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
597 gfc_type_letter (x->ts.type), x->ts.kind);
598 else
599 f->value.function.name
600 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
601 gfc_type_letter (x->ts.type), x->ts.kind,
602 gfc_type_letter (y->ts.type), y->ts.kind);
606 void
607 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
609 gfc_resolve_cmplx (f, x, y, gfc_get_int_expr (gfc_default_integer_kind, NULL,
610 gfc_default_double_kind));
614 void
615 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
617 int kind;
619 if (x->ts.type == BT_INTEGER)
621 if (y->ts.type == BT_INTEGER)
622 kind = gfc_default_real_kind;
623 else
624 kind = y->ts.kind;
626 else
628 if (y->ts.type == BT_REAL)
629 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
630 else
631 kind = x->ts.kind;
634 f->ts.type = BT_COMPLEX;
635 f->ts.kind = kind;
636 f->value.function.name
637 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
638 gfc_type_letter (x->ts.type), x->ts.kind,
639 gfc_type_letter (y->ts.type), y->ts.kind);
643 void
644 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
646 f->ts = x->ts;
647 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
651 void
652 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
654 f->ts = x->ts;
655 f->value.function.name
656 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
660 void
661 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
663 f->ts = x->ts;
664 f->value.function.name
665 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
669 void
670 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
672 f->ts.type = BT_INTEGER;
673 if (kind)
674 f->ts.kind = mpz_get_si (kind->value.integer);
675 else
676 f->ts.kind = gfc_default_integer_kind;
678 if (dim != NULL)
680 f->rank = mask->rank - 1;
681 gfc_resolve_dim_arg (dim);
682 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
685 resolve_mask_arg (mask);
687 f->value.function.name
688 = gfc_get_string (PREFIX ("count_%d_%c"), f->ts.kind,
689 gfc_type_letter (mask->ts.type));
693 void
694 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
695 gfc_expr *dim)
697 int n, m;
699 if (array->ts.type == BT_CHARACTER && array->ref)
700 gfc_resolve_substring_charlen (array);
702 f->ts = array->ts;
703 f->rank = array->rank;
704 f->shape = gfc_copy_shape (array->shape, array->rank);
706 if (shift->rank > 0)
707 n = 1;
708 else
709 n = 0;
711 /* If dim kind is greater than default integer we need to use the larger. */
712 m = gfc_default_integer_kind;
713 if (dim != NULL)
714 m = m < dim->ts.kind ? dim->ts.kind : m;
716 /* Convert shift to at least m, so we don't need
717 kind=1 and kind=2 versions of the library functions. */
718 if (shift->ts.kind < m)
720 gfc_typespec ts;
721 gfc_clear_ts (&ts);
722 ts.type = BT_INTEGER;
723 ts.kind = m;
724 gfc_convert_type_warn (shift, &ts, 2, 0);
727 if (dim != NULL)
729 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
730 && dim->symtree->n.sym->attr.optional)
732 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
733 dim->representation.length = shift->ts.kind;
735 else
737 gfc_resolve_dim_arg (dim);
738 /* Convert dim to shift's kind to reduce variations. */
739 if (dim->ts.kind != shift->ts.kind)
740 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
744 if (array->ts.type == BT_CHARACTER)
746 if (array->ts.kind == gfc_default_character_kind)
747 f->value.function.name
748 = gfc_get_string (PREFIX ("cshift%d_%d_char"), n, shift->ts.kind);
749 else
750 f->value.function.name
751 = gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n, shift->ts.kind,
752 array->ts.kind);
754 else
755 f->value.function.name
756 = gfc_get_string (PREFIX ("cshift%d_%d"), n, shift->ts.kind);
760 void
761 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
763 gfc_typespec ts;
764 gfc_clear_ts (&ts);
766 f->ts.type = BT_CHARACTER;
767 f->ts.kind = gfc_default_character_kind;
769 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
770 if (time->ts.kind != 8)
772 ts.type = BT_INTEGER;
773 ts.kind = 8;
774 ts.u.derived = NULL;
775 ts.u.cl = NULL;
776 gfc_convert_type (time, &ts, 2);
779 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
783 void
784 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
786 f->ts.type = BT_REAL;
787 f->ts.kind = gfc_default_double_kind;
788 f->value.function.name
789 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
793 void
794 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
796 f->ts.type = a->ts.type;
797 if (p != NULL)
798 f->ts.kind = gfc_kind_max (a,p);
799 else
800 f->ts.kind = a->ts.kind;
802 if (p != NULL && a->ts.kind != p->ts.kind)
804 if (a->ts.kind == gfc_kind_max (a,p))
805 gfc_convert_type (p, &a->ts, 2);
806 else
807 gfc_convert_type (a, &p->ts, 2);
810 f->value.function.name
811 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
815 void
816 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
818 gfc_expr temp;
820 temp.expr_type = EXPR_OP;
821 gfc_clear_ts (&temp.ts);
822 temp.value.op.op = INTRINSIC_NONE;
823 temp.value.op.op1 = a;
824 temp.value.op.op2 = b;
825 gfc_type_convert_binary (&temp, 1);
826 f->ts = temp.ts;
827 f->value.function.name
828 = gfc_get_string (PREFIX ("dot_product_%c%d"),
829 gfc_type_letter (f->ts.type), f->ts.kind);
833 void
834 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
835 gfc_expr *b ATTRIBUTE_UNUSED)
837 f->ts.kind = gfc_default_double_kind;
838 f->ts.type = BT_REAL;
839 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
843 void
844 gfc_resolve_dshift (gfc_expr *f, gfc_expr *i, gfc_expr *j ATTRIBUTE_UNUSED,
845 gfc_expr *shift ATTRIBUTE_UNUSED)
847 f->ts = i->ts;
848 if (f->value.function.isym->id == GFC_ISYM_DSHIFTL)
849 f->value.function.name = gfc_get_string ("dshiftl_i%d", f->ts.kind);
850 else if (f->value.function.isym->id == GFC_ISYM_DSHIFTR)
851 f->value.function.name = gfc_get_string ("dshiftr_i%d", f->ts.kind);
852 else
853 gcc_unreachable ();
857 void
858 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
859 gfc_expr *boundary, gfc_expr *dim)
861 int n, m;
863 if (array->ts.type == BT_CHARACTER && array->ref)
864 gfc_resolve_substring_charlen (array);
866 f->ts = array->ts;
867 f->rank = array->rank;
868 f->shape = gfc_copy_shape (array->shape, array->rank);
870 n = 0;
871 if (shift->rank > 0)
872 n = n | 1;
873 if (boundary && boundary->rank > 0)
874 n = n | 2;
876 /* If dim kind is greater than default integer we need to use the larger. */
877 m = gfc_default_integer_kind;
878 if (dim != NULL)
879 m = m < dim->ts.kind ? dim->ts.kind : m;
881 /* Convert shift to at least m, so we don't need
882 kind=1 and kind=2 versions of the library functions. */
883 if (shift->ts.kind < m)
885 gfc_typespec ts;
886 gfc_clear_ts (&ts);
887 ts.type = BT_INTEGER;
888 ts.kind = m;
889 gfc_convert_type_warn (shift, &ts, 2, 0);
892 if (dim != NULL)
894 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
895 && dim->symtree->n.sym->attr.optional)
897 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
898 dim->representation.length = shift->ts.kind;
900 else
902 gfc_resolve_dim_arg (dim);
903 /* Convert dim to shift's kind to reduce variations. */
904 if (dim->ts.kind != shift->ts.kind)
905 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
909 if (array->ts.type == BT_CHARACTER)
911 if (array->ts.kind == gfc_default_character_kind)
912 f->value.function.name
913 = gfc_get_string (PREFIX ("eoshift%d_%d_char"), n, shift->ts.kind);
914 else
915 f->value.function.name
916 = gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n, shift->ts.kind,
917 array->ts.kind);
919 else
920 f->value.function.name
921 = gfc_get_string (PREFIX ("eoshift%d_%d"), n, shift->ts.kind);
925 void
926 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
928 f->ts = x->ts;
929 f->value.function.name
930 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
934 void
935 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
937 f->ts.type = BT_INTEGER;
938 f->ts.kind = gfc_default_integer_kind;
939 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
943 /* Resolve the EXTENDS_TYPE_OF intrinsic function. */
945 void
946 gfc_resolve_extends_type_of (gfc_expr *f, gfc_expr *a, gfc_expr *mo)
948 gfc_symbol *vtab;
949 gfc_symtree *st;
951 /* Prevent double resolution. */
952 if (f->ts.type == BT_LOGICAL)
953 return;
955 /* Replace the first argument with the corresponding vtab. */
956 if (a->ts.type == BT_CLASS)
957 gfc_add_vptr_component (a);
958 else if (a->ts.type == BT_DERIVED)
960 vtab = gfc_find_derived_vtab (a->ts.u.derived);
961 /* Clear the old expr. */
962 gfc_free_ref_list (a->ref);
963 memset (a, '\0', sizeof (gfc_expr));
964 /* Construct a new one. */
965 a->expr_type = EXPR_VARIABLE;
966 st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
967 a->symtree = st;
968 a->ts = vtab->ts;
971 /* Replace the second argument with the corresponding vtab. */
972 if (mo->ts.type == BT_CLASS)
973 gfc_add_vptr_component (mo);
974 else if (mo->ts.type == BT_DERIVED)
976 vtab = gfc_find_derived_vtab (mo->ts.u.derived);
977 /* Clear the old expr. */
978 gfc_free_ref_list (mo->ref);
979 memset (mo, '\0', sizeof (gfc_expr));
980 /* Construct a new one. */
981 mo->expr_type = EXPR_VARIABLE;
982 st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
983 mo->symtree = st;
984 mo->ts = vtab->ts;
987 f->ts.type = BT_LOGICAL;
988 f->ts.kind = 4;
990 f->value.function.isym->formal->ts = a->ts;
991 f->value.function.isym->formal->next->ts = mo->ts;
993 /* Call library function. */
994 f->value.function.name = gfc_get_string (PREFIX ("is_extension_of"));
998 void
999 gfc_resolve_fdate (gfc_expr *f)
1001 f->ts.type = BT_CHARACTER;
1002 f->ts.kind = gfc_default_character_kind;
1003 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
1007 void
1008 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1010 f->ts.type = BT_INTEGER;
1011 f->ts.kind = (kind == NULL)
1012 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1013 f->value.function.name
1014 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
1015 gfc_type_letter (a->ts.type), a->ts.kind);
1019 void
1020 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
1022 f->ts.type = BT_INTEGER;
1023 f->ts.kind = gfc_default_integer_kind;
1024 if (n->ts.kind != f->ts.kind)
1025 gfc_convert_type (n, &f->ts, 2);
1026 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
1030 void
1031 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
1033 f->ts = x->ts;
1034 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
1038 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
1040 void
1041 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
1043 f->ts = x->ts;
1044 f->value.function.name = gfc_get_string ("<intrinsic>");
1048 void
1049 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
1051 f->ts = x->ts;
1052 f->value.function.name
1053 = gfc_get_string ("__tgamma_%d", x->ts.kind);
1057 void
1058 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
1060 f->ts.type = BT_INTEGER;
1061 f->ts.kind = 4;
1062 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
1066 void
1067 gfc_resolve_getgid (gfc_expr *f)
1069 f->ts.type = BT_INTEGER;
1070 f->ts.kind = 4;
1071 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
1075 void
1076 gfc_resolve_getpid (gfc_expr *f)
1078 f->ts.type = BT_INTEGER;
1079 f->ts.kind = 4;
1080 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
1084 void
1085 gfc_resolve_getuid (gfc_expr *f)
1087 f->ts.type = BT_INTEGER;
1088 f->ts.kind = 4;
1089 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
1093 void
1094 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
1096 f->ts.type = BT_INTEGER;
1097 f->ts.kind = 4;
1098 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
1102 void
1103 gfc_resolve_hypot (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
1105 f->ts = x->ts;
1106 f->value.function.name = gfc_get_string ("__hypot_r%d", x->ts.kind);
1110 void
1111 gfc_resolve_iall (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1113 resolve_transformational ("iall", f, array, dim, mask);
1117 void
1118 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1120 /* If the kind of i and j are different, then g77 cross-promoted the
1121 kinds to the largest value. The Fortran 95 standard requires the
1122 kinds to match. */
1123 if (i->ts.kind != j->ts.kind)
1125 if (i->ts.kind == gfc_kind_max (i, j))
1126 gfc_convert_type (j, &i->ts, 2);
1127 else
1128 gfc_convert_type (i, &j->ts, 2);
1131 f->ts = i->ts;
1132 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
1136 void
1137 gfc_resolve_iany (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1139 resolve_transformational ("iany", f, array, dim, mask);
1143 void
1144 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1146 f->ts = i->ts;
1147 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
1151 void
1152 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
1153 gfc_expr *len ATTRIBUTE_UNUSED)
1155 f->ts = i->ts;
1156 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
1160 void
1161 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1163 f->ts = i->ts;
1164 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
1168 void
1169 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1171 f->ts.type = BT_INTEGER;
1172 if (kind)
1173 f->ts.kind = mpz_get_si (kind->value.integer);
1174 else
1175 f->ts.kind = gfc_default_integer_kind;
1176 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1180 void
1181 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1183 f->ts.type = BT_INTEGER;
1184 if (kind)
1185 f->ts.kind = mpz_get_si (kind->value.integer);
1186 else
1187 f->ts.kind = gfc_default_integer_kind;
1188 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1192 void
1193 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
1195 gfc_resolve_nint (f, a, NULL);
1199 void
1200 gfc_resolve_ierrno (gfc_expr *f)
1202 f->ts.type = BT_INTEGER;
1203 f->ts.kind = gfc_default_integer_kind;
1204 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
1208 void
1209 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1211 /* If the kind of i and j are different, then g77 cross-promoted the
1212 kinds to the largest value. The Fortran 95 standard requires the
1213 kinds to match. */
1214 if (i->ts.kind != j->ts.kind)
1216 if (i->ts.kind == gfc_kind_max (i, j))
1217 gfc_convert_type (j, &i->ts, 2);
1218 else
1219 gfc_convert_type (i, &j->ts, 2);
1222 f->ts = i->ts;
1223 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
1227 void
1228 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1230 /* If the kind of i and j are different, then g77 cross-promoted the
1231 kinds to the largest value. The Fortran 95 standard requires the
1232 kinds to match. */
1233 if (i->ts.kind != j->ts.kind)
1235 if (i->ts.kind == gfc_kind_max (i, j))
1236 gfc_convert_type (j, &i->ts, 2);
1237 else
1238 gfc_convert_type (i, &j->ts, 2);
1241 f->ts = i->ts;
1242 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
1246 void
1247 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
1248 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
1249 gfc_expr *kind)
1251 gfc_typespec ts;
1252 gfc_clear_ts (&ts);
1254 f->ts.type = BT_INTEGER;
1255 if (kind)
1256 f->ts.kind = mpz_get_si (kind->value.integer);
1257 else
1258 f->ts.kind = gfc_default_integer_kind;
1260 if (back && back->ts.kind != gfc_default_integer_kind)
1262 ts.type = BT_LOGICAL;
1263 ts.kind = gfc_default_integer_kind;
1264 ts.u.derived = NULL;
1265 ts.u.cl = NULL;
1266 gfc_convert_type (back, &ts, 2);
1269 f->value.function.name
1270 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
1274 void
1275 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1277 f->ts.type = BT_INTEGER;
1278 f->ts.kind = (kind == NULL)
1279 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1280 f->value.function.name
1281 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1282 gfc_type_letter (a->ts.type), a->ts.kind);
1286 void
1287 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1289 f->ts.type = BT_INTEGER;
1290 f->ts.kind = 2;
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);
1297 void
1298 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
1300 f->ts.type = BT_INTEGER;
1301 f->ts.kind = 8;
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);
1308 void
1309 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1311 f->ts.type = BT_INTEGER;
1312 f->ts.kind = 4;
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);
1319 void
1320 gfc_resolve_iparity (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1322 resolve_transformational ("iparity", f, array, dim, mask);
1326 void
1327 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1329 gfc_typespec ts;
1330 gfc_clear_ts (&ts);
1332 f->ts.type = BT_LOGICAL;
1333 f->ts.kind = gfc_default_integer_kind;
1334 if (u->ts.kind != gfc_c_int_kind)
1336 ts.type = BT_INTEGER;
1337 ts.kind = gfc_c_int_kind;
1338 ts.u.derived = NULL;
1339 ts.u.cl = NULL;
1340 gfc_convert_type (u, &ts, 2);
1343 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1347 void
1348 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1350 f->ts = i->ts;
1351 f->value.function.name
1352 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1356 void
1357 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1359 f->ts = i->ts;
1360 f->value.function.name
1361 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1365 void
1366 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1368 f->ts = i->ts;
1369 f->value.function.name
1370 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1374 void
1375 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1377 int s_kind;
1379 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1381 f->ts = i->ts;
1382 f->value.function.name
1383 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1387 void
1388 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1389 gfc_expr *s ATTRIBUTE_UNUSED)
1391 f->ts.type = BT_INTEGER;
1392 f->ts.kind = gfc_default_integer_kind;
1393 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1397 void
1398 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1400 resolve_bound (f, array, dim, kind, "__lbound", false);
1404 void
1405 gfc_resolve_lcobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1407 resolve_bound (f, array, dim, kind, "__lcobound", true);
1411 void
1412 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1414 f->ts.type = BT_INTEGER;
1415 if (kind)
1416 f->ts.kind = mpz_get_si (kind->value.integer);
1417 else
1418 f->ts.kind = gfc_default_integer_kind;
1419 f->value.function.name
1420 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1421 gfc_default_integer_kind);
1425 void
1426 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1428 f->ts.type = BT_INTEGER;
1429 if (kind)
1430 f->ts.kind = mpz_get_si (kind->value.integer);
1431 else
1432 f->ts.kind = gfc_default_integer_kind;
1433 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1437 void
1438 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1440 f->ts = x->ts;
1441 f->value.function.name
1442 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1446 void
1447 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1448 gfc_expr *p2 ATTRIBUTE_UNUSED)
1450 f->ts.type = BT_INTEGER;
1451 f->ts.kind = gfc_default_integer_kind;
1452 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1456 void
1457 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1459 f->ts.type= BT_INTEGER;
1460 f->ts.kind = gfc_index_integer_kind;
1461 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1465 void
1466 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1468 f->ts = x->ts;
1469 f->value.function.name
1470 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1474 void
1475 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1477 f->ts = x->ts;
1478 f->value.function.name
1479 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1480 x->ts.kind);
1484 void
1485 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1487 f->ts.type = BT_LOGICAL;
1488 f->ts.kind = (kind == NULL)
1489 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1490 f->rank = a->rank;
1492 f->value.function.name
1493 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1494 gfc_type_letter (a->ts.type), a->ts.kind);
1498 void
1499 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1501 if (size->ts.kind < gfc_index_integer_kind)
1503 gfc_typespec ts;
1504 gfc_clear_ts (&ts);
1506 ts.type = BT_INTEGER;
1507 ts.kind = gfc_index_integer_kind;
1508 gfc_convert_type_warn (size, &ts, 2, 0);
1511 f->ts.type = BT_INTEGER;
1512 f->ts.kind = gfc_index_integer_kind;
1513 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1517 void
1518 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1520 gfc_expr temp;
1522 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1524 f->ts.type = BT_LOGICAL;
1525 f->ts.kind = gfc_default_logical_kind;
1527 else
1529 temp.expr_type = EXPR_OP;
1530 gfc_clear_ts (&temp.ts);
1531 temp.value.op.op = INTRINSIC_NONE;
1532 temp.value.op.op1 = a;
1533 temp.value.op.op2 = b;
1534 gfc_type_convert_binary (&temp, 1);
1535 f->ts = temp.ts;
1538 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1540 if (a->rank == 2 && b->rank == 2)
1542 if (a->shape && b->shape)
1544 f->shape = gfc_get_shape (f->rank);
1545 mpz_init_set (f->shape[0], a->shape[0]);
1546 mpz_init_set (f->shape[1], b->shape[1]);
1549 else if (a->rank == 1)
1551 if (b->shape)
1553 f->shape = gfc_get_shape (f->rank);
1554 mpz_init_set (f->shape[0], b->shape[1]);
1557 else
1559 /* b->rank == 1 and a->rank == 2 here, all other cases have
1560 been caught in check.c. */
1561 if (a->shape)
1563 f->shape = gfc_get_shape (f->rank);
1564 mpz_init_set (f->shape[0], a->shape[0]);
1568 f->value.function.name
1569 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1570 f->ts.kind);
1574 static void
1575 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1577 gfc_actual_arglist *a;
1579 f->ts.type = args->expr->ts.type;
1580 f->ts.kind = args->expr->ts.kind;
1581 /* Find the largest type kind. */
1582 for (a = args->next; a; a = a->next)
1584 if (a->expr->ts.kind > f->ts.kind)
1585 f->ts.kind = a->expr->ts.kind;
1588 /* Convert all parameters to the required kind. */
1589 for (a = args; a; a = a->next)
1591 if (a->expr->ts.kind != f->ts.kind)
1592 gfc_convert_type (a->expr, &f->ts, 2);
1595 f->value.function.name
1596 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1600 void
1601 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1603 gfc_resolve_minmax ("__max_%c%d", f, args);
1607 void
1608 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1609 gfc_expr *mask)
1611 const char *name;
1612 int i, j, idim;
1614 f->ts.type = BT_INTEGER;
1615 f->ts.kind = gfc_default_integer_kind;
1617 if (dim == NULL)
1619 f->rank = 1;
1620 f->shape = gfc_get_shape (1);
1621 mpz_init_set_si (f->shape[0], array->rank);
1623 else
1625 f->rank = array->rank - 1;
1626 gfc_resolve_dim_arg (dim);
1627 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1629 idim = (int) mpz_get_si (dim->value.integer);
1630 f->shape = gfc_get_shape (f->rank);
1631 for (i = 0, j = 0; i < f->rank; i++, j++)
1633 if (i == (idim - 1))
1634 j++;
1635 mpz_init_set (f->shape[i], array->shape[j]);
1640 if (mask)
1642 if (mask->rank == 0)
1643 name = "smaxloc";
1644 else
1645 name = "mmaxloc";
1647 resolve_mask_arg (mask);
1649 else
1650 name = "maxloc";
1652 f->value.function.name
1653 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1654 gfc_type_letter (array->ts.type), array->ts.kind);
1658 void
1659 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1660 gfc_expr *mask)
1662 const char *name;
1663 int i, j, idim;
1665 f->ts = array->ts;
1667 if (dim != NULL)
1669 f->rank = array->rank - 1;
1670 gfc_resolve_dim_arg (dim);
1672 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1674 idim = (int) mpz_get_si (dim->value.integer);
1675 f->shape = gfc_get_shape (f->rank);
1676 for (i = 0, j = 0; i < f->rank; i++, j++)
1678 if (i == (idim - 1))
1679 j++;
1680 mpz_init_set (f->shape[i], array->shape[j]);
1685 if (mask)
1687 if (mask->rank == 0)
1688 name = "smaxval";
1689 else
1690 name = "mmaxval";
1692 resolve_mask_arg (mask);
1694 else
1695 name = "maxval";
1697 f->value.function.name
1698 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1699 gfc_type_letter (array->ts.type), array->ts.kind);
1703 void
1704 gfc_resolve_mclock (gfc_expr *f)
1706 f->ts.type = BT_INTEGER;
1707 f->ts.kind = 4;
1708 f->value.function.name = PREFIX ("mclock");
1712 void
1713 gfc_resolve_mclock8 (gfc_expr *f)
1715 f->ts.type = BT_INTEGER;
1716 f->ts.kind = 8;
1717 f->value.function.name = PREFIX ("mclock8");
1721 void
1722 gfc_resolve_mask (gfc_expr *f, gfc_expr *i ATTRIBUTE_UNUSED,
1723 gfc_expr *kind)
1725 f->ts.type = BT_INTEGER;
1726 f->ts.kind = kind ? mpz_get_si (kind->value.integer)
1727 : gfc_default_integer_kind;
1729 if (f->value.function.isym->id == GFC_ISYM_MASKL)
1730 f->value.function.name = gfc_get_string ("__maskl_i%d", f->ts.kind);
1731 else
1732 f->value.function.name = gfc_get_string ("__maskr_i%d", f->ts.kind);
1736 void
1737 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1738 gfc_expr *fsource ATTRIBUTE_UNUSED,
1739 gfc_expr *mask ATTRIBUTE_UNUSED)
1741 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1742 gfc_resolve_substring_charlen (tsource);
1744 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1745 gfc_resolve_substring_charlen (fsource);
1747 if (tsource->ts.type == BT_CHARACTER)
1748 check_charlen_present (tsource);
1750 f->ts = tsource->ts;
1751 f->value.function.name
1752 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1753 tsource->ts.kind);
1757 void
1758 gfc_resolve_merge_bits (gfc_expr *f, gfc_expr *i,
1759 gfc_expr *j ATTRIBUTE_UNUSED,
1760 gfc_expr *mask ATTRIBUTE_UNUSED)
1762 f->ts = i->ts;
1763 f->value.function.name = gfc_get_string ("__merge_bits_i%d", i->ts.kind);
1767 void
1768 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1770 gfc_resolve_minmax ("__min_%c%d", f, args);
1774 void
1775 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1776 gfc_expr *mask)
1778 const char *name;
1779 int i, j, idim;
1781 f->ts.type = BT_INTEGER;
1782 f->ts.kind = gfc_default_integer_kind;
1784 if (dim == NULL)
1786 f->rank = 1;
1787 f->shape = gfc_get_shape (1);
1788 mpz_init_set_si (f->shape[0], array->rank);
1790 else
1792 f->rank = array->rank - 1;
1793 gfc_resolve_dim_arg (dim);
1794 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1796 idim = (int) mpz_get_si (dim->value.integer);
1797 f->shape = gfc_get_shape (f->rank);
1798 for (i = 0, j = 0; i < f->rank; i++, j++)
1800 if (i == (idim - 1))
1801 j++;
1802 mpz_init_set (f->shape[i], array->shape[j]);
1807 if (mask)
1809 if (mask->rank == 0)
1810 name = "sminloc";
1811 else
1812 name = "mminloc";
1814 resolve_mask_arg (mask);
1816 else
1817 name = "minloc";
1819 f->value.function.name
1820 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1821 gfc_type_letter (array->ts.type), array->ts.kind);
1825 void
1826 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1827 gfc_expr *mask)
1829 const char *name;
1830 int i, j, idim;
1832 f->ts = array->ts;
1834 if (dim != NULL)
1836 f->rank = array->rank - 1;
1837 gfc_resolve_dim_arg (dim);
1839 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1841 idim = (int) mpz_get_si (dim->value.integer);
1842 f->shape = gfc_get_shape (f->rank);
1843 for (i = 0, j = 0; i < f->rank; i++, j++)
1845 if (i == (idim - 1))
1846 j++;
1847 mpz_init_set (f->shape[i], array->shape[j]);
1852 if (mask)
1854 if (mask->rank == 0)
1855 name = "sminval";
1856 else
1857 name = "mminval";
1859 resolve_mask_arg (mask);
1861 else
1862 name = "minval";
1864 f->value.function.name
1865 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1866 gfc_type_letter (array->ts.type), array->ts.kind);
1870 void
1871 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1873 f->ts.type = a->ts.type;
1874 if (p != NULL)
1875 f->ts.kind = gfc_kind_max (a,p);
1876 else
1877 f->ts.kind = a->ts.kind;
1879 if (p != NULL && a->ts.kind != p->ts.kind)
1881 if (a->ts.kind == gfc_kind_max (a,p))
1882 gfc_convert_type (p, &a->ts, 2);
1883 else
1884 gfc_convert_type (a, &p->ts, 2);
1887 f->value.function.name
1888 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1892 void
1893 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1895 f->ts.type = a->ts.type;
1896 if (p != NULL)
1897 f->ts.kind = gfc_kind_max (a,p);
1898 else
1899 f->ts.kind = a->ts.kind;
1901 if (p != NULL && a->ts.kind != p->ts.kind)
1903 if (a->ts.kind == gfc_kind_max (a,p))
1904 gfc_convert_type (p, &a->ts, 2);
1905 else
1906 gfc_convert_type (a, &p->ts, 2);
1909 f->value.function.name
1910 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1911 f->ts.kind);
1914 void
1915 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1917 if (p->ts.kind != a->ts.kind)
1918 gfc_convert_type (p, &a->ts, 2);
1920 f->ts = a->ts;
1921 f->value.function.name
1922 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1923 a->ts.kind);
1926 void
1927 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1929 f->ts.type = BT_INTEGER;
1930 f->ts.kind = (kind == NULL)
1931 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1932 f->value.function.name
1933 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1937 void
1938 gfc_resolve_norm2 (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1940 resolve_transformational ("norm2", f, array, dim, NULL);
1944 void
1945 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1947 f->ts = i->ts;
1948 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1952 void
1953 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1955 f->ts.type = i->ts.type;
1956 f->ts.kind = gfc_kind_max (i, j);
1958 if (i->ts.kind != j->ts.kind)
1960 if (i->ts.kind == gfc_kind_max (i, j))
1961 gfc_convert_type (j, &i->ts, 2);
1962 else
1963 gfc_convert_type (i, &j->ts, 2);
1966 f->value.function.name
1967 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1971 void
1972 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1973 gfc_expr *vector ATTRIBUTE_UNUSED)
1975 if (array->ts.type == BT_CHARACTER && array->ref)
1976 gfc_resolve_substring_charlen (array);
1978 f->ts = array->ts;
1979 f->rank = 1;
1981 resolve_mask_arg (mask);
1983 if (mask->rank != 0)
1985 if (array->ts.type == BT_CHARACTER)
1986 f->value.function.name
1987 = array->ts.kind == 1 ? PREFIX ("pack_char")
1988 : gfc_get_string
1989 (PREFIX ("pack_char%d"),
1990 array->ts.kind);
1991 else
1992 f->value.function.name = PREFIX ("pack");
1994 else
1996 if (array->ts.type == BT_CHARACTER)
1997 f->value.function.name
1998 = array->ts.kind == 1 ? PREFIX ("pack_s_char")
1999 : gfc_get_string
2000 (PREFIX ("pack_s_char%d"),
2001 array->ts.kind);
2002 else
2003 f->value.function.name = PREFIX ("pack_s");
2008 void
2009 gfc_resolve_parity (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
2011 resolve_transformational ("parity", f, array, dim, NULL);
2015 void
2016 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
2017 gfc_expr *mask)
2019 resolve_transformational ("product", f, array, dim, mask);
2023 void
2024 gfc_resolve_rank (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED)
2026 f->ts.type = BT_INTEGER;
2027 f->ts.kind = gfc_default_integer_kind;
2028 f->value.function.name = gfc_get_string ("__rank");
2032 void
2033 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
2035 f->ts.type = BT_REAL;
2037 if (kind != NULL)
2038 f->ts.kind = mpz_get_si (kind->value.integer);
2039 else
2040 f->ts.kind = (a->ts.type == BT_COMPLEX)
2041 ? a->ts.kind : gfc_default_real_kind;
2043 f->value.function.name
2044 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
2045 gfc_type_letter (a->ts.type), a->ts.kind);
2049 void
2050 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
2052 f->ts.type = BT_REAL;
2053 f->ts.kind = a->ts.kind;
2054 f->value.function.name
2055 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
2056 gfc_type_letter (a->ts.type), a->ts.kind);
2060 void
2061 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2062 gfc_expr *p2 ATTRIBUTE_UNUSED)
2064 f->ts.type = BT_INTEGER;
2065 f->ts.kind = gfc_default_integer_kind;
2066 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
2070 void
2071 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
2072 gfc_expr *ncopies)
2074 int len;
2075 gfc_expr *tmp;
2076 f->ts.type = BT_CHARACTER;
2077 f->ts.kind = string->ts.kind;
2078 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
2080 /* If possible, generate a character length. */
2081 if (f->ts.u.cl == NULL)
2082 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
2084 tmp = NULL;
2085 if (string->expr_type == EXPR_CONSTANT)
2087 len = string->value.character.length;
2088 tmp = gfc_get_int_expr (gfc_default_integer_kind, NULL , len);
2090 else if (string->ts.u.cl && string->ts.u.cl->length)
2092 tmp = gfc_copy_expr (string->ts.u.cl->length);
2095 if (tmp)
2096 f->ts.u.cl->length = gfc_multiply (tmp, gfc_copy_expr (ncopies));
2100 void
2101 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
2102 gfc_expr *pad ATTRIBUTE_UNUSED,
2103 gfc_expr *order ATTRIBUTE_UNUSED)
2105 mpz_t rank;
2106 int kind;
2107 int i;
2109 if (source->ts.type == BT_CHARACTER && source->ref)
2110 gfc_resolve_substring_charlen (source);
2112 f->ts = source->ts;
2114 gfc_array_size (shape, &rank);
2115 f->rank = mpz_get_si (rank);
2116 mpz_clear (rank);
2117 switch (source->ts.type)
2119 case BT_COMPLEX:
2120 case BT_REAL:
2121 case BT_INTEGER:
2122 case BT_LOGICAL:
2123 case BT_CHARACTER:
2124 kind = source->ts.kind;
2125 break;
2127 default:
2128 kind = 0;
2129 break;
2132 switch (kind)
2134 case 4:
2135 case 8:
2136 case 10:
2137 case 16:
2138 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
2139 f->value.function.name
2140 = gfc_get_string (PREFIX ("reshape_%c%d"),
2141 gfc_type_letter (source->ts.type),
2142 source->ts.kind);
2143 else if (source->ts.type == BT_CHARACTER)
2144 f->value.function.name = gfc_get_string (PREFIX ("reshape_char%d"),
2145 kind);
2146 else
2147 f->value.function.name
2148 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
2149 break;
2151 default:
2152 f->value.function.name = (source->ts.type == BT_CHARACTER
2153 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
2154 break;
2157 if (shape->expr_type == EXPR_ARRAY && gfc_is_constant_expr (shape))
2159 gfc_constructor *c;
2160 f->shape = gfc_get_shape (f->rank);
2161 c = gfc_constructor_first (shape->value.constructor);
2162 for (i = 0; i < f->rank; i++)
2164 mpz_init_set (f->shape[i], c->expr->value.integer);
2165 c = gfc_constructor_next (c);
2169 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
2170 so many runtime variations. */
2171 if (shape->ts.kind != gfc_index_integer_kind)
2173 gfc_typespec ts = shape->ts;
2174 ts.kind = gfc_index_integer_kind;
2175 gfc_convert_type_warn (shape, &ts, 2, 0);
2177 if (order && order->ts.kind != gfc_index_integer_kind)
2178 gfc_convert_type_warn (order, &shape->ts, 2, 0);
2182 void
2183 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
2185 f->ts = x->ts;
2186 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
2190 void
2191 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED)
2193 f->ts = x->ts;
2194 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
2198 void
2199 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
2200 gfc_expr *set ATTRIBUTE_UNUSED,
2201 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2203 f->ts.type = BT_INTEGER;
2204 if (kind)
2205 f->ts.kind = mpz_get_si (kind->value.integer);
2206 else
2207 f->ts.kind = gfc_default_integer_kind;
2208 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
2212 void
2213 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
2215 t1->ts = t0->ts;
2216 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
2220 void
2221 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x,
2222 gfc_expr *i ATTRIBUTE_UNUSED)
2224 f->ts = x->ts;
2225 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
2229 void
2230 gfc_resolve_shape (gfc_expr *f, gfc_expr *array, gfc_expr *kind)
2232 f->ts.type = BT_INTEGER;
2234 if (kind)
2235 f->ts.kind = mpz_get_si (kind->value.integer);
2236 else
2237 f->ts.kind = gfc_default_integer_kind;
2239 f->rank = 1;
2240 if (array->rank != -1)
2242 f->shape = gfc_get_shape (1);
2243 mpz_init_set_ui (f->shape[0], array->rank);
2246 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
2250 void
2251 gfc_resolve_shift (gfc_expr *f, gfc_expr *i, gfc_expr *shift ATTRIBUTE_UNUSED)
2253 f->ts = i->ts;
2254 if (f->value.function.isym->id == GFC_ISYM_SHIFTA)
2255 f->value.function.name = gfc_get_string ("shifta_i%d", f->ts.kind);
2256 else if (f->value.function.isym->id == GFC_ISYM_SHIFTL)
2257 f->value.function.name = gfc_get_string ("shiftl_i%d", f->ts.kind);
2258 else if (f->value.function.isym->id == GFC_ISYM_SHIFTR)
2259 f->value.function.name = gfc_get_string ("shiftr_i%d", f->ts.kind);
2260 else
2261 gcc_unreachable ();
2265 void
2266 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
2268 f->ts = a->ts;
2269 f->value.function.name
2270 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
2274 void
2275 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
2277 f->ts.type = BT_INTEGER;
2278 f->ts.kind = gfc_c_int_kind;
2280 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2281 if (handler->ts.type == BT_INTEGER)
2283 if (handler->ts.kind != gfc_c_int_kind)
2284 gfc_convert_type (handler, &f->ts, 2);
2285 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
2287 else
2288 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
2290 if (number->ts.kind != gfc_c_int_kind)
2291 gfc_convert_type (number, &f->ts, 2);
2295 void
2296 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
2298 f->ts = x->ts;
2299 f->value.function.name
2300 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2304 void
2305 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
2307 f->ts = x->ts;
2308 f->value.function.name
2309 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2313 void
2314 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2315 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
2317 f->ts.type = BT_INTEGER;
2318 if (kind)
2319 f->ts.kind = mpz_get_si (kind->value.integer);
2320 else
2321 f->ts.kind = gfc_default_integer_kind;
2325 void
2326 gfc_resolve_stride (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2327 gfc_expr *dim ATTRIBUTE_UNUSED)
2329 f->ts.type = BT_INTEGER;
2330 f->ts.kind = gfc_index_integer_kind;
2334 void
2335 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
2337 f->ts = x->ts;
2338 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
2342 void
2343 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2344 gfc_expr *ncopies)
2346 if (source->ts.type == BT_CHARACTER && source->ref)
2347 gfc_resolve_substring_charlen (source);
2349 if (source->ts.type == BT_CHARACTER)
2350 check_charlen_present (source);
2352 f->ts = source->ts;
2353 f->rank = source->rank + 1;
2354 if (source->rank == 0)
2356 if (source->ts.type == BT_CHARACTER)
2357 f->value.function.name
2358 = source->ts.kind == 1 ? PREFIX ("spread_char_scalar")
2359 : gfc_get_string
2360 (PREFIX ("spread_char%d_scalar"),
2361 source->ts.kind);
2362 else
2363 f->value.function.name = PREFIX ("spread_scalar");
2365 else
2367 if (source->ts.type == BT_CHARACTER)
2368 f->value.function.name
2369 = source->ts.kind == 1 ? PREFIX ("spread_char")
2370 : gfc_get_string
2371 (PREFIX ("spread_char%d"),
2372 source->ts.kind);
2373 else
2374 f->value.function.name = PREFIX ("spread");
2377 if (dim && gfc_is_constant_expr (dim)
2378 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2380 int i, idim;
2381 idim = mpz_get_ui (dim->value.integer);
2382 f->shape = gfc_get_shape (f->rank);
2383 for (i = 0; i < (idim - 1); i++)
2384 mpz_init_set (f->shape[i], source->shape[i]);
2386 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2388 for (i = idim; i < f->rank ; i++)
2389 mpz_init_set (f->shape[i], source->shape[i-1]);
2393 gfc_resolve_dim_arg (dim);
2394 gfc_resolve_index (ncopies, 1);
2398 void
2399 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2401 f->ts = x->ts;
2402 f->value.function.name
2403 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2407 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2409 void
2410 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2411 gfc_expr *a ATTRIBUTE_UNUSED)
2413 f->ts.type = BT_INTEGER;
2414 f->ts.kind = gfc_default_integer_kind;
2415 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2419 void
2420 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2421 gfc_expr *a ATTRIBUTE_UNUSED)
2423 f->ts.type = BT_INTEGER;
2424 f->ts.kind = gfc_default_integer_kind;
2425 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2429 void
2430 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2432 f->ts.type = BT_INTEGER;
2433 f->ts.kind = gfc_default_integer_kind;
2434 if (n->ts.kind != f->ts.kind)
2435 gfc_convert_type (n, &f->ts, 2);
2437 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2441 void
2442 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2444 gfc_typespec ts;
2445 gfc_clear_ts (&ts);
2447 f->ts.type = BT_INTEGER;
2448 f->ts.kind = gfc_c_int_kind;
2449 if (u->ts.kind != gfc_c_int_kind)
2451 ts.type = BT_INTEGER;
2452 ts.kind = gfc_c_int_kind;
2453 ts.u.derived = NULL;
2454 ts.u.cl = NULL;
2455 gfc_convert_type (u, &ts, 2);
2458 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2462 void
2463 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2465 f->ts.type = BT_INTEGER;
2466 f->ts.kind = gfc_c_int_kind;
2467 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2471 void
2472 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2474 gfc_typespec ts;
2475 gfc_clear_ts (&ts);
2477 f->ts.type = BT_INTEGER;
2478 f->ts.kind = gfc_c_int_kind;
2479 if (u->ts.kind != gfc_c_int_kind)
2481 ts.type = BT_INTEGER;
2482 ts.kind = gfc_c_int_kind;
2483 ts.u.derived = NULL;
2484 ts.u.cl = NULL;
2485 gfc_convert_type (u, &ts, 2);
2488 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2492 void
2493 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2495 f->ts.type = BT_INTEGER;
2496 f->ts.kind = gfc_c_int_kind;
2497 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2501 void
2502 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2504 gfc_typespec ts;
2505 gfc_clear_ts (&ts);
2507 f->ts.type = BT_INTEGER;
2508 f->ts.kind = gfc_intio_kind;
2509 if (u->ts.kind != gfc_c_int_kind)
2511 ts.type = BT_INTEGER;
2512 ts.kind = gfc_c_int_kind;
2513 ts.u.derived = NULL;
2514 ts.u.cl = NULL;
2515 gfc_convert_type (u, &ts, 2);
2518 f->value.function.name = gfc_get_string (PREFIX ("ftell2"));
2522 void
2523 gfc_resolve_storage_size (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
2524 gfc_expr *kind)
2526 f->ts.type = BT_INTEGER;
2527 if (kind)
2528 f->ts.kind = mpz_get_si (kind->value.integer);
2529 else
2530 f->ts.kind = gfc_default_integer_kind;
2534 void
2535 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2537 resolve_transformational ("sum", f, array, dim, mask);
2541 void
2542 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2543 gfc_expr *p2 ATTRIBUTE_UNUSED)
2545 f->ts.type = BT_INTEGER;
2546 f->ts.kind = gfc_default_integer_kind;
2547 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2551 /* Resolve the g77 compatibility function SYSTEM. */
2553 void
2554 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2556 f->ts.type = BT_INTEGER;
2557 f->ts.kind = 4;
2558 f->value.function.name = gfc_get_string (PREFIX ("system"));
2562 void
2563 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2565 f->ts = x->ts;
2566 f->value.function.name
2567 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2571 void
2572 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2574 f->ts = x->ts;
2575 f->value.function.name
2576 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2580 void
2581 gfc_resolve_image_index (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2582 gfc_expr *sub ATTRIBUTE_UNUSED)
2584 static char image_index[] = "__image_index";
2585 f->ts.type = BT_INTEGER;
2586 f->ts.kind = gfc_default_integer_kind;
2587 f->value.function.name = image_index;
2591 void
2592 gfc_resolve_this_image (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
2594 static char this_image[] = "__this_image";
2595 if (array)
2596 resolve_bound (f, array, dim, NULL, "__this_image", true);
2597 else
2599 f->ts.type = BT_INTEGER;
2600 f->ts.kind = gfc_default_integer_kind;
2601 f->value.function.name = this_image;
2606 void
2607 gfc_resolve_time (gfc_expr *f)
2609 f->ts.type = BT_INTEGER;
2610 f->ts.kind = 4;
2611 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2615 void
2616 gfc_resolve_time8 (gfc_expr *f)
2618 f->ts.type = BT_INTEGER;
2619 f->ts.kind = 8;
2620 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2624 void
2625 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2626 gfc_expr *mold, gfc_expr *size)
2628 /* TODO: Make this do something meaningful. */
2629 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2631 if (mold->ts.type == BT_CHARACTER
2632 && !mold->ts.u.cl->length
2633 && gfc_is_constant_expr (mold))
2635 int len;
2636 if (mold->expr_type == EXPR_CONSTANT)
2638 len = mold->value.character.length;
2639 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2640 NULL, len);
2642 else
2644 gfc_constructor *c = gfc_constructor_first (mold->value.constructor);
2645 len = c->expr->value.character.length;
2646 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2647 NULL, len);
2651 f->ts = mold->ts;
2653 if (size == NULL && mold->rank == 0)
2655 f->rank = 0;
2656 f->value.function.name = transfer0;
2658 else
2660 f->rank = 1;
2661 f->value.function.name = transfer1;
2662 if (size && gfc_is_constant_expr (size))
2664 f->shape = gfc_get_shape (1);
2665 mpz_init_set (f->shape[0], size->value.integer);
2671 void
2672 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2675 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2676 gfc_resolve_substring_charlen (matrix);
2678 f->ts = matrix->ts;
2679 f->rank = 2;
2680 if (matrix->shape)
2682 f->shape = gfc_get_shape (2);
2683 mpz_init_set (f->shape[0], matrix->shape[1]);
2684 mpz_init_set (f->shape[1], matrix->shape[0]);
2687 switch (matrix->ts.kind)
2689 case 4:
2690 case 8:
2691 case 10:
2692 case 16:
2693 switch (matrix->ts.type)
2695 case BT_REAL:
2696 case BT_COMPLEX:
2697 f->value.function.name
2698 = gfc_get_string (PREFIX ("transpose_%c%d"),
2699 gfc_type_letter (matrix->ts.type),
2700 matrix->ts.kind);
2701 break;
2703 case BT_INTEGER:
2704 case BT_LOGICAL:
2705 /* Use the integer routines for real and logical cases. This
2706 assumes they all have the same alignment requirements. */
2707 f->value.function.name
2708 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2709 break;
2711 default:
2712 if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4)
2713 f->value.function.name = PREFIX ("transpose_char4");
2714 else
2715 f->value.function.name = PREFIX ("transpose");
2716 break;
2718 break;
2720 default:
2721 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2722 ? PREFIX ("transpose_char")
2723 : PREFIX ("transpose"));
2724 break;
2729 void
2730 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2732 f->ts.type = BT_CHARACTER;
2733 f->ts.kind = string->ts.kind;
2734 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2738 void
2739 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2741 resolve_bound (f, array, dim, kind, "__ubound", false);
2745 void
2746 gfc_resolve_ucobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2748 resolve_bound (f, array, dim, kind, "__ucobound", true);
2752 /* Resolve the g77 compatibility function UMASK. */
2754 void
2755 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2757 f->ts.type = BT_INTEGER;
2758 f->ts.kind = n->ts.kind;
2759 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2763 /* Resolve the g77 compatibility function UNLINK. */
2765 void
2766 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2768 f->ts.type = BT_INTEGER;
2769 f->ts.kind = 4;
2770 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2774 void
2775 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2777 gfc_typespec ts;
2778 gfc_clear_ts (&ts);
2780 f->ts.type = BT_CHARACTER;
2781 f->ts.kind = gfc_default_character_kind;
2783 if (unit->ts.kind != gfc_c_int_kind)
2785 ts.type = BT_INTEGER;
2786 ts.kind = gfc_c_int_kind;
2787 ts.u.derived = NULL;
2788 ts.u.cl = NULL;
2789 gfc_convert_type (unit, &ts, 2);
2792 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2796 void
2797 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2798 gfc_expr *field ATTRIBUTE_UNUSED)
2800 if (vector->ts.type == BT_CHARACTER && vector->ref)
2801 gfc_resolve_substring_charlen (vector);
2803 f->ts = vector->ts;
2804 f->rank = mask->rank;
2805 resolve_mask_arg (mask);
2807 if (vector->ts.type == BT_CHARACTER)
2809 if (vector->ts.kind == 1)
2810 f->value.function.name
2811 = gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0);
2812 else
2813 f->value.function.name
2814 = gfc_get_string (PREFIX ("unpack%d_char%d"),
2815 field->rank > 0 ? 1 : 0, vector->ts.kind);
2817 else
2818 f->value.function.name
2819 = gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0);
2823 void
2824 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2825 gfc_expr *set ATTRIBUTE_UNUSED,
2826 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2828 f->ts.type = BT_INTEGER;
2829 if (kind)
2830 f->ts.kind = mpz_get_si (kind->value.integer);
2831 else
2832 f->ts.kind = gfc_default_integer_kind;
2833 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2837 void
2838 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2840 f->ts.type = i->ts.type;
2841 f->ts.kind = gfc_kind_max (i, j);
2843 if (i->ts.kind != j->ts.kind)
2845 if (i->ts.kind == gfc_kind_max (i, j))
2846 gfc_convert_type (j, &i->ts, 2);
2847 else
2848 gfc_convert_type (i, &j->ts, 2);
2851 f->value.function.name
2852 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2856 /* Intrinsic subroutine resolution. */
2858 void
2859 gfc_resolve_alarm_sub (gfc_code *c)
2861 const char *name;
2862 gfc_expr *seconds, *handler;
2863 gfc_typespec ts;
2864 gfc_clear_ts (&ts);
2866 seconds = c->ext.actual->expr;
2867 handler = c->ext.actual->next->expr;
2868 ts.type = BT_INTEGER;
2869 ts.kind = gfc_c_int_kind;
2871 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2872 In all cases, the status argument is of default integer kind
2873 (enforced in check.c) so that the function suffix is fixed. */
2874 if (handler->ts.type == BT_INTEGER)
2876 if (handler->ts.kind != gfc_c_int_kind)
2877 gfc_convert_type (handler, &ts, 2);
2878 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2879 gfc_default_integer_kind);
2881 else
2882 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2883 gfc_default_integer_kind);
2885 if (seconds->ts.kind != gfc_c_int_kind)
2886 gfc_convert_type (seconds, &ts, 2);
2888 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2891 void
2892 gfc_resolve_cpu_time (gfc_code *c)
2894 const char *name;
2895 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2896 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2900 /* Create a formal arglist based on an actual one and set the INTENTs given. */
2902 static gfc_formal_arglist*
2903 create_formal_for_intents (gfc_actual_arglist* actual, const sym_intent* ints)
2905 gfc_formal_arglist* head;
2906 gfc_formal_arglist* tail;
2907 int i;
2909 if (!actual)
2910 return NULL;
2912 head = tail = gfc_get_formal_arglist ();
2913 for (i = 0; actual; actual = actual->next, tail = tail->next, ++i)
2915 gfc_symbol* sym;
2917 sym = gfc_new_symbol ("dummyarg", NULL);
2918 sym->ts = actual->expr->ts;
2920 sym->attr.intent = ints[i];
2921 tail->sym = sym;
2923 if (actual->next)
2924 tail->next = gfc_get_formal_arglist ();
2927 return head;
2931 void
2932 gfc_resolve_atomic_def (gfc_code *c)
2934 const char *name = "atomic_define";
2935 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2939 void
2940 gfc_resolve_atomic_ref (gfc_code *c)
2942 const char *name = "atomic_ref";
2943 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2947 void
2948 gfc_resolve_mvbits (gfc_code *c)
2950 static const sym_intent INTENTS[] = {INTENT_IN, INTENT_IN, INTENT_IN,
2951 INTENT_INOUT, INTENT_IN};
2953 const char *name;
2954 gfc_typespec ts;
2955 gfc_clear_ts (&ts);
2957 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2958 they will be converted so that they fit into a C int. */
2959 ts.type = BT_INTEGER;
2960 ts.kind = gfc_c_int_kind;
2961 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2962 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2963 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2964 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2965 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2966 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2968 /* TO and FROM are guaranteed to have the same kind parameter. */
2969 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2970 c->ext.actual->expr->ts.kind);
2971 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2972 /* Mark as elemental subroutine as this does not happen automatically. */
2973 c->resolved_sym->attr.elemental = 1;
2975 /* Create a dummy formal arglist so the INTENTs are known later for purpose
2976 of creating temporaries. */
2977 c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS);
2981 void
2982 gfc_resolve_random_number (gfc_code *c)
2984 const char *name;
2985 int kind;
2987 kind = c->ext.actual->expr->ts.kind;
2988 if (c->ext.actual->expr->rank == 0)
2989 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2990 else
2991 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2993 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2997 void
2998 gfc_resolve_random_seed (gfc_code *c)
3000 const char *name;
3002 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
3003 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3007 void
3008 gfc_resolve_rename_sub (gfc_code *c)
3010 const char *name;
3011 int kind;
3013 if (c->ext.actual->next->next->expr != NULL)
3014 kind = c->ext.actual->next->next->expr->ts.kind;
3015 else
3016 kind = gfc_default_integer_kind;
3018 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
3019 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3023 void
3024 gfc_resolve_kill_sub (gfc_code *c)
3026 const char *name;
3027 int kind;
3029 if (c->ext.actual->next->next->expr != NULL)
3030 kind = c->ext.actual->next->next->expr->ts.kind;
3031 else
3032 kind = gfc_default_integer_kind;
3034 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
3035 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3039 void
3040 gfc_resolve_link_sub (gfc_code *c)
3042 const char *name;
3043 int kind;
3045 if (c->ext.actual->next->next->expr != NULL)
3046 kind = c->ext.actual->next->next->expr->ts.kind;
3047 else
3048 kind = gfc_default_integer_kind;
3050 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
3051 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3055 void
3056 gfc_resolve_symlnk_sub (gfc_code *c)
3058 const char *name;
3059 int kind;
3061 if (c->ext.actual->next->next->expr != NULL)
3062 kind = c->ext.actual->next->next->expr->ts.kind;
3063 else
3064 kind = gfc_default_integer_kind;
3066 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
3067 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3071 /* G77 compatibility subroutines dtime() and etime(). */
3073 void
3074 gfc_resolve_dtime_sub (gfc_code *c)
3076 const char *name;
3077 name = gfc_get_string (PREFIX ("dtime_sub"));
3078 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3081 void
3082 gfc_resolve_etime_sub (gfc_code *c)
3084 const char *name;
3085 name = gfc_get_string (PREFIX ("etime_sub"));
3086 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3090 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
3092 void
3093 gfc_resolve_itime (gfc_code *c)
3095 c->resolved_sym
3096 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
3097 gfc_default_integer_kind));
3100 void
3101 gfc_resolve_idate (gfc_code *c)
3103 c->resolved_sym
3104 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
3105 gfc_default_integer_kind));
3108 void
3109 gfc_resolve_ltime (gfc_code *c)
3111 c->resolved_sym
3112 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
3113 gfc_default_integer_kind));
3116 void
3117 gfc_resolve_gmtime (gfc_code *c)
3119 c->resolved_sym
3120 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
3121 gfc_default_integer_kind));
3125 /* G77 compatibility subroutine second(). */
3127 void
3128 gfc_resolve_second_sub (gfc_code *c)
3130 const char *name;
3131 name = gfc_get_string (PREFIX ("second_sub"));
3132 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3136 void
3137 gfc_resolve_sleep_sub (gfc_code *c)
3139 const char *name;
3140 int kind;
3142 if (c->ext.actual->expr != NULL)
3143 kind = c->ext.actual->expr->ts.kind;
3144 else
3145 kind = gfc_default_integer_kind;
3147 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
3148 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3152 /* G77 compatibility function srand(). */
3154 void
3155 gfc_resolve_srand (gfc_code *c)
3157 const char *name;
3158 name = gfc_get_string (PREFIX ("srand"));
3159 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3163 /* Resolve the getarg intrinsic subroutine. */
3165 void
3166 gfc_resolve_getarg (gfc_code *c)
3168 const char *name;
3170 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
3172 gfc_typespec ts;
3173 gfc_clear_ts (&ts);
3175 ts.type = BT_INTEGER;
3176 ts.kind = gfc_default_integer_kind;
3178 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3181 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
3182 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3186 /* Resolve the getcwd intrinsic subroutine. */
3188 void
3189 gfc_resolve_getcwd_sub (gfc_code *c)
3191 const char *name;
3192 int kind;
3194 if (c->ext.actual->next->expr != NULL)
3195 kind = c->ext.actual->next->expr->ts.kind;
3196 else
3197 kind = gfc_default_integer_kind;
3199 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
3200 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3204 /* Resolve the get_command intrinsic subroutine. */
3206 void
3207 gfc_resolve_get_command (gfc_code *c)
3209 const char *name;
3210 int kind;
3211 kind = gfc_default_integer_kind;
3212 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
3213 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3217 /* Resolve the get_command_argument intrinsic subroutine. */
3219 void
3220 gfc_resolve_get_command_argument (gfc_code *c)
3222 const char *name;
3223 int kind;
3224 kind = gfc_default_integer_kind;
3225 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
3226 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3230 /* Resolve the get_environment_variable intrinsic subroutine. */
3232 void
3233 gfc_resolve_get_environment_variable (gfc_code *code)
3235 const char *name;
3236 int kind;
3237 kind = gfc_default_integer_kind;
3238 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
3239 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3243 void
3244 gfc_resolve_signal_sub (gfc_code *c)
3246 const char *name;
3247 gfc_expr *number, *handler, *status;
3248 gfc_typespec ts;
3249 gfc_clear_ts (&ts);
3251 number = c->ext.actual->expr;
3252 handler = c->ext.actual->next->expr;
3253 status = c->ext.actual->next->next->expr;
3254 ts.type = BT_INTEGER;
3255 ts.kind = gfc_c_int_kind;
3257 /* handler can be either BT_INTEGER or BT_PROCEDURE */
3258 if (handler->ts.type == BT_INTEGER)
3260 if (handler->ts.kind != gfc_c_int_kind)
3261 gfc_convert_type (handler, &ts, 2);
3262 name = gfc_get_string (PREFIX ("signal_sub_int"));
3264 else
3265 name = gfc_get_string (PREFIX ("signal_sub"));
3267 if (number->ts.kind != gfc_c_int_kind)
3268 gfc_convert_type (number, &ts, 2);
3269 if (status != NULL && status->ts.kind != gfc_c_int_kind)
3270 gfc_convert_type (status, &ts, 2);
3272 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3276 /* Resolve the SYSTEM intrinsic subroutine. */
3278 void
3279 gfc_resolve_system_sub (gfc_code *c)
3281 const char *name;
3282 name = gfc_get_string (PREFIX ("system_sub"));
3283 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3287 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
3289 void
3290 gfc_resolve_system_clock (gfc_code *c)
3292 const char *name;
3293 int kind;
3295 if (c->ext.actual->expr != NULL)
3296 kind = c->ext.actual->expr->ts.kind;
3297 else if (c->ext.actual->next->expr != NULL)
3298 kind = c->ext.actual->next->expr->ts.kind;
3299 else if (c->ext.actual->next->next->expr != NULL)
3300 kind = c->ext.actual->next->next->expr->ts.kind;
3301 else
3302 kind = gfc_default_integer_kind;
3304 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
3305 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3309 /* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine. */
3310 void
3311 gfc_resolve_execute_command_line (gfc_code *c)
3313 const char *name;
3314 name = gfc_get_string (PREFIX ("execute_command_line_i%d"),
3315 gfc_default_integer_kind);
3316 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3320 /* Resolve the EXIT intrinsic subroutine. */
3322 void
3323 gfc_resolve_exit (gfc_code *c)
3325 const char *name;
3326 gfc_typespec ts;
3327 gfc_expr *n;
3328 gfc_clear_ts (&ts);
3330 /* The STATUS argument has to be of default kind. If it is not,
3331 we convert it. */
3332 ts.type = BT_INTEGER;
3333 ts.kind = gfc_default_integer_kind;
3334 n = c->ext.actual->expr;
3335 if (n != NULL && n->ts.kind != ts.kind)
3336 gfc_convert_type (n, &ts, 2);
3338 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
3339 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3343 /* Resolve the FLUSH intrinsic subroutine. */
3345 void
3346 gfc_resolve_flush (gfc_code *c)
3348 const char *name;
3349 gfc_typespec ts;
3350 gfc_expr *n;
3351 gfc_clear_ts (&ts);
3353 ts.type = BT_INTEGER;
3354 ts.kind = gfc_default_integer_kind;
3355 n = c->ext.actual->expr;
3356 if (n != NULL && n->ts.kind != ts.kind)
3357 gfc_convert_type (n, &ts, 2);
3359 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
3360 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3364 void
3365 gfc_resolve_free (gfc_code *c)
3367 gfc_typespec ts;
3368 gfc_expr *n;
3369 gfc_clear_ts (&ts);
3371 ts.type = BT_INTEGER;
3372 ts.kind = gfc_index_integer_kind;
3373 n = c->ext.actual->expr;
3374 if (n->ts.kind != ts.kind)
3375 gfc_convert_type (n, &ts, 2);
3377 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
3381 void
3382 gfc_resolve_ctime_sub (gfc_code *c)
3384 gfc_typespec ts;
3385 gfc_clear_ts (&ts);
3387 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3388 if (c->ext.actual->expr->ts.kind != 8)
3390 ts.type = BT_INTEGER;
3391 ts.kind = 8;
3392 ts.u.derived = NULL;
3393 ts.u.cl = NULL;
3394 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3397 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3401 void
3402 gfc_resolve_fdate_sub (gfc_code *c)
3404 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3408 void
3409 gfc_resolve_gerror (gfc_code *c)
3411 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3415 void
3416 gfc_resolve_getlog (gfc_code *c)
3418 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3422 void
3423 gfc_resolve_hostnm_sub (gfc_code *c)
3425 const char *name;
3426 int kind;
3428 if (c->ext.actual->next->expr != NULL)
3429 kind = c->ext.actual->next->expr->ts.kind;
3430 else
3431 kind = gfc_default_integer_kind;
3433 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3434 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3438 void
3439 gfc_resolve_perror (gfc_code *c)
3441 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3444 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3446 void
3447 gfc_resolve_stat_sub (gfc_code *c)
3449 const char *name;
3450 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3451 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3455 void
3456 gfc_resolve_lstat_sub (gfc_code *c)
3458 const char *name;
3459 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3460 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3464 void
3465 gfc_resolve_fstat_sub (gfc_code *c)
3467 const char *name;
3468 gfc_expr *u;
3469 gfc_typespec *ts;
3471 u = c->ext.actual->expr;
3472 ts = &c->ext.actual->next->expr->ts;
3473 if (u->ts.kind != ts->kind)
3474 gfc_convert_type (u, ts, 2);
3475 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3476 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3480 void
3481 gfc_resolve_fgetc_sub (gfc_code *c)
3483 const char *name;
3484 gfc_typespec ts;
3485 gfc_expr *u, *st;
3486 gfc_clear_ts (&ts);
3488 u = c->ext.actual->expr;
3489 st = c->ext.actual->next->next->expr;
3491 if (u->ts.kind != gfc_c_int_kind)
3493 ts.type = BT_INTEGER;
3494 ts.kind = gfc_c_int_kind;
3495 ts.u.derived = NULL;
3496 ts.u.cl = NULL;
3497 gfc_convert_type (u, &ts, 2);
3500 if (st != NULL)
3501 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3502 else
3503 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3505 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3509 void
3510 gfc_resolve_fget_sub (gfc_code *c)
3512 const char *name;
3513 gfc_expr *st;
3515 st = c->ext.actual->next->expr;
3516 if (st != NULL)
3517 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3518 else
3519 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3521 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3525 void
3526 gfc_resolve_fputc_sub (gfc_code *c)
3528 const char *name;
3529 gfc_typespec ts;
3530 gfc_expr *u, *st;
3531 gfc_clear_ts (&ts);
3533 u = c->ext.actual->expr;
3534 st = c->ext.actual->next->next->expr;
3536 if (u->ts.kind != gfc_c_int_kind)
3538 ts.type = BT_INTEGER;
3539 ts.kind = gfc_c_int_kind;
3540 ts.u.derived = NULL;
3541 ts.u.cl = NULL;
3542 gfc_convert_type (u, &ts, 2);
3545 if (st != NULL)
3546 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3547 else
3548 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3550 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3554 void
3555 gfc_resolve_fput_sub (gfc_code *c)
3557 const char *name;
3558 gfc_expr *st;
3560 st = c->ext.actual->next->expr;
3561 if (st != NULL)
3562 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3563 else
3564 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3566 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3570 void
3571 gfc_resolve_fseek_sub (gfc_code *c)
3573 gfc_expr *unit;
3574 gfc_expr *offset;
3575 gfc_expr *whence;
3576 gfc_typespec ts;
3577 gfc_clear_ts (&ts);
3579 unit = c->ext.actual->expr;
3580 offset = c->ext.actual->next->expr;
3581 whence = c->ext.actual->next->next->expr;
3583 if (unit->ts.kind != gfc_c_int_kind)
3585 ts.type = BT_INTEGER;
3586 ts.kind = gfc_c_int_kind;
3587 ts.u.derived = NULL;
3588 ts.u.cl = NULL;
3589 gfc_convert_type (unit, &ts, 2);
3592 if (offset->ts.kind != gfc_intio_kind)
3594 ts.type = BT_INTEGER;
3595 ts.kind = gfc_intio_kind;
3596 ts.u.derived = NULL;
3597 ts.u.cl = NULL;
3598 gfc_convert_type (offset, &ts, 2);
3601 if (whence->ts.kind != gfc_c_int_kind)
3603 ts.type = BT_INTEGER;
3604 ts.kind = gfc_c_int_kind;
3605 ts.u.derived = NULL;
3606 ts.u.cl = NULL;
3607 gfc_convert_type (whence, &ts, 2);
3610 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3613 void
3614 gfc_resolve_ftell_sub (gfc_code *c)
3616 const char *name;
3617 gfc_expr *unit;
3618 gfc_expr *offset;
3619 gfc_typespec ts;
3620 gfc_clear_ts (&ts);
3622 unit = c->ext.actual->expr;
3623 offset = c->ext.actual->next->expr;
3625 if (unit->ts.kind != gfc_c_int_kind)
3627 ts.type = BT_INTEGER;
3628 ts.kind = gfc_c_int_kind;
3629 ts.u.derived = NULL;
3630 ts.u.cl = NULL;
3631 gfc_convert_type (unit, &ts, 2);
3634 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3635 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3639 void
3640 gfc_resolve_ttynam_sub (gfc_code *c)
3642 gfc_typespec ts;
3643 gfc_clear_ts (&ts);
3645 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3647 ts.type = BT_INTEGER;
3648 ts.kind = gfc_c_int_kind;
3649 ts.u.derived = NULL;
3650 ts.u.cl = NULL;
3651 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3654 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3658 /* Resolve the UMASK intrinsic subroutine. */
3660 void
3661 gfc_resolve_umask_sub (gfc_code *c)
3663 const char *name;
3664 int kind;
3666 if (c->ext.actual->next->expr != NULL)
3667 kind = c->ext.actual->next->expr->ts.kind;
3668 else
3669 kind = gfc_default_integer_kind;
3671 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3672 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3675 /* Resolve the UNLINK intrinsic subroutine. */
3677 void
3678 gfc_resolve_unlink_sub (gfc_code *c)
3680 const char *name;
3681 int kind;
3683 if (c->ext.actual->next->expr != NULL)
3684 kind = c->ext.actual->next->expr->ts.kind;
3685 else
3686 kind = gfc_default_integer_kind;
3688 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3689 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);