2015-05-06 Thomas Koenig <tkoenig@gcc.gnu.org>
[official-gcc.git] / gcc / fortran / iresolve.c
blob32ef0719eade56384a0271c30b2f42edb8a5450e
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);
2200 void
2201 gfc_resolve_fe_runtime_error (gfc_code *c)
2203 const char *name;
2204 gfc_actual_arglist *a;
2206 name = gfc_get_string (PREFIX ("runtime_error"));
2208 for (a = c->ext.actual->next; a; a = a->next)
2209 a->name = "%VAL";
2211 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2214 void
2215 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED)
2217 f->ts = x->ts;
2218 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
2222 void
2223 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
2224 gfc_expr *set ATTRIBUTE_UNUSED,
2225 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2227 f->ts.type = BT_INTEGER;
2228 if (kind)
2229 f->ts.kind = mpz_get_si (kind->value.integer);
2230 else
2231 f->ts.kind = gfc_default_integer_kind;
2232 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
2236 void
2237 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
2239 t1->ts = t0->ts;
2240 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
2244 void
2245 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x,
2246 gfc_expr *i ATTRIBUTE_UNUSED)
2248 f->ts = x->ts;
2249 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
2253 void
2254 gfc_resolve_shape (gfc_expr *f, gfc_expr *array, gfc_expr *kind)
2256 f->ts.type = BT_INTEGER;
2258 if (kind)
2259 f->ts.kind = mpz_get_si (kind->value.integer);
2260 else
2261 f->ts.kind = gfc_default_integer_kind;
2263 f->rank = 1;
2264 if (array->rank != -1)
2266 f->shape = gfc_get_shape (1);
2267 mpz_init_set_ui (f->shape[0], array->rank);
2270 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
2274 void
2275 gfc_resolve_shift (gfc_expr *f, gfc_expr *i, gfc_expr *shift ATTRIBUTE_UNUSED)
2277 f->ts = i->ts;
2278 if (f->value.function.isym->id == GFC_ISYM_SHIFTA)
2279 f->value.function.name = gfc_get_string ("shifta_i%d", f->ts.kind);
2280 else if (f->value.function.isym->id == GFC_ISYM_SHIFTL)
2281 f->value.function.name = gfc_get_string ("shiftl_i%d", f->ts.kind);
2282 else if (f->value.function.isym->id == GFC_ISYM_SHIFTR)
2283 f->value.function.name = gfc_get_string ("shiftr_i%d", f->ts.kind);
2284 else
2285 gcc_unreachable ();
2289 void
2290 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
2292 f->ts = a->ts;
2293 f->value.function.name
2294 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
2298 void
2299 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
2301 f->ts.type = BT_INTEGER;
2302 f->ts.kind = gfc_c_int_kind;
2304 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2305 if (handler->ts.type == BT_INTEGER)
2307 if (handler->ts.kind != gfc_c_int_kind)
2308 gfc_convert_type (handler, &f->ts, 2);
2309 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
2311 else
2312 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
2314 if (number->ts.kind != gfc_c_int_kind)
2315 gfc_convert_type (number, &f->ts, 2);
2319 void
2320 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
2322 f->ts = x->ts;
2323 f->value.function.name
2324 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2328 void
2329 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
2331 f->ts = x->ts;
2332 f->value.function.name
2333 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2337 void
2338 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2339 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
2341 f->ts.type = BT_INTEGER;
2342 if (kind)
2343 f->ts.kind = mpz_get_si (kind->value.integer);
2344 else
2345 f->ts.kind = gfc_default_integer_kind;
2349 void
2350 gfc_resolve_stride (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2351 gfc_expr *dim ATTRIBUTE_UNUSED)
2353 f->ts.type = BT_INTEGER;
2354 f->ts.kind = gfc_index_integer_kind;
2358 void
2359 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
2361 f->ts = x->ts;
2362 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
2366 void
2367 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2368 gfc_expr *ncopies)
2370 if (source->ts.type == BT_CHARACTER && source->ref)
2371 gfc_resolve_substring_charlen (source);
2373 if (source->ts.type == BT_CHARACTER)
2374 check_charlen_present (source);
2376 f->ts = source->ts;
2377 f->rank = source->rank + 1;
2378 if (source->rank == 0)
2380 if (source->ts.type == BT_CHARACTER)
2381 f->value.function.name
2382 = source->ts.kind == 1 ? PREFIX ("spread_char_scalar")
2383 : gfc_get_string
2384 (PREFIX ("spread_char%d_scalar"),
2385 source->ts.kind);
2386 else
2387 f->value.function.name = PREFIX ("spread_scalar");
2389 else
2391 if (source->ts.type == BT_CHARACTER)
2392 f->value.function.name
2393 = source->ts.kind == 1 ? PREFIX ("spread_char")
2394 : gfc_get_string
2395 (PREFIX ("spread_char%d"),
2396 source->ts.kind);
2397 else
2398 f->value.function.name = PREFIX ("spread");
2401 if (dim && gfc_is_constant_expr (dim)
2402 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2404 int i, idim;
2405 idim = mpz_get_ui (dim->value.integer);
2406 f->shape = gfc_get_shape (f->rank);
2407 for (i = 0; i < (idim - 1); i++)
2408 mpz_init_set (f->shape[i], source->shape[i]);
2410 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2412 for (i = idim; i < f->rank ; i++)
2413 mpz_init_set (f->shape[i], source->shape[i-1]);
2417 gfc_resolve_dim_arg (dim);
2418 gfc_resolve_index (ncopies, 1);
2422 void
2423 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2425 f->ts = x->ts;
2426 f->value.function.name
2427 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2431 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2433 void
2434 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2435 gfc_expr *a ATTRIBUTE_UNUSED)
2437 f->ts.type = BT_INTEGER;
2438 f->ts.kind = gfc_default_integer_kind;
2439 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2443 void
2444 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2445 gfc_expr *a ATTRIBUTE_UNUSED)
2447 f->ts.type = BT_INTEGER;
2448 f->ts.kind = gfc_default_integer_kind;
2449 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2453 void
2454 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2456 f->ts.type = BT_INTEGER;
2457 f->ts.kind = gfc_default_integer_kind;
2458 if (n->ts.kind != f->ts.kind)
2459 gfc_convert_type (n, &f->ts, 2);
2461 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2465 void
2466 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2468 gfc_typespec ts;
2469 gfc_clear_ts (&ts);
2471 f->ts.type = BT_INTEGER;
2472 f->ts.kind = gfc_c_int_kind;
2473 if (u->ts.kind != gfc_c_int_kind)
2475 ts.type = BT_INTEGER;
2476 ts.kind = gfc_c_int_kind;
2477 ts.u.derived = NULL;
2478 ts.u.cl = NULL;
2479 gfc_convert_type (u, &ts, 2);
2482 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2486 void
2487 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2489 f->ts.type = BT_INTEGER;
2490 f->ts.kind = gfc_c_int_kind;
2491 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2495 void
2496 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2498 gfc_typespec ts;
2499 gfc_clear_ts (&ts);
2501 f->ts.type = BT_INTEGER;
2502 f->ts.kind = gfc_c_int_kind;
2503 if (u->ts.kind != gfc_c_int_kind)
2505 ts.type = BT_INTEGER;
2506 ts.kind = gfc_c_int_kind;
2507 ts.u.derived = NULL;
2508 ts.u.cl = NULL;
2509 gfc_convert_type (u, &ts, 2);
2512 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2516 void
2517 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2519 f->ts.type = BT_INTEGER;
2520 f->ts.kind = gfc_c_int_kind;
2521 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2525 void
2526 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2528 gfc_typespec ts;
2529 gfc_clear_ts (&ts);
2531 f->ts.type = BT_INTEGER;
2532 f->ts.kind = gfc_intio_kind;
2533 if (u->ts.kind != gfc_c_int_kind)
2535 ts.type = BT_INTEGER;
2536 ts.kind = gfc_c_int_kind;
2537 ts.u.derived = NULL;
2538 ts.u.cl = NULL;
2539 gfc_convert_type (u, &ts, 2);
2542 f->value.function.name = gfc_get_string (PREFIX ("ftell2"));
2546 void
2547 gfc_resolve_storage_size (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
2548 gfc_expr *kind)
2550 f->ts.type = BT_INTEGER;
2551 if (kind)
2552 f->ts.kind = mpz_get_si (kind->value.integer);
2553 else
2554 f->ts.kind = gfc_default_integer_kind;
2558 void
2559 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2561 resolve_transformational ("sum", f, array, dim, mask);
2565 void
2566 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2567 gfc_expr *p2 ATTRIBUTE_UNUSED)
2569 f->ts.type = BT_INTEGER;
2570 f->ts.kind = gfc_default_integer_kind;
2571 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2575 /* Resolve the g77 compatibility function SYSTEM. */
2577 void
2578 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2580 f->ts.type = BT_INTEGER;
2581 f->ts.kind = 4;
2582 f->value.function.name = gfc_get_string (PREFIX ("system"));
2586 void
2587 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2589 f->ts = x->ts;
2590 f->value.function.name
2591 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2595 void
2596 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2598 f->ts = x->ts;
2599 f->value.function.name
2600 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2604 void
2605 gfc_resolve_image_index (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2606 gfc_expr *sub ATTRIBUTE_UNUSED)
2608 static char image_index[] = "__image_index";
2609 f->ts.type = BT_INTEGER;
2610 f->ts.kind = gfc_default_integer_kind;
2611 f->value.function.name = image_index;
2615 void
2616 gfc_resolve_this_image (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
2617 gfc_expr *distance ATTRIBUTE_UNUSED)
2619 static char this_image[] = "__this_image";
2620 if (array && gfc_is_coarray (array))
2621 resolve_bound (f, array, dim, NULL, "__this_image", true);
2622 else
2624 f->ts.type = BT_INTEGER;
2625 f->ts.kind = gfc_default_integer_kind;
2626 f->value.function.name = this_image;
2631 void
2632 gfc_resolve_time (gfc_expr *f)
2634 f->ts.type = BT_INTEGER;
2635 f->ts.kind = 4;
2636 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2640 void
2641 gfc_resolve_time8 (gfc_expr *f)
2643 f->ts.type = BT_INTEGER;
2644 f->ts.kind = 8;
2645 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2649 void
2650 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2651 gfc_expr *mold, gfc_expr *size)
2653 /* TODO: Make this do something meaningful. */
2654 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2656 if (mold->ts.type == BT_CHARACTER
2657 && !mold->ts.u.cl->length
2658 && gfc_is_constant_expr (mold))
2660 int len;
2661 if (mold->expr_type == EXPR_CONSTANT)
2663 len = mold->value.character.length;
2664 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2665 NULL, len);
2667 else
2669 gfc_constructor *c = gfc_constructor_first (mold->value.constructor);
2670 len = c->expr->value.character.length;
2671 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2672 NULL, len);
2676 f->ts = mold->ts;
2678 if (size == NULL && mold->rank == 0)
2680 f->rank = 0;
2681 f->value.function.name = transfer0;
2683 else
2685 f->rank = 1;
2686 f->value.function.name = transfer1;
2687 if (size && gfc_is_constant_expr (size))
2689 f->shape = gfc_get_shape (1);
2690 mpz_init_set (f->shape[0], size->value.integer);
2696 void
2697 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2700 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2701 gfc_resolve_substring_charlen (matrix);
2703 f->ts = matrix->ts;
2704 f->rank = 2;
2705 if (matrix->shape)
2707 f->shape = gfc_get_shape (2);
2708 mpz_init_set (f->shape[0], matrix->shape[1]);
2709 mpz_init_set (f->shape[1], matrix->shape[0]);
2712 switch (matrix->ts.kind)
2714 case 4:
2715 case 8:
2716 case 10:
2717 case 16:
2718 switch (matrix->ts.type)
2720 case BT_REAL:
2721 case BT_COMPLEX:
2722 f->value.function.name
2723 = gfc_get_string (PREFIX ("transpose_%c%d"),
2724 gfc_type_letter (matrix->ts.type),
2725 matrix->ts.kind);
2726 break;
2728 case BT_INTEGER:
2729 case BT_LOGICAL:
2730 /* Use the integer routines for real and logical cases. This
2731 assumes they all have the same alignment requirements. */
2732 f->value.function.name
2733 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2734 break;
2736 default:
2737 if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4)
2738 f->value.function.name = PREFIX ("transpose_char4");
2739 else
2740 f->value.function.name = PREFIX ("transpose");
2741 break;
2743 break;
2745 default:
2746 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2747 ? PREFIX ("transpose_char")
2748 : PREFIX ("transpose"));
2749 break;
2754 void
2755 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2757 f->ts.type = BT_CHARACTER;
2758 f->ts.kind = string->ts.kind;
2759 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2763 void
2764 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2766 resolve_bound (f, array, dim, kind, "__ubound", false);
2770 void
2771 gfc_resolve_ucobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2773 resolve_bound (f, array, dim, kind, "__ucobound", true);
2777 /* Resolve the g77 compatibility function UMASK. */
2779 void
2780 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2782 f->ts.type = BT_INTEGER;
2783 f->ts.kind = n->ts.kind;
2784 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2788 /* Resolve the g77 compatibility function UNLINK. */
2790 void
2791 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2793 f->ts.type = BT_INTEGER;
2794 f->ts.kind = 4;
2795 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2799 void
2800 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2802 gfc_typespec ts;
2803 gfc_clear_ts (&ts);
2805 f->ts.type = BT_CHARACTER;
2806 f->ts.kind = gfc_default_character_kind;
2808 if (unit->ts.kind != gfc_c_int_kind)
2810 ts.type = BT_INTEGER;
2811 ts.kind = gfc_c_int_kind;
2812 ts.u.derived = NULL;
2813 ts.u.cl = NULL;
2814 gfc_convert_type (unit, &ts, 2);
2817 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2821 void
2822 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2823 gfc_expr *field ATTRIBUTE_UNUSED)
2825 if (vector->ts.type == BT_CHARACTER && vector->ref)
2826 gfc_resolve_substring_charlen (vector);
2828 f->ts = vector->ts;
2829 f->rank = mask->rank;
2830 resolve_mask_arg (mask);
2832 if (vector->ts.type == BT_CHARACTER)
2834 if (vector->ts.kind == 1)
2835 f->value.function.name
2836 = gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0);
2837 else
2838 f->value.function.name
2839 = gfc_get_string (PREFIX ("unpack%d_char%d"),
2840 field->rank > 0 ? 1 : 0, vector->ts.kind);
2842 else
2843 f->value.function.name
2844 = gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0);
2848 void
2849 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2850 gfc_expr *set ATTRIBUTE_UNUSED,
2851 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2853 f->ts.type = BT_INTEGER;
2854 if (kind)
2855 f->ts.kind = mpz_get_si (kind->value.integer);
2856 else
2857 f->ts.kind = gfc_default_integer_kind;
2858 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2862 void
2863 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2865 f->ts.type = i->ts.type;
2866 f->ts.kind = gfc_kind_max (i, j);
2868 if (i->ts.kind != j->ts.kind)
2870 if (i->ts.kind == gfc_kind_max (i, j))
2871 gfc_convert_type (j, &i->ts, 2);
2872 else
2873 gfc_convert_type (i, &j->ts, 2);
2876 f->value.function.name
2877 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2881 /* Intrinsic subroutine resolution. */
2883 void
2884 gfc_resolve_alarm_sub (gfc_code *c)
2886 const char *name;
2887 gfc_expr *seconds, *handler;
2888 gfc_typespec ts;
2889 gfc_clear_ts (&ts);
2891 seconds = c->ext.actual->expr;
2892 handler = c->ext.actual->next->expr;
2893 ts.type = BT_INTEGER;
2894 ts.kind = gfc_c_int_kind;
2896 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2897 In all cases, the status argument is of default integer kind
2898 (enforced in check.c) so that the function suffix is fixed. */
2899 if (handler->ts.type == BT_INTEGER)
2901 if (handler->ts.kind != gfc_c_int_kind)
2902 gfc_convert_type (handler, &ts, 2);
2903 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2904 gfc_default_integer_kind);
2906 else
2907 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2908 gfc_default_integer_kind);
2910 if (seconds->ts.kind != gfc_c_int_kind)
2911 gfc_convert_type (seconds, &ts, 2);
2913 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2916 void
2917 gfc_resolve_cpu_time (gfc_code *c)
2919 const char *name;
2920 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2921 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2925 /* Create a formal arglist based on an actual one and set the INTENTs given. */
2927 static gfc_formal_arglist*
2928 create_formal_for_intents (gfc_actual_arglist* actual, const sym_intent* ints)
2930 gfc_formal_arglist* head;
2931 gfc_formal_arglist* tail;
2932 int i;
2934 if (!actual)
2935 return NULL;
2937 head = tail = gfc_get_formal_arglist ();
2938 for (i = 0; actual; actual = actual->next, tail = tail->next, ++i)
2940 gfc_symbol* sym;
2942 sym = gfc_new_symbol ("dummyarg", NULL);
2943 sym->ts = actual->expr->ts;
2945 sym->attr.intent = ints[i];
2946 tail->sym = sym;
2948 if (actual->next)
2949 tail->next = gfc_get_formal_arglist ();
2952 return head;
2956 void
2957 gfc_resolve_atomic_def (gfc_code *c)
2959 const char *name = "atomic_define";
2960 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2964 void
2965 gfc_resolve_atomic_ref (gfc_code *c)
2967 const char *name = "atomic_ref";
2968 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2972 void
2973 gfc_resolve_mvbits (gfc_code *c)
2975 static const sym_intent INTENTS[] = {INTENT_IN, INTENT_IN, INTENT_IN,
2976 INTENT_INOUT, INTENT_IN};
2978 const char *name;
2979 gfc_typespec ts;
2980 gfc_clear_ts (&ts);
2982 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2983 they will be converted so that they fit into a C int. */
2984 ts.type = BT_INTEGER;
2985 ts.kind = gfc_c_int_kind;
2986 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2987 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2988 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2989 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2990 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2991 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2993 /* TO and FROM are guaranteed to have the same kind parameter. */
2994 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2995 c->ext.actual->expr->ts.kind);
2996 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2997 /* Mark as elemental subroutine as this does not happen automatically. */
2998 c->resolved_sym->attr.elemental = 1;
3000 /* Create a dummy formal arglist so the INTENTs are known later for purpose
3001 of creating temporaries. */
3002 c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS);
3006 void
3007 gfc_resolve_random_number (gfc_code *c)
3009 const char *name;
3010 int kind;
3012 kind = c->ext.actual->expr->ts.kind;
3013 if (c->ext.actual->expr->rank == 0)
3014 name = gfc_get_string (PREFIX ("random_r%d"), kind);
3015 else
3016 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
3018 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3022 void
3023 gfc_resolve_random_seed (gfc_code *c)
3025 const char *name;
3027 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
3028 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3032 void
3033 gfc_resolve_rename_sub (gfc_code *c)
3035 const char *name;
3036 int kind;
3038 if (c->ext.actual->next->next->expr != NULL)
3039 kind = c->ext.actual->next->next->expr->ts.kind;
3040 else
3041 kind = gfc_default_integer_kind;
3043 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
3044 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3048 void
3049 gfc_resolve_kill_sub (gfc_code *c)
3051 const char *name;
3052 int kind;
3054 if (c->ext.actual->next->next->expr != NULL)
3055 kind = c->ext.actual->next->next->expr->ts.kind;
3056 else
3057 kind = gfc_default_integer_kind;
3059 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
3060 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3064 void
3065 gfc_resolve_link_sub (gfc_code *c)
3067 const char *name;
3068 int kind;
3070 if (c->ext.actual->next->next->expr != NULL)
3071 kind = c->ext.actual->next->next->expr->ts.kind;
3072 else
3073 kind = gfc_default_integer_kind;
3075 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
3076 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3080 void
3081 gfc_resolve_symlnk_sub (gfc_code *c)
3083 const char *name;
3084 int kind;
3086 if (c->ext.actual->next->next->expr != NULL)
3087 kind = c->ext.actual->next->next->expr->ts.kind;
3088 else
3089 kind = gfc_default_integer_kind;
3091 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
3092 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3096 /* G77 compatibility subroutines dtime() and etime(). */
3098 void
3099 gfc_resolve_dtime_sub (gfc_code *c)
3101 const char *name;
3102 name = gfc_get_string (PREFIX ("dtime_sub"));
3103 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3106 void
3107 gfc_resolve_etime_sub (gfc_code *c)
3109 const char *name;
3110 name = gfc_get_string (PREFIX ("etime_sub"));
3111 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3115 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
3117 void
3118 gfc_resolve_itime (gfc_code *c)
3120 c->resolved_sym
3121 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
3122 gfc_default_integer_kind));
3125 void
3126 gfc_resolve_idate (gfc_code *c)
3128 c->resolved_sym
3129 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
3130 gfc_default_integer_kind));
3133 void
3134 gfc_resolve_ltime (gfc_code *c)
3136 c->resolved_sym
3137 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
3138 gfc_default_integer_kind));
3141 void
3142 gfc_resolve_gmtime (gfc_code *c)
3144 c->resolved_sym
3145 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
3146 gfc_default_integer_kind));
3150 /* G77 compatibility subroutine second(). */
3152 void
3153 gfc_resolve_second_sub (gfc_code *c)
3155 const char *name;
3156 name = gfc_get_string (PREFIX ("second_sub"));
3157 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3161 void
3162 gfc_resolve_sleep_sub (gfc_code *c)
3164 const char *name;
3165 int kind;
3167 if (c->ext.actual->expr != NULL)
3168 kind = c->ext.actual->expr->ts.kind;
3169 else
3170 kind = gfc_default_integer_kind;
3172 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
3173 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3177 /* G77 compatibility function srand(). */
3179 void
3180 gfc_resolve_srand (gfc_code *c)
3182 const char *name;
3183 name = gfc_get_string (PREFIX ("srand"));
3184 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3188 /* Resolve the getarg intrinsic subroutine. */
3190 void
3191 gfc_resolve_getarg (gfc_code *c)
3193 const char *name;
3195 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
3197 gfc_typespec ts;
3198 gfc_clear_ts (&ts);
3200 ts.type = BT_INTEGER;
3201 ts.kind = gfc_default_integer_kind;
3203 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3206 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
3207 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3211 /* Resolve the getcwd intrinsic subroutine. */
3213 void
3214 gfc_resolve_getcwd_sub (gfc_code *c)
3216 const char *name;
3217 int kind;
3219 if (c->ext.actual->next->expr != NULL)
3220 kind = c->ext.actual->next->expr->ts.kind;
3221 else
3222 kind = gfc_default_integer_kind;
3224 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
3225 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3229 /* Resolve the get_command intrinsic subroutine. */
3231 void
3232 gfc_resolve_get_command (gfc_code *c)
3234 const char *name;
3235 int kind;
3236 kind = gfc_default_integer_kind;
3237 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
3238 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3242 /* Resolve the get_command_argument intrinsic subroutine. */
3244 void
3245 gfc_resolve_get_command_argument (gfc_code *c)
3247 const char *name;
3248 int kind;
3249 kind = gfc_default_integer_kind;
3250 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
3251 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3255 /* Resolve the get_environment_variable intrinsic subroutine. */
3257 void
3258 gfc_resolve_get_environment_variable (gfc_code *code)
3260 const char *name;
3261 int kind;
3262 kind = gfc_default_integer_kind;
3263 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
3264 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3268 void
3269 gfc_resolve_signal_sub (gfc_code *c)
3271 const char *name;
3272 gfc_expr *number, *handler, *status;
3273 gfc_typespec ts;
3274 gfc_clear_ts (&ts);
3276 number = c->ext.actual->expr;
3277 handler = c->ext.actual->next->expr;
3278 status = c->ext.actual->next->next->expr;
3279 ts.type = BT_INTEGER;
3280 ts.kind = gfc_c_int_kind;
3282 /* handler can be either BT_INTEGER or BT_PROCEDURE */
3283 if (handler->ts.type == BT_INTEGER)
3285 if (handler->ts.kind != gfc_c_int_kind)
3286 gfc_convert_type (handler, &ts, 2);
3287 name = gfc_get_string (PREFIX ("signal_sub_int"));
3289 else
3290 name = gfc_get_string (PREFIX ("signal_sub"));
3292 if (number->ts.kind != gfc_c_int_kind)
3293 gfc_convert_type (number, &ts, 2);
3294 if (status != NULL && status->ts.kind != gfc_c_int_kind)
3295 gfc_convert_type (status, &ts, 2);
3297 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3301 /* Resolve the SYSTEM intrinsic subroutine. */
3303 void
3304 gfc_resolve_system_sub (gfc_code *c)
3306 const char *name;
3307 name = gfc_get_string (PREFIX ("system_sub"));
3308 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3312 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
3314 void
3315 gfc_resolve_system_clock (gfc_code *c)
3317 const char *name;
3318 int kind;
3319 gfc_expr *count = c->ext.actual->expr;
3320 gfc_expr *count_max = c->ext.actual->next->next->expr;
3322 /* The INTEGER(8) version has higher precision, it is used if both COUNT
3323 and COUNT_MAX can hold 64-bit values, or are absent. */
3324 if ((!count || count->ts.kind >= 8)
3325 && (!count_max || count_max->ts.kind >= 8))
3326 kind = 8;
3327 else
3328 kind = gfc_default_integer_kind;
3330 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
3331 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3335 /* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine. */
3336 void
3337 gfc_resolve_execute_command_line (gfc_code *c)
3339 const char *name;
3340 name = gfc_get_string (PREFIX ("execute_command_line_i%d"),
3341 gfc_default_integer_kind);
3342 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3346 /* Resolve the EXIT intrinsic subroutine. */
3348 void
3349 gfc_resolve_exit (gfc_code *c)
3351 const char *name;
3352 gfc_typespec ts;
3353 gfc_expr *n;
3354 gfc_clear_ts (&ts);
3356 /* The STATUS argument has to be of default kind. If it is not,
3357 we convert it. */
3358 ts.type = BT_INTEGER;
3359 ts.kind = gfc_default_integer_kind;
3360 n = c->ext.actual->expr;
3361 if (n != NULL && n->ts.kind != ts.kind)
3362 gfc_convert_type (n, &ts, 2);
3364 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
3365 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3369 /* Resolve the FLUSH intrinsic subroutine. */
3371 void
3372 gfc_resolve_flush (gfc_code *c)
3374 const char *name;
3375 gfc_typespec ts;
3376 gfc_expr *n;
3377 gfc_clear_ts (&ts);
3379 ts.type = BT_INTEGER;
3380 ts.kind = gfc_default_integer_kind;
3381 n = c->ext.actual->expr;
3382 if (n != NULL && n->ts.kind != ts.kind)
3383 gfc_convert_type (n, &ts, 2);
3385 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
3386 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3390 void
3391 gfc_resolve_free (gfc_code *c)
3393 gfc_typespec ts;
3394 gfc_expr *n;
3395 gfc_clear_ts (&ts);
3397 ts.type = BT_INTEGER;
3398 ts.kind = gfc_index_integer_kind;
3399 n = c->ext.actual->expr;
3400 if (n->ts.kind != ts.kind)
3401 gfc_convert_type (n, &ts, 2);
3403 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
3407 void
3408 gfc_resolve_ctime_sub (gfc_code *c)
3410 gfc_typespec ts;
3411 gfc_clear_ts (&ts);
3413 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3414 if (c->ext.actual->expr->ts.kind != 8)
3416 ts.type = BT_INTEGER;
3417 ts.kind = 8;
3418 ts.u.derived = NULL;
3419 ts.u.cl = NULL;
3420 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3423 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3427 void
3428 gfc_resolve_fdate_sub (gfc_code *c)
3430 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3434 void
3435 gfc_resolve_gerror (gfc_code *c)
3437 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3441 void
3442 gfc_resolve_getlog (gfc_code *c)
3444 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3448 void
3449 gfc_resolve_hostnm_sub (gfc_code *c)
3451 const char *name;
3452 int kind;
3454 if (c->ext.actual->next->expr != NULL)
3455 kind = c->ext.actual->next->expr->ts.kind;
3456 else
3457 kind = gfc_default_integer_kind;
3459 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3460 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3464 void
3465 gfc_resolve_perror (gfc_code *c)
3467 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3470 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3472 void
3473 gfc_resolve_stat_sub (gfc_code *c)
3475 const char *name;
3476 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3477 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3481 void
3482 gfc_resolve_lstat_sub (gfc_code *c)
3484 const char *name;
3485 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3486 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3490 void
3491 gfc_resolve_fstat_sub (gfc_code *c)
3493 const char *name;
3494 gfc_expr *u;
3495 gfc_typespec *ts;
3497 u = c->ext.actual->expr;
3498 ts = &c->ext.actual->next->expr->ts;
3499 if (u->ts.kind != ts->kind)
3500 gfc_convert_type (u, ts, 2);
3501 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3502 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3506 void
3507 gfc_resolve_fgetc_sub (gfc_code *c)
3509 const char *name;
3510 gfc_typespec ts;
3511 gfc_expr *u, *st;
3512 gfc_clear_ts (&ts);
3514 u = c->ext.actual->expr;
3515 st = c->ext.actual->next->next->expr;
3517 if (u->ts.kind != gfc_c_int_kind)
3519 ts.type = BT_INTEGER;
3520 ts.kind = gfc_c_int_kind;
3521 ts.u.derived = NULL;
3522 ts.u.cl = NULL;
3523 gfc_convert_type (u, &ts, 2);
3526 if (st != NULL)
3527 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3528 else
3529 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3531 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3535 void
3536 gfc_resolve_fget_sub (gfc_code *c)
3538 const char *name;
3539 gfc_expr *st;
3541 st = c->ext.actual->next->expr;
3542 if (st != NULL)
3543 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3544 else
3545 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3547 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3551 void
3552 gfc_resolve_fputc_sub (gfc_code *c)
3554 const char *name;
3555 gfc_typespec ts;
3556 gfc_expr *u, *st;
3557 gfc_clear_ts (&ts);
3559 u = c->ext.actual->expr;
3560 st = c->ext.actual->next->next->expr;
3562 if (u->ts.kind != gfc_c_int_kind)
3564 ts.type = BT_INTEGER;
3565 ts.kind = gfc_c_int_kind;
3566 ts.u.derived = NULL;
3567 ts.u.cl = NULL;
3568 gfc_convert_type (u, &ts, 2);
3571 if (st != NULL)
3572 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3573 else
3574 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3576 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3580 void
3581 gfc_resolve_fput_sub (gfc_code *c)
3583 const char *name;
3584 gfc_expr *st;
3586 st = c->ext.actual->next->expr;
3587 if (st != NULL)
3588 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3589 else
3590 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3592 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3596 void
3597 gfc_resolve_fseek_sub (gfc_code *c)
3599 gfc_expr *unit;
3600 gfc_expr *offset;
3601 gfc_expr *whence;
3602 gfc_typespec ts;
3603 gfc_clear_ts (&ts);
3605 unit = c->ext.actual->expr;
3606 offset = c->ext.actual->next->expr;
3607 whence = c->ext.actual->next->next->expr;
3609 if (unit->ts.kind != gfc_c_int_kind)
3611 ts.type = BT_INTEGER;
3612 ts.kind = gfc_c_int_kind;
3613 ts.u.derived = NULL;
3614 ts.u.cl = NULL;
3615 gfc_convert_type (unit, &ts, 2);
3618 if (offset->ts.kind != gfc_intio_kind)
3620 ts.type = BT_INTEGER;
3621 ts.kind = gfc_intio_kind;
3622 ts.u.derived = NULL;
3623 ts.u.cl = NULL;
3624 gfc_convert_type (offset, &ts, 2);
3627 if (whence->ts.kind != gfc_c_int_kind)
3629 ts.type = BT_INTEGER;
3630 ts.kind = gfc_c_int_kind;
3631 ts.u.derived = NULL;
3632 ts.u.cl = NULL;
3633 gfc_convert_type (whence, &ts, 2);
3636 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3639 void
3640 gfc_resolve_ftell_sub (gfc_code *c)
3642 const char *name;
3643 gfc_expr *unit;
3644 gfc_expr *offset;
3645 gfc_typespec ts;
3646 gfc_clear_ts (&ts);
3648 unit = c->ext.actual->expr;
3649 offset = c->ext.actual->next->expr;
3651 if (unit->ts.kind != gfc_c_int_kind)
3653 ts.type = BT_INTEGER;
3654 ts.kind = gfc_c_int_kind;
3655 ts.u.derived = NULL;
3656 ts.u.cl = NULL;
3657 gfc_convert_type (unit, &ts, 2);
3660 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3661 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3665 void
3666 gfc_resolve_ttynam_sub (gfc_code *c)
3668 gfc_typespec ts;
3669 gfc_clear_ts (&ts);
3671 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3673 ts.type = BT_INTEGER;
3674 ts.kind = gfc_c_int_kind;
3675 ts.u.derived = NULL;
3676 ts.u.cl = NULL;
3677 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3680 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3684 /* Resolve the UMASK intrinsic subroutine. */
3686 void
3687 gfc_resolve_umask_sub (gfc_code *c)
3689 const char *name;
3690 int kind;
3692 if (c->ext.actual->next->expr != NULL)
3693 kind = c->ext.actual->next->expr->ts.kind;
3694 else
3695 kind = gfc_default_integer_kind;
3697 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3698 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3701 /* Resolve the UNLINK intrinsic subroutine. */
3703 void
3704 gfc_resolve_unlink_sub (gfc_code *c)
3706 const char *name;
3707 int kind;
3709 if (c->ext.actual->next->expr != NULL)
3710 kind = c->ext.actual->next->expr->ts.kind;
3711 else
3712 kind = gfc_default_integer_kind;
3714 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3715 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);