* intrinsic.c: Add EXECUTE_COMMAND_LINE intrinsic.
[official-gcc.git] / gcc / fortran / iresolve.c
blob66df99e3bf5d445603317091984c8483a28e58ae
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);
144 /********************** Resolution functions **********************/
147 void
148 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
150 f->ts = a->ts;
151 if (f->ts.type == BT_COMPLEX)
152 f->ts.type = BT_REAL;
154 f->value.function.name
155 = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
159 void
160 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
161 gfc_expr *mode ATTRIBUTE_UNUSED)
163 f->ts.type = BT_INTEGER;
164 f->ts.kind = gfc_c_int_kind;
165 f->value.function.name = PREFIX ("access_func");
169 void
170 gfc_resolve_adjustl (gfc_expr *f, gfc_expr *string)
172 f->ts.type = BT_CHARACTER;
173 f->ts.kind = string->ts.kind;
174 f->value.function.name = gfc_get_string ("__adjustl_s%d", f->ts.kind);
178 void
179 gfc_resolve_adjustr (gfc_expr *f, gfc_expr *string)
181 f->ts.type = BT_CHARACTER;
182 f->ts.kind = string->ts.kind;
183 f->value.function.name = gfc_get_string ("__adjustr_s%d", f->ts.kind);
187 static void
188 gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind,
189 const char *name)
191 f->ts.type = BT_CHARACTER;
192 f->ts.kind = (kind == NULL)
193 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
194 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
195 f->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
197 f->value.function.name = gfc_get_string (name, f->ts.kind,
198 gfc_type_letter (x->ts.type),
199 x->ts.kind);
203 void
204 gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
206 gfc_resolve_char_achar (f, x, kind, "__achar_%d_%c%d");
210 void
211 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
213 f->ts = x->ts;
214 f->value.function.name
215 = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
219 void
220 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
222 f->ts = x->ts;
223 f->value.function.name
224 = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
225 x->ts.kind);
229 void
230 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
232 f->ts.type = BT_REAL;
233 f->ts.kind = x->ts.kind;
234 f->value.function.name
235 = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
236 x->ts.kind);
240 void
241 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
243 f->ts.type = i->ts.type;
244 f->ts.kind = gfc_kind_max (i, j);
246 if (i->ts.kind != j->ts.kind)
248 if (i->ts.kind == gfc_kind_max (i, j))
249 gfc_convert_type (j, &i->ts, 2);
250 else
251 gfc_convert_type (i, &j->ts, 2);
254 f->value.function.name
255 = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
259 void
260 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
262 gfc_typespec ts;
263 gfc_clear_ts (&ts);
265 f->ts.type = a->ts.type;
266 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
268 if (a->ts.kind != f->ts.kind)
270 ts.type = f->ts.type;
271 ts.kind = f->ts.kind;
272 gfc_convert_type (a, &ts, 2);
274 /* The resolved name is only used for specific intrinsics where
275 the return kind is the same as the arg kind. */
276 f->value.function.name
277 = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
281 void
282 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
284 gfc_resolve_aint (f, a, NULL);
288 void
289 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
291 f->ts = mask->ts;
293 if (dim != NULL)
295 gfc_resolve_dim_arg (dim);
296 f->rank = mask->rank - 1;
297 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
300 f->value.function.name
301 = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
302 mask->ts.kind);
306 void
307 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
309 gfc_typespec ts;
310 gfc_clear_ts (&ts);
312 f->ts.type = a->ts.type;
313 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
315 if (a->ts.kind != f->ts.kind)
317 ts.type = f->ts.type;
318 ts.kind = f->ts.kind;
319 gfc_convert_type (a, &ts, 2);
322 /* The resolved name is only used for specific intrinsics where
323 the return kind is the same as the arg kind. */
324 f->value.function.name
325 = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
326 a->ts.kind);
330 void
331 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
333 gfc_resolve_anint (f, a, NULL);
337 void
338 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
340 f->ts = mask->ts;
342 if (dim != NULL)
344 gfc_resolve_dim_arg (dim);
345 f->rank = mask->rank - 1;
346 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
349 f->value.function.name
350 = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
351 mask->ts.kind);
355 void
356 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
358 f->ts = x->ts;
359 f->value.function.name
360 = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
363 void
364 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
366 f->ts = x->ts;
367 f->value.function.name
368 = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
369 x->ts.kind);
372 void
373 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
375 f->ts = x->ts;
376 f->value.function.name
377 = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
380 void
381 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
383 f->ts = x->ts;
384 f->value.function.name
385 = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
386 x->ts.kind);
389 void
390 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
392 f->ts = x->ts;
393 f->value.function.name
394 = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
395 x->ts.kind);
399 /* Resolve the BESYN and BESJN intrinsics. */
401 void
402 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
404 gfc_typespec ts;
405 gfc_clear_ts (&ts);
407 f->ts = x->ts;
408 if (n->ts.kind != gfc_c_int_kind)
410 ts.type = BT_INTEGER;
411 ts.kind = gfc_c_int_kind;
412 gfc_convert_type (n, &ts, 2);
414 f->value.function.name = gfc_get_string ("<intrinsic>");
418 void
419 gfc_resolve_bessel_n2 (gfc_expr *f, gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
421 gfc_typespec ts;
422 gfc_clear_ts (&ts);
424 f->ts = x->ts;
425 f->rank = 1;
426 if (n1->expr_type == EXPR_CONSTANT && n2->expr_type == EXPR_CONSTANT)
428 f->shape = gfc_get_shape (1);
429 mpz_init (f->shape[0]);
430 mpz_sub (f->shape[0], n2->value.integer, n1->value.integer);
431 mpz_add_ui (f->shape[0], f->shape[0], 1);
434 if (n1->ts.kind != gfc_c_int_kind)
436 ts.type = BT_INTEGER;
437 ts.kind = gfc_c_int_kind;
438 gfc_convert_type (n1, &ts, 2);
441 if (n2->ts.kind != gfc_c_int_kind)
443 ts.type = BT_INTEGER;
444 ts.kind = gfc_c_int_kind;
445 gfc_convert_type (n2, &ts, 2);
448 if (f->value.function.isym->id == GFC_ISYM_JN2)
449 f->value.function.name = gfc_get_string (PREFIX ("bessel_jn_r%d"),
450 f->ts.kind);
451 else
452 f->value.function.name = gfc_get_string (PREFIX ("bessel_yn_r%d"),
453 f->ts.kind);
457 void
458 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
460 f->ts.type = BT_LOGICAL;
461 f->ts.kind = gfc_default_logical_kind;
462 f->value.function.name
463 = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
467 void
468 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
470 f->ts.type = BT_INTEGER;
471 f->ts.kind = (kind == NULL)
472 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
473 f->value.function.name
474 = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
475 gfc_type_letter (a->ts.type), a->ts.kind);
479 void
480 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
482 gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d");
486 void
487 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
489 f->ts.type = BT_INTEGER;
490 f->ts.kind = gfc_default_integer_kind;
491 f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
495 void
496 gfc_resolve_chdir_sub (gfc_code *c)
498 const char *name;
499 int kind;
501 if (c->ext.actual->next->expr != NULL)
502 kind = c->ext.actual->next->expr->ts.kind;
503 else
504 kind = gfc_default_integer_kind;
506 name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
507 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
511 void
512 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
513 gfc_expr *mode ATTRIBUTE_UNUSED)
515 f->ts.type = BT_INTEGER;
516 f->ts.kind = gfc_c_int_kind;
517 f->value.function.name = PREFIX ("chmod_func");
521 void
522 gfc_resolve_chmod_sub (gfc_code *c)
524 const char *name;
525 int kind;
527 if (c->ext.actual->next->next->expr != NULL)
528 kind = c->ext.actual->next->next->expr->ts.kind;
529 else
530 kind = gfc_default_integer_kind;
532 name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
533 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
537 void
538 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
540 f->ts.type = BT_COMPLEX;
541 f->ts.kind = (kind == NULL)
542 ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
544 if (y == NULL)
545 f->value.function.name
546 = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
547 gfc_type_letter (x->ts.type), x->ts.kind);
548 else
549 f->value.function.name
550 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
551 gfc_type_letter (x->ts.type), x->ts.kind,
552 gfc_type_letter (y->ts.type), y->ts.kind);
556 void
557 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
559 gfc_resolve_cmplx (f, x, y, gfc_get_int_expr (gfc_default_integer_kind, NULL,
560 gfc_default_double_kind));
564 void
565 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
567 int kind;
569 if (x->ts.type == BT_INTEGER)
571 if (y->ts.type == BT_INTEGER)
572 kind = gfc_default_real_kind;
573 else
574 kind = y->ts.kind;
576 else
578 if (y->ts.type == BT_REAL)
579 kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
580 else
581 kind = x->ts.kind;
584 f->ts.type = BT_COMPLEX;
585 f->ts.kind = kind;
586 f->value.function.name
587 = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
588 gfc_type_letter (x->ts.type), x->ts.kind,
589 gfc_type_letter (y->ts.type), y->ts.kind);
593 void
594 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
596 f->ts = x->ts;
597 f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
601 void
602 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
604 f->ts = x->ts;
605 f->value.function.name
606 = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
610 void
611 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
613 f->ts = x->ts;
614 f->value.function.name
615 = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
619 void
620 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
622 f->ts.type = BT_INTEGER;
623 if (kind)
624 f->ts.kind = mpz_get_si (kind->value.integer);
625 else
626 f->ts.kind = gfc_default_integer_kind;
628 if (dim != NULL)
630 f->rank = mask->rank - 1;
631 gfc_resolve_dim_arg (dim);
632 f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
635 resolve_mask_arg (mask);
637 f->value.function.name
638 = gfc_get_string (PREFIX ("count_%d_%c"), f->ts.kind,
639 gfc_type_letter (mask->ts.type));
643 void
644 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
645 gfc_expr *dim)
647 int n, m;
649 if (array->ts.type == BT_CHARACTER && array->ref)
650 gfc_resolve_substring_charlen (array);
652 f->ts = array->ts;
653 f->rank = array->rank;
654 f->shape = gfc_copy_shape (array->shape, array->rank);
656 if (shift->rank > 0)
657 n = 1;
658 else
659 n = 0;
661 /* If dim kind is greater than default integer we need to use the larger. */
662 m = gfc_default_integer_kind;
663 if (dim != NULL)
664 m = m < dim->ts.kind ? dim->ts.kind : m;
666 /* Convert shift to at least m, so we don't need
667 kind=1 and kind=2 versions of the library functions. */
668 if (shift->ts.kind < m)
670 gfc_typespec ts;
671 gfc_clear_ts (&ts);
672 ts.type = BT_INTEGER;
673 ts.kind = m;
674 gfc_convert_type_warn (shift, &ts, 2, 0);
677 if (dim != NULL)
679 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
680 && dim->symtree->n.sym->attr.optional)
682 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
683 dim->representation.length = shift->ts.kind;
685 else
687 gfc_resolve_dim_arg (dim);
688 /* Convert dim to shift's kind to reduce variations. */
689 if (dim->ts.kind != shift->ts.kind)
690 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
694 if (array->ts.type == BT_CHARACTER)
696 if (array->ts.kind == gfc_default_character_kind)
697 f->value.function.name
698 = gfc_get_string (PREFIX ("cshift%d_%d_char"), n, shift->ts.kind);
699 else
700 f->value.function.name
701 = gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n, shift->ts.kind,
702 array->ts.kind);
704 else
705 f->value.function.name
706 = gfc_get_string (PREFIX ("cshift%d_%d"), n, shift->ts.kind);
710 void
711 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
713 gfc_typespec ts;
714 gfc_clear_ts (&ts);
716 f->ts.type = BT_CHARACTER;
717 f->ts.kind = gfc_default_character_kind;
719 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
720 if (time->ts.kind != 8)
722 ts.type = BT_INTEGER;
723 ts.kind = 8;
724 ts.u.derived = NULL;
725 ts.u.cl = NULL;
726 gfc_convert_type (time, &ts, 2);
729 f->value.function.name = gfc_get_string (PREFIX ("ctime"));
733 void
734 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
736 f->ts.type = BT_REAL;
737 f->ts.kind = gfc_default_double_kind;
738 f->value.function.name
739 = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
743 void
744 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
746 f->ts.type = a->ts.type;
747 if (p != NULL)
748 f->ts.kind = gfc_kind_max (a,p);
749 else
750 f->ts.kind = a->ts.kind;
752 if (p != NULL && a->ts.kind != p->ts.kind)
754 if (a->ts.kind == gfc_kind_max (a,p))
755 gfc_convert_type (p, &a->ts, 2);
756 else
757 gfc_convert_type (a, &p->ts, 2);
760 f->value.function.name
761 = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
765 void
766 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
768 gfc_expr temp;
770 temp.expr_type = EXPR_OP;
771 gfc_clear_ts (&temp.ts);
772 temp.value.op.op = INTRINSIC_NONE;
773 temp.value.op.op1 = a;
774 temp.value.op.op2 = b;
775 gfc_type_convert_binary (&temp, 1);
776 f->ts = temp.ts;
777 f->value.function.name
778 = gfc_get_string (PREFIX ("dot_product_%c%d"),
779 gfc_type_letter (f->ts.type), f->ts.kind);
783 void
784 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
785 gfc_expr *b ATTRIBUTE_UNUSED)
787 f->ts.kind = gfc_default_double_kind;
788 f->ts.type = BT_REAL;
789 f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
793 void
794 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
795 gfc_expr *boundary, gfc_expr *dim)
797 int n, m;
799 if (array->ts.type == BT_CHARACTER && array->ref)
800 gfc_resolve_substring_charlen (array);
802 f->ts = array->ts;
803 f->rank = array->rank;
804 f->shape = gfc_copy_shape (array->shape, array->rank);
806 n = 0;
807 if (shift->rank > 0)
808 n = n | 1;
809 if (boundary && boundary->rank > 0)
810 n = n | 2;
812 /* If dim kind is greater than default integer we need to use the larger. */
813 m = gfc_default_integer_kind;
814 if (dim != NULL)
815 m = m < dim->ts.kind ? dim->ts.kind : m;
817 /* Convert shift to at least m, so we don't need
818 kind=1 and kind=2 versions of the library functions. */
819 if (shift->ts.kind < m)
821 gfc_typespec ts;
822 gfc_clear_ts (&ts);
823 ts.type = BT_INTEGER;
824 ts.kind = m;
825 gfc_convert_type_warn (shift, &ts, 2, 0);
828 if (dim != NULL)
830 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
831 && dim->symtree->n.sym->attr.optional)
833 /* Mark this for later setting the type in gfc_conv_missing_dummy. */
834 dim->representation.length = shift->ts.kind;
836 else
838 gfc_resolve_dim_arg (dim);
839 /* Convert dim to shift's kind to reduce variations. */
840 if (dim->ts.kind != shift->ts.kind)
841 gfc_convert_type_warn (dim, &shift->ts, 2, 0);
845 if (array->ts.type == BT_CHARACTER)
847 if (array->ts.kind == gfc_default_character_kind)
848 f->value.function.name
849 = gfc_get_string (PREFIX ("eoshift%d_%d_char"), n, shift->ts.kind);
850 else
851 f->value.function.name
852 = gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n, shift->ts.kind,
853 array->ts.kind);
855 else
856 f->value.function.name
857 = gfc_get_string (PREFIX ("eoshift%d_%d"), n, shift->ts.kind);
861 void
862 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
864 f->ts = x->ts;
865 f->value.function.name
866 = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
870 void
871 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
873 f->ts.type = BT_INTEGER;
874 f->ts.kind = gfc_default_integer_kind;
875 f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
879 /* Resolve the EXTENDS_TYPE_OF intrinsic function. */
881 void
882 gfc_resolve_extends_type_of (gfc_expr *f, gfc_expr *a, gfc_expr *mo)
884 gfc_symbol *vtab;
885 gfc_symtree *st;
887 /* Prevent double resolution. */
888 if (f->ts.type == BT_LOGICAL)
889 return;
891 /* Replace the first argument with the corresponding vtab. */
892 if (a->ts.type == BT_CLASS)
893 gfc_add_component_ref (a, "$vptr");
894 else if (a->ts.type == BT_DERIVED)
896 vtab = gfc_find_derived_vtab (a->ts.u.derived);
897 /* Clear the old expr. */
898 gfc_free_ref_list (a->ref);
899 memset (a, '\0', sizeof (gfc_expr));
900 /* Construct a new one. */
901 a->expr_type = EXPR_VARIABLE;
902 st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
903 a->symtree = st;
904 a->ts = vtab->ts;
907 /* Replace the second argument with the corresponding vtab. */
908 if (mo->ts.type == BT_CLASS)
909 gfc_add_component_ref (mo, "$vptr");
910 else if (mo->ts.type == BT_DERIVED)
912 vtab = gfc_find_derived_vtab (mo->ts.u.derived);
913 /* Clear the old expr. */
914 gfc_free_ref_list (mo->ref);
915 memset (mo, '\0', sizeof (gfc_expr));
916 /* Construct a new one. */
917 mo->expr_type = EXPR_VARIABLE;
918 st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
919 mo->symtree = st;
920 mo->ts = vtab->ts;
923 f->ts.type = BT_LOGICAL;
924 f->ts.kind = 4;
926 f->value.function.isym->formal->ts = a->ts;
927 f->value.function.isym->formal->next->ts = mo->ts;
929 /* Call library function. */
930 f->value.function.name = gfc_get_string (PREFIX ("is_extension_of"));
934 void
935 gfc_resolve_fdate (gfc_expr *f)
937 f->ts.type = BT_CHARACTER;
938 f->ts.kind = gfc_default_character_kind;
939 f->value.function.name = gfc_get_string (PREFIX ("fdate"));
943 void
944 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
946 f->ts.type = BT_INTEGER;
947 f->ts.kind = (kind == NULL)
948 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
949 f->value.function.name
950 = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
951 gfc_type_letter (a->ts.type), a->ts.kind);
955 void
956 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
958 f->ts.type = BT_INTEGER;
959 f->ts.kind = gfc_default_integer_kind;
960 if (n->ts.kind != f->ts.kind)
961 gfc_convert_type (n, &f->ts, 2);
962 f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
966 void
967 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
969 f->ts = x->ts;
970 f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
974 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
976 void
977 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
979 f->ts = x->ts;
980 f->value.function.name = gfc_get_string ("<intrinsic>");
984 void
985 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
987 f->ts = x->ts;
988 f->value.function.name
989 = gfc_get_string ("__tgamma_%d", x->ts.kind);
993 void
994 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
996 f->ts.type = BT_INTEGER;
997 f->ts.kind = 4;
998 f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
1002 void
1003 gfc_resolve_getgid (gfc_expr *f)
1005 f->ts.type = BT_INTEGER;
1006 f->ts.kind = 4;
1007 f->value.function.name = gfc_get_string (PREFIX ("getgid"));
1011 void
1012 gfc_resolve_getpid (gfc_expr *f)
1014 f->ts.type = BT_INTEGER;
1015 f->ts.kind = 4;
1016 f->value.function.name = gfc_get_string (PREFIX ("getpid"));
1020 void
1021 gfc_resolve_getuid (gfc_expr *f)
1023 f->ts.type = BT_INTEGER;
1024 f->ts.kind = 4;
1025 f->value.function.name = gfc_get_string (PREFIX ("getuid"));
1029 void
1030 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
1032 f->ts.type = BT_INTEGER;
1033 f->ts.kind = 4;
1034 f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
1038 void
1039 gfc_resolve_hypot (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
1041 f->ts = x->ts;
1042 f->value.function.name = gfc_get_string ("__hypot_r%d", x->ts.kind);
1046 void
1047 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1049 /* If the kind of i and j are different, then g77 cross-promoted the
1050 kinds to the largest value. The Fortran 95 standard requires the
1051 kinds to match. */
1052 if (i->ts.kind != j->ts.kind)
1054 if (i->ts.kind == gfc_kind_max (i, j))
1055 gfc_convert_type (j, &i->ts, 2);
1056 else
1057 gfc_convert_type (i, &j->ts, 2);
1060 f->ts = i->ts;
1061 f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
1065 void
1066 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1068 f->ts = i->ts;
1069 f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
1073 void
1074 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
1075 gfc_expr *len ATTRIBUTE_UNUSED)
1077 f->ts = i->ts;
1078 f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
1082 void
1083 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1085 f->ts = i->ts;
1086 f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
1090 void
1091 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1093 f->ts.type = BT_INTEGER;
1094 if (kind)
1095 f->ts.kind = mpz_get_si (kind->value.integer);
1096 else
1097 f->ts.kind = gfc_default_integer_kind;
1098 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1102 void
1103 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1105 f->ts.type = BT_INTEGER;
1106 if (kind)
1107 f->ts.kind = mpz_get_si (kind->value.integer);
1108 else
1109 f->ts.kind = gfc_default_integer_kind;
1110 f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1114 void
1115 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
1117 gfc_resolve_nint (f, a, NULL);
1121 void
1122 gfc_resolve_ierrno (gfc_expr *f)
1124 f->ts.type = BT_INTEGER;
1125 f->ts.kind = gfc_default_integer_kind;
1126 f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
1130 void
1131 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1133 /* If the kind of i and j are different, then g77 cross-promoted the
1134 kinds to the largest value. The Fortran 95 standard requires the
1135 kinds to match. */
1136 if (i->ts.kind != j->ts.kind)
1138 if (i->ts.kind == gfc_kind_max (i, j))
1139 gfc_convert_type (j, &i->ts, 2);
1140 else
1141 gfc_convert_type (i, &j->ts, 2);
1144 f->ts = i->ts;
1145 f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
1149 void
1150 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1152 /* If the kind of i and j are different, then g77 cross-promoted the
1153 kinds to the largest value. The Fortran 95 standard requires the
1154 kinds to match. */
1155 if (i->ts.kind != j->ts.kind)
1157 if (i->ts.kind == gfc_kind_max (i, j))
1158 gfc_convert_type (j, &i->ts, 2);
1159 else
1160 gfc_convert_type (i, &j->ts, 2);
1163 f->ts = i->ts;
1164 f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
1168 void
1169 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
1170 gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
1171 gfc_expr *kind)
1173 gfc_typespec ts;
1174 gfc_clear_ts (&ts);
1176 f->ts.type = BT_INTEGER;
1177 if (kind)
1178 f->ts.kind = mpz_get_si (kind->value.integer);
1179 else
1180 f->ts.kind = gfc_default_integer_kind;
1182 if (back && back->ts.kind != gfc_default_integer_kind)
1184 ts.type = BT_LOGICAL;
1185 ts.kind = gfc_default_integer_kind;
1186 ts.u.derived = NULL;
1187 ts.u.cl = NULL;
1188 gfc_convert_type (back, &ts, 2);
1191 f->value.function.name
1192 = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
1196 void
1197 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1199 f->ts.type = BT_INTEGER;
1200 f->ts.kind = (kind == NULL)
1201 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1202 f->value.function.name
1203 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1204 gfc_type_letter (a->ts.type), a->ts.kind);
1208 void
1209 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1211 f->ts.type = BT_INTEGER;
1212 f->ts.kind = 2;
1213 f->value.function.name
1214 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1215 gfc_type_letter (a->ts.type), a->ts.kind);
1219 void
1220 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
1222 f->ts.type = BT_INTEGER;
1223 f->ts.kind = 8;
1224 f->value.function.name
1225 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1226 gfc_type_letter (a->ts.type), a->ts.kind);
1230 void
1231 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1233 f->ts.type = BT_INTEGER;
1234 f->ts.kind = 4;
1235 f->value.function.name
1236 = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1237 gfc_type_letter (a->ts.type), a->ts.kind);
1241 void
1242 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1244 gfc_typespec ts;
1245 gfc_clear_ts (&ts);
1247 f->ts.type = BT_LOGICAL;
1248 f->ts.kind = gfc_default_integer_kind;
1249 if (u->ts.kind != gfc_c_int_kind)
1251 ts.type = BT_INTEGER;
1252 ts.kind = gfc_c_int_kind;
1253 ts.u.derived = NULL;
1254 ts.u.cl = NULL;
1255 gfc_convert_type (u, &ts, 2);
1258 f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1262 void
1263 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1265 f->ts = i->ts;
1266 f->value.function.name
1267 = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1271 void
1272 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1274 f->ts = i->ts;
1275 f->value.function.name
1276 = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1280 void
1281 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1283 f->ts = i->ts;
1284 f->value.function.name
1285 = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1289 void
1290 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1292 int s_kind;
1294 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1296 f->ts = i->ts;
1297 f->value.function.name
1298 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1302 void
1303 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1304 gfc_expr *s ATTRIBUTE_UNUSED)
1306 f->ts.type = BT_INTEGER;
1307 f->ts.kind = gfc_default_integer_kind;
1308 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1312 void
1313 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1315 resolve_bound (f, array, dim, kind, "__lbound", false);
1319 void
1320 gfc_resolve_lcobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1322 resolve_bound (f, array, dim, kind, "__lcobound", true);
1326 void
1327 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1329 f->ts.type = BT_INTEGER;
1330 if (kind)
1331 f->ts.kind = mpz_get_si (kind->value.integer);
1332 else
1333 f->ts.kind = gfc_default_integer_kind;
1334 f->value.function.name
1335 = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1336 gfc_default_integer_kind);
1340 void
1341 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1343 f->ts.type = BT_INTEGER;
1344 if (kind)
1345 f->ts.kind = mpz_get_si (kind->value.integer);
1346 else
1347 f->ts.kind = gfc_default_integer_kind;
1348 f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1352 void
1353 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1355 f->ts = x->ts;
1356 f->value.function.name
1357 = gfc_get_string ("__lgamma_%d", x->ts.kind);
1361 void
1362 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1363 gfc_expr *p2 ATTRIBUTE_UNUSED)
1365 f->ts.type = BT_INTEGER;
1366 f->ts.kind = gfc_default_integer_kind;
1367 f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1371 void
1372 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1374 f->ts.type= BT_INTEGER;
1375 f->ts.kind = gfc_index_integer_kind;
1376 f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1380 void
1381 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1383 f->ts = x->ts;
1384 f->value.function.name
1385 = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1389 void
1390 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1392 f->ts = x->ts;
1393 f->value.function.name
1394 = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1395 x->ts.kind);
1399 void
1400 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1402 f->ts.type = BT_LOGICAL;
1403 f->ts.kind = (kind == NULL)
1404 ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1405 f->rank = a->rank;
1407 f->value.function.name
1408 = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1409 gfc_type_letter (a->ts.type), a->ts.kind);
1413 void
1414 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1416 if (size->ts.kind < gfc_index_integer_kind)
1418 gfc_typespec ts;
1419 gfc_clear_ts (&ts);
1421 ts.type = BT_INTEGER;
1422 ts.kind = gfc_index_integer_kind;
1423 gfc_convert_type_warn (size, &ts, 2, 0);
1426 f->ts.type = BT_INTEGER;
1427 f->ts.kind = gfc_index_integer_kind;
1428 f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1432 void
1433 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1435 gfc_expr temp;
1437 if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1439 f->ts.type = BT_LOGICAL;
1440 f->ts.kind = gfc_default_logical_kind;
1442 else
1444 temp.expr_type = EXPR_OP;
1445 gfc_clear_ts (&temp.ts);
1446 temp.value.op.op = INTRINSIC_NONE;
1447 temp.value.op.op1 = a;
1448 temp.value.op.op2 = b;
1449 gfc_type_convert_binary (&temp, 1);
1450 f->ts = temp.ts;
1453 f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1455 if (a->rank == 2 && b->rank == 2)
1457 if (a->shape && b->shape)
1459 f->shape = gfc_get_shape (f->rank);
1460 mpz_init_set (f->shape[0], a->shape[0]);
1461 mpz_init_set (f->shape[1], b->shape[1]);
1464 else if (a->rank == 1)
1466 if (b->shape)
1468 f->shape = gfc_get_shape (f->rank);
1469 mpz_init_set (f->shape[0], b->shape[1]);
1472 else
1474 /* b->rank == 1 and a->rank == 2 here, all other cases have
1475 been caught in check.c. */
1476 if (a->shape)
1478 f->shape = gfc_get_shape (f->rank);
1479 mpz_init_set (f->shape[0], a->shape[0]);
1483 f->value.function.name
1484 = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1485 f->ts.kind);
1489 static void
1490 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1492 gfc_actual_arglist *a;
1494 f->ts.type = args->expr->ts.type;
1495 f->ts.kind = args->expr->ts.kind;
1496 /* Find the largest type kind. */
1497 for (a = args->next; a; a = a->next)
1499 if (a->expr->ts.kind > f->ts.kind)
1500 f->ts.kind = a->expr->ts.kind;
1503 /* Convert all parameters to the required kind. */
1504 for (a = args; a; a = a->next)
1506 if (a->expr->ts.kind != f->ts.kind)
1507 gfc_convert_type (a->expr, &f->ts, 2);
1510 f->value.function.name
1511 = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1515 void
1516 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1518 gfc_resolve_minmax ("__max_%c%d", f, args);
1522 void
1523 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1524 gfc_expr *mask)
1526 const char *name;
1527 int i, j, idim;
1529 f->ts.type = BT_INTEGER;
1530 f->ts.kind = gfc_default_integer_kind;
1532 if (dim == NULL)
1534 f->rank = 1;
1535 f->shape = gfc_get_shape (1);
1536 mpz_init_set_si (f->shape[0], array->rank);
1538 else
1540 f->rank = array->rank - 1;
1541 gfc_resolve_dim_arg (dim);
1542 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1544 idim = (int) mpz_get_si (dim->value.integer);
1545 f->shape = gfc_get_shape (f->rank);
1546 for (i = 0, j = 0; i < f->rank; i++, j++)
1548 if (i == (idim - 1))
1549 j++;
1550 mpz_init_set (f->shape[i], array->shape[j]);
1555 if (mask)
1557 if (mask->rank == 0)
1558 name = "smaxloc";
1559 else
1560 name = "mmaxloc";
1562 resolve_mask_arg (mask);
1564 else
1565 name = "maxloc";
1567 f->value.function.name
1568 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1569 gfc_type_letter (array->ts.type), array->ts.kind);
1573 void
1574 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1575 gfc_expr *mask)
1577 const char *name;
1578 int i, j, idim;
1580 f->ts = array->ts;
1582 if (dim != NULL)
1584 f->rank = array->rank - 1;
1585 gfc_resolve_dim_arg (dim);
1587 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1589 idim = (int) mpz_get_si (dim->value.integer);
1590 f->shape = gfc_get_shape (f->rank);
1591 for (i = 0, j = 0; i < f->rank; i++, j++)
1593 if (i == (idim - 1))
1594 j++;
1595 mpz_init_set (f->shape[i], array->shape[j]);
1600 if (mask)
1602 if (mask->rank == 0)
1603 name = "smaxval";
1604 else
1605 name = "mmaxval";
1607 resolve_mask_arg (mask);
1609 else
1610 name = "maxval";
1612 f->value.function.name
1613 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1614 gfc_type_letter (array->ts.type), array->ts.kind);
1618 void
1619 gfc_resolve_mclock (gfc_expr *f)
1621 f->ts.type = BT_INTEGER;
1622 f->ts.kind = 4;
1623 f->value.function.name = PREFIX ("mclock");
1627 void
1628 gfc_resolve_mclock8 (gfc_expr *f)
1630 f->ts.type = BT_INTEGER;
1631 f->ts.kind = 8;
1632 f->value.function.name = PREFIX ("mclock8");
1636 void
1637 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1638 gfc_expr *fsource ATTRIBUTE_UNUSED,
1639 gfc_expr *mask ATTRIBUTE_UNUSED)
1641 if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1642 gfc_resolve_substring_charlen (tsource);
1644 if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1645 gfc_resolve_substring_charlen (fsource);
1647 if (tsource->ts.type == BT_CHARACTER)
1648 check_charlen_present (tsource);
1650 f->ts = tsource->ts;
1651 f->value.function.name
1652 = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1653 tsource->ts.kind);
1657 void
1658 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1660 gfc_resolve_minmax ("__min_%c%d", f, args);
1664 void
1665 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1666 gfc_expr *mask)
1668 const char *name;
1669 int i, j, idim;
1671 f->ts.type = BT_INTEGER;
1672 f->ts.kind = gfc_default_integer_kind;
1674 if (dim == NULL)
1676 f->rank = 1;
1677 f->shape = gfc_get_shape (1);
1678 mpz_init_set_si (f->shape[0], array->rank);
1680 else
1682 f->rank = array->rank - 1;
1683 gfc_resolve_dim_arg (dim);
1684 if (array->shape && dim->expr_type == EXPR_CONSTANT)
1686 idim = (int) mpz_get_si (dim->value.integer);
1687 f->shape = gfc_get_shape (f->rank);
1688 for (i = 0, j = 0; i < f->rank; i++, j++)
1690 if (i == (idim - 1))
1691 j++;
1692 mpz_init_set (f->shape[i], array->shape[j]);
1697 if (mask)
1699 if (mask->rank == 0)
1700 name = "sminloc";
1701 else
1702 name = "mminloc";
1704 resolve_mask_arg (mask);
1706 else
1707 name = "minloc";
1709 f->value.function.name
1710 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1711 gfc_type_letter (array->ts.type), array->ts.kind);
1715 void
1716 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1717 gfc_expr *mask)
1719 const char *name;
1720 int i, j, idim;
1722 f->ts = array->ts;
1724 if (dim != NULL)
1726 f->rank = array->rank - 1;
1727 gfc_resolve_dim_arg (dim);
1729 if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1731 idim = (int) mpz_get_si (dim->value.integer);
1732 f->shape = gfc_get_shape (f->rank);
1733 for (i = 0, j = 0; i < f->rank; i++, j++)
1735 if (i == (idim - 1))
1736 j++;
1737 mpz_init_set (f->shape[i], array->shape[j]);
1742 if (mask)
1744 if (mask->rank == 0)
1745 name = "sminval";
1746 else
1747 name = "mminval";
1749 resolve_mask_arg (mask);
1751 else
1752 name = "minval";
1754 f->value.function.name
1755 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1756 gfc_type_letter (array->ts.type), array->ts.kind);
1760 void
1761 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1763 f->ts.type = a->ts.type;
1764 if (p != NULL)
1765 f->ts.kind = gfc_kind_max (a,p);
1766 else
1767 f->ts.kind = a->ts.kind;
1769 if (p != NULL && a->ts.kind != p->ts.kind)
1771 if (a->ts.kind == gfc_kind_max (a,p))
1772 gfc_convert_type (p, &a->ts, 2);
1773 else
1774 gfc_convert_type (a, &p->ts, 2);
1777 f->value.function.name
1778 = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1782 void
1783 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1785 f->ts.type = a->ts.type;
1786 if (p != NULL)
1787 f->ts.kind = gfc_kind_max (a,p);
1788 else
1789 f->ts.kind = a->ts.kind;
1791 if (p != NULL && a->ts.kind != p->ts.kind)
1793 if (a->ts.kind == gfc_kind_max (a,p))
1794 gfc_convert_type (p, &a->ts, 2);
1795 else
1796 gfc_convert_type (a, &p->ts, 2);
1799 f->value.function.name
1800 = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1801 f->ts.kind);
1804 void
1805 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1807 if (p->ts.kind != a->ts.kind)
1808 gfc_convert_type (p, &a->ts, 2);
1810 f->ts = a->ts;
1811 f->value.function.name
1812 = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1813 a->ts.kind);
1816 void
1817 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1819 f->ts.type = BT_INTEGER;
1820 f->ts.kind = (kind == NULL)
1821 ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1822 f->value.function.name
1823 = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1827 void
1828 gfc_resolve_norm2 (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1830 f->ts = array->ts;
1832 if (dim != NULL)
1834 f->rank = array->rank - 1;
1835 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
1836 gfc_resolve_dim_arg (dim);
1839 f->value.function.name
1840 = gfc_get_string (PREFIX ("norm2_r%d"), array->ts.kind);
1844 void
1845 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1847 f->ts = i->ts;
1848 f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1852 void
1853 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1855 f->ts.type = i->ts.type;
1856 f->ts.kind = gfc_kind_max (i, j);
1858 if (i->ts.kind != j->ts.kind)
1860 if (i->ts.kind == gfc_kind_max (i, j))
1861 gfc_convert_type (j, &i->ts, 2);
1862 else
1863 gfc_convert_type (i, &j->ts, 2);
1866 f->value.function.name
1867 = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1871 void
1872 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1873 gfc_expr *vector ATTRIBUTE_UNUSED)
1875 if (array->ts.type == BT_CHARACTER && array->ref)
1876 gfc_resolve_substring_charlen (array);
1878 f->ts = array->ts;
1879 f->rank = 1;
1881 resolve_mask_arg (mask);
1883 if (mask->rank != 0)
1885 if (array->ts.type == BT_CHARACTER)
1886 f->value.function.name
1887 = array->ts.kind == 1 ? PREFIX ("pack_char")
1888 : gfc_get_string
1889 (PREFIX ("pack_char%d"),
1890 array->ts.kind);
1891 else
1892 f->value.function.name = PREFIX ("pack");
1894 else
1896 if (array->ts.type == BT_CHARACTER)
1897 f->value.function.name
1898 = array->ts.kind == 1 ? PREFIX ("pack_s_char")
1899 : gfc_get_string
1900 (PREFIX ("pack_s_char%d"),
1901 array->ts.kind);
1902 else
1903 f->value.function.name = PREFIX ("pack_s");
1908 void
1909 gfc_resolve_parity (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1911 f->ts = array->ts;
1913 if (dim != NULL)
1915 f->rank = array->rank - 1;
1916 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
1917 gfc_resolve_dim_arg (dim);
1920 resolve_mask_arg (array);
1922 f->value.function.name
1923 = gfc_get_string (PREFIX ("parity_l%d"), array->ts.kind);
1927 void
1928 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1929 gfc_expr *mask)
1931 const char *name;
1933 f->ts = array->ts;
1935 if (dim != NULL)
1937 f->rank = array->rank - 1;
1938 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
1939 gfc_resolve_dim_arg (dim);
1942 if (mask)
1944 if (mask->rank == 0)
1945 name = "sproduct";
1946 else
1947 name = "mproduct";
1949 resolve_mask_arg (mask);
1951 else
1952 name = "product";
1954 f->value.function.name
1955 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1956 gfc_type_letter (array->ts.type), array->ts.kind);
1960 void
1961 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1963 f->ts.type = BT_REAL;
1965 if (kind != NULL)
1966 f->ts.kind = mpz_get_si (kind->value.integer);
1967 else
1968 f->ts.kind = (a->ts.type == BT_COMPLEX)
1969 ? a->ts.kind : gfc_default_real_kind;
1971 f->value.function.name
1972 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1973 gfc_type_letter (a->ts.type), a->ts.kind);
1977 void
1978 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
1980 f->ts.type = BT_REAL;
1981 f->ts.kind = a->ts.kind;
1982 f->value.function.name
1983 = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
1984 gfc_type_letter (a->ts.type), a->ts.kind);
1988 void
1989 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1990 gfc_expr *p2 ATTRIBUTE_UNUSED)
1992 f->ts.type = BT_INTEGER;
1993 f->ts.kind = gfc_default_integer_kind;
1994 f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
1998 void
1999 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
2000 gfc_expr *ncopies ATTRIBUTE_UNUSED)
2002 f->ts.type = BT_CHARACTER;
2003 f->ts.kind = string->ts.kind;
2004 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
2008 void
2009 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
2010 gfc_expr *pad ATTRIBUTE_UNUSED,
2011 gfc_expr *order ATTRIBUTE_UNUSED)
2013 mpz_t rank;
2014 int kind;
2015 int i;
2017 if (source->ts.type == BT_CHARACTER && source->ref)
2018 gfc_resolve_substring_charlen (source);
2020 f->ts = source->ts;
2022 gfc_array_size (shape, &rank);
2023 f->rank = mpz_get_si (rank);
2024 mpz_clear (rank);
2025 switch (source->ts.type)
2027 case BT_COMPLEX:
2028 case BT_REAL:
2029 case BT_INTEGER:
2030 case BT_LOGICAL:
2031 case BT_CHARACTER:
2032 kind = source->ts.kind;
2033 break;
2035 default:
2036 kind = 0;
2037 break;
2040 switch (kind)
2042 case 4:
2043 case 8:
2044 case 10:
2045 case 16:
2046 if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
2047 f->value.function.name
2048 = gfc_get_string (PREFIX ("reshape_%c%d"),
2049 gfc_type_letter (source->ts.type),
2050 source->ts.kind);
2051 else if (source->ts.type == BT_CHARACTER)
2052 f->value.function.name = gfc_get_string (PREFIX ("reshape_char%d"),
2053 kind);
2054 else
2055 f->value.function.name
2056 = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
2057 break;
2059 default:
2060 f->value.function.name = (source->ts.type == BT_CHARACTER
2061 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
2062 break;
2065 /* TODO: Make this work with a constant ORDER parameter. */
2066 if (shape->expr_type == EXPR_ARRAY
2067 && gfc_is_constant_expr (shape)
2068 && order == NULL)
2070 gfc_constructor *c;
2071 f->shape = gfc_get_shape (f->rank);
2072 c = gfc_constructor_first (shape->value.constructor);
2073 for (i = 0; i < f->rank; i++)
2075 mpz_init_set (f->shape[i], c->expr->value.integer);
2076 c = gfc_constructor_next (c);
2080 /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
2081 so many runtime variations. */
2082 if (shape->ts.kind != gfc_index_integer_kind)
2084 gfc_typespec ts = shape->ts;
2085 ts.kind = gfc_index_integer_kind;
2086 gfc_convert_type_warn (shape, &ts, 2, 0);
2088 if (order && order->ts.kind != gfc_index_integer_kind)
2089 gfc_convert_type_warn (order, &shape->ts, 2, 0);
2093 void
2094 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
2096 f->ts = x->ts;
2097 f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
2101 void
2102 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED)
2104 f->ts = x->ts;
2105 f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
2109 void
2110 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
2111 gfc_expr *set ATTRIBUTE_UNUSED,
2112 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2114 f->ts.type = BT_INTEGER;
2115 if (kind)
2116 f->ts.kind = mpz_get_si (kind->value.integer);
2117 else
2118 f->ts.kind = gfc_default_integer_kind;
2119 f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
2123 void
2124 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
2126 t1->ts = t0->ts;
2127 t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
2131 void
2132 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x,
2133 gfc_expr *i ATTRIBUTE_UNUSED)
2135 f->ts = x->ts;
2136 f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
2140 void
2141 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
2143 f->ts.type = BT_INTEGER;
2144 f->ts.kind = gfc_default_integer_kind;
2145 f->rank = 1;
2146 f->shape = gfc_get_shape (1);
2147 mpz_init_set_ui (f->shape[0], array->rank);
2148 f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
2152 void
2153 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
2155 f->ts = a->ts;
2156 f->value.function.name
2157 = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
2161 void
2162 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
2164 f->ts.type = BT_INTEGER;
2165 f->ts.kind = gfc_c_int_kind;
2167 /* handler can be either BT_INTEGER or BT_PROCEDURE */
2168 if (handler->ts.type == BT_INTEGER)
2170 if (handler->ts.kind != gfc_c_int_kind)
2171 gfc_convert_type (handler, &f->ts, 2);
2172 f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
2174 else
2175 f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
2177 if (number->ts.kind != gfc_c_int_kind)
2178 gfc_convert_type (number, &f->ts, 2);
2182 void
2183 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
2185 f->ts = x->ts;
2186 f->value.function.name
2187 = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2191 void
2192 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
2194 f->ts = x->ts;
2195 f->value.function.name
2196 = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2200 void
2201 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2202 gfc_expr *dim 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;
2212 void
2213 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
2215 f->ts = x->ts;
2216 f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
2220 void
2221 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2222 gfc_expr *ncopies)
2224 if (source->ts.type == BT_CHARACTER && source->ref)
2225 gfc_resolve_substring_charlen (source);
2227 if (source->ts.type == BT_CHARACTER)
2228 check_charlen_present (source);
2230 f->ts = source->ts;
2231 f->rank = source->rank + 1;
2232 if (source->rank == 0)
2234 if (source->ts.type == BT_CHARACTER)
2235 f->value.function.name
2236 = source->ts.kind == 1 ? PREFIX ("spread_char_scalar")
2237 : gfc_get_string
2238 (PREFIX ("spread_char%d_scalar"),
2239 source->ts.kind);
2240 else
2241 f->value.function.name = PREFIX ("spread_scalar");
2243 else
2245 if (source->ts.type == BT_CHARACTER)
2246 f->value.function.name
2247 = source->ts.kind == 1 ? PREFIX ("spread_char")
2248 : gfc_get_string
2249 (PREFIX ("spread_char%d"),
2250 source->ts.kind);
2251 else
2252 f->value.function.name = PREFIX ("spread");
2255 if (dim && gfc_is_constant_expr (dim)
2256 && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2258 int i, idim;
2259 idim = mpz_get_ui (dim->value.integer);
2260 f->shape = gfc_get_shape (f->rank);
2261 for (i = 0; i < (idim - 1); i++)
2262 mpz_init_set (f->shape[i], source->shape[i]);
2264 mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2266 for (i = idim; i < f->rank ; i++)
2267 mpz_init_set (f->shape[i], source->shape[i-1]);
2271 gfc_resolve_dim_arg (dim);
2272 gfc_resolve_index (ncopies, 1);
2276 void
2277 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2279 f->ts = x->ts;
2280 f->value.function.name
2281 = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2285 /* Resolve the g77 compatibility function STAT AND FSTAT. */
2287 void
2288 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2289 gfc_expr *a ATTRIBUTE_UNUSED)
2291 f->ts.type = BT_INTEGER;
2292 f->ts.kind = gfc_default_integer_kind;
2293 f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2297 void
2298 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2299 gfc_expr *a ATTRIBUTE_UNUSED)
2301 f->ts.type = BT_INTEGER;
2302 f->ts.kind = gfc_default_integer_kind;
2303 f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2307 void
2308 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2310 f->ts.type = BT_INTEGER;
2311 f->ts.kind = gfc_default_integer_kind;
2312 if (n->ts.kind != f->ts.kind)
2313 gfc_convert_type (n, &f->ts, 2);
2315 f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2319 void
2320 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2322 gfc_typespec ts;
2323 gfc_clear_ts (&ts);
2325 f->ts.type = BT_INTEGER;
2326 f->ts.kind = gfc_c_int_kind;
2327 if (u->ts.kind != gfc_c_int_kind)
2329 ts.type = BT_INTEGER;
2330 ts.kind = gfc_c_int_kind;
2331 ts.u.derived = NULL;
2332 ts.u.cl = NULL;
2333 gfc_convert_type (u, &ts, 2);
2336 f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2340 void
2341 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2343 f->ts.type = BT_INTEGER;
2344 f->ts.kind = gfc_c_int_kind;
2345 f->value.function.name = gfc_get_string (PREFIX ("fget"));
2349 void
2350 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2352 gfc_typespec ts;
2353 gfc_clear_ts (&ts);
2355 f->ts.type = BT_INTEGER;
2356 f->ts.kind = gfc_c_int_kind;
2357 if (u->ts.kind != gfc_c_int_kind)
2359 ts.type = BT_INTEGER;
2360 ts.kind = gfc_c_int_kind;
2361 ts.u.derived = NULL;
2362 ts.u.cl = NULL;
2363 gfc_convert_type (u, &ts, 2);
2366 f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2370 void
2371 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2373 f->ts.type = BT_INTEGER;
2374 f->ts.kind = gfc_c_int_kind;
2375 f->value.function.name = gfc_get_string (PREFIX ("fput"));
2379 void
2380 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2382 gfc_typespec ts;
2383 gfc_clear_ts (&ts);
2385 f->ts.type = BT_INTEGER;
2386 f->ts.kind = gfc_index_integer_kind;
2387 if (u->ts.kind != gfc_c_int_kind)
2389 ts.type = BT_INTEGER;
2390 ts.kind = gfc_c_int_kind;
2391 ts.u.derived = NULL;
2392 ts.u.cl = NULL;
2393 gfc_convert_type (u, &ts, 2);
2396 f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2400 void
2401 gfc_resolve_storage_size (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
2402 gfc_expr *kind)
2404 f->ts.type = BT_INTEGER;
2405 if (kind)
2406 f->ts.kind = mpz_get_si (kind->value.integer);
2407 else
2408 f->ts.kind = gfc_default_integer_kind;
2412 void
2413 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2415 const char *name;
2417 f->ts = array->ts;
2419 if (mask)
2421 if (mask->rank == 0)
2422 name = "ssum";
2423 else
2424 name = "msum";
2426 resolve_mask_arg (mask);
2428 else
2429 name = "sum";
2431 if (dim != NULL)
2433 f->rank = array->rank - 1;
2434 f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
2435 gfc_resolve_dim_arg (dim);
2438 f->value.function.name
2439 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2440 gfc_type_letter (array->ts.type), array->ts.kind);
2444 void
2445 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2446 gfc_expr *p2 ATTRIBUTE_UNUSED)
2448 f->ts.type = BT_INTEGER;
2449 f->ts.kind = gfc_default_integer_kind;
2450 f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2454 /* Resolve the g77 compatibility function SYSTEM. */
2456 void
2457 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2459 f->ts.type = BT_INTEGER;
2460 f->ts.kind = 4;
2461 f->value.function.name = gfc_get_string (PREFIX ("system"));
2465 void
2466 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2468 f->ts = x->ts;
2469 f->value.function.name
2470 = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2474 void
2475 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2477 f->ts = x->ts;
2478 f->value.function.name
2479 = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2483 void
2484 gfc_resolve_image_index (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2485 gfc_expr *sub ATTRIBUTE_UNUSED)
2487 static char this_image[] = "__image_index";
2488 f->ts.kind = gfc_default_integer_kind;
2489 f->value.function.name = this_image;
2493 void
2494 gfc_resolve_this_image (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
2496 resolve_bound (f, array, dim, NULL, "__this_image", true);
2500 void
2501 gfc_resolve_time (gfc_expr *f)
2503 f->ts.type = BT_INTEGER;
2504 f->ts.kind = 4;
2505 f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2509 void
2510 gfc_resolve_time8 (gfc_expr *f)
2512 f->ts.type = BT_INTEGER;
2513 f->ts.kind = 8;
2514 f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2518 void
2519 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2520 gfc_expr *mold, gfc_expr *size)
2522 /* TODO: Make this do something meaningful. */
2523 static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2525 if (mold->ts.type == BT_CHARACTER
2526 && !mold->ts.u.cl->length
2527 && gfc_is_constant_expr (mold))
2529 int len;
2530 if (mold->expr_type == EXPR_CONSTANT)
2532 len = mold->value.character.length;
2533 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2534 NULL, len);
2536 else
2538 gfc_constructor *c = gfc_constructor_first (mold->value.constructor);
2539 len = c->expr->value.character.length;
2540 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2541 NULL, len);
2545 f->ts = mold->ts;
2547 if (size == NULL && mold->rank == 0)
2549 f->rank = 0;
2550 f->value.function.name = transfer0;
2552 else
2554 f->rank = 1;
2555 f->value.function.name = transfer1;
2556 if (size && gfc_is_constant_expr (size))
2558 f->shape = gfc_get_shape (1);
2559 mpz_init_set (f->shape[0], size->value.integer);
2565 void
2566 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2569 if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2570 gfc_resolve_substring_charlen (matrix);
2572 f->ts = matrix->ts;
2573 f->rank = 2;
2574 if (matrix->shape)
2576 f->shape = gfc_get_shape (2);
2577 mpz_init_set (f->shape[0], matrix->shape[1]);
2578 mpz_init_set (f->shape[1], matrix->shape[0]);
2581 switch (matrix->ts.kind)
2583 case 4:
2584 case 8:
2585 case 10:
2586 case 16:
2587 switch (matrix->ts.type)
2589 case BT_REAL:
2590 case BT_COMPLEX:
2591 f->value.function.name
2592 = gfc_get_string (PREFIX ("transpose_%c%d"),
2593 gfc_type_letter (matrix->ts.type),
2594 matrix->ts.kind);
2595 break;
2597 case BT_INTEGER:
2598 case BT_LOGICAL:
2599 /* Use the integer routines for real and logical cases. This
2600 assumes they all have the same alignment requirements. */
2601 f->value.function.name
2602 = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2603 break;
2605 default:
2606 if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4)
2607 f->value.function.name = PREFIX ("transpose_char4");
2608 else
2609 f->value.function.name = PREFIX ("transpose");
2610 break;
2612 break;
2614 default:
2615 f->value.function.name = (matrix->ts.type == BT_CHARACTER
2616 ? PREFIX ("transpose_char")
2617 : PREFIX ("transpose"));
2618 break;
2623 void
2624 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2626 f->ts.type = BT_CHARACTER;
2627 f->ts.kind = string->ts.kind;
2628 f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2632 void
2633 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2635 resolve_bound (f, array, dim, kind, "__ubound", false);
2639 void
2640 gfc_resolve_ucobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2642 resolve_bound (f, array, dim, kind, "__ucobound", true);
2646 /* Resolve the g77 compatibility function UMASK. */
2648 void
2649 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2651 f->ts.type = BT_INTEGER;
2652 f->ts.kind = n->ts.kind;
2653 f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2657 /* Resolve the g77 compatibility function UNLINK. */
2659 void
2660 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2662 f->ts.type = BT_INTEGER;
2663 f->ts.kind = 4;
2664 f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2668 void
2669 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2671 gfc_typespec ts;
2672 gfc_clear_ts (&ts);
2674 f->ts.type = BT_CHARACTER;
2675 f->ts.kind = gfc_default_character_kind;
2677 if (unit->ts.kind != gfc_c_int_kind)
2679 ts.type = BT_INTEGER;
2680 ts.kind = gfc_c_int_kind;
2681 ts.u.derived = NULL;
2682 ts.u.cl = NULL;
2683 gfc_convert_type (unit, &ts, 2);
2686 f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2690 void
2691 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2692 gfc_expr *field ATTRIBUTE_UNUSED)
2694 if (vector->ts.type == BT_CHARACTER && vector->ref)
2695 gfc_resolve_substring_charlen (vector);
2697 f->ts = vector->ts;
2698 f->rank = mask->rank;
2699 resolve_mask_arg (mask);
2701 if (vector->ts.type == BT_CHARACTER)
2703 if (vector->ts.kind == 1)
2704 f->value.function.name
2705 = gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0);
2706 else
2707 f->value.function.name
2708 = gfc_get_string (PREFIX ("unpack%d_char%d"),
2709 field->rank > 0 ? 1 : 0, vector->ts.kind);
2711 else
2712 f->value.function.name
2713 = gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0);
2717 void
2718 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2719 gfc_expr *set ATTRIBUTE_UNUSED,
2720 gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2722 f->ts.type = BT_INTEGER;
2723 if (kind)
2724 f->ts.kind = mpz_get_si (kind->value.integer);
2725 else
2726 f->ts.kind = gfc_default_integer_kind;
2727 f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2731 void
2732 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2734 f->ts.type = i->ts.type;
2735 f->ts.kind = gfc_kind_max (i, j);
2737 if (i->ts.kind != j->ts.kind)
2739 if (i->ts.kind == gfc_kind_max (i, j))
2740 gfc_convert_type (j, &i->ts, 2);
2741 else
2742 gfc_convert_type (i, &j->ts, 2);
2745 f->value.function.name
2746 = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2750 /* Intrinsic subroutine resolution. */
2752 void
2753 gfc_resolve_alarm_sub (gfc_code *c)
2755 const char *name;
2756 gfc_expr *seconds, *handler;
2757 gfc_typespec ts;
2758 gfc_clear_ts (&ts);
2760 seconds = c->ext.actual->expr;
2761 handler = c->ext.actual->next->expr;
2762 ts.type = BT_INTEGER;
2763 ts.kind = gfc_c_int_kind;
2765 /* handler can be either BT_INTEGER or BT_PROCEDURE.
2766 In all cases, the status argument is of default integer kind
2767 (enforced in check.c) so that the function suffix is fixed. */
2768 if (handler->ts.type == BT_INTEGER)
2770 if (handler->ts.kind != gfc_c_int_kind)
2771 gfc_convert_type (handler, &ts, 2);
2772 name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2773 gfc_default_integer_kind);
2775 else
2776 name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2777 gfc_default_integer_kind);
2779 if (seconds->ts.kind != gfc_c_int_kind)
2780 gfc_convert_type (seconds, &ts, 2);
2782 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2785 void
2786 gfc_resolve_cpu_time (gfc_code *c)
2788 const char *name;
2789 name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2790 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2794 /* Create a formal arglist based on an actual one and set the INTENTs given. */
2796 static gfc_formal_arglist*
2797 create_formal_for_intents (gfc_actual_arglist* actual, const sym_intent* ints)
2799 gfc_formal_arglist* head;
2800 gfc_formal_arglist* tail;
2801 int i;
2803 if (!actual)
2804 return NULL;
2806 head = tail = gfc_get_formal_arglist ();
2807 for (i = 0; actual; actual = actual->next, tail = tail->next, ++i)
2809 gfc_symbol* sym;
2811 sym = gfc_new_symbol ("dummyarg", NULL);
2812 sym->ts = actual->expr->ts;
2814 sym->attr.intent = ints[i];
2815 tail->sym = sym;
2817 if (actual->next)
2818 tail->next = gfc_get_formal_arglist ();
2821 return head;
2825 void
2826 gfc_resolve_mvbits (gfc_code *c)
2828 static const sym_intent INTENTS[] = {INTENT_IN, INTENT_IN, INTENT_IN,
2829 INTENT_INOUT, INTENT_IN};
2831 const char *name;
2832 gfc_typespec ts;
2833 gfc_clear_ts (&ts);
2835 /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
2836 they will be converted so that they fit into a C int. */
2837 ts.type = BT_INTEGER;
2838 ts.kind = gfc_c_int_kind;
2839 if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2840 gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2841 if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2842 gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2843 if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2844 gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2846 /* TO and FROM are guaranteed to have the same kind parameter. */
2847 name = gfc_get_string (PREFIX ("mvbits_i%d"),
2848 c->ext.actual->expr->ts.kind);
2849 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2850 /* Mark as elemental subroutine as this does not happen automatically. */
2851 c->resolved_sym->attr.elemental = 1;
2853 /* Create a dummy formal arglist so the INTENTs are known later for purpose
2854 of creating temporaries. */
2855 c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS);
2859 void
2860 gfc_resolve_random_number (gfc_code *c)
2862 const char *name;
2863 int kind;
2865 kind = c->ext.actual->expr->ts.kind;
2866 if (c->ext.actual->expr->rank == 0)
2867 name = gfc_get_string (PREFIX ("random_r%d"), kind);
2868 else
2869 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2871 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2875 void
2876 gfc_resolve_random_seed (gfc_code *c)
2878 const char *name;
2880 name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2881 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2885 void
2886 gfc_resolve_rename_sub (gfc_code *c)
2888 const char *name;
2889 int kind;
2891 if (c->ext.actual->next->next->expr != NULL)
2892 kind = c->ext.actual->next->next->expr->ts.kind;
2893 else
2894 kind = gfc_default_integer_kind;
2896 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2897 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2901 void
2902 gfc_resolve_kill_sub (gfc_code *c)
2904 const char *name;
2905 int kind;
2907 if (c->ext.actual->next->next->expr != NULL)
2908 kind = c->ext.actual->next->next->expr->ts.kind;
2909 else
2910 kind = gfc_default_integer_kind;
2912 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2913 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2917 void
2918 gfc_resolve_link_sub (gfc_code *c)
2920 const char *name;
2921 int kind;
2923 if (c->ext.actual->next->next->expr != NULL)
2924 kind = c->ext.actual->next->next->expr->ts.kind;
2925 else
2926 kind = gfc_default_integer_kind;
2928 name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2929 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2933 void
2934 gfc_resolve_symlnk_sub (gfc_code *c)
2936 const char *name;
2937 int kind;
2939 if (c->ext.actual->next->next->expr != NULL)
2940 kind = c->ext.actual->next->next->expr->ts.kind;
2941 else
2942 kind = gfc_default_integer_kind;
2944 name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2945 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2949 /* G77 compatibility subroutines dtime() and etime(). */
2951 void
2952 gfc_resolve_dtime_sub (gfc_code *c)
2954 const char *name;
2955 name = gfc_get_string (PREFIX ("dtime_sub"));
2956 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2959 void
2960 gfc_resolve_etime_sub (gfc_code *c)
2962 const char *name;
2963 name = gfc_get_string (PREFIX ("etime_sub"));
2964 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2968 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
2970 void
2971 gfc_resolve_itime (gfc_code *c)
2973 c->resolved_sym
2974 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
2975 gfc_default_integer_kind));
2978 void
2979 gfc_resolve_idate (gfc_code *c)
2981 c->resolved_sym
2982 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
2983 gfc_default_integer_kind));
2986 void
2987 gfc_resolve_ltime (gfc_code *c)
2989 c->resolved_sym
2990 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
2991 gfc_default_integer_kind));
2994 void
2995 gfc_resolve_gmtime (gfc_code *c)
2997 c->resolved_sym
2998 = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
2999 gfc_default_integer_kind));
3003 /* G77 compatibility subroutine second(). */
3005 void
3006 gfc_resolve_second_sub (gfc_code *c)
3008 const char *name;
3009 name = gfc_get_string (PREFIX ("second_sub"));
3010 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3014 void
3015 gfc_resolve_sleep_sub (gfc_code *c)
3017 const char *name;
3018 int kind;
3020 if (c->ext.actual->expr != NULL)
3021 kind = c->ext.actual->expr->ts.kind;
3022 else
3023 kind = gfc_default_integer_kind;
3025 name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
3026 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3030 /* G77 compatibility function srand(). */
3032 void
3033 gfc_resolve_srand (gfc_code *c)
3035 const char *name;
3036 name = gfc_get_string (PREFIX ("srand"));
3037 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3041 /* Resolve the getarg intrinsic subroutine. */
3043 void
3044 gfc_resolve_getarg (gfc_code *c)
3046 const char *name;
3048 if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
3050 gfc_typespec ts;
3051 gfc_clear_ts (&ts);
3053 ts.type = BT_INTEGER;
3054 ts.kind = gfc_default_integer_kind;
3056 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3059 name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
3060 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3064 /* Resolve the getcwd intrinsic subroutine. */
3066 void
3067 gfc_resolve_getcwd_sub (gfc_code *c)
3069 const char *name;
3070 int kind;
3072 if (c->ext.actual->next->expr != NULL)
3073 kind = c->ext.actual->next->expr->ts.kind;
3074 else
3075 kind = gfc_default_integer_kind;
3077 name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
3078 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3082 /* Resolve the get_command intrinsic subroutine. */
3084 void
3085 gfc_resolve_get_command (gfc_code *c)
3087 const char *name;
3088 int kind;
3089 kind = gfc_default_integer_kind;
3090 name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
3091 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3095 /* Resolve the get_command_argument intrinsic subroutine. */
3097 void
3098 gfc_resolve_get_command_argument (gfc_code *c)
3100 const char *name;
3101 int kind;
3102 kind = gfc_default_integer_kind;
3103 name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
3104 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3108 /* Resolve the get_environment_variable intrinsic subroutine. */
3110 void
3111 gfc_resolve_get_environment_variable (gfc_code *code)
3113 const char *name;
3114 int kind;
3115 kind = gfc_default_integer_kind;
3116 name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
3117 code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3121 void
3122 gfc_resolve_signal_sub (gfc_code *c)
3124 const char *name;
3125 gfc_expr *number, *handler, *status;
3126 gfc_typespec ts;
3127 gfc_clear_ts (&ts);
3129 number = c->ext.actual->expr;
3130 handler = c->ext.actual->next->expr;
3131 status = c->ext.actual->next->next->expr;
3132 ts.type = BT_INTEGER;
3133 ts.kind = gfc_c_int_kind;
3135 /* handler can be either BT_INTEGER or BT_PROCEDURE */
3136 if (handler->ts.type == BT_INTEGER)
3138 if (handler->ts.kind != gfc_c_int_kind)
3139 gfc_convert_type (handler, &ts, 2);
3140 name = gfc_get_string (PREFIX ("signal_sub_int"));
3142 else
3143 name = gfc_get_string (PREFIX ("signal_sub"));
3145 if (number->ts.kind != gfc_c_int_kind)
3146 gfc_convert_type (number, &ts, 2);
3147 if (status != NULL && status->ts.kind != gfc_c_int_kind)
3148 gfc_convert_type (status, &ts, 2);
3150 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3154 /* Resolve the SYSTEM intrinsic subroutine. */
3156 void
3157 gfc_resolve_system_sub (gfc_code *c)
3159 const char *name;
3160 name = gfc_get_string (PREFIX ("system_sub"));
3161 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3165 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
3167 void
3168 gfc_resolve_system_clock (gfc_code *c)
3170 const char *name;
3171 int kind;
3173 if (c->ext.actual->expr != NULL)
3174 kind = c->ext.actual->expr->ts.kind;
3175 else if (c->ext.actual->next->expr != NULL)
3176 kind = c->ext.actual->next->expr->ts.kind;
3177 else if (c->ext.actual->next->next->expr != NULL)
3178 kind = c->ext.actual->next->next->expr->ts.kind;
3179 else
3180 kind = gfc_default_integer_kind;
3182 name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
3183 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3187 /* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine. */
3188 void
3189 gfc_resolve_execute_command_line (gfc_code *c)
3191 const char *name;
3192 name = gfc_get_string (PREFIX ("execute_command_line_i%d"),
3193 gfc_default_integer_kind);
3194 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3198 /* Resolve the EXIT intrinsic subroutine. */
3200 void
3201 gfc_resolve_exit (gfc_code *c)
3203 const char *name;
3204 gfc_typespec ts;
3205 gfc_expr *n;
3206 gfc_clear_ts (&ts);
3208 /* The STATUS argument has to be of default kind. If it is not,
3209 we convert it. */
3210 ts.type = BT_INTEGER;
3211 ts.kind = gfc_default_integer_kind;
3212 n = c->ext.actual->expr;
3213 if (n != NULL && n->ts.kind != ts.kind)
3214 gfc_convert_type (n, &ts, 2);
3216 name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
3217 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3221 /* Resolve the FLUSH intrinsic subroutine. */
3223 void
3224 gfc_resolve_flush (gfc_code *c)
3226 const char *name;
3227 gfc_typespec ts;
3228 gfc_expr *n;
3229 gfc_clear_ts (&ts);
3231 ts.type = BT_INTEGER;
3232 ts.kind = gfc_default_integer_kind;
3233 n = c->ext.actual->expr;
3234 if (n != NULL && n->ts.kind != ts.kind)
3235 gfc_convert_type (n, &ts, 2);
3237 name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
3238 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3242 void
3243 gfc_resolve_free (gfc_code *c)
3245 gfc_typespec ts;
3246 gfc_expr *n;
3247 gfc_clear_ts (&ts);
3249 ts.type = BT_INTEGER;
3250 ts.kind = gfc_index_integer_kind;
3251 n = c->ext.actual->expr;
3252 if (n->ts.kind != ts.kind)
3253 gfc_convert_type (n, &ts, 2);
3255 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
3259 void
3260 gfc_resolve_ctime_sub (gfc_code *c)
3262 gfc_typespec ts;
3263 gfc_clear_ts (&ts);
3265 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3266 if (c->ext.actual->expr->ts.kind != 8)
3268 ts.type = BT_INTEGER;
3269 ts.kind = 8;
3270 ts.u.derived = NULL;
3271 ts.u.cl = NULL;
3272 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3275 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3279 void
3280 gfc_resolve_fdate_sub (gfc_code *c)
3282 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3286 void
3287 gfc_resolve_gerror (gfc_code *c)
3289 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3293 void
3294 gfc_resolve_getlog (gfc_code *c)
3296 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3300 void
3301 gfc_resolve_hostnm_sub (gfc_code *c)
3303 const char *name;
3304 int kind;
3306 if (c->ext.actual->next->expr != NULL)
3307 kind = c->ext.actual->next->expr->ts.kind;
3308 else
3309 kind = gfc_default_integer_kind;
3311 name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3312 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3316 void
3317 gfc_resolve_perror (gfc_code *c)
3319 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3322 /* Resolve the STAT and FSTAT intrinsic subroutines. */
3324 void
3325 gfc_resolve_stat_sub (gfc_code *c)
3327 const char *name;
3328 name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3329 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3333 void
3334 gfc_resolve_lstat_sub (gfc_code *c)
3336 const char *name;
3337 name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3338 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3342 void
3343 gfc_resolve_fstat_sub (gfc_code *c)
3345 const char *name;
3346 gfc_expr *u;
3347 gfc_typespec *ts;
3349 u = c->ext.actual->expr;
3350 ts = &c->ext.actual->next->expr->ts;
3351 if (u->ts.kind != ts->kind)
3352 gfc_convert_type (u, ts, 2);
3353 name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3354 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3358 void
3359 gfc_resolve_fgetc_sub (gfc_code *c)
3361 const char *name;
3362 gfc_typespec ts;
3363 gfc_expr *u, *st;
3364 gfc_clear_ts (&ts);
3366 u = c->ext.actual->expr;
3367 st = c->ext.actual->next->next->expr;
3369 if (u->ts.kind != gfc_c_int_kind)
3371 ts.type = BT_INTEGER;
3372 ts.kind = gfc_c_int_kind;
3373 ts.u.derived = NULL;
3374 ts.u.cl = NULL;
3375 gfc_convert_type (u, &ts, 2);
3378 if (st != NULL)
3379 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3380 else
3381 name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3383 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3387 void
3388 gfc_resolve_fget_sub (gfc_code *c)
3390 const char *name;
3391 gfc_expr *st;
3393 st = c->ext.actual->next->expr;
3394 if (st != NULL)
3395 name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3396 else
3397 name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3399 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3403 void
3404 gfc_resolve_fputc_sub (gfc_code *c)
3406 const char *name;
3407 gfc_typespec ts;
3408 gfc_expr *u, *st;
3409 gfc_clear_ts (&ts);
3411 u = c->ext.actual->expr;
3412 st = c->ext.actual->next->next->expr;
3414 if (u->ts.kind != gfc_c_int_kind)
3416 ts.type = BT_INTEGER;
3417 ts.kind = gfc_c_int_kind;
3418 ts.u.derived = NULL;
3419 ts.u.cl = NULL;
3420 gfc_convert_type (u, &ts, 2);
3423 if (st != NULL)
3424 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3425 else
3426 name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3428 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3432 void
3433 gfc_resolve_fput_sub (gfc_code *c)
3435 const char *name;
3436 gfc_expr *st;
3438 st = c->ext.actual->next->expr;
3439 if (st != NULL)
3440 name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3441 else
3442 name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3444 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3448 void
3449 gfc_resolve_fseek_sub (gfc_code *c)
3451 gfc_expr *unit;
3452 gfc_expr *offset;
3453 gfc_expr *whence;
3454 gfc_typespec ts;
3455 gfc_clear_ts (&ts);
3457 unit = c->ext.actual->expr;
3458 offset = c->ext.actual->next->expr;
3459 whence = c->ext.actual->next->next->expr;
3461 if (unit->ts.kind != gfc_c_int_kind)
3463 ts.type = BT_INTEGER;
3464 ts.kind = gfc_c_int_kind;
3465 ts.u.derived = NULL;
3466 ts.u.cl = NULL;
3467 gfc_convert_type (unit, &ts, 2);
3470 if (offset->ts.kind != gfc_intio_kind)
3472 ts.type = BT_INTEGER;
3473 ts.kind = gfc_intio_kind;
3474 ts.u.derived = NULL;
3475 ts.u.cl = NULL;
3476 gfc_convert_type (offset, &ts, 2);
3479 if (whence->ts.kind != gfc_c_int_kind)
3481 ts.type = BT_INTEGER;
3482 ts.kind = gfc_c_int_kind;
3483 ts.u.derived = NULL;
3484 ts.u.cl = NULL;
3485 gfc_convert_type (whence, &ts, 2);
3488 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3491 void
3492 gfc_resolve_ftell_sub (gfc_code *c)
3494 const char *name;
3495 gfc_expr *unit;
3496 gfc_expr *offset;
3497 gfc_typespec ts;
3498 gfc_clear_ts (&ts);
3500 unit = c->ext.actual->expr;
3501 offset = c->ext.actual->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 name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3513 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3517 void
3518 gfc_resolve_ttynam_sub (gfc_code *c)
3520 gfc_typespec ts;
3521 gfc_clear_ts (&ts);
3523 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3525 ts.type = BT_INTEGER;
3526 ts.kind = gfc_c_int_kind;
3527 ts.u.derived = NULL;
3528 ts.u.cl = NULL;
3529 gfc_convert_type (c->ext.actual->expr, &ts, 2);
3532 c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3536 /* Resolve the UMASK intrinsic subroutine. */
3538 void
3539 gfc_resolve_umask_sub (gfc_code *c)
3541 const char *name;
3542 int kind;
3544 if (c->ext.actual->next->expr != NULL)
3545 kind = c->ext.actual->next->expr->ts.kind;
3546 else
3547 kind = gfc_default_integer_kind;
3549 name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3550 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3553 /* Resolve the UNLINK intrinsic subroutine. */
3555 void
3556 gfc_resolve_unlink_sub (gfc_code *c)
3558 const char *name;
3559 int kind;
3561 if (c->ext.actual->next->expr != NULL)
3562 kind = c->ext.actual->next->expr->ts.kind;
3563 else
3564 kind = gfc_default_integer_kind;
3566 name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3567 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);