Daily bump.
[official-gcc.git] / gcc / fortran / iresolve.c
blob6fa0994cf2322169b70c773166a4c4bd202c4ee1
1 /* Intrinsic function resolution.
2 Copyright (C) 2000-2015 Free Software Foundation, Inc.
3 Contributed by Andy Vaught & Katherine Holcomb
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
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 "hash-set.h"
33 #include "machmode.h"
34 #include "vec.h"
35 #include "double-int.h"
36 #include "input.h"
37 #include "alias.h"
38 #include "symtab.h"
39 #include "options.h"
40 #include "wide-int.h"
41 #include "inchash.h"
42 #include "tree.h"
43 #include "stringpool.h"
44 #include "gfortran.h"
45 #include "intrinsic.h"
46 #include "constructor.h"
47 #include "arith.h"
49 /* Given printf-like arguments, return a stable version of the result string.
51 We already have a working, optimized string hashing table in the form of
52 the identifier table. Reusing this table is likely not to be wasted,
53 since if the function name makes it to the gimple output of the frontend,
54 we'll have to create the identifier anyway. */
56 const char *
57 gfc_get_string (const char *format, ...)
59 char temp_name[128];
60 va_list ap;
61 tree ident;
63 va_start (ap, format);
64 vsnprintf (temp_name, sizeof (temp_name), format, ap);
65 va_end (ap);
66 temp_name[sizeof (temp_name) - 1] = 0;
68 ident = get_identifier (temp_name);
69 return IDENTIFIER_POINTER (ident);
72 /* MERGE and SPREAD need to have source charlen's present for passing
73 to the result expression. */
74 static void
75 check_charlen_present (gfc_expr *source)
77 if (source->ts.u.cl == NULL)
78 source->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
80 if (source->expr_type == EXPR_CONSTANT)
82 source->ts.u.cl->length
83 = gfc_get_int_expr (gfc_default_integer_kind, NULL,
84 source->value.character.length);
85 source->rank = 0;
87 else if (source->expr_type == EXPR_ARRAY)
89 gfc_constructor *c = gfc_constructor_first (source->value.constructor);
90 source->ts.u.cl->length
91 = gfc_get_int_expr (gfc_default_integer_kind, NULL,
92 c->expr->value.character.length);
96 /* Helper function for resolving the "mask" argument. */
98 static void
99 resolve_mask_arg (gfc_expr *mask)
102 gfc_typespec ts;
103 gfc_clear_ts (&ts);
105 if (mask->rank == 0)
107 /* For the scalar case, coerce the mask to kind=4 unconditionally
108 (because this is the only kind we have a library function
109 for). */
111 if (mask->ts.kind != 4)
113 ts.type = BT_LOGICAL;
114 ts.kind = 4;
115 gfc_convert_type (mask, &ts, 2);
118 else
120 /* In the library, we access the mask with a GFC_LOGICAL_1
121 argument. No need to waste memory if we are about to create
122 a temporary array. */
123 if (mask->expr_type == EXPR_OP && mask->ts.kind != 1)
125 ts.type = BT_LOGICAL;
126 ts.kind = 1;
127 gfc_convert_type_warn (mask, &ts, 2, 0);
133 static void
134 resolve_bound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind,
135 const char *name, bool coarray)
137 f->ts.type = BT_INTEGER;
138 if (kind)
139 f->ts.kind = mpz_get_si (kind->value.integer);
140 else
141 f->ts.kind = gfc_default_integer_kind;
143 if (dim == NULL)
145 f->rank = 1;
146 if (array->rank != -1)
148 f->shape = gfc_get_shape (1);
149 mpz_init_set_ui (f->shape[0], coarray ? gfc_get_corank (array)
150 : array->rank);
154 f->value.function.name = gfc_get_string (name);
158 static void
159 resolve_transformational (const char *name, gfc_expr *f, gfc_expr *array,
160 gfc_expr *dim, gfc_expr *mask)
162 const char *prefix;
164 f->ts = array->ts;
166 if (mask)
168 if (mask->rank == 0)
169 prefix = "s";
170 else
171 prefix = "m";
173 resolve_mask_arg (mask);
175 else
176 prefix = "";
178 if (dim != NULL)
180 f->rank = array->rank - 1;
181 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
182 gfc_resolve_dim_arg (dim);
185 f->value.function.name
186 = gfc_get_string (PREFIX ("%s%s_%c%d"), prefix, name,
187 gfc_type_letter (array->ts.type), array->ts.kind);
191 /********************** Resolution functions **********************/
194 void
195 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
197 f->ts = a->ts;
198 if (f->ts.type == BT_COMPLEX)
199 f->ts.type = BT_REAL;
201 f->value.function.name
202 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
206 void
207 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
208 gfc_expr *mode ATTRIBUTE_UNUSED)
210 f->ts.type = BT_INTEGER;
211 f->ts.kind = gfc_c_int_kind;
212 f->value.function.name = PREFIX ("access_func");
216 void
217 gfc_resolve_adjustl (gfc_expr *f, gfc_expr *string)
219 f->ts.type = BT_CHARACTER;
220 f->ts.kind = string->ts.kind;
221 f->value.function.name = gfc_get_string ("__adjustl_s%d", f->ts.kind);
225 void
226 gfc_resolve_adjustr (gfc_expr *f, gfc_expr *string)
228 f->ts.type = BT_CHARACTER;
229 f->ts.kind = string->ts.kind;
230 f->value.function.name = gfc_get_string ("__adjustr_s%d", f->ts.kind);
234 static void
235 gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind,
236 const char *name)
238 f->ts.type = BT_CHARACTER;
239 f->ts.kind = (kind == NULL)
240 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
241 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
242 f->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
244 f->value.function.name = gfc_get_string (name, f->ts.kind,
245 gfc_type_letter (x->ts.type),
246 x->ts.kind);
250 void
251 gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
253 gfc_resolve_char_achar (f, x, kind, "__achar_%d_%c%d");
257 void
258 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
260 f->ts = x->ts;
261 f->value.function.name
262 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
266 void
267 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
269 f->ts = x->ts;
270 f->value.function.name
271 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
272 x->ts.kind);
276 void
277 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
279 f->ts.type = BT_REAL;
280 f->ts.kind = x->ts.kind;
281 f->value.function.name
282 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
283 x->ts.kind);
287 void
288 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
290 f->ts.type = i->ts.type;
291 f->ts.kind = gfc_kind_max (i, j);
293 if (i->ts.kind != j->ts.kind)
295 if (i->ts.kind == gfc_kind_max (i, j))
296 gfc_convert_type (j, &i->ts, 2);
297 else
298 gfc_convert_type (i, &j->ts, 2);
301 f->value.function.name
302 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
306 void
307 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
309 gfc_typespec ts;
310 gfc_clear_ts (&ts);
312 f->ts.type = a->ts.type;
313 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
315 if (a->ts.kind != f->ts.kind)
317 ts.type = f->ts.type;
318 ts.kind = f->ts.kind;
319 gfc_convert_type (a, &ts, 2);
321 /* The resolved name is only used for specific intrinsics where
322 the return kind is the same as the arg kind. */
323 f->value.function.name
324 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
328 void
329 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
331 gfc_resolve_aint (f, a, NULL);
335 void
336 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
338 f->ts = mask->ts;
340 if (dim != NULL)
342 gfc_resolve_dim_arg (dim);
343 f->rank = mask->rank - 1;
344 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
347 f->value.function.name
348 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
349 mask->ts.kind);
353 void
354 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
356 gfc_typespec ts;
357 gfc_clear_ts (&ts);
359 f->ts.type = a->ts.type;
360 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
362 if (a->ts.kind != f->ts.kind)
364 ts.type = f->ts.type;
365 ts.kind = f->ts.kind;
366 gfc_convert_type (a, &ts, 2);
369 /* The resolved name is only used for specific intrinsics where
370 the return kind is the same as the arg kind. */
371 f->value.function.name
372 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
373 a->ts.kind);
377 void
378 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
380 gfc_resolve_anint (f, a, NULL);
384 void
385 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
387 f->ts = mask->ts;
389 if (dim != NULL)
391 gfc_resolve_dim_arg (dim);
392 f->rank = mask->rank - 1;
393 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
396 f->value.function.name
397 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
398 mask->ts.kind);
402 void
403 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
405 f->ts = x->ts;
406 f->value.function.name
407 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
410 void
411 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
413 f->ts = x->ts;
414 f->value.function.name
415 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
416 x->ts.kind);
419 void
420 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
422 f->ts = x->ts;
423 f->value.function.name
424 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
427 void
428 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
430 f->ts = x->ts;
431 f->value.function.name
432 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
433 x->ts.kind);
436 void
437 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
439 f->ts = x->ts;
440 f->value.function.name
441 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
442 x->ts.kind);
446 /* Resolve the BESYN and BESJN intrinsics. */
448 void
449 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
451 gfc_typespec ts;
452 gfc_clear_ts (&ts);
454 f->ts = x->ts;
455 if (n->ts.kind != gfc_c_int_kind)
457 ts.type = BT_INTEGER;
458 ts.kind = gfc_c_int_kind;
459 gfc_convert_type (n, &ts, 2);
461 f->value.function.name = gfc_get_string ("<intrinsic>");
465 void
466 gfc_resolve_bessel_n2 (gfc_expr *f, gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
468 gfc_typespec ts;
469 gfc_clear_ts (&ts);
471 f->ts = x->ts;
472 f->rank = 1;
473 if (n1->expr_type == EXPR_CONSTANT && n2->expr_type == EXPR_CONSTANT)
475 f->shape = gfc_get_shape (1);
476 mpz_init (f->shape[0]);
477 mpz_sub (f->shape[0], n2->value.integer, n1->value.integer);
478 mpz_add_ui (f->shape[0], f->shape[0], 1);
481 if (n1->ts.kind != gfc_c_int_kind)
483 ts.type = BT_INTEGER;
484 ts.kind = gfc_c_int_kind;
485 gfc_convert_type (n1, &ts, 2);
488 if (n2->ts.kind != gfc_c_int_kind)
490 ts.type = BT_INTEGER;
491 ts.kind = gfc_c_int_kind;
492 gfc_convert_type (n2, &ts, 2);
495 if (f->value.function.isym->id == GFC_ISYM_JN2)
496 f->value.function.name = gfc_get_string (PREFIX ("bessel_jn_r%d"),
497 f->ts.kind);
498 else
499 f->value.function.name = gfc_get_string (PREFIX ("bessel_yn_r%d"),
500 f->ts.kind);
504 void
505 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
507 f->ts.type = BT_LOGICAL;
508 f->ts.kind = gfc_default_logical_kind;
509 f->value.function.name
510 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
514 void
515 gfc_resolve_c_loc (gfc_expr *f, gfc_expr *x ATTRIBUTE_UNUSED)
517 f->ts = f->value.function.isym->ts;
521 void
522 gfc_resolve_c_funloc (gfc_expr *f, gfc_expr *x ATTRIBUTE_UNUSED)
524 f->ts = f->value.function.isym->ts;
528 void
529 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
531 f->ts.type = BT_INTEGER;
532 f->ts.kind = (kind == NULL)
533 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
534 f->value.function.name
535 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
536 gfc_type_letter (a->ts.type), a->ts.kind);
540 void
541 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
543 gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d");
547 void
548 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
550 f->ts.type = BT_INTEGER;
551 f->ts.kind = gfc_default_integer_kind;
552 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
556 void
557 gfc_resolve_chdir_sub (gfc_code *c)
559 const char *name;
560 int kind;
562 if (c->ext.actual->next->expr != NULL)
563 kind = c->ext.actual->next->expr->ts.kind;
564 else
565 kind = gfc_default_integer_kind;
567 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
568 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
572 void
573 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
574 gfc_expr *mode ATTRIBUTE_UNUSED)
576 f->ts.type = BT_INTEGER;
577 f->ts.kind = gfc_c_int_kind;
578 f->value.function.name = PREFIX ("chmod_func");
582 void
583 gfc_resolve_chmod_sub (gfc_code *c)
585 const char *name;
586 int kind;
588 if (c->ext.actual->next->next->expr != NULL)
589 kind = c->ext.actual->next->next->expr->ts.kind;
590 else
591 kind = gfc_default_integer_kind;
593 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
594 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
598 void
599 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
601 f->ts.type = BT_COMPLEX;
602 f->ts.kind = (kind == NULL)
603 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
605 if (y == NULL)
606 f->value.function.name
607 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
608 gfc_type_letter (x->ts.type), x->ts.kind);
609 else
610 f->value.function.name
611 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
612 gfc_type_letter (x->ts.type), x->ts.kind,
613 gfc_type_letter (y->ts.type), y->ts.kind);
617 void
618 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
620 gfc_resolve_cmplx (f, x, y, gfc_get_int_expr (gfc_default_integer_kind, NULL,
621 gfc_default_double_kind));
625 void
626 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
628 int kind;
630 if (x->ts.type == BT_INTEGER)
632 if (y->ts.type == BT_INTEGER)
633 kind = gfc_default_real_kind;
634 else
635 kind = y->ts.kind;
637 else
639 if (y->ts.type == BT_REAL)
640 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
641 else
642 kind = x->ts.kind;
645 f->ts.type = BT_COMPLEX;
646 f->ts.kind = kind;
647 f->value.function.name
648 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
649 gfc_type_letter (x->ts.type), x->ts.kind,
650 gfc_type_letter (y->ts.type), y->ts.kind);
654 void
655 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
657 f->ts = x->ts;
658 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
662 void
663 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
665 f->ts = x->ts;
666 f->value.function.name
667 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
671 void
672 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
674 f->ts = x->ts;
675 f->value.function.name
676 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
680 void
681 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
683 f->ts.type = BT_INTEGER;
684 if (kind)
685 f->ts.kind = mpz_get_si (kind->value.integer);
686 else
687 f->ts.kind = gfc_default_integer_kind;
689 if (dim != NULL)
691 f->rank = mask->rank - 1;
692 gfc_resolve_dim_arg (dim);
693 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
696 resolve_mask_arg (mask);
698 f->value.function.name
699 = gfc_get_string (PREFIX ("count_%d_%c"), f->ts.kind,
700 gfc_type_letter (mask->ts.type));
704 void
705 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
706 gfc_expr *dim)
708 int n, m;
710 if (array->ts.type == BT_CHARACTER && array->ref)
711 gfc_resolve_substring_charlen (array);
713 f->ts = array->ts;
714 f->rank = array->rank;
715 f->shape = gfc_copy_shape (array->shape, array->rank);
717 if (shift->rank > 0)
718 n = 1;
719 else
720 n = 0;
722 /* If dim kind is greater than default integer we need to use the larger. */
723 m = gfc_default_integer_kind;
724 if (dim != NULL)
725 m = m < dim->ts.kind ? dim->ts.kind : m;
727 /* Convert shift to at least m, so we don't need
728 kind=1 and kind=2 versions of the library functions. */
729 if (shift->ts.kind < m)
731 gfc_typespec ts;
732 gfc_clear_ts (&ts);
733 ts.type = BT_INTEGER;
734 ts.kind = m;
735 gfc_convert_type_warn (shift, &ts, 2, 0);
738 if (dim != NULL)
740 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
741 && dim->symtree->n.sym->attr.optional)
743 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
744 dim->representation.length = shift->ts.kind;
746 else
748 gfc_resolve_dim_arg (dim);
749 /* Convert dim to shift's kind to reduce variations. */
750 if (dim->ts.kind != shift->ts.kind)
751 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
755 if (array->ts.type == BT_CHARACTER)
757 if (array->ts.kind == gfc_default_character_kind)
758 f->value.function.name
759 = gfc_get_string (PREFIX ("cshift%d_%d_char"), n, shift->ts.kind);
760 else
761 f->value.function.name
762 = gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n, shift->ts.kind,
763 array->ts.kind);
765 else
766 f->value.function.name
767 = gfc_get_string (PREFIX ("cshift%d_%d"), n, shift->ts.kind);
771 void
772 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
774 gfc_typespec ts;
775 gfc_clear_ts (&ts);
777 f->ts.type = BT_CHARACTER;
778 f->ts.kind = gfc_default_character_kind;
780 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
781 if (time->ts.kind != 8)
783 ts.type = BT_INTEGER;
784 ts.kind = 8;
785 ts.u.derived = NULL;
786 ts.u.cl = NULL;
787 gfc_convert_type (time, &ts, 2);
790 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
794 void
795 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
797 f->ts.type = BT_REAL;
798 f->ts.kind = gfc_default_double_kind;
799 f->value.function.name
800 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
804 void
805 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
807 f->ts.type = a->ts.type;
808 if (p != NULL)
809 f->ts.kind = gfc_kind_max (a,p);
810 else
811 f->ts.kind = a->ts.kind;
813 if (p != NULL && a->ts.kind != p->ts.kind)
815 if (a->ts.kind == gfc_kind_max (a,p))
816 gfc_convert_type (p, &a->ts, 2);
817 else
818 gfc_convert_type (a, &p->ts, 2);
821 f->value.function.name
822 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
826 void
827 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
829 gfc_expr temp;
831 temp.expr_type = EXPR_OP;
832 gfc_clear_ts (&temp.ts);
833 temp.value.op.op = INTRINSIC_NONE;
834 temp.value.op.op1 = a;
835 temp.value.op.op2 = b;
836 gfc_type_convert_binary (&temp, 1);
837 f->ts = temp.ts;
838 f->value.function.name
839 = gfc_get_string (PREFIX ("dot_product_%c%d"),
840 gfc_type_letter (f->ts.type), f->ts.kind);
844 void
845 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
846 gfc_expr *b ATTRIBUTE_UNUSED)
848 f->ts.kind = gfc_default_double_kind;
849 f->ts.type = BT_REAL;
850 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
854 void
855 gfc_resolve_dshift (gfc_expr *f, gfc_expr *i, gfc_expr *j ATTRIBUTE_UNUSED,
856 gfc_expr *shift ATTRIBUTE_UNUSED)
858 f->ts = i->ts;
859 if (f->value.function.isym->id == GFC_ISYM_DSHIFTL)
860 f->value.function.name = gfc_get_string ("dshiftl_i%d", f->ts.kind);
861 else if (f->value.function.isym->id == GFC_ISYM_DSHIFTR)
862 f->value.function.name = gfc_get_string ("dshiftr_i%d", f->ts.kind);
863 else
864 gcc_unreachable ();
868 void
869 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
870 gfc_expr *boundary, gfc_expr *dim)
872 int n, m;
874 if (array->ts.type == BT_CHARACTER && array->ref)
875 gfc_resolve_substring_charlen (array);
877 f->ts = array->ts;
878 f->rank = array->rank;
879 f->shape = gfc_copy_shape (array->shape, array->rank);
881 n = 0;
882 if (shift->rank > 0)
883 n = n | 1;
884 if (boundary && boundary->rank > 0)
885 n = n | 2;
887 /* If dim kind is greater than default integer we need to use the larger. */
888 m = gfc_default_integer_kind;
889 if (dim != NULL)
890 m = m < dim->ts.kind ? dim->ts.kind : m;
892 /* Convert shift to at least m, so we don't need
893 kind=1 and kind=2 versions of the library functions. */
894 if (shift->ts.kind < m)
896 gfc_typespec ts;
897 gfc_clear_ts (&ts);
898 ts.type = BT_INTEGER;
899 ts.kind = m;
900 gfc_convert_type_warn (shift, &ts, 2, 0);
903 if (dim != NULL)
905 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
906 && dim->symtree->n.sym->attr.optional)
908 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
909 dim->representation.length = shift->ts.kind;
911 else
913 gfc_resolve_dim_arg (dim);
914 /* Convert dim to shift's kind to reduce variations. */
915 if (dim->ts.kind != shift->ts.kind)
916 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
920 if (array->ts.type == BT_CHARACTER)
922 if (array->ts.kind == gfc_default_character_kind)
923 f->value.function.name
924 = gfc_get_string (PREFIX ("eoshift%d_%d_char"), n, shift->ts.kind);
925 else
926 f->value.function.name
927 = gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n, shift->ts.kind,
928 array->ts.kind);
930 else
931 f->value.function.name
932 = gfc_get_string (PREFIX ("eoshift%d_%d"), n, shift->ts.kind);
936 void
937 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
939 f->ts = x->ts;
940 f->value.function.name
941 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
945 void
946 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
948 f->ts.type = BT_INTEGER;
949 f->ts.kind = gfc_default_integer_kind;
950 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
954 /* Resolve the EXTENDS_TYPE_OF intrinsic function. */
956 void
957 gfc_resolve_extends_type_of (gfc_expr *f, gfc_expr *a, gfc_expr *mo)
959 gfc_symbol *vtab;
960 gfc_symtree *st;
962 /* Prevent double resolution. */
963 if (f->ts.type == BT_LOGICAL)
964 return;
966 /* Replace the first argument with the corresponding vtab. */
967 if (a->ts.type == BT_CLASS)
968 gfc_add_vptr_component (a);
969 else if (a->ts.type == BT_DERIVED)
971 vtab = gfc_find_derived_vtab (a->ts.u.derived);
972 /* Clear the old expr. */
973 gfc_free_ref_list (a->ref);
974 memset (a, '\0', sizeof (gfc_expr));
975 /* Construct a new one. */
976 a->expr_type = EXPR_VARIABLE;
977 st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
978 a->symtree = st;
979 a->ts = vtab->ts;
982 /* Replace the second argument with the corresponding vtab. */
983 if (mo->ts.type == BT_CLASS)
984 gfc_add_vptr_component (mo);
985 else if (mo->ts.type == BT_DERIVED)
987 vtab = gfc_find_derived_vtab (mo->ts.u.derived);
988 /* Clear the old expr. */
989 gfc_free_ref_list (mo->ref);
990 memset (mo, '\0', sizeof (gfc_expr));
991 /* Construct a new one. */
992 mo->expr_type = EXPR_VARIABLE;
993 st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
994 mo->symtree = st;
995 mo->ts = vtab->ts;
998 f->ts.type = BT_LOGICAL;
999 f->ts.kind = 4;
1001 f->value.function.isym->formal->ts = a->ts;
1002 f->value.function.isym->formal->next->ts = mo->ts;
1004 /* Call library function. */
1005 f->value.function.name = gfc_get_string (PREFIX ("is_extension_of"));
1009 void
1010 gfc_resolve_fdate (gfc_expr *f)
1012 f->ts.type = BT_CHARACTER;
1013 f->ts.kind = gfc_default_character_kind;
1014 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
1018 void
1019 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1021 f->ts.type = BT_INTEGER;
1022 f->ts.kind = (kind == NULL)
1023 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1024 f->value.function.name
1025 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
1026 gfc_type_letter (a->ts.type), a->ts.kind);
1030 void
1031 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
1033 f->ts.type = BT_INTEGER;
1034 f->ts.kind = gfc_default_integer_kind;
1035 if (n->ts.kind != f->ts.kind)
1036 gfc_convert_type (n, &f->ts, 2);
1037 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
1041 void
1042 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
1044 f->ts = x->ts;
1045 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
1049 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
1051 void
1052 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
1054 f->ts = x->ts;
1055 f->value.function.name = gfc_get_string ("<intrinsic>");
1059 void
1060 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
1062 f->ts = x->ts;
1063 f->value.function.name
1064 = gfc_get_string ("__tgamma_%d", x->ts.kind);
1068 void
1069 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
1071 f->ts.type = BT_INTEGER;
1072 f->ts.kind = 4;
1073 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
1077 void
1078 gfc_resolve_getgid (gfc_expr *f)
1080 f->ts.type = BT_INTEGER;
1081 f->ts.kind = 4;
1082 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
1086 void
1087 gfc_resolve_getpid (gfc_expr *f)
1089 f->ts.type = BT_INTEGER;
1090 f->ts.kind = 4;
1091 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
1095 void
1096 gfc_resolve_getuid (gfc_expr *f)
1098 f->ts.type = BT_INTEGER;
1099 f->ts.kind = 4;
1100 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
1104 void
1105 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
1107 f->ts.type = BT_INTEGER;
1108 f->ts.kind = 4;
1109 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
1113 void
1114 gfc_resolve_hypot (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
1116 f->ts = x->ts;
1117 f->value.function.name = gfc_get_string ("__hypot_r%d", x->ts.kind);
1121 void
1122 gfc_resolve_iall (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1124 resolve_transformational ("iall", f, array, dim, mask);
1128 void
1129 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1131 /* If the kind of i and j are different, then g77 cross-promoted the
1132 kinds to the largest value. The Fortran 95 standard requires the
1133 kinds to match. */
1134 if (i->ts.kind != j->ts.kind)
1136 if (i->ts.kind == gfc_kind_max (i, j))
1137 gfc_convert_type (j, &i->ts, 2);
1138 else
1139 gfc_convert_type (i, &j->ts, 2);
1142 f->ts = i->ts;
1143 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
1147 void
1148 gfc_resolve_iany (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1150 resolve_transformational ("iany", f, array, dim, mask);
1154 void
1155 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1157 f->ts = i->ts;
1158 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
1162 void
1163 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
1164 gfc_expr *len ATTRIBUTE_UNUSED)
1166 f->ts = i->ts;
1167 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
1171 void
1172 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1174 f->ts = i->ts;
1175 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
1179 void
1180 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1182 f->ts.type = BT_INTEGER;
1183 if (kind)
1184 f->ts.kind = mpz_get_si (kind->value.integer);
1185 else
1186 f->ts.kind = gfc_default_integer_kind;
1187 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1191 void
1192 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1194 f->ts.type = BT_INTEGER;
1195 if (kind)
1196 f->ts.kind = mpz_get_si (kind->value.integer);
1197 else
1198 f->ts.kind = gfc_default_integer_kind;
1199 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1203 void
1204 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
1206 gfc_resolve_nint (f, a, NULL);
1210 void
1211 gfc_resolve_ierrno (gfc_expr *f)
1213 f->ts.type = BT_INTEGER;
1214 f->ts.kind = gfc_default_integer_kind;
1215 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
1219 void
1220 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1222 /* If the kind of i and j are different, then g77 cross-promoted the
1223 kinds to the largest value. The Fortran 95 standard requires the
1224 kinds to match. */
1225 if (i->ts.kind != j->ts.kind)
1227 if (i->ts.kind == gfc_kind_max (i, j))
1228 gfc_convert_type (j, &i->ts, 2);
1229 else
1230 gfc_convert_type (i, &j->ts, 2);
1233 f->ts = i->ts;
1234 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
1238 void
1239 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1241 /* If the kind of i and j are different, then g77 cross-promoted the
1242 kinds to the largest value. The Fortran 95 standard requires the
1243 kinds to match. */
1244 if (i->ts.kind != j->ts.kind)
1246 if (i->ts.kind == gfc_kind_max (i, j))
1247 gfc_convert_type (j, &i->ts, 2);
1248 else
1249 gfc_convert_type (i, &j->ts, 2);
1252 f->ts = i->ts;
1253 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
1257 void
1258 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
1259 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
1260 gfc_expr *kind)
1262 gfc_typespec ts;
1263 gfc_clear_ts (&ts);
1265 f->ts.type = BT_INTEGER;
1266 if (kind)
1267 f->ts.kind = mpz_get_si (kind->value.integer);
1268 else
1269 f->ts.kind = gfc_default_integer_kind;
1271 if (back && back->ts.kind != gfc_default_integer_kind)
1273 ts.type = BT_LOGICAL;
1274 ts.kind = gfc_default_integer_kind;
1275 ts.u.derived = NULL;
1276 ts.u.cl = NULL;
1277 gfc_convert_type (back, &ts, 2);
1280 f->value.function.name
1281 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
1285 void
1286 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1288 f->ts.type = BT_INTEGER;
1289 f->ts.kind = (kind == NULL)
1290 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1291 f->value.function.name
1292 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1293 gfc_type_letter (a->ts.type), a->ts.kind);
1297 void
1298 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1300 f->ts.type = BT_INTEGER;
1301 f->ts.kind = 2;
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_int8 (gfc_expr *f, gfc_expr *a)
1311 f->ts.type = BT_INTEGER;
1312 f->ts.kind = 8;
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_long (gfc_expr *f, gfc_expr *a)
1322 f->ts.type = BT_INTEGER;
1323 f->ts.kind = 4;
1324 f->value.function.name
1325 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1326 gfc_type_letter (a->ts.type), a->ts.kind);
1330 void
1331 gfc_resolve_iparity (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1333 resolve_transformational ("iparity", f, array, dim, mask);
1337 void
1338 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1340 gfc_typespec ts;
1341 gfc_clear_ts (&ts);
1343 f->ts.type = BT_LOGICAL;
1344 f->ts.kind = gfc_default_integer_kind;
1345 if (u->ts.kind != gfc_c_int_kind)
1347 ts.type = BT_INTEGER;
1348 ts.kind = gfc_c_int_kind;
1349 ts.u.derived = NULL;
1350 ts.u.cl = NULL;
1351 gfc_convert_type (u, &ts, 2);
1354 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1358 void
1359 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1361 f->ts = i->ts;
1362 f->value.function.name
1363 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1367 void
1368 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1370 f->ts = i->ts;
1371 f->value.function.name
1372 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1376 void
1377 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1379 f->ts = i->ts;
1380 f->value.function.name
1381 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1385 void
1386 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1388 int s_kind;
1390 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1392 f->ts = i->ts;
1393 f->value.function.name
1394 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1398 void
1399 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1400 gfc_expr *s ATTRIBUTE_UNUSED)
1402 f->ts.type = BT_INTEGER;
1403 f->ts.kind = gfc_default_integer_kind;
1404 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1408 void
1409 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1411 resolve_bound (f, array, dim, kind, "__lbound", false);
1415 void
1416 gfc_resolve_lcobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1418 resolve_bound (f, array, dim, kind, "__lcobound", true);
1422 void
1423 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1425 f->ts.type = BT_INTEGER;
1426 if (kind)
1427 f->ts.kind = mpz_get_si (kind->value.integer);
1428 else
1429 f->ts.kind = gfc_default_integer_kind;
1430 f->value.function.name
1431 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1432 gfc_default_integer_kind);
1436 void
1437 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1439 f->ts.type = BT_INTEGER;
1440 if (kind)
1441 f->ts.kind = mpz_get_si (kind->value.integer);
1442 else
1443 f->ts.kind = gfc_default_integer_kind;
1444 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1448 void
1449 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1451 f->ts = x->ts;
1452 f->value.function.name
1453 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1457 void
1458 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1459 gfc_expr *p2 ATTRIBUTE_UNUSED)
1461 f->ts.type = BT_INTEGER;
1462 f->ts.kind = gfc_default_integer_kind;
1463 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1467 void
1468 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1470 f->ts.type= BT_INTEGER;
1471 f->ts.kind = gfc_index_integer_kind;
1472 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1476 void
1477 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1479 f->ts = x->ts;
1480 f->value.function.name
1481 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1485 void
1486 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1488 f->ts = x->ts;
1489 f->value.function.name
1490 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1491 x->ts.kind);
1495 void
1496 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1498 f->ts.type = BT_LOGICAL;
1499 f->ts.kind = (kind == NULL)
1500 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1501 f->rank = a->rank;
1503 f->value.function.name
1504 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1505 gfc_type_letter (a->ts.type), a->ts.kind);
1509 void
1510 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1512 if (size->ts.kind < gfc_index_integer_kind)
1514 gfc_typespec ts;
1515 gfc_clear_ts (&ts);
1517 ts.type = BT_INTEGER;
1518 ts.kind = gfc_index_integer_kind;
1519 gfc_convert_type_warn (size, &ts, 2, 0);
1522 f->ts.type = BT_INTEGER;
1523 f->ts.kind = gfc_index_integer_kind;
1524 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1528 void
1529 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1531 gfc_expr temp;
1533 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1535 f->ts.type = BT_LOGICAL;
1536 f->ts.kind = gfc_default_logical_kind;
1538 else
1540 temp.expr_type = EXPR_OP;
1541 gfc_clear_ts (&temp.ts);
1542 temp.value.op.op = INTRINSIC_NONE;
1543 temp.value.op.op1 = a;
1544 temp.value.op.op2 = b;
1545 gfc_type_convert_binary (&temp, 1);
1546 f->ts = temp.ts;
1549 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1551 if (a->rank == 2 && b->rank == 2)
1553 if (a->shape && b->shape)
1555 f->shape = gfc_get_shape (f->rank);
1556 mpz_init_set (f->shape[0], a->shape[0]);
1557 mpz_init_set (f->shape[1], b->shape[1]);
1560 else if (a->rank == 1)
1562 if (b->shape)
1564 f->shape = gfc_get_shape (f->rank);
1565 mpz_init_set (f->shape[0], b->shape[1]);
1568 else
1570 /* b->rank == 1 and a->rank == 2 here, all other cases have
1571 been caught in check.c. */
1572 if (a->shape)
1574 f->shape = gfc_get_shape (f->rank);
1575 mpz_init_set (f->shape[0], a->shape[0]);
1579 f->value.function.name
1580 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1581 f->ts.kind);
1585 static void
1586 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1588 gfc_actual_arglist *a;
1590 f->ts.type = args->expr->ts.type;
1591 f->ts.kind = args->expr->ts.kind;
1592 /* Find the largest type kind. */
1593 for (a = args->next; a; a = a->next)
1595 if (a->expr->ts.kind > f->ts.kind)
1596 f->ts.kind = a->expr->ts.kind;
1599 /* Convert all parameters to the required kind. */
1600 for (a = args; a; a = a->next)
1602 if (a->expr->ts.kind != f->ts.kind)
1603 gfc_convert_type (a->expr, &f->ts, 2);
1606 f->value.function.name
1607 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1611 void
1612 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1614 gfc_resolve_minmax ("__max_%c%d", f, args);
1618 void
1619 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1620 gfc_expr *mask)
1622 const char *name;
1623 int i, j, idim;
1625 f->ts.type = BT_INTEGER;
1626 f->ts.kind = gfc_default_integer_kind;
1628 if (dim == NULL)
1630 f->rank = 1;
1631 f->shape = gfc_get_shape (1);
1632 mpz_init_set_si (f->shape[0], array->rank);
1634 else
1636 f->rank = array->rank - 1;
1637 gfc_resolve_dim_arg (dim);
1638 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1640 idim = (int) mpz_get_si (dim->value.integer);
1641 f->shape = gfc_get_shape (f->rank);
1642 for (i = 0, j = 0; i < f->rank; i++, j++)
1644 if (i == (idim - 1))
1645 j++;
1646 mpz_init_set (f->shape[i], array->shape[j]);
1651 if (mask)
1653 if (mask->rank == 0)
1654 name = "smaxloc";
1655 else
1656 name = "mmaxloc";
1658 resolve_mask_arg (mask);
1660 else
1661 name = "maxloc";
1663 f->value.function.name
1664 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1665 gfc_type_letter (array->ts.type), array->ts.kind);
1669 void
1670 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1671 gfc_expr *mask)
1673 const char *name;
1674 int i, j, idim;
1676 f->ts = array->ts;
1678 if (dim != NULL)
1680 f->rank = array->rank - 1;
1681 gfc_resolve_dim_arg (dim);
1683 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1685 idim = (int) mpz_get_si (dim->value.integer);
1686 f->shape = gfc_get_shape (f->rank);
1687 for (i = 0, j = 0; i < f->rank; i++, j++)
1689 if (i == (idim - 1))
1690 j++;
1691 mpz_init_set (f->shape[i], array->shape[j]);
1696 if (mask)
1698 if (mask->rank == 0)
1699 name = "smaxval";
1700 else
1701 name = "mmaxval";
1703 resolve_mask_arg (mask);
1705 else
1706 name = "maxval";
1708 f->value.function.name
1709 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1710 gfc_type_letter (array->ts.type), array->ts.kind);
1714 void
1715 gfc_resolve_mclock (gfc_expr *f)
1717 f->ts.type = BT_INTEGER;
1718 f->ts.kind = 4;
1719 f->value.function.name = PREFIX ("mclock");
1723 void
1724 gfc_resolve_mclock8 (gfc_expr *f)
1726 f->ts.type = BT_INTEGER;
1727 f->ts.kind = 8;
1728 f->value.function.name = PREFIX ("mclock8");
1732 void
1733 gfc_resolve_mask (gfc_expr *f, gfc_expr *i ATTRIBUTE_UNUSED,
1734 gfc_expr *kind)
1736 f->ts.type = BT_INTEGER;
1737 f->ts.kind = kind ? mpz_get_si (kind->value.integer)
1738 : gfc_default_integer_kind;
1740 if (f->value.function.isym->id == GFC_ISYM_MASKL)
1741 f->value.function.name = gfc_get_string ("__maskl_i%d", f->ts.kind);
1742 else
1743 f->value.function.name = gfc_get_string ("__maskr_i%d", f->ts.kind);
1747 void
1748 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1749 gfc_expr *fsource ATTRIBUTE_UNUSED,
1750 gfc_expr *mask ATTRIBUTE_UNUSED)
1752 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1753 gfc_resolve_substring_charlen (tsource);
1755 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1756 gfc_resolve_substring_charlen (fsource);
1758 if (tsource->ts.type == BT_CHARACTER)
1759 check_charlen_present (tsource);
1761 f->ts = tsource->ts;
1762 f->value.function.name
1763 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1764 tsource->ts.kind);
1768 void
1769 gfc_resolve_merge_bits (gfc_expr *f, gfc_expr *i,
1770 gfc_expr *j ATTRIBUTE_UNUSED,
1771 gfc_expr *mask ATTRIBUTE_UNUSED)
1773 f->ts = i->ts;
1774 f->value.function.name = gfc_get_string ("__merge_bits_i%d", i->ts.kind);
1778 void
1779 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1781 gfc_resolve_minmax ("__min_%c%d", f, args);
1785 void
1786 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1787 gfc_expr *mask)
1789 const char *name;
1790 int i, j, idim;
1792 f->ts.type = BT_INTEGER;
1793 f->ts.kind = gfc_default_integer_kind;
1795 if (dim == NULL)
1797 f->rank = 1;
1798 f->shape = gfc_get_shape (1);
1799 mpz_init_set_si (f->shape[0], array->rank);
1801 else
1803 f->rank = array->rank - 1;
1804 gfc_resolve_dim_arg (dim);
1805 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1807 idim = (int) mpz_get_si (dim->value.integer);
1808 f->shape = gfc_get_shape (f->rank);
1809 for (i = 0, j = 0; i < f->rank; i++, j++)
1811 if (i == (idim - 1))
1812 j++;
1813 mpz_init_set (f->shape[i], array->shape[j]);
1818 if (mask)
1820 if (mask->rank == 0)
1821 name = "sminloc";
1822 else
1823 name = "mminloc";
1825 resolve_mask_arg (mask);
1827 else
1828 name = "minloc";
1830 f->value.function.name
1831 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1832 gfc_type_letter (array->ts.type), array->ts.kind);
1836 void
1837 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1838 gfc_expr *mask)
1840 const char *name;
1841 int i, j, idim;
1843 f->ts = array->ts;
1845 if (dim != NULL)
1847 f->rank = array->rank - 1;
1848 gfc_resolve_dim_arg (dim);
1850 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1852 idim = (int) mpz_get_si (dim->value.integer);
1853 f->shape = gfc_get_shape (f->rank);
1854 for (i = 0, j = 0; i < f->rank; i++, j++)
1856 if (i == (idim - 1))
1857 j++;
1858 mpz_init_set (f->shape[i], array->shape[j]);
1863 if (mask)
1865 if (mask->rank == 0)
1866 name = "sminval";
1867 else
1868 name = "mminval";
1870 resolve_mask_arg (mask);
1872 else
1873 name = "minval";
1875 f->value.function.name
1876 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1877 gfc_type_letter (array->ts.type), array->ts.kind);
1881 void
1882 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1884 f->ts.type = a->ts.type;
1885 if (p != NULL)
1886 f->ts.kind = gfc_kind_max (a,p);
1887 else
1888 f->ts.kind = a->ts.kind;
1890 if (p != NULL && a->ts.kind != p->ts.kind)
1892 if (a->ts.kind == gfc_kind_max (a,p))
1893 gfc_convert_type (p, &a->ts, 2);
1894 else
1895 gfc_convert_type (a, &p->ts, 2);
1898 f->value.function.name
1899 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1903 void
1904 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1906 f->ts.type = a->ts.type;
1907 if (p != NULL)
1908 f->ts.kind = gfc_kind_max (a,p);
1909 else
1910 f->ts.kind = a->ts.kind;
1912 if (p != NULL && a->ts.kind != p->ts.kind)
1914 if (a->ts.kind == gfc_kind_max (a,p))
1915 gfc_convert_type (p, &a->ts, 2);
1916 else
1917 gfc_convert_type (a, &p->ts, 2);
1920 f->value.function.name
1921 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1922 f->ts.kind);
1925 void
1926 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1928 if (p->ts.kind != a->ts.kind)
1929 gfc_convert_type (p, &a->ts, 2);
1931 f->ts = a->ts;
1932 f->value.function.name
1933 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1934 a->ts.kind);
1937 void
1938 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1940 f->ts.type = BT_INTEGER;
1941 f->ts.kind = (kind == NULL)
1942 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1943 f->value.function.name
1944 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1948 void
1949 gfc_resolve_norm2 (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1951 resolve_transformational ("norm2", f, array, dim, NULL);
1955 void
1956 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1958 f->ts = i->ts;
1959 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1963 void
1964 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1966 f->ts.type = i->ts.type;
1967 f->ts.kind = gfc_kind_max (i, j);
1969 if (i->ts.kind != j->ts.kind)
1971 if (i->ts.kind == gfc_kind_max (i, j))
1972 gfc_convert_type (j, &i->ts, 2);
1973 else
1974 gfc_convert_type (i, &j->ts, 2);
1977 f->value.function.name
1978 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1982 void
1983 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1984 gfc_expr *vector ATTRIBUTE_UNUSED)
1986 if (array->ts.type == BT_CHARACTER && array->ref)
1987 gfc_resolve_substring_charlen (array);
1989 f->ts = array->ts;
1990 f->rank = 1;
1992 resolve_mask_arg (mask);
1994 if (mask->rank != 0)
1996 if (array->ts.type == BT_CHARACTER)
1997 f->value.function.name
1998 = array->ts.kind == 1 ? PREFIX ("pack_char")
1999 : gfc_get_string
2000 (PREFIX ("pack_char%d"),
2001 array->ts.kind);
2002 else
2003 f->value.function.name = PREFIX ("pack");
2005 else
2007 if (array->ts.type == BT_CHARACTER)
2008 f->value.function.name
2009 = array->ts.kind == 1 ? PREFIX ("pack_s_char")
2010 : gfc_get_string
2011 (PREFIX ("pack_s_char%d"),
2012 array->ts.kind);
2013 else
2014 f->value.function.name = PREFIX ("pack_s");
2019 void
2020 gfc_resolve_parity (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
2022 resolve_transformational ("parity", f, array, dim, NULL);
2026 void
2027 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
2028 gfc_expr *mask)
2030 resolve_transformational ("product", f, array, dim, mask);
2034 void
2035 gfc_resolve_rank (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED)
2037 f->ts.type = BT_INTEGER;
2038 f->ts.kind = gfc_default_integer_kind;
2039 f->value.function.name = gfc_get_string ("__rank");
2043 void
2044 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
2046 f->ts.type = BT_REAL;
2048 if (kind != NULL)
2049 f->ts.kind = mpz_get_si (kind->value.integer);
2050 else
2051 f->ts.kind = (a->ts.type == BT_COMPLEX)
2052 ? a->ts.kind : gfc_default_real_kind;
2054 f->value.function.name
2055 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
2056 gfc_type_letter (a->ts.type), a->ts.kind);
2060 void
2061 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
2063 f->ts.type = BT_REAL;
2064 f->ts.kind = a->ts.kind;
2065 f->value.function.name
2066 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
2067 gfc_type_letter (a->ts.type), a->ts.kind);
2071 void
2072 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2073 gfc_expr *p2 ATTRIBUTE_UNUSED)
2075 f->ts.type = BT_INTEGER;
2076 f->ts.kind = gfc_default_integer_kind;
2077 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
2081 void
2082 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
2083 gfc_expr *ncopies)
2085 int len;
2086 gfc_expr *tmp;
2087 f->ts.type = BT_CHARACTER;
2088 f->ts.kind = string->ts.kind;
2089 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
2091 /* If possible, generate a character length. */
2092 if (f->ts.u.cl == NULL)
2093 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
2095 tmp = NULL;
2096 if (string->expr_type == EXPR_CONSTANT)
2098 len = string->value.character.length;
2099 tmp = gfc_get_int_expr (gfc_default_integer_kind, NULL , len);
2101 else if (string->ts.u.cl && string->ts.u.cl->length)
2103 tmp = gfc_copy_expr (string->ts.u.cl->length);
2106 if (tmp)
2107 f->ts.u.cl->length = gfc_multiply (tmp, gfc_copy_expr (ncopies));
2111 void
2112 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
2113 gfc_expr *pad ATTRIBUTE_UNUSED,
2114 gfc_expr *order ATTRIBUTE_UNUSED)
2116 mpz_t rank;
2117 int kind;
2118 int i;
2120 if (source->ts.type == BT_CHARACTER && source->ref)
2121 gfc_resolve_substring_charlen (source);
2123 f->ts = source->ts;
2125 gfc_array_size (shape, &rank);
2126 f->rank = mpz_get_si (rank);
2127 mpz_clear (rank);
2128 switch (source->ts.type)
2130 case BT_COMPLEX:
2131 case BT_REAL:
2132 case BT_INTEGER:
2133 case BT_LOGICAL:
2134 case BT_CHARACTER:
2135 kind = source->ts.kind;
2136 break;
2138 default:
2139 kind = 0;
2140 break;
2143 switch (kind)
2145 case 4:
2146 case 8:
2147 case 10:
2148 case 16:
2149 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
2150 f->value.function.name
2151 = gfc_get_string (PREFIX ("reshape_%c%d"),
2152 gfc_type_letter (source->ts.type),
2153 source->ts.kind);
2154 else if (source->ts.type == BT_CHARACTER)
2155 f->value.function.name = gfc_get_string (PREFIX ("reshape_char%d"),
2156 kind);
2157 else
2158 f->value.function.name
2159 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
2160 break;
2162 default:
2163 f->value.function.name = (source->ts.type == BT_CHARACTER
2164 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
2165 break;
2168 if (shape->expr_type == EXPR_ARRAY && gfc_is_constant_expr (shape))
2170 gfc_constructor *c;
2171 f->shape = gfc_get_shape (f->rank);
2172 c = gfc_constructor_first (shape->value.constructor);
2173 for (i = 0; i < f->rank; i++)
2175 mpz_init_set (f->shape[i], c->expr->value.integer);
2176 c = gfc_constructor_next (c);
2180 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
2181 so many runtime variations. */
2182 if (shape->ts.kind != gfc_index_integer_kind)
2184 gfc_typespec ts = shape->ts;
2185 ts.kind = gfc_index_integer_kind;
2186 gfc_convert_type_warn (shape, &ts, 2, 0);
2188 if (order && order->ts.kind != gfc_index_integer_kind)
2189 gfc_convert_type_warn (order, &shape->ts, 2, 0);
2193 void
2194 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
2196 f->ts = x->ts;
2197 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
2201 void
2202 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED)
2204 f->ts = x->ts;
2205 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
2209 void
2210 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
2211 gfc_expr *set ATTRIBUTE_UNUSED,
2212 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2214 f->ts.type = BT_INTEGER;
2215 if (kind)
2216 f->ts.kind = mpz_get_si (kind->value.integer);
2217 else
2218 f->ts.kind = gfc_default_integer_kind;
2219 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
2223 void
2224 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
2226 t1->ts = t0->ts;
2227 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
2231 void
2232 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x,
2233 gfc_expr *i ATTRIBUTE_UNUSED)
2235 f->ts = x->ts;
2236 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
2240 void
2241 gfc_resolve_shape (gfc_expr *f, gfc_expr *array, gfc_expr *kind)
2243 f->ts.type = BT_INTEGER;
2245 if (kind)
2246 f->ts.kind = mpz_get_si (kind->value.integer);
2247 else
2248 f->ts.kind = gfc_default_integer_kind;
2250 f->rank = 1;
2251 if (array->rank != -1)
2253 f->shape = gfc_get_shape (1);
2254 mpz_init_set_ui (f->shape[0], array->rank);
2257 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
2261 void
2262 gfc_resolve_shift (gfc_expr *f, gfc_expr *i, gfc_expr *shift ATTRIBUTE_UNUSED)
2264 f->ts = i->ts;
2265 if (f->value.function.isym->id == GFC_ISYM_SHIFTA)
2266 f->value.function.name = gfc_get_string ("shifta_i%d", f->ts.kind);
2267 else if (f->value.function.isym->id == GFC_ISYM_SHIFTL)
2268 f->value.function.name = gfc_get_string ("shiftl_i%d", f->ts.kind);
2269 else if (f->value.function.isym->id == GFC_ISYM_SHIFTR)
2270 f->value.function.name = gfc_get_string ("shiftr_i%d", f->ts.kind);
2271 else
2272 gcc_unreachable ();
2276 void
2277 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
2279 f->ts = a->ts;
2280 f->value.function.name
2281 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
2285 void
2286 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
2288 f->ts.type = BT_INTEGER;
2289 f->ts.kind = gfc_c_int_kind;
2291 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2292 if (handler->ts.type == BT_INTEGER)
2294 if (handler->ts.kind != gfc_c_int_kind)
2295 gfc_convert_type (handler, &f->ts, 2);
2296 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
2298 else
2299 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
2301 if (number->ts.kind != gfc_c_int_kind)
2302 gfc_convert_type (number, &f->ts, 2);
2306 void
2307 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
2309 f->ts = x->ts;
2310 f->value.function.name
2311 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2315 void
2316 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
2318 f->ts = x->ts;
2319 f->value.function.name
2320 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2324 void
2325 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2326 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
2328 f->ts.type = BT_INTEGER;
2329 if (kind)
2330 f->ts.kind = mpz_get_si (kind->value.integer);
2331 else
2332 f->ts.kind = gfc_default_integer_kind;
2336 void
2337 gfc_resolve_stride (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2338 gfc_expr *dim ATTRIBUTE_UNUSED)
2340 f->ts.type = BT_INTEGER;
2341 f->ts.kind = gfc_index_integer_kind;
2345 void
2346 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
2348 f->ts = x->ts;
2349 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
2353 void
2354 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2355 gfc_expr *ncopies)
2357 if (source->ts.type == BT_CHARACTER && source->ref)
2358 gfc_resolve_substring_charlen (source);
2360 if (source->ts.type == BT_CHARACTER)
2361 check_charlen_present (source);
2363 f->ts = source->ts;
2364 f->rank = source->rank + 1;
2365 if (source->rank == 0)
2367 if (source->ts.type == BT_CHARACTER)
2368 f->value.function.name
2369 = source->ts.kind == 1 ? PREFIX ("spread_char_scalar")
2370 : gfc_get_string
2371 (PREFIX ("spread_char%d_scalar"),
2372 source->ts.kind);
2373 else
2374 f->value.function.name = PREFIX ("spread_scalar");
2376 else
2378 if (source->ts.type == BT_CHARACTER)
2379 f->value.function.name
2380 = source->ts.kind == 1 ? PREFIX ("spread_char")
2381 : gfc_get_string
2382 (PREFIX ("spread_char%d"),
2383 source->ts.kind);
2384 else
2385 f->value.function.name = PREFIX ("spread");
2388 if (dim && gfc_is_constant_expr (dim)
2389 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2391 int i, idim;
2392 idim = mpz_get_ui (dim->value.integer);
2393 f->shape = gfc_get_shape (f->rank);
2394 for (i = 0; i < (idim - 1); i++)
2395 mpz_init_set (f->shape[i], source->shape[i]);
2397 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2399 for (i = idim; i < f->rank ; i++)
2400 mpz_init_set (f->shape[i], source->shape[i-1]);
2404 gfc_resolve_dim_arg (dim);
2405 gfc_resolve_index (ncopies, 1);
2409 void
2410 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2412 f->ts = x->ts;
2413 f->value.function.name
2414 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2418 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2420 void
2421 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2422 gfc_expr *a ATTRIBUTE_UNUSED)
2424 f->ts.type = BT_INTEGER;
2425 f->ts.kind = gfc_default_integer_kind;
2426 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2430 void
2431 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2432 gfc_expr *a ATTRIBUTE_UNUSED)
2434 f->ts.type = BT_INTEGER;
2435 f->ts.kind = gfc_default_integer_kind;
2436 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2440 void
2441 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2443 f->ts.type = BT_INTEGER;
2444 f->ts.kind = gfc_default_integer_kind;
2445 if (n->ts.kind != f->ts.kind)
2446 gfc_convert_type (n, &f->ts, 2);
2448 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2452 void
2453 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2455 gfc_typespec ts;
2456 gfc_clear_ts (&ts);
2458 f->ts.type = BT_INTEGER;
2459 f->ts.kind = gfc_c_int_kind;
2460 if (u->ts.kind != gfc_c_int_kind)
2462 ts.type = BT_INTEGER;
2463 ts.kind = gfc_c_int_kind;
2464 ts.u.derived = NULL;
2465 ts.u.cl = NULL;
2466 gfc_convert_type (u, &ts, 2);
2469 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2473 void
2474 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2476 f->ts.type = BT_INTEGER;
2477 f->ts.kind = gfc_c_int_kind;
2478 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2482 void
2483 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2485 gfc_typespec ts;
2486 gfc_clear_ts (&ts);
2488 f->ts.type = BT_INTEGER;
2489 f->ts.kind = gfc_c_int_kind;
2490 if (u->ts.kind != gfc_c_int_kind)
2492 ts.type = BT_INTEGER;
2493 ts.kind = gfc_c_int_kind;
2494 ts.u.derived = NULL;
2495 ts.u.cl = NULL;
2496 gfc_convert_type (u, &ts, 2);
2499 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2503 void
2504 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2506 f->ts.type = BT_INTEGER;
2507 f->ts.kind = gfc_c_int_kind;
2508 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2512 void
2513 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2515 gfc_typespec ts;
2516 gfc_clear_ts (&ts);
2518 f->ts.type = BT_INTEGER;
2519 f->ts.kind = gfc_intio_kind;
2520 if (u->ts.kind != gfc_c_int_kind)
2522 ts.type = BT_INTEGER;
2523 ts.kind = gfc_c_int_kind;
2524 ts.u.derived = NULL;
2525 ts.u.cl = NULL;
2526 gfc_convert_type (u, &ts, 2);
2529 f->value.function.name = gfc_get_string (PREFIX ("ftell2"));
2533 void
2534 gfc_resolve_storage_size (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
2535 gfc_expr *kind)
2537 f->ts.type = BT_INTEGER;
2538 if (kind)
2539 f->ts.kind = mpz_get_si (kind->value.integer);
2540 else
2541 f->ts.kind = gfc_default_integer_kind;
2545 void
2546 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2548 resolve_transformational ("sum", f, array, dim, mask);
2552 void
2553 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2554 gfc_expr *p2 ATTRIBUTE_UNUSED)
2556 f->ts.type = BT_INTEGER;
2557 f->ts.kind = gfc_default_integer_kind;
2558 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2562 /* Resolve the g77 compatibility function SYSTEM. */
2564 void
2565 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2567 f->ts.type = BT_INTEGER;
2568 f->ts.kind = 4;
2569 f->value.function.name = gfc_get_string (PREFIX ("system"));
2573 void
2574 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2576 f->ts = x->ts;
2577 f->value.function.name
2578 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2582 void
2583 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2585 f->ts = x->ts;
2586 f->value.function.name
2587 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2591 void
2592 gfc_resolve_image_index (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2593 gfc_expr *sub ATTRIBUTE_UNUSED)
2595 static char image_index[] = "__image_index";
2596 f->ts.type = BT_INTEGER;
2597 f->ts.kind = gfc_default_integer_kind;
2598 f->value.function.name = image_index;
2602 void
2603 gfc_resolve_this_image (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
2604 gfc_expr *distance ATTRIBUTE_UNUSED)
2606 static char this_image[] = "__this_image";
2607 if (array && gfc_is_coarray (array))
2608 resolve_bound (f, array, dim, NULL, "__this_image", true);
2609 else
2611 f->ts.type = BT_INTEGER;
2612 f->ts.kind = gfc_default_integer_kind;
2613 f->value.function.name = this_image;
2618 void
2619 gfc_resolve_time (gfc_expr *f)
2621 f->ts.type = BT_INTEGER;
2622 f->ts.kind = 4;
2623 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2627 void
2628 gfc_resolve_time8 (gfc_expr *f)
2630 f->ts.type = BT_INTEGER;
2631 f->ts.kind = 8;
2632 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2636 void
2637 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2638 gfc_expr *mold, gfc_expr *size)
2640 /* TODO: Make this do something meaningful. */
2641 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2643 if (mold->ts.type == BT_CHARACTER
2644 && !mold->ts.u.cl->length
2645 && gfc_is_constant_expr (mold))
2647 int len;
2648 if (mold->expr_type == EXPR_CONSTANT)
2650 len = mold->value.character.length;
2651 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2652 NULL, len);
2654 else
2656 gfc_constructor *c = gfc_constructor_first (mold->value.constructor);
2657 len = c->expr->value.character.length;
2658 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2659 NULL, len);
2663 f->ts = mold->ts;
2665 if (size == NULL && mold->rank == 0)
2667 f->rank = 0;
2668 f->value.function.name = transfer0;
2670 else
2672 f->rank = 1;
2673 f->value.function.name = transfer1;
2674 if (size && gfc_is_constant_expr (size))
2676 f->shape = gfc_get_shape (1);
2677 mpz_init_set (f->shape[0], size->value.integer);
2683 void
2684 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2687 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2688 gfc_resolve_substring_charlen (matrix);
2690 f->ts = matrix->ts;
2691 f->rank = 2;
2692 if (matrix->shape)
2694 f->shape = gfc_get_shape (2);
2695 mpz_init_set (f->shape[0], matrix->shape[1]);
2696 mpz_init_set (f->shape[1], matrix->shape[0]);
2699 switch (matrix->ts.kind)
2701 case 4:
2702 case 8:
2703 case 10:
2704 case 16:
2705 switch (matrix->ts.type)
2707 case BT_REAL:
2708 case BT_COMPLEX:
2709 f->value.function.name
2710 = gfc_get_string (PREFIX ("transpose_%c%d"),
2711 gfc_type_letter (matrix->ts.type),
2712 matrix->ts.kind);
2713 break;
2715 case BT_INTEGER:
2716 case BT_LOGICAL:
2717 /* Use the integer routines for real and logical cases. This
2718 assumes they all have the same alignment requirements. */
2719 f->value.function.name
2720 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2721 break;
2723 default:
2724 if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4)
2725 f->value.function.name = PREFIX ("transpose_char4");
2726 else
2727 f->value.function.name = PREFIX ("transpose");
2728 break;
2730 break;
2732 default:
2733 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2734 ? PREFIX ("transpose_char")
2735 : PREFIX ("transpose"));
2736 break;
2741 void
2742 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2744 f->ts.type = BT_CHARACTER;
2745 f->ts.kind = string->ts.kind;
2746 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2750 void
2751 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2753 resolve_bound (f, array, dim, kind, "__ubound", false);
2757 void
2758 gfc_resolve_ucobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2760 resolve_bound (f, array, dim, kind, "__ucobound", true);
2764 /* Resolve the g77 compatibility function UMASK. */
2766 void
2767 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2769 f->ts.type = BT_INTEGER;
2770 f->ts.kind = n->ts.kind;
2771 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2775 /* Resolve the g77 compatibility function UNLINK. */
2777 void
2778 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2780 f->ts.type = BT_INTEGER;
2781 f->ts.kind = 4;
2782 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2786 void
2787 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2789 gfc_typespec ts;
2790 gfc_clear_ts (&ts);
2792 f->ts.type = BT_CHARACTER;
2793 f->ts.kind = gfc_default_character_kind;
2795 if (unit->ts.kind != gfc_c_int_kind)
2797 ts.type = BT_INTEGER;
2798 ts.kind = gfc_c_int_kind;
2799 ts.u.derived = NULL;
2800 ts.u.cl = NULL;
2801 gfc_convert_type (unit, &ts, 2);
2804 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2808 void
2809 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2810 gfc_expr *field ATTRIBUTE_UNUSED)
2812 if (vector->ts.type == BT_CHARACTER && vector->ref)
2813 gfc_resolve_substring_charlen (vector);
2815 f->ts = vector->ts;
2816 f->rank = mask->rank;
2817 resolve_mask_arg (mask);
2819 if (vector->ts.type == BT_CHARACTER)
2821 if (vector->ts.kind == 1)
2822 f->value.function.name
2823 = gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0);
2824 else
2825 f->value.function.name
2826 = gfc_get_string (PREFIX ("unpack%d_char%d"),
2827 field->rank > 0 ? 1 : 0, vector->ts.kind);
2829 else
2830 f->value.function.name
2831 = gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0);
2835 void
2836 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2837 gfc_expr *set ATTRIBUTE_UNUSED,
2838 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2840 f->ts.type = BT_INTEGER;
2841 if (kind)
2842 f->ts.kind = mpz_get_si (kind->value.integer);
2843 else
2844 f->ts.kind = gfc_default_integer_kind;
2845 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2849 void
2850 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2852 f->ts.type = i->ts.type;
2853 f->ts.kind = gfc_kind_max (i, j);
2855 if (i->ts.kind != j->ts.kind)
2857 if (i->ts.kind == gfc_kind_max (i, j))
2858 gfc_convert_type (j, &i->ts, 2);
2859 else
2860 gfc_convert_type (i, &j->ts, 2);
2863 f->value.function.name
2864 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2868 /* Intrinsic subroutine resolution. */
2870 void
2871 gfc_resolve_alarm_sub (gfc_code *c)
2873 const char *name;
2874 gfc_expr *seconds, *handler;
2875 gfc_typespec ts;
2876 gfc_clear_ts (&ts);
2878 seconds = c->ext.actual->expr;
2879 handler = c->ext.actual->next->expr;
2880 ts.type = BT_INTEGER;
2881 ts.kind = gfc_c_int_kind;
2883 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2884 In all cases, the status argument is of default integer kind
2885 (enforced in check.c) so that the function suffix is fixed. */
2886 if (handler->ts.type == BT_INTEGER)
2888 if (handler->ts.kind != gfc_c_int_kind)
2889 gfc_convert_type (handler, &ts, 2);
2890 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2891 gfc_default_integer_kind);
2893 else
2894 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2895 gfc_default_integer_kind);
2897 if (seconds->ts.kind != gfc_c_int_kind)
2898 gfc_convert_type (seconds, &ts, 2);
2900 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2903 void
2904 gfc_resolve_cpu_time (gfc_code *c)
2906 const char *name;
2907 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2908 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2912 /* Create a formal arglist based on an actual one and set the INTENTs given. */
2914 static gfc_formal_arglist*
2915 create_formal_for_intents (gfc_actual_arglist* actual, const sym_intent* ints)
2917 gfc_formal_arglist* head;
2918 gfc_formal_arglist* tail;
2919 int i;
2921 if (!actual)
2922 return NULL;
2924 head = tail = gfc_get_formal_arglist ();
2925 for (i = 0; actual; actual = actual->next, tail = tail->next, ++i)
2927 gfc_symbol* sym;
2929 sym = gfc_new_symbol ("dummyarg", NULL);
2930 sym->ts = actual->expr->ts;
2932 sym->attr.intent = ints[i];
2933 tail->sym = sym;
2935 if (actual->next)
2936 tail->next = gfc_get_formal_arglist ();
2939 return head;
2943 void
2944 gfc_resolve_atomic_def (gfc_code *c)
2946 const char *name = "atomic_define";
2947 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2951 void
2952 gfc_resolve_atomic_ref (gfc_code *c)
2954 const char *name = "atomic_ref";
2955 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2959 void
2960 gfc_resolve_mvbits (gfc_code *c)
2962 static const sym_intent INTENTS[] = {INTENT_IN, INTENT_IN, INTENT_IN,
2963 INTENT_INOUT, INTENT_IN};
2965 const char *name;
2966 gfc_typespec ts;
2967 gfc_clear_ts (&ts);
2969 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2970 they will be converted so that they fit into a C int. */
2971 ts.type = BT_INTEGER;
2972 ts.kind = gfc_c_int_kind;
2973 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2974 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2975 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2976 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2977 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2978 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2980 /* TO and FROM are guaranteed to have the same kind parameter. */
2981 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2982 c->ext.actual->expr->ts.kind);
2983 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2984 /* Mark as elemental subroutine as this does not happen automatically. */
2985 c->resolved_sym->attr.elemental = 1;
2987 /* Create a dummy formal arglist so the INTENTs are known later for purpose
2988 of creating temporaries. */
2989 c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS);
2993 void
2994 gfc_resolve_random_number (gfc_code *c)
2996 const char *name;
2997 int kind;
2999 kind = c->ext.actual->expr->ts.kind;
3000 if (c->ext.actual->expr->rank == 0)
3001 name = gfc_get_string (PREFIX ("random_r%d"), kind);
3002 else
3003 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
3005 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3009 void
3010 gfc_resolve_random_seed (gfc_code *c)
3012 const char *name;
3014 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
3015 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3019 void
3020 gfc_resolve_rename_sub (gfc_code *c)
3022 const char *name;
3023 int kind;
3025 if (c->ext.actual->next->next->expr != NULL)
3026 kind = c->ext.actual->next->next->expr->ts.kind;
3027 else
3028 kind = gfc_default_integer_kind;
3030 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
3031 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3035 void
3036 gfc_resolve_kill_sub (gfc_code *c)
3038 const char *name;
3039 int kind;
3041 if (c->ext.actual->next->next->expr != NULL)
3042 kind = c->ext.actual->next->next->expr->ts.kind;
3043 else
3044 kind = gfc_default_integer_kind;
3046 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
3047 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3051 void
3052 gfc_resolve_link_sub (gfc_code *c)
3054 const char *name;
3055 int kind;
3057 if (c->ext.actual->next->next->expr != NULL)
3058 kind = c->ext.actual->next->next->expr->ts.kind;
3059 else
3060 kind = gfc_default_integer_kind;
3062 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
3063 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3067 void
3068 gfc_resolve_symlnk_sub (gfc_code *c)
3070 const char *name;
3071 int kind;
3073 if (c->ext.actual->next->next->expr != NULL)
3074 kind = c->ext.actual->next->next->expr->ts.kind;
3075 else
3076 kind = gfc_default_integer_kind;
3078 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
3079 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3083 /* G77 compatibility subroutines dtime() and etime(). */
3085 void
3086 gfc_resolve_dtime_sub (gfc_code *c)
3088 const char *name;
3089 name = gfc_get_string (PREFIX ("dtime_sub"));
3090 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3093 void
3094 gfc_resolve_etime_sub (gfc_code *c)
3096 const char *name;
3097 name = gfc_get_string (PREFIX ("etime_sub"));
3098 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3102 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
3104 void
3105 gfc_resolve_itime (gfc_code *c)
3107 c->resolved_sym
3108 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
3109 gfc_default_integer_kind));
3112 void
3113 gfc_resolve_idate (gfc_code *c)
3115 c->resolved_sym
3116 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
3117 gfc_default_integer_kind));
3120 void
3121 gfc_resolve_ltime (gfc_code *c)
3123 c->resolved_sym
3124 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
3125 gfc_default_integer_kind));
3128 void
3129 gfc_resolve_gmtime (gfc_code *c)
3131 c->resolved_sym
3132 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
3133 gfc_default_integer_kind));
3137 /* G77 compatibility subroutine second(). */
3139 void
3140 gfc_resolve_second_sub (gfc_code *c)
3142 const char *name;
3143 name = gfc_get_string (PREFIX ("second_sub"));
3144 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3148 void
3149 gfc_resolve_sleep_sub (gfc_code *c)
3151 const char *name;
3152 int kind;
3154 if (c->ext.actual->expr != NULL)
3155 kind = c->ext.actual->expr->ts.kind;
3156 else
3157 kind = gfc_default_integer_kind;
3159 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
3160 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3164 /* G77 compatibility function srand(). */
3166 void
3167 gfc_resolve_srand (gfc_code *c)
3169 const char *name;
3170 name = gfc_get_string (PREFIX ("srand"));
3171 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3175 /* Resolve the getarg intrinsic subroutine. */
3177 void
3178 gfc_resolve_getarg (gfc_code *c)
3180 const char *name;
3182 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
3184 gfc_typespec ts;
3185 gfc_clear_ts (&ts);
3187 ts.type = BT_INTEGER;
3188 ts.kind = gfc_default_integer_kind;
3190 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3193 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
3194 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3198 /* Resolve the getcwd intrinsic subroutine. */
3200 void
3201 gfc_resolve_getcwd_sub (gfc_code *c)
3203 const char *name;
3204 int kind;
3206 if (c->ext.actual->next->expr != NULL)
3207 kind = c->ext.actual->next->expr->ts.kind;
3208 else
3209 kind = gfc_default_integer_kind;
3211 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
3212 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3216 /* Resolve the get_command intrinsic subroutine. */
3218 void
3219 gfc_resolve_get_command (gfc_code *c)
3221 const char *name;
3222 int kind;
3223 kind = gfc_default_integer_kind;
3224 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
3225 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3229 /* Resolve the get_command_argument intrinsic subroutine. */
3231 void
3232 gfc_resolve_get_command_argument (gfc_code *c)
3234 const char *name;
3235 int kind;
3236 kind = gfc_default_integer_kind;
3237 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
3238 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3242 /* Resolve the get_environment_variable intrinsic subroutine. */
3244 void
3245 gfc_resolve_get_environment_variable (gfc_code *code)
3247 const char *name;
3248 int kind;
3249 kind = gfc_default_integer_kind;
3250 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
3251 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3255 void
3256 gfc_resolve_signal_sub (gfc_code *c)
3258 const char *name;
3259 gfc_expr *number, *handler, *status;
3260 gfc_typespec ts;
3261 gfc_clear_ts (&ts);
3263 number = c->ext.actual->expr;
3264 handler = c->ext.actual->next->expr;
3265 status = c->ext.actual->next->next->expr;
3266 ts.type = BT_INTEGER;
3267 ts.kind = gfc_c_int_kind;
3269 /* handler can be either BT_INTEGER or BT_PROCEDURE */
3270 if (handler->ts.type == BT_INTEGER)
3272 if (handler->ts.kind != gfc_c_int_kind)
3273 gfc_convert_type (handler, &ts, 2);
3274 name = gfc_get_string (PREFIX ("signal_sub_int"));
3276 else
3277 name = gfc_get_string (PREFIX ("signal_sub"));
3279 if (number->ts.kind != gfc_c_int_kind)
3280 gfc_convert_type (number, &ts, 2);
3281 if (status != NULL && status->ts.kind != gfc_c_int_kind)
3282 gfc_convert_type (status, &ts, 2);
3284 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3288 /* Resolve the SYSTEM intrinsic subroutine. */
3290 void
3291 gfc_resolve_system_sub (gfc_code *c)
3293 const char *name;
3294 name = gfc_get_string (PREFIX ("system_sub"));
3295 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3299 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
3301 void
3302 gfc_resolve_system_clock (gfc_code *c)
3304 const char *name;
3305 int kind;
3306 gfc_expr *count = c->ext.actual->expr;
3307 gfc_expr *count_max = c->ext.actual->next->next->expr;
3309 /* The INTEGER(8) version has higher precision, it is used if both COUNT
3310 and COUNT_MAX can hold 64-bit values, or are absent. */
3311 if ((!count || count->ts.kind >= 8)
3312 && (!count_max || count_max->ts.kind >= 8))
3313 kind = 8;
3314 else
3315 kind = gfc_default_integer_kind;
3317 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
3318 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3322 /* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine. */
3323 void
3324 gfc_resolve_execute_command_line (gfc_code *c)
3326 const char *name;
3327 name = gfc_get_string (PREFIX ("execute_command_line_i%d"),
3328 gfc_default_integer_kind);
3329 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3333 /* Resolve the EXIT intrinsic subroutine. */
3335 void
3336 gfc_resolve_exit (gfc_code *c)
3338 const char *name;
3339 gfc_typespec ts;
3340 gfc_expr *n;
3341 gfc_clear_ts (&ts);
3343 /* The STATUS argument has to be of default kind. If it is not,
3344 we convert it. */
3345 ts.type = BT_INTEGER;
3346 ts.kind = gfc_default_integer_kind;
3347 n = c->ext.actual->expr;
3348 if (n != NULL && n->ts.kind != ts.kind)
3349 gfc_convert_type (n, &ts, 2);
3351 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
3352 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3356 /* Resolve the FLUSH intrinsic subroutine. */
3358 void
3359 gfc_resolve_flush (gfc_code *c)
3361 const char *name;
3362 gfc_typespec ts;
3363 gfc_expr *n;
3364 gfc_clear_ts (&ts);
3366 ts.type = BT_INTEGER;
3367 ts.kind = gfc_default_integer_kind;
3368 n = c->ext.actual->expr;
3369 if (n != NULL && n->ts.kind != ts.kind)
3370 gfc_convert_type (n, &ts, 2);
3372 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
3373 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3377 void
3378 gfc_resolve_free (gfc_code *c)
3380 gfc_typespec ts;
3381 gfc_expr *n;
3382 gfc_clear_ts (&ts);
3384 ts.type = BT_INTEGER;
3385 ts.kind = gfc_index_integer_kind;
3386 n = c->ext.actual->expr;
3387 if (n->ts.kind != ts.kind)
3388 gfc_convert_type (n, &ts, 2);
3390 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
3394 void
3395 gfc_resolve_ctime_sub (gfc_code *c)
3397 gfc_typespec ts;
3398 gfc_clear_ts (&ts);
3400 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3401 if (c->ext.actual->expr->ts.kind != 8)
3403 ts.type = BT_INTEGER;
3404 ts.kind = 8;
3405 ts.u.derived = NULL;
3406 ts.u.cl = NULL;
3407 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3410 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3414 void
3415 gfc_resolve_fdate_sub (gfc_code *c)
3417 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3421 void
3422 gfc_resolve_gerror (gfc_code *c)
3424 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3428 void
3429 gfc_resolve_getlog (gfc_code *c)
3431 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3435 void
3436 gfc_resolve_hostnm_sub (gfc_code *c)
3438 const char *name;
3439 int kind;
3441 if (c->ext.actual->next->expr != NULL)
3442 kind = c->ext.actual->next->expr->ts.kind;
3443 else
3444 kind = gfc_default_integer_kind;
3446 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3447 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3451 void
3452 gfc_resolve_perror (gfc_code *c)
3454 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3457 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3459 void
3460 gfc_resolve_stat_sub (gfc_code *c)
3462 const char *name;
3463 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3464 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3468 void
3469 gfc_resolve_lstat_sub (gfc_code *c)
3471 const char *name;
3472 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3473 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3477 void
3478 gfc_resolve_fstat_sub (gfc_code *c)
3480 const char *name;
3481 gfc_expr *u;
3482 gfc_typespec *ts;
3484 u = c->ext.actual->expr;
3485 ts = &c->ext.actual->next->expr->ts;
3486 if (u->ts.kind != ts->kind)
3487 gfc_convert_type (u, ts, 2);
3488 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3489 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3493 void
3494 gfc_resolve_fgetc_sub (gfc_code *c)
3496 const char *name;
3497 gfc_typespec ts;
3498 gfc_expr *u, *st;
3499 gfc_clear_ts (&ts);
3501 u = c->ext.actual->expr;
3502 st = c->ext.actual->next->next->expr;
3504 if (u->ts.kind != gfc_c_int_kind)
3506 ts.type = BT_INTEGER;
3507 ts.kind = gfc_c_int_kind;
3508 ts.u.derived = NULL;
3509 ts.u.cl = NULL;
3510 gfc_convert_type (u, &ts, 2);
3513 if (st != NULL)
3514 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3515 else
3516 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3518 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3522 void
3523 gfc_resolve_fget_sub (gfc_code *c)
3525 const char *name;
3526 gfc_expr *st;
3528 st = c->ext.actual->next->expr;
3529 if (st != NULL)
3530 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3531 else
3532 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3534 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3538 void
3539 gfc_resolve_fputc_sub (gfc_code *c)
3541 const char *name;
3542 gfc_typespec ts;
3543 gfc_expr *u, *st;
3544 gfc_clear_ts (&ts);
3546 u = c->ext.actual->expr;
3547 st = c->ext.actual->next->next->expr;
3549 if (u->ts.kind != gfc_c_int_kind)
3551 ts.type = BT_INTEGER;
3552 ts.kind = gfc_c_int_kind;
3553 ts.u.derived = NULL;
3554 ts.u.cl = NULL;
3555 gfc_convert_type (u, &ts, 2);
3558 if (st != NULL)
3559 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3560 else
3561 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3563 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3567 void
3568 gfc_resolve_fput_sub (gfc_code *c)
3570 const char *name;
3571 gfc_expr *st;
3573 st = c->ext.actual->next->expr;
3574 if (st != NULL)
3575 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3576 else
3577 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3579 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3583 void
3584 gfc_resolve_fseek_sub (gfc_code *c)
3586 gfc_expr *unit;
3587 gfc_expr *offset;
3588 gfc_expr *whence;
3589 gfc_typespec ts;
3590 gfc_clear_ts (&ts);
3592 unit = c->ext.actual->expr;
3593 offset = c->ext.actual->next->expr;
3594 whence = c->ext.actual->next->next->expr;
3596 if (unit->ts.kind != gfc_c_int_kind)
3598 ts.type = BT_INTEGER;
3599 ts.kind = gfc_c_int_kind;
3600 ts.u.derived = NULL;
3601 ts.u.cl = NULL;
3602 gfc_convert_type (unit, &ts, 2);
3605 if (offset->ts.kind != gfc_intio_kind)
3607 ts.type = BT_INTEGER;
3608 ts.kind = gfc_intio_kind;
3609 ts.u.derived = NULL;
3610 ts.u.cl = NULL;
3611 gfc_convert_type (offset, &ts, 2);
3614 if (whence->ts.kind != gfc_c_int_kind)
3616 ts.type = BT_INTEGER;
3617 ts.kind = gfc_c_int_kind;
3618 ts.u.derived = NULL;
3619 ts.u.cl = NULL;
3620 gfc_convert_type (whence, &ts, 2);
3623 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3626 void
3627 gfc_resolve_ftell_sub (gfc_code *c)
3629 const char *name;
3630 gfc_expr *unit;
3631 gfc_expr *offset;
3632 gfc_typespec ts;
3633 gfc_clear_ts (&ts);
3635 unit = c->ext.actual->expr;
3636 offset = c->ext.actual->next->expr;
3638 if (unit->ts.kind != gfc_c_int_kind)
3640 ts.type = BT_INTEGER;
3641 ts.kind = gfc_c_int_kind;
3642 ts.u.derived = NULL;
3643 ts.u.cl = NULL;
3644 gfc_convert_type (unit, &ts, 2);
3647 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3648 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3652 void
3653 gfc_resolve_ttynam_sub (gfc_code *c)
3655 gfc_typespec ts;
3656 gfc_clear_ts (&ts);
3658 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3660 ts.type = BT_INTEGER;
3661 ts.kind = gfc_c_int_kind;
3662 ts.u.derived = NULL;
3663 ts.u.cl = NULL;
3664 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3667 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3671 /* Resolve the UMASK intrinsic subroutine. */
3673 void
3674 gfc_resolve_umask_sub (gfc_code *c)
3676 const char *name;
3677 int kind;
3679 if (c->ext.actual->next->expr != NULL)
3680 kind = c->ext.actual->next->expr->ts.kind;
3681 else
3682 kind = gfc_default_integer_kind;
3684 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3685 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3688 /* Resolve the UNLINK intrinsic subroutine. */
3690 void
3691 gfc_resolve_unlink_sub (gfc_code *c)
3693 const char *name;
3694 int kind;
3696 if (c->ext.actual->next->expr != NULL)
3697 kind = c->ext.actual->next->expr->ts.kind;
3698 else
3699 kind = gfc_default_integer_kind;
3701 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3702 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);