Update ChangeLog and version files for release
[official-gcc.git] / gcc / fortran / iresolve.c
blobecea1c3a714a25f1a170f48afe7db5034cae7f6a
1 /* Intrinsic function resolution.
2 Copyright (C) 2000-2016 Free Software Foundation, Inc.
3 Contributed by Andy Vaught & Katherine Holcomb
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 /* Assign name and types to intrinsic procedures. For functions, the
23 first argument to a resolution function is an expression pointer to
24 the original function node and the rest are pointers to the
25 arguments of the function call. For subroutines, a pointer to the
26 code node is passed. The result type and library subroutine name
27 are generally set according to the function arguments. */
29 #include "config.h"
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tree.h"
33 #include "gfortran.h"
34 #include "stringpool.h"
35 #include "intrinsic.h"
36 #include "constructor.h"
37 #include "arith.h"
39 /* Given printf-like arguments, return a stable version of the result string.
41 We already have a working, optimized string hashing table in the form of
42 the identifier table. Reusing this table is likely not to be wasted,
43 since if the function name makes it to the gimple output of the frontend,
44 we'll have to create the identifier anyway. */
46 const char *
47 gfc_get_string (const char *format, ...)
49 char temp_name[128];
50 va_list ap;
51 tree ident;
53 va_start (ap, format);
54 vsnprintf (temp_name, sizeof (temp_name), format, ap);
55 va_end (ap);
56 temp_name[sizeof (temp_name) - 1] = 0;
58 ident = get_identifier (temp_name);
59 return IDENTIFIER_POINTER (ident);
62 /* MERGE and SPREAD need to have source charlen's present for passing
63 to the result expression. */
64 static void
65 check_charlen_present (gfc_expr *source)
67 if (source->ts.u.cl == NULL)
68 source->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
70 if (source->expr_type == EXPR_CONSTANT)
72 source->ts.u.cl->length
73 = gfc_get_int_expr (gfc_default_integer_kind, NULL,
74 source->value.character.length);
75 source->rank = 0;
77 else if (source->expr_type == EXPR_ARRAY)
79 gfc_constructor *c = gfc_constructor_first (source->value.constructor);
80 source->ts.u.cl->length
81 = gfc_get_int_expr (gfc_default_integer_kind, NULL,
82 c->expr->value.character.length);
86 /* Helper function for resolving the "mask" argument. */
88 static void
89 resolve_mask_arg (gfc_expr *mask)
92 gfc_typespec ts;
93 gfc_clear_ts (&ts);
95 if (mask->rank == 0)
97 /* For the scalar case, coerce the mask to kind=4 unconditionally
98 (because this is the only kind we have a library function
99 for). */
101 if (mask->ts.kind != 4)
103 ts.type = BT_LOGICAL;
104 ts.kind = 4;
105 gfc_convert_type (mask, &ts, 2);
108 else
110 /* In the library, we access the mask with a GFC_LOGICAL_1
111 argument. No need to waste memory if we are about to create
112 a temporary array. */
113 if (mask->expr_type == EXPR_OP && mask->ts.kind != 1)
115 ts.type = BT_LOGICAL;
116 ts.kind = 1;
117 gfc_convert_type_warn (mask, &ts, 2, 0);
123 static void
124 resolve_bound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind,
125 const char *name, bool coarray)
127 f->ts.type = BT_INTEGER;
128 if (kind)
129 f->ts.kind = mpz_get_si (kind->value.integer);
130 else
131 f->ts.kind = gfc_default_integer_kind;
133 if (dim == NULL)
135 f->rank = 1;
136 if (array->rank != -1)
138 f->shape = gfc_get_shape (1);
139 mpz_init_set_ui (f->shape[0], coarray ? gfc_get_corank (array)
140 : array->rank);
144 f->value.function.name = gfc_get_string (name);
148 static void
149 resolve_transformational (const char *name, gfc_expr *f, gfc_expr *array,
150 gfc_expr *dim, gfc_expr *mask)
152 const char *prefix;
154 f->ts = array->ts;
156 if (mask)
158 if (mask->rank == 0)
159 prefix = "s";
160 else
161 prefix = "m";
163 resolve_mask_arg (mask);
165 else
166 prefix = "";
168 if (dim != NULL)
170 f->rank = array->rank - 1;
171 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
172 gfc_resolve_dim_arg (dim);
175 f->value.function.name
176 = gfc_get_string (PREFIX ("%s%s_%c%d"), prefix, name,
177 gfc_type_letter (array->ts.type), array->ts.kind);
181 /********************** Resolution functions **********************/
184 void
185 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
187 f->ts = a->ts;
188 if (f->ts.type == BT_COMPLEX)
189 f->ts.type = BT_REAL;
191 f->value.function.name
192 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
196 void
197 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
198 gfc_expr *mode ATTRIBUTE_UNUSED)
200 f->ts.type = BT_INTEGER;
201 f->ts.kind = gfc_c_int_kind;
202 f->value.function.name = PREFIX ("access_func");
206 void
207 gfc_resolve_adjustl (gfc_expr *f, gfc_expr *string)
209 f->ts.type = BT_CHARACTER;
210 f->ts.kind = string->ts.kind;
211 if (string->ts.u.cl)
212 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, string->ts.u.cl);
214 f->value.function.name = gfc_get_string ("__adjustl_s%d", f->ts.kind);
218 void
219 gfc_resolve_adjustr (gfc_expr *f, gfc_expr *string)
221 f->ts.type = BT_CHARACTER;
222 f->ts.kind = string->ts.kind;
223 if (string->ts.u.cl)
224 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, string->ts.u.cl);
226 f->value.function.name = gfc_get_string ("__adjustr_s%d", f->ts.kind);
230 static void
231 gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind,
232 const char *name)
234 f->ts.type = BT_CHARACTER;
235 f->ts.kind = (kind == NULL)
236 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
237 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
238 f->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
240 f->value.function.name = gfc_get_string (name, f->ts.kind,
241 gfc_type_letter (x->ts.type),
242 x->ts.kind);
246 void
247 gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
249 gfc_resolve_char_achar (f, x, kind, "__achar_%d_%c%d");
253 void
254 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
256 f->ts = x->ts;
257 f->value.function.name
258 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
262 void
263 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
265 f->ts = x->ts;
266 f->value.function.name
267 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
268 x->ts.kind);
272 void
273 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
275 f->ts.type = BT_REAL;
276 f->ts.kind = x->ts.kind;
277 f->value.function.name
278 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
279 x->ts.kind);
283 void
284 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
286 f->ts.type = i->ts.type;
287 f->ts.kind = gfc_kind_max (i, j);
289 if (i->ts.kind != j->ts.kind)
291 if (i->ts.kind == gfc_kind_max (i, j))
292 gfc_convert_type (j, &i->ts, 2);
293 else
294 gfc_convert_type (i, &j->ts, 2);
297 f->value.function.name
298 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
302 void
303 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
305 gfc_typespec ts;
306 gfc_clear_ts (&ts);
308 f->ts.type = a->ts.type;
309 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
311 if (a->ts.kind != f->ts.kind)
313 ts.type = f->ts.type;
314 ts.kind = f->ts.kind;
315 gfc_convert_type (a, &ts, 2);
317 /* The resolved name is only used for specific intrinsics where
318 the return kind is the same as the arg kind. */
319 f->value.function.name
320 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
324 void
325 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
327 gfc_resolve_aint (f, a, NULL);
331 void
332 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
334 f->ts = mask->ts;
336 if (dim != NULL)
338 gfc_resolve_dim_arg (dim);
339 f->rank = mask->rank - 1;
340 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
343 f->value.function.name
344 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
345 mask->ts.kind);
349 void
350 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
352 gfc_typespec ts;
353 gfc_clear_ts (&ts);
355 f->ts.type = a->ts.type;
356 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
358 if (a->ts.kind != f->ts.kind)
360 ts.type = f->ts.type;
361 ts.kind = f->ts.kind;
362 gfc_convert_type (a, &ts, 2);
365 /* The resolved name is only used for specific intrinsics where
366 the return kind is the same as the arg kind. */
367 f->value.function.name
368 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
369 a->ts.kind);
373 void
374 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
376 gfc_resolve_anint (f, a, NULL);
380 void
381 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
383 f->ts = mask->ts;
385 if (dim != NULL)
387 gfc_resolve_dim_arg (dim);
388 f->rank = mask->rank - 1;
389 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
392 f->value.function.name
393 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
394 mask->ts.kind);
398 void
399 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
401 f->ts = x->ts;
402 f->value.function.name
403 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
406 void
407 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
409 f->ts = x->ts;
410 f->value.function.name
411 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
412 x->ts.kind);
415 void
416 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
418 f->ts = x->ts;
419 f->value.function.name
420 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
423 void
424 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
426 f->ts = x->ts;
427 f->value.function.name
428 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
429 x->ts.kind);
432 void
433 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
435 f->ts = x->ts;
436 f->value.function.name
437 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
438 x->ts.kind);
442 /* Resolve the BESYN and BESJN intrinsics. */
444 void
445 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
447 gfc_typespec ts;
448 gfc_clear_ts (&ts);
450 f->ts = x->ts;
451 if (n->ts.kind != gfc_c_int_kind)
453 ts.type = BT_INTEGER;
454 ts.kind = gfc_c_int_kind;
455 gfc_convert_type (n, &ts, 2);
457 f->value.function.name = gfc_get_string ("<intrinsic>");
461 void
462 gfc_resolve_bessel_n2 (gfc_expr *f, gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
464 gfc_typespec ts;
465 gfc_clear_ts (&ts);
467 f->ts = x->ts;
468 f->rank = 1;
469 if (n1->expr_type == EXPR_CONSTANT && n2->expr_type == EXPR_CONSTANT)
471 f->shape = gfc_get_shape (1);
472 mpz_init (f->shape[0]);
473 mpz_sub (f->shape[0], n2->value.integer, n1->value.integer);
474 mpz_add_ui (f->shape[0], f->shape[0], 1);
477 if (n1->ts.kind != gfc_c_int_kind)
479 ts.type = BT_INTEGER;
480 ts.kind = gfc_c_int_kind;
481 gfc_convert_type (n1, &ts, 2);
484 if (n2->ts.kind != gfc_c_int_kind)
486 ts.type = BT_INTEGER;
487 ts.kind = gfc_c_int_kind;
488 gfc_convert_type (n2, &ts, 2);
491 if (f->value.function.isym->id == GFC_ISYM_JN2)
492 f->value.function.name = gfc_get_string (PREFIX ("bessel_jn_r%d"),
493 f->ts.kind);
494 else
495 f->value.function.name = gfc_get_string (PREFIX ("bessel_yn_r%d"),
496 f->ts.kind);
500 void
501 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
503 f->ts.type = BT_LOGICAL;
504 f->ts.kind = gfc_default_logical_kind;
505 f->value.function.name
506 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
510 void
511 gfc_resolve_c_loc (gfc_expr *f, gfc_expr *x ATTRIBUTE_UNUSED)
513 f->ts = f->value.function.isym->ts;
517 void
518 gfc_resolve_c_funloc (gfc_expr *f, gfc_expr *x ATTRIBUTE_UNUSED)
520 f->ts = f->value.function.isym->ts;
524 void
525 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
527 f->ts.type = BT_INTEGER;
528 f->ts.kind = (kind == NULL)
529 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
530 f->value.function.name
531 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
532 gfc_type_letter (a->ts.type), a->ts.kind);
536 void
537 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
539 gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d");
543 void
544 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
546 f->ts.type = BT_INTEGER;
547 f->ts.kind = gfc_default_integer_kind;
548 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
552 void
553 gfc_resolve_chdir_sub (gfc_code *c)
555 const char *name;
556 int kind;
558 if (c->ext.actual->next->expr != NULL)
559 kind = c->ext.actual->next->expr->ts.kind;
560 else
561 kind = gfc_default_integer_kind;
563 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
564 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
568 void
569 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
570 gfc_expr *mode ATTRIBUTE_UNUSED)
572 f->ts.type = BT_INTEGER;
573 f->ts.kind = gfc_c_int_kind;
574 f->value.function.name = PREFIX ("chmod_func");
578 void
579 gfc_resolve_chmod_sub (gfc_code *c)
581 const char *name;
582 int kind;
584 if (c->ext.actual->next->next->expr != NULL)
585 kind = c->ext.actual->next->next->expr->ts.kind;
586 else
587 kind = gfc_default_integer_kind;
589 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
590 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
594 void
595 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
597 f->ts.type = BT_COMPLEX;
598 f->ts.kind = (kind == NULL)
599 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
601 if (y == NULL)
602 f->value.function.name
603 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
604 gfc_type_letter (x->ts.type), x->ts.kind);
605 else
606 f->value.function.name
607 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
608 gfc_type_letter (x->ts.type), x->ts.kind,
609 gfc_type_letter (y->ts.type), y->ts.kind);
613 void
614 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
616 gfc_resolve_cmplx (f, x, y, gfc_get_int_expr (gfc_default_integer_kind, NULL,
617 gfc_default_double_kind));
621 void
622 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
624 int kind;
626 if (x->ts.type == BT_INTEGER)
628 if (y->ts.type == BT_INTEGER)
629 kind = gfc_default_real_kind;
630 else
631 kind = y->ts.kind;
633 else
635 if (y->ts.type == BT_REAL)
636 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
637 else
638 kind = x->ts.kind;
641 f->ts.type = BT_COMPLEX;
642 f->ts.kind = kind;
643 f->value.function.name
644 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
645 gfc_type_letter (x->ts.type), x->ts.kind,
646 gfc_type_letter (y->ts.type), y->ts.kind);
650 void
651 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
653 f->ts = x->ts;
654 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
658 void
659 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
661 f->ts = x->ts;
662 f->value.function.name
663 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
667 void
668 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
670 f->ts = x->ts;
671 f->value.function.name
672 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
676 void
677 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
679 f->ts.type = BT_INTEGER;
680 if (kind)
681 f->ts.kind = mpz_get_si (kind->value.integer);
682 else
683 f->ts.kind = gfc_default_integer_kind;
685 if (dim != NULL)
687 f->rank = mask->rank - 1;
688 gfc_resolve_dim_arg (dim);
689 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
692 resolve_mask_arg (mask);
694 f->value.function.name
695 = gfc_get_string (PREFIX ("count_%d_%c"), f->ts.kind,
696 gfc_type_letter (mask->ts.type));
700 void
701 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
702 gfc_expr *dim)
704 int n, m;
706 if (array->ts.type == BT_CHARACTER && array->ref)
707 gfc_resolve_substring_charlen (array);
709 f->ts = array->ts;
710 f->rank = array->rank;
711 f->shape = gfc_copy_shape (array->shape, array->rank);
713 if (shift->rank > 0)
714 n = 1;
715 else
716 n = 0;
718 /* If dim kind is greater than default integer we need to use the larger. */
719 m = gfc_default_integer_kind;
720 if (dim != NULL)
721 m = m < dim->ts.kind ? dim->ts.kind : m;
723 /* Convert shift to at least m, so we don't need
724 kind=1 and kind=2 versions of the library functions. */
725 if (shift->ts.kind < m)
727 gfc_typespec ts;
728 gfc_clear_ts (&ts);
729 ts.type = BT_INTEGER;
730 ts.kind = m;
731 gfc_convert_type_warn (shift, &ts, 2, 0);
734 if (dim != NULL)
736 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
737 && dim->symtree->n.sym->attr.optional)
739 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
740 dim->representation.length = shift->ts.kind;
742 else
744 gfc_resolve_dim_arg (dim);
745 /* Convert dim to shift's kind to reduce variations. */
746 if (dim->ts.kind != shift->ts.kind)
747 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
751 if (array->ts.type == BT_CHARACTER)
753 if (array->ts.kind == gfc_default_character_kind)
754 f->value.function.name
755 = gfc_get_string (PREFIX ("cshift%d_%d_char"), n, shift->ts.kind);
756 else
757 f->value.function.name
758 = gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n, shift->ts.kind,
759 array->ts.kind);
761 else
762 f->value.function.name
763 = gfc_get_string (PREFIX ("cshift%d_%d"), n, shift->ts.kind);
767 void
768 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
770 gfc_typespec ts;
771 gfc_clear_ts (&ts);
773 f->ts.type = BT_CHARACTER;
774 f->ts.kind = gfc_default_character_kind;
776 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
777 if (time->ts.kind != 8)
779 ts.type = BT_INTEGER;
780 ts.kind = 8;
781 ts.u.derived = NULL;
782 ts.u.cl = NULL;
783 gfc_convert_type (time, &ts, 2);
786 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
790 void
791 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
793 f->ts.type = BT_REAL;
794 f->ts.kind = gfc_default_double_kind;
795 f->value.function.name
796 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
800 void
801 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
803 f->ts.type = a->ts.type;
804 if (p != NULL)
805 f->ts.kind = gfc_kind_max (a,p);
806 else
807 f->ts.kind = a->ts.kind;
809 if (p != NULL && a->ts.kind != p->ts.kind)
811 if (a->ts.kind == gfc_kind_max (a,p))
812 gfc_convert_type (p, &a->ts, 2);
813 else
814 gfc_convert_type (a, &p->ts, 2);
817 f->value.function.name
818 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
822 void
823 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
825 gfc_expr temp;
827 temp.expr_type = EXPR_OP;
828 gfc_clear_ts (&temp.ts);
829 temp.value.op.op = INTRINSIC_NONE;
830 temp.value.op.op1 = a;
831 temp.value.op.op2 = b;
832 gfc_type_convert_binary (&temp, 1);
833 f->ts = temp.ts;
834 f->value.function.name
835 = gfc_get_string (PREFIX ("dot_product_%c%d"),
836 gfc_type_letter (f->ts.type), f->ts.kind);
840 void
841 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
842 gfc_expr *b ATTRIBUTE_UNUSED)
844 f->ts.kind = gfc_default_double_kind;
845 f->ts.type = BT_REAL;
846 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
850 void
851 gfc_resolve_dshift (gfc_expr *f, gfc_expr *i, gfc_expr *j ATTRIBUTE_UNUSED,
852 gfc_expr *shift ATTRIBUTE_UNUSED)
854 f->ts = i->ts;
855 if (f->value.function.isym->id == GFC_ISYM_DSHIFTL)
856 f->value.function.name = gfc_get_string ("dshiftl_i%d", f->ts.kind);
857 else if (f->value.function.isym->id == GFC_ISYM_DSHIFTR)
858 f->value.function.name = gfc_get_string ("dshiftr_i%d", f->ts.kind);
859 else
860 gcc_unreachable ();
864 void
865 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
866 gfc_expr *boundary, gfc_expr *dim)
868 int n, m;
870 if (array->ts.type == BT_CHARACTER && array->ref)
871 gfc_resolve_substring_charlen (array);
873 f->ts = array->ts;
874 f->rank = array->rank;
875 f->shape = gfc_copy_shape (array->shape, array->rank);
877 n = 0;
878 if (shift->rank > 0)
879 n = n | 1;
880 if (boundary && boundary->rank > 0)
881 n = n | 2;
883 /* If dim kind is greater than default integer we need to use the larger. */
884 m = gfc_default_integer_kind;
885 if (dim != NULL)
886 m = m < dim->ts.kind ? dim->ts.kind : m;
888 /* Convert shift to at least m, so we don't need
889 kind=1 and kind=2 versions of the library functions. */
890 if (shift->ts.kind < m)
892 gfc_typespec ts;
893 gfc_clear_ts (&ts);
894 ts.type = BT_INTEGER;
895 ts.kind = m;
896 gfc_convert_type_warn (shift, &ts, 2, 0);
899 if (dim != NULL)
901 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
902 && dim->symtree->n.sym->attr.optional)
904 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
905 dim->representation.length = shift->ts.kind;
907 else
909 gfc_resolve_dim_arg (dim);
910 /* Convert dim to shift's kind to reduce variations. */
911 if (dim->ts.kind != shift->ts.kind)
912 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
916 if (array->ts.type == BT_CHARACTER)
918 if (array->ts.kind == gfc_default_character_kind)
919 f->value.function.name
920 = gfc_get_string (PREFIX ("eoshift%d_%d_char"), n, shift->ts.kind);
921 else
922 f->value.function.name
923 = gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n, shift->ts.kind,
924 array->ts.kind);
926 else
927 f->value.function.name
928 = gfc_get_string (PREFIX ("eoshift%d_%d"), n, shift->ts.kind);
932 void
933 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
935 f->ts = x->ts;
936 f->value.function.name
937 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
941 void
942 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
944 f->ts.type = BT_INTEGER;
945 f->ts.kind = gfc_default_integer_kind;
946 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
950 /* Resolve the EXTENDS_TYPE_OF intrinsic function. */
952 void
953 gfc_resolve_extends_type_of (gfc_expr *f, gfc_expr *a, gfc_expr *mo)
955 gfc_symbol *vtab;
956 gfc_symtree *st;
958 /* Prevent double resolution. */
959 if (f->ts.type == BT_LOGICAL)
960 return;
962 /* Replace the first argument with the corresponding vtab. */
963 if (a->ts.type == BT_CLASS)
964 gfc_add_vptr_component (a);
965 else if (a->ts.type == BT_DERIVED)
967 vtab = gfc_find_derived_vtab (a->ts.u.derived);
968 /* Clear the old expr. */
969 gfc_free_ref_list (a->ref);
970 memset (a, '\0', sizeof (gfc_expr));
971 /* Construct a new one. */
972 a->expr_type = EXPR_VARIABLE;
973 st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
974 a->symtree = st;
975 a->ts = vtab->ts;
978 /* Replace the second argument with the corresponding vtab. */
979 if (mo->ts.type == BT_CLASS)
980 gfc_add_vptr_component (mo);
981 else if (mo->ts.type == BT_DERIVED)
983 vtab = gfc_find_derived_vtab (mo->ts.u.derived);
984 /* Clear the old expr. */
985 gfc_free_ref_list (mo->ref);
986 memset (mo, '\0', sizeof (gfc_expr));
987 /* Construct a new one. */
988 mo->expr_type = EXPR_VARIABLE;
989 st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
990 mo->symtree = st;
991 mo->ts = vtab->ts;
994 f->ts.type = BT_LOGICAL;
995 f->ts.kind = 4;
997 f->value.function.isym->formal->ts = a->ts;
998 f->value.function.isym->formal->next->ts = mo->ts;
1000 /* Call library function. */
1001 f->value.function.name = gfc_get_string (PREFIX ("is_extension_of"));
1005 void
1006 gfc_resolve_fdate (gfc_expr *f)
1008 f->ts.type = BT_CHARACTER;
1009 f->ts.kind = gfc_default_character_kind;
1010 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
1014 void
1015 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1017 f->ts.type = BT_INTEGER;
1018 f->ts.kind = (kind == NULL)
1019 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1020 f->value.function.name
1021 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
1022 gfc_type_letter (a->ts.type), a->ts.kind);
1026 void
1027 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
1029 f->ts.type = BT_INTEGER;
1030 f->ts.kind = gfc_default_integer_kind;
1031 if (n->ts.kind != f->ts.kind)
1032 gfc_convert_type (n, &f->ts, 2);
1033 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
1037 void
1038 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
1040 f->ts = x->ts;
1041 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
1045 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
1047 void
1048 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
1050 f->ts = x->ts;
1051 f->value.function.name = gfc_get_string ("<intrinsic>");
1055 void
1056 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
1058 f->ts = x->ts;
1059 f->value.function.name
1060 = gfc_get_string ("__tgamma_%d", x->ts.kind);
1064 void
1065 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
1067 f->ts.type = BT_INTEGER;
1068 f->ts.kind = 4;
1069 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
1073 void
1074 gfc_resolve_getgid (gfc_expr *f)
1076 f->ts.type = BT_INTEGER;
1077 f->ts.kind = 4;
1078 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
1082 void
1083 gfc_resolve_getpid (gfc_expr *f)
1085 f->ts.type = BT_INTEGER;
1086 f->ts.kind = 4;
1087 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
1091 void
1092 gfc_resolve_getuid (gfc_expr *f)
1094 f->ts.type = BT_INTEGER;
1095 f->ts.kind = 4;
1096 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
1100 void
1101 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
1103 f->ts.type = BT_INTEGER;
1104 f->ts.kind = 4;
1105 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
1109 void
1110 gfc_resolve_hypot (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
1112 f->ts = x->ts;
1113 f->value.function.name = gfc_get_string ("__hypot_r%d", x->ts.kind);
1117 void
1118 gfc_resolve_iall (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1120 resolve_transformational ("iall", f, array, dim, mask);
1124 void
1125 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1127 /* If the kind of i and j are different, then g77 cross-promoted the
1128 kinds to the largest value. The Fortran 95 standard requires the
1129 kinds to match. */
1130 if (i->ts.kind != j->ts.kind)
1132 if (i->ts.kind == gfc_kind_max (i, j))
1133 gfc_convert_type (j, &i->ts, 2);
1134 else
1135 gfc_convert_type (i, &j->ts, 2);
1138 f->ts = i->ts;
1139 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
1143 void
1144 gfc_resolve_iany (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1146 resolve_transformational ("iany", f, array, dim, mask);
1150 void
1151 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1153 f->ts = i->ts;
1154 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
1158 void
1159 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
1160 gfc_expr *len ATTRIBUTE_UNUSED)
1162 f->ts = i->ts;
1163 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
1167 void
1168 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1170 f->ts = i->ts;
1171 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
1175 void
1176 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1178 f->ts.type = BT_INTEGER;
1179 if (kind)
1180 f->ts.kind = mpz_get_si (kind->value.integer);
1181 else
1182 f->ts.kind = gfc_default_integer_kind;
1183 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1187 void
1188 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1190 f->ts.type = BT_INTEGER;
1191 if (kind)
1192 f->ts.kind = mpz_get_si (kind->value.integer);
1193 else
1194 f->ts.kind = gfc_default_integer_kind;
1195 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1199 void
1200 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
1202 gfc_resolve_nint (f, a, NULL);
1206 void
1207 gfc_resolve_ierrno (gfc_expr *f)
1209 f->ts.type = BT_INTEGER;
1210 f->ts.kind = gfc_default_integer_kind;
1211 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
1215 void
1216 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1218 /* If the kind of i and j are different, then g77 cross-promoted the
1219 kinds to the largest value. The Fortran 95 standard requires the
1220 kinds to match. */
1221 if (i->ts.kind != j->ts.kind)
1223 if (i->ts.kind == gfc_kind_max (i, j))
1224 gfc_convert_type (j, &i->ts, 2);
1225 else
1226 gfc_convert_type (i, &j->ts, 2);
1229 f->ts = i->ts;
1230 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
1234 void
1235 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1237 /* If the kind of i and j are different, then g77 cross-promoted the
1238 kinds to the largest value. The Fortran 95 standard requires the
1239 kinds to match. */
1240 if (i->ts.kind != j->ts.kind)
1242 if (i->ts.kind == gfc_kind_max (i, j))
1243 gfc_convert_type (j, &i->ts, 2);
1244 else
1245 gfc_convert_type (i, &j->ts, 2);
1248 f->ts = i->ts;
1249 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
1253 void
1254 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
1255 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
1256 gfc_expr *kind)
1258 gfc_typespec ts;
1259 gfc_clear_ts (&ts);
1261 f->ts.type = BT_INTEGER;
1262 if (kind)
1263 f->ts.kind = mpz_get_si (kind->value.integer);
1264 else
1265 f->ts.kind = gfc_default_integer_kind;
1267 if (back && back->ts.kind != gfc_default_integer_kind)
1269 ts.type = BT_LOGICAL;
1270 ts.kind = gfc_default_integer_kind;
1271 ts.u.derived = NULL;
1272 ts.u.cl = NULL;
1273 gfc_convert_type (back, &ts, 2);
1276 f->value.function.name
1277 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
1281 void
1282 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1284 f->ts.type = BT_INTEGER;
1285 f->ts.kind = (kind == NULL)
1286 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1287 f->value.function.name
1288 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1289 gfc_type_letter (a->ts.type), a->ts.kind);
1293 void
1294 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1296 f->ts.type = BT_INTEGER;
1297 f->ts.kind = 2;
1298 f->value.function.name
1299 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1300 gfc_type_letter (a->ts.type), a->ts.kind);
1304 void
1305 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
1307 f->ts.type = BT_INTEGER;
1308 f->ts.kind = 8;
1309 f->value.function.name
1310 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1311 gfc_type_letter (a->ts.type), a->ts.kind);
1315 void
1316 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1318 f->ts.type = BT_INTEGER;
1319 f->ts.kind = 4;
1320 f->value.function.name
1321 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1322 gfc_type_letter (a->ts.type), a->ts.kind);
1326 void
1327 gfc_resolve_iparity (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1329 resolve_transformational ("iparity", f, array, dim, mask);
1333 void
1334 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1336 gfc_typespec ts;
1337 gfc_clear_ts (&ts);
1339 f->ts.type = BT_LOGICAL;
1340 f->ts.kind = gfc_default_integer_kind;
1341 if (u->ts.kind != gfc_c_int_kind)
1343 ts.type = BT_INTEGER;
1344 ts.kind = gfc_c_int_kind;
1345 ts.u.derived = NULL;
1346 ts.u.cl = NULL;
1347 gfc_convert_type (u, &ts, 2);
1350 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1354 void
1355 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1357 f->ts = i->ts;
1358 f->value.function.name
1359 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1363 void
1364 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1366 f->ts = i->ts;
1367 f->value.function.name
1368 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1372 void
1373 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1375 f->ts = i->ts;
1376 f->value.function.name
1377 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1381 void
1382 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1384 int s_kind;
1386 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1388 f->ts = i->ts;
1389 f->value.function.name
1390 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1394 void
1395 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1396 gfc_expr *s ATTRIBUTE_UNUSED)
1398 f->ts.type = BT_INTEGER;
1399 f->ts.kind = gfc_default_integer_kind;
1400 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1404 void
1405 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1407 resolve_bound (f, array, dim, kind, "__lbound", false);
1411 void
1412 gfc_resolve_lcobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1414 resolve_bound (f, array, dim, kind, "__lcobound", true);
1418 void
1419 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1421 f->ts.type = BT_INTEGER;
1422 if (kind)
1423 f->ts.kind = mpz_get_si (kind->value.integer);
1424 else
1425 f->ts.kind = gfc_default_integer_kind;
1426 f->value.function.name
1427 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1428 gfc_default_integer_kind);
1432 void
1433 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1435 f->ts.type = BT_INTEGER;
1436 if (kind)
1437 f->ts.kind = mpz_get_si (kind->value.integer);
1438 else
1439 f->ts.kind = gfc_default_integer_kind;
1440 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1444 void
1445 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1447 f->ts = x->ts;
1448 f->value.function.name
1449 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1453 void
1454 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1455 gfc_expr *p2 ATTRIBUTE_UNUSED)
1457 f->ts.type = BT_INTEGER;
1458 f->ts.kind = gfc_default_integer_kind;
1459 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1463 void
1464 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1466 f->ts.type= BT_INTEGER;
1467 f->ts.kind = gfc_index_integer_kind;
1468 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1472 void
1473 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1475 f->ts = x->ts;
1476 f->value.function.name
1477 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1481 void
1482 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1484 f->ts = x->ts;
1485 f->value.function.name
1486 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1487 x->ts.kind);
1491 void
1492 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1494 f->ts.type = BT_LOGICAL;
1495 f->ts.kind = (kind == NULL)
1496 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1497 f->rank = a->rank;
1499 f->value.function.name
1500 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1501 gfc_type_letter (a->ts.type), a->ts.kind);
1505 void
1506 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1508 gfc_expr temp;
1510 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1512 f->ts.type = BT_LOGICAL;
1513 f->ts.kind = gfc_default_logical_kind;
1515 else
1517 temp.expr_type = EXPR_OP;
1518 gfc_clear_ts (&temp.ts);
1519 temp.value.op.op = INTRINSIC_NONE;
1520 temp.value.op.op1 = a;
1521 temp.value.op.op2 = b;
1522 gfc_type_convert_binary (&temp, 1);
1523 f->ts = temp.ts;
1526 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1528 if (a->rank == 2 && b->rank == 2)
1530 if (a->shape && b->shape)
1532 f->shape = gfc_get_shape (f->rank);
1533 mpz_init_set (f->shape[0], a->shape[0]);
1534 mpz_init_set (f->shape[1], b->shape[1]);
1537 else if (a->rank == 1)
1539 if (b->shape)
1541 f->shape = gfc_get_shape (f->rank);
1542 mpz_init_set (f->shape[0], b->shape[1]);
1545 else
1547 /* b->rank == 1 and a->rank == 2 here, all other cases have
1548 been caught in check.c. */
1549 if (a->shape)
1551 f->shape = gfc_get_shape (f->rank);
1552 mpz_init_set (f->shape[0], a->shape[0]);
1556 f->value.function.name
1557 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1558 f->ts.kind);
1562 static void
1563 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1565 gfc_actual_arglist *a;
1567 f->ts.type = args->expr->ts.type;
1568 f->ts.kind = args->expr->ts.kind;
1569 /* Find the largest type kind. */
1570 for (a = args->next; a; a = a->next)
1572 if (a->expr->ts.kind > f->ts.kind)
1573 f->ts.kind = a->expr->ts.kind;
1576 /* Convert all parameters to the required kind. */
1577 for (a = args; a; a = a->next)
1579 if (a->expr->ts.kind != f->ts.kind)
1580 gfc_convert_type (a->expr, &f->ts, 2);
1583 f->value.function.name
1584 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1588 void
1589 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1591 gfc_resolve_minmax ("__max_%c%d", f, args);
1595 void
1596 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1597 gfc_expr *mask)
1599 const char *name;
1600 int i, j, idim;
1602 f->ts.type = BT_INTEGER;
1603 f->ts.kind = gfc_default_integer_kind;
1605 if (dim == NULL)
1607 f->rank = 1;
1608 f->shape = gfc_get_shape (1);
1609 mpz_init_set_si (f->shape[0], array->rank);
1611 else
1613 f->rank = array->rank - 1;
1614 gfc_resolve_dim_arg (dim);
1615 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1617 idim = (int) mpz_get_si (dim->value.integer);
1618 f->shape = gfc_get_shape (f->rank);
1619 for (i = 0, j = 0; i < f->rank; i++, j++)
1621 if (i == (idim - 1))
1622 j++;
1623 mpz_init_set (f->shape[i], array->shape[j]);
1628 if (mask)
1630 if (mask->rank == 0)
1631 name = "smaxloc";
1632 else
1633 name = "mmaxloc";
1635 resolve_mask_arg (mask);
1637 else
1638 name = "maxloc";
1640 f->value.function.name
1641 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1642 gfc_type_letter (array->ts.type), array->ts.kind);
1646 void
1647 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1648 gfc_expr *mask)
1650 const char *name;
1651 int i, j, idim;
1653 f->ts = array->ts;
1655 if (dim != NULL)
1657 f->rank = array->rank - 1;
1658 gfc_resolve_dim_arg (dim);
1660 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1662 idim = (int) mpz_get_si (dim->value.integer);
1663 f->shape = gfc_get_shape (f->rank);
1664 for (i = 0, j = 0; i < f->rank; i++, j++)
1666 if (i == (idim - 1))
1667 j++;
1668 mpz_init_set (f->shape[i], array->shape[j]);
1673 if (mask)
1675 if (mask->rank == 0)
1676 name = "smaxval";
1677 else
1678 name = "mmaxval";
1680 resolve_mask_arg (mask);
1682 else
1683 name = "maxval";
1685 f->value.function.name
1686 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1687 gfc_type_letter (array->ts.type), array->ts.kind);
1691 void
1692 gfc_resolve_mclock (gfc_expr *f)
1694 f->ts.type = BT_INTEGER;
1695 f->ts.kind = 4;
1696 f->value.function.name = PREFIX ("mclock");
1700 void
1701 gfc_resolve_mclock8 (gfc_expr *f)
1703 f->ts.type = BT_INTEGER;
1704 f->ts.kind = 8;
1705 f->value.function.name = PREFIX ("mclock8");
1709 void
1710 gfc_resolve_mask (gfc_expr *f, gfc_expr *i ATTRIBUTE_UNUSED,
1711 gfc_expr *kind)
1713 f->ts.type = BT_INTEGER;
1714 f->ts.kind = kind ? mpz_get_si (kind->value.integer)
1715 : gfc_default_integer_kind;
1717 if (f->value.function.isym->id == GFC_ISYM_MASKL)
1718 f->value.function.name = gfc_get_string ("__maskl_i%d", f->ts.kind);
1719 else
1720 f->value.function.name = gfc_get_string ("__maskr_i%d", f->ts.kind);
1724 void
1725 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1726 gfc_expr *fsource ATTRIBUTE_UNUSED,
1727 gfc_expr *mask ATTRIBUTE_UNUSED)
1729 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1730 gfc_resolve_substring_charlen (tsource);
1732 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1733 gfc_resolve_substring_charlen (fsource);
1735 if (tsource->ts.type == BT_CHARACTER)
1736 check_charlen_present (tsource);
1738 f->ts = tsource->ts;
1739 f->value.function.name
1740 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1741 tsource->ts.kind);
1745 void
1746 gfc_resolve_merge_bits (gfc_expr *f, gfc_expr *i,
1747 gfc_expr *j ATTRIBUTE_UNUSED,
1748 gfc_expr *mask ATTRIBUTE_UNUSED)
1750 f->ts = i->ts;
1751 f->value.function.name = gfc_get_string ("__merge_bits_i%d", i->ts.kind);
1755 void
1756 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1758 gfc_resolve_minmax ("__min_%c%d", f, args);
1762 void
1763 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1764 gfc_expr *mask)
1766 const char *name;
1767 int i, j, idim;
1769 f->ts.type = BT_INTEGER;
1770 f->ts.kind = gfc_default_integer_kind;
1772 if (dim == NULL)
1774 f->rank = 1;
1775 f->shape = gfc_get_shape (1);
1776 mpz_init_set_si (f->shape[0], array->rank);
1778 else
1780 f->rank = array->rank - 1;
1781 gfc_resolve_dim_arg (dim);
1782 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1784 idim = (int) mpz_get_si (dim->value.integer);
1785 f->shape = gfc_get_shape (f->rank);
1786 for (i = 0, j = 0; i < f->rank; i++, j++)
1788 if (i == (idim - 1))
1789 j++;
1790 mpz_init_set (f->shape[i], array->shape[j]);
1795 if (mask)
1797 if (mask->rank == 0)
1798 name = "sminloc";
1799 else
1800 name = "mminloc";
1802 resolve_mask_arg (mask);
1804 else
1805 name = "minloc";
1807 f->value.function.name
1808 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1809 gfc_type_letter (array->ts.type), array->ts.kind);
1813 void
1814 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1815 gfc_expr *mask)
1817 const char *name;
1818 int i, j, idim;
1820 f->ts = array->ts;
1822 if (dim != NULL)
1824 f->rank = array->rank - 1;
1825 gfc_resolve_dim_arg (dim);
1827 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1829 idim = (int) mpz_get_si (dim->value.integer);
1830 f->shape = gfc_get_shape (f->rank);
1831 for (i = 0, j = 0; i < f->rank; i++, j++)
1833 if (i == (idim - 1))
1834 j++;
1835 mpz_init_set (f->shape[i], array->shape[j]);
1840 if (mask)
1842 if (mask->rank == 0)
1843 name = "sminval";
1844 else
1845 name = "mminval";
1847 resolve_mask_arg (mask);
1849 else
1850 name = "minval";
1852 f->value.function.name
1853 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1854 gfc_type_letter (array->ts.type), array->ts.kind);
1858 void
1859 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1861 f->ts.type = a->ts.type;
1862 if (p != NULL)
1863 f->ts.kind = gfc_kind_max (a,p);
1864 else
1865 f->ts.kind = a->ts.kind;
1867 if (p != NULL && a->ts.kind != p->ts.kind)
1869 if (a->ts.kind == gfc_kind_max (a,p))
1870 gfc_convert_type (p, &a->ts, 2);
1871 else
1872 gfc_convert_type (a, &p->ts, 2);
1875 f->value.function.name
1876 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1880 void
1881 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1883 f->ts.type = a->ts.type;
1884 if (p != NULL)
1885 f->ts.kind = gfc_kind_max (a,p);
1886 else
1887 f->ts.kind = a->ts.kind;
1889 if (p != NULL && a->ts.kind != p->ts.kind)
1891 if (a->ts.kind == gfc_kind_max (a,p))
1892 gfc_convert_type (p, &a->ts, 2);
1893 else
1894 gfc_convert_type (a, &p->ts, 2);
1897 f->value.function.name
1898 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1899 f->ts.kind);
1902 void
1903 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1905 if (p->ts.kind != a->ts.kind)
1906 gfc_convert_type (p, &a->ts, 2);
1908 f->ts = a->ts;
1909 f->value.function.name
1910 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1911 a->ts.kind);
1914 void
1915 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1917 f->ts.type = BT_INTEGER;
1918 f->ts.kind = (kind == NULL)
1919 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1920 f->value.function.name
1921 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1925 void
1926 gfc_resolve_norm2 (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1928 resolve_transformational ("norm2", f, array, dim, NULL);
1932 void
1933 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1935 f->ts = i->ts;
1936 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1940 void
1941 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1943 f->ts.type = i->ts.type;
1944 f->ts.kind = gfc_kind_max (i, j);
1946 if (i->ts.kind != j->ts.kind)
1948 if (i->ts.kind == gfc_kind_max (i, j))
1949 gfc_convert_type (j, &i->ts, 2);
1950 else
1951 gfc_convert_type (i, &j->ts, 2);
1954 f->value.function.name
1955 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1959 void
1960 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1961 gfc_expr *vector ATTRIBUTE_UNUSED)
1963 if (array->ts.type == BT_CHARACTER && array->ref)
1964 gfc_resolve_substring_charlen (array);
1966 f->ts = array->ts;
1967 f->rank = 1;
1969 resolve_mask_arg (mask);
1971 if (mask->rank != 0)
1973 if (array->ts.type == BT_CHARACTER)
1974 f->value.function.name
1975 = array->ts.kind == 1 ? PREFIX ("pack_char")
1976 : gfc_get_string
1977 (PREFIX ("pack_char%d"),
1978 array->ts.kind);
1979 else
1980 f->value.function.name = PREFIX ("pack");
1982 else
1984 if (array->ts.type == BT_CHARACTER)
1985 f->value.function.name
1986 = array->ts.kind == 1 ? PREFIX ("pack_s_char")
1987 : gfc_get_string
1988 (PREFIX ("pack_s_char%d"),
1989 array->ts.kind);
1990 else
1991 f->value.function.name = PREFIX ("pack_s");
1996 void
1997 gfc_resolve_parity (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1999 resolve_transformational ("parity", f, array, dim, NULL);
2003 void
2004 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
2005 gfc_expr *mask)
2007 resolve_transformational ("product", f, array, dim, mask);
2011 void
2012 gfc_resolve_rank (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED)
2014 f->ts.type = BT_INTEGER;
2015 f->ts.kind = gfc_default_integer_kind;
2016 f->value.function.name = gfc_get_string ("__rank");
2020 void
2021 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
2023 f->ts.type = BT_REAL;
2025 if (kind != NULL)
2026 f->ts.kind = mpz_get_si (kind->value.integer);
2027 else
2028 f->ts.kind = (a->ts.type == BT_COMPLEX)
2029 ? a->ts.kind : gfc_default_real_kind;
2031 f->value.function.name
2032 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
2033 gfc_type_letter (a->ts.type), a->ts.kind);
2037 void
2038 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
2040 f->ts.type = BT_REAL;
2041 f->ts.kind = a->ts.kind;
2042 f->value.function.name
2043 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
2044 gfc_type_letter (a->ts.type), a->ts.kind);
2048 void
2049 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2050 gfc_expr *p2 ATTRIBUTE_UNUSED)
2052 f->ts.type = BT_INTEGER;
2053 f->ts.kind = gfc_default_integer_kind;
2054 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
2058 void
2059 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
2060 gfc_expr *ncopies)
2062 int len;
2063 gfc_expr *tmp;
2064 f->ts.type = BT_CHARACTER;
2065 f->ts.kind = string->ts.kind;
2066 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
2068 /* If possible, generate a character length. */
2069 if (f->ts.u.cl == NULL)
2070 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
2072 tmp = NULL;
2073 if (string->expr_type == EXPR_CONSTANT)
2075 len = string->value.character.length;
2076 tmp = gfc_get_int_expr (gfc_default_integer_kind, NULL , len);
2078 else if (string->ts.u.cl && string->ts.u.cl->length)
2080 tmp = gfc_copy_expr (string->ts.u.cl->length);
2083 if (tmp)
2084 f->ts.u.cl->length = gfc_multiply (tmp, gfc_copy_expr (ncopies));
2088 void
2089 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
2090 gfc_expr *pad ATTRIBUTE_UNUSED,
2091 gfc_expr *order ATTRIBUTE_UNUSED)
2093 mpz_t rank;
2094 int kind;
2095 int i;
2097 if (source->ts.type == BT_CHARACTER && source->ref)
2098 gfc_resolve_substring_charlen (source);
2100 f->ts = source->ts;
2102 gfc_array_size (shape, &rank);
2103 f->rank = mpz_get_si (rank);
2104 mpz_clear (rank);
2105 switch (source->ts.type)
2107 case BT_COMPLEX:
2108 case BT_REAL:
2109 case BT_INTEGER:
2110 case BT_LOGICAL:
2111 case BT_CHARACTER:
2112 kind = source->ts.kind;
2113 break;
2115 default:
2116 kind = 0;
2117 break;
2120 switch (kind)
2122 case 4:
2123 case 8:
2124 case 10:
2125 case 16:
2126 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
2127 f->value.function.name
2128 = gfc_get_string (PREFIX ("reshape_%c%d"),
2129 gfc_type_letter (source->ts.type),
2130 source->ts.kind);
2131 else if (source->ts.type == BT_CHARACTER)
2132 f->value.function.name = gfc_get_string (PREFIX ("reshape_char%d"),
2133 kind);
2134 else
2135 f->value.function.name
2136 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
2137 break;
2139 default:
2140 f->value.function.name = (source->ts.type == BT_CHARACTER
2141 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
2142 break;
2145 if (shape->expr_type == EXPR_ARRAY && gfc_is_constant_expr (shape))
2147 gfc_constructor *c;
2148 f->shape = gfc_get_shape (f->rank);
2149 c = gfc_constructor_first (shape->value.constructor);
2150 for (i = 0; i < f->rank; i++)
2152 mpz_init_set (f->shape[i], c->expr->value.integer);
2153 c = gfc_constructor_next (c);
2157 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
2158 so many runtime variations. */
2159 if (shape->ts.kind != gfc_index_integer_kind)
2161 gfc_typespec ts = shape->ts;
2162 ts.kind = gfc_index_integer_kind;
2163 gfc_convert_type_warn (shape, &ts, 2, 0);
2165 if (order && order->ts.kind != gfc_index_integer_kind)
2166 gfc_convert_type_warn (order, &shape->ts, 2, 0);
2170 void
2171 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
2173 f->ts = x->ts;
2174 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
2177 void
2178 gfc_resolve_fe_runtime_error (gfc_code *c)
2180 const char *name;
2181 gfc_actual_arglist *a;
2183 name = gfc_get_string (PREFIX ("runtime_error"));
2185 for (a = c->ext.actual->next; a; a = a->next)
2186 a->name = "%VAL";
2188 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2191 void
2192 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED)
2194 f->ts = x->ts;
2195 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
2199 void
2200 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
2201 gfc_expr *set ATTRIBUTE_UNUSED,
2202 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2204 f->ts.type = BT_INTEGER;
2205 if (kind)
2206 f->ts.kind = mpz_get_si (kind->value.integer);
2207 else
2208 f->ts.kind = gfc_default_integer_kind;
2209 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
2213 void
2214 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
2216 t1->ts = t0->ts;
2217 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
2221 void
2222 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x,
2223 gfc_expr *i ATTRIBUTE_UNUSED)
2225 f->ts = x->ts;
2226 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
2230 void
2231 gfc_resolve_shape (gfc_expr *f, gfc_expr *array, gfc_expr *kind)
2233 f->ts.type = BT_INTEGER;
2235 if (kind)
2236 f->ts.kind = mpz_get_si (kind->value.integer);
2237 else
2238 f->ts.kind = gfc_default_integer_kind;
2240 f->rank = 1;
2241 if (array->rank != -1)
2243 f->shape = gfc_get_shape (1);
2244 mpz_init_set_ui (f->shape[0], array->rank);
2247 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
2251 void
2252 gfc_resolve_shift (gfc_expr *f, gfc_expr *i, gfc_expr *shift ATTRIBUTE_UNUSED)
2254 f->ts = i->ts;
2255 if (f->value.function.isym->id == GFC_ISYM_SHIFTA)
2256 f->value.function.name = gfc_get_string ("shifta_i%d", f->ts.kind);
2257 else if (f->value.function.isym->id == GFC_ISYM_SHIFTL)
2258 f->value.function.name = gfc_get_string ("shiftl_i%d", f->ts.kind);
2259 else if (f->value.function.isym->id == GFC_ISYM_SHIFTR)
2260 f->value.function.name = gfc_get_string ("shiftr_i%d", f->ts.kind);
2261 else
2262 gcc_unreachable ();
2266 void
2267 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
2269 f->ts = a->ts;
2270 f->value.function.name
2271 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
2275 void
2276 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
2278 f->ts.type = BT_INTEGER;
2279 f->ts.kind = gfc_c_int_kind;
2281 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2282 if (handler->ts.type == BT_INTEGER)
2284 if (handler->ts.kind != gfc_c_int_kind)
2285 gfc_convert_type (handler, &f->ts, 2);
2286 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
2288 else
2289 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
2291 if (number->ts.kind != gfc_c_int_kind)
2292 gfc_convert_type (number, &f->ts, 2);
2296 void
2297 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
2299 f->ts = x->ts;
2300 f->value.function.name
2301 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2305 void
2306 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
2308 f->ts = x->ts;
2309 f->value.function.name
2310 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2314 void
2315 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2316 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
2318 f->ts.type = BT_INTEGER;
2319 if (kind)
2320 f->ts.kind = mpz_get_si (kind->value.integer);
2321 else
2322 f->ts.kind = gfc_default_integer_kind;
2326 void
2327 gfc_resolve_stride (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2328 gfc_expr *dim ATTRIBUTE_UNUSED)
2330 f->ts.type = BT_INTEGER;
2331 f->ts.kind = gfc_index_integer_kind;
2335 void
2336 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
2338 f->ts = x->ts;
2339 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
2343 void
2344 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2345 gfc_expr *ncopies)
2347 if (source->ts.type == BT_CHARACTER && source->ref)
2348 gfc_resolve_substring_charlen (source);
2350 if (source->ts.type == BT_CHARACTER)
2351 check_charlen_present (source);
2353 f->ts = source->ts;
2354 f->rank = source->rank + 1;
2355 if (source->rank == 0)
2357 if (source->ts.type == BT_CHARACTER)
2358 f->value.function.name
2359 = source->ts.kind == 1 ? PREFIX ("spread_char_scalar")
2360 : gfc_get_string
2361 (PREFIX ("spread_char%d_scalar"),
2362 source->ts.kind);
2363 else
2364 f->value.function.name = PREFIX ("spread_scalar");
2366 else
2368 if (source->ts.type == BT_CHARACTER)
2369 f->value.function.name
2370 = source->ts.kind == 1 ? PREFIX ("spread_char")
2371 : gfc_get_string
2372 (PREFIX ("spread_char%d"),
2373 source->ts.kind);
2374 else
2375 f->value.function.name = PREFIX ("spread");
2378 if (dim && gfc_is_constant_expr (dim)
2379 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2381 int i, idim;
2382 idim = mpz_get_ui (dim->value.integer);
2383 f->shape = gfc_get_shape (f->rank);
2384 for (i = 0; i < (idim - 1); i++)
2385 mpz_init_set (f->shape[i], source->shape[i]);
2387 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2389 for (i = idim; i < f->rank ; i++)
2390 mpz_init_set (f->shape[i], source->shape[i-1]);
2394 gfc_resolve_dim_arg (dim);
2395 gfc_resolve_index (ncopies, 1);
2399 void
2400 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2402 f->ts = x->ts;
2403 f->value.function.name
2404 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2408 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2410 void
2411 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2412 gfc_expr *a ATTRIBUTE_UNUSED)
2414 f->ts.type = BT_INTEGER;
2415 f->ts.kind = gfc_default_integer_kind;
2416 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2420 void
2421 gfc_resolve_lstat (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 ("lstat_i%d"), f->ts.kind);
2430 void
2431 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2433 f->ts.type = BT_INTEGER;
2434 f->ts.kind = gfc_default_integer_kind;
2435 if (n->ts.kind != f->ts.kind)
2436 gfc_convert_type (n, &f->ts, 2);
2438 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2442 void
2443 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2445 gfc_typespec ts;
2446 gfc_clear_ts (&ts);
2448 f->ts.type = BT_INTEGER;
2449 f->ts.kind = gfc_c_int_kind;
2450 if (u->ts.kind != gfc_c_int_kind)
2452 ts.type = BT_INTEGER;
2453 ts.kind = gfc_c_int_kind;
2454 ts.u.derived = NULL;
2455 ts.u.cl = NULL;
2456 gfc_convert_type (u, &ts, 2);
2459 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2463 void
2464 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2466 f->ts.type = BT_INTEGER;
2467 f->ts.kind = gfc_c_int_kind;
2468 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2472 void
2473 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2475 gfc_typespec ts;
2476 gfc_clear_ts (&ts);
2478 f->ts.type = BT_INTEGER;
2479 f->ts.kind = gfc_c_int_kind;
2480 if (u->ts.kind != gfc_c_int_kind)
2482 ts.type = BT_INTEGER;
2483 ts.kind = gfc_c_int_kind;
2484 ts.u.derived = NULL;
2485 ts.u.cl = NULL;
2486 gfc_convert_type (u, &ts, 2);
2489 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2493 void
2494 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2496 f->ts.type = BT_INTEGER;
2497 f->ts.kind = gfc_c_int_kind;
2498 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2502 void
2503 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2505 gfc_typespec ts;
2506 gfc_clear_ts (&ts);
2508 f->ts.type = BT_INTEGER;
2509 f->ts.kind = gfc_intio_kind;
2510 if (u->ts.kind != gfc_c_int_kind)
2512 ts.type = BT_INTEGER;
2513 ts.kind = gfc_c_int_kind;
2514 ts.u.derived = NULL;
2515 ts.u.cl = NULL;
2516 gfc_convert_type (u, &ts, 2);
2519 f->value.function.name = gfc_get_string (PREFIX ("ftell2"));
2523 void
2524 gfc_resolve_storage_size (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
2525 gfc_expr *kind)
2527 f->ts.type = BT_INTEGER;
2528 if (kind)
2529 f->ts.kind = mpz_get_si (kind->value.integer);
2530 else
2531 f->ts.kind = gfc_default_integer_kind;
2535 void
2536 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2538 resolve_transformational ("sum", f, array, dim, mask);
2542 void
2543 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2544 gfc_expr *p2 ATTRIBUTE_UNUSED)
2546 f->ts.type = BT_INTEGER;
2547 f->ts.kind = gfc_default_integer_kind;
2548 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2552 /* Resolve the g77 compatibility function SYSTEM. */
2554 void
2555 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2557 f->ts.type = BT_INTEGER;
2558 f->ts.kind = 4;
2559 f->value.function.name = gfc_get_string (PREFIX ("system"));
2563 void
2564 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2566 f->ts = x->ts;
2567 f->value.function.name
2568 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2572 void
2573 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2575 f->ts = x->ts;
2576 f->value.function.name
2577 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2581 void
2582 gfc_resolve_image_index (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2583 gfc_expr *sub ATTRIBUTE_UNUSED)
2585 static char image_index[] = "__image_index";
2586 f->ts.type = BT_INTEGER;
2587 f->ts.kind = gfc_default_integer_kind;
2588 f->value.function.name = image_index;
2592 void
2593 gfc_resolve_this_image (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
2594 gfc_expr *distance ATTRIBUTE_UNUSED)
2596 static char this_image[] = "__this_image";
2597 if (array && gfc_is_coarray (array))
2598 resolve_bound (f, array, dim, NULL, "__this_image", true);
2599 else
2601 f->ts.type = BT_INTEGER;
2602 f->ts.kind = gfc_default_integer_kind;
2603 f->value.function.name = this_image;
2608 void
2609 gfc_resolve_time (gfc_expr *f)
2611 f->ts.type = BT_INTEGER;
2612 f->ts.kind = 4;
2613 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2617 void
2618 gfc_resolve_time8 (gfc_expr *f)
2620 f->ts.type = BT_INTEGER;
2621 f->ts.kind = 8;
2622 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2626 void
2627 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2628 gfc_expr *mold, gfc_expr *size)
2630 /* TODO: Make this do something meaningful. */
2631 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2633 if (mold->ts.type == BT_CHARACTER
2634 && !mold->ts.u.cl->length
2635 && gfc_is_constant_expr (mold))
2637 int len;
2638 if (mold->expr_type == EXPR_CONSTANT)
2640 len = mold->value.character.length;
2641 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2642 NULL, len);
2644 else
2646 gfc_constructor *c = gfc_constructor_first (mold->value.constructor);
2647 len = c->expr->value.character.length;
2648 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2649 NULL, len);
2653 f->ts = mold->ts;
2655 if (size == NULL && mold->rank == 0)
2657 f->rank = 0;
2658 f->value.function.name = transfer0;
2660 else
2662 f->rank = 1;
2663 f->value.function.name = transfer1;
2664 if (size && gfc_is_constant_expr (size))
2666 f->shape = gfc_get_shape (1);
2667 mpz_init_set (f->shape[0], size->value.integer);
2673 void
2674 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2677 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2678 gfc_resolve_substring_charlen (matrix);
2680 f->ts = matrix->ts;
2681 f->rank = 2;
2682 if (matrix->shape)
2684 f->shape = gfc_get_shape (2);
2685 mpz_init_set (f->shape[0], matrix->shape[1]);
2686 mpz_init_set (f->shape[1], matrix->shape[0]);
2689 switch (matrix->ts.kind)
2691 case 4:
2692 case 8:
2693 case 10:
2694 case 16:
2695 switch (matrix->ts.type)
2697 case BT_REAL:
2698 case BT_COMPLEX:
2699 f->value.function.name
2700 = gfc_get_string (PREFIX ("transpose_%c%d"),
2701 gfc_type_letter (matrix->ts.type),
2702 matrix->ts.kind);
2703 break;
2705 case BT_INTEGER:
2706 case BT_LOGICAL:
2707 /* Use the integer routines for real and logical cases. This
2708 assumes they all have the same alignment requirements. */
2709 f->value.function.name
2710 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2711 break;
2713 default:
2714 if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4)
2715 f->value.function.name = PREFIX ("transpose_char4");
2716 else
2717 f->value.function.name = PREFIX ("transpose");
2718 break;
2720 break;
2722 default:
2723 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2724 ? PREFIX ("transpose_char")
2725 : PREFIX ("transpose"));
2726 break;
2731 void
2732 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2734 f->ts.type = BT_CHARACTER;
2735 f->ts.kind = string->ts.kind;
2736 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2740 void
2741 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2743 resolve_bound (f, array, dim, kind, "__ubound", false);
2747 void
2748 gfc_resolve_ucobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2750 resolve_bound (f, array, dim, kind, "__ucobound", true);
2754 /* Resolve the g77 compatibility function UMASK. */
2756 void
2757 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2759 f->ts.type = BT_INTEGER;
2760 f->ts.kind = n->ts.kind;
2761 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2765 /* Resolve the g77 compatibility function UNLINK. */
2767 void
2768 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2770 f->ts.type = BT_INTEGER;
2771 f->ts.kind = 4;
2772 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2776 void
2777 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2779 gfc_typespec ts;
2780 gfc_clear_ts (&ts);
2782 f->ts.type = BT_CHARACTER;
2783 f->ts.kind = gfc_default_character_kind;
2785 if (unit->ts.kind != gfc_c_int_kind)
2787 ts.type = BT_INTEGER;
2788 ts.kind = gfc_c_int_kind;
2789 ts.u.derived = NULL;
2790 ts.u.cl = NULL;
2791 gfc_convert_type (unit, &ts, 2);
2794 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2798 void
2799 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2800 gfc_expr *field ATTRIBUTE_UNUSED)
2802 if (vector->ts.type == BT_CHARACTER && vector->ref)
2803 gfc_resolve_substring_charlen (vector);
2805 f->ts = vector->ts;
2806 f->rank = mask->rank;
2807 resolve_mask_arg (mask);
2809 if (vector->ts.type == BT_CHARACTER)
2811 if (vector->ts.kind == 1)
2812 f->value.function.name
2813 = gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0);
2814 else
2815 f->value.function.name
2816 = gfc_get_string (PREFIX ("unpack%d_char%d"),
2817 field->rank > 0 ? 1 : 0, vector->ts.kind);
2819 else
2820 f->value.function.name
2821 = gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0);
2825 void
2826 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2827 gfc_expr *set ATTRIBUTE_UNUSED,
2828 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2830 f->ts.type = BT_INTEGER;
2831 if (kind)
2832 f->ts.kind = mpz_get_si (kind->value.integer);
2833 else
2834 f->ts.kind = gfc_default_integer_kind;
2835 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2839 void
2840 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2842 f->ts.type = i->ts.type;
2843 f->ts.kind = gfc_kind_max (i, j);
2845 if (i->ts.kind != j->ts.kind)
2847 if (i->ts.kind == gfc_kind_max (i, j))
2848 gfc_convert_type (j, &i->ts, 2);
2849 else
2850 gfc_convert_type (i, &j->ts, 2);
2853 f->value.function.name
2854 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2858 /* Intrinsic subroutine resolution. */
2860 void
2861 gfc_resolve_alarm_sub (gfc_code *c)
2863 const char *name;
2864 gfc_expr *seconds, *handler;
2865 gfc_typespec ts;
2866 gfc_clear_ts (&ts);
2868 seconds = c->ext.actual->expr;
2869 handler = c->ext.actual->next->expr;
2870 ts.type = BT_INTEGER;
2871 ts.kind = gfc_c_int_kind;
2873 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2874 In all cases, the status argument is of default integer kind
2875 (enforced in check.c) so that the function suffix is fixed. */
2876 if (handler->ts.type == BT_INTEGER)
2878 if (handler->ts.kind != gfc_c_int_kind)
2879 gfc_convert_type (handler, &ts, 2);
2880 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2881 gfc_default_integer_kind);
2883 else
2884 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2885 gfc_default_integer_kind);
2887 if (seconds->ts.kind != gfc_c_int_kind)
2888 gfc_convert_type (seconds, &ts, 2);
2890 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2893 void
2894 gfc_resolve_cpu_time (gfc_code *c)
2896 const char *name;
2897 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2898 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2902 /* Create a formal arglist based on an actual one and set the INTENTs given. */
2904 static gfc_formal_arglist*
2905 create_formal_for_intents (gfc_actual_arglist* actual, const sym_intent* ints)
2907 gfc_formal_arglist* head;
2908 gfc_formal_arglist* tail;
2909 int i;
2911 if (!actual)
2912 return NULL;
2914 head = tail = gfc_get_formal_arglist ();
2915 for (i = 0; actual; actual = actual->next, tail = tail->next, ++i)
2917 gfc_symbol* sym;
2919 sym = gfc_new_symbol ("dummyarg", NULL);
2920 sym->ts = actual->expr->ts;
2922 sym->attr.intent = ints[i];
2923 tail->sym = sym;
2925 if (actual->next)
2926 tail->next = gfc_get_formal_arglist ();
2929 return head;
2933 void
2934 gfc_resolve_atomic_def (gfc_code *c)
2936 const char *name = "atomic_define";
2937 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2941 void
2942 gfc_resolve_atomic_ref (gfc_code *c)
2944 const char *name = "atomic_ref";
2945 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2948 void
2949 gfc_resolve_event_query (gfc_code *c)
2951 const char *name = "event_query";
2952 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2955 void
2956 gfc_resolve_mvbits (gfc_code *c)
2958 static const sym_intent INTENTS[] = {INTENT_IN, INTENT_IN, INTENT_IN,
2959 INTENT_INOUT, INTENT_IN};
2961 const char *name;
2962 gfc_typespec ts;
2963 gfc_clear_ts (&ts);
2965 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2966 they will be converted so that they fit into a C int. */
2967 ts.type = BT_INTEGER;
2968 ts.kind = gfc_c_int_kind;
2969 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2970 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2971 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2972 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2973 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2974 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2976 /* TO and FROM are guaranteed to have the same kind parameter. */
2977 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2978 c->ext.actual->expr->ts.kind);
2979 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2980 /* Mark as elemental subroutine as this does not happen automatically. */
2981 c->resolved_sym->attr.elemental = 1;
2983 /* Create a dummy formal arglist so the INTENTs are known later for purpose
2984 of creating temporaries. */
2985 c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS);
2989 void
2990 gfc_resolve_random_number (gfc_code *c)
2992 const char *name;
2993 int kind;
2995 kind = c->ext.actual->expr->ts.kind;
2996 if (c->ext.actual->expr->rank == 0)
2997 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2998 else
2999 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
3001 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3005 void
3006 gfc_resolve_random_seed (gfc_code *c)
3008 const char *name;
3010 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
3011 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3015 void
3016 gfc_resolve_rename_sub (gfc_code *c)
3018 const char *name;
3019 int kind;
3021 if (c->ext.actual->next->next->expr != NULL)
3022 kind = c->ext.actual->next->next->expr->ts.kind;
3023 else
3024 kind = gfc_default_integer_kind;
3026 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
3027 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3031 void
3032 gfc_resolve_kill_sub (gfc_code *c)
3034 const char *name;
3035 int kind;
3037 if (c->ext.actual->next->next->expr != NULL)
3038 kind = c->ext.actual->next->next->expr->ts.kind;
3039 else
3040 kind = gfc_default_integer_kind;
3042 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
3043 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3047 void
3048 gfc_resolve_link_sub (gfc_code *c)
3050 const char *name;
3051 int kind;
3053 if (c->ext.actual->next->next->expr != NULL)
3054 kind = c->ext.actual->next->next->expr->ts.kind;
3055 else
3056 kind = gfc_default_integer_kind;
3058 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
3059 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3063 void
3064 gfc_resolve_symlnk_sub (gfc_code *c)
3066 const char *name;
3067 int kind;
3069 if (c->ext.actual->next->next->expr != NULL)
3070 kind = c->ext.actual->next->next->expr->ts.kind;
3071 else
3072 kind = gfc_default_integer_kind;
3074 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
3075 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3079 /* G77 compatibility subroutines dtime() and etime(). */
3081 void
3082 gfc_resolve_dtime_sub (gfc_code *c)
3084 const char *name;
3085 name = gfc_get_string (PREFIX ("dtime_sub"));
3086 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3089 void
3090 gfc_resolve_etime_sub (gfc_code *c)
3092 const char *name;
3093 name = gfc_get_string (PREFIX ("etime_sub"));
3094 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3098 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
3100 void
3101 gfc_resolve_itime (gfc_code *c)
3103 c->resolved_sym
3104 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
3105 gfc_default_integer_kind));
3108 void
3109 gfc_resolve_idate (gfc_code *c)
3111 c->resolved_sym
3112 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
3113 gfc_default_integer_kind));
3116 void
3117 gfc_resolve_ltime (gfc_code *c)
3119 c->resolved_sym
3120 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
3121 gfc_default_integer_kind));
3124 void
3125 gfc_resolve_gmtime (gfc_code *c)
3127 c->resolved_sym
3128 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
3129 gfc_default_integer_kind));
3133 /* G77 compatibility subroutine second(). */
3135 void
3136 gfc_resolve_second_sub (gfc_code *c)
3138 const char *name;
3139 name = gfc_get_string (PREFIX ("second_sub"));
3140 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3144 void
3145 gfc_resolve_sleep_sub (gfc_code *c)
3147 const char *name;
3148 int kind;
3150 if (c->ext.actual->expr != NULL)
3151 kind = c->ext.actual->expr->ts.kind;
3152 else
3153 kind = gfc_default_integer_kind;
3155 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
3156 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3160 /* G77 compatibility function srand(). */
3162 void
3163 gfc_resolve_srand (gfc_code *c)
3165 const char *name;
3166 name = gfc_get_string (PREFIX ("srand"));
3167 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3171 /* Resolve the getarg intrinsic subroutine. */
3173 void
3174 gfc_resolve_getarg (gfc_code *c)
3176 const char *name;
3178 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
3180 gfc_typespec ts;
3181 gfc_clear_ts (&ts);
3183 ts.type = BT_INTEGER;
3184 ts.kind = gfc_default_integer_kind;
3186 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3189 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
3190 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3194 /* Resolve the getcwd intrinsic subroutine. */
3196 void
3197 gfc_resolve_getcwd_sub (gfc_code *c)
3199 const char *name;
3200 int kind;
3202 if (c->ext.actual->next->expr != NULL)
3203 kind = c->ext.actual->next->expr->ts.kind;
3204 else
3205 kind = gfc_default_integer_kind;
3207 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
3208 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3212 /* Resolve the get_command intrinsic subroutine. */
3214 void
3215 gfc_resolve_get_command (gfc_code *c)
3217 const char *name;
3218 int kind;
3219 kind = gfc_default_integer_kind;
3220 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
3221 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3225 /* Resolve the get_command_argument intrinsic subroutine. */
3227 void
3228 gfc_resolve_get_command_argument (gfc_code *c)
3230 const char *name;
3231 int kind;
3232 kind = gfc_default_integer_kind;
3233 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
3234 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3238 /* Resolve the get_environment_variable intrinsic subroutine. */
3240 void
3241 gfc_resolve_get_environment_variable (gfc_code *code)
3243 const char *name;
3244 int kind;
3245 kind = gfc_default_integer_kind;
3246 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
3247 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3251 void
3252 gfc_resolve_signal_sub (gfc_code *c)
3254 const char *name;
3255 gfc_expr *number, *handler, *status;
3256 gfc_typespec ts;
3257 gfc_clear_ts (&ts);
3259 number = c->ext.actual->expr;
3260 handler = c->ext.actual->next->expr;
3261 status = c->ext.actual->next->next->expr;
3262 ts.type = BT_INTEGER;
3263 ts.kind = gfc_c_int_kind;
3265 /* handler can be either BT_INTEGER or BT_PROCEDURE */
3266 if (handler->ts.type == BT_INTEGER)
3268 if (handler->ts.kind != gfc_c_int_kind)
3269 gfc_convert_type (handler, &ts, 2);
3270 name = gfc_get_string (PREFIX ("signal_sub_int"));
3272 else
3273 name = gfc_get_string (PREFIX ("signal_sub"));
3275 if (number->ts.kind != gfc_c_int_kind)
3276 gfc_convert_type (number, &ts, 2);
3277 if (status != NULL && status->ts.kind != gfc_c_int_kind)
3278 gfc_convert_type (status, &ts, 2);
3280 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3284 /* Resolve the SYSTEM intrinsic subroutine. */
3286 void
3287 gfc_resolve_system_sub (gfc_code *c)
3289 const char *name;
3290 name = gfc_get_string (PREFIX ("system_sub"));
3291 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3295 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
3297 void
3298 gfc_resolve_system_clock (gfc_code *c)
3300 const char *name;
3301 int kind;
3302 gfc_expr *count = c->ext.actual->expr;
3303 gfc_expr *count_max = c->ext.actual->next->next->expr;
3305 /* The INTEGER(8) version has higher precision, it is used if both COUNT
3306 and COUNT_MAX can hold 64-bit values, or are absent. */
3307 if ((!count || count->ts.kind >= 8)
3308 && (!count_max || count_max->ts.kind >= 8))
3309 kind = 8;
3310 else
3311 kind = gfc_default_integer_kind;
3313 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
3314 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3318 /* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine. */
3319 void
3320 gfc_resolve_execute_command_line (gfc_code *c)
3322 const char *name;
3323 name = gfc_get_string (PREFIX ("execute_command_line_i%d"),
3324 gfc_default_integer_kind);
3325 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3329 /* Resolve the EXIT intrinsic subroutine. */
3331 void
3332 gfc_resolve_exit (gfc_code *c)
3334 const char *name;
3335 gfc_typespec ts;
3336 gfc_expr *n;
3337 gfc_clear_ts (&ts);
3339 /* The STATUS argument has to be of default kind. If it is not,
3340 we convert it. */
3341 ts.type = BT_INTEGER;
3342 ts.kind = gfc_default_integer_kind;
3343 n = c->ext.actual->expr;
3344 if (n != NULL && n->ts.kind != ts.kind)
3345 gfc_convert_type (n, &ts, 2);
3347 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
3348 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3352 /* Resolve the FLUSH intrinsic subroutine. */
3354 void
3355 gfc_resolve_flush (gfc_code *c)
3357 const char *name;
3358 gfc_typespec ts;
3359 gfc_expr *n;
3360 gfc_clear_ts (&ts);
3362 ts.type = BT_INTEGER;
3363 ts.kind = gfc_default_integer_kind;
3364 n = c->ext.actual->expr;
3365 if (n != NULL && n->ts.kind != ts.kind)
3366 gfc_convert_type (n, &ts, 2);
3368 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
3369 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3373 void
3374 gfc_resolve_ctime_sub (gfc_code *c)
3376 gfc_typespec ts;
3377 gfc_clear_ts (&ts);
3379 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3380 if (c->ext.actual->expr->ts.kind != 8)
3382 ts.type = BT_INTEGER;
3383 ts.kind = 8;
3384 ts.u.derived = NULL;
3385 ts.u.cl = NULL;
3386 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3389 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3393 void
3394 gfc_resolve_fdate_sub (gfc_code *c)
3396 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3400 void
3401 gfc_resolve_gerror (gfc_code *c)
3403 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3407 void
3408 gfc_resolve_getlog (gfc_code *c)
3410 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3414 void
3415 gfc_resolve_hostnm_sub (gfc_code *c)
3417 const char *name;
3418 int kind;
3420 if (c->ext.actual->next->expr != NULL)
3421 kind = c->ext.actual->next->expr->ts.kind;
3422 else
3423 kind = gfc_default_integer_kind;
3425 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3426 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3430 void
3431 gfc_resolve_perror (gfc_code *c)
3433 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3436 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3438 void
3439 gfc_resolve_stat_sub (gfc_code *c)
3441 const char *name;
3442 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3443 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3447 void
3448 gfc_resolve_lstat_sub (gfc_code *c)
3450 const char *name;
3451 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3452 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3456 void
3457 gfc_resolve_fstat_sub (gfc_code *c)
3459 const char *name;
3460 gfc_expr *u;
3461 gfc_typespec *ts;
3463 u = c->ext.actual->expr;
3464 ts = &c->ext.actual->next->expr->ts;
3465 if (u->ts.kind != ts->kind)
3466 gfc_convert_type (u, ts, 2);
3467 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3468 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3472 void
3473 gfc_resolve_fgetc_sub (gfc_code *c)
3475 const char *name;
3476 gfc_typespec ts;
3477 gfc_expr *u, *st;
3478 gfc_clear_ts (&ts);
3480 u = c->ext.actual->expr;
3481 st = c->ext.actual->next->next->expr;
3483 if (u->ts.kind != gfc_c_int_kind)
3485 ts.type = BT_INTEGER;
3486 ts.kind = gfc_c_int_kind;
3487 ts.u.derived = NULL;
3488 ts.u.cl = NULL;
3489 gfc_convert_type (u, &ts, 2);
3492 if (st != NULL)
3493 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3494 else
3495 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3497 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3501 void
3502 gfc_resolve_fget_sub (gfc_code *c)
3504 const char *name;
3505 gfc_expr *st;
3507 st = c->ext.actual->next->expr;
3508 if (st != NULL)
3509 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3510 else
3511 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3513 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3517 void
3518 gfc_resolve_fputc_sub (gfc_code *c)
3520 const char *name;
3521 gfc_typespec ts;
3522 gfc_expr *u, *st;
3523 gfc_clear_ts (&ts);
3525 u = c->ext.actual->expr;
3526 st = c->ext.actual->next->next->expr;
3528 if (u->ts.kind != gfc_c_int_kind)
3530 ts.type = BT_INTEGER;
3531 ts.kind = gfc_c_int_kind;
3532 ts.u.derived = NULL;
3533 ts.u.cl = NULL;
3534 gfc_convert_type (u, &ts, 2);
3537 if (st != NULL)
3538 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3539 else
3540 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3542 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3546 void
3547 gfc_resolve_fput_sub (gfc_code *c)
3549 const char *name;
3550 gfc_expr *st;
3552 st = c->ext.actual->next->expr;
3553 if (st != NULL)
3554 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3555 else
3556 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3558 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3562 void
3563 gfc_resolve_fseek_sub (gfc_code *c)
3565 gfc_expr *unit;
3566 gfc_expr *offset;
3567 gfc_expr *whence;
3568 gfc_typespec ts;
3569 gfc_clear_ts (&ts);
3571 unit = c->ext.actual->expr;
3572 offset = c->ext.actual->next->expr;
3573 whence = c->ext.actual->next->next->expr;
3575 if (unit->ts.kind != gfc_c_int_kind)
3577 ts.type = BT_INTEGER;
3578 ts.kind = gfc_c_int_kind;
3579 ts.u.derived = NULL;
3580 ts.u.cl = NULL;
3581 gfc_convert_type (unit, &ts, 2);
3584 if (offset->ts.kind != gfc_intio_kind)
3586 ts.type = BT_INTEGER;
3587 ts.kind = gfc_intio_kind;
3588 ts.u.derived = NULL;
3589 ts.u.cl = NULL;
3590 gfc_convert_type (offset, &ts, 2);
3593 if (whence->ts.kind != gfc_c_int_kind)
3595 ts.type = BT_INTEGER;
3596 ts.kind = gfc_c_int_kind;
3597 ts.u.derived = NULL;
3598 ts.u.cl = NULL;
3599 gfc_convert_type (whence, &ts, 2);
3602 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3605 void
3606 gfc_resolve_ftell_sub (gfc_code *c)
3608 const char *name;
3609 gfc_expr *unit;
3610 gfc_expr *offset;
3611 gfc_typespec ts;
3612 gfc_clear_ts (&ts);
3614 unit = c->ext.actual->expr;
3615 offset = c->ext.actual->next->expr;
3617 if (unit->ts.kind != gfc_c_int_kind)
3619 ts.type = BT_INTEGER;
3620 ts.kind = gfc_c_int_kind;
3621 ts.u.derived = NULL;
3622 ts.u.cl = NULL;
3623 gfc_convert_type (unit, &ts, 2);
3626 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3627 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3631 void
3632 gfc_resolve_ttynam_sub (gfc_code *c)
3634 gfc_typespec ts;
3635 gfc_clear_ts (&ts);
3637 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3639 ts.type = BT_INTEGER;
3640 ts.kind = gfc_c_int_kind;
3641 ts.u.derived = NULL;
3642 ts.u.cl = NULL;
3643 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3646 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3650 /* Resolve the UMASK intrinsic subroutine. */
3652 void
3653 gfc_resolve_umask_sub (gfc_code *c)
3655 const char *name;
3656 int kind;
3658 if (c->ext.actual->next->expr != NULL)
3659 kind = c->ext.actual->next->expr->ts.kind;
3660 else
3661 kind = gfc_default_integer_kind;
3663 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3664 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3667 /* Resolve the UNLINK intrinsic subroutine. */
3669 void
3670 gfc_resolve_unlink_sub (gfc_code *c)
3672 const char *name;
3673 int kind;
3675 if (c->ext.actual->next->expr != NULL)
3676 kind = c->ext.actual->next->expr->ts.kind;
3677 else
3678 kind = gfc_default_integer_kind;
3680 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3681 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);