comparison gcc/fortran/iresolve.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* Intrinsic function resolution. 1 /* Intrinsic function resolution.
2 Copyright (C) 2000-2017 Free Software Foundation, Inc. 2 Copyright (C) 2000-2018 Free Software Foundation, Inc.
3 Contributed by Andy Vaught & Katherine Holcomb 3 Contributed by Andy Vaught & Katherine Holcomb
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
34 #include "stringpool.h" 34 #include "stringpool.h"
35 #include "intrinsic.h" 35 #include "intrinsic.h"
36 #include "constructor.h" 36 #include "constructor.h"
37 #include "arith.h" 37 #include "arith.h"
38 38
39 /* Given printf-like arguments, return a stable version of the result string. 39 /* Given printf-like arguments, return a stable version of the result string.
40 40
41 We already have a working, optimized string hashing table in the form of 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, 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, 43 since if the function name makes it to the gimple output of the frontend,
44 we'll have to create the identifier anyway. */ 44 we'll have to create the identifier anyway. */
45 45
46 const char * 46 const char *
47 gfc_get_string (const char *format, ...) 47 gfc_get_string (const char *format, ...)
80 source->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); 80 source->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
81 81
82 if (source->expr_type == EXPR_CONSTANT) 82 if (source->expr_type == EXPR_CONSTANT)
83 { 83 {
84 source->ts.u.cl->length 84 source->ts.u.cl->length
85 = gfc_get_int_expr (gfc_default_integer_kind, NULL, 85 = gfc_get_int_expr (gfc_charlen_int_kind, NULL,
86 source->value.character.length); 86 source->value.character.length);
87 source->rank = 0; 87 source->rank = 0;
88 } 88 }
89 else if (source->expr_type == EXPR_ARRAY) 89 else if (source->expr_type == EXPR_ARRAY)
90 { 90 {
91 gfc_constructor *c = gfc_constructor_first (source->value.constructor); 91 gfc_constructor *c = gfc_constructor_first (source->value.constructor);
92 source->ts.u.cl->length 92 source->ts.u.cl->length
93 = gfc_get_int_expr (gfc_default_integer_kind, NULL, 93 = gfc_get_int_expr (gfc_charlen_int_kind, NULL,
94 c->expr->value.character.length); 94 c->expr->value.character.length);
95 } 95 }
96 } 96 }
97 97
98 /* Helper function for resolving the "mask" argument. */ 98 /* Helper function for resolving the "mask" argument. */
245 { 245 {
246 f->ts.type = BT_CHARACTER; 246 f->ts.type = BT_CHARACTER;
247 f->ts.kind = (kind == NULL) 247 f->ts.kind = (kind == NULL)
248 ? gfc_default_character_kind : mpz_get_si (kind->value.integer); 248 ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
249 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); 249 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
250 f->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1); 250 f->ts.u.cl->length = gfc_get_int_expr (gfc_charlen_int_kind, NULL, 1);
251 251
252 f->value.function.name 252 f->value.function.name
253 = gfc_get_string ("__%schar_%d_%c%d", is_achar ? "a" : "", f->ts.kind, 253 = gfc_get_string ("__%schar_%d_%c%d", is_achar ? "a" : "", f->ts.kind,
254 gfc_type_letter (x->ts.type), x->ts.kind); 254 gfc_type_letter (x->ts.type), x->ts.kind);
255 } 255 }
314 void 314 void
315 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind) 315 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
316 { 316 {
317 gfc_typespec ts; 317 gfc_typespec ts;
318 gfc_clear_ts (&ts); 318 gfc_clear_ts (&ts);
319 319
320 f->ts.type = a->ts.type; 320 f->ts.type = a->ts.type;
321 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer); 321 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
322 322
323 if (a->ts.kind != f->ts.kind) 323 if (a->ts.kind != f->ts.kind)
324 { 324 {
361 void 361 void
362 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind) 362 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
363 { 363 {
364 gfc_typespec ts; 364 gfc_typespec ts;
365 gfc_clear_ts (&ts); 365 gfc_clear_ts (&ts);
366 366
367 f->ts.type = a->ts.type; 367 f->ts.type = a->ts.type;
368 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer); 368 f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
369 369
370 if (a->ts.kind != f->ts.kind) 370 if (a->ts.kind != f->ts.kind)
371 { 371 {
456 void 456 void
457 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x) 457 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
458 { 458 {
459 gfc_typespec ts; 459 gfc_typespec ts;
460 gfc_clear_ts (&ts); 460 gfc_clear_ts (&ts);
461 461
462 f->ts = x->ts; 462 f->ts = x->ts;
463 if (n->ts.kind != gfc_c_int_kind) 463 if (n->ts.kind != gfc_c_int_kind)
464 { 464 {
465 ts.type = BT_INTEGER; 465 ts.type = BT_INTEGER;
466 ts.kind = gfc_c_int_kind; 466 ts.kind = gfc_c_int_kind;
473 void 473 void
474 gfc_resolve_bessel_n2 (gfc_expr *f, gfc_expr *n1, gfc_expr *n2, gfc_expr *x) 474 gfc_resolve_bessel_n2 (gfc_expr *f, gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
475 { 475 {
476 gfc_typespec ts; 476 gfc_typespec ts;
477 gfc_clear_ts (&ts); 477 gfc_clear_ts (&ts);
478 478
479 f->ts = x->ts; 479 f->ts = x->ts;
480 f->rank = 1; 480 f->rank = 1;
481 if (n1->expr_type == EXPR_CONSTANT && n2->expr_type == EXPR_CONSTANT) 481 if (n1->expr_type == EXPR_CONSTANT && n2->expr_type == EXPR_CONSTANT)
482 { 482 {
483 f->shape = gfc_get_shape (1); 483 f->shape = gfc_get_shape (1);
696 is_trig_resolved (gfc_expr *f) 696 is_trig_resolved (gfc_expr *f)
697 { 697 {
698 /* We know we've already resolved the function if we see the lib call 698 /* We know we've already resolved the function if we see the lib call
699 starting with '__'. */ 699 starting with '__'. */
700 return (f->value.function.name != NULL 700 return (f->value.function.name != NULL
701 && strncmp ("__", f->value.function.name, 2) == 0); 701 && gfc_str_startswith (f->value.function.name, "__"));
702 } 702 }
703 703
704 /* Return a shallow copy of the function expression f. The original expression 704 /* Return a shallow copy of the function expression f. The original expression
705 has its pointers cleared so that it may be freed without affecting the 705 has its pointers cleared so that it may be freed without affecting the
706 shallow copy. This is similar to gfc_copy_expr, but doesn't perform a deep 706 shallow copy. This is similar to gfc_copy_expr, but doesn't perform a deep
809 809
810 /* If dim kind is greater than default integer we need to use the larger. */ 810 /* If dim kind is greater than default integer we need to use the larger. */
811 m = gfc_default_integer_kind; 811 m = gfc_default_integer_kind;
812 if (dim != NULL) 812 if (dim != NULL)
813 m = m < dim->ts.kind ? dim->ts.kind : m; 813 m = m < dim->ts.kind ? dim->ts.kind : m;
814 814
815 /* Convert shift to at least m, so we don't need 815 /* Convert shift to at least m, so we don't need
816 kind=1 and kind=2 versions of the library functions. */ 816 kind=1 and kind=2 versions of the library functions. */
817 if (shift->ts.kind < m) 817 if (shift->ts.kind < m)
818 { 818 {
819 gfc_typespec ts; 819 gfc_typespec ts;
820 gfc_clear_ts (&ts); 820 gfc_clear_ts (&ts);
821 ts.type = BT_INTEGER; 821 ts.type = BT_INTEGER;
822 ts.kind = m; 822 ts.kind = m;
823 gfc_convert_type_warn (shift, &ts, 2, 0); 823 gfc_convert_type_warn (shift, &ts, 2, 0);
824 } 824 }
825 825
826 if (dim != NULL) 826 if (dim != NULL)
827 { 827 {
828 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL 828 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
829 && dim->symtree->n.sym->attr.optional) 829 && dim->symtree->n.sym->attr.optional)
830 { 830 {
859 void 859 void
860 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time) 860 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
861 { 861 {
862 gfc_typespec ts; 862 gfc_typespec ts;
863 gfc_clear_ts (&ts); 863 gfc_clear_ts (&ts);
864 864
865 f->ts.type = BT_CHARACTER; 865 f->ts.type = BT_CHARACTER;
866 f->ts.kind = gfc_default_character_kind; 866 f->ts.kind = gfc_default_character_kind;
867 867
868 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */ 868 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
869 if (time->ts.kind != 8) 869 if (time->ts.kind != 8)
974 974
975 /* If dim kind is greater than default integer we need to use the larger. */ 975 /* If dim kind is greater than default integer we need to use the larger. */
976 m = gfc_default_integer_kind; 976 m = gfc_default_integer_kind;
977 if (dim != NULL) 977 if (dim != NULL)
978 m = m < dim->ts.kind ? dim->ts.kind : m; 978 m = m < dim->ts.kind ? dim->ts.kind : m;
979 979
980 /* Convert shift to at least m, so we don't need 980 /* Convert shift to at least m, so we don't need
981 kind=1 and kind=2 versions of the library functions. */ 981 kind=1 and kind=2 versions of the library functions. */
982 if (shift->ts.kind < m) 982 if (shift->ts.kind < m)
983 { 983 {
984 gfc_typespec ts; 984 gfc_typespec ts;
985 gfc_clear_ts (&ts); 985 gfc_clear_ts (&ts);
986 ts.type = BT_INTEGER; 986 ts.type = BT_INTEGER;
987 ts.kind = m; 987 ts.kind = m;
988 gfc_convert_type_warn (shift, &ts, 2, 0); 988 gfc_convert_type_warn (shift, &ts, 2, 0);
989 } 989 }
990 990
991 if (dim != NULL) 991 if (dim != NULL)
992 { 992 {
993 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL 993 if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
994 && dim->symtree->n.sym->attr.optional) 994 && dim->symtree->n.sym->attr.optional)
995 { 995 {
1223 1223
1224 void 1224 void
1225 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j) 1225 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1226 { 1226 {
1227 /* If the kind of i and j are different, then g77 cross-promoted the 1227 /* If the kind of i and j are different, then g77 cross-promoted the
1228 kinds to the largest value. The Fortran 95 standard requires the 1228 kinds to the largest value. The Fortran 95 standard requires the
1229 kinds to match. */ 1229 kinds to match. */
1230 if (i->ts.kind != j->ts.kind) 1230 if (i->ts.kind != j->ts.kind)
1231 { 1231 {
1232 if (i->ts.kind == gfc_kind_max (i, j)) 1232 if (i->ts.kind == gfc_kind_max (i, j))
1233 gfc_convert_type (j, &i->ts, 2); 1233 gfc_convert_type (j, &i->ts, 2);
1314 1314
1315 void 1315 void
1316 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j) 1316 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1317 { 1317 {
1318 /* If the kind of i and j are different, then g77 cross-promoted the 1318 /* If the kind of i and j are different, then g77 cross-promoted the
1319 kinds to the largest value. The Fortran 95 standard requires the 1319 kinds to the largest value. The Fortran 95 standard requires the
1320 kinds to match. */ 1320 kinds to match. */
1321 if (i->ts.kind != j->ts.kind) 1321 if (i->ts.kind != j->ts.kind)
1322 { 1322 {
1323 if (i->ts.kind == gfc_kind_max (i, j)) 1323 if (i->ts.kind == gfc_kind_max (i, j))
1324 gfc_convert_type (j, &i->ts, 2); 1324 gfc_convert_type (j, &i->ts, 2);
1333 1333
1334 void 1334 void
1335 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j) 1335 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1336 { 1336 {
1337 /* If the kind of i and j are different, then g77 cross-promoted the 1337 /* If the kind of i and j are different, then g77 cross-promoted the
1338 kinds to the largest value. The Fortran 95 standard requires the 1338 kinds to the largest value. The Fortran 95 standard requires the
1339 kinds to match. */ 1339 kinds to match. */
1340 if (i->ts.kind != j->ts.kind) 1340 if (i->ts.kind != j->ts.kind)
1341 { 1341 {
1342 if (i->ts.kind == gfc_kind_max (i, j)) 1342 if (i->ts.kind == gfc_kind_max (i, j))
1343 gfc_convert_type (j, &i->ts, 2); 1343 gfc_convert_type (j, &i->ts, 2);
1433 void 1433 void
1434 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u) 1434 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1435 { 1435 {
1436 gfc_typespec ts; 1436 gfc_typespec ts;
1437 gfc_clear_ts (&ts); 1437 gfc_clear_ts (&ts);
1438 1438
1439 f->ts.type = BT_LOGICAL; 1439 f->ts.type = BT_LOGICAL;
1440 f->ts.kind = gfc_default_integer_kind; 1440 f->ts.kind = gfc_default_integer_kind;
1441 if (u->ts.kind != gfc_c_int_kind) 1441 if (u->ts.kind != gfc_c_int_kind)
1442 { 1442 {
1443 ts.type = BT_INTEGER; 1443 ts.type = BT_INTEGER;
1486 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind; 1486 s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1487 1487
1488 f->ts = i->ts; 1488 f->ts = i->ts;
1489 f->value.function.name 1489 f->value.function.name
1490 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind); 1490 = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1491 }
1492
1493
1494 void
1495 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1496 gfc_expr *s ATTRIBUTE_UNUSED)
1497 {
1498 f->ts.type = BT_INTEGER;
1499 f->ts.kind = gfc_default_integer_kind;
1500 f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1501 } 1491 }
1502 1492
1503 1493
1504 void 1494 void
1505 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind) 1495 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1640 { 1630 {
1641 f->shape = gfc_get_shape (f->rank); 1631 f->shape = gfc_get_shape (f->rank);
1642 mpz_init_set (f->shape[0], b->shape[1]); 1632 mpz_init_set (f->shape[0], b->shape[1]);
1643 } 1633 }
1644 } 1634 }
1645 else 1635 else
1646 { 1636 {
1647 /* b->rank == 1 and a->rank == 2 here, all other cases have 1637 /* b->rank == 1 and a->rank == 2 here, all other cases have
1648 been caught in check.c. */ 1638 been caught in check.c. */
1649 if (a->shape) 1639 if (a->shape)
1650 { 1640 {
1689 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args) 1679 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1690 { 1680 {
1691 gfc_resolve_minmax ("__max_%c%d", f, args); 1681 gfc_resolve_minmax ("__max_%c%d", f, args);
1692 } 1682 }
1693 1683
1684 /* The smallest kind for which a minloc and maxloc implementation exists. */
1685
1686 #define MINMAXLOC_MIN_KIND 4
1694 1687
1695 void 1688 void
1696 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim, 1689 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1697 gfc_expr *mask) 1690 gfc_expr *mask, gfc_expr *kind, gfc_expr *back)
1698 { 1691 {
1699 const char *name; 1692 const char *name;
1700 int i, j, idim; 1693 int i, j, idim;
1701 1694 int fkind;
1702 f->ts.type = BT_INTEGER; 1695 int d_num;
1703 f->ts.kind = gfc_default_integer_kind; 1696
1697 f->ts.type = BT_INTEGER;
1698
1699 /* The library versions only exist for kinds 4, 8 and 16. For smaller kinds,
1700 we do a type conversion further down. */
1701 if (kind)
1702 fkind = mpz_get_si (kind->value.integer);
1703 else
1704 fkind = gfc_default_integer_kind;
1705
1706 if (fkind < MINMAXLOC_MIN_KIND)
1707 f->ts.kind = MINMAXLOC_MIN_KIND;
1708 else
1709 f->ts.kind = fkind;
1704 1710
1705 if (dim == NULL) 1711 if (dim == NULL)
1706 { 1712 {
1707 f->rank = 1; 1713 f->rank = 1;
1708 f->shape = gfc_get_shape (1); 1714 f->shape = gfc_get_shape (1);
1735 resolve_mask_arg (mask); 1741 resolve_mask_arg (mask);
1736 } 1742 }
1737 else 1743 else
1738 name = "maxloc"; 1744 name = "maxloc";
1739 1745
1740 f->value.function.name 1746 if (dim)
1741 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind, 1747 {
1748 if (array->ts.type != BT_CHARACTER || f->rank != 0)
1749 d_num = 1;
1750 else
1751 d_num = 2;
1752 }
1753 else
1754 d_num = 0;
1755
1756 f->value.function.name
1757 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, d_num, f->ts.kind,
1742 gfc_type_letter (array->ts.type), array->ts.kind); 1758 gfc_type_letter (array->ts.type), array->ts.kind);
1759
1760 if (kind)
1761 fkind = mpz_get_si (kind->value.integer);
1762 else
1763 fkind = gfc_default_integer_kind;
1764
1765 if (fkind != f->ts.kind)
1766 {
1767 gfc_typespec ts;
1768 gfc_clear_ts (&ts);
1769
1770 ts.type = BT_INTEGER;
1771 ts.kind = fkind;
1772 gfc_convert_type_warn (f, &ts, 2, 0);
1773 }
1774
1775 if (back->ts.kind != gfc_logical_4_kind)
1776 {
1777 gfc_typespec ts;
1778 gfc_clear_ts (&ts);
1779 ts.type = BT_LOGICAL;
1780 ts.kind = gfc_logical_4_kind;
1781 gfc_convert_type_warn (back, &ts, 2, 0);
1782 }
1743 } 1783 }
1744 1784
1745 1785
1746 void 1786 void
1747 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim, 1787 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1780 resolve_mask_arg (mask); 1820 resolve_mask_arg (mask);
1781 } 1821 }
1782 else 1822 else
1783 name = "maxval"; 1823 name = "maxval";
1784 1824
1785 f->value.function.name 1825 if (array->ts.type != BT_CHARACTER)
1786 = gfc_get_string (PREFIX ("%s_%c%d"), name, 1826 f->value.function.name
1787 gfc_type_letter (array->ts.type), array->ts.kind); 1827 = gfc_get_string (PREFIX ("%s_%c%d"), name,
1828 gfc_type_letter (array->ts.type), array->ts.kind);
1829 else
1830 f->value.function.name
1831 = gfc_get_string (PREFIX ("%s%d_%c%d"), name, f->rank != 0,
1832 gfc_type_letter (array->ts.type), array->ts.kind);
1788 } 1833 }
1789 1834
1790 1835
1791 void 1836 void
1792 gfc_resolve_mclock (gfc_expr *f) 1837 gfc_resolve_mclock (gfc_expr *f)
1859 } 1904 }
1860 1905
1861 1906
1862 void 1907 void
1863 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim, 1908 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1864 gfc_expr *mask) 1909 gfc_expr *mask, gfc_expr *kind, gfc_expr *back)
1865 { 1910 {
1866 const char *name; 1911 const char *name;
1867 int i, j, idim; 1912 int i, j, idim;
1868 1913 int fkind;
1869 f->ts.type = BT_INTEGER; 1914 int d_num;
1870 f->ts.kind = gfc_default_integer_kind; 1915
1916 f->ts.type = BT_INTEGER;
1917
1918 /* The library versions only exist for kinds 4, 8 and 16. For smaller kinds,
1919 we do a type conversion further down. */
1920 if (kind)
1921 fkind = mpz_get_si (kind->value.integer);
1922 else
1923 fkind = gfc_default_integer_kind;
1924
1925 if (fkind < MINMAXLOC_MIN_KIND)
1926 f->ts.kind = MINMAXLOC_MIN_KIND;
1927 else
1928 f->ts.kind = fkind;
1871 1929
1872 if (dim == NULL) 1930 if (dim == NULL)
1873 { 1931 {
1874 f->rank = 1; 1932 f->rank = 1;
1875 f->shape = gfc_get_shape (1); 1933 f->shape = gfc_get_shape (1);
1902 resolve_mask_arg (mask); 1960 resolve_mask_arg (mask);
1903 } 1961 }
1904 else 1962 else
1905 name = "minloc"; 1963 name = "minloc";
1906 1964
1907 f->value.function.name 1965 if (dim)
1908 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind, 1966 {
1967 if (array->ts.type != BT_CHARACTER || f->rank != 0)
1968 d_num = 1;
1969 else
1970 d_num = 2;
1971 }
1972 else
1973 d_num = 0;
1974
1975 f->value.function.name
1976 = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, d_num, f->ts.kind,
1909 gfc_type_letter (array->ts.type), array->ts.kind); 1977 gfc_type_letter (array->ts.type), array->ts.kind);
1978
1979 if (fkind != f->ts.kind)
1980 {
1981 gfc_typespec ts;
1982 gfc_clear_ts (&ts);
1983
1984 ts.type = BT_INTEGER;
1985 ts.kind = fkind;
1986 gfc_convert_type_warn (f, &ts, 2, 0);
1987 }
1988
1989 if (back->ts.kind != gfc_logical_4_kind)
1990 {
1991 gfc_typespec ts;
1992 gfc_clear_ts (&ts);
1993 ts.type = BT_LOGICAL;
1994 ts.kind = gfc_logical_4_kind;
1995 gfc_convert_type_warn (back, &ts, 2, 0);
1996 }
1910 } 1997 }
1911 1998
1912 1999
1913 void 2000 void
1914 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim, 2001 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1947 resolve_mask_arg (mask); 2034 resolve_mask_arg (mask);
1948 } 2035 }
1949 else 2036 else
1950 name = "minval"; 2037 name = "minval";
1951 2038
1952 f->value.function.name 2039 if (array->ts.type != BT_CHARACTER)
1953 = gfc_get_string (PREFIX ("%s_%c%d"), name, 2040 f->value.function.name
1954 gfc_type_letter (array->ts.type), array->ts.kind); 2041 = gfc_get_string (PREFIX ("%s_%c%d"), name,
2042 gfc_type_letter (array->ts.type), array->ts.kind);
2043 else
2044 f->value.function.name
2045 = gfc_get_string (PREFIX ("%s%d_%c%d"), name, f->rank != 0,
2046 gfc_type_letter (array->ts.type), array->ts.kind);
1955 } 2047 }
1956 2048
1957 2049
1958 void 2050 void
1959 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p) 2051 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
2157 2249
2158 void 2250 void
2159 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string, 2251 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
2160 gfc_expr *ncopies) 2252 gfc_expr *ncopies)
2161 { 2253 {
2162 int len;
2163 gfc_expr *tmp; 2254 gfc_expr *tmp;
2164 f->ts.type = BT_CHARACTER; 2255 f->ts.type = BT_CHARACTER;
2165 f->ts.kind = string->ts.kind; 2256 f->ts.kind = string->ts.kind;
2166 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind); 2257 f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
2167 2258
2170 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); 2261 f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
2171 2262
2172 tmp = NULL; 2263 tmp = NULL;
2173 if (string->expr_type == EXPR_CONSTANT) 2264 if (string->expr_type == EXPR_CONSTANT)
2174 { 2265 {
2175 len = string->value.character.length; 2266 tmp = gfc_get_int_expr (gfc_charlen_int_kind, NULL,
2176 tmp = gfc_get_int_expr (gfc_default_integer_kind, NULL , len); 2267 string->value.character.length);
2177 } 2268 }
2178 else if (string->ts.u.cl && string->ts.u.cl->length) 2269 else if (string->ts.u.cl && string->ts.u.cl->length)
2179 { 2270 {
2180 tmp = gfc_copy_expr (string->ts.u.cl->length); 2271 tmp = gfc_copy_expr (string->ts.u.cl->length);
2181 } 2272 }
2858 f->ts.kind = gfc_default_integer_kind; 2949 f->ts.kind = gfc_default_integer_kind;
2859 f->value.function.name = image_status; 2950 f->value.function.name = image_status;
2860 } 2951 }
2861 2952
2862 2953
2954 /* Resolve get_team (). */
2955
2956 void
2957 gfc_resolve_get_team (gfc_expr *f, gfc_expr *level ATTRIBUTE_UNUSED)
2958 {
2959 static char get_team[] = "_gfortran_caf_get_team";
2960 f->rank = 0;
2961 f->ts.type = BT_INTEGER;
2962 f->ts.kind = gfc_default_integer_kind;
2963 f->value.function.name = get_team;
2964 }
2965
2966
2863 /* Resolve image_index (...). */ 2967 /* Resolve image_index (...). */
2864 2968
2865 void 2969 void
2866 gfc_resolve_image_index (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED, 2970 gfc_resolve_image_index (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2867 gfc_expr *sub ATTRIBUTE_UNUSED) 2971 gfc_expr *sub ATTRIBUTE_UNUSED)
2885 if (kind == NULL) 2989 if (kind == NULL)
2886 f->ts.kind = gfc_default_integer_kind; 2990 f->ts.kind = gfc_default_integer_kind;
2887 else 2991 else
2888 gfc_extract_int (kind, &f->ts.kind); 2992 gfc_extract_int (kind, &f->ts.kind);
2889 f->value.function.name = stopped_images; 2993 f->value.function.name = stopped_images;
2994 }
2995
2996
2997 /* Resolve team_number (team). */
2998
2999 void
3000 gfc_resolve_team_number (gfc_expr *f, gfc_expr *team ATTRIBUTE_UNUSED)
3001 {
3002 static char team_number[] = "_gfortran_caf_team_number";
3003 f->rank = 0;
3004 f->ts.type = BT_INTEGER;
3005 f->ts.kind = gfc_default_integer_kind;
3006 f->value.function.name = team_number;
2890 } 3007 }
2891 3008
2892 3009
2893 void 3010 void
2894 gfc_resolve_this_image (gfc_expr *f, gfc_expr *array, gfc_expr *dim, 3011 gfc_resolve_this_image (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
2937 { 3054 {
2938 int len; 3055 int len;
2939 if (mold->expr_type == EXPR_CONSTANT) 3056 if (mold->expr_type == EXPR_CONSTANT)
2940 { 3057 {
2941 len = mold->value.character.length; 3058 len = mold->value.character.length;
2942 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, 3059 mold->ts.u.cl->length = gfc_get_int_expr (gfc_charlen_int_kind,
2943 NULL, len); 3060 NULL, len);
2944 } 3061 }
2945 else 3062 else
2946 { 3063 {
2947 gfc_constructor *c = gfc_constructor_first (mold->value.constructor); 3064 gfc_constructor *c = gfc_constructor_first (mold->value.constructor);
2948 len = c->expr->value.character.length; 3065 len = c->expr->value.character.length;
2949 mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, 3066 mold->ts.u.cl->length = gfc_get_int_expr (gfc_charlen_int_kind,
2950 NULL, len); 3067 NULL, len);
2951 } 3068 }
2952 } 3069 }
2953 3070
2954 f->ts = mold->ts; 3071 f->ts = mold->ts;
3077 void 3194 void
3078 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit) 3195 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
3079 { 3196 {
3080 gfc_typespec ts; 3197 gfc_typespec ts;
3081 gfc_clear_ts (&ts); 3198 gfc_clear_ts (&ts);
3082 3199
3083 f->ts.type = BT_CHARACTER; 3200 f->ts.type = BT_CHARACTER;
3084 f->ts.kind = gfc_default_character_kind; 3201 f->ts.kind = gfc_default_character_kind;
3085 3202
3086 if (unit->ts.kind != gfc_c_int_kind) 3203 if (unit->ts.kind != gfc_c_int_kind)
3087 { 3204 {
3285 of creating temporaries. */ 3402 of creating temporaries. */
3286 c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS); 3403 c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS);
3287 } 3404 }
3288 3405
3289 3406
3407 /* Set up the call to RANDOM_INIT. */
3408
3409 void
3410 gfc_resolve_random_init (gfc_code *c)
3411 {
3412 const char *name;
3413 name = gfc_get_string (PREFIX ("random_init"));
3414 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3415 }
3416
3417
3290 void 3418 void
3291 gfc_resolve_random_number (gfc_code *c) 3419 gfc_resolve_random_number (gfc_code *c)
3292 { 3420 {
3293 const char *name; 3421 const char *name;
3294 int kind; 3422 int kind;
3296 kind = c->ext.actual->expr->ts.kind; 3424 kind = c->ext.actual->expr->ts.kind;
3297 if (c->ext.actual->expr->rank == 0) 3425 if (c->ext.actual->expr->rank == 0)
3298 name = gfc_get_string (PREFIX ("random_r%d"), kind); 3426 name = gfc_get_string (PREFIX ("random_r%d"), kind);
3299 else 3427 else
3300 name = gfc_get_string (PREFIX ("arandom_r%d"), kind); 3428 name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
3301 3429
3302 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); 3430 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3303 } 3431 }
3304 3432
3305 3433
3306 void 3434 void
3317 gfc_resolve_rename_sub (gfc_code *c) 3445 gfc_resolve_rename_sub (gfc_code *c)
3318 { 3446 {
3319 const char *name; 3447 const char *name;
3320 int kind; 3448 int kind;
3321 3449
3450 /* Find the type of status. If not present use default integer kind. */
3322 if (c->ext.actual->next->next->expr != NULL) 3451 if (c->ext.actual->next->next->expr != NULL)
3323 kind = c->ext.actual->next->next->expr->ts.kind; 3452 kind = c->ext.actual->next->next->expr->ts.kind;
3324 else 3453 else
3325 kind = gfc_default_integer_kind; 3454 kind = gfc_default_integer_kind;
3326 3455
3327 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind); 3456 name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
3328 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); 3457 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3329 } 3458 }
3330 3459
3331
3332 void
3333 gfc_resolve_kill_sub (gfc_code *c)
3334 {
3335 const char *name;
3336 int kind;
3337
3338 if (c->ext.actual->next->next->expr != NULL)
3339 kind = c->ext.actual->next->next->expr->ts.kind;
3340 else
3341 kind = gfc_default_integer_kind;
3342
3343 name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
3344 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3345 }
3346
3347 3460
3348 void 3461 void
3349 gfc_resolve_link_sub (gfc_code *c) 3462 gfc_resolve_link_sub (gfc_code *c)
3350 { 3463 {
3351 const char *name; 3464 const char *name;
3674 void 3787 void
3675 gfc_resolve_ctime_sub (gfc_code *c) 3788 gfc_resolve_ctime_sub (gfc_code *c)
3676 { 3789 {
3677 gfc_typespec ts; 3790 gfc_typespec ts;
3678 gfc_clear_ts (&ts); 3791 gfc_clear_ts (&ts);
3679 3792
3680 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */ 3793 /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3681 if (c->ext.actual->expr->ts.kind != 8) 3794 if (c->ext.actual->expr->ts.kind != 8)
3682 { 3795 {
3683 ts.type = BT_INTEGER; 3796 ts.type = BT_INTEGER;
3684 ts.kind = 8; 3797 ts.kind = 8;
3858 3971
3859 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name); 3972 c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3860 } 3973 }
3861 3974
3862 3975
3863 void 3976 void
3864 gfc_resolve_fseek_sub (gfc_code *c) 3977 gfc_resolve_fseek_sub (gfc_code *c)
3865 { 3978 {
3866 gfc_expr *unit; 3979 gfc_expr *unit;
3867 gfc_expr *offset; 3980 gfc_expr *offset;
3868 gfc_expr *whence; 3981 gfc_expr *whence;
3932 void 4045 void
3933 gfc_resolve_ttynam_sub (gfc_code *c) 4046 gfc_resolve_ttynam_sub (gfc_code *c)
3934 { 4047 {
3935 gfc_typespec ts; 4048 gfc_typespec ts;
3936 gfc_clear_ts (&ts); 4049 gfc_clear_ts (&ts);
3937 4050
3938 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind) 4051 if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3939 { 4052 {
3940 ts.type = BT_INTEGER; 4053 ts.type = BT_INTEGER;
3941 ts.kind = gfc_c_int_kind; 4054 ts.kind = gfc_c_int_kind;
3942 ts.u.derived = NULL; 4055 ts.u.derived = NULL;