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
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ T Y P E --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2024, 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 3, 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 COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Aspects; use Aspects;
with Atree; use Atree;
with Alloc;
with Debug; use Debug;
with Einfo; use Einfo;
with Einfo.Entities; use Einfo.Entities;
with Einfo.Utils; use Einfo.Utils;
with Elists; use Elists;
with Nlists; use Nlists;
with Errout; use Errout;
with Lib; use Lib;
with Namet; use Namet;
with Opt; use Opt;
with Output; use Output;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch8; use Sem_Ch8;
with Sem_Ch12; use Sem_Ch12;
with Sem_Disp; use Sem_Disp;
with Sem_Dist; use Sem_Dist;
with Sem_Util; use Sem_Util;
with Stand; use Stand;
with Sinfo; use Sinfo;
with Sinfo.Nodes; use Sinfo.Nodes;
with Sinfo.Utils; use Sinfo.Utils;
with Snames; use Snames;
with Table;
with Treepr; use Treepr;
with Uintp; use Uintp;
with GNAT.HTable; use GNAT.HTable;
package body Sem_Type is
---------------------
-- Data Structures --
---------------------
-- The following data structures establish a mapping between nodes and
-- their interpretations. An overloaded node has an entry in Interp_Map,
-- which in turn contains a pointer into the All_Interp array. The
-- interpretations of a given node are contiguous in All_Interp. Each set
-- of interpretations is terminated with the marker No_Interp.
-- Interp_Map All_Interp
-- +-----+ +--------+
-- | | --->|interp1 |
-- |_____| | |interp2 |
-- |index|---------| |nointerp|
-- |-----| | |
-- | | | |
-- +-----+ +--------+
-- This scheme does not currently reclaim interpretations. In principle,
-- after a unit is compiled, all overloadings have been resolved, and the
-- candidate interpretations should be deleted. This should be easier
-- now than with the previous scheme???
package All_Interp is new Table.Table (
Table_Component_Type => Interp,
Table_Index_Type => Interp_Index,
Table_Low_Bound => 0,
Table_Initial => Alloc.All_Interp_Initial,
Table_Increment => Alloc.All_Interp_Increment,
Table_Name => "All_Interp");
Header_Max : constant := 3079;
-- The number of hash buckets; an arbitrary prime number
subtype Header_Num is Integer range 0 .. Header_Max - 1;
function Hash (N : Node_Id) return Header_Num;
-- A trivial hashing function for nodes, used to insert an overloaded
-- node into the Interp_Map table.
package Interp_Map is new Simple_HTable
(Header_Num => Header_Num,
Element => Interp_Index,
No_Element => -1,
Key => Node_Id,
Hash => Hash,
Equal => "=");
Last_Overloaded : Node_Id := Empty;
-- Overloaded node after initializing a new collection of intepretation
-------------------------------------
-- Handling of Overload Resolution --
-------------------------------------
-- Overload resolution uses two passes over the syntax tree of a complete
-- context. In the first, bottom-up pass, the types of actuals in calls
-- are used to resolve possibly overloaded subprogram and operator names.
-- In the second top-down pass, the type of the context (for example the
-- condition in a while statement) is used to resolve a possibly ambiguous
-- call, and the unique subprogram name in turn imposes a specific context
-- on each of its actuals.
-- Most expressions are in fact unambiguous, and the bottom-up pass is
-- sufficient to resolve most everything. To simplify the common case,
-- names and expressions carry a flag Is_Overloaded to indicate whether
-- they have more than one interpretation. If the flag is off, then each
-- name has already a unique meaning and type, and the bottom-up pass is
-- sufficient (and much simpler).
--------------------------
-- Operator Overloading --
--------------------------
-- The visibility of operators is handled differently from that of other
-- entities. We do not introduce explicit versions of primitive operators
-- for each type definition. As a result, there is only one entity
-- corresponding to predefined addition on all numeric types, etc. The
-- back end resolves predefined operators according to their type. The
-- visibility of primitive operations then reduces to the visibility of the
-- resulting type: (a + b) is a legal interpretation of some primitive
-- operator + if the type of the result (which must also be the type of a
-- and b) is directly visible (either immediately visible or use-visible).
-- User-defined operators are treated like other functions, but the
-- visibility of these user-defined operations must be special-cased
-- to determine whether they hide or are hidden by predefined operators.
-- The form P."+" (x, y) requires additional handling.
-- Concatenation is treated more conventionally: for every one-dimensional
-- array type we introduce a explicit concatenation operator. This is
-- necessary to handle the case of (element & element => array) which
-- cannot be handled conveniently if there is no explicit instance of
-- resulting type of the operation.
-----------------------
-- Local Subprograms --
-----------------------
procedure All_Overloads;
pragma Warnings (Off, All_Overloads);
-- Debugging procedure: list full contents of Overloads table
function Binary_Op_Interp_Has_Abstract_Op
(N : Node_Id;
E : Entity_Id) return Entity_Id;
-- Given the node and entity of a binary operator, determine whether the
-- actuals of E contain an abstract interpretation with regards to the
-- types of their corresponding formals. Return the abstract operation or
-- Empty.
function Function_Interp_Has_Abstract_Op
(N : Node_Id;
E : Entity_Id) return Entity_Id;
-- Given the node and entity of a function call, determine whether the
-- actuals of E contain an abstract interpretation with regards to the
-- types of their corresponding formals. Return the abstract operation or
-- Empty.
function Has_Abstract_Op
(N : Node_Id;
Typ : Entity_Id) return Entity_Id;
-- Subsidiary routine to Binary_Op_Interp_Has_Abstract_Op and Function_
-- Interp_Has_Abstract_Op. Determine whether an overloaded node has an
-- abstract interpretation which yields type Typ.
procedure New_Interps (N : Node_Id);
-- Initialize collection of interpretations for the given node, which is
-- either an overloaded entity, or an operation whose arguments have
-- multiple interpretations. Interpretations can be added to only one
-- node at a time.
--------------------
-- Add_One_Interp --
--------------------
procedure Add_One_Interp
(N : Node_Id;
E : Entity_Id;
T : Entity_Id;
Opnd_Type : Entity_Id := Empty)
is
Vis_Type : Entity_Id;
procedure Add_Entry (Name : Entity_Id; Typ : Entity_Id);
-- Add one interpretation to an overloaded node. Add a new entry if
-- not hidden by previous one, and remove previous one if hidden by
-- new one.
function Is_Universal_Operation (Op : Entity_Id) return Boolean;
-- True if the entity is a predefined operator and the operands have
-- a universal Interpretation.
---------------
-- Add_Entry --
---------------
procedure Add_Entry (Name : Entity_Id; Typ : Entity_Id) is
Abstr_Op : Entity_Id := Empty;
I : Interp_Index;
It : Interp;
-- Start of processing for Add_Entry
begin
-- Find out whether the new entry references interpretations that
-- are abstract or disabled by abstract operators.
if Ada_Version >= Ada_2005 then
if Nkind (N) in N_Binary_Op then
Abstr_Op := Binary_Op_Interp_Has_Abstract_Op (N, Name);
elsif Nkind (N) = N_Function_Call
and then Ekind (Name) = E_Function
then
Abstr_Op := Function_Interp_Has_Abstract_Op (N, Name);
end if;
end if;
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
-- Avoid making duplicate entries in overloads
if Name = It.Nam
and then Base_Type (It.Typ) = Base_Type (T)
then
return;
-- A user-defined subprogram hides another declared at an outer
-- level, or one that is use-visible. So return if previous
-- definition hides new one (which is either in an outer
-- scope, or use-visible). Note that for functions use-visible
-- is the same as potentially use-visible. If new one hides
-- previous one, replace entry in table of interpretations.
-- If this is a universal operation, retain the operator in case
-- preference rule applies.
elsif ((Ekind (Name) in E_Function | E_Procedure
and then Ekind (Name) = Ekind (It.Nam))
or else (Ekind (Name) = E_Operator
and then Ekind (It.Nam) = E_Function))
and then Is_Immediately_Visible (It.Nam)
and then Type_Conformant (Name, It.Nam)
and then Base_Type (It.Typ) = Base_Type (T)
then
if Is_Universal_Operation (Name) then
exit;
-- If node is an operator symbol, we have no actuals with
-- which to check hiding, and this is done in full in the
-- caller (Analyze_Subprogram_Renaming) so we include the
-- predefined operator in any case.
elsif Nkind (N) = N_Operator_Symbol
or else
(Nkind (N) = N_Expanded_Name
and then Nkind (Selector_Name (N)) = N_Operator_Symbol)
then
exit;
elsif not In_Open_Scopes (Scope (Name))
or else Scope_Depth (Scope (Name)) <=
Scope_Depth (Scope (It.Nam))
then
-- If ambiguity within instance, and entity is not an
-- implicit operation, save for later disambiguation.
if Scope (Name) = Scope (It.Nam)
and then not Is_Inherited_Operation (Name)
and then In_Instance
then
exit;
else
return;
end if;
else
All_Interp.Table (I).Nam := Name;
return;
end if;
-- Otherwise keep going
else
Get_Next_Interp (I, It);
end if;
end loop;
All_Interp.Table (All_Interp.Last) := (Name, Typ, Abstr_Op);
All_Interp.Append (No_Interp);
end Add_Entry;
----------------------------
-- Is_Universal_Operation --
----------------------------
function Is_Universal_Operation (Op : Entity_Id) return Boolean is
Arg : Node_Id;
begin
if Ekind (Op) /= E_Operator then
return False;
elsif Nkind (N) in N_Binary_Op then
if Present (Universal_Interpretation (Left_Opnd (N)))
and then Present (Universal_Interpretation (Right_Opnd (N)))
then
return True;
elsif Nkind (N) in N_Op_Eq | N_Op_Ne
and then
(Is_Anonymous_Access_Type (Etype (Left_Opnd (N)))
or else Is_Anonymous_Access_Type (Etype (Right_Opnd (N))))
then
return True;
else
return False;
end if;
elsif Nkind (N) in N_Unary_Op then
return Present (Universal_Interpretation (Right_Opnd (N)));
elsif Nkind (N) = N_Function_Call then
Arg := First_Actual (N);
while Present (Arg) loop
if No (Universal_Interpretation (Arg)) then
return False;
end if;
Next_Actual (Arg);
end loop;
return True;
else
return False;
end if;
end Is_Universal_Operation;
-- Start of processing for Add_One_Interp
begin
-- If the interpretation is a predefined operator, verify that it is
-- visible, or that the entity has already been resolved (case of an
-- instantiation node that refers to a predefined operation, or an
-- internally generated operator node, or an operator given as an
-- expanded name). If the operator is a comparison or equality, then
-- it is the type of the operand that is relevant here.
if Ekind (E) = E_Operator then
if Present (Opnd_Type) then
Vis_Type := Opnd_Type;
else
Vis_Type := Base_Type (T);
end if;
if Nkind (N) = N_Expanded_Name
or else (Nkind (N) in N_Op and then E = Entity (N))
or else Is_Visible_Operator (N, Vis_Type)
then
null;
-- Save type for subsequent error message, in case no other
-- interpretation is found.
else
Candidate_Type := Vis_Type;
return;
end if;
-- In an instance, an abstract non-dispatching operation cannot be a
-- candidate interpretation, because it could not have been one in the
-- generic (it may be a spurious overloading in the instance).
elsif In_Instance
and then Is_Overloadable (E)
and then Is_Abstract_Subprogram (E)
and then not Is_Dispatching_Operation (E)
then
return;
-- An inherited interface operation that is implemented by some derived
-- type does not participate in overload resolution, only the
-- implementation operation does.
elsif Is_Hidden (E)
and then Is_Subprogram (E)
and then Present (Interface_Alias (E))
then
-- Ada 2005 (AI-251): If this primitive operation corresponds with
-- an immediate ancestor interface there is no need to add it to the
-- list of interpretations. The corresponding aliased primitive is
-- also in this list of primitive operations and will be used instead
-- because otherwise we have a dummy ambiguity between the two
-- subprograms which are in fact the same.
if not Is_Ancestor
(Find_Dispatching_Type (Interface_Alias (E)),
Find_Dispatching_Type (E))
then
Add_One_Interp (N, Interface_Alias (E), T);
-- Otherwise this is the first interpretation, N has type Any_Type
-- and we must place the new type on the node.
else
Set_Etype (N, T);
end if;
return;
-- Calling stubs for an RACW operation never participate in resolution,
-- they are executed only through dispatching calls.
elsif Is_RACW_Stub_Type_Operation (E) then
return;
end if;
-- If this is the first interpretation of N, N has type Any_Type.
-- In that case place the new type on the node. If one interpretation
-- already exists, indicate that the node is overloaded, and store
-- both the previous and the new interpretation in All_Interp. If
-- this is a later interpretation, just add it to the set.
if Etype (N) = Any_Type then
if Is_Type (E) then
Set_Etype (N, T);
else
-- Record both the operator or subprogram name, and its type
if Nkind (N) in N_Op or else Is_Entity_Name (N) then
Set_Entity (N, E);
end if;
Set_Etype (N, T);
end if;
-- Either there is no current interpretation in the table for any
-- node or the interpretation that is present is for a different
-- node. In both cases add a new interpretation to the table.
elsif No (Last_Overloaded)
or else
(Last_Overloaded /= N
and then not Is_Overloaded (N))
then
New_Interps (N);
if (Nkind (N) in N_Op or else Is_Entity_Name (N))
and then Present (Entity (N))
then
Add_Entry (Entity (N), Etype (N));
elsif Nkind (N) in N_Subprogram_Call
and then Is_Entity_Name (Name (N))
then
Add_Entry (Entity (Name (N)), Etype (N));
-- If this is an indirect call there will be no name associated
-- with the previous entry. To make diagnostics clearer, save
-- Subprogram_Type of first interpretation, so that the error will
-- point to the anonymous access to subprogram, not to the result
-- type of the call itself.
elsif (Nkind (N)) = N_Function_Call
and then Nkind (Name (N)) = N_Explicit_Dereference
and then Is_Overloaded (Name (N))
then
declare
It : Interp;
Itn : Interp_Index;
pragma Warnings (Off, Itn);
begin
Get_First_Interp (Name (N), Itn, It);
Add_Entry (It.Nam, Etype (N));
end;
else
-- Overloaded prefix in indexed or selected component, or call
-- whose name is an expression or another call.
Add_Entry (Etype (N), Etype (N));
end if;
Add_Entry (E, T);
else
Add_Entry (E, T);
end if;
end Add_One_Interp;
-------------------
-- All_Overloads --
-------------------
procedure All_Overloads is
begin
for J in All_Interp.First .. All_Interp.Last loop
if Present (All_Interp.Table (J).Nam) then
Write_Entity_Info (All_Interp.Table (J). Nam, " ");
else
Write_Str ("No Interp");
Write_Eol;
end if;
Write_Str ("=================");
Write_Eol;
end loop;
end All_Overloads;
--------------------------------------
-- Binary_Op_Interp_Has_Abstract_Op --
--------------------------------------
function Binary_Op_Interp_Has_Abstract_Op
(N : Node_Id;
E : Entity_Id) return Entity_Id
is
Abstr_Op : Entity_Id;
E_Left : constant Node_Id := First_Formal (E);
E_Right : constant Node_Id := Next_Formal (E_Left);
begin
Abstr_Op := Has_Abstract_Op (Left_Opnd (N), Etype (E_Left));
if Present (Abstr_Op) then
return Abstr_Op;
end if;
return Has_Abstract_Op (Right_Opnd (N), Etype (E_Right));
end Binary_Op_Interp_Has_Abstract_Op;
---------------------
-- Collect_Interps --
---------------------
procedure Collect_Interps (N : Node_Id) is
Ent : constant Entity_Id := Entity (N);
H : Entity_Id;
First_Interp : Interp_Index;
function Within_Instance (E : Entity_Id) return Boolean;
-- Within an instance there can be spurious ambiguities between a local
-- entity and one declared outside of the instance. This can only happen
-- for subprograms, because otherwise the local entity hides the outer
-- one. For an overloadable entity, this predicate determines whether it
-- is a candidate within the instance, or must be ignored.
---------------------
-- Within_Instance --
---------------------
function Within_Instance (E : Entity_Id) return Boolean is
Inst : Entity_Id;
Scop : Entity_Id;
begin
if not In_Instance then
return False;
end if;
Inst := Current_Scope;
while Present (Inst) and then not Is_Generic_Instance (Inst) loop
Inst := Scope (Inst);
end loop;
Scop := Scope (E);
while Present (Scop) and then Scop /= Standard_Standard loop
if Scop = Inst then
return True;
end if;
Scop := Scope (Scop);
end loop;
return False;
end Within_Instance;
-- Start of processing for Collect_Interps
begin
New_Interps (N);
-- Unconditionally add the entity that was initially matched
First_Interp := All_Interp.Last;
Add_One_Interp (N, Ent, Etype (N));
-- For expanded name, pick up all additional entities from the
-- same scope, since these are obviously also visible. Note that
-- these are not necessarily contiguous on the homonym chain.
if Nkind (N) = N_Expanded_Name then
H := Homonym (Ent);
while Present (H) loop
if Scope (H) = Scope (Entity (N)) then
Add_One_Interp (N, H, Etype (H));
end if;
H := Homonym (H);
end loop;
-- Case of direct name
else
-- First, search the homonym chain for directly visible entities
H := Current_Entity (Ent);
while Present (H) loop
exit when
not Is_Overloadable (H)
and then Is_Immediately_Visible (H);
if Is_Immediately_Visible (H) and then H /= Ent then
-- Only add interpretation if not hidden by an inner
-- immediately visible one.
for J in First_Interp .. All_Interp.Last - 1 loop
-- Current homograph is not hidden. Add to overloads
if not Is_Immediately_Visible (All_Interp.Table (J).Nam) then
exit;
-- Homograph is hidden, unless it is a predefined operator
elsif Type_Conformant (H, All_Interp.Table (J).Nam) then
-- A homograph in the same scope can occur within an
-- instantiation, the resulting ambiguity has to be
-- resolved later. The homographs may both be local
-- functions or actuals, or may be declared at different
-- levels within the instance. The renaming of an actual
-- within the instance must not be included.
if Within_Instance (H)
and then H /= Renamed_Entity (Ent)
and then not Is_Inherited_Operation (H)
then
All_Interp.Table (All_Interp.Last) :=
(H, Etype (H), Empty);
All_Interp.Append (No_Interp);
goto Next_Homograph;
elsif Scope (H) /= Standard_Standard then
goto Next_Homograph;
end if;
end if;
end loop;
-- On exit, we know that current homograph is not hidden
Add_One_Interp (N, H, Etype (H));
if Debug_Flag_E then
Write_Str ("Add overloaded interpretation ");
Write_Int (Int (H));
Write_Eol;
end if;
end if;
<<Next_Homograph>>
H := Homonym (H);
end loop;
-- Scan list of homographs for use-visible entities only
H := Current_Entity (Ent);
while Present (H) loop
if Is_Potentially_Use_Visible (H)
and then H /= Ent
and then Is_Overloadable (H)
then
for J in First_Interp .. All_Interp.Last - 1 loop
if not Is_Immediately_Visible (All_Interp.Table (J).Nam) then
exit;
elsif Type_Conformant (H, All_Interp.Table (J).Nam) then
goto Next_Use_Homograph;
end if;
end loop;
Add_One_Interp (N, H, Etype (H));
end if;
<<Next_Use_Homograph>>
H := Homonym (H);
end loop;
end if;
if All_Interp.Last = First_Interp + 1 then
-- The final interpretation is in fact not overloaded. Note that the
-- unique legal interpretation may or may not be the original one,
-- so we need to update N's entity and etype now, because once N
-- is marked as not overloaded it is also expected to carry the
-- proper interpretation.
Set_Is_Overloaded (N, False);
Set_Entity (N, All_Interp.Table (First_Interp).Nam);
Set_Etype (N, All_Interp.Table (First_Interp).Typ);
end if;
end Collect_Interps;
------------
-- Covers --
------------
function Covers (T1, T2 : Entity_Id) return Boolean is
BT1 : Entity_Id;
BT2 : Entity_Id;
function Full_View_Covers (Typ1, Typ2 : Entity_Id) return Boolean;
-- In an instance the proper view may not always be correct for
-- private types, but private and full view are compatible. This
-- removes spurious errors from nested instantiations that involve,
-- among other things, types derived from private types.
function Real_Actual (T : Entity_Id) return Entity_Id;
-- If an actual in an inner instance is the formal of an enclosing
-- generic, the actual in the enclosing instance is the one that can
-- create an accidental ambiguity, and the check on compatibility of
-- generic actual types must use this enclosing actual.
----------------------
-- Full_View_Covers --
----------------------
function Full_View_Covers (Typ1, Typ2 : Entity_Id) return Boolean is
begin
if Present (Full_View (Typ1))
and then Covers (Full_View (Typ1), Typ2)
then
return True;
elsif Present (Underlying_Full_View (Typ1))
and then Covers (Underlying_Full_View (Typ1), Typ2)
then
return True;
else
return False;
end if;
end Full_View_Covers;
-----------------
-- Real_Actual --
-----------------
function Real_Actual (T : Entity_Id) return Entity_Id is
Par : constant Node_Id := Parent (T);
RA : Entity_Id;
begin
-- Retrieve parent subtype from subtype declaration for actual
if Nkind (Par) = N_Subtype_Declaration
and then not Comes_From_Source (Par)
and then Is_Entity_Name (Subtype_Indication (Par))
then
RA := Entity (Subtype_Indication (Par));
if Is_Generic_Actual_Type (RA) then
return RA;
end if;
end if;
-- Otherwise actual is not the actual of an enclosing instance
return T;
end Real_Actual;
-- Start of processing for Covers
begin
-- If either operand is missing, then this is an error, but ignore it
-- and pretend we have a cover if errors already detected since this may
-- simply mean we have malformed trees or a semantic error upstream.
if No (T1) or else No (T2) then
if Total_Errors_Detected /= 0 then
return True;
else
raise Program_Error;
end if;
end if;
-- Trivial case: same types are always compatible
if T1 = T2 then
return True;
end if;
-- First check for Standard_Void_Type, which is special. Subsequent
-- processing in this routine assumes T1 and T2 are bona fide types;
-- Standard_Void_Type is a special entity that has some, but not all,
-- properties of types.
if T1 = Standard_Void_Type or else T2 = Standard_Void_Type then
return False;
end if;
BT1 := Base_Type (T1);
BT2 := Base_Type (T2);
-- Handle underlying view of records with unknown discriminants
-- using the original entity that motivated the construction of
-- this underlying record view (see Build_Derived_Private_Type).
if Is_Underlying_Record_View (BT1) then
BT1 := Underlying_Record_View (BT1);
end if;
if Is_Underlying_Record_View (BT2) then
BT2 := Underlying_Record_View (BT2);
end if;
-- Simplest case: types that have the same base type and are not generic
-- actuals are compatible. Generic actuals belong to their class but are
-- not compatible with other types of their class, and in particular
-- with other generic actuals. They are however compatible with their
-- own subtypes, and itypes with the same base are compatible as well.
-- Similarly, constrained subtypes obtained from expressions of an
-- unconstrained nominal type are compatible with the base type (may
-- lead to spurious ambiguities in obscure cases ???)
-- Generic actuals require special treatment to avoid spurious ambi-
-- guities in an instance, when two formal types are instantiated with
-- the same actual, so that different subprograms end up with the same
-- signature in the instance. If a generic actual is the actual of an
-- enclosing instance, it is that actual that we must compare: generic
-- actuals are only incompatible if they appear in the same instance.
if BT1 = BT2
or else BT1 = T2
or else BT2 = T1
then
if not Is_Generic_Actual_Type (T1)
or else
not Is_Generic_Actual_Type (T2)
then
return True;
-- Both T1 and T2 are generic actual types
else
declare
RT1 : constant Entity_Id := Real_Actual (T1);
RT2 : constant Entity_Id := Real_Actual (T2);
begin
return RT1 = RT2
or else Is_Itype (T1)
or else Is_Itype (T2)
or else Is_Constr_Subt_For_U_Nominal (T1)
or else Is_Constr_Subt_For_U_Nominal (T2)
or else Scope (RT1) /= Scope (RT2);
end;
end if;
-- This test may seem to be redundant with the above one, but it catches
-- peculiar cases where a private type declared in a package is used in
-- a generic construct declared in another package, and the body of the
-- former package contains an instantiation of the generic construct on
-- an object whose type is a subtype of the private type; in this case,
-- the subtype is not private but the type is private in the instance.
elsif Is_Subtype_Of (T1 => T2, T2 => T1) then
return True;
-- Literals are compatible with types in a given "class"
elsif (T2 = Universal_Integer and then Is_Integer_Type (T1))
or else (T2 = Universal_Real and then Is_Real_Type (T1))
or else (T2 = Universal_Fixed and then Is_Fixed_Point_Type (T1))
or else (T2 = Universal_Access and then Is_Access_Type (T1))
or else (T2 = Any_Fixed and then Is_Fixed_Point_Type (T1))
or else (T2 = Any_Character and then Is_Character_Type (T1))
or else (T2 = Any_String and then Is_String_Type (T1))
then
return True;
-- The context may be class wide, and a class-wide type is compatible
-- with any member of the class.
elsif Is_Class_Wide_Type (T1)
and then Is_Ancestor (Root_Type (T1), T2)
then
return True;
elsif Is_Class_Wide_Type (T1)
and then Is_Class_Wide_Type (T2)
and then Base_Type (Etype (T1)) = Base_Type (Etype (T2))
then
return True;
-- Ada 2005 (AI-345): A class-wide abstract interface type covers a
-- task_type or protected_type that implements the interface.
elsif Ada_Version >= Ada_2005
and then Is_Concurrent_Type (T2)
and then Is_Class_Wide_Type (T1)
and then Is_Interface (Etype (T1))
and then Interface_Present_In_Ancestor
(Typ => BT2, Iface => Etype (T1))
then
return True;
-- Ada 2005 (AI-251): A class-wide abstract interface type T1 covers an
-- object T2 implementing T1.
elsif Ada_Version >= Ada_2005
and then Is_Tagged_Type (T2)
and then Is_Class_Wide_Type (T1)
and then Is_Interface (Etype (T1))
then
if Interface_Present_In_Ancestor (Typ => T2,
Iface => Etype (T1))
then
return True;
end if;
declare
E : Entity_Id;
Elmt : Elmt_Id;
begin
if Is_Concurrent_Type (BT2) then
E := Corresponding_Record_Type (BT2);
else
E := BT2;
end if;
-- Ada 2005 (AI-251): A class-wide abstract interface type T1
-- covers an object T2 that implements a direct derivation of T1.
-- Note: test for presence of E is defense against previous error.
if No (E) then
Check_Error_Detected;
-- Here we have a corresponding record type
elsif Present (Interfaces (E)) then
Elmt := First_Elmt (Interfaces (E));
while Present (Elmt) loop
if Is_Ancestor (Etype (T1), Node (Elmt)) then
return True;
else
Next_Elmt (Elmt);
end if;
end loop;
end if;
-- We should also check the case in which T1 is an ancestor of
-- some implemented interface???
return False;
end;
-- In a dispatching call, the formal is of some specific type, and the
-- actual is of the corresponding class-wide type, including a subtype
-- of the class-wide type.
elsif Is_Class_Wide_Type (T2)
and then
(Class_Wide_Type (T1) = Class_Wide_Type (T2)
or else Base_Type (Root_Type (T2)) = BT1)
then
return True;
-- Some contexts require a class of types rather than a specific type.
-- For example, conditions require any boolean type, fixed point
-- attributes require some real type, etc. The built-in types Any_XXX
-- represent these classes.
elsif (T1 = Any_Integer and then Is_Integer_Type (T2))
or else (T1 = Any_Boolean and then Is_Boolean_Type (T2))
or else (T1 = Any_Real and then Is_Real_Type (T2))
or else (T1 = Any_Fixed and then Is_Fixed_Point_Type (T2))
or else (T1 = Any_Discrete and then Is_Discrete_Type (T2))
then
return True;
-- An aggregate is compatible with an array or record type
elsif T2 = Any_Composite and then Is_Aggregate_Type (T1) then
return True;
-- In Ada_2022, an aggregate is compatible with the type that
-- as the corresponding aspect.
elsif Ada_Version >= Ada_2022
and then T2 = Any_Composite
and then Has_Aspect (T1, Aspect_Aggregate)
then
return True;
-- If the expected type is an anonymous access, the designated type must
-- cover that of the expression. Use the base type for this check: even
-- though access subtypes are rare in sources, they are generated for
-- actuals in instantiations.
elsif Ekind (BT1) = E_Anonymous_Access_Type
and then Is_Access_Type (T2)
and then Covers (Designated_Type (T1), Designated_Type (T2))
then
return True;
-- Ada 2012 (AI05-0149): Allow an anonymous access type in the context
-- of a named general access type. An implicit conversion will be
-- applied. For the resolution, the designated types must match if
-- untagged; further, if the designated type is tagged, the designated
-- type of the anonymous access type shall be covered by the designated
-- type of the named access type.
elsif Ada_Version >= Ada_2012
and then Ekind (BT1) = E_General_Access_Type
and then Ekind (BT2) = E_Anonymous_Access_Type
and then Covers (Designated_Type (T1), Designated_Type (T2))
and then Is_Class_Wide_Type (Designated_Type (T1)) >=
Is_Class_Wide_Type (Designated_Type (T2))
then
return True;
-- An Access_To_Subprogram is compatible with itself, or with an
-- anonymous type created for an attribute reference Access.
elsif Ekind (BT1) in E_Access_Subprogram_Type
| E_Access_Protected_Subprogram_Type
and then Is_Access_Type (T2)
and then (not Comes_From_Source (T1)
or else not Comes_From_Source (T2))
and then (Is_Overloadable (Designated_Type (T2))
or else Ekind (Designated_Type (T2)) = E_Subprogram_Type)
and then Type_Conformant (Designated_Type (T1), Designated_Type (T2))
and then Mode_Conformant (Designated_Type (T1), Designated_Type (T2))
then
return True;
-- Ada 2005 (AI-254): An Anonymous_Access_To_Subprogram is compatible
-- with itself, or with an anonymous type created for an attribute
-- reference Access.
elsif Ekind (BT1) in E_Anonymous_Access_Subprogram_Type
| E_Anonymous_Access_Protected_Subprogram_Type
and then Is_Access_Type (T2)
and then (not Comes_From_Source (T1)
or else not Comes_From_Source (T2))
and then (Is_Overloadable (Designated_Type (T2))
or else Ekind (Designated_Type (T2)) = E_Subprogram_Type)
and then Type_Conformant (Designated_Type (T1), Designated_Type (T2))
and then Mode_Conformant (Designated_Type (T1), Designated_Type (T2))
then
return True;
-- The context can be a remote access type, and the expression the
-- corresponding source type declared in a categorized package, or
-- vice versa.
elsif Is_Record_Type (T1)
and then (Is_Remote_Call_Interface (T1) or else Is_Remote_Types (T1))
and then Present (Corresponding_Remote_Type (T1))
then
return Covers (Corresponding_Remote_Type (T1), T2);
-- and conversely.
elsif Is_Record_Type (T2)
and then (Is_Remote_Call_Interface (T2) or else Is_Remote_Types (T2))
and then Present (Corresponding_Remote_Type (T2))
then
return Covers (Corresponding_Remote_Type (T2), T1);
-- Synchronized types are represented at run time by their corresponding
-- record type. During expansion one is replaced with the other, but
-- they are compatible views of the same type.
elsif Is_Record_Type (T1)
and then Is_Concurrent_Type (T2)
and then Present (Corresponding_Record_Type (T2))
then
return Covers (T1, Corresponding_Record_Type (T2));
elsif Is_Concurrent_Type (T1)
and then Present (Corresponding_Record_Type (T1))
and then Is_Record_Type (T2)
then
return Covers (Corresponding_Record_Type (T1), T2);
-- During analysis, an attribute reference 'Access has a special type
-- kind: Access_Attribute_Type, to be replaced eventually with the type
-- imposed by context.
elsif Ekind (T2) = E_Access_Attribute_Type
and then Ekind (BT1) in E_General_Access_Type | E_Access_Type
and then Covers (Designated_Type (T1), Designated_Type (T2))
then
-- If the target type is a RACW type while the source is an access
-- attribute type, we are building a RACW that may be exported.
if Is_Remote_Access_To_Class_Wide_Type (BT1) then
Set_Has_RACW (Current_Sem_Unit);
end if;
return True;
-- Ditto for allocators, which eventually resolve to the context type
elsif Ekind (T2) = E_Allocator_Type and then Is_Access_Type (T1) then
return Covers (Designated_Type (T1), Designated_Type (T2))
or else
(From_Limited_With (Designated_Type (T1))
and then Covers (Designated_Type (T2), Designated_Type (T1)));
-- A boolean operation on integer literals is compatible with modular
-- context.
elsif T2 = Any_Modular and then Is_Modular_Integer_Type (T1) then
return True;
-- The actual type may be the result of a previous error
elsif BT2 = Any_Type then
return True;
-- A Raise_Expressions is legal in any expression context
elsif BT2 = Raise_Type then
return True;
-- A packed array type covers its corresponding non-packed type. This is
-- not legitimate Ada, but allows the omission of a number of otherwise
-- useless unchecked conversions, and since this can only arise in
-- (known correct) expanded code, no harm is done.
elsif Is_Packed_Array (T2)
and then T1 = Packed_Array_Impl_Type (T2)
then
return True;
-- Similarly an array type covers its corresponding packed array type
elsif Is_Packed_Array (T1)
and then T2 = Packed_Array_Impl_Type (T1)
then
return True;
-- With types exported from instantiations, check whether a partial and
-- a full view match. Verify that types are legal, to prevent cascaded
-- errors.
elsif Is_Private_Type (T1)
and then Is_Type (T2)
and then Is_Generic_Actual_Type (T2)
and then Full_View_Covers (T1, T2)
then
return True;
elsif Is_Private_Type (T2)
and then Is_Type (T1)
and then Is_Generic_Actual_Type (T1)
and then Full_View_Covers (T2, T1)
then
return True;
-- In the expansion of inlined bodies, types are compatible if they
-- are structurally equivalent.
elsif In_Inlined_Body
and then (Underlying_Type (T1) = Underlying_Type (T2)
or else
(Is_Access_Type (T1)
and then Is_Access_Type (T2)
and then Designated_Type (T1) = Designated_Type (T2))
or else
(T1 = Universal_Access
and then Is_Access_Type (Underlying_Type (T2)))
or else
(T2 = Any_Composite
and then Is_Composite_Type (Underlying_Type (T1))))
then
return True;
-- Ada 2005 (AI-50217): Additional branches to make the shadow entity
-- obtained through a limited_with compatible with its real entity.
elsif From_Limited_With (T1) then
-- If the expected type is the nonlimited view of a type, the
-- expression may have the limited view. If that one in turn is
-- incomplete, get full view if available.
return Has_Non_Limited_View (T1)
and then Covers (Get_Full_View (Non_Limited_View (T1)), T2);
elsif From_Limited_With (T2) then
-- If units in the context have Limited_With clauses on each other,
-- either type might have a limited view. Checks performed elsewhere
-- verify that the context type is the nonlimited view.
return Has_Non_Limited_View (T2)
and then Covers (T1, Get_Full_View (Non_Limited_View (T2)));
-- Ada 2005 (AI-412): Coverage for regular incomplete subtypes
elsif Ekind (T1) = E_Incomplete_Subtype then
return Covers (Full_View (Etype (T1)), T2);
elsif Ekind (T2) = E_Incomplete_Subtype then
return Covers (T1, Full_View (Etype (T2)));
-- Ada 2005 (AI-423): Coverage of formal anonymous access types
-- and actual anonymous access types in the context of generic
-- instantiations. We have the following situation:
-- generic
-- type Formal is private;
-- Formal_Obj : access Formal; -- T1
-- package G is ...
-- package P is
-- type Actual is ...
-- Actual_Obj : access Actual; -- T2
-- package Instance is new G (Formal => Actual,
-- Formal_Obj => Actual_Obj);
elsif Ada_Version >= Ada_2005
and then Is_Anonymous_Access_Type (T1)
and then Is_Anonymous_Access_Type (T2)
and then Is_Generic_Type (Directly_Designated_Type (T1))
and then Get_Instance_Of (Directly_Designated_Type (T1)) =
Directly_Designated_Type (T2)
then
return True;
-- Otherwise, types are not compatible
else
return False;
end if;
end Covers;
------------------
-- Disambiguate --
------------------
function Disambiguate
(N : Node_Id;
I1, I2 : Interp_Index;
Typ : Entity_Id) return Interp
is
I : Interp_Index;
It : Interp;
It1, It2 : Interp;
Nam1, Nam2 : Entity_Id;
Predef_Subp : Entity_Id;
User_Subp : Entity_Id;
function Inherited_From_Actual (S : Entity_Id) return Boolean;
-- Determine whether one of the candidates is an operation inherited by
-- a type that is derived from an actual in an instantiation.
function In_Same_Declaration_List
(Typ : Entity_Id;
Op_Decl : Entity_Id) return Boolean;
-- AI05-0020: a spurious ambiguity may arise when equality on anonymous
-- access types is declared on the partial view of a designated type, so
-- that the type declaration and equality are not in the same list of
-- declarations. This AI gives a preference rule for the user-defined
-- operation. Same rule applies for arithmetic operations on private
-- types completed with fixed-point types: the predefined operation is
-- hidden; this is already handled properly in GNAT.
function Is_Actual_Subprogram (S : Entity_Id) return Boolean;
-- Determine whether a subprogram is an actual in an enclosing instance.
-- An overloading between such a subprogram and one declared outside the
-- instance is resolved in favor of the first, because it resolved in
-- the generic. Within the instance the actual is represented by a
-- constructed subprogram renaming.
function Matches (Op : Node_Id; Func_Id : Entity_Id) return Boolean;
-- Determine whether function Func_Id is an exact match for binary or
-- unary operator Op.
function Operand_Type return Entity_Id;
-- Determine type of operand for an equality operation, to apply Ada
-- 2005 rules to equality on anonymous access types.
function Standard_Operator return Boolean;
-- Check whether subprogram is predefined operator declared in Standard.
-- It may given by an operator name, or by an expanded name whose prefix
-- is Standard.
function Remove_Conversions_And_Abstract_Operations return Interp;
-- Last chance for pathological cases involving comparisons on literals,
-- and user overloadings of the same operator. Such pathologies have
-- been removed from the ACVC, but still appear in two DEC tests, with
-- the following notable quote from Ben Brosgol:
--
-- [Note: I disclaim all credit/responsibility/blame for coming up with
-- this example; Robert Dewar brought it to our attention, since it is
-- apparently found in the ACVC 1.5. I did not attempt to find the
-- reason in the Reference Manual that makes the example legal, since I
-- was too nauseated by it to want to pursue it further.]
--
-- Accordingly, this is not a fully recursive solution, but it handles
-- DEC tests c460vsa, c460vsb. It also handles ai00136a, which pushes
-- pathology in the other direction with calls whose multiple overloaded
-- actuals make them truly unresolvable.
-- The new rules concerning abstract operations create additional need
-- for special handling of expressions with universal operands, see
-- comments to Has_Abstract_Interpretation below.
function Is_User_Defined_Anonymous_Access_Equality
(User_Subp, Predef_Subp : Entity_Id) return Boolean;
-- Check for Ada 2005, AI-020: If the context involves an anonymous
-- access operand, recognize a user-defined equality (User_Subp) with
-- the proper signature, declared in the same declarative list as the
-- type and not hiding a predefined equality Predef_Subp.
---------------------------
-- Inherited_From_Actual --
---------------------------
function Inherited_From_Actual (S : Entity_Id) return Boolean is
Par : constant Node_Id := Parent (S);
begin
if Nkind (Par) /= N_Full_Type_Declaration
or else Nkind (Type_Definition (Par)) /= N_Derived_Type_Definition
then
return False;
else
return Is_Entity_Name (Subtype_Indication (Type_Definition (Par)))
and then
Is_Generic_Actual_Type (
Entity (Subtype_Indication (Type_Definition (Par))));
end if;
end Inherited_From_Actual;
------------------------------
-- In_Same_Declaration_List --
------------------------------
function In_Same_Declaration_List
(Typ : Entity_Id;
Op_Decl : Entity_Id) return Boolean
is
Scop : constant Entity_Id := Scope (Typ);
begin
return In_Same_List (Parent (Typ), Op_Decl)
or else
(Is_Package_Or_Generic_Package (Scop)
and then List_Containing (Op_Decl) =
Visible_Declarations (Parent (Scop))
and then List_Containing (Parent (Typ)) =
Private_Declarations (Parent (Scop)));
end In_Same_Declaration_List;
--------------------------
-- Is_Actual_Subprogram --
--------------------------
function Is_Actual_Subprogram (S : Entity_Id) return Boolean is
begin
return In_Open_Scopes (Scope (S))
and then Nkind (Unit_Declaration_Node (S)) =
N_Subprogram_Renaming_Declaration
-- Determine if the renaming came from source or was generated as a
-- a result of generic expansion since the actual is represented by
-- a constructed subprogram renaming.
and then not Comes_From_Source (Unit_Declaration_Node (S))
and then
(Is_Generic_Instance (Scope (S))
or else Is_Wrapper_Package (Scope (S)));
end Is_Actual_Subprogram;
-------------
-- Matches --
-------------
function Matches (Op : Node_Id; Func_Id : Entity_Id) return Boolean is
function Matching_Types
(Opnd_Typ : Entity_Id;
Formal_Typ : Entity_Id) return Boolean;
-- Determine whether operand type Opnd_Typ and formal parameter type
-- Formal_Typ are either the same or compatible.
--------------------
-- Matching_Types --
--------------------
function Matching_Types
(Opnd_Typ : Entity_Id;
Formal_Typ : Entity_Id) return Boolean
is
begin
-- A direct match
if Opnd_Typ = Formal_Typ then
return True;
-- Any integer type matches universal integer
elsif Opnd_Typ = Universal_Integer
and then Is_Integer_Type (Formal_Typ)
then
return True;
-- Any floating point type matches universal real
elsif Opnd_Typ = Universal_Real
and then Is_Floating_Point_Type (Formal_Typ)
then
return True;
-- The type of the formal parameter maps a generic actual type to
-- a generic formal type. If the operand type is the type being
-- mapped in an instance, then this is a match.
elsif Is_Generic_Actual_Type (Formal_Typ)
and then Etype (Formal_Typ) = Opnd_Typ
then
return True;
-- Formal_Typ is a private view, or Opnd_Typ and Formal_Typ are
-- compatible only on a base-type basis.
else
return False;
end if;
end Matching_Types;
-- Local variables
F1 : constant Entity_Id := First_Formal (Func_Id);
F1_Typ : constant Entity_Id := Etype (F1);
F2 : constant Entity_Id := Next_Formal (F1);
F2_Typ : constant Entity_Id := Etype (F2);
Lop_Typ : constant Entity_Id := Etype (Left_Opnd (Op));
Rop_Typ : constant Entity_Id := Etype (Right_Opnd (Op));
-- Start of processing for Matches
begin
if Lop_Typ = F1_Typ then
return Matching_Types (Rop_Typ, F2_Typ);
elsif Rop_Typ = F2_Typ then
return Matching_Types (Lop_Typ, F1_Typ);
-- Otherwise this is not a good match because each operand-formal
-- pair is compatible only on base-type basis, which is not specific
-- enough.
else
return False;
end if;
end Matches;
------------------
-- Operand_Type --
------------------
function Operand_Type return Entity_Id is
Opnd : Node_Id;
begin
if Nkind (N) = N_Function_Call then
Opnd := First_Actual (N);
else
Opnd := Left_Opnd (N);
end if;
return Etype (Opnd);
end Operand_Type;
------------------------------------------------
-- Remove_Conversions_And_Abstract_Operations --
------------------------------------------------
function Remove_Conversions_And_Abstract_Operations return Interp is
I : Interp_Index;
It : Interp;
It1 : Interp;
F1 : Entity_Id;
Act1 : Node_Id;
Act2 : Node_Id;
function Has_Abstract_Interpretation (N : Node_Id) return Boolean;
-- If an operation has universal operands, the universal operation
-- is present among its interpretations. If there is an abstract
-- interpretation for the operator, with a numeric result, this
-- interpretation was already removed in sem_ch4, but the universal
-- one is still visible. We must rescan the list of operators and
-- remove the universal interpretation to resolve the ambiguity.
function Is_Numeric_Only_Type (T : Entity_Id) return Boolean;
-- Return True if T is a numeric type and not Any_Type
---------------------------------
-- Has_Abstract_Interpretation --
---------------------------------
function Has_Abstract_Interpretation (N : Node_Id) return Boolean is
E : Entity_Id;
begin
if Nkind (N) not in N_Op
or else Ada_Version < Ada_2005
or else not Is_Overloaded (N)
or else No (Universal_Interpretation (N))
then
return False;
else
E := Get_Name_Entity_Id (Chars (N));
while Present (E) loop
if Is_Overloadable (E)
and then Is_Abstract_Subprogram (E)
and then Is_Numeric_Only_Type (Etype (E))
then
return True;
else
E := Homonym (E);
end if;
end loop;
-- Finally, if an operand of the binary operator is itself
-- an operator, recurse to see whether its own abstract
-- interpretation is responsible for the spurious ambiguity.
if Nkind (N) in N_Binary_Op then
return Has_Abstract_Interpretation (Left_Opnd (N))
or else Has_Abstract_Interpretation (Right_Opnd (N));
elsif Nkind (N) in N_Unary_Op then
return Has_Abstract_Interpretation (Right_Opnd (N));
else
return False;
end if;
end if;
end Has_Abstract_Interpretation;
--------------------------
-- Is_Numeric_Only_Type --
--------------------------
function Is_Numeric_Only_Type (T : Entity_Id) return Boolean is
begin
return Is_Numeric_Type (T) and then T /= Any_Type;
end Is_Numeric_Only_Type;
-- Start of processing for Remove_Conversions_And_Abstract_Operations
begin
It1 := No_Interp;
Get_First_Interp (N, I, It);
while Present (It.Typ) loop
if not Is_Overloadable (It.Nam) then
return No_Interp;
end if;
F1 := First_Formal (It.Nam);
if No (F1) then
return It1;
else
if Nkind (N) in N_Subprogram_Call then
Act1 := First_Actual (N);
if Present (Act1) then
Act2 := Next_Actual (Act1);
else
Act2 := Empty;
end if;
elsif Nkind (N) in N_Unary_Op then
Act1 := Right_Opnd (N);
Act2 := Empty;
elsif Nkind (N) in N_Binary_Op then
Act1 := Left_Opnd (N);
Act2 := Right_Opnd (N);
-- Use the type of the second formal, so as to include
-- exponentiation, where the exponent may be ambiguous and
-- the result non-universal.
Next_Formal (F1);
else
return It1;
end if;
if Nkind (Act1) in N_Op
and then Is_Overloaded (Act1)
and then
(Nkind (Act1) in N_Unary_Op
or else Nkind (Left_Opnd (Act1)) in
N_Integer_Literal | N_Real_Literal)
and then Nkind (Right_Opnd (Act1)) in
N_Integer_Literal | N_Real_Literal
and then Has_Compatible_Type (Act1, Standard_Boolean)
and then Etype (F1) = Standard_Boolean
then
-- If the two candidates are the original ones, the
-- ambiguity is real. Otherwise keep the original, further
-- calls to Disambiguate will take care of others in the
-- list of candidates.
if It1 /= No_Interp then
if It = Disambiguate.It1
or else It = Disambiguate.It2
then
if It1 = Disambiguate.It1
or else It1 = Disambiguate.It2
then
return No_Interp;
else
It1 := It;
end if;
end if;
elsif Present (Act2)
and then Nkind (Act2) in N_Op
and then Is_Overloaded (Act2)
and then Nkind (Right_Opnd (Act2)) in
N_Integer_Literal | N_Real_Literal
and then Has_Compatible_Type (Act2, Standard_Boolean)
then
-- The preference rule on the first actual is not
-- sufficient to disambiguate.
goto Next_Interp;
else
It1 := It;
end if;
elsif Is_Numeric_Only_Type (Etype (F1))
and then Has_Abstract_Interpretation (Act1)
then
-- Current interpretation is not the right one because it
-- expects a numeric operand. Examine all the others.
declare
I : Interp_Index;
It : Interp;
begin
Get_First_Interp (N, I, It);
while Present (It.Typ) loop
if not Is_Numeric_Only_Type
(Etype (First_Formal (It.Nam)))
then
if No (Act2)
or else not
Is_Numeric_Only_Type
(Etype (Next_Formal (First_Formal (It.Nam))))
or else not Has_Abstract_Interpretation (Act2)
then
return It;
end if;
end if;
Get_Next_Interp (I, It);
end loop;
return No_Interp;
end;
elsif Is_Numeric_Only_Type (Etype (F1))
and then Present (Act2)
and then Has_Abstract_Interpretation (Act2)
then
-- Current interpretation is not the right one because it
-- expects a numeric operand. Examine all the others.
declare
I : Interp_Index;
It : Interp;
begin
Get_First_Interp (N, I, It);
while Present (It.Typ) loop
if not Is_Numeric_Only_Type
(Etype (Next_Formal (First_Formal (It.Nam))))
then
if not Is_Numeric_Only_Type
(Etype (First_Formal (It.Nam)))
or else not Has_Abstract_Interpretation (Act1)
then
return It;
end if;
end if;
Get_Next_Interp (I, It);
end loop;
return No_Interp;
end;
end if;
end if;
<<Next_Interp>>
Get_Next_Interp (I, It);
end loop;
return It1;
end Remove_Conversions_And_Abstract_Operations;
-----------------------
-- Standard_Operator --
-----------------------
function Standard_Operator return Boolean is
Nam : Node_Id;
begin
if Nkind (N) in N_Op then
return True;
elsif Nkind (N) = N_Function_Call then
Nam := Name (N);
if Nkind (Nam) /= N_Expanded_Name then
return True;
else
return Entity (Prefix (Nam)) = Standard_Standard;
end if;
else
return False;
end if;
end Standard_Operator;
-----------------------------------------------
-- Is_User_Defined_Anonymous_Access_Equality --
-----------------------------------------------
function Is_User_Defined_Anonymous_Access_Equality
(User_Subp, Predef_Subp : Entity_Id) return Boolean is
begin
return Present (User_Subp)
-- Check for Ada 2005 and use of anonymous access
and then Ada_Version >= Ada_2005
and then Etype (User_Subp) = Standard_Boolean
and then Is_Anonymous_Access_Type (Operand_Type)
-- This check is only relevant if User_Subp is visible and not in
-- an instance
and then (In_Open_Scopes (Scope (User_Subp))
or else Is_Potentially_Use_Visible (User_Subp))
and then not In_Instance
and then not Hides_Op (User_Subp, Predef_Subp)
-- Is User_Subp declared in the same declarative list as the type?
and then
In_Same_Declaration_List
(Designated_Type (Operand_Type),
Unit_Declaration_Node (User_Subp));
end Is_User_Defined_Anonymous_Access_Equality;
-- Start of processing for Disambiguate
begin
-- Recover the two legal interpretations
Get_First_Interp (N, I, It);
while I /= I1 loop
Get_Next_Interp (I, It);
end loop;
It1 := It;
Nam1 := It.Nam;
while I /= I2 loop
Get_Next_Interp (I, It);
end loop;
It2 := It;
Nam2 := It.Nam;
-- Check whether one of the entities is an Ada 2005/2012/2022 and we
-- are operating in an earlier mode, in which case we discard the Ada
-- 2005/2012/2022 entity, so that we get proper Ada 95 overload
-- resolution.
if Ada_Version < Ada_2005 then
if Is_Ada_2005_Only (Nam1)
or else Is_Ada_2012_Only (Nam1)
or else Is_Ada_2022_Only (Nam1)
then
return It2;
elsif Is_Ada_2005_Only (Nam2)
or else Is_Ada_2012_Only (Nam2)
or else Is_Ada_2022_Only (Nam2)
then
return It1;
end if;
-- Check whether one of the entities is an Ada 2012/2022 entity and we
-- are operating in Ada 2005 mode, in which case we discard the Ada 2012
-- Ada 2022 entity, so that we get proper Ada 2005 overload resolution.
elsif Ada_Version = Ada_2005 then
if Is_Ada_2012_Only (Nam1) or else Is_Ada_2022_Only (Nam1) then
return It2;
elsif Is_Ada_2012_Only (Nam2) or else Is_Ada_2022_Only (Nam2) then
return It1;
end if;
-- Ditto for Ada 2012 vs Ada 2022.
elsif Ada_Version = Ada_2012 then
if Is_Ada_2022_Only (Nam1) then
return It2;
elsif Is_Ada_2022_Only (Nam2) then
return It1;
end if;
end if;
-- If the context is universal, the predefined operator is preferred.
-- This includes bounds in numeric type declarations, and expressions
-- in type conversions. If no interpretation yields a universal type,
-- then we must check whether the user-defined entity hides the prede-
-- fined one.
if Chars (Nam1) in Any_Operator_Name and then Standard_Operator then
if Typ = Universal_Integer
or else Typ = Universal_Real
or else Typ = Any_Integer
or else Typ = Any_Discrete
or else Typ = Any_Real
or else Typ = Any_Type
then
-- Find an interpretation that yields the universal type, or else
-- a predefined operator that yields a predefined numeric type.
declare
Candidate : Interp := No_Interp;
begin
Get_First_Interp (N, I, It);
while Present (It.Typ) loop
if Is_Universal_Numeric_Type (It.Typ)
and then (Typ = Any_Type or else Covers (Typ, It.Typ))
then
return It;
elsif Is_Numeric_Type (It.Typ)
and then Scope (It.Typ) = Standard_Standard
and then Scope (It.Nam) = Standard_Standard
and then Covers (Typ, It.Typ)
then
Candidate := It;
end if;
Get_Next_Interp (I, It);
end loop;
if Candidate /= No_Interp then
return Candidate;
end if;
end;
elsif Chars (Nam1) /= Name_Op_Not
and then (Typ = Standard_Boolean or else Typ = Any_Boolean)
then
-- Equality or comparison operation. Choose predefined operator if
-- arguments are universal. The node may be an operator, name, or
-- a function call, so unpack arguments accordingly.
declare
Arg1, Arg2 : Node_Id;
begin
if Nkind (N) in N_Op then
Arg1 := Left_Opnd (N);
Arg2 := Right_Opnd (N);
elsif Is_Entity_Name (N) then
Arg1 := First_Entity (Entity (N));
Arg2 := Next_Entity (Arg1);
else
Arg1 := First_Actual (N);
Arg2 := Next_Actual (Arg1);
end if;
if Present (Arg2) then
if Ekind (Nam1) = E_Operator then
Predef_Subp := Nam1;
User_Subp := Nam2;
elsif Ekind (Nam2) = E_Operator then
Predef_Subp := Nam2;
User_Subp := Nam1;
else
Predef_Subp := Empty;
User_Subp := Empty;
end if;
-- Take into account universal interpretation as well as
-- universal_access equality, as long as AI05-0020 does not
-- trigger.
if (Present (Universal_Interpretation (Arg1))
and then Universal_Interpretation (Arg2) =
Universal_Interpretation (Arg1))
or else
(Nkind (N) in N_Op_Eq | N_Op_Ne
and then (Is_Anonymous_Access_Type (Etype (Arg1))
or else
Is_Anonymous_Access_Type (Etype (Arg2)))
and then not
Is_User_Defined_Anonymous_Access_Equality
(User_Subp, Predef_Subp))
then
Get_First_Interp (N, I, It);
while Scope (It.Nam) /= Standard_Standard loop
Get_Next_Interp (I, It);
end loop;
return It;
end if;
end if;
end;
end if;
end if;
-- If no universal interpretation, check whether user-defined operator
-- hides predefined one, as well as other special cases. If the node
-- is a range, then one or both bounds are ambiguous. Each will have
-- to be disambiguated w.r.t. the context type. The type of the range
-- itself is imposed by the context, so we can return either legal
-- interpretation.
if Ekind (Nam1) = E_Operator then
Predef_Subp := Nam1;
User_Subp := Nam2;
elsif Ekind (Nam2) = E_Operator then
Predef_Subp := Nam2;
User_Subp := Nam1;
elsif Nkind (N) = N_Range then
return It1;
-- Implement AI05-105: A renaming declaration with an access
-- definition must resolve to an anonymous access type. This
-- is a resolution rule and can be used to disambiguate.
elsif Nkind (Parent (N)) = N_Object_Renaming_Declaration
and then Present (Access_Definition (Parent (N)))
then
if Is_Anonymous_Access_Type (It1.Typ) then
if Ekind (It2.Typ) = Ekind (It1.Typ) then
-- True ambiguity
return No_Interp;
else
return It1;
end if;
elsif Is_Anonymous_Access_Type (It2.Typ) then
return It2;
-- No legal interpretation
else
return No_Interp;
end if;
-- Two access attribute types may have been created for an expression
-- with an implicit dereference, which is automatically overloaded.
-- If both access attribute types designate the same object type,
-- disambiguation if any will take place elsewhere, so keep any one of
-- the interpretations.
elsif Ekind (It1.Typ) = E_Access_Attribute_Type
and then Ekind (It2.Typ) = E_Access_Attribute_Type
and then Designated_Type (It1.Typ) = Designated_Type (It2.Typ)
then
return It1;
-- If two user defined-subprograms are visible, it is a true ambiguity,
-- unless one of them is an entry and the context is a conditional or
-- timed entry call, or unless we are within an instance and this is
-- results from two formals types with the same actual.
else
if Nkind (N) = N_Procedure_Call_Statement
and then Nkind (Parent (N)) = N_Entry_Call_Alternative
and then N = Entry_Call_Statement (Parent (N))
then
if Ekind (Nam2) = E_Entry then
return It2;
elsif Ekind (Nam1) = E_Entry then
return It1;
else
return No_Interp;
end if;
-- If the ambiguity occurs within an instance, it is due to several
-- formal types with the same actual. Look for an exact match between
-- the types of the formals of the overloadable entities, and the
-- actuals in the call, to recover the unambiguous match in the
-- original generic.
-- The ambiguity can also be due to an overloading between a formal
-- subprogram and a subprogram declared outside the generic. If the
-- node is overloaded, it did not resolve to the global entity in
-- the generic, and we choose the formal subprogram.
-- Finally, the ambiguity can be between an explicit subprogram and
-- one inherited (with different defaults) from an actual. In this
-- case the resolution was to the explicit declaration in the
-- generic, and remains so in the instance.
-- The same sort of disambiguation needed for calls is also required
-- for the name given in a subprogram renaming, and that case is
-- handled here as well. We test Comes_From_Source to exclude this
-- treatment for implicit renamings created for formal subprograms.
elsif In_Instance and then not In_Generic_Actual (N) then
if Nkind (N) in N_Subprogram_Call
or else
(Nkind (N) in N_Has_Entity
and then
Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
and then Comes_From_Source (Parent (N)))
then
declare
Actual : Node_Id;
Formal : Entity_Id;
Renam : Entity_Id := Empty;
Is_Act1 : constant Boolean := Is_Actual_Subprogram (Nam1);
Is_Act2 : constant Boolean := Is_Actual_Subprogram (Nam2);
begin
if Is_Act1 and then not Is_Act2 then
return It1;
elsif Is_Act2 and then not Is_Act1 then
return It2;
elsif Inherited_From_Actual (Nam1)
and then Comes_From_Source (Nam2)
then
return It2;
elsif Inherited_From_Actual (Nam2)
and then Comes_From_Source (Nam1)
then
return It1;
end if;
-- In the case of a renamed subprogram, pick up the entity
-- of the renaming declaration so we can traverse its
-- formal parameters.
if Nkind (N) in N_Has_Entity then
Renam := Defining_Unit_Name (Specification (Parent (N)));
end if;
if Present (Renam) then
Actual := First_Formal (Renam);
else
Actual := First_Actual (N);
end if;
Formal := First_Formal (Nam1);
while Present (Actual) loop
if Etype (Actual) /= Etype (Formal) then
return It2;
end if;
if Present (Renam) then
Next_Formal (Actual);
else
Next_Actual (Actual);
end if;
Next_Formal (Formal);
end loop;
return It1;
end;
elsif Nkind (N) in N_Binary_Op then
if Matches (N, Nam1) then
return It1;
else
return It2;
end if;
elsif Nkind (N) in N_Unary_Op then
if Etype (Right_Opnd (N)) = Etype (First_Formal (Nam1)) then
return It1;
else
return It2;
end if;
else
return Remove_Conversions_And_Abstract_Operations;
end if;
else
return Remove_Conversions_And_Abstract_Operations;
end if;
end if;
-- An implicit concatenation operator on a string type cannot be
-- disambiguated from the predefined concatenation. This can only
-- happen with concatenation of string literals.
if Chars (User_Subp) = Name_Op_Concat
and then Ekind (User_Subp) = E_Operator
and then Is_String_Type (Etype (First_Formal (User_Subp)))
then
return No_Interp;
-- If the user-defined operator matches the signature of the operator,
-- and is declared in an open scope, or in the scope of the resulting
-- type, or given by an expanded name that names its scope, it hides
-- the predefined operator for the type. But exponentiation has to be
-- special-cased because the latter operator does not have a symmetric
-- signature, and may not be hidden by the explicit one.
elsif Hides_Op (User_Subp, Predef_Subp)
or else (Nkind (N) = N_Function_Call
and then Nkind (Name (N)) = N_Expanded_Name
and then (Chars (Predef_Subp) /= Name_Op_Expon
or else Hides_Op (User_Subp, Predef_Subp))
and then Scope (User_Subp) = Entity (Prefix (Name (N))))
then
if It1.Nam = User_Subp then
return It1;
else
return It2;
end if;
-- Otherwise, the predefined operator has precedence, or if the user-
-- defined operation is directly visible we have a true ambiguity.
-- If this is a fixed-point multiplication and division in Ada 83 mode,
-- exclude the universal_fixed operator, which often causes ambiguities
-- in legacy code.
-- Ditto in Ada 2012, where an ambiguity may arise for an operation
-- on a partial view that is completed with a fixed point type. See
-- AI05-0020 and AI05-0209. The ambiguity is resolved in favor of the
-- user-defined type and subprogram, so that a client of the package
-- has the same resolution as the body of the package.
else
if (In_Open_Scopes (Scope (User_Subp))
or else Is_Potentially_Use_Visible (User_Subp))
and then not In_Instance
then
if Is_Fixed_Point_Type (Typ)
and then Chars (Nam1) in Name_Op_Multiply | Name_Op_Divide
and then
(Ada_Version = Ada_83
or else (Ada_Version >= Ada_2012
and then In_Same_Declaration_List
(First_Subtype (Typ),
Unit_Declaration_Node (User_Subp))))
then
if It2.Nam = Predef_Subp then
return It1;
else
return It2;
end if;
-- Check for AI05-020
elsif Chars (Nam1) in Name_Op_Eq | Name_Op_Ne
and then Is_User_Defined_Anonymous_Access_Equality
(User_Subp, Predef_Subp)
then
if It2.Nam = Predef_Subp then
return It1;
else
return It2;
end if;
-- RM 8.4(10): an immediately visible operator hides a use-visible
-- user-defined operation that is a homograph. This disambiguation
-- cannot take place earlier because visibility of the predefined
-- operator can only be established when operand types are known.
elsif Ekind (User_Subp) = E_Function
and then Ekind (Predef_Subp) = E_Operator
and then Operator_Matches_Spec (Predef_Subp, User_Subp)
and then Nkind (N) in N_Op
and then not Is_Overloaded (Right_Opnd (N))
and then
Is_Immediately_Visible (Base_Type (Etype (Right_Opnd (N))))
and then Is_Potentially_Use_Visible (User_Subp)
then
if It1.Nam = Predef_Subp then
return It1;
else
return It2;
end if;
else
return Remove_Conversions_And_Abstract_Operations;
end if;
elsif It1.Nam = Predef_Subp then
return It1;
else
return It2;
end if;
end if;
end Disambiguate;
-------------------------
-- Entity_Matches_Spec --
-------------------------
function Entity_Matches_Spec (Old_S, New_S : Entity_Id) return Boolean is
begin
-- For the simple case of same kinds, type conformance is required, but
-- a parameterless function can also rename a literal.
if Ekind (Old_S) = Ekind (New_S)
or else (Ekind (New_S) = E_Function
and then Ekind (Old_S) = E_Enumeration_Literal)
then
return Type_Conformant (New_S, Old_S);
-- Likewise for a procedure and an entry
elsif Ekind (New_S) = E_Procedure and then Is_Entry (Old_S) then
return Type_Conformant (New_S, Old_S);
-- For a user-defined operator, use the dedicated predicate
elsif Ekind (New_S) = E_Function and then Ekind (Old_S) = E_Operator then
return Operator_Matches_Spec (Old_S, New_S);
else
return False;
end if;
end Entity_Matches_Spec;
----------------------
-- Find_Unique_Type --
----------------------
function Find_Unique_Type (L : Node_Id; R : Node_Id) return Entity_Id is
T : constant Entity_Id := Specific_Type (Etype (L), Etype (R));
begin
if T = Any_Type then
if Is_User_Defined_Literal (L, Etype (R)) then
return Etype (R);
elsif Is_User_Defined_Literal (R, Etype (L)) then
return Etype (L);
end if;
end if;
return T;
end Find_Unique_Type;
-------------------------------------
-- Function_Interp_Has_Abstract_Op --
-------------------------------------
function Function_Interp_Has_Abstract_Op
(N : Node_Id;
E : Entity_Id) return Entity_Id
is
Abstr_Op : Entity_Id;
Act : Node_Id;
Act_Parm : Node_Id;
Form_Parm : Node_Id;
begin
if Is_Overloaded (N) then
-- Move through the formals and actuals of the call to
-- determine if an abstract interpretation exists.
Act_Parm := First_Actual (N);
Form_Parm := First_Formal (E);
while Present (Act_Parm) and then Present (Form_Parm) loop
Act := Act_Parm;
-- Extract the actual from a parameter association
if Nkind (Act) = N_Parameter_Association then
Act := Explicit_Actual_Parameter (Act);
end if;
-- Use the actual and the type of its correponding formal to test
-- for an abstract interpretation and return it when found.
Abstr_Op := Has_Abstract_Op (Act, Etype (Form_Parm));
if Present (Abstr_Op) then
return Abstr_Op;
end if;
Next_Actual (Act_Parm);
Next_Formal (Form_Parm);
end loop;
end if;
-- Otherwise, return empty
return Empty;
end Function_Interp_Has_Abstract_Op;
----------------------
-- Get_First_Interp --
----------------------
procedure Get_First_Interp
(N : Node_Id;
I : out Interp_Index;
It : out Interp)
is
Int_Ind : Interp_Index;
O_N : Node_Id;
begin
-- If a selected component is overloaded because the selector has
-- multiple interpretations, the node is a call to a protected
-- operation or an indirect call. Retrieve the interpretation from
-- the selector name. The selected component may be overloaded as well
-- if the prefix is overloaded. That case is unchanged.
if Nkind (N) = N_Selected_Component
and then Is_Overloaded (Selector_Name (N))
then
O_N := Selector_Name (N);
else
O_N := N;
end if;
Int_Ind := Interp_Map.Get (O_N);
-- Procedure should never be called if the node has no interpretations
if Int_Ind < 0 then
raise Program_Error;
end if;
I := Int_Ind;
It := All_Interp.Table (Int_Ind);
end Get_First_Interp;
---------------------
-- Get_Next_Interp --
---------------------
procedure Get_Next_Interp (I : in out Interp_Index; It : out Interp) is
begin
I := I + 1;
It := All_Interp.Table (I);
end Get_Next_Interp;
-------------------------
-- Has_Compatible_Type --
-------------------------
function Has_Compatible_Type (N : Node_Id; Typ : Entity_Id) return Boolean
is
I : Interp_Index;
It : Interp;
begin
if N = Error then
return False;
end if;
if Nkind (N) = N_Subtype_Indication or else not Is_Overloaded (N) then
if Covers (Typ, Etype (N))
-- Ada 2005 (AI-345): The context may be a synchronized interface.
-- If the type is already frozen, use the corresponding_record to
-- check whether it is a proper descendant.
or else
(Is_Record_Type (Typ)
and then Is_Concurrent_Type (Etype (N))
and then Present (Corresponding_Record_Type (Etype (N)))
and then Covers (Typ, Corresponding_Record_Type (Etype (N))))
or else
(Is_Concurrent_Type (Typ)
and then Is_Record_Type (Etype (N))
and then Present (Corresponding_Record_Type (Typ))
and then Covers (Corresponding_Record_Type (Typ), Etype (N)))
or else Is_User_Defined_Literal (N, Typ)
then
return True;
end if;
-- Overloaded case
else
Get_First_Interp (N, I, It);
while Present (It.Typ) loop
if Covers (Typ, It.Typ)
-- Ada 2005 (AI-345)
or else
(Is_Record_Type (Typ)
and then Is_Concurrent_Type (It.Typ)
and then Present (Corresponding_Record_Type (Etype (It.Typ)))
and then
Covers (Typ, Corresponding_Record_Type (Etype (It.Typ))))
or else
(Is_Concurrent_Type (Typ)
and then Is_Record_Type (It.Typ)
and then Present (Corresponding_Record_Type (Typ))
and then
Covers (Corresponding_Record_Type (Typ), Etype (It.Typ)))
then
return True;
end if;
Get_Next_Interp (I, It);
end loop;
end if;
return False;
end Has_Compatible_Type;
---------------------
-- Has_Abstract_Op --
---------------------
function Has_Abstract_Op
(N : Node_Id;
Typ : Entity_Id) return Entity_Id
is
I : Interp_Index;
It : Interp;
begin
if Is_Overloaded (N) then
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
if Present (It.Abstract_Op)
and then Etype (It.Abstract_Op) = Typ
then
return It.Abstract_Op;
end if;
Get_Next_Interp (I, It);
end loop;
end if;
return Empty;
end Has_Abstract_Op;
----------
-- Hash --
----------
function Hash (N : Node_Id) return Header_Num is
begin
return Header_Num (N mod Header_Max);
end Hash;
--------------
-- Hides_Op --
--------------
function Hides_Op (F : Entity_Id; Op : Entity_Id) return Boolean is
Btyp : constant Entity_Id := Base_Type (Etype (First_Formal (F)));
begin
return Operator_Matches_Spec (Op, F)
and then (In_Open_Scopes (Scope (F))
or else Scope (F) = Scope (Btyp)
or else (not In_Open_Scopes (Scope (Btyp))
and then not In_Use (Btyp)
and then not In_Use (Scope (Btyp))));
end Hides_Op;
------------------------
-- Init_Interp_Tables --
------------------------
procedure Init_Interp_Tables is
begin
All_Interp.Init;
Interp_Map.Reset;
end Init_Interp_Tables;
-----------------------------------
-- Interface_Present_In_Ancestor --
-----------------------------------
function Interface_Present_In_Ancestor
(Typ : Entity_Id;
Iface : Entity_Id) return Boolean
is
Target_Typ : Entity_Id;
Iface_Typ : Entity_Id;
function Iface_Present_In_Ancestor (Typ : Entity_Id) return Boolean;
-- Returns True if Typ or some ancestor of Typ implements Iface
-------------------------------
-- Iface_Present_In_Ancestor --
-------------------------------
function Iface_Present_In_Ancestor (Typ : Entity_Id) return Boolean is
E : Entity_Id;
AI : Entity_Id;
Elmt : Elmt_Id;
begin
if Typ = Iface_Typ then
return True;
end if;
-- Handle private types
if Present (Full_View (Typ))
and then not Is_Concurrent_Type (Full_View (Typ))
then
E := Full_View (Typ);
else
E := Typ;
end if;
loop
if Is_Record_Type (E)
and then Present (Interfaces (E))
then
Elmt := First_Elmt (Interfaces (E));
while Present (Elmt) loop
AI := Node (Elmt);
if AI = Iface_Typ or else Is_Ancestor (Iface_Typ, AI) then
return True;
end if;
Next_Elmt (Elmt);
end loop;
end if;
exit when Etype (E) = E
-- Handle private types
or else (Present (Full_View (Etype (E)))
and then Full_View (Etype (E)) = E);
-- Check if the current type is a direct derivation of the
-- interface
if Etype (E) = Iface_Typ then
return True;
end if;
-- Climb to the immediate ancestor handling private types
if Present (Full_View (Etype (E))) then
E := Full_View (Etype (E));
else
E := Etype (E);
end if;
end loop;
return False;
end Iface_Present_In_Ancestor;
-- Start of processing for Interface_Present_In_Ancestor
begin
-- Iface might be a class-wide subtype, so we have to apply Base_Type
if Is_Class_Wide_Type (Iface) then
Iface_Typ := Etype (Base_Type (Iface));
else
Iface_Typ := Iface;
end if;
-- Handle subtypes
Iface_Typ := Base_Type (Iface_Typ);
if Is_Access_Type (Typ) then
Target_Typ := Etype (Directly_Designated_Type (Typ));
else
Target_Typ := Typ;
end if;
if Is_Concurrent_Record_Type (Target_Typ) then
Target_Typ := Corresponding_Concurrent_Type (Target_Typ);
end if;
Target_Typ := Base_Type (Target_Typ);
-- In case of concurrent types we can't use the Corresponding Record_Typ
-- to look for the interface because it is built by the expander (and
-- hence it is not always available). For this reason we traverse the
-- list of interfaces (available in the parent of the concurrent type).
if Is_Concurrent_Type (Target_Typ) then
declare
AI : Node_Id;
begin
AI := First (Interface_List (Parent (Target_Typ)));
-- The progenitor itself may be a subtype of an interface type
while Present (AI) loop
if Etype (AI) = Iface_Typ
or else Base_Type (Etype (AI)) = Iface_Typ
then
return True;
elsif Present (Interfaces (Etype (AI)))
and then Iface_Present_In_Ancestor (Etype (AI))
then
return True;
end if;
Next (AI);
end loop;
end;
return False;
end if;
if Is_Class_Wide_Type (Target_Typ) then
Target_Typ := Etype (Target_Typ);
end if;
if Ekind (Target_Typ) = E_Incomplete_Type then
-- We must have either a full view or a nonlimited view of the type
-- to locate the list of ancestors.
if Present (Full_View (Target_Typ)) then
Target_Typ := Full_View (Target_Typ);
else
-- In a spec expression or in an expression function, the use of
-- an incomplete type is legal; legality of the conversion will be
-- checked at freeze point of related entity.
if In_Spec_Expression then
return True;
else
pragma Assert (Present (Non_Limited_View (Target_Typ)));
Target_Typ := Non_Limited_View (Target_Typ);
end if;
end if;
-- Protect the front end against previously detected errors
if Ekind (Target_Typ) = E_Incomplete_Type then
return False;
end if;
end if;
return Iface_Present_In_Ancestor (Target_Typ);
end Interface_Present_In_Ancestor;
---------------------
-- Intersect_Types --
---------------------
function Intersect_Types (L, R : Node_Id) return Entity_Id is
Index : Interp_Index;
It : Interp;
Typ : Entity_Id;
function Check_Right_Argument (T : Entity_Id) return Entity_Id;
-- Find interpretation of right arg that has type compatible with T
--------------------------
-- Check_Right_Argument --
--------------------------
function Check_Right_Argument (T : Entity_Id) return Entity_Id is
Index : Interp_Index;
It : Interp;
T2 : Entity_Id;
begin
if not Is_Overloaded (R) then
return Specific_Type (T, Etype (R));
else
Get_First_Interp (R, Index, It);
loop
T2 := Specific_Type (T, It.Typ);
if T2 /= Any_Type then
return T2;
end if;
Get_Next_Interp (Index, It);
exit when No (It.Typ);
end loop;
return Any_Type;
end if;
end Check_Right_Argument;
-- Start of processing for Intersect_Types
begin
if Etype (L) = Any_Type or else Etype (R) = Any_Type then
return Any_Type;
end if;
if not Is_Overloaded (L) then
Typ := Check_Right_Argument (Etype (L));
else
Typ := Any_Type;
Get_First_Interp (L, Index, It);
while Present (It.Typ) loop
Typ := Check_Right_Argument (It.Typ);
exit when Typ /= Any_Type;
Get_Next_Interp (Index, It);
end loop;
end if;
-- If Typ is Any_Type, it means no compatible pair of types was found
if Typ = Any_Type then
if Nkind (Parent (L)) in N_Op then
Error_Msg_N ("incompatible types for operator", Parent (L));
elsif Nkind (Parent (L)) = N_Range then
Error_Msg_N ("incompatible types given in constraint", Parent (L));
-- Ada 2005 (AI-251): Complete the error notification
elsif Is_Class_Wide_Type (Etype (R))
and then Is_Interface (Etype (Class_Wide_Type (Etype (R))))
then
Error_Msg_NE ("(Ada 2005) does not implement interface }",
L, Etype (Class_Wide_Type (Etype (R))));
-- Specialize message if one operand is a limited view, a priori
-- unrelated to all other types.
elsif From_Limited_With (Etype (R)) then
Error_Msg_NE ("limited view of& not compatible with context",
R, Etype (R));
elsif From_Limited_With (Etype (L)) then
Error_Msg_NE ("limited view of& not compatible with context",
L, Etype (L));
else
Error_Msg_N ("incompatible types", Parent (L));
end if;
end if;
return Typ;
end Intersect_Types;
-----------------------
-- In_Generic_Actual --
-----------------------
function In_Generic_Actual (Exp : Node_Id) return Boolean is
Par : constant Node_Id := Parent (Exp);
begin
if No (Par) then
return False;
elsif Nkind (Par) in N_Declaration then
return
Nkind (Par) = N_Object_Declaration
and then Present (Corresponding_Generic_Association (Par));
elsif Nkind (Par) = N_Object_Renaming_Declaration then
return Present (Corresponding_Generic_Association (Par));
elsif Nkind (Par) in N_Statement_Other_Than_Procedure_Call then
return False;
else
return In_Generic_Actual (Par);
end if;
end In_Generic_Actual;
-----------------
-- Is_Ancestor --
-----------------
function Is_Ancestor
(T1 : Entity_Id;
T2 : Entity_Id;
Use_Full_View : Boolean := False) return Boolean
is
BT1 : Entity_Id;
BT2 : Entity_Id;
Par : Entity_Id;
begin
BT1 := Base_Type (T1);
BT2 := Base_Type (T2);
-- Handle underlying view of records with unknown discriminants using
-- the original entity that motivated the construction of this
-- underlying record view (see Build_Derived_Private_Type).
if Is_Underlying_Record_View (BT1) then
BT1 := Underlying_Record_View (BT1);
end if;
if Is_Underlying_Record_View (BT2) then
BT2 := Underlying_Record_View (BT2);
end if;
if BT1 = BT2 then
return True;
-- The predicate must look past privacy
elsif Is_Private_Type (T1)
and then Present (Full_View (T1))
and then BT2 = Base_Type (Full_View (T1))
then
return True;
elsif Is_Private_Type (T2)
and then Present (Full_View (T2))
and then BT1 = Base_Type (Full_View (T2))
then
return True;
else
-- Obtain the parent of the base type of T2 (use the full view if
-- allowed).
if Use_Full_View
and then Is_Private_Type (BT2)
and then Present (Full_View (BT2))
then
-- No climbing needed if its full view is the root type
if Full_View (BT2) = Root_Type (Full_View (BT2)) then
return False;
end if;
Par := Etype (Full_View (BT2));
else
Par := Etype (BT2);
end if;
loop
-- If there was a error on the type declaration, do not recurse
if Error_Posted (Par) then
return False;
elsif BT1 = Base_Type (Par)
or else (Is_Private_Type (T1)
and then Present (Full_View (T1))
and then Base_Type (Par) = Base_Type (Full_View (T1)))
then
return True;
elsif Is_Private_Type (Par)
and then Present (Full_View (Par))
and then Full_View (Par) = BT1
then
return True;
-- Root type found
elsif Par = Root_Type (Par) then
return False;
-- Continue climbing
else
-- Use the full-view of private types (if allowed). Guard
-- against infinite loops when full view has same type as
-- parent, as can happen with interface extensions.
if Use_Full_View
and then Is_Private_Type (Par)
and then Present (Full_View (Par))
and then Par /= Etype (Full_View (Par))
then
Par := Etype (Full_View (Par));
else
Par := Etype (Par);
end if;
end if;
end loop;
end if;
end Is_Ancestor;
--------------------
-- Is_Progenitor --
--------------------
function Is_Progenitor
(Iface : Entity_Id;
Typ : Entity_Id) return Boolean
is
begin
return Implements_Interface (Typ, Iface, Exclude_Parents => True);
end Is_Progenitor;
-------------------
-- Is_Subtype_Of --
-------------------
function Is_Subtype_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
S : Entity_Id;
begin
S := Ancestor_Subtype (T1);
while Present (S) loop
if S = T2 then
return True;
else
S := Ancestor_Subtype (S);
end if;
end loop;
return False;
end Is_Subtype_Of;
-------------------------
-- Is_Visible_Operator --
-------------------------
function Is_Visible_Operator (N : Node_Id; Typ : Entity_Id) return Boolean
is
begin
-- The predefined operators of the universal types are always visible
if Typ in Universal_Integer | Universal_Real | Universal_Access then
return True;
-- AI95-0230: Keep restriction imposed by Ada 83 and 95, do not allow
-- anonymous access types in universal_access equality operators.
elsif Is_Anonymous_Access_Type (Typ) then
return Ada_Version >= Ada_2005;
-- Similar reasoning for special types used for composite types before
-- type resolution is done.
elsif Typ = Any_Composite or else Typ = Any_String then
return True;
-- Within an instance, the predefined operators of the formal types are
-- visible and, for the other types, the generic package declaration has
-- already been successfully analyzed. Likewise for an inlined body.
elsif In_Instance or else In_Inlined_Body then
return True;
-- If the operation is given in functional notation and the prefix is an
-- expanded name, then the operator is visible if the prefix is the scope
-- of the type, or System if the type is declared in an extension of it.
elsif Nkind (N) = N_Function_Call
and then Nkind (Name (N)) = N_Expanded_Name
then
declare
Pref : constant Entity_Id := Entity (Prefix (Name (N)));
Scop : constant Entity_Id := Scope (Typ);
begin
return Pref = Scop
or else (Present (System_Aux_Id)
and then Scop = System_Aux_Id
and then Pref = Scope (Scop));
end;
-- Otherwise the operator is visible when the type is visible
else
return Is_Potentially_Use_Visible (Typ)
or else In_Use (Typ)
or else (In_Use (Scope (Typ)) and then not Is_Hidden (Typ))
or else In_Open_Scopes (Scope (Typ));
end if;
end Is_Visible_Operator;
------------------
-- List_Interps --
------------------
procedure List_Interps (Nam : Node_Id; Err : Node_Id) is
Index : Interp_Index;
It : Interp;
begin
Get_First_Interp (Nam, Index, It);
while Present (It.Nam) loop
if Scope (It.Nam) = Standard_Standard
and then Scope (It.Typ) /= Standard_Standard
then
Error_Msg_Sloc := Sloc (Parent (It.Typ));
Error_Msg_NE ("\\& (inherited) declared#!", Err, It.Nam);
else
Error_Msg_Sloc := Sloc (It.Nam);
Error_Msg_NE ("\\& declared#!", Err, It.Nam);
end if;
Get_Next_Interp (Index, It);
end loop;
end List_Interps;
-----------------
-- New_Interps --
-----------------
procedure New_Interps (N : Node_Id) is
begin
All_Interp.Append (No_Interp);
-- Add or rewrite the existing node
Last_Overloaded := N;
Interp_Map.Set (N, All_Interp.Last);
Set_Is_Overloaded (N, True);
end New_Interps;
---------------------------
-- Operator_Matches_Spec --
---------------------------
function Operator_Matches_Spec (Op, New_S : Entity_Id) return Boolean is
New_First_F : constant Entity_Id := First_Formal (New_S);
Op_Name : constant Name_Id := Chars (Op);
T : constant Entity_Id := Etype (New_S);
New_F : Entity_Id;
Num : Nat;
Old_F : Entity_Id;
T1 : Entity_Id;
T2 : Entity_Id;
begin
-- To verify that a predefined operator matches a given signature, do a
-- case analysis of the operator classes. Function can have one or two
-- formals and must have the proper result type.
New_F := New_First_F;
Old_F := First_Formal (Op);
Num := 0;
while Present (New_F) and then Present (Old_F) loop
Num := Num + 1;
Next_Formal (New_F);
Next_Formal (Old_F);
end loop;
-- Definite mismatch if different number of parameters
if Present (Old_F) or else Present (New_F) then
return False;
-- Unary operators
elsif Num = 1 then
T1 := Etype (New_First_F);
if Op_Name in Name_Op_Subtract | Name_Op_Add | Name_Op_Abs then
return Base_Type (T1) = Base_Type (T)
and then Is_Numeric_Type (T);
elsif Op_Name = Name_Op_Not then
return Base_Type (T1) = Base_Type (T)
and then Valid_Boolean_Arg (Base_Type (T));
else
return False;
end if;
-- Binary operators
else
T1 := Etype (New_First_F);
T2 := Etype (Next_Formal (New_First_F));
if Op_Name in Name_Op_And | Name_Op_Or | Name_Op_Xor then
return Base_Type (T1) = Base_Type (T2)
and then Base_Type (T1) = Base_Type (T)
and then Valid_Boolean_Arg (Base_Type (T));
elsif Op_Name in Name_Op_Eq | Name_Op_Ne then
return Base_Type (T1) = Base_Type (T2)
and then Valid_Equality_Arg (T1)
and then Is_Boolean_Type (T);
elsif Op_Name in Name_Op_Lt | Name_Op_Le | Name_Op_Gt | Name_Op_Ge
then
return Base_Type (T1) = Base_Type (T2)
and then Valid_Comparison_Arg (T1)
and then Is_Boolean_Type (T);
elsif Op_Name in Name_Op_Add | Name_Op_Subtract then
return Base_Type (T1) = Base_Type (T2)
and then Base_Type (T1) = Base_Type (T)
and then Is_Numeric_Type (T);
-- For division and multiplication, a user-defined function does not
-- match the predefined universal_fixed operation, except in Ada 83.
elsif Op_Name = Name_Op_Divide then
return (Base_Type (T1) = Base_Type (T2)
and then Base_Type (T1) = Base_Type (T)
and then Is_Numeric_Type (T)
and then (not Is_Fixed_Point_Type (T)
or else Ada_Version = Ada_83))
-- Mixed_Mode operations on fixed-point types
or else (Base_Type (T1) = Base_Type (T)
and then Base_Type (T2) = Base_Type (Standard_Integer)
and then Is_Fixed_Point_Type (T))
-- A user defined operator can also match (and hide) a mixed
-- operation on universal literals.
or else (Is_Integer_Type (T2)
and then Is_Floating_Point_Type (T1)
and then Base_Type (T1) = Base_Type (T));
elsif Op_Name = Name_Op_Multiply then
return (Base_Type (T1) = Base_Type (T2)
and then Base_Type (T1) = Base_Type (T)
and then Is_Numeric_Type (T)
and then (not Is_Fixed_Point_Type (T)
or else Ada_Version = Ada_83))
-- Mixed_Mode operations on fixed-point types
or else (Base_Type (T1) = Base_Type (T)
and then Base_Type (T2) = Base_Type (Standard_Integer)
and then Is_Fixed_Point_Type (T))
or else (Base_Type (T2) = Base_Type (T)
and then Base_Type (T1) = Base_Type (Standard_Integer)
and then Is_Fixed_Point_Type (T))
or else (Is_Integer_Type (T2)
and then Is_Floating_Point_Type (T1)
and then Base_Type (T1) = Base_Type (T))
or else (Is_Integer_Type (T1)
and then Is_Floating_Point_Type (T2)
and then Base_Type (T2) = Base_Type (T));
elsif Op_Name in Name_Op_Mod | Name_Op_Rem then
return Base_Type (T1) = Base_Type (T2)
and then Base_Type (T1) = Base_Type (T)
and then Is_Integer_Type (T);
elsif Op_Name = Name_Op_Expon then
return Base_Type (T1) = Base_Type (T)
and then Is_Numeric_Type (T)
and then Base_Type (T2) = Base_Type (Standard_Integer);
elsif Op_Name = Name_Op_Concat then
return Is_Array_Type (T)
and then Base_Type (T) = Base_Type (Etype (Op))
and then (Base_Type (T1) = Base_Type (T)
or else
Base_Type (T1) = Base_Type (Component_Type (T)))
and then (Base_Type (T2) = Base_Type (T)
or else
Base_Type (T2) = Base_Type (Component_Type (T)));
else
return False;
end if;
end if;
end Operator_Matches_Spec;
-------------------
-- Remove_Interp --
-------------------
procedure Remove_Interp (I : in out Interp_Index) is
II : Interp_Index;
begin
-- Find end of interp list and copy downward to erase the discarded one
II := I + 1;
while Present (All_Interp.Table (II).Typ) loop
II := II + 1;
end loop;
for J in I + 1 .. II loop
All_Interp.Table (J - 1) := All_Interp.Table (J);
end loop;
-- Back up interp index to insure that iterator will pick up next
-- available interpretation.
I := I - 1;
end Remove_Interp;
------------------
-- Save_Interps --
------------------
procedure Save_Interps (Old_N : Node_Id; New_N : Node_Id) is
Old_Ind : Interp_Index;
O_N : Node_Id;
begin
if Is_Overloaded (Old_N) then
Set_Is_Overloaded (New_N);
if Nkind (Old_N) = N_Selected_Component
and then Is_Overloaded (Selector_Name (Old_N))
then
O_N := Selector_Name (Old_N);
else
O_N := Old_N;
end if;
Old_Ind := Interp_Map.Get (O_N);
pragma Assert (Old_Ind >= 0);
New_Interps (New_N);
Interp_Map.Set (New_N, Old_Ind);
end if;
end Save_Interps;
-------------------
-- Specific_Type --
-------------------
function Specific_Type (Typ_1, Typ_2 : Entity_Id) return Entity_Id is
T1 : constant Entity_Id := Available_View (Typ_1);
T2 : constant Entity_Id := Available_View (Typ_2);
B1 : constant Entity_Id := Base_Type (T1);
B2 : constant Entity_Id := Base_Type (T2);
function Is_Remote_Access (T : Entity_Id) return Boolean;
-- Check whether T is the equivalent type of a remote access type.
-- If distribution is enabled, T is a legal context for Null.
----------------------
-- Is_Remote_Access --
----------------------
function Is_Remote_Access (T : Entity_Id) return Boolean is
begin
return Is_Record_Type (T)
and then (Is_Remote_Call_Interface (T)
or else Is_Remote_Types (T))
and then Present (Corresponding_Remote_Type (T))
and then Is_Access_Type (Corresponding_Remote_Type (T));
end Is_Remote_Access;
-- Start of processing for Specific_Type
begin
if T1 = Any_Type or else T2 = Any_Type then
return Any_Type;
end if;
if B1 = B2 then
return B1;
elsif (T1 = Universal_Integer and then Is_Integer_Type (T2))
or else (T1 = Universal_Real and then Is_Real_Type (T2))
or else (T1 = Universal_Fixed and then Is_Fixed_Point_Type (T2))
or else (T1 = Any_Fixed and then Is_Fixed_Point_Type (T2))
or else (T1 = Any_Modular and then Is_Modular_Integer_Type (T2))
or else (T1 = Any_Character and then Is_Character_Type (T2))
or else (T1 = Any_String and then Is_String_Type (T2))
or else (T1 = Any_Composite and then Is_Aggregate_Type (T2))
then
return B2;
elsif (T1 = Universal_Access
or else Ekind (T1) in E_Allocator_Type | E_Access_Attribute_Type)
and then (Is_Access_Type (T2) or else Is_Remote_Access (T2))
then
return B2;
elsif T1 = Raise_Type then
return B2;
elsif (T2 = Universal_Integer and then Is_Integer_Type (T1))
or else (T2 = Universal_Real and then Is_Real_Type (T1))
or else (T2 = Universal_Fixed and then Is_Fixed_Point_Type (T1))
or else (T2 = Any_Fixed and then Is_Fixed_Point_Type (T1))
or else (T2 = Any_Modular and then Is_Modular_Integer_Type (T1))
or else (T2 = Any_Character and then Is_Character_Type (T1))
or else (T2 = Any_String and then Is_String_Type (T1))
or else (T2 = Any_Composite and then Is_Aggregate_Type (T1))
then
return B1;
elsif (T2 = Universal_Access
or else Ekind (T2) in E_Allocator_Type | E_Access_Attribute_Type)
and then (Is_Access_Type (T1) or else Is_Remote_Access (T1))
then
return B1;
elsif T2 = Raise_Type then
return B1;
-- Ada 2005 (AI-251): T1 and T2 are class-wide types, and T2 is an
-- interface, return T1, and vice versa.
elsif Is_Class_Wide_Type (T1)
and then Is_Class_Wide_Type (T2)
and then Is_Interface (Etype (T2))
then
return B1;
elsif Is_Class_Wide_Type (T2)
and then Is_Class_Wide_Type (T1)
and then Is_Interface (Etype (T1))
then
return B2;
-- Ada 2005 (AI-251): T1 is a concrete type that implements the
-- class-wide interface T2, return T1, and vice versa.
elsif Is_Tagged_Type (T1)
and then Is_Class_Wide_Type (T2)
and then Is_Interface (Etype (T2))
and then Interface_Present_In_Ancestor (Typ => T1,
Iface => Etype (T2))
then
return B1;
elsif Is_Tagged_Type (T2)
and then Is_Class_Wide_Type (T1)
and then Is_Interface (Etype (T1))
and then Interface_Present_In_Ancestor (Typ => T2,
Iface => Etype (T1))
then
return B2;
elsif Is_Class_Wide_Type (T1)
and then Is_Ancestor (Root_Type (T1), T2)
then
return B1;
elsif Is_Class_Wide_Type (T2)
and then Is_Ancestor (Root_Type (T2), T1)
then
return B2;
elsif Is_Access_Type (T1)
and then Is_Access_Type (T2)
and then Is_Class_Wide_Type (Designated_Type (T1))
and then not Is_Class_Wide_Type (Designated_Type (T2))
and then
Is_Ancestor (Root_Type (Designated_Type (T1)), Designated_Type (T2))
then
return T1;
elsif Is_Access_Type (T1)
and then Is_Access_Type (T2)
and then Is_Class_Wide_Type (Designated_Type (T2))
and then not Is_Class_Wide_Type (Designated_Type (T1))
and then
Is_Ancestor (Root_Type (Designated_Type (T2)), Designated_Type (T1))
then
return T2;
elsif Ekind (B1) in E_Access_Subprogram_Type
| E_Access_Protected_Subprogram_Type
and then Ekind (Designated_Type (B1)) /= E_Subprogram_Type
and then Is_Access_Type (T2)
then
return T2;
elsif Ekind (B2) in E_Access_Subprogram_Type
| E_Access_Protected_Subprogram_Type
and then Ekind (Designated_Type (B2)) /= E_Subprogram_Type
and then Is_Access_Type (T1)
then
return T1;
-- Ada 2005 (AI-230): Support the following operators:
-- function "=" (L, R : universal_access) return Boolean;
-- function "/=" (L, R : universal_access) return Boolean;
-- Pool-specific access types (E_Access_Type) are not covered by these
-- operators because of the legality rule of 4.5.2(9.2): "The operands
-- of the equality operators for universal_access shall be convertible
-- to one another (see 4.6)". For example, considering the type decla-
-- ration "type P is access Integer" and an anonymous access to Integer,
-- P is convertible to "access Integer" by 4.6 (24.11-24.15), but there
-- is no rule in 4.6 that allows "access Integer" to be converted to P.
-- Note that this does not preclude one operand to be a pool-specific
-- access type, as a previous version of this code enforced.
elsif Is_Anonymous_Access_Type (T1)
and then Is_Access_Type (T2)
and then Ada_Version >= Ada_2005
then
return T1;
elsif Is_Anonymous_Access_Type (T2)
and then Is_Access_Type (T1)
and then Ada_Version >= Ada_2005
then
return T2;
-- With types exported from instantiation, also check private views the
-- same way as Covers
elsif Is_Private_Type (T1) and then Is_Generic_Actual_Type (T2) then
if Present (Full_View (T1)) then
return Specific_Type (Full_View (T1), T2);
elsif Present (Underlying_Full_View (T1)) then
return Specific_Type (Underlying_Full_View (T1), T2);
end if;
elsif Is_Private_Type (T2) and then Is_Generic_Actual_Type (T1) then
if Present (Full_View (T2)) then
return Specific_Type (T1, Full_View (T2));
elsif Present (Underlying_Full_View (T2)) then
return Specific_Type (T1, Underlying_Full_View (T2));
end if;
end if;
-- If none of the above cases applies, types are not compatible
return Any_Type;
end Specific_Type;
---------------------
-- Set_Abstract_Op --
---------------------
procedure Set_Abstract_Op (I : Interp_Index; V : Entity_Id) is
begin
All_Interp.Table (I).Abstract_Op := V;
end Set_Abstract_Op;
-----------------------
-- Valid_Boolean_Arg --
-----------------------
-- In addition to booleans and arrays of booleans, we must include
-- aggregates as valid boolean arguments, because in the first pass of
-- resolution their components are not examined. If it turns out not to be
-- an aggregate of booleans, this will be diagnosed in Resolve.
-- Any_Composite must be checked for prior to the array type checks because
-- Any_Composite does not have any associated indexes.
function Valid_Boolean_Arg (T : Entity_Id) return Boolean is
begin
if Is_Boolean_Type (T)
or else Is_Modular_Integer_Type (T)
or else T = Universal_Integer
or else T = Any_Composite
or else T = Raise_Type
then
return True;
elsif Is_Array_Type (T)
and then Number_Dimensions (T) = 1
and then Is_Boolean_Type (Component_Type (T))
and then
((not Is_Private_Composite (T) and then not Is_Limited_Composite (T))
or else In_Instance
or else Available_Full_View_Of_Component (T))
then
return True;
else
return False;
end if;
end Valid_Boolean_Arg;
--------------------------
-- Valid_Comparison_Arg --
--------------------------
-- See above for the reason why aggregates and strings are included
function Valid_Comparison_Arg (T : Entity_Id) return Boolean is
begin
if Is_Discrete_Type (T) or else Is_Real_Type (T) then
return True;
elsif T = Any_Composite or else T = Any_String then
return True;
elsif Is_Array_Type (T)
and then Number_Dimensions (T) = 1
and then Is_Discrete_Type (Component_Type (T))
and then (not Is_Private_Composite (T) or else In_Instance)
and then (not Is_Limited_Composite (T) or else In_Instance)
then
return True;
elsif Is_Array_Type (T)
and then Number_Dimensions (T) = 1
and then Is_Discrete_Type (Component_Type (T))
and then Available_Full_View_Of_Component (T)
then
return True;
elsif Is_String_Type (T) then
return True;
else
return False;
end if;
end Valid_Comparison_Arg;
------------------------
-- Valid_Equality_Arg --
------------------------
-- Same reasoning as above but implicit because of the nonlimited test
function Valid_Equality_Arg (T : Entity_Id) return Boolean is
begin
-- AI95-0230: Keep restriction imposed by Ada 83 and 95, do not allow
-- anonymous access types in universal_access equality operators.
if Is_Anonymous_Access_Type (T) then
return Ada_Version >= Ada_2005;
elsif not Is_Limited_Type (T) then
return True;
elsif Is_Array_Type (T)
and then not Is_Limited_Type (Component_Type (T))
and then Available_Full_View_Of_Component (T)
then
return True;
else
return False;
end if;
end Valid_Equality_Arg;
------------------
-- Write_Interp --
------------------
procedure Write_Interp (It : Interp) is
begin
Write_Str ("Nam: ");
Print_Tree_Node (It.Nam);
Write_Str ("Typ: ");
Print_Tree_Node (It.Typ);
Write_Str ("Abstract_Op: ");
Print_Tree_Node (It.Abstract_Op);
end Write_Interp;
---------------------
-- Write_Overloads --
---------------------
procedure Write_Overloads (N : Node_Id) is
I : Interp_Index;
It : Interp;
Nam : Entity_Id;
begin
Write_Str ("Overloads: ");
Print_Node_Briefly (N);
if not Is_Overloaded (N) then
if Is_Entity_Name (N) then
Write_Line ("Non-overloaded entity ");
Write_Entity_Info (Entity (N), " ");
end if;
elsif Nkind (N) not in N_Has_Entity then
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
Write_Int (Int (It.Typ));
Write_Str (" ");
Write_Name (Chars (It.Typ));
Write_Eol;
Get_Next_Interp (I, It);
end loop;
else
Get_First_Interp (N, I, It);
Write_Line ("Overloaded entity ");
Write_Line (" Name Type Abstract Op");
Write_Line ("===============================================");
Nam := It.Nam;
while Present (Nam) loop
Write_Int (Int (Nam));
Write_Str (" ");
Write_Name (Chars (Nam));
Write_Str (" ");
Write_Int (Int (It.Typ));
Write_Str (" ");
Write_Name (Chars (It.Typ));
if Present (It.Abstract_Op) then
Write_Str (" ");
Write_Int (Int (It.Abstract_Op));
Write_Str (" ");
Write_Name (Chars (It.Abstract_Op));
end if;
Write_Eol;
Get_Next_Interp (I, It);
Nam := It.Nam;
end loop;
end if;
end Write_Overloads;
end Sem_Type;
|