1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ R E S --
-- --
-- B o d y --
-- --
-- $Revision: 1.699 $
-- --
-- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Checks; use Checks;
with Debug; use Debug;
with Debug_A; use Debug_A;
with Einfo; use Einfo;
with Errout; use Errout;
with Expander; use Expander;
with Exp_Ch7; use Exp_Ch7;
with Exp_Util; use Exp_Util;
with Freeze; use Freeze;
with Itypes; use Itypes;
with Lib; use Lib;
with Lib.Xref; use Lib.Xref;
with Namet; use Namet;
with Nmake; use Nmake;
with Nlists; use Nlists;
with Opt; use Opt;
with Output; use Output;
with Restrict; use Restrict;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Aggr; use Sem_Aggr;
with Sem_Attr; use Sem_Attr;
with Sem_Cat; use Sem_Cat;
with Sem_Ch4; use Sem_Ch4;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch8; use Sem_Ch8;
with Sem_Disp; use Sem_Disp;
with Sem_Dist; use Sem_Dist;
with Sem_Elab; use Sem_Elab;
with Sem_Eval; use Sem_Eval;
with Sem_Intr; use Sem_Intr;
with Sem_Util; use Sem_Util;
with Sem_Type; use Sem_Type;
with Sem_Warn; use Sem_Warn;
with Sinfo; use Sinfo;
with Stand; use Stand;
with Stringt; use Stringt;
with Targparm; use Targparm;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
with Urealp; use Urealp;
package body Sem_Res is
-----------------------
-- Local Subprograms --
-----------------------
-- Second pass (top-down) type checking and overload resolution procedures
-- Typ is the type required by context. These procedures propagate the
-- type information recursively to the descendants of N. If the node
-- is not overloaded, its Etype is established in the first pass. If
-- overloaded, the Resolve routines set the correct type. For arith.
-- operators, the Etype is the base type of the context.
-- Note that Resolve_Attribute is separated off in Sem_Attr
procedure Ambiguous_Character (C : Node_Id);
-- Give list of candidate interpretations when a character literal cannot
-- be resolved.
procedure Check_Discriminant_Use (N : Node_Id);
-- Enforce the restrictions on the use of discriminants when constraining
-- a component of a discriminated type (record or concurrent type).
procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id);
-- Given a node for an operator associated with type T, check that
-- the operator is visible. Operators all of whose operands are
-- universal must be checked for visibility during resolution
-- because their type is not determinable based on their operands.
function Check_Infinite_Recursion (N : Node_Id) return Boolean;
-- Given a call node, N, which is known to occur immediately within the
-- subprogram being called, determines whether it is a detectable case of
-- an infinite recursion, and if so, outputs appropriate messages. Returns
-- True if an infinite recursion is detected, and False otherwise.
procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id);
-- If the type of the object being initialized uses the secondary stack
-- directly or indirectly, create a transient scope for the call to the
-- Init_Proc. This is because we do not create transient scopes for the
-- initialization of individual components within the init_proc itself.
-- Could be optimized away perhaps?
procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
-- If a default expression in entry call N depends on the discriminants
-- of the task, it must be replaced with a reference to the discriminant
-- of the task being called.
procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
function Operator_Kind
(Op_Name : Name_Id;
Is_Binary : Boolean)
return Node_Kind;
-- Utility to map the name of an operator into the corresponding Node. Used
-- by other node rewriting procedures.
procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
-- Resolve actuals of call, and add default expressions for missing ones.
procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
-- Called from Resolve_Call, when the prefix denotes an entry or element
-- of entry family. Actuals are resolved as for subprograms, and the node
-- is rebuilt as an entry call. Also called for protected operations. Typ
-- is the context type, which is used when the operation is a protected
-- function with no arguments, and the return value is indexed.
procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
-- A call to a user-defined intrinsic operator is rewritten as a call
-- to the corresponding predefined operator, with suitable conversions.
procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
-- If an operator node resolves to a call to a user-defined operator,
-- rewrite the node as a function call.
procedure Make_Call_Into_Operator
(N : Node_Id;
Typ : Entity_Id;
Op_Id : Entity_Id);
-- Inverse transformation: if an operator is given in functional notation,
-- then after resolving the node, transform into an operator node, so
-- that operands are resolved properly. Recall that predefined operators
-- do not have a full signature and special resolution rules apply.
procedure Rewrite_Renamed_Operator (N : Node_Id; Op : Entity_Id);
-- An operator can rename another, e.g. in an instantiation. In that
-- case, the proper operator node must be constructed.
procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
-- The String_Literal_Subtype is built for all strings that are not
-- operands of a static concatenation operation. If the argument is not
-- a String the function is a no-op.
procedure Set_Slice_Subtype (N : Node_Id);
-- Build subtype of array type, with the range specified by the slice.
function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
-- A universal_fixed expression in an universal context is unambiguous if
-- there is only one applicable fixed point type. Determining whether
-- there is only one requires a search over all visible entities, and
-- happens only in very pathological cases (see 6115-006).
function Valid_Conversion
(N : Node_Id;
Target : Entity_Id;
Operand : Node_Id)
return Boolean;
-- Verify legality rules given in 4.6 (8-23). Target is the target
-- type of the conversion, which may be an implicit conversion of
-- an actual parameter to an anonymous access type (in which case
-- N denotes the actual parameter and N = Operand).
-------------------------
-- Ambiguous_Character --
-------------------------
procedure Ambiguous_Character (C : Node_Id) is
E : Entity_Id;
begin
if Nkind (C) = N_Character_Literal then
Error_Msg_N ("ambiguous character literal", C);
Error_Msg_N
("\possible interpretations: Character, Wide_Character!", C);
E := Current_Entity (C);
if Present (E) then
while Present (E) loop
Error_Msg_NE ("\possible interpretation:}!", C, Etype (E));
E := Homonym (E);
end loop;
end if;
end if;
end Ambiguous_Character;
-------------------------
-- Analyze_And_Resolve --
-------------------------
procedure Analyze_And_Resolve (N : Node_Id) is
begin
Analyze (N);
Resolve (N, Etype (N));
end Analyze_And_Resolve;
procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
begin
Analyze (N);
Resolve (N, Typ);
end Analyze_And_Resolve;
-- Version withs check(s) suppressed
procedure Analyze_And_Resolve
(N : Node_Id;
Typ : Entity_Id;
Suppress : Check_Id)
is
Scop : Entity_Id := Current_Scope;
begin
if Suppress = All_Checks then
declare
Svg : constant Suppress_Record := Scope_Suppress;
begin
Scope_Suppress := (others => True);
Analyze_And_Resolve (N, Typ);
Scope_Suppress := Svg;
end;
else
declare
Svg : constant Boolean := Get_Scope_Suppress (Suppress);
begin
Set_Scope_Suppress (Suppress, True);
Analyze_And_Resolve (N, Typ);
Set_Scope_Suppress (Suppress, Svg);
end;
end if;
if Current_Scope /= Scop
and then Scope_Is_Transient
then
-- This can only happen if a transient scope was created
-- for an inner expression, which will be removed upon
-- completion of the analysis of an enclosing construct.
-- The transient scope must have the suppress status of
-- the enclosing environment, not of this Analyze call.
Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
Scope_Suppress;
end if;
end Analyze_And_Resolve;
procedure Analyze_And_Resolve
(N : Node_Id;
Suppress : Check_Id)
is
Scop : Entity_Id := Current_Scope;
begin
if Suppress = All_Checks then
declare
Svg : constant Suppress_Record := Scope_Suppress;
begin
Scope_Suppress := (others => True);
Analyze_And_Resolve (N);
Scope_Suppress := Svg;
end;
else
declare
Svg : constant Boolean := Get_Scope_Suppress (Suppress);
begin
Set_Scope_Suppress (Suppress, True);
Analyze_And_Resolve (N);
Set_Scope_Suppress (Suppress, Svg);
end;
end if;
if Current_Scope /= Scop
and then Scope_Is_Transient
then
Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
Scope_Suppress;
end if;
end Analyze_And_Resolve;
----------------------------
-- Check_Discriminant_Use --
----------------------------
procedure Check_Discriminant_Use (N : Node_Id) is
PN : constant Node_Id := Parent (N);
Disc : constant Entity_Id := Entity (N);
P : Node_Id;
D : Node_Id;
begin
-- Any use in a default expression is legal.
if In_Default_Expression then
null;
elsif Nkind (PN) = N_Range then
-- Discriminant cannot be used to constrain a scalar type.
P := Parent (PN);
if Nkind (P) = N_Range_Constraint
and then Nkind (Parent (P)) = N_Subtype_Indication
and then Nkind (Parent (Parent (P))) = N_Component_Declaration
then
Error_Msg_N ("discriminant cannot constrain scalar type", N);
elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
-- The following check catches the unusual case where
-- a discriminant appears within an index constraint
-- that is part of a larger expression within a constraint
-- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
-- For now we only check case of record components, and
-- note that a similar check should also apply in the
-- case of discriminant constraints below. ???
-- Note that the check for N_Subtype_Declaration below is to
-- detect the valid use of discriminants in the constraints of a
-- subtype declaration when this subtype declaration appears
-- inside the scope of a record type (which is syntactically
-- illegal, but which may be created as part of derived type
-- processing for records). See Sem_Ch3.Build_Derived_Record_Type
-- for more info.
if Ekind (Current_Scope) = E_Record_Type
and then Scope (Disc) = Current_Scope
and then not
(Nkind (Parent (P)) = N_Subtype_Indication
and then
(Nkind (Parent (Parent (P))) = N_Component_Declaration
or else Nkind (Parent (Parent (P))) = N_Subtype_Declaration)
and then Paren_Count (N) = 0)
then
Error_Msg_N
("discriminant must appear alone in component constraint", N);
return;
end if;
-- Detect a common beginner error:
-- type R (D : Positive := 100) is record
-- Name: String (1 .. D);
-- end record;
-- The default value causes an object of type R to be
-- allocated with room for Positive'Last characters.
declare
SI : Node_Id;
T : Entity_Id;
TB : Node_Id;
CB : Entity_Id;
function Large_Storage_Type (T : Entity_Id) return Boolean;
-- Return True if type T has a large enough range that
-- any array whose index type covered the whole range of
-- the type would likely raise Storage_Error.
function Large_Storage_Type (T : Entity_Id) return Boolean is
begin
return
T = Standard_Integer
or else
T = Standard_Positive
or else
T = Standard_Natural;
end Large_Storage_Type;
begin
-- Check that the Disc has a large range
if not Large_Storage_Type (Etype (Disc)) then
goto No_Danger;
end if;
-- If the enclosing type is limited, we allocate only the
-- default value, not the maximum, and there is no need for
-- a warning.
if Is_Limited_Type (Scope (Disc)) then
goto No_Danger;
end if;
-- Check that it is the high bound
if N /= High_Bound (PN)
or else not Present (Discriminant_Default_Value (Disc))
then
goto No_Danger;
end if;
-- Check the array allows a large range at this bound.
-- First find the array
SI := Parent (P);
if Nkind (SI) /= N_Subtype_Indication then
goto No_Danger;
end if;
T := Entity (Subtype_Mark (SI));
if not Is_Array_Type (T) then
goto No_Danger;
end if;
-- Next, find the dimension
TB := First_Index (T);
CB := First (Constraints (P));
while True
and then Present (TB)
and then Present (CB)
and then CB /= PN
loop
Next_Index (TB);
Next (CB);
end loop;
if CB /= PN then
goto No_Danger;
end if;
-- Now, check the dimension has a large range
if not Large_Storage_Type (Etype (TB)) then
goto No_Danger;
end if;
-- Warn about the danger
Error_Msg_N
("creation of object of this type may raise Storage_Error?",
N);
<<No_Danger>>
null;
end;
end if;
-- Legal case is in index or discriminant constraint
elsif Nkind (PN) = N_Index_Or_Discriminant_Constraint
or else Nkind (PN) = N_Discriminant_Association
then
if Paren_Count (N) > 0 then
Error_Msg_N
("discriminant in constraint must appear alone", N);
end if;
return;
-- Otherwise, context is an expression. It should not be within
-- (i.e. a subexpression of) a constraint for a component.
else
D := PN;
P := Parent (PN);
while Nkind (P) /= N_Component_Declaration
and then Nkind (P) /= N_Subtype_Indication
and then Nkind (P) /= N_Entry_Declaration
loop
D := P;
P := Parent (P);
exit when No (P);
end loop;
-- If the discriminant is used in an expression that is a bound
-- of a scalar type, an Itype is created and the bounds are attached
-- to its range, not to the original subtype indication. Such use
-- is of course a double fault.
if (Nkind (P) = N_Subtype_Indication
and then
(Nkind (Parent (P)) = N_Component_Declaration
or else Nkind (Parent (P)) = N_Derived_Type_Definition)
and then D = Constraint (P))
-- The constraint itself may be given by a subtype indication,
-- rather than by a more common discrete range.
or else (Nkind (P) = N_Subtype_Indication
and then Nkind (Parent (P)) = N_Index_Or_Discriminant_Constraint)
or else Nkind (P) = N_Entry_Declaration
or else Nkind (D) = N_Defining_Identifier
then
Error_Msg_N
("discriminant in constraint must appear alone", N);
end if;
end if;
end Check_Discriminant_Use;
--------------------------------
-- Check_For_Visible_Operator --
--------------------------------
procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id) is
Orig_Node : Node_Id := Original_Node (N);
begin
if Comes_From_Source (Orig_Node)
and then not In_Open_Scopes (Scope (T))
and then not Is_Potentially_Use_Visible (T)
and then not In_Use (T)
and then not In_Use (Scope (T))
and then (not Present (Entity (N))
or else Ekind (Entity (N)) /= E_Function)
and then (Nkind (Orig_Node) /= N_Function_Call
or else Nkind (Name (Orig_Node)) /= N_Expanded_Name
or else Entity (Prefix (Name (Orig_Node))) /= Scope (T))
and then not In_Instance
then
Error_Msg_NE
("operator for} is not directly visible!", N, First_Subtype (T));
Error_Msg_N ("use clause would make operation legal!", N);
end if;
end Check_For_Visible_Operator;
------------------------------
-- Check_Infinite_Recursion --
------------------------------
function Check_Infinite_Recursion (N : Node_Id) return Boolean is
P : Node_Id;
C : Node_Id;
begin
-- Loop moving up tree, quitting if something tells us we are
-- definitely not in an infinite recursion situation.
C := N;
loop
P := Parent (C);
exit when Nkind (P) = N_Subprogram_Body;
if Nkind (P) = N_Or_Else or else
Nkind (P) = N_And_Then or else
Nkind (P) = N_If_Statement or else
Nkind (P) = N_Case_Statement
then
return False;
elsif Nkind (P) = N_Handled_Sequence_Of_Statements
and then C /= First (Statements (P))
then
return False;
else
C := P;
end if;
end loop;
Warn_On_Instance := True;
Error_Msg_N ("possible infinite recursion?", N);
Error_Msg_N ("\Storage_Error may be raised at run time?", N);
Warn_On_Instance := False;
return True;
end Check_Infinite_Recursion;
-------------------------------
-- Check_Initialization_Call --
-------------------------------
procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
Typ : Entity_Id := Etype (First_Formal (Nam));
function Uses_SS (T : Entity_Id) return Boolean;
function Uses_SS (T : Entity_Id) return Boolean is
Comp : Entity_Id;
Expr : Node_Id;
begin
if Is_Controlled (T)
or else Has_Controlled_Component (T)
or else Functions_Return_By_DSP_On_Target
then
return False;
elsif Is_Array_Type (T) then
return Uses_SS (Component_Type (T));
elsif Is_Record_Type (T) then
Comp := First_Component (T);
while Present (Comp) loop
if Ekind (Comp) = E_Component
and then Nkind (Parent (Comp)) = N_Component_Declaration
then
Expr := Expression (Parent (Comp));
if Nkind (Expr) = N_Function_Call
and then Requires_Transient_Scope (Etype (Expr))
then
return True;
elsif Uses_SS (Etype (Comp)) then
return True;
end if;
end if;
Next_Component (Comp);
end loop;
return False;
else
return False;
end if;
end Uses_SS;
begin
if Uses_SS (Typ) then
Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
end if;
end Check_Initialization_Call;
------------------------------
-- Check_Parameterless_Call --
------------------------------
procedure Check_Parameterless_Call (N : Node_Id) is
Nam : Node_Id;
begin
if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
return;
end if;
-- Rewrite as call if overloadable entity that is (or could be, in
-- the overloaded case) a function call. If we know for sure that
-- the entity is an enumeration literal, we do not rewrite it.
if (Is_Entity_Name (N)
and then Is_Overloadable (Entity (N))
and then (Ekind (Entity (N)) /= E_Enumeration_Literal
or else Is_Overloaded (N)))
-- Rewrite as call if it is an explicit deference of an expression of
-- a subprogram access type, and the suprogram type is not that of a
-- procedure or entry.
or else
(Nkind (N) = N_Explicit_Dereference
and then Ekind (Etype (N)) = E_Subprogram_Type
and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type)
-- Rewrite as call if it is a selected component which is a function,
-- this is the case of a call to a protected function (which may be
-- overloaded with other protected operations).
or else
(Nkind (N) = N_Selected_Component
and then (Ekind (Entity (Selector_Name (N))) = E_Function
or else ((Ekind (Entity (Selector_Name (N))) = E_Entry
or else
Ekind (Entity (Selector_Name (N))) = E_Procedure)
and then Is_Overloaded (Selector_Name (N)))))
-- If one of the above three conditions is met, rewrite as call.
-- Apply the rewriting only once.
then
if Nkind (Parent (N)) /= N_Function_Call
or else N /= Name (Parent (N))
then
Nam := New_Copy (N);
-- If overloaded, overload set belongs to new copy.
Save_Interps (N, Nam);
-- Change node to parameterless function call (note that the
-- Parameter_Associations associations field is left set to Empty,
-- its normal default value since there are no parameters)
Change_Node (N, N_Function_Call);
Set_Name (N, Nam);
Set_Sloc (N, Sloc (Nam));
Analyze_Call (N);
end if;
elsif Nkind (N) = N_Parameter_Association then
Check_Parameterless_Call (Explicit_Actual_Parameter (N));
end if;
end Check_Parameterless_Call;
-----------------------------
-- Make_Call_Into_Operator --
-----------------------------
procedure Make_Call_Into_Operator
(N : Node_Id;
Typ : Entity_Id;
Op_Id : Entity_Id)
is
Op_Name : constant Name_Id := Chars (Op_Id);
Act1 : Node_Id := First_Actual (N);
Act2 : Node_Id := Next_Actual (Act1);
Error : Boolean := False;
Is_Binary : constant Boolean := Present (Act2);
Op_Node : Node_Id;
Opnd_Type : Entity_Id;
Orig_Type : Entity_Id := Empty;
Pack : Entity_Id;
type Kind_Test is access function (E : Entity_Id) return Boolean;
function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
-- Determine whether E is an acess type declared by an access decla-
-- ration, and not an (anonymous) allocator type.
function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
-- If the operand is not universal, and the operator is given by a
-- expanded name, verify that the operand has an interpretation with
-- a type defined in the given scope of the operator.
function Type_In_P (Test : Kind_Test) return Entity_Id;
-- Find a type of the given class in the package Pack that contains
-- the operator.
-----------------------------
-- Is_Definite_Access_Type --
-----------------------------
function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
Btyp : constant Entity_Id := Base_Type (E);
begin
return Ekind (Btyp) = E_Access_Type
or else (Ekind (Btyp) = E_Access_Subprogram_Type
and then Comes_From_Source (Btyp));
end Is_Definite_Access_Type;
---------------------------
-- Operand_Type_In_Scope --
---------------------------
function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
Nod : constant Node_Id := Right_Opnd (Op_Node);
I : Interp_Index;
It : Interp;
begin
if not Is_Overloaded (Nod) then
return Scope (Base_Type (Etype (Nod))) = S;
else
Get_First_Interp (Nod, I, It);
while Present (It.Typ) loop
if Scope (Base_Type (It.Typ)) = S then
return True;
end if;
Get_Next_Interp (I, It);
end loop;
return False;
end if;
end Operand_Type_In_Scope;
---------------
-- Type_In_P --
---------------
function Type_In_P (Test : Kind_Test) return Entity_Id is
E : Entity_Id;
function In_Decl return Boolean;
-- Verify that node is not part of the type declaration for the
-- candidate type, which would otherwise be invisible.
-------------
-- In_Decl --
-------------
function In_Decl return Boolean is
Decl_Node : constant Node_Id := Parent (E);
N2 : Node_Id;
begin
N2 := N;
if Etype (E) = Any_Type then
return True;
elsif No (Decl_Node) then
return False;
else
while Present (N2)
and then Nkind (N2) /= N_Compilation_Unit
loop
if N2 = Decl_Node then
return True;
else
N2 := Parent (N2);
end if;
end loop;
return False;
end if;
end In_Decl;
-- Start of processing for Type_In_P
begin
-- If the context type is declared in the prefix package, this
-- is the desired base type.
if Scope (Base_Type (Typ)) = Pack
and then Test (Typ)
then
return Base_Type (Typ);
else
E := First_Entity (Pack);
while Present (E) loop
if Test (E)
and then not In_Decl
then
return E;
end if;
Next_Entity (E);
end loop;
return Empty;
end if;
end Type_In_P;
---------------------------
-- Operand_Type_In_Scope --
---------------------------
-- Start of processing for Make_Call_Into_Operator
begin
Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
-- Binary operator
if Is_Binary then
Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
Save_Interps (Act1, Left_Opnd (Op_Node));
Save_Interps (Act2, Right_Opnd (Op_Node));
Act1 := Left_Opnd (Op_Node);
Act2 := Right_Opnd (Op_Node);
-- Unary operator
else
Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
Save_Interps (Act1, Right_Opnd (Op_Node));
Act1 := Right_Opnd (Op_Node);
end if;
-- If the operator is denoted by an expanded name, and the prefix is
-- not Standard, but the operator is a predefined one whose scope is
-- Standard, then this is an implicit_operator, inserted as an
-- interpretation by the procedure of the same name. This procedure
-- overestimates the presence of implicit operators, because it does
-- not examine the type of the operands. Verify now that the operand
-- type appears in the given scope. If right operand is universal,
-- check the other operand. In the case of concatenation, either
-- argument can be the component type, so check the type of the result.
-- If both arguments are literals, look for a type of the right kind
-- defined in the given scope. This elaborate nonsense is brought to
-- you courtesy of b33302a. The type itself must be frozen, so we must
-- find the type of the proper class in the given scope.
-- A final wrinkle is the multiplication operator for fixed point
-- types, which is defined in Standard only, and not in the scope of
-- the fixed_point type itself.
if Nkind (Name (N)) = N_Expanded_Name then
Pack := Entity (Prefix (Name (N)));
-- If the entity being called is defined in the given package,
-- it is a renaming of a predefined operator, and known to be
-- legal.
if Scope (Entity (Name (N))) = Pack
and then Pack /= Standard_Standard
then
null;
elsif (Op_Name = Name_Op_Multiply
or else Op_Name = Name_Op_Divide)
and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
then
if Pack /= Standard_Standard then
Error := True;
end if;
else
Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
if Op_Name = Name_Op_Concat then
Opnd_Type := Base_Type (Typ);
elsif (Scope (Opnd_Type) = Standard_Standard
and then Is_Binary)
or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
and then Is_Binary
and then not Comes_From_Source (Opnd_Type))
then
Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
end if;
if Scope (Opnd_Type) = Standard_Standard then
-- Verify that the scope contains a type that corresponds to
-- the given literal. Optimize the case where Pack is Standard.
if Pack /= Standard_Standard then
if Opnd_Type = Universal_Integer then
Orig_Type := Type_In_P (Is_Integer_Type'Access);
elsif Opnd_Type = Universal_Real then
Orig_Type := Type_In_P (Is_Real_Type'Access);
elsif Opnd_Type = Any_String then
Orig_Type := Type_In_P (Is_String_Type'Access);
elsif Opnd_Type = Any_Access then
Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
elsif Opnd_Type = Any_Composite then
Orig_Type := Type_In_P (Is_Composite_Type'Access);
if Present (Orig_Type) then
if Has_Private_Component (Orig_Type) then
Orig_Type := Empty;
else
Set_Etype (Act1, Orig_Type);
if Is_Binary then
Set_Etype (Act2, Orig_Type);
end if;
end if;
end if;
else
Orig_Type := Empty;
end if;
Error := No (Orig_Type);
end if;
elsif Ekind (Opnd_Type) = E_Allocator_Type
and then No (Type_In_P (Is_Definite_Access_Type'Access))
then
Error := True;
-- If the type is defined elsewhere, and the operator is not
-- defined in the given scope (by a renaming declaration, e.g.)
-- then this is an error as well. If an extension of System is
-- present, and the type may be defined there, Pack must be
-- System itself.
elsif Scope (Opnd_Type) /= Pack
and then Scope (Op_Id) /= Pack
and then (No (System_Aux_Id)
or else Scope (Opnd_Type) /= System_Aux_Id
or else Pack /= Scope (System_Aux_Id))
then
Error := True;
elsif Pack = Standard_Standard
and then not Operand_Type_In_Scope (Standard_Standard)
then
Error := True;
end if;
end if;
if Error then
Error_Msg_Node_2 := Pack;
Error_Msg_NE
("& not declared in&", N, Selector_Name (Name (N)));
Set_Etype (N, Any_Type);
return;
end if;
end if;
Set_Chars (Op_Node, Op_Name);
Set_Etype (Op_Node, Base_Type (Etype (N)));
Set_Entity (Op_Node, Op_Id);
Generate_Reference (Op_Id, N, ' ');
Rewrite (N, Op_Node);
Resolve (N, Typ);
-- For predefined operators on literals, the operation freezes
-- their type.
if Present (Orig_Type) then
Set_Etype (Act1, Orig_Type);
Freeze_Expression (Act1);
end if;
end Make_Call_Into_Operator;
-------------------
-- Operator_Kind --
-------------------
function Operator_Kind
(Op_Name : Name_Id;
Is_Binary : Boolean)
return Node_Kind
is
Kind : Node_Kind;
begin
if Is_Binary then
if Op_Name = Name_Op_And then Kind := N_Op_And;
elsif Op_Name = Name_Op_Or then Kind := N_Op_Or;
elsif Op_Name = Name_Op_Xor then Kind := N_Op_Xor;
elsif Op_Name = Name_Op_Eq then Kind := N_Op_Eq;
elsif Op_Name = Name_Op_Ne then Kind := N_Op_Ne;
elsif Op_Name = Name_Op_Lt then Kind := N_Op_Lt;
elsif Op_Name = Name_Op_Le then Kind := N_Op_Le;
elsif Op_Name = Name_Op_Gt then Kind := N_Op_Gt;
elsif Op_Name = Name_Op_Ge then Kind := N_Op_Ge;
elsif Op_Name = Name_Op_Add then Kind := N_Op_Add;
elsif Op_Name = Name_Op_Subtract then Kind := N_Op_Subtract;
elsif Op_Name = Name_Op_Concat then Kind := N_Op_Concat;
elsif Op_Name = Name_Op_Multiply then Kind := N_Op_Multiply;
elsif Op_Name = Name_Op_Divide then Kind := N_Op_Divide;
elsif Op_Name = Name_Op_Mod then Kind := N_Op_Mod;
elsif Op_Name = Name_Op_Rem then Kind := N_Op_Rem;
elsif Op_Name = Name_Op_Expon then Kind := N_Op_Expon;
else
pragma Assert (False);
raise Program_Error;
end if;
-- Unary operators
else
if Op_Name = Name_Op_Add then Kind := N_Op_Plus;
elsif Op_Name = Name_Op_Subtract then Kind := N_Op_Minus;
elsif Op_Name = Name_Op_Abs then Kind := N_Op_Abs;
elsif Op_Name = Name_Op_Not then Kind := N_Op_Not;
else
pragma Assert (False);
raise Program_Error;
end if;
end if;
return Kind;
end Operator_Kind;
-----------------------------
-- Pre_Analyze_And_Resolve --
-----------------------------
procedure Pre_Analyze_And_Resolve (N : Node_Id; T : Entity_Id) is
Save_Full_Analysis : constant Boolean := Full_Analysis;
begin
Full_Analysis := False;
Expander_Mode_Save_And_Set (False);
-- We suppress all checks for this analysis, since the checks will
-- be applied properly, and in the right location, when the default
-- expression is reanalyzed and reexpanded later on.
Analyze_And_Resolve (N, T, Suppress => All_Checks);
Expander_Mode_Restore;
Full_Analysis := Save_Full_Analysis;
end Pre_Analyze_And_Resolve;
-- Version without context type.
procedure Pre_Analyze_And_Resolve (N : Node_Id) is
Save_Full_Analysis : constant Boolean := Full_Analysis;
begin
Full_Analysis := False;
Expander_Mode_Save_And_Set (False);
Analyze (N);
Resolve (N, Etype (N), Suppress => All_Checks);
Expander_Mode_Restore;
Full_Analysis := Save_Full_Analysis;
end Pre_Analyze_And_Resolve;
----------------------------------
-- Replace_Actual_Discriminants --
----------------------------------
procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Tsk : Node_Id := Empty;
function Process_Discr (Nod : Node_Id) return Traverse_Result;
-------------------
-- Process_Discr --
-------------------
function Process_Discr (Nod : Node_Id) return Traverse_Result is
Ent : Entity_Id;
begin
if Nkind (Nod) = N_Identifier then
Ent := Entity (Nod);
if Present (Ent)
and then Ekind (Ent) = E_Discriminant
then
Rewrite (Nod,
Make_Selected_Component (Loc,
Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
Selector_Name => Make_Identifier (Loc, Chars (Ent))));
Set_Etype (Nod, Etype (Ent));
end if;
end if;
return OK;
end Process_Discr;
procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
-- Start of processing for Replace_Actual_Discriminants
begin
if not Expander_Active then
return;
end if;
if Nkind (Name (N)) = N_Selected_Component then
Tsk := Prefix (Name (N));
elsif Nkind (Name (N)) = N_Indexed_Component then
Tsk := Prefix (Prefix (Name (N)));
end if;
if No (Tsk) then
return;
else
Replace_Discrs (Default);
end if;
end Replace_Actual_Discriminants;
-------------
-- Resolve --
-------------
procedure Resolve (N : Node_Id; Typ : Entity_Id) is
I : Interp_Index;
I1 : Interp_Index;
It : Interp;
It1 : Interp;
Found : Boolean := False;
Seen : Entity_Id;
Ctx_Type : Entity_Id := Typ;
Expr_Type : Entity_Id;
Ambiguous : Boolean := False;
procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
-- Try and fix up a literal so that it matches its expected type. New
-- literals are manufactured if necessary to avoid cascaded errors.
procedure Resolution_Failed;
-- Called when attempt at resolving current expression fails
--------------------
-- Patch_Up_Value --
--------------------
procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
begin
if Nkind (N) = N_Integer_Literal
and then Is_Real_Type (Typ)
then
Rewrite (N,
Make_Real_Literal (Sloc (N),
Realval => UR_From_Uint (Intval (N))));
Set_Etype (N, Universal_Real);
Set_Is_Static_Expression (N);
elsif Nkind (N) = N_Real_Literal
and then Is_Integer_Type (Typ)
then
Rewrite (N,
Make_Integer_Literal (Sloc (N),
Intval => UR_To_Uint (Realval (N))));
Set_Etype (N, Universal_Integer);
Set_Is_Static_Expression (N);
elsif Nkind (N) = N_String_Literal
and then Is_Character_Type (Typ)
then
Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
Rewrite (N,
Make_Character_Literal (Sloc (N),
Chars => Name_Find,
Char_Literal_Value => Char_Code (Character'Pos ('A'))));
Set_Etype (N, Any_Character);
Set_Is_Static_Expression (N);
elsif Nkind (N) /= N_String_Literal
and then Is_String_Type (Typ)
then
Rewrite (N,
Make_String_Literal (Sloc (N),
Strval => End_String));
elsif Nkind (N) = N_Range then
Patch_Up_Value (Low_Bound (N), Typ);
Patch_Up_Value (High_Bound (N), Typ);
end if;
end Patch_Up_Value;
-----------------------
-- Resolution_Failed --
-----------------------
procedure Resolution_Failed is
begin
Patch_Up_Value (N, Typ);
Set_Etype (N, Typ);
Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
Set_Is_Overloaded (N, False);
-- The caller will return without calling the expander, so we need
-- to set the analyzed flag. Note that it is fine to set Analyzed
-- to True even if we are in the middle of a shallow analysis,
-- (see the spec of sem for more details) since this is an error
-- situation anyway, and there is no point in repeating the
-- analysis later (indeed it won't work to repeat it later, since
-- we haven't got a clear resolution of which entity is being
-- referenced.)
Set_Analyzed (N, True);
return;
end Resolution_Failed;
-- Start of processing for Resolve
begin
-- Access attribute on remote subprogram cannot be used for
-- a non-remote access-to-subprogram type.
if Nkind (N) = N_Attribute_Reference
and then (Attribute_Name (N) = Name_Access
or else Attribute_Name (N) = Name_Unrestricted_Access
or else Attribute_Name (N) = Name_Unchecked_Access)
and then Comes_From_Source (N)
and then Is_Entity_Name (Prefix (N))
and then Is_Remote_Call_Interface (Entity (Prefix (N)))
and then not Is_Remote_Access_To_Subprogram_Type (Typ)
then
Error_Msg_N
("prefix must statically denote a non-remote subprogram", N);
end if;
-- If the context is a Remote_Access_To_Subprogram, access attributes
-- must be resolved with the corresponding fat pointer. There is no need
-- to check for the attribute name since the return type of an
-- attribute is never a remote type.
if Nkind (N) = N_Attribute_Reference
and then Comes_From_Source (N)
and then (Is_Remote_Call_Interface (Typ)
or else Is_Remote_Types (Typ))
then
declare
Attr : constant Attribute_Id :=
Get_Attribute_Id (Attribute_Name (N));
Pref : constant Node_Id := Prefix (N);
Decl : Node_Id;
Spec : Node_Id;
Is_Remote : Boolean := True;
begin
-- Check that Typ is a fat pointer with a reference to a RAS as
-- original access type.
if
(Ekind (Typ) = E_Access_Subprogram_Type
and then Present (Equivalent_Type (Typ)))
or else
(Ekind (Typ) = E_Record_Type
and then Present (Corresponding_Remote_Type (Typ)))
then
-- Prefix (N) must statically denote a remote subprogram
-- declared in a package specification.
if Attr = Attribute_Access then
Decl := Unit_Declaration_Node (Entity (Pref));
if Nkind (Decl) = N_Subprogram_Body then
Spec := Corresponding_Spec (Decl);
if not No (Spec) then
Decl := Unit_Declaration_Node (Spec);
end if;
end if;
Spec := Parent (Decl);
if not Is_Entity_Name (Prefix (N))
or else Nkind (Spec) /= N_Package_Specification
or else
not Is_Remote_Call_Interface (Defining_Entity (Spec))
then
Is_Remote := False;
Error_Msg_N
("prefix must statically denote a remote subprogram ",
N);
end if;
end if;
if Attr = Attribute_Access
or else Attr = Attribute_Unchecked_Access
or else Attr = Attribute_Unrestricted_Access
then
Check_Subtype_Conformant
(New_Id => Entity (Prefix (N)),
Old_Id => Designated_Type
(Corresponding_Remote_Type (Typ)),
Err_Loc => N);
if Is_Remote then
Process_Remote_AST_Attribute (N, Typ);
end if;
end if;
end if;
end;
end if;
Debug_A_Entry ("resolving ", N);
if Is_Fixed_Point_Type (Typ) then
Check_Restriction (No_Fixed_Point, N);
elsif Is_Floating_Point_Type (Typ)
and then Typ /= Universal_Real
and then Typ /= Any_Real
then
Check_Restriction (No_Floating_Point, N);
end if;
-- Return if already analyzed
if Analyzed (N) then
Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
return;
-- Return if type = Any_Type (previous error encountered)
elsif Etype (N) = Any_Type then
Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
return;
end if;
Check_Parameterless_Call (N);
-- If not overloaded, then we know the type, and all that needs doing
-- is to check that this type is compatible with the context.
if not Is_Overloaded (N) then
Found := Covers (Typ, Etype (N));
Expr_Type := Etype (N);
-- In the overloaded case, we must select the interpretation that
-- is compatible with the context (i.e. the type passed to Resolve)
else
Get_First_Interp (N, I, It);
-- Loop through possible interpretations
Interp_Loop : while Present (It.Typ) loop
-- We are only interested in interpretations that are compatible
-- with the expected type, any other interpretations are ignored
if Covers (Typ, It.Typ) then
-- First matching interpretation
if not Found then
Found := True;
I1 := I;
Seen := It.Nam;
Expr_Type := It.Typ;
-- Matching intepretation that is not the first, maybe an
-- error, but there are some cases where preference rules are
-- used to choose between the two possibilities. These and
-- some more obscure cases are handled in Disambiguate.
else
Error_Msg_Sloc := Sloc (Seen);
It1 := Disambiguate (N, I1, I, Typ);
if It1 = No_Interp then
-- Before we issue an ambiguity complaint, check for
-- the case of a subprogram call where at least one
-- of the arguments is Any_Type, and if so, suppress
-- the message, since it is a cascaded error.
if Nkind (N) = N_Function_Call
or else Nkind (N) = N_Procedure_Call_Statement
then
declare
A : Node_Id := First_Actual (N);
E : Node_Id;
begin
while Present (A) loop
E := A;
if Nkind (E) = N_Parameter_Association then
E := Explicit_Actual_Parameter (E);
end if;
if Etype (E) = Any_Type then
if Debug_Flag_V then
Write_Str ("Any_Type in call");
Write_Eol;
end if;
exit Interp_Loop;
end if;
Next_Actual (A);
end loop;
end;
elsif Nkind (N) in N_Binary_Op
and then (Etype (Left_Opnd (N)) = Any_Type
or else Etype (Right_Opnd (N)) = Any_Type)
then
exit Interp_Loop;
elsif Nkind (N) in N_Unary_Op
and then Etype (Right_Opnd (N)) = Any_Type
then
exit Interp_Loop;
end if;
-- Not that special case, so issue message using the
-- flag Ambiguous to control printing of the header
-- message only at the start of an ambiguous set.
if not Ambiguous then
Error_Msg_NE
("ambiguous expression (cannot resolve&)!",
N, It.Nam);
Error_Msg_N
("possible interpretation#!", N);
Ambiguous := True;
end if;
Error_Msg_Sloc := Sloc (It.Nam);
Error_Msg_N ("possible interpretation#!", N);
-- Disambiguation has succeeded. Skip the remaining
-- interpretations.
else
Seen := It1.Nam;
Expr_Type := It1.Typ;
while Present (It.Typ) loop
Get_Next_Interp (I, It);
end loop;
end if;
end if;
-- We have a matching interpretation, Expr_Type is the
-- type from this interpretation, and Seen is the entity.
-- For an operator, just set the entity name. The type will
-- be set by the specific operator resolution routine.
if Nkind (N) in N_Op then
Set_Entity (N, Seen);
Generate_Reference (Seen, N);
elsif Nkind (N) = N_Character_Literal then
Set_Etype (N, Expr_Type);
-- For an explicit dereference, attribute reference, range,
-- short-circuit form (which is not an operator node),
-- or a call with a name that is an explicit dereference,
-- there is nothing to be done at this point.
elsif Nkind (N) = N_Explicit_Dereference
or else Nkind (N) = N_Attribute_Reference
or else Nkind (N) = N_And_Then
or else Nkind (N) = N_Indexed_Component
or else Nkind (N) = N_Or_Else
or else Nkind (N) = N_Range
or else Nkind (N) = N_Selected_Component
or else Nkind (N) = N_Slice
or else Nkind (Name (N)) = N_Explicit_Dereference
then
null;
-- For procedure or function calls, set the type of the
-- name, and also the entity pointer for the prefix
elsif (Nkind (N) = N_Procedure_Call_Statement
or else Nkind (N) = N_Function_Call)
and then (Is_Entity_Name (Name (N))
or else Nkind (Name (N)) = N_Operator_Symbol)
then
Set_Etype (Name (N), Expr_Type);
Set_Entity (Name (N), Seen);
Generate_Reference (Seen, Name (N));
elsif Nkind (N) = N_Function_Call
and then Nkind (Name (N)) = N_Selected_Component
then
Set_Etype (Name (N), Expr_Type);
Set_Entity (Selector_Name (Name (N)), Seen);
Generate_Reference (Seen, Selector_Name (Name (N)));
-- For all other cases, just set the type of the Name
else
Set_Etype (Name (N), Expr_Type);
end if;
-- Here if interpetation is incompatible with context type
else
if Debug_Flag_V then
Write_Str (" intepretation incompatible with context");
Write_Eol;
end if;
end if;
-- Move to next interpretation
exit Interp_Loop when not Present (It.Typ);
Get_Next_Interp (I, It);
end loop Interp_Loop;
end if;
-- At this stage Found indicates whether or not an acceptable
-- interpretation exists. If not, then we have an error, except
-- that if the context is Any_Type as a result of some other error,
-- then we suppress the error report.
if not Found then
if Typ /= Any_Type then
-- If type we are looking for is Void, then this is the
-- procedure call case, and the error is simply that what
-- we gave is not a procedure name (we think of procedure
-- calls as expressions with types internally, but the user
-- doesn't think of them this way!)
if Typ = Standard_Void_Type then
Error_Msg_N ("expect procedure name in procedure call", N);
Found := True;
-- Otherwise we do have a subexpression with the wrong type
-- Check for the case of an allocator which uses an access
-- type instead of the designated type. This is a common
-- error and we specialize the message, posting an error
-- on the operand of the allocator, complaining that we
-- expected the designated type of the allocator.
elsif Nkind (N) = N_Allocator
and then Ekind (Typ) in Access_Kind
and then Ekind (Etype (N)) in Access_Kind
and then Designated_Type (Etype (N)) = Typ
then
Wrong_Type (Expression (N), Designated_Type (Typ));
Found := True;
-- Check for an aggregate. Sometimes we can get bogus
-- aggregates from misuse of parentheses, and we are
-- about to complain about the aggregate without even
-- looking inside it.
-- Instead, if we have an aggregate of type Any_Composite,
-- then analyze and resolve the component fields, and then
-- only issue another message if we get no errors doing
-- this (otherwise assume that the errors in the aggregate
-- caused the problem).
elsif Nkind (N) = N_Aggregate
and then Etype (N) = Any_Composite
then
-- Disable expansion in any case. If there is a type mismatch
-- it may be fatal to try to expand the aggregate. The flag
-- would otherwise be set to false when the error is posted.
Expander_Active := False;
declare
procedure Check_Aggr (Aggr : Node_Id);
-- Check one aggregate, and set Found to True if we
-- have a definite error in any of its elements
procedure Check_Elmt (Aelmt : Node_Id);
-- Check one element of aggregate and set Found to
-- True if we definitely have an error in the element.
procedure Check_Aggr (Aggr : Node_Id) is
Elmt : Node_Id;
begin
if Present (Expressions (Aggr)) then
Elmt := First (Expressions (Aggr));
while Present (Elmt) loop
Check_Elmt (Elmt);
Next (Elmt);
end loop;
end if;
if Present (Component_Associations (Aggr)) then
Elmt := First (Component_Associations (Aggr));
while Present (Elmt) loop
Check_Elmt (Expression (Elmt));
Next (Elmt);
end loop;
end if;
end Check_Aggr;
procedure Check_Elmt (Aelmt : Node_Id) is
begin
-- If we have a nested aggregate, go inside it (to
-- attempt a naked analyze-resolve of the aggregate
-- can cause undesirable cascaded errors). Do not
-- resolve expression if it needs a type from context,
-- as for integer * fixed expression.
if Nkind (Aelmt) = N_Aggregate then
Check_Aggr (Aelmt);
else
Analyze (Aelmt);
if not Is_Overloaded (Aelmt)
and then Etype (Aelmt) /= Any_Fixed
then
Resolve (Aelmt, Etype (Aelmt));
end if;
if Etype (Aelmt) = Any_Type then
Found := True;
end if;
end if;
end Check_Elmt;
begin
Check_Aggr (N);
end;
end if;
-- If an error message was issued already, Found got reset
-- to True, so if it is still False, issue the standard
-- Wrong_Type message.
if not Found then
if Is_Overloaded (N)
and then Nkind (N) = N_Function_Call
then
Error_Msg_Node_2 := Typ;
Error_Msg_NE ("no visible interpretation of&" &
" matches expected type&", N, Name (N));
if All_Errors_Mode then
declare
Index : Interp_Index;
It : Interp;
begin
Error_Msg_N ("\possible interpretations:", N);
Get_First_Interp (Name (N), Index, It);
while Present (It.Nam) loop
Error_Msg_Sloc := Sloc (It.Nam);
Error_Msg_Node_2 := It.Typ;
Error_Msg_NE ("\& declared#, type&",
N, It.Nam);
Get_Next_Interp (Index, It);
end loop;
end;
else
Error_Msg_N ("\use -gnatf for details", N);
end if;
else
Wrong_Type (N, Typ);
end if;
end if;
end if;
Resolution_Failed;
return;
-- Test if we have more than one interpretation for the context
elsif Ambiguous then
Resolution_Failed;
return;
-- Here we have an acceptable interpretation for the context
else
-- A user-defined operator is tranformed into a function call at
-- this point, so that further processing knows that operators are
-- really operators (i.e. are predefined operators). User-defined
-- operators that are intrinsic are just renamings of the predefined
-- ones, and need not be turned into calls either, but if they rename
-- a different operator, we must transform the node accordingly.
-- Instantiations of Unchecked_Conversion are intrinsic but are
-- treated as functions, even if given an operator designator.
if Nkind (N) in N_Op
and then Present (Entity (N))
and then Ekind (Entity (N)) /= E_Operator
then
if not Is_Intrinsic_Subprogram (Entity (N))
or else Is_Generic_Instance (Entity (N))
then
Rewrite_Operator_As_Call (N, Entity (N));
elsif Present (Alias (Entity (N))) then
if Chars (Alias (Entity (N))) in Any_Operator_Name then
Rewrite_Renamed_Operator (N, Alias (Entity (N)));
else
Rewrite_Operator_As_Call (N, Alias (Entity (N)));
end if;
end if;
end if;
-- Propagate type information and normalize tree for various
-- predefined operations. If the context only imposes a class of
-- types, rather than a specific type, propagate the actual type
-- downward.
if Typ = Any_Integer
or else Typ = Any_Boolean
or else Typ = Any_Modular
or else Typ = Any_Real
or else Typ = Any_Discrete
then
Ctx_Type := Expr_Type;
-- Any_Fixed is legal in a real context only if a specific
-- fixed point type is imposed. If Norman Cohen can be
-- confused by this, it deserves a separate message.
if Typ = Any_Real
and then Expr_Type = Any_Fixed
then
Error_Msg_N ("Illegal context for mixed mode operation", N);
Set_Etype (N, Universal_Real);
Ctx_Type := Universal_Real;
end if;
end if;
case N_Subexpr'(Nkind (N)) is
when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
when N_Allocator => Resolve_Allocator (N, Ctx_Type);
when N_And_Then | N_Or_Else
=> Resolve_Short_Circuit (N, Ctx_Type);
when N_Attribute_Reference
=> Resolve_Attribute (N, Ctx_Type);
when N_Character_Literal
=> Resolve_Character_Literal (N, Ctx_Type);
when N_Conditional_Expression
=> Resolve_Conditional_Expression (N, Ctx_Type);
when N_Expanded_Name
=> Resolve_Entity_Name (N, Ctx_Type);
when N_Extension_Aggregate
=> Resolve_Extension_Aggregate (N, Ctx_Type);
when N_Explicit_Dereference
=> Resolve_Explicit_Dereference (N, Ctx_Type);
when N_Function_Call
=> Resolve_Call (N, Ctx_Type);
when N_Identifier
=> Resolve_Entity_Name (N, Ctx_Type);
when N_In | N_Not_In
=> Resolve_Membership_Op (N, Ctx_Type);
when N_Indexed_Component
=> Resolve_Indexed_Component (N, Ctx_Type);
when N_Integer_Literal
=> Resolve_Integer_Literal (N, Ctx_Type);
when N_Null => Resolve_Null (N, Ctx_Type);
when N_Op_And | N_Op_Or | N_Op_Xor
=> Resolve_Logical_Op (N, Ctx_Type);
when N_Op_Eq | N_Op_Ne
=> Resolve_Equality_Op (N, Ctx_Type);
when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
=> Resolve_Comparison_Op (N, Ctx_Type);
when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
N_Op_Divide | N_Op_Mod | N_Op_Rem
=> Resolve_Arithmetic_Op (N, Ctx_Type);
when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
when N_Op_Plus | N_Op_Minus | N_Op_Abs
=> Resolve_Unary_Op (N, Ctx_Type);
when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
when N_Procedure_Call_Statement
=> Resolve_Call (N, Ctx_Type);
when N_Operator_Symbol
=> Resolve_Operator_Symbol (N, Ctx_Type);
when N_Qualified_Expression
=> Resolve_Qualified_Expression (N, Ctx_Type);
when N_Raise_xxx_Error
=> Set_Etype (N, Ctx_Type);
when N_Range => Resolve_Range (N, Ctx_Type);
when N_Real_Literal
=> Resolve_Real_Literal (N, Ctx_Type);
when N_Reference => Resolve_Reference (N, Ctx_Type);
when N_Selected_Component
=> Resolve_Selected_Component (N, Ctx_Type);
when N_Slice => Resolve_Slice (N, Ctx_Type);
when N_String_Literal
=> Resolve_String_Literal (N, Ctx_Type);
when N_Subprogram_Info
=> Resolve_Subprogram_Info (N, Ctx_Type);
when N_Type_Conversion
=> Resolve_Type_Conversion (N, Ctx_Type);
when N_Unchecked_Expression =>
Resolve_Unchecked_Expression (N, Ctx_Type);
when N_Unchecked_Type_Conversion =>
Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
end case;
-- If the subexpression was replaced by a non-subexpression, then
-- all we do is to expand it. The only legitimate case we know of
-- is converting procedure call statement to entry call statements,
-- but there may be others, so at least temporarily, we are making
-- this test general since it was general in previous versions ???
if Nkind (N) not in N_Subexpr then
Debug_A_Exit ("resolving ", N, " (done)");
Expand (N);
return;
end if;
-- The expression is definitely NOT overloaded at this point, so
-- we reset the Is_Overloaded flag to avoid any confusion when
-- reanalyzing the node.
Set_Is_Overloaded (N, False);
-- Freeze expression type, entity if it is a name, and designated
-- type if it is an allocator (RM 13.14(9,10)).
-- Now that the resolution of the type of the node is complete,
-- and we did not detect an error, we can expand this node. We
-- skip the expand call if we are in a default expression, see
-- section "Handling of Default Expressions" in Sem spec.
Debug_A_Exit ("resolving ", N, " (done)");
-- We unconditionally freeze the expression, even if we are in
-- default expression mode (the Freeze_Expression routine tests
-- this flag and only freezes static types if it is set).
Freeze_Expression (N);
Expand (N);
end if;
end Resolve;
-- Version with check(s) suppressed
procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
begin
if Suppress = All_Checks then
declare
Svg : constant Suppress_Record := Scope_Suppress;
begin
Scope_Suppress := (others => True);
Resolve (N, Typ);
Scope_Suppress := Svg;
end;
else
declare
Svg : constant Boolean := Get_Scope_Suppress (Suppress);
begin
Set_Scope_Suppress (Suppress, True);
Resolve (N, Typ);
Set_Scope_Suppress (Suppress, Svg);
end;
end if;
end Resolve;
---------------------
-- Resolve_Actuals --
---------------------
procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
Loc : constant Source_Ptr := Sloc (N);
A : Node_Id;
F : Entity_Id;
A_Typ : Entity_Id;
F_Typ : Entity_Id;
Prev : Node_Id := Empty;
procedure Insert_Default;
-- If the actual is missing in a call, insert in the actuals list
-- an instance of the default expression. The insertion is always
-- a named association.
--------------------
-- Insert_Default --
--------------------
procedure Insert_Default is
Actval : Node_Id;
Assoc : Node_Id;
begin
-- Note that we do a full New_Copy_Tree, so that any associated
-- Itypes are properly copied. This may not be needed any more,
-- but it does no harm as a safety measure! Defaults of a generic
-- formal may be out of bounds of the corresponding actual (see
-- cc1311b) and an additional check may be required.
if Present (Default_Value (F)) then
Actval := New_Copy_Tree (Default_Value (F),
New_Scope => Current_Scope, New_Sloc => Loc);
if Is_Concurrent_Type (Scope (Nam))
and then Has_Discriminants (Scope (Nam))
then
Replace_Actual_Discriminants (N, Actval);
end if;
if Is_Overloadable (Nam)
and then Present (Alias (Nam))
then
if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
and then not Is_Tagged_Type (Etype (F))
then
-- If default is a real literal, do not introduce a
-- conversion whose effect may depend on the run-time
-- size of universal real.
if Nkind (Actval) = N_Real_Literal then
Set_Etype (Actval, Base_Type (Etype (F)));
else
Actval := Unchecked_Convert_To (Etype (F), Actval);
end if;
end if;
if Is_Scalar_Type (Etype (F)) then
Enable_Range_Check (Actval);
end if;
Set_Parent (Actval, N);
Analyze_And_Resolve (Actval, Etype (Actval));
else
Set_Parent (Actval, N);
-- Resolve aggregates with their base type, to avoid scope
-- anomalies: the subtype was first built in the suprogram
-- declaration, and the current call may be nested.
if Nkind (Actval) = N_Aggregate
and then Has_Discriminants (Etype (Actval))
then
Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
else
Analyze_And_Resolve (Actval, Etype (Actval));
end if;
end if;
-- If default is a tag indeterminate function call, propagate
-- tag to obtain proper dispatching.
if Is_Controlling_Formal (F)
and then Nkind (Default_Value (F)) = N_Function_Call
then
Set_Is_Controlling_Actual (Actval);
end if;
else
-- Missing argument in call, nothing to insert.
return;
end if;
-- If the default expression raises constraint error, then just
-- silently replace it with an N_Raise_Constraint_Error node,
-- since we already gave the warning on the subprogram spec.
if Raises_Constraint_Error (Actval) then
Rewrite (Actval,
Make_Raise_Constraint_Error (Loc));
Set_Raises_Constraint_Error (Actval);
Set_Etype (Actval, Etype (F));
end if;
Assoc :=
Make_Parameter_Association (Loc,
Explicit_Actual_Parameter => Actval,
Selector_Name => Make_Identifier (Loc, Chars (F)));
-- Case of insertion is first named actual
if No (Prev) or else
Nkind (Parent (Prev)) /= N_Parameter_Association
then
Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
Set_First_Named_Actual (N, Actval);
if No (Prev) then
if not Present (Parameter_Associations (N)) then
Set_Parameter_Associations (N, New_List (Assoc));
else
Append (Assoc, Parameter_Associations (N));
end if;
else
Insert_After (Prev, Assoc);
end if;
-- Case of insertion is not first named actual
else
Set_Next_Named_Actual
(Assoc, Next_Named_Actual (Parent (Prev)));
Set_Next_Named_Actual (Parent (Prev), Actval);
Append (Assoc, Parameter_Associations (N));
end if;
Mark_Rewrite_Insertion (Assoc);
Mark_Rewrite_Insertion (Actval);
Prev := Actval;
end Insert_Default;
-- Start of processing for Resolve_Actuals
begin
A := First_Actual (N);
F := First_Formal (Nam);
while Present (F) loop
if Present (A)
and then (Nkind (Parent (A)) /= N_Parameter_Association
or else
Chars (Selector_Name (Parent (A))) = Chars (F))
then
-- If the formal is Out or In_Out, do not resolve and expand the
-- conversion, because it is subsequently expanded into explicit
-- temporaries and assignments. However, the object of the
-- conversion can be resolved. An exception is the case of
-- a tagged type conversion with a class-wide actual. In that
-- case we want the tag check to occur and no temporary will
-- will be needed (no representation change can occur) and
-- the parameter is passed by reference, so we go ahead and
-- resolve the type conversion.
if Ekind (F) /= E_In_Parameter
and then Nkind (A) = N_Type_Conversion
and then not Is_Class_Wide_Type (Etype (Expression (A)))
then
if Conversion_OK (A)
or else Valid_Conversion (A, Etype (A), Expression (A))
then
Resolve (Expression (A), Etype (Expression (A)));
end if;
else
Resolve (A, Etype (F));
end if;
A_Typ := Etype (A);
F_Typ := Etype (F);
if Ekind (F) /= E_In_Parameter
and then not Is_OK_Variable_For_Out_Formal (A)
then
-- Specialize error message for protected procedure call
-- within function call of the same protected object.
if Is_Entity_Name (A)
and then Chars (Entity (A)) = Name_uObject
and then Ekind (Current_Scope) = E_Function
and then Convention (Current_Scope) = Convention_Protected
and then Ekind (Nam) /= E_Function
then
Error_Msg_N ("within protected function, protected " &
"object is constant", A);
Error_Msg_N ("\cannot call operation that may modify it", A);
else
Error_Msg_NE ("actual for& must be a variable", A, F);
end if;
end if;
if Ekind (F) /= E_Out_Parameter then
Check_Unset_Reference (A);
if Ada_83
and then Is_Entity_Name (A)
and then Ekind (Entity (A)) = E_Out_Parameter
then
Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
end if;
end if;
-- Apply appropriate range checks for in, out, and in-out
-- parameters. Out and in-out parameters also need a separate
-- check, if there is a type conversion, to make sure the return
-- value meets the constraints of the variable before the
-- conversion.
-- Gigi looks at the check flag and uses the appropriate types.
-- For now since one flag is used there is an optimization which
-- might not be done in the In Out case since Gigi does not do
-- any analysis. More thought required about this ???
if Ekind (F) = E_In_Parameter
or else Ekind (F) = E_In_Out_Parameter
then
if Is_Scalar_Type (Etype (A)) then
Apply_Scalar_Range_Check (A, F_Typ);
elsif Is_Array_Type (Etype (A)) then
Apply_Length_Check (A, F_Typ);
elsif Is_Record_Type (F_Typ)
and then Has_Discriminants (F_Typ)
and then Is_Constrained (F_Typ)
and then (not Is_Derived_Type (F_Typ)
or else Comes_From_Source (Nam))
then
Apply_Discriminant_Check (A, F_Typ);
elsif Is_Access_Type (F_Typ)
and then Is_Array_Type (Designated_Type (F_Typ))
and then Is_Constrained (Designated_Type (F_Typ))
then
Apply_Length_Check (A, F_Typ);
elsif Is_Access_Type (F_Typ)
and then Has_Discriminants (Designated_Type (F_Typ))
and then Is_Constrained (Designated_Type (F_Typ))
then
Apply_Discriminant_Check (A, F_Typ);
else
Apply_Range_Check (A, F_Typ);
end if;
end if;
if Ekind (F) = E_Out_Parameter
or else Ekind (F) = E_In_Out_Parameter
then
if Nkind (A) = N_Type_Conversion then
if Is_Scalar_Type (A_Typ) then
Apply_Scalar_Range_Check
(Expression (A), Etype (Expression (A)), A_Typ);
else
Apply_Range_Check
(Expression (A), Etype (Expression (A)), A_Typ);
end if;
else
if Is_Scalar_Type (F_Typ) then
Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
elsif Is_Array_Type (F_Typ)
and then Ekind (F) = E_Out_Parameter
then
Apply_Length_Check (A, F_Typ);
else
Apply_Range_Check (A, A_Typ, F_Typ);
end if;
end if;
end if;
-- An actual associated with an access parameter is implicitly
-- converted to the anonymous access type of the formal and
-- must satisfy the legality checks for access conversions.
if Ekind (F_Typ) = E_Anonymous_Access_Type then
if not Valid_Conversion (A, F_Typ, A) then
Error_Msg_N
("invalid implicit conversion for access parameter", A);
end if;
end if;
-- Check bad case of atomic/volatile argument (RM C.6(12))
if Is_By_Reference_Type (Etype (F))
and then Comes_From_Source (N)
then
if Is_Atomic_Object (A)
and then not Is_Atomic (Etype (F))
then
Error_Msg_N
("cannot pass atomic argument to non-atomic formal",
N);
elsif Is_Volatile_Object (A)
and then not Is_Volatile (Etype (F))
then
Error_Msg_N
("cannot pass volatile argument to non-volatile formal",
N);
end if;
end if;
-- Check that subprograms don't have improper controlling
-- arguments (RM 3.9.2 (9))
if Is_Controlling_Formal (F) then
Set_Is_Controlling_Actual (A);
elsif Nkind (A) = N_Explicit_Dereference then
Validate_Remote_Access_To_Class_Wide_Type (A);
end if;
if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
and then not Is_Class_Wide_Type (F_Typ)
and then not Is_Controlling_Formal (F)
then
Error_Msg_N ("class-wide argument not allowed here!", A);
if Is_Subprogram (Nam) then
Error_Msg_Node_2 := F_Typ;
Error_Msg_NE
("& is not a primitive operation of &!", A, Nam);
end if;
elsif Is_Access_Type (A_Typ)
and then Is_Access_Type (F_Typ)
and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
or else (Nkind (A) = N_Attribute_Reference
and then Is_Class_Wide_Type (Etype (Prefix (A)))))
and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
and then not Is_Controlling_Formal (F)
then
Error_Msg_N
("access to class-wide argument not allowed here!", A);
if Is_Subprogram (Nam) then
Error_Msg_Node_2 := Designated_Type (F_Typ);
Error_Msg_NE
("& is not a primitive operation of &!", A, Nam);
end if;
end if;
Eval_Actual (A);
-- If it is a named association, treat the selector_name as
-- a proper identifier, and mark the corresponding entity.
if Nkind (Parent (A)) = N_Parameter_Association then
Set_Entity (Selector_Name (Parent (A)), F);
Generate_Reference (F, Selector_Name (Parent (A)));
Set_Etype (Selector_Name (Parent (A)), F_Typ);
Generate_Reference (F_Typ, N, ' ');
end if;
Prev := A;
Next_Actual (A);
else
Insert_Default;
end if;
Next_Formal (F);
end loop;
end Resolve_Actuals;
-----------------------
-- Resolve_Allocator --
-----------------------
procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
E : constant Node_Id := Expression (N);
Subtyp : Entity_Id;
Discrim : Entity_Id;
Constr : Node_Id;
Disc_Exp : Node_Id;
begin
-- Replace general access with specific type
if Ekind (Etype (N)) = E_Allocator_Type then
Set_Etype (N, Base_Type (Typ));
end if;
if Is_Abstract (Typ) then
Error_Msg_N ("type of allocator cannot be abstract", N);
end if;
-- For qualified expression, resolve the expression using the
-- given subtype (nothing to do for type mark, subtype indication)
if Nkind (E) = N_Qualified_Expression then
if Is_Class_Wide_Type (Etype (E))
and then not Is_Class_Wide_Type (Designated_Type (Typ))
then
Error_Msg_N
("class-wide allocator not allowed for this access type", N);
end if;
Resolve (Expression (E), Etype (E));
Check_Unset_Reference (Expression (E));
-- For a subtype mark or subtype indication, freeze the subtype
else
Freeze_Expression (E);
if Is_Access_Constant (Typ) and then not No_Initialization (N) then
Error_Msg_N
("initialization required for access-to-constant allocator", N);
end if;
-- A special accessibility check is needed for allocators that
-- constrain access discriminants. The level of the type of the
-- expression used to contrain an access discriminant cannot be
-- deeper than the type of the allocator (in constrast to access
-- parameters, where the level of the actual can be arbitrary).
-- We can't use Valid_Conversion to perform this check because
-- in general the type of the allocator is unrelated to the type
-- of the access discriminant. Note that specialized checks are
-- needed for the cases of a constraint expression which is an
-- access attribute or an access discriminant.
if Nkind (Original_Node (E)) = N_Subtype_Indication
and then Ekind (Typ) /= E_Anonymous_Access_Type
then
Subtyp := Entity (Subtype_Mark (Original_Node (E)));
if Has_Discriminants (Subtyp) then
Discrim := First_Discriminant (Base_Type (Subtyp));
Constr := First (Constraints (Constraint (Original_Node (E))));
while Present (Discrim) and then Present (Constr) loop
if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
if Nkind (Constr) = N_Discriminant_Association then
Disc_Exp := Original_Node (Expression (Constr));
else
Disc_Exp := Original_Node (Constr);
end if;
if Type_Access_Level (Etype (Disc_Exp))
> Type_Access_Level (Typ)
then
Error_Msg_N
("operand type has deeper level than allocator type",
Disc_Exp);
elsif Nkind (Disc_Exp) = N_Attribute_Reference
and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
= Attribute_Access
and then Object_Access_Level (Prefix (Disc_Exp))
> Type_Access_Level (Typ)
then
Error_Msg_N
("prefix of attribute has deeper level than"
& " allocator type", Disc_Exp);
-- When the operand is an access discriminant the check
-- is against the level of the prefix object.
elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
and then Nkind (Disc_Exp) = N_Selected_Component
and then Object_Access_Level (Prefix (Disc_Exp))
> Type_Access_Level (Typ)
then
Error_Msg_N
("access discriminant has deeper level than"
& " allocator type", Disc_Exp);
end if;
end if;
Next_Discriminant (Discrim);
Next (Constr);
end loop;
end if;
end if;
end if;
-- Check for allocation from an empty storage pool
if No_Pool_Assigned (Typ) then
declare
Loc : constant Source_Ptr := Sloc (N);
begin
Error_Msg_N ("?allocation from empty storage pool!", N);
Error_Msg_N ("?Storage_Error will be raised at run time!", N);
Insert_Action (N,
Make_Raise_Storage_Error (Loc));
end;
end if;
end Resolve_Allocator;
---------------------------
-- Resolve_Arithmetic_Op --
---------------------------
-- Used for resolving all arithmetic operators except exponentiation
procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
T : Entity_Id;
TL : Entity_Id := Base_Type (Etype (L));
TR : Entity_Id := Base_Type (Etype (R));
B_Typ : constant Entity_Id := Base_Type (Typ);
-- We do the resolution using the base type, because intermediate values
-- in expressions always are of the base type, not a subtype of it.
function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
-- Return True iff given type is Integer or universal real/integer
procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
-- Choose type of integer literal in fixed-point operation to conform
-- to available fixed-point type. T is the type of the other operand,
-- which is needed to determine the expected type of N.
procedure Set_Operand_Type (N : Node_Id);
-- Set operand type to T if universal
function Universal_Interpretation (N : Node_Id) return Entity_Id;
-- Find universal type of operand, if any.
-----------------------------
-- Is_Integer_Or_Universal --
-----------------------------
function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
T : Entity_Id;
Index : Interp_Index;
It : Interp;
begin
if not Is_Overloaded (N) then
T := Etype (N);
return Base_Type (T) = Base_Type (Standard_Integer)
or else T = Universal_Integer
or else T = Universal_Real;
else
Get_First_Interp (N, Index, It);
while Present (It.Typ) loop
if Base_Type (It.Typ) = Base_Type (Standard_Integer)
or else It.Typ = Universal_Integer
or else It.Typ = Universal_Real
then
return True;
end if;
Get_Next_Interp (Index, It);
end loop;
end if;
return False;
end Is_Integer_Or_Universal;
----------------------------
-- Set_Mixed_Mode_Operand --
----------------------------
procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
Index : Interp_Index;
It : Interp;
begin
if Universal_Interpretation (N) = Universal_Integer then
-- A universal integer literal is resolved as standard integer
-- except in the case of a fixed-point result, where we leave
-- it as universal (to be handled by Exp_Fixd later on)
if Is_Fixed_Point_Type (T) then
Resolve (N, Universal_Integer);
else
Resolve (N, Standard_Integer);
end if;
elsif Universal_Interpretation (N) = Universal_Real
and then (T = Base_Type (Standard_Integer)
or else T = Universal_Integer
or else T = Universal_Real)
then
-- A universal real can appear in a fixed-type context. We resolve
-- the literal with that context, even though this might raise an
-- exception prematurely (the other operand may be zero).
Resolve (N, B_Typ);
elsif Etype (N) = Base_Type (Standard_Integer)
and then T = Universal_Real
and then Is_Overloaded (N)
then
-- Integer arg in mixed-mode operation. Resolve with universal
-- type, in case preference rule must be applied.
Resolve (N, Universal_Integer);
elsif Etype (N) = T
and then B_Typ /= Universal_Fixed
then
-- Not a mixed-mode operation. Resolve with context.
Resolve (N, B_Typ);
elsif Etype (N) = Any_Fixed then
-- N may itself be a mixed-mode operation, so use context type.
Resolve (N, B_Typ);
elsif Is_Fixed_Point_Type (T)
and then B_Typ = Universal_Fixed
and then Is_Overloaded (N)
then
-- Must be (fixed * fixed) operation, operand must have one
-- compatible interpretation.
Resolve (N, Any_Fixed);
elsif Is_Fixed_Point_Type (B_Typ)
and then (T = Universal_Real
or else Is_Fixed_Point_Type (T))
and then Is_Overloaded (N)
then
-- C * F(X) in a fixed context, where C is a real literal or a
-- fixed-point expression. F must have either a fixed type
-- interpretation or an integer interpretation, but not both.
Get_First_Interp (N, Index, It);
while Present (It.Typ) loop
if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
if Analyzed (N) then
Error_Msg_N ("ambiguous operand in fixed operation", N);
else
Resolve (N, Standard_Integer);
end if;
elsif Is_Fixed_Point_Type (It.Typ) then
if Analyzed (N) then
Error_Msg_N ("ambiguous operand in fixed operation", N);
else
Resolve (N, It.Typ);
end if;
end if;
Get_Next_Interp (Index, It);
end loop;
-- Reanalyze the literal with the fixed type of the context.
if N = L then
Set_Analyzed (R, False);
Resolve (R, B_Typ);
else
Set_Analyzed (L, False);
Resolve (L, B_Typ);
end if;
else
Resolve (N, Etype (N));
end if;
end Set_Mixed_Mode_Operand;
----------------------
-- Set_Operand_Type --
----------------------
procedure Set_Operand_Type (N : Node_Id) is
begin
if Etype (N) = Universal_Integer
or else Etype (N) = Universal_Real
then
Set_Etype (N, T);
end if;
end Set_Operand_Type;
------------------------------
-- Universal_Interpretation --
------------------------------
function Universal_Interpretation (N : Node_Id) return Entity_Id is
Index : Interp_Index;
It : Interp;
begin
if not Is_Overloaded (N) then
if Etype (N) = Universal_Integer
or else Etype (N) = Universal_Real
then
return Etype (N);
else
return Empty;
end if;
else
Get_First_Interp (N, Index, It);
while Present (It.Typ) loop
if It.Typ = Universal_Integer
or else It.Typ = Universal_Real
then
return It.Typ;
end if;
Get_Next_Interp (Index, It);
end loop;
return Empty;
end if;
end Universal_Interpretation;
-- Start of processing for Resolve_Arithmetic_Op
begin
if Comes_From_Source (N)
and then Ekind (Entity (N)) = E_Function
and then Is_Imported (Entity (N))
and then Present (First_Rep_Item (Entity (N)))
then
Resolve_Intrinsic_Operator (N, Typ);
return;
-- Special-case for mixed-mode universal expressions or fixed point
-- type operation: each argument is resolved separately. The same
-- treatment is required if one of the operands of a fixed point
-- operation is universal real, since in this case we don't do a
-- conversion to a specific fixed-point type (instead the expander
-- takes care of the case).
elsif (B_Typ = Universal_Integer
or else B_Typ = Universal_Real)
and then Present (Universal_Interpretation (L))
and then Present (Universal_Interpretation (R))
then
Resolve (L, Universal_Interpretation (L));
Resolve (R, Universal_Interpretation (R));
Set_Etype (N, B_Typ);
elsif (B_Typ = Universal_Real
or else Etype (N) = Universal_Fixed
or else (Etype (N) = Any_Fixed
and then Is_Fixed_Point_Type (B_Typ))
or else (Is_Fixed_Point_Type (B_Typ)
and then (Is_Integer_Or_Universal (L)
or else
Is_Integer_Or_Universal (R))))
and then (Nkind (N) = N_Op_Multiply or else
Nkind (N) = N_Op_Divide)
then
if TL = Universal_Integer or else TR = Universal_Integer then
Check_For_Visible_Operator (N, B_Typ);
end if;
-- If context is a fixed type and one operand is integer, the
-- other is resolved with the type of the context.
if Is_Fixed_Point_Type (B_Typ)
and then (Base_Type (TL) = Base_Type (Standard_Integer)
or else TL = Universal_Integer)
then
Resolve (R, B_Typ);
Resolve (L, TL);
elsif Is_Fixed_Point_Type (B_Typ)
and then (Base_Type (TR) = Base_Type (Standard_Integer)
or else TR = Universal_Integer)
then
Resolve (L, B_Typ);
Resolve (R, TR);
else
Set_Mixed_Mode_Operand (L, TR);
Set_Mixed_Mode_Operand (R, TL);
end if;
if Etype (N) = Universal_Fixed
or else Etype (N) = Any_Fixed
then
if B_Typ = Universal_Fixed
and then Nkind (Parent (N)) /= N_Type_Conversion
and then Nkind (Parent (N)) /= N_Unchecked_Type_Conversion
then
Error_Msg_N
("type cannot be determined from context!", N);
Error_Msg_N
("\explicit conversion to result type required", N);
Set_Etype (L, Any_Type);
Set_Etype (R, Any_Type);
else
if Ada_83
and then Etype (N) = Universal_Fixed
and then Nkind (Parent (N)) /= N_Type_Conversion
and then Nkind (Parent (N)) /= N_Unchecked_Type_Conversion
then
Error_Msg_N
("(Ada 83) fixed-point operation " &
"needs explicit conversion",
N);
end if;
Set_Etype (N, B_Typ);
end if;
elsif Is_Fixed_Point_Type (B_Typ)
and then (Is_Integer_Or_Universal (L)
or else Nkind (L) = N_Real_Literal
or else Nkind (R) = N_Real_Literal
or else
Is_Integer_Or_Universal (R))
then
Set_Etype (N, B_Typ);
elsif Etype (N) = Any_Fixed then
-- If no previous errors, this is only possible if one operand
-- is overloaded and the context is universal. Resolve as such.
Set_Etype (N, B_Typ);
end if;
else
if (TL = Universal_Integer or else TL = Universal_Real)
and then (TR = Universal_Integer or else TR = Universal_Real)
then
Check_For_Visible_Operator (N, B_Typ);
end if;
-- If the context is Universal_Fixed and the operands are also
-- universal fixed, this is an error, unless there is only one
-- applicable fixed_point type (usually duration).
if B_Typ = Universal_Fixed
and then Etype (L) = Universal_Fixed
then
T := Unique_Fixed_Point_Type (N);
if T = Any_Type then
Set_Etype (N, T);
return;
else
Resolve (L, T);
Resolve (R, T);
end if;
else
Resolve (L, B_Typ);
Resolve (R, B_Typ);
end if;
-- If one of the arguments was resolved to a non-universal type.
-- label the result of the operation itself with the same type.
-- Do the same for the universal argument, if any.
T := Intersect_Types (L, R);
Set_Etype (N, Base_Type (T));
Set_Operand_Type (L);
Set_Operand_Type (R);
end if;
Generate_Operator_Reference (N);
Eval_Arithmetic_Op (N);
-- Set overflow checking bit. Much cleverer code needed here eventually
-- and perhaps the Resolve routines should be separated for the various
-- arithmetic operations, since they will need different processing. ???
if Nkind (N) in N_Op then
if not Overflow_Checks_Suppressed (Etype (N)) then
Set_Do_Overflow_Check (N);
end if;
end if;
Check_Unset_Reference (L);
Check_Unset_Reference (R);
end Resolve_Arithmetic_Op;
------------------
-- Resolve_Call --
------------------
procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
Loc : constant Source_Ptr := Sloc (N);
Subp : constant Node_Id := Name (N);
Nam : Entity_Id;
I : Interp_Index;
It : Interp;
Norm_OK : Boolean;
Scop : Entity_Id;
function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
-- Utility to check whether the name in the call is a predefined
-- operator, in which case the call is made into an operator node.
-- An instance of an intrinsic conversion operation may be given
-- an operator name, but is not treated like an operator.
function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
begin
return Is_Intrinsic_Subprogram (Nam)
and then not Is_Generic_Instance (Nam)
and then Chars (Nam) in Any_Operator_Name;
end Is_Predefined_Op;
-- Start of processing for Resolve_Call
begin
-- The context imposes a unique interpretation with type Typ on
-- a procedure or function call. Find the entity of the subprogram
-- that yields the expected type, and propagate the corresponding
-- formal constraints on the actuals. The caller has established
-- that an interpretation exists, and emitted an error if not unique.
-- First deal with the case of a call to an access-to-subprogram,
-- dereference made explicit in Analyze_Call.
if Ekind (Etype (Subp)) = E_Subprogram_Type then
if not Is_Overloaded (Subp) then
Nam := Etype (Subp);
else
-- Find the interpretation whose type (a subprogram type)
-- has a return type that is compatible with the context.
Get_First_Interp (Subp, I, It);
while Present (It.Typ) loop
if Covers (Typ, Etype (It.Typ)) then
Nam := It.Typ;
exit;
end if;
Get_Next_Interp (I, It);
end loop;
end if;
-- If the prefix is not an entity, then resolve it
if not Is_Entity_Name (Subp) then
Resolve (Subp, Nam);
end if;
-- If this is a procedure call which is really an entry call, do
-- the conversion of the procedure call to an entry call. Protected
-- operations use the same circuitry because the name in the call
-- can be an arbitrary expression with special resolution rules.
elsif Nkind (Subp) = N_Selected_Component
or else Nkind (Subp) = N_Indexed_Component
or else (Is_Entity_Name (Subp)
and then Ekind (Entity (Subp)) = E_Entry)
then
Resolve_Entry_Call (N, Typ);
Check_Elab_Call (N);
return;
-- Normal subprogram call with name established in Resolve
elsif not (Is_Type (Entity (Subp))) then
Nam := Entity (Subp);
Set_Entity_With_Style_Check (Subp, Nam);
Generate_Reference (Nam, Subp);
-- Otherwise we must have the case of an overloaded call
else
pragma Assert (Is_Overloaded (Subp));
Get_First_Interp (Subp, I, It);
while Present (It.Typ) loop
if Covers (Typ, It.Typ) then
Nam := It.Nam;
Set_Entity_With_Style_Check (Subp, Nam);
Generate_Reference (Nam, Subp);
exit;
end if;
Get_Next_Interp (I, It);
end loop;
end if;
-- Check that a call to Current_Task does not occur in an entry body
if Is_RTE (Nam, RE_Current_Task) then
declare
P : Node_Id;
begin
P := N;
loop
P := Parent (P);
exit when No (P);
if Nkind (P) = N_Entry_Body then
Error_Msg_NE
("& should not be used in entry body ('R'M C.7(17))",
N, Nam);
exit;
end if;
end loop;
end;
end if;
-- Check that a procedure call does not occur in the context
-- of the entry call statement of a conditional or timed
-- entry call. Note that the case of a call to a subprogram
-- renaming of an entry will also be rejected. The test
-- for N not being an N_Entry_Call_Statement is defensive,
-- covering the possibility that the processing of entry
-- calls might reach this point due to later modifications
-- of the code above.
if Nkind (Parent (N)) = N_Entry_Call_Alternative
and then Nkind (N) /= N_Entry_Call_Statement
and then Entry_Call_Statement (Parent (N)) = N
then
Error_Msg_N ("entry call required in select statement", N);
end if;
-- Freeze the subprogram name if not in default expression. Note
-- that we freeze procedure calls as well as function calls.
-- Procedure calls are not frozen according to the rules (RM
-- 13.14(14)) because it is impossible to have a procedure call to
-- a non-frozen procedure in pure Ada, but in the code that we
-- generate in the expander, this rule needs extending because we
-- can generate procedure calls that need freezing.
if Is_Entity_Name (Subp) and then not In_Default_Expression then
Freeze_Expression (Subp);
end if;
-- For a predefined operator, the type of the result is the type
-- imposed by context, except for a predefined operation on universal
-- fixed. Otherwise The type of the call is the type returned by the
-- subprogram being called.
if Is_Predefined_Op (Nam) then
if Etype (N) /= Universal_Fixed then
Set_Etype (N, Typ);
end if;
-- If the subprogram returns an array type, and the context
-- requires the component type of that array type, the node is
-- really an indexing of the parameterless call. Resolve as such.
elsif Needs_No_Actuals (Nam)
and then
((Is_Array_Type (Etype (Nam))
and then Covers (Typ, Component_Type (Etype (Nam))))
or else (Is_Access_Type (Etype (Nam))
and then Is_Array_Type (Designated_Type (Etype (Nam)))
and then
Covers (Typ,
Component_Type (Designated_Type (Etype (Nam))))))
then
declare
Index_Node : Node_Id;
begin
Check_Elab_Call (N);
if Component_Type (Etype (Nam)) /= Any_Type then
Index_Node :=
Make_Indexed_Component (Loc,
Prefix =>
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Nam, Loc)),
Expressions => Parameter_Associations (N));
-- Since we are correcting a node classification error made by
-- the parser, we call Replace rather than Rewrite.
Replace (N, Index_Node);
Set_Etype (Prefix (N), Etype (Nam));
Set_Etype (N, Typ);
Resolve_Indexed_Component (N, Typ);
end if;
return;
end;
else
Set_Etype (N, Etype (Nam));
end if;
-- In the case where the call is to an overloaded subprogram, Analyze
-- calls Normalize_Actuals once per overloaded subprogram. Therefore in
-- such a case Normalize_Actuals needs to be called once more to order
-- the actuals correctly. Otherwise the call will have the ordering
-- given by the last overloaded subprogram whether this is the correct
-- one being called or not.
if Is_Overloaded (Subp) then
Normalize_Actuals (N, Nam, False, Norm_OK);
pragma Assert (Norm_OK);
end if;
-- In any case, call is fully resolved now. Reset Overload flag, to
-- prevent subsequent overload resolution if node is analyzed again
Set_Is_Overloaded (Subp, False);
Set_Is_Overloaded (N, False);
-- If we are calling the current subprogram from immediately within
-- its body, then that is the case where we can sometimes detect
-- cases of infinite recursion statically. Do not try this in case
-- restriction No_Recursion is in effect anyway.
Scop := Current_Scope;
if Nam = Scop
and then not Restrictions (No_Recursion)
and then Check_Infinite_Recursion (N)
then
-- Here we detected and flagged an infinite recursion, so we do
-- not need to test the case below for further warnings.
null;
-- If call is to immediately containing subprogram, then check for
-- the case of a possible run-time detectable infinite recursion.
else
while Scop /= Standard_Standard loop
if Nam = Scop then
-- Although in general recursion is not statically checkable,
-- the case of calling an immediately containing subprogram
-- is easy to catch.
Check_Restriction (No_Recursion, N);
-- If the recursive call is to a parameterless procedure, then
-- even if we can't statically detect infinite recursion, this
-- is pretty suspicious, and we output a warning. Furthermore,
-- we will try later to detect some cases here at run time by
-- expanding checking code (see Detect_Infinite_Recursion in
-- package Exp_Ch6).
-- If the recursive call is within a handler we do not emit a
-- warning, because this is a common idiom: loop until input
-- is correct, catch illegal input in handler and restart.
if No (First_Formal (Nam))
and then Etype (Nam) = Standard_Void_Type
and then not Error_Posted (N)
and then Nkind (Parent (N)) /= N_Exception_Handler
then
Set_Has_Recursive_Call (Nam);
Error_Msg_N ("possible infinite recursion?", N);
Error_Msg_N ("Storage_Error may be raised at run time?", N);
end if;
exit;
end if;
Scop := Scope (Scop);
end loop;
end if;
-- If subprogram name is a predefined operator, it was given in
-- functional notation. Replace call node with operator node, so
-- that actuals can be resolved appropriately.
if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
return;
elsif Present (Alias (Nam))
and then Is_Predefined_Op (Alias (Nam))
then
Resolve_Actuals (N, Nam);
Make_Call_Into_Operator (N, Typ, Alias (Nam));
return;
end if;
-- Create a transient scope if the resulting type requires it.
-- There are 3 notable exceptions: in init_procs, the transient scope
-- overhead is not needed and even incorrect due to the actual expansion
-- of adjust calls; the second case is enumeration literal pseudo calls,
-- the other case is unchecked_conversion.
-- If this is an initialization call for a type whose initialization
-- uses the secondary stack, we also need to create a transient scope
-- for it, precisely because we will not do it within the init_proc
-- itself.
if Expander_Active
and then Is_Type (Etype (Nam))
and then Requires_Transient_Scope (Etype (Nam))
and then Ekind (Nam) /= E_Enumeration_Literal
and then not Within_Init_Proc
and then not (Is_Intrinsic_Subprogram (Nam)
and then Present (Parent (Nam))
and then Present (Generic_Parent (Parent (Nam)))
and then Chars (Generic_Parent (Parent (Nam))) =
Name_Unchecked_Conversion)
then
Establish_Transient_Scope
(N, Sec_Stack => not Functions_Return_By_DSP_On_Target);
elsif Chars (Nam) = Name_uInit_Proc
and then not Within_Init_Proc
then
Check_Initialization_Call (N, Nam);
end if;
-- A protected function cannot be called within the definition of the
-- enclosing protected type.
if Is_Protected_Type (Scope (Nam))
and then In_Open_Scopes (Scope (Nam))
and then not Has_Completion (Scope (Nam))
then
Error_Msg_NE
("& cannot be called before end of protected definition", N, Nam);
end if;
-- Propagate interpretation to actuals, and add default expressions
-- where needed.
if Present (First_Formal (Nam)) then
Resolve_Actuals (N, Nam);
-- Overloaded literals are rewritten as function calls, for
-- purpose of resolution. After resolution, we can replace
-- the call with the literal itself.
elsif Ekind (Nam) = E_Enumeration_Literal then
Copy_Node (Subp, N);
Resolve_Entity_Name (N, Typ);
-- Avoid validation, since it is a static function call.
return;
end if;
-- If the subprogram is a primitive operation, check whether or not
-- it is a correct dispatching call.
if Is_Overloadable (Nam)
and then Is_Dispatching_Operation (Nam)
then
Check_Dispatching_Call (N);
-- If the subprogram is abstract, check that the call has a
-- controlling argument (i.e. is dispatching) or is disptaching on
-- result
if Is_Abstract (Nam)
and then No (Controlling_Argument (N))
and then not Is_Class_Wide_Type (Typ)
and then not Is_Tag_Indeterminate (N)
then
Error_Msg_N ("call to abstract subprogram must be dispatching", N);
end if;
elsif Is_Abstract (Nam)
and then not In_Instance
then
Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
end if;
if Is_Intrinsic_Subprogram (Nam) then
Check_Intrinsic_Call (N);
end if;
-- If we fall through we definitely have a non-static call
Check_Elab_Call (N);
end Resolve_Call;
-------------------------------
-- Resolve_Character_Literal --
-------------------------------
procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
B_Typ : constant Entity_Id := Base_Type (Typ);
C : Entity_Id;
begin
-- Verify that the character does belong to the type of the context
Set_Etype (N, B_Typ);
Eval_Character_Literal (N);
-- Wide_Character literals must always be defined, since the set of
-- wide character literals is complete, i.e. if a character literal
-- is accepted by the parser, then it is OK for wide character.
if Root_Type (B_Typ) = Standard_Wide_Character then
return;
-- Always accept character literal for type Any_Character, which
-- occurs in error situations and in comparisons of literals, both
-- of which should accept all literals.
elsif B_Typ = Any_Character then
return;
-- For Standard.Character or a type derived from it, check that
-- the literal is in range
elsif Root_Type (B_Typ) = Standard_Character then
if In_Character_Range (Char_Literal_Value (N)) then
return;
end if;
-- If the entity is already set, this has already been resolved in
-- a generic context, or comes from expansion. Nothing else to do.
elsif Present (Entity (N)) then
return;
-- Otherwise we have a user defined character type, and we can use
-- the standard visibility mechanisms to locate the referenced entity
else
C := Current_Entity (N);
while Present (C) loop
if Etype (C) = B_Typ then
Set_Entity_With_Style_Check (N, C);
Generate_Reference (C, N);
return;
end if;
C := Homonym (C);
end loop;
end if;
-- If we fall through, then the literal does not match any of the
-- entries of the enumeration type. This isn't just a constraint
-- error situation, it is an illegality (see RM 4.2).
Error_Msg_NE
("character not defined for }", N, First_Subtype (B_Typ));
end Resolve_Character_Literal;
---------------------------
-- Resolve_Comparison_Op --
---------------------------
-- Context requires a boolean type, and plays no role in resolution.
-- Processing identical to that for equality operators.
procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
T : Entity_Id;
begin
-- If this is an intrinsic operation which is not predefined, use
-- the types of its declared arguments to resolve the possibly
-- overloaded operands. Otherwise the operands are unambiguous and
-- specify the expected type.
if Scope (Entity (N)) /= Standard_Standard then
T := Etype (First_Entity (Entity (N)));
else
T := Find_Unique_Type (L, R);
if T = Any_Fixed then
T := Unique_Fixed_Point_Type (L);
end if;
end if;
Set_Etype (N, Typ);
Generate_Reference (T, N, ' ');
if T /= Any_Type then
if T = Any_String
or else T = Any_Composite
or else T = Any_Character
then
if T = Any_Character then
Ambiguous_Character (L);
else
Error_Msg_N ("ambiguous operands for comparison", N);
end if;
Set_Etype (N, Any_Type);
return;
else
if Comes_From_Source (N)
and then Has_Unchecked_Union (T)
then
Error_Msg_N
("cannot compare Unchecked_Union values", N);
end if;
Resolve (L, T);
Resolve (R, T);
Check_Unset_Reference (L);
Check_Unset_Reference (R);
Generate_Operator_Reference (N);
Eval_Relational_Op (N);
end if;
end if;
end Resolve_Comparison_Op;
------------------------------------
-- Resolve_Conditional_Expression --
------------------------------------
procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
Condition : constant Node_Id := First (Expressions (N));
Then_Expr : constant Node_Id := Next (Condition);
Else_Expr : constant Node_Id := Next (Then_Expr);
begin
Resolve (Condition, Standard_Boolean);
Resolve (Then_Expr, Typ);
Resolve (Else_Expr, Typ);
Set_Etype (N, Typ);
Eval_Conditional_Expression (N);
end Resolve_Conditional_Expression;
-----------------------------------------
-- Resolve_Discrete_Subtype_Indication --
-----------------------------------------
procedure Resolve_Discrete_Subtype_Indication
(N : Node_Id;
Typ : Entity_Id)
is
R : Node_Id;
S : Entity_Id;
begin
Analyze (Subtype_Mark (N));
S := Entity (Subtype_Mark (N));
if Nkind (Constraint (N)) /= N_Range_Constraint then
Error_Msg_N ("expect range constraint for discrete type", N);
Set_Etype (N, Any_Type);
else
R := Range_Expression (Constraint (N));
Analyze (R);
if Base_Type (S) /= Base_Type (Typ) then
Error_Msg_NE
("expect subtype of }", N, First_Subtype (Typ));
-- Rewrite the constraint as a range of Typ
-- to allow compilation to proceed further.
Set_Etype (N, Typ);
Rewrite (Low_Bound (R),
Make_Attribute_Reference (Sloc (Low_Bound (R)),
Prefix => New_Occurrence_Of (Typ, Sloc (R)),
Attribute_Name => Name_First));
Rewrite (High_Bound (R),
Make_Attribute_Reference (Sloc (High_Bound (R)),
Prefix => New_Occurrence_Of (Typ, Sloc (R)),
Attribute_Name => Name_First));
else
Resolve (R, Typ);
Set_Etype (N, Etype (R));
-- Additionally, we must check that the bounds are compatible
-- with the given subtype, which might be different from the
-- type of the context.
Apply_Range_Check (R, S);
-- ??? If the above check statically detects a Constraint_Error
-- it replaces the offending bound(s) of the range R with a
-- Constraint_Error node. When the itype which uses these bounds
-- is frozen the resulting call to Duplicate_Subexpr generates
-- a new temporary for the bounds.
-- Unfortunately there are other itypes that are also made depend
-- on these bounds, so when Duplicate_Subexpr is called they get
-- a forward reference to the newly created temporaries and Gigi
-- aborts on such forward references. This is probably sign of a
-- more fundamental problem somewhere else in either the order of
-- itype freezing or the way certain itypes are constructed.
-- To get around this problem we call Remove_Side_Effects right
-- away if either bounds of R are a Constraint_Error.
declare
L : Node_Id := Low_Bound (R);
H : Node_Id := High_Bound (R);
begin
if Nkind (L) = N_Raise_Constraint_Error then
Remove_Side_Effects (L);
end if;
if Nkind (H) = N_Raise_Constraint_Error then
Remove_Side_Effects (H);
end if;
end;
Check_Unset_Reference (Low_Bound (R));
Check_Unset_Reference (High_Bound (R));
end if;
end if;
end Resolve_Discrete_Subtype_Indication;
-------------------------
-- Resolve_Entity_Name --
-------------------------
-- Used to resolve identifiers and expanded names
procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
E : constant Entity_Id := Entity (N);
begin
-- Replace named numbers by corresponding literals. Note that this is
-- the one case where Resolve_Entity_Name must reset the Etype, since
-- it is currently marked as universal.
if Ekind (E) = E_Named_Integer then
Set_Etype (N, Typ);
Eval_Named_Integer (N);
elsif Ekind (E) = E_Named_Real then
Set_Etype (N, Typ);
Eval_Named_Real (N);
-- Allow use of subtype only if it is a concurrent type where we are
-- currently inside the body. This will eventually be expanded
-- into a call to Self (for tasks) or _object (for protected
-- objects). Any other use of a subtype is invalid.
elsif Is_Type (E) then
if Is_Concurrent_Type (E)
and then In_Open_Scopes (E)
then
null;
else
Error_Msg_N
("Invalid use of subtype mark in expression or call", N);
end if;
-- Check discriminant use if entity is discriminant in current scope,
-- i.e. discriminant of record or concurrent type currently being
-- analyzed. Uses in corresponding body are unrestricted.
elsif Ekind (E) = E_Discriminant
and then Scope (E) = Current_Scope
and then not Has_Completion (Current_Scope)
then
Check_Discriminant_Use (N);
-- A parameterless generic function cannot appear in a context that
-- requires resolution.
elsif Ekind (E) = E_Generic_Function then
Error_Msg_N ("illegal use of generic function", N);
elsif Ekind (E) = E_Out_Parameter
and then Ada_83
and then (Nkind (Parent (N)) in N_Op
or else (Nkind (Parent (N)) = N_Assignment_Statement
and then N = Expression (Parent (N)))
or else Nkind (Parent (N)) = N_Explicit_Dereference)
then
Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
-- In all other cases, just do the possible static evaluation
else
-- A deferred constant that appears in an expression must have
-- a completion, unless it has been removed by in-place expansion
-- of an aggregate.
if Ekind (E) = E_Constant
and then Comes_From_Source (E)
and then No (Constant_Value (E))
and then Is_Frozen (Etype (E))
and then not In_Default_Expression
and then not Is_Imported (E)
then
if No_Initialization (Parent (E))
or else (Present (Full_View (E))
and then No_Initialization (Parent (Full_View (E))))
then
null;
else
Error_Msg_N (
"deferred constant is frozen before completion", N);
end if;
end if;
Eval_Entity_Name (N);
end if;
end Resolve_Entity_Name;
-------------------
-- Resolve_Entry --
-------------------
procedure Resolve_Entry (Entry_Name : Node_Id) is
Loc : constant Source_Ptr := Sloc (Entry_Name);
Nam : Entity_Id;
New_N : Node_Id;
S : Entity_Id;
Tsk : Entity_Id;
E_Name : Node_Id;
Index : Node_Id;
function Actual_Index_Type (E : Entity_Id) return Entity_Id;
-- If the bounds of the entry family being called depend on task
-- discriminants, build a new index subtype where a discriminant is
-- replaced with the the value of the discriminant of the target task.
-- The target task is the prefix of the entry name in the call.
-----------------------
-- Actual_Index_Type --
-----------------------
function Actual_Index_Type (E : Entity_Id) return Entity_Id is
Typ : Entity_Id := Entry_Index_Type (E);
Tsk : Entity_Id := Scope (E);
Lo : Node_Id := Type_Low_Bound (Typ);
Hi : Node_Id := Type_High_Bound (Typ);
New_T : Entity_Id;
function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
-- If the bound is given by a discriminant, replace with a reference
-- to the discriminant of the same name in the target task.
-- If the entry name is the target of a requeue statement and the
-- entry is in the current protected object, the bound to be used
-- is the discriminal of the object (see apply_range_checks for
-- details of the transformation).
-----------------------------
-- Actual_Discriminant_Ref --
-----------------------------
function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
Typ : Entity_Id := Etype (Bound);
Ref : Node_Id;
begin
Remove_Side_Effects (Bound);
if not Is_Entity_Name (Bound)
or else Ekind (Entity (Bound)) /= E_Discriminant
then
return Bound;
elsif Is_Protected_Type (Tsk)
and then In_Open_Scopes (Tsk)
and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
then
return New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
else
Ref :=
Make_Selected_Component (Loc,
Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
Analyze (Ref);
Resolve (Ref, Typ);
return Ref;
end if;
end Actual_Discriminant_Ref;
-- Start of processing for Actual_Index_Type
begin
if not Has_Discriminants (Tsk)
or else (not Is_Entity_Name (Lo)
and then not Is_Entity_Name (Hi))
then
return Entry_Index_Type (E);
else
New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
Set_Etype (New_T, Base_Type (Typ));
Set_Size_Info (New_T, Typ);
Set_RM_Size (New_T, RM_Size (Typ));
Set_Scalar_Range (New_T,
Make_Range (Sloc (Entry_Name),
Low_Bound => Actual_Discriminant_Ref (Lo),
High_Bound => Actual_Discriminant_Ref (Hi)));
return New_T;
end if;
end Actual_Index_Type;
-- Start of processing of Resolve_Entry
begin
-- Find name of entry being called, and resolve prefix of name
-- with its own type. The prefix can be overloaded, and the name
-- and signature of the entry must be taken into account.
if Nkind (Entry_Name) = N_Indexed_Component then
-- Case of dealing with entry family within the current tasks
E_Name := Prefix (Entry_Name);
else
E_Name := Entry_Name;
end if;
if Is_Entity_Name (E_Name) then
-- Entry call to an entry (or entry family) in the current task.
-- This is legal even though the task will deadlock. Rewrite as
-- call to current task.
-- This can also be a call to an entry in an enclosing task.
-- If this is a single task, we have to retrieve its name,
-- because the scope of the entry is the task type, not the
-- object. If the enclosing task is a task type, the identity
-- of the task is given by its own self variable.
-- Finally this can be a requeue on an entry of the same task
-- or protected object.
S := Scope (Entity (E_Name));
for J in reverse 0 .. Scope_Stack.Last loop
if Is_Task_Type (Scope_Stack.Table (J).Entity)
and then not Comes_From_Source (S)
then
-- S is an enclosing task or protected object. The concurrent
-- declaration has been converted into a type declaration, and
-- the object itself has an object declaration that follows
-- the type in the same declarative part.
Tsk := Next_Entity (S);
while Etype (Tsk) /= S loop
Next_Entity (Tsk);
end loop;
S := Tsk;
exit;
elsif S = Scope_Stack.Table (J).Entity then
-- Call to current task. Will be transformed into call to Self
exit;
end if;
end loop;
New_N :=
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (S, Loc),
Selector_Name =>
New_Occurrence_Of (Entity (E_Name), Loc));
Rewrite (E_Name, New_N);
Analyze (E_Name);
elsif Nkind (Entry_Name) = N_Selected_Component
and then Is_Overloaded (Prefix (Entry_Name))
then
-- Use the entry name (which must be unique at this point) to
-- find the prefix that returns the corresponding task type or
-- protected type.
declare
Pref : Node_Id := Prefix (Entry_Name);
I : Interp_Index;
It : Interp;
Ent : Entity_Id := Entity (Selector_Name (Entry_Name));
begin
Get_First_Interp (Pref, I, It);
while Present (It.Typ) loop
if Scope (Ent) = It.Typ then
Set_Etype (Pref, It.Typ);
exit;
end if;
Get_Next_Interp (I, It);
end loop;
end;
end if;
if Nkind (Entry_Name) = N_Selected_Component then
Resolve (Prefix (Entry_Name), Etype (Prefix (Entry_Name)));
elsif Nkind (Entry_Name) = N_Indexed_Component then
Nam := Entity (Selector_Name (Prefix (Entry_Name)));
Resolve (Prefix (Prefix (Entry_Name)),
Etype (Prefix (Prefix (Entry_Name))));
Index := First (Expressions (Entry_Name));
Resolve (Index, Entry_Index_Type (Nam));
-- Up to this point the expression could have been the actual
-- in a simple entry call, and be given by a named association.
if Nkind (Index) = N_Parameter_Association then
Error_Msg_N ("expect expression for entry index", Index);
else
Apply_Range_Check (Index, Actual_Index_Type (Nam));
end if;
else
pragma Assert (False);
raise Program_Error;
end if;
end Resolve_Entry;
------------------------
-- Resolve_Entry_Call --
------------------------
procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
Entry_Name : constant Node_Id := Name (N);
Loc : constant Source_Ptr := Sloc (Entry_Name);
Actuals : List_Id;
First_Named : Node_Id;
Nam : Entity_Id;
Norm_OK : Boolean;
Obj : Node_Id;
Was_Over : Boolean;
begin
-- Processing of the name is similar for entry calls and protected
-- operation calls. Once the entity is determined, we can complete
-- the resolution of the actuals.
-- The selector may be overloaded, in the case of a protected object
-- with overloaded functions. The type of the context is used for
-- resolution.
if Nkind (Entry_Name) = N_Selected_Component
and then Is_Overloaded (Selector_Name (Entry_Name))
and then Typ /= Standard_Void_Type
then
declare
I : Interp_Index;
It : Interp;
begin
Get_First_Interp (Selector_Name (Entry_Name), I, It);
while Present (It.Typ) loop
if Covers (Typ, It.Typ) then
Set_Entity (Selector_Name (Entry_Name), It.Nam);
Set_Etype (Entry_Name, It.Typ);
Generate_Reference (It.Typ, N, ' ');
end if;
Get_Next_Interp (I, It);
end loop;
end;
end if;
Resolve_Entry (Entry_Name);
if Nkind (Entry_Name) = N_Selected_Component then
-- Simple entry call.
Nam := Entity (Selector_Name (Entry_Name));
Obj := Prefix (Entry_Name);
Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
elsif Nkind (Entry_Name) = N_Indexed_Component then
-- Call to member of entry family.
Nam := Entity (Selector_Name (Prefix (Entry_Name)));
Obj := Prefix (Prefix (Entry_Name));
Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
end if;
-- Use context type to disambiguate a protected function that can be
-- called without actuals and that returns an array type, and where
-- the argument list may be an indexing of the returned value.
if Ekind (Nam) = E_Function
and then Needs_No_Actuals (Nam)
and then Present (Parameter_Associations (N))
and then
((Is_Array_Type (Etype (Nam))
and then Covers (Typ, Component_Type (Etype (Nam))))
or else (Is_Access_Type (Etype (Nam))
and then Is_Array_Type (Designated_Type (Etype (Nam)))
and then Covers (Typ,
Component_Type (Designated_Type (Etype (Nam))))))
then
declare
Index_Node : Node_Id;
begin
Index_Node :=
Make_Indexed_Component (Loc,
Prefix =>
Make_Function_Call (Loc,
Name => Relocate_Node (Entry_Name)),
Expressions => Parameter_Associations (N));
-- Since we are correcting a node classification error made by
-- the parser, we call Replace rather than Rewrite.
Replace (N, Index_Node);
Set_Etype (Prefix (N), Etype (Nam));
Set_Etype (N, Typ);
Resolve_Indexed_Component (N, Typ);
return;
end;
end if;
-- The operation name may have been overloaded. Order the actuals
-- according to the formals of the resolved entity.
if Was_Over then
Normalize_Actuals (N, Nam, False, Norm_OK);
pragma Assert (Norm_OK);
end if;
Resolve_Actuals (N, Nam);
Generate_Reference (Nam, Entry_Name);
if Ekind (Nam) = E_Entry
or else Ekind (Nam) = E_Entry_Family
then
Check_Potentially_Blocking_Operation (N);
end if;
-- Verify that a procedure call cannot masquerade as an entry
-- call where an entry call is expected.
if Ekind (Nam) = E_Procedure then
if Nkind (Parent (N)) = N_Entry_Call_Alternative
and then N = Entry_Call_Statement (Parent (N))
then
Error_Msg_N ("entry call required in select statement", N);
elsif Nkind (Parent (N)) = N_Triggering_Alternative
and then N = Triggering_Statement (Parent (N))
then
Error_Msg_N ("triggering statement cannot be procedure call", N);
elsif Ekind (Scope (Nam)) = E_Task_Type
and then not In_Open_Scopes (Scope (Nam))
then
Error_Msg_N ("Task has no entry with this name", Entry_Name);
end if;
end if;
-- After resolution, entry calls and protected procedure calls
-- are changed into entry calls, for expansion. The structure
-- of the node does not change, so it can safely be done in place.
-- Protected function calls must keep their structure because they
-- are subexpressions.
if Ekind (Nam) /= E_Function then
-- A protected operation that is not a function may modify the
-- corresponding object, and cannot apply to a constant.
-- If this is an internal call, the prefix is the type itself.
if Is_Protected_Type (Scope (Nam))
and then not Is_Variable (Obj)
and then (not Is_Entity_Name (Obj)
or else not Is_Type (Entity (Obj)))
then
Error_Msg_N
("prefix of protected procedure or entry call must be variable",
Entry_Name);
end if;
Actuals := Parameter_Associations (N);
First_Named := First_Named_Actual (N);
Rewrite (N,
Make_Entry_Call_Statement (Loc,
Name => Entry_Name,
Parameter_Associations => Actuals));
Set_First_Named_Actual (N, First_Named);
Set_Analyzed (N, True);
-- Protected functions can return on the secondary stack, in which
-- case we must trigger the transient scope mechanism
elsif Expander_Active
and then Requires_Transient_Scope (Etype (Nam))
then
Establish_Transient_Scope (N,
Sec_Stack => not Functions_Return_By_DSP_On_Target);
end if;
end Resolve_Entry_Call;
-------------------------
-- Resolve_Equality_Op --
-------------------------
-- Both arguments must have the same type, and the boolean context
-- does not participate in the resolution. The first pass verifies
-- that the interpretation is not ambiguous, and the type of the left
-- argument is correctly set, or is Any_Type in case of ambiguity.
-- If both arguments are strings or aggregates, allocators, or Null,
-- they are ambiguous even though they carry a single (universal) type.
-- Diagnose this case here.
procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
T : Entity_Id := Find_Unique_Type (L, R);
function Find_Unique_Access_Type return Entity_Id;
-- In the case of allocators, make a last-ditch attempt to find a single
-- access type with the right designated type. This is semantically
-- dubious, and of no interest to any real code, but c48008a makes it
-- all worthwhile.
-----------------------------
-- Find_Unique_Access_Type --
-----------------------------
function Find_Unique_Access_Type return Entity_Id is
Acc : Entity_Id;
E : Entity_Id;
S : Entity_Id := Current_Scope;
begin
if Ekind (Etype (R)) = E_Allocator_Type then
Acc := Designated_Type (Etype (R));
elsif Ekind (Etype (L)) = E_Allocator_Type then
Acc := Designated_Type (Etype (L));
else
return Empty;
end if;
while S /= Standard_Standard loop
E := First_Entity (S);
while Present (E) loop
if Is_Type (E)
and then Is_Access_Type (E)
and then Ekind (E) /= E_Allocator_Type
and then Designated_Type (E) = Base_Type (Acc)
then
return E;
end if;
Next_Entity (E);
end loop;
S := Scope (S);
end loop;
return Empty;
end Find_Unique_Access_Type;
-- Start of processing for Resolve_Equality_Op
begin
Set_Etype (N, Base_Type (Typ));
Generate_Reference (T, N, ' ');
if T = Any_Fixed then
T := Unique_Fixed_Point_Type (L);
end if;
if T /= Any_Type then
if T = Any_String
or else T = Any_Composite
or else T = Any_Character
then
if T = Any_Character then
Ambiguous_Character (L);
else
Error_Msg_N ("ambiguous operands for equality", N);
end if;
Set_Etype (N, Any_Type);
return;
elsif T = Any_Access
or else Ekind (T) = E_Allocator_Type
then
T := Find_Unique_Access_Type;
if No (T) then
Error_Msg_N ("ambiguous operands for equality", N);
Set_Etype (N, Any_Type);
return;
end if;
end if;
if Comes_From_Source (N)
and then Has_Unchecked_Union (T)
then
Error_Msg_N
("cannot compare Unchecked_Union values", N);
end if;
Resolve (L, T);
Resolve (R, T);
Check_Unset_Reference (L);
Check_Unset_Reference (R);
Generate_Operator_Reference (N);
-- If this is an inequality, it may be the implicit inequality
-- created for a user-defined operation, in which case the corres-
-- ponding equality operation is not intrinsic, and the operation
-- cannot be constant-folded. Else fold.
if Nkind (N) = N_Op_Eq
or else Comes_From_Source (Entity (N))
or else Ekind (Entity (N)) = E_Operator
or else Is_Intrinsic_Subprogram
(Corresponding_Equality (Entity (N)))
then
Eval_Relational_Op (N);
elsif Nkind (N) = N_Op_Ne
and then Is_Abstract (Entity (N))
then
Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
end if;
end if;
end Resolve_Equality_Op;
----------------------------------
-- Resolve_Explicit_Dereference --
----------------------------------
procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
P : constant Node_Id := Prefix (N);
I : Interp_Index;
It : Interp;
begin
-- Now that we know the type, check that this is not a
-- dereference of an uncompleted type. Note that this
-- is not entirely correct, because dereferences of
-- private types are legal in default expressions.
-- This consideration also applies to similar checks
-- for allocators, qualified expressions, and type
-- conversions. ???
Check_Fully_Declared (Typ, N);
if Is_Overloaded (P) then
-- Use the context type to select the prefix that has the
-- correct designated type.
Get_First_Interp (P, I, It);
while Present (It.Typ) loop
exit when Is_Access_Type (It.Typ)
and then Covers (Typ, Designated_Type (It.Typ));
Get_Next_Interp (I, It);
end loop;
Resolve (P, It.Typ);
Set_Etype (N, Designated_Type (It.Typ));
else
Resolve (P, Etype (P));
end if;
if Is_Access_Type (Etype (P)) then
Apply_Access_Check (N);
end if;
-- If the designated type is a packed unconstrained array type,
-- and the explicit dereference is not in the context of an
-- attribute reference, then we must compute and set the actual
-- subtype, since it is needed by Gigi. The reason we exclude
-- the attribute case is that this is handled fine by Gigi, and
-- in fact we use such attributes to build the actual subtype.
-- We also exclude generated code (which builds actual subtypes
-- directly if they are needed).
if Is_Array_Type (Etype (N))
and then Is_Packed (Etype (N))
and then not Is_Constrained (Etype (N))
and then Nkind (Parent (N)) /= N_Attribute_Reference
and then Comes_From_Source (N)
then
Set_Etype (N, Get_Actual_Subtype (N));
end if;
-- Note: there is no Eval processing required for an explicit
-- deference, because the type is known to be an allocators, and
-- allocator expressions can never be static.
end Resolve_Explicit_Dereference;
-------------------------------
-- Resolve_Indexed_Component --
-------------------------------
procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
Name : constant Node_Id := Prefix (N);
Expr : Node_Id;
Array_Type : Entity_Id;
Index : Node_Id;
begin
if Is_Overloaded (Name) then
-- Use the context type to select the prefix that yields the
-- correct component type.
declare
I : Interp_Index;
It : Interp;
I1 : Interp_Index := 0;
P : constant Node_Id := Prefix (N);
Found : Boolean := False;
begin
Get_First_Interp (P, I, It);
while Present (It.Typ) loop
if (Is_Array_Type (It.Typ)
and then Covers (Typ, Component_Type (It.Typ)))
or else (Is_Access_Type (It.Typ)
and then Is_Array_Type (Designated_Type (It.Typ))
and then Covers
(Typ, Component_Type (Designated_Type (It.Typ))))
then
if Found then
It := Disambiguate (P, I1, I, Any_Type);
if It = No_Interp then
Error_Msg_N ("ambiguous prefix for indexing", N);
Set_Etype (N, Typ);
return;
else
Found := True;
Array_Type := It.Typ;
I1 := I;
end if;
else
Found := True;
Array_Type := It.Typ;
I1 := I;
end if;
end if;
Get_Next_Interp (I, It);
end loop;
end;
else
Array_Type := Etype (Name);
end if;
Resolve (Name, Array_Type);
Array_Type := Get_Actual_Subtype_If_Available (Name);
-- If prefix is access type, dereference to get real array type.
-- Note: we do not apply an access check because the expander always
-- introduces an explicit dereference, and the check will happen there.
if Is_Access_Type (Array_Type) then
Array_Type := Designated_Type (Array_Type);
end if;
-- If name was overloaded, set component type correctly now.
Set_Etype (N, Component_Type (Array_Type));
Index := First_Index (Array_Type);
Expr := First (Expressions (N));
-- The prefix may have resolved to a string literal, in which case
-- its etype has a special representation. This is only possible
-- currently if the prefix is a static concatenation, written in
-- functional notation.
if Ekind (Array_Type) = E_String_Literal_Subtype then
Resolve (Expr, Standard_Positive);
else
while Present (Index) and Present (Expr) loop
Resolve (Expr, Etype (Index));
Check_Unset_Reference (Expr);
if Is_Scalar_Type (Etype (Expr)) then
Apply_Scalar_Range_Check (Expr, Etype (Index));
else
Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
end if;
Next_Index (Index);
Next (Expr);
end loop;
end if;
Eval_Indexed_Component (N);
end Resolve_Indexed_Component;
-----------------------------
-- Resolve_Integer_Literal --
-----------------------------
procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
begin
Set_Etype (N, Typ);
Eval_Integer_Literal (N);
end Resolve_Integer_Literal;
---------------------------------
-- Resolve_Intrinsic_Operator --
---------------------------------
procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
Op : Entity_Id;
Arg1 : Node_Id := Left_Opnd (N);
Arg2 : Node_Id := Right_Opnd (N);
begin
Op := Entity (N);
while Scope (Op) /= Standard_Standard loop
Op := Homonym (Op);
pragma Assert (Present (Op));
end loop;
Set_Entity (N, Op);
if Typ /= Etype (Arg1) or else Typ = Etype (Arg2) then
Rewrite (Left_Opnd (N), Convert_To (Typ, Arg1));
Rewrite (Right_Opnd (N), Convert_To (Typ, Arg2));
Analyze (Left_Opnd (N));
Analyze (Right_Opnd (N));
end if;
Resolve_Arithmetic_Op (N, Typ);
end Resolve_Intrinsic_Operator;
------------------------
-- Resolve_Logical_Op --
------------------------
procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
B_Typ : Entity_Id;
begin
-- Predefined operations on scalar types yield the base type. On
-- the other hand, logical operations on arrays yield the type of
-- the arguments (and the context).
if Is_Array_Type (Typ) then
B_Typ := Typ;
else
B_Typ := Base_Type (Typ);
end if;
-- The following test is required because the operands of the operation
-- may be literals, in which case the resulting type appears to be
-- compatible with a signed integer type, when in fact it is compatible
-- only with modular types. If the context itself is universal, the
-- operation is illegal.
if not Valid_Boolean_Arg (Typ) then
Error_Msg_N ("invalid context for logical operation", N);
Set_Etype (N, Any_Type);
return;
elsif Typ = Any_Modular then
Error_Msg_N
("no modular type available in this context", N);
Set_Etype (N, Any_Type);
return;
end if;
Resolve (Left_Opnd (N), B_Typ);
Resolve (Right_Opnd (N), B_Typ);
Check_Unset_Reference (Left_Opnd (N));
Check_Unset_Reference (Right_Opnd (N));
Set_Etype (N, B_Typ);
Generate_Operator_Reference (N);
Eval_Logical_Op (N);
end Resolve_Logical_Op;
---------------------------
-- Resolve_Membership_Op --
---------------------------
-- The context can only be a boolean type, and does not determine
-- the arguments. Arguments should be unambiguous, but the preference
-- rule for universal types applies.
procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
T : Entity_Id;
begin
if not Is_Overloaded (R)
and then
(Etype (R) = Universal_Integer or else
Etype (R) = Universal_Real)
and then Is_Overloaded (L)
then
T := Etype (R);
else
T := Intersect_Types (L, R);
end if;
Resolve (L, T);
Check_Unset_Reference (L);
if Nkind (R) = N_Range
and then not Is_Scalar_Type (T)
then
Error_Msg_N ("scalar type required for range", R);
end if;
if Is_Entity_Name (R) then
Freeze_Expression (R);
else
Resolve (R, T);
Check_Unset_Reference (R);
end if;
Eval_Membership_Op (N);
end Resolve_Membership_Op;
------------------
-- Resolve_Null --
------------------
procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
begin
-- For now allow circumvention of the restriction against
-- anonymous null access values via a debug switch to allow
-- for easier trasition (in particular for GNULLI packages
-- that violate the rule). ???
if not Debug_Flag_J
and then Ekind (Typ) = E_Anonymous_Access_Type
and then Comes_From_Source (N)
then
Error_Msg_N ("null cannot be of an anonymous access type", N);
end if;
-- In a distributed context, null for a remote access to subprogram
-- may need to be replaced with a special record aggregate. In this
-- case, return after having done the transformation.
if (Ekind (Typ) = E_Record_Type
or else Is_Remote_Access_To_Subprogram_Type (Typ))
and then Remote_AST_Null_Value (N, Typ)
then
return;
end if;
-- The null literal takes its type from the context.
Set_Etype (N, Typ);
end Resolve_Null;
-----------------------
-- Resolve_Op_Concat --
-----------------------
procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
Btyp : constant Entity_Id := Base_Type (Typ);
Op1 : constant Node_Id := Left_Opnd (N);
Op2 : constant Node_Id := Right_Opnd (N);
procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean);
-- Internal procedure to resolve one operand of concatenation operator.
-- The operand is either of the array type or of the component type.
-- If the operand is an aggregate, and the component type is composite,
-- this is ambiguous if component type has aggregates.
-------------------------------
-- Resolve_Concatenation_Arg --
-------------------------------
procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean) is
begin
if In_Instance then
if Is_Comp
or else (not Is_Overloaded (Arg)
and then Etype (Arg) /= Any_Composite
and then Covers (Component_Type (Typ), Etype (Arg)))
then
Resolve (Arg, Component_Type (Typ));
else
Resolve (Arg, Btyp);
end if;
elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
if Nkind (Arg) = N_Aggregate
and then Is_Composite_Type (Component_Type (Typ))
then
if Is_Private_Type (Component_Type (Typ)) then
Resolve (Arg, Btyp);
else
Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
Set_Etype (Arg, Any_Type);
end if;
else
if Is_Overloaded (Arg)
and then Has_Compatible_Type (Arg, Typ)
and then Etype (Arg) /= Any_Type
then
Error_Msg_N ("ambiguous operand for concatenation!", Arg);
declare
I : Interp_Index;
It : Interp;
begin
Get_First_Interp (Arg, I, It);
while Present (It.Nam) loop
if Base_Type (Etype (It.Nam)) = Base_Type (Typ)
or else Base_Type (Etype (It.Nam)) =
Base_Type (Component_Type (Typ))
then
Error_Msg_Sloc := Sloc (It.Nam);
Error_Msg_N ("\possible interpretation#", Arg);
end if;
Get_Next_Interp (I, It);
end loop;
end;
end if;
Resolve (Arg, Component_Type (Typ));
if Arg = Left_Opnd (N) then
Set_Is_Component_Left_Opnd (N);
else
Set_Is_Component_Right_Opnd (N);
end if;
end if;
else
Resolve (Arg, Btyp);
end if;
Check_Unset_Reference (Arg);
end Resolve_Concatenation_Arg;
-- Start of processing for Resolve_Op_Concat
begin
Set_Etype (N, Btyp);
if Is_Limited_Composite (Btyp) then
Error_Msg_N ("concatenation not available for limited array", N);
end if;
-- If the operands are themselves concatenations, resolve them as
-- such directly. This removes several layers of recursion and allows
-- GNAT to handle larger multiple concatenations.
if Nkind (Op1) = N_Op_Concat
and then not Is_Array_Type (Component_Type (Typ))
and then Entity (Op1) = Entity (N)
then
Resolve_Op_Concat (Op1, Typ);
else
Resolve_Concatenation_Arg
(Op1, Is_Component_Left_Opnd (N));
end if;
if Nkind (Op2) = N_Op_Concat
and then not Is_Array_Type (Component_Type (Typ))
and then Entity (Op2) = Entity (N)
then
Resolve_Op_Concat (Op2, Typ);
else
Resolve_Concatenation_Arg
(Op2, Is_Component_Right_Opnd (N));
end if;
Generate_Operator_Reference (N);
if Is_String_Type (Typ) then
Eval_Concatenation (N);
end if;
-- If this is not a static concatenation, insure that static
-- string operands have their subtypes properly constructed.
if Nkind (N) /= N_String_Literal then
Set_String_Literal_Subtype (Op1, Typ);
Set_String_Literal_Subtype (Op2, Typ);
end if;
end Resolve_Op_Concat;
----------------------
-- Resolve_Op_Expon --
----------------------
procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
B_Typ : constant Entity_Id := Base_Type (Typ);
begin
-- Catch attempts to do fixed-point exponentation with universal
-- operands, which is a case where the illegality is not caught
-- during normal operator analysis.
if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
Error_Msg_N ("exponentiation not available for fixed point", N);
return;
end if;
if Etype (Left_Opnd (N)) = Universal_Integer
or else Etype (Left_Opnd (N)) = Universal_Real
then
Check_For_Visible_Operator (N, B_Typ);
end if;
-- We do the resolution using the base type, because intermediate values
-- in expressions always are of the base type, not a subtype of it.
Resolve (Left_Opnd (N), B_Typ);
Resolve (Right_Opnd (N), Standard_Integer);
Check_Unset_Reference (Left_Opnd (N));
Check_Unset_Reference (Right_Opnd (N));
Set_Etype (N, B_Typ);
Generate_Operator_Reference (N);
Eval_Op_Expon (N);
-- Set overflow checking bit. Much cleverer code needed here eventually
-- and perhaps the Resolve routines should be separated for the various
-- arithmetic operations, since they will need different processing. ???
if Nkind (N) in N_Op then
if not Overflow_Checks_Suppressed (Etype (N)) then
Set_Do_Overflow_Check (N, True);
end if;
end if;
end Resolve_Op_Expon;
--------------------
-- Resolve_Op_Not --
--------------------
procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
B_Typ : Entity_Id;
function Parent_Is_Boolean return Boolean;
-- This function determines if the parent node is a boolean operator
-- or operation (comparison op, membership test, or short circuit form)
-- and the not in question is the left operand of this operation.
-- Note that if the not is in parens, then false is returned.
function Parent_Is_Boolean return Boolean is
begin
if Paren_Count (N) /= 0 then
return False;
else
case Nkind (Parent (N)) is
when N_Op_And |
N_Op_Eq |
N_Op_Ge |
N_Op_Gt |
N_Op_Le |
N_Op_Lt |
N_Op_Ne |
N_Op_Or |
N_Op_Xor |
N_In |
N_Not_In |
N_And_Then |
N_Or_Else =>
return Left_Opnd (Parent (N)) = N;
when others =>
return False;
end case;
end if;
end Parent_Is_Boolean;
-- Start of processing for Resolve_Op_Not
begin
-- Predefined operations on scalar types yield the base type. On
-- the other hand, logical operations on arrays yield the type of
-- the arguments (and the context).
if Is_Array_Type (Typ) then
B_Typ := Typ;
else
B_Typ := Base_Type (Typ);
end if;
if not Valid_Boolean_Arg (Typ) then
Error_Msg_N ("invalid operand type for operator&", N);
Set_Etype (N, Any_Type);
return;
elsif (Typ = Universal_Integer
or else Typ = Any_Modular)
then
if Parent_Is_Boolean then
Error_Msg_N
("operand of not must be enclosed in parentheses",
Right_Opnd (N));
else
Error_Msg_N
("no modular type available in this context", N);
end if;
Set_Etype (N, Any_Type);
return;
else
if not Is_Boolean_Type (Typ)
and then Parent_Is_Boolean
then
Error_Msg_N ("?not expression should be parenthesized here", N);
end if;
Resolve (Right_Opnd (N), B_Typ);
Check_Unset_Reference (Right_Opnd (N));
Set_Etype (N, B_Typ);
Generate_Operator_Reference (N);
Eval_Op_Not (N);
end if;
end Resolve_Op_Not;
-----------------------------
-- Resolve_Operator_Symbol --
-----------------------------
-- Nothing to be done, all resolved already
procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
begin
null;
end Resolve_Operator_Symbol;
----------------------------------
-- Resolve_Qualified_Expression --
----------------------------------
procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
Expr : constant Node_Id := Expression (N);
begin
Resolve (Expr, Target_Typ);
-- A qualified expression requires an exact match of the type,
-- class-wide matching is not allowed.
if Is_Class_Wide_Type (Target_Typ)
and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
then
Wrong_Type (Expr, Target_Typ);
end if;
-- If the target type is unconstrained, then we reset the type of
-- the result from the type of the expression. For other cases, the
-- actual subtype of the expression is the target type.
if Is_Composite_Type (Target_Typ)
and then not Is_Constrained (Target_Typ)
then
Set_Etype (N, Etype (Expr));
end if;
Eval_Qualified_Expression (N);
end Resolve_Qualified_Expression;
-------------------
-- Resolve_Range --
-------------------
procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
L : constant Node_Id := Low_Bound (N);
H : constant Node_Id := High_Bound (N);
begin
Set_Etype (N, Typ);
Resolve (L, Typ);
Resolve (H, Typ);
Check_Unset_Reference (L);
Check_Unset_Reference (H);
-- We have to check the bounds for being within the base range as
-- required for a non-static context. Normally this is automatic
-- and done as part of evaluating expressions, but the N_Range
-- node is an exception, since in GNAT we consider this node to
-- be a subexpression, even though in Ada it is not. The circuit
-- in Sem_Eval could check for this, but that would put the test
-- on the main evaluation path for expressions.
Check_Non_Static_Context (L);
Check_Non_Static_Context (H);
end Resolve_Range;
--------------------------
-- Resolve_Real_Literal --
--------------------------
procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
Actual_Typ : constant Entity_Id := Etype (N);
begin
-- Special processing for fixed-point literals to make sure that the
-- value is an exact multiple of small where this is required. We
-- skip this for the universal real case, and also for generic types.
if Is_Fixed_Point_Type (Typ)
and then Typ /= Universal_Fixed
and then Typ /= Any_Fixed
and then not Is_Generic_Type (Typ)
then
declare
Val : constant Ureal := Realval (N);
Cintr : constant Ureal := Val / Small_Value (Typ);
Cint : constant Uint := UR_Trunc (Cintr);
Den : constant Uint := Norm_Den (Cintr);
Stat : Boolean;
begin
-- Case of literal is not an exact multiple of the Small
if Den /= 1 then
-- For a source program literal for a decimal fixed-point
-- type, this is statically illegal (RM 4.9(36)).
if Is_Decimal_Fixed_Point_Type (Typ)
and then Actual_Typ = Universal_Real
and then Comes_From_Source (N)
then
Error_Msg_N ("value has extraneous low order digits", N);
end if;
-- Replace literal by a value that is the exact representation
-- of a value of the type, i.e. a multiple of the small value,
-- by truncation, since Machine_Rounds is false for all GNAT
-- fixed-point types (RM 4.9(38)).
Stat := Is_Static_Expression (N);
Rewrite (N,
Make_Real_Literal (Sloc (N),
Realval => Small_Value (Typ) * Cint));
Set_Is_Static_Expression (N, Stat);
end if;
-- In all cases, set the corresponding integer field
Set_Corresponding_Integer_Value (N, Cint);
end;
end if;
-- Now replace the actual type by the expected type as usual
Set_Etype (N, Typ);
Eval_Real_Literal (N);
end Resolve_Real_Literal;
-----------------------
-- Resolve_Reference --
-----------------------
procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
P : constant Node_Id := Prefix (N);
begin
-- Replace general access with specific type
if Ekind (Etype (N)) = E_Allocator_Type then
Set_Etype (N, Base_Type (Typ));
end if;
Resolve (P, Designated_Type (Etype (N)));
-- If we are taking the reference of a volatile entity, then treat
-- it as a potential modification of this entity. This is much too
-- conservative, but is neccessary because remove side effects can
-- result in transformations of normal assignments into reference
-- sequences that otherwise fail to notice the modification.
if Is_Entity_Name (P) and then Is_Volatile (Entity (P)) then
Note_Possible_Modification (P);
end if;
end Resolve_Reference;
--------------------------------
-- Resolve_Selected_Component --
--------------------------------
procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
Comp : Entity_Id;
Comp1 : Entity_Id;
P : constant Node_Id := Prefix (N);
S : constant Node_Id := Selector_Name (N);
T : Entity_Id := Etype (P);
I : Interp_Index;
I1 : Interp_Index;
It : Interp;
It1 : Interp;
Found : Boolean;
begin
if Is_Overloaded (P) then
-- Use the context type to select the prefix that has a selector
-- of the correct name and type.
Found := False;
Get_First_Interp (P, I, It);
Search : while Present (It.Typ) loop
if Is_Access_Type (It.Typ) then
T := Designated_Type (It.Typ);
else
T := It.Typ;
end if;
if Is_Record_Type (T) then
Comp := First_Entity (T);
while Present (Comp) loop
if Chars (Comp) = Chars (S)
and then Covers (Etype (Comp), Typ)
then
if not Found then
Found := True;
I1 := I;
It1 := It;
Comp1 := Comp;
else
It := Disambiguate (P, I1, I, Any_Type);
if It = No_Interp then
Error_Msg_N
("ambiguous prefix for selected component", N);
Set_Etype (N, Typ);
return;
else
It1 := It;
if Scope (Comp1) /= It1.Typ then
-- Resolution chooses the new interpretation.
-- Find the component with the right name.
Comp1 := First_Entity (It1.Typ);
while Present (Comp1)
and then Chars (Comp1) /= Chars (S)
loop
Comp1 := Next_Entity (Comp1);
end loop;
end if;
exit Search;
end if;
end if;
end if;
Comp := Next_Entity (Comp);
end loop;
end if;
Get_Next_Interp (I, It);
end loop Search;
Resolve (P, It1.Typ);
Set_Etype (N, Typ);
Set_Entity (S, Comp1);
else
-- Resolve prefix with its type.
Resolve (P, T);
end if;
-- Deal with access type case
if Is_Access_Type (Etype (P)) then
Apply_Access_Check (N);
T := Designated_Type (Etype (P));
else
T := Etype (P);
end if;
if Has_Discriminants (T)
and then Present (Original_Record_Component (Entity (S)))
and then Ekind (Original_Record_Component (Entity (S))) = E_Component
and then Present (Discriminant_Checking_Func
(Original_Record_Component (Entity (S))))
and then not Discriminant_Checks_Suppressed (T)
then
Set_Do_Discriminant_Check (N);
end if;
if Ekind (Entity (S)) = E_Void then
Error_Msg_N ("premature use of component", S);
end if;
-- If the prefix is a record conversion, this may be a renamed
-- discriminant whose bounds differ from those of the original
-- one, so we must ensure that a range check is performed.
if Nkind (P) = N_Type_Conversion
and then Ekind (Entity (S)) = E_Discriminant
then
Set_Etype (N, Base_Type (Typ));
end if;
-- Note: No Eval processing is required, because the prefix is of a
-- record type, or protected type, and neither can possibly be static.
end Resolve_Selected_Component;
-------------------
-- Resolve_Shift --
-------------------
procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
B_Typ : constant Entity_Id := Base_Type (Typ);
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
begin
-- We do the resolution using the base type, because intermediate values
-- in expressions always are of the base type, not a subtype of it.
Resolve (L, B_Typ);
Resolve (R, Standard_Natural);
Check_Unset_Reference (L);
Check_Unset_Reference (R);
Set_Etype (N, B_Typ);
Generate_Operator_Reference (N);
Eval_Shift (N);
end Resolve_Shift;
---------------------------
-- Resolve_Short_Circuit --
---------------------------
procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
B_Typ : constant Entity_Id := Base_Type (Typ);
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
begin
Resolve (L, B_Typ);
Resolve (R, B_Typ);
Check_Unset_Reference (L);
Check_Unset_Reference (R);
Set_Etype (N, B_Typ);
Eval_Short_Circuit (N);
end Resolve_Short_Circuit;
-------------------
-- Resolve_Slice --
-------------------
procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
Name : constant Node_Id := Prefix (N);
Drange : constant Node_Id := Discrete_Range (N);
Array_Type : Entity_Id;
Index : Node_Id;
begin
if Is_Overloaded (Name) then
-- Use the context type to select the prefix that yields the
-- correct array type.
declare
I : Interp_Index;
I1 : Interp_Index := 0;
It : Interp;
P : constant Node_Id := Prefix (N);
Found : Boolean := False;
begin
Get_First_Interp (P, I, It);
while Present (It.Typ) loop
if (Is_Array_Type (It.Typ)
and then Covers (Typ, It.Typ))
or else (Is_Access_Type (It.Typ)
and then Is_Array_Type (Designated_Type (It.Typ))
and then Covers (Typ, Designated_Type (It.Typ)))
then
if Found then
It := Disambiguate (P, I1, I, Any_Type);
if It = No_Interp then
Error_Msg_N ("ambiguous prefix for slicing", N);
Set_Etype (N, Typ);
return;
else
Found := True;
Array_Type := It.Typ;
I1 := I;
end if;
else
Found := True;
Array_Type := It.Typ;
I1 := I;
end if;
end if;
Get_Next_Interp (I, It);
end loop;
end;
else
Array_Type := Etype (Name);
end if;
Resolve (Name, Array_Type);
if Is_Access_Type (Array_Type) then
Apply_Access_Check (N);
Array_Type := Designated_Type (Array_Type);
elsif Is_Entity_Name (Name)
or else (Nkind (Name) = N_Function_Call
and then not Is_Constrained (Etype (Name)))
then
Array_Type := Get_Actual_Subtype (Name);
end if;
-- If name was overloaded, set slice type correctly now
Set_Etype (N, Array_Type);
-- If the range is specified by a subtype mark, no resolution
-- is necessary.
if not Is_Entity_Name (Drange) then
Index := First_Index (Array_Type);
Resolve (Drange, Base_Type (Etype (Index)));
if Nkind (Drange) = N_Range then
Apply_Range_Check (Drange, Etype (Index));
end if;
end if;
Set_Slice_Subtype (N);
Eval_Slice (N);
end Resolve_Slice;
----------------------------
-- Resolve_String_Literal --
----------------------------
procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
C_Typ : constant Entity_Id := Component_Type (Typ);
R_Typ : constant Entity_Id := Root_Type (C_Typ);
Loc : constant Source_Ptr := Sloc (N);
Str : constant String_Id := Strval (N);
Strlen : constant Nat := String_Length (Str);
Subtype_Id : Entity_Id;
Need_Check : Boolean;
begin
-- For a string appearing in a concatenation, defer creation of the
-- string_literal_subtype until the end of the resolution of the
-- concatenation, because the literal may be constant-folded away.
-- This is a useful optimization for long concatenation expressions.
-- If the string is an aggregate built for a single character (which
-- happens in a non-static context) or a is null string to which special
-- checks may apply, we build the subtype. Wide strings must also get
-- a string subtype if they come from a one character aggregate. Strings
-- generated by attributes might be static, but it is often hard to
-- determine whether the enclosing context is static, so we generate
-- subtypes for them as well, thus losing some rarer optimizations ???
-- Same for strings that come from a static conversion.
Need_Check :=
(Strlen = 0 and then Typ /= Standard_String)
or else Nkind (Parent (N)) /= N_Op_Concat
or else (N /= Left_Opnd (Parent (N))
and then N /= Right_Opnd (Parent (N)))
or else (Typ = Standard_Wide_String
and then Nkind (Original_Node (N)) /= N_String_Literal);
-- If the resolving type is itself a string literal subtype, we
-- can just reuse it, since there is no point in creating another.
if Ekind (Typ) = E_String_Literal_Subtype then
Subtype_Id := Typ;
elsif Nkind (Parent (N)) = N_Op_Concat
and then not Need_Check
and then Nkind (Original_Node (N)) /= N_Character_Literal
and then Nkind (Original_Node (N)) /= N_Attribute_Reference
and then Nkind (Original_Node (N)) /= N_Qualified_Expression
and then Nkind (Original_Node (N)) /= N_Type_Conversion
then
Subtype_Id := Typ;
-- Otherwise we must create a string literal subtype. Note that the
-- whole idea of string literal subtypes is simply to avoid the need
-- for building a full fledged array subtype for each literal.
else
Set_String_Literal_Subtype (N, Typ);
Subtype_Id := Etype (N);
end if;
if Nkind (Parent (N)) /= N_Op_Concat
or else Need_Check
then
Set_Etype (N, Subtype_Id);
Eval_String_Literal (N);
end if;
if Is_Limited_Composite (Typ)
or else Is_Private_Composite (Typ)
then
Error_Msg_N ("string literal not available for private array", N);
Set_Etype (N, Any_Type);
return;
end if;
-- The validity of a null string has been checked in the
-- call to Eval_String_Literal.
if Strlen = 0 then
return;
-- Always accept string literal with component type Any_Character,
-- which occurs in error situations and in comparisons of literals,
-- both of which should accept all literals.
elsif R_Typ = Any_Character then
return;
-- If the type is bit-packed, then we always tranform the string
-- literal into a full fledged aggregate.
elsif Is_Bit_Packed_Array (Typ) then
null;
-- Deal with cases of Wide_String and String
else
-- For Standard.Wide_String, or any other type whose component
-- type is Standard.Wide_Character, we know that all the
-- characters in the string must be acceptable, since the parser
-- accepted the characters as valid character literals.
if R_Typ = Standard_Wide_Character then
null;
-- For the case of Standard.String, or any other type whose
-- component type is Standard.Character, we must make sure that
-- there are no wide characters in the string, i.e. that it is
-- entirely composed of characters in range of type String.
-- If the string literal is the result of a static concatenation,
-- the test has already been performed on the components, and need
-- not be repeated.
elsif R_Typ = Standard_Character
and then Nkind (Original_Node (N)) /= N_Op_Concat
then
for J in 1 .. Strlen loop
if not In_Character_Range (Get_String_Char (Str, J)) then
-- If we are out of range, post error. This is one of the
-- very few places that we place the flag in the middle of
-- a token, right under the offending wide character.
Error_Msg
("literal out of range of type Character",
Source_Ptr (Int (Loc) + J));
return;
end if;
end loop;
-- If the root type is not a standard character, then we will convert
-- the string into an aggregate and will let the aggregate code do
-- the checking.
else
null;
end if;
-- See if the component type of the array corresponding to the
-- string has compile time known bounds. If yes we can directly
-- check whether the evaluation of the string will raise constraint
-- error. Otherwise we need to transform the string literal into
-- the corresponding character aggregate and let the aggregate
-- code do the checking.
if R_Typ = Standard_Wide_Character
or else R_Typ = Standard_Character
then
-- Check for the case of full range, where we are definitely OK
if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
return;
end if;
-- Here the range is not the complete base type range, so check
declare
Comp_Typ_Lo : constant Node_Id :=
Type_Low_Bound (Component_Type (Typ));
Comp_Typ_Hi : constant Node_Id :=
Type_High_Bound (Component_Type (Typ));
Char_Val : Uint;
begin
if Compile_Time_Known_Value (Comp_Typ_Lo)
and then Compile_Time_Known_Value (Comp_Typ_Hi)
then
for J in 1 .. Strlen loop
Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
if Char_Val < Expr_Value (Comp_Typ_Lo)
or else Char_Val > Expr_Value (Comp_Typ_Hi)
then
Apply_Compile_Time_Constraint_Error
(N, "character out of range?",
Loc => Source_Ptr (Int (Loc) + J));
end if;
end loop;
return;
end if;
end;
end if;
end if;
-- If we got here we meed to transform the string literal into the
-- equivalent qualified positional array aggregate. This is rather
-- heavy artillery for this situation, but it is hard work to avoid.
declare
Lits : List_Id := New_List;
P : Source_Ptr := Loc + 1;
C : Char_Code;
begin
-- Build the character literals, we give them source locations
-- that correspond to the string positions, which is a bit tricky
-- given the possible presence of wide character escape sequences.
for J in 1 .. Strlen loop
C := Get_String_Char (Str, J);
Set_Character_Literal_Name (C);
Append_To (Lits,
Make_Character_Literal (P, Name_Find, C));
if In_Character_Range (C) then
P := P + 1;
-- Should we have a call to Skip_Wide here ???
-- ??? else
-- Skip_Wide (P);
end if;
end loop;
Rewrite (N,
Make_Qualified_Expression (Loc,
Subtype_Mark => New_Reference_To (Typ, Loc),
Expression =>
Make_Aggregate (Loc, Expressions => Lits)));
Analyze_And_Resolve (N, Typ);
end;
end Resolve_String_Literal;
-----------------------------
-- Resolve_Subprogram_Info --
-----------------------------
procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
begin
Set_Etype (N, Typ);
end Resolve_Subprogram_Info;
-----------------------------
-- Resolve_Type_Conversion --
-----------------------------
procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
Target_Type : constant Entity_Id := Etype (N);
Conv_OK : constant Boolean := Conversion_OK (N);
Operand : Node_Id;
Opnd_Type : Entity_Id;
Rop : Node_Id;
begin
Operand := Expression (N);
if not Conv_OK
and then not Valid_Conversion (N, Target_Type, Operand)
then
return;
end if;
if Etype (Operand) = Any_Fixed then
-- Mixed-mode operation involving a literal. Context must be a fixed
-- type which is applied to the literal subsequently.
if Is_Fixed_Point_Type (Typ) then
Set_Etype (Operand, Universal_Real);
elsif Is_Numeric_Type (Typ)
and then (Nkind (Operand) = N_Op_Multiply
or else Nkind (Operand) = N_Op_Divide)
and then (Etype (Right_Opnd (Operand)) = Universal_Real
or else Etype (Left_Opnd (Operand)) = Universal_Real)
then
if Unique_Fixed_Point_Type (N) = Any_Type then
return; -- expression is ambiguous.
else
Set_Etype (Operand, Standard_Duration);
end if;
if Etype (Right_Opnd (Operand)) = Universal_Real then
Rop := New_Copy_Tree (Right_Opnd (Operand));
else
Rop := New_Copy_Tree (Left_Opnd (Operand));
end if;
Resolve (Rop, Standard_Long_Long_Float);
if Realval (Rop) /= Ureal_0
and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
then
Error_Msg_N ("universal real operand can only be interpreted?",
Rop);
Error_Msg_N ("\as Duration, and will lose precision?", Rop);
end if;
else
Error_Msg_N ("invalid context for mixed mode operation", N);
Set_Etype (Operand, Any_Type);
return;
end if;
end if;
Opnd_Type := Etype (Operand);
Resolve (Operand, Opnd_Type);
-- Note: we do the Eval_Type_Conversion call before applying the
-- required checks for a subtype conversion. This is important,
-- since both are prepared under certain circumstances to change
-- the type conversion to a constraint error node, but in the case
-- of Eval_Type_Conversion this may reflect an illegality in the
-- static case, and we would miss the illegality (getting only a
-- warning message), if we applied the type conversion checks first.
Eval_Type_Conversion (N);
-- If after evaluation, we still have a type conversion, then we
-- may need to apply checks required for a subtype conversion.
-- Skip these type conversion checks if universal fixed operands
-- operands involved, since range checks are handled separately for
-- these cases (in the appropriate Expand routines in unit Exp_Fixd).
if Nkind (N) = N_Type_Conversion
and then not Is_Generic_Type (Root_Type (Target_Type))
and then Target_Type /= Universal_Fixed
and then Opnd_Type /= Universal_Fixed
then
Apply_Type_Conversion_Checks (N);
end if;
-- Issue warning for conversion of simple object to its own type
if Warn_On_Redundant_Constructs
and then Comes_From_Source (N)
and then Nkind (N) = N_Type_Conversion
and then Is_Entity_Name (Expression (N))
and then Etype (Entity (Expression (N))) = Target_Type
then
Error_Msg_NE
("?useless conversion, & has this type",
N, Entity (Expression (N)));
end if;
end Resolve_Type_Conversion;
----------------------
-- Resolve_Unary_Op --
----------------------
procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
B_Typ : Entity_Id := Base_Type (Typ);
R : constant Node_Id := Right_Opnd (N);
begin
-- Generate warning for expressions like -5 mod 3
if Paren_Count (N) = 0
and then Nkind (N) = N_Op_Minus
and then Nkind (Right_Opnd (N)) = N_Op_Mod
then
Error_Msg_N
("?unary minus expression should be parenthesized here", N);
end if;
if Etype (R) = Universal_Integer
or else Etype (R) = Universal_Real
then
Check_For_Visible_Operator (N, B_Typ);
end if;
Set_Etype (N, B_Typ);
Resolve (R, B_Typ);
Check_Unset_Reference (R);
Generate_Operator_Reference (N);
Eval_Unary_Op (N);
-- Set overflow checking bit. Much cleverer code needed here eventually
-- and perhaps the Resolve routines should be separated for the various
-- arithmetic operations, since they will need different processing ???
if Nkind (N) in N_Op then
if not Overflow_Checks_Suppressed (Etype (N)) then
Set_Do_Overflow_Check (N, True);
end if;
end if;
end Resolve_Unary_Op;
----------------------------------
-- Resolve_Unchecked_Expression --
----------------------------------
procedure Resolve_Unchecked_Expression
(N : Node_Id;
Typ : Entity_Id)
is
begin
Resolve (Expression (N), Typ, Suppress => All_Checks);
Set_Etype (N, Typ);
end Resolve_Unchecked_Expression;
---------------------------------------
-- Resolve_Unchecked_Type_Conversion --
---------------------------------------
procedure Resolve_Unchecked_Type_Conversion
(N : Node_Id;
Typ : Entity_Id)
is
Operand : constant Node_Id := Expression (N);
Opnd_Type : constant Entity_Id := Etype (Operand);
begin
-- Resolve operand using its own type.
Resolve (Operand, Opnd_Type);
Eval_Unchecked_Conversion (N);
end Resolve_Unchecked_Type_Conversion;
------------------------------
-- Rewrite_Operator_As_Call --
------------------------------
procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
Loc : Source_Ptr := Sloc (N);
Actuals : List_Id := New_List;
New_N : Node_Id;
begin
if Nkind (N) in N_Binary_Op then
Append (Left_Opnd (N), Actuals);
end if;
Append (Right_Opnd (N), Actuals);
New_N :=
Make_Function_Call (Sloc => Loc,
Name => New_Occurrence_Of (Nam, Loc),
Parameter_Associations => Actuals);
Preserve_Comes_From_Source (New_N, N);
Preserve_Comes_From_Source (Name (New_N), N);
Rewrite (N, New_N);
Set_Etype (N, Etype (Nam));
end Rewrite_Operator_As_Call;
------------------------------
-- Rewrite_Renamed_Operator --
------------------------------
procedure Rewrite_Renamed_Operator (N : Node_Id; Op : Entity_Id) is
Nam : constant Name_Id := Chars (Op);
Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
Op_Node : Node_Id;
begin
if Chars (N) /= Nam then
-- Rewrite the operator node using the real operator, not its
-- renaming.
Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
Set_Chars (Op_Node, Nam);
Set_Etype (Op_Node, Etype (N));
Set_Entity (Op_Node, Op);
Set_Right_Opnd (Op_Node, Right_Opnd (N));
Generate_Reference (Op, N);
if Is_Binary then
Set_Left_Opnd (Op_Node, Left_Opnd (N));
end if;
Rewrite (N, Op_Node);
end if;
end Rewrite_Renamed_Operator;
-----------------------
-- Set_Slice_Subtype --
-----------------------
-- Build an implicit subtype declaration to represent the type delivered
-- by the slice. This is an abbreviated version of an array subtype. We
-- define an index subtype for the slice, using either the subtype name
-- or the discrete range of the slice. To be consistent with index usage
-- elsewhere, we create a list header to hold the single index. This list
-- is not otherwise attached to the syntax tree.
procedure Set_Slice_Subtype (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Index : Node_Id;
Index_List : List_Id := New_List;
Index_Subtype : Entity_Id;
Index_Type : Entity_Id;
Slice_Subtype : Entity_Id;
Drange : constant Node_Id := Discrete_Range (N);
begin
if Is_Entity_Name (Drange) then
Index_Subtype := Entity (Drange);
else
-- We force the evaluation of a range. This is definitely needed in
-- the renamed case, and seems safer to do unconditionally. Note in
-- any case that since we will create and insert an Itype referring
-- to this range, we must make sure any side effect removal actions
-- are inserted before the Itype definition.
if Nkind (Drange) = N_Range then
Force_Evaluation (Low_Bound (Drange));
Force_Evaluation (High_Bound (Drange));
end if;
Index_Type := Base_Type (Etype (Drange));
Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
Set_Scalar_Range (Index_Subtype, Drange);
Set_Etype (Index_Subtype, Index_Type);
Set_Size_Info (Index_Subtype, Index_Type);
Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
end if;
Slice_Subtype := Create_Itype (E_Array_Subtype, N);
Index := New_Occurrence_Of (Index_Subtype, Loc);
Set_Etype (Index, Index_Subtype);
Append (Index, Index_List);
Set_Component_Type (Slice_Subtype, Component_Type (Etype (N)));
Set_First_Index (Slice_Subtype, Index);
Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
Set_Is_Constrained (Slice_Subtype, True);
Init_Size_Align (Slice_Subtype);
Check_Compile_Time_Size (Slice_Subtype);
-- The Etype of the existing Slice node is reset to this slice
-- subtype. Its bounds are obtained from its first index.
Set_Etype (N, Slice_Subtype);
-- In the packed case, this must be immediately frozen
-- Couldn't we always freeze here??? and if we did, then the above
-- call to Check_Compile_Time_Size could be eliminated, which would
-- be nice, because then that routine could be made private to Freeze.
if Is_Packed (Slice_Subtype) and not In_Default_Expression then
Freeze_Itype (Slice_Subtype, N);
end if;
end Set_Slice_Subtype;
--------------------------------
-- Set_String_Literal_Subtype --
--------------------------------
procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
Subtype_Id : Entity_Id;
begin
if Nkind (N) /= N_String_Literal then
return;
else
Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
end if;
Set_Component_Type (Subtype_Id, Component_Type (Typ));
Set_String_Literal_Length (Subtype_Id,
UI_From_Int (String_Length (Strval (N))));
Set_Etype (Subtype_Id, Base_Type (Typ));
Set_Is_Constrained (Subtype_Id);
-- The low bound is set from the low bound of the corresponding
-- index type. Note that we do not store the high bound in the
-- string literal subtype, but it can be deduced if necssary
-- from the length and the low bound.
Set_String_Literal_Low_Bound
(Subtype_Id, Type_Low_Bound (Etype (First_Index (Typ))));
Set_Etype (N, Subtype_Id);
end Set_String_Literal_Subtype;
-----------------------------
-- Unique_Fixed_Point_Type --
-----------------------------
function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
T1 : Entity_Id := Empty;
T2 : Entity_Id;
Item : Node_Id;
Scop : Entity_Id;
procedure Fixed_Point_Error;
-- If true ambiguity, give details.
procedure Fixed_Point_Error is
begin
Error_Msg_N ("ambiguous universal_fixed_expression", N);
Error_Msg_NE ("\possible interpretation as}", N, T1);
Error_Msg_NE ("\possible interpretation as}", N, T2);
end Fixed_Point_Error;
begin
-- The operations on Duration are visible, so Duration is always a
-- possible interpretation.
T1 := Standard_Duration;
Scop := Current_Scope;
-- Look for fixed-point types in enclosing scopes.
while Scop /= Standard_Standard loop
T2 := First_Entity (Scop);
while Present (T2) loop
if Is_Fixed_Point_Type (T2)
and then Current_Entity (T2) = T2
and then Scope (Base_Type (T2)) = Scop
then
if Present (T1) then
Fixed_Point_Error;
return Any_Type;
else
T1 := T2;
end if;
end if;
Next_Entity (T2);
end loop;
Scop := Scope (Scop);
end loop;
-- Look for visible fixed type declarations in the context.
Item := First (Context_Items (Cunit (Current_Sem_Unit)));
while Present (Item) loop
if Nkind (Item) = N_With_Clause then
Scop := Entity (Name (Item));
T2 := First_Entity (Scop);
while Present (T2) loop
if Is_Fixed_Point_Type (T2)
and then Scope (Base_Type (T2)) = Scop
and then (Is_Potentially_Use_Visible (T2)
or else In_Use (T2))
then
if Present (T1) then
Fixed_Point_Error;
return Any_Type;
else
T1 := T2;
end if;
end if;
Next_Entity (T2);
end loop;
end if;
Next (Item);
end loop;
if Nkind (N) = N_Real_Literal then
Error_Msg_NE ("real literal interpreted as }?", N, T1);
else
Error_Msg_NE ("universal_fixed expression interpreted as }?", N, T1);
end if;
return T1;
end Unique_Fixed_Point_Type;
----------------------
-- Valid_Conversion --
----------------------
function Valid_Conversion
(N : Node_Id;
Target : Entity_Id;
Operand : Node_Id)
return Boolean
is
Target_Type : Entity_Id := Base_Type (Target);
Opnd_Type : Entity_Id := Etype (Operand);
function Conversion_Check
(Valid : Boolean;
Msg : String)
return Boolean;
-- Little routine to post Msg if Valid is False, returns Valid value
function Valid_Tagged_Conversion
(Target_Type : Entity_Id;
Opnd_Type : Entity_Id)
return Boolean;
-- Specifically test for validity of tagged conversions
----------------------
-- Conversion_Check --
----------------------
function Conversion_Check
(Valid : Boolean;
Msg : String)
return Boolean
is
begin
if not Valid then
Error_Msg_N (Msg, Operand);
end if;
return Valid;
end Conversion_Check;
-----------------------------
-- Valid_Tagged_Conversion --
-----------------------------
function Valid_Tagged_Conversion
(Target_Type : Entity_Id;
Opnd_Type : Entity_Id)
return Boolean
is
begin
-- Upward conversions are allowed (RM 4.6(22)).
if Covers (Target_Type, Opnd_Type)
or else Is_Ancestor (Target_Type, Opnd_Type)
then
return True;
-- Downward conversion are allowed if the operand is
-- is class-wide (RM 4.6(23)).
elsif Is_Class_Wide_Type (Opnd_Type)
and then Covers (Opnd_Type, Target_Type)
then
return True;
elsif Covers (Opnd_Type, Target_Type)
or else Is_Ancestor (Opnd_Type, Target_Type)
then
return
Conversion_Check (False,
"downward conversion of tagged objects not allowed");
else
Error_Msg_NE
("invalid tagged conversion, not compatible with}",
N, First_Subtype (Opnd_Type));
return False;
end if;
end Valid_Tagged_Conversion;
-- Start of processing for Valid_Conversion
begin
Check_Parameterless_Call (Operand);
if Is_Overloaded (Operand) then
declare
I : Interp_Index;
I1 : Interp_Index;
It : Interp;
It1 : Interp;
N1 : Entity_Id;
begin
-- Remove procedure calls, which syntactically cannot appear
-- in this context, but which cannot be removed by type checking,
-- because the context does not impose a type.
Get_First_Interp (Operand, I, It);
while Present (It.Typ) loop
if It.Typ = Standard_Void_Type then
Remove_Interp (I);
end if;
Get_Next_Interp (I, It);
end loop;
Get_First_Interp (Operand, I, It);
I1 := I;
It1 := It;
if No (It.Typ) then
Error_Msg_N ("illegal operand in conversion", Operand);
return False;
end if;
Get_Next_Interp (I, It);
if Present (It.Typ) then
N1 := It1.Nam;
It1 := Disambiguate (Operand, I1, I, Any_Type);
if It1 = No_Interp then
Error_Msg_N ("ambiguous operand in conversion", Operand);
Error_Msg_Sloc := Sloc (It.Nam);
Error_Msg_N ("possible interpretation#!", Operand);
Error_Msg_Sloc := Sloc (N1);
Error_Msg_N ("possible interpretation#!", Operand);
return False;
end if;
end if;
Set_Etype (Operand, It1.Typ);
Opnd_Type := It1.Typ;
end;
end if;
if Chars (Current_Scope) = Name_Unchecked_Conversion then
-- This check is dubious, what if there were a user defined
-- scope whose name was Unchecked_Conversion ???
return True;
elsif Is_Numeric_Type (Target_Type) then
if Opnd_Type = Universal_Fixed then
return True;
else
return Conversion_Check (Is_Numeric_Type (Opnd_Type),
"illegal operand for numeric conversion");
end if;
elsif Is_Array_Type (Target_Type) then
if not Is_Array_Type (Opnd_Type)
or else Opnd_Type = Any_Composite
or else Opnd_Type = Any_String
then
Error_Msg_N
("illegal operand for array conversion", Operand);
return False;
elsif Number_Dimensions (Target_Type) /=
Number_Dimensions (Opnd_Type)
then
Error_Msg_N
("incompatible number of dimensions for conversion", Operand);
return False;
else
declare
Target_Index : Node_Id := First_Index (Target_Type);
Opnd_Index : Node_Id := First_Index (Opnd_Type);
Target_Index_Type : Entity_Id;
Opnd_Index_Type : Entity_Id;
Target_Comp_Type : Entity_Id := Component_Type (Target_Type);
Opnd_Comp_Type : Entity_Id := Component_Type (Opnd_Type);
begin
while Present (Target_Index) and then Present (Opnd_Index) loop
Target_Index_Type := Etype (Target_Index);
Opnd_Index_Type := Etype (Opnd_Index);
if not (Is_Integer_Type (Target_Index_Type)
and then Is_Integer_Type (Opnd_Index_Type))
and then (Root_Type (Target_Index_Type)
/= Root_Type (Opnd_Index_Type))
then
Error_Msg_N
("incompatible index types for array conversion",
Operand);
return False;
end if;
Next_Index (Target_Index);
Next_Index (Opnd_Index);
end loop;
if Base_Type (Target_Comp_Type) /=
Base_Type (Opnd_Comp_Type)
then
Error_Msg_N
("incompatible component types for array conversion",
Operand);
return False;
elsif
Is_Constrained (Target_Comp_Type)
/= Is_Constrained (Opnd_Comp_Type)
or else not Subtypes_Statically_Match
(Target_Comp_Type, Opnd_Comp_Type)
then
Error_Msg_N
("component subtypes must statically match", Operand);
return False;
end if;
end;
end if;
return True;
elsif (Ekind (Target_Type) = E_General_Access_Type
or else Ekind (Target_Type) = E_Anonymous_Access_Type)
and then
Conversion_Check
(Is_Access_Type (Opnd_Type)
and then Ekind (Opnd_Type) /=
E_Access_Subprogram_Type
and then Ekind (Opnd_Type) /=
E_Access_Protected_Subprogram_Type,
"must be an access-to-object type")
then
if Is_Access_Constant (Opnd_Type)
and then not Is_Access_Constant (Target_Type)
then
Error_Msg_N
("access-to-constant operand type not allowed", Operand);
return False;
end if;
-- Check the static accessibility rule of 4.6(17). Note that
-- the check is not enforced when within an instance body, since
-- the RM requires such cases to be caught at run time.
if Ekind (Target_Type) /= E_Anonymous_Access_Type then
if Type_Access_Level (Opnd_Type)
> Type_Access_Level (Target_Type)
then
-- In an instance, this is a run-time check, but one we
-- know will fail, so generate an appropriate warning.
-- The raise will be generated by Expand_N_Type_Conversion.
if In_Instance_Body then
Error_Msg_N
("?cannot convert local pointer to non-local access type",
Operand);
Error_Msg_N
("?Program_Error will be raised at run time", Operand);
else
Error_Msg_N
("cannot convert local pointer to non-local access type",
Operand);
return False;
end if;
elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type then
-- When the operand is a selected access discriminant
-- the check needs to be made against the level of the
-- object denoted by the prefix of the selected name.
-- (Object_Access_Level handles checking the prefix
-- of the operand for this case.)
if Nkind (Operand) = N_Selected_Component
and then Object_Access_Level (Operand)
> Type_Access_Level (Target_Type)
then
-- In an instance, this is a run-time check, but one we
-- know will fail, so generate an appropriate warning.
-- The raise will be generated by Expand_N_Type_Conversion.
if In_Instance_Body then
Error_Msg_N
("?cannot convert access discriminant to non-local" &
" access type", Operand);
Error_Msg_N
("?Program_Error will be raised at run time", Operand);
else
Error_Msg_N
("cannot convert access discriminant to non-local" &
" access type", Operand);
return False;
end if;
end if;
-- The case of a reference to an access discriminant
-- from within a type declaration (which will appear
-- as a discriminal) is always illegal because the
-- level of the discriminant is considered to be
-- deeper than any (namable) access type.
if Is_Entity_Name (Operand)
and then (Ekind (Entity (Operand)) = E_In_Parameter
or else Ekind (Entity (Operand)) = E_Constant)
and then Present (Discriminal_Link (Entity (Operand)))
then
Error_Msg_N
("discriminant has deeper accessibility level than target",
Operand);
return False;
end if;
end if;
end if;
declare
Target : constant Entity_Id := Designated_Type (Target_Type);
Opnd : constant Entity_Id := Designated_Type (Opnd_Type);
begin
if Is_Tagged_Type (Target) then
return Valid_Tagged_Conversion (Target, Opnd);
else
if Base_Type (Target) /= Base_Type (Opnd) then
Error_Msg_NE
("target designated type not compatible with }",
N, Base_Type (Opnd));
return False;
elsif not Subtypes_Statically_Match (Target, Opnd)
and then (not Has_Discriminants (Target)
or else Is_Constrained (Target))
then
Error_Msg_NE
("target designated subtype not compatible with }",
N, Opnd);
return False;
else
return True;
end if;
end if;
end;
elsif Ekind (Target_Type) = E_Access_Subprogram_Type
and then Conversion_Check
(Ekind (Base_Type (Opnd_Type)) = E_Access_Subprogram_Type,
"illegal operand for access subprogram conversion")
then
-- Check that the designated types are subtype conformant
if not Subtype_Conformant (Designated_Type (Opnd_Type),
Designated_Type (Target_Type))
then
Error_Msg_N
("operand type is not subtype conformant with target type",
Operand);
end if;
-- Check the static accessibility rule of 4.6(20)
if Type_Access_Level (Opnd_Type) >
Type_Access_Level (Target_Type)
then
Error_Msg_N
("operand type has deeper accessibility level than target",
Operand);
-- Check that if the operand type is declared in a generic body,
-- then the target type must be declared within that same body
-- (enforces last sentence of 4.6(20)).
elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
declare
O_Gen : constant Node_Id :=
Enclosing_Generic_Body (Opnd_Type);
T_Gen : Node_Id :=
Enclosing_Generic_Body (Target_Type);
begin
while Present (T_Gen) and then T_Gen /= O_Gen loop
T_Gen := Enclosing_Generic_Body (T_Gen);
end loop;
if T_Gen /= O_Gen then
Error_Msg_N
("target type must be declared in same generic body"
& " as operand type", N);
end if;
end;
end if;
return True;
elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
then
-- It is valid to convert from one RAS type to another provided
-- that their specification statically match.
Check_Subtype_Conformant
(New_Id =>
Designated_Type (Corresponding_Remote_Type (Target_Type)),
Old_Id =>
Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
Err_Loc =>
N);
return True;
elsif Is_Tagged_Type (Target_Type) then
return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
-- Types derived from the same root type are convertible.
elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
return True;
-- In an instance, there may be inconsistent views of the same
-- type, or types derived from the same type.
elsif In_Instance
and then Underlying_Type (Target_Type) = Underlying_Type (Opnd_Type)
then
return True;
-- Special check for common access type error case
elsif Ekind (Target_Type) = E_Access_Type
and then Is_Access_Type (Opnd_Type)
then
Error_Msg_N ("target type must be general access type!", N);
Error_Msg_NE ("add ALL to }!", N, Target_Type);
return False;
else
Error_Msg_NE ("invalid conversion, not compatible with }",
N, Opnd_Type);
return False;
end if;
end Valid_Conversion;
end Sem_Res;
|