2011-01-29 Tobias Burnus <burnus@net-b.de>
[official-gcc.git] / gcc / fortran / iresolve.c
blobec9dd422fb626e12f8f351e6397bf8069a2909b9
1 /* Intrinsic function resolution.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Andy Vaught & Katherine Holcomb
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
24 /* Assign name and types to intrinsic procedures. For functions, the
25 first argument to a resolution function is an expression pointer to
26 the original function node and the rest are pointers to the
27 arguments of the function call. For subroutines, a pointer to the
28 code node is passed. The result type and library subroutine name
29 are generally set according to the function arguments. */
31 #include "config.h"
32 #include "system.h"
33 #include "coretypes.h"
34 #include "tree.h"
35 #include "gfortran.h"
36 #include "intrinsic.h"
37 #include "constructor.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 f->shape = gfc_get_shape (1);
137 mpz_init_set_ui (f->shape[0], coarray ? gfc_get_corank (array)
138 : array->rank);
141 f->value.function.name = xstrdup (name);
145 static void
146 resolve_transformational (const char *name, gfc_expr *f, gfc_expr *array,
147 gfc_expr *dim, gfc_expr *mask)
149 const char *prefix;
151 f->ts = array->ts;
153 if (mask)
155 if (mask->rank == 0)
156 prefix = "s";
157 else
158 prefix = "m";
160 resolve_mask_arg (mask);
162 else
163 prefix = "";
165 if (dim != NULL)
167 f->rank = array->rank - 1;
168 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
169 gfc_resolve_dim_arg (dim);
172 f->value.function.name
173 = gfc_get_string (PREFIX ("%s%s_%c%d"), prefix, name,
174 gfc_type_letter (array->ts.type), array->ts.kind);
178 /********************** Resolution functions **********************/
181 void
182 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
184 f->ts = a->ts;
185 if (f->ts.type == BT_COMPLEX)
186 f->ts.type = BT_REAL;
188 f->value.function.name
189 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
193 void
194 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
195 gfc_expr *mode ATTRIBUTE_UNUSED)
197 f->ts.type = BT_INTEGER;
198 f->ts.kind = gfc_c_int_kind;
199 f->value.function.name = PREFIX ("access_func");
203 void
204 gfc_resolve_adjustl (gfc_expr *f, gfc_expr *string)
206 f->ts.type = BT_CHARACTER;
207 f->ts.kind = string->ts.kind;
208 f->value.function.name = gfc_get_string ("__adjustl_s%d", f->ts.kind);
212 void
213 gfc_resolve_adjustr (gfc_expr *f, gfc_expr *string)
215 f->ts.type = BT_CHARACTER;
216 f->ts.kind = string->ts.kind;
217 f->value.function.name = gfc_get_string ("__adjustr_s%d", f->ts.kind);
221 static void
222 gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind,
223 const char *name)
225 f->ts.type = BT_CHARACTER;
226 f->ts.kind = (kind == NULL)
227 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
228 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
229 f->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
231 f->value.function.name = gfc_get_string (name, f->ts.kind,
232 gfc_type_letter (x->ts.type),
233 x->ts.kind);
237 void
238 gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
240 gfc_resolve_char_achar (f, x, kind, "__achar_%d_%c%d");
244 void
245 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
247 f->ts = x->ts;
248 f->value.function.name
249 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
253 void
254 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
256 f->ts = x->ts;
257 f->value.function.name
258 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
259 x->ts.kind);
263 void
264 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
266 f->ts.type = BT_REAL;
267 f->ts.kind = x->ts.kind;
268 f->value.function.name
269 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
270 x->ts.kind);
274 void
275 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
277 f->ts.type = i->ts.type;
278 f->ts.kind = gfc_kind_max (i, j);
280 if (i->ts.kind != j->ts.kind)
282 if (i->ts.kind == gfc_kind_max (i, j))
283 gfc_convert_type (j, &i->ts, 2);
284 else
285 gfc_convert_type (i, &j->ts, 2);
288 f->value.function.name
289 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
293 void
294 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
296 gfc_typespec ts;
297 gfc_clear_ts (&ts);
299 f->ts.type = a->ts.type;
300 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
302 if (a->ts.kind != f->ts.kind)
304 ts.type = f->ts.type;
305 ts.kind = f->ts.kind;
306 gfc_convert_type (a, &ts, 2);
308 /* The resolved name is only used for specific intrinsics where
309 the return kind is the same as the arg kind. */
310 f->value.function.name
311 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
315 void
316 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
318 gfc_resolve_aint (f, a, NULL);
322 void
323 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
325 f->ts = mask->ts;
327 if (dim != NULL)
329 gfc_resolve_dim_arg (dim);
330 f->rank = mask->rank - 1;
331 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
334 f->value.function.name
335 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
336 mask->ts.kind);
340 void
341 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
343 gfc_typespec ts;
344 gfc_clear_ts (&ts);
346 f->ts.type = a->ts.type;
347 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
349 if (a->ts.kind != f->ts.kind)
351 ts.type = f->ts.type;
352 ts.kind = f->ts.kind;
353 gfc_convert_type (a, &ts, 2);
356 /* The resolved name is only used for specific intrinsics where
357 the return kind is the same as the arg kind. */
358 f->value.function.name
359 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
360 a->ts.kind);
364 void
365 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
367 gfc_resolve_anint (f, a, NULL);
371 void
372 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
374 f->ts = mask->ts;
376 if (dim != NULL)
378 gfc_resolve_dim_arg (dim);
379 f->rank = mask->rank - 1;
380 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
383 f->value.function.name
384 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
385 mask->ts.kind);
389 void
390 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
392 f->ts = x->ts;
393 f->value.function.name
394 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
397 void
398 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
400 f->ts = x->ts;
401 f->value.function.name
402 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
403 x->ts.kind);
406 void
407 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
409 f->ts = x->ts;
410 f->value.function.name
411 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
414 void
415 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
417 f->ts = x->ts;
418 f->value.function.name
419 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
420 x->ts.kind);
423 void
424 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
426 f->ts = x->ts;
427 f->value.function.name
428 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
429 x->ts.kind);
433 /* Resolve the BESYN and BESJN intrinsics. */
435 void
436 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
438 gfc_typespec ts;
439 gfc_clear_ts (&ts);
441 f->ts = x->ts;
442 if (n->ts.kind != gfc_c_int_kind)
444 ts.type = BT_INTEGER;
445 ts.kind = gfc_c_int_kind;
446 gfc_convert_type (n, &ts, 2);
448 f->value.function.name = gfc_get_string ("<intrinsic>");
452 void
453 gfc_resolve_bessel_n2 (gfc_expr *f, gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
455 gfc_typespec ts;
456 gfc_clear_ts (&ts);
458 f->ts = x->ts;
459 f->rank = 1;
460 if (n1->expr_type == EXPR_CONSTANT && n2->expr_type == EXPR_CONSTANT)
462 f->shape = gfc_get_shape (1);
463 mpz_init (f->shape[0]);
464 mpz_sub (f->shape[0], n2->value.integer, n1->value.integer);
465 mpz_add_ui (f->shape[0], f->shape[0], 1);
468 if (n1->ts.kind != gfc_c_int_kind)
470 ts.type = BT_INTEGER;
471 ts.kind = gfc_c_int_kind;
472 gfc_convert_type (n1, &ts, 2);
475 if (n2->ts.kind != gfc_c_int_kind)
477 ts.type = BT_INTEGER;
478 ts.kind = gfc_c_int_kind;
479 gfc_convert_type (n2, &ts, 2);
482 if (f->value.function.isym->id == GFC_ISYM_JN2)
483 f->value.function.name = gfc_get_string (PREFIX ("bessel_jn_r%d"),
484 f->ts.kind);
485 else
486 f->value.function.name = gfc_get_string (PREFIX ("bessel_yn_r%d"),
487 f->ts.kind);
491 void
492 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
494 f->ts.type = BT_LOGICAL;
495 f->ts.kind = gfc_default_logical_kind;
496 f->value.function.name
497 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
501 void
502 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
504 f->ts.type = BT_INTEGER;
505 f->ts.kind = (kind == NULL)
506 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
507 f->value.function.name
508 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
509 gfc_type_letter (a->ts.type), a->ts.kind);
513 void
514 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
516 gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d");
520 void
521 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
523 f->ts.type = BT_INTEGER;
524 f->ts.kind = gfc_default_integer_kind;
525 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
529 void
530 gfc_resolve_chdir_sub (gfc_code *c)
532 const char *name;
533 int kind;
535 if (c->ext.actual->next->expr != NULL)
536 kind = c->ext.actual->next->expr->ts.kind;
537 else
538 kind = gfc_default_integer_kind;
540 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
541 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
545 void
546 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
547 gfc_expr *mode ATTRIBUTE_UNUSED)
549 f->ts.type = BT_INTEGER;
550 f->ts.kind = gfc_c_int_kind;
551 f->value.function.name = PREFIX ("chmod_func");
555 void
556 gfc_resolve_chmod_sub (gfc_code *c)
558 const char *name;
559 int kind;
561 if (c->ext.actual->next->next->expr != NULL)
562 kind = c->ext.actual->next->next->expr->ts.kind;
563 else
564 kind = gfc_default_integer_kind;
566 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
567 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
571 void
572 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
574 f->ts.type = BT_COMPLEX;
575 f->ts.kind = (kind == NULL)
576 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
578 if (y == NULL)
579 f->value.function.name
580 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
581 gfc_type_letter (x->ts.type), x->ts.kind);
582 else
583 f->value.function.name
584 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
585 gfc_type_letter (x->ts.type), x->ts.kind,
586 gfc_type_letter (y->ts.type), y->ts.kind);
590 void
591 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
593 gfc_resolve_cmplx (f, x, y, gfc_get_int_expr (gfc_default_integer_kind, NULL,
594 gfc_default_double_kind));
598 void
599 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
601 int kind;
603 if (x->ts.type == BT_INTEGER)
605 if (y->ts.type == BT_INTEGER)
606 kind = gfc_default_real_kind;
607 else
608 kind = y->ts.kind;
610 else
612 if (y->ts.type == BT_REAL)
613 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
614 else
615 kind = x->ts.kind;
618 f->ts.type = BT_COMPLEX;
619 f->ts.kind = kind;
620 f->value.function.name
621 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
622 gfc_type_letter (x->ts.type), x->ts.kind,
623 gfc_type_letter (y->ts.type), y->ts.kind);
627 void
628 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
630 f->ts = x->ts;
631 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
635 void
636 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
638 f->ts = x->ts;
639 f->value.function.name
640 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
644 void
645 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
647 f->ts = x->ts;
648 f->value.function.name
649 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
653 void
654 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
656 f->ts.type = BT_INTEGER;
657 if (kind)
658 f->ts.kind = mpz_get_si (kind->value.integer);
659 else
660 f->ts.kind = gfc_default_integer_kind;
662 if (dim != NULL)
664 f->rank = mask->rank - 1;
665 gfc_resolve_dim_arg (dim);
666 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
669 resolve_mask_arg (mask);
671 f->value.function.name
672 = gfc_get_string (PREFIX ("count_%d_%c"), f->ts.kind,
673 gfc_type_letter (mask->ts.type));
677 void
678 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
679 gfc_expr *dim)
681 int n, m;
683 if (array->ts.type == BT_CHARACTER && array->ref)
684 gfc_resolve_substring_charlen (array);
686 f->ts = array->ts;
687 f->rank = array->rank;
688 f->shape = gfc_copy_shape (array->shape, array->rank);
690 if (shift->rank > 0)
691 n = 1;
692 else
693 n = 0;
695 /* If dim kind is greater than default integer we need to use the larger. */
696 m = gfc_default_integer_kind;
697 if (dim != NULL)
698 m = m < dim->ts.kind ? dim->ts.kind : m;
700 /* Convert shift to at least m, so we don't need
701 kind=1 and kind=2 versions of the library functions. */
702 if (shift->ts.kind < m)
704 gfc_typespec ts;
705 gfc_clear_ts (&ts);
706 ts.type = BT_INTEGER;
707 ts.kind = m;
708 gfc_convert_type_warn (shift, &ts, 2, 0);
711 if (dim != NULL)
713 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
714 && dim->symtree->n.sym->attr.optional)
716 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
717 dim->representation.length = shift->ts.kind;
719 else
721 gfc_resolve_dim_arg (dim);
722 /* Convert dim to shift's kind to reduce variations. */
723 if (dim->ts.kind != shift->ts.kind)
724 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
728 if (array->ts.type == BT_CHARACTER)
730 if (array->ts.kind == gfc_default_character_kind)
731 f->value.function.name
732 = gfc_get_string (PREFIX ("cshift%d_%d_char"), n, shift->ts.kind);
733 else
734 f->value.function.name
735 = gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n, shift->ts.kind,
736 array->ts.kind);
738 else
739 f->value.function.name
740 = gfc_get_string (PREFIX ("cshift%d_%d"), n, shift->ts.kind);
744 void
745 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
747 gfc_typespec ts;
748 gfc_clear_ts (&ts);
750 f->ts.type = BT_CHARACTER;
751 f->ts.kind = gfc_default_character_kind;
753 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
754 if (time->ts.kind != 8)
756 ts.type = BT_INTEGER;
757 ts.kind = 8;
758 ts.u.derived = NULL;
759 ts.u.cl = NULL;
760 gfc_convert_type (time, &ts, 2);
763 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
767 void
768 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
770 f->ts.type = BT_REAL;
771 f->ts.kind = gfc_default_double_kind;
772 f->value.function.name
773 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
777 void
778 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
780 f->ts.type = a->ts.type;
781 if (p != NULL)
782 f->ts.kind = gfc_kind_max (a,p);
783 else
784 f->ts.kind = a->ts.kind;
786 if (p != NULL && a->ts.kind != p->ts.kind)
788 if (a->ts.kind == gfc_kind_max (a,p))
789 gfc_convert_type (p, &a->ts, 2);
790 else
791 gfc_convert_type (a, &p->ts, 2);
794 f->value.function.name
795 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
799 void
800 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
802 gfc_expr temp;
804 temp.expr_type = EXPR_OP;
805 gfc_clear_ts (&temp.ts);
806 temp.value.op.op = INTRINSIC_NONE;
807 temp.value.op.op1 = a;
808 temp.value.op.op2 = b;
809 gfc_type_convert_binary (&temp, 1);
810 f->ts = temp.ts;
811 f->value.function.name
812 = gfc_get_string (PREFIX ("dot_product_%c%d"),
813 gfc_type_letter (f->ts.type), f->ts.kind);
817 void
818 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
819 gfc_expr *b ATTRIBUTE_UNUSED)
821 f->ts.kind = gfc_default_double_kind;
822 f->ts.type = BT_REAL;
823 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
827 void
828 gfc_resolve_dshift (gfc_expr *f, gfc_expr *i, gfc_expr *j ATTRIBUTE_UNUSED,
829 gfc_expr *shift ATTRIBUTE_UNUSED)
831 f->ts = i->ts;
832 if (f->value.function.isym->id == GFC_ISYM_DSHIFTL)
833 f->value.function.name = gfc_get_string ("dshiftl_i%d", f->ts.kind);
834 else if (f->value.function.isym->id == GFC_ISYM_DSHIFTR)
835 f->value.function.name = gfc_get_string ("dshiftr_i%d", f->ts.kind);
836 else
837 gcc_unreachable ();
841 void
842 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
843 gfc_expr *boundary, gfc_expr *dim)
845 int n, m;
847 if (array->ts.type == BT_CHARACTER && array->ref)
848 gfc_resolve_substring_charlen (array);
850 f->ts = array->ts;
851 f->rank = array->rank;
852 f->shape = gfc_copy_shape (array->shape, array->rank);
854 n = 0;
855 if (shift->rank > 0)
856 n = n | 1;
857 if (boundary && boundary->rank > 0)
858 n = n | 2;
860 /* If dim kind is greater than default integer we need to use the larger. */
861 m = gfc_default_integer_kind;
862 if (dim != NULL)
863 m = m < dim->ts.kind ? dim->ts.kind : m;
865 /* Convert shift to at least m, so we don't need
866 kind=1 and kind=2 versions of the library functions. */
867 if (shift->ts.kind < m)
869 gfc_typespec ts;
870 gfc_clear_ts (&ts);
871 ts.type = BT_INTEGER;
872 ts.kind = m;
873 gfc_convert_type_warn (shift, &ts, 2, 0);
876 if (dim != NULL)
878 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
879 && dim->symtree->n.sym->attr.optional)
881 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
882 dim->representation.length = shift->ts.kind;
884 else
886 gfc_resolve_dim_arg (dim);
887 /* Convert dim to shift's kind to reduce variations. */
888 if (dim->ts.kind != shift->ts.kind)
889 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
893 if (array->ts.type == BT_CHARACTER)
895 if (array->ts.kind == gfc_default_character_kind)
896 f->value.function.name
897 = gfc_get_string (PREFIX ("eoshift%d_%d_char"), n, shift->ts.kind);
898 else
899 f->value.function.name
900 = gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n, shift->ts.kind,
901 array->ts.kind);
903 else
904 f->value.function.name
905 = gfc_get_string (PREFIX ("eoshift%d_%d"), n, shift->ts.kind);
909 void
910 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
912 f->ts = x->ts;
913 f->value.function.name
914 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
918 void
919 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
921 f->ts.type = BT_INTEGER;
922 f->ts.kind = gfc_default_integer_kind;
923 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
927 /* Resolve the EXTENDS_TYPE_OF intrinsic function. */
929 void
930 gfc_resolve_extends_type_of (gfc_expr *f, gfc_expr *a, gfc_expr *mo)
932 gfc_symbol *vtab;
933 gfc_symtree *st;
935 /* Prevent double resolution. */
936 if (f->ts.type == BT_LOGICAL)
937 return;
939 /* Replace the first argument with the corresponding vtab. */
940 if (a->ts.type == BT_CLASS)
941 gfc_add_vptr_component (a);
942 else if (a->ts.type == BT_DERIVED)
944 vtab = gfc_find_derived_vtab (a->ts.u.derived);
945 /* Clear the old expr. */
946 gfc_free_ref_list (a->ref);
947 memset (a, '\0', sizeof (gfc_expr));
948 /* Construct a new one. */
949 a->expr_type = EXPR_VARIABLE;
950 st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
951 a->symtree = st;
952 a->ts = vtab->ts;
955 /* Replace the second argument with the corresponding vtab. */
956 if (mo->ts.type == BT_CLASS)
957 gfc_add_vptr_component (mo);
958 else if (mo->ts.type == BT_DERIVED)
960 vtab = gfc_find_derived_vtab (mo->ts.u.derived);
961 /* Clear the old expr. */
962 gfc_free_ref_list (mo->ref);
963 memset (mo, '\0', sizeof (gfc_expr));
964 /* Construct a new one. */
965 mo->expr_type = EXPR_VARIABLE;
966 st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
967 mo->symtree = st;
968 mo->ts = vtab->ts;
971 f->ts.type = BT_LOGICAL;
972 f->ts.kind = 4;
974 f->value.function.isym->formal->ts = a->ts;
975 f->value.function.isym->formal->next->ts = mo->ts;
977 /* Call library function. */
978 f->value.function.name = gfc_get_string (PREFIX ("is_extension_of"));
982 void
983 gfc_resolve_fdate (gfc_expr *f)
985 f->ts.type = BT_CHARACTER;
986 f->ts.kind = gfc_default_character_kind;
987 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
991 void
992 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
994 f->ts.type = BT_INTEGER;
995 f->ts.kind = (kind == NULL)
996 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
997 f->value.function.name
998 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
999 gfc_type_letter (a->ts.type), a->ts.kind);
1003 void
1004 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
1006 f->ts.type = BT_INTEGER;
1007 f->ts.kind = gfc_default_integer_kind;
1008 if (n->ts.kind != f->ts.kind)
1009 gfc_convert_type (n, &f->ts, 2);
1010 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
1014 void
1015 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
1017 f->ts = x->ts;
1018 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
1022 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
1024 void
1025 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
1027 f->ts = x->ts;
1028 f->value.function.name = gfc_get_string ("<intrinsic>");
1032 void
1033 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
1035 f->ts = x->ts;
1036 f->value.function.name
1037 = gfc_get_string ("__tgamma_%d", x->ts.kind);
1041 void
1042 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
1044 f->ts.type = BT_INTEGER;
1045 f->ts.kind = 4;
1046 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
1050 void
1051 gfc_resolve_getgid (gfc_expr *f)
1053 f->ts.type = BT_INTEGER;
1054 f->ts.kind = 4;
1055 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
1059 void
1060 gfc_resolve_getpid (gfc_expr *f)
1062 f->ts.type = BT_INTEGER;
1063 f->ts.kind = 4;
1064 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
1068 void
1069 gfc_resolve_getuid (gfc_expr *f)
1071 f->ts.type = BT_INTEGER;
1072 f->ts.kind = 4;
1073 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
1077 void
1078 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
1080 f->ts.type = BT_INTEGER;
1081 f->ts.kind = 4;
1082 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
1086 void
1087 gfc_resolve_hypot (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
1089 f->ts = x->ts;
1090 f->value.function.name = gfc_get_string ("__hypot_r%d", x->ts.kind);
1094 void
1095 gfc_resolve_iall (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1097 resolve_transformational ("iall", f, array, dim, mask);
1101 void
1102 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1104 /* If the kind of i and j are different, then g77 cross-promoted the
1105 kinds to the largest value. The Fortran 95 standard requires the
1106 kinds to match. */
1107 if (i->ts.kind != j->ts.kind)
1109 if (i->ts.kind == gfc_kind_max (i, j))
1110 gfc_convert_type (j, &i->ts, 2);
1111 else
1112 gfc_convert_type (i, &j->ts, 2);
1115 f->ts = i->ts;
1116 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
1120 void
1121 gfc_resolve_iany (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1123 resolve_transformational ("iany", f, array, dim, mask);
1127 void
1128 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1130 f->ts = i->ts;
1131 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
1135 void
1136 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
1137 gfc_expr *len ATTRIBUTE_UNUSED)
1139 f->ts = i->ts;
1140 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
1144 void
1145 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1147 f->ts = i->ts;
1148 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
1152 void
1153 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1155 f->ts.type = BT_INTEGER;
1156 if (kind)
1157 f->ts.kind = mpz_get_si (kind->value.integer);
1158 else
1159 f->ts.kind = gfc_default_integer_kind;
1160 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1164 void
1165 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1167 f->ts.type = BT_INTEGER;
1168 if (kind)
1169 f->ts.kind = mpz_get_si (kind->value.integer);
1170 else
1171 f->ts.kind = gfc_default_integer_kind;
1172 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1176 void
1177 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
1179 gfc_resolve_nint (f, a, NULL);
1183 void
1184 gfc_resolve_ierrno (gfc_expr *f)
1186 f->ts.type = BT_INTEGER;
1187 f->ts.kind = gfc_default_integer_kind;
1188 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
1192 void
1193 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1195 /* If the kind of i and j are different, then g77 cross-promoted the
1196 kinds to the largest value. The Fortran 95 standard requires the
1197 kinds to match. */
1198 if (i->ts.kind != j->ts.kind)
1200 if (i->ts.kind == gfc_kind_max (i, j))
1201 gfc_convert_type (j, &i->ts, 2);
1202 else
1203 gfc_convert_type (i, &j->ts, 2);
1206 f->ts = i->ts;
1207 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
1211 void
1212 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1214 /* If the kind of i and j are different, then g77 cross-promoted the
1215 kinds to the largest value. The Fortran 95 standard requires the
1216 kinds to match. */
1217 if (i->ts.kind != j->ts.kind)
1219 if (i->ts.kind == gfc_kind_max (i, j))
1220 gfc_convert_type (j, &i->ts, 2);
1221 else
1222 gfc_convert_type (i, &j->ts, 2);
1225 f->ts = i->ts;
1226 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
1230 void
1231 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
1232 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
1233 gfc_expr *kind)
1235 gfc_typespec ts;
1236 gfc_clear_ts (&ts);
1238 f->ts.type = BT_INTEGER;
1239 if (kind)
1240 f->ts.kind = mpz_get_si (kind->value.integer);
1241 else
1242 f->ts.kind = gfc_default_integer_kind;
1244 if (back && back->ts.kind != gfc_default_integer_kind)
1246 ts.type = BT_LOGICAL;
1247 ts.kind = gfc_default_integer_kind;
1248 ts.u.derived = NULL;
1249 ts.u.cl = NULL;
1250 gfc_convert_type (back, &ts, 2);
1253 f->value.function.name
1254 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
1258 void
1259 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1261 f->ts.type = BT_INTEGER;
1262 f->ts.kind = (kind == NULL)
1263 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1264 f->value.function.name
1265 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1266 gfc_type_letter (a->ts.type), a->ts.kind);
1270 void
1271 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1273 f->ts.type = BT_INTEGER;
1274 f->ts.kind = 2;
1275 f->value.function.name
1276 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1277 gfc_type_letter (a->ts.type), a->ts.kind);
1281 void
1282 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
1284 f->ts.type = BT_INTEGER;
1285 f->ts.kind = 8;
1286 f->value.function.name
1287 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1288 gfc_type_letter (a->ts.type), a->ts.kind);
1292 void
1293 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1295 f->ts.type = BT_INTEGER;
1296 f->ts.kind = 4;
1297 f->value.function.name
1298 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1299 gfc_type_letter (a->ts.type), a->ts.kind);
1303 void
1304 gfc_resolve_iparity (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1306 resolve_transformational ("iparity", f, array, dim, mask);
1310 void
1311 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1313 gfc_typespec ts;
1314 gfc_clear_ts (&ts);
1316 f->ts.type = BT_LOGICAL;
1317 f->ts.kind = gfc_default_integer_kind;
1318 if (u->ts.kind != gfc_c_int_kind)
1320 ts.type = BT_INTEGER;
1321 ts.kind = gfc_c_int_kind;
1322 ts.u.derived = NULL;
1323 ts.u.cl = NULL;
1324 gfc_convert_type (u, &ts, 2);
1327 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1331 void
1332 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1334 f->ts = i->ts;
1335 f->value.function.name
1336 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1340 void
1341 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1343 f->ts = i->ts;
1344 f->value.function.name
1345 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1349 void
1350 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1352 f->ts = i->ts;
1353 f->value.function.name
1354 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1358 void
1359 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1361 int s_kind;
1363 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1365 f->ts = i->ts;
1366 f->value.function.name
1367 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1371 void
1372 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1373 gfc_expr *s ATTRIBUTE_UNUSED)
1375 f->ts.type = BT_INTEGER;
1376 f->ts.kind = gfc_default_integer_kind;
1377 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1381 void
1382 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1384 resolve_bound (f, array, dim, kind, "__lbound", false);
1388 void
1389 gfc_resolve_lcobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1391 resolve_bound (f, array, dim, kind, "__lcobound", true);
1395 void
1396 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1398 f->ts.type = BT_INTEGER;
1399 if (kind)
1400 f->ts.kind = mpz_get_si (kind->value.integer);
1401 else
1402 f->ts.kind = gfc_default_integer_kind;
1403 f->value.function.name
1404 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1405 gfc_default_integer_kind);
1409 void
1410 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1412 f->ts.type = BT_INTEGER;
1413 if (kind)
1414 f->ts.kind = mpz_get_si (kind->value.integer);
1415 else
1416 f->ts.kind = gfc_default_integer_kind;
1417 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1421 void
1422 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1424 f->ts = x->ts;
1425 f->value.function.name
1426 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1430 void
1431 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1432 gfc_expr *p2 ATTRIBUTE_UNUSED)
1434 f->ts.type = BT_INTEGER;
1435 f->ts.kind = gfc_default_integer_kind;
1436 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1440 void
1441 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1443 f->ts.type= BT_INTEGER;
1444 f->ts.kind = gfc_index_integer_kind;
1445 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1449 void
1450 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1452 f->ts = x->ts;
1453 f->value.function.name
1454 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1458 void
1459 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1461 f->ts = x->ts;
1462 f->value.function.name
1463 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1464 x->ts.kind);
1468 void
1469 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1471 f->ts.type = BT_LOGICAL;
1472 f->ts.kind = (kind == NULL)
1473 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1474 f->rank = a->rank;
1476 f->value.function.name
1477 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1478 gfc_type_letter (a->ts.type), a->ts.kind);
1482 void
1483 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1485 if (size->ts.kind < gfc_index_integer_kind)
1487 gfc_typespec ts;
1488 gfc_clear_ts (&ts);
1490 ts.type = BT_INTEGER;
1491 ts.kind = gfc_index_integer_kind;
1492 gfc_convert_type_warn (size, &ts, 2, 0);
1495 f->ts.type = BT_INTEGER;
1496 f->ts.kind = gfc_index_integer_kind;
1497 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1501 void
1502 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1504 gfc_expr temp;
1506 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1508 f->ts.type = BT_LOGICAL;
1509 f->ts.kind = gfc_default_logical_kind;
1511 else
1513 temp.expr_type = EXPR_OP;
1514 gfc_clear_ts (&temp.ts);
1515 temp.value.op.op = INTRINSIC_NONE;
1516 temp.value.op.op1 = a;
1517 temp.value.op.op2 = b;
1518 gfc_type_convert_binary (&temp, 1);
1519 f->ts = temp.ts;
1522 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1524 if (a->rank == 2 && b->rank == 2)
1526 if (a->shape && b->shape)
1528 f->shape = gfc_get_shape (f->rank);
1529 mpz_init_set (f->shape[0], a->shape[0]);
1530 mpz_init_set (f->shape[1], b->shape[1]);
1533 else if (a->rank == 1)
1535 if (b->shape)
1537 f->shape = gfc_get_shape (f->rank);
1538 mpz_init_set (f->shape[0], b->shape[1]);
1541 else
1543 /* b->rank == 1 and a->rank == 2 here, all other cases have
1544 been caught in check.c. */
1545 if (a->shape)
1547 f->shape = gfc_get_shape (f->rank);
1548 mpz_init_set (f->shape[0], a->shape[0]);
1552 f->value.function.name
1553 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1554 f->ts.kind);
1558 static void
1559 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1561 gfc_actual_arglist *a;
1563 f->ts.type = args->expr->ts.type;
1564 f->ts.kind = args->expr->ts.kind;
1565 /* Find the largest type kind. */
1566 for (a = args->next; a; a = a->next)
1568 if (a->expr->ts.kind > f->ts.kind)
1569 f->ts.kind = a->expr->ts.kind;
1572 /* Convert all parameters to the required kind. */
1573 for (a = args; a; a = a->next)
1575 if (a->expr->ts.kind != f->ts.kind)
1576 gfc_convert_type (a->expr, &f->ts, 2);
1579 f->value.function.name
1580 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1584 void
1585 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1587 gfc_resolve_minmax ("__max_%c%d", f, args);
1591 void
1592 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1593 gfc_expr *mask)
1595 const char *name;
1596 int i, j, idim;
1598 f->ts.type = BT_INTEGER;
1599 f->ts.kind = gfc_default_integer_kind;
1601 if (dim == NULL)
1603 f->rank = 1;
1604 f->shape = gfc_get_shape (1);
1605 mpz_init_set_si (f->shape[0], array->rank);
1607 else
1609 f->rank = array->rank - 1;
1610 gfc_resolve_dim_arg (dim);
1611 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1613 idim = (int) mpz_get_si (dim->value.integer);
1614 f->shape = gfc_get_shape (f->rank);
1615 for (i = 0, j = 0; i < f->rank; i++, j++)
1617 if (i == (idim - 1))
1618 j++;
1619 mpz_init_set (f->shape[i], array->shape[j]);
1624 if (mask)
1626 if (mask->rank == 0)
1627 name = "smaxloc";
1628 else
1629 name = "mmaxloc";
1631 resolve_mask_arg (mask);
1633 else
1634 name = "maxloc";
1636 f->value.function.name
1637 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1638 gfc_type_letter (array->ts.type), array->ts.kind);
1642 void
1643 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1644 gfc_expr *mask)
1646 const char *name;
1647 int i, j, idim;
1649 f->ts = array->ts;
1651 if (dim != NULL)
1653 f->rank = array->rank - 1;
1654 gfc_resolve_dim_arg (dim);
1656 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1658 idim = (int) mpz_get_si (dim->value.integer);
1659 f->shape = gfc_get_shape (f->rank);
1660 for (i = 0, j = 0; i < f->rank; i++, j++)
1662 if (i == (idim - 1))
1663 j++;
1664 mpz_init_set (f->shape[i], array->shape[j]);
1669 if (mask)
1671 if (mask->rank == 0)
1672 name = "smaxval";
1673 else
1674 name = "mmaxval";
1676 resolve_mask_arg (mask);
1678 else
1679 name = "maxval";
1681 f->value.function.name
1682 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1683 gfc_type_letter (array->ts.type), array->ts.kind);
1687 void
1688 gfc_resolve_mclock (gfc_expr *f)
1690 f->ts.type = BT_INTEGER;
1691 f->ts.kind = 4;
1692 f->value.function.name = PREFIX ("mclock");
1696 void
1697 gfc_resolve_mclock8 (gfc_expr *f)
1699 f->ts.type = BT_INTEGER;
1700 f->ts.kind = 8;
1701 f->value.function.name = PREFIX ("mclock8");
1705 void
1706 gfc_resolve_mask (gfc_expr *f, gfc_expr *i ATTRIBUTE_UNUSED,
1707 gfc_expr *kind)
1709 f->ts.type = BT_INTEGER;
1710 f->ts.kind = kind ? mpz_get_si (kind->value.integer)
1711 : gfc_default_integer_kind;
1713 if (f->value.function.isym->id == GFC_ISYM_MASKL)
1714 f->value.function.name = gfc_get_string ("__maskl_i%d", f->ts.kind);
1715 else
1716 f->value.function.name = gfc_get_string ("__maskr_i%d", f->ts.kind);
1720 void
1721 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1722 gfc_expr *fsource ATTRIBUTE_UNUSED,
1723 gfc_expr *mask ATTRIBUTE_UNUSED)
1725 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1726 gfc_resolve_substring_charlen (tsource);
1728 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1729 gfc_resolve_substring_charlen (fsource);
1731 if (tsource->ts.type == BT_CHARACTER)
1732 check_charlen_present (tsource);
1734 f->ts = tsource->ts;
1735 f->value.function.name
1736 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1737 tsource->ts.kind);
1741 void
1742 gfc_resolve_merge_bits (gfc_expr *f, gfc_expr *i,
1743 gfc_expr *j ATTRIBUTE_UNUSED,
1744 gfc_expr *mask ATTRIBUTE_UNUSED)
1746 f->ts = i->ts;
1747 f->value.function.name = gfc_get_string ("__merge_bits_i%d", i->ts.kind);
1751 void
1752 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1754 gfc_resolve_minmax ("__min_%c%d", f, args);
1758 void
1759 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1760 gfc_expr *mask)
1762 const char *name;
1763 int i, j, idim;
1765 f->ts.type = BT_INTEGER;
1766 f->ts.kind = gfc_default_integer_kind;
1768 if (dim == NULL)
1770 f->rank = 1;
1771 f->shape = gfc_get_shape (1);
1772 mpz_init_set_si (f->shape[0], array->rank);
1774 else
1776 f->rank = array->rank - 1;
1777 gfc_resolve_dim_arg (dim);
1778 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1780 idim = (int) mpz_get_si (dim->value.integer);
1781 f->shape = gfc_get_shape (f->rank);
1782 for (i = 0, j = 0; i < f->rank; i++, j++)
1784 if (i == (idim - 1))
1785 j++;
1786 mpz_init_set (f->shape[i], array->shape[j]);
1791 if (mask)
1793 if (mask->rank == 0)
1794 name = "sminloc";
1795 else
1796 name = "mminloc";
1798 resolve_mask_arg (mask);
1800 else
1801 name = "minloc";
1803 f->value.function.name
1804 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1805 gfc_type_letter (array->ts.type), array->ts.kind);
1809 void
1810 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1811 gfc_expr *mask)
1813 const char *name;
1814 int i, j, idim;
1816 f->ts = array->ts;
1818 if (dim != NULL)
1820 f->rank = array->rank - 1;
1821 gfc_resolve_dim_arg (dim);
1823 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1825 idim = (int) mpz_get_si (dim->value.integer);
1826 f->shape = gfc_get_shape (f->rank);
1827 for (i = 0, j = 0; i < f->rank; i++, j++)
1829 if (i == (idim - 1))
1830 j++;
1831 mpz_init_set (f->shape[i], array->shape[j]);
1836 if (mask)
1838 if (mask->rank == 0)
1839 name = "sminval";
1840 else
1841 name = "mminval";
1843 resolve_mask_arg (mask);
1845 else
1846 name = "minval";
1848 f->value.function.name
1849 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1850 gfc_type_letter (array->ts.type), array->ts.kind);
1854 void
1855 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1857 f->ts.type = a->ts.type;
1858 if (p != NULL)
1859 f->ts.kind = gfc_kind_max (a,p);
1860 else
1861 f->ts.kind = a->ts.kind;
1863 if (p != NULL && a->ts.kind != p->ts.kind)
1865 if (a->ts.kind == gfc_kind_max (a,p))
1866 gfc_convert_type (p, &a->ts, 2);
1867 else
1868 gfc_convert_type (a, &p->ts, 2);
1871 f->value.function.name
1872 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1876 void
1877 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1879 f->ts.type = a->ts.type;
1880 if (p != NULL)
1881 f->ts.kind = gfc_kind_max (a,p);
1882 else
1883 f->ts.kind = a->ts.kind;
1885 if (p != NULL && a->ts.kind != p->ts.kind)
1887 if (a->ts.kind == gfc_kind_max (a,p))
1888 gfc_convert_type (p, &a->ts, 2);
1889 else
1890 gfc_convert_type (a, &p->ts, 2);
1893 f->value.function.name
1894 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1895 f->ts.kind);
1898 void
1899 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1901 if (p->ts.kind != a->ts.kind)
1902 gfc_convert_type (p, &a->ts, 2);
1904 f->ts = a->ts;
1905 f->value.function.name
1906 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1907 a->ts.kind);
1910 void
1911 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1913 f->ts.type = BT_INTEGER;
1914 f->ts.kind = (kind == NULL)
1915 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1916 f->value.function.name
1917 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1921 void
1922 gfc_resolve_norm2 (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1924 resolve_transformational ("norm2", f, array, dim, NULL);
1928 void
1929 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1931 f->ts = i->ts;
1932 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1936 void
1937 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1939 f->ts.type = i->ts.type;
1940 f->ts.kind = gfc_kind_max (i, j);
1942 if (i->ts.kind != j->ts.kind)
1944 if (i->ts.kind == gfc_kind_max (i, j))
1945 gfc_convert_type (j, &i->ts, 2);
1946 else
1947 gfc_convert_type (i, &j->ts, 2);
1950 f->value.function.name
1951 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1955 void
1956 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1957 gfc_expr *vector ATTRIBUTE_UNUSED)
1959 if (array->ts.type == BT_CHARACTER && array->ref)
1960 gfc_resolve_substring_charlen (array);
1962 f->ts = array->ts;
1963 f->rank = 1;
1965 resolve_mask_arg (mask);
1967 if (mask->rank != 0)
1969 if (array->ts.type == BT_CHARACTER)
1970 f->value.function.name
1971 = array->ts.kind == 1 ? PREFIX ("pack_char")
1972 : gfc_get_string
1973 (PREFIX ("pack_char%d"),
1974 array->ts.kind);
1975 else
1976 f->value.function.name = PREFIX ("pack");
1978 else
1980 if (array->ts.type == BT_CHARACTER)
1981 f->value.function.name
1982 = array->ts.kind == 1 ? PREFIX ("pack_s_char")
1983 : gfc_get_string
1984 (PREFIX ("pack_s_char%d"),
1985 array->ts.kind);
1986 else
1987 f->value.function.name = PREFIX ("pack_s");
1992 void
1993 gfc_resolve_parity (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1995 resolve_transformational ("parity", f, array, dim, NULL);
1999 void
2000 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
2001 gfc_expr *mask)
2003 resolve_transformational ("product", f, array, dim, mask);
2007 void
2008 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
2010 f->ts.type = BT_REAL;
2012 if (kind != NULL)
2013 f->ts.kind = mpz_get_si (kind->value.integer);
2014 else
2015 f->ts.kind = (a->ts.type == BT_COMPLEX)
2016 ? a->ts.kind : gfc_default_real_kind;
2018 f->value.function.name
2019 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
2020 gfc_type_letter (a->ts.type), a->ts.kind);
2024 void
2025 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
2027 f->ts.type = BT_REAL;
2028 f->ts.kind = a->ts.kind;
2029 f->value.function.name
2030 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
2031 gfc_type_letter (a->ts.type), a->ts.kind);
2035 void
2036 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2037 gfc_expr *p2 ATTRIBUTE_UNUSED)
2039 f->ts.type = BT_INTEGER;
2040 f->ts.kind = gfc_default_integer_kind;
2041 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
2045 void
2046 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
2047 gfc_expr *ncopies ATTRIBUTE_UNUSED)
2049 f->ts.type = BT_CHARACTER;
2050 f->ts.kind = string->ts.kind;
2051 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
2055 void
2056 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
2057 gfc_expr *pad ATTRIBUTE_UNUSED,
2058 gfc_expr *order ATTRIBUTE_UNUSED)
2060 mpz_t rank;
2061 int kind;
2062 int i;
2064 if (source->ts.type == BT_CHARACTER && source->ref)
2065 gfc_resolve_substring_charlen (source);
2067 f->ts = source->ts;
2069 gfc_array_size (shape, &rank);
2070 f->rank = mpz_get_si (rank);
2071 mpz_clear (rank);
2072 switch (source->ts.type)
2074 case BT_COMPLEX:
2075 case BT_REAL:
2076 case BT_INTEGER:
2077 case BT_LOGICAL:
2078 case BT_CHARACTER:
2079 kind = source->ts.kind;
2080 break;
2082 default:
2083 kind = 0;
2084 break;
2087 switch (kind)
2089 case 4:
2090 case 8:
2091 case 10:
2092 case 16:
2093 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
2094 f->value.function.name
2095 = gfc_get_string (PREFIX ("reshape_%c%d"),
2096 gfc_type_letter (source->ts.type),
2097 source->ts.kind);
2098 else if (source->ts.type == BT_CHARACTER)
2099 f->value.function.name = gfc_get_string (PREFIX ("reshape_char%d"),
2100 kind);
2101 else
2102 f->value.function.name
2103 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
2104 break;
2106 default:
2107 f->value.function.name = (source->ts.type == BT_CHARACTER
2108 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
2109 break;
2112 /* TODO: Make this work with a constant ORDER parameter. */
2113 if (shape->expr_type == EXPR_ARRAY
2114 && gfc_is_constant_expr (shape)
2115 && order == NULL)
2117 gfc_constructor *c;
2118 f->shape = gfc_get_shape (f->rank);
2119 c = gfc_constructor_first (shape->value.constructor);
2120 for (i = 0; i < f->rank; i++)
2122 mpz_init_set (f->shape[i], c->expr->value.integer);
2123 c = gfc_constructor_next (c);
2127 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
2128 so many runtime variations. */
2129 if (shape->ts.kind != gfc_index_integer_kind)
2131 gfc_typespec ts = shape->ts;
2132 ts.kind = gfc_index_integer_kind;
2133 gfc_convert_type_warn (shape, &ts, 2, 0);
2135 if (order && order->ts.kind != gfc_index_integer_kind)
2136 gfc_convert_type_warn (order, &shape->ts, 2, 0);
2140 void
2141 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
2143 f->ts = x->ts;
2144 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
2148 void
2149 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED)
2151 f->ts = x->ts;
2152 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
2156 void
2157 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
2158 gfc_expr *set ATTRIBUTE_UNUSED,
2159 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2161 f->ts.type = BT_INTEGER;
2162 if (kind)
2163 f->ts.kind = mpz_get_si (kind->value.integer);
2164 else
2165 f->ts.kind = gfc_default_integer_kind;
2166 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
2170 void
2171 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
2173 t1->ts = t0->ts;
2174 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
2178 void
2179 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x,
2180 gfc_expr *i ATTRIBUTE_UNUSED)
2182 f->ts = x->ts;
2183 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
2187 void
2188 gfc_resolve_shape (gfc_expr *f, gfc_expr *array, gfc_expr *kind)
2190 f->ts.type = BT_INTEGER;
2192 if (kind)
2193 f->ts.kind = mpz_get_si (kind->value.integer);
2194 else
2195 f->ts.kind = gfc_default_integer_kind;
2197 f->rank = 1;
2198 f->shape = gfc_get_shape (1);
2199 mpz_init_set_ui (f->shape[0], array->rank);
2200 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
2204 void
2205 gfc_resolve_shift (gfc_expr *f, gfc_expr *i, gfc_expr *shift ATTRIBUTE_UNUSED)
2207 f->ts = i->ts;
2208 if (f->value.function.isym->id == GFC_ISYM_SHIFTA)
2209 f->value.function.name = gfc_get_string ("shifta_i%d", f->ts.kind);
2210 else if (f->value.function.isym->id == GFC_ISYM_SHIFTL)
2211 f->value.function.name = gfc_get_string ("shiftl_i%d", f->ts.kind);
2212 else if (f->value.function.isym->id == GFC_ISYM_SHIFTR)
2213 f->value.function.name = gfc_get_string ("shiftr_i%d", f->ts.kind);
2214 else
2215 gcc_unreachable ();
2219 void
2220 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
2222 f->ts = a->ts;
2223 f->value.function.name
2224 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
2228 void
2229 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
2231 f->ts.type = BT_INTEGER;
2232 f->ts.kind = gfc_c_int_kind;
2234 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2235 if (handler->ts.type == BT_INTEGER)
2237 if (handler->ts.kind != gfc_c_int_kind)
2238 gfc_convert_type (handler, &f->ts, 2);
2239 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
2241 else
2242 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
2244 if (number->ts.kind != gfc_c_int_kind)
2245 gfc_convert_type (number, &f->ts, 2);
2249 void
2250 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
2252 f->ts = x->ts;
2253 f->value.function.name
2254 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2258 void
2259 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
2261 f->ts = x->ts;
2262 f->value.function.name
2263 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2267 void
2268 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2269 gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
2271 f->ts.type = BT_INTEGER;
2272 if (kind)
2273 f->ts.kind = mpz_get_si (kind->value.integer);
2274 else
2275 f->ts.kind = gfc_default_integer_kind;
2279 void
2280 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
2282 f->ts = x->ts;
2283 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
2287 void
2288 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2289 gfc_expr *ncopies)
2291 if (source->ts.type == BT_CHARACTER && source->ref)
2292 gfc_resolve_substring_charlen (source);
2294 if (source->ts.type == BT_CHARACTER)
2295 check_charlen_present (source);
2297 f->ts = source->ts;
2298 f->rank = source->rank + 1;
2299 if (source->rank == 0)
2301 if (source->ts.type == BT_CHARACTER)
2302 f->value.function.name
2303 = source->ts.kind == 1 ? PREFIX ("spread_char_scalar")
2304 : gfc_get_string
2305 (PREFIX ("spread_char%d_scalar"),
2306 source->ts.kind);
2307 else
2308 f->value.function.name = PREFIX ("spread_scalar");
2310 else
2312 if (source->ts.type == BT_CHARACTER)
2313 f->value.function.name
2314 = source->ts.kind == 1 ? PREFIX ("spread_char")
2315 : gfc_get_string
2316 (PREFIX ("spread_char%d"),
2317 source->ts.kind);
2318 else
2319 f->value.function.name = PREFIX ("spread");
2322 if (dim && gfc_is_constant_expr (dim)
2323 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2325 int i, idim;
2326 idim = mpz_get_ui (dim->value.integer);
2327 f->shape = gfc_get_shape (f->rank);
2328 for (i = 0; i < (idim - 1); i++)
2329 mpz_init_set (f->shape[i], source->shape[i]);
2331 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2333 for (i = idim; i < f->rank ; i++)
2334 mpz_init_set (f->shape[i], source->shape[i-1]);
2338 gfc_resolve_dim_arg (dim);
2339 gfc_resolve_index (ncopies, 1);
2343 void
2344 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2346 f->ts = x->ts;
2347 f->value.function.name
2348 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2352 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2354 void
2355 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2356 gfc_expr *a ATTRIBUTE_UNUSED)
2358 f->ts.type = BT_INTEGER;
2359 f->ts.kind = gfc_default_integer_kind;
2360 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2364 void
2365 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2366 gfc_expr *a ATTRIBUTE_UNUSED)
2368 f->ts.type = BT_INTEGER;
2369 f->ts.kind = gfc_default_integer_kind;
2370 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2374 void
2375 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2377 f->ts.type = BT_INTEGER;
2378 f->ts.kind = gfc_default_integer_kind;
2379 if (n->ts.kind != f->ts.kind)
2380 gfc_convert_type (n, &f->ts, 2);
2382 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2386 void
2387 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2389 gfc_typespec ts;
2390 gfc_clear_ts (&ts);
2392 f->ts.type = BT_INTEGER;
2393 f->ts.kind = gfc_c_int_kind;
2394 if (u->ts.kind != gfc_c_int_kind)
2396 ts.type = BT_INTEGER;
2397 ts.kind = gfc_c_int_kind;
2398 ts.u.derived = NULL;
2399 ts.u.cl = NULL;
2400 gfc_convert_type (u, &ts, 2);
2403 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2407 void
2408 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2410 f->ts.type = BT_INTEGER;
2411 f->ts.kind = gfc_c_int_kind;
2412 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2416 void
2417 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2419 gfc_typespec ts;
2420 gfc_clear_ts (&ts);
2422 f->ts.type = BT_INTEGER;
2423 f->ts.kind = gfc_c_int_kind;
2424 if (u->ts.kind != gfc_c_int_kind)
2426 ts.type = BT_INTEGER;
2427 ts.kind = gfc_c_int_kind;
2428 ts.u.derived = NULL;
2429 ts.u.cl = NULL;
2430 gfc_convert_type (u, &ts, 2);
2433 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2437 void
2438 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2440 f->ts.type = BT_INTEGER;
2441 f->ts.kind = gfc_c_int_kind;
2442 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2446 void
2447 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2449 gfc_typespec ts;
2450 gfc_clear_ts (&ts);
2452 f->ts.type = BT_INTEGER;
2453 f->ts.kind = gfc_index_integer_kind;
2454 if (u->ts.kind != gfc_c_int_kind)
2456 ts.type = BT_INTEGER;
2457 ts.kind = gfc_c_int_kind;
2458 ts.u.derived = NULL;
2459 ts.u.cl = NULL;
2460 gfc_convert_type (u, &ts, 2);
2463 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2467 void
2468 gfc_resolve_storage_size (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
2469 gfc_expr *kind)
2471 f->ts.type = BT_INTEGER;
2472 if (kind)
2473 f->ts.kind = mpz_get_si (kind->value.integer);
2474 else
2475 f->ts.kind = gfc_default_integer_kind;
2479 void
2480 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2482 resolve_transformational ("sum", f, array, dim, mask);
2486 void
2487 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2488 gfc_expr *p2 ATTRIBUTE_UNUSED)
2490 f->ts.type = BT_INTEGER;
2491 f->ts.kind = gfc_default_integer_kind;
2492 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2496 /* Resolve the g77 compatibility function SYSTEM. */
2498 void
2499 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2501 f->ts.type = BT_INTEGER;
2502 f->ts.kind = 4;
2503 f->value.function.name = gfc_get_string (PREFIX ("system"));
2507 void
2508 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2510 f->ts = x->ts;
2511 f->value.function.name
2512 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2516 void
2517 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2519 f->ts = x->ts;
2520 f->value.function.name
2521 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2525 void
2526 gfc_resolve_image_index (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2527 gfc_expr *sub ATTRIBUTE_UNUSED)
2529 static char this_image[] = "__image_index";
2530 f->ts.kind = gfc_default_integer_kind;
2531 f->value.function.name = this_image;
2535 void
2536 gfc_resolve_this_image (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
2538 resolve_bound (f, array, dim, NULL, "__this_image", true);
2542 void
2543 gfc_resolve_time (gfc_expr *f)
2545 f->ts.type = BT_INTEGER;
2546 f->ts.kind = 4;
2547 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2551 void
2552 gfc_resolve_time8 (gfc_expr *f)
2554 f->ts.type = BT_INTEGER;
2555 f->ts.kind = 8;
2556 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2560 void
2561 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2562 gfc_expr *mold, gfc_expr *size)
2564 /* TODO: Make this do something meaningful. */
2565 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2567 if (mold->ts.type == BT_CHARACTER
2568 && !mold->ts.u.cl->length
2569 && gfc_is_constant_expr (mold))
2571 int len;
2572 if (mold->expr_type == EXPR_CONSTANT)
2574 len = mold->value.character.length;
2575 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2576 NULL, len);
2578 else
2580 gfc_constructor *c = gfc_constructor_first (mold->value.constructor);
2581 len = c->expr->value.character.length;
2582 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2583 NULL, len);
2587 f->ts = mold->ts;
2589 if (size == NULL && mold->rank == 0)
2591 f->rank = 0;
2592 f->value.function.name = transfer0;
2594 else
2596 f->rank = 1;
2597 f->value.function.name = transfer1;
2598 if (size && gfc_is_constant_expr (size))
2600 f->shape = gfc_get_shape (1);
2601 mpz_init_set (f->shape[0], size->value.integer);
2607 void
2608 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2611 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2612 gfc_resolve_substring_charlen (matrix);
2614 f->ts = matrix->ts;
2615 f->rank = 2;
2616 if (matrix->shape)
2618 f->shape = gfc_get_shape (2);
2619 mpz_init_set (f->shape[0], matrix->shape[1]);
2620 mpz_init_set (f->shape[1], matrix->shape[0]);
2623 switch (matrix->ts.kind)
2625 case 4:
2626 case 8:
2627 case 10:
2628 case 16:
2629 switch (matrix->ts.type)
2631 case BT_REAL:
2632 case BT_COMPLEX:
2633 f->value.function.name
2634 = gfc_get_string (PREFIX ("transpose_%c%d"),
2635 gfc_type_letter (matrix->ts.type),
2636 matrix->ts.kind);
2637 break;
2639 case BT_INTEGER:
2640 case BT_LOGICAL:
2641 /* Use the integer routines for real and logical cases. This
2642 assumes they all have the same alignment requirements. */
2643 f->value.function.name
2644 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2645 break;
2647 default:
2648 if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4)
2649 f->value.function.name = PREFIX ("transpose_char4");
2650 else
2651 f->value.function.name = PREFIX ("transpose");
2652 break;
2654 break;
2656 default:
2657 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2658 ? PREFIX ("transpose_char")
2659 : PREFIX ("transpose"));
2660 break;
2665 void
2666 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2668 f->ts.type = BT_CHARACTER;
2669 f->ts.kind = string->ts.kind;
2670 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2674 void
2675 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2677 resolve_bound (f, array, dim, kind, "__ubound", false);
2681 void
2682 gfc_resolve_ucobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2684 resolve_bound (f, array, dim, kind, "__ucobound", true);
2688 /* Resolve the g77 compatibility function UMASK. */
2690 void
2691 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2693 f->ts.type = BT_INTEGER;
2694 f->ts.kind = n->ts.kind;
2695 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2699 /* Resolve the g77 compatibility function UNLINK. */
2701 void
2702 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2704 f->ts.type = BT_INTEGER;
2705 f->ts.kind = 4;
2706 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2710 void
2711 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2713 gfc_typespec ts;
2714 gfc_clear_ts (&ts);
2716 f->ts.type = BT_CHARACTER;
2717 f->ts.kind = gfc_default_character_kind;
2719 if (unit->ts.kind != gfc_c_int_kind)
2721 ts.type = BT_INTEGER;
2722 ts.kind = gfc_c_int_kind;
2723 ts.u.derived = NULL;
2724 ts.u.cl = NULL;
2725 gfc_convert_type (unit, &ts, 2);
2728 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2732 void
2733 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2734 gfc_expr *field ATTRIBUTE_UNUSED)
2736 if (vector->ts.type == BT_CHARACTER && vector->ref)
2737 gfc_resolve_substring_charlen (vector);
2739 f->ts = vector->ts;
2740 f->rank = mask->rank;
2741 resolve_mask_arg (mask);
2743 if (vector->ts.type == BT_CHARACTER)
2745 if (vector->ts.kind == 1)
2746 f->value.function.name
2747 = gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0);
2748 else
2749 f->value.function.name
2750 = gfc_get_string (PREFIX ("unpack%d_char%d"),
2751 field->rank > 0 ? 1 : 0, vector->ts.kind);
2753 else
2754 f->value.function.name
2755 = gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0);
2759 void
2760 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2761 gfc_expr *set ATTRIBUTE_UNUSED,
2762 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2764 f->ts.type = BT_INTEGER;
2765 if (kind)
2766 f->ts.kind = mpz_get_si (kind->value.integer);
2767 else
2768 f->ts.kind = gfc_default_integer_kind;
2769 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2773 void
2774 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2776 f->ts.type = i->ts.type;
2777 f->ts.kind = gfc_kind_max (i, j);
2779 if (i->ts.kind != j->ts.kind)
2781 if (i->ts.kind == gfc_kind_max (i, j))
2782 gfc_convert_type (j, &i->ts, 2);
2783 else
2784 gfc_convert_type (i, &j->ts, 2);
2787 f->value.function.name
2788 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2792 /* Intrinsic subroutine resolution. */
2794 void
2795 gfc_resolve_alarm_sub (gfc_code *c)
2797 const char *name;
2798 gfc_expr *seconds, *handler;
2799 gfc_typespec ts;
2800 gfc_clear_ts (&ts);
2802 seconds = c->ext.actual->expr;
2803 handler = c->ext.actual->next->expr;
2804 ts.type = BT_INTEGER;
2805 ts.kind = gfc_c_int_kind;
2807 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2808 In all cases, the status argument is of default integer kind
2809 (enforced in check.c) so that the function suffix is fixed. */
2810 if (handler->ts.type == BT_INTEGER)
2812 if (handler->ts.kind != gfc_c_int_kind)
2813 gfc_convert_type (handler, &ts, 2);
2814 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2815 gfc_default_integer_kind);
2817 else
2818 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2819 gfc_default_integer_kind);
2821 if (seconds->ts.kind != gfc_c_int_kind)
2822 gfc_convert_type (seconds, &ts, 2);
2824 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2827 void
2828 gfc_resolve_cpu_time (gfc_code *c)
2830 const char *name;
2831 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2832 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2836 /* Create a formal arglist based on an actual one and set the INTENTs given. */
2838 static gfc_formal_arglist*
2839 create_formal_for_intents (gfc_actual_arglist* actual, const sym_intent* ints)
2841 gfc_formal_arglist* head;
2842 gfc_formal_arglist* tail;
2843 int i;
2845 if (!actual)
2846 return NULL;
2848 head = tail = gfc_get_formal_arglist ();
2849 for (i = 0; actual; actual = actual->next, tail = tail->next, ++i)
2851 gfc_symbol* sym;
2853 sym = gfc_new_symbol ("dummyarg", NULL);
2854 sym->ts = actual->expr->ts;
2856 sym->attr.intent = ints[i];
2857 tail->sym = sym;
2859 if (actual->next)
2860 tail->next = gfc_get_formal_arglist ();
2863 return head;
2867 void
2868 gfc_resolve_mvbits (gfc_code *c)
2870 static const sym_intent INTENTS[] = {INTENT_IN, INTENT_IN, INTENT_IN,
2871 INTENT_INOUT, INTENT_IN};
2873 const char *name;
2874 gfc_typespec ts;
2875 gfc_clear_ts (&ts);
2877 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2878 they will be converted so that they fit into a C int. */
2879 ts.type = BT_INTEGER;
2880 ts.kind = gfc_c_int_kind;
2881 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2882 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2883 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2884 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2885 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2886 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2888 /* TO and FROM are guaranteed to have the same kind parameter. */
2889 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2890 c->ext.actual->expr->ts.kind);
2891 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2892 /* Mark as elemental subroutine as this does not happen automatically. */
2893 c->resolved_sym->attr.elemental = 1;
2895 /* Create a dummy formal arglist so the INTENTs are known later for purpose
2896 of creating temporaries. */
2897 c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS);
2901 void
2902 gfc_resolve_random_number (gfc_code *c)
2904 const char *name;
2905 int kind;
2907 kind = c->ext.actual->expr->ts.kind;
2908 if (c->ext.actual->expr->rank == 0)
2909 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2910 else
2911 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2913 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2917 void
2918 gfc_resolve_random_seed (gfc_code *c)
2920 const char *name;
2922 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2923 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2927 void
2928 gfc_resolve_rename_sub (gfc_code *c)
2930 const char *name;
2931 int kind;
2933 if (c->ext.actual->next->next->expr != NULL)
2934 kind = c->ext.actual->next->next->expr->ts.kind;
2935 else
2936 kind = gfc_default_integer_kind;
2938 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2939 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2943 void
2944 gfc_resolve_kill_sub (gfc_code *c)
2946 const char *name;
2947 int kind;
2949 if (c->ext.actual->next->next->expr != NULL)
2950 kind = c->ext.actual->next->next->expr->ts.kind;
2951 else
2952 kind = gfc_default_integer_kind;
2954 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2955 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2959 void
2960 gfc_resolve_link_sub (gfc_code *c)
2962 const char *name;
2963 int kind;
2965 if (c->ext.actual->next->next->expr != NULL)
2966 kind = c->ext.actual->next->next->expr->ts.kind;
2967 else
2968 kind = gfc_default_integer_kind;
2970 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2971 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2975 void
2976 gfc_resolve_symlnk_sub (gfc_code *c)
2978 const char *name;
2979 int kind;
2981 if (c->ext.actual->next->next->expr != NULL)
2982 kind = c->ext.actual->next->next->expr->ts.kind;
2983 else
2984 kind = gfc_default_integer_kind;
2986 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2987 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2991 /* G77 compatibility subroutines dtime() and etime(). */
2993 void
2994 gfc_resolve_dtime_sub (gfc_code *c)
2996 const char *name;
2997 name = gfc_get_string (PREFIX ("dtime_sub"));
2998 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3001 void
3002 gfc_resolve_etime_sub (gfc_code *c)
3004 const char *name;
3005 name = gfc_get_string (PREFIX ("etime_sub"));
3006 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3010 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
3012 void
3013 gfc_resolve_itime (gfc_code *c)
3015 c->resolved_sym
3016 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
3017 gfc_default_integer_kind));
3020 void
3021 gfc_resolve_idate (gfc_code *c)
3023 c->resolved_sym
3024 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
3025 gfc_default_integer_kind));
3028 void
3029 gfc_resolve_ltime (gfc_code *c)
3031 c->resolved_sym
3032 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
3033 gfc_default_integer_kind));
3036 void
3037 gfc_resolve_gmtime (gfc_code *c)
3039 c->resolved_sym
3040 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
3041 gfc_default_integer_kind));
3045 /* G77 compatibility subroutine second(). */
3047 void
3048 gfc_resolve_second_sub (gfc_code *c)
3050 const char *name;
3051 name = gfc_get_string (PREFIX ("second_sub"));
3052 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3056 void
3057 gfc_resolve_sleep_sub (gfc_code *c)
3059 const char *name;
3060 int kind;
3062 if (c->ext.actual->expr != NULL)
3063 kind = c->ext.actual->expr->ts.kind;
3064 else
3065 kind = gfc_default_integer_kind;
3067 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
3068 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3072 /* G77 compatibility function srand(). */
3074 void
3075 gfc_resolve_srand (gfc_code *c)
3077 const char *name;
3078 name = gfc_get_string (PREFIX ("srand"));
3079 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3083 /* Resolve the getarg intrinsic subroutine. */
3085 void
3086 gfc_resolve_getarg (gfc_code *c)
3088 const char *name;
3090 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
3092 gfc_typespec ts;
3093 gfc_clear_ts (&ts);
3095 ts.type = BT_INTEGER;
3096 ts.kind = gfc_default_integer_kind;
3098 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3101 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
3102 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3106 /* Resolve the getcwd intrinsic subroutine. */
3108 void
3109 gfc_resolve_getcwd_sub (gfc_code *c)
3111 const char *name;
3112 int kind;
3114 if (c->ext.actual->next->expr != NULL)
3115 kind = c->ext.actual->next->expr->ts.kind;
3116 else
3117 kind = gfc_default_integer_kind;
3119 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
3120 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3124 /* Resolve the get_command intrinsic subroutine. */
3126 void
3127 gfc_resolve_get_command (gfc_code *c)
3129 const char *name;
3130 int kind;
3131 kind = gfc_default_integer_kind;
3132 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
3133 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3137 /* Resolve the get_command_argument intrinsic subroutine. */
3139 void
3140 gfc_resolve_get_command_argument (gfc_code *c)
3142 const char *name;
3143 int kind;
3144 kind = gfc_default_integer_kind;
3145 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
3146 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3150 /* Resolve the get_environment_variable intrinsic subroutine. */
3152 void
3153 gfc_resolve_get_environment_variable (gfc_code *code)
3155 const char *name;
3156 int kind;
3157 kind = gfc_default_integer_kind;
3158 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
3159 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3163 void
3164 gfc_resolve_signal_sub (gfc_code *c)
3166 const char *name;
3167 gfc_expr *number, *handler, *status;
3168 gfc_typespec ts;
3169 gfc_clear_ts (&ts);
3171 number = c->ext.actual->expr;
3172 handler = c->ext.actual->next->expr;
3173 status = c->ext.actual->next->next->expr;
3174 ts.type = BT_INTEGER;
3175 ts.kind = gfc_c_int_kind;
3177 /* handler can be either BT_INTEGER or BT_PROCEDURE */
3178 if (handler->ts.type == BT_INTEGER)
3180 if (handler->ts.kind != gfc_c_int_kind)
3181 gfc_convert_type (handler, &ts, 2);
3182 name = gfc_get_string (PREFIX ("signal_sub_int"));
3184 else
3185 name = gfc_get_string (PREFIX ("signal_sub"));
3187 if (number->ts.kind != gfc_c_int_kind)
3188 gfc_convert_type (number, &ts, 2);
3189 if (status != NULL && status->ts.kind != gfc_c_int_kind)
3190 gfc_convert_type (status, &ts, 2);
3192 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3196 /* Resolve the SYSTEM intrinsic subroutine. */
3198 void
3199 gfc_resolve_system_sub (gfc_code *c)
3201 const char *name;
3202 name = gfc_get_string (PREFIX ("system_sub"));
3203 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3207 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
3209 void
3210 gfc_resolve_system_clock (gfc_code *c)
3212 const char *name;
3213 int kind;
3215 if (c->ext.actual->expr != NULL)
3216 kind = c->ext.actual->expr->ts.kind;
3217 else if (c->ext.actual->next->expr != NULL)
3218 kind = c->ext.actual->next->expr->ts.kind;
3219 else if (c->ext.actual->next->next->expr != NULL)
3220 kind = c->ext.actual->next->next->expr->ts.kind;
3221 else
3222 kind = gfc_default_integer_kind;
3224 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
3225 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3229 /* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine. */
3230 void
3231 gfc_resolve_execute_command_line (gfc_code *c)
3233 const char *name;
3234 name = gfc_get_string (PREFIX ("execute_command_line_i%d"),
3235 gfc_default_integer_kind);
3236 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3240 /* Resolve the EXIT intrinsic subroutine. */
3242 void
3243 gfc_resolve_exit (gfc_code *c)
3245 const char *name;
3246 gfc_typespec ts;
3247 gfc_expr *n;
3248 gfc_clear_ts (&ts);
3250 /* The STATUS argument has to be of default kind. If it is not,
3251 we convert it. */
3252 ts.type = BT_INTEGER;
3253 ts.kind = gfc_default_integer_kind;
3254 n = c->ext.actual->expr;
3255 if (n != NULL && n->ts.kind != ts.kind)
3256 gfc_convert_type (n, &ts, 2);
3258 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
3259 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3263 /* Resolve the FLUSH intrinsic subroutine. */
3265 void
3266 gfc_resolve_flush (gfc_code *c)
3268 const char *name;
3269 gfc_typespec ts;
3270 gfc_expr *n;
3271 gfc_clear_ts (&ts);
3273 ts.type = BT_INTEGER;
3274 ts.kind = gfc_default_integer_kind;
3275 n = c->ext.actual->expr;
3276 if (n != NULL && n->ts.kind != ts.kind)
3277 gfc_convert_type (n, &ts, 2);
3279 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
3280 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3284 void
3285 gfc_resolve_free (gfc_code *c)
3287 gfc_typespec ts;
3288 gfc_expr *n;
3289 gfc_clear_ts (&ts);
3291 ts.type = BT_INTEGER;
3292 ts.kind = gfc_index_integer_kind;
3293 n = c->ext.actual->expr;
3294 if (n->ts.kind != ts.kind)
3295 gfc_convert_type (n, &ts, 2);
3297 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
3301 void
3302 gfc_resolve_ctime_sub (gfc_code *c)
3304 gfc_typespec ts;
3305 gfc_clear_ts (&ts);
3307 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3308 if (c->ext.actual->expr->ts.kind != 8)
3310 ts.type = BT_INTEGER;
3311 ts.kind = 8;
3312 ts.u.derived = NULL;
3313 ts.u.cl = NULL;
3314 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3317 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3321 void
3322 gfc_resolve_fdate_sub (gfc_code *c)
3324 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3328 void
3329 gfc_resolve_gerror (gfc_code *c)
3331 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3335 void
3336 gfc_resolve_getlog (gfc_code *c)
3338 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3342 void
3343 gfc_resolve_hostnm_sub (gfc_code *c)
3345 const char *name;
3346 int kind;
3348 if (c->ext.actual->next->expr != NULL)
3349 kind = c->ext.actual->next->expr->ts.kind;
3350 else
3351 kind = gfc_default_integer_kind;
3353 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3354 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3358 void
3359 gfc_resolve_perror (gfc_code *c)
3361 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3364 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3366 void
3367 gfc_resolve_stat_sub (gfc_code *c)
3369 const char *name;
3370 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3371 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3375 void
3376 gfc_resolve_lstat_sub (gfc_code *c)
3378 const char *name;
3379 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3380 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3384 void
3385 gfc_resolve_fstat_sub (gfc_code *c)
3387 const char *name;
3388 gfc_expr *u;
3389 gfc_typespec *ts;
3391 u = c->ext.actual->expr;
3392 ts = &c->ext.actual->next->expr->ts;
3393 if (u->ts.kind != ts->kind)
3394 gfc_convert_type (u, ts, 2);
3395 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3396 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3400 void
3401 gfc_resolve_fgetc_sub (gfc_code *c)
3403 const char *name;
3404 gfc_typespec ts;
3405 gfc_expr *u, *st;
3406 gfc_clear_ts (&ts);
3408 u = c->ext.actual->expr;
3409 st = c->ext.actual->next->next->expr;
3411 if (u->ts.kind != gfc_c_int_kind)
3413 ts.type = BT_INTEGER;
3414 ts.kind = gfc_c_int_kind;
3415 ts.u.derived = NULL;
3416 ts.u.cl = NULL;
3417 gfc_convert_type (u, &ts, 2);
3420 if (st != NULL)
3421 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3422 else
3423 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3425 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3429 void
3430 gfc_resolve_fget_sub (gfc_code *c)
3432 const char *name;
3433 gfc_expr *st;
3435 st = c->ext.actual->next->expr;
3436 if (st != NULL)
3437 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3438 else
3439 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3441 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3445 void
3446 gfc_resolve_fputc_sub (gfc_code *c)
3448 const char *name;
3449 gfc_typespec ts;
3450 gfc_expr *u, *st;
3451 gfc_clear_ts (&ts);
3453 u = c->ext.actual->expr;
3454 st = c->ext.actual->next->next->expr;
3456 if (u->ts.kind != gfc_c_int_kind)
3458 ts.type = BT_INTEGER;
3459 ts.kind = gfc_c_int_kind;
3460 ts.u.derived = NULL;
3461 ts.u.cl = NULL;
3462 gfc_convert_type (u, &ts, 2);
3465 if (st != NULL)
3466 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3467 else
3468 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3470 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3474 void
3475 gfc_resolve_fput_sub (gfc_code *c)
3477 const char *name;
3478 gfc_expr *st;
3480 st = c->ext.actual->next->expr;
3481 if (st != NULL)
3482 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3483 else
3484 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3486 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3490 void
3491 gfc_resolve_fseek_sub (gfc_code *c)
3493 gfc_expr *unit;
3494 gfc_expr *offset;
3495 gfc_expr *whence;
3496 gfc_typespec ts;
3497 gfc_clear_ts (&ts);
3499 unit = c->ext.actual->expr;
3500 offset = c->ext.actual->next->expr;
3501 whence = c->ext.actual->next->next->expr;
3503 if (unit->ts.kind != gfc_c_int_kind)
3505 ts.type = BT_INTEGER;
3506 ts.kind = gfc_c_int_kind;
3507 ts.u.derived = NULL;
3508 ts.u.cl = NULL;
3509 gfc_convert_type (unit, &ts, 2);
3512 if (offset->ts.kind != gfc_intio_kind)
3514 ts.type = BT_INTEGER;
3515 ts.kind = gfc_intio_kind;
3516 ts.u.derived = NULL;
3517 ts.u.cl = NULL;
3518 gfc_convert_type (offset, &ts, 2);
3521 if (whence->ts.kind != gfc_c_int_kind)
3523 ts.type = BT_INTEGER;
3524 ts.kind = gfc_c_int_kind;
3525 ts.u.derived = NULL;
3526 ts.u.cl = NULL;
3527 gfc_convert_type (whence, &ts, 2);
3530 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3533 void
3534 gfc_resolve_ftell_sub (gfc_code *c)
3536 const char *name;
3537 gfc_expr *unit;
3538 gfc_expr *offset;
3539 gfc_typespec ts;
3540 gfc_clear_ts (&ts);
3542 unit = c->ext.actual->expr;
3543 offset = c->ext.actual->next->expr;
3545 if (unit->ts.kind != gfc_c_int_kind)
3547 ts.type = BT_INTEGER;
3548 ts.kind = gfc_c_int_kind;
3549 ts.u.derived = NULL;
3550 ts.u.cl = NULL;
3551 gfc_convert_type (unit, &ts, 2);
3554 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3555 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3559 void
3560 gfc_resolve_ttynam_sub (gfc_code *c)
3562 gfc_typespec ts;
3563 gfc_clear_ts (&ts);
3565 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3567 ts.type = BT_INTEGER;
3568 ts.kind = gfc_c_int_kind;
3569 ts.u.derived = NULL;
3570 ts.u.cl = NULL;
3571 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3574 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3578 /* Resolve the UMASK intrinsic subroutine. */
3580 void
3581 gfc_resolve_umask_sub (gfc_code *c)
3583 const char *name;
3584 int kind;
3586 if (c->ext.actual->next->expr != NULL)
3587 kind = c->ext.actual->next->expr->ts.kind;
3588 else
3589 kind = gfc_default_integer_kind;
3591 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3592 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3595 /* Resolve the UNLINK intrinsic subroutine. */
3597 void
3598 gfc_resolve_unlink_sub (gfc_code *c)
3600 const char *name;
3601 int kind;
3603 if (c->ext.actual->next->expr != NULL)
3604 kind = c->ext.actual->next->expr->ts.kind;
3605 else
3606 kind = gfc_default_integer_kind;
3608 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3609 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);